Python-checkins
Threads by month
- ----- 2025 -----
- January
- ----- 2024 -----
- December
- November
- 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
January 2025
- 1 participants
- 500 discussions
Jan. 20, 2025
https://github.com/python/cpython/commit/59fcae793f94be977c56c1f3c2988bd93d…
commit: 59fcae793f94be977c56c1f3c2988bd93d6b1564
branch: main
author: Bénédikt Tran <10796600+picnixz(a)users.noreply.github.com>
committer: picnixz <10796600+picnixz(a)users.noreply.github.com>
date: 2025-01-20T13:50:10+01:00
summary:
Remove duplicated dict keys in `test_{embed,long}.py` fixtures (#128727)
files:
M Lib/test/test_embed.py
M Lib/test/test_long.py
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index a2400aa96c3ddd..6d1b4cce498276 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -1049,7 +1049,6 @@ def test_init_compat_env(self):
'use_hash_seed': True,
'hash_seed': 42,
'tracemalloc': 2,
- 'perf_profiling': 0,
'import_time': True,
'code_debug_ranges': False,
'malloc_stats': True,
@@ -1086,7 +1085,6 @@ def test_init_python_env(self):
'use_hash_seed': True,
'hash_seed': 42,
'tracemalloc': 2,
- 'perf_profiling': 0,
'import_time': True,
'code_debug_ranges': False,
'malloc_stats': True,
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index 19978118c80dba..f336d49fa4f008 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -1470,7 +1470,6 @@ def equivalent_python(byte_array, byteorder, signed=False):
b'\x00': 0,
b'\x00\x00': 0,
b'\x01': 1,
- b'\x00\x01': 256,
b'\xff': -1,
b'\xff\xff': -1,
b'\x81': -127,
1
0
gh-111178: Regen clinic and fix exceptions.c post gh-128447 (#129060)
by erlend-aasland Jan. 20, 2025
by erlend-aasland Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/da0f47ceabd5c3f334265d8abe5ce1ba3d…
commit: da0f47ceabd5c3f334265d8abe5ce1ba3d5bcf0e
branch: main
author: Erlend E. Aasland <erlend(a)python.org>
committer: erlend-aasland <erlend.aasland(a)protonmail.com>
date: 2025-01-20T12:46:30Z
summary:
gh-111178: Regen clinic and fix exceptions.c post gh-128447 (#129060)
files:
M Objects/clinic/exceptions.c.h
M Objects/exceptions.c
diff --git a/Objects/clinic/exceptions.c.h b/Objects/clinic/exceptions.c.h
index caa5b0c63e53c5..3bd9a8553ab2fc 100644
--- a/Objects/clinic/exceptions.c.h
+++ b/Objects/clinic/exceptions.c.h
@@ -17,12 +17,12 @@ static PyObject *
BaseException___reduce___impl(PyBaseExceptionObject *self);
static PyObject *
-BaseException___reduce__(PyBaseExceptionObject *self, PyObject *Py_UNUSED(ignored))
+BaseException___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = BaseException___reduce___impl(self);
+ return_value = BaseException___reduce___impl((PyBaseExceptionObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -45,7 +45,7 @@ BaseException___setstate__(PyBaseExceptionObject *self, PyObject *state)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = BaseException___setstate___impl(self, state);
+ return_value = BaseException___setstate___impl((PyBaseExceptionObject *)self, state);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -69,7 +69,7 @@ BaseException_with_traceback(PyBaseExceptionObject *self, PyObject *tb)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = BaseException_with_traceback_impl(self, tb);
+ return_value = BaseException_with_traceback_impl((PyBaseExceptionObject *)self, tb);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -88,7 +88,7 @@ static PyObject *
BaseException_add_note_impl(PyBaseExceptionObject *self, PyObject *note);
static PyObject *
-BaseException_add_note(PyBaseExceptionObject *self, PyObject *arg)
+BaseException_add_note(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
PyObject *note;
@@ -99,7 +99,7 @@ BaseException_add_note(PyBaseExceptionObject *self, PyObject *arg)
}
note = arg;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = BaseException_add_note_impl(self, note);
+ return_value = BaseException_add_note_impl((PyBaseExceptionObject *)self, note);
Py_END_CRITICAL_SECTION();
exit:
@@ -120,12 +120,12 @@ static PyObject *
BaseException_args_get_impl(PyBaseExceptionObject *self);
static PyObject *
-BaseException_args_get(PyBaseExceptionObject *self, void *Py_UNUSED(context))
+BaseException_args_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = BaseException_args_get_impl(self);
+ return_value = BaseException_args_get_impl((PyBaseExceptionObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -145,12 +145,12 @@ static int
BaseException_args_set_impl(PyBaseExceptionObject *self, PyObject *value);
static int
-BaseException_args_set(PyBaseExceptionObject *self, PyObject *value, void *Py_UNUSED(context))
+BaseException_args_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = BaseException_args_set_impl(self, value);
+ return_value = BaseException_args_set_impl((PyBaseExceptionObject *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -170,12 +170,12 @@ static PyObject *
BaseException___traceback___get_impl(PyBaseExceptionObject *self);
static PyObject *
-BaseException___traceback___get(PyBaseExceptionObject *self, void *Py_UNUSED(context))
+BaseException___traceback___get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = BaseException___traceback___get_impl(self);
+ return_value = BaseException___traceback___get_impl((PyBaseExceptionObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -196,12 +196,12 @@ BaseException___traceback___set_impl(PyBaseExceptionObject *self,
PyObject *value);
static int
-BaseException___traceback___set(PyBaseExceptionObject *self, PyObject *value, void *Py_UNUSED(context))
+BaseException___traceback___set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = BaseException___traceback___set_impl(self, value);
+ return_value = BaseException___traceback___set_impl((PyBaseExceptionObject *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -221,12 +221,12 @@ static PyObject *
BaseException___context___get_impl(PyBaseExceptionObject *self);
static PyObject *
-BaseException___context___get(PyBaseExceptionObject *self, void *Py_UNUSED(context))
+BaseException___context___get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = BaseException___context___get_impl(self);
+ return_value = BaseException___context___get_impl((PyBaseExceptionObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -247,12 +247,12 @@ BaseException___context___set_impl(PyBaseExceptionObject *self,
PyObject *value);
static int
-BaseException___context___set(PyBaseExceptionObject *self, PyObject *value, void *Py_UNUSED(context))
+BaseException___context___set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = BaseException___context___set_impl(self, value);
+ return_value = BaseException___context___set_impl((PyBaseExceptionObject *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -272,12 +272,12 @@ static PyObject *
BaseException___cause___get_impl(PyBaseExceptionObject *self);
static PyObject *
-BaseException___cause___get(PyBaseExceptionObject *self, void *Py_UNUSED(context))
+BaseException___cause___get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = BaseException___cause___get_impl(self);
+ return_value = BaseException___cause___get_impl((PyBaseExceptionObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -298,14 +298,14 @@ BaseException___cause___set_impl(PyBaseExceptionObject *self,
PyObject *value);
static int
-BaseException___cause___set(PyBaseExceptionObject *self, PyObject *value, void *Py_UNUSED(context))
+BaseException___cause___set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = BaseException___cause___set_impl(self, value);
+ return_value = BaseException___cause___set_impl((PyBaseExceptionObject *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
}
-/*[clinic end generated code: output=58afcfd60057fc39 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8be99f8a7e527ba4 input=a9049054013a1b77]*/
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 4df89edfaf3953..d23b7f7c76c3e7 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -4256,7 +4256,7 @@ _PyException_AddNote(PyObject *exc, PyObject *note)
Py_TYPE(exc)->tp_name);
return -1;
}
- PyObject *r = BaseException_add_note(_PyBaseExceptionObject_cast(exc), note);
+ PyObject *r = BaseException_add_note(exc, note);
int res = r == NULL ? -1 : 0;
Py_XDECREF(r);
return res;
1
0
Jan. 20, 2025
https://github.com/python/cpython/commit/a30277a06af0f41ffaab8839bdfe7c79b9…
commit: a30277a06af0f41ffaab8839bdfe7c79b9b4e0ef
branch: main
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2025-01-20T14:32:27+02:00
summary:
gh-71339: Use new assertion methods in test_capi (GH-129053)
files:
M Lib/test/test_capi/test_abstract.py
M Lib/test/test_capi/test_misc.py
M Lib/test/test_capi/test_sys.py
diff --git a/Lib/test/test_capi/test_abstract.py b/Lib/test/test_capi/test_abstract.py
index 6a626813f23379..3de251bc5c241e 100644
--- a/Lib/test/test_capi/test_abstract.py
+++ b/Lib/test/test_capi/test_abstract.py
@@ -274,7 +274,7 @@ def test_object_setattr(self):
# PyObject_SetAttr(obj, attr_name, NULL) removes the attribute
xsetattr(obj, 'a', NULL)
- self.assertFalse(hasattr(obj, 'a'))
+ self.assertNotHasAttr(obj, 'a')
self.assertRaises(AttributeError, xsetattr, obj, 'b', NULL)
self.assertRaises(RuntimeError, xsetattr, obj, 'evil', NULL)
@@ -294,7 +294,7 @@ def test_object_setattrstring(self):
# PyObject_SetAttrString(obj, attr_name, NULL) removes the attribute
setattrstring(obj, b'a', NULL)
- self.assertFalse(hasattr(obj, 'a'))
+ self.assertNotHasAttr(obj, 'a')
self.assertRaises(AttributeError, setattrstring, obj, b'b', NULL)
self.assertRaises(RuntimeError, setattrstring, obj, b'evil', NULL)
@@ -311,10 +311,10 @@ def test_object_delattr(self):
obj.a = 1
setattr(obj, '\U0001f40d', 2)
xdelattr(obj, 'a')
- self.assertFalse(hasattr(obj, 'a'))
+ self.assertNotHasAttr(obj, 'a')
self.assertRaises(AttributeError, xdelattr, obj, 'b')
xdelattr(obj, '\U0001f40d')
- self.assertFalse(hasattr(obj, '\U0001f40d'))
+ self.assertNotHasAttr(obj, '\U0001f40d')
self.assertRaises(AttributeError, xdelattr, 42, 'numerator')
self.assertRaises(RuntimeError, xdelattr, obj, 'evil')
@@ -328,10 +328,10 @@ def test_object_delattrstring(self):
obj.a = 1
setattr(obj, '\U0001f40d', 2)
delattrstring(obj, b'a')
- self.assertFalse(hasattr(obj, 'a'))
+ self.assertNotHasAttr(obj, 'a')
self.assertRaises(AttributeError, delattrstring, obj, b'b')
delattrstring(obj, '\U0001f40d'.encode())
- self.assertFalse(hasattr(obj, '\U0001f40d'))
+ self.assertNotHasAttr(obj, '\U0001f40d')
self.assertRaises(AttributeError, delattrstring, 42, b'numerator')
self.assertRaises(RuntimeError, delattrstring, obj, b'evil')
diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py
index 99d9a757759dcd..ac09d72c7741c9 100644
--- a/Lib/test/test_capi/test_misc.py
+++ b/Lib/test/test_capi/test_misc.py
@@ -116,8 +116,7 @@ def test_no_FatalError_infinite_loop(self):
"after Python initialization and before Python finalization, "
"but it was called without an active thread state. "
"Are you trying to call the C API inside of a Py_BEGIN_ALLOW_THREADS block?").encode()
- self.assertTrue(err.rstrip().startswith(msg),
- err)
+ self.assertStartsWith(err.rstrip(), msg)
def test_memoryview_from_NULL_pointer(self):
self.assertRaises(ValueError, _testcapi.make_memoryview_from_NULL_pointer)
@@ -720,7 +719,7 @@ def test_heaptype_with_setattro(self):
def test_heaptype_with_custom_metaclass(self):
metaclass = _testcapi.HeapCTypeMetaclass
- self.assertTrue(issubclass(metaclass, type))
+ self.assertIsSubclass(metaclass, type)
# Class creation from C
t = _testcapi.pytype_fromspec_meta(metaclass)
@@ -736,7 +735,7 @@ def test_heaptype_with_custom_metaclass(self):
def test_heaptype_with_custom_metaclass_null_new(self):
metaclass = _testcapi.HeapCTypeMetaclassNullNew
- self.assertTrue(issubclass(metaclass, type))
+ self.assertIsSubclass(metaclass, type)
# Class creation from C
t = _testcapi.pytype_fromspec_meta(metaclass)
@@ -751,7 +750,7 @@ def test_heaptype_with_custom_metaclass_null_new(self):
def test_heaptype_with_custom_metaclass_custom_new(self):
metaclass = _testcapi.HeapCTypeMetaclassCustomNew
- self.assertTrue(issubclass(_testcapi.HeapCTypeMetaclassCustomNew, type))
+ self.assertIsSubclass(_testcapi.HeapCTypeMetaclassCustomNew, type)
msg = "Metaclasses with custom tp_new are not supported."
with self.assertRaisesRegex(TypeError, msg):
@@ -910,8 +909,7 @@ def test_export_symbols(self):
names.append('Py_FrozenMain')
for name in names:
- with self.subTest(name=name):
- self.assertTrue(hasattr(ctypes.pythonapi, name))
+ self.assertHasAttr(ctypes.pythonapi, name)
def test_clear_managed_dict(self):
@@ -1503,7 +1501,8 @@ def inner(arg5, arg6):
self.assertIsInstance(closure, tuple)
self.assertEqual(len(closure), 1)
self.assertEqual(len(closure), len(func.__code__.co_freevars))
- self.assertTrue(all(isinstance(cell, CellType) for cell in closure))
+ for cell in closure:
+ self.assertIsInstance(cell, CellType)
self.assertTrue(closure[0].cell_contents, 5)
func = with_two_levels(1, 2)(3, 4)
@@ -1512,7 +1511,8 @@ def inner(arg5, arg6):
self.assertIsInstance(closure, tuple)
self.assertEqual(len(closure), 4)
self.assertEqual(len(closure), len(func.__code__.co_freevars))
- self.assertTrue(all(isinstance(cell, CellType) for cell in closure))
+ for cell in closure:
+ self.assertIsInstance(cell, CellType)
self.assertEqual([cell.cell_contents for cell in closure],
[1, 2, 3, 4])
@@ -2365,7 +2365,7 @@ def test_mutate_exception(self):
support.run_in_subinterp("import binascii; binascii.Error.foobar = 'foobar'")
- self.assertFalse(hasattr(binascii.Error, "foobar"))
+ self.assertNotHasAttr(binascii.Error, "foobar")
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
# gh-117649: The free-threaded build does not currently support sharing
diff --git a/Lib/test/test_capi/test_sys.py b/Lib/test/test_capi/test_sys.py
index 54a8e026d883d4..d3a9b378e7769a 100644
--- a/Lib/test/test_capi/test_sys.py
+++ b/Lib/test/test_capi/test_sys.py
@@ -51,7 +51,7 @@ def test_sys_setobject(self):
self.assertEqual(setobject(b'newattr', value2), 0)
self.assertIs(sys.newattr, value2)
self.assertEqual(setobject(b'newattr', NULL), 0)
- self.assertFalse(hasattr(sys, 'newattr'))
+ self.assertNotHasAttr(sys, 'newattr')
self.assertEqual(setobject(b'newattr', NULL), 0)
finally:
with contextlib.suppress(AttributeError):
@@ -60,7 +60,7 @@ def test_sys_setobject(self):
self.assertEqual(setobject('\U0001f40d'.encode(), value), 0)
self.assertIs(getattr(sys, '\U0001f40d'), value)
self.assertEqual(setobject('\U0001f40d'.encode(), NULL), 0)
- self.assertFalse(hasattr(sys, '\U0001f40d'))
+ self.assertNotHasAttr(sys, '\U0001f40d')
finally:
with contextlib.suppress(AttributeError):
delattr(sys, '\U0001f40d')
1
0
[3.12] gh-71339: Add additional assertion methods in test.support (GH-128707) (GH-128815) (GH-129059)
by serhiy-storchaka Jan. 20, 2025
by serhiy-storchaka Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/032058cb62c77824800d76a765ba28c733…
commit: 032058cb62c77824800d76a765ba28c733b4335f
branch: 3.12
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2025-01-20T12:06:02Z
summary:
[3.12] gh-71339: Add additional assertion methods in test.support (GH-128707) (GH-128815) (GH-129059)
Add a mix-in class ExtraAssertions containing the following methods:
* assertHasAttr() and assertNotHasAttr()
* assertIsSubclass() and assertNotIsSubclass()
* assertStartsWith() and assertNotStartsWith()
* assertEndsWith() and assertNotEndsWith()
(cherry picked from commit c6a566e47b9903d48e6e1e78a1af20e6c6c535cf)
Co-authored-by: Serhiy Storchaka <storchaka(a)gmail.com>
(cherry picked from commit 06cad77a5b345adde88609be9c3c470c5cd9f417)
files:
M Lib/test/support/testcase.py
M Lib/test/test_descr.py
M Lib/test/test_gdb/util.py
M Lib/test/test_pyclbr.py
M Lib/test/test_typing.py
M Lib/test/test_venv.py
diff --git a/Lib/test/support/testcase.py b/Lib/test/support/testcase.py
index fad1e4cb3499c0..fd32457d1467ca 100644
--- a/Lib/test/support/testcase.py
+++ b/Lib/test/support/testcase.py
@@ -1,6 +1,63 @@
from math import copysign, isnan
+class ExtraAssertions:
+
+ def assertIsSubclass(self, cls, superclass, msg=None):
+ if issubclass(cls, superclass):
+ return
+ standardMsg = f'{cls!r} is not a subclass of {superclass!r}'
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertNotIsSubclass(self, cls, superclass, msg=None):
+ if not issubclass(cls, superclass):
+ return
+ standardMsg = f'{cls!r} is a subclass of {superclass!r}'
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertHasAttr(self, obj, name, msg=None):
+ if not hasattr(obj, name):
+ if isinstance(obj, types.ModuleType):
+ standardMsg = f'module {obj.__name__!r} has no attribute {name!r}'
+ elif isinstance(obj, type):
+ standardMsg = f'type object {obj.__name__!r} has no attribute {name!r}'
+ else:
+ standardMsg = f'{type(obj).__name__!r} object has no attribute {name!r}'
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertNotHasAttr(self, obj, name, msg=None):
+ if hasattr(obj, name):
+ if isinstance(obj, types.ModuleType):
+ standardMsg = f'module {obj.__name__!r} has unexpected attribute {name!r}'
+ elif isinstance(obj, type):
+ standardMsg = f'type object {obj.__name__!r} has unexpected attribute {name!r}'
+ else:
+ standardMsg = f'{type(obj).__name__!r} object has unexpected attribute {name!r}'
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertStartsWith(self, s, prefix, msg=None):
+ if s.startswith(prefix):
+ return
+ standardMsg = f"{s!r} doesn't start with {prefix!r}"
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertNotStartsWith(self, s, prefix, msg=None):
+ if not s.startswith(prefix):
+ return
+ self.fail(self._formatMessage(msg, f"{s!r} starts with {prefix!r}"))
+
+ def assertEndsWith(self, s, suffix, msg=None):
+ if s.endswith(suffix):
+ return
+ standardMsg = f"{s!r} doesn't end with {suffix!r}"
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertNotEndsWith(self, s, suffix, msg=None):
+ if not s.endswith(suffix):
+ return
+ self.fail(self._formatMessage(msg, f"{s!r} ends with {suffix!r}"))
+
+
class ExceptionIsLikeMixin:
def assertExceptionIsLike(self, exc, template):
"""
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 3a11435e3e2543..99388b53878f36 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -15,6 +15,7 @@
from copy import deepcopy
from contextlib import redirect_stdout
from test import support
+from test.support.testcase import ExtraAssertions
try:
import _testcapi
@@ -403,15 +404,7 @@ def test_wrap_lenfunc_bad_cast(self):
self.assertEqual(range(sys.maxsize).__len__(), sys.maxsize)
-class ClassPropertiesAndMethods(unittest.TestCase):
-
- def assertHasAttr(self, obj, name):
- self.assertTrue(hasattr(obj, name),
- '%r has no attribute %r' % (obj, name))
-
- def assertNotHasAttr(self, obj, name):
- self.assertFalse(hasattr(obj, name),
- '%r has unexpected attribute %r' % (obj, name))
+class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
def test_python_dicts(self):
# Testing Python subclass of dict...
diff --git a/Lib/test/test_gdb/util.py b/Lib/test/test_gdb/util.py
index 8fe9cfc543395e..54c6b2de7cc99d 100644
--- a/Lib/test/test_gdb/util.py
+++ b/Lib/test/test_gdb/util.py
@@ -7,6 +7,7 @@
import sysconfig
import unittest
from test import support
+from test.support.testcase import ExtraAssertions
GDB_PROGRAM = shutil.which('gdb') or 'gdb'
@@ -152,7 +153,7 @@ def setup_module():
print()
-class DebuggerTests(unittest.TestCase):
+class DebuggerTests(unittest.TestCase, ExtraAssertions):
"""Test that the debugger can debug Python."""
@@ -280,11 +281,6 @@ def get_stack_trace(self, source=None, script=None,
return out
- def assertEndsWith(self, actual, exp_end):
- '''Ensure that the given "actual" string ends with "exp_end"'''
- self.assertTrue(actual.endswith(exp_end),
- msg='%r did not end with %r' % (actual, exp_end))
-
def assertMultilineMatches(self, actual, pattern):
m = re.match(pattern, actual, re.DOTALL)
if not m:
diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py
index 5415fa08330325..a7580a4124defd 100644
--- a/Lib/test/test_pyclbr.py
+++ b/Lib/test/test_pyclbr.py
@@ -10,6 +10,7 @@
from unittest import TestCase, main as unittest_main
from test.test_importlib import util as test_importlib_util
import warnings
+from test.support.testcase import ExtraAssertions
StaticMethodType = type(staticmethod(lambda: None))
@@ -22,7 +23,7 @@
# is imperfect (as designed), testModule is called with a set of
# members to ignore.
-class PyclbrTest(TestCase):
+class PyclbrTest(TestCase, ExtraAssertions):
def assertListEq(self, l1, l2, ignore):
''' succeed iff {l1} - {ignore} == {l2} - {ignore} '''
@@ -31,14 +32,6 @@ def assertListEq(self, l1, l2, ignore):
print("l1=%r\nl2=%r\nignore=%r" % (l1, l2, ignore), file=sys.stderr)
self.fail("%r missing" % missing.pop())
- def assertHasattr(self, obj, attr, ignore):
- ''' succeed iff hasattr(obj,attr) or attr in ignore. '''
- if attr in ignore: return
- if not hasattr(obj, attr): print("???", attr)
- self.assertTrue(hasattr(obj, attr),
- 'expected hasattr(%r, %r)' % (obj, attr))
-
-
def assertHaskey(self, obj, key, ignore):
''' succeed iff key in obj or key in ignore. '''
if key in ignore: return
@@ -86,7 +79,7 @@ def ismethod(oclass, obj, name):
for name, value in dict.items():
if name in ignore:
continue
- self.assertHasattr(module, name, ignore)
+ self.assertHasAttr(module, name, ignore)
py_item = getattr(module, name)
if isinstance(value, pyclbr.Function):
self.assertIsInstance(py_item, (FunctionType, BuiltinFunctionType))
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index c5f4d775f22fb6..5c862d7928c950 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -47,6 +47,7 @@
import types
from test.support import captured_stderr, cpython_only
+from test.support.testcase import ExtraAssertions
from test.typinganndata import ann_module695, mod_generics_cache, _typed_dict_helper
@@ -55,21 +56,7 @@
CANNOT_SUBCLASS_INSTANCE = 'Cannot subclass an instance of %s'
-class BaseTestCase(TestCase):
-
- def assertIsSubclass(self, cls, class_or_tuple, msg=None):
- if not issubclass(cls, class_or_tuple):
- message = '%r is not a subclass of %r' % (cls, class_or_tuple)
- if msg is not None:
- message += ' : %s' % msg
- raise self.failureException(message)
-
- def assertNotIsSubclass(self, cls, class_or_tuple, msg=None):
- if issubclass(cls, class_or_tuple):
- message = '%r is a subclass of %r' % (cls, class_or_tuple)
- if msg is not None:
- message += ' : %s' % msg
- raise self.failureException(message)
+class BaseTestCase(TestCase, ExtraAssertions):
def clear_caches(self):
for f in typing._cleanups:
@@ -1051,10 +1038,6 @@ class Gen[*Ts]: ...
class TypeVarTupleTests(BaseTestCase):
- def assertEndsWith(self, string, tail):
- if not string.endswith(tail):
- self.fail(f"String {string!r} does not end with {tail!r}")
-
def test_name(self):
Ts = TypeVarTuple('Ts')
self.assertEqual(Ts.__name__, 'Ts')
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
index 8254a701e09a10..43c67ac751d585 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -25,6 +25,7 @@
requires_resource, copy_python_src_ignore)
from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree,
TESTFN, FakePath)
+from test.support.testcase import ExtraAssertions
import unittest
import venv
from unittest.mock import patch, Mock
@@ -58,7 +59,7 @@ def check_output(cmd, encoding=None):
p.returncode, cmd, out, err)
return out, err
-class BaseTest(unittest.TestCase):
+class BaseTest(unittest.TestCase, ExtraAssertions):
"""Base class for venv tests."""
maxDiff = 80 * 50
@@ -98,10 +99,6 @@ def get_text_file_contents(self, *args, encoding='utf-8'):
result = f.read()
return result
- def assertEndsWith(self, string, tail):
- if not string.endswith(tail):
- self.fail(f"String {string!r} does not end with {tail!r}")
-
class BasicTest(BaseTest):
"""Test venv module functionality."""
1
0
gh-111178: Generate correct signature for most self converters (#128447)
by erlend-aasland Jan. 20, 2025
by erlend-aasland Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/537296cdcdecae5c2322e809d01ec07f0c…
commit: 537296cdcdecae5c2322e809d01ec07f0cb79245
branch: main
author: Erlend E. Aasland <erlend(a)python.org>
committer: erlend-aasland <erlend.aasland(a)protonmail.com>
date: 2025-01-20T12:40:18+01:00
summary:
gh-111178: Generate correct signature for most self converters (#128447)
files:
M Lib/test/clinic.test.c
M Modules/_ctypes/clinic/_ctypes.c.h
M Modules/_datetimemodule.c
M Modules/_io/bytesio.c
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/stringio.c.h
M Modules/_io/clinic/textio.c.h
M Modules/_io/clinic/winconsoleio.c.h
M Modules/_io/stringio.c
M Modules/_multiprocessing/clinic/semaphore.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/row.c.h
M Modules/_sqlite/cursor.c
M Modules/_sre/clinic/sre.c.h
M Modules/_ssl.c
M Modules/_ssl/clinic/cert.c.h
M Modules/arraymodule.c
M Modules/cjkcodecs/clinic/multibytecodec.c.h
M Modules/clinic/_asynciomodule.c.h
M Modules/clinic/_bz2module.c.h
M Modules/clinic/_collectionsmodule.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/_gdbmmodule.c.h
M Modules/clinic/_hashopenssl.c.h
M Modules/clinic/_lsprof.c.h
M Modules/clinic/_lzmamodule.c.h
M Modules/clinic/_pickle.c.h
M Modules/clinic/_queuemodule.c.h
M Modules/clinic/_randommodule.c.h
M Modules/clinic/_ssl.c.h
M Modules/clinic/_struct.c.h
M Modules/clinic/_testmultiphase.c.h
M Modules/clinic/_tkinter.c.h
M Modules/clinic/_winapi.c.h
M Modules/clinic/arraymodule.c.h
M Modules/clinic/blake2module.c.h
M Modules/clinic/md5module.c.h
M Modules/clinic/overlapped.c.h
M Modules/clinic/posixmodule.c.h
M Modules/clinic/pyexpat.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/socketmodule.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/dictobject.c.h
M Objects/clinic/listobject.c.h
M Objects/clinic/memoryobject.c.h
M Objects/clinic/odictobject.c.h
M Objects/clinic/setobject.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/codeobject.c
M Objects/setobject.c
M PC/clinic/winreg.c.h
M Python/clinic/context.c.h
M Python/clinic/instruction_sequence.c.h
M Tools/clinic/libclinic/converters.py
diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c
index e4f146c0841188..0dfcc281985100 100644
--- a/Lib/test/clinic.test.c
+++ b/Lib/test/clinic.test.c
@@ -4758,7 +4758,7 @@ static PyObject *
Test_cls_with_param_impl(TestObj *self, PyTypeObject *cls, int a);
static PyObject *
-Test_cls_with_param(TestObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+Test_cls_with_param(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -4798,7 +4798,7 @@ Test_cls_with_param(TestObj *self, PyTypeObject *cls, PyObject *const *args, Py_
if (a == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = Test_cls_with_param_impl(self, cls, a);
+ return_value = Test_cls_with_param_impl((TestObj *)self, cls, a);
exit:
return return_value;
@@ -4806,7 +4806,7 @@ Test_cls_with_param(TestObj *self, PyTypeObject *cls, PyObject *const *args, Py_
static PyObject *
Test_cls_with_param_impl(TestObj *self, PyTypeObject *cls, int a)
-/*[clinic end generated code: output=83a391eea66d08f8 input=af158077bd237ef9]*/
+/*[clinic end generated code: output=7e893134a81fef92 input=af158077bd237ef9]*/
/*[clinic input]
@@ -4908,18 +4908,18 @@ static PyObject *
Test_cls_no_params_impl(TestObj *self, PyTypeObject *cls);
static PyObject *
-Test_cls_no_params(TestObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+Test_cls_no_params(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "cls_no_params() takes no arguments");
return NULL;
}
- return Test_cls_no_params_impl(self, cls);
+ return Test_cls_no_params_impl((TestObj *)self, cls);
}
static PyObject *
Test_cls_no_params_impl(TestObj *self, PyTypeObject *cls)
-/*[clinic end generated code: output=4d68b4652c144af3 input=e7e2e4e344e96a11]*/
+/*[clinic end generated code: output=8845de054449f40a input=e7e2e4e344e96a11]*/
/*[clinic input]
@@ -4945,7 +4945,7 @@ Test_metho_not_default_return_converter(TestObj *self, PyObject *a)
PyObject *return_value = NULL;
int _return_value;
- _return_value = Test_metho_not_default_return_converter_impl(self, a);
+ _return_value = Test_metho_not_default_return_converter_impl((TestObj *)self, a);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -4957,7 +4957,7 @@ Test_metho_not_default_return_converter(TestObj *self, PyObject *a)
static int
Test_metho_not_default_return_converter_impl(TestObj *self, PyObject *a)
-/*[clinic end generated code: output=3350de11bd538007 input=428657129b521177]*/
+/*[clinic end generated code: output=b2cce75a7af2e6ce input=428657129b521177]*/
/*[clinic input]
@@ -4983,7 +4983,7 @@ static PyObject *
Test_an_metho_arg_named_arg_impl(TestObj *self, int arg);
static PyObject *
-Test_an_metho_arg_named_arg(TestObj *self, PyObject *arg_)
+Test_an_metho_arg_named_arg(PyObject *self, PyObject *arg_)
{
PyObject *return_value = NULL;
int arg;
@@ -4992,7 +4992,7 @@ Test_an_metho_arg_named_arg(TestObj *self, PyObject *arg_)
if (arg == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = Test_an_metho_arg_named_arg_impl(self, arg);
+ return_value = Test_an_metho_arg_named_arg_impl((TestObj *)self, arg);
exit:
return return_value;
@@ -5000,7 +5000,7 @@ Test_an_metho_arg_named_arg(TestObj *self, PyObject *arg_)
static PyObject *
Test_an_metho_arg_named_arg_impl(TestObj *self, int arg)
-/*[clinic end generated code: output=9f04de4a62287e28 input=2a53a57cf5624f95]*/
+/*[clinic end generated code: output=38554f09950d07e7 input=2a53a57cf5624f95]*/
/*[clinic input]
@@ -5289,14 +5289,14 @@ static PyObject *
Test_meth_coexist_impl(TestObj *self);
static PyObject *
-Test_meth_coexist(TestObj *self, PyObject *Py_UNUSED(ignored))
+Test_meth_coexist(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return Test_meth_coexist_impl(self);
+ return Test_meth_coexist_impl((TestObj *)self);
}
static PyObject *
Test_meth_coexist_impl(TestObj *self)
-/*[clinic end generated code: output=808a293d0cd27439 input=2a1d75b5e6fec6dd]*/
+/*[clinic end generated code: output=7edf4e95b29f06fa input=2a1d75b5e6fec6dd]*/
/*[clinic input]
@getter
@@ -5317,14 +5317,14 @@ static PyObject *
Test_property_get_impl(TestObj *self);
static PyObject *
-Test_property_get(TestObj *self, void *Py_UNUSED(context))
+Test_property_get(PyObject *self, void *Py_UNUSED(context))
{
- return Test_property_get_impl(self);
+ return Test_property_get_impl((TestObj *)self);
}
static PyObject *
Test_property_get_impl(TestObj *self)
-/*[clinic end generated code: output=7cadd0f539805266 input=2d92b3449fbc7d2b]*/
+/*[clinic end generated code: output=b38d68abd3466a6e input=2d92b3449fbc7d2b]*/
/*[clinic input]
@setter
@@ -5345,18 +5345,18 @@ static int
Test_property_set_impl(TestObj *self, PyObject *value);
static int
-Test_property_set(TestObj *self, PyObject *value, void *Py_UNUSED(context))
+Test_property_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
- return_value = Test_property_set_impl(self, value);
+ return_value = Test_property_set_impl((TestObj *)self, value);
return return_value;
}
static int
Test_property_set_impl(TestObj *self, PyObject *value)
-/*[clinic end generated code: output=e4342fe9bb1d7817 input=3bc3f46a23c83a88]*/
+/*[clinic end generated code: output=49f925ab2a33b637 input=3bc3f46a23c83a88]*/
/*[clinic input]
@setter
@@ -5377,18 +5377,18 @@ static int
Test_setter_first_with_docstr_set_impl(TestObj *self, PyObject *value);
static int
-Test_setter_first_with_docstr_set(TestObj *self, PyObject *value, void *Py_UNUSED(context))
+Test_setter_first_with_docstr_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
- return_value = Test_setter_first_with_docstr_set_impl(self, value);
+ return_value = Test_setter_first_with_docstr_set_impl((TestObj *)self, value);
return return_value;
}
static int
Test_setter_first_with_docstr_set_impl(TestObj *self, PyObject *value)
-/*[clinic end generated code: output=e4d76b558a4061db input=31a045ce11bbe961]*/
+/*[clinic end generated code: output=5aaf44373c0af545 input=31a045ce11bbe961]*/
/*[clinic input]
@getter
@@ -5418,14 +5418,14 @@ static PyObject *
Test_setter_first_with_docstr_get_impl(TestObj *self);
static PyObject *
-Test_setter_first_with_docstr_get(TestObj *self, void *Py_UNUSED(context))
+Test_setter_first_with_docstr_get(PyObject *self, void *Py_UNUSED(context))
{
- return Test_setter_first_with_docstr_get_impl(self);
+ return Test_setter_first_with_docstr_get_impl((TestObj *)self);
}
static PyObject *
Test_setter_first_with_docstr_get_impl(TestObj *self)
-/*[clinic end generated code: output=749a30266f9fb443 input=10af4e43b3cb34dc]*/
+/*[clinic end generated code: output=fe6e3aa844a24920 input=10af4e43b3cb34dc]*/
/*[clinic input]
output push
@@ -5708,7 +5708,7 @@ Test__pyarg_parsestackandkeywords_impl(TestObj *self, PyTypeObject *cls,
Py_ssize_t key_length);
static PyObject *
-Test__pyarg_parsestackandkeywords(TestObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+Test__pyarg_parsestackandkeywords(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -5731,7 +5731,7 @@ Test__pyarg_parsestackandkeywords(TestObj *self, PyTypeObject *cls, PyObject *co
&key, &key_length)) {
goto exit;
}
- return_value = Test__pyarg_parsestackandkeywords_impl(self, cls, key, key_length);
+ return_value = Test__pyarg_parsestackandkeywords_impl((TestObj *)self, cls, key, key_length);
exit:
return return_value;
@@ -5741,7 +5741,7 @@ static PyObject *
Test__pyarg_parsestackandkeywords_impl(TestObj *self, PyTypeObject *cls,
const char *key,
Py_ssize_t key_length)
-/*[clinic end generated code: output=4fda8a7f2547137c input=fc72ef4b4cfafabc]*/
+/*[clinic end generated code: output=7060c213d7b8200e input=fc72ef4b4cfafabc]*/
/*[clinic input]
diff --git a/Modules/_ctypes/clinic/_ctypes.c.h b/Modules/_ctypes/clinic/_ctypes.c.h
index 405a3c9238d77d..1f2e871137ed79 100644
--- a/Modules/_ctypes/clinic/_ctypes.c.h
+++ b/Modules/_ctypes/clinic/_ctypes.c.h
@@ -331,7 +331,7 @@ PyCPointerType_set_type_impl(PyTypeObject *self, PyTypeObject *cls,
PyObject *type);
static PyObject *
-PyCPointerType_set_type(PyTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+PyCPointerType_set_type(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -356,7 +356,7 @@ PyCPointerType_set_type(PyTypeObject *self, PyTypeObject *cls, PyObject *const *
goto exit;
}
type = args[0];
- return_value = PyCPointerType_set_type_impl(self, cls, type);
+ return_value = PyCPointerType_set_type_impl((PyTypeObject *)self, cls, type);
exit:
return return_value;
@@ -616,12 +616,12 @@ static int
_ctypes_CFuncPtr_errcheck_set_impl(PyCFuncPtrObject *self, PyObject *value);
static int
-_ctypes_CFuncPtr_errcheck_set(PyCFuncPtrObject *self, PyObject *value, void *Py_UNUSED(context))
+_ctypes_CFuncPtr_errcheck_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ctypes_CFuncPtr_errcheck_set_impl(self, value);
+ return_value = _ctypes_CFuncPtr_errcheck_set_impl((PyCFuncPtrObject *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -648,12 +648,12 @@ static PyObject *
_ctypes_CFuncPtr_errcheck_get_impl(PyCFuncPtrObject *self);
static PyObject *
-_ctypes_CFuncPtr_errcheck_get(PyCFuncPtrObject *self, void *Py_UNUSED(context))
+_ctypes_CFuncPtr_errcheck_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ctypes_CFuncPtr_errcheck_get_impl(self);
+ return_value = _ctypes_CFuncPtr_errcheck_get_impl((PyCFuncPtrObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -673,12 +673,12 @@ static int
_ctypes_CFuncPtr_restype_set_impl(PyCFuncPtrObject *self, PyObject *value);
static int
-_ctypes_CFuncPtr_restype_set(PyCFuncPtrObject *self, PyObject *value, void *Py_UNUSED(context))
+_ctypes_CFuncPtr_restype_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ctypes_CFuncPtr_restype_set_impl(self, value);
+ return_value = _ctypes_CFuncPtr_restype_set_impl((PyCFuncPtrObject *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -705,12 +705,12 @@ static PyObject *
_ctypes_CFuncPtr_restype_get_impl(PyCFuncPtrObject *self);
static PyObject *
-_ctypes_CFuncPtr_restype_get(PyCFuncPtrObject *self, void *Py_UNUSED(context))
+_ctypes_CFuncPtr_restype_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ctypes_CFuncPtr_restype_get_impl(self);
+ return_value = _ctypes_CFuncPtr_restype_get_impl((PyCFuncPtrObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -730,12 +730,12 @@ static int
_ctypes_CFuncPtr_argtypes_set_impl(PyCFuncPtrObject *self, PyObject *value);
static int
-_ctypes_CFuncPtr_argtypes_set(PyCFuncPtrObject *self, PyObject *value, void *Py_UNUSED(context))
+_ctypes_CFuncPtr_argtypes_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ctypes_CFuncPtr_argtypes_set_impl(self, value);
+ return_value = _ctypes_CFuncPtr_argtypes_set_impl((PyCFuncPtrObject *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -762,12 +762,12 @@ static PyObject *
_ctypes_CFuncPtr_argtypes_get_impl(PyCFuncPtrObject *self);
static PyObject *
-_ctypes_CFuncPtr_argtypes_get(PyCFuncPtrObject *self, void *Py_UNUSED(context))
+_ctypes_CFuncPtr_argtypes_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ctypes_CFuncPtr_argtypes_get_impl(self);
+ return_value = _ctypes_CFuncPtr_argtypes_get_impl((PyCFuncPtrObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -793,4 +793,4 @@ Simple_from_outparm(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py
}
return Simple_from_outparm_impl(self, cls);
}
-/*[clinic end generated code: output=cb3583522a2c5ce5 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a18d87239b6fb8ca input=a9049054013a1b77]*/
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 368d10411366c4..cf8bd60f3e3f81 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -4947,7 +4947,7 @@ datetime.time.replace
minute: int(c_default="TIME_GET_MINUTE(self)") = unchanged
second: int(c_default="TIME_GET_SECOND(self)") = unchanged
microsecond: int(c_default="TIME_GET_MICROSECOND(self)") = unchanged
- tzinfo: object(c_default="HASTZINFO(self) ? self->tzinfo : Py_None") = unchanged
+ tzinfo: object(c_default="HASTZINFO(self) ? ((PyDateTime_Time *)self)->tzinfo : Py_None") = unchanged
*
fold: int(c_default="TIME_GET_FOLD(self)") = unchanged
@@ -4958,7 +4958,7 @@ static PyObject *
datetime_time_replace_impl(PyDateTime_Time *self, int hour, int minute,
int second, int microsecond, PyObject *tzinfo,
int fold)
-/*[clinic end generated code: output=0b89a44c299e4f80 input=9b6a35b1e704b0ca]*/
+/*[clinic end generated code: output=0b89a44c299e4f80 input=abf23656e8df4e97]*/
{
return new_time_subclass_fold_ex(hour, minute, second, microsecond, tzinfo,
fold, (PyObject *)Py_TYPE(self));
@@ -6449,7 +6449,7 @@ datetime.datetime.replace
minute: int(c_default="DATE_GET_MINUTE(self)") = unchanged
second: int(c_default="DATE_GET_SECOND(self)") = unchanged
microsecond: int(c_default="DATE_GET_MICROSECOND(self)") = unchanged
- tzinfo: object(c_default="HASTZINFO(self) ? self->tzinfo : Py_None") = unchanged
+ tzinfo: object(c_default="HASTZINFO(self) ? ((PyDateTime_DateTime *)self)->tzinfo : Py_None") = unchanged
*
fold: int(c_default="DATE_GET_FOLD(self)") = unchanged
@@ -6461,7 +6461,7 @@ datetime_datetime_replace_impl(PyDateTime_DateTime *self, int year,
int month, int day, int hour, int minute,
int second, int microsecond, PyObject *tzinfo,
int fold)
-/*[clinic end generated code: output=00bc96536833fddb input=9b38253d56d9bcad]*/
+/*[clinic end generated code: output=00bc96536833fddb input=fd972762d604d3e7]*/
{
return new_datetime_subclass_fold_ex(year, month, day, hour, minute,
second, microsecond, tzinfo, fold,
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index fb66d3db0f7a1f..16095333db6638 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -588,7 +588,7 @@ _io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer)
/*[clinic input]
_io.BytesIO.truncate
- size: Py_ssize_t(accept={int, NoneType}, c_default="self->pos") = None
+ size: Py_ssize_t(accept={int, NoneType}, c_default="((bytesio *)self)->pos") = None
/
Truncate the file to at most size bytes.
@@ -599,7 +599,7 @@ The current file position is unchanged. Returns the new size.
static PyObject *
_io_BytesIO_truncate_impl(bytesio *self, Py_ssize_t size)
-/*[clinic end generated code: output=9ad17650c15fa09b input=423759dd42d2f7c1]*/
+/*[clinic end generated code: output=9ad17650c15fa09b input=dae4295e11c1bbb4]*/
{
CHECK_CLOSED(self);
CHECK_EXPORTS(self);
diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h
index e035bd99baca5f..8ab8000fafee02 100644
--- a/Modules/_io/clinic/bufferedio.c.h
+++ b/Modules/_io/clinic/bufferedio.c.h
@@ -288,12 +288,12 @@ static PyObject *
_io__Buffered___sizeof___impl(buffered *self);
static PyObject *
-_io__Buffered___sizeof__(buffered *self, PyObject *Py_UNUSED(ignored))
+_io__Buffered___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered___sizeof___impl(self);
+ return_value = _io__Buffered___sizeof___impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -319,12 +319,12 @@ static PyObject *
_io__Buffered_simple_flush_impl(buffered *self);
static PyObject *
-_io__Buffered_simple_flush(buffered *self, PyObject *Py_UNUSED(ignored))
+_io__Buffered_simple_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_simple_flush_impl(self);
+ return_value = _io__Buffered_simple_flush_impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -344,12 +344,12 @@ static PyObject *
_io__Buffered_closed_get_impl(buffered *self);
static PyObject *
-_io__Buffered_closed_get(buffered *self, void *Py_UNUSED(context))
+_io__Buffered_closed_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_closed_get_impl(self);
+ return_value = _io__Buffered_closed_get_impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -367,12 +367,12 @@ static PyObject *
_io__Buffered_close_impl(buffered *self);
static PyObject *
-_io__Buffered_close(buffered *self, PyObject *Py_UNUSED(ignored))
+_io__Buffered_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_close_impl(self);
+ return_value = _io__Buffered_close_impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -390,12 +390,12 @@ static PyObject *
_io__Buffered_detach_impl(buffered *self);
static PyObject *
-_io__Buffered_detach(buffered *self, PyObject *Py_UNUSED(ignored))
+_io__Buffered_detach(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_detach_impl(self);
+ return_value = _io__Buffered_detach_impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -413,12 +413,12 @@ static PyObject *
_io__Buffered_seekable_impl(buffered *self);
static PyObject *
-_io__Buffered_seekable(buffered *self, PyObject *Py_UNUSED(ignored))
+_io__Buffered_seekable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_seekable_impl(self);
+ return_value = _io__Buffered_seekable_impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -436,12 +436,12 @@ static PyObject *
_io__Buffered_readable_impl(buffered *self);
static PyObject *
-_io__Buffered_readable(buffered *self, PyObject *Py_UNUSED(ignored))
+_io__Buffered_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_readable_impl(self);
+ return_value = _io__Buffered_readable_impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -459,12 +459,12 @@ static PyObject *
_io__Buffered_writable_impl(buffered *self);
static PyObject *
-_io__Buffered_writable(buffered *self, PyObject *Py_UNUSED(ignored))
+_io__Buffered_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_writable_impl(self);
+ return_value = _io__Buffered_writable_impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -484,12 +484,12 @@ static PyObject *
_io__Buffered_name_get_impl(buffered *self);
static PyObject *
-_io__Buffered_name_get(buffered *self, void *Py_UNUSED(context))
+_io__Buffered_name_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_name_get_impl(self);
+ return_value = _io__Buffered_name_get_impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -509,12 +509,12 @@ static PyObject *
_io__Buffered_mode_get_impl(buffered *self);
static PyObject *
-_io__Buffered_mode_get(buffered *self, void *Py_UNUSED(context))
+_io__Buffered_mode_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_mode_get_impl(self);
+ return_value = _io__Buffered_mode_get_impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -532,12 +532,12 @@ static PyObject *
_io__Buffered_fileno_impl(buffered *self);
static PyObject *
-_io__Buffered_fileno(buffered *self, PyObject *Py_UNUSED(ignored))
+_io__Buffered_fileno(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_fileno_impl(self);
+ return_value = _io__Buffered_fileno_impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -555,12 +555,12 @@ static PyObject *
_io__Buffered_isatty_impl(buffered *self);
static PyObject *
-_io__Buffered_isatty(buffered *self, PyObject *Py_UNUSED(ignored))
+_io__Buffered_isatty(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_isatty_impl(self);
+ return_value = _io__Buffered_isatty_impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -578,12 +578,12 @@ static PyObject *
_io__Buffered_flush_impl(buffered *self);
static PyObject *
-_io__Buffered_flush(buffered *self, PyObject *Py_UNUSED(ignored))
+_io__Buffered_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_flush_impl(self);
+ return_value = _io__Buffered_flush_impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -601,7 +601,7 @@ static PyObject *
_io__Buffered_peek_impl(buffered *self, Py_ssize_t size);
static PyObject *
-_io__Buffered_peek(buffered *self, PyObject *const *args, Py_ssize_t nargs)
+_io__Buffered_peek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t size = 0;
@@ -626,7 +626,7 @@ _io__Buffered_peek(buffered *self, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_peek_impl(self, size);
+ return_value = _io__Buffered_peek_impl((buffered *)self, size);
Py_END_CRITICAL_SECTION();
exit:
@@ -645,7 +645,7 @@ static PyObject *
_io__Buffered_read_impl(buffered *self, Py_ssize_t n);
static PyObject *
-_io__Buffered_read(buffered *self, PyObject *const *args, Py_ssize_t nargs)
+_io__Buffered_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t n = -1;
@@ -661,7 +661,7 @@ _io__Buffered_read(buffered *self, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_read_impl(self, n);
+ return_value = _io__Buffered_read_impl((buffered *)self, n);
Py_END_CRITICAL_SECTION();
exit:
@@ -680,7 +680,7 @@ static PyObject *
_io__Buffered_read1_impl(buffered *self, Py_ssize_t n);
static PyObject *
-_io__Buffered_read1(buffered *self, PyObject *const *args, Py_ssize_t nargs)
+_io__Buffered_read1(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t n = -1;
@@ -705,7 +705,7 @@ _io__Buffered_read1(buffered *self, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_read1_impl(self, n);
+ return_value = _io__Buffered_read1_impl((buffered *)self, n);
Py_END_CRITICAL_SECTION();
exit:
@@ -724,7 +724,7 @@ static PyObject *
_io__Buffered_readinto_impl(buffered *self, Py_buffer *buffer);
static PyObject *
-_io__Buffered_readinto(buffered *self, PyObject *arg)
+_io__Buffered_readinto(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer buffer = {NULL, NULL};
@@ -734,7 +734,7 @@ _io__Buffered_readinto(buffered *self, PyObject *arg)
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_readinto_impl(self, &buffer);
+ return_value = _io__Buffered_readinto_impl((buffered *)self, &buffer);
Py_END_CRITICAL_SECTION();
exit:
@@ -758,7 +758,7 @@ static PyObject *
_io__Buffered_readinto1_impl(buffered *self, Py_buffer *buffer);
static PyObject *
-_io__Buffered_readinto1(buffered *self, PyObject *arg)
+_io__Buffered_readinto1(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer buffer = {NULL, NULL};
@@ -768,7 +768,7 @@ _io__Buffered_readinto1(buffered *self, PyObject *arg)
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_readinto1_impl(self, &buffer);
+ return_value = _io__Buffered_readinto1_impl((buffered *)self, &buffer);
Py_END_CRITICAL_SECTION();
exit:
@@ -792,7 +792,7 @@ static PyObject *
_io__Buffered_readline_impl(buffered *self, Py_ssize_t size);
static PyObject *
-_io__Buffered_readline(buffered *self, PyObject *const *args, Py_ssize_t nargs)
+_io__Buffered_readline(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t size = -1;
@@ -808,7 +808,7 @@ _io__Buffered_readline(buffered *self, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_readline_impl(self, size);
+ return_value = _io__Buffered_readline_impl((buffered *)self, size);
Py_END_CRITICAL_SECTION();
exit:
@@ -827,12 +827,12 @@ static PyObject *
_io__Buffered_tell_impl(buffered *self);
static PyObject *
-_io__Buffered_tell(buffered *self, PyObject *Py_UNUSED(ignored))
+_io__Buffered_tell(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_tell_impl(self);
+ return_value = _io__Buffered_tell_impl((buffered *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -850,7 +850,7 @@ static PyObject *
_io__Buffered_seek_impl(buffered *self, PyObject *targetobj, int whence);
static PyObject *
-_io__Buffered_seek(buffered *self, PyObject *const *args, Py_ssize_t nargs)
+_io__Buffered_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *targetobj;
@@ -869,7 +869,7 @@ _io__Buffered_seek(buffered *self, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_seek_impl(self, targetobj, whence);
+ return_value = _io__Buffered_seek_impl((buffered *)self, targetobj, whence);
Py_END_CRITICAL_SECTION();
exit:
@@ -888,7 +888,7 @@ static PyObject *
_io__Buffered_truncate_impl(buffered *self, PyTypeObject *cls, PyObject *pos);
static PyObject *
-_io__Buffered_truncate(buffered *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_io__Buffered_truncate(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -918,7 +918,7 @@ _io__Buffered_truncate(buffered *self, PyTypeObject *cls, PyObject *const *args,
pos = args[0];
skip_optional_posonly:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io__Buffered_truncate_impl(self, cls, pos);
+ return_value = _io__Buffered_truncate_impl((buffered *)self, cls, pos);
Py_END_CRITICAL_SECTION();
exit:
@@ -1089,7 +1089,7 @@ static PyObject *
_io_BufferedWriter_write_impl(buffered *self, Py_buffer *buffer);
static PyObject *
-_io_BufferedWriter_write(buffered *self, PyObject *arg)
+_io_BufferedWriter_write(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer buffer = {NULL, NULL};
@@ -1098,7 +1098,7 @@ _io_BufferedWriter_write(buffered *self, PyObject *arg)
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_BufferedWriter_write_impl(self, &buffer);
+ return_value = _io_BufferedWriter_write_impl((buffered *)self, &buffer);
Py_END_CRITICAL_SECTION();
exit:
@@ -1246,4 +1246,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=8f28a97987a9fbe1 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=f019d29701ba2556 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h
index 98d88698c5e9b7..5528df952c33fb 100644
--- a/Modules/_io/clinic/bytesio.c.h
+++ b/Modules/_io/clinic/bytesio.c.h
@@ -22,9 +22,9 @@ static PyObject *
_io_BytesIO_readable_impl(bytesio *self);
static PyObject *
-_io_BytesIO_readable(bytesio *self, PyObject *Py_UNUSED(ignored))
+_io_BytesIO_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_BytesIO_readable_impl(self);
+ return _io_BytesIO_readable_impl((bytesio *)self);
}
PyDoc_STRVAR(_io_BytesIO_writable__doc__,
@@ -40,9 +40,9 @@ static PyObject *
_io_BytesIO_writable_impl(bytesio *self);
static PyObject *
-_io_BytesIO_writable(bytesio *self, PyObject *Py_UNUSED(ignored))
+_io_BytesIO_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_BytesIO_writable_impl(self);
+ return _io_BytesIO_writable_impl((bytesio *)self);
}
PyDoc_STRVAR(_io_BytesIO_seekable__doc__,
@@ -58,9 +58,9 @@ static PyObject *
_io_BytesIO_seekable_impl(bytesio *self);
static PyObject *
-_io_BytesIO_seekable(bytesio *self, PyObject *Py_UNUSED(ignored))
+_io_BytesIO_seekable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_BytesIO_seekable_impl(self);
+ return _io_BytesIO_seekable_impl((bytesio *)self);
}
PyDoc_STRVAR(_io_BytesIO_flush__doc__,
@@ -76,9 +76,9 @@ static PyObject *
_io_BytesIO_flush_impl(bytesio *self);
static PyObject *
-_io_BytesIO_flush(bytesio *self, PyObject *Py_UNUSED(ignored))
+_io_BytesIO_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_BytesIO_flush_impl(self);
+ return _io_BytesIO_flush_impl((bytesio *)self);
}
PyDoc_STRVAR(_io_BytesIO_getbuffer__doc__,
@@ -94,13 +94,13 @@ static PyObject *
_io_BytesIO_getbuffer_impl(bytesio *self, PyTypeObject *cls);
static PyObject *
-_io_BytesIO_getbuffer(bytesio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_io_BytesIO_getbuffer(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "getbuffer() takes no arguments");
return NULL;
}
- return _io_BytesIO_getbuffer_impl(self, cls);
+ return _io_BytesIO_getbuffer_impl((bytesio *)self, cls);
}
PyDoc_STRVAR(_io_BytesIO_getvalue__doc__,
@@ -116,9 +116,9 @@ static PyObject *
_io_BytesIO_getvalue_impl(bytesio *self);
static PyObject *
-_io_BytesIO_getvalue(bytesio *self, PyObject *Py_UNUSED(ignored))
+_io_BytesIO_getvalue(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_BytesIO_getvalue_impl(self);
+ return _io_BytesIO_getvalue_impl((bytesio *)self);
}
PyDoc_STRVAR(_io_BytesIO_isatty__doc__,
@@ -136,9 +136,9 @@ static PyObject *
_io_BytesIO_isatty_impl(bytesio *self);
static PyObject *
-_io_BytesIO_isatty(bytesio *self, PyObject *Py_UNUSED(ignored))
+_io_BytesIO_isatty(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_BytesIO_isatty_impl(self);
+ return _io_BytesIO_isatty_impl((bytesio *)self);
}
PyDoc_STRVAR(_io_BytesIO_tell__doc__,
@@ -154,9 +154,9 @@ static PyObject *
_io_BytesIO_tell_impl(bytesio *self);
static PyObject *
-_io_BytesIO_tell(bytesio *self, PyObject *Py_UNUSED(ignored))
+_io_BytesIO_tell(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_BytesIO_tell_impl(self);
+ return _io_BytesIO_tell_impl((bytesio *)self);
}
PyDoc_STRVAR(_io_BytesIO_read__doc__,
@@ -175,7 +175,7 @@ static PyObject *
_io_BytesIO_read_impl(bytesio *self, Py_ssize_t size);
static PyObject *
-_io_BytesIO_read(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_BytesIO_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t size = -1;
@@ -190,7 +190,7 @@ _io_BytesIO_read(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = _io_BytesIO_read_impl(self, size);
+ return_value = _io_BytesIO_read_impl((bytesio *)self, size);
exit:
return return_value;
@@ -212,7 +212,7 @@ static PyObject *
_io_BytesIO_read1_impl(bytesio *self, Py_ssize_t size);
static PyObject *
-_io_BytesIO_read1(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_BytesIO_read1(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t size = -1;
@@ -227,7 +227,7 @@ _io_BytesIO_read1(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = _io_BytesIO_read1_impl(self, size);
+ return_value = _io_BytesIO_read1_impl((bytesio *)self, size);
exit:
return return_value;
@@ -250,7 +250,7 @@ static PyObject *
_io_BytesIO_readline_impl(bytesio *self, Py_ssize_t size);
static PyObject *
-_io_BytesIO_readline(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_BytesIO_readline(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t size = -1;
@@ -265,7 +265,7 @@ _io_BytesIO_readline(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = _io_BytesIO_readline_impl(self, size);
+ return_value = _io_BytesIO_readline_impl((bytesio *)self, size);
exit:
return return_value;
@@ -288,7 +288,7 @@ static PyObject *
_io_BytesIO_readlines_impl(bytesio *self, PyObject *arg);
static PyObject *
-_io_BytesIO_readlines(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_BytesIO_readlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *arg = Py_None;
@@ -301,7 +301,7 @@ _io_BytesIO_readlines(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
}
arg = args[0];
skip_optional:
- return_value = _io_BytesIO_readlines_impl(self, arg);
+ return_value = _io_BytesIO_readlines_impl((bytesio *)self, arg);
exit:
return return_value;
@@ -323,7 +323,7 @@ static PyObject *
_io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer);
static PyObject *
-_io_BytesIO_readinto(bytesio *self, PyObject *arg)
+_io_BytesIO_readinto(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer buffer = {NULL, NULL};
@@ -332,7 +332,7 @@ _io_BytesIO_readinto(bytesio *self, PyObject *arg)
_PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
goto exit;
}
- return_value = _io_BytesIO_readinto_impl(self, &buffer);
+ return_value = _io_BytesIO_readinto_impl((bytesio *)self, &buffer);
exit:
/* Cleanup for buffer */
@@ -359,10 +359,10 @@ static PyObject *
_io_BytesIO_truncate_impl(bytesio *self, Py_ssize_t size);
static PyObject *
-_io_BytesIO_truncate(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_BytesIO_truncate(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
- Py_ssize_t size = self->pos;
+ Py_ssize_t size = ((bytesio *)self)->pos;
if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) {
goto exit;
@@ -374,7 +374,7 @@ _io_BytesIO_truncate(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = _io_BytesIO_truncate_impl(self, size);
+ return_value = _io_BytesIO_truncate_impl((bytesio *)self, size);
exit:
return return_value;
@@ -399,7 +399,7 @@ static PyObject *
_io_BytesIO_seek_impl(bytesio *self, Py_ssize_t pos, int whence);
static PyObject *
-_io_BytesIO_seek(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_BytesIO_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t pos;
@@ -428,7 +428,7 @@ _io_BytesIO_seek(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = _io_BytesIO_seek_impl(self, pos, whence);
+ return_value = _io_BytesIO_seek_impl((bytesio *)self, pos, whence);
exit:
return return_value;
@@ -471,9 +471,9 @@ static PyObject *
_io_BytesIO_close_impl(bytesio *self);
static PyObject *
-_io_BytesIO_close(bytesio *self, PyObject *Py_UNUSED(ignored))
+_io_BytesIO_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_BytesIO_close_impl(self);
+ return _io_BytesIO_close_impl((bytesio *)self);
}
PyDoc_STRVAR(_io_BytesIO___init____doc__,
@@ -535,4 +535,4 @@ _io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=985ff54e89f6036e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8a5e153bc7584b55 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h
index 0b8b4a49ac24b6..22d27bce67799e 100644
--- a/Modules/_io/clinic/fileio.c.h
+++ b/Modules/_io/clinic/fileio.c.h
@@ -25,13 +25,13 @@ static PyObject *
_io_FileIO_close_impl(fileio *self, PyTypeObject *cls);
static PyObject *
-_io_FileIO_close(fileio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_io_FileIO_close(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "close() takes no arguments");
return NULL;
}
- return _io_FileIO_close_impl(self, cls);
+ return _io_FileIO_close_impl((fileio *)self, cls);
}
PyDoc_STRVAR(_io_FileIO___init____doc__,
@@ -151,9 +151,9 @@ static PyObject *
_io_FileIO_fileno_impl(fileio *self);
static PyObject *
-_io_FileIO_fileno(fileio *self, PyObject *Py_UNUSED(ignored))
+_io_FileIO_fileno(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_FileIO_fileno_impl(self);
+ return _io_FileIO_fileno_impl((fileio *)self);
}
PyDoc_STRVAR(_io_FileIO_readable__doc__,
@@ -169,9 +169,9 @@ static PyObject *
_io_FileIO_readable_impl(fileio *self);
static PyObject *
-_io_FileIO_readable(fileio *self, PyObject *Py_UNUSED(ignored))
+_io_FileIO_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_FileIO_readable_impl(self);
+ return _io_FileIO_readable_impl((fileio *)self);
}
PyDoc_STRVAR(_io_FileIO_writable__doc__,
@@ -187,9 +187,9 @@ static PyObject *
_io_FileIO_writable_impl(fileio *self);
static PyObject *
-_io_FileIO_writable(fileio *self, PyObject *Py_UNUSED(ignored))
+_io_FileIO_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_FileIO_writable_impl(self);
+ return _io_FileIO_writable_impl((fileio *)self);
}
PyDoc_STRVAR(_io_FileIO_seekable__doc__,
@@ -205,9 +205,9 @@ static PyObject *
_io_FileIO_seekable_impl(fileio *self);
static PyObject *
-_io_FileIO_seekable(fileio *self, PyObject *Py_UNUSED(ignored))
+_io_FileIO_seekable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_FileIO_seekable_impl(self);
+ return _io_FileIO_seekable_impl((fileio *)self);
}
PyDoc_STRVAR(_io_FileIO_readinto__doc__,
@@ -223,7 +223,7 @@ static PyObject *
_io_FileIO_readinto_impl(fileio *self, PyTypeObject *cls, Py_buffer *buffer);
static PyObject *
-_io_FileIO_readinto(fileio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_io_FileIO_readinto(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -251,7 +251,7 @@ _io_FileIO_readinto(fileio *self, PyTypeObject *cls, PyObject *const *args, Py_s
_PyArg_BadArgument("readinto", "argument 1", "read-write bytes-like object", args[0]);
goto exit;
}
- return_value = _io_FileIO_readinto_impl(self, cls, &buffer);
+ return_value = _io_FileIO_readinto_impl((fileio *)self, cls, &buffer);
exit:
/* Cleanup for buffer */
@@ -278,9 +278,9 @@ static PyObject *
_io_FileIO_readall_impl(fileio *self);
static PyObject *
-_io_FileIO_readall(fileio *self, PyObject *Py_UNUSED(ignored))
+_io_FileIO_readall(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_FileIO_readall_impl(self);
+ return _io_FileIO_readall_impl((fileio *)self);
}
PyDoc_STRVAR(_io_FileIO_read__doc__,
@@ -300,7 +300,7 @@ static PyObject *
_io_FileIO_read_impl(fileio *self, PyTypeObject *cls, Py_ssize_t size);
static PyObject *
-_io_FileIO_read(fileio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_io_FileIO_read(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -331,7 +331,7 @@ _io_FileIO_read(fileio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize
goto exit;
}
skip_optional_posonly:
- return_value = _io_FileIO_read_impl(self, cls, size);
+ return_value = _io_FileIO_read_impl((fileio *)self, cls, size);
exit:
return return_value;
@@ -354,7 +354,7 @@ static PyObject *
_io_FileIO_write_impl(fileio *self, PyTypeObject *cls, Py_buffer *b);
static PyObject *
-_io_FileIO_write(fileio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_io_FileIO_write(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -381,7 +381,7 @@ _io_FileIO_write(fileio *self, PyTypeObject *cls, PyObject *const *args, Py_ssiz
if (PyObject_GetBuffer(args[0], &b, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = _io_FileIO_write_impl(self, cls, &b);
+ return_value = _io_FileIO_write_impl((fileio *)self, cls, &b);
exit:
/* Cleanup for b */
@@ -413,7 +413,7 @@ static PyObject *
_io_FileIO_seek_impl(fileio *self, PyObject *pos, int whence);
static PyObject *
-_io_FileIO_seek(fileio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_FileIO_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *pos;
@@ -431,7 +431,7 @@ _io_FileIO_seek(fileio *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = _io_FileIO_seek_impl(self, pos, whence);
+ return_value = _io_FileIO_seek_impl((fileio *)self, pos, whence);
exit:
return return_value;
@@ -452,9 +452,9 @@ static PyObject *
_io_FileIO_tell_impl(fileio *self);
static PyObject *
-_io_FileIO_tell(fileio *self, PyObject *Py_UNUSED(ignored))
+_io_FileIO_tell(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_FileIO_tell_impl(self);
+ return _io_FileIO_tell_impl((fileio *)self);
}
#if defined(HAVE_FTRUNCATE)
@@ -475,7 +475,7 @@ static PyObject *
_io_FileIO_truncate_impl(fileio *self, PyTypeObject *cls, PyObject *posobj);
static PyObject *
-_io_FileIO_truncate(fileio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_io_FileIO_truncate(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -504,7 +504,7 @@ _io_FileIO_truncate(fileio *self, PyTypeObject *cls, PyObject *const *args, Py_s
}
posobj = args[0];
skip_optional_posonly:
- return_value = _io_FileIO_truncate_impl(self, cls, posobj);
+ return_value = _io_FileIO_truncate_impl((fileio *)self, cls, posobj);
exit:
return return_value;
@@ -525,12 +525,12 @@ static PyObject *
_io_FileIO_isatty_impl(fileio *self);
static PyObject *
-_io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
+_io_FileIO_isatty(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_FileIO_isatty_impl(self);
+ return _io_FileIO_isatty_impl((fileio *)self);
}
#ifndef _IO_FILEIO_TRUNCATE_METHODDEF
#define _IO_FILEIO_TRUNCATE_METHODDEF
#endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
-/*[clinic end generated code: output=1c262ae135da4dcb input=a9049054013a1b77]*/
+/*[clinic end generated code: output=dcbeb6a0b13e4b1f input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h
index 6f9205af32f010..bc571698806bde 100644
--- a/Modules/_io/clinic/stringio.c.h
+++ b/Modules/_io/clinic/stringio.c.h
@@ -23,12 +23,12 @@ static PyObject *
_io_StringIO_getvalue_impl(stringio *self);
static PyObject *
-_io_StringIO_getvalue(stringio *self, PyObject *Py_UNUSED(ignored))
+_io_StringIO_getvalue(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_getvalue_impl(self);
+ return_value = _io_StringIO_getvalue_impl((stringio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -47,12 +47,12 @@ static PyObject *
_io_StringIO_tell_impl(stringio *self);
static PyObject *
-_io_StringIO_tell(stringio *self, PyObject *Py_UNUSED(ignored))
+_io_StringIO_tell(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_tell_impl(self);
+ return_value = _io_StringIO_tell_impl((stringio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -74,7 +74,7 @@ static PyObject *
_io_StringIO_read_impl(stringio *self, Py_ssize_t size);
static PyObject *
-_io_StringIO_read(stringio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_StringIO_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t size = -1;
@@ -90,7 +90,7 @@ _io_StringIO_read(stringio *self, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_read_impl(self, size);
+ return_value = _io_StringIO_read_impl((stringio *)self, size);
Py_END_CRITICAL_SECTION();
exit:
@@ -112,7 +112,7 @@ static PyObject *
_io_StringIO_readline_impl(stringio *self, Py_ssize_t size);
static PyObject *
-_io_StringIO_readline(stringio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_StringIO_readline(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t size = -1;
@@ -128,7 +128,7 @@ _io_StringIO_readline(stringio *self, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_readline_impl(self, size);
+ return_value = _io_StringIO_readline_impl((stringio *)self, size);
Py_END_CRITICAL_SECTION();
exit:
@@ -152,10 +152,10 @@ static PyObject *
_io_StringIO_truncate_impl(stringio *self, Py_ssize_t size);
static PyObject *
-_io_StringIO_truncate(stringio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_StringIO_truncate(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
- Py_ssize_t size = self->pos;
+ Py_ssize_t size = ((stringio *)self)->pos;
if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) {
goto exit;
@@ -168,7 +168,7 @@ _io_StringIO_truncate(stringio *self, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_truncate_impl(self, size);
+ return_value = _io_StringIO_truncate_impl((stringio *)self, size);
Py_END_CRITICAL_SECTION();
exit:
@@ -194,7 +194,7 @@ static PyObject *
_io_StringIO_seek_impl(stringio *self, Py_ssize_t pos, int whence);
static PyObject *
-_io_StringIO_seek(stringio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_StringIO_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t pos;
@@ -224,7 +224,7 @@ _io_StringIO_seek(stringio *self, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_seek_impl(self, pos, whence);
+ return_value = _io_StringIO_seek_impl((stringio *)self, pos, whence);
Py_END_CRITICAL_SECTION();
exit:
@@ -252,7 +252,7 @@ _io_StringIO_write(stringio *self, PyObject *obj)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_write_impl(self, obj);
+ return_value = _io_StringIO_write_impl((stringio *)self, obj);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -276,12 +276,12 @@ static PyObject *
_io_StringIO_close_impl(stringio *self);
static PyObject *
-_io_StringIO_close(stringio *self, PyObject *Py_UNUSED(ignored))
+_io_StringIO_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_close_impl(self);
+ return_value = _io_StringIO_close_impl((stringio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -371,12 +371,12 @@ static PyObject *
_io_StringIO_readable_impl(stringio *self);
static PyObject *
-_io_StringIO_readable(stringio *self, PyObject *Py_UNUSED(ignored))
+_io_StringIO_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_readable_impl(self);
+ return_value = _io_StringIO_readable_impl((stringio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -395,12 +395,12 @@ static PyObject *
_io_StringIO_writable_impl(stringio *self);
static PyObject *
-_io_StringIO_writable(stringio *self, PyObject *Py_UNUSED(ignored))
+_io_StringIO_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_writable_impl(self);
+ return_value = _io_StringIO_writable_impl((stringio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -419,12 +419,12 @@ static PyObject *
_io_StringIO_seekable_impl(stringio *self);
static PyObject *
-_io_StringIO_seekable(stringio *self, PyObject *Py_UNUSED(ignored))
+_io_StringIO_seekable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_seekable_impl(self);
+ return_value = _io_StringIO_seekable_impl((stringio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -442,12 +442,12 @@ static PyObject *
_io_StringIO___getstate___impl(stringio *self);
static PyObject *
-_io_StringIO___getstate__(stringio *self, PyObject *Py_UNUSED(ignored))
+_io_StringIO___getstate__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO___getstate___impl(self);
+ return_value = _io_StringIO___getstate___impl((stringio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -470,7 +470,7 @@ _io_StringIO___setstate__(stringio *self, PyObject *state)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO___setstate___impl(self, state);
+ return_value = _io_StringIO___setstate___impl((stringio *)self, state);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -490,12 +490,12 @@ static PyObject *
_io_StringIO_closed_get_impl(stringio *self);
static PyObject *
-_io_StringIO_closed_get(stringio *self, void *Py_UNUSED(context))
+_io_StringIO_closed_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_closed_get_impl(self);
+ return_value = _io_StringIO_closed_get_impl((stringio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -515,12 +515,12 @@ static PyObject *
_io_StringIO_line_buffering_get_impl(stringio *self);
static PyObject *
-_io_StringIO_line_buffering_get(stringio *self, void *Py_UNUSED(context))
+_io_StringIO_line_buffering_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_line_buffering_get_impl(self);
+ return_value = _io_StringIO_line_buffering_get_impl((stringio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -540,14 +540,14 @@ static PyObject *
_io_StringIO_newlines_get_impl(stringio *self);
static PyObject *
-_io_StringIO_newlines_get(stringio *self, void *Py_UNUSED(context))
+_io_StringIO_newlines_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_StringIO_newlines_get_impl(self);
+ return_value = _io_StringIO_newlines_get_impl((stringio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
}
-/*[clinic end generated code: output=9d2b092274469d42 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=7796e223e778a214 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h
index 0acc1f060c811b..9ce1d70ad71052 100644
--- a/Modules/_io/clinic/textio.c.h
+++ b/Modules/_io/clinic/textio.c.h
@@ -379,7 +379,7 @@ _io_IncrementalNewlineDecoder_decode_impl(nldecoder_object *self,
PyObject *input, int final);
static PyObject *
-_io_IncrementalNewlineDecoder_decode(nldecoder_object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_io_IncrementalNewlineDecoder_decode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -426,7 +426,7 @@ _io_IncrementalNewlineDecoder_decode(nldecoder_object *self, PyObject *const *ar
goto exit;
}
skip_optional_pos:
- return_value = _io_IncrementalNewlineDecoder_decode_impl(self, input, final);
+ return_value = _io_IncrementalNewlineDecoder_decode_impl((nldecoder_object *)self, input, final);
exit:
return return_value;
@@ -444,9 +444,9 @@ static PyObject *
_io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self);
static PyObject *
-_io_IncrementalNewlineDecoder_getstate(nldecoder_object *self, PyObject *Py_UNUSED(ignored))
+_io_IncrementalNewlineDecoder_getstate(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_IncrementalNewlineDecoder_getstate_impl(self);
+ return _io_IncrementalNewlineDecoder_getstate_impl((nldecoder_object *)self);
}
PyDoc_STRVAR(_io_IncrementalNewlineDecoder_setstate__doc__,
@@ -469,9 +469,9 @@ static PyObject *
_io_IncrementalNewlineDecoder_reset_impl(nldecoder_object *self);
static PyObject *
-_io_IncrementalNewlineDecoder_reset(nldecoder_object *self, PyObject *Py_UNUSED(ignored))
+_io_IncrementalNewlineDecoder_reset(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io_IncrementalNewlineDecoder_reset_impl(self);
+ return _io_IncrementalNewlineDecoder_reset_impl((nldecoder_object *)self);
}
PyDoc_STRVAR(_io_TextIOWrapper___init____doc__,
@@ -654,7 +654,7 @@ _io_TextIOWrapper_reconfigure_impl(textio *self, PyObject *encoding,
PyObject *write_through_obj);
static PyObject *
-_io_TextIOWrapper_reconfigure(textio *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_io_TextIOWrapper_reconfigure(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -725,7 +725,7 @@ _io_TextIOWrapper_reconfigure(textio *self, PyObject *const *args, Py_ssize_t na
write_through_obj = args[4];
skip_optional_kwonly:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_reconfigure_impl(self, encoding, errors, newline_obj, line_buffering_obj, write_through_obj);
+ return_value = _io_TextIOWrapper_reconfigure_impl((textio *)self, encoding, errors, newline_obj, line_buffering_obj, write_through_obj);
Py_END_CRITICAL_SECTION();
exit:
@@ -744,12 +744,12 @@ static PyObject *
_io_TextIOWrapper_detach_impl(textio *self);
static PyObject *
-_io_TextIOWrapper_detach(textio *self, PyObject *Py_UNUSED(ignored))
+_io_TextIOWrapper_detach(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_detach_impl(self);
+ return_value = _io_TextIOWrapper_detach_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -767,7 +767,7 @@ static PyObject *
_io_TextIOWrapper_write_impl(textio *self, PyObject *text);
static PyObject *
-_io_TextIOWrapper_write(textio *self, PyObject *arg)
+_io_TextIOWrapper_write(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
PyObject *text;
@@ -778,7 +778,7 @@ _io_TextIOWrapper_write(textio *self, PyObject *arg)
}
text = arg;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_write_impl(self, text);
+ return_value = _io_TextIOWrapper_write_impl((textio *)self, text);
Py_END_CRITICAL_SECTION();
exit:
@@ -797,7 +797,7 @@ static PyObject *
_io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n);
static PyObject *
-_io_TextIOWrapper_read(textio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_TextIOWrapper_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t n = -1;
@@ -813,7 +813,7 @@ _io_TextIOWrapper_read(textio *self, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_read_impl(self, n);
+ return_value = _io_TextIOWrapper_read_impl((textio *)self, n);
Py_END_CRITICAL_SECTION();
exit:
@@ -832,7 +832,7 @@ static PyObject *
_io_TextIOWrapper_readline_impl(textio *self, Py_ssize_t size);
static PyObject *
-_io_TextIOWrapper_readline(textio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_TextIOWrapper_readline(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t size = -1;
@@ -857,7 +857,7 @@ _io_TextIOWrapper_readline(textio *self, PyObject *const *args, Py_ssize_t nargs
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_readline_impl(self, size);
+ return_value = _io_TextIOWrapper_readline_impl((textio *)self, size);
Py_END_CRITICAL_SECTION();
exit:
@@ -894,7 +894,7 @@ static PyObject *
_io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence);
static PyObject *
-_io_TextIOWrapper_seek(textio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_TextIOWrapper_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *cookieObj;
@@ -913,7 +913,7 @@ _io_TextIOWrapper_seek(textio *self, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_seek_impl(self, cookieObj, whence);
+ return_value = _io_TextIOWrapper_seek_impl((textio *)self, cookieObj, whence);
Py_END_CRITICAL_SECTION();
exit:
@@ -936,12 +936,12 @@ static PyObject *
_io_TextIOWrapper_tell_impl(textio *self);
static PyObject *
-_io_TextIOWrapper_tell(textio *self, PyObject *Py_UNUSED(ignored))
+_io_TextIOWrapper_tell(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_tell_impl(self);
+ return_value = _io_TextIOWrapper_tell_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -959,7 +959,7 @@ static PyObject *
_io_TextIOWrapper_truncate_impl(textio *self, PyObject *pos);
static PyObject *
-_io_TextIOWrapper_truncate(textio *self, PyObject *const *args, Py_ssize_t nargs)
+_io_TextIOWrapper_truncate(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *pos = Py_None;
@@ -973,7 +973,7 @@ _io_TextIOWrapper_truncate(textio *self, PyObject *const *args, Py_ssize_t nargs
pos = args[0];
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_truncate_impl(self, pos);
+ return_value = _io_TextIOWrapper_truncate_impl((textio *)self, pos);
Py_END_CRITICAL_SECTION();
exit:
@@ -992,12 +992,12 @@ static PyObject *
_io_TextIOWrapper_fileno_impl(textio *self);
static PyObject *
-_io_TextIOWrapper_fileno(textio *self, PyObject *Py_UNUSED(ignored))
+_io_TextIOWrapper_fileno(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_fileno_impl(self);
+ return_value = _io_TextIOWrapper_fileno_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1015,12 +1015,12 @@ static PyObject *
_io_TextIOWrapper_seekable_impl(textio *self);
static PyObject *
-_io_TextIOWrapper_seekable(textio *self, PyObject *Py_UNUSED(ignored))
+_io_TextIOWrapper_seekable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_seekable_impl(self);
+ return_value = _io_TextIOWrapper_seekable_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1038,12 +1038,12 @@ static PyObject *
_io_TextIOWrapper_readable_impl(textio *self);
static PyObject *
-_io_TextIOWrapper_readable(textio *self, PyObject *Py_UNUSED(ignored))
+_io_TextIOWrapper_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_readable_impl(self);
+ return_value = _io_TextIOWrapper_readable_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1061,12 +1061,12 @@ static PyObject *
_io_TextIOWrapper_writable_impl(textio *self);
static PyObject *
-_io_TextIOWrapper_writable(textio *self, PyObject *Py_UNUSED(ignored))
+_io_TextIOWrapper_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_writable_impl(self);
+ return_value = _io_TextIOWrapper_writable_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1084,12 +1084,12 @@ static PyObject *
_io_TextIOWrapper_isatty_impl(textio *self);
static PyObject *
-_io_TextIOWrapper_isatty(textio *self, PyObject *Py_UNUSED(ignored))
+_io_TextIOWrapper_isatty(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_isatty_impl(self);
+ return_value = _io_TextIOWrapper_isatty_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1107,12 +1107,12 @@ static PyObject *
_io_TextIOWrapper_flush_impl(textio *self);
static PyObject *
-_io_TextIOWrapper_flush(textio *self, PyObject *Py_UNUSED(ignored))
+_io_TextIOWrapper_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_flush_impl(self);
+ return_value = _io_TextIOWrapper_flush_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1130,12 +1130,12 @@ static PyObject *
_io_TextIOWrapper_close_impl(textio *self);
static PyObject *
-_io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored))
+_io_TextIOWrapper_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_close_impl(self);
+ return_value = _io_TextIOWrapper_close_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1155,12 +1155,12 @@ static PyObject *
_io_TextIOWrapper_name_get_impl(textio *self);
static PyObject *
-_io_TextIOWrapper_name_get(textio *self, void *Py_UNUSED(context))
+_io_TextIOWrapper_name_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_name_get_impl(self);
+ return_value = _io_TextIOWrapper_name_get_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1180,12 +1180,12 @@ static PyObject *
_io_TextIOWrapper_closed_get_impl(textio *self);
static PyObject *
-_io_TextIOWrapper_closed_get(textio *self, void *Py_UNUSED(context))
+_io_TextIOWrapper_closed_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_closed_get_impl(self);
+ return_value = _io_TextIOWrapper_closed_get_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1205,12 +1205,12 @@ static PyObject *
_io_TextIOWrapper_newlines_get_impl(textio *self);
static PyObject *
-_io_TextIOWrapper_newlines_get(textio *self, void *Py_UNUSED(context))
+_io_TextIOWrapper_newlines_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_newlines_get_impl(self);
+ return_value = _io_TextIOWrapper_newlines_get_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1230,12 +1230,12 @@ static PyObject *
_io_TextIOWrapper_errors_get_impl(textio *self);
static PyObject *
-_io_TextIOWrapper_errors_get(textio *self, void *Py_UNUSED(context))
+_io_TextIOWrapper_errors_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper_errors_get_impl(self);
+ return_value = _io_TextIOWrapper_errors_get_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1255,12 +1255,12 @@ static PyObject *
_io_TextIOWrapper__CHUNK_SIZE_get_impl(textio *self);
static PyObject *
-_io_TextIOWrapper__CHUNK_SIZE_get(textio *self, void *Py_UNUSED(context))
+_io_TextIOWrapper__CHUNK_SIZE_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper__CHUNK_SIZE_get_impl(self);
+ return_value = _io_TextIOWrapper__CHUNK_SIZE_get_impl((textio *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1280,14 +1280,14 @@ static int
_io_TextIOWrapper__CHUNK_SIZE_set_impl(textio *self, PyObject *value);
static int
-_io_TextIOWrapper__CHUNK_SIZE_set(textio *self, PyObject *value, void *Py_UNUSED(context))
+_io_TextIOWrapper__CHUNK_SIZE_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _io_TextIOWrapper__CHUNK_SIZE_set_impl(self, value);
+ return_value = _io_TextIOWrapper__CHUNK_SIZE_set_impl((textio *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
}
-/*[clinic end generated code: output=423a320f087792b9 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6e64e43113a97340 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/winconsoleio.c.h b/Modules/_io/clinic/winconsoleio.c.h
index df281dfeb13fef..ba6dcde6e01064 100644
--- a/Modules/_io/clinic/winconsoleio.c.h
+++ b/Modules/_io/clinic/winconsoleio.c.h
@@ -27,13 +27,13 @@ static PyObject *
_io__WindowsConsoleIO_close_impl(winconsoleio *self, PyTypeObject *cls);
static PyObject *
-_io__WindowsConsoleIO_close(winconsoleio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_io__WindowsConsoleIO_close(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "close() takes no arguments");
return NULL;
}
- return _io__WindowsConsoleIO_close_impl(self, cls);
+ return _io__WindowsConsoleIO_close_impl((winconsoleio *)self, cls);
}
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
@@ -154,9 +154,9 @@ static PyObject *
_io__WindowsConsoleIO_fileno_impl(winconsoleio *self);
static PyObject *
-_io__WindowsConsoleIO_fileno(winconsoleio *self, PyObject *Py_UNUSED(ignored))
+_io__WindowsConsoleIO_fileno(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io__WindowsConsoleIO_fileno_impl(self);
+ return _io__WindowsConsoleIO_fileno_impl((winconsoleio *)self);
}
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
@@ -176,9 +176,9 @@ static PyObject *
_io__WindowsConsoleIO_readable_impl(winconsoleio *self);
static PyObject *
-_io__WindowsConsoleIO_readable(winconsoleio *self, PyObject *Py_UNUSED(ignored))
+_io__WindowsConsoleIO_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io__WindowsConsoleIO_readable_impl(self);
+ return _io__WindowsConsoleIO_readable_impl((winconsoleio *)self);
}
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
@@ -198,9 +198,9 @@ static PyObject *
_io__WindowsConsoleIO_writable_impl(winconsoleio *self);
static PyObject *
-_io__WindowsConsoleIO_writable(winconsoleio *self, PyObject *Py_UNUSED(ignored))
+_io__WindowsConsoleIO_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io__WindowsConsoleIO_writable_impl(self);
+ return _io__WindowsConsoleIO_writable_impl((winconsoleio *)self);
}
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
@@ -221,7 +221,7 @@ _io__WindowsConsoleIO_readinto_impl(winconsoleio *self, PyTypeObject *cls,
Py_buffer *buffer);
static PyObject *
-_io__WindowsConsoleIO_readinto(winconsoleio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_io__WindowsConsoleIO_readinto(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -249,7 +249,7 @@ _io__WindowsConsoleIO_readinto(winconsoleio *self, PyTypeObject *cls, PyObject *
_PyArg_BadArgument("readinto", "argument 1", "read-write bytes-like object", args[0]);
goto exit;
}
- return_value = _io__WindowsConsoleIO_readinto_impl(self, cls, &buffer);
+ return_value = _io__WindowsConsoleIO_readinto_impl((winconsoleio *)self, cls, &buffer);
exit:
/* Cleanup for buffer */
@@ -279,9 +279,9 @@ static PyObject *
_io__WindowsConsoleIO_readall_impl(winconsoleio *self);
static PyObject *
-_io__WindowsConsoleIO_readall(winconsoleio *self, PyObject *Py_UNUSED(ignored))
+_io__WindowsConsoleIO_readall(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io__WindowsConsoleIO_readall_impl(self);
+ return _io__WindowsConsoleIO_readall_impl((winconsoleio *)self);
}
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
@@ -306,7 +306,7 @@ _io__WindowsConsoleIO_read_impl(winconsoleio *self, PyTypeObject *cls,
Py_ssize_t size);
static PyObject *
-_io__WindowsConsoleIO_read(winconsoleio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_io__WindowsConsoleIO_read(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -337,7 +337,7 @@ _io__WindowsConsoleIO_read(winconsoleio *self, PyTypeObject *cls, PyObject *cons
goto exit;
}
skip_optional_posonly:
- return_value = _io__WindowsConsoleIO_read_impl(self, cls, size);
+ return_value = _io__WindowsConsoleIO_read_impl((winconsoleio *)self, cls, size);
exit:
return return_value;
@@ -364,7 +364,7 @@ _io__WindowsConsoleIO_write_impl(winconsoleio *self, PyTypeObject *cls,
Py_buffer *b);
static PyObject *
-_io__WindowsConsoleIO_write(winconsoleio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_io__WindowsConsoleIO_write(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -391,7 +391,7 @@ _io__WindowsConsoleIO_write(winconsoleio *self, PyTypeObject *cls, PyObject *con
if (PyObject_GetBuffer(args[0], &b, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = _io__WindowsConsoleIO_write_impl(self, cls, &b);
+ return_value = _io__WindowsConsoleIO_write_impl((winconsoleio *)self, cls, &b);
exit:
/* Cleanup for b */
@@ -419,9 +419,9 @@ static PyObject *
_io__WindowsConsoleIO_isatty_impl(winconsoleio *self);
static PyObject *
-_io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored))
+_io__WindowsConsoleIO_isatty(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _io__WindowsConsoleIO_isatty_impl(self);
+ return _io__WindowsConsoleIO_isatty_impl((winconsoleio *)self);
}
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
@@ -461,4 +461,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=78e0f6abf4de2d6d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=edc47f5c49589045 input=a9049054013a1b77]*/
diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c
index 65e8d97aa8ac19..687f584ee6caff 100644
--- a/Modules/_io/stringio.c
+++ b/Modules/_io/stringio.c
@@ -437,7 +437,7 @@ stringio_iternext(stringio *self)
/*[clinic input]
@critical_section
_io.StringIO.truncate
- pos as size: Py_ssize_t(accept={int, NoneType}, c_default="self->pos") = None
+ pos as size: Py_ssize_t(accept={int, NoneType}, c_default="((stringio *)self)->pos") = None
/
Truncate size to pos.
@@ -449,7 +449,7 @@ Returns the new absolute position.
static PyObject *
_io_StringIO_truncate_impl(stringio *self, Py_ssize_t size)
-/*[clinic end generated code: output=eb3aef8e06701365 input=461b872dce238452]*/
+/*[clinic end generated code: output=eb3aef8e06701365 input=fa8a6c98bb2ba780]*/
{
CHECK_INITIALIZED(self);
CHECK_CLOSED(self);
diff --git a/Modules/_multiprocessing/clinic/semaphore.c.h b/Modules/_multiprocessing/clinic/semaphore.c.h
index 2702c3369c76ed..e789137ec1e013 100644
--- a/Modules/_multiprocessing/clinic/semaphore.c.h
+++ b/Modules/_multiprocessing/clinic/semaphore.c.h
@@ -25,7 +25,7 @@ _multiprocessing_SemLock_acquire_impl(SemLockObject *self, int blocking,
PyObject *timeout_obj);
static PyObject *
-_multiprocessing_SemLock_acquire(SemLockObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_multiprocessing_SemLock_acquire(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -78,7 +78,7 @@ _multiprocessing_SemLock_acquire(SemLockObject *self, PyObject *const *args, Py_
timeout_obj = args[1];
skip_optional_pos:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _multiprocessing_SemLock_acquire_impl(self, blocking, timeout_obj);
+ return_value = _multiprocessing_SemLock_acquire_impl((SemLockObject *)self, blocking, timeout_obj);
Py_END_CRITICAL_SECTION();
exit:
@@ -102,12 +102,12 @@ static PyObject *
_multiprocessing_SemLock_release_impl(SemLockObject *self);
static PyObject *
-_multiprocessing_SemLock_release(SemLockObject *self, PyObject *Py_UNUSED(ignored))
+_multiprocessing_SemLock_release(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _multiprocessing_SemLock_release_impl(self);
+ return_value = _multiprocessing_SemLock_release_impl((SemLockObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -131,7 +131,7 @@ _multiprocessing_SemLock_acquire_impl(SemLockObject *self, int blocking,
PyObject *timeout_obj);
static PyObject *
-_multiprocessing_SemLock_acquire(SemLockObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_multiprocessing_SemLock_acquire(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -184,7 +184,7 @@ _multiprocessing_SemLock_acquire(SemLockObject *self, PyObject *const *args, Py_
timeout_obj = args[1];
skip_optional_pos:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _multiprocessing_SemLock_acquire_impl(self, blocking, timeout_obj);
+ return_value = _multiprocessing_SemLock_acquire_impl((SemLockObject *)self, blocking, timeout_obj);
Py_END_CRITICAL_SECTION();
exit:
@@ -208,12 +208,12 @@ static PyObject *
_multiprocessing_SemLock_release_impl(SemLockObject *self);
static PyObject *
-_multiprocessing_SemLock_release(SemLockObject *self, PyObject *Py_UNUSED(ignored))
+_multiprocessing_SemLock_release(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _multiprocessing_SemLock_release_impl(self);
+ return_value = _multiprocessing_SemLock_release_impl((SemLockObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -358,12 +358,12 @@ static PyObject *
_multiprocessing_SemLock__count_impl(SemLockObject *self);
static PyObject *
-_multiprocessing_SemLock__count(SemLockObject *self, PyObject *Py_UNUSED(ignored))
+_multiprocessing_SemLock__count(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _multiprocessing_SemLock__count_impl(self);
+ return_value = _multiprocessing_SemLock__count_impl((SemLockObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -386,9 +386,9 @@ static PyObject *
_multiprocessing_SemLock__is_mine_impl(SemLockObject *self);
static PyObject *
-_multiprocessing_SemLock__is_mine(SemLockObject *self, PyObject *Py_UNUSED(ignored))
+_multiprocessing_SemLock__is_mine(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _multiprocessing_SemLock__is_mine_impl(self);
+ return _multiprocessing_SemLock__is_mine_impl((SemLockObject *)self);
}
#endif /* defined(HAVE_MP_SEMAPHORE) */
@@ -408,9 +408,9 @@ static PyObject *
_multiprocessing_SemLock__get_value_impl(SemLockObject *self);
static PyObject *
-_multiprocessing_SemLock__get_value(SemLockObject *self, PyObject *Py_UNUSED(ignored))
+_multiprocessing_SemLock__get_value(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _multiprocessing_SemLock__get_value_impl(self);
+ return _multiprocessing_SemLock__get_value_impl((SemLockObject *)self);
}
#endif /* defined(HAVE_MP_SEMAPHORE) */
@@ -430,9 +430,9 @@ static PyObject *
_multiprocessing_SemLock__is_zero_impl(SemLockObject *self);
static PyObject *
-_multiprocessing_SemLock__is_zero(SemLockObject *self, PyObject *Py_UNUSED(ignored))
+_multiprocessing_SemLock__is_zero(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _multiprocessing_SemLock__is_zero_impl(self);
+ return _multiprocessing_SemLock__is_zero_impl((SemLockObject *)self);
}
#endif /* defined(HAVE_MP_SEMAPHORE) */
@@ -452,9 +452,9 @@ static PyObject *
_multiprocessing_SemLock__after_fork_impl(SemLockObject *self);
static PyObject *
-_multiprocessing_SemLock__after_fork(SemLockObject *self, PyObject *Py_UNUSED(ignored))
+_multiprocessing_SemLock__after_fork(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _multiprocessing_SemLock__after_fork_impl(self);
+ return _multiprocessing_SemLock__after_fork_impl((SemLockObject *)self);
}
#endif /* defined(HAVE_MP_SEMAPHORE) */
@@ -474,12 +474,12 @@ static PyObject *
_multiprocessing_SemLock___enter___impl(SemLockObject *self);
static PyObject *
-_multiprocessing_SemLock___enter__(SemLockObject *self, PyObject *Py_UNUSED(ignored))
+_multiprocessing_SemLock___enter__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _multiprocessing_SemLock___enter___impl(self);
+ return_value = _multiprocessing_SemLock___enter___impl((SemLockObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -504,7 +504,7 @@ _multiprocessing_SemLock___exit___impl(SemLockObject *self,
PyObject *exc_value, PyObject *exc_tb);
static PyObject *
-_multiprocessing_SemLock___exit__(SemLockObject *self, PyObject *const *args, Py_ssize_t nargs)
+_multiprocessing_SemLock___exit__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *exc_type = Py_None;
@@ -528,7 +528,7 @@ _multiprocessing_SemLock___exit__(SemLockObject *self, PyObject *const *args, Py
exc_tb = args[2];
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _multiprocessing_SemLock___exit___impl(self, exc_type, exc_value, exc_tb);
+ return_value = _multiprocessing_SemLock___exit___impl((SemLockObject *)self, exc_type, exc_value, exc_tb);
Py_END_CRITICAL_SECTION();
exit:
@@ -576,4 +576,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=9023d3e48a24afd2 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=e28d0fdbfefd1235 input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/blob.c.h b/Modules/_sqlite/clinic/blob.c.h
index b95ba948aaf97f..921e7cbd7ffcab 100644
--- a/Modules/_sqlite/clinic/blob.c.h
+++ b/Modules/_sqlite/clinic/blob.c.h
@@ -17,9 +17,9 @@ static PyObject *
blob_close_impl(pysqlite_Blob *self);
static PyObject *
-blob_close(pysqlite_Blob *self, PyObject *Py_UNUSED(ignored))
+blob_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return blob_close_impl(self);
+ return blob_close_impl((pysqlite_Blob *)self);
}
PyDoc_STRVAR(blob_read__doc__,
@@ -42,7 +42,7 @@ static PyObject *
blob_read_impl(pysqlite_Blob *self, int length);
static PyObject *
-blob_read(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
+blob_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int length = -1;
@@ -58,7 +58,7 @@ blob_read(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = blob_read_impl(self, length);
+ return_value = blob_read_impl((pysqlite_Blob *)self, length);
exit:
return return_value;
@@ -80,7 +80,7 @@ static PyObject *
blob_write_impl(pysqlite_Blob *self, Py_buffer *data);
static PyObject *
-blob_write(pysqlite_Blob *self, PyObject *arg)
+blob_write(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer data = {NULL, NULL};
@@ -88,7 +88,7 @@ blob_write(pysqlite_Blob *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = blob_write_impl(self, &data);
+ return_value = blob_write_impl((pysqlite_Blob *)self, &data);
exit:
/* Cleanup for data */
@@ -116,7 +116,7 @@ static PyObject *
blob_seek_impl(pysqlite_Blob *self, int offset, int origin);
static PyObject *
-blob_seek(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
+blob_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int offset;
@@ -137,7 +137,7 @@ blob_seek(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = blob_seek_impl(self, offset, origin);
+ return_value = blob_seek_impl((pysqlite_Blob *)self, offset, origin);
exit:
return return_value;
@@ -156,9 +156,9 @@ static PyObject *
blob_tell_impl(pysqlite_Blob *self);
static PyObject *
-blob_tell(pysqlite_Blob *self, PyObject *Py_UNUSED(ignored))
+blob_tell(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return blob_tell_impl(self);
+ return blob_tell_impl((pysqlite_Blob *)self);
}
PyDoc_STRVAR(blob_enter__doc__,
@@ -174,9 +174,9 @@ static PyObject *
blob_enter_impl(pysqlite_Blob *self);
static PyObject *
-blob_enter(pysqlite_Blob *self, PyObject *Py_UNUSED(ignored))
+blob_enter(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return blob_enter_impl(self);
+ return blob_enter_impl((pysqlite_Blob *)self);
}
PyDoc_STRVAR(blob_exit__doc__,
@@ -193,7 +193,7 @@ blob_exit_impl(pysqlite_Blob *self, PyObject *type, PyObject *val,
PyObject *tb);
static PyObject *
-blob_exit(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
+blob_exit(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *type;
@@ -206,9 +206,9 @@ blob_exit(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
type = args[0];
val = args[1];
tb = args[2];
- return_value = blob_exit_impl(self, type, val, tb);
+ return_value = blob_exit_impl((pysqlite_Blob *)self, type, val, tb);
exit:
return return_value;
}
-/*[clinic end generated code: output=31abd55660e0c5af input=a9049054013a1b77]*/
+/*[clinic end generated code: output=f03f4ba622b67ae0 input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/connection.c.h b/Modules/_sqlite/clinic/connection.c.h
index 42eb6eb2f12554..82fba44eb1b074 100644
--- a/Modules/_sqlite/clinic/connection.c.h
+++ b/Modules/_sqlite/clinic/connection.c.h
@@ -182,7 +182,7 @@ static PyObject *
pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory);
static PyObject *
-pysqlite_connection_cursor(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pysqlite_connection_cursor(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -224,7 +224,7 @@ pysqlite_connection_cursor(pysqlite_Connection *self, PyObject *const *args, Py_
}
factory = args[0];
skip_optional_pos:
- return_value = pysqlite_connection_cursor_impl(self, factory);
+ return_value = pysqlite_connection_cursor_impl((pysqlite_Connection *)self, factory);
exit:
return return_value;
@@ -255,7 +255,7 @@ blobopen_impl(pysqlite_Connection *self, const char *table, const char *col,
sqlite3_int64 row, int readonly, const char *name);
static PyObject *
-blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+blobopen(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -351,7 +351,7 @@ blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyO
goto exit;
}
skip_optional_kwonly:
- return_value = blobopen_impl(self, table, col, row, readonly, name);
+ return_value = blobopen_impl((pysqlite_Connection *)self, table, col, row, readonly, name);
exit:
return return_value;
@@ -372,9 +372,9 @@ static PyObject *
pysqlite_connection_close_impl(pysqlite_Connection *self);
static PyObject *
-pysqlite_connection_close(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
+pysqlite_connection_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return pysqlite_connection_close_impl(self);
+ return pysqlite_connection_close_impl((pysqlite_Connection *)self);
}
PyDoc_STRVAR(pysqlite_connection_commit__doc__,
@@ -392,9 +392,9 @@ static PyObject *
pysqlite_connection_commit_impl(pysqlite_Connection *self);
static PyObject *
-pysqlite_connection_commit(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
+pysqlite_connection_commit(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return pysqlite_connection_commit_impl(self);
+ return pysqlite_connection_commit_impl((pysqlite_Connection *)self);
}
PyDoc_STRVAR(pysqlite_connection_rollback__doc__,
@@ -412,9 +412,9 @@ static PyObject *
pysqlite_connection_rollback_impl(pysqlite_Connection *self);
static PyObject *
-pysqlite_connection_rollback(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
+pysqlite_connection_rollback(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return pysqlite_connection_rollback_impl(self);
+ return pysqlite_connection_rollback_impl((pysqlite_Connection *)self);
}
PyDoc_STRVAR(pysqlite_connection_create_function__doc__,
@@ -449,7 +449,7 @@ pysqlite_connection_create_function_impl(pysqlite_Connection *self,
#endif
static PyObject *
-pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pysqlite_connection_create_function(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -525,7 +525,7 @@ pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls
goto exit;
}
skip_optional_kwonly:
- return_value = pysqlite_connection_create_function_impl(self, cls, name, narg, func, deterministic);
+ return_value = pysqlite_connection_create_function_impl((pysqlite_Connection *)self, cls, name, narg, func, deterministic);
exit:
return return_value;
@@ -557,7 +557,7 @@ create_window_function_impl(pysqlite_Connection *self, PyTypeObject *cls,
PyObject *aggregate_class);
static PyObject *
-create_window_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+create_window_function(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -601,7 +601,7 @@ create_window_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *c
goto exit;
}
aggregate_class = args[2];
- return_value = create_window_function_impl(self, cls, name, num_params, aggregate_class);
+ return_value = create_window_function_impl((pysqlite_Connection *)self, cls, name, num_params, aggregate_class);
exit:
return return_value;
@@ -642,7 +642,7 @@ pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
#endif
static PyObject *
-pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pysqlite_connection_create_aggregate(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -708,7 +708,7 @@ pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyTypeObject *cl
goto exit;
}
aggregate_class = args[2];
- return_value = pysqlite_connection_create_aggregate_impl(self, cls, name, n_arg, aggregate_class);
+ return_value = pysqlite_connection_create_aggregate_impl((pysqlite_Connection *)self, cls, name, n_arg, aggregate_class);
exit:
return return_value;
@@ -745,7 +745,7 @@ pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
#endif
static PyObject *
-pysqlite_connection_set_authorizer(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pysqlite_connection_set_authorizer(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -792,7 +792,7 @@ pysqlite_connection_set_authorizer(pysqlite_Connection *self, PyTypeObject *cls,
}
}
callable = args[0];
- return_value = pysqlite_connection_set_authorizer_impl(self, cls, callable);
+ return_value = pysqlite_connection_set_authorizer_impl((pysqlite_Connection *)self, cls, callable);
exit:
return return_value;
@@ -839,7 +839,7 @@ pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
#endif
static PyObject *
-pysqlite_connection_set_progress_handler(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pysqlite_connection_set_progress_handler(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -891,7 +891,7 @@ pysqlite_connection_set_progress_handler(pysqlite_Connection *self, PyTypeObject
if (n == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = pysqlite_connection_set_progress_handler_impl(self, cls, callable, n);
+ return_value = pysqlite_connection_set_progress_handler_impl((pysqlite_Connection *)self, cls, callable, n);
exit:
return return_value;
@@ -928,7 +928,7 @@ pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
#endif
static PyObject *
-pysqlite_connection_set_trace_callback(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pysqlite_connection_set_trace_callback(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -975,7 +975,7 @@ pysqlite_connection_set_trace_callback(pysqlite_Connection *self, PyTypeObject *
}
}
callable = args[0];
- return_value = pysqlite_connection_set_trace_callback_impl(self, cls, callable);
+ return_value = pysqlite_connection_set_trace_callback_impl((pysqlite_Connection *)self, cls, callable);
exit:
return return_value;
@@ -997,7 +997,7 @@ pysqlite_connection_enable_load_extension_impl(pysqlite_Connection *self,
int onoff);
static PyObject *
-pysqlite_connection_enable_load_extension(pysqlite_Connection *self, PyObject *arg)
+pysqlite_connection_enable_load_extension(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int onoff;
@@ -1006,7 +1006,7 @@ pysqlite_connection_enable_load_extension(pysqlite_Connection *self, PyObject *a
if (onoff < 0) {
goto exit;
}
- return_value = pysqlite_connection_enable_load_extension_impl(self, onoff);
+ return_value = pysqlite_connection_enable_load_extension_impl((pysqlite_Connection *)self, onoff);
exit:
return return_value;
@@ -1031,7 +1031,7 @@ pysqlite_connection_load_extension_impl(pysqlite_Connection *self,
const char *entrypoint);
static PyObject *
-pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pysqlite_connection_load_extension(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1104,7 +1104,7 @@ pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *const *a
goto exit;
}
skip_optional_kwonly:
- return_value = pysqlite_connection_load_extension_impl(self, extension_name, entrypoint);
+ return_value = pysqlite_connection_load_extension_impl((pysqlite_Connection *)self, extension_name, entrypoint);
exit:
return return_value;
@@ -1126,7 +1126,7 @@ pysqlite_connection_execute_impl(pysqlite_Connection *self, PyObject *sql,
PyObject *parameters);
static PyObject *
-pysqlite_connection_execute(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
+pysqlite_connection_execute(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sql;
@@ -1145,7 +1145,7 @@ pysqlite_connection_execute(pysqlite_Connection *self, PyObject *const *args, Py
}
parameters = args[1];
skip_optional:
- return_value = pysqlite_connection_execute_impl(self, sql, parameters);
+ return_value = pysqlite_connection_execute_impl((pysqlite_Connection *)self, sql, parameters);
exit:
return return_value;
@@ -1165,7 +1165,7 @@ pysqlite_connection_executemany_impl(pysqlite_Connection *self,
PyObject *sql, PyObject *parameters);
static PyObject *
-pysqlite_connection_executemany(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
+pysqlite_connection_executemany(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sql;
@@ -1180,7 +1180,7 @@ pysqlite_connection_executemany(pysqlite_Connection *self, PyObject *const *args
}
sql = args[0];
parameters = args[1];
- return_value = pysqlite_connection_executemany_impl(self, sql, parameters);
+ return_value = pysqlite_connection_executemany_impl((pysqlite_Connection *)self, sql, parameters);
exit:
return return_value;
@@ -1208,9 +1208,9 @@ static PyObject *
pysqlite_connection_interrupt_impl(pysqlite_Connection *self);
static PyObject *
-pysqlite_connection_interrupt(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
+pysqlite_connection_interrupt(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return pysqlite_connection_interrupt_impl(self);
+ return pysqlite_connection_interrupt_impl((pysqlite_Connection *)self);
}
PyDoc_STRVAR(pysqlite_connection_iterdump__doc__,
@@ -1230,7 +1230,7 @@ pysqlite_connection_iterdump_impl(pysqlite_Connection *self,
PyObject *filter);
static PyObject *
-pysqlite_connection_iterdump(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pysqlite_connection_iterdump(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1272,7 +1272,7 @@ pysqlite_connection_iterdump(pysqlite_Connection *self, PyObject *const *args, P
}
filter = args[0];
skip_optional_kwonly:
- return_value = pysqlite_connection_iterdump_impl(self, filter);
+ return_value = pysqlite_connection_iterdump_impl((pysqlite_Connection *)self, filter);
exit:
return return_value;
@@ -1295,7 +1295,7 @@ pysqlite_connection_backup_impl(pysqlite_Connection *self,
double sleep);
static PyObject *
-pysqlite_connection_backup(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pysqlite_connection_backup(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1388,7 +1388,7 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *const *args, Py_
}
}
skip_optional_kwonly:
- return_value = pysqlite_connection_backup_impl(self, target, pages, progress, name, sleep);
+ return_value = pysqlite_connection_backup_impl((pysqlite_Connection *)self, target, pages, progress, name, sleep);
exit:
return return_value;
@@ -1410,7 +1410,7 @@ pysqlite_connection_create_collation_impl(pysqlite_Connection *self,
PyObject *callable);
static PyObject *
-pysqlite_connection_create_collation(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pysqlite_connection_create_collation(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1449,7 +1449,7 @@ pysqlite_connection_create_collation(pysqlite_Connection *self, PyTypeObject *cl
goto exit;
}
callable = args[1];
- return_value = pysqlite_connection_create_collation_impl(self, cls, name, callable);
+ return_value = pysqlite_connection_create_collation_impl((pysqlite_Connection *)self, cls, name, callable);
exit:
return return_value;
@@ -1478,7 +1478,7 @@ static PyObject *
serialize_impl(pysqlite_Connection *self, const char *name);
static PyObject *
-serialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+serialize(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1532,7 +1532,7 @@ serialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, Py
goto exit;
}
skip_optional_kwonly:
- return_value = serialize_impl(self, name);
+ return_value = serialize_impl((pysqlite_Connection *)self, name);
exit:
return return_value;
@@ -1568,7 +1568,7 @@ deserialize_impl(pysqlite_Connection *self, Py_buffer *data,
const char *name);
static PyObject *
-deserialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+deserialize(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1638,7 +1638,7 @@ deserialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs,
goto exit;
}
skip_optional_kwonly:
- return_value = deserialize_impl(self, &data, name);
+ return_value = deserialize_impl((pysqlite_Connection *)self, &data, name);
exit:
/* Cleanup for data */
@@ -1666,9 +1666,9 @@ static PyObject *
pysqlite_connection_enter_impl(pysqlite_Connection *self);
static PyObject *
-pysqlite_connection_enter(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
+pysqlite_connection_enter(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return pysqlite_connection_enter_impl(self);
+ return pysqlite_connection_enter_impl((pysqlite_Connection *)self);
}
PyDoc_STRVAR(pysqlite_connection_exit__doc__,
@@ -1687,7 +1687,7 @@ pysqlite_connection_exit_impl(pysqlite_Connection *self, PyObject *exc_type,
PyObject *exc_value, PyObject *exc_tb);
static PyObject *
-pysqlite_connection_exit(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
+pysqlite_connection_exit(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *exc_type;
@@ -1700,7 +1700,7 @@ pysqlite_connection_exit(pysqlite_Connection *self, PyObject *const *args, Py_ss
exc_type = args[0];
exc_value = args[1];
exc_tb = args[2];
- return_value = pysqlite_connection_exit_impl(self, exc_type, exc_value, exc_tb);
+ return_value = pysqlite_connection_exit_impl((pysqlite_Connection *)self, exc_type, exc_value, exc_tb);
exit:
return return_value;
@@ -1729,7 +1729,7 @@ static PyObject *
setlimit_impl(pysqlite_Connection *self, int category, int limit);
static PyObject *
-setlimit(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
+setlimit(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int category;
@@ -1746,7 +1746,7 @@ setlimit(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
if (limit == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = setlimit_impl(self, category, limit);
+ return_value = setlimit_impl((pysqlite_Connection *)self, category, limit);
exit:
return return_value;
@@ -1768,7 +1768,7 @@ static PyObject *
getlimit_impl(pysqlite_Connection *self, int category);
static PyObject *
-getlimit(pysqlite_Connection *self, PyObject *arg)
+getlimit(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int category;
@@ -1777,7 +1777,7 @@ getlimit(pysqlite_Connection *self, PyObject *arg)
if (category == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = getlimit_impl(self, category);
+ return_value = getlimit_impl((pysqlite_Connection *)self, category);
exit:
return return_value;
@@ -1799,7 +1799,7 @@ static PyObject *
setconfig_impl(pysqlite_Connection *self, int op, int enable);
static PyObject *
-setconfig(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
+setconfig(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int op;
@@ -1820,7 +1820,7 @@ setconfig(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = setconfig_impl(self, op, enable);
+ return_value = setconfig_impl((pysqlite_Connection *)self, op, enable);
exit:
return return_value;
@@ -1842,7 +1842,7 @@ static int
getconfig_impl(pysqlite_Connection *self, int op);
static PyObject *
-getconfig(pysqlite_Connection *self, PyObject *arg)
+getconfig(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int op;
@@ -1852,7 +1852,7 @@ getconfig(pysqlite_Connection *self, PyObject *arg)
if (op == -1 && PyErr_Occurred()) {
goto exit;
}
- _return_value = getconfig_impl(self, op);
+ _return_value = getconfig_impl((pysqlite_Connection *)self, op);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -1881,4 +1881,4 @@ getconfig(pysqlite_Connection *self, PyObject *arg)
#ifndef DESERIALIZE_METHODDEF
#define DESERIALIZE_METHODDEF
#endif /* !defined(DESERIALIZE_METHODDEF) */
-/*[clinic end generated code: output=a8fd19301c7390cc input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c59effb407b8ea4d input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/cursor.c.h b/Modules/_sqlite/clinic/cursor.c.h
index ca7823cf5aef5b..590e429e9139f1 100644
--- a/Modules/_sqlite/clinic/cursor.c.h
+++ b/Modules/_sqlite/clinic/cursor.c.h
@@ -52,7 +52,7 @@ pysqlite_cursor_execute_impl(pysqlite_Cursor *self, PyObject *sql,
PyObject *parameters);
static PyObject *
-pysqlite_cursor_execute(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
+pysqlite_cursor_execute(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sql;
@@ -71,7 +71,7 @@ pysqlite_cursor_execute(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t
}
parameters = args[1];
skip_optional:
- return_value = pysqlite_cursor_execute_impl(self, sql, parameters);
+ return_value = pysqlite_cursor_execute_impl((pysqlite_Cursor *)self, sql, parameters);
exit:
return return_value;
@@ -91,7 +91,7 @@ pysqlite_cursor_executemany_impl(pysqlite_Cursor *self, PyObject *sql,
PyObject *seq_of_parameters);
static PyObject *
-pysqlite_cursor_executemany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
+pysqlite_cursor_executemany(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sql;
@@ -106,7 +106,7 @@ pysqlite_cursor_executemany(pysqlite_Cursor *self, PyObject *const *args, Py_ssi
}
sql = args[0];
seq_of_parameters = args[1];
- return_value = pysqlite_cursor_executemany_impl(self, sql, seq_of_parameters);
+ return_value = pysqlite_cursor_executemany_impl((pysqlite_Cursor *)self, sql, seq_of_parameters);
exit:
return return_value;
@@ -126,7 +126,7 @@ pysqlite_cursor_executescript_impl(pysqlite_Cursor *self,
const char *sql_script);
static PyObject *
-pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *arg)
+pysqlite_cursor_executescript(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *sql_script;
@@ -144,7 +144,7 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = pysqlite_cursor_executescript_impl(self, sql_script);
+ return_value = pysqlite_cursor_executescript_impl((pysqlite_Cursor *)self, sql_script);
exit:
return return_value;
@@ -163,9 +163,9 @@ static PyObject *
pysqlite_cursor_fetchone_impl(pysqlite_Cursor *self);
static PyObject *
-pysqlite_cursor_fetchone(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
+pysqlite_cursor_fetchone(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return pysqlite_cursor_fetchone_impl(self);
+ return pysqlite_cursor_fetchone_impl((pysqlite_Cursor *)self);
}
PyDoc_STRVAR(pysqlite_cursor_fetchmany__doc__,
@@ -184,7 +184,7 @@ static PyObject *
pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, int maxrows);
static PyObject *
-pysqlite_cursor_fetchmany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pysqlite_cursor_fetchmany(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -214,7 +214,7 @@ pysqlite_cursor_fetchmany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize
#undef KWTUPLE
PyObject *argsbuf[1];
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
- int maxrows = self->arraysize;
+ int maxrows = ((pysqlite_Cursor *)self)->arraysize;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
@@ -229,7 +229,7 @@ pysqlite_cursor_fetchmany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize
goto exit;
}
skip_optional_pos:
- return_value = pysqlite_cursor_fetchmany_impl(self, maxrows);
+ return_value = pysqlite_cursor_fetchmany_impl((pysqlite_Cursor *)self, maxrows);
exit:
return return_value;
@@ -248,9 +248,9 @@ static PyObject *
pysqlite_cursor_fetchall_impl(pysqlite_Cursor *self);
static PyObject *
-pysqlite_cursor_fetchall(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
+pysqlite_cursor_fetchall(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return pysqlite_cursor_fetchall_impl(self);
+ return pysqlite_cursor_fetchall_impl((pysqlite_Cursor *)self);
}
PyDoc_STRVAR(pysqlite_cursor_setinputsizes__doc__,
@@ -276,7 +276,7 @@ pysqlite_cursor_setoutputsize_impl(pysqlite_Cursor *self, PyObject *size,
PyObject *column);
static PyObject *
-pysqlite_cursor_setoutputsize(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
+pysqlite_cursor_setoutputsize(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *size;
@@ -291,7 +291,7 @@ pysqlite_cursor_setoutputsize(pysqlite_Cursor *self, PyObject *const *args, Py_s
}
column = args[1];
skip_optional:
- return_value = pysqlite_cursor_setoutputsize_impl(self, size, column);
+ return_value = pysqlite_cursor_setoutputsize_impl((pysqlite_Cursor *)self, size, column);
exit:
return return_value;
@@ -310,8 +310,8 @@ static PyObject *
pysqlite_cursor_close_impl(pysqlite_Cursor *self);
static PyObject *
-pysqlite_cursor_close(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
+pysqlite_cursor_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return pysqlite_cursor_close_impl(self);
+ return pysqlite_cursor_close_impl((pysqlite_Cursor *)self);
}
-/*[clinic end generated code: output=f0804afc5f8646c1 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=82620ca7622b547c input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/row.c.h b/Modules/_sqlite/clinic/row.c.h
index e8d1dbf2ba8bc9..068906744e445f 100644
--- a/Modules/_sqlite/clinic/row.c.h
+++ b/Modules/_sqlite/clinic/row.c.h
@@ -52,8 +52,8 @@ static PyObject *
pysqlite_row_keys_impl(pysqlite_Row *self);
static PyObject *
-pysqlite_row_keys(pysqlite_Row *self, PyObject *Py_UNUSED(ignored))
+pysqlite_row_keys(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return pysqlite_row_keys_impl(self);
+ return pysqlite_row_keys_impl((pysqlite_Row *)self);
}
-/*[clinic end generated code: output=788bf817acc02b8e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6c1acbb48f386468 input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 0fbd408f18cf6a..24e97fcf1897e9 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -1155,7 +1155,7 @@ pysqlite_cursor_fetchone_impl(pysqlite_Cursor *self)
/*[clinic input]
_sqlite3.Cursor.fetchmany as pysqlite_cursor_fetchmany
- size as maxrows: int(c_default='self->arraysize') = 1
+ size as maxrows: int(c_default='((pysqlite_Cursor *)self)->arraysize') = 1
The default value is set by the Cursor.arraysize attribute.
Fetches several rows from the resultset.
@@ -1163,7 +1163,7 @@ Fetches several rows from the resultset.
static PyObject *
pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, int maxrows)
-/*[clinic end generated code: output=a8ef31fea64d0906 input=c26e6ca3f34debd0]*/
+/*[clinic end generated code: output=a8ef31fea64d0906 input=035dbe44a1005bf2]*/
{
PyObject* row;
PyObject* list;
diff --git a/Modules/_sre/clinic/sre.c.h b/Modules/_sre/clinic/sre.c.h
index 87e4785a428468..cfc6813f37f012 100644
--- a/Modules/_sre/clinic/sre.c.h
+++ b/Modules/_sre/clinic/sre.c.h
@@ -179,7 +179,7 @@ _sre_SRE_Pattern_match_impl(PatternObject *self, PyTypeObject *cls,
Py_ssize_t endpos);
static PyObject *
-_sre_SRE_Pattern_match(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Pattern_match(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -252,7 +252,7 @@ _sre_SRE_Pattern_match(PatternObject *self, PyTypeObject *cls, PyObject *const *
endpos = ival;
}
skip_optional_pos:
- return_value = _sre_SRE_Pattern_match_impl(self, cls, string, pos, endpos);
+ return_value = _sre_SRE_Pattern_match_impl((PatternObject *)self, cls, string, pos, endpos);
exit:
return return_value;
@@ -273,7 +273,7 @@ _sre_SRE_Pattern_fullmatch_impl(PatternObject *self, PyTypeObject *cls,
Py_ssize_t endpos);
static PyObject *
-_sre_SRE_Pattern_fullmatch(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Pattern_fullmatch(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -346,7 +346,7 @@ _sre_SRE_Pattern_fullmatch(PatternObject *self, PyTypeObject *cls, PyObject *con
endpos = ival;
}
skip_optional_pos:
- return_value = _sre_SRE_Pattern_fullmatch_impl(self, cls, string, pos, endpos);
+ return_value = _sre_SRE_Pattern_fullmatch_impl((PatternObject *)self, cls, string, pos, endpos);
exit:
return return_value;
@@ -369,7 +369,7 @@ _sre_SRE_Pattern_search_impl(PatternObject *self, PyTypeObject *cls,
Py_ssize_t endpos);
static PyObject *
-_sre_SRE_Pattern_search(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Pattern_search(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -442,7 +442,7 @@ _sre_SRE_Pattern_search(PatternObject *self, PyTypeObject *cls, PyObject *const
endpos = ival;
}
skip_optional_pos:
- return_value = _sre_SRE_Pattern_search_impl(self, cls, string, pos, endpos);
+ return_value = _sre_SRE_Pattern_search_impl((PatternObject *)self, cls, string, pos, endpos);
exit:
return return_value;
@@ -462,7 +462,7 @@ _sre_SRE_Pattern_findall_impl(PatternObject *self, PyObject *string,
Py_ssize_t pos, Py_ssize_t endpos);
static PyObject *
-_sre_SRE_Pattern_findall(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Pattern_findall(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -535,7 +535,7 @@ _sre_SRE_Pattern_findall(PatternObject *self, PyObject *const *args, Py_ssize_t
endpos = ival;
}
skip_optional_pos:
- return_value = _sre_SRE_Pattern_findall_impl(self, string, pos, endpos);
+ return_value = _sre_SRE_Pattern_findall_impl((PatternObject *)self, string, pos, endpos);
exit:
return return_value;
@@ -558,7 +558,7 @@ _sre_SRE_Pattern_finditer_impl(PatternObject *self, PyTypeObject *cls,
Py_ssize_t endpos);
static PyObject *
-_sre_SRE_Pattern_finditer(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Pattern_finditer(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -631,7 +631,7 @@ _sre_SRE_Pattern_finditer(PatternObject *self, PyTypeObject *cls, PyObject *cons
endpos = ival;
}
skip_optional_pos:
- return_value = _sre_SRE_Pattern_finditer_impl(self, cls, string, pos, endpos);
+ return_value = _sre_SRE_Pattern_finditer_impl((PatternObject *)self, cls, string, pos, endpos);
exit:
return return_value;
@@ -651,7 +651,7 @@ _sre_SRE_Pattern_scanner_impl(PatternObject *self, PyTypeObject *cls,
Py_ssize_t endpos);
static PyObject *
-_sre_SRE_Pattern_scanner(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Pattern_scanner(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -724,7 +724,7 @@ _sre_SRE_Pattern_scanner(PatternObject *self, PyTypeObject *cls, PyObject *const
endpos = ival;
}
skip_optional_pos:
- return_value = _sre_SRE_Pattern_scanner_impl(self, cls, string, pos, endpos);
+ return_value = _sre_SRE_Pattern_scanner_impl((PatternObject *)self, cls, string, pos, endpos);
exit:
return return_value;
@@ -744,7 +744,7 @@ _sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string,
Py_ssize_t maxsplit);
static PyObject *
-_sre_SRE_Pattern_split(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Pattern_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -799,7 +799,7 @@ _sre_SRE_Pattern_split(PatternObject *self, PyObject *const *args, Py_ssize_t na
maxsplit = ival;
}
skip_optional_pos:
- return_value = _sre_SRE_Pattern_split_impl(self, string, maxsplit);
+ return_value = _sre_SRE_Pattern_split_impl((PatternObject *)self, string, maxsplit);
exit:
return return_value;
@@ -819,7 +819,7 @@ _sre_SRE_Pattern_sub_impl(PatternObject *self, PyTypeObject *cls,
PyObject *repl, PyObject *string, Py_ssize_t count);
static PyObject *
-_sre_SRE_Pattern_sub(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Pattern_sub(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -876,7 +876,7 @@ _sre_SRE_Pattern_sub(PatternObject *self, PyTypeObject *cls, PyObject *const *ar
count = ival;
}
skip_optional_pos:
- return_value = _sre_SRE_Pattern_sub_impl(self, cls, repl, string, count);
+ return_value = _sre_SRE_Pattern_sub_impl((PatternObject *)self, cls, repl, string, count);
exit:
return return_value;
@@ -897,7 +897,7 @@ _sre_SRE_Pattern_subn_impl(PatternObject *self, PyTypeObject *cls,
Py_ssize_t count);
static PyObject *
-_sre_SRE_Pattern_subn(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Pattern_subn(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -954,7 +954,7 @@ _sre_SRE_Pattern_subn(PatternObject *self, PyTypeObject *cls, PyObject *const *a
count = ival;
}
skip_optional_pos:
- return_value = _sre_SRE_Pattern_subn_impl(self, cls, repl, string, count);
+ return_value = _sre_SRE_Pattern_subn_impl((PatternObject *)self, cls, repl, string, count);
exit:
return return_value;
@@ -972,9 +972,9 @@ static PyObject *
_sre_SRE_Pattern___copy___impl(PatternObject *self);
static PyObject *
-_sre_SRE_Pattern___copy__(PatternObject *self, PyObject *Py_UNUSED(ignored))
+_sre_SRE_Pattern___copy__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _sre_SRE_Pattern___copy___impl(self);
+ return _sre_SRE_Pattern___copy___impl((PatternObject *)self);
}
PyDoc_STRVAR(_sre_SRE_Pattern___deepcopy____doc__,
@@ -1001,7 +1001,7 @@ _sre_SRE_Pattern__fail_after_impl(PatternObject *self, int count,
PyObject *exception);
static PyObject *
-_sre_SRE_Pattern__fail_after(PatternObject *self, PyObject *const *args, Py_ssize_t nargs)
+_sre_SRE_Pattern__fail_after(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int count;
@@ -1015,7 +1015,7 @@ _sre_SRE_Pattern__fail_after(PatternObject *self, PyObject *const *args, Py_ssiz
goto exit;
}
exception = args[1];
- return_value = _sre_SRE_Pattern__fail_after_impl(self, count, exception);
+ return_value = _sre_SRE_Pattern__fail_after_impl((PatternObject *)self, count, exception);
exit:
return return_value;
@@ -1169,7 +1169,7 @@ static PyObject *
_sre_SRE_Match_expand_impl(MatchObject *self, PyObject *template);
static PyObject *
-_sre_SRE_Match_expand(MatchObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Match_expand(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1206,7 +1206,7 @@ _sre_SRE_Match_expand(MatchObject *self, PyObject *const *args, Py_ssize_t nargs
goto exit;
}
template = args[0];
- return_value = _sre_SRE_Match_expand_impl(self, template);
+ return_value = _sre_SRE_Match_expand_impl((MatchObject *)self, template);
exit:
return return_value;
@@ -1228,7 +1228,7 @@ static PyObject *
_sre_SRE_Match_groups_impl(MatchObject *self, PyObject *default_value);
static PyObject *
-_sre_SRE_Match_groups(MatchObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Match_groups(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1270,7 +1270,7 @@ _sre_SRE_Match_groups(MatchObject *self, PyObject *const *args, Py_ssize_t nargs
}
default_value = args[0];
skip_optional_pos:
- return_value = _sre_SRE_Match_groups_impl(self, default_value);
+ return_value = _sre_SRE_Match_groups_impl((MatchObject *)self, default_value);
exit:
return return_value;
@@ -1292,7 +1292,7 @@ static PyObject *
_sre_SRE_Match_groupdict_impl(MatchObject *self, PyObject *default_value);
static PyObject *
-_sre_SRE_Match_groupdict(MatchObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Match_groupdict(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1334,7 +1334,7 @@ _sre_SRE_Match_groupdict(MatchObject *self, PyObject *const *args, Py_ssize_t na
}
default_value = args[0];
skip_optional_pos:
- return_value = _sre_SRE_Match_groupdict_impl(self, default_value);
+ return_value = _sre_SRE_Match_groupdict_impl((MatchObject *)self, default_value);
exit:
return return_value;
@@ -1353,7 +1353,7 @@ static Py_ssize_t
_sre_SRE_Match_start_impl(MatchObject *self, PyObject *group);
static PyObject *
-_sre_SRE_Match_start(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
+_sre_SRE_Match_start(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *group = NULL;
@@ -1367,7 +1367,7 @@ _sre_SRE_Match_start(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
}
group = args[0];
skip_optional:
- _return_value = _sre_SRE_Match_start_impl(self, group);
+ _return_value = _sre_SRE_Match_start_impl((MatchObject *)self, group);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -1390,7 +1390,7 @@ static Py_ssize_t
_sre_SRE_Match_end_impl(MatchObject *self, PyObject *group);
static PyObject *
-_sre_SRE_Match_end(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
+_sre_SRE_Match_end(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *group = NULL;
@@ -1404,7 +1404,7 @@ _sre_SRE_Match_end(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
}
group = args[0];
skip_optional:
- _return_value = _sre_SRE_Match_end_impl(self, group);
+ _return_value = _sre_SRE_Match_end_impl((MatchObject *)self, group);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -1427,7 +1427,7 @@ static PyObject *
_sre_SRE_Match_span_impl(MatchObject *self, PyObject *group);
static PyObject *
-_sre_SRE_Match_span(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
+_sre_SRE_Match_span(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *group = NULL;
@@ -1440,7 +1440,7 @@ _sre_SRE_Match_span(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
}
group = args[0];
skip_optional:
- return_value = _sre_SRE_Match_span_impl(self, group);
+ return_value = _sre_SRE_Match_span_impl((MatchObject *)self, group);
exit:
return return_value;
@@ -1458,9 +1458,9 @@ static PyObject *
_sre_SRE_Match___copy___impl(MatchObject *self);
static PyObject *
-_sre_SRE_Match___copy__(MatchObject *self, PyObject *Py_UNUSED(ignored))
+_sre_SRE_Match___copy__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _sre_SRE_Match___copy___impl(self);
+ return _sre_SRE_Match___copy___impl((MatchObject *)self);
}
PyDoc_STRVAR(_sre_SRE_Match___deepcopy____doc__,
@@ -1483,13 +1483,13 @@ static PyObject *
_sre_SRE_Scanner_match_impl(ScannerObject *self, PyTypeObject *cls);
static PyObject *
-_sre_SRE_Scanner_match(ScannerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Scanner_match(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "match() takes no arguments");
return NULL;
}
- return _sre_SRE_Scanner_match_impl(self, cls);
+ return _sre_SRE_Scanner_match_impl((ScannerObject *)self, cls);
}
PyDoc_STRVAR(_sre_SRE_Scanner_search__doc__,
@@ -1504,16 +1504,16 @@ static PyObject *
_sre_SRE_Scanner_search_impl(ScannerObject *self, PyTypeObject *cls);
static PyObject *
-_sre_SRE_Scanner_search(ScannerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_sre_SRE_Scanner_search(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "search() takes no arguments");
return NULL;
}
- return _sre_SRE_Scanner_search_impl(self, cls);
+ return _sre_SRE_Scanner_search_impl((ScannerObject *)self, cls);
}
#ifndef _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF
#define _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF
#endif /* !defined(_SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF) */
-/*[clinic end generated code: output=f8cb77f2261f0b2e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3654103c87eb4830 input=a9049054013a1b77]*/
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index a7d0f509aed3d1..c15a582a92aa4a 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -965,13 +965,13 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
}
}
if (owner && owner != Py_None) {
- if (_ssl__SSLSocket_owner_set(self, owner, NULL) == -1) {
+ if (_ssl__SSLSocket_owner_set((PyObject *)self, owner, NULL) < 0) {
Py_DECREF(self);
return NULL;
}
}
if (session && session != Py_None) {
- if (_ssl__SSLSocket_session_set(self, session, NULL) == -1) {
+ if (_ssl__SSLSocket_session_set((PyObject *)self, session, NULL) < 0) {
Py_DECREF(self);
return NULL;
}
diff --git a/Modules/_ssl/clinic/cert.c.h b/Modules/_ssl/clinic/cert.c.h
index 19559442cd9b88..3e0c5b405092db 100644
--- a/Modules/_ssl/clinic/cert.c.h
+++ b/Modules/_ssl/clinic/cert.c.h
@@ -20,7 +20,7 @@ static PyObject *
_ssl_Certificate_public_bytes_impl(PySSLCertificate *self, int format);
static PyObject *
-_ssl_Certificate_public_bytes(PySSLCertificate *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_ssl_Certificate_public_bytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -65,7 +65,7 @@ _ssl_Certificate_public_bytes(PySSLCertificate *self, PyObject *const *args, Py_
goto exit;
}
skip_optional_pos:
- return_value = _ssl_Certificate_public_bytes_impl(self, format);
+ return_value = _ssl_Certificate_public_bytes_impl((PySSLCertificate *)self, format);
exit:
return return_value;
@@ -83,8 +83,8 @@ static PyObject *
_ssl_Certificate_get_info_impl(PySSLCertificate *self);
static PyObject *
-_ssl_Certificate_get_info(PySSLCertificate *self, PyObject *Py_UNUSED(ignored))
+_ssl_Certificate_get_info(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _ssl_Certificate_get_info_impl(self);
+ return _ssl_Certificate_get_info_impl((PySSLCertificate *)self);
}
-/*[clinic end generated code: output=e5fa354db5fc56b4 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=51365b498b975ee0 input=a9049054013a1b77]*/
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index fdbb0f0e8d6691..28c6a0ae05c598 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1557,7 +1557,7 @@ array_array_fromfile_impl(arrayobject *self, PyTypeObject *cls, PyObject *f,
not_enough_bytes = (PyBytes_GET_SIZE(b) != nbytes);
- res = array_array_frombytes(self, b);
+ res = array_array_frombytes((PyObject *)self, b);
Py_DECREF(b);
if (res == NULL)
return NULL;
@@ -2797,8 +2797,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
else if (initial != NULL && (PyByteArray_Check(initial) ||
PyBytes_Check(initial))) {
PyObject *v;
- v = array_array_frombytes((arrayobject *)a,
- initial);
+ v = array_array_frombytes((PyObject *)a, initial);
if (v == NULL) {
Py_DECREF(a);
return NULL;
diff --git a/Modules/cjkcodecs/clinic/multibytecodec.c.h b/Modules/cjkcodecs/clinic/multibytecodec.c.h
index 7e7ea9e0fdfa8e..d77bbd48066354 100644
--- a/Modules/cjkcodecs/clinic/multibytecodec.c.h
+++ b/Modules/cjkcodecs/clinic/multibytecodec.c.h
@@ -28,7 +28,7 @@ _multibytecodec_MultibyteCodec_encode_impl(MultibyteCodecObject *self,
const char *errors);
static PyObject *
-_multibytecodec_MultibyteCodec_encode(MultibyteCodecObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_multibytecodec_MultibyteCodec_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -89,7 +89,7 @@ _multibytecodec_MultibyteCodec_encode(MultibyteCodecObject *self, PyObject *cons
goto exit;
}
skip_optional_pos:
- return_value = _multibytecodec_MultibyteCodec_encode_impl(self, input, errors);
+ return_value = _multibytecodec_MultibyteCodec_encode_impl((MultibyteCodecObject *)self, input, errors);
exit:
return return_value;
@@ -115,7 +115,7 @@ _multibytecodec_MultibyteCodec_decode_impl(MultibyteCodecObject *self,
const char *errors);
static PyObject *
-_multibytecodec_MultibyteCodec_decode(MultibyteCodecObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_multibytecodec_MultibyteCodec_decode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -178,7 +178,7 @@ _multibytecodec_MultibyteCodec_decode(MultibyteCodecObject *self, PyObject *cons
goto exit;
}
skip_optional_pos:
- return_value = _multibytecodec_MultibyteCodec_decode_impl(self, &input, errors);
+ return_value = _multibytecodec_MultibyteCodec_decode_impl((MultibyteCodecObject *)self, &input, errors);
exit:
/* Cleanup for input */
@@ -203,7 +203,7 @@ _multibytecodec_MultibyteIncrementalEncoder_encode_impl(MultibyteIncrementalEnco
int final);
static PyObject *
-_multibytecodec_MultibyteIncrementalEncoder_encode(MultibyteIncrementalEncoderObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_multibytecodec_MultibyteIncrementalEncoder_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -250,7 +250,7 @@ _multibytecodec_MultibyteIncrementalEncoder_encode(MultibyteIncrementalEncoderOb
goto exit;
}
skip_optional_pos:
- return_value = _multibytecodec_MultibyteIncrementalEncoder_encode_impl(self, input, final);
+ return_value = _multibytecodec_MultibyteIncrementalEncoder_encode_impl((MultibyteIncrementalEncoderObject *)self, input, final);
exit:
return return_value;
@@ -268,9 +268,9 @@ static PyObject *
_multibytecodec_MultibyteIncrementalEncoder_getstate_impl(MultibyteIncrementalEncoderObject *self);
static PyObject *
-_multibytecodec_MultibyteIncrementalEncoder_getstate(MultibyteIncrementalEncoderObject *self, PyObject *Py_UNUSED(ignored))
+_multibytecodec_MultibyteIncrementalEncoder_getstate(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _multibytecodec_MultibyteIncrementalEncoder_getstate_impl(self);
+ return _multibytecodec_MultibyteIncrementalEncoder_getstate_impl((MultibyteIncrementalEncoderObject *)self);
}
PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalEncoder_setstate__doc__,
@@ -286,7 +286,7 @@ _multibytecodec_MultibyteIncrementalEncoder_setstate_impl(MultibyteIncrementalEn
PyLongObject *statelong);
static PyObject *
-_multibytecodec_MultibyteIncrementalEncoder_setstate(MultibyteIncrementalEncoderObject *self, PyObject *arg)
+_multibytecodec_MultibyteIncrementalEncoder_setstate(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
PyLongObject *statelong;
@@ -296,7 +296,7 @@ _multibytecodec_MultibyteIncrementalEncoder_setstate(MultibyteIncrementalEncoder
goto exit;
}
statelong = (PyLongObject *)arg;
- return_value = _multibytecodec_MultibyteIncrementalEncoder_setstate_impl(self, statelong);
+ return_value = _multibytecodec_MultibyteIncrementalEncoder_setstate_impl((MultibyteIncrementalEncoderObject *)self, statelong);
exit:
return return_value;
@@ -314,9 +314,9 @@ static PyObject *
_multibytecodec_MultibyteIncrementalEncoder_reset_impl(MultibyteIncrementalEncoderObject *self);
static PyObject *
-_multibytecodec_MultibyteIncrementalEncoder_reset(MultibyteIncrementalEncoderObject *self, PyObject *Py_UNUSED(ignored))
+_multibytecodec_MultibyteIncrementalEncoder_reset(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _multibytecodec_MultibyteIncrementalEncoder_reset_impl(self);
+ return _multibytecodec_MultibyteIncrementalEncoder_reset_impl((MultibyteIncrementalEncoderObject *)self);
}
PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalDecoder_decode__doc__,
@@ -333,7 +333,7 @@ _multibytecodec_MultibyteIncrementalDecoder_decode_impl(MultibyteIncrementalDeco
int final);
static PyObject *
-_multibytecodec_MultibyteIncrementalDecoder_decode(MultibyteIncrementalDecoderObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_multibytecodec_MultibyteIncrementalDecoder_decode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -382,7 +382,7 @@ _multibytecodec_MultibyteIncrementalDecoder_decode(MultibyteIncrementalDecoderOb
goto exit;
}
skip_optional_pos:
- return_value = _multibytecodec_MultibyteIncrementalDecoder_decode_impl(self, &input, final);
+ return_value = _multibytecodec_MultibyteIncrementalDecoder_decode_impl((MultibyteIncrementalDecoderObject *)self, &input, final);
exit:
/* Cleanup for input */
@@ -405,9 +405,9 @@ static PyObject *
_multibytecodec_MultibyteIncrementalDecoder_getstate_impl(MultibyteIncrementalDecoderObject *self);
static PyObject *
-_multibytecodec_MultibyteIncrementalDecoder_getstate(MultibyteIncrementalDecoderObject *self, PyObject *Py_UNUSED(ignored))
+_multibytecodec_MultibyteIncrementalDecoder_getstate(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _multibytecodec_MultibyteIncrementalDecoder_getstate_impl(self);
+ return _multibytecodec_MultibyteIncrementalDecoder_getstate_impl((MultibyteIncrementalDecoderObject *)self);
}
PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalDecoder_setstate__doc__,
@@ -423,7 +423,7 @@ _multibytecodec_MultibyteIncrementalDecoder_setstate_impl(MultibyteIncrementalDe
PyObject *state);
static PyObject *
-_multibytecodec_MultibyteIncrementalDecoder_setstate(MultibyteIncrementalDecoderObject *self, PyObject *arg)
+_multibytecodec_MultibyteIncrementalDecoder_setstate(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
PyObject *state;
@@ -433,7 +433,7 @@ _multibytecodec_MultibyteIncrementalDecoder_setstate(MultibyteIncrementalDecoder
goto exit;
}
state = arg;
- return_value = _multibytecodec_MultibyteIncrementalDecoder_setstate_impl(self, state);
+ return_value = _multibytecodec_MultibyteIncrementalDecoder_setstate_impl((MultibyteIncrementalDecoderObject *)self, state);
exit:
return return_value;
@@ -451,9 +451,9 @@ static PyObject *
_multibytecodec_MultibyteIncrementalDecoder_reset_impl(MultibyteIncrementalDecoderObject *self);
static PyObject *
-_multibytecodec_MultibyteIncrementalDecoder_reset(MultibyteIncrementalDecoderObject *self, PyObject *Py_UNUSED(ignored))
+_multibytecodec_MultibyteIncrementalDecoder_reset(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _multibytecodec_MultibyteIncrementalDecoder_reset_impl(self);
+ return _multibytecodec_MultibyteIncrementalDecoder_reset_impl((MultibyteIncrementalDecoderObject *)self);
}
PyDoc_STRVAR(_multibytecodec_MultibyteStreamReader_read__doc__,
@@ -469,7 +469,7 @@ _multibytecodec_MultibyteStreamReader_read_impl(MultibyteStreamReaderObject *sel
PyObject *sizeobj);
static PyObject *
-_multibytecodec_MultibyteStreamReader_read(MultibyteStreamReaderObject *self, PyObject *const *args, Py_ssize_t nargs)
+_multibytecodec_MultibyteStreamReader_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sizeobj = Py_None;
@@ -482,7 +482,7 @@ _multibytecodec_MultibyteStreamReader_read(MultibyteStreamReaderObject *self, Py
}
sizeobj = args[0];
skip_optional:
- return_value = _multibytecodec_MultibyteStreamReader_read_impl(self, sizeobj);
+ return_value = _multibytecodec_MultibyteStreamReader_read_impl((MultibyteStreamReaderObject *)self, sizeobj);
exit:
return return_value;
@@ -501,7 +501,7 @@ _multibytecodec_MultibyteStreamReader_readline_impl(MultibyteStreamReaderObject
PyObject *sizeobj);
static PyObject *
-_multibytecodec_MultibyteStreamReader_readline(MultibyteStreamReaderObject *self, PyObject *const *args, Py_ssize_t nargs)
+_multibytecodec_MultibyteStreamReader_readline(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sizeobj = Py_None;
@@ -514,7 +514,7 @@ _multibytecodec_MultibyteStreamReader_readline(MultibyteStreamReaderObject *self
}
sizeobj = args[0];
skip_optional:
- return_value = _multibytecodec_MultibyteStreamReader_readline_impl(self, sizeobj);
+ return_value = _multibytecodec_MultibyteStreamReader_readline_impl((MultibyteStreamReaderObject *)self, sizeobj);
exit:
return return_value;
@@ -533,7 +533,7 @@ _multibytecodec_MultibyteStreamReader_readlines_impl(MultibyteStreamReaderObject
PyObject *sizehintobj);
static PyObject *
-_multibytecodec_MultibyteStreamReader_readlines(MultibyteStreamReaderObject *self, PyObject *const *args, Py_ssize_t nargs)
+_multibytecodec_MultibyteStreamReader_readlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sizehintobj = Py_None;
@@ -546,7 +546,7 @@ _multibytecodec_MultibyteStreamReader_readlines(MultibyteStreamReaderObject *sel
}
sizehintobj = args[0];
skip_optional:
- return_value = _multibytecodec_MultibyteStreamReader_readlines_impl(self, sizehintobj);
+ return_value = _multibytecodec_MultibyteStreamReader_readlines_impl((MultibyteStreamReaderObject *)self, sizehintobj);
exit:
return return_value;
@@ -564,9 +564,9 @@ static PyObject *
_multibytecodec_MultibyteStreamReader_reset_impl(MultibyteStreamReaderObject *self);
static PyObject *
-_multibytecodec_MultibyteStreamReader_reset(MultibyteStreamReaderObject *self, PyObject *Py_UNUSED(ignored))
+_multibytecodec_MultibyteStreamReader_reset(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _multibytecodec_MultibyteStreamReader_reset_impl(self);
+ return _multibytecodec_MultibyteStreamReader_reset_impl((MultibyteStreamReaderObject *)self);
}
PyDoc_STRVAR(_multibytecodec_MultibyteStreamWriter_write__doc__,
@@ -583,7 +583,7 @@ _multibytecodec_MultibyteStreamWriter_write_impl(MultibyteStreamWriterObject *se
PyObject *strobj);
static PyObject *
-_multibytecodec_MultibyteStreamWriter_write(MultibyteStreamWriterObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_multibytecodec_MultibyteStreamWriter_write(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -608,7 +608,7 @@ _multibytecodec_MultibyteStreamWriter_write(MultibyteStreamWriterObject *self, P
goto exit;
}
strobj = args[0];
- return_value = _multibytecodec_MultibyteStreamWriter_write_impl(self, cls, strobj);
+ return_value = _multibytecodec_MultibyteStreamWriter_write_impl((MultibyteStreamWriterObject *)self, cls, strobj);
exit:
return return_value;
@@ -628,7 +628,7 @@ _multibytecodec_MultibyteStreamWriter_writelines_impl(MultibyteStreamWriterObjec
PyObject *lines);
static PyObject *
-_multibytecodec_MultibyteStreamWriter_writelines(MultibyteStreamWriterObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_multibytecodec_MultibyteStreamWriter_writelines(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -653,7 +653,7 @@ _multibytecodec_MultibyteStreamWriter_writelines(MultibyteStreamWriterObject *se
goto exit;
}
lines = args[0];
- return_value = _multibytecodec_MultibyteStreamWriter_writelines_impl(self, cls, lines);
+ return_value = _multibytecodec_MultibyteStreamWriter_writelines_impl((MultibyteStreamWriterObject *)self, cls, lines);
exit:
return return_value;
@@ -672,13 +672,13 @@ _multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *se
PyTypeObject *cls);
static PyObject *
-_multibytecodec_MultibyteStreamWriter_reset(MultibyteStreamWriterObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_multibytecodec_MultibyteStreamWriter_reset(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "reset() takes no arguments");
return NULL;
}
- return _multibytecodec_MultibyteStreamWriter_reset_impl(self, cls);
+ return _multibytecodec_MultibyteStreamWriter_reset_impl((MultibyteStreamWriterObject *)self, cls);
}
PyDoc_STRVAR(_multibytecodec___create_codec__doc__,
@@ -688,4 +688,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=60e1fa3a7615c148 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6571941b8e45b013 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_asynciomodule.c.h b/Modules/clinic/_asynciomodule.c.h
index 3a37cdd9b5fa83..794585572b13b9 100644
--- a/Modules/clinic/_asynciomodule.c.h
+++ b/Modules/clinic/_asynciomodule.c.h
@@ -97,12 +97,12 @@ static PyObject *
_asyncio_Future_result_impl(FutureObj *self);
static PyObject *
-_asyncio_Future_result(FutureObj *self, PyObject *Py_UNUSED(ignored))
+_asyncio_Future_result(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future_result_impl(self);
+ return_value = _asyncio_Future_result_impl((FutureObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -126,7 +126,7 @@ static PyObject *
_asyncio_Future_exception_impl(FutureObj *self, PyTypeObject *cls);
static PyObject *
-_asyncio_Future_exception(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_asyncio_Future_exception(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
@@ -135,7 +135,7 @@ _asyncio_Future_exception(FutureObj *self, PyTypeObject *cls, PyObject *const *a
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future_exception_impl(self, cls);
+ return_value = _asyncio_Future_exception_impl((FutureObj *)self, cls);
Py_END_CRITICAL_SECTION();
exit:
@@ -159,7 +159,7 @@ _asyncio_Future_set_result_impl(FutureObj *self, PyTypeObject *cls,
PyObject *result);
static PyObject *
-_asyncio_Future_set_result(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_asyncio_Future_set_result(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -185,7 +185,7 @@ _asyncio_Future_set_result(FutureObj *self, PyTypeObject *cls, PyObject *const *
}
result = args[0];
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future_set_result_impl(self, cls, result);
+ return_value = _asyncio_Future_set_result_impl((FutureObj *)self, cls, result);
Py_END_CRITICAL_SECTION();
exit:
@@ -209,7 +209,7 @@ _asyncio_Future_set_exception_impl(FutureObj *self, PyTypeObject *cls,
PyObject *exception);
static PyObject *
-_asyncio_Future_set_exception(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_asyncio_Future_set_exception(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -235,7 +235,7 @@ _asyncio_Future_set_exception(FutureObj *self, PyTypeObject *cls, PyObject *cons
}
exception = args[0];
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future_set_exception_impl(self, cls, exception);
+ return_value = _asyncio_Future_set_exception_impl((FutureObj *)self, cls, exception);
Py_END_CRITICAL_SECTION();
exit:
@@ -260,7 +260,7 @@ _asyncio_Future_add_done_callback_impl(FutureObj *self, PyTypeObject *cls,
PyObject *fn, PyObject *context);
static PyObject *
-_asyncio_Future_add_done_callback(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_asyncio_Future_add_done_callback(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -305,7 +305,7 @@ _asyncio_Future_add_done_callback(FutureObj *self, PyTypeObject *cls, PyObject *
context = args[1];
skip_optional_kwonly:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future_add_done_callback_impl(self, cls, fn, context);
+ return_value = _asyncio_Future_add_done_callback_impl((FutureObj *)self, cls, fn, context);
Py_END_CRITICAL_SECTION();
exit:
@@ -328,7 +328,7 @@ _asyncio_Future_remove_done_callback_impl(FutureObj *self, PyTypeObject *cls,
PyObject *fn);
static PyObject *
-_asyncio_Future_remove_done_callback(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_asyncio_Future_remove_done_callback(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -354,7 +354,7 @@ _asyncio_Future_remove_done_callback(FutureObj *self, PyTypeObject *cls, PyObjec
}
fn = args[0];
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future_remove_done_callback_impl(self, cls, fn);
+ return_value = _asyncio_Future_remove_done_callback_impl((FutureObj *)self, cls, fn);
Py_END_CRITICAL_SECTION();
exit:
@@ -379,7 +379,7 @@ _asyncio_Future_cancel_impl(FutureObj *self, PyTypeObject *cls,
PyObject *msg);
static PyObject *
-_asyncio_Future_cancel(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_asyncio_Future_cancel(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -422,7 +422,7 @@ _asyncio_Future_cancel(FutureObj *self, PyTypeObject *cls, PyObject *const *args
msg = args[0];
skip_optional_pos:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future_cancel_impl(self, cls, msg);
+ return_value = _asyncio_Future_cancel_impl((FutureObj *)self, cls, msg);
Py_END_CRITICAL_SECTION();
exit:
@@ -442,12 +442,12 @@ static PyObject *
_asyncio_Future_cancelled_impl(FutureObj *self);
static PyObject *
-_asyncio_Future_cancelled(FutureObj *self, PyObject *Py_UNUSED(ignored))
+_asyncio_Future_cancelled(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future_cancelled_impl(self);
+ return_value = _asyncio_Future_cancelled_impl((FutureObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -469,12 +469,12 @@ static PyObject *
_asyncio_Future_done_impl(FutureObj *self);
static PyObject *
-_asyncio_Future_done(FutureObj *self, PyObject *Py_UNUSED(ignored))
+_asyncio_Future_done(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future_done_impl(self);
+ return_value = _asyncio_Future_done_impl((FutureObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -493,7 +493,7 @@ static PyObject *
_asyncio_Future_get_loop_impl(FutureObj *self, PyTypeObject *cls);
static PyObject *
-_asyncio_Future_get_loop(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_asyncio_Future_get_loop(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
@@ -502,7 +502,7 @@ _asyncio_Future_get_loop(FutureObj *self, PyTypeObject *cls, PyObject *const *ar
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future_get_loop_impl(self, cls);
+ return_value = _asyncio_Future_get_loop_impl((FutureObj *)self, cls);
Py_END_CRITICAL_SECTION();
exit:
@@ -523,12 +523,12 @@ static PyObject *
_asyncio_Future__asyncio_future_blocking_get_impl(FutureObj *self);
static PyObject *
-_asyncio_Future__asyncio_future_blocking_get(FutureObj *self, void *Py_UNUSED(context))
+_asyncio_Future__asyncio_future_blocking_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future__asyncio_future_blocking_get_impl(self);
+ return_value = _asyncio_Future__asyncio_future_blocking_get_impl((FutureObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -549,12 +549,12 @@ _asyncio_Future__asyncio_future_blocking_set_impl(FutureObj *self,
PyObject *value);
static int
-_asyncio_Future__asyncio_future_blocking_set(FutureObj *self, PyObject *value, void *Py_UNUSED(context))
+_asyncio_Future__asyncio_future_blocking_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future__asyncio_future_blocking_set_impl(self, value);
+ return_value = _asyncio_Future__asyncio_future_blocking_set_impl((FutureObj *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -574,12 +574,12 @@ static PyObject *
_asyncio_Future__log_traceback_get_impl(FutureObj *self);
static PyObject *
-_asyncio_Future__log_traceback_get(FutureObj *self, void *Py_UNUSED(context))
+_asyncio_Future__log_traceback_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future__log_traceback_get_impl(self);
+ return_value = _asyncio_Future__log_traceback_get_impl((FutureObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -599,12 +599,12 @@ static int
_asyncio_Future__log_traceback_set_impl(FutureObj *self, PyObject *value);
static int
-_asyncio_Future__log_traceback_set(FutureObj *self, PyObject *value, void *Py_UNUSED(context))
+_asyncio_Future__log_traceback_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future__log_traceback_set_impl(self, value);
+ return_value = _asyncio_Future__log_traceback_set_impl((FutureObj *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -624,12 +624,12 @@ static PyObject *
_asyncio_Future__loop_get_impl(FutureObj *self);
static PyObject *
-_asyncio_Future__loop_get(FutureObj *self, void *Py_UNUSED(context))
+_asyncio_Future__loop_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future__loop_get_impl(self);
+ return_value = _asyncio_Future__loop_get_impl((FutureObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -649,12 +649,12 @@ static PyObject *
_asyncio_Future__callbacks_get_impl(FutureObj *self);
static PyObject *
-_asyncio_Future__callbacks_get(FutureObj *self, void *Py_UNUSED(context))
+_asyncio_Future__callbacks_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future__callbacks_get_impl(self);
+ return_value = _asyncio_Future__callbacks_get_impl((FutureObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -674,12 +674,12 @@ static PyObject *
_asyncio_Future__result_get_impl(FutureObj *self);
static PyObject *
-_asyncio_Future__result_get(FutureObj *self, void *Py_UNUSED(context))
+_asyncio_Future__result_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future__result_get_impl(self);
+ return_value = _asyncio_Future__result_get_impl((FutureObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -699,12 +699,12 @@ static PyObject *
_asyncio_Future__exception_get_impl(FutureObj *self);
static PyObject *
-_asyncio_Future__exception_get(FutureObj *self, void *Py_UNUSED(context))
+_asyncio_Future__exception_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future__exception_get_impl(self);
+ return_value = _asyncio_Future__exception_get_impl((FutureObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -724,12 +724,12 @@ static PyObject *
_asyncio_Future__source_traceback_get_impl(FutureObj *self);
static PyObject *
-_asyncio_Future__source_traceback_get(FutureObj *self, void *Py_UNUSED(context))
+_asyncio_Future__source_traceback_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future__source_traceback_get_impl(self);
+ return_value = _asyncio_Future__source_traceback_get_impl((FutureObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -749,12 +749,12 @@ static PyObject *
_asyncio_Future__cancel_message_get_impl(FutureObj *self);
static PyObject *
-_asyncio_Future__cancel_message_get(FutureObj *self, void *Py_UNUSED(context))
+_asyncio_Future__cancel_message_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future__cancel_message_get_impl(self);
+ return_value = _asyncio_Future__cancel_message_get_impl((FutureObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -774,12 +774,12 @@ static int
_asyncio_Future__cancel_message_set_impl(FutureObj *self, PyObject *value);
static int
-_asyncio_Future__cancel_message_set(FutureObj *self, PyObject *value, void *Py_UNUSED(context))
+_asyncio_Future__cancel_message_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future__cancel_message_set_impl(self, value);
+ return_value = _asyncio_Future__cancel_message_set_impl((FutureObj *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -799,12 +799,12 @@ static PyObject *
_asyncio_Future__state_get_impl(FutureObj *self);
static PyObject *
-_asyncio_Future__state_get(FutureObj *self, void *Py_UNUSED(context))
+_asyncio_Future__state_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future__state_get_impl(self);
+ return_value = _asyncio_Future__state_get_impl((FutureObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -826,12 +826,12 @@ static PyObject *
_asyncio_Future__make_cancelled_error_impl(FutureObj *self);
static PyObject *
-_asyncio_Future__make_cancelled_error(FutureObj *self, PyObject *Py_UNUSED(ignored))
+_asyncio_Future__make_cancelled_error(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Future__make_cancelled_error_impl(self);
+ return_value = _asyncio_Future__make_cancelled_error_impl((FutureObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -939,12 +939,12 @@ static PyObject *
_asyncio_Task__log_destroy_pending_get_impl(TaskObj *self);
static PyObject *
-_asyncio_Task__log_destroy_pending_get(TaskObj *self, void *Py_UNUSED(context))
+_asyncio_Task__log_destroy_pending_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Task__log_destroy_pending_get_impl(self);
+ return_value = _asyncio_Task__log_destroy_pending_get_impl((TaskObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -964,12 +964,12 @@ static int
_asyncio_Task__log_destroy_pending_set_impl(TaskObj *self, PyObject *value);
static int
-_asyncio_Task__log_destroy_pending_set(TaskObj *self, PyObject *value, void *Py_UNUSED(context))
+_asyncio_Task__log_destroy_pending_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Task__log_destroy_pending_set_impl(self, value);
+ return_value = _asyncio_Task__log_destroy_pending_set_impl((TaskObj *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -989,12 +989,12 @@ static PyObject *
_asyncio_Task__must_cancel_get_impl(TaskObj *self);
static PyObject *
-_asyncio_Task__must_cancel_get(TaskObj *self, void *Py_UNUSED(context))
+_asyncio_Task__must_cancel_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Task__must_cancel_get_impl(self);
+ return_value = _asyncio_Task__must_cancel_get_impl((TaskObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1014,12 +1014,12 @@ static PyObject *
_asyncio_Task__coro_get_impl(TaskObj *self);
static PyObject *
-_asyncio_Task__coro_get(TaskObj *self, void *Py_UNUSED(context))
+_asyncio_Task__coro_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Task__coro_get_impl(self);
+ return_value = _asyncio_Task__coro_get_impl((TaskObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1039,12 +1039,12 @@ static PyObject *
_asyncio_Task__fut_waiter_get_impl(TaskObj *self);
static PyObject *
-_asyncio_Task__fut_waiter_get(TaskObj *self, void *Py_UNUSED(context))
+_asyncio_Task__fut_waiter_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Task__fut_waiter_get_impl(self);
+ return_value = _asyncio_Task__fut_waiter_get_impl((TaskObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1066,12 +1066,12 @@ static PyObject *
_asyncio_Task__make_cancelled_error_impl(TaskObj *self);
static PyObject *
-_asyncio_Task__make_cancelled_error(TaskObj *self, PyObject *Py_UNUSED(ignored))
+_asyncio_Task__make_cancelled_error(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Task__make_cancelled_error_impl(self);
+ return_value = _asyncio_Task__make_cancelled_error_impl((TaskObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1109,7 +1109,7 @@ static PyObject *
_asyncio_Task_cancel_impl(TaskObj *self, PyObject *msg);
static PyObject *
-_asyncio_Task_cancel(TaskObj *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_asyncio_Task_cancel(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1152,7 +1152,7 @@ _asyncio_Task_cancel(TaskObj *self, PyObject *const *args, Py_ssize_t nargs, PyO
msg = args[0];
skip_optional_pos:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Task_cancel_impl(self, msg);
+ return_value = _asyncio_Task_cancel_impl((TaskObj *)self, msg);
Py_END_CRITICAL_SECTION();
exit:
@@ -1175,12 +1175,12 @@ static PyObject *
_asyncio_Task_cancelling_impl(TaskObj *self);
static PyObject *
-_asyncio_Task_cancelling(TaskObj *self, PyObject *Py_UNUSED(ignored))
+_asyncio_Task_cancelling(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Task_cancelling_impl(self);
+ return_value = _asyncio_Task_cancelling_impl((TaskObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1204,12 +1204,12 @@ static PyObject *
_asyncio_Task_uncancel_impl(TaskObj *self);
static PyObject *
-_asyncio_Task_uncancel(TaskObj *self, PyObject *Py_UNUSED(ignored))
+_asyncio_Task_uncancel(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Task_uncancel_impl(self);
+ return_value = _asyncio_Task_uncancel_impl((TaskObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1247,7 +1247,7 @@ _asyncio_Task_get_stack_impl(TaskObj *self, PyTypeObject *cls,
PyObject *limit);
static PyObject *
-_asyncio_Task_get_stack(TaskObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_asyncio_Task_get_stack(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1289,7 +1289,7 @@ _asyncio_Task_get_stack(TaskObj *self, PyTypeObject *cls, PyObject *const *args,
}
limit = args[0];
skip_optional_kwonly:
- return_value = _asyncio_Task_get_stack_impl(self, cls, limit);
+ return_value = _asyncio_Task_get_stack_impl((TaskObj *)self, cls, limit);
exit:
return return_value;
@@ -1315,7 +1315,7 @@ _asyncio_Task_print_stack_impl(TaskObj *self, PyTypeObject *cls,
PyObject *limit, PyObject *file);
static PyObject *
-_asyncio_Task_print_stack(TaskObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_asyncio_Task_print_stack(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1364,7 +1364,7 @@ _asyncio_Task_print_stack(TaskObj *self, PyTypeObject *cls, PyObject *const *arg
}
file = args[1];
skip_optional_kwonly:
- return_value = _asyncio_Task_print_stack_impl(self, cls, limit, file);
+ return_value = _asyncio_Task_print_stack_impl((TaskObj *)self, cls, limit, file);
exit:
return return_value;
@@ -1398,12 +1398,12 @@ static PyObject *
_asyncio_Task_get_coro_impl(TaskObj *self);
static PyObject *
-_asyncio_Task_get_coro(TaskObj *self, PyObject *Py_UNUSED(ignored))
+_asyncio_Task_get_coro(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Task_get_coro_impl(self);
+ return_value = _asyncio_Task_get_coro_impl((TaskObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1421,9 +1421,9 @@ static PyObject *
_asyncio_Task_get_context_impl(TaskObj *self);
static PyObject *
-_asyncio_Task_get_context(TaskObj *self, PyObject *Py_UNUSED(ignored))
+_asyncio_Task_get_context(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _asyncio_Task_get_context_impl(self);
+ return _asyncio_Task_get_context_impl((TaskObj *)self);
}
PyDoc_STRVAR(_asyncio_Task_get_name__doc__,
@@ -1438,12 +1438,12 @@ static PyObject *
_asyncio_Task_get_name_impl(TaskObj *self);
static PyObject *
-_asyncio_Task_get_name(TaskObj *self, PyObject *Py_UNUSED(ignored))
+_asyncio_Task_get_name(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Task_get_name_impl(self);
+ return_value = _asyncio_Task_get_name_impl((TaskObj *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1466,7 +1466,7 @@ _asyncio_Task_set_name(TaskObj *self, PyObject *value)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _asyncio_Task_set_name_impl(self, value);
+ return_value = _asyncio_Task_set_name_impl((TaskObj *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -2088,4 +2088,4 @@ _asyncio_all_tasks(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py
exit:
return return_value;
}
-/*[clinic end generated code: output=408e156476ced07f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ec2fa1d60b094978 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_bz2module.c.h b/Modules/clinic/_bz2module.c.h
index 93988bf48a1b00..a599bd1a8be96a 100644
--- a/Modules/clinic/_bz2module.c.h
+++ b/Modules/clinic/_bz2module.c.h
@@ -27,7 +27,7 @@ static PyObject *
_bz2_BZ2Compressor_compress_impl(BZ2Compressor *self, Py_buffer *data);
static PyObject *
-_bz2_BZ2Compressor_compress(BZ2Compressor *self, PyObject *arg)
+_bz2_BZ2Compressor_compress(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer data = {NULL, NULL};
@@ -35,7 +35,7 @@ _bz2_BZ2Compressor_compress(BZ2Compressor *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = _bz2_BZ2Compressor_compress_impl(self, &data);
+ return_value = _bz2_BZ2Compressor_compress_impl((BZ2Compressor *)self, &data);
exit:
/* Cleanup for data */
@@ -63,9 +63,9 @@ static PyObject *
_bz2_BZ2Compressor_flush_impl(BZ2Compressor *self);
static PyObject *
-_bz2_BZ2Compressor_flush(BZ2Compressor *self, PyObject *Py_UNUSED(ignored))
+_bz2_BZ2Compressor_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _bz2_BZ2Compressor_flush_impl(self);
+ return _bz2_BZ2Compressor_flush_impl((BZ2Compressor *)self);
}
PyDoc_STRVAR(_bz2_BZ2Compressor__doc__,
@@ -137,7 +137,7 @@ _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data,
Py_ssize_t max_length);
static PyObject *
-_bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_bz2_BZ2Decompressor_decompress(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -194,7 +194,7 @@ _bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *const *args, Py
max_length = ival;
}
skip_optional_pos:
- return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data, max_length);
+ return_value = _bz2_BZ2Decompressor_decompress_impl((BZ2Decompressor *)self, &data, max_length);
exit:
/* Cleanup for data */
@@ -235,4 +235,4 @@ _bz2_BZ2Decompressor(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=701a383434374c36 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=0fc5a6292c5fd2c5 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_collectionsmodule.c.h b/Modules/clinic/_collectionsmodule.c.h
index b4e3325e89502b..ddf18c2c77a8cd 100644
--- a/Modules/clinic/_collectionsmodule.c.h
+++ b/Modules/clinic/_collectionsmodule.c.h
@@ -23,12 +23,12 @@ static PyObject *
deque_pop_impl(dequeobject *deque);
static PyObject *
-deque_pop(dequeobject *deque, PyObject *Py_UNUSED(ignored))
+deque_pop(PyObject *deque, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_pop_impl(deque);
+ return_value = deque_pop_impl((dequeobject *)deque);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -47,12 +47,12 @@ static PyObject *
deque_popleft_impl(dequeobject *deque);
static PyObject *
-deque_popleft(dequeobject *deque, PyObject *Py_UNUSED(ignored))
+deque_popleft(PyObject *deque, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_popleft_impl(deque);
+ return_value = deque_popleft_impl((dequeobject *)deque);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -76,7 +76,7 @@ deque_append(dequeobject *deque, PyObject *item)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_append_impl(deque, item);
+ return_value = deque_append_impl((dequeobject *)deque, item);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -100,7 +100,7 @@ deque_appendleft(dequeobject *deque, PyObject *item)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_appendleft_impl(deque, item);
+ return_value = deque_appendleft_impl((dequeobject *)deque, item);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -124,7 +124,7 @@ deque_extend(dequeobject *deque, PyObject *iterable)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_extend_impl(deque, iterable);
+ return_value = deque_extend_impl((dequeobject *)deque, iterable);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -148,7 +148,7 @@ deque_extendleft(dequeobject *deque, PyObject *iterable)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_extendleft_impl(deque, iterable);
+ return_value = deque_extendleft_impl((dequeobject *)deque, iterable);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -167,12 +167,12 @@ static PyObject *
deque_copy_impl(dequeobject *deque);
static PyObject *
-deque_copy(dequeobject *deque, PyObject *Py_UNUSED(ignored))
+deque_copy(PyObject *deque, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_copy_impl(deque);
+ return_value = deque_copy_impl((dequeobject *)deque);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -191,12 +191,12 @@ static PyObject *
deque___copy___impl(dequeobject *deque);
static PyObject *
-deque___copy__(dequeobject *deque, PyObject *Py_UNUSED(ignored))
+deque___copy__(PyObject *deque, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque___copy___impl(deque);
+ return_value = deque___copy___impl((dequeobject *)deque);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -215,12 +215,12 @@ static PyObject *
deque_clearmethod_impl(dequeobject *deque);
static PyObject *
-deque_clearmethod(dequeobject *deque, PyObject *Py_UNUSED(ignored))
+deque_clearmethod(PyObject *deque, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_clearmethod_impl(deque);
+ return_value = deque_clearmethod_impl((dequeobject *)deque);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -239,7 +239,7 @@ static PyObject *
deque_rotate_impl(dequeobject *deque, Py_ssize_t n);
static PyObject *
-deque_rotate(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
+deque_rotate(PyObject *deque, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t n = 1;
@@ -264,7 +264,7 @@ deque_rotate(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_rotate_impl(deque, n);
+ return_value = deque_rotate_impl((dequeobject *)deque, n);
Py_END_CRITICAL_SECTION();
exit:
@@ -284,12 +284,12 @@ static PyObject *
deque_reverse_impl(dequeobject *deque);
static PyObject *
-deque_reverse(dequeobject *deque, PyObject *Py_UNUSED(ignored))
+deque_reverse(PyObject *deque, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_reverse_impl(deque);
+ return_value = deque_reverse_impl((dequeobject *)deque);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -313,7 +313,7 @@ deque_count(dequeobject *deque, PyObject *v)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_count_impl(deque, v);
+ return_value = deque_count_impl((dequeobject *)deque, v);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -335,7 +335,7 @@ deque_index_impl(dequeobject *deque, PyObject *v, Py_ssize_t start,
Py_ssize_t stop);
static PyObject *
-deque_index(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
+deque_index(PyObject *deque, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *v;
@@ -360,7 +360,7 @@ deque_index(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_index_impl(deque, v, start, stop);
+ return_value = deque_index_impl((dequeobject *)deque, v, start, stop);
Py_END_CRITICAL_SECTION();
exit:
@@ -380,7 +380,7 @@ static PyObject *
deque_insert_impl(dequeobject *deque, Py_ssize_t index, PyObject *value);
static PyObject *
-deque_insert(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
+deque_insert(PyObject *deque, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t index;
@@ -403,7 +403,7 @@ deque_insert(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
}
value = args[1];
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_insert_impl(deque, index, value);
+ return_value = deque_insert_impl((dequeobject *)deque, index, value);
Py_END_CRITICAL_SECTION();
exit:
@@ -428,7 +428,7 @@ deque_remove(dequeobject *deque, PyObject *value)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque_remove_impl(deque, value);
+ return_value = deque_remove_impl((dequeobject *)deque, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -447,9 +447,9 @@ static PyObject *
deque___reduce___impl(dequeobject *deque);
static PyObject *
-deque___reduce__(dequeobject *deque, PyObject *Py_UNUSED(ignored))
+deque___reduce__(PyObject *deque, PyObject *Py_UNUSED(ignored))
{
- return deque___reduce___impl(deque);
+ return deque___reduce___impl((dequeobject *)deque);
}
PyDoc_STRVAR(deque_init__doc__,
@@ -534,12 +534,12 @@ static PyObject *
deque___sizeof___impl(dequeobject *deque);
static PyObject *
-deque___sizeof__(dequeobject *deque, PyObject *Py_UNUSED(ignored))
+deque___sizeof__(PyObject *deque, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(deque);
- return_value = deque___sizeof___impl(deque);
+ return_value = deque___sizeof___impl((dequeobject *)deque);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -558,9 +558,9 @@ static PyObject *
deque___reversed___impl(dequeobject *deque);
static PyObject *
-deque___reversed__(dequeobject *deque, PyObject *Py_UNUSED(ignored))
+deque___reversed__(PyObject *deque, PyObject *Py_UNUSED(ignored))
{
- return deque___reversed___impl(deque);
+ return deque___reversed___impl((dequeobject *)deque);
}
PyDoc_STRVAR(_collections__count_elements__doc__,
@@ -630,4 +630,4 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=65f896fb13902f6d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=2d89c39288fc7389 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_curses_panel.c.h b/Modules/clinic/_curses_panel.c.h
index b6bff5274a3a91..6f4966825ec4bf 100644
--- a/Modules/clinic/_curses_panel.c.h
+++ b/Modules/clinic/_curses_panel.c.h
@@ -20,13 +20,13 @@ static PyObject *
_curses_panel_panel_bottom_impl(PyCursesPanelObject *self, PyTypeObject *cls);
static PyObject *
-_curses_panel_panel_bottom(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_curses_panel_panel_bottom(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "bottom() takes no arguments");
return NULL;
}
- return _curses_panel_panel_bottom_impl(self, cls);
+ return _curses_panel_panel_bottom_impl((PyCursesPanelObject *)self, cls);
}
PyDoc_STRVAR(_curses_panel_panel_hide__doc__,
@@ -44,13 +44,13 @@ static PyObject *
_curses_panel_panel_hide_impl(PyCursesPanelObject *self, PyTypeObject *cls);
static PyObject *
-_curses_panel_panel_hide(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_curses_panel_panel_hide(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "hide() takes no arguments");
return NULL;
}
- return _curses_panel_panel_hide_impl(self, cls);
+ return _curses_panel_panel_hide_impl((PyCursesPanelObject *)self, cls);
}
PyDoc_STRVAR(_curses_panel_panel_show__doc__,
@@ -66,13 +66,13 @@ static PyObject *
_curses_panel_panel_show_impl(PyCursesPanelObject *self, PyTypeObject *cls);
static PyObject *
-_curses_panel_panel_show(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_curses_panel_panel_show(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "show() takes no arguments");
return NULL;
}
- return _curses_panel_panel_show_impl(self, cls);
+ return _curses_panel_panel_show_impl((PyCursesPanelObject *)self, cls);
}
PyDoc_STRVAR(_curses_panel_panel_top__doc__,
@@ -88,13 +88,13 @@ static PyObject *
_curses_panel_panel_top_impl(PyCursesPanelObject *self, PyTypeObject *cls);
static PyObject *
-_curses_panel_panel_top(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_curses_panel_panel_top(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "top() takes no arguments");
return NULL;
}
- return _curses_panel_panel_top_impl(self, cls);
+ return _curses_panel_panel_top_impl((PyCursesPanelObject *)self, cls);
}
PyDoc_STRVAR(_curses_panel_panel_above__doc__,
@@ -110,9 +110,9 @@ static PyObject *
_curses_panel_panel_above_impl(PyCursesPanelObject *self);
static PyObject *
-_curses_panel_panel_above(PyCursesPanelObject *self, PyObject *Py_UNUSED(ignored))
+_curses_panel_panel_above(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _curses_panel_panel_above_impl(self);
+ return _curses_panel_panel_above_impl((PyCursesPanelObject *)self);
}
PyDoc_STRVAR(_curses_panel_panel_below__doc__,
@@ -128,9 +128,9 @@ static PyObject *
_curses_panel_panel_below_impl(PyCursesPanelObject *self);
static PyObject *
-_curses_panel_panel_below(PyCursesPanelObject *self, PyObject *Py_UNUSED(ignored))
+_curses_panel_panel_below(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _curses_panel_panel_below_impl(self);
+ return _curses_panel_panel_below_impl((PyCursesPanelObject *)self);
}
PyDoc_STRVAR(_curses_panel_panel_hidden__doc__,
@@ -146,9 +146,9 @@ static PyObject *
_curses_panel_panel_hidden_impl(PyCursesPanelObject *self);
static PyObject *
-_curses_panel_panel_hidden(PyCursesPanelObject *self, PyObject *Py_UNUSED(ignored))
+_curses_panel_panel_hidden(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _curses_panel_panel_hidden_impl(self);
+ return _curses_panel_panel_hidden_impl((PyCursesPanelObject *)self);
}
PyDoc_STRVAR(_curses_panel_panel_move__doc__,
@@ -165,7 +165,7 @@ _curses_panel_panel_move_impl(PyCursesPanelObject *self, PyTypeObject *cls,
int y, int x);
static PyObject *
-_curses_panel_panel_move(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_curses_panel_panel_move(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -198,7 +198,7 @@ _curses_panel_panel_move(PyCursesPanelObject *self, PyTypeObject *cls, PyObject
if (x == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = _curses_panel_panel_move_impl(self, cls, y, x);
+ return_value = _curses_panel_panel_move_impl((PyCursesPanelObject *)self, cls, y, x);
exit:
return return_value;
@@ -217,9 +217,9 @@ static PyObject *
_curses_panel_panel_window_impl(PyCursesPanelObject *self);
static PyObject *
-_curses_panel_panel_window(PyCursesPanelObject *self, PyObject *Py_UNUSED(ignored))
+_curses_panel_panel_window(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _curses_panel_panel_window_impl(self);
+ return _curses_panel_panel_window_impl((PyCursesPanelObject *)self);
}
PyDoc_STRVAR(_curses_panel_panel_replace__doc__,
@@ -237,7 +237,7 @@ _curses_panel_panel_replace_impl(PyCursesPanelObject *self,
PyCursesWindowObject *win);
static PyObject *
-_curses_panel_panel_replace(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_curses_panel_panel_replace(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -266,7 +266,7 @@ _curses_panel_panel_replace(PyCursesPanelObject *self, PyTypeObject *cls, PyObje
goto exit;
}
win = (PyCursesWindowObject *)args[0];
- return_value = _curses_panel_panel_replace_impl(self, cls, win);
+ return_value = _curses_panel_panel_replace_impl((PyCursesPanelObject *)self, cls, win);
exit:
return return_value;
@@ -286,7 +286,7 @@ _curses_panel_panel_set_userptr_impl(PyCursesPanelObject *self,
PyTypeObject *cls, PyObject *obj);
static PyObject *
-_curses_panel_panel_set_userptr(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_curses_panel_panel_set_userptr(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -311,7 +311,7 @@ _curses_panel_panel_set_userptr(PyCursesPanelObject *self, PyTypeObject *cls, Py
goto exit;
}
obj = args[0];
- return_value = _curses_panel_panel_set_userptr_impl(self, cls, obj);
+ return_value = _curses_panel_panel_set_userptr_impl((PyCursesPanelObject *)self, cls, obj);
exit:
return return_value;
@@ -331,13 +331,13 @@ _curses_panel_panel_userptr_impl(PyCursesPanelObject *self,
PyTypeObject *cls);
static PyObject *
-_curses_panel_panel_userptr(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_curses_panel_panel_userptr(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "userptr() takes no arguments");
return NULL;
}
- return _curses_panel_panel_userptr_impl(self, cls);
+ return _curses_panel_panel_userptr_impl((PyCursesPanelObject *)self, cls);
}
PyDoc_STRVAR(_curses_panel_bottom_panel__doc__,
@@ -424,4 +424,4 @@ _curses_panel_update_panels(PyObject *module, PyObject *Py_UNUSED(ignored))
{
return _curses_panel_update_panels_impl(module);
}
-/*[clinic end generated code: output=298e49d54c0b14a0 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=36853ecb4a979814 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_cursesmodule.c.h b/Modules/clinic/_cursesmodule.c.h
index 524a114aba98bc..8291d5d635c79d 100644
--- a/Modules/clinic/_cursesmodule.c.h
+++ b/Modules/clinic/_cursesmodule.c.h
@@ -35,7 +35,7 @@ _curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1,
long attr);
static PyObject *
-_curses_window_addch(PyCursesWindowObject *self, PyObject *args)
+_curses_window_addch(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_left_1 = 0;
@@ -74,7 +74,7 @@ _curses_window_addch(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.addch requires 1 to 4 arguments");
goto exit;
}
- return_value = _curses_window_addch_impl(self, group_left_1, y, x, ch, group_right_1, attr);
+ return_value = _curses_window_addch_impl((PyCursesWindowObject *)self, group_left_1, y, x, ch, group_right_1, attr);
exit:
return return_value;
@@ -107,7 +107,7 @@ _curses_window_addstr_impl(PyCursesWindowObject *self, int group_left_1,
long attr);
static PyObject *
-_curses_window_addstr(PyCursesWindowObject *self, PyObject *args)
+_curses_window_addstr(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_left_1 = 0;
@@ -146,7 +146,7 @@ _curses_window_addstr(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.addstr requires 1 to 4 arguments");
goto exit;
}
- return_value = _curses_window_addstr_impl(self, group_left_1, y, x, str, group_right_1, attr);
+ return_value = _curses_window_addstr_impl((PyCursesWindowObject *)self, group_left_1, y, x, str, group_right_1, attr);
exit:
return return_value;
@@ -181,7 +181,7 @@ _curses_window_addnstr_impl(PyCursesWindowObject *self, int group_left_1,
int group_right_1, long attr);
static PyObject *
-_curses_window_addnstr(PyCursesWindowObject *self, PyObject *args)
+_curses_window_addnstr(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_left_1 = 0;
@@ -221,7 +221,7 @@ _curses_window_addnstr(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.addnstr requires 2 to 5 arguments");
goto exit;
}
- return_value = _curses_window_addnstr_impl(self, group_left_1, y, x, str, n, group_right_1, attr);
+ return_value = _curses_window_addnstr_impl((PyCursesWindowObject *)self, group_left_1, y, x, str, n, group_right_1, attr);
exit:
return return_value;
@@ -245,7 +245,7 @@ static PyObject *
_curses_window_bkgd_impl(PyCursesWindowObject *self, PyObject *ch, long attr);
static PyObject *
-_curses_window_bkgd(PyCursesWindowObject *self, PyObject *const *args, Py_ssize_t nargs)
+_curses_window_bkgd(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *ch;
@@ -263,7 +263,7 @@ _curses_window_bkgd(PyCursesWindowObject *self, PyObject *const *args, Py_ssize_
goto exit;
}
skip_optional:
- return_value = _curses_window_bkgd_impl(self, ch, attr);
+ return_value = _curses_window_bkgd_impl((PyCursesWindowObject *)self, ch, attr);
exit:
return return_value;
@@ -282,7 +282,7 @@ static PyObject *
_curses_window_attroff_impl(PyCursesWindowObject *self, long attr);
static PyObject *
-_curses_window_attroff(PyCursesWindowObject *self, PyObject *arg)
+_curses_window_attroff(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
long attr;
@@ -291,7 +291,7 @@ _curses_window_attroff(PyCursesWindowObject *self, PyObject *arg)
if (attr == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = _curses_window_attroff_impl(self, attr);
+ return_value = _curses_window_attroff_impl((PyCursesWindowObject *)self, attr);
exit:
return return_value;
@@ -310,7 +310,7 @@ static PyObject *
_curses_window_attron_impl(PyCursesWindowObject *self, long attr);
static PyObject *
-_curses_window_attron(PyCursesWindowObject *self, PyObject *arg)
+_curses_window_attron(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
long attr;
@@ -319,7 +319,7 @@ _curses_window_attron(PyCursesWindowObject *self, PyObject *arg)
if (attr == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = _curses_window_attron_impl(self, attr);
+ return_value = _curses_window_attron_impl((PyCursesWindowObject *)self, attr);
exit:
return return_value;
@@ -338,7 +338,7 @@ static PyObject *
_curses_window_attrset_impl(PyCursesWindowObject *self, long attr);
static PyObject *
-_curses_window_attrset(PyCursesWindowObject *self, PyObject *arg)
+_curses_window_attrset(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
long attr;
@@ -347,7 +347,7 @@ _curses_window_attrset(PyCursesWindowObject *self, PyObject *arg)
if (attr == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = _curses_window_attrset_impl(self, attr);
+ return_value = _curses_window_attrset_impl((PyCursesWindowObject *)self, attr);
exit:
return return_value;
@@ -372,7 +372,7 @@ _curses_window_bkgdset_impl(PyCursesWindowObject *self, PyObject *ch,
long attr);
static PyObject *
-_curses_window_bkgdset(PyCursesWindowObject *self, PyObject *const *args, Py_ssize_t nargs)
+_curses_window_bkgdset(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *ch;
@@ -390,7 +390,7 @@ _curses_window_bkgdset(PyCursesWindowObject *self, PyObject *const *args, Py_ssi
goto exit;
}
skip_optional:
- return_value = _curses_window_bkgdset_impl(self, ch, attr);
+ return_value = _curses_window_bkgdset_impl((PyCursesWindowObject *)self, ch, attr);
exit:
return return_value;
@@ -437,7 +437,7 @@ _curses_window_border_impl(PyCursesWindowObject *self, PyObject *ls,
PyObject *br);
static PyObject *
-_curses_window_border(PyCursesWindowObject *self, PyObject *const *args, Py_ssize_t nargs)
+_curses_window_border(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *ls = NULL;
@@ -485,7 +485,7 @@ _curses_window_border(PyCursesWindowObject *self, PyObject *const *args, Py_ssiz
}
br = args[7];
skip_optional:
- return_value = _curses_window_border_impl(self, ls, rs, ts, bs, tl, tr, bl, br);
+ return_value = _curses_window_border_impl((PyCursesWindowObject *)self, ls, rs, ts, bs, tl, tr, bl, br);
exit:
return return_value;
@@ -511,7 +511,7 @@ _curses_window_box_impl(PyCursesWindowObject *self, int group_right_1,
PyObject *verch, PyObject *horch);
static PyObject *
-_curses_window_box(PyCursesWindowObject *self, PyObject *args)
+_curses_window_box(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_right_1 = 0;
@@ -531,7 +531,7 @@ _curses_window_box(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.box requires 0 to 2 arguments");
goto exit;
}
- return_value = _curses_window_box_impl(self, group_right_1, verch, horch);
+ return_value = _curses_window_box_impl((PyCursesWindowObject *)self, group_right_1, verch, horch);
exit:
return return_value;
@@ -554,7 +554,7 @@ _curses_window_delch_impl(PyCursesWindowObject *self, int group_right_1,
int y, int x);
static PyObject *
-_curses_window_delch(PyCursesWindowObject *self, PyObject *args)
+_curses_window_delch(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_right_1 = 0;
@@ -574,7 +574,7 @@ _curses_window_delch(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.delch requires 0 to 2 arguments");
goto exit;
}
- return_value = _curses_window_delch_impl(self, group_right_1, y, x);
+ return_value = _curses_window_delch_impl((PyCursesWindowObject *)self, group_right_1, y, x);
exit:
return return_value;
@@ -605,7 +605,7 @@ _curses_window_derwin_impl(PyCursesWindowObject *self, int group_left_1,
int nlines, int ncols, int begin_y, int begin_x);
static PyObject *
-_curses_window_derwin(PyCursesWindowObject *self, PyObject *args)
+_curses_window_derwin(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_left_1 = 0;
@@ -630,7 +630,7 @@ _curses_window_derwin(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.derwin requires 2 to 4 arguments");
goto exit;
}
- return_value = _curses_window_derwin_impl(self, group_left_1, nlines, ncols, begin_y, begin_x);
+ return_value = _curses_window_derwin_impl((PyCursesWindowObject *)self, group_left_1, nlines, ncols, begin_y, begin_x);
exit:
return return_value;
@@ -655,7 +655,7 @@ _curses_window_echochar_impl(PyCursesWindowObject *self, PyObject *ch,
long attr);
static PyObject *
-_curses_window_echochar(PyCursesWindowObject *self, PyObject *const *args, Py_ssize_t nargs)
+_curses_window_echochar(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *ch;
@@ -673,7 +673,7 @@ _curses_window_echochar(PyCursesWindowObject *self, PyObject *const *args, Py_ss
goto exit;
}
skip_optional:
- return_value = _curses_window_echochar_impl(self, ch, attr);
+ return_value = _curses_window_echochar_impl((PyCursesWindowObject *)self, ch, attr);
exit:
return return_value;
@@ -699,7 +699,7 @@ static PyObject *
_curses_window_enclose_impl(PyCursesWindowObject *self, int y, int x);
static PyObject *
-_curses_window_enclose(PyCursesWindowObject *self, PyObject *const *args, Py_ssize_t nargs)
+_curses_window_enclose(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int y;
@@ -716,7 +716,7 @@ _curses_window_enclose(PyCursesWindowObject *self, PyObject *const *args, Py_ssi
if (x == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = _curses_window_enclose_impl(self, y, x);
+ return_value = _curses_window_enclose_impl((PyCursesWindowObject *)self, y, x);
exit:
return return_value;
@@ -737,12 +737,12 @@ static long
_curses_window_getbkgd_impl(PyCursesWindowObject *self);
static PyObject *
-_curses_window_getbkgd(PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored))
+_curses_window_getbkgd(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
long _return_value;
- _return_value = _curses_window_getbkgd_impl(self);
+ _return_value = _curses_window_getbkgd_impl((PyCursesWindowObject *)self);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -773,7 +773,7 @@ _curses_window_getch_impl(PyCursesWindowObject *self, int group_right_1,
int y, int x);
static PyObject *
-_curses_window_getch(PyCursesWindowObject *self, PyObject *args)
+_curses_window_getch(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_right_1 = 0;
@@ -794,7 +794,7 @@ _curses_window_getch(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.getch requires 0 to 2 arguments");
goto exit;
}
- _return_value = _curses_window_getch_impl(self, group_right_1, y, x);
+ _return_value = _curses_window_getch_impl((PyCursesWindowObject *)self, group_right_1, y, x);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -825,7 +825,7 @@ _curses_window_getkey_impl(PyCursesWindowObject *self, int group_right_1,
int y, int x);
static PyObject *
-_curses_window_getkey(PyCursesWindowObject *self, PyObject *args)
+_curses_window_getkey(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_right_1 = 0;
@@ -845,7 +845,7 @@ _curses_window_getkey(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.getkey requires 0 to 2 arguments");
goto exit;
}
- return_value = _curses_window_getkey_impl(self, group_right_1, y, x);
+ return_value = _curses_window_getkey_impl((PyCursesWindowObject *)self, group_right_1, y, x);
exit:
return return_value;
@@ -873,7 +873,7 @@ _curses_window_get_wch_impl(PyCursesWindowObject *self, int group_right_1,
int y, int x);
static PyObject *
-_curses_window_get_wch(PyCursesWindowObject *self, PyObject *args)
+_curses_window_get_wch(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_right_1 = 0;
@@ -893,7 +893,7 @@ _curses_window_get_wch(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.get_wch requires 0 to 2 arguments");
goto exit;
}
- return_value = _curses_window_get_wch_impl(self, group_right_1, y, x);
+ return_value = _curses_window_get_wch_impl((PyCursesWindowObject *)self, group_right_1, y, x);
exit:
return return_value;
@@ -925,7 +925,7 @@ _curses_window_hline_impl(PyCursesWindowObject *self, int group_left_1,
int group_right_1, long attr);
static PyObject *
-_curses_window_hline(PyCursesWindowObject *self, PyObject *args)
+_curses_window_hline(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_left_1 = 0;
@@ -965,7 +965,7 @@ _curses_window_hline(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.hline requires 2 to 5 arguments");
goto exit;
}
- return_value = _curses_window_hline_impl(self, group_left_1, y, x, ch, n, group_right_1, attr);
+ return_value = _curses_window_hline_impl((PyCursesWindowObject *)self, group_left_1, y, x, ch, n, group_right_1, attr);
exit:
return return_value;
@@ -996,7 +996,7 @@ _curses_window_insch_impl(PyCursesWindowObject *self, int group_left_1,
long attr);
static PyObject *
-_curses_window_insch(PyCursesWindowObject *self, PyObject *args)
+_curses_window_insch(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_left_1 = 0;
@@ -1035,7 +1035,7 @@ _curses_window_insch(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.insch requires 1 to 4 arguments");
goto exit;
}
- return_value = _curses_window_insch_impl(self, group_left_1, y, x, ch, group_right_1, attr);
+ return_value = _curses_window_insch_impl((PyCursesWindowObject *)self, group_left_1, y, x, ch, group_right_1, attr);
exit:
return return_value;
@@ -1060,7 +1060,7 @@ _curses_window_inch_impl(PyCursesWindowObject *self, int group_right_1,
int y, int x);
static PyObject *
-_curses_window_inch(PyCursesWindowObject *self, PyObject *args)
+_curses_window_inch(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_right_1 = 0;
@@ -1081,7 +1081,7 @@ _curses_window_inch(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.inch requires 0 to 2 arguments");
goto exit;
}
- _return_value = _curses_window_inch_impl(self, group_right_1, y, x);
+ _return_value = _curses_window_inch_impl((PyCursesWindowObject *)self, group_right_1, y, x);
if ((_return_value == (unsigned long)-1) && PyErr_Occurred()) {
goto exit;
}
@@ -1119,7 +1119,7 @@ _curses_window_insstr_impl(PyCursesWindowObject *self, int group_left_1,
long attr);
static PyObject *
-_curses_window_insstr(PyCursesWindowObject *self, PyObject *args)
+_curses_window_insstr(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_left_1 = 0;
@@ -1158,7 +1158,7 @@ _curses_window_insstr(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.insstr requires 1 to 4 arguments");
goto exit;
}
- return_value = _curses_window_insstr_impl(self, group_left_1, y, x, str, group_right_1, attr);
+ return_value = _curses_window_insstr_impl((PyCursesWindowObject *)self, group_left_1, y, x, str, group_right_1, attr);
exit:
return return_value;
@@ -1195,7 +1195,7 @@ _curses_window_insnstr_impl(PyCursesWindowObject *self, int group_left_1,
int group_right_1, long attr);
static PyObject *
-_curses_window_insnstr(PyCursesWindowObject *self, PyObject *args)
+_curses_window_insnstr(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_left_1 = 0;
@@ -1235,7 +1235,7 @@ _curses_window_insnstr(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.insnstr requires 2 to 5 arguments");
goto exit;
}
- return_value = _curses_window_insnstr_impl(self, group_left_1, y, x, str, n, group_right_1, attr);
+ return_value = _curses_window_insnstr_impl((PyCursesWindowObject *)self, group_left_1, y, x, str, n, group_right_1, attr);
exit:
return return_value;
@@ -1259,7 +1259,7 @@ static PyObject *
_curses_window_is_linetouched_impl(PyCursesWindowObject *self, int line);
static PyObject *
-_curses_window_is_linetouched(PyCursesWindowObject *self, PyObject *arg)
+_curses_window_is_linetouched(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int line;
@@ -1268,7 +1268,7 @@ _curses_window_is_linetouched(PyCursesWindowObject *self, PyObject *arg)
if (line == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = _curses_window_is_linetouched_impl(self, line);
+ return_value = _curses_window_is_linetouched_impl((PyCursesWindowObject *)self, line);
exit:
return return_value;
@@ -1294,7 +1294,7 @@ _curses_window_noutrefresh_impl(PyCursesWindowObject *self,
int smaxcol);
static PyObject *
-_curses_window_noutrefresh(PyCursesWindowObject *self, PyObject *args)
+_curses_window_noutrefresh(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_right_1 = 0;
@@ -1318,7 +1318,7 @@ _curses_window_noutrefresh(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.noutrefresh requires 0 to 6 arguments");
goto exit;
}
- return_value = _curses_window_noutrefresh_impl(self, group_right_1, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol);
+ return_value = _curses_window_noutrefresh_impl((PyCursesWindowObject *)self, group_right_1, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol);
exit:
return return_value;
@@ -1345,9 +1345,9 @@ static PyObject *
_curses_window_noutrefresh_impl(PyCursesWindowObject *self);
static PyObject *
-_curses_window_noutrefresh(PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored))
+_curses_window_noutrefresh(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _curses_window_noutrefresh_impl(self);
+ return _curses_window_noutrefresh_impl((PyCursesWindowObject *)self);
}
#endif /* !defined(py_is_pad) */
@@ -1375,7 +1375,7 @@ _curses_window_overlay_impl(PyCursesWindowObject *self,
int dmincol, int dmaxrow, int dmaxcol);
static PyObject *
-_curses_window_overlay(PyCursesWindowObject *self, PyObject *args)
+_curses_window_overlay(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
PyCursesWindowObject *destwin;
@@ -1403,7 +1403,7 @@ _curses_window_overlay(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.overlay requires 1 to 7 arguments");
goto exit;
}
- return_value = _curses_window_overlay_impl(self, destwin, group_right_1, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol);
+ return_value = _curses_window_overlay_impl((PyCursesWindowObject *)self, destwin, group_right_1, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol);
exit:
return return_value;
@@ -1434,7 +1434,7 @@ _curses_window_overwrite_impl(PyCursesWindowObject *self,
int dmaxcol);
static PyObject *
-_curses_window_overwrite(PyCursesWindowObject *self, PyObject *args)
+_curses_window_overwrite(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
PyCursesWindowObject *destwin;
@@ -1462,7 +1462,7 @@ _curses_window_overwrite(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.overwrite requires 1 to 7 arguments");
goto exit;
}
- return_value = _curses_window_overwrite_impl(self, destwin, group_right_1, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol);
+ return_value = _curses_window_overwrite_impl((PyCursesWindowObject *)self, destwin, group_right_1, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol);
exit:
return return_value;
@@ -1499,7 +1499,7 @@ static PyObject *
_curses_window_redrawln_impl(PyCursesWindowObject *self, int beg, int num);
static PyObject *
-_curses_window_redrawln(PyCursesWindowObject *self, PyObject *const *args, Py_ssize_t nargs)
+_curses_window_redrawln(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int beg;
@@ -1516,7 +1516,7 @@ _curses_window_redrawln(PyCursesWindowObject *self, PyObject *const *args, Py_ss
if (num == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = _curses_window_redrawln_impl(self, beg, num);
+ return_value = _curses_window_redrawln_impl((PyCursesWindowObject *)self, beg, num);
exit:
return return_value;
@@ -1547,7 +1547,7 @@ _curses_window_refresh_impl(PyCursesWindowObject *self, int group_right_1,
int smincol, int smaxrow, int smaxcol);
static PyObject *
-_curses_window_refresh(PyCursesWindowObject *self, PyObject *args)
+_curses_window_refresh(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_right_1 = 0;
@@ -1571,7 +1571,7 @@ _curses_window_refresh(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.refresh requires 0 to 6 arguments");
goto exit;
}
- return_value = _curses_window_refresh_impl(self, group_right_1, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol);
+ return_value = _curses_window_refresh_impl((PyCursesWindowObject *)self, group_right_1, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol);
exit:
return return_value;
@@ -1598,7 +1598,7 @@ _curses_window_setscrreg_impl(PyCursesWindowObject *self, int top,
int bottom);
static PyObject *
-_curses_window_setscrreg(PyCursesWindowObject *self, PyObject *const *args, Py_ssize_t nargs)
+_curses_window_setscrreg(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int top;
@@ -1615,7 +1615,7 @@ _curses_window_setscrreg(PyCursesWindowObject *self, PyObject *const *args, Py_s
if (bottom == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = _curses_window_setscrreg_impl(self, top, bottom);
+ return_value = _curses_window_setscrreg_impl((PyCursesWindowObject *)self, top, bottom);
exit:
return return_value;
@@ -1645,7 +1645,7 @@ _curses_window_subwin_impl(PyCursesWindowObject *self, int group_left_1,
int nlines, int ncols, int begin_y, int begin_x);
static PyObject *
-_curses_window_subwin(PyCursesWindowObject *self, PyObject *args)
+_curses_window_subwin(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_left_1 = 0;
@@ -1670,7 +1670,7 @@ _curses_window_subwin(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.subwin requires 2 to 4 arguments");
goto exit;
}
- return_value = _curses_window_subwin_impl(self, group_left_1, nlines, ncols, begin_y, begin_x);
+ return_value = _curses_window_subwin_impl((PyCursesWindowObject *)self, group_left_1, nlines, ncols, begin_y, begin_x);
exit:
return return_value;
@@ -1693,7 +1693,7 @@ _curses_window_scroll_impl(PyCursesWindowObject *self, int group_right_1,
int lines);
static PyObject *
-_curses_window_scroll(PyCursesWindowObject *self, PyObject *args)
+_curses_window_scroll(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_right_1 = 0;
@@ -1712,7 +1712,7 @@ _curses_window_scroll(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.scroll requires 0 to 1 arguments");
goto exit;
}
- return_value = _curses_window_scroll_impl(self, group_right_1, lines);
+ return_value = _curses_window_scroll_impl((PyCursesWindowObject *)self, group_right_1, lines);
exit:
return return_value;
@@ -1733,7 +1733,7 @@ _curses_window_touchline_impl(PyCursesWindowObject *self, int start,
int count, int group_right_1, int changed);
static PyObject *
-_curses_window_touchline(PyCursesWindowObject *self, PyObject *args)
+_curses_window_touchline(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int start;
@@ -1757,7 +1757,7 @@ _curses_window_touchline(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.touchline requires 2 to 3 arguments");
goto exit;
}
- return_value = _curses_window_touchline_impl(self, start, count, group_right_1, changed);
+ return_value = _curses_window_touchline_impl((PyCursesWindowObject *)self, start, count, group_right_1, changed);
exit:
return return_value;
@@ -1787,7 +1787,7 @@ _curses_window_vline_impl(PyCursesWindowObject *self, int group_left_1,
int group_right_1, long attr);
static PyObject *
-_curses_window_vline(PyCursesWindowObject *self, PyObject *args)
+_curses_window_vline(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int group_left_1 = 0;
@@ -1827,7 +1827,7 @@ _curses_window_vline(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "_curses.window.vline requires 2 to 5 arguments");
goto exit;
}
- return_value = _curses_window_vline_impl(self, group_left_1, y, x, ch, n, group_right_1, attr);
+ return_value = _curses_window_vline_impl((PyCursesWindowObject *)self, group_left_1, y, x, ch, n, group_right_1, attr);
exit:
return return_value;
@@ -4379,4 +4379,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=26fe38c09ff8ca44 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c4211865ed96c2af input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_datetimemodule.c.h b/Modules/clinic/_datetimemodule.c.h
index 72c230fc8aee68..8f33c9e7d4eae5 100644
--- a/Modules/clinic/_datetimemodule.c.h
+++ b/Modules/clinic/_datetimemodule.c.h
@@ -97,7 +97,7 @@ datetime_date_replace_impl(PyDateTime_Date *self, int year, int month,
int day);
static PyObject *
-datetime_date_replace(PyDateTime_Date *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+datetime_date_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -162,7 +162,7 @@ datetime_date_replace(PyDateTime_Date *self, PyObject *const *args, Py_ssize_t n
goto exit;
}
skip_optional_pos:
- return_value = datetime_date_replace_impl(self, year, month, day);
+ return_value = datetime_date_replace_impl((PyDateTime_Date *)self, year, month, day);
exit:
return return_value;
@@ -184,7 +184,7 @@ datetime_time_replace_impl(PyDateTime_Time *self, int hour, int minute,
int fold);
static PyObject *
-datetime_time_replace(PyDateTime_Time *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+datetime_time_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -218,7 +218,7 @@ datetime_time_replace(PyDateTime_Time *self, PyObject *const *args, Py_ssize_t n
int minute = TIME_GET_MINUTE(self);
int second = TIME_GET_SECOND(self);
int microsecond = TIME_GET_MICROSECOND(self);
- PyObject *tzinfo = HASTZINFO(self) ? self->tzinfo : Py_None;
+ PyObject *tzinfo = HASTZINFO(self) ? ((PyDateTime_Time *)self)->tzinfo : Py_None;
int fold = TIME_GET_FOLD(self);
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
@@ -280,7 +280,7 @@ datetime_time_replace(PyDateTime_Time *self, PyObject *const *args, Py_ssize_t n
goto exit;
}
skip_optional_kwonly:
- return_value = datetime_time_replace_impl(self, hour, minute, second, microsecond, tzinfo, fold);
+ return_value = datetime_time_replace_impl((PyDateTime_Time *)self, hour, minute, second, microsecond, tzinfo, fold);
exit:
return return_value;
@@ -370,7 +370,7 @@ datetime_datetime_replace_impl(PyDateTime_DateTime *self, int year,
int fold);
static PyObject *
-datetime_datetime_replace(PyDateTime_DateTime *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+datetime_datetime_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -407,7 +407,7 @@ datetime_datetime_replace(PyDateTime_DateTime *self, PyObject *const *args, Py_s
int minute = DATE_GET_MINUTE(self);
int second = DATE_GET_SECOND(self);
int microsecond = DATE_GET_MICROSECOND(self);
- PyObject *tzinfo = HASTZINFO(self) ? self->tzinfo : Py_None;
+ PyObject *tzinfo = HASTZINFO(self) ? ((PyDateTime_DateTime *)self)->tzinfo : Py_None;
int fold = DATE_GET_FOLD(self);
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
@@ -496,9 +496,9 @@ datetime_datetime_replace(PyDateTime_DateTime *self, PyObject *const *args, Py_s
goto exit;
}
skip_optional_kwonly:
- return_value = datetime_datetime_replace_impl(self, year, month, day, hour, minute, second, microsecond, tzinfo, fold);
+ return_value = datetime_datetime_replace_impl((PyDateTime_DateTime *)self, year, month, day, hour, minute, second, microsecond, tzinfo, fold);
exit:
return return_value;
}
-/*[clinic end generated code: output=203217a61ea14171 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8acf62fbc7328f79 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_dbmmodule.c.h b/Modules/clinic/_dbmmodule.c.h
index 4379b433db3738..5e503194408776 100644
--- a/Modules/clinic/_dbmmodule.c.h
+++ b/Modules/clinic/_dbmmodule.c.h
@@ -20,9 +20,9 @@ static PyObject *
_dbm_dbm_close_impl(dbmobject *self);
static PyObject *
-_dbm_dbm_close(dbmobject *self, PyObject *Py_UNUSED(ignored))
+_dbm_dbm_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _dbm_dbm_close_impl(self);
+ return _dbm_dbm_close_impl((dbmobject *)self);
}
PyDoc_STRVAR(_dbm_dbm_keys__doc__,
@@ -38,13 +38,13 @@ static PyObject *
_dbm_dbm_keys_impl(dbmobject *self, PyTypeObject *cls);
static PyObject *
-_dbm_dbm_keys(dbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_dbm_dbm_keys(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "keys() takes no arguments");
return NULL;
}
- return _dbm_dbm_keys_impl(self, cls);
+ return _dbm_dbm_keys_impl((dbmobject *)self, cls);
}
PyDoc_STRVAR(_dbm_dbm_get__doc__,
@@ -61,7 +61,7 @@ _dbm_dbm_get_impl(dbmobject *self, PyTypeObject *cls, const char *key,
Py_ssize_t key_length, PyObject *default_value);
static PyObject *
-_dbm_dbm_get(dbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_dbm_dbm_get(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -85,7 +85,7 @@ _dbm_dbm_get(dbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize
&key, &key_length, &default_value)) {
goto exit;
}
- return_value = _dbm_dbm_get_impl(self, cls, key, key_length, default_value);
+ return_value = _dbm_dbm_get_impl((dbmobject *)self, cls, key, key_length, default_value);
exit:
return return_value;
@@ -107,7 +107,7 @@ _dbm_dbm_setdefault_impl(dbmobject *self, PyTypeObject *cls, const char *key,
Py_ssize_t key_length, PyObject *default_value);
static PyObject *
-_dbm_dbm_setdefault(dbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_dbm_dbm_setdefault(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -131,7 +131,7 @@ _dbm_dbm_setdefault(dbmobject *self, PyTypeObject *cls, PyObject *const *args, P
&key, &key_length, &default_value)) {
goto exit;
}
- return_value = _dbm_dbm_setdefault_impl(self, cls, key, key_length, default_value);
+ return_value = _dbm_dbm_setdefault_impl((dbmobject *)self, cls, key, key_length, default_value);
exit:
return return_value;
@@ -150,13 +150,13 @@ static PyObject *
_dbm_dbm_clear_impl(dbmobject *self, PyTypeObject *cls);
static PyObject *
-_dbm_dbm_clear(dbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_dbm_dbm_clear(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "clear() takes no arguments");
return NULL;
}
- return _dbm_dbm_clear_impl(self, cls);
+ return _dbm_dbm_clear_impl((dbmobject *)self, cls);
}
PyDoc_STRVAR(dbmopen__doc__,
@@ -221,4 +221,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=f7d9a87d80a64278 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3b456118f231b160 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h
index 07045e72040664..78391887b615cf 100644
--- a/Modules/clinic/_elementtree.c.h
+++ b/Modules/clinic/_elementtree.c.h
@@ -22,7 +22,7 @@ _elementtree_Element_append_impl(ElementObject *self, PyTypeObject *cls,
PyObject *subelement);
static PyObject *
-_elementtree_Element_append(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_elementtree_Element_append(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -51,7 +51,7 @@ _elementtree_Element_append(ElementObject *self, PyTypeObject *cls, PyObject *co
goto exit;
}
subelement = args[0];
- return_value = _elementtree_Element_append_impl(self, cls, subelement);
+ return_value = _elementtree_Element_append_impl((ElementObject *)self, cls, subelement);
exit:
return return_value;
@@ -69,9 +69,9 @@ static PyObject *
_elementtree_Element_clear_impl(ElementObject *self);
static PyObject *
-_elementtree_Element_clear(ElementObject *self, PyObject *Py_UNUSED(ignored))
+_elementtree_Element_clear(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _elementtree_Element_clear_impl(self);
+ return _elementtree_Element_clear_impl((ElementObject *)self);
}
PyDoc_STRVAR(_elementtree_Element___copy____doc__,
@@ -86,13 +86,13 @@ static PyObject *
_elementtree_Element___copy___impl(ElementObject *self, PyTypeObject *cls);
static PyObject *
-_elementtree_Element___copy__(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_elementtree_Element___copy__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "__copy__() takes no arguments");
return NULL;
}
- return _elementtree_Element___copy___impl(self, cls);
+ return _elementtree_Element___copy___impl((ElementObject *)self, cls);
}
PyDoc_STRVAR(_elementtree_Element___deepcopy____doc__,
@@ -107,7 +107,7 @@ static PyObject *
_elementtree_Element___deepcopy___impl(ElementObject *self, PyObject *memo);
static PyObject *
-_elementtree_Element___deepcopy__(ElementObject *self, PyObject *arg)
+_elementtree_Element___deepcopy__(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
PyObject *memo;
@@ -117,7 +117,7 @@ _elementtree_Element___deepcopy__(ElementObject *self, PyObject *arg)
goto exit;
}
memo = arg;
- return_value = _elementtree_Element___deepcopy___impl(self, memo);
+ return_value = _elementtree_Element___deepcopy___impl((ElementObject *)self, memo);
exit:
return return_value;
@@ -135,12 +135,12 @@ static size_t
_elementtree_Element___sizeof___impl(ElementObject *self);
static PyObject *
-_elementtree_Element___sizeof__(ElementObject *self, PyObject *Py_UNUSED(ignored))
+_elementtree_Element___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
size_t _return_value;
- _return_value = _elementtree_Element___sizeof___impl(self);
+ _return_value = _elementtree_Element___sizeof___impl((ElementObject *)self);
if ((_return_value == (size_t)-1) && PyErr_Occurred()) {
goto exit;
}
@@ -162,9 +162,9 @@ static PyObject *
_elementtree_Element___getstate___impl(ElementObject *self);
static PyObject *
-_elementtree_Element___getstate__(ElementObject *self, PyObject *Py_UNUSED(ignored))
+_elementtree_Element___getstate__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _elementtree_Element___getstate___impl(self);
+ return _elementtree_Element___getstate___impl((ElementObject *)self);
}
PyDoc_STRVAR(_elementtree_Element___setstate____doc__,
@@ -180,7 +180,7 @@ _elementtree_Element___setstate___impl(ElementObject *self,
PyTypeObject *cls, PyObject *state);
static PyObject *
-_elementtree_Element___setstate__(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_elementtree_Element___setstate__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -205,7 +205,7 @@ _elementtree_Element___setstate__(ElementObject *self, PyTypeObject *cls, PyObje
goto exit;
}
state = args[0];
- return_value = _elementtree_Element___setstate___impl(self, cls, state);
+ return_value = _elementtree_Element___setstate___impl((ElementObject *)self, cls, state);
exit:
return return_value;
@@ -224,7 +224,7 @@ _elementtree_Element_extend_impl(ElementObject *self, PyTypeObject *cls,
PyObject *elements);
static PyObject *
-_elementtree_Element_extend(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_elementtree_Element_extend(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -249,7 +249,7 @@ _elementtree_Element_extend(ElementObject *self, PyTypeObject *cls, PyObject *co
goto exit;
}
elements = args[0];
- return_value = _elementtree_Element_extend_impl(self, cls, elements);
+ return_value = _elementtree_Element_extend_impl((ElementObject *)self, cls, elements);
exit:
return return_value;
@@ -268,7 +268,7 @@ _elementtree_Element_find_impl(ElementObject *self, PyTypeObject *cls,
PyObject *path, PyObject *namespaces);
static PyObject *
-_elementtree_Element_find(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_elementtree_Element_find(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -312,7 +312,7 @@ _elementtree_Element_find(ElementObject *self, PyTypeObject *cls, PyObject *cons
}
namespaces = args[1];
skip_optional_pos:
- return_value = _elementtree_Element_find_impl(self, cls, path, namespaces);
+ return_value = _elementtree_Element_find_impl((ElementObject *)self, cls, path, namespaces);
exit:
return return_value;
@@ -332,7 +332,7 @@ _elementtree_Element_findtext_impl(ElementObject *self, PyTypeObject *cls,
PyObject *namespaces);
static PyObject *
-_elementtree_Element_findtext(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_elementtree_Element_findtext(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -383,7 +383,7 @@ _elementtree_Element_findtext(ElementObject *self, PyTypeObject *cls, PyObject *
}
namespaces = args[2];
skip_optional_pos:
- return_value = _elementtree_Element_findtext_impl(self, cls, path, default_value, namespaces);
+ return_value = _elementtree_Element_findtext_impl((ElementObject *)self, cls, path, default_value, namespaces);
exit:
return return_value;
@@ -402,7 +402,7 @@ _elementtree_Element_findall_impl(ElementObject *self, PyTypeObject *cls,
PyObject *path, PyObject *namespaces);
static PyObject *
-_elementtree_Element_findall(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_elementtree_Element_findall(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -446,7 +446,7 @@ _elementtree_Element_findall(ElementObject *self, PyTypeObject *cls, PyObject *c
}
namespaces = args[1];
skip_optional_pos:
- return_value = _elementtree_Element_findall_impl(self, cls, path, namespaces);
+ return_value = _elementtree_Element_findall_impl((ElementObject *)self, cls, path, namespaces);
exit:
return return_value;
@@ -465,7 +465,7 @@ _elementtree_Element_iterfind_impl(ElementObject *self, PyTypeObject *cls,
PyObject *path, PyObject *namespaces);
static PyObject *
-_elementtree_Element_iterfind(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_elementtree_Element_iterfind(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -509,7 +509,7 @@ _elementtree_Element_iterfind(ElementObject *self, PyTypeObject *cls, PyObject *
}
namespaces = args[1];
skip_optional_pos:
- return_value = _elementtree_Element_iterfind_impl(self, cls, path, namespaces);
+ return_value = _elementtree_Element_iterfind_impl((ElementObject *)self, cls, path, namespaces);
exit:
return return_value;
@@ -528,7 +528,7 @@ _elementtree_Element_get_impl(ElementObject *self, PyObject *key,
PyObject *default_value);
static PyObject *
-_elementtree_Element_get(ElementObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_elementtree_Element_get(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -572,7 +572,7 @@ _elementtree_Element_get(ElementObject *self, PyObject *const *args, Py_ssize_t
}
default_value = args[1];
skip_optional_pos:
- return_value = _elementtree_Element_get_impl(self, key, default_value);
+ return_value = _elementtree_Element_get_impl((ElementObject *)self, key, default_value);
exit:
return return_value;
@@ -591,7 +591,7 @@ _elementtree_Element_iter_impl(ElementObject *self, PyTypeObject *cls,
PyObject *tag);
static PyObject *
-_elementtree_Element_iter(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_elementtree_Element_iter(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -633,7 +633,7 @@ _elementtree_Element_iter(ElementObject *self, PyTypeObject *cls, PyObject *cons
}
tag = args[0];
skip_optional_pos:
- return_value = _elementtree_Element_iter_impl(self, cls, tag);
+ return_value = _elementtree_Element_iter_impl((ElementObject *)self, cls, tag);
exit:
return return_value;
@@ -651,13 +651,13 @@ static PyObject *
_elementtree_Element_itertext_impl(ElementObject *self, PyTypeObject *cls);
static PyObject *
-_elementtree_Element_itertext(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_elementtree_Element_itertext(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "itertext() takes no arguments");
return NULL;
}
- return _elementtree_Element_itertext_impl(self, cls);
+ return _elementtree_Element_itertext_impl((ElementObject *)self, cls);
}
PyDoc_STRVAR(_elementtree_Element_insert__doc__,
@@ -673,7 +673,7 @@ _elementtree_Element_insert_impl(ElementObject *self, Py_ssize_t index,
PyObject *subelement);
static PyObject *
-_elementtree_Element_insert(ElementObject *self, PyObject *const *args, Py_ssize_t nargs)
+_elementtree_Element_insert(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t index;
@@ -699,7 +699,7 @@ _elementtree_Element_insert(ElementObject *self, PyObject *const *args, Py_ssize
goto exit;
}
subelement = args[1];
- return_value = _elementtree_Element_insert_impl(self, index, subelement);
+ return_value = _elementtree_Element_insert_impl((ElementObject *)self, index, subelement);
exit:
return return_value;
@@ -717,9 +717,9 @@ static PyObject *
_elementtree_Element_items_impl(ElementObject *self);
static PyObject *
-_elementtree_Element_items(ElementObject *self, PyObject *Py_UNUSED(ignored))
+_elementtree_Element_items(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _elementtree_Element_items_impl(self);
+ return _elementtree_Element_items_impl((ElementObject *)self);
}
PyDoc_STRVAR(_elementtree_Element_keys__doc__,
@@ -734,9 +734,9 @@ static PyObject *
_elementtree_Element_keys_impl(ElementObject *self);
static PyObject *
-_elementtree_Element_keys(ElementObject *self, PyObject *Py_UNUSED(ignored))
+_elementtree_Element_keys(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _elementtree_Element_keys_impl(self);
+ return _elementtree_Element_keys_impl((ElementObject *)self);
}
PyDoc_STRVAR(_elementtree_Element_makeelement__doc__,
@@ -752,7 +752,7 @@ _elementtree_Element_makeelement_impl(ElementObject *self, PyTypeObject *cls,
PyObject *tag, PyObject *attrib);
static PyObject *
-_elementtree_Element_makeelement(ElementObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_elementtree_Element_makeelement(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -783,7 +783,7 @@ _elementtree_Element_makeelement(ElementObject *self, PyTypeObject *cls, PyObjec
goto exit;
}
attrib = args[1];
- return_value = _elementtree_Element_makeelement_impl(self, cls, tag, attrib);
+ return_value = _elementtree_Element_makeelement_impl((ElementObject *)self, cls, tag, attrib);
exit:
return return_value;
@@ -801,7 +801,7 @@ static PyObject *
_elementtree_Element_remove_impl(ElementObject *self, PyObject *subelement);
static PyObject *
-_elementtree_Element_remove(ElementObject *self, PyObject *arg)
+_elementtree_Element_remove(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
PyObject *subelement;
@@ -811,7 +811,7 @@ _elementtree_Element_remove(ElementObject *self, PyObject *arg)
goto exit;
}
subelement = arg;
- return_value = _elementtree_Element_remove_impl(self, subelement);
+ return_value = _elementtree_Element_remove_impl((ElementObject *)self, subelement);
exit:
return return_value;
@@ -830,7 +830,7 @@ _elementtree_Element_set_impl(ElementObject *self, PyObject *key,
PyObject *value);
static PyObject *
-_elementtree_Element_set(ElementObject *self, PyObject *const *args, Py_ssize_t nargs)
+_elementtree_Element_set(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *key;
@@ -841,7 +841,7 @@ _elementtree_Element_set(ElementObject *self, PyObject *const *args, Py_ssize_t
}
key = args[0];
value = args[1];
- return_value = _elementtree_Element_set_impl(self, key, value);
+ return_value = _elementtree_Element_set_impl((ElementObject *)self, key, value);
exit:
return return_value;
@@ -1013,7 +1013,7 @@ _elementtree_TreeBuilder_pi_impl(TreeBuilderObject *self, PyObject *target,
PyObject *text);
static PyObject *
-_elementtree_TreeBuilder_pi(TreeBuilderObject *self, PyObject *const *args, Py_ssize_t nargs)
+_elementtree_TreeBuilder_pi(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *target;
@@ -1028,7 +1028,7 @@ _elementtree_TreeBuilder_pi(TreeBuilderObject *self, PyObject *const *args, Py_s
}
text = args[1];
skip_optional:
- return_value = _elementtree_TreeBuilder_pi_impl(self, target, text);
+ return_value = _elementtree_TreeBuilder_pi_impl((TreeBuilderObject *)self, target, text);
exit:
return return_value;
@@ -1046,9 +1046,9 @@ static PyObject *
_elementtree_TreeBuilder_close_impl(TreeBuilderObject *self);
static PyObject *
-_elementtree_TreeBuilder_close(TreeBuilderObject *self, PyObject *Py_UNUSED(ignored))
+_elementtree_TreeBuilder_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _elementtree_TreeBuilder_close_impl(self);
+ return _elementtree_TreeBuilder_close_impl((TreeBuilderObject *)self);
}
PyDoc_STRVAR(_elementtree_TreeBuilder_start__doc__,
@@ -1064,7 +1064,7 @@ _elementtree_TreeBuilder_start_impl(TreeBuilderObject *self, PyObject *tag,
PyObject *attrs);
static PyObject *
-_elementtree_TreeBuilder_start(TreeBuilderObject *self, PyObject *const *args, Py_ssize_t nargs)
+_elementtree_TreeBuilder_start(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *tag;
@@ -1079,7 +1079,7 @@ _elementtree_TreeBuilder_start(TreeBuilderObject *self, PyObject *const *args, P
goto exit;
}
attrs = args[1];
- return_value = _elementtree_TreeBuilder_start_impl(self, tag, attrs);
+ return_value = _elementtree_TreeBuilder_start_impl((TreeBuilderObject *)self, tag, attrs);
exit:
return return_value;
@@ -1176,9 +1176,9 @@ static PyObject *
_elementtree_XMLParser_close_impl(XMLParserObject *self);
static PyObject *
-_elementtree_XMLParser_close(XMLParserObject *self, PyObject *Py_UNUSED(ignored))
+_elementtree_XMLParser_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _elementtree_XMLParser_close_impl(self);
+ return _elementtree_XMLParser_close_impl((XMLParserObject *)self);
}
PyDoc_STRVAR(_elementtree_XMLParser_flush__doc__,
@@ -1193,9 +1193,9 @@ static PyObject *
_elementtree_XMLParser_flush_impl(XMLParserObject *self);
static PyObject *
-_elementtree_XMLParser_flush(XMLParserObject *self, PyObject *Py_UNUSED(ignored))
+_elementtree_XMLParser_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _elementtree_XMLParser_flush_impl(self);
+ return _elementtree_XMLParser_flush_impl((XMLParserObject *)self);
}
PyDoc_STRVAR(_elementtree_XMLParser_feed__doc__,
@@ -1228,7 +1228,7 @@ _elementtree_XMLParser__setevents_impl(XMLParserObject *self,
PyObject *events_to_report);
static PyObject *
-_elementtree_XMLParser__setevents(XMLParserObject *self, PyObject *const *args, Py_ssize_t nargs)
+_elementtree_XMLParser__setevents(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *events_queue;
@@ -1243,9 +1243,9 @@ _elementtree_XMLParser__setevents(XMLParserObject *self, PyObject *const *args,
}
events_to_report = args[1];
skip_optional:
- return_value = _elementtree_XMLParser__setevents_impl(self, events_queue, events_to_report);
+ return_value = _elementtree_XMLParser__setevents_impl((XMLParserObject *)self, events_queue, events_to_report);
exit:
return return_value;
}
-/*[clinic end generated code: output=b713bf59fd0fef9b input=a9049054013a1b77]*/
+/*[clinic end generated code: output=e5c758958f14f102 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_gdbmmodule.c.h b/Modules/clinic/_gdbmmodule.c.h
index bbf4365114c0aa..00950f18e53541 100644
--- a/Modules/clinic/_gdbmmodule.c.h
+++ b/Modules/clinic/_gdbmmodule.c.h
@@ -20,7 +20,7 @@ static PyObject *
_gdbm_gdbm_get_impl(gdbmobject *self, PyObject *key, PyObject *default_value);
static PyObject *
-_gdbm_gdbm_get(gdbmobject *self, PyObject *const *args, Py_ssize_t nargs)
+_gdbm_gdbm_get(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *key;
@@ -35,7 +35,7 @@ _gdbm_gdbm_get(gdbmobject *self, PyObject *const *args, Py_ssize_t nargs)
}
default_value = args[1];
skip_optional:
- return_value = _gdbm_gdbm_get_impl(self, key, default_value);
+ return_value = _gdbm_gdbm_get_impl((gdbmobject *)self, key, default_value);
exit:
return return_value;
@@ -55,7 +55,7 @@ _gdbm_gdbm_setdefault_impl(gdbmobject *self, PyObject *key,
PyObject *default_value);
static PyObject *
-_gdbm_gdbm_setdefault(gdbmobject *self, PyObject *const *args, Py_ssize_t nargs)
+_gdbm_gdbm_setdefault(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *key;
@@ -70,7 +70,7 @@ _gdbm_gdbm_setdefault(gdbmobject *self, PyObject *const *args, Py_ssize_t nargs)
}
default_value = args[1];
skip_optional:
- return_value = _gdbm_gdbm_setdefault_impl(self, key, default_value);
+ return_value = _gdbm_gdbm_setdefault_impl((gdbmobject *)self, key, default_value);
exit:
return return_value;
@@ -89,9 +89,9 @@ static PyObject *
_gdbm_gdbm_close_impl(gdbmobject *self);
static PyObject *
-_gdbm_gdbm_close(gdbmobject *self, PyObject *Py_UNUSED(ignored))
+_gdbm_gdbm_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _gdbm_gdbm_close_impl(self);
+ return _gdbm_gdbm_close_impl((gdbmobject *)self);
}
PyDoc_STRVAR(_gdbm_gdbm_keys__doc__,
@@ -107,13 +107,13 @@ static PyObject *
_gdbm_gdbm_keys_impl(gdbmobject *self, PyTypeObject *cls);
static PyObject *
-_gdbm_gdbm_keys(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_gdbm_gdbm_keys(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "keys() takes no arguments");
return NULL;
}
- return _gdbm_gdbm_keys_impl(self, cls);
+ return _gdbm_gdbm_keys_impl((gdbmobject *)self, cls);
}
PyDoc_STRVAR(_gdbm_gdbm_firstkey__doc__,
@@ -133,13 +133,13 @@ static PyObject *
_gdbm_gdbm_firstkey_impl(gdbmobject *self, PyTypeObject *cls);
static PyObject *
-_gdbm_gdbm_firstkey(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_gdbm_gdbm_firstkey(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "firstkey() takes no arguments");
return NULL;
}
- return _gdbm_gdbm_firstkey_impl(self, cls);
+ return _gdbm_gdbm_firstkey_impl((gdbmobject *)self, cls);
}
PyDoc_STRVAR(_gdbm_gdbm_nextkey__doc__,
@@ -164,7 +164,7 @@ _gdbm_gdbm_nextkey_impl(gdbmobject *self, PyTypeObject *cls, const char *key,
Py_ssize_t key_length);
static PyObject *
-_gdbm_gdbm_nextkey(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_gdbm_gdbm_nextkey(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -187,7 +187,7 @@ _gdbm_gdbm_nextkey(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, P
&key, &key_length)) {
goto exit;
}
- return_value = _gdbm_gdbm_nextkey_impl(self, cls, key, key_length);
+ return_value = _gdbm_gdbm_nextkey_impl((gdbmobject *)self, cls, key, key_length);
exit:
return return_value;
@@ -212,13 +212,13 @@ static PyObject *
_gdbm_gdbm_reorganize_impl(gdbmobject *self, PyTypeObject *cls);
static PyObject *
-_gdbm_gdbm_reorganize(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_gdbm_gdbm_reorganize(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "reorganize() takes no arguments");
return NULL;
}
- return _gdbm_gdbm_reorganize_impl(self, cls);
+ return _gdbm_gdbm_reorganize_impl((gdbmobject *)self, cls);
}
PyDoc_STRVAR(_gdbm_gdbm_sync__doc__,
@@ -237,13 +237,13 @@ static PyObject *
_gdbm_gdbm_sync_impl(gdbmobject *self, PyTypeObject *cls);
static PyObject *
-_gdbm_gdbm_sync(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_gdbm_gdbm_sync(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "sync() takes no arguments");
return NULL;
}
- return _gdbm_gdbm_sync_impl(self, cls);
+ return _gdbm_gdbm_sync_impl((gdbmobject *)self, cls);
}
PyDoc_STRVAR(_gdbm_gdbm_clear__doc__,
@@ -259,13 +259,13 @@ static PyObject *
_gdbm_gdbm_clear_impl(gdbmobject *self, PyTypeObject *cls);
static PyObject *
-_gdbm_gdbm_clear(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_gdbm_gdbm_clear(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "clear() takes no arguments");
return NULL;
}
- return _gdbm_gdbm_clear_impl(self, cls);
+ return _gdbm_gdbm_clear_impl((gdbmobject *)self, cls);
}
PyDoc_STRVAR(dbmopen__doc__,
@@ -343,4 +343,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=07bdeb4a8ecb328e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d974cb39e4ee5d67 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h
index f54f065f7d2b71..d219b80b791a66 100644
--- a/Modules/clinic/_hashopenssl.c.h
+++ b/Modules/clinic/_hashopenssl.c.h
@@ -22,9 +22,9 @@ static PyObject *
EVP_copy_impl(EVPobject *self);
static PyObject *
-EVP_copy(EVPobject *self, PyObject *Py_UNUSED(ignored))
+EVP_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return EVP_copy_impl(self);
+ return EVP_copy_impl((EVPobject *)self);
}
PyDoc_STRVAR(EVP_digest__doc__,
@@ -40,9 +40,9 @@ static PyObject *
EVP_digest_impl(EVPobject *self);
static PyObject *
-EVP_digest(EVPobject *self, PyObject *Py_UNUSED(ignored))
+EVP_digest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return EVP_digest_impl(self);
+ return EVP_digest_impl((EVPobject *)self);
}
PyDoc_STRVAR(EVP_hexdigest__doc__,
@@ -58,9 +58,9 @@ static PyObject *
EVP_hexdigest_impl(EVPobject *self);
static PyObject *
-EVP_hexdigest(EVPobject *self, PyObject *Py_UNUSED(ignored))
+EVP_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return EVP_hexdigest_impl(self);
+ return EVP_hexdigest_impl((EVPobject *)self);
}
PyDoc_STRVAR(EVP_update__doc__,
@@ -87,7 +87,7 @@ static PyObject *
EVPXOF_digest_impl(EVPobject *self, Py_ssize_t length);
static PyObject *
-EVPXOF_digest(EVPobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+EVPXOF_digest(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -135,7 +135,7 @@ EVPXOF_digest(EVPobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
}
length = ival;
}
- return_value = EVPXOF_digest_impl(self, length);
+ return_value = EVPXOF_digest_impl((EVPobject *)self, length);
exit:
return return_value;
@@ -158,7 +158,7 @@ static PyObject *
EVPXOF_hexdigest_impl(EVPobject *self, Py_ssize_t length);
static PyObject *
-EVPXOF_hexdigest(EVPobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+EVPXOF_hexdigest(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -206,7 +206,7 @@ EVPXOF_hexdigest(EVPobject *self, PyObject *const *args, Py_ssize_t nargs, PyObj
}
length = ival;
}
- return_value = EVPXOF_hexdigest_impl(self, length);
+ return_value = EVPXOF_hexdigest_impl((EVPobject *)self, length);
exit:
return return_value;
@@ -1634,9 +1634,9 @@ static PyObject *
_hashlib_HMAC_copy_impl(HMACobject *self);
static PyObject *
-_hashlib_HMAC_copy(HMACobject *self, PyObject *Py_UNUSED(ignored))
+_hashlib_HMAC_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _hashlib_HMAC_copy_impl(self);
+ return _hashlib_HMAC_copy_impl((HMACobject *)self);
}
PyDoc_STRVAR(_hashlib_HMAC_update__doc__,
@@ -1652,7 +1652,7 @@ static PyObject *
_hashlib_HMAC_update_impl(HMACobject *self, PyObject *msg);
static PyObject *
-_hashlib_HMAC_update(HMACobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_hashlib_HMAC_update(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1689,7 +1689,7 @@ _hashlib_HMAC_update(HMACobject *self, PyObject *const *args, Py_ssize_t nargs,
goto exit;
}
msg = args[0];
- return_value = _hashlib_HMAC_update_impl(self, msg);
+ return_value = _hashlib_HMAC_update_impl((HMACobject *)self, msg);
exit:
return return_value;
@@ -1708,9 +1708,9 @@ static PyObject *
_hashlib_HMAC_digest_impl(HMACobject *self);
static PyObject *
-_hashlib_HMAC_digest(HMACobject *self, PyObject *Py_UNUSED(ignored))
+_hashlib_HMAC_digest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _hashlib_HMAC_digest_impl(self);
+ return _hashlib_HMAC_digest_impl((HMACobject *)self);
}
PyDoc_STRVAR(_hashlib_HMAC_hexdigest__doc__,
@@ -1729,9 +1729,9 @@ static PyObject *
_hashlib_HMAC_hexdigest_impl(HMACobject *self);
static PyObject *
-_hashlib_HMAC_hexdigest(HMACobject *self, PyObject *Py_UNUSED(ignored))
+_hashlib_HMAC_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _hashlib_HMAC_hexdigest_impl(self);
+ return _hashlib_HMAC_hexdigest_impl((HMACobject *)self);
}
PyDoc_STRVAR(_hashlib_get_fips_mode__doc__,
@@ -1844,4 +1844,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=c3ef67e4a573cc7a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=811a8b50beae1018 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_lsprof.c.h b/Modules/clinic/_lsprof.c.h
index e19840f97e5c69..6a75a8f9833d1e 100644
--- a/Modules/clinic/_lsprof.c.h
+++ b/Modules/clinic/_lsprof.c.h
@@ -43,13 +43,13 @@ static PyObject *
_lsprof_Profiler_getstats_impl(ProfilerObject *self, PyTypeObject *cls);
static PyObject *
-_lsprof_Profiler_getstats(ProfilerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_lsprof_Profiler_getstats(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "getstats() takes no arguments");
return NULL;
}
- return _lsprof_Profiler_getstats_impl(self, cls);
+ return _lsprof_Profiler_getstats_impl((ProfilerObject *)self, cls);
}
PyDoc_STRVAR(_lsprof_Profiler__pystart_callback__doc__,
@@ -65,7 +65,7 @@ _lsprof_Profiler__pystart_callback_impl(ProfilerObject *self, PyObject *code,
PyObject *instruction_offset);
static PyObject *
-_lsprof_Profiler__pystart_callback(ProfilerObject *self, PyObject *const *args, Py_ssize_t nargs)
+_lsprof_Profiler__pystart_callback(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *code;
@@ -76,7 +76,7 @@ _lsprof_Profiler__pystart_callback(ProfilerObject *self, PyObject *const *args,
}
code = args[0];
instruction_offset = args[1];
- return_value = _lsprof_Profiler__pystart_callback_impl(self, code, instruction_offset);
+ return_value = _lsprof_Profiler__pystart_callback_impl((ProfilerObject *)self, code, instruction_offset);
exit:
return return_value;
@@ -97,7 +97,7 @@ _lsprof_Profiler__pyreturn_callback_impl(ProfilerObject *self,
PyObject *retval);
static PyObject *
-_lsprof_Profiler__pyreturn_callback(ProfilerObject *self, PyObject *const *args, Py_ssize_t nargs)
+_lsprof_Profiler__pyreturn_callback(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *code;
@@ -110,7 +110,7 @@ _lsprof_Profiler__pyreturn_callback(ProfilerObject *self, PyObject *const *args,
code = args[0];
instruction_offset = args[1];
retval = args[2];
- return_value = _lsprof_Profiler__pyreturn_callback_impl(self, code, instruction_offset, retval);
+ return_value = _lsprof_Profiler__pyreturn_callback_impl((ProfilerObject *)self, code, instruction_offset, retval);
exit:
return return_value;
@@ -130,7 +130,7 @@ _lsprof_Profiler__ccall_callback_impl(ProfilerObject *self, PyObject *code,
PyObject *callable, PyObject *self_arg);
static PyObject *
-_lsprof_Profiler__ccall_callback(ProfilerObject *self, PyObject *const *args, Py_ssize_t nargs)
+_lsprof_Profiler__ccall_callback(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *code;
@@ -145,7 +145,7 @@ _lsprof_Profiler__ccall_callback(ProfilerObject *self, PyObject *const *args, Py
instruction_offset = args[1];
callable = args[2];
self_arg = args[3];
- return_value = _lsprof_Profiler__ccall_callback_impl(self, code, instruction_offset, callable, self_arg);
+ return_value = _lsprof_Profiler__ccall_callback_impl((ProfilerObject *)self, code, instruction_offset, callable, self_arg);
exit:
return return_value;
@@ -167,7 +167,7 @@ _lsprof_Profiler__creturn_callback_impl(ProfilerObject *self, PyObject *code,
PyObject *self_arg);
static PyObject *
-_lsprof_Profiler__creturn_callback(ProfilerObject *self, PyObject *const *args, Py_ssize_t nargs)
+_lsprof_Profiler__creturn_callback(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *code;
@@ -182,7 +182,7 @@ _lsprof_Profiler__creturn_callback(ProfilerObject *self, PyObject *const *args,
instruction_offset = args[1];
callable = args[2];
self_arg = args[3];
- return_value = _lsprof_Profiler__creturn_callback_impl(self, code, instruction_offset, callable, self_arg);
+ return_value = _lsprof_Profiler__creturn_callback_impl((ProfilerObject *)self, code, instruction_offset, callable, self_arg);
exit:
return return_value;
@@ -209,7 +209,7 @@ _lsprof_Profiler_enable_impl(ProfilerObject *self, int subcalls,
int builtins);
static PyObject *
-_lsprof_Profiler_enable(ProfilerObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_lsprof_Profiler_enable(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -264,7 +264,7 @@ _lsprof_Profiler_enable(ProfilerObject *self, PyObject *const *args, Py_ssize_t
goto exit;
}
skip_optional_pos:
- return_value = _lsprof_Profiler_enable_impl(self, subcalls, builtins);
+ return_value = _lsprof_Profiler_enable_impl((ProfilerObject *)self, subcalls, builtins);
exit:
return return_value;
@@ -283,9 +283,9 @@ static PyObject *
_lsprof_Profiler_disable_impl(ProfilerObject *self);
static PyObject *
-_lsprof_Profiler_disable(ProfilerObject *self, PyObject *Py_UNUSED(ignored))
+_lsprof_Profiler_disable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _lsprof_Profiler_disable_impl(self);
+ return _lsprof_Profiler_disable_impl((ProfilerObject *)self);
}
PyDoc_STRVAR(_lsprof_Profiler_clear__doc__,
@@ -301,9 +301,9 @@ static PyObject *
_lsprof_Profiler_clear_impl(ProfilerObject *self);
static PyObject *
-_lsprof_Profiler_clear(ProfilerObject *self, PyObject *Py_UNUSED(ignored))
+_lsprof_Profiler_clear(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _lsprof_Profiler_clear_impl(self);
+ return _lsprof_Profiler_clear_impl((ProfilerObject *)self);
}
PyDoc_STRVAR(profiler_init__doc__,
@@ -407,4 +407,4 @@ profiler_init(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=e56d849e35d005a5 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d983dbf23fd8ac3b input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_lzmamodule.c.h b/Modules/clinic/_lzmamodule.c.h
index 187f7b183dca84..c7c81d8d1f1b9d 100644
--- a/Modules/clinic/_lzmamodule.c.h
+++ b/Modules/clinic/_lzmamodule.c.h
@@ -27,7 +27,7 @@ static PyObject *
_lzma_LZMACompressor_compress_impl(Compressor *self, Py_buffer *data);
static PyObject *
-_lzma_LZMACompressor_compress(Compressor *self, PyObject *arg)
+_lzma_LZMACompressor_compress(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer data = {NULL, NULL};
@@ -35,7 +35,7 @@ _lzma_LZMACompressor_compress(Compressor *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = _lzma_LZMACompressor_compress_impl(self, &data);
+ return_value = _lzma_LZMACompressor_compress_impl((Compressor *)self, &data);
exit:
/* Cleanup for data */
@@ -63,9 +63,9 @@ static PyObject *
_lzma_LZMACompressor_flush_impl(Compressor *self);
static PyObject *
-_lzma_LZMACompressor_flush(Compressor *self, PyObject *Py_UNUSED(ignored))
+_lzma_LZMACompressor_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _lzma_LZMACompressor_flush_impl(self);
+ return _lzma_LZMACompressor_flush_impl((Compressor *)self);
}
PyDoc_STRVAR(_lzma_LZMADecompressor_decompress__doc__,
@@ -95,7 +95,7 @@ _lzma_LZMADecompressor_decompress_impl(Decompressor *self, Py_buffer *data,
Py_ssize_t max_length);
static PyObject *
-_lzma_LZMADecompressor_decompress(Decompressor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_lzma_LZMADecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -152,7 +152,7 @@ _lzma_LZMADecompressor_decompress(Decompressor *self, PyObject *const *args, Py_
max_length = ival;
}
skip_optional_pos:
- return_value = _lzma_LZMADecompressor_decompress_impl(self, &data, max_length);
+ return_value = _lzma_LZMADecompressor_decompress_impl((Decompressor *)self, &data, max_length);
exit:
/* Cleanup for data */
@@ -329,4 +329,4 @@ _lzma__decode_filter_properties(PyObject *module, PyObject *const *args, Py_ssiz
return return_value;
}
-/*[clinic end generated code: output=52e1b68d0886cebb input=a9049054013a1b77]*/
+/*[clinic end generated code: output=19ed9b1182f5ddf9 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_pickle.c.h b/Modules/clinic/_pickle.c.h
index 2e84bb83e21ca6..91d355c5afb353 100644
--- a/Modules/clinic/_pickle.c.h
+++ b/Modules/clinic/_pickle.c.h
@@ -26,9 +26,9 @@ static PyObject *
_pickle_Pickler_clear_memo_impl(PicklerObject *self);
static PyObject *
-_pickle_Pickler_clear_memo(PicklerObject *self, PyObject *Py_UNUSED(ignored))
+_pickle_Pickler_clear_memo(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _pickle_Pickler_clear_memo_impl(self);
+ return _pickle_Pickler_clear_memo_impl((PicklerObject *)self);
}
PyDoc_STRVAR(_pickle_Pickler_dump__doc__,
@@ -45,7 +45,7 @@ _pickle_Pickler_dump_impl(PicklerObject *self, PyTypeObject *cls,
PyObject *obj);
static PyObject *
-_pickle_Pickler_dump(PicklerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_pickle_Pickler_dump(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -70,7 +70,7 @@ _pickle_Pickler_dump(PicklerObject *self, PyTypeObject *cls, PyObject *const *ar
goto exit;
}
obj = args[0];
- return_value = _pickle_Pickler_dump_impl(self, cls, obj);
+ return_value = _pickle_Pickler_dump_impl((PicklerObject *)self, cls, obj);
exit:
return return_value;
@@ -89,12 +89,12 @@ static size_t
_pickle_Pickler___sizeof___impl(PicklerObject *self);
static PyObject *
-_pickle_Pickler___sizeof__(PicklerObject *self, PyObject *Py_UNUSED(ignored))
+_pickle_Pickler___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
size_t _return_value;
- _return_value = _pickle_Pickler___sizeof___impl(self);
+ _return_value = _pickle_Pickler___sizeof___impl((PicklerObject *)self);
if ((_return_value == (size_t)-1) && PyErr_Occurred()) {
goto exit;
}
@@ -227,9 +227,9 @@ static PyObject *
_pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self);
static PyObject *
-_pickle_PicklerMemoProxy_clear(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
+_pickle_PicklerMemoProxy_clear(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _pickle_PicklerMemoProxy_clear_impl(self);
+ return _pickle_PicklerMemoProxy_clear_impl((PicklerMemoProxyObject *)self);
}
PyDoc_STRVAR(_pickle_PicklerMemoProxy_copy__doc__,
@@ -245,9 +245,9 @@ static PyObject *
_pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self);
static PyObject *
-_pickle_PicklerMemoProxy_copy(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
+_pickle_PicklerMemoProxy_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _pickle_PicklerMemoProxy_copy_impl(self);
+ return _pickle_PicklerMemoProxy_copy_impl((PicklerMemoProxyObject *)self);
}
PyDoc_STRVAR(_pickle_PicklerMemoProxy___reduce____doc__,
@@ -263,9 +263,9 @@ static PyObject *
_pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self);
static PyObject *
-_pickle_PicklerMemoProxy___reduce__(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
+_pickle_PicklerMemoProxy___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _pickle_PicklerMemoProxy___reduce___impl(self);
+ return _pickle_PicklerMemoProxy___reduce___impl((PicklerMemoProxyObject *)self);
}
PyDoc_STRVAR(_pickle_Unpickler_persistent_load__doc__,
@@ -281,7 +281,7 @@ _pickle_Unpickler_persistent_load_impl(UnpicklerObject *self,
PyTypeObject *cls, PyObject *pid);
static PyObject *
-_pickle_Unpickler_persistent_load(UnpicklerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_pickle_Unpickler_persistent_load(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -306,7 +306,7 @@ _pickle_Unpickler_persistent_load(UnpicklerObject *self, PyTypeObject *cls, PyOb
goto exit;
}
pid = args[0];
- return_value = _pickle_Unpickler_persistent_load_impl(self, cls, pid);
+ return_value = _pickle_Unpickler_persistent_load_impl((UnpicklerObject *)self, cls, pid);
exit:
return return_value;
@@ -329,13 +329,13 @@ static PyObject *
_pickle_Unpickler_load_impl(UnpicklerObject *self, PyTypeObject *cls);
static PyObject *
-_pickle_Unpickler_load(UnpicklerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_pickle_Unpickler_load(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "load() takes no arguments");
return NULL;
}
- return _pickle_Unpickler_load_impl(self, cls);
+ return _pickle_Unpickler_load_impl((UnpicklerObject *)self, cls);
}
PyDoc_STRVAR(_pickle_Unpickler_find_class__doc__,
@@ -360,7 +360,7 @@ _pickle_Unpickler_find_class_impl(UnpicklerObject *self, PyTypeObject *cls,
PyObject *global_name);
static PyObject *
-_pickle_Unpickler_find_class(UnpicklerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_pickle_Unpickler_find_class(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -387,7 +387,7 @@ _pickle_Unpickler_find_class(UnpicklerObject *self, PyTypeObject *cls, PyObject
}
module_name = args[0];
global_name = args[1];
- return_value = _pickle_Unpickler_find_class_impl(self, cls, module_name, global_name);
+ return_value = _pickle_Unpickler_find_class_impl((UnpicklerObject *)self, cls, module_name, global_name);
exit:
return return_value;
@@ -406,12 +406,12 @@ static size_t
_pickle_Unpickler___sizeof___impl(UnpicklerObject *self);
static PyObject *
-_pickle_Unpickler___sizeof__(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
+_pickle_Unpickler___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
size_t _return_value;
- _return_value = _pickle_Unpickler___sizeof___impl(self);
+ _return_value = _pickle_Unpickler___sizeof___impl((UnpicklerObject *)self);
if ((_return_value == (size_t)-1) && PyErr_Occurred()) {
goto exit;
}
@@ -566,9 +566,9 @@ static PyObject *
_pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self);
static PyObject *
-_pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
+_pickle_UnpicklerMemoProxy_clear(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _pickle_UnpicklerMemoProxy_clear_impl(self);
+ return _pickle_UnpicklerMemoProxy_clear_impl((UnpicklerMemoProxyObject *)self);
}
PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_copy__doc__,
@@ -584,9 +584,9 @@ static PyObject *
_pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self);
static PyObject *
-_pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
+_pickle_UnpicklerMemoProxy_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _pickle_UnpicklerMemoProxy_copy_impl(self);
+ return _pickle_UnpicklerMemoProxy_copy_impl((UnpicklerMemoProxyObject *)self);
}
PyDoc_STRVAR(_pickle_UnpicklerMemoProxy___reduce____doc__,
@@ -602,9 +602,9 @@ static PyObject *
_pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self);
static PyObject *
-_pickle_UnpicklerMemoProxy___reduce__(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
+_pickle_UnpicklerMemoProxy___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _pickle_UnpicklerMemoProxy___reduce___impl(self);
+ return _pickle_UnpicklerMemoProxy___reduce___impl((UnpicklerMemoProxyObject *)self);
}
PyDoc_STRVAR(_pickle_dump__doc__,
@@ -1086,4 +1086,4 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
exit:
return return_value;
}
-/*[clinic end generated code: output=48ceb6687a8e716c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d71dc73af298ebe8 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_queuemodule.c.h b/Modules/clinic/_queuemodule.c.h
index f0d4a3a164cd5f..2dfc3e6be1984e 100644
--- a/Modules/clinic/_queuemodule.c.h
+++ b/Modules/clinic/_queuemodule.c.h
@@ -55,7 +55,7 @@ _queue_SimpleQueue_put_impl(simplequeueobject *self, PyObject *item,
int block, PyObject *timeout);
static PyObject *
-_queue_SimpleQueue_put(simplequeueobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_queue_SimpleQueue_put(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -110,7 +110,7 @@ _queue_SimpleQueue_put(simplequeueobject *self, PyObject *const *args, Py_ssize_
timeout = args[2];
skip_optional_pos:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _queue_SimpleQueue_put_impl(self, item, block, timeout);
+ return_value = _queue_SimpleQueue_put_impl((simplequeueobject *)self, item, block, timeout);
Py_END_CRITICAL_SECTION();
exit:
@@ -133,7 +133,7 @@ static PyObject *
_queue_SimpleQueue_put_nowait_impl(simplequeueobject *self, PyObject *item);
static PyObject *
-_queue_SimpleQueue_put_nowait(simplequeueobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_queue_SimpleQueue_put_nowait(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -171,7 +171,7 @@ _queue_SimpleQueue_put_nowait(simplequeueobject *self, PyObject *const *args, Py
}
item = args[0];
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _queue_SimpleQueue_put_nowait_impl(self, item);
+ return_value = _queue_SimpleQueue_put_nowait_impl((simplequeueobject *)self, item);
Py_END_CRITICAL_SECTION();
exit:
@@ -200,7 +200,7 @@ _queue_SimpleQueue_get_impl(simplequeueobject *self, PyTypeObject *cls,
int block, PyObject *timeout_obj);
static PyObject *
-_queue_SimpleQueue_get(simplequeueobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_queue_SimpleQueue_get(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -253,7 +253,7 @@ _queue_SimpleQueue_get(simplequeueobject *self, PyTypeObject *cls, PyObject *con
timeout_obj = args[1];
skip_optional_pos:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _queue_SimpleQueue_get_impl(self, cls, block, timeout_obj);
+ return_value = _queue_SimpleQueue_get_impl((simplequeueobject *)self, cls, block, timeout_obj);
Py_END_CRITICAL_SECTION();
exit:
@@ -277,7 +277,7 @@ _queue_SimpleQueue_get_nowait_impl(simplequeueobject *self,
PyTypeObject *cls);
static PyObject *
-_queue_SimpleQueue_get_nowait(simplequeueobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_queue_SimpleQueue_get_nowait(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
@@ -286,7 +286,7 @@ _queue_SimpleQueue_get_nowait(simplequeueobject *self, PyTypeObject *cls, PyObje
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _queue_SimpleQueue_get_nowait_impl(self, cls);
+ return_value = _queue_SimpleQueue_get_nowait_impl((simplequeueobject *)self, cls);
Py_END_CRITICAL_SECTION();
exit:
@@ -306,13 +306,13 @@ static int
_queue_SimpleQueue_empty_impl(simplequeueobject *self);
static PyObject *
-_queue_SimpleQueue_empty(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
+_queue_SimpleQueue_empty(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
int _return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- _return_value = _queue_SimpleQueue_empty_impl(self);
+ _return_value = _queue_SimpleQueue_empty_impl((simplequeueobject *)self);
Py_END_CRITICAL_SECTION();
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
@@ -336,13 +336,13 @@ static Py_ssize_t
_queue_SimpleQueue_qsize_impl(simplequeueobject *self);
static PyObject *
-_queue_SimpleQueue_qsize(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
+_queue_SimpleQueue_qsize(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_ssize_t _return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- _return_value = _queue_SimpleQueue_qsize_impl(self);
+ _return_value = _queue_SimpleQueue_qsize_impl((simplequeueobject *)self);
Py_END_CRITICAL_SECTION();
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
@@ -352,4 +352,4 @@ _queue_SimpleQueue_qsize(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
exit:
return return_value;
}
-/*[clinic end generated code: output=07b5742dca7692d9 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=e04e15a1b959c700 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_randommodule.c.h b/Modules/clinic/_randommodule.c.h
index 6193acac67e7ac..b2d67e11c63595 100644
--- a/Modules/clinic/_randommodule.c.h
+++ b/Modules/clinic/_randommodule.c.h
@@ -18,12 +18,12 @@ static PyObject *
_random_Random_random_impl(RandomObject *self);
static PyObject *
-_random_Random_random(RandomObject *self, PyObject *Py_UNUSED(ignored))
+_random_Random_random(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _random_Random_random_impl(self);
+ return_value = _random_Random_random_impl((RandomObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -45,7 +45,7 @@ static PyObject *
_random_Random_seed_impl(RandomObject *self, PyObject *n);
static PyObject *
-_random_Random_seed(RandomObject *self, PyObject *const *args, Py_ssize_t nargs)
+_random_Random_seed(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *n = Py_None;
@@ -59,7 +59,7 @@ _random_Random_seed(RandomObject *self, PyObject *const *args, Py_ssize_t nargs)
n = args[0];
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _random_Random_seed_impl(self, n);
+ return_value = _random_Random_seed_impl((RandomObject *)self, n);
Py_END_CRITICAL_SECTION();
exit:
@@ -79,12 +79,12 @@ static PyObject *
_random_Random_getstate_impl(RandomObject *self);
static PyObject *
-_random_Random_getstate(RandomObject *self, PyObject *Py_UNUSED(ignored))
+_random_Random_getstate(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _random_Random_getstate_impl(self);
+ return_value = _random_Random_getstate_impl((RandomObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -108,7 +108,7 @@ _random_Random_setstate(RandomObject *self, PyObject *state)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _random_Random_setstate_impl(self, state);
+ return_value = _random_Random_setstate_impl((RandomObject *)self, state);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -127,7 +127,7 @@ static PyObject *
_random_Random_getrandbits_impl(RandomObject *self, int k);
static PyObject *
-_random_Random_getrandbits(RandomObject *self, PyObject *arg)
+_random_Random_getrandbits(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int k;
@@ -137,10 +137,10 @@ _random_Random_getrandbits(RandomObject *self, PyObject *arg)
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _random_Random_getrandbits_impl(self, k);
+ return_value = _random_Random_getrandbits_impl((RandomObject *)self, k);
Py_END_CRITICAL_SECTION();
exit:
return return_value;
}
-/*[clinic end generated code: output=bf49ece1d341b1b6 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=859cfbf59c133a4e input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h
index becdb9cc1831fa..73c5d304f1a141 100644
--- a/Modules/clinic/_ssl.c.h
+++ b/Modules/clinic/_ssl.c.h
@@ -21,12 +21,12 @@ static PyObject *
_ssl__SSLSocket_do_handshake_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_do_handshake(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLSocket_do_handshake(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_do_handshake_impl(self);
+ return_value = _ssl__SSLSocket_do_handshake_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -79,7 +79,7 @@ static PyObject *
_ssl__SSLSocket_getpeercert_impl(PySSLSocket *self, int binary_mode);
static PyObject *
-_ssl__SSLSocket_getpeercert(PySSLSocket *self, PyObject *const *args, Py_ssize_t nargs)
+_ssl__SSLSocket_getpeercert(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int binary_mode = 0;
@@ -96,7 +96,7 @@ _ssl__SSLSocket_getpeercert(PySSLSocket *self, PyObject *const *args, Py_ssize_t
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_getpeercert_impl(self, binary_mode);
+ return_value = _ssl__SSLSocket_getpeercert_impl((PySSLSocket *)self, binary_mode);
Py_END_CRITICAL_SECTION();
exit:
@@ -115,12 +115,12 @@ static PyObject *
_ssl__SSLSocket_get_verified_chain_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_get_verified_chain(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLSocket_get_verified_chain(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_get_verified_chain_impl(self);
+ return_value = _ssl__SSLSocket_get_verified_chain_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -138,12 +138,12 @@ static PyObject *
_ssl__SSLSocket_get_unverified_chain_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_get_unverified_chain(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLSocket_get_unverified_chain(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_get_unverified_chain_impl(self);
+ return_value = _ssl__SSLSocket_get_unverified_chain_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -161,12 +161,12 @@ static PyObject *
_ssl__SSLSocket_shared_ciphers_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_shared_ciphers(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLSocket_shared_ciphers(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_shared_ciphers_impl(self);
+ return_value = _ssl__SSLSocket_shared_ciphers_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -184,12 +184,12 @@ static PyObject *
_ssl__SSLSocket_cipher_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_cipher(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLSocket_cipher(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_cipher_impl(self);
+ return_value = _ssl__SSLSocket_cipher_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -207,12 +207,12 @@ static PyObject *
_ssl__SSLSocket_version_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_version(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLSocket_version(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_version_impl(self);
+ return_value = _ssl__SSLSocket_version_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -230,12 +230,12 @@ static PyObject *
_ssl__SSLSocket_selected_alpn_protocol_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_selected_alpn_protocol(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLSocket_selected_alpn_protocol(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_selected_alpn_protocol_impl(self);
+ return_value = _ssl__SSLSocket_selected_alpn_protocol_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -253,9 +253,9 @@ static PyObject *
_ssl__SSLSocket_compression_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_compression(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLSocket_compression(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _ssl__SSLSocket_compression_impl(self);
+ return _ssl__SSLSocket_compression_impl((PySSLSocket *)self);
}
PyDoc_STRVAR(_ssl__SSLSocket_context__doc__,
@@ -283,12 +283,12 @@ static PyObject *
_ssl__SSLSocket_context_get_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_context_get(PySSLSocket *self, void *Py_UNUSED(context))
+_ssl__SSLSocket_context_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_context_get_impl(self);
+ return_value = _ssl__SSLSocket_context_get_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -308,12 +308,12 @@ static int
_ssl__SSLSocket_context_set_impl(PySSLSocket *self, PyObject *value);
static int
-_ssl__SSLSocket_context_set(PySSLSocket *self, PyObject *value, void *Py_UNUSED(context))
+_ssl__SSLSocket_context_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_context_set_impl(self, value);
+ return_value = _ssl__SSLSocket_context_set_impl((PySSLSocket *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -340,12 +340,12 @@ static PyObject *
_ssl__SSLSocket_server_side_get_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_server_side_get(PySSLSocket *self, void *Py_UNUSED(context))
+_ssl__SSLSocket_server_side_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_server_side_get_impl(self);
+ return_value = _ssl__SSLSocket_server_side_get_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -372,12 +372,12 @@ static PyObject *
_ssl__SSLSocket_server_hostname_get_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_server_hostname_get(PySSLSocket *self, void *Py_UNUSED(context))
+_ssl__SSLSocket_server_hostname_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_server_hostname_get_impl(self);
+ return_value = _ssl__SSLSocket_server_hostname_get_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -406,12 +406,12 @@ static PyObject *
_ssl__SSLSocket_owner_get_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_owner_get(PySSLSocket *self, void *Py_UNUSED(context))
+_ssl__SSLSocket_owner_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_owner_get_impl(self);
+ return_value = _ssl__SSLSocket_owner_get_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -431,12 +431,12 @@ static int
_ssl__SSLSocket_owner_set_impl(PySSLSocket *self, PyObject *value);
static int
-_ssl__SSLSocket_owner_set(PySSLSocket *self, PyObject *value, void *Py_UNUSED(context))
+_ssl__SSLSocket_owner_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_owner_set_impl(self, value);
+ return_value = _ssl__SSLSocket_owner_set_impl((PySSLSocket *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -457,7 +457,7 @@ static PyObject *
_ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b);
static PyObject *
-_ssl__SSLSocket_write(PySSLSocket *self, PyObject *arg)
+_ssl__SSLSocket_write(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer b = {NULL, NULL};
@@ -466,7 +466,7 @@ _ssl__SSLSocket_write(PySSLSocket *self, PyObject *arg)
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_write_impl(self, &b);
+ return_value = _ssl__SSLSocket_write_impl((PySSLSocket *)self, &b);
Py_END_CRITICAL_SECTION();
exit:
@@ -491,12 +491,12 @@ static PyObject *
_ssl__SSLSocket_pending_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_pending(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLSocket_pending(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_pending_impl(self);
+ return_value = _ssl__SSLSocket_pending_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -514,7 +514,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
int group_right_1, Py_buffer *buffer);
static PyObject *
-_ssl__SSLSocket_read(PySSLSocket *self, PyObject *args)
+_ssl__SSLSocket_read(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
Py_ssize_t len;
@@ -538,7 +538,7 @@ _ssl__SSLSocket_read(PySSLSocket *self, PyObject *args)
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_read_impl(self, len, group_right_1, &buffer);
+ return_value = _ssl__SSLSocket_read_impl((PySSLSocket *)self, len, group_right_1, &buffer);
Py_END_CRITICAL_SECTION();
exit:
@@ -563,12 +563,12 @@ static PyObject *
_ssl__SSLSocket_shutdown_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_shutdown(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLSocket_shutdown(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_shutdown_impl(self);
+ return_value = _ssl__SSLSocket_shutdown_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -592,7 +592,7 @@ _ssl__SSLSocket_get_channel_binding_impl(PySSLSocket *self,
const char *cb_type);
static PyObject *
-_ssl__SSLSocket_get_channel_binding(PySSLSocket *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_ssl__SSLSocket_get_channel_binding(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -647,7 +647,7 @@ _ssl__SSLSocket_get_channel_binding(PySSLSocket *self, PyObject *const *args, Py
}
skip_optional_pos:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_get_channel_binding_impl(self, cb_type);
+ return_value = _ssl__SSLSocket_get_channel_binding_impl((PySSLSocket *)self, cb_type);
Py_END_CRITICAL_SECTION();
exit:
@@ -667,12 +667,12 @@ static PyObject *
_ssl__SSLSocket_verify_client_post_handshake_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_verify_client_post_handshake(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLSocket_verify_client_post_handshake(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_verify_client_post_handshake_impl(self);
+ return_value = _ssl__SSLSocket_verify_client_post_handshake_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -699,12 +699,12 @@ static PyObject *
_ssl__SSLSocket_session_get_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_session_get(PySSLSocket *self, void *Py_UNUSED(context))
+_ssl__SSLSocket_session_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_session_get_impl(self);
+ return_value = _ssl__SSLSocket_session_get_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -724,12 +724,12 @@ static int
_ssl__SSLSocket_session_set_impl(PySSLSocket *self, PyObject *value);
static int
-_ssl__SSLSocket_session_set(PySSLSocket *self, PyObject *value, void *Py_UNUSED(context))
+_ssl__SSLSocket_session_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_session_set_impl(self, value);
+ return_value = _ssl__SSLSocket_session_set_impl((PySSLSocket *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -756,12 +756,12 @@ static PyObject *
_ssl__SSLSocket_session_reused_get_impl(PySSLSocket *self);
static PyObject *
-_ssl__SSLSocket_session_reused_get(PySSLSocket *self, void *Py_UNUSED(context))
+_ssl__SSLSocket_session_reused_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLSocket_session_reused_get_impl(self);
+ return_value = _ssl__SSLSocket_session_reused_get_impl((PySSLSocket *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -808,7 +808,7 @@ static PyObject *
_ssl__SSLContext_set_ciphers_impl(PySSLContext *self, const char *cipherlist);
static PyObject *
-_ssl__SSLContext_set_ciphers(PySSLContext *self, PyObject *arg)
+_ssl__SSLContext_set_ciphers(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *cipherlist;
@@ -827,7 +827,7 @@ _ssl__SSLContext_set_ciphers(PySSLContext *self, PyObject *arg)
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_set_ciphers_impl(self, cipherlist);
+ return_value = _ssl__SSLContext_set_ciphers_impl((PySSLContext *)self, cipherlist);
Py_END_CRITICAL_SECTION();
exit:
@@ -846,12 +846,12 @@ static PyObject *
_ssl__SSLContext_get_ciphers_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_get_ciphers(PySSLContext *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLContext_get_ciphers(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_get_ciphers_impl(self);
+ return_value = _ssl__SSLContext_get_ciphers_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -870,7 +870,7 @@ _ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self,
Py_buffer *protos);
static PyObject *
-_ssl__SSLContext__set_alpn_protocols(PySSLContext *self, PyObject *arg)
+_ssl__SSLContext__set_alpn_protocols(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer protos = {NULL, NULL};
@@ -879,7 +879,7 @@ _ssl__SSLContext__set_alpn_protocols(PySSLContext *self, PyObject *arg)
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext__set_alpn_protocols_impl(self, &protos);
+ return_value = _ssl__SSLContext__set_alpn_protocols_impl((PySSLContext *)self, &protos);
Py_END_CRITICAL_SECTION();
exit:
@@ -905,12 +905,12 @@ static PyObject *
_ssl__SSLContext_verify_mode_get_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_verify_mode_get(PySSLContext *self, void *Py_UNUSED(context))
+_ssl__SSLContext_verify_mode_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_verify_mode_get_impl(self);
+ return_value = _ssl__SSLContext_verify_mode_get_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -930,12 +930,12 @@ static int
_ssl__SSLContext_verify_mode_set_impl(PySSLContext *self, PyObject *value);
static int
-_ssl__SSLContext_verify_mode_set(PySSLContext *self, PyObject *value, void *Py_UNUSED(context))
+_ssl__SSLContext_verify_mode_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_verify_mode_set_impl(self, value);
+ return_value = _ssl__SSLContext_verify_mode_set_impl((PySSLContext *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -955,12 +955,12 @@ static PyObject *
_ssl__SSLContext_verify_flags_get_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_verify_flags_get(PySSLContext *self, void *Py_UNUSED(context))
+_ssl__SSLContext_verify_flags_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_verify_flags_get_impl(self);
+ return_value = _ssl__SSLContext_verify_flags_get_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -980,12 +980,12 @@ static int
_ssl__SSLContext_verify_flags_set_impl(PySSLContext *self, PyObject *value);
static int
-_ssl__SSLContext_verify_flags_set(PySSLContext *self, PyObject *value, void *Py_UNUSED(context))
+_ssl__SSLContext_verify_flags_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_verify_flags_set_impl(self, value);
+ return_value = _ssl__SSLContext_verify_flags_set_impl((PySSLContext *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1005,12 +1005,12 @@ static PyObject *
_ssl__SSLContext_minimum_version_get_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_minimum_version_get(PySSLContext *self, void *Py_UNUSED(context))
+_ssl__SSLContext_minimum_version_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_minimum_version_get_impl(self);
+ return_value = _ssl__SSLContext_minimum_version_get_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1031,12 +1031,12 @@ _ssl__SSLContext_minimum_version_set_impl(PySSLContext *self,
PyObject *value);
static int
-_ssl__SSLContext_minimum_version_set(PySSLContext *self, PyObject *value, void *Py_UNUSED(context))
+_ssl__SSLContext_minimum_version_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_minimum_version_set_impl(self, value);
+ return_value = _ssl__SSLContext_minimum_version_set_impl((PySSLContext *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1056,12 +1056,12 @@ static PyObject *
_ssl__SSLContext_maximum_version_get_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_maximum_version_get(PySSLContext *self, void *Py_UNUSED(context))
+_ssl__SSLContext_maximum_version_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_maximum_version_get_impl(self);
+ return_value = _ssl__SSLContext_maximum_version_get_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1082,12 +1082,12 @@ _ssl__SSLContext_maximum_version_set_impl(PySSLContext *self,
PyObject *value);
static int
-_ssl__SSLContext_maximum_version_set(PySSLContext *self, PyObject *value, void *Py_UNUSED(context))
+_ssl__SSLContext_maximum_version_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_maximum_version_set_impl(self, value);
+ return_value = _ssl__SSLContext_maximum_version_set_impl((PySSLContext *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1114,12 +1114,12 @@ static PyObject *
_ssl__SSLContext_num_tickets_get_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_num_tickets_get(PySSLContext *self, void *Py_UNUSED(context))
+_ssl__SSLContext_num_tickets_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_num_tickets_get_impl(self);
+ return_value = _ssl__SSLContext_num_tickets_get_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1139,12 +1139,12 @@ static int
_ssl__SSLContext_num_tickets_set_impl(PySSLContext *self, PyObject *value);
static int
-_ssl__SSLContext_num_tickets_set(PySSLContext *self, PyObject *value, void *Py_UNUSED(context))
+_ssl__SSLContext_num_tickets_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_num_tickets_set_impl(self, value);
+ return_value = _ssl__SSLContext_num_tickets_set_impl((PySSLContext *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1171,12 +1171,12 @@ static PyObject *
_ssl__SSLContext_security_level_get_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_security_level_get(PySSLContext *self, void *Py_UNUSED(context))
+_ssl__SSLContext_security_level_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_security_level_get_impl(self);
+ return_value = _ssl__SSLContext_security_level_get_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1196,12 +1196,12 @@ static PyObject *
_ssl__SSLContext_options_get_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_options_get(PySSLContext *self, void *Py_UNUSED(context))
+_ssl__SSLContext_options_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_options_get_impl(self);
+ return_value = _ssl__SSLContext_options_get_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1221,12 +1221,12 @@ static int
_ssl__SSLContext_options_set_impl(PySSLContext *self, PyObject *value);
static int
-_ssl__SSLContext_options_set(PySSLContext *self, PyObject *value, void *Py_UNUSED(context))
+_ssl__SSLContext_options_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_options_set_impl(self, value);
+ return_value = _ssl__SSLContext_options_set_impl((PySSLContext *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1246,12 +1246,12 @@ static PyObject *
_ssl__SSLContext__host_flags_get_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext__host_flags_get(PySSLContext *self, void *Py_UNUSED(context))
+_ssl__SSLContext__host_flags_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext__host_flags_get_impl(self);
+ return_value = _ssl__SSLContext__host_flags_get_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1271,12 +1271,12 @@ static int
_ssl__SSLContext__host_flags_set_impl(PySSLContext *self, PyObject *value);
static int
-_ssl__SSLContext__host_flags_set(PySSLContext *self, PyObject *value, void *Py_UNUSED(context))
+_ssl__SSLContext__host_flags_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext__host_flags_set_impl(self, value);
+ return_value = _ssl__SSLContext__host_flags_set_impl((PySSLContext *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1296,12 +1296,12 @@ static PyObject *
_ssl__SSLContext_check_hostname_get_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_check_hostname_get(PySSLContext *self, void *Py_UNUSED(context))
+_ssl__SSLContext_check_hostname_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_check_hostname_get_impl(self);
+ return_value = _ssl__SSLContext_check_hostname_get_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1321,12 +1321,12 @@ static int
_ssl__SSLContext_check_hostname_set_impl(PySSLContext *self, PyObject *value);
static int
-_ssl__SSLContext_check_hostname_set(PySSLContext *self, PyObject *value, void *Py_UNUSED(context))
+_ssl__SSLContext_check_hostname_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_check_hostname_set_impl(self, value);
+ return_value = _ssl__SSLContext_check_hostname_set_impl((PySSLContext *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1346,12 +1346,12 @@ static PyObject *
_ssl__SSLContext_protocol_get_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_protocol_get(PySSLContext *self, void *Py_UNUSED(context))
+_ssl__SSLContext_protocol_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_protocol_get_impl(self);
+ return_value = _ssl__SSLContext_protocol_get_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1370,7 +1370,7 @@ _ssl__SSLContext_load_cert_chain_impl(PySSLContext *self, PyObject *certfile,
PyObject *keyfile, PyObject *password);
static PyObject *
-_ssl__SSLContext_load_cert_chain(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_ssl__SSLContext_load_cert_chain(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1422,7 +1422,7 @@ _ssl__SSLContext_load_cert_chain(PySSLContext *self, PyObject *const *args, Py_s
password = args[2];
skip_optional_pos:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_load_cert_chain_impl(self, certfile, keyfile, password);
+ return_value = _ssl__SSLContext_load_cert_chain_impl((PySSLContext *)self, certfile, keyfile, password);
Py_END_CRITICAL_SECTION();
exit:
@@ -1444,7 +1444,7 @@ _ssl__SSLContext_load_verify_locations_impl(PySSLContext *self,
PyObject *cadata);
static PyObject *
-_ssl__SSLContext_load_verify_locations(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_ssl__SSLContext_load_verify_locations(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1501,7 +1501,7 @@ _ssl__SSLContext_load_verify_locations(PySSLContext *self, PyObject *const *args
cadata = args[2];
skip_optional_pos:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_load_verify_locations_impl(self, cafile, capath, cadata);
+ return_value = _ssl__SSLContext_load_verify_locations_impl((PySSLContext *)self, cafile, capath, cadata);
Py_END_CRITICAL_SECTION();
exit:
@@ -1525,7 +1525,7 @@ _ssl__SSLContext_load_dh_params(PySSLContext *self, PyObject *filepath)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_load_dh_params_impl(self, filepath);
+ return_value = _ssl__SSLContext_load_dh_params_impl((PySSLContext *)self, filepath);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1546,7 +1546,7 @@ _ssl__SSLContext__wrap_socket_impl(PySSLContext *self, PyObject *sock,
PyObject *owner, PyObject *session);
static PyObject *
-_ssl__SSLContext__wrap_socket(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_ssl__SSLContext__wrap_socket(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1618,7 +1618,7 @@ _ssl__SSLContext__wrap_socket(PySSLContext *self, PyObject *const *args, Py_ssiz
session = args[4];
skip_optional_kwonly:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext__wrap_socket_impl(self, sock, server_side, hostname_obj, owner, session);
+ return_value = _ssl__SSLContext__wrap_socket_impl((PySSLContext *)self, sock, server_side, hostname_obj, owner, session);
Py_END_CRITICAL_SECTION();
exit:
@@ -1641,7 +1641,7 @@ _ssl__SSLContext__wrap_bio_impl(PySSLContext *self, PySSLMemoryBIO *incoming,
PyObject *session);
static PyObject *
-_ssl__SSLContext__wrap_bio(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_ssl__SSLContext__wrap_bio(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1719,7 +1719,7 @@ _ssl__SSLContext__wrap_bio(PySSLContext *self, PyObject *const *args, Py_ssize_t
session = args[5];
skip_optional_kwonly:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext__wrap_bio_impl(self, incoming, outgoing, server_side, hostname_obj, owner, session);
+ return_value = _ssl__SSLContext__wrap_bio_impl((PySSLContext *)self, incoming, outgoing, server_side, hostname_obj, owner, session);
Py_END_CRITICAL_SECTION();
exit:
@@ -1738,12 +1738,12 @@ static PyObject *
_ssl__SSLContext_session_stats_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_session_stats(PySSLContext *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLContext_session_stats(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_session_stats_impl(self);
+ return_value = _ssl__SSLContext_session_stats_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1761,12 +1761,12 @@ static PyObject *
_ssl__SSLContext_set_default_verify_paths_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_set_default_verify_paths(PySSLContext *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLContext_set_default_verify_paths(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_set_default_verify_paths_impl(self);
+ return_value = _ssl__SSLContext_set_default_verify_paths_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1789,7 +1789,7 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_set_ecdh_curve_impl(self, name);
+ return_value = _ssl__SSLContext_set_ecdh_curve_impl((PySSLContext *)self, name);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1821,12 +1821,12 @@ static PyObject *
_ssl__SSLContext_sni_callback_get_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_sni_callback_get(PySSLContext *self, void *Py_UNUSED(context))
+_ssl__SSLContext_sni_callback_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_sni_callback_get_impl(self);
+ return_value = _ssl__SSLContext_sni_callback_get_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1846,12 +1846,12 @@ static int
_ssl__SSLContext_sni_callback_set_impl(PySSLContext *self, PyObject *value);
static int
-_ssl__SSLContext_sni_callback_set(PySSLContext *self, PyObject *value, void *Py_UNUSED(context))
+_ssl__SSLContext_sni_callback_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
{
int return_value;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_sni_callback_set_impl(self, value);
+ return_value = _ssl__SSLContext_sni_callback_set_impl((PySSLContext *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1876,12 +1876,12 @@ static PyObject *
_ssl__SSLContext_cert_store_stats_impl(PySSLContext *self);
static PyObject *
-_ssl__SSLContext_cert_store_stats(PySSLContext *self, PyObject *Py_UNUSED(ignored))
+_ssl__SSLContext_cert_store_stats(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_cert_store_stats_impl(self);
+ return_value = _ssl__SSLContext_cert_store_stats_impl((PySSLContext *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1906,7 +1906,7 @@ static PyObject *
_ssl__SSLContext_get_ca_certs_impl(PySSLContext *self, int binary_form);
static PyObject *
-_ssl__SSLContext_get_ca_certs(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_ssl__SSLContext_get_ca_certs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1952,7 +1952,7 @@ _ssl__SSLContext_get_ca_certs(PySSLContext *self, PyObject *const *args, Py_ssiz
}
skip_optional_pos:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_get_ca_certs_impl(self, binary_form);
+ return_value = _ssl__SSLContext_get_ca_certs_impl((PySSLContext *)self, binary_form);
Py_END_CRITICAL_SECTION();
exit:
@@ -1972,7 +1972,7 @@ _ssl__SSLContext_set_psk_client_callback_impl(PySSLContext *self,
PyObject *callback);
static PyObject *
-_ssl__SSLContext_set_psk_client_callback(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_ssl__SSLContext_set_psk_client_callback(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -2010,7 +2010,7 @@ _ssl__SSLContext_set_psk_client_callback(PySSLContext *self, PyObject *const *ar
}
callback = args[0];
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_set_psk_client_callback_impl(self, callback);
+ return_value = _ssl__SSLContext_set_psk_client_callback_impl((PySSLContext *)self, callback);
Py_END_CRITICAL_SECTION();
exit:
@@ -2031,7 +2031,7 @@ _ssl__SSLContext_set_psk_server_callback_impl(PySSLContext *self,
const char *identity_hint);
static PyObject *
-_ssl__SSLContext_set_psk_server_callback(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_ssl__SSLContext_set_psk_server_callback(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -2093,7 +2093,7 @@ _ssl__SSLContext_set_psk_server_callback(PySSLContext *self, PyObject *const *ar
}
skip_optional_pos:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl__SSLContext_set_psk_server_callback_impl(self, callback, identity_hint);
+ return_value = _ssl__SSLContext_set_psk_server_callback_impl((PySSLContext *)self, callback, identity_hint);
Py_END_CRITICAL_SECTION();
exit:
@@ -2146,12 +2146,12 @@ static PyObject *
_ssl_MemoryBIO_pending_get_impl(PySSLMemoryBIO *self);
static PyObject *
-_ssl_MemoryBIO_pending_get(PySSLMemoryBIO *self, void *Py_UNUSED(context))
+_ssl_MemoryBIO_pending_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl_MemoryBIO_pending_get_impl(self);
+ return_value = _ssl_MemoryBIO_pending_get_impl((PySSLMemoryBIO *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -2178,12 +2178,12 @@ static PyObject *
_ssl_MemoryBIO_eof_get_impl(PySSLMemoryBIO *self);
static PyObject *
-_ssl_MemoryBIO_eof_get(PySSLMemoryBIO *self, void *Py_UNUSED(context))
+_ssl_MemoryBIO_eof_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl_MemoryBIO_eof_get_impl(self);
+ return_value = _ssl_MemoryBIO_eof_get_impl((PySSLMemoryBIO *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -2207,7 +2207,7 @@ static PyObject *
_ssl_MemoryBIO_read_impl(PySSLMemoryBIO *self, int len);
static PyObject *
-_ssl_MemoryBIO_read(PySSLMemoryBIO *self, PyObject *const *args, Py_ssize_t nargs)
+_ssl_MemoryBIO_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int len = -1;
@@ -2224,7 +2224,7 @@ _ssl_MemoryBIO_read(PySSLMemoryBIO *self, PyObject *const *args, Py_ssize_t narg
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl_MemoryBIO_read_impl(self, len);
+ return_value = _ssl_MemoryBIO_read_impl((PySSLMemoryBIO *)self, len);
Py_END_CRITICAL_SECTION();
exit:
@@ -2246,7 +2246,7 @@ static PyObject *
_ssl_MemoryBIO_write_impl(PySSLMemoryBIO *self, Py_buffer *b);
static PyObject *
-_ssl_MemoryBIO_write(PySSLMemoryBIO *self, PyObject *arg)
+_ssl_MemoryBIO_write(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer b = {NULL, NULL};
@@ -2255,7 +2255,7 @@ _ssl_MemoryBIO_write(PySSLMemoryBIO *self, PyObject *arg)
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl_MemoryBIO_write_impl(self, &b);
+ return_value = _ssl_MemoryBIO_write_impl((PySSLMemoryBIO *)self, &b);
Py_END_CRITICAL_SECTION();
exit:
@@ -2282,12 +2282,12 @@ static PyObject *
_ssl_MemoryBIO_write_eof_impl(PySSLMemoryBIO *self);
static PyObject *
-_ssl_MemoryBIO_write_eof(PySSLMemoryBIO *self, PyObject *Py_UNUSED(ignored))
+_ssl_MemoryBIO_write_eof(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl_MemoryBIO_write_eof_impl(self);
+ return_value = _ssl_MemoryBIO_write_eof_impl((PySSLMemoryBIO *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -2314,12 +2314,12 @@ static PyObject *
_ssl_SSLSession_time_get_impl(PySSLSession *self);
static PyObject *
-_ssl_SSLSession_time_get(PySSLSession *self, void *Py_UNUSED(context))
+_ssl_SSLSession_time_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl_SSLSession_time_get_impl(self);
+ return_value = _ssl_SSLSession_time_get_impl((PySSLSession *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -2346,12 +2346,12 @@ static PyObject *
_ssl_SSLSession_timeout_get_impl(PySSLSession *self);
static PyObject *
-_ssl_SSLSession_timeout_get(PySSLSession *self, void *Py_UNUSED(context))
+_ssl_SSLSession_timeout_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl_SSLSession_timeout_get_impl(self);
+ return_value = _ssl_SSLSession_timeout_get_impl((PySSLSession *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -2378,12 +2378,12 @@ static PyObject *
_ssl_SSLSession_ticket_lifetime_hint_get_impl(PySSLSession *self);
static PyObject *
-_ssl_SSLSession_ticket_lifetime_hint_get(PySSLSession *self, void *Py_UNUSED(context))
+_ssl_SSLSession_ticket_lifetime_hint_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl_SSLSession_ticket_lifetime_hint_get_impl(self);
+ return_value = _ssl_SSLSession_ticket_lifetime_hint_get_impl((PySSLSession *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -2410,12 +2410,12 @@ static PyObject *
_ssl_SSLSession_id_get_impl(PySSLSession *self);
static PyObject *
-_ssl_SSLSession_id_get(PySSLSession *self, void *Py_UNUSED(context))
+_ssl_SSLSession_id_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl_SSLSession_id_get_impl(self);
+ return_value = _ssl_SSLSession_id_get_impl((PySSLSession *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -2442,12 +2442,12 @@ static PyObject *
_ssl_SSLSession_has_ticket_get_impl(PySSLSession *self);
static PyObject *
-_ssl_SSLSession_has_ticket_get(PySSLSession *self, void *Py_UNUSED(context))
+_ssl_SSLSession_has_ticket_get(PyObject *self, void *Py_UNUSED(context))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = _ssl_SSLSession_has_ticket_get_impl(self);
+ return_value = _ssl_SSLSession_has_ticket_get_impl((PySSLSession *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -2878,4 +2878,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=e71f1ef621aead08 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=bededfb2b927bd41 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_struct.c.h b/Modules/clinic/_struct.c.h
index cfc2fe7fc1dd58..7cf179f7a69d55 100644
--- a/Modules/clinic/_struct.c.h
+++ b/Modules/clinic/_struct.c.h
@@ -87,7 +87,7 @@ static PyObject *
Struct_unpack_impl(PyStructObject *self, Py_buffer *buffer);
static PyObject *
-Struct_unpack(PyStructObject *self, PyObject *arg)
+Struct_unpack(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer buffer = {NULL, NULL};
@@ -95,7 +95,7 @@ Struct_unpack(PyStructObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = Struct_unpack_impl(self, &buffer);
+ return_value = Struct_unpack_impl((PyStructObject *)self, &buffer);
exit:
/* Cleanup for buffer */
@@ -127,7 +127,7 @@ Struct_unpack_from_impl(PyStructObject *self, Py_buffer *buffer,
Py_ssize_t offset);
static PyObject *
-Struct_unpack_from(PyStructObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+Struct_unpack_from(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -184,7 +184,7 @@ Struct_unpack_from(PyStructObject *self, PyObject *const *args, Py_ssize_t nargs
offset = ival;
}
skip_optional_pos:
- return_value = Struct_unpack_from_impl(self, &buffer, offset);
+ return_value = Struct_unpack_from_impl((PyStructObject *)self, &buffer, offset);
exit:
/* Cleanup for buffer */
@@ -439,4 +439,4 @@ iter_unpack(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
return return_value;
}
-/*[clinic end generated code: output=faff90f99c6bd09f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ec540c21be08e1d0 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_testmultiphase.c.h b/Modules/clinic/_testmultiphase.c.h
index 5a432a6f70386d..01c29c0753ae13 100644
--- a/Modules/clinic/_testmultiphase.c.h
+++ b/Modules/clinic/_testmultiphase.c.h
@@ -25,13 +25,13 @@ _testmultiphase_StateAccessType_get_defining_module_impl(StateAccessTypeObject *
PyTypeObject *cls);
static PyObject *
-_testmultiphase_StateAccessType_get_defining_module(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_testmultiphase_StateAccessType_get_defining_module(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "get_defining_module() takes no arguments");
return NULL;
}
- return _testmultiphase_StateAccessType_get_defining_module_impl(self, cls);
+ return _testmultiphase_StateAccessType_get_defining_module_impl((StateAccessTypeObject *)self, cls);
}
PyDoc_STRVAR(_testmultiphase_StateAccessType_getmodulebydef_bad_def__doc__,
@@ -48,13 +48,13 @@ _testmultiphase_StateAccessType_getmodulebydef_bad_def_impl(StateAccessTypeObjec
PyTypeObject *cls);
static PyObject *
-_testmultiphase_StateAccessType_getmodulebydef_bad_def(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_testmultiphase_StateAccessType_getmodulebydef_bad_def(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "getmodulebydef_bad_def() takes no arguments");
return NULL;
}
- return _testmultiphase_StateAccessType_getmodulebydef_bad_def_impl(self, cls);
+ return _testmultiphase_StateAccessType_getmodulebydef_bad_def_impl((StateAccessTypeObject *)self, cls);
}
PyDoc_STRVAR(_testmultiphase_StateAccessType_increment_count_clinic__doc__,
@@ -76,7 +76,7 @@ _testmultiphase_StateAccessType_increment_count_clinic_impl(StateAccessTypeObjec
int n, int twice);
static PyObject *
-_testmultiphase_StateAccessType_increment_count_clinic(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_testmultiphase_StateAccessType_increment_count_clinic(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -135,7 +135,7 @@ _testmultiphase_StateAccessType_increment_count_clinic(StateAccessTypeObject *se
goto exit;
}
skip_optional_kwonly:
- return_value = _testmultiphase_StateAccessType_increment_count_clinic_impl(self, cls, n, twice);
+ return_value = _testmultiphase_StateAccessType_increment_count_clinic_impl((StateAccessTypeObject *)self, cls, n, twice);
exit:
return return_value;
@@ -155,12 +155,12 @@ _testmultiphase_StateAccessType_get_count_impl(StateAccessTypeObject *self,
PyTypeObject *cls);
static PyObject *
-_testmultiphase_StateAccessType_get_count(StateAccessTypeObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+_testmultiphase_StateAccessType_get_count(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "get_count() takes no arguments");
return NULL;
}
- return _testmultiphase_StateAccessType_get_count_impl(self, cls);
+ return _testmultiphase_StateAccessType_get_count_impl((StateAccessTypeObject *)self, cls);
}
-/*[clinic end generated code: output=c1aa0af3572bf059 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ea0ca98e467e53c2 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_tkinter.c.h b/Modules/clinic/_tkinter.c.h
index 2b1ac954b4d570..d6e783b04fe968 100644
--- a/Modules/clinic/_tkinter.c.h
+++ b/Modules/clinic/_tkinter.c.h
@@ -16,7 +16,7 @@ static PyObject *
_tkinter_tkapp_eval_impl(TkappObject *self, const char *script);
static PyObject *
-_tkinter_tkapp_eval(TkappObject *self, PyObject *arg)
+_tkinter_tkapp_eval(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *script;
@@ -34,7 +34,7 @@ _tkinter_tkapp_eval(TkappObject *self, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = _tkinter_tkapp_eval_impl(self, script);
+ return_value = _tkinter_tkapp_eval_impl((TkappObject *)self, script);
exit:
return return_value;
@@ -52,7 +52,7 @@ static PyObject *
_tkinter_tkapp_evalfile_impl(TkappObject *self, const char *fileName);
static PyObject *
-_tkinter_tkapp_evalfile(TkappObject *self, PyObject *arg)
+_tkinter_tkapp_evalfile(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *fileName;
@@ -70,7 +70,7 @@ _tkinter_tkapp_evalfile(TkappObject *self, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = _tkinter_tkapp_evalfile_impl(self, fileName);
+ return_value = _tkinter_tkapp_evalfile_impl((TkappObject *)self, fileName);
exit:
return return_value;
@@ -88,7 +88,7 @@ static PyObject *
_tkinter_tkapp_record_impl(TkappObject *self, const char *script);
static PyObject *
-_tkinter_tkapp_record(TkappObject *self, PyObject *arg)
+_tkinter_tkapp_record(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *script;
@@ -106,7 +106,7 @@ _tkinter_tkapp_record(TkappObject *self, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = _tkinter_tkapp_record_impl(self, script);
+ return_value = _tkinter_tkapp_record_impl((TkappObject *)self, script);
exit:
return return_value;
@@ -124,7 +124,7 @@ static PyObject *
_tkinter_tkapp_adderrorinfo_impl(TkappObject *self, const char *msg);
static PyObject *
-_tkinter_tkapp_adderrorinfo(TkappObject *self, PyObject *arg)
+_tkinter_tkapp_adderrorinfo(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *msg;
@@ -142,7 +142,7 @@ _tkinter_tkapp_adderrorinfo(TkappObject *self, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = _tkinter_tkapp_adderrorinfo_impl(self, msg);
+ return_value = _tkinter_tkapp_adderrorinfo_impl((TkappObject *)self, msg);
exit:
return return_value;
@@ -184,7 +184,7 @@ static PyObject *
_tkinter_tkapp_exprstring_impl(TkappObject *self, const char *s);
static PyObject *
-_tkinter_tkapp_exprstring(TkappObject *self, PyObject *arg)
+_tkinter_tkapp_exprstring(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *s;
@@ -202,7 +202,7 @@ _tkinter_tkapp_exprstring(TkappObject *self, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = _tkinter_tkapp_exprstring_impl(self, s);
+ return_value = _tkinter_tkapp_exprstring_impl((TkappObject *)self, s);
exit:
return return_value;
@@ -220,7 +220,7 @@ static PyObject *
_tkinter_tkapp_exprlong_impl(TkappObject *self, const char *s);
static PyObject *
-_tkinter_tkapp_exprlong(TkappObject *self, PyObject *arg)
+_tkinter_tkapp_exprlong(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *s;
@@ -238,7 +238,7 @@ _tkinter_tkapp_exprlong(TkappObject *self, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = _tkinter_tkapp_exprlong_impl(self, s);
+ return_value = _tkinter_tkapp_exprlong_impl((TkappObject *)self, s);
exit:
return return_value;
@@ -256,7 +256,7 @@ static PyObject *
_tkinter_tkapp_exprdouble_impl(TkappObject *self, const char *s);
static PyObject *
-_tkinter_tkapp_exprdouble(TkappObject *self, PyObject *arg)
+_tkinter_tkapp_exprdouble(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *s;
@@ -274,7 +274,7 @@ _tkinter_tkapp_exprdouble(TkappObject *self, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = _tkinter_tkapp_exprdouble_impl(self, s);
+ return_value = _tkinter_tkapp_exprdouble_impl((TkappObject *)self, s);
exit:
return return_value;
@@ -292,7 +292,7 @@ static PyObject *
_tkinter_tkapp_exprboolean_impl(TkappObject *self, const char *s);
static PyObject *
-_tkinter_tkapp_exprboolean(TkappObject *self, PyObject *arg)
+_tkinter_tkapp_exprboolean(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *s;
@@ -310,7 +310,7 @@ _tkinter_tkapp_exprboolean(TkappObject *self, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = _tkinter_tkapp_exprboolean_impl(self, s);
+ return_value = _tkinter_tkapp_exprboolean_impl((TkappObject *)self, s);
exit:
return return_value;
@@ -337,7 +337,7 @@ _tkinter_tkapp_createcommand_impl(TkappObject *self, const char *name,
PyObject *func);
static PyObject *
-_tkinter_tkapp_createcommand(TkappObject *self, PyObject *const *args, Py_ssize_t nargs)
+_tkinter_tkapp_createcommand(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
const char *name;
@@ -360,7 +360,7 @@ _tkinter_tkapp_createcommand(TkappObject *self, PyObject *const *args, Py_ssize_
goto exit;
}
func = args[1];
- return_value = _tkinter_tkapp_createcommand_impl(self, name, func);
+ return_value = _tkinter_tkapp_createcommand_impl((TkappObject *)self, name, func);
exit:
return return_value;
@@ -378,7 +378,7 @@ static PyObject *
_tkinter_tkapp_deletecommand_impl(TkappObject *self, const char *name);
static PyObject *
-_tkinter_tkapp_deletecommand(TkappObject *self, PyObject *arg)
+_tkinter_tkapp_deletecommand(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *name;
@@ -396,7 +396,7 @@ _tkinter_tkapp_deletecommand(TkappObject *self, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = _tkinter_tkapp_deletecommand_impl(self, name);
+ return_value = _tkinter_tkapp_deletecommand_impl((TkappObject *)self, name);
exit:
return return_value;
@@ -417,7 +417,7 @@ _tkinter_tkapp_createfilehandler_impl(TkappObject *self, PyObject *file,
int mask, PyObject *func);
static PyObject *
-_tkinter_tkapp_createfilehandler(TkappObject *self, PyObject *const *args, Py_ssize_t nargs)
+_tkinter_tkapp_createfilehandler(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *file;
@@ -433,7 +433,7 @@ _tkinter_tkapp_createfilehandler(TkappObject *self, PyObject *const *args, Py_ss
goto exit;
}
func = args[2];
- return_value = _tkinter_tkapp_createfilehandler_impl(self, file, mask, func);
+ return_value = _tkinter_tkapp_createfilehandler_impl((TkappObject *)self, file, mask, func);
exit:
return return_value;
@@ -465,9 +465,9 @@ static PyObject *
_tkinter_tktimertoken_deletetimerhandler_impl(TkttObject *self);
static PyObject *
-_tkinter_tktimertoken_deletetimerhandler(TkttObject *self, PyObject *Py_UNUSED(ignored))
+_tkinter_tktimertoken_deletetimerhandler(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _tkinter_tktimertoken_deletetimerhandler_impl(self);
+ return _tkinter_tktimertoken_deletetimerhandler_impl((TkttObject *)self);
}
PyDoc_STRVAR(_tkinter_tkapp_createtimerhandler__doc__,
@@ -483,7 +483,7 @@ _tkinter_tkapp_createtimerhandler_impl(TkappObject *self, int milliseconds,
PyObject *func);
static PyObject *
-_tkinter_tkapp_createtimerhandler(TkappObject *self, PyObject *const *args, Py_ssize_t nargs)
+_tkinter_tkapp_createtimerhandler(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int milliseconds;
@@ -497,7 +497,7 @@ _tkinter_tkapp_createtimerhandler(TkappObject *self, PyObject *const *args, Py_s
goto exit;
}
func = args[1];
- return_value = _tkinter_tkapp_createtimerhandler_impl(self, milliseconds, func);
+ return_value = _tkinter_tkapp_createtimerhandler_impl((TkappObject *)self, milliseconds, func);
exit:
return return_value;
@@ -515,7 +515,7 @@ static PyObject *
_tkinter_tkapp_mainloop_impl(TkappObject *self, int threshold);
static PyObject *
-_tkinter_tkapp_mainloop(TkappObject *self, PyObject *const *args, Py_ssize_t nargs)
+_tkinter_tkapp_mainloop(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int threshold = 0;
@@ -531,7 +531,7 @@ _tkinter_tkapp_mainloop(TkappObject *self, PyObject *const *args, Py_ssize_t nar
goto exit;
}
skip_optional:
- return_value = _tkinter_tkapp_mainloop_impl(self, threshold);
+ return_value = _tkinter_tkapp_mainloop_impl((TkappObject *)self, threshold);
exit:
return return_value;
@@ -549,7 +549,7 @@ static PyObject *
_tkinter_tkapp_dooneevent_impl(TkappObject *self, int flags);
static PyObject *
-_tkinter_tkapp_dooneevent(TkappObject *self, PyObject *const *args, Py_ssize_t nargs)
+_tkinter_tkapp_dooneevent(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int flags = 0;
@@ -565,7 +565,7 @@ _tkinter_tkapp_dooneevent(TkappObject *self, PyObject *const *args, Py_ssize_t n
goto exit;
}
skip_optional:
- return_value = _tkinter_tkapp_dooneevent_impl(self, flags);
+ return_value = _tkinter_tkapp_dooneevent_impl((TkappObject *)self, flags);
exit:
return return_value;
@@ -583,9 +583,9 @@ static PyObject *
_tkinter_tkapp_quit_impl(TkappObject *self);
static PyObject *
-_tkinter_tkapp_quit(TkappObject *self, PyObject *Py_UNUSED(ignored))
+_tkinter_tkapp_quit(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _tkinter_tkapp_quit_impl(self);
+ return _tkinter_tkapp_quit_impl((TkappObject *)self);
}
PyDoc_STRVAR(_tkinter_tkapp_interpaddr__doc__,
@@ -600,9 +600,9 @@ static PyObject *
_tkinter_tkapp_interpaddr_impl(TkappObject *self);
static PyObject *
-_tkinter_tkapp_interpaddr(TkappObject *self, PyObject *Py_UNUSED(ignored))
+_tkinter_tkapp_interpaddr(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _tkinter_tkapp_interpaddr_impl(self);
+ return _tkinter_tkapp_interpaddr_impl((TkappObject *)self);
}
PyDoc_STRVAR(_tkinter_tkapp_loadtk__doc__,
@@ -617,9 +617,9 @@ static PyObject *
_tkinter_tkapp_loadtk_impl(TkappObject *self);
static PyObject *
-_tkinter_tkapp_loadtk(TkappObject *self, PyObject *Py_UNUSED(ignored))
+_tkinter_tkapp_loadtk(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _tkinter_tkapp_loadtk_impl(self);
+ return _tkinter_tkapp_loadtk_impl((TkappObject *)self);
}
PyDoc_STRVAR(_tkinter_tkapp_settrace__doc__,
@@ -644,9 +644,9 @@ static PyObject *
_tkinter_tkapp_gettrace_impl(TkappObject *self);
static PyObject *
-_tkinter_tkapp_gettrace(TkappObject *self, PyObject *Py_UNUSED(ignored))
+_tkinter_tkapp_gettrace(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _tkinter_tkapp_gettrace_impl(self);
+ return _tkinter_tkapp_gettrace_impl((TkappObject *)self);
}
PyDoc_STRVAR(_tkinter_tkapp_willdispatch__doc__,
@@ -661,9 +661,9 @@ static PyObject *
_tkinter_tkapp_willdispatch_impl(TkappObject *self);
static PyObject *
-_tkinter_tkapp_willdispatch(TkappObject *self, PyObject *Py_UNUSED(ignored))
+_tkinter_tkapp_willdispatch(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _tkinter_tkapp_willdispatch_impl(self);
+ return _tkinter_tkapp_willdispatch_impl((TkappObject *)self);
}
PyDoc_STRVAR(_tkinter__flatten__doc__,
@@ -888,4 +888,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=d90c1a9850c63249 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=172a98df5f209a84 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_winapi.c.h b/Modules/clinic/_winapi.c.h
index 8bbecc44dc9c11..6a2f8d45cd4e0c 100644
--- a/Modules/clinic/_winapi.c.h
+++ b/Modules/clinic/_winapi.c.h
@@ -21,7 +21,7 @@ static PyObject *
_winapi_Overlapped_GetOverlappedResult_impl(OverlappedObject *self, int wait);
static PyObject *
-_winapi_Overlapped_GetOverlappedResult(OverlappedObject *self, PyObject *arg)
+_winapi_Overlapped_GetOverlappedResult(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int wait;
@@ -30,7 +30,7 @@ _winapi_Overlapped_GetOverlappedResult(OverlappedObject *self, PyObject *arg)
if (wait < 0) {
goto exit;
}
- return_value = _winapi_Overlapped_GetOverlappedResult_impl(self, wait);
+ return_value = _winapi_Overlapped_GetOverlappedResult_impl((OverlappedObject *)self, wait);
exit:
return return_value;
@@ -48,9 +48,9 @@ static PyObject *
_winapi_Overlapped_getbuffer_impl(OverlappedObject *self);
static PyObject *
-_winapi_Overlapped_getbuffer(OverlappedObject *self, PyObject *Py_UNUSED(ignored))
+_winapi_Overlapped_getbuffer(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _winapi_Overlapped_getbuffer_impl(self);
+ return _winapi_Overlapped_getbuffer_impl((OverlappedObject *)self);
}
PyDoc_STRVAR(_winapi_Overlapped_cancel__doc__,
@@ -65,9 +65,9 @@ static PyObject *
_winapi_Overlapped_cancel_impl(OverlappedObject *self);
static PyObject *
-_winapi_Overlapped_cancel(OverlappedObject *self, PyObject *Py_UNUSED(ignored))
+_winapi_Overlapped_cancel(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _winapi_Overlapped_cancel_impl(self);
+ return _winapi_Overlapped_cancel_impl((OverlappedObject *)self);
}
PyDoc_STRVAR(_winapi_CloseHandle__doc__,
@@ -2127,4 +2127,4 @@ _winapi_CopyFile2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyO
return return_value;
}
-/*[clinic end generated code: output=b2a178bde6868e88 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=06b56212b2186250 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h
index 4a7266ecb8b84f..c5b62b16699d06 100644
--- a/Modules/clinic/arraymodule.c.h
+++ b/Modules/clinic/arraymodule.c.h
@@ -21,9 +21,9 @@ static PyObject *
array_array_clear_impl(arrayobject *self);
static PyObject *
-array_array_clear(arrayobject *self, PyObject *Py_UNUSED(ignored))
+array_array_clear(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return array_array_clear_impl(self);
+ return array_array_clear_impl((arrayobject *)self);
}
PyDoc_STRVAR(array_array___copy____doc__,
@@ -39,9 +39,9 @@ static PyObject *
array_array___copy___impl(arrayobject *self);
static PyObject *
-array_array___copy__(arrayobject *self, PyObject *Py_UNUSED(ignored))
+array_array___copy__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return array_array___copy___impl(self);
+ return array_array___copy___impl((arrayobject *)self);
}
PyDoc_STRVAR(array_array___deepcopy____doc__,
@@ -78,7 +78,7 @@ array_array_index_impl(arrayobject *self, PyObject *v, Py_ssize_t start,
Py_ssize_t stop);
static PyObject *
-array_array_index(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
+array_array_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *v;
@@ -102,7 +102,7 @@ array_array_index(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = array_array_index_impl(self, v, start, stop);
+ return_value = array_array_index_impl((arrayobject *)self, v, start, stop);
exit:
return return_value;
@@ -132,7 +132,7 @@ static PyObject *
array_array_pop_impl(arrayobject *self, Py_ssize_t i);
static PyObject *
-array_array_pop(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
+array_array_pop(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t i = -1;
@@ -156,7 +156,7 @@ array_array_pop(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
i = ival;
}
skip_optional:
- return_value = array_array_pop_impl(self, i);
+ return_value = array_array_pop_impl((arrayobject *)self, i);
exit:
return return_value;
@@ -175,7 +175,7 @@ static PyObject *
array_array_extend_impl(arrayobject *self, PyTypeObject *cls, PyObject *bb);
static PyObject *
-array_array_extend(arrayobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+array_array_extend(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -200,7 +200,7 @@ array_array_extend(arrayobject *self, PyTypeObject *cls, PyObject *const *args,
goto exit;
}
bb = args[0];
- return_value = array_array_extend_impl(self, cls, bb);
+ return_value = array_array_extend_impl((arrayobject *)self, cls, bb);
exit:
return return_value;
@@ -219,7 +219,7 @@ static PyObject *
array_array_insert_impl(arrayobject *self, Py_ssize_t i, PyObject *v);
static PyObject *
-array_array_insert(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
+array_array_insert(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t i;
@@ -241,7 +241,7 @@ array_array_insert(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
i = ival;
}
v = args[1];
- return_value = array_array_insert_impl(self, i, v);
+ return_value = array_array_insert_impl((arrayobject *)self, i, v);
exit:
return return_value;
@@ -263,9 +263,9 @@ static PyObject *
array_array_buffer_info_impl(arrayobject *self);
static PyObject *
-array_array_buffer_info(arrayobject *self, PyObject *Py_UNUSED(ignored))
+array_array_buffer_info(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return array_array_buffer_info_impl(self);
+ return array_array_buffer_info_impl((arrayobject *)self);
}
PyDoc_STRVAR(array_array_append__doc__,
@@ -293,9 +293,9 @@ static PyObject *
array_array_byteswap_impl(arrayobject *self);
static PyObject *
-array_array_byteswap(arrayobject *self, PyObject *Py_UNUSED(ignored))
+array_array_byteswap(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return array_array_byteswap_impl(self);
+ return array_array_byteswap_impl((arrayobject *)self);
}
PyDoc_STRVAR(array_array_reverse__doc__,
@@ -311,9 +311,9 @@ static PyObject *
array_array_reverse_impl(arrayobject *self);
static PyObject *
-array_array_reverse(arrayobject *self, PyObject *Py_UNUSED(ignored))
+array_array_reverse(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return array_array_reverse_impl(self);
+ return array_array_reverse_impl((arrayobject *)self);
}
PyDoc_STRVAR(array_array_fromfile__doc__,
@@ -330,7 +330,7 @@ array_array_fromfile_impl(arrayobject *self, PyTypeObject *cls, PyObject *f,
Py_ssize_t n);
static PyObject *
-array_array_fromfile(arrayobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+array_array_fromfile(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -368,7 +368,7 @@ array_array_fromfile(arrayobject *self, PyTypeObject *cls, PyObject *const *args
}
n = ival;
}
- return_value = array_array_fromfile_impl(self, cls, f, n);
+ return_value = array_array_fromfile_impl((arrayobject *)self, cls, f, n);
exit:
return return_value;
@@ -387,7 +387,7 @@ static PyObject *
array_array_tofile_impl(arrayobject *self, PyTypeObject *cls, PyObject *f);
static PyObject *
-array_array_tofile(arrayobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+array_array_tofile(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -412,7 +412,7 @@ array_array_tofile(arrayobject *self, PyTypeObject *cls, PyObject *const *args,
goto exit;
}
f = args[0];
- return_value = array_array_tofile_impl(self, cls, f);
+ return_value = array_array_tofile_impl((arrayobject *)self, cls, f);
exit:
return return_value;
@@ -440,9 +440,9 @@ static PyObject *
array_array_tolist_impl(arrayobject *self);
static PyObject *
-array_array_tolist(arrayobject *self, PyObject *Py_UNUSED(ignored))
+array_array_tolist(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return array_array_tolist_impl(self);
+ return array_array_tolist_impl((arrayobject *)self);
}
PyDoc_STRVAR(array_array_frombytes__doc__,
@@ -458,7 +458,7 @@ static PyObject *
array_array_frombytes_impl(arrayobject *self, Py_buffer *buffer);
static PyObject *
-array_array_frombytes(arrayobject *self, PyObject *arg)
+array_array_frombytes(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer buffer = {NULL, NULL};
@@ -466,7 +466,7 @@ array_array_frombytes(arrayobject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = array_array_frombytes_impl(self, &buffer);
+ return_value = array_array_frombytes_impl((arrayobject *)self, &buffer);
exit:
/* Cleanup for buffer */
@@ -490,9 +490,9 @@ static PyObject *
array_array_tobytes_impl(arrayobject *self);
static PyObject *
-array_array_tobytes(arrayobject *self, PyObject *Py_UNUSED(ignored))
+array_array_tobytes(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return array_array_tobytes_impl(self);
+ return array_array_tobytes_impl((arrayobject *)self);
}
PyDoc_STRVAR(array_array_fromunicode__doc__,
@@ -512,7 +512,7 @@ static PyObject *
array_array_fromunicode_impl(arrayobject *self, PyObject *ustr);
static PyObject *
-array_array_fromunicode(arrayobject *self, PyObject *arg)
+array_array_fromunicode(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
PyObject *ustr;
@@ -522,7 +522,7 @@ array_array_fromunicode(arrayobject *self, PyObject *arg)
goto exit;
}
ustr = arg;
- return_value = array_array_fromunicode_impl(self, ustr);
+ return_value = array_array_fromunicode_impl((arrayobject *)self, ustr);
exit:
return return_value;
@@ -545,9 +545,9 @@ static PyObject *
array_array_tounicode_impl(arrayobject *self);
static PyObject *
-array_array_tounicode(arrayobject *self, PyObject *Py_UNUSED(ignored))
+array_array_tounicode(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return array_array_tounicode_impl(self);
+ return array_array_tounicode_impl((arrayobject *)self);
}
PyDoc_STRVAR(array_array___sizeof____doc__,
@@ -563,9 +563,9 @@ static PyObject *
array_array___sizeof___impl(arrayobject *self);
static PyObject *
-array_array___sizeof__(arrayobject *self, PyObject *Py_UNUSED(ignored))
+array_array___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return array_array___sizeof___impl(self);
+ return array_array___sizeof___impl((arrayobject *)self);
}
PyDoc_STRVAR(array__array_reconstructor__doc__,
@@ -634,7 +634,7 @@ array_array___reduce_ex___impl(arrayobject *self, PyTypeObject *cls,
PyObject *value);
static PyObject *
-array_array___reduce_ex__(arrayobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+array_array___reduce_ex__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -659,7 +659,7 @@ array_array___reduce_ex__(arrayobject *self, PyTypeObject *cls, PyObject *const
goto exit;
}
value = args[0];
- return_value = array_array___reduce_ex___impl(self, cls, value);
+ return_value = array_array___reduce_ex___impl((arrayobject *)self, cls, value);
exit:
return return_value;
@@ -678,13 +678,13 @@ static PyObject *
array_arrayiterator___reduce___impl(arrayiterobject *self, PyTypeObject *cls);
static PyObject *
-array_arrayiterator___reduce__(arrayiterobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+array_arrayiterator___reduce__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "__reduce__() takes no arguments");
return NULL;
}
- return array_arrayiterator___reduce___impl(self, cls);
+ return array_arrayiterator___reduce___impl((arrayiterobject *)self, cls);
}
PyDoc_STRVAR(array_arrayiterator___setstate____doc__,
@@ -695,4 +695,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=22dbe12826bfa86f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8120dc5c4fa414b9 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/blake2module.c.h b/Modules/clinic/blake2module.c.h
index f695f27e9e6c42..b5ac90143a1740 100644
--- a/Modules/clinic/blake2module.c.h
+++ b/Modules/clinic/blake2module.c.h
@@ -412,9 +412,9 @@ static PyObject *
_blake2_blake2b_copy_impl(Blake2Object *self);
static PyObject *
-_blake2_blake2b_copy(Blake2Object *self, PyObject *Py_UNUSED(ignored))
+_blake2_blake2b_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _blake2_blake2b_copy_impl(self);
+ return _blake2_blake2b_copy_impl((Blake2Object *)self);
}
PyDoc_STRVAR(_blake2_blake2b_update__doc__,
@@ -439,9 +439,9 @@ static PyObject *
_blake2_blake2b_digest_impl(Blake2Object *self);
static PyObject *
-_blake2_blake2b_digest(Blake2Object *self, PyObject *Py_UNUSED(ignored))
+_blake2_blake2b_digest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _blake2_blake2b_digest_impl(self);
+ return _blake2_blake2b_digest_impl((Blake2Object *)self);
}
PyDoc_STRVAR(_blake2_blake2b_hexdigest__doc__,
@@ -457,8 +457,8 @@ static PyObject *
_blake2_blake2b_hexdigest_impl(Blake2Object *self);
static PyObject *
-_blake2_blake2b_hexdigest(Blake2Object *self, PyObject *Py_UNUSED(ignored))
+_blake2_blake2b_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _blake2_blake2b_hexdigest_impl(self);
+ return _blake2_blake2b_hexdigest_impl((Blake2Object *)self);
}
-/*[clinic end generated code: output=e0aaaf112d023b79 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6e03c947b7e0d973 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/md5module.c.h b/Modules/clinic/md5module.c.h
index 7721616862ed0d..1f0acebf47b6ff 100644
--- a/Modules/clinic/md5module.c.h
+++ b/Modules/clinic/md5module.c.h
@@ -21,13 +21,13 @@ static PyObject *
MD5Type_copy_impl(MD5object *self, PyTypeObject *cls);
static PyObject *
-MD5Type_copy(MD5object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+MD5Type_copy(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "copy() takes no arguments");
return NULL;
}
- return MD5Type_copy_impl(self, cls);
+ return MD5Type_copy_impl((MD5object *)self, cls);
}
PyDoc_STRVAR(MD5Type_digest__doc__,
@@ -43,9 +43,9 @@ static PyObject *
MD5Type_digest_impl(MD5object *self);
static PyObject *
-MD5Type_digest(MD5object *self, PyObject *Py_UNUSED(ignored))
+MD5Type_digest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return MD5Type_digest_impl(self);
+ return MD5Type_digest_impl((MD5object *)self);
}
PyDoc_STRVAR(MD5Type_hexdigest__doc__,
@@ -61,9 +61,9 @@ static PyObject *
MD5Type_hexdigest_impl(MD5object *self);
static PyObject *
-MD5Type_hexdigest(MD5object *self, PyObject *Py_UNUSED(ignored))
+MD5Type_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return MD5Type_hexdigest_impl(self);
+ return MD5Type_hexdigest_impl((MD5object *)self);
}
PyDoc_STRVAR(MD5Type_update__doc__,
@@ -149,4 +149,4 @@ _md5_md5(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
exit:
return return_value;
}
-/*[clinic end generated code: output=62ebf28802ae8b5f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a4292eab710dcb60 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/overlapped.c.h b/Modules/clinic/overlapped.c.h
index 9d5adb5193f297..7e5715660022c1 100644
--- a/Modules/clinic/overlapped.c.h
+++ b/Modules/clinic/overlapped.c.h
@@ -516,9 +516,9 @@ static PyObject *
_overlapped_Overlapped_cancel_impl(OverlappedObject *self);
static PyObject *
-_overlapped_Overlapped_cancel(OverlappedObject *self, PyObject *Py_UNUSED(ignored))
+_overlapped_Overlapped_cancel(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _overlapped_Overlapped_cancel_impl(self);
+ return _overlapped_Overlapped_cancel_impl((OverlappedObject *)self);
}
PyDoc_STRVAR(_overlapped_Overlapped_getresult__doc__,
@@ -537,7 +537,7 @@ static PyObject *
_overlapped_Overlapped_getresult_impl(OverlappedObject *self, BOOL wait);
static PyObject *
-_overlapped_Overlapped_getresult(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_getresult(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
BOOL wait = FALSE;
@@ -553,7 +553,7 @@ _overlapped_Overlapped_getresult(OverlappedObject *self, PyObject *const *args,
goto exit;
}
skip_optional:
- return_value = _overlapped_Overlapped_getresult_impl(self, wait);
+ return_value = _overlapped_Overlapped_getresult_impl((OverlappedObject *)self, wait);
exit:
return return_value;
@@ -573,7 +573,7 @@ _overlapped_Overlapped_ReadFile_impl(OverlappedObject *self, HANDLE handle,
DWORD size);
static PyObject *
-_overlapped_Overlapped_ReadFile(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_ReadFile(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
HANDLE handle;
@@ -589,7 +589,7 @@ _overlapped_Overlapped_ReadFile(OverlappedObject *self, PyObject *const *args, P
if (!_PyLong_UnsignedLong_Converter(args[1], &size)) {
goto exit;
}
- return_value = _overlapped_Overlapped_ReadFile_impl(self, handle, size);
+ return_value = _overlapped_Overlapped_ReadFile_impl((OverlappedObject *)self, handle, size);
exit:
return return_value;
@@ -609,7 +609,7 @@ _overlapped_Overlapped_ReadFileInto_impl(OverlappedObject *self,
HANDLE handle, Py_buffer *bufobj);
static PyObject *
-_overlapped_Overlapped_ReadFileInto(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_ReadFileInto(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
HANDLE handle;
@@ -625,7 +625,7 @@ _overlapped_Overlapped_ReadFileInto(OverlappedObject *self, PyObject *const *arg
if (PyObject_GetBuffer(args[1], &bufobj, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = _overlapped_Overlapped_ReadFileInto_impl(self, handle, &bufobj);
+ return_value = _overlapped_Overlapped_ReadFileInto_impl((OverlappedObject *)self, handle, &bufobj);
exit:
/* Cleanup for bufobj */
@@ -650,7 +650,7 @@ _overlapped_Overlapped_WSARecv_impl(OverlappedObject *self, HANDLE handle,
DWORD size, DWORD flags);
static PyObject *
-_overlapped_Overlapped_WSARecv(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_WSARecv(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
HANDLE handle;
@@ -674,7 +674,7 @@ _overlapped_Overlapped_WSARecv(OverlappedObject *self, PyObject *const *args, Py
goto exit;
}
skip_optional:
- return_value = _overlapped_Overlapped_WSARecv_impl(self, handle, size, flags);
+ return_value = _overlapped_Overlapped_WSARecv_impl((OverlappedObject *)self, handle, size, flags);
exit:
return return_value;
@@ -695,7 +695,7 @@ _overlapped_Overlapped_WSARecvInto_impl(OverlappedObject *self,
DWORD flags);
static PyObject *
-_overlapped_Overlapped_WSARecvInto(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_WSARecvInto(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
HANDLE handle;
@@ -715,7 +715,7 @@ _overlapped_Overlapped_WSARecvInto(OverlappedObject *self, PyObject *const *args
if (!_PyLong_UnsignedLong_Converter(args[2], &flags)) {
goto exit;
}
- return_value = _overlapped_Overlapped_WSARecvInto_impl(self, handle, &bufobj, flags);
+ return_value = _overlapped_Overlapped_WSARecvInto_impl((OverlappedObject *)self, handle, &bufobj, flags);
exit:
/* Cleanup for bufobj */
@@ -740,7 +740,7 @@ _overlapped_Overlapped_WriteFile_impl(OverlappedObject *self, HANDLE handle,
Py_buffer *bufobj);
static PyObject *
-_overlapped_Overlapped_WriteFile(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_WriteFile(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
HANDLE handle;
@@ -756,7 +756,7 @@ _overlapped_Overlapped_WriteFile(OverlappedObject *self, PyObject *const *args,
if (PyObject_GetBuffer(args[1], &bufobj, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = _overlapped_Overlapped_WriteFile_impl(self, handle, &bufobj);
+ return_value = _overlapped_Overlapped_WriteFile_impl((OverlappedObject *)self, handle, &bufobj);
exit:
/* Cleanup for bufobj */
@@ -781,7 +781,7 @@ _overlapped_Overlapped_WSASend_impl(OverlappedObject *self, HANDLE handle,
Py_buffer *bufobj, DWORD flags);
static PyObject *
-_overlapped_Overlapped_WSASend(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_WSASend(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
HANDLE handle;
@@ -801,7 +801,7 @@ _overlapped_Overlapped_WSASend(OverlappedObject *self, PyObject *const *args, Py
if (!_PyLong_UnsignedLong_Converter(args[2], &flags)) {
goto exit;
}
- return_value = _overlapped_Overlapped_WSASend_impl(self, handle, &bufobj, flags);
+ return_value = _overlapped_Overlapped_WSASend_impl((OverlappedObject *)self, handle, &bufobj, flags);
exit:
/* Cleanup for bufobj */
@@ -827,7 +827,7 @@ _overlapped_Overlapped_AcceptEx_impl(OverlappedObject *self,
HANDLE AcceptSocket);
static PyObject *
-_overlapped_Overlapped_AcceptEx(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_AcceptEx(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
HANDLE ListenSocket;
@@ -844,7 +844,7 @@ _overlapped_Overlapped_AcceptEx(OverlappedObject *self, PyObject *const *args, P
if (!AcceptSocket && PyErr_Occurred()) {
goto exit;
}
- return_value = _overlapped_Overlapped_AcceptEx_impl(self, ListenSocket, AcceptSocket);
+ return_value = _overlapped_Overlapped_AcceptEx_impl((OverlappedObject *)self, ListenSocket, AcceptSocket);
exit:
return return_value;
@@ -867,7 +867,7 @@ _overlapped_Overlapped_ConnectEx_impl(OverlappedObject *self,
PyObject *AddressObj);
static PyObject *
-_overlapped_Overlapped_ConnectEx(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_ConnectEx(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
HANDLE ConnectSocket;
@@ -885,7 +885,7 @@ _overlapped_Overlapped_ConnectEx(OverlappedObject *self, PyObject *const *args,
goto exit;
}
AddressObj = args[1];
- return_value = _overlapped_Overlapped_ConnectEx_impl(self, ConnectSocket, AddressObj);
+ return_value = _overlapped_Overlapped_ConnectEx_impl((OverlappedObject *)self, ConnectSocket, AddressObj);
exit:
return return_value;
@@ -904,7 +904,7 @@ _overlapped_Overlapped_DisconnectEx_impl(OverlappedObject *self,
HANDLE Socket, DWORD flags);
static PyObject *
-_overlapped_Overlapped_DisconnectEx(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_DisconnectEx(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
HANDLE Socket;
@@ -920,7 +920,7 @@ _overlapped_Overlapped_DisconnectEx(OverlappedObject *self, PyObject *const *arg
if (!_PyLong_UnsignedLong_Converter(args[1], &flags)) {
goto exit;
}
- return_value = _overlapped_Overlapped_DisconnectEx_impl(self, Socket, flags);
+ return_value = _overlapped_Overlapped_DisconnectEx_impl((OverlappedObject *)self, Socket, flags);
exit:
return return_value;
@@ -944,7 +944,7 @@ _overlapped_Overlapped_TransmitFile_impl(OverlappedObject *self,
DWORD count_per_send, DWORD flags);
static PyObject *
-_overlapped_Overlapped_TransmitFile(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_TransmitFile(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
HANDLE Socket;
@@ -981,7 +981,7 @@ _overlapped_Overlapped_TransmitFile(OverlappedObject *self, PyObject *const *arg
if (!_PyLong_UnsignedLong_Converter(args[6], &flags)) {
goto exit;
}
- return_value = _overlapped_Overlapped_TransmitFile_impl(self, Socket, File, offset, offset_high, count_to_write, count_per_send, flags);
+ return_value = _overlapped_Overlapped_TransmitFile_impl((OverlappedObject *)self, Socket, File, offset, offset_high, count_to_write, count_per_send, flags);
exit:
return return_value;
@@ -1001,7 +1001,7 @@ _overlapped_Overlapped_ConnectNamedPipe_impl(OverlappedObject *self,
HANDLE Pipe);
static PyObject *
-_overlapped_Overlapped_ConnectNamedPipe(OverlappedObject *self, PyObject *arg)
+_overlapped_Overlapped_ConnectNamedPipe(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
HANDLE Pipe;
@@ -1010,7 +1010,7 @@ _overlapped_Overlapped_ConnectNamedPipe(OverlappedObject *self, PyObject *arg)
if (!Pipe && PyErr_Occurred()) {
goto exit;
}
- return_value = _overlapped_Overlapped_ConnectNamedPipe_impl(self, Pipe);
+ return_value = _overlapped_Overlapped_ConnectNamedPipe_impl((OverlappedObject *)self, Pipe);
exit:
return return_value;
@@ -1030,7 +1030,7 @@ _overlapped_Overlapped_ConnectPipe_impl(OverlappedObject *self,
const wchar_t *Address);
static PyObject *
-_overlapped_Overlapped_ConnectPipe(OverlappedObject *self, PyObject *arg)
+_overlapped_Overlapped_ConnectPipe(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const wchar_t *Address = NULL;
@@ -1043,7 +1043,7 @@ _overlapped_Overlapped_ConnectPipe(OverlappedObject *self, PyObject *arg)
if (Address == NULL) {
goto exit;
}
- return_value = _overlapped_Overlapped_ConnectPipe_impl(self, Address);
+ return_value = _overlapped_Overlapped_ConnectPipe_impl((OverlappedObject *)self, Address);
exit:
/* Cleanup for Address */
@@ -1105,7 +1105,7 @@ _overlapped_Overlapped_WSASendTo_impl(OverlappedObject *self, HANDLE handle,
PyObject *AddressObj);
static PyObject *
-_overlapped_Overlapped_WSASendTo(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_WSASendTo(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
HANDLE handle;
@@ -1131,7 +1131,7 @@ _overlapped_Overlapped_WSASendTo(OverlappedObject *self, PyObject *const *args,
goto exit;
}
AddressObj = args[3];
- return_value = _overlapped_Overlapped_WSASendTo_impl(self, handle, &bufobj, flags, AddressObj);
+ return_value = _overlapped_Overlapped_WSASendTo_impl((OverlappedObject *)self, handle, &bufobj, flags, AddressObj);
exit:
/* Cleanup for bufobj */
@@ -1157,7 +1157,7 @@ _overlapped_Overlapped_WSARecvFrom_impl(OverlappedObject *self,
DWORD flags);
static PyObject *
-_overlapped_Overlapped_WSARecvFrom(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_WSARecvFrom(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
HANDLE handle;
@@ -1181,7 +1181,7 @@ _overlapped_Overlapped_WSARecvFrom(OverlappedObject *self, PyObject *const *args
goto exit;
}
skip_optional:
- return_value = _overlapped_Overlapped_WSARecvFrom_impl(self, handle, size, flags);
+ return_value = _overlapped_Overlapped_WSARecvFrom_impl((OverlappedObject *)self, handle, size, flags);
exit:
return return_value;
@@ -1202,7 +1202,7 @@ _overlapped_Overlapped_WSARecvFromInto_impl(OverlappedObject *self,
DWORD size, DWORD flags);
static PyObject *
-_overlapped_Overlapped_WSARecvFromInto(OverlappedObject *self, PyObject *const *args, Py_ssize_t nargs)
+_overlapped_Overlapped_WSARecvFromInto(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
HANDLE handle;
@@ -1230,7 +1230,7 @@ _overlapped_Overlapped_WSARecvFromInto(OverlappedObject *self, PyObject *const *
goto exit;
}
skip_optional:
- return_value = _overlapped_Overlapped_WSARecvFromInto_impl(self, handle, &bufobj, size, flags);
+ return_value = _overlapped_Overlapped_WSARecvFromInto_impl((OverlappedObject *)self, handle, &bufobj, size, flags);
exit:
/* Cleanup for bufobj */
@@ -1240,4 +1240,4 @@ _overlapped_Overlapped_WSARecvFromInto(OverlappedObject *self, PyObject *const *
return return_value;
}
-/*[clinic end generated code: output=14c4f87906f28dc5 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d009cc9e53d9732a input=a9049054013a1b77]*/
diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h
index 4e6c5b068c42b7..96bf21dced92f0 100644
--- a/Modules/clinic/posixmodule.c.h
+++ b/Modules/clinic/posixmodule.c.h
@@ -11662,7 +11662,7 @@ static int
os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class);
static PyObject *
-os_DirEntry_is_symlink(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+os_DirEntry_is_symlink(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
int _return_value;
@@ -11671,7 +11671,7 @@ os_DirEntry_is_symlink(DirEntry *self, PyTypeObject *defining_class, PyObject *c
PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments");
goto exit;
}
- _return_value = os_DirEntry_is_symlink_impl(self, defining_class);
+ _return_value = os_DirEntry_is_symlink_impl((DirEntry *)self, defining_class);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -11694,12 +11694,12 @@ static int
os_DirEntry_is_junction_impl(DirEntry *self);
static PyObject *
-os_DirEntry_is_junction(DirEntry *self, PyObject *Py_UNUSED(ignored))
+os_DirEntry_is_junction(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
int _return_value;
- _return_value = os_DirEntry_is_junction_impl(self);
+ _return_value = os_DirEntry_is_junction_impl((DirEntry *)self);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -11723,7 +11723,7 @@ os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class,
int follow_symlinks);
static PyObject *
-os_DirEntry_stat(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+os_DirEntry_stat(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -11768,7 +11768,7 @@ os_DirEntry_stat(DirEntry *self, PyTypeObject *defining_class, PyObject *const *
goto exit;
}
skip_optional_kwonly:
- return_value = os_DirEntry_stat_impl(self, defining_class, follow_symlinks);
+ return_value = os_DirEntry_stat_impl((DirEntry *)self, defining_class, follow_symlinks);
exit:
return return_value;
@@ -11788,7 +11788,7 @@ os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class,
int follow_symlinks);
static PyObject *
-os_DirEntry_is_dir(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+os_DirEntry_is_dir(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -11834,7 +11834,7 @@ os_DirEntry_is_dir(DirEntry *self, PyTypeObject *defining_class, PyObject *const
goto exit;
}
skip_optional_kwonly:
- _return_value = os_DirEntry_is_dir_impl(self, defining_class, follow_symlinks);
+ _return_value = os_DirEntry_is_dir_impl((DirEntry *)self, defining_class, follow_symlinks);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -11858,7 +11858,7 @@ os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class,
int follow_symlinks);
static PyObject *
-os_DirEntry_is_file(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+os_DirEntry_is_file(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -11904,7 +11904,7 @@ os_DirEntry_is_file(DirEntry *self, PyTypeObject *defining_class, PyObject *cons
goto exit;
}
skip_optional_kwonly:
- _return_value = os_DirEntry_is_file_impl(self, defining_class, follow_symlinks);
+ _return_value = os_DirEntry_is_file_impl((DirEntry *)self, defining_class, follow_symlinks);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -11927,9 +11927,9 @@ static PyObject *
os_DirEntry_inode_impl(DirEntry *self);
static PyObject *
-os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
+os_DirEntry_inode(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return os_DirEntry_inode_impl(self);
+ return os_DirEntry_inode_impl((DirEntry *)self);
}
PyDoc_STRVAR(os_DirEntry___fspath____doc__,
@@ -11945,9 +11945,9 @@ static PyObject *
os_DirEntry___fspath___impl(DirEntry *self);
static PyObject *
-os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
+os_DirEntry___fspath__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return os_DirEntry___fspath___impl(self);
+ return os_DirEntry___fspath___impl((DirEntry *)self);
}
PyDoc_STRVAR(os_scandir__doc__,
@@ -13140,4 +13140,4 @@ os__emscripten_debugger(PyObject *module, PyObject *Py_UNUSED(ignored))
#ifndef OS__EMSCRIPTEN_DEBUGGER_METHODDEF
#define OS__EMSCRIPTEN_DEBUGGER_METHODDEF
#endif /* !defined(OS__EMSCRIPTEN_DEBUGGER_METHODDEF) */
-/*[clinic end generated code: output=39b69b279fd637f7 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=34cb96bd07bcef90 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/pyexpat.c.h b/Modules/clinic/pyexpat.c.h
index e57aa8a07d78c7..9eba59731c3fba 100644
--- a/Modules/clinic/pyexpat.c.h
+++ b/Modules/clinic/pyexpat.c.h
@@ -22,7 +22,7 @@ pyexpat_xmlparser_SetReparseDeferralEnabled_impl(xmlparseobject *self,
int enabled);
static PyObject *
-pyexpat_xmlparser_SetReparseDeferralEnabled(xmlparseobject *self, PyObject *arg)
+pyexpat_xmlparser_SetReparseDeferralEnabled(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int enabled;
@@ -31,7 +31,7 @@ pyexpat_xmlparser_SetReparseDeferralEnabled(xmlparseobject *self, PyObject *arg)
if (enabled < 0) {
goto exit;
}
- return_value = pyexpat_xmlparser_SetReparseDeferralEnabled_impl(self, enabled);
+ return_value = pyexpat_xmlparser_SetReparseDeferralEnabled_impl((xmlparseobject *)self, enabled);
exit:
return return_value;
@@ -50,9 +50,9 @@ static PyObject *
pyexpat_xmlparser_GetReparseDeferralEnabled_impl(xmlparseobject *self);
static PyObject *
-pyexpat_xmlparser_GetReparseDeferralEnabled(xmlparseobject *self, PyObject *Py_UNUSED(ignored))
+pyexpat_xmlparser_GetReparseDeferralEnabled(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return pyexpat_xmlparser_GetReparseDeferralEnabled_impl(self);
+ return pyexpat_xmlparser_GetReparseDeferralEnabled_impl((xmlparseobject *)self);
}
PyDoc_STRVAR(pyexpat_xmlparser_Parse__doc__,
@@ -71,7 +71,7 @@ pyexpat_xmlparser_Parse_impl(xmlparseobject *self, PyTypeObject *cls,
PyObject *data, int isfinal);
static PyObject *
-pyexpat_xmlparser_Parse(xmlparseobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pyexpat_xmlparser_Parse(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -105,7 +105,7 @@ pyexpat_xmlparser_Parse(xmlparseobject *self, PyTypeObject *cls, PyObject *const
goto exit;
}
skip_optional_posonly:
- return_value = pyexpat_xmlparser_Parse_impl(self, cls, data, isfinal);
+ return_value = pyexpat_xmlparser_Parse_impl((xmlparseobject *)self, cls, data, isfinal);
exit:
return return_value;
@@ -125,7 +125,7 @@ pyexpat_xmlparser_ParseFile_impl(xmlparseobject *self, PyTypeObject *cls,
PyObject *file);
static PyObject *
-pyexpat_xmlparser_ParseFile(xmlparseobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pyexpat_xmlparser_ParseFile(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -150,7 +150,7 @@ pyexpat_xmlparser_ParseFile(xmlparseobject *self, PyTypeObject *cls, PyObject *c
goto exit;
}
file = args[0];
- return_value = pyexpat_xmlparser_ParseFile_impl(self, cls, file);
+ return_value = pyexpat_xmlparser_ParseFile_impl((xmlparseobject *)self, cls, file);
exit:
return return_value;
@@ -169,7 +169,7 @@ static PyObject *
pyexpat_xmlparser_SetBase_impl(xmlparseobject *self, const char *base);
static PyObject *
-pyexpat_xmlparser_SetBase(xmlparseobject *self, PyObject *arg)
+pyexpat_xmlparser_SetBase(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *base;
@@ -187,7 +187,7 @@ pyexpat_xmlparser_SetBase(xmlparseobject *self, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = pyexpat_xmlparser_SetBase_impl(self, base);
+ return_value = pyexpat_xmlparser_SetBase_impl((xmlparseobject *)self, base);
exit:
return return_value;
@@ -206,9 +206,9 @@ static PyObject *
pyexpat_xmlparser_GetBase_impl(xmlparseobject *self);
static PyObject *
-pyexpat_xmlparser_GetBase(xmlparseobject *self, PyObject *Py_UNUSED(ignored))
+pyexpat_xmlparser_GetBase(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return pyexpat_xmlparser_GetBase_impl(self);
+ return pyexpat_xmlparser_GetBase_impl((xmlparseobject *)self);
}
PyDoc_STRVAR(pyexpat_xmlparser_GetInputContext__doc__,
@@ -227,9 +227,9 @@ static PyObject *
pyexpat_xmlparser_GetInputContext_impl(xmlparseobject *self);
static PyObject *
-pyexpat_xmlparser_GetInputContext(xmlparseobject *self, PyObject *Py_UNUSED(ignored))
+pyexpat_xmlparser_GetInputContext(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return pyexpat_xmlparser_GetInputContext_impl(self);
+ return pyexpat_xmlparser_GetInputContext_impl((xmlparseobject *)self);
}
PyDoc_STRVAR(pyexpat_xmlparser_ExternalEntityParserCreate__doc__,
@@ -249,7 +249,7 @@ pyexpat_xmlparser_ExternalEntityParserCreate_impl(xmlparseobject *self,
const char *encoding);
static PyObject *
-pyexpat_xmlparser_ExternalEntityParserCreate(xmlparseobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pyexpat_xmlparser_ExternalEntityParserCreate(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -309,7 +309,7 @@ pyexpat_xmlparser_ExternalEntityParserCreate(xmlparseobject *self, PyTypeObject
goto exit;
}
skip_optional_posonly:
- return_value = pyexpat_xmlparser_ExternalEntityParserCreate_impl(self, cls, context, encoding);
+ return_value = pyexpat_xmlparser_ExternalEntityParserCreate_impl((xmlparseobject *)self, cls, context, encoding);
exit:
return return_value;
@@ -333,7 +333,7 @@ static PyObject *
pyexpat_xmlparser_SetParamEntityParsing_impl(xmlparseobject *self, int flag);
static PyObject *
-pyexpat_xmlparser_SetParamEntityParsing(xmlparseobject *self, PyObject *arg)
+pyexpat_xmlparser_SetParamEntityParsing(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int flag;
@@ -342,7 +342,7 @@ pyexpat_xmlparser_SetParamEntityParsing(xmlparseobject *self, PyObject *arg)
if (flag == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = pyexpat_xmlparser_SetParamEntityParsing_impl(self, flag);
+ return_value = pyexpat_xmlparser_SetParamEntityParsing_impl((xmlparseobject *)self, flag);
exit:
return return_value;
@@ -368,7 +368,7 @@ pyexpat_xmlparser_UseForeignDTD_impl(xmlparseobject *self, PyTypeObject *cls,
int flag);
static PyObject *
-pyexpat_xmlparser_UseForeignDTD(xmlparseobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+pyexpat_xmlparser_UseForeignDTD(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -400,7 +400,7 @@ pyexpat_xmlparser_UseForeignDTD(xmlparseobject *self, PyTypeObject *cls, PyObjec
goto exit;
}
skip_optional_posonly:
- return_value = pyexpat_xmlparser_UseForeignDTD_impl(self, cls, flag);
+ return_value = pyexpat_xmlparser_UseForeignDTD_impl((xmlparseobject *)self, cls, flag);
exit:
return return_value;
@@ -550,4 +550,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=63be65cb1823b5f8 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=7ee30ae5b666d0a8 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/selectmodule.c.h b/Modules/clinic/selectmodule.c.h
index 806a888d6b8cd9..d8bdd6f95f3d29 100644
--- a/Modules/clinic/selectmodule.c.h
+++ b/Modules/clinic/selectmodule.c.h
@@ -91,7 +91,7 @@ static PyObject *
select_poll_register_impl(pollObject *self, int fd, unsigned short eventmask);
static PyObject *
-select_poll_register(pollObject *self, PyObject *const *args, Py_ssize_t nargs)
+select_poll_register(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int fd;
@@ -112,7 +112,7 @@ select_poll_register(pollObject *self, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = select_poll_register_impl(self, fd, eventmask);
+ return_value = select_poll_register_impl((pollObject *)self, fd, eventmask);
Py_END_CRITICAL_SECTION();
exit:
@@ -142,7 +142,7 @@ static PyObject *
select_poll_modify_impl(pollObject *self, int fd, unsigned short eventmask);
static PyObject *
-select_poll_modify(pollObject *self, PyObject *const *args, Py_ssize_t nargs)
+select_poll_modify(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int fd;
@@ -159,7 +159,7 @@ select_poll_modify(pollObject *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = select_poll_modify_impl(self, fd, eventmask);
+ return_value = select_poll_modify_impl((pollObject *)self, fd, eventmask);
Py_END_CRITICAL_SECTION();
exit:
@@ -183,7 +183,7 @@ static PyObject *
select_poll_unregister_impl(pollObject *self, int fd);
static PyObject *
-select_poll_unregister(pollObject *self, PyObject *arg)
+select_poll_unregister(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int fd;
@@ -193,7 +193,7 @@ select_poll_unregister(pollObject *self, PyObject *arg)
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = select_poll_unregister_impl(self, fd);
+ return_value = select_poll_unregister_impl((pollObject *)self, fd);
Py_END_CRITICAL_SECTION();
exit:
@@ -224,7 +224,7 @@ static PyObject *
select_poll_poll_impl(pollObject *self, PyObject *timeout_obj);
static PyObject *
-select_poll_poll(pollObject *self, PyObject *const *args, Py_ssize_t nargs)
+select_poll_poll(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *timeout_obj = Py_None;
@@ -238,7 +238,7 @@ select_poll_poll(pollObject *self, PyObject *const *args, Py_ssize_t nargs)
timeout_obj = args[0];
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = select_poll_poll_impl(self, timeout_obj);
+ return_value = select_poll_poll_impl((pollObject *)self, timeout_obj);
Py_END_CRITICAL_SECTION();
exit:
@@ -270,7 +270,7 @@ select_devpoll_register_impl(devpollObject *self, int fd,
unsigned short eventmask);
static PyObject *
-select_devpoll_register(devpollObject *self, PyObject *const *args, Py_ssize_t nargs)
+select_devpoll_register(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int fd;
@@ -291,7 +291,7 @@ select_devpoll_register(devpollObject *self, PyObject *const *args, Py_ssize_t n
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = select_devpoll_register_impl(self, fd, eventmask);
+ return_value = select_devpoll_register_impl((devpollObject *)self, fd, eventmask);
Py_END_CRITICAL_SECTION();
exit:
@@ -323,7 +323,7 @@ select_devpoll_modify_impl(devpollObject *self, int fd,
unsigned short eventmask);
static PyObject *
-select_devpoll_modify(devpollObject *self, PyObject *const *args, Py_ssize_t nargs)
+select_devpoll_modify(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int fd;
@@ -344,7 +344,7 @@ select_devpoll_modify(devpollObject *self, PyObject *const *args, Py_ssize_t nar
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = select_devpoll_modify_impl(self, fd, eventmask);
+ return_value = select_devpoll_modify_impl((devpollObject *)self, fd, eventmask);
Py_END_CRITICAL_SECTION();
exit:
@@ -368,7 +368,7 @@ static PyObject *
select_devpoll_unregister_impl(devpollObject *self, int fd);
static PyObject *
-select_devpoll_unregister(devpollObject *self, PyObject *arg)
+select_devpoll_unregister(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int fd;
@@ -378,7 +378,7 @@ select_devpoll_unregister(devpollObject *self, PyObject *arg)
goto exit;
}
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = select_devpoll_unregister_impl(self, fd);
+ return_value = select_devpoll_unregister_impl((devpollObject *)self, fd);
Py_END_CRITICAL_SECTION();
exit:
@@ -409,7 +409,7 @@ static PyObject *
select_devpoll_poll_impl(devpollObject *self, PyObject *timeout_obj);
static PyObject *
-select_devpoll_poll(devpollObject *self, PyObject *const *args, Py_ssize_t nargs)
+select_devpoll_poll(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *timeout_obj = Py_None;
@@ -423,7 +423,7 @@ select_devpoll_poll(devpollObject *self, PyObject *const *args, Py_ssize_t nargs
timeout_obj = args[0];
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = select_devpoll_poll_impl(self, timeout_obj);
+ return_value = select_devpoll_poll_impl((devpollObject *)self, timeout_obj);
Py_END_CRITICAL_SECTION();
exit:
@@ -449,12 +449,12 @@ static PyObject *
select_devpoll_close_impl(devpollObject *self);
static PyObject *
-select_devpoll_close(devpollObject *self, PyObject *Py_UNUSED(ignored))
+select_devpoll_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = select_devpoll_close_impl(self);
+ return_value = select_devpoll_close_impl((devpollObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -477,12 +477,12 @@ static PyObject *
select_devpoll_fileno_impl(devpollObject *self);
static PyObject *
-select_devpoll_fileno(devpollObject *self, PyObject *Py_UNUSED(ignored))
+select_devpoll_fileno(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = select_devpoll_fileno_impl(self);
+ return_value = select_devpoll_fileno_impl((devpollObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -643,12 +643,12 @@ static PyObject *
select_epoll_close_impl(pyEpoll_Object *self);
static PyObject *
-select_epoll_close(pyEpoll_Object *self, PyObject *Py_UNUSED(ignored))
+select_epoll_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = select_epoll_close_impl(self);
+ return_value = select_epoll_close_impl((pyEpoll_Object *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -671,9 +671,9 @@ static PyObject *
select_epoll_fileno_impl(pyEpoll_Object *self);
static PyObject *
-select_epoll_fileno(pyEpoll_Object *self, PyObject *Py_UNUSED(ignored))
+select_epoll_fileno(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return select_epoll_fileno_impl(self);
+ return select_epoll_fileno_impl((pyEpoll_Object *)self);
}
#endif /* defined(HAVE_EPOLL) */
@@ -734,7 +734,7 @@ select_epoll_register_impl(pyEpoll_Object *self, int fd,
unsigned int eventmask);
static PyObject *
-select_epoll_register(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+select_epoll_register(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -784,7 +784,7 @@ select_epoll_register(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t na
goto exit;
}
skip_optional_pos:
- return_value = select_epoll_register_impl(self, fd, eventmask);
+ return_value = select_epoll_register_impl((pyEpoll_Object *)self, fd, eventmask);
exit:
return return_value;
@@ -813,7 +813,7 @@ select_epoll_modify_impl(pyEpoll_Object *self, int fd,
unsigned int eventmask);
static PyObject *
-select_epoll_modify(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+select_epoll_modify(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -858,7 +858,7 @@ select_epoll_modify(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t narg
if (eventmask == (unsigned int)-1 && PyErr_Occurred()) {
goto exit;
}
- return_value = select_epoll_modify_impl(self, fd, eventmask);
+ return_value = select_epoll_modify_impl((pyEpoll_Object *)self, fd, eventmask);
exit:
return return_value;
@@ -884,7 +884,7 @@ static PyObject *
select_epoll_unregister_impl(pyEpoll_Object *self, int fd);
static PyObject *
-select_epoll_unregister(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+select_epoll_unregister(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -924,7 +924,7 @@ select_epoll_unregister(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t
if (fd < 0) {
goto exit;
}
- return_value = select_epoll_unregister_impl(self, fd);
+ return_value = select_epoll_unregister_impl((pyEpoll_Object *)self, fd);
exit:
return return_value;
@@ -957,7 +957,7 @@ select_epoll_poll_impl(pyEpoll_Object *self, PyObject *timeout_obj,
int maxevents);
static PyObject *
-select_epoll_poll(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+select_epoll_poll(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1009,7 +1009,7 @@ select_epoll_poll(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs,
goto exit;
}
skip_optional_pos:
- return_value = select_epoll_poll_impl(self, timeout_obj, maxevents);
+ return_value = select_epoll_poll_impl((pyEpoll_Object *)self, timeout_obj, maxevents);
exit:
return return_value;
@@ -1031,9 +1031,9 @@ static PyObject *
select_epoll___enter___impl(pyEpoll_Object *self);
static PyObject *
-select_epoll___enter__(pyEpoll_Object *self, PyObject *Py_UNUSED(ignored))
+select_epoll___enter__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return select_epoll___enter___impl(self);
+ return select_epoll___enter___impl((pyEpoll_Object *)self);
}
#endif /* defined(HAVE_EPOLL) */
@@ -1053,7 +1053,7 @@ select_epoll___exit___impl(pyEpoll_Object *self, PyObject *exc_type,
PyObject *exc_value, PyObject *exc_tb);
static PyObject *
-select_epoll___exit__(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs)
+select_epoll___exit__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *exc_type = Py_None;
@@ -1076,7 +1076,7 @@ select_epoll___exit__(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t na
}
exc_tb = args[2];
skip_optional:
- return_value = select_epoll___exit___impl(self, exc_type, exc_value, exc_tb);
+ return_value = select_epoll___exit___impl((pyEpoll_Object *)self, exc_type, exc_value, exc_tb);
exit:
return return_value;
@@ -1146,12 +1146,12 @@ static PyObject *
select_kqueue_close_impl(kqueue_queue_Object *self);
static PyObject *
-select_kqueue_close(kqueue_queue_Object *self, PyObject *Py_UNUSED(ignored))
+select_kqueue_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = select_kqueue_close_impl(self);
+ return_value = select_kqueue_close_impl((kqueue_queue_Object *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -1174,9 +1174,9 @@ static PyObject *
select_kqueue_fileno_impl(kqueue_queue_Object *self);
static PyObject *
-select_kqueue_fileno(kqueue_queue_Object *self, PyObject *Py_UNUSED(ignored))
+select_kqueue_fileno(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return select_kqueue_fileno_impl(self);
+ return select_kqueue_fileno_impl((kqueue_queue_Object *)self);
}
#endif /* defined(HAVE_KQUEUE) */
@@ -1238,7 +1238,7 @@ select_kqueue_control_impl(kqueue_queue_Object *self, PyObject *changelist,
int maxevents, PyObject *otimeout);
static PyObject *
-select_kqueue_control(kqueue_queue_Object *self, PyObject *const *args, Py_ssize_t nargs)
+select_kqueue_control(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *changelist;
@@ -1258,7 +1258,7 @@ select_kqueue_control(kqueue_queue_Object *self, PyObject *const *args, Py_ssize
}
otimeout = args[2];
skip_optional:
- return_value = select_kqueue_control_impl(self, changelist, maxevents, otimeout);
+ return_value = select_kqueue_control_impl((kqueue_queue_Object *)self, changelist, maxevents, otimeout);
exit:
return return_value;
@@ -1365,4 +1365,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=78b4e67f7d401b5e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c18fd93efc5f4dce input=a9049054013a1b77]*/
diff --git a/Modules/clinic/sha1module.c.h b/Modules/clinic/sha1module.c.h
index 6af77ba64ecce6..ddd8e66a41d7ff 100644
--- a/Modules/clinic/sha1module.c.h
+++ b/Modules/clinic/sha1module.c.h
@@ -21,13 +21,13 @@ static PyObject *
SHA1Type_copy_impl(SHA1object *self, PyTypeObject *cls);
static PyObject *
-SHA1Type_copy(SHA1object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+SHA1Type_copy(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "copy() takes no arguments");
return NULL;
}
- return SHA1Type_copy_impl(self, cls);
+ return SHA1Type_copy_impl((SHA1object *)self, cls);
}
PyDoc_STRVAR(SHA1Type_digest__doc__,
@@ -43,9 +43,9 @@ static PyObject *
SHA1Type_digest_impl(SHA1object *self);
static PyObject *
-SHA1Type_digest(SHA1object *self, PyObject *Py_UNUSED(ignored))
+SHA1Type_digest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return SHA1Type_digest_impl(self);
+ return SHA1Type_digest_impl((SHA1object *)self);
}
PyDoc_STRVAR(SHA1Type_hexdigest__doc__,
@@ -61,9 +61,9 @@ static PyObject *
SHA1Type_hexdigest_impl(SHA1object *self);
static PyObject *
-SHA1Type_hexdigest(SHA1object *self, PyObject *Py_UNUSED(ignored))
+SHA1Type_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return SHA1Type_hexdigest_impl(self);
+ return SHA1Type_hexdigest_impl((SHA1object *)self);
}
PyDoc_STRVAR(SHA1Type_update__doc__,
@@ -149,4 +149,4 @@ _sha1_sha1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
exit:
return return_value;
}
-/*[clinic end generated code: output=917e2789f1f5ebf9 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ad6f3788a6e7ff6f input=a9049054013a1b77]*/
diff --git a/Modules/clinic/sha2module.c.h b/Modules/clinic/sha2module.c.h
index fec655a0dfaa58..d86f5510d752e8 100644
--- a/Modules/clinic/sha2module.c.h
+++ b/Modules/clinic/sha2module.c.h
@@ -21,13 +21,13 @@ static PyObject *
SHA256Type_copy_impl(SHA256object *self, PyTypeObject *cls);
static PyObject *
-SHA256Type_copy(SHA256object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+SHA256Type_copy(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "copy() takes no arguments");
return NULL;
}
- return SHA256Type_copy_impl(self, cls);
+ return SHA256Type_copy_impl((SHA256object *)self, cls);
}
PyDoc_STRVAR(SHA512Type_copy__doc__,
@@ -43,13 +43,13 @@ static PyObject *
SHA512Type_copy_impl(SHA512object *self, PyTypeObject *cls);
static PyObject *
-SHA512Type_copy(SHA512object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+SHA512Type_copy(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "copy() takes no arguments");
return NULL;
}
- return SHA512Type_copy_impl(self, cls);
+ return SHA512Type_copy_impl((SHA512object *)self, cls);
}
PyDoc_STRVAR(SHA256Type_digest__doc__,
@@ -65,9 +65,9 @@ static PyObject *
SHA256Type_digest_impl(SHA256object *self);
static PyObject *
-SHA256Type_digest(SHA256object *self, PyObject *Py_UNUSED(ignored))
+SHA256Type_digest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return SHA256Type_digest_impl(self);
+ return SHA256Type_digest_impl((SHA256object *)self);
}
PyDoc_STRVAR(SHA512Type_digest__doc__,
@@ -83,9 +83,9 @@ static PyObject *
SHA512Type_digest_impl(SHA512object *self);
static PyObject *
-SHA512Type_digest(SHA512object *self, PyObject *Py_UNUSED(ignored))
+SHA512Type_digest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return SHA512Type_digest_impl(self);
+ return SHA512Type_digest_impl((SHA512object *)self);
}
PyDoc_STRVAR(SHA256Type_hexdigest__doc__,
@@ -101,9 +101,9 @@ static PyObject *
SHA256Type_hexdigest_impl(SHA256object *self);
static PyObject *
-SHA256Type_hexdigest(SHA256object *self, PyObject *Py_UNUSED(ignored))
+SHA256Type_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return SHA256Type_hexdigest_impl(self);
+ return SHA256Type_hexdigest_impl((SHA256object *)self);
}
PyDoc_STRVAR(SHA512Type_hexdigest__doc__,
@@ -119,9 +119,9 @@ static PyObject *
SHA512Type_hexdigest_impl(SHA512object *self);
static PyObject *
-SHA512Type_hexdigest(SHA512object *self, PyObject *Py_UNUSED(ignored))
+SHA512Type_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return SHA512Type_hexdigest_impl(self);
+ return SHA512Type_hexdigest_impl((SHA512object *)self);
}
PyDoc_STRVAR(SHA256Type_update__doc__,
@@ -441,4 +441,4 @@ _sha2_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
exit:
return return_value;
}
-/*[clinic end generated code: output=602a6939b8ec0927 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=1d7fec114eb6b6e3 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/sha3module.c.h b/Modules/clinic/sha3module.c.h
index d9f4b66f81a038..729e216ce023cf 100644
--- a/Modules/clinic/sha3module.c.h
+++ b/Modules/clinic/sha3module.c.h
@@ -92,9 +92,9 @@ static PyObject *
_sha3_sha3_224_copy_impl(SHA3object *self);
static PyObject *
-_sha3_sha3_224_copy(SHA3object *self, PyObject *Py_UNUSED(ignored))
+_sha3_sha3_224_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _sha3_sha3_224_copy_impl(self);
+ return _sha3_sha3_224_copy_impl((SHA3object *)self);
}
PyDoc_STRVAR(_sha3_sha3_224_digest__doc__,
@@ -110,9 +110,9 @@ static PyObject *
_sha3_sha3_224_digest_impl(SHA3object *self);
static PyObject *
-_sha3_sha3_224_digest(SHA3object *self, PyObject *Py_UNUSED(ignored))
+_sha3_sha3_224_digest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _sha3_sha3_224_digest_impl(self);
+ return _sha3_sha3_224_digest_impl((SHA3object *)self);
}
PyDoc_STRVAR(_sha3_sha3_224_hexdigest__doc__,
@@ -128,9 +128,9 @@ static PyObject *
_sha3_sha3_224_hexdigest_impl(SHA3object *self);
static PyObject *
-_sha3_sha3_224_hexdigest(SHA3object *self, PyObject *Py_UNUSED(ignored))
+_sha3_sha3_224_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _sha3_sha3_224_hexdigest_impl(self);
+ return _sha3_sha3_224_hexdigest_impl((SHA3object *)self);
}
PyDoc_STRVAR(_sha3_sha3_224_update__doc__,
@@ -155,7 +155,7 @@ static PyObject *
_sha3_shake_128_digest_impl(SHA3object *self, unsigned long length);
static PyObject *
-_sha3_shake_128_digest(SHA3object *self, PyObject *arg)
+_sha3_shake_128_digest(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
unsigned long length;
@@ -163,7 +163,7 @@ _sha3_shake_128_digest(SHA3object *self, PyObject *arg)
if (!_PyLong_UnsignedLong_Converter(arg, &length)) {
goto exit;
}
- return_value = _sha3_shake_128_digest_impl(self, length);
+ return_value = _sha3_shake_128_digest_impl((SHA3object *)self, length);
exit:
return return_value;
@@ -182,7 +182,7 @@ static PyObject *
_sha3_shake_128_hexdigest_impl(SHA3object *self, unsigned long length);
static PyObject *
-_sha3_shake_128_hexdigest(SHA3object *self, PyObject *arg)
+_sha3_shake_128_hexdigest(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
unsigned long length;
@@ -190,9 +190,9 @@ _sha3_shake_128_hexdigest(SHA3object *self, PyObject *arg)
if (!_PyLong_UnsignedLong_Converter(arg, &length)) {
goto exit;
}
- return_value = _sha3_shake_128_hexdigest_impl(self, length);
+ return_value = _sha3_shake_128_hexdigest_impl((SHA3object *)self, length);
exit:
return return_value;
}
-/*[clinic end generated code: output=5c644eb0ed42b993 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=21da06d9570969d8 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/socketmodule.c.h b/Modules/clinic/socketmodule.c.h
index 2152f288a9722f..dc62c4290d3e3b 100644
--- a/Modules/clinic/socketmodule.c.h
+++ b/Modules/clinic/socketmodule.c.h
@@ -23,9 +23,9 @@ static PyObject *
_socket_socket_close_impl(PySocketSockObject *s);
static PyObject *
-_socket_socket_close(PySocketSockObject *s, PyObject *Py_UNUSED(ignored))
+_socket_socket_close(PyObject *s, PyObject *Py_UNUSED(ignored))
{
- return _socket_socket_close_impl(s);
+ return _socket_socket_close_impl((PySocketSockObject *)s);
}
static int
@@ -126,7 +126,7 @@ static PyObject *
_socket_socket_ntohs_impl(PySocketSockObject *self, int x);
static PyObject *
-_socket_socket_ntohs(PySocketSockObject *self, PyObject *arg)
+_socket_socket_ntohs(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int x;
@@ -135,7 +135,7 @@ _socket_socket_ntohs(PySocketSockObject *self, PyObject *arg)
if (x == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = _socket_socket_ntohs_impl(self, x);
+ return_value = _socket_socket_ntohs_impl((PySocketSockObject *)self, x);
exit:
return return_value;
@@ -154,7 +154,7 @@ static PyObject *
_socket_socket_htons_impl(PySocketSockObject *self, int x);
static PyObject *
-_socket_socket_htons(PySocketSockObject *self, PyObject *arg)
+_socket_socket_htons(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int x;
@@ -163,7 +163,7 @@ _socket_socket_htons(PySocketSockObject *self, PyObject *arg)
if (x == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = _socket_socket_htons_impl(self, x);
+ return_value = _socket_socket_htons_impl((PySocketSockObject *)self, x);
exit:
return return_value;
@@ -182,7 +182,7 @@ static PyObject *
_socket_socket_inet_aton_impl(PySocketSockObject *self, const char *ip_addr);
static PyObject *
-_socket_socket_inet_aton(PySocketSockObject *self, PyObject *arg)
+_socket_socket_inet_aton(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *ip_addr;
@@ -200,7 +200,7 @@ _socket_socket_inet_aton(PySocketSockObject *self, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = _socket_socket_inet_aton_impl(self, ip_addr);
+ return_value = _socket_socket_inet_aton_impl((PySocketSockObject *)self, ip_addr);
exit:
return return_value;
@@ -221,7 +221,7 @@ static PyObject *
_socket_socket_inet_ntoa_impl(PySocketSockObject *self, Py_buffer *packed_ip);
static PyObject *
-_socket_socket_inet_ntoa(PySocketSockObject *self, PyObject *arg)
+_socket_socket_inet_ntoa(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer packed_ip = {NULL, NULL};
@@ -229,7 +229,7 @@ _socket_socket_inet_ntoa(PySocketSockObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &packed_ip, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = _socket_socket_inet_ntoa_impl(self, &packed_ip);
+ return_value = _socket_socket_inet_ntoa_impl((PySocketSockObject *)self, &packed_ip);
exit:
/* Cleanup for packed_ip */
@@ -257,7 +257,7 @@ static PyObject *
_socket_socket_if_nametoindex_impl(PySocketSockObject *self, PyObject *oname);
static PyObject *
-_socket_socket_if_nametoindex(PySocketSockObject *self, PyObject *arg)
+_socket_socket_if_nametoindex(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
PyObject *oname;
@@ -265,7 +265,7 @@ _socket_socket_if_nametoindex(PySocketSockObject *self, PyObject *arg)
if (!PyUnicode_FSConverter(arg, &oname)) {
goto exit;
}
- return_value = _socket_socket_if_nametoindex_impl(self, oname);
+ return_value = _socket_socket_if_nametoindex_impl((PySocketSockObject *)self, oname);
exit:
return return_value;
@@ -280,4 +280,4 @@ _socket_socket_if_nametoindex(PySocketSockObject *self, PyObject *arg)
#ifndef _SOCKET_SOCKET_IF_NAMETOINDEX_METHODDEF
#define _SOCKET_SOCKET_IF_NAMETOINDEX_METHODDEF
#endif /* !defined(_SOCKET_SOCKET_IF_NAMETOINDEX_METHODDEF) */
-/*[clinic end generated code: output=3e612e8df1c322dd input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d39efc30d811e74b input=a9049054013a1b77]*/
diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h
index 19906dc328d897..91a3ac76bcf0cc 100644
--- a/Modules/clinic/zlibmodule.c.h
+++ b/Modules/clinic/zlibmodule.c.h
@@ -439,7 +439,7 @@ zlib_Compress_compress_impl(compobject *self, PyTypeObject *cls,
Py_buffer *data);
static PyObject *
-zlib_Compress_compress(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+zlib_Compress_compress(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -466,7 +466,7 @@ zlib_Compress_compress(compobject *self, PyTypeObject *cls, PyObject *const *arg
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = zlib_Compress_compress_impl(self, cls, &data);
+ return_value = zlib_Compress_compress_impl((compobject *)self, cls, &data);
exit:
/* Cleanup for data */
@@ -502,7 +502,7 @@ zlib_Decompress_decompress_impl(compobject *self, PyTypeObject *cls,
Py_buffer *data, Py_ssize_t max_length);
static PyObject *
-zlib_Decompress_decompress(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+zlib_Decompress_decompress(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -559,7 +559,7 @@ zlib_Decompress_decompress(compobject *self, PyTypeObject *cls, PyObject *const
max_length = ival;
}
skip_optional_pos:
- return_value = zlib_Decompress_decompress_impl(self, cls, &data, max_length);
+ return_value = zlib_Decompress_decompress_impl((compobject *)self, cls, &data, max_length);
exit:
/* Cleanup for data */
@@ -589,7 +589,7 @@ static PyObject *
zlib_Compress_flush_impl(compobject *self, PyTypeObject *cls, int mode);
static PyObject *
-zlib_Compress_flush(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+zlib_Compress_flush(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -621,7 +621,7 @@ zlib_Compress_flush(compobject *self, PyTypeObject *cls, PyObject *const *args,
goto exit;
}
skip_optional_posonly:
- return_value = zlib_Compress_flush_impl(self, cls, mode);
+ return_value = zlib_Compress_flush_impl((compobject *)self, cls, mode);
exit:
return return_value;
@@ -642,13 +642,13 @@ static PyObject *
zlib_Compress_copy_impl(compobject *self, PyTypeObject *cls);
static PyObject *
-zlib_Compress_copy(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+zlib_Compress_copy(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "copy() takes no arguments");
return NULL;
}
- return zlib_Compress_copy_impl(self, cls);
+ return zlib_Compress_copy_impl((compobject *)self, cls);
}
#endif /* defined(HAVE_ZLIB_COPY) */
@@ -667,13 +667,13 @@ static PyObject *
zlib_Compress___copy___impl(compobject *self, PyTypeObject *cls);
static PyObject *
-zlib_Compress___copy__(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+zlib_Compress___copy__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "__copy__() takes no arguments");
return NULL;
}
- return zlib_Compress___copy___impl(self, cls);
+ return zlib_Compress___copy___impl((compobject *)self, cls);
}
#endif /* defined(HAVE_ZLIB_COPY) */
@@ -693,7 +693,7 @@ zlib_Compress___deepcopy___impl(compobject *self, PyTypeObject *cls,
PyObject *memo);
static PyObject *
-zlib_Compress___deepcopy__(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+zlib_Compress___deepcopy__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -718,7 +718,7 @@ zlib_Compress___deepcopy__(compobject *self, PyTypeObject *cls, PyObject *const
goto exit;
}
memo = args[0];
- return_value = zlib_Compress___deepcopy___impl(self, cls, memo);
+ return_value = zlib_Compress___deepcopy___impl((compobject *)self, cls, memo);
exit:
return return_value;
@@ -741,13 +741,13 @@ static PyObject *
zlib_Decompress_copy_impl(compobject *self, PyTypeObject *cls);
static PyObject *
-zlib_Decompress_copy(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+zlib_Decompress_copy(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "copy() takes no arguments");
return NULL;
}
- return zlib_Decompress_copy_impl(self, cls);
+ return zlib_Decompress_copy_impl((compobject *)self, cls);
}
#endif /* defined(HAVE_ZLIB_COPY) */
@@ -766,13 +766,13 @@ static PyObject *
zlib_Decompress___copy___impl(compobject *self, PyTypeObject *cls);
static PyObject *
-zlib_Decompress___copy__(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+zlib_Decompress___copy__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "__copy__() takes no arguments");
return NULL;
}
- return zlib_Decompress___copy___impl(self, cls);
+ return zlib_Decompress___copy___impl((compobject *)self, cls);
}
#endif /* defined(HAVE_ZLIB_COPY) */
@@ -792,7 +792,7 @@ zlib_Decompress___deepcopy___impl(compobject *self, PyTypeObject *cls,
PyObject *memo);
static PyObject *
-zlib_Decompress___deepcopy__(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+zlib_Decompress___deepcopy__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -817,7 +817,7 @@ zlib_Decompress___deepcopy__(compobject *self, PyTypeObject *cls, PyObject *cons
goto exit;
}
memo = args[0];
- return_value = zlib_Decompress___deepcopy___impl(self, cls, memo);
+ return_value = zlib_Decompress___deepcopy___impl((compobject *)self, cls, memo);
exit:
return return_value;
@@ -842,7 +842,7 @@ zlib_Decompress_flush_impl(compobject *self, PyTypeObject *cls,
Py_ssize_t length);
static PyObject *
-zlib_Decompress_flush(compobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+zlib_Decompress_flush(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -882,7 +882,7 @@ zlib_Decompress_flush(compobject *self, PyTypeObject *cls, PyObject *const *args
length = ival;
}
skip_optional_posonly:
- return_value = zlib_Decompress_flush_impl(self, cls, length);
+ return_value = zlib_Decompress_flush_impl((compobject *)self, cls, length);
exit:
return return_value;
@@ -915,7 +915,7 @@ zlib_ZlibDecompressor_decompress_impl(ZlibDecompressor *self,
Py_buffer *data, Py_ssize_t max_length);
static PyObject *
-zlib_ZlibDecompressor_decompress(ZlibDecompressor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+zlib_ZlibDecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -972,7 +972,7 @@ zlib_ZlibDecompressor_decompress(ZlibDecompressor *self, PyObject *const *args,
max_length = ival;
}
skip_optional_pos:
- return_value = zlib_ZlibDecompressor_decompress_impl(self, &data, max_length);
+ return_value = zlib_ZlibDecompressor_decompress_impl((ZlibDecompressor *)self, &data, max_length);
exit:
/* Cleanup for data */
@@ -1109,4 +1109,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=2fef49f168842b17 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=969872868c303e8a input=a9049054013a1b77]*/
diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h
index dee7c1e8bffd25..91cf5363e639d1 100644
--- a/Objects/clinic/bytearrayobject.c.h
+++ b/Objects/clinic/bytearrayobject.c.h
@@ -123,7 +123,7 @@ bytearray_find_impl(PyByteArrayObject *self, PyObject *sub, Py_ssize_t start,
Py_ssize_t end);
static PyObject *
-bytearray_find(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_find(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sub;
@@ -147,7 +147,7 @@ bytearray_find(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = bytearray_find_impl(self, sub, start, end);
+ return_value = bytearray_find_impl((PyByteArrayObject *)self, sub, start, end);
exit:
return return_value;
@@ -172,7 +172,7 @@ bytearray_count_impl(PyByteArrayObject *self, PyObject *sub,
Py_ssize_t start, Py_ssize_t end);
static PyObject *
-bytearray_count(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_count(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sub;
@@ -196,7 +196,7 @@ bytearray_count(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs
goto exit;
}
skip_optional:
- return_value = bytearray_count_impl(self, sub, start, end);
+ return_value = bytearray_count_impl((PyByteArrayObject *)self, sub, start, end);
exit:
return return_value;
@@ -215,9 +215,9 @@ static PyObject *
bytearray_clear_impl(PyByteArrayObject *self);
static PyObject *
-bytearray_clear(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
+bytearray_clear(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return bytearray_clear_impl(self);
+ return bytearray_clear_impl((PyByteArrayObject *)self);
}
PyDoc_STRVAR(bytearray_copy__doc__,
@@ -233,9 +233,9 @@ static PyObject *
bytearray_copy_impl(PyByteArrayObject *self);
static PyObject *
-bytearray_copy(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
+bytearray_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return bytearray_copy_impl(self);
+ return bytearray_copy_impl((PyByteArrayObject *)self);
}
PyDoc_STRVAR(bytearray_index__doc__,
@@ -259,7 +259,7 @@ bytearray_index_impl(PyByteArrayObject *self, PyObject *sub,
Py_ssize_t start, Py_ssize_t end);
static PyObject *
-bytearray_index(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sub;
@@ -283,7 +283,7 @@ bytearray_index(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs
goto exit;
}
skip_optional:
- return_value = bytearray_index_impl(self, sub, start, end);
+ return_value = bytearray_index_impl((PyByteArrayObject *)self, sub, start, end);
exit:
return return_value;
@@ -310,7 +310,7 @@ bytearray_rfind_impl(PyByteArrayObject *self, PyObject *sub,
Py_ssize_t start, Py_ssize_t end);
static PyObject *
-bytearray_rfind(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_rfind(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sub;
@@ -334,7 +334,7 @@ bytearray_rfind(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs
goto exit;
}
skip_optional:
- return_value = bytearray_rfind_impl(self, sub, start, end);
+ return_value = bytearray_rfind_impl((PyByteArrayObject *)self, sub, start, end);
exit:
return return_value;
@@ -361,7 +361,7 @@ bytearray_rindex_impl(PyByteArrayObject *self, PyObject *sub,
Py_ssize_t start, Py_ssize_t end);
static PyObject *
-bytearray_rindex(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_rindex(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sub;
@@ -385,7 +385,7 @@ bytearray_rindex(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
goto exit;
}
skip_optional:
- return_value = bytearray_rindex_impl(self, sub, start, end);
+ return_value = bytearray_rindex_impl((PyByteArrayObject *)self, sub, start, end);
exit:
return return_value;
@@ -412,7 +412,7 @@ bytearray_startswith_impl(PyByteArrayObject *self, PyObject *subobj,
Py_ssize_t start, Py_ssize_t end);
static PyObject *
-bytearray_startswith(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_startswith(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *subobj;
@@ -436,7 +436,7 @@ bytearray_startswith(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t
goto exit;
}
skip_optional:
- return_value = bytearray_startswith_impl(self, subobj, start, end);
+ return_value = bytearray_startswith_impl((PyByteArrayObject *)self, subobj, start, end);
exit:
return return_value;
@@ -463,7 +463,7 @@ bytearray_endswith_impl(PyByteArrayObject *self, PyObject *subobj,
Py_ssize_t start, Py_ssize_t end);
static PyObject *
-bytearray_endswith(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_endswith(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *subobj;
@@ -487,7 +487,7 @@ bytearray_endswith(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t na
goto exit;
}
skip_optional:
- return_value = bytearray_endswith_impl(self, subobj, start, end);
+ return_value = bytearray_endswith_impl((PyByteArrayObject *)self, subobj, start, end);
exit:
return return_value;
@@ -510,7 +510,7 @@ static PyObject *
bytearray_removeprefix_impl(PyByteArrayObject *self, Py_buffer *prefix);
static PyObject *
-bytearray_removeprefix(PyByteArrayObject *self, PyObject *arg)
+bytearray_removeprefix(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer prefix = {NULL, NULL};
@@ -518,7 +518,7 @@ bytearray_removeprefix(PyByteArrayObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &prefix, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = bytearray_removeprefix_impl(self, &prefix);
+ return_value = bytearray_removeprefix_impl((PyByteArrayObject *)self, &prefix);
exit:
/* Cleanup for prefix */
@@ -546,7 +546,7 @@ static PyObject *
bytearray_removesuffix_impl(PyByteArrayObject *self, Py_buffer *suffix);
static PyObject *
-bytearray_removesuffix(PyByteArrayObject *self, PyObject *arg)
+bytearray_removesuffix(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer suffix = {NULL, NULL};
@@ -554,7 +554,7 @@ bytearray_removesuffix(PyByteArrayObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &suffix, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = bytearray_removesuffix_impl(self, &suffix);
+ return_value = bytearray_removesuffix_impl((PyByteArrayObject *)self, &suffix);
exit:
/* Cleanup for suffix */
@@ -585,7 +585,7 @@ bytearray_translate_impl(PyByteArrayObject *self, PyObject *table,
PyObject *deletechars);
static PyObject *
-bytearray_translate(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+bytearray_translate(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -629,7 +629,7 @@ bytearray_translate(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t n
}
deletechars = args[1];
skip_optional_pos:
- return_value = bytearray_translate_impl(self, table, deletechars);
+ return_value = bytearray_translate_impl((PyByteArrayObject *)self, table, deletechars);
exit:
return return_value;
@@ -704,7 +704,7 @@ bytearray_replace_impl(PyByteArrayObject *self, Py_buffer *old,
Py_buffer *new, Py_ssize_t count);
static PyObject *
-bytearray_replace(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_buffer old = {NULL, NULL};
@@ -736,7 +736,7 @@ bytearray_replace(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nar
count = ival;
}
skip_optional:
- return_value = bytearray_replace_impl(self, &old, &new, count);
+ return_value = bytearray_replace_impl((PyByteArrayObject *)self, &old, &new, count);
exit:
/* Cleanup for old */
@@ -773,7 +773,7 @@ bytearray_split_impl(PyByteArrayObject *self, PyObject *sep,
Py_ssize_t maxsplit);
static PyObject *
-bytearray_split(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+bytearray_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -833,7 +833,7 @@ bytearray_split(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs
maxsplit = ival;
}
skip_optional_pos:
- return_value = bytearray_split_impl(self, sep, maxsplit);
+ return_value = bytearray_split_impl((PyByteArrayObject *)self, sep, maxsplit);
exit:
return return_value;
@@ -896,7 +896,7 @@ bytearray_rsplit_impl(PyByteArrayObject *self, PyObject *sep,
Py_ssize_t maxsplit);
static PyObject *
-bytearray_rsplit(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+bytearray_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -956,7 +956,7 @@ bytearray_rsplit(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
maxsplit = ival;
}
skip_optional_pos:
- return_value = bytearray_rsplit_impl(self, sep, maxsplit);
+ return_value = bytearray_rsplit_impl((PyByteArrayObject *)self, sep, maxsplit);
exit:
return return_value;
@@ -975,9 +975,9 @@ static PyObject *
bytearray_reverse_impl(PyByteArrayObject *self);
static PyObject *
-bytearray_reverse(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
+bytearray_reverse(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return bytearray_reverse_impl(self);
+ return bytearray_reverse_impl((PyByteArrayObject *)self);
}
PyDoc_STRVAR(bytearray_insert__doc__,
@@ -998,7 +998,7 @@ static PyObject *
bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item);
static PyObject *
-bytearray_insert(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_insert(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t index;
@@ -1022,7 +1022,7 @@ bytearray_insert(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
if (!_getbytevalue(args[1], &item)) {
goto exit;
}
- return_value = bytearray_insert_impl(self, index, item);
+ return_value = bytearray_insert_impl((PyByteArrayObject *)self, index, item);
exit:
return return_value;
@@ -1044,7 +1044,7 @@ static PyObject *
bytearray_append_impl(PyByteArrayObject *self, int item);
static PyObject *
-bytearray_append(PyByteArrayObject *self, PyObject *arg)
+bytearray_append(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int item;
@@ -1052,7 +1052,7 @@ bytearray_append(PyByteArrayObject *self, PyObject *arg)
if (!_getbytevalue(arg, &item)) {
goto exit;
}
- return_value = bytearray_append_impl(self, item);
+ return_value = bytearray_append_impl((PyByteArrayObject *)self, item);
exit:
return return_value;
@@ -1089,7 +1089,7 @@ static PyObject *
bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index);
static PyObject *
-bytearray_pop(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_pop(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t index = -1;
@@ -1113,7 +1113,7 @@ bytearray_pop(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
index = ival;
}
skip_optional:
- return_value = bytearray_pop_impl(self, index);
+ return_value = bytearray_pop_impl((PyByteArrayObject *)self, index);
exit:
return return_value;
@@ -1135,7 +1135,7 @@ static PyObject *
bytearray_remove_impl(PyByteArrayObject *self, int value);
static PyObject *
-bytearray_remove(PyByteArrayObject *self, PyObject *arg)
+bytearray_remove(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int value;
@@ -1143,7 +1143,7 @@ bytearray_remove(PyByteArrayObject *self, PyObject *arg)
if (!_getbytevalue(arg, &value)) {
goto exit;
}
- return_value = bytearray_remove_impl(self, value);
+ return_value = bytearray_remove_impl((PyByteArrayObject *)self, value);
exit:
return return_value;
@@ -1164,7 +1164,7 @@ static PyObject *
bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes);
static PyObject *
-bytearray_strip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_strip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *bytes = Py_None;
@@ -1177,7 +1177,7 @@ bytearray_strip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs
}
bytes = args[0];
skip_optional:
- return_value = bytearray_strip_impl(self, bytes);
+ return_value = bytearray_strip_impl((PyByteArrayObject *)self, bytes);
exit:
return return_value;
@@ -1198,7 +1198,7 @@ static PyObject *
bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes);
static PyObject *
-bytearray_lstrip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_lstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *bytes = Py_None;
@@ -1211,7 +1211,7 @@ bytearray_lstrip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
}
bytes = args[0];
skip_optional:
- return_value = bytearray_lstrip_impl(self, bytes);
+ return_value = bytearray_lstrip_impl((PyByteArrayObject *)self, bytes);
exit:
return return_value;
@@ -1232,7 +1232,7 @@ static PyObject *
bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes);
static PyObject *
-bytearray_rstrip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_rstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *bytes = Py_None;
@@ -1245,7 +1245,7 @@ bytearray_rstrip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
}
bytes = args[0];
skip_optional:
- return_value = bytearray_rstrip_impl(self, bytes);
+ return_value = bytearray_rstrip_impl((PyByteArrayObject *)self, bytes);
exit:
return return_value;
@@ -1274,7 +1274,7 @@ bytearray_decode_impl(PyByteArrayObject *self, const char *encoding,
const char *errors);
static PyObject *
-bytearray_decode(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+bytearray_decode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1347,7 +1347,7 @@ bytearray_decode(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
goto exit;
}
skip_optional_pos:
- return_value = bytearray_decode_impl(self, encoding, errors);
+ return_value = bytearray_decode_impl((PyByteArrayObject *)self, encoding, errors);
exit:
return return_value;
@@ -1382,7 +1382,7 @@ static PyObject *
bytearray_splitlines_impl(PyByteArrayObject *self, int keepends);
static PyObject *
-bytearray_splitlines(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+bytearray_splitlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1427,7 +1427,7 @@ bytearray_splitlines(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t
goto exit;
}
skip_optional_pos:
- return_value = bytearray_splitlines_impl(self, keepends);
+ return_value = bytearray_splitlines_impl((PyByteArrayObject *)self, keepends);
exit:
return return_value;
@@ -1495,7 +1495,7 @@ static PyObject *
bytearray_hex_impl(PyByteArrayObject *self, PyObject *sep, int bytes_per_sep);
static PyObject *
-bytearray_hex(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+bytearray_hex(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1547,7 +1547,7 @@ bytearray_hex(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs,
goto exit;
}
skip_optional_pos:
- return_value = bytearray_hex_impl(self, sep, bytes_per_sep);
+ return_value = bytearray_hex_impl((PyByteArrayObject *)self, sep, bytes_per_sep);
exit:
return return_value;
@@ -1566,9 +1566,9 @@ static PyObject *
bytearray_reduce_impl(PyByteArrayObject *self);
static PyObject *
-bytearray_reduce(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
+bytearray_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return bytearray_reduce_impl(self);
+ return bytearray_reduce_impl((PyByteArrayObject *)self);
}
PyDoc_STRVAR(bytearray_reduce_ex__doc__,
@@ -1584,7 +1584,7 @@ static PyObject *
bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto);
static PyObject *
-bytearray_reduce_ex(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytearray_reduce_ex(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
int proto = 0;
@@ -1600,7 +1600,7 @@ bytearray_reduce_ex(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t n
goto exit;
}
skip_optional:
- return_value = bytearray_reduce_ex_impl(self, proto);
+ return_value = bytearray_reduce_ex_impl((PyByteArrayObject *)self, proto);
exit:
return return_value;
@@ -1619,8 +1619,8 @@ static PyObject *
bytearray_sizeof_impl(PyByteArrayObject *self);
static PyObject *
-bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
+bytearray_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return bytearray_sizeof_impl(self);
+ return bytearray_sizeof_impl((PyByteArrayObject *)self);
}
-/*[clinic end generated code: output=4488e38e7ffcc6ec input=a9049054013a1b77]*/
+/*[clinic end generated code: output=bc8bec8514102bf3 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h
index d2c6cc88770999..9aef736428ad0e 100644
--- a/Objects/clinic/bytesobject.c.h
+++ b/Objects/clinic/bytesobject.c.h
@@ -22,9 +22,9 @@ static PyObject *
bytes___bytes___impl(PyBytesObject *self);
static PyObject *
-bytes___bytes__(PyBytesObject *self, PyObject *Py_UNUSED(ignored))
+bytes___bytes__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return bytes___bytes___impl(self);
+ return bytes___bytes___impl((PyBytesObject *)self);
}
PyDoc_STRVAR(bytes_split__doc__,
@@ -48,7 +48,7 @@ static PyObject *
bytes_split_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit);
static PyObject *
-bytes_split(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+bytes_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -108,7 +108,7 @@ bytes_split(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje
maxsplit = ival;
}
skip_optional_pos:
- return_value = bytes_split_impl(self, sep, maxsplit);
+ return_value = bytes_split_impl((PyBytesObject *)self, sep, maxsplit);
exit:
return return_value;
@@ -134,7 +134,7 @@ static PyObject *
bytes_partition_impl(PyBytesObject *self, Py_buffer *sep);
static PyObject *
-bytes_partition(PyBytesObject *self, PyObject *arg)
+bytes_partition(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer sep = {NULL, NULL};
@@ -142,7 +142,7 @@ bytes_partition(PyBytesObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = bytes_partition_impl(self, &sep);
+ return_value = bytes_partition_impl((PyBytesObject *)self, &sep);
exit:
/* Cleanup for sep */
@@ -173,7 +173,7 @@ static PyObject *
bytes_rpartition_impl(PyBytesObject *self, Py_buffer *sep);
static PyObject *
-bytes_rpartition(PyBytesObject *self, PyObject *arg)
+bytes_rpartition(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer sep = {NULL, NULL};
@@ -181,7 +181,7 @@ bytes_rpartition(PyBytesObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = bytes_rpartition_impl(self, &sep);
+ return_value = bytes_rpartition_impl((PyBytesObject *)self, &sep);
exit:
/* Cleanup for sep */
@@ -215,7 +215,7 @@ static PyObject *
bytes_rsplit_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit);
static PyObject *
-bytes_rsplit(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+bytes_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -275,7 +275,7 @@ bytes_rsplit(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj
maxsplit = ival;
}
skip_optional_pos:
- return_value = bytes_rsplit_impl(self, sep, maxsplit);
+ return_value = bytes_rsplit_impl((PyBytesObject *)self, sep, maxsplit);
exit:
return return_value;
@@ -317,7 +317,7 @@ bytes_find_impl(PyBytesObject *self, PyObject *sub, Py_ssize_t start,
Py_ssize_t end);
static PyObject *
-bytes_find(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytes_find(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sub;
@@ -341,7 +341,7 @@ bytes_find(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = bytes_find_impl(self, sub, start, end);
+ return_value = bytes_find_impl((PyBytesObject *)self, sub, start, end);
exit:
return return_value;
@@ -368,7 +368,7 @@ bytes_index_impl(PyBytesObject *self, PyObject *sub, Py_ssize_t start,
Py_ssize_t end);
static PyObject *
-bytes_index(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytes_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sub;
@@ -392,7 +392,7 @@ bytes_index(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = bytes_index_impl(self, sub, start, end);
+ return_value = bytes_index_impl((PyBytesObject *)self, sub, start, end);
exit:
return return_value;
@@ -419,7 +419,7 @@ bytes_rfind_impl(PyBytesObject *self, PyObject *sub, Py_ssize_t start,
Py_ssize_t end);
static PyObject *
-bytes_rfind(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytes_rfind(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sub;
@@ -443,7 +443,7 @@ bytes_rfind(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = bytes_rfind_impl(self, sub, start, end);
+ return_value = bytes_rfind_impl((PyBytesObject *)self, sub, start, end);
exit:
return return_value;
@@ -470,7 +470,7 @@ bytes_rindex_impl(PyBytesObject *self, PyObject *sub, Py_ssize_t start,
Py_ssize_t end);
static PyObject *
-bytes_rindex(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytes_rindex(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sub;
@@ -494,7 +494,7 @@ bytes_rindex(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = bytes_rindex_impl(self, sub, start, end);
+ return_value = bytes_rindex_impl((PyBytesObject *)self, sub, start, end);
exit:
return return_value;
@@ -515,7 +515,7 @@ static PyObject *
bytes_strip_impl(PyBytesObject *self, PyObject *bytes);
static PyObject *
-bytes_strip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytes_strip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *bytes = Py_None;
@@ -528,7 +528,7 @@ bytes_strip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
}
bytes = args[0];
skip_optional:
- return_value = bytes_strip_impl(self, bytes);
+ return_value = bytes_strip_impl((PyBytesObject *)self, bytes);
exit:
return return_value;
@@ -549,7 +549,7 @@ static PyObject *
bytes_lstrip_impl(PyBytesObject *self, PyObject *bytes);
static PyObject *
-bytes_lstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytes_lstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *bytes = Py_None;
@@ -562,7 +562,7 @@ bytes_lstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
}
bytes = args[0];
skip_optional:
- return_value = bytes_lstrip_impl(self, bytes);
+ return_value = bytes_lstrip_impl((PyBytesObject *)self, bytes);
exit:
return return_value;
@@ -583,7 +583,7 @@ static PyObject *
bytes_rstrip_impl(PyBytesObject *self, PyObject *bytes);
static PyObject *
-bytes_rstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytes_rstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *bytes = Py_None;
@@ -596,7 +596,7 @@ bytes_rstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
}
bytes = args[0];
skip_optional:
- return_value = bytes_rstrip_impl(self, bytes);
+ return_value = bytes_rstrip_impl((PyBytesObject *)self, bytes);
exit:
return return_value;
@@ -621,7 +621,7 @@ bytes_count_impl(PyBytesObject *self, PyObject *sub, Py_ssize_t start,
Py_ssize_t end);
static PyObject *
-bytes_count(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytes_count(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *sub;
@@ -645,7 +645,7 @@ bytes_count(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = bytes_count_impl(self, sub, start, end);
+ return_value = bytes_count_impl((PyBytesObject *)self, sub, start, end);
exit:
return return_value;
@@ -671,7 +671,7 @@ bytes_translate_impl(PyBytesObject *self, PyObject *table,
PyObject *deletechars);
static PyObject *
-bytes_translate(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+bytes_translate(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -715,7 +715,7 @@ bytes_translate(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, Py
}
deletechars = args[1];
skip_optional_pos:
- return_value = bytes_translate_impl(self, table, deletechars);
+ return_value = bytes_translate_impl((PyBytesObject *)self, table, deletechars);
exit:
return return_value;
@@ -790,7 +790,7 @@ bytes_replace_impl(PyBytesObject *self, Py_buffer *old, Py_buffer *new,
Py_ssize_t count);
static PyObject *
-bytes_replace(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytes_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_buffer old = {NULL, NULL};
@@ -822,7 +822,7 @@ bytes_replace(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
count = ival;
}
skip_optional:
- return_value = bytes_replace_impl(self, &old, &new, count);
+ return_value = bytes_replace_impl((PyBytesObject *)self, &old, &new, count);
exit:
/* Cleanup for old */
@@ -853,7 +853,7 @@ static PyObject *
bytes_removeprefix_impl(PyBytesObject *self, Py_buffer *prefix);
static PyObject *
-bytes_removeprefix(PyBytesObject *self, PyObject *arg)
+bytes_removeprefix(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer prefix = {NULL, NULL};
@@ -861,7 +861,7 @@ bytes_removeprefix(PyBytesObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &prefix, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = bytes_removeprefix_impl(self, &prefix);
+ return_value = bytes_removeprefix_impl((PyBytesObject *)self, &prefix);
exit:
/* Cleanup for prefix */
@@ -889,7 +889,7 @@ static PyObject *
bytes_removesuffix_impl(PyBytesObject *self, Py_buffer *suffix);
static PyObject *
-bytes_removesuffix(PyBytesObject *self, PyObject *arg)
+bytes_removesuffix(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer suffix = {NULL, NULL};
@@ -897,7 +897,7 @@ bytes_removesuffix(PyBytesObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &suffix, PyBUF_SIMPLE) != 0) {
goto exit;
}
- return_value = bytes_removesuffix_impl(self, &suffix);
+ return_value = bytes_removesuffix_impl((PyBytesObject *)self, &suffix);
exit:
/* Cleanup for suffix */
@@ -929,7 +929,7 @@ bytes_startswith_impl(PyBytesObject *self, PyObject *subobj,
Py_ssize_t start, Py_ssize_t end);
static PyObject *
-bytes_startswith(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytes_startswith(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *subobj;
@@ -953,7 +953,7 @@ bytes_startswith(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = bytes_startswith_impl(self, subobj, start, end);
+ return_value = bytes_startswith_impl((PyBytesObject *)self, subobj, start, end);
exit:
return return_value;
@@ -980,7 +980,7 @@ bytes_endswith_impl(PyBytesObject *self, PyObject *subobj, Py_ssize_t start,
Py_ssize_t end);
static PyObject *
-bytes_endswith(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
+bytes_endswith(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *subobj;
@@ -1004,7 +1004,7 @@ bytes_endswith(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = bytes_endswith_impl(self, subobj, start, end);
+ return_value = bytes_endswith_impl((PyBytesObject *)self, subobj, start, end);
exit:
return return_value;
@@ -1033,7 +1033,7 @@ bytes_decode_impl(PyBytesObject *self, const char *encoding,
const char *errors);
static PyObject *
-bytes_decode(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+bytes_decode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1106,7 +1106,7 @@ bytes_decode(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj
goto exit;
}
skip_optional_pos:
- return_value = bytes_decode_impl(self, encoding, errors);
+ return_value = bytes_decode_impl((PyBytesObject *)self, encoding, errors);
exit:
return return_value;
@@ -1128,7 +1128,7 @@ static PyObject *
bytes_splitlines_impl(PyBytesObject *self, int keepends);
static PyObject *
-bytes_splitlines(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+bytes_splitlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1173,7 +1173,7 @@ bytes_splitlines(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, P
goto exit;
}
skip_optional_pos:
- return_value = bytes_splitlines_impl(self, keepends);
+ return_value = bytes_splitlines_impl((PyBytesObject *)self, keepends);
exit:
return return_value;
@@ -1241,7 +1241,7 @@ static PyObject *
bytes_hex_impl(PyBytesObject *self, PyObject *sep, int bytes_per_sep);
static PyObject *
-bytes_hex(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+bytes_hex(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -1293,7 +1293,7 @@ bytes_hex(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
goto exit;
}
skip_optional_pos:
- return_value = bytes_hex_impl(self, sep, bytes_per_sep);
+ return_value = bytes_hex_impl((PyBytesObject *)self, sep, bytes_per_sep);
exit:
return return_value;
@@ -1391,4 +1391,4 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=fb7939a1983e463a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=96fe2d6ef9ac8f6a input=a9049054013a1b77]*/
diff --git a/Objects/clinic/classobject.c.h b/Objects/clinic/classobject.c.h
index 3e149c97324a6a..5934f1c2a41669 100644
--- a/Objects/clinic/classobject.c.h
+++ b/Objects/clinic/classobject.c.h
@@ -16,9 +16,9 @@ static PyObject *
method___reduce___impl(PyMethodObject *self);
static PyObject *
-method___reduce__(PyMethodObject *self, PyObject *Py_UNUSED(ignored))
+method___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return method___reduce___impl(self);
+ return method___reduce___impl((PyMethodObject *)self);
}
PyDoc_STRVAR(method_new__doc__,
@@ -82,4 +82,4 @@ instancemethod_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=5a5e3f2d0726f189 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ab546abf90aac94e input=a9049054013a1b77]*/
diff --git a/Objects/clinic/codeobject.c.h b/Objects/clinic/codeobject.c.h
index 45738f767df50f..2184742cc0d99d 100644
--- a/Objects/clinic/codeobject.c.h
+++ b/Objects/clinic/codeobject.c.h
@@ -174,7 +174,7 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
PyObject *co_exceptiontable);
static PyObject *
-code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+code_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -204,24 +204,24 @@ code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje
#undef KWTUPLE
PyObject *argsbuf[18];
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
- int co_argcount = self->co_argcount;
- int co_posonlyargcount = self->co_posonlyargcount;
- int co_kwonlyargcount = self->co_kwonlyargcount;
- int co_nlocals = self->co_nlocals;
- int co_stacksize = self->co_stacksize;
- int co_flags = self->co_flags;
- int co_firstlineno = self->co_firstlineno;
+ int co_argcount = ((PyCodeObject *)self)->co_argcount;
+ int co_posonlyargcount = ((PyCodeObject *)self)->co_posonlyargcount;
+ int co_kwonlyargcount = ((PyCodeObject *)self)->co_kwonlyargcount;
+ int co_nlocals = ((PyCodeObject *)self)->co_nlocals;
+ int co_stacksize = ((PyCodeObject *)self)->co_stacksize;
+ int co_flags = ((PyCodeObject *)self)->co_flags;
+ int co_firstlineno = ((PyCodeObject *)self)->co_firstlineno;
PyObject *co_code = NULL;
- PyObject *co_consts = self->co_consts;
- PyObject *co_names = self->co_names;
+ PyObject *co_consts = ((PyCodeObject *)self)->co_consts;
+ PyObject *co_names = ((PyCodeObject *)self)->co_names;
PyObject *co_varnames = NULL;
PyObject *co_freevars = NULL;
PyObject *co_cellvars = NULL;
- PyObject *co_filename = self->co_filename;
- PyObject *co_name = self->co_name;
- PyObject *co_qualname = self->co_qualname;
- PyObject *co_linetable = self->co_linetable;
- PyObject *co_exceptiontable = self->co_exceptiontable;
+ PyObject *co_filename = ((PyCodeObject *)self)->co_filename;
+ PyObject *co_name = ((PyCodeObject *)self)->co_name;
+ PyObject *co_qualname = ((PyCodeObject *)self)->co_qualname;
+ PyObject *co_linetable = ((PyCodeObject *)self)->co_linetable;
+ PyObject *co_exceptiontable = ((PyCodeObject *)self)->co_exceptiontable;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
/*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
@@ -400,7 +400,7 @@ code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje
}
co_exceptiontable = args[17];
skip_optional_kwonly:
- return_value = code_replace_impl(self, co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals, co_stacksize, co_flags, co_firstlineno, co_code, co_consts, co_names, co_varnames, co_freevars, co_cellvars, co_filename, co_name, co_qualname, co_linetable, co_exceptiontable);
+ return_value = code_replace_impl((PyCodeObject *)self, co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals, co_stacksize, co_flags, co_firstlineno, co_code, co_consts, co_names, co_varnames, co_freevars, co_cellvars, co_filename, co_name, co_qualname, co_linetable, co_exceptiontable);
exit:
return return_value;
@@ -421,7 +421,7 @@ static PyObject *
code__varname_from_oparg_impl(PyCodeObject *self, int oparg);
static PyObject *
-code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+code__varname_from_oparg(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -461,9 +461,9 @@ code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t n
if (oparg == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = code__varname_from_oparg_impl(self, oparg);
+ return_value = code__varname_from_oparg_impl((PyCodeObject *)self, oparg);
exit:
return return_value;
}
-/*[clinic end generated code: output=e919ea67a1bcf524 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=73861c79e93aaee5 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/complexobject.c.h b/Objects/clinic/complexobject.c.h
index 3c3d1071b6eec3..e00da1d960c54d 100644
--- a/Objects/clinic/complexobject.c.h
+++ b/Objects/clinic/complexobject.c.h
@@ -21,9 +21,9 @@ static PyObject *
complex_conjugate_impl(PyComplexObject *self);
static PyObject *
-complex_conjugate(PyComplexObject *self, PyObject *Py_UNUSED(ignored))
+complex_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return complex_conjugate_impl(self);
+ return complex_conjugate_impl((PyComplexObject *)self);
}
PyDoc_STRVAR(complex___getnewargs____doc__,
@@ -38,9 +38,9 @@ static PyObject *
complex___getnewargs___impl(PyComplexObject *self);
static PyObject *
-complex___getnewargs__(PyComplexObject *self, PyObject *Py_UNUSED(ignored))
+complex___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return complex___getnewargs___impl(self);
+ return complex___getnewargs___impl((PyComplexObject *)self);
}
PyDoc_STRVAR(complex___format____doc__,
@@ -56,7 +56,7 @@ static PyObject *
complex___format___impl(PyComplexObject *self, PyObject *format_spec);
static PyObject *
-complex___format__(PyComplexObject *self, PyObject *arg)
+complex___format__(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
PyObject *format_spec;
@@ -66,7 +66,7 @@ complex___format__(PyComplexObject *self, PyObject *arg)
goto exit;
}
format_spec = arg;
- return_value = complex___format___impl(self, format_spec);
+ return_value = complex___format___impl((PyComplexObject *)self, format_spec);
exit:
return return_value;
@@ -85,9 +85,9 @@ static PyObject *
complex___complex___impl(PyComplexObject *self);
static PyObject *
-complex___complex__(PyComplexObject *self, PyObject *Py_UNUSED(ignored))
+complex___complex__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return complex___complex___impl(self);
+ return complex___complex___impl((PyComplexObject *)self);
}
PyDoc_STRVAR(complex_new__doc__,
@@ -170,4 +170,4 @@ PyDoc_STRVAR(complex_from_number__doc__,
#define COMPLEX_FROM_NUMBER_METHODDEF \
{"from_number", (PyCFunction)complex_from_number, METH_O|METH_CLASS, complex_from_number__doc__},
-/*[clinic end generated code: output=8c49a41c5a7f0aee input=a9049054013a1b77]*/
+/*[clinic end generated code: output=252cddef7f9169a0 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/dictobject.c.h b/Objects/clinic/dictobject.c.h
index fb46c4c64334f9..cdf39ce147203b 100644
--- a/Objects/clinic/dictobject.c.h
+++ b/Objects/clinic/dictobject.c.h
@@ -52,9 +52,9 @@ static PyObject *
dict_copy_impl(PyDictObject *self);
static PyObject *
-dict_copy(PyDictObject *self, PyObject *Py_UNUSED(ignored))
+dict_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return dict_copy_impl(self);
+ return dict_copy_impl((PyDictObject *)self);
}
PyDoc_STRVAR(dict___contains____doc__,
@@ -79,7 +79,7 @@ static PyObject *
dict_get_impl(PyDictObject *self, PyObject *key, PyObject *default_value);
static PyObject *
-dict_get(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
+dict_get(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *key;
@@ -95,7 +95,7 @@ dict_get(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
default_value = args[1];
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = dict_get_impl(self, key, default_value);
+ return_value = dict_get_impl((PyDictObject *)self, key, default_value);
Py_END_CRITICAL_SECTION();
exit:
@@ -118,7 +118,7 @@ dict_setdefault_impl(PyDictObject *self, PyObject *key,
PyObject *default_value);
static PyObject *
-dict_setdefault(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
+dict_setdefault(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *key;
@@ -134,7 +134,7 @@ dict_setdefault(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
default_value = args[1];
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = dict_setdefault_impl(self, key, default_value);
+ return_value = dict_setdefault_impl((PyDictObject *)self, key, default_value);
Py_END_CRITICAL_SECTION();
exit:
@@ -154,9 +154,9 @@ static PyObject *
dict_clear_impl(PyDictObject *self);
static PyObject *
-dict_clear(PyDictObject *self, PyObject *Py_UNUSED(ignored))
+dict_clear(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return dict_clear_impl(self);
+ return dict_clear_impl((PyDictObject *)self);
}
PyDoc_STRVAR(dict_pop__doc__,
@@ -175,7 +175,7 @@ static PyObject *
dict_pop_impl(PyDictObject *self, PyObject *key, PyObject *default_value);
static PyObject *
-dict_pop(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
+dict_pop(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *key;
@@ -190,7 +190,7 @@ dict_pop(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
}
default_value = args[1];
skip_optional:
- return_value = dict_pop_impl(self, key, default_value);
+ return_value = dict_pop_impl((PyDictObject *)self, key, default_value);
exit:
return return_value;
@@ -212,12 +212,12 @@ static PyObject *
dict_popitem_impl(PyDictObject *self);
static PyObject *
-dict_popitem(PyDictObject *self, PyObject *Py_UNUSED(ignored))
+dict_popitem(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = dict_popitem_impl(self);
+ return_value = dict_popitem_impl((PyDictObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -236,9 +236,9 @@ static PyObject *
dict___sizeof___impl(PyDictObject *self);
static PyObject *
-dict___sizeof__(PyDictObject *self, PyObject *Py_UNUSED(ignored))
+dict___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return dict___sizeof___impl(self);
+ return dict___sizeof___impl((PyDictObject *)self);
}
PyDoc_STRVAR(dict___reversed____doc__,
@@ -254,9 +254,9 @@ static PyObject *
dict___reversed___impl(PyDictObject *self);
static PyObject *
-dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored))
+dict___reversed__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return dict___reversed___impl(self);
+ return dict___reversed___impl((PyDictObject *)self);
}
PyDoc_STRVAR(dict_keys__doc__,
@@ -272,9 +272,9 @@ static PyObject *
dict_keys_impl(PyDictObject *self);
static PyObject *
-dict_keys(PyDictObject *self, PyObject *Py_UNUSED(ignored))
+dict_keys(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return dict_keys_impl(self);
+ return dict_keys_impl((PyDictObject *)self);
}
PyDoc_STRVAR(dict_items__doc__,
@@ -290,9 +290,9 @@ static PyObject *
dict_items_impl(PyDictObject *self);
static PyObject *
-dict_items(PyDictObject *self, PyObject *Py_UNUSED(ignored))
+dict_items(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return dict_items_impl(self);
+ return dict_items_impl((PyDictObject *)self);
}
PyDoc_STRVAR(dict_values__doc__,
@@ -308,8 +308,8 @@ static PyObject *
dict_values_impl(PyDictObject *self);
static PyObject *
-dict_values(PyDictObject *self, PyObject *Py_UNUSED(ignored))
+dict_values(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return dict_values_impl(self);
+ return dict_values_impl((PyDictObject *)self);
}
-/*[clinic end generated code: output=f3dd5f3fb8122aef input=a9049054013a1b77]*/
+/*[clinic end generated code: output=4956c5b276ea652f input=a9049054013a1b77]*/
diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h
index 975f253c096275..a29ed9f7088700 100644
--- a/Objects/clinic/listobject.c.h
+++ b/Objects/clinic/listobject.c.h
@@ -23,7 +23,7 @@ static PyObject *
list_insert_impl(PyListObject *self, Py_ssize_t index, PyObject *object);
static PyObject *
-list_insert(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
+list_insert(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t index;
@@ -46,7 +46,7 @@ list_insert(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
}
object = args[1];
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = list_insert_impl(self, index, object);
+ return_value = list_insert_impl((PyListObject *)self, index, object);
Py_END_CRITICAL_SECTION();
exit:
@@ -66,12 +66,12 @@ static PyObject *
py_list_clear_impl(PyListObject *self);
static PyObject *
-py_list_clear(PyListObject *self, PyObject *Py_UNUSED(ignored))
+py_list_clear(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = py_list_clear_impl(self);
+ return_value = py_list_clear_impl((PyListObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -90,12 +90,12 @@ static PyObject *
list_copy_impl(PyListObject *self);
static PyObject *
-list_copy(PyListObject *self, PyObject *Py_UNUSED(ignored))
+list_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = list_copy_impl(self);
+ return_value = list_copy_impl((PyListObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -119,7 +119,7 @@ list_append(PyListObject *self, PyObject *object)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = list_append_impl(self, object);
+ return_value = list_append_impl((PyListObject *)self, object);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -149,7 +149,7 @@ static PyObject *
list_pop_impl(PyListObject *self, Py_ssize_t index);
static PyObject *
-list_pop(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
+list_pop(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
Py_ssize_t index = -1;
@@ -174,7 +174,7 @@ list_pop(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
}
skip_optional:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = list_pop_impl(self, index);
+ return_value = list_pop_impl((PyListObject *)self, index);
Py_END_CRITICAL_SECTION();
exit:
@@ -202,7 +202,7 @@ static PyObject *
list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse);
static PyObject *
-list_sort(PyListObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+list_sort(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -255,7 +255,7 @@ list_sort(PyListObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
}
skip_optional_kwonly:
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = list_sort_impl(self, keyfunc, reverse);
+ return_value = list_sort_impl((PyListObject *)self, keyfunc, reverse);
Py_END_CRITICAL_SECTION();
exit:
@@ -275,12 +275,12 @@ static PyObject *
list_reverse_impl(PyListObject *self);
static PyObject *
-list_reverse(PyListObject *self, PyObject *Py_UNUSED(ignored))
+list_reverse(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = list_reverse_impl(self);
+ return_value = list_reverse_impl((PyListObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -302,7 +302,7 @@ list_index_impl(PyListObject *self, PyObject *value, Py_ssize_t start,
Py_ssize_t stop);
static PyObject *
-list_index(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
+list_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *value;
@@ -326,7 +326,7 @@ list_index(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = list_index_impl(self, value, start, stop);
+ return_value = list_index_impl((PyListObject *)self, value, start, stop);
exit:
return return_value;
@@ -361,7 +361,7 @@ list_remove(PyListObject *self, PyObject *value)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
- return_value = list_remove_impl(self, value);
+ return_value = list_remove_impl((PyListObject *)self, value);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -418,9 +418,9 @@ static PyObject *
list___sizeof___impl(PyListObject *self);
static PyObject *
-list___sizeof__(PyListObject *self, PyObject *Py_UNUSED(ignored))
+list___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return list___sizeof___impl(self);
+ return list___sizeof___impl((PyListObject *)self);
}
PyDoc_STRVAR(list___reversed____doc__,
@@ -436,8 +436,8 @@ static PyObject *
list___reversed___impl(PyListObject *self);
static PyObject *
-list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
+list___reversed__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return list___reversed___impl(self);
+ return list___reversed___impl((PyListObject *)self);
}
-/*[clinic end generated code: output=9357151278d77ea1 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=35c43dc33f9ba521 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/memoryobject.c.h b/Objects/clinic/memoryobject.c.h
index a6cf1f431a15b0..4706c92051926c 100644
--- a/Objects/clinic/memoryobject.c.h
+++ b/Objects/clinic/memoryobject.c.h
@@ -137,9 +137,9 @@ static PyObject *
memoryview_release_impl(PyMemoryViewObject *self);
static PyObject *
-memoryview_release(PyMemoryViewObject *self, PyObject *Py_UNUSED(ignored))
+memoryview_release(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return memoryview_release_impl(self);
+ return memoryview_release_impl((PyMemoryViewObject *)self);
}
PyDoc_STRVAR(memoryview_cast__doc__,
@@ -156,7 +156,7 @@ memoryview_cast_impl(PyMemoryViewObject *self, PyObject *format,
PyObject *shape);
static PyObject *
-memoryview_cast(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+memoryview_cast(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -204,7 +204,7 @@ memoryview_cast(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t narg
}
shape = args[1];
skip_optional_pos:
- return_value = memoryview_cast_impl(self, format, shape);
+ return_value = memoryview_cast_impl((PyMemoryViewObject *)self, format, shape);
exit:
return return_value;
@@ -223,9 +223,9 @@ static PyObject *
memoryview_toreadonly_impl(PyMemoryViewObject *self);
static PyObject *
-memoryview_toreadonly(PyMemoryViewObject *self, PyObject *Py_UNUSED(ignored))
+memoryview_toreadonly(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return memoryview_toreadonly_impl(self);
+ return memoryview_toreadonly_impl((PyMemoryViewObject *)self);
}
PyDoc_STRVAR(memoryview_tolist__doc__,
@@ -241,9 +241,9 @@ static PyObject *
memoryview_tolist_impl(PyMemoryViewObject *self);
static PyObject *
-memoryview_tolist(PyMemoryViewObject *self, PyObject *Py_UNUSED(ignored))
+memoryview_tolist(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return memoryview_tolist_impl(self);
+ return memoryview_tolist_impl((PyMemoryViewObject *)self);
}
PyDoc_STRVAR(memoryview_tobytes__doc__,
@@ -265,7 +265,7 @@ static PyObject *
memoryview_tobytes_impl(PyMemoryViewObject *self, const char *order);
static PyObject *
-memoryview_tobytes(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+memoryview_tobytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -324,7 +324,7 @@ memoryview_tobytes(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t n
goto exit;
}
skip_optional_pos:
- return_value = memoryview_tobytes_impl(self, order);
+ return_value = memoryview_tobytes_impl((PyMemoryViewObject *)self, order);
exit:
return return_value;
@@ -361,7 +361,7 @@ memoryview_hex_impl(PyMemoryViewObject *self, PyObject *sep,
int bytes_per_sep);
static PyObject *
-memoryview_hex(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+memoryview_hex(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -413,7 +413,7 @@ memoryview_hex(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t nargs
goto exit;
}
skip_optional_pos:
- return_value = memoryview_hex_impl(self, sep, bytes_per_sep);
+ return_value = memoryview_hex_impl((PyMemoryViewObject *)self, sep, bytes_per_sep);
exit:
return return_value;
@@ -444,7 +444,7 @@ memoryview_index_impl(PyMemoryViewObject *self, PyObject *value,
Py_ssize_t start, Py_ssize_t stop);
static PyObject *
-memoryview_index(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t nargs)
+memoryview_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *value;
@@ -468,9 +468,9 @@ memoryview_index(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t nar
goto exit;
}
skip_optional:
- return_value = memoryview_index_impl(self, value, start, stop);
+ return_value = memoryview_index_impl((PyMemoryViewObject *)self, value, start, stop);
exit:
return return_value;
}
-/*[clinic end generated code: output=132893ef5f67ad73 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=2ef6c061d9c4e3dc input=a9049054013a1b77]*/
diff --git a/Objects/clinic/odictobject.c.h b/Objects/clinic/odictobject.c.h
index 4b97596e5dbd2f..44d89c4e0ef2f7 100644
--- a/Objects/clinic/odictobject.c.h
+++ b/Objects/clinic/odictobject.c.h
@@ -87,7 +87,7 @@ OrderedDict_setdefault_impl(PyODictObject *self, PyObject *key,
PyObject *default_value);
static PyObject *
-OrderedDict_setdefault(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+OrderedDict_setdefault(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -131,7 +131,7 @@ OrderedDict_setdefault(PyODictObject *self, PyObject *const *args, Py_ssize_t na
}
default_value = args[1];
skip_optional_pos:
- return_value = OrderedDict_setdefault_impl(self, key, default_value);
+ return_value = OrderedDict_setdefault_impl((PyODictObject *)self, key, default_value);
exit:
return return_value;
@@ -154,7 +154,7 @@ OrderedDict_pop_impl(PyODictObject *self, PyObject *key,
PyObject *default_value);
static PyObject *
-OrderedDict_pop(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+OrderedDict_pop(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -198,7 +198,7 @@ OrderedDict_pop(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, Py
}
default_value = args[1];
skip_optional_pos:
- return_value = OrderedDict_pop_impl(self, key, default_value);
+ return_value = OrderedDict_pop_impl((PyODictObject *)self, key, default_value);
exit:
return return_value;
@@ -219,7 +219,7 @@ static PyObject *
OrderedDict_popitem_impl(PyODictObject *self, int last);
static PyObject *
-OrderedDict_popitem(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+OrderedDict_popitem(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -264,7 +264,7 @@ OrderedDict_popitem(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs
goto exit;
}
skip_optional_pos:
- return_value = OrderedDict_popitem_impl(self, last);
+ return_value = OrderedDict_popitem_impl((PyODictObject *)self, last);
exit:
return return_value;
@@ -285,7 +285,7 @@ static PyObject *
OrderedDict_move_to_end_impl(PyODictObject *self, PyObject *key, int last);
static PyObject *
-OrderedDict_move_to_end(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+OrderedDict_move_to_end(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -332,9 +332,9 @@ OrderedDict_move_to_end(PyODictObject *self, PyObject *const *args, Py_ssize_t n
goto exit;
}
skip_optional_pos:
- return_value = OrderedDict_move_to_end_impl(self, key, last);
+ return_value = OrderedDict_move_to_end_impl((PyODictObject *)self, key, last);
exit:
return return_value;
}
-/*[clinic end generated code: output=2aa6fc0567c9252c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=55bd390bb516e997 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/setobject.c.h b/Objects/clinic/setobject.c.h
index 986993b4aa9bda..bf7e604e4b0a46 100644
--- a/Objects/clinic/setobject.c.h
+++ b/Objects/clinic/setobject.c.h
@@ -19,12 +19,12 @@ static PyObject *
set_pop_impl(PySetObject *so);
static PyObject *
-set_pop(PySetObject *so, PyObject *Py_UNUSED(ignored))
+set_pop(PyObject *so, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(so);
- return_value = set_pop_impl(so);
+ return_value = set_pop_impl((PySetObject *)so);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -44,7 +44,7 @@ set_update_impl(PySetObject *so, PyObject * const *others,
Py_ssize_t others_length);
static PyObject *
-set_update(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
+set_update(PyObject *so, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject * const *others;
@@ -52,7 +52,7 @@ set_update(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
others = args;
others_length = nargs;
- return_value = set_update_impl(so, others, others_length);
+ return_value = set_update_impl((PySetObject *)so, others, others_length);
return return_value;
}
@@ -70,12 +70,12 @@ static PyObject *
set_copy_impl(PySetObject *so);
static PyObject *
-set_copy(PySetObject *so, PyObject *Py_UNUSED(ignored))
+set_copy(PyObject *so, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(so);
- return_value = set_copy_impl(so);
+ return_value = set_copy_impl((PySetObject *)so);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -94,12 +94,12 @@ static PyObject *
frozenset_copy_impl(PySetObject *so);
static PyObject *
-frozenset_copy(PySetObject *so, PyObject *Py_UNUSED(ignored))
+frozenset_copy(PyObject *so, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(so);
- return_value = frozenset_copy_impl(so);
+ return_value = frozenset_copy_impl((PySetObject *)so);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -118,12 +118,12 @@ static PyObject *
set_clear_impl(PySetObject *so);
static PyObject *
-set_clear(PySetObject *so, PyObject *Py_UNUSED(ignored))
+set_clear(PyObject *so, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(so);
- return_value = set_clear_impl(so);
+ return_value = set_clear_impl((PySetObject *)so);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -143,7 +143,7 @@ set_union_impl(PySetObject *so, PyObject * const *others,
Py_ssize_t others_length);
static PyObject *
-set_union(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
+set_union(PyObject *so, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject * const *others;
@@ -151,7 +151,7 @@ set_union(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
others = args;
others_length = nargs;
- return_value = set_union_impl(so, others, others_length);
+ return_value = set_union_impl((PySetObject *)so, others, others_length);
return return_value;
}
@@ -170,7 +170,7 @@ set_intersection_multi_impl(PySetObject *so, PyObject * const *others,
Py_ssize_t others_length);
static PyObject *
-set_intersection_multi(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
+set_intersection_multi(PyObject *so, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject * const *others;
@@ -178,7 +178,7 @@ set_intersection_multi(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
others = args;
others_length = nargs;
- return_value = set_intersection_multi_impl(so, others, others_length);
+ return_value = set_intersection_multi_impl((PySetObject *)so, others, others_length);
return return_value;
}
@@ -197,7 +197,7 @@ set_intersection_update_multi_impl(PySetObject *so, PyObject * const *others,
Py_ssize_t others_length);
static PyObject *
-set_intersection_update_multi(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
+set_intersection_update_multi(PyObject *so, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject * const *others;
@@ -205,7 +205,7 @@ set_intersection_update_multi(PySetObject *so, PyObject *const *args, Py_ssize_t
others = args;
others_length = nargs;
- return_value = set_intersection_update_multi_impl(so, others, others_length);
+ return_value = set_intersection_update_multi_impl((PySetObject *)so, others, others_length);
return return_value;
}
@@ -228,7 +228,7 @@ set_isdisjoint(PySetObject *so, PyObject *other)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION2(so, other);
- return_value = set_isdisjoint_impl(so, other);
+ return_value = set_isdisjoint_impl((PySetObject *)so, other);
Py_END_CRITICAL_SECTION2();
return return_value;
@@ -248,7 +248,7 @@ set_difference_update_impl(PySetObject *so, PyObject * const *others,
Py_ssize_t others_length);
static PyObject *
-set_difference_update(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
+set_difference_update(PyObject *so, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject * const *others;
@@ -256,7 +256,7 @@ set_difference_update(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
others = args;
others_length = nargs;
- return_value = set_difference_update_impl(so, others, others_length);
+ return_value = set_difference_update_impl((PySetObject *)so, others, others_length);
return return_value;
}
@@ -275,7 +275,7 @@ set_difference_multi_impl(PySetObject *so, PyObject * const *others,
Py_ssize_t others_length);
static PyObject *
-set_difference_multi(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
+set_difference_multi(PyObject *so, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject * const *others;
@@ -283,7 +283,7 @@ set_difference_multi(PySetObject *so, PyObject *const *args, Py_ssize_t nargs)
others = args;
others_length = nargs;
- return_value = set_difference_multi_impl(so, others, others_length);
+ return_value = set_difference_multi_impl((PySetObject *)so, others, others_length);
return return_value;
}
@@ -315,7 +315,7 @@ set_symmetric_difference(PySetObject *so, PyObject *other)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION2(so, other);
- return_value = set_symmetric_difference_impl(so, other);
+ return_value = set_symmetric_difference_impl((PySetObject *)so, other);
Py_END_CRITICAL_SECTION2();
return return_value;
@@ -339,7 +339,7 @@ set_issubset(PySetObject *so, PyObject *other)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION2(so, other);
- return_value = set_issubset_impl(so, other);
+ return_value = set_issubset_impl((PySetObject *)so, other);
Py_END_CRITICAL_SECTION2();
return return_value;
@@ -363,7 +363,7 @@ set_issuperset(PySetObject *so, PyObject *other)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION2(so, other);
- return_value = set_issuperset_impl(so, other);
+ return_value = set_issuperset_impl((PySetObject *)so, other);
Py_END_CRITICAL_SECTION2();
return return_value;
@@ -389,7 +389,7 @@ set_add(PySetObject *so, PyObject *key)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(so);
- return_value = set_add_impl(so, key);
+ return_value = set_add_impl((PySetObject *)so, key);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -413,7 +413,7 @@ set___contains__(PySetObject *so, PyObject *key)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(so);
- return_value = set___contains___impl(so, key);
+ return_value = set___contains___impl((PySetObject *)so, key);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -439,7 +439,7 @@ set_remove(PySetObject *so, PyObject *key)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(so);
- return_value = set_remove_impl(so, key);
+ return_value = set_remove_impl((PySetObject *)so, key);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -466,7 +466,7 @@ set_discard(PySetObject *so, PyObject *key)
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(so);
- return_value = set_discard_impl(so, key);
+ return_value = set_discard_impl((PySetObject *)so, key);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -485,12 +485,12 @@ static PyObject *
set___reduce___impl(PySetObject *so);
static PyObject *
-set___reduce__(PySetObject *so, PyObject *Py_UNUSED(ignored))
+set___reduce__(PyObject *so, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(so);
- return_value = set___reduce___impl(so);
+ return_value = set___reduce___impl((PySetObject *)so);
Py_END_CRITICAL_SECTION();
return return_value;
@@ -509,14 +509,14 @@ static PyObject *
set___sizeof___impl(PySetObject *so);
static PyObject *
-set___sizeof__(PySetObject *so, PyObject *Py_UNUSED(ignored))
+set___sizeof__(PyObject *so, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(so);
- return_value = set___sizeof___impl(so);
+ return_value = set___sizeof___impl((PySetObject *)so);
Py_END_CRITICAL_SECTION();
return return_value;
}
-/*[clinic end generated code: output=4b65e7709927f31f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=83b7742a762ce465 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/tupleobject.c.h b/Objects/clinic/tupleobject.c.h
index 5d6a2c481a5f2a..40ffd4c1755769 100644
--- a/Objects/clinic/tupleobject.c.h
+++ b/Objects/clinic/tupleobject.c.h
@@ -20,7 +20,7 @@ tuple_index_impl(PyTupleObject *self, PyObject *value, Py_ssize_t start,
Py_ssize_t stop);
static PyObject *
-tuple_index(PyTupleObject *self, PyObject *const *args, Py_ssize_t nargs)
+tuple_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *value;
@@ -44,7 +44,7 @@ tuple_index(PyTupleObject *self, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
skip_optional:
- return_value = tuple_index_impl(self, value, start, stop);
+ return_value = tuple_index_impl((PyTupleObject *)self, value, start, stop);
exit:
return return_value;
@@ -110,8 +110,8 @@ static PyObject *
tuple___getnewargs___impl(PyTupleObject *self);
static PyObject *
-tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
+tuple___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return tuple___getnewargs___impl(self);
+ return tuple___getnewargs___impl((PyTupleObject *)self);
}
-/*[clinic end generated code: output=a6a9abba5d121f4c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=779cb4a13db67397 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/typeobject.c.h b/Objects/clinic/typeobject.c.h
index 1fa153598db213..5e8187b3f5b748 100644
--- a/Objects/clinic/typeobject.c.h
+++ b/Objects/clinic/typeobject.c.h
@@ -22,7 +22,7 @@ type___instancecheck__(PyTypeObject *self, PyObject *instance)
PyObject *return_value = NULL;
int _return_value;
- _return_value = type___instancecheck___impl(self, instance);
+ _return_value = type___instancecheck___impl((PyTypeObject *)self, instance);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -50,7 +50,7 @@ type___subclasscheck__(PyTypeObject *self, PyObject *subclass)
PyObject *return_value = NULL;
int _return_value;
- _return_value = type___subclasscheck___impl(self, subclass);
+ _return_value = type___subclasscheck___impl((PyTypeObject *)self, subclass);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -73,9 +73,9 @@ static PyObject *
type_mro_impl(PyTypeObject *self);
static PyObject *
-type_mro(PyTypeObject *self, PyObject *Py_UNUSED(ignored))
+type_mro(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return type_mro_impl(self);
+ return type_mro_impl((PyTypeObject *)self);
}
PyDoc_STRVAR(type___subclasses____doc__,
@@ -91,9 +91,9 @@ static PyObject *
type___subclasses___impl(PyTypeObject *self);
static PyObject *
-type___subclasses__(PyTypeObject *self, PyObject *Py_UNUSED(ignored))
+type___subclasses__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return type___subclasses___impl(self);
+ return type___subclasses___impl((PyTypeObject *)self);
}
PyDoc_STRVAR(type___dir____doc__,
@@ -109,9 +109,9 @@ static PyObject *
type___dir___impl(PyTypeObject *self);
static PyObject *
-type___dir__(PyTypeObject *self, PyObject *Py_UNUSED(ignored))
+type___dir__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return type___dir___impl(self);
+ return type___dir___impl((PyTypeObject *)self);
}
PyDoc_STRVAR(type___sizeof____doc__,
@@ -127,9 +127,9 @@ static PyObject *
type___sizeof___impl(PyTypeObject *self);
static PyObject *
-type___sizeof__(PyTypeObject *self, PyObject *Py_UNUSED(ignored))
+type___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return type___sizeof___impl(self);
+ return type___sizeof___impl((PyTypeObject *)self);
}
PyDoc_STRVAR(object___getstate____doc__,
@@ -262,4 +262,4 @@ object___dir__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return object___dir___impl(self);
}
-/*[clinic end generated code: output=b56c87f9cace1921 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=f7db85fd11818c63 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/typevarobject.c.h b/Objects/clinic/typevarobject.c.h
index c17998830b02eb..e50ed7d95b9b2a 100644
--- a/Objects/clinic/typevarobject.c.h
+++ b/Objects/clinic/typevarobject.c.h
@@ -143,7 +143,7 @@ typevar_typing_prepare_subst_impl(typevarobject *self, PyObject *alias,
PyObject *args);
static PyObject *
-typevar_typing_prepare_subst(typevarobject *self, PyObject *const *args, Py_ssize_t nargs)
+typevar_typing_prepare_subst(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *alias;
@@ -154,7 +154,7 @@ typevar_typing_prepare_subst(typevarobject *self, PyObject *const *args, Py_ssiz
}
alias = args[0];
__clinic_args = args[1];
- return_value = typevar_typing_prepare_subst_impl(self, alias, __clinic_args);
+ return_value = typevar_typing_prepare_subst_impl((typevarobject *)self, alias, __clinic_args);
exit:
return return_value;
@@ -172,9 +172,9 @@ static PyObject *
typevar_reduce_impl(typevarobject *self);
static PyObject *
-typevar_reduce(typevarobject *self, PyObject *Py_UNUSED(ignored))
+typevar_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return typevar_reduce_impl(self);
+ return typevar_reduce_impl((typevarobject *)self);
}
PyDoc_STRVAR(typevar_has_default__doc__,
@@ -189,9 +189,9 @@ static PyObject *
typevar_has_default_impl(typevarobject *self);
static PyObject *
-typevar_has_default(typevarobject *self, PyObject *Py_UNUSED(ignored))
+typevar_has_default(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return typevar_has_default_impl(self);
+ return typevar_has_default_impl((typevarobject *)self);
}
PyDoc_STRVAR(paramspecargs_new__doc__,
@@ -431,7 +431,7 @@ paramspec_typing_prepare_subst_impl(paramspecobject *self, PyObject *alias,
PyObject *args);
static PyObject *
-paramspec_typing_prepare_subst(paramspecobject *self, PyObject *const *args, Py_ssize_t nargs)
+paramspec_typing_prepare_subst(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *alias;
@@ -442,7 +442,7 @@ paramspec_typing_prepare_subst(paramspecobject *self, PyObject *const *args, Py_
}
alias = args[0];
__clinic_args = args[1];
- return_value = paramspec_typing_prepare_subst_impl(self, alias, __clinic_args);
+ return_value = paramspec_typing_prepare_subst_impl((paramspecobject *)self, alias, __clinic_args);
exit:
return return_value;
@@ -460,9 +460,9 @@ static PyObject *
paramspec_reduce_impl(paramspecobject *self);
static PyObject *
-paramspec_reduce(paramspecobject *self, PyObject *Py_UNUSED(ignored))
+paramspec_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return paramspec_reduce_impl(self);
+ return paramspec_reduce_impl((paramspecobject *)self);
}
PyDoc_STRVAR(paramspec_has_default__doc__,
@@ -477,9 +477,9 @@ static PyObject *
paramspec_has_default_impl(paramspecobject *self);
static PyObject *
-paramspec_has_default(paramspecobject *self, PyObject *Py_UNUSED(ignored))
+paramspec_has_default(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return paramspec_has_default_impl(self);
+ return paramspec_has_default_impl((paramspecobject *)self);
}
PyDoc_STRVAR(typevartuple__doc__,
@@ -570,7 +570,7 @@ typevartuple_typing_prepare_subst_impl(typevartupleobject *self,
PyObject *alias, PyObject *args);
static PyObject *
-typevartuple_typing_prepare_subst(typevartupleobject *self, PyObject *const *args, Py_ssize_t nargs)
+typevartuple_typing_prepare_subst(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *alias;
@@ -581,7 +581,7 @@ typevartuple_typing_prepare_subst(typevartupleobject *self, PyObject *const *arg
}
alias = args[0];
__clinic_args = args[1];
- return_value = typevartuple_typing_prepare_subst_impl(self, alias, __clinic_args);
+ return_value = typevartuple_typing_prepare_subst_impl((typevartupleobject *)self, alias, __clinic_args);
exit:
return return_value;
@@ -599,9 +599,9 @@ static PyObject *
typevartuple_reduce_impl(typevartupleobject *self);
static PyObject *
-typevartuple_reduce(typevartupleobject *self, PyObject *Py_UNUSED(ignored))
+typevartuple_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return typevartuple_reduce_impl(self);
+ return typevartuple_reduce_impl((typevartupleobject *)self);
}
PyDoc_STRVAR(typevartuple_has_default__doc__,
@@ -616,9 +616,9 @@ static PyObject *
typevartuple_has_default_impl(typevartupleobject *self);
static PyObject *
-typevartuple_has_default(typevartupleobject *self, PyObject *Py_UNUSED(ignored))
+typevartuple_has_default(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return typevartuple_has_default_impl(self);
+ return typevartuple_has_default_impl((typevartupleobject *)self);
}
PyDoc_STRVAR(typealias_reduce__doc__,
@@ -633,9 +633,9 @@ static PyObject *
typealias_reduce_impl(typealiasobject *self);
static PyObject *
-typealias_reduce(typealiasobject *self, PyObject *Py_UNUSED(ignored))
+typealias_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return typealias_reduce_impl(self);
+ return typealias_reduce_impl((typealiasobject *)self);
}
PyDoc_STRVAR(typealias_new__doc__,
@@ -706,4 +706,4 @@ typealias_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=26351c3549f5ad83 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=f499d959a942c599 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h
index 361f20c0fa4c1d..5c6a425b0f803a 100644
--- a/Objects/clinic/unicodeobject.c.h
+++ b/Objects/clinic/unicodeobject.c.h
@@ -22,9 +22,9 @@ static PyObject *
EncodingMap_size_impl(struct encoding_map *self);
static PyObject *
-EncodingMap_size(struct encoding_map *self, PyObject *Py_UNUSED(ignored))
+EncodingMap_size(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return EncodingMap_size_impl(self);
+ return EncodingMap_size_impl((struct encoding_map *)self);
}
PyDoc_STRVAR(unicode_title__doc__,
@@ -1895,4 +1895,4 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=30efbf79c5a07dd2 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=4d1cecd6d08498a4 input=a9049054013a1b77]*/
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 539200c97c1206..91332edbfd3061 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -2212,24 +2212,24 @@ code_branchesiterator(PyObject *self, PyObject *Py_UNUSED(args))
code.replace
*
- co_argcount: int(c_default="self->co_argcount") = unchanged
- co_posonlyargcount: int(c_default="self->co_posonlyargcount") = unchanged
- co_kwonlyargcount: int(c_default="self->co_kwonlyargcount") = unchanged
- co_nlocals: int(c_default="self->co_nlocals") = unchanged
- co_stacksize: int(c_default="self->co_stacksize") = unchanged
- co_flags: int(c_default="self->co_flags") = unchanged
- co_firstlineno: int(c_default="self->co_firstlineno") = unchanged
+ co_argcount: int(c_default="((PyCodeObject *)self)->co_argcount") = unchanged
+ co_posonlyargcount: int(c_default="((PyCodeObject *)self)->co_posonlyargcount") = unchanged
+ co_kwonlyargcount: int(c_default="((PyCodeObject *)self)->co_kwonlyargcount") = unchanged
+ co_nlocals: int(c_default="((PyCodeObject *)self)->co_nlocals") = unchanged
+ co_stacksize: int(c_default="((PyCodeObject *)self)->co_stacksize") = unchanged
+ co_flags: int(c_default="((PyCodeObject *)self)->co_flags") = unchanged
+ co_firstlineno: int(c_default="((PyCodeObject *)self)->co_firstlineno") = unchanged
co_code: object(subclass_of="&PyBytes_Type", c_default="NULL") = unchanged
- co_consts: object(subclass_of="&PyTuple_Type", c_default="self->co_consts") = unchanged
- co_names: object(subclass_of="&PyTuple_Type", c_default="self->co_names") = unchanged
+ co_consts: object(subclass_of="&PyTuple_Type", c_default="((PyCodeObject *)self)->co_consts") = unchanged
+ co_names: object(subclass_of="&PyTuple_Type", c_default="((PyCodeObject *)self)->co_names") = unchanged
co_varnames: object(subclass_of="&PyTuple_Type", c_default="NULL") = unchanged
co_freevars: object(subclass_of="&PyTuple_Type", c_default="NULL") = unchanged
co_cellvars: object(subclass_of="&PyTuple_Type", c_default="NULL") = unchanged
- co_filename: unicode(c_default="self->co_filename") = unchanged
- co_name: unicode(c_default="self->co_name") = unchanged
- co_qualname: unicode(c_default="self->co_qualname") = unchanged
- co_linetable: object(subclass_of="&PyBytes_Type", c_default="self->co_linetable") = unchanged
- co_exceptiontable: object(subclass_of="&PyBytes_Type", c_default="self->co_exceptiontable") = unchanged
+ co_filename: unicode(c_default="((PyCodeObject *)self)->co_filename") = unchanged
+ co_name: unicode(c_default="((PyCodeObject *)self)->co_name") = unchanged
+ co_qualname: unicode(c_default="((PyCodeObject *)self)->co_qualname") = unchanged
+ co_linetable: object(subclass_of="&PyBytes_Type", c_default="((PyCodeObject *)self)->co_linetable") = unchanged
+ co_exceptiontable: object(subclass_of="&PyBytes_Type", c_default="((PyCodeObject *)self)->co_exceptiontable") = unchanged
Return a copy of the code object with new values for the specified fields.
[clinic start generated code]*/
@@ -2244,7 +2244,7 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
PyObject *co_filename, PyObject *co_name,
PyObject *co_qualname, PyObject *co_linetable,
PyObject *co_exceptiontable)
-/*[clinic end generated code: output=e75c48a15def18b9 input=18e280e07846c122]*/
+/*[clinic end generated code: output=e75c48a15def18b9 input=a455a89c57ac9d42]*/
{
#define CHECK_INT_ARG(ARG) \
if (ARG < 0) { \
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 955ccbebf74b54..26ab352ca6d989 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -1298,7 +1298,7 @@ set_union_impl(PySetObject *so, PyObject * const *others,
PyObject *other;
Py_ssize_t i;
- result = (PySetObject *)set_copy(so, NULL);
+ result = (PySetObject *)set_copy((PyObject *)so, NULL);
if (result == NULL)
return NULL;
@@ -1321,13 +1321,12 @@ set_or(PyObject *self, PyObject *other)
if (!PyAnySet_Check(self) || !PyAnySet_Check(other))
Py_RETURN_NOTIMPLEMENTED;
- PySetObject *so = _PySet_CAST(self);
- result = (PySetObject *)set_copy(so, NULL);
+ result = (PySetObject *)set_copy(self, NULL);
if (result == NULL) {
return NULL;
}
- if (Py_Is((PyObject *)so, other)) {
+ if (Py_Is(self, other)) {
return (PyObject *)result;
}
if (set_update_local(result, other)) {
@@ -1449,7 +1448,7 @@ set_intersection_multi_impl(PySetObject *so, PyObject * const *others,
Py_ssize_t i;
if (others_length == 0) {
- return set_copy(so, NULL);
+ return set_copy((PyObject *)so, NULL);
}
PyObject *result = Py_NewRef(so);
@@ -1806,7 +1805,7 @@ set_difference_multi_impl(PySetObject *so, PyObject * const *others,
PyObject *result, *other;
if (others_length == 0) {
- return set_copy(so, NULL);
+ return set_copy((PyObject *)so, NULL);
}
other = others[0];
@@ -1929,7 +1928,7 @@ set_symmetric_difference_update(PySetObject *so, PyObject *other)
/*[clinic end generated code: output=fbb049c0806028de input=a50acf0365e1f0a5]*/
{
if (Py_Is((PyObject *)so, other)) {
- return set_clear(so, NULL);
+ return set_clear((PyObject *)so, NULL);
}
int rv;
@@ -2646,7 +2645,7 @@ PySet_Clear(PyObject *set)
PyErr_BadInternalCall();
return -1;
}
- (void)set_clear((PySetObject *)set, NULL);
+ (void)set_clear(set, NULL);
return 0;
}
@@ -2742,7 +2741,7 @@ PySet_Pop(PyObject *set)
PyErr_BadInternalCall();
return NULL;
}
- return set_pop((PySetObject *)set, NULL);
+ return set_pop(set, NULL);
}
int
diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h
index b14913366b77eb..00fa6a75ec113e 100644
--- a/PC/clinic/winreg.c.h
+++ b/PC/clinic/winreg.c.h
@@ -26,9 +26,9 @@ static PyObject *
winreg_HKEYType_Close_impl(PyHKEYObject *self);
static PyObject *
-winreg_HKEYType_Close(PyHKEYObject *self, PyObject *Py_UNUSED(ignored))
+winreg_HKEYType_Close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return winreg_HKEYType_Close_impl(self);
+ return winreg_HKEYType_Close_impl((PyHKEYObject *)self);
}
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
@@ -56,9 +56,9 @@ static PyObject *
winreg_HKEYType_Detach_impl(PyHKEYObject *self);
static PyObject *
-winreg_HKEYType_Detach(PyHKEYObject *self, PyObject *Py_UNUSED(ignored))
+winreg_HKEYType_Detach(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return winreg_HKEYType_Detach_impl(self);
+ return winreg_HKEYType_Detach_impl((PyHKEYObject *)self);
}
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
@@ -77,12 +77,12 @@ static PyHKEYObject *
winreg_HKEYType___enter___impl(PyHKEYObject *self);
static PyObject *
-winreg_HKEYType___enter__(PyHKEYObject *self, PyObject *Py_UNUSED(ignored))
+winreg_HKEYType___enter__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
PyHKEYObject *_return_value;
- _return_value = winreg_HKEYType___enter___impl(self);
+ _return_value = winreg_HKEYType___enter___impl((PyHKEYObject *)self);
return_value = (PyObject *)_return_value;
return return_value;
@@ -105,7 +105,7 @@ winreg_HKEYType___exit___impl(PyHKEYObject *self, PyObject *exc_type,
PyObject *exc_value, PyObject *traceback);
static PyObject *
-winreg_HKEYType___exit__(PyHKEYObject *self, PyObject *const *args, Py_ssize_t nargs)
+winreg_HKEYType___exit__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *exc_type;
@@ -118,7 +118,7 @@ winreg_HKEYType___exit__(PyHKEYObject *self, PyObject *const *args, Py_ssize_t n
exc_type = args[0];
exc_value = args[1];
traceback = args[2];
- return_value = winreg_HKEYType___exit___impl(self, exc_type, exc_value, traceback);
+ return_value = winreg_HKEYType___exit___impl((PyHKEYObject *)self, exc_type, exc_value, traceback);
exit:
return return_value;
@@ -1766,4 +1766,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=aef4aa8ab8ddf38f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=fbe9b075cd2fa833 input=a9049054013a1b77]*/
diff --git a/Python/clinic/context.c.h b/Python/clinic/context.c.h
index 997ac6f63384a9..71f05aa02a51e7 100644
--- a/Python/clinic/context.c.h
+++ b/Python/clinic/context.c.h
@@ -21,7 +21,7 @@ _contextvars_Context_get_impl(PyContext *self, PyObject *key,
PyObject *default_value);
static PyObject *
-_contextvars_Context_get(PyContext *self, PyObject *const *args, Py_ssize_t nargs)
+_contextvars_Context_get(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *key;
@@ -36,7 +36,7 @@ _contextvars_Context_get(PyContext *self, PyObject *const *args, Py_ssize_t narg
}
default_value = args[1];
skip_optional:
- return_value = _contextvars_Context_get_impl(self, key, default_value);
+ return_value = _contextvars_Context_get_impl((PyContext *)self, key, default_value);
exit:
return return_value;
@@ -57,9 +57,9 @@ static PyObject *
_contextvars_Context_items_impl(PyContext *self);
static PyObject *
-_contextvars_Context_items(PyContext *self, PyObject *Py_UNUSED(ignored))
+_contextvars_Context_items(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _contextvars_Context_items_impl(self);
+ return _contextvars_Context_items_impl((PyContext *)self);
}
PyDoc_STRVAR(_contextvars_Context_keys__doc__,
@@ -75,9 +75,9 @@ static PyObject *
_contextvars_Context_keys_impl(PyContext *self);
static PyObject *
-_contextvars_Context_keys(PyContext *self, PyObject *Py_UNUSED(ignored))
+_contextvars_Context_keys(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _contextvars_Context_keys_impl(self);
+ return _contextvars_Context_keys_impl((PyContext *)self);
}
PyDoc_STRVAR(_contextvars_Context_values__doc__,
@@ -93,9 +93,9 @@ static PyObject *
_contextvars_Context_values_impl(PyContext *self);
static PyObject *
-_contextvars_Context_values(PyContext *self, PyObject *Py_UNUSED(ignored))
+_contextvars_Context_values(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _contextvars_Context_values_impl(self);
+ return _contextvars_Context_values_impl((PyContext *)self);
}
PyDoc_STRVAR(_contextvars_Context_copy__doc__,
@@ -111,9 +111,9 @@ static PyObject *
_contextvars_Context_copy_impl(PyContext *self);
static PyObject *
-_contextvars_Context_copy(PyContext *self, PyObject *Py_UNUSED(ignored))
+_contextvars_Context_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return _contextvars_Context_copy_impl(self);
+ return _contextvars_Context_copy_impl((PyContext *)self);
}
PyDoc_STRVAR(_contextvars_ContextVar_get__doc__,
@@ -135,7 +135,7 @@ static PyObject *
_contextvars_ContextVar_get_impl(PyContextVar *self, PyObject *default_value);
static PyObject *
-_contextvars_ContextVar_get(PyContextVar *self, PyObject *const *args, Py_ssize_t nargs)
+_contextvars_ContextVar_get(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *default_value = NULL;
@@ -148,7 +148,7 @@ _contextvars_ContextVar_get(PyContextVar *self, PyObject *const *args, Py_ssize_
}
default_value = args[0];
skip_optional:
- return_value = _contextvars_ContextVar_get_impl(self, default_value);
+ return_value = _contextvars_ContextVar_get_impl((PyContextVar *)self, default_value);
exit:
return return_value;
@@ -179,4 +179,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=b667826178444c3f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=444567eaf0df25e0 input=a9049054013a1b77]*/
diff --git a/Python/clinic/instruction_sequence.c.h b/Python/clinic/instruction_sequence.c.h
index 45693e5856f8a7..41ab2de44e426e 100644
--- a/Python/clinic/instruction_sequence.c.h
+++ b/Python/clinic/instruction_sequence.c.h
@@ -51,7 +51,7 @@ InstructionSequenceType_use_label_impl(_PyInstructionSequence *self,
int label);
static PyObject *
-InstructionSequenceType_use_label(_PyInstructionSequence *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+InstructionSequenceType_use_label(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -91,7 +91,7 @@ InstructionSequenceType_use_label(_PyInstructionSequence *self, PyObject *const
if (label == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = InstructionSequenceType_use_label_impl(self, label);
+ return_value = InstructionSequenceType_use_label_impl((_PyInstructionSequence *)self, label);
exit:
return return_value;
@@ -113,7 +113,7 @@ InstructionSequenceType_addop_impl(_PyInstructionSequence *self, int opcode,
int end_lineno, int end_col_offset);
static PyObject *
-InstructionSequenceType_addop(_PyInstructionSequence *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+InstructionSequenceType_addop(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -178,7 +178,7 @@ InstructionSequenceType_addop(_PyInstructionSequence *self, PyObject *const *arg
if (end_col_offset == -1 && PyErr_Occurred()) {
goto exit;
}
- return_value = InstructionSequenceType_addop_impl(self, opcode, oparg, lineno, col_offset, end_lineno, end_col_offset);
+ return_value = InstructionSequenceType_addop_impl((_PyInstructionSequence *)self, opcode, oparg, lineno, col_offset, end_lineno, end_col_offset);
exit:
return return_value;
@@ -197,12 +197,12 @@ static int
InstructionSequenceType_new_label_impl(_PyInstructionSequence *self);
static PyObject *
-InstructionSequenceType_new_label(_PyInstructionSequence *self, PyObject *Py_UNUSED(ignored))
+InstructionSequenceType_new_label(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *return_value = NULL;
int _return_value;
- _return_value = InstructionSequenceType_new_label_impl(self);
+ _return_value = InstructionSequenceType_new_label_impl((_PyInstructionSequence *)self);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
@@ -226,7 +226,7 @@ InstructionSequenceType_add_nested_impl(_PyInstructionSequence *self,
PyObject *nested);
static PyObject *
-InstructionSequenceType_add_nested(_PyInstructionSequence *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+InstructionSequenceType_add_nested(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -263,7 +263,7 @@ InstructionSequenceType_add_nested(_PyInstructionSequence *self, PyObject *const
goto exit;
}
nested = args[0];
- return_value = InstructionSequenceType_add_nested_impl(self, nested);
+ return_value = InstructionSequenceType_add_nested_impl((_PyInstructionSequence *)self, nested);
exit:
return return_value;
@@ -282,9 +282,9 @@ static PyObject *
InstructionSequenceType_get_nested_impl(_PyInstructionSequence *self);
static PyObject *
-InstructionSequenceType_get_nested(_PyInstructionSequence *self, PyObject *Py_UNUSED(ignored))
+InstructionSequenceType_get_nested(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return InstructionSequenceType_get_nested_impl(self);
+ return InstructionSequenceType_get_nested_impl((_PyInstructionSequence *)self);
}
PyDoc_STRVAR(InstructionSequenceType_get_instructions__doc__,
@@ -300,8 +300,8 @@ static PyObject *
InstructionSequenceType_get_instructions_impl(_PyInstructionSequence *self);
static PyObject *
-InstructionSequenceType_get_instructions(_PyInstructionSequence *self, PyObject *Py_UNUSED(ignored))
+InstructionSequenceType_get_instructions(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- return InstructionSequenceType_get_instructions_impl(self);
+ return InstructionSequenceType_get_instructions_impl((_PyInstructionSequence *)self);
}
-/*[clinic end generated code: output=35163e5b589b4446 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=e6b5d05bde008cc2 input=a9049054013a1b77]*/
diff --git a/Tools/clinic/libclinic/converters.py b/Tools/clinic/libclinic/converters.py
index a65f73ba02fb5d..2998eb519648aa 100644
--- a/Tools/clinic/libclinic/converters.py
+++ b/Tools/clinic/libclinic/converters.py
@@ -1182,10 +1182,8 @@ def pre_render(self) -> None:
@property
def parser_type(self) -> str:
assert self.type is not None
- if self.function.kind in {METHOD_INIT, METHOD_NEW, STATIC_METHOD, CLASS_METHOD}:
- tp, _ = correct_name_for_self(self.function)
- return tp
- return self.type
+ tp, _ = correct_name_for_self(self.function)
+ return tp
def render(self, parameter: Parameter, data: CRenderData) -> None:
"""
1
0
gh-128360: Add `_Py_AssertHoldsTstate` as assertion for holding a thread state (#128361)
by kumaraditya303 Jan. 20, 2025
by kumaraditya303 Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/4d0a6595a06c554c57ebd90ee64ff4c2be…
commit: 4d0a6595a06c554c57ebd90ee64ff4c2bec239b8
branch: main
author: Peter Bierma <zintensitydev(a)gmail.com>
committer: kumaraditya303 <kumaraditya(a)python.org>
date: 2025-01-20T17:04:35+05:30
summary:
gh-128360: Add `_Py_AssertHoldsTstate` as assertion for holding a thread state (#128361)
Co-authored-by: Kumar Aditya <kumaraditya(a)python.org>
files:
M Include/internal/pycore_pystate.h
M Modules/socketmodule.c
M Objects/object.c
M Objects/obmalloc.c
M Python/ceval_gil.c
M Python/errors.c
M Python/fileutils.c
M Python/legacy_tracing.c
M Python/pystate.c
M Python/pytime.c
M Python/tracemalloc.c
diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h
index 1e73e541ef8de0..ff3b222b157810 100644
--- a/Include/internal/pycore_pystate.h
+++ b/Include/internal/pycore_pystate.h
@@ -300,6 +300,19 @@ PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);
// See also PyInterpreterState_Get() and _PyInterpreterState_GET().
extern PyInterpreterState* _PyGILState_GetInterpreterStateUnsafe(void);
+#ifndef NDEBUG
+/* Modern equivalent of assert(PyGILState_Check()) */
+static inline void
+_Py_AssertHoldsTstateFunc(const char *func)
+{
+ PyThreadState *tstate = _PyThreadState_GET();
+ _Py_EnsureFuncTstateNotNULL(func, tstate);
+}
+#define _Py_AssertHoldsTstate() _Py_AssertHoldsTstateFunc(__func__)
+#else
+#define _Py_AssertHoldsTstate()
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index e70aa304f2f3a3..5e81253ca4a591 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -110,6 +110,7 @@ Local naming conventions:
#include "pycore_fileutils.h" // _Py_set_inheritable()
#include "pycore_moduleobject.h" // _PyModule_GetState
#include "pycore_time.h" // _PyTime_AsMilliseconds()
+#include "pycore_pystate.h" // _Py_AssertHoldsTstate()
#include "pycore_pyatomic_ft_wrappers.h"
#ifdef _Py_MEMORY_SANITIZER
@@ -822,8 +823,8 @@ internal_select(PySocketSockObject *s, int writing, PyTime_t interval,
struct timeval tv, *tvp;
#endif
- /* must be called with the GIL held */
- assert(PyGILState_Check());
+ /* must be called with a thread state */
+ _Py_AssertHoldsTstate();
/* Error condition is for output only */
assert(!(connect && !writing));
@@ -936,8 +937,8 @@ sock_call_ex(PySocketSockObject *s,
int deadline_initialized = 0;
int res;
- /* sock_call() must be called with the GIL held. */
- assert(PyGILState_Check());
+ /* sock_call() must be called with a thread state. */
+ _Py_AssertHoldsTstate();
/* outer loop to retry select() when select() is interrupted by a signal
or to retry select()+sock_func() on false positive (see above) */
diff --git a/Objects/object.c b/Objects/object.c
index 4e900d8e79d91a..51b6016b9c191c 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -3073,14 +3073,14 @@ _Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt)
}
int PyRefTracer_SetTracer(PyRefTracer tracer, void *data) {
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
_PyRuntime.ref_tracer.tracer_func = tracer;
_PyRuntime.ref_tracer.tracer_data = data;
return 0;
}
PyRefTracer PyRefTracer_GetTracer(void** data) {
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
if (data != NULL) {
*data = _PyRuntime.ref_tracer.tracer_data;
}
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
index b103deb01ca712..5688049b024696 100644
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -2909,7 +2909,8 @@ _PyMem_DebugRawRealloc(void *ctx, void *p, size_t nbytes)
static inline void
_PyMem_DebugCheckGIL(const char *func)
{
- if (!PyGILState_Check()) {
+ PyThreadState *tstate = _PyThreadState_GET();
+ if (tstate == NULL) {
#ifndef Py_GIL_DISABLED
_Py_FatalErrorFunc(func,
"Python memory allocator called "
diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c
index 1f811e72406130..416eec01052224 100644
--- a/Python/ceval_gil.c
+++ b/Python/ceval_gil.c
@@ -995,7 +995,7 @@ _Py_unset_eval_breaker_bit_all(PyInterpreterState *interp, uintptr_t bit)
void
_Py_FinishPendingCalls(PyThreadState *tstate)
{
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
assert(_PyThreadState_CheckConsistency(tstate));
struct _pending_calls *pending = &tstate->interp->ceval.pending;
@@ -1056,7 +1056,7 @@ _PyEval_MakePendingCalls(PyThreadState *tstate)
int
Py_MakePendingCalls(void)
{
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
PyThreadState *tstate = _PyThreadState_GET();
assert(_PyThreadState_CheckConsistency(tstate));
diff --git a/Python/errors.c b/Python/errors.c
index b6ac2f767a283b..9c7b771133dcf4 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -314,8 +314,8 @@ _PyErr_SetLocaleString(PyObject *exception, const char *string)
PyObject* _Py_HOT_FUNCTION
PyErr_Occurred(void)
{
- /* The caller must hold the GIL. */
- assert(PyGILState_Check());
+ /* The caller must hold a thread state. */
+ _Py_AssertHoldsTstate();
PyThreadState *tstate = _PyThreadState_GET();
return _PyErr_Occurred(tstate);
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 6bc3a44c3c1313..72804c39220591 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -1,6 +1,7 @@
#include "Python.h"
#include "pycore_fileutils.h" // fileutils definitions
#include "pycore_runtime.h" // _PyRuntime
+#include "pycore_pystate.h" // _Py_AssertHoldsTstate()
#include "osdefs.h" // SEP
#include <stdlib.h> // mbstowcs()
@@ -1311,7 +1312,7 @@ _Py_fstat(int fd, struct _Py_stat_struct *status)
{
int res;
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
Py_BEGIN_ALLOW_THREADS
res = _Py_fstat_noraise(fd, status);
@@ -1691,7 +1692,7 @@ int
_Py_open(const char *pathname, int flags)
{
/* _Py_open() must be called with the GIL held. */
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
return _Py_open_impl(pathname, flags, 1);
}
@@ -1766,7 +1767,7 @@ _Py_wfopen(const wchar_t *path, const wchar_t *mode)
FILE*
Py_fopen(PyObject *path, const char *mode)
{
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
if (PySys_Audit("open", "Osi", path, mode, 0) < 0) {
return NULL;
@@ -1881,7 +1882,7 @@ _Py_read(int fd, void *buf, size_t count)
int err;
int async_err = 0;
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
/* _Py_read() must not be called with an exception set, otherwise the
* caller may think that read() was interrupted by a signal and the signal
@@ -2047,7 +2048,7 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held)
Py_ssize_t
_Py_write(int fd, const void *buf, size_t count)
{
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
/* _Py_write() must not be called with an exception set, otherwise the
* caller may think that write() was interrupted by a signal and the signal
@@ -2675,7 +2676,7 @@ _Py_dup(int fd)
HANDLE handle;
#endif
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
#ifdef MS_WINDOWS
handle = _Py_get_osfhandle(fd);
diff --git a/Python/legacy_tracing.c b/Python/legacy_tracing.c
index 45af275f1f6dce..97634f9183c7d5 100644
--- a/Python/legacy_tracing.c
+++ b/Python/legacy_tracing.c
@@ -491,8 +491,8 @@ int
_PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
{
assert(is_tstate_valid(tstate));
- /* The caller must hold the GIL */
- assert(PyGILState_Check());
+ /* The caller must hold a thread state */
+ _Py_AssertHoldsTstate();
/* Call _PySys_Audit() in the context of the current thread state,
even if tstate is not the current thread state. */
@@ -586,8 +586,8 @@ int
_PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
{
assert(is_tstate_valid(tstate));
- /* The caller must hold the GIL */
- assert(PyGILState_Check());
+ /* The caller must hold a thread state */
+ _Py_AssertHoldsTstate();
/* Call _PySys_Audit() in the context of the current thread state,
even if tstate is not the current thread state. */
diff --git a/Python/pystate.c b/Python/pystate.c
index c546b7c3a9f10e..52703b048d6022 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -2897,7 +2897,6 @@ _PyInterpreterState_GetConfigCopy(PyConfig *config)
const PyConfig*
_Py_GetConfig(void)
{
- assert(PyGILState_Check());
PyThreadState *tstate = current_fast_get();
_Py_EnsureTstateNotNULL(tstate);
return _PyInterpreterState_GetConfig(tstate->interp);
diff --git a/Python/pytime.c b/Python/pytime.c
index 2b37cd991ef4e4..c039fc98ce4bde 100644
--- a/Python/pytime.c
+++ b/Python/pytime.c
@@ -1,5 +1,6 @@
#include "Python.h"
#include "pycore_time.h" // PyTime_t
+#include "pycore_pystate.h" // _Py_AssertHoldsTstate()
#include <time.h> // gmtime_r()
#ifdef HAVE_SYS_TIME_H
@@ -897,14 +898,14 @@ _PyTime_AsTimespec(PyTime_t t, struct timespec *ts)
#endif
-// N.B. If raise_exc=0, this may be called without the GIL.
+// N.B. If raise_exc=0, this may be called without a thread state.
static int
py_get_system_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
{
assert(info == NULL || raise_exc);
if (raise_exc) {
- // raise_exc requires to hold the GIL
- assert(PyGILState_Check());
+ // raise_exc requires to hold a thread state
+ _Py_AssertHoldsTstate();
}
#ifdef MS_WINDOWS
@@ -1142,14 +1143,14 @@ py_mach_timebase_info(_PyTimeFraction *base, int raise_exc)
#endif
-// N.B. If raise_exc=0, this may be called without the GIL.
+// N.B. If raise_exc=0, this may be called without a thread state.
static int
py_get_monotonic_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
{
assert(info == NULL || raise_exc);
if (raise_exc) {
- // raise_exc requires to hold the GIL
- assert(PyGILState_Check());
+ // raise_exc requires to hold a thread state
+ _Py_AssertHoldsTstate();
}
#if defined(MS_WINDOWS)
diff --git a/Python/tracemalloc.c b/Python/tracemalloc.c
index 919c564ee72967..a9f45e5ead1a11 100644
--- a/Python/tracemalloc.c
+++ b/Python/tracemalloc.c
@@ -367,7 +367,7 @@ traceback_new(void)
traceback_t *traceback;
_Py_hashtable_entry_t *entry;
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
/* get frames */
traceback = tracemalloc_traceback;
@@ -749,7 +749,7 @@ static void
tracemalloc_clear_traces_unlocked(void)
{
// Clearing tracemalloc_filenames requires the GIL to call Py_DECREF()
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
set_reentrant(1);
@@ -1302,7 +1302,7 @@ PyTraceMalloc_Untrack(unsigned int domain, uintptr_t ptr)
void
_PyTraceMalloc_Fini(void)
{
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
tracemalloc_deinit();
}
@@ -1323,7 +1323,7 @@ _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event,
return 0;
}
- assert(PyGILState_Check());
+ _Py_AssertHoldsTstate();
TABLES_LOCK();
if (!tracemalloc_config.tracing) {
1
0
Jan. 20, 2025
https://github.com/python/cpython/commit/c6b570e5e3b214d2038645c5fa7806e0fb…
commit: c6b570e5e3b214d2038645c5fa7806e0fb3f7dcd
branch: main
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: kumaraditya303 <kumaraditya(a)python.org>
date: 2025-01-20T17:02:39+05:30
summary:
gh-71339: Use new assertion methods in `test_asyncio` (#129051)
files:
M Lib/test/test_asyncio/test_base_events.py
M Lib/test/test_asyncio/test_events.py
M Lib/test/test_asyncio/test_futures.py
M Lib/test/test_asyncio/test_locks.py
M Lib/test/test_asyncio/test_protocols.py
M Lib/test/test_asyncio/test_queues.py
M Lib/test/test_asyncio/test_sock_lowlevel.py
M Lib/test/test_asyncio/test_streams.py
M Lib/test/test_asyncio/test_tasks.py
M Lib/test/test_asyncio/test_windows_utils.py
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index 1e063c1352ecb9..102c9be0ecf031 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -1345,7 +1345,7 @@ def getaddrinfo_task(*args, **kwds):
with self.assertRaises(OSError) as cm:
self.loop.run_until_complete(coro)
- self.assertTrue(str(cm.exception).startswith('Multiple exceptions: '))
+ self.assertStartsWith(str(cm.exception), 'Multiple exceptions: ')
self.assertTrue(m_socket.socket.return_value.close.called)
coro = self.loop.create_connection(
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index ed75b909317357..ada049e9c7d387 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -2184,7 +2184,7 @@ def test_subprocess_stderr(self):
transp.close()
self.assertEqual(b'OUT:test', proto.data[1])
- self.assertTrue(proto.data[2].startswith(b'ERR:test'), proto.data[2])
+ self.assertStartsWith(proto.data[2], b'ERR:test')
self.assertEqual(0, proto.returncode)
@support.requires_subprocess()
@@ -2206,8 +2206,7 @@ def test_subprocess_stderr_redirect_to_stdout(self):
stdin.write(b'test')
self.loop.run_until_complete(proto.completed)
- self.assertTrue(proto.data[1].startswith(b'OUT:testERR:test'),
- proto.data[1])
+ self.assertStartsWith(proto.data[1], b'OUT:testERR:test')
self.assertEqual(b'', proto.data[2])
transp.close()
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
index 84b44011b9a844..01d6230e6dd9a3 100644
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -242,7 +242,7 @@ def test_uninitialized(self):
def test_future_cancel_message_getter(self):
f = self._new_future(loop=self.loop)
- self.assertTrue(hasattr(f, '_cancel_message'))
+ self.assertHasAttr(f, '_cancel_message')
self.assertEqual(f._cancel_message, None)
f.cancel('my message')
diff --git a/Lib/test/test_asyncio/test_locks.py b/Lib/test/test_asyncio/test_locks.py
index aabfcd418829b2..3bb3e5c4ca0658 100644
--- a/Lib/test/test_asyncio/test_locks.py
+++ b/Lib/test/test_asyncio/test_locks.py
@@ -27,11 +27,11 @@ class LockTests(unittest.IsolatedAsyncioTestCase):
async def test_repr(self):
lock = asyncio.Lock()
- self.assertTrue(repr(lock).endswith('[unlocked]>'))
+ self.assertEndsWith(repr(lock), '[unlocked]>')
self.assertTrue(RGX_REPR.match(repr(lock)))
await lock.acquire()
- self.assertTrue(repr(lock).endswith('[locked]>'))
+ self.assertEndsWith(repr(lock), '[locked]>')
self.assertTrue(RGX_REPR.match(repr(lock)))
async def test_lock(self):
@@ -286,12 +286,12 @@ class EventTests(unittest.IsolatedAsyncioTestCase):
def test_repr(self):
ev = asyncio.Event()
- self.assertTrue(repr(ev).endswith('[unset]>'))
+ self.assertEndsWith(repr(ev), '[unset]>')
match = RGX_REPR.match(repr(ev))
self.assertEqual(match.group('extras'), 'unset')
ev.set()
- self.assertTrue(repr(ev).endswith('[set]>'))
+ self.assertEndsWith(repr(ev), '[set]>')
self.assertTrue(RGX_REPR.match(repr(ev)))
ev._waiters.append(mock.Mock())
@@ -916,11 +916,11 @@ def test_initial_value_zero(self):
async def test_repr(self):
sem = asyncio.Semaphore()
- self.assertTrue(repr(sem).endswith('[unlocked, value:1]>'))
+ self.assertEndsWith(repr(sem), '[unlocked, value:1]>')
self.assertTrue(RGX_REPR.match(repr(sem)))
await sem.acquire()
- self.assertTrue(repr(sem).endswith('[locked]>'))
+ self.assertEndsWith(repr(sem), '[locked]>')
self.assertTrue('waiters' not in repr(sem))
self.assertTrue(RGX_REPR.match(repr(sem)))
diff --git a/Lib/test/test_asyncio/test_protocols.py b/Lib/test/test_asyncio/test_protocols.py
index a8627b5b5b87f2..4484a031988533 100644
--- a/Lib/test/test_asyncio/test_protocols.py
+++ b/Lib/test/test_asyncio/test_protocols.py
@@ -19,7 +19,7 @@ def test_base_protocol(self):
self.assertIsNone(p.connection_lost(f))
self.assertIsNone(p.pause_writing())
self.assertIsNone(p.resume_writing())
- self.assertFalse(hasattr(p, '__dict__'))
+ self.assertNotHasAttr(p, '__dict__')
def test_protocol(self):
f = mock.Mock()
@@ -30,7 +30,7 @@ def test_protocol(self):
self.assertIsNone(p.eof_received())
self.assertIsNone(p.pause_writing())
self.assertIsNone(p.resume_writing())
- self.assertFalse(hasattr(p, '__dict__'))
+ self.assertNotHasAttr(p, '__dict__')
def test_buffered_protocol(self):
f = mock.Mock()
@@ -41,7 +41,7 @@ def test_buffered_protocol(self):
self.assertIsNone(p.buffer_updated(150))
self.assertIsNone(p.pause_writing())
self.assertIsNone(p.resume_writing())
- self.assertFalse(hasattr(p, '__dict__'))
+ self.assertNotHasAttr(p, '__dict__')
def test_datagram_protocol(self):
f = mock.Mock()
@@ -50,7 +50,7 @@ def test_datagram_protocol(self):
self.assertIsNone(dp.connection_lost(f))
self.assertIsNone(dp.error_received(f))
self.assertIsNone(dp.datagram_received(f, f))
- self.assertFalse(hasattr(dp, '__dict__'))
+ self.assertNotHasAttr(dp, '__dict__')
def test_subprocess_protocol(self):
f = mock.Mock()
@@ -60,7 +60,7 @@ def test_subprocess_protocol(self):
self.assertIsNone(sp.pipe_data_received(1, f))
self.assertIsNone(sp.pipe_connection_lost(1, f))
self.assertIsNone(sp.process_exited())
- self.assertFalse(hasattr(sp, '__dict__'))
+ self.assertNotHasAttr(sp, '__dict__')
if __name__ == '__main__':
diff --git a/Lib/test/test_asyncio/test_queues.py b/Lib/test/test_asyncio/test_queues.py
index 1a8d604faea1fd..090b9774c2289f 100644
--- a/Lib/test/test_asyncio/test_queues.py
+++ b/Lib/test/test_asyncio/test_queues.py
@@ -18,7 +18,7 @@ async def _test_repr_or_str(self, fn, expect_id):
appear in fn(Queue()).
"""
q = asyncio.Queue()
- self.assertTrue(fn(q).startswith('<Queue'), fn(q))
+ self.assertStartsWith(fn(q), '<Queue')
id_is_present = hex(id(q)) in fn(q)
self.assertEqual(expect_id, id_is_present)
diff --git a/Lib/test/test_asyncio/test_sock_lowlevel.py b/Lib/test/test_asyncio/test_sock_lowlevel.py
index 5b1e5143820cad..4f7b9a1dda6b78 100644
--- a/Lib/test/test_asyncio/test_sock_lowlevel.py
+++ b/Lib/test/test_asyncio/test_sock_lowlevel.py
@@ -110,7 +110,7 @@ def _basetest_sock_client_ops(self, httpd, sock):
self.loop.run_until_complete(
self.loop.sock_recv(sock, 1024))
sock.close()
- self.assertTrue(data.startswith(b'HTTP/1.0 200 OK'))
+ self.assertStartsWith(data, b'HTTP/1.0 200 OK')
def _basetest_sock_recv_into(self, httpd, sock):
# same as _basetest_sock_client_ops, but using sock_recv_into
@@ -127,7 +127,7 @@ def _basetest_sock_recv_into(self, httpd, sock):
self.loop.run_until_complete(
self.loop.sock_recv_into(sock, buf[nbytes:]))
sock.close()
- self.assertTrue(data.startswith(b'HTTP/1.0 200 OK'))
+ self.assertStartsWith(data, b'HTTP/1.0 200 OK')
def test_sock_client_ops(self):
with test_utils.run_test_server() as httpd:
@@ -150,7 +150,7 @@ async def _basetest_sock_recv_racing(self, httpd, sock):
# consume data
await self.loop.sock_recv(sock, 1024)
- self.assertTrue(data.startswith(b'HTTP/1.0 200 OK'))
+ self.assertStartsWith(data, b'HTTP/1.0 200 OK')
async def _basetest_sock_recv_into_racing(self, httpd, sock):
sock.setblocking(False)
@@ -168,7 +168,7 @@ async def _basetest_sock_recv_into_racing(self, httpd, sock):
nbytes = await self.loop.sock_recv_into(sock, buf[:1024])
# consume data
await self.loop.sock_recv_into(sock, buf[nbytes:])
- self.assertTrue(data.startswith(b'HTTP/1.0 200 OK'))
+ self.assertStartsWith(data, b'HTTP/1.0 200 OK')
await task
@@ -217,7 +217,7 @@ async def recv_all():
sock.shutdown(socket.SHUT_WR)
data = await task
# ProactorEventLoop could deliver hello, so endswith is necessary
- self.assertTrue(data.endswith(b'world'))
+ self.assertEndsWith(data, b'world')
# After the first connect attempt before the listener is ready,
# the socket needs time to "recover" to make the next connect call.
@@ -298,7 +298,7 @@ async def _basetest_huge_content(self, address):
data = await self.loop.sock_recv(sock, DATA_SIZE)
# HTTP headers size is less than MTU,
# they are sent by the first packet always
- self.assertTrue(data.startswith(b'HTTP/1.0 200 OK'))
+ self.assertStartsWith(data, b'HTTP/1.0 200 OK')
while data.find(b'\r\n\r\n') == -1:
data += await self.loop.sock_recv(sock, DATA_SIZE)
# Strip headers
@@ -351,7 +351,7 @@ async def _basetest_huge_content_recvinto(self, address):
data = bytes(buf[:nbytes])
# HTTP headers size is less than MTU,
# they are sent by the first packet always
- self.assertTrue(data.startswith(b'HTTP/1.0 200 OK'))
+ self.assertStartsWith(data, b'HTTP/1.0 200 OK')
while data.find(b'\r\n\r\n') == -1:
nbytes = await self.loop.sock_recv_into(sock, buf)
data = bytes(buf[:nbytes])
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py
index 047ada8c5d23df..673c6b46c647f3 100644
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -50,7 +50,7 @@ def _basetest_open_connection(self, open_connection_fut):
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
f = reader.read()
data = self.loop.run_until_complete(f)
- self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
+ self.assertEndsWith(data, b'\r\n\r\nTest message')
writer.close()
self.assertEqual(messages, [])
@@ -75,7 +75,7 @@ def _basetest_open_connection_no_loop_ssl(self, open_connection_fut):
writer.write(b'GET / HTTP/1.0\r\n\r\n')
f = reader.read()
data = self.loop.run_until_complete(f)
- self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
+ self.assertEndsWith(data, b'\r\n\r\nTest message')
writer.close()
self.assertEqual(messages, [])
@@ -1002,7 +1002,7 @@ def test_wait_closed_on_close(self):
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
f = rd.read()
data = self.loop.run_until_complete(f)
- self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
+ self.assertEndsWith(data, b'\r\n\r\nTest message')
self.assertFalse(wr.is_closing())
wr.close()
self.assertTrue(wr.is_closing())
@@ -1028,7 +1028,7 @@ async def inner(httpd):
data = await rd.readline()
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
data = await rd.read()
- self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
+ self.assertEndsWith(data, b'\r\n\r\nTest message')
wr.close()
await wr.wait_closed()
@@ -1048,7 +1048,7 @@ async def inner(httpd):
data = await rd.readline()
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
data = await rd.read()
- self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
+ self.assertEndsWith(data, b'\r\n\r\nTest message')
wr.close()
with self.assertRaises(ConnectionResetError):
wr.write(b'data')
@@ -1089,12 +1089,12 @@ async def inner(httpd):
data = await rd.readline()
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
data = await rd.read()
- self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
+ self.assertEndsWith(data, b'\r\n\r\nTest message')
with self.assertWarns(ResourceWarning) as cm:
del wr
gc.collect()
self.assertEqual(len(cm.warnings), 1)
- self.assertTrue(str(cm.warnings[0].message).startswith("unclosed <StreamWriter"))
+ self.assertStartsWith(str(cm.warnings[0].message), "unclosed <StreamWriter")
messages = []
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
@@ -1112,7 +1112,7 @@ async def inner(httpd):
data = await rd.readline()
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
data = await rd.read()
- self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
+ self.assertEndsWith(data, b'\r\n\r\nTest message')
# Make "loop is closed" occur first before "del wr" for this test.
self.loop.stop()
@@ -1144,7 +1144,7 @@ async def inner(rd, wr):
del wr
gc.collect()
self.assertEqual(len(cm.warnings), 1)
- self.assertTrue(str(cm.warnings[0].message).startswith("unclosed <StreamWriter"))
+ self.assertStartsWith(str(cm.warnings[0].message), "unclosed <StreamWriter")
async def outer():
srv = await asyncio.start_server(inner, socket_helper.HOSTv4, 0)
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index b5363226ad79f4..7a052817766a07 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -110,7 +110,7 @@ def test_task_cancel_message_getter(self):
async def coro():
pass
t = self.new_task(self.loop, coro())
- self.assertTrue(hasattr(t, '_cancel_message'))
+ self.assertHasAttr(t, '_cancel_message')
self.assertEqual(t._cancel_message, None)
t.cancel('my message')
@@ -3131,7 +3131,7 @@ def new_task(self, coro):
class GenericTaskTests(test_utils.TestCase):
def test_future_subclass(self):
- self.assertTrue(issubclass(asyncio.Task, asyncio.Future))
+ self.assertIsSubclass(asyncio.Task, asyncio.Future)
@support.cpython_only
def test_asyncio_module_compiled(self):
diff --git a/Lib/test/test_asyncio/test_windows_utils.py b/Lib/test/test_asyncio/test_windows_utils.py
index be70720707cea7..a6b207567c4f00 100644
--- a/Lib/test/test_asyncio/test_windows_utils.py
+++ b/Lib/test/test_asyncio/test_windows_utils.py
@@ -121,8 +121,8 @@ def test_popen(self):
self.assertGreater(len(out), 0)
self.assertGreater(len(err), 0)
# allow for partial reads...
- self.assertTrue(msg.upper().rstrip().startswith(out))
- self.assertTrue(b"stderr".startswith(err))
+ self.assertStartsWith(msg.upper().rstrip(), out)
+ self.assertStartsWith(b"stderr", err)
# The context manager calls wait() and closes resources
with p:
1
0
gh-128595: Default to stdout isatty for colour detection instead of stderr (#128498)
by hugovk Jan. 20, 2025
by hugovk Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/6f167d71347de6717d9f6b64026e21f23d…
commit: 6f167d71347de6717d9f6b64026e21f23d41ef0b
branch: main
author: Hugo van Kemenade <1324225+hugovk(a)users.noreply.github.com>
committer: hugovk <1324225+hugovk(a)users.noreply.github.com>
date: 2025-01-20T12:52:42+02:00
summary:
gh-128595: Default to stdout isatty for colour detection instead of stderr (#128498)
Co-authored-by: Serhiy Storchaka <storchaka(a)gmail.com>
Co-authored-by: Victor Stinner <vstinner(a)python.org>
files:
A Misc/NEWS.d/next/Library/2025-01-07-21-48-32.gh-issue-128498.n6jtlW.rst
M Lib/_colorize.py
M Lib/doctest.py
M Lib/test/libregrtest/single.py
M Lib/test/support/__init__.py
M Lib/traceback.py
M Lib/unittest/result.py
M Lib/unittest/runner.py
diff --git a/Lib/_colorize.py b/Lib/_colorize.py
index f609901887a26b..bab2e599b2c810 100644
--- a/Lib/_colorize.py
+++ b/Lib/_colorize.py
@@ -26,14 +26,17 @@ class ANSIColors:
setattr(NoColors, attr, "")
-def get_colors(colorize: bool = False) -> ANSIColors:
- if colorize or can_colorize():
+def get_colors(colorize: bool = False, *, file=None) -> ANSIColors:
+ if colorize or can_colorize(file=file):
return ANSIColors()
else:
return NoColors
-def can_colorize() -> bool:
+def can_colorize(*, file=None) -> bool:
+ if file is None:
+ file = sys.stdout
+
if not sys.flags.ignore_environment:
if os.environ.get("PYTHON_COLORS") == "0":
return False
@@ -49,7 +52,7 @@ def can_colorize() -> bool:
if os.environ.get("TERM") == "dumb":
return False
- if not hasattr(sys.stderr, "fileno"):
+ if not hasattr(file, "fileno"):
return False
if sys.platform == "win32":
@@ -62,6 +65,6 @@ def can_colorize() -> bool:
return False
try:
- return os.isatty(sys.stderr.fileno())
+ return os.isatty(file.fileno())
except io.UnsupportedOperation:
- return sys.stderr.isatty()
+ return file.isatty()
diff --git a/Lib/doctest.py b/Lib/doctest.py
index bb281fc483c41c..e02e73ed722f7e 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -1558,7 +1558,7 @@ def out(s):
save_displayhook = sys.displayhook
sys.displayhook = sys.__displayhook__
saved_can_colorize = _colorize.can_colorize
- _colorize.can_colorize = lambda: False
+ _colorize.can_colorize = lambda *args, **kwargs: False
color_variables = {"PYTHON_COLORS": None, "FORCE_COLOR": None}
for key in color_variables:
color_variables[key] = os.environ.pop(key, None)
diff --git a/Lib/test/libregrtest/single.py b/Lib/test/libregrtest/single.py
index 0e174f82abed28..54df688bbc470e 100644
--- a/Lib/test/libregrtest/single.py
+++ b/Lib/test/libregrtest/single.py
@@ -162,8 +162,8 @@ def test_func():
def _runtest_env_changed_exc(result: TestResult, runtests: RunTests,
display_failure: bool = True) -> None:
# Handle exceptions, detect environment changes.
- ansi = get_colors()
- red, reset, yellow = ansi.RED, ansi.RESET, ansi.YELLOW
+ stdout = get_colors(file=sys.stdout)
+ stderr = get_colors(file=sys.stderr)
# Reset the environment_altered flag to detect if a test altered
# the environment
@@ -184,18 +184,24 @@ def _runtest_env_changed_exc(result: TestResult, runtests: RunTests,
_load_run_test(result, runtests)
except support.ResourceDenied as exc:
if not quiet and not pgo:
- print(f"{yellow}{test_name} skipped -- {exc}{reset}", flush=True)
+ print(
+ f"{stdout.YELLOW}{test_name} skipped -- {exc}{stdout.RESET}",
+ flush=True,
+ )
result.state = State.RESOURCE_DENIED
return
except unittest.SkipTest as exc:
if not quiet and not pgo:
- print(f"{yellow}{test_name} skipped -- {exc}{reset}", flush=True)
+ print(
+ f"{stdout.YELLOW}{test_name} skipped -- {exc}{stdout.RESET}",
+ flush=True,
+ )
result.state = State.SKIPPED
return
except support.TestFailedWithDetails as exc:
- msg = f"{red}test {test_name} failed{reset}"
+ msg = f"{stderr.RED}test {test_name} failed{stderr.RESET}"
if display_failure:
- msg = f"{red}{msg} -- {exc}{reset}"
+ msg = f"{stderr.RED}{msg} -- {exc}{stderr.RESET}"
print(msg, file=sys.stderr, flush=True)
result.state = State.FAILED
result.errors = exc.errors
@@ -203,9 +209,9 @@ def _runtest_env_changed_exc(result: TestResult, runtests: RunTests,
result.stats = exc.stats
return
except support.TestFailed as exc:
- msg = f"{red}test {test_name} failed{reset}"
+ msg = f"{stderr.RED}test {test_name} failed{stderr.RESET}"
if display_failure:
- msg = f"{red}{msg} -- {exc}{reset}"
+ msg = f"{stderr.RED}{msg} -- {exc}{stderr.RESET}"
print(msg, file=sys.stderr, flush=True)
result.state = State.FAILED
result.stats = exc.stats
@@ -220,8 +226,11 @@ def _runtest_env_changed_exc(result: TestResult, runtests: RunTests,
except:
if not pgo:
msg = traceback.format_exc()
- print(f"{red}test {test_name} crashed -- {msg}{reset}",
- file=sys.stderr, flush=True)
+ print(
+ f"{stderr.RED}test {test_name} crashed -- {msg}{stderr.RESET}",
+ file=sys.stderr,
+ flush=True,
+ )
result.state = State.UNCAUGHT_EXC
return
@@ -303,7 +312,7 @@ def run_single_test(test_name: TestName, runtests: RunTests) -> TestResult:
If runtests.use_junit, xml_data is a list containing each generated
testsuite element.
"""
- ansi = get_colors()
+ ansi = get_colors(file=sys.stderr)
red, reset, yellow = ansi.BOLD_RED, ansi.RESET, ansi.YELLOW
start_time = time.perf_counter()
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index ee9520a8838625..e05e91babc2499 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2839,7 +2839,7 @@ def no_color():
from .os_helper import EnvironmentVarGuard
with (
- swap_attr(_colorize, "can_colorize", lambda: False),
+ swap_attr(_colorize, "can_colorize", lambda file=None: False),
EnvironmentVarGuard() as env,
):
for var in {"FORCE_COLOR", "NO_COLOR", "PYTHON_COLORS"}:
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 6367c00e4d4b86..3ed06af15a0a89 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -135,7 +135,7 @@ def print_exception(exc, /, value=_sentinel, tb=_sentinel, limit=None, \
def _print_exception_bltin(exc, /):
file = sys.stderr if sys.stderr is not None else sys.__stderr__
- colorize = _colorize.can_colorize()
+ colorize = _colorize.can_colorize(file=file)
return print_exception(exc, limit=BUILTIN_EXCEPTION_LIMIT, file=file, colorize=colorize)
diff --git a/Lib/unittest/result.py b/Lib/unittest/result.py
index 97262735aa8311..b8ea396db6772e 100644
--- a/Lib/unittest/result.py
+++ b/Lib/unittest/result.py
@@ -191,7 +191,8 @@ def _exc_info_to_string(self, err, test):
capture_locals=self.tb_locals, compact=True)
from _colorize import can_colorize
- msgLines = list(tb_e.format(colorize=can_colorize()))
+ colorize = hasattr(self, "stream") and can_colorize(file=self.stream)
+ msgLines = list(tb_e.format(colorize=colorize))
if self.buffer:
output = sys.stdout.getvalue()
diff --git a/Lib/unittest/runner.py b/Lib/unittest/runner.py
index d60c295a1eddf7..eb0234a2617680 100644
--- a/Lib/unittest/runner.py
+++ b/Lib/unittest/runner.py
@@ -45,7 +45,7 @@ def __init__(self, stream, descriptions, verbosity, *, durations=None):
self.showAll = verbosity > 1
self.dots = verbosity == 1
self.descriptions = descriptions
- self._ansi = get_colors()
+ self._ansi = get_colors(file=stream)
self._newline = True
self.durations = durations
@@ -286,7 +286,7 @@ def run(self, test):
expected_fails, unexpected_successes, skipped = results
infos = []
- ansi = get_colors()
+ ansi = get_colors(file=self.stream)
bold_red = ansi.BOLD_RED
green = ansi.GREEN
red = ansi.RED
diff --git a/Misc/NEWS.d/next/Library/2025-01-07-21-48-32.gh-issue-128498.n6jtlW.rst b/Misc/NEWS.d/next/Library/2025-01-07-21-48-32.gh-issue-128498.n6jtlW.rst
new file mode 100644
index 00000000000000..9a241e37c20a44
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-07-21-48-32.gh-issue-128498.n6jtlW.rst
@@ -0,0 +1,2 @@
+Default to stdout isatty for color detection instead of stderr. Patch by
+Hugo van Kemenade.
1
0
https://github.com/python/cpython/commit/a42915979796565635dcfcd45d2b62b3e5…
commit: a42915979796565635dcfcd45d2b62b3e5e46eba
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-20T11:42:04+01:00
summary:
Reorganize the PyInitConfig documentation (#129047)
Document the new PyInitConfig API before the old PyConfig API.
files:
M Doc/c-api/init_config.rst
diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst
index 85566631ca1676..a549d4c55fc43d 100644
--- a/Doc/c-api/init_config.rst
+++ b/Doc/c-api/init_config.rst
@@ -6,28 +6,15 @@
Python Initialization Configuration
***********************************
-.. _pyconfig_api:
-
-PyConfig C API
-==============
-.. versionadded:: 3.8
-
-Python can be initialized with :c:func:`Py_InitializeFromConfig` and the
-:c:type:`PyConfig` structure. It can be preinitialized with
-:c:func:`Py_PreInitialize` and the :c:type:`PyPreConfig` structure.
+.. _pyinitconfig_api:
-There are two kinds of configuration:
+PyInitConfig C API
+==================
-* The :ref:`Python Configuration <init-python-config>` can be used to build a
- customized Python which behaves as the regular Python. For example,
- environment variables and command line arguments are used to configure
- Python.
+.. versionadded:: 3.14
-* The :ref:`Isolated Configuration <init-isolated-conf>` can be used to embed
- Python into an application. It isolates Python from the system. For example,
- environment variables are ignored, the LC_CTYPE locale is left unchanged and
- no signal handler is registered.
+Python can be initialized with :c:func:`Py_InitializeFromInitConfig`.
The :c:func:`Py_RunMain` function can be used to write a customized Python
program.
@@ -35,1906 +22,1920 @@ program.
See also :ref:`Initialization, Finalization, and Threads <initialization>`.
.. seealso::
- :pep:`587` "Python Initialization Configuration".
+ :pep:`741` "Python Configuration C API".
Example
-------
-Example of customized Python always running in isolated mode::
-
- int main(int argc, char **argv)
- {
- PyStatus status;
+Example of customized Python always running with the :ref:`Python Development
+Mode <devmode>` enabled; return ``-1`` on error:
- PyConfig config;
- PyConfig_InitPythonConfig(&config);
- config.isolated = 1;
+.. code-block:: c
- /* Decode command line arguments.
- Implicitly preinitialize Python (in isolated mode). */
- status = PyConfig_SetBytesArgv(&config, argc, argv);
- if (PyStatus_Exception(status)) {
- goto exception;
+ int init_python(void)
+ {
+ PyInitConfig *config = PyInitConfig_Create();
+ if (config == NULL) {
+ printf("PYTHON INIT ERROR: memory allocation failed\n");
+ return -1;
}
- status = Py_InitializeFromConfig(&config);
- if (PyStatus_Exception(status)) {
- goto exception;
+ // Enable the Python Development Mode
+ if (PyInitConfig_SetInt(config, "dev_mode", 1) < 0) {
+ goto error;
}
- PyConfig_Clear(&config);
- return Py_RunMain();
+ // Initialize Python with the configuration
+ if (Py_InitializeFromInitConfig(config) < 0) {
+ goto error;
+ }
+ PyInitConfig_Free(config);
+ return 0;
- exception:
- PyConfig_Clear(&config);
- if (PyStatus_IsExit(status)) {
- return status.exitcode;
+ error:
+ {
+ // Display the error message.
+ //
+ // This uncommon braces style is used, because you cannot make
+ // goto targets point to variable declarations.
+ const char *err_msg;
+ (void)PyInitConfig_GetError(config, &err_msg);
+ printf("PYTHON INIT ERROR: %s\n", err_msg);
+ PyInitConfig_Free(config);
+ return -1;
}
- /* Display the error message and exit the process with
- non-zero exit code */
- Py_ExitStatusException(status);
}
+Create Config
+-------------
-PyWideStringList
-----------------
+.. c:struct:: PyInitConfig
-.. c:type:: PyWideStringList
+ Opaque structure to configure the Python initialization.
- List of ``wchar_t*`` strings.
- If *length* is non-zero, *items* must be non-``NULL`` and all strings must be
- non-``NULL``.
+.. c:function:: PyInitConfig* PyInitConfig_Create(void)
- .. c:namespace:: NULL
+ Create a new initialization configuration using :ref:`Isolated Configuration
+ <init-isolated-conf>` default values.
- Methods:
+ It must be freed by :c:func:`PyInitConfig_Free`.
- .. c:function:: PyStatus PyWideStringList_Append(PyWideStringList *list, const wchar_t *item)
+ Return ``NULL`` on memory allocation failure.
- Append *item* to *list*.
- Python must be preinitialized to call this function.
+.. c:function:: void PyInitConfig_Free(PyInitConfig *config)
- .. c:function:: PyStatus PyWideStringList_Insert(PyWideStringList *list, Py_ssize_t index, const wchar_t *item)
+ Free memory of the initialization configuration *config*.
- Insert *item* into *list* at *index*.
+ If *config* is ``NULL``, no operation is performed.
- If *index* is greater than or equal to *list* length, append *item* to
- *list*.
- *index* must be greater than or equal to ``0``.
+Error Handling
+--------------
- Python must be preinitialized to call this function.
+.. c:function:: int PyInitConfig_GetError(PyInitConfig* config, const char **err_msg)
- .. c:namespace:: PyWideStringList
+ Get the *config* error message.
- Structure fields:
+ * Set *\*err_msg* and return ``1`` if an error is set.
+ * Set *\*err_msg* to ``NULL`` and return ``0`` otherwise.
- .. c:member:: Py_ssize_t length
+ An error message is an UTF-8 encoded string.
- List length.
+ If *config* has an exit code, format the exit code as an error
+ message.
- .. c:member:: wchar_t** items
+ The error message remains valid until another ``PyInitConfig``
+ function is called with *config*. The caller doesn't have to free the
+ error message.
- List items.
-PyStatus
---------
+.. c:function:: int PyInitConfig_GetExitCode(PyInitConfig* config, int *exitcode)
-.. c:type:: PyStatus
+ Get the *config* exit code.
- Structure to store an initialization function status: success, error
- or exit.
+ * Set *\*exitcode* and return ``1`` if *config* has an exit code set.
+ * Return ``0`` if *config* has no exit code set.
- For an error, it can store the C function name which created the error.
+ Only the ``Py_InitializeFromInitConfig()`` function can set an exit
+ code if the ``parse_argv`` option is non-zero.
- Structure fields:
+ An exit code can be set when parsing the command line failed (exit
+ code ``2``) or when a command line option asks to display the command
+ line help (exit code ``0``).
- .. c:member:: int exitcode
- Exit code. Argument passed to ``exit()``.
+Get Options
+-----------
- .. c:member:: const char *err_msg
+The configuration option *name* parameter must be a non-NULL
+null-terminated UTF-8 encoded string.
- Error message.
+.. c:function:: int PyInitConfig_HasOption(PyInitConfig *config, const char *name)
- .. c:member:: const char *func
+ Test if the configuration has an option called *name*.
- Name of the function which created an error, can be ``NULL``.
+ Return ``1`` if the option exists, or return ``0`` otherwise.
- .. c:namespace:: NULL
- Functions to create a status:
+.. c:function:: int PyInitConfig_GetInt(PyInitConfig *config, const char *name, int64_t *value)
- .. c:function:: PyStatus PyStatus_Ok(void)
+ Get an integer configuration option.
- Success.
+ * Set *\*value*, and return ``0`` on success.
+ * Set an error in *config* and return ``-1`` on error.
- .. c:function:: PyStatus PyStatus_Error(const char *err_msg)
- Initialization error with a message.
+.. c:function:: int PyInitConfig_GetStr(PyInitConfig *config, const char *name, char **value)
- *err_msg* must not be ``NULL``.
+ Get a string configuration option as a null-terminated UTF-8
+ encoded string.
- .. c:function:: PyStatus PyStatus_NoMemory(void)
+ * Set *\*value*, and return ``0`` on success.
+ * Set an error in *config* and return ``-1`` on error.
- Memory allocation failure (out of memory).
+ *\*value* can be set to ``NULL`` if the option is an optional string and the
+ option is unset.
- .. c:function:: PyStatus PyStatus_Exit(int exitcode)
+ On success, the string must be released with ``free(value)`` if it's not
+ ``NULL``.
- Exit Python with the specified exit code.
- Functions to handle a status:
+.. c:function:: int PyInitConfig_GetStrList(PyInitConfig *config, const char *name, size_t *length, char ***items)
- .. c:function:: int PyStatus_Exception(PyStatus status)
+ Get a string list configuration option as an array of
+ null-terminated UTF-8 encoded strings.
- Is the status an error or an exit? If true, the exception must be
- handled; by calling :c:func:`Py_ExitStatusException` for example.
+ * Set *\*length* and *\*value*, and return ``0`` on success.
+ * Set an error in *config* and return ``-1`` on error.
- .. c:function:: int PyStatus_IsError(PyStatus status)
+ On success, the string list must be released with
+ ``PyInitConfig_FreeStrList(length, items)``.
- Is the result an error?
- .. c:function:: int PyStatus_IsExit(PyStatus status)
+.. c:function:: void PyInitConfig_FreeStrList(size_t length, char **items)
- Is the result an exit?
+ Free memory of a string list created by
+ ``PyInitConfig_GetStrList()``.
- .. c:function:: void Py_ExitStatusException(PyStatus status)
- Call ``exit(exitcode)`` if *status* is an exit. Print the error
- message and exit with a non-zero exit code if *status* is an error. Must
- only be called if ``PyStatus_Exception(status)`` is non-zero.
+Set Options
+-----------
-.. note::
- Internally, Python uses macros which set ``PyStatus.func``,
- whereas functions to create a status set ``func`` to ``NULL``.
+The configuration option *name* parameter must be a non-NULL null-terminated
+UTF-8 encoded string.
-Example::
+Some configuration options have side effects on other options. This logic is
+only implemented when ``Py_InitializeFromInitConfig()`` is called, not by the
+"Set" functions below. For example, setting ``dev_mode`` to ``1`` does not set
+``faulthandler`` to ``1``.
- PyStatus alloc(void **ptr, size_t size)
- {
- *ptr = PyMem_RawMalloc(size);
- if (*ptr == NULL) {
- return PyStatus_NoMemory();
- }
- return PyStatus_Ok();
- }
+.. c:function:: int PyInitConfig_SetInt(PyInitConfig *config, const char *name, int64_t value)
- int main(int argc, char **argv)
- {
- void *ptr;
- PyStatus status = alloc(&ptr, 16);
- if (PyStatus_Exception(status)) {
- Py_ExitStatusException(status);
- }
- PyMem_Free(ptr);
- return 0;
- }
+ Set an integer configuration option.
+ * Return ``0`` on success.
+ * Set an error in *config* and return ``-1`` on error.
-PyPreConfig
------------
-.. c:type:: PyPreConfig
+.. c:function:: int PyInitConfig_SetStr(PyInitConfig *config, const char *name, const char *value)
- Structure used to preinitialize Python.
+ Set a string configuration option from a null-terminated UTF-8
+ encoded string. The string is copied.
- .. c:namespace:: NULL
+ * Return ``0`` on success.
+ * Set an error in *config* and return ``-1`` on error.
- Function to initialize a preconfiguration:
- .. c:function:: void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig)
+.. c:function:: int PyInitConfig_SetStrList(PyInitConfig *config, const char *name, size_t length, char * const *items)
- Initialize the preconfiguration with :ref:`Python Configuration
- <init-python-config>`.
+ Set a string list configuration option from an array of
+ null-terminated UTF-8 encoded strings. The string list is copied.
- .. c:function:: void PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig)
+ * Return ``0`` on success.
+ * Set an error in *config* and return ``-1`` on error.
- Initialize the preconfiguration with :ref:`Isolated Configuration
- <init-isolated-conf>`.
- .. c:namespace:: PyPreConfig
+Module
+------
- Structure fields:
+.. c:function:: int PyInitConfig_AddModule(PyInitConfig *config, const char *name, PyObject* (*initfunc)(void))
- .. c:member:: int allocator
-
- Name of the Python memory allocators:
+ Add a built-in extension module to the table of built-in modules.
- * ``PYMEM_ALLOCATOR_NOT_SET`` (``0``): don't change memory allocators
- (use defaults).
- * ``PYMEM_ALLOCATOR_DEFAULT`` (``1``): :ref:`default memory allocators
- <default-memory-allocators>`.
- * ``PYMEM_ALLOCATOR_DEBUG`` (``2``): :ref:`default memory allocators
- <default-memory-allocators>` with :ref:`debug hooks
- <pymem-debug-hooks>`.
- * ``PYMEM_ALLOCATOR_MALLOC`` (``3``): use ``malloc()`` of the C library.
- * ``PYMEM_ALLOCATOR_MALLOC_DEBUG`` (``4``): force usage of
- ``malloc()`` with :ref:`debug hooks <pymem-debug-hooks>`.
- * ``PYMEM_ALLOCATOR_PYMALLOC`` (``5``): :ref:`Python pymalloc memory
- allocator <pymalloc>`.
- * ``PYMEM_ALLOCATOR_PYMALLOC_DEBUG`` (``6``): :ref:`Python pymalloc
- memory allocator <pymalloc>` with :ref:`debug hooks
- <pymem-debug-hooks>`.
- * ``PYMEM_ALLOCATOR_MIMALLOC`` (``6``): use ``mimalloc``, a fast
- malloc replacement.
- * ``PYMEM_ALLOCATOR_MIMALLOC_DEBUG`` (``7``): use ``mimalloc``, a fast
- malloc replacement with :ref:`debug hooks <pymem-debug-hooks>`.
+ The new module can be imported by the name *name*, and uses the function
+ *initfunc* as the initialization function called on the first attempted
+ import.
+ * Return ``0`` on success.
+ * Set an error in *config* and return ``-1`` on error.
- ``PYMEM_ALLOCATOR_PYMALLOC`` and ``PYMEM_ALLOCATOR_PYMALLOC_DEBUG`` are
- not supported if Python is :option:`configured using --without-pymalloc
- <--without-pymalloc>`.
+ If Python is initialized multiple times, ``PyInitConfig_AddModule()`` must
+ be called at each Python initialization.
- ``PYMEM_ALLOCATOR_MIMALLOC`` and ``PYMEM_ALLOCATOR_MIMALLOC_DEBUG`` are
- not supported if Python is :option:`configured using --without-mimalloc
- <--without-mimalloc>` or if the underlying atomic support isn't
- available.
+ Similar to the :c:func:`PyImport_AppendInittab` function.
- See :ref:`Memory Management <memory>`.
- Default: ``PYMEM_ALLOCATOR_NOT_SET``.
+Initialize Python
+-----------------
- .. c:member:: int configure_locale
+.. c:function:: int Py_InitializeFromInitConfig(PyInitConfig *config)
- Set the LC_CTYPE locale to the user preferred locale.
+ Initialize Python from the initialization configuration.
- If equals to ``0``, set :c:member:`~PyPreConfig.coerce_c_locale` and
- :c:member:`~PyPreConfig.coerce_c_locale_warn` members to ``0``.
+ * Return ``0`` on success.
+ * Set an error in *config* and return ``-1`` on error.
+ * Set an exit code in *config* and return ``-1`` if Python wants to
+ exit.
- See the :term:`locale encoding`.
+ See ``PyInitConfig_GetExitcode()`` for the exit code case.
- Default: ``1`` in Python config, ``0`` in isolated config.
- .. c:member:: int coerce_c_locale
+Runtime Python configuration API
+================================
- If equals to ``2``, coerce the C locale.
+At runtime, it's possible to get and set configuration options using
+:c:func:`PyConfig_Get` and :c:func:`PyConfig_Set` functions.
- If equals to ``1``, read the LC_CTYPE locale to decide if it should be
- coerced.
+The configuration option *name* parameter must be a non-NULL null-terminated
+UTF-8 encoded string.
- See the :term:`locale encoding`.
+Some options are read from the :mod:`sys` attributes. For example, the option
+``"argv"`` is read from :data:`sys.argv`.
- Default: ``-1`` in Python config, ``0`` in isolated config.
- .. c:member:: int coerce_c_locale_warn
+.. c:function:: PyObject* PyConfig_Get(const char *name)
- If non-zero, emit a warning if the C locale is coerced.
+ Get the current runtime value of a configuration option as a Python object.
- Default: ``-1`` in Python config, ``0`` in isolated config.
+ * Return a new reference on success.
+ * Set an exception and return ``NULL`` on error.
- .. c:member:: int dev_mode
+ The object type depends on the configuration option. It can be:
- :ref:`Python Development Mode <devmode>`: see
- :c:member:`PyConfig.dev_mode`.
+ * ``bool``
+ * ``int``
+ * ``str``
+ * ``list[str]``
+ * ``dict[str, str]``
- Default: ``-1`` in Python mode, ``0`` in isolated mode.
+ The caller must hold the GIL. The function cannot be called before
+ Python initialization nor after Python finalization.
- .. c:member:: int isolated
+ .. versionadded:: 3.14
- Isolated mode: see :c:member:`PyConfig.isolated`.
- Default: ``0`` in Python mode, ``1`` in isolated mode.
+.. c:function:: int PyConfig_GetInt(const char *name, int *value)
- .. c:member:: int legacy_windows_fs_encoding
+ Similar to :c:func:`PyConfig_Get`, but get the value as a C int.
- If non-zero:
+ * Return ``0`` on success.
+ * Set an exception and return ``-1`` on error.
- * Set :c:member:`PyPreConfig.utf8_mode` to ``0``,
- * Set :c:member:`PyConfig.filesystem_encoding` to ``"mbcs"``,
- * Set :c:member:`PyConfig.filesystem_errors` to ``"replace"``.
+ .. versionadded:: 3.14
- Initialized from the :envvar:`PYTHONLEGACYWINDOWSFSENCODING` environment
- variable value.
- Only available on Windows. ``#ifdef MS_WINDOWS`` macro can be used for
- Windows specific code.
+.. c:function:: PyObject* PyConfig_Names(void)
- Default: ``0``.
+ Get all configuration option names as a ``frozenset``.
- .. c:member:: int parse_argv
+ * Return a new reference on success.
+ * Set an exception and return ``NULL`` on error.
- If non-zero, :c:func:`Py_PreInitializeFromArgs` and
- :c:func:`Py_PreInitializeFromBytesArgs` parse their ``argv`` argument the
- same way the regular Python parses command line arguments: see
- :ref:`Command Line Arguments <using-on-cmdline>`.
+ The caller must hold the GIL. The function cannot be called before
+ Python initialization nor after Python finalization.
- Default: ``1`` in Python config, ``0`` in isolated config.
+ .. versionadded:: 3.14
- .. c:member:: int use_environment
- Use :ref:`environment variables <using-on-envvars>`? See
- :c:member:`PyConfig.use_environment`.
+.. c:function:: int PyConfig_Set(const char *name, PyObject *value)
- Default: ``1`` in Python config and ``0`` in isolated config.
+ Set the current runtime value of a configuration option.
- .. c:member:: int utf8_mode
+ * Raise a :exc:`ValueError` if there is no option *name*.
+ * Raise a :exc:`ValueError` if *value* is an invalid value.
+ * Raise a :exc:`ValueError` if the option is read-only (cannot be set).
+ * Raise a :exc:`TypeError` if *value* has not the proper type.
- If non-zero, enable the :ref:`Python UTF-8 Mode <utf8-mode>`.
+ The caller must hold the GIL. The function cannot be called before
+ Python initialization nor after Python finalization.
- Set to ``0`` or ``1`` by the :option:`-X utf8 <-X>` command line option
- and the :envvar:`PYTHONUTF8` environment variable.
+ .. versionadded:: 3.14
- Also set to ``1`` if the ``LC_CTYPE`` locale is ``C`` or ``POSIX``.
- Default: ``-1`` in Python config and ``0`` in isolated config.
+.. _pyconfig_api:
+PyConfig C API
+==============
-.. _c-preinit:
+.. versionadded:: 3.8
-Preinitialize Python with PyPreConfig
--------------------------------------
+Python can be initialized with :c:func:`Py_InitializeFromConfig` and the
+:c:type:`PyConfig` structure. It can be preinitialized with
+:c:func:`Py_PreInitialize` and the :c:type:`PyPreConfig` structure.
-The preinitialization of Python:
+There are two kinds of configuration:
-* Set the Python memory allocators (:c:member:`PyPreConfig.allocator`)
-* Configure the LC_CTYPE locale (:term:`locale encoding`)
-* Set the :ref:`Python UTF-8 Mode <utf8-mode>`
- (:c:member:`PyPreConfig.utf8_mode`)
+* The :ref:`Python Configuration <init-python-config>` can be used to build a
+ customized Python which behaves as the regular Python. For example,
+ environment variables and command line arguments are used to configure
+ Python.
-The current preconfiguration (``PyPreConfig`` type) is stored in
-``_PyRuntime.preconfig``.
+* The :ref:`Isolated Configuration <init-isolated-conf>` can be used to embed
+ Python into an application. It isolates Python from the system. For example,
+ environment variables are ignored, the LC_CTYPE locale is left unchanged and
+ no signal handler is registered.
-Functions to preinitialize Python:
+The :c:func:`Py_RunMain` function can be used to write a customized Python
+program.
-.. c:function:: PyStatus Py_PreInitialize(const PyPreConfig *preconfig)
+See also :ref:`Initialization, Finalization, and Threads <initialization>`.
- Preinitialize Python from *preconfig* preconfiguration.
+.. seealso::
+ :pep:`587` "Python Initialization Configuration".
- *preconfig* must not be ``NULL``.
-.. c:function:: PyStatus Py_PreInitializeFromBytesArgs(const PyPreConfig *preconfig, int argc, char * const *argv)
+Example
+-------
- Preinitialize Python from *preconfig* preconfiguration.
+Example of customized Python always running in isolated mode::
- Parse *argv* command line arguments (bytes strings) if
- :c:member:`~PyPreConfig.parse_argv` of *preconfig* is non-zero.
+ int main(int argc, char **argv)
+ {
+ PyStatus status;
- *preconfig* must not be ``NULL``.
+ PyConfig config;
+ PyConfig_InitPythonConfig(&config);
+ config.isolated = 1;
-.. c:function:: PyStatus Py_PreInitializeFromArgs(const PyPreConfig *preconfig, int argc, wchar_t * const * argv)
+ /* Decode command line arguments.
+ Implicitly preinitialize Python (in isolated mode). */
+ status = PyConfig_SetBytesArgv(&config, argc, argv);
+ if (PyStatus_Exception(status)) {
+ goto exception;
+ }
- Preinitialize Python from *preconfig* preconfiguration.
+ status = Py_InitializeFromConfig(&config);
+ if (PyStatus_Exception(status)) {
+ goto exception;
+ }
+ PyConfig_Clear(&config);
- Parse *argv* command line arguments (wide strings) if
- :c:member:`~PyPreConfig.parse_argv` of *preconfig* is non-zero.
+ return Py_RunMain();
- *preconfig* must not be ``NULL``.
+ exception:
+ PyConfig_Clear(&config);
+ if (PyStatus_IsExit(status)) {
+ return status.exitcode;
+ }
+ /* Display the error message and exit the process with
+ non-zero exit code */
+ Py_ExitStatusException(status);
+ }
-The caller is responsible to handle exceptions (error or exit) using
-:c:func:`PyStatus_Exception` and :c:func:`Py_ExitStatusException`.
-For :ref:`Python Configuration <init-python-config>`
-(:c:func:`PyPreConfig_InitPythonConfig`), if Python is initialized with
-command line arguments, the command line arguments must also be passed to
-preinitialize Python, since they have an effect on the pre-configuration
-like encodings. For example, the :option:`-X utf8 <-X>` command line option
-enables the :ref:`Python UTF-8 Mode <utf8-mode>`.
+PyWideStringList
+----------------
-``PyMem_SetAllocator()`` can be called after :c:func:`Py_PreInitialize` and
-before :c:func:`Py_InitializeFromConfig` to install a custom memory allocator.
-It can be called before :c:func:`Py_PreInitialize` if
-:c:member:`PyPreConfig.allocator` is set to ``PYMEM_ALLOCATOR_NOT_SET``.
+.. c:type:: PyWideStringList
-Python memory allocation functions like :c:func:`PyMem_RawMalloc` must not be
-used before the Python preinitialization, whereas calling directly ``malloc()``
-and ``free()`` is always safe. :c:func:`Py_DecodeLocale` must not be called
-before the Python preinitialization.
+ List of ``wchar_t*`` strings.
-Example using the preinitialization to enable
-the :ref:`Python UTF-8 Mode <utf8-mode>`::
+ If *length* is non-zero, *items* must be non-``NULL`` and all strings must be
+ non-``NULL``.
- PyStatus status;
- PyPreConfig preconfig;
- PyPreConfig_InitPythonConfig(&preconfig);
+ .. c:namespace:: NULL
- preconfig.utf8_mode = 1;
+ Methods:
- status = Py_PreInitialize(&preconfig);
- if (PyStatus_Exception(status)) {
- Py_ExitStatusException(status);
- }
+ .. c:function:: PyStatus PyWideStringList_Append(PyWideStringList *list, const wchar_t *item)
- /* at this point, Python speaks UTF-8 */
+ Append *item* to *list*.
- Py_Initialize();
- /* ... use Python API here ... */
- Py_Finalize();
+ Python must be preinitialized to call this function.
+ .. c:function:: PyStatus PyWideStringList_Insert(PyWideStringList *list, Py_ssize_t index, const wchar_t *item)
-PyConfig
---------
+ Insert *item* into *list* at *index*.
-.. c:type:: PyConfig
+ If *index* is greater than or equal to *list* length, append *item* to
+ *list*.
- Structure containing most parameters to configure Python.
+ *index* must be greater than or equal to ``0``.
- When done, the :c:func:`PyConfig_Clear` function must be used to release the
- configuration memory.
+ Python must be preinitialized to call this function.
- .. c:namespace:: NULL
+ .. c:namespace:: PyWideStringList
- Structure methods:
+ Structure fields:
- .. c:function:: void PyConfig_InitPythonConfig(PyConfig *config)
+ .. c:member:: Py_ssize_t length
- Initialize configuration with the :ref:`Python Configuration
- <init-python-config>`.
+ List length.
- .. c:function:: void PyConfig_InitIsolatedConfig(PyConfig *config)
+ .. c:member:: wchar_t** items
- Initialize configuration with the :ref:`Isolated Configuration
- <init-isolated-conf>`.
+ List items.
- .. c:function:: PyStatus PyConfig_SetString(PyConfig *config, wchar_t * const *config_str, const wchar_t *str)
+PyStatus
+--------
- Copy the wide character string *str* into ``*config_str``.
+.. c:type:: PyStatus
- :ref:`Preinitialize Python <c-preinit>` if needed.
+ Structure to store an initialization function status: success, error
+ or exit.
- .. c:function:: PyStatus PyConfig_SetBytesString(PyConfig *config, wchar_t * const *config_str, const char *str)
+ For an error, it can store the C function name which created the error.
- Decode *str* using :c:func:`Py_DecodeLocale` and set the result into
- ``*config_str``.
+ Structure fields:
- :ref:`Preinitialize Python <c-preinit>` if needed.
+ .. c:member:: int exitcode
- .. c:function:: PyStatus PyConfig_SetArgv(PyConfig *config, int argc, wchar_t * const *argv)
+ Exit code. Argument passed to ``exit()``.
- Set command line arguments (:c:member:`~PyConfig.argv` member of
- *config*) from the *argv* list of wide character strings.
+ .. c:member:: const char *err_msg
- :ref:`Preinitialize Python <c-preinit>` if needed.
+ Error message.
- .. c:function:: PyStatus PyConfig_SetBytesArgv(PyConfig *config, int argc, char * const *argv)
+ .. c:member:: const char *func
- Set command line arguments (:c:member:`~PyConfig.argv` member of
- *config*) from the *argv* list of bytes strings. Decode bytes using
- :c:func:`Py_DecodeLocale`.
+ Name of the function which created an error, can be ``NULL``.
- :ref:`Preinitialize Python <c-preinit>` if needed.
+ .. c:namespace:: NULL
- .. c:function:: PyStatus PyConfig_SetWideStringList(PyConfig *config, PyWideStringList *list, Py_ssize_t length, wchar_t **items)
+ Functions to create a status:
- Set the list of wide strings *list* to *length* and *items*.
+ .. c:function:: PyStatus PyStatus_Ok(void)
- :ref:`Preinitialize Python <c-preinit>` if needed.
+ Success.
- .. c:function:: PyStatus PyConfig_Read(PyConfig *config)
+ .. c:function:: PyStatus PyStatus_Error(const char *err_msg)
- Read all Python configuration.
+ Initialization error with a message.
- Fields which are already initialized are left unchanged.
+ *err_msg* must not be ``NULL``.
- Fields for :ref:`path configuration <init-path-config>` are no longer
- calculated or modified when calling this function, as of Python 3.11.
+ .. c:function:: PyStatus PyStatus_NoMemory(void)
- The :c:func:`PyConfig_Read` function only parses
- :c:member:`PyConfig.argv` arguments once: :c:member:`PyConfig.parse_argv`
- is set to ``2`` after arguments are parsed. Since Python arguments are
- stripped from :c:member:`PyConfig.argv`, parsing arguments twice would
- parse the application options as Python options.
+ Memory allocation failure (out of memory).
- :ref:`Preinitialize Python <c-preinit>` if needed.
+ .. c:function:: PyStatus PyStatus_Exit(int exitcode)
- .. versionchanged:: 3.10
- The :c:member:`PyConfig.argv` arguments are now only parsed once,
- :c:member:`PyConfig.parse_argv` is set to ``2`` after arguments are
- parsed, and arguments are only parsed if
- :c:member:`PyConfig.parse_argv` equals ``1``.
+ Exit Python with the specified exit code.
- .. versionchanged:: 3.11
- :c:func:`PyConfig_Read` no longer calculates all paths, and so fields
- listed under :ref:`Python Path Configuration <init-path-config>` may
- no longer be updated until :c:func:`Py_InitializeFromConfig` is
- called.
+ Functions to handle a status:
- .. c:function:: void PyConfig_Clear(PyConfig *config)
+ .. c:function:: int PyStatus_Exception(PyStatus status)
- Release configuration memory.
+ Is the status an error or an exit? If true, the exception must be
+ handled; by calling :c:func:`Py_ExitStatusException` for example.
- Most ``PyConfig`` methods :ref:`preinitialize Python <c-preinit>` if needed.
- In that case, the Python preinitialization configuration
- (:c:type:`PyPreConfig`) in based on the :c:type:`PyConfig`. If configuration
- fields which are in common with :c:type:`PyPreConfig` are tuned, they must
- be set before calling a :c:type:`PyConfig` method:
+ .. c:function:: int PyStatus_IsError(PyStatus status)
- * :c:member:`PyConfig.dev_mode`
- * :c:member:`PyConfig.isolated`
- * :c:member:`PyConfig.parse_argv`
- * :c:member:`PyConfig.use_environment`
+ Is the result an error?
- Moreover, if :c:func:`PyConfig_SetArgv` or :c:func:`PyConfig_SetBytesArgv`
- is used, this method must be called before other methods, since the
- preinitialization configuration depends on command line arguments (if
- :c:member:`~PyConfig.parse_argv` is non-zero).
+ .. c:function:: int PyStatus_IsExit(PyStatus status)
- The caller of these methods is responsible to handle exceptions (error or
- exit) using ``PyStatus_Exception()`` and ``Py_ExitStatusException()``.
+ Is the result an exit?
- .. c:namespace:: PyConfig
+ .. c:function:: void Py_ExitStatusException(PyStatus status)
- Structure fields:
+ Call ``exit(exitcode)`` if *status* is an exit. Print the error
+ message and exit with a non-zero exit code if *status* is an error. Must
+ only be called if ``PyStatus_Exception(status)`` is non-zero.
- .. c:member:: PyWideStringList argv
+.. note::
+ Internally, Python uses macros which set ``PyStatus.func``,
+ whereas functions to create a status set ``func`` to ``NULL``.
- .. index::
- single: main()
- single: argv (in module sys)
+Example::
- Set :data:`sys.argv` command line arguments based on
- :c:member:`~PyConfig.argv`. These parameters are similar to those passed
- to the program's :c:func:`main` function with the difference that the
- first entry should refer to the script file to be executed rather than
- the executable hosting the Python interpreter. If there isn't a script
- that will be run, the first entry in :c:member:`~PyConfig.argv` can be an
- empty string.
+ PyStatus alloc(void **ptr, size_t size)
+ {
+ *ptr = PyMem_RawMalloc(size);
+ if (*ptr == NULL) {
+ return PyStatus_NoMemory();
+ }
+ return PyStatus_Ok();
+ }
- Set :c:member:`~PyConfig.parse_argv` to ``1`` to parse
- :c:member:`~PyConfig.argv` the same way the regular Python parses Python
- command line arguments and then to strip Python arguments from
- :c:member:`~PyConfig.argv`.
+ int main(int argc, char **argv)
+ {
+ void *ptr;
+ PyStatus status = alloc(&ptr, 16);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
+ PyMem_Free(ptr);
+ return 0;
+ }
- If :c:member:`~PyConfig.argv` is empty, an empty string is added to
- ensure that :data:`sys.argv` always exists and is never empty.
- Default: ``NULL``.
+PyPreConfig
+-----------
- See also the :c:member:`~PyConfig.orig_argv` member.
+.. c:type:: PyPreConfig
- .. c:member:: int safe_path
+ Structure used to preinitialize Python.
- If equals to zero, ``Py_RunMain()`` prepends a potentially unsafe path to
- :data:`sys.path` at startup:
+ .. c:namespace:: NULL
- * If :c:member:`argv[0] <PyConfig.argv>` is equal to ``L"-m"``
- (``python -m module``), prepend the current working directory.
- * If running a script (``python script.py``), prepend the script's
- directory. If it's a symbolic link, resolve symbolic links.
- * Otherwise (``python -c code`` and ``python``), prepend an empty string,
- which means the current working directory.
+ Function to initialize a preconfiguration:
- Set to ``1`` by the :option:`-P` command line option and the
- :envvar:`PYTHONSAFEPATH` environment variable.
+ .. c:function:: void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig)
- Default: ``0`` in Python config, ``1`` in isolated config.
+ Initialize the preconfiguration with :ref:`Python Configuration
+ <init-python-config>`.
- .. versionadded:: 3.11
+ .. c:function:: void PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig)
- .. c:member:: wchar_t* base_exec_prefix
+ Initialize the preconfiguration with :ref:`Isolated Configuration
+ <init-isolated-conf>`.
- :data:`sys.base_exec_prefix`.
+ .. c:namespace:: PyPreConfig
- Default: ``NULL``.
+ Structure fields:
- Part of the :ref:`Python Path Configuration <init-path-config>` output.
+ .. c:member:: int allocator
- See also :c:member:`PyConfig.exec_prefix`.
+ Name of the Python memory allocators:
- .. c:member:: wchar_t* base_executable
+ * ``PYMEM_ALLOCATOR_NOT_SET`` (``0``): don't change memory allocators
+ (use defaults).
+ * ``PYMEM_ALLOCATOR_DEFAULT`` (``1``): :ref:`default memory allocators
+ <default-memory-allocators>`.
+ * ``PYMEM_ALLOCATOR_DEBUG`` (``2``): :ref:`default memory allocators
+ <default-memory-allocators>` with :ref:`debug hooks
+ <pymem-debug-hooks>`.
+ * ``PYMEM_ALLOCATOR_MALLOC`` (``3``): use ``malloc()`` of the C library.
+ * ``PYMEM_ALLOCATOR_MALLOC_DEBUG`` (``4``): force usage of
+ ``malloc()`` with :ref:`debug hooks <pymem-debug-hooks>`.
+ * ``PYMEM_ALLOCATOR_PYMALLOC`` (``5``): :ref:`Python pymalloc memory
+ allocator <pymalloc>`.
+ * ``PYMEM_ALLOCATOR_PYMALLOC_DEBUG`` (``6``): :ref:`Python pymalloc
+ memory allocator <pymalloc>` with :ref:`debug hooks
+ <pymem-debug-hooks>`.
+ * ``PYMEM_ALLOCATOR_MIMALLOC`` (``6``): use ``mimalloc``, a fast
+ malloc replacement.
+ * ``PYMEM_ALLOCATOR_MIMALLOC_DEBUG`` (``7``): use ``mimalloc``, a fast
+ malloc replacement with :ref:`debug hooks <pymem-debug-hooks>`.
- Python base executable: :data:`sys._base_executable`.
- Set by the :envvar:`__PYVENV_LAUNCHER__` environment variable.
+ ``PYMEM_ALLOCATOR_PYMALLOC`` and ``PYMEM_ALLOCATOR_PYMALLOC_DEBUG`` are
+ not supported if Python is :option:`configured using --without-pymalloc
+ <--without-pymalloc>`.
- Set from :c:member:`PyConfig.executable` if ``NULL``.
+ ``PYMEM_ALLOCATOR_MIMALLOC`` and ``PYMEM_ALLOCATOR_MIMALLOC_DEBUG`` are
+ not supported if Python is :option:`configured using --without-mimalloc
+ <--without-mimalloc>` or if the underlying atomic support isn't
+ available.
- Default: ``NULL``.
+ See :ref:`Memory Management <memory>`.
- Part of the :ref:`Python Path Configuration <init-path-config>` output.
+ Default: ``PYMEM_ALLOCATOR_NOT_SET``.
- See also :c:member:`PyConfig.executable`.
+ .. c:member:: int configure_locale
- .. c:member:: wchar_t* base_prefix
+ Set the LC_CTYPE locale to the user preferred locale.
- :data:`sys.base_prefix`.
+ If equals to ``0``, set :c:member:`~PyPreConfig.coerce_c_locale` and
+ :c:member:`~PyPreConfig.coerce_c_locale_warn` members to ``0``.
- Default: ``NULL``.
+ See the :term:`locale encoding`.
- Part of the :ref:`Python Path Configuration <init-path-config>` output.
+ Default: ``1`` in Python config, ``0`` in isolated config.
- See also :c:member:`PyConfig.prefix`.
+ .. c:member:: int coerce_c_locale
- .. c:member:: int buffered_stdio
+ If equals to ``2``, coerce the C locale.
- If equals to ``0`` and :c:member:`~PyConfig.configure_c_stdio` is non-zero,
- disable buffering on the C streams stdout and stderr.
+ If equals to ``1``, read the LC_CTYPE locale to decide if it should be
+ coerced.
- Set to ``0`` by the :option:`-u` command line option and the
- :envvar:`PYTHONUNBUFFERED` environment variable.
+ See the :term:`locale encoding`.
- stdin is always opened in buffered mode.
+ Default: ``-1`` in Python config, ``0`` in isolated config.
- Default: ``1``.
+ .. c:member:: int coerce_c_locale_warn
- .. c:member:: int bytes_warning
+ If non-zero, emit a warning if the C locale is coerced.
- If equals to ``1``, issue a warning when comparing :class:`bytes` or
- :class:`bytearray` with :class:`str`, or comparing :class:`bytes` with
- :class:`int`.
-
- If equal or greater to ``2``, raise a :exc:`BytesWarning` exception in these
- cases.
-
- Incremented by the :option:`-b` command line option.
+ Default: ``-1`` in Python config, ``0`` in isolated config.
- Default: ``0``.
+ .. c:member:: int dev_mode
- .. c:member:: int warn_default_encoding
+ :ref:`Python Development Mode <devmode>`: see
+ :c:member:`PyConfig.dev_mode`.
- If non-zero, emit a :exc:`EncodingWarning` warning when :class:`io.TextIOWrapper`
- uses its default encoding. See :ref:`io-encoding-warning` for details.
+ Default: ``-1`` in Python mode, ``0`` in isolated mode.
- Default: ``0``.
+ .. c:member:: int isolated
- .. versionadded:: 3.10
+ Isolated mode: see :c:member:`PyConfig.isolated`.
- .. c:member:: int code_debug_ranges
+ Default: ``0`` in Python mode, ``1`` in isolated mode.
- If equals to ``0``, disables the inclusion of the end line and column
- mappings in code objects. Also disables traceback printing carets to
- specific error locations.
+ .. c:member:: int legacy_windows_fs_encoding
- Set to ``0`` by the :envvar:`PYTHONNODEBUGRANGES` environment variable
- and by the :option:`-X no_debug_ranges <-X>` command line option.
+ If non-zero:
- Default: ``1``.
+ * Set :c:member:`PyPreConfig.utf8_mode` to ``0``,
+ * Set :c:member:`PyConfig.filesystem_encoding` to ``"mbcs"``,
+ * Set :c:member:`PyConfig.filesystem_errors` to ``"replace"``.
- .. versionadded:: 3.11
+ Initialized from the :envvar:`PYTHONLEGACYWINDOWSFSENCODING` environment
+ variable value.
- .. c:member:: wchar_t* check_hash_pycs_mode
+ Only available on Windows. ``#ifdef MS_WINDOWS`` macro can be used for
+ Windows specific code.
- Control the validation behavior of hash-based ``.pyc`` files:
- value of the :option:`--check-hash-based-pycs` command line option.
+ Default: ``0``.
- Valid values:
+ .. c:member:: int parse_argv
- - ``L"always"``: Hash the source file for invalidation regardless of
- value of the 'check_source' flag.
- - ``L"never"``: Assume that hash-based pycs always are valid.
- - ``L"default"``: The 'check_source' flag in hash-based pycs
- determines invalidation.
+ If non-zero, :c:func:`Py_PreInitializeFromArgs` and
+ :c:func:`Py_PreInitializeFromBytesArgs` parse their ``argv`` argument the
+ same way the regular Python parses command line arguments: see
+ :ref:`Command Line Arguments <using-on-cmdline>`.
- Default: ``L"default"``.
+ Default: ``1`` in Python config, ``0`` in isolated config.
- See also :pep:`552` "Deterministic pycs".
+ .. c:member:: int use_environment
- .. c:member:: int configure_c_stdio
+ Use :ref:`environment variables <using-on-envvars>`? See
+ :c:member:`PyConfig.use_environment`.
- If non-zero, configure C standard streams:
+ Default: ``1`` in Python config and ``0`` in isolated config.
- * On Windows, set the binary mode (``O_BINARY``) on stdin, stdout and
- stderr.
- * If :c:member:`~PyConfig.buffered_stdio` equals zero, disable buffering
- of stdin, stdout and stderr streams.
- * If :c:member:`~PyConfig.interactive` is non-zero, enable stream
- buffering on stdin and stdout (only stdout on Windows).
+ .. c:member:: int utf8_mode
- Default: ``1`` in Python config, ``0`` in isolated config.
+ If non-zero, enable the :ref:`Python UTF-8 Mode <utf8-mode>`.
- .. c:member:: int dev_mode
+ Set to ``0`` or ``1`` by the :option:`-X utf8 <-X>` command line option
+ and the :envvar:`PYTHONUTF8` environment variable.
- If non-zero, enable the :ref:`Python Development Mode <devmode>`.
+ Also set to ``1`` if the ``LC_CTYPE`` locale is ``C`` or ``POSIX``.
- Set to ``1`` by the :option:`-X dev <-X>` option and the
- :envvar:`PYTHONDEVMODE` environment variable.
+ Default: ``-1`` in Python config and ``0`` in isolated config.
- Default: ``-1`` in Python mode, ``0`` in isolated mode.
- .. c:member:: int dump_refs
+.. _c-preinit:
- Dump Python references?
+Preinitialize Python with PyPreConfig
+-------------------------------------
- If non-zero, dump all objects which are still alive at exit.
+The preinitialization of Python:
- Set to ``1`` by the :envvar:`PYTHONDUMPREFS` environment variable.
+* Set the Python memory allocators (:c:member:`PyPreConfig.allocator`)
+* Configure the LC_CTYPE locale (:term:`locale encoding`)
+* Set the :ref:`Python UTF-8 Mode <utf8-mode>`
+ (:c:member:`PyPreConfig.utf8_mode`)
- Needs a special build of Python with the ``Py_TRACE_REFS`` macro defined:
- see the :option:`configure --with-trace-refs option <--with-trace-refs>`.
+The current preconfiguration (``PyPreConfig`` type) is stored in
+``_PyRuntime.preconfig``.
- Default: ``0``.
+Functions to preinitialize Python:
- .. c:member:: wchar_t* exec_prefix
+.. c:function:: PyStatus Py_PreInitialize(const PyPreConfig *preconfig)
- The site-specific directory prefix where the platform-dependent Python
- files are installed: :data:`sys.exec_prefix`.
+ Preinitialize Python from *preconfig* preconfiguration.
- Default: ``NULL``.
+ *preconfig* must not be ``NULL``.
- Part of the :ref:`Python Path Configuration <init-path-config>` output.
+.. c:function:: PyStatus Py_PreInitializeFromBytesArgs(const PyPreConfig *preconfig, int argc, char * const *argv)
- See also :c:member:`PyConfig.base_exec_prefix`.
+ Preinitialize Python from *preconfig* preconfiguration.
- .. c:member:: wchar_t* executable
+ Parse *argv* command line arguments (bytes strings) if
+ :c:member:`~PyPreConfig.parse_argv` of *preconfig* is non-zero.
- The absolute path of the executable binary for the Python interpreter:
- :data:`sys.executable`.
+ *preconfig* must not be ``NULL``.
- Default: ``NULL``.
+.. c:function:: PyStatus Py_PreInitializeFromArgs(const PyPreConfig *preconfig, int argc, wchar_t * const * argv)
- Part of the :ref:`Python Path Configuration <init-path-config>` output.
+ Preinitialize Python from *preconfig* preconfiguration.
- See also :c:member:`PyConfig.base_executable`.
+ Parse *argv* command line arguments (wide strings) if
+ :c:member:`~PyPreConfig.parse_argv` of *preconfig* is non-zero.
- .. c:member:: int faulthandler
+ *preconfig* must not be ``NULL``.
- Enable faulthandler?
+The caller is responsible to handle exceptions (error or exit) using
+:c:func:`PyStatus_Exception` and :c:func:`Py_ExitStatusException`.
- If non-zero, call :func:`faulthandler.enable` at startup.
+For :ref:`Python Configuration <init-python-config>`
+(:c:func:`PyPreConfig_InitPythonConfig`), if Python is initialized with
+command line arguments, the command line arguments must also be passed to
+preinitialize Python, since they have an effect on the pre-configuration
+like encodings. For example, the :option:`-X utf8 <-X>` command line option
+enables the :ref:`Python UTF-8 Mode <utf8-mode>`.
- Set to ``1`` by :option:`-X faulthandler <-X>` and the
- :envvar:`PYTHONFAULTHANDLER` environment variable.
+``PyMem_SetAllocator()`` can be called after :c:func:`Py_PreInitialize` and
+before :c:func:`Py_InitializeFromConfig` to install a custom memory allocator.
+It can be called before :c:func:`Py_PreInitialize` if
+:c:member:`PyPreConfig.allocator` is set to ``PYMEM_ALLOCATOR_NOT_SET``.
- Default: ``-1`` in Python mode, ``0`` in isolated mode.
+Python memory allocation functions like :c:func:`PyMem_RawMalloc` must not be
+used before the Python preinitialization, whereas calling directly ``malloc()``
+and ``free()`` is always safe. :c:func:`Py_DecodeLocale` must not be called
+before the Python preinitialization.
- .. c:member:: wchar_t* filesystem_encoding
+Example using the preinitialization to enable
+the :ref:`Python UTF-8 Mode <utf8-mode>`::
- :term:`Filesystem encoding <filesystem encoding and error handler>`:
- :func:`sys.getfilesystemencoding`.
+ PyStatus status;
+ PyPreConfig preconfig;
+ PyPreConfig_InitPythonConfig(&preconfig);
- On macOS, Android and VxWorks: use ``"utf-8"`` by default.
+ preconfig.utf8_mode = 1;
- On Windows: use ``"utf-8"`` by default, or ``"mbcs"`` if
- :c:member:`~PyPreConfig.legacy_windows_fs_encoding` of
- :c:type:`PyPreConfig` is non-zero.
+ status = Py_PreInitialize(&preconfig);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ }
- Default encoding on other platforms:
+ /* at this point, Python speaks UTF-8 */
- * ``"utf-8"`` if :c:member:`PyPreConfig.utf8_mode` is non-zero.
- * ``"ascii"`` if Python detects that ``nl_langinfo(CODESET)`` announces
- the ASCII encoding, whereas the ``mbstowcs()`` function
- decodes from a different encoding (usually Latin1).
- * ``"utf-8"`` if ``nl_langinfo(CODESET)`` returns an empty string.
- * Otherwise, use the :term:`locale encoding`:
- ``nl_langinfo(CODESET)`` result.
+ Py_Initialize();
+ /* ... use Python API here ... */
+ Py_Finalize();
- At Python startup, the encoding name is normalized to the Python codec
- name. For example, ``"ANSI_X3.4-1968"`` is replaced with ``"ascii"``.
- See also the :c:member:`~PyConfig.filesystem_errors` member.
+PyConfig
+--------
- .. c:member:: wchar_t* filesystem_errors
+.. c:type:: PyConfig
- :term:`Filesystem error handler <filesystem encoding and error handler>`:
- :func:`sys.getfilesystemencodeerrors`.
+ Structure containing most parameters to configure Python.
- On Windows: use ``"surrogatepass"`` by default, or ``"replace"`` if
- :c:member:`~PyPreConfig.legacy_windows_fs_encoding` of
- :c:type:`PyPreConfig` is non-zero.
+ When done, the :c:func:`PyConfig_Clear` function must be used to release the
+ configuration memory.
- On other platforms: use ``"surrogateescape"`` by default.
+ .. c:namespace:: NULL
- Supported error handlers:
+ Structure methods:
- * ``"strict"``
- * ``"surrogateescape"``
- * ``"surrogatepass"`` (only supported with the UTF-8 encoding)
+ .. c:function:: void PyConfig_InitPythonConfig(PyConfig *config)
- See also the :c:member:`~PyConfig.filesystem_encoding` member.
+ Initialize configuration with the :ref:`Python Configuration
+ <init-python-config>`.
- .. c:member:: unsigned long hash_seed
- .. c:member:: int use_hash_seed
+ .. c:function:: void PyConfig_InitIsolatedConfig(PyConfig *config)
- Randomized hash function seed.
+ Initialize configuration with the :ref:`Isolated Configuration
+ <init-isolated-conf>`.
- If :c:member:`~PyConfig.use_hash_seed` is zero, a seed is chosen randomly
- at Python startup, and :c:member:`~PyConfig.hash_seed` is ignored.
+ .. c:function:: PyStatus PyConfig_SetString(PyConfig *config, wchar_t * const *config_str, const wchar_t *str)
- Set by the :envvar:`PYTHONHASHSEED` environment variable.
+ Copy the wide character string *str* into ``*config_str``.
- Default *use_hash_seed* value: ``-1`` in Python mode, ``0`` in isolated
- mode.
+ :ref:`Preinitialize Python <c-preinit>` if needed.
- .. c:member:: wchar_t* home
+ .. c:function:: PyStatus PyConfig_SetBytesString(PyConfig *config, wchar_t * const *config_str, const char *str)
- Set the default Python "home" directory, that is, the location of the
- standard Python libraries (see :envvar:`PYTHONHOME`).
+ Decode *str* using :c:func:`Py_DecodeLocale` and set the result into
+ ``*config_str``.
- Set by the :envvar:`PYTHONHOME` environment variable.
+ :ref:`Preinitialize Python <c-preinit>` if needed.
- Default: ``NULL``.
+ .. c:function:: PyStatus PyConfig_SetArgv(PyConfig *config, int argc, wchar_t * const *argv)
- Part of the :ref:`Python Path Configuration <init-path-config>` input.
+ Set command line arguments (:c:member:`~PyConfig.argv` member of
+ *config*) from the *argv* list of wide character strings.
- .. c:member:: int import_time
+ :ref:`Preinitialize Python <c-preinit>` if needed.
- If non-zero, profile import time.
+ .. c:function:: PyStatus PyConfig_SetBytesArgv(PyConfig *config, int argc, char * const *argv)
- Set the ``1`` by the :option:`-X importtime <-X>` option and the
- :envvar:`PYTHONPROFILEIMPORTTIME` environment variable.
+ Set command line arguments (:c:member:`~PyConfig.argv` member of
+ *config*) from the *argv* list of bytes strings. Decode bytes using
+ :c:func:`Py_DecodeLocale`.
- Default: ``0``.
+ :ref:`Preinitialize Python <c-preinit>` if needed.
- .. c:member:: int inspect
+ .. c:function:: PyStatus PyConfig_SetWideStringList(PyConfig *config, PyWideStringList *list, Py_ssize_t length, wchar_t **items)
- Enter interactive mode after executing a script or a command.
+ Set the list of wide strings *list* to *length* and *items*.
- If greater than ``0``, enable inspect: when a script is passed as first
- argument or the -c option is used, enter interactive mode after executing
- the script or the command, even when :data:`sys.stdin` does not appear to
- be a terminal.
+ :ref:`Preinitialize Python <c-preinit>` if needed.
- Incremented by the :option:`-i` command line option. Set to ``1`` if the
- :envvar:`PYTHONINSPECT` environment variable is non-empty.
+ .. c:function:: PyStatus PyConfig_Read(PyConfig *config)
- Default: ``0``.
+ Read all Python configuration.
- .. c:member:: int install_signal_handlers
+ Fields which are already initialized are left unchanged.
- Install Python signal handlers?
+ Fields for :ref:`path configuration <init-path-config>` are no longer
+ calculated or modified when calling this function, as of Python 3.11.
- Default: ``1`` in Python mode, ``0`` in isolated mode.
-
- .. c:member:: int interactive
-
- If greater than ``0``, enable the interactive mode (REPL).
-
- Incremented by the :option:`-i` command line option.
+ The :c:func:`PyConfig_Read` function only parses
+ :c:member:`PyConfig.argv` arguments once: :c:member:`PyConfig.parse_argv`
+ is set to ``2`` after arguments are parsed. Since Python arguments are
+ stripped from :c:member:`PyConfig.argv`, parsing arguments twice would
+ parse the application options as Python options.
- Default: ``0``.
+ :ref:`Preinitialize Python <c-preinit>` if needed.
- .. c:member:: int int_max_str_digits
+ .. versionchanged:: 3.10
+ The :c:member:`PyConfig.argv` arguments are now only parsed once,
+ :c:member:`PyConfig.parse_argv` is set to ``2`` after arguments are
+ parsed, and arguments are only parsed if
+ :c:member:`PyConfig.parse_argv` equals ``1``.
- Configures the :ref:`integer string conversion length limitation
- <int_max_str_digits>`. An initial value of ``-1`` means the value will
- be taken from the command line or environment or otherwise default to
- 4300 (:data:`sys.int_info.default_max_str_digits`). A value of ``0``
- disables the limitation. Values greater than zero but less than 640
- (:data:`sys.int_info.str_digits_check_threshold`) are unsupported and
- will produce an error.
+ .. versionchanged:: 3.11
+ :c:func:`PyConfig_Read` no longer calculates all paths, and so fields
+ listed under :ref:`Python Path Configuration <init-path-config>` may
+ no longer be updated until :c:func:`Py_InitializeFromConfig` is
+ called.
- Configured by the :option:`-X int_max_str_digits <-X>` command line
- flag or the :envvar:`PYTHONINTMAXSTRDIGITS` environment variable.
+ .. c:function:: void PyConfig_Clear(PyConfig *config)
- Default: ``-1`` in Python mode. 4300
- (:data:`sys.int_info.default_max_str_digits`) in isolated mode.
+ Release configuration memory.
- .. versionadded:: 3.12
+ Most ``PyConfig`` methods :ref:`preinitialize Python <c-preinit>` if needed.
+ In that case, the Python preinitialization configuration
+ (:c:type:`PyPreConfig`) in based on the :c:type:`PyConfig`. If configuration
+ fields which are in common with :c:type:`PyPreConfig` are tuned, they must
+ be set before calling a :c:type:`PyConfig` method:
- .. c:member:: int cpu_count
+ * :c:member:`PyConfig.dev_mode`
+ * :c:member:`PyConfig.isolated`
+ * :c:member:`PyConfig.parse_argv`
+ * :c:member:`PyConfig.use_environment`
- If the value of :c:member:`~PyConfig.cpu_count` is not ``-1`` then it will
- override the return values of :func:`os.cpu_count`,
- :func:`os.process_cpu_count`, and :func:`multiprocessing.cpu_count`.
+ Moreover, if :c:func:`PyConfig_SetArgv` or :c:func:`PyConfig_SetBytesArgv`
+ is used, this method must be called before other methods, since the
+ preinitialization configuration depends on command line arguments (if
+ :c:member:`~PyConfig.parse_argv` is non-zero).
- Configured by the :samp:`-X cpu_count={n|default}` command line
- flag or the :envvar:`PYTHON_CPU_COUNT` environment variable.
+ The caller of these methods is responsible to handle exceptions (error or
+ exit) using ``PyStatus_Exception()`` and ``Py_ExitStatusException()``.
- Default: ``-1``.
+ .. c:namespace:: PyConfig
- .. versionadded:: 3.13
+ Structure fields:
- .. c:member:: int isolated
+ .. c:member:: PyWideStringList argv
- If greater than ``0``, enable isolated mode:
+ .. index::
+ single: main()
+ single: argv (in module sys)
- * Set :c:member:`~PyConfig.safe_path` to ``1``:
- don't prepend a potentially unsafe path to :data:`sys.path` at Python
- startup, such as the current directory, the script's directory or an
- empty string.
- * Set :c:member:`~PyConfig.use_environment` to ``0``: ignore ``PYTHON``
- environment variables.
- * Set :c:member:`~PyConfig.user_site_directory` to ``0``: don't add the user
- site directory to :data:`sys.path`.
- * Python REPL doesn't import :mod:`readline` nor enable default readline
- configuration on interactive prompts.
+ Set :data:`sys.argv` command line arguments based on
+ :c:member:`~PyConfig.argv`. These parameters are similar to those passed
+ to the program's :c:func:`main` function with the difference that the
+ first entry should refer to the script file to be executed rather than
+ the executable hosting the Python interpreter. If there isn't a script
+ that will be run, the first entry in :c:member:`~PyConfig.argv` can be an
+ empty string.
- Set to ``1`` by the :option:`-I` command line option.
+ Set :c:member:`~PyConfig.parse_argv` to ``1`` to parse
+ :c:member:`~PyConfig.argv` the same way the regular Python parses Python
+ command line arguments and then to strip Python arguments from
+ :c:member:`~PyConfig.argv`.
- Default: ``0`` in Python mode, ``1`` in isolated mode.
+ If :c:member:`~PyConfig.argv` is empty, an empty string is added to
+ ensure that :data:`sys.argv` always exists and is never empty.
- See also the :ref:`Isolated Configuration <init-isolated-conf>` and
- :c:member:`PyPreConfig.isolated`.
+ Default: ``NULL``.
- .. c:member:: int legacy_windows_stdio
+ See also the :c:member:`~PyConfig.orig_argv` member.
- If non-zero, use :class:`io.FileIO` instead of
- :class:`!io._WindowsConsoleIO` for :data:`sys.stdin`, :data:`sys.stdout`
- and :data:`sys.stderr`.
+ .. c:member:: int safe_path
- Set to ``1`` if the :envvar:`PYTHONLEGACYWINDOWSSTDIO` environment
- variable is set to a non-empty string.
+ If equals to zero, ``Py_RunMain()`` prepends a potentially unsafe path to
+ :data:`sys.path` at startup:
- Only available on Windows. ``#ifdef MS_WINDOWS`` macro can be used for
- Windows specific code.
+ * If :c:member:`argv[0] <PyConfig.argv>` is equal to ``L"-m"``
+ (``python -m module``), prepend the current working directory.
+ * If running a script (``python script.py``), prepend the script's
+ directory. If it's a symbolic link, resolve symbolic links.
+ * Otherwise (``python -c code`` and ``python``), prepend an empty string,
+ which means the current working directory.
- Default: ``0``.
+ Set to ``1`` by the :option:`-P` command line option and the
+ :envvar:`PYTHONSAFEPATH` environment variable.
- See also the :pep:`528` (Change Windows console encoding to UTF-8).
+ Default: ``0`` in Python config, ``1`` in isolated config.
- .. c:member:: int malloc_stats
+ .. versionadded:: 3.11
- If non-zero, dump statistics on :ref:`Python pymalloc memory allocator
- <pymalloc>` at exit.
+ .. c:member:: wchar_t* base_exec_prefix
- Set to ``1`` by the :envvar:`PYTHONMALLOCSTATS` environment variable.
+ :data:`sys.base_exec_prefix`.
- The option is ignored if Python is :option:`configured using
- the --without-pymalloc option <--without-pymalloc>`.
+ Default: ``NULL``.
- Default: ``0``.
+ Part of the :ref:`Python Path Configuration <init-path-config>` output.
- .. c:member:: wchar_t* platlibdir
+ See also :c:member:`PyConfig.exec_prefix`.
- Platform library directory name: :data:`sys.platlibdir`.
+ .. c:member:: wchar_t* base_executable
- Set by the :envvar:`PYTHONPLATLIBDIR` environment variable.
+ Python base executable: :data:`sys._base_executable`.
- Default: value of the ``PLATLIBDIR`` macro which is set by the
- :option:`configure --with-platlibdir option <--with-platlibdir>`
- (default: ``"lib"``, or ``"DLLs"`` on Windows).
+ Set by the :envvar:`__PYVENV_LAUNCHER__` environment variable.
- Part of the :ref:`Python Path Configuration <init-path-config>` input.
+ Set from :c:member:`PyConfig.executable` if ``NULL``.
- .. versionadded:: 3.9
+ Default: ``NULL``.
- .. versionchanged:: 3.11
- This macro is now used on Windows to locate the standard
- library extension modules, typically under ``DLLs``. However,
- for compatibility, note that this value is ignored for any
- non-standard layouts, including in-tree builds and virtual
- environments.
+ Part of the :ref:`Python Path Configuration <init-path-config>` output.
- .. c:member:: wchar_t* pythonpath_env
+ See also :c:member:`PyConfig.executable`.
- Module search paths (:data:`sys.path`) as a string separated by ``DELIM``
- (:data:`os.pathsep`).
+ .. c:member:: wchar_t* base_prefix
- Set by the :envvar:`PYTHONPATH` environment variable.
+ :data:`sys.base_prefix`.
Default: ``NULL``.
- Part of the :ref:`Python Path Configuration <init-path-config>` input.
-
- .. c:member:: PyWideStringList module_search_paths
- .. c:member:: int module_search_paths_set
+ Part of the :ref:`Python Path Configuration <init-path-config>` output.
- Module search paths: :data:`sys.path`.
+ See also :c:member:`PyConfig.prefix`.
- If :c:member:`~PyConfig.module_search_paths_set` is equal to ``0``,
- :c:func:`Py_InitializeFromConfig` will replace
- :c:member:`~PyConfig.module_search_paths` and sets
- :c:member:`~PyConfig.module_search_paths_set` to ``1``.
+ .. c:member:: int buffered_stdio
- Default: empty list (``module_search_paths``) and ``0``
- (``module_search_paths_set``).
+ If equals to ``0`` and :c:member:`~PyConfig.configure_c_stdio` is non-zero,
+ disable buffering on the C streams stdout and stderr.
- Part of the :ref:`Python Path Configuration <init-path-config>` output.
+ Set to ``0`` by the :option:`-u` command line option and the
+ :envvar:`PYTHONUNBUFFERED` environment variable.
- .. c:member:: int optimization_level
+ stdin is always opened in buffered mode.
- Compilation optimization level:
+ Default: ``1``.
- * ``0``: Peephole optimizer, set ``__debug__`` to ``True``.
- * ``1``: Level 0, remove assertions, set ``__debug__`` to ``False``.
- * ``2``: Level 1, strip docstrings.
+ .. c:member:: int bytes_warning
- Incremented by the :option:`-O` command line option. Set to the
- :envvar:`PYTHONOPTIMIZE` environment variable value.
+ If equals to ``1``, issue a warning when comparing :class:`bytes` or
+ :class:`bytearray` with :class:`str`, or comparing :class:`bytes` with
+ :class:`int`.
- Default: ``0``.
+ If equal or greater to ``2``, raise a :exc:`BytesWarning` exception in these
+ cases.
- .. c:member:: PyWideStringList orig_argv
+ Incremented by the :option:`-b` command line option.
- The list of the original command line arguments passed to the Python
- executable: :data:`sys.orig_argv`.
+ Default: ``0``.
- If :c:member:`~PyConfig.orig_argv` list is empty and
- :c:member:`~PyConfig.argv` is not a list only containing an empty
- string, :c:func:`PyConfig_Read` copies :c:member:`~PyConfig.argv` into
- :c:member:`~PyConfig.orig_argv` before modifying
- :c:member:`~PyConfig.argv` (if :c:member:`~PyConfig.parse_argv` is
- non-zero).
+ .. c:member:: int warn_default_encoding
- See also the :c:member:`~PyConfig.argv` member and the
- :c:func:`Py_GetArgcArgv` function.
+ If non-zero, emit a :exc:`EncodingWarning` warning when :class:`io.TextIOWrapper`
+ uses its default encoding. See :ref:`io-encoding-warning` for details.
- Default: empty list.
+ Default: ``0``.
.. versionadded:: 3.10
- .. c:member:: int parse_argv
+ .. c:member:: int code_debug_ranges
- Parse command line arguments?
+ If equals to ``0``, disables the inclusion of the end line and column
+ mappings in code objects. Also disables traceback printing carets to
+ specific error locations.
- If equals to ``1``, parse :c:member:`~PyConfig.argv` the same way the regular
- Python parses :ref:`command line arguments <using-on-cmdline>`, and strip
- Python arguments from :c:member:`~PyConfig.argv`.
+ Set to ``0`` by the :envvar:`PYTHONNODEBUGRANGES` environment variable
+ and by the :option:`-X no_debug_ranges <-X>` command line option.
- The :c:func:`PyConfig_Read` function only parses
- :c:member:`PyConfig.argv` arguments once: :c:member:`PyConfig.parse_argv`
- is set to ``2`` after arguments are parsed. Since Python arguments are
- stripped from :c:member:`PyConfig.argv`, parsing arguments twice would
- parse the application options as Python options.
+ Default: ``1``.
- Default: ``1`` in Python mode, ``0`` in isolated mode.
+ .. versionadded:: 3.11
- .. versionchanged:: 3.10
- The :c:member:`PyConfig.argv` arguments are now only parsed if
- :c:member:`PyConfig.parse_argv` equals to ``1``.
+ .. c:member:: wchar_t* check_hash_pycs_mode
- .. c:member:: int parser_debug
+ Control the validation behavior of hash-based ``.pyc`` files:
+ value of the :option:`--check-hash-based-pycs` command line option.
- Parser debug mode. If greater than ``0``, turn on parser debugging output (for expert only, depending
- on compilation options).
+ Valid values:
- Incremented by the :option:`-d` command line option. Set to the
- :envvar:`PYTHONDEBUG` environment variable value.
+ - ``L"always"``: Hash the source file for invalidation regardless of
+ value of the 'check_source' flag.
+ - ``L"never"``: Assume that hash-based pycs always are valid.
+ - ``L"default"``: The 'check_source' flag in hash-based pycs
+ determines invalidation.
- Needs a :ref:`debug build of Python <debug-build>` (the ``Py_DEBUG`` macro
- must be defined).
+ Default: ``L"default"``.
- Default: ``0``.
+ See also :pep:`552` "Deterministic pycs".
- .. c:member:: int pathconfig_warnings
-
- If non-zero, calculation of path configuration is allowed to log
- warnings into ``stderr``. If equals to ``0``, suppress these warnings.
-
- Default: ``1`` in Python mode, ``0`` in isolated mode.
-
- Part of the :ref:`Python Path Configuration <init-path-config>` input.
+ .. c:member:: int configure_c_stdio
- .. versionchanged:: 3.11
- Now also applies on Windows.
+ If non-zero, configure C standard streams:
- .. c:member:: wchar_t* prefix
+ * On Windows, set the binary mode (``O_BINARY``) on stdin, stdout and
+ stderr.
+ * If :c:member:`~PyConfig.buffered_stdio` equals zero, disable buffering
+ of stdin, stdout and stderr streams.
+ * If :c:member:`~PyConfig.interactive` is non-zero, enable stream
+ buffering on stdin and stdout (only stdout on Windows).
- The site-specific directory prefix where the platform independent Python
- files are installed: :data:`sys.prefix`.
+ Default: ``1`` in Python config, ``0`` in isolated config.
- Default: ``NULL``.
+ .. c:member:: int dev_mode
- Part of the :ref:`Python Path Configuration <init-path-config>` output.
+ If non-zero, enable the :ref:`Python Development Mode <devmode>`.
- See also :c:member:`PyConfig.base_prefix`.
+ Set to ``1`` by the :option:`-X dev <-X>` option and the
+ :envvar:`PYTHONDEVMODE` environment variable.
- .. c:member:: wchar_t* program_name
+ Default: ``-1`` in Python mode, ``0`` in isolated mode.
- Program name used to initialize :c:member:`~PyConfig.executable` and in
- early error messages during Python initialization.
+ .. c:member:: int dump_refs
- * On macOS, use :envvar:`PYTHONEXECUTABLE` environment variable if set.
- * If the ``WITH_NEXT_FRAMEWORK`` macro is defined, use
- :envvar:`__PYVENV_LAUNCHER__` environment variable if set.
- * Use ``argv[0]`` of :c:member:`~PyConfig.argv` if available and
- non-empty.
- * Otherwise, use ``L"python"`` on Windows, or ``L"python3"`` on other
- platforms.
+ Dump Python references?
- Default: ``NULL``.
+ If non-zero, dump all objects which are still alive at exit.
- Part of the :ref:`Python Path Configuration <init-path-config>` input.
+ Set to ``1`` by the :envvar:`PYTHONDUMPREFS` environment variable.
- .. c:member:: wchar_t* pycache_prefix
+ Needs a special build of Python with the ``Py_TRACE_REFS`` macro defined:
+ see the :option:`configure --with-trace-refs option <--with-trace-refs>`.
- Directory where cached ``.pyc`` files are written:
- :data:`sys.pycache_prefix`.
+ Default: ``0``.
- Set by the :option:`-X pycache_prefix=PATH <-X>` command line option and
- the :envvar:`PYTHONPYCACHEPREFIX` environment variable.
- The command-line option takes precedence.
+ .. c:member:: wchar_t* exec_prefix
- If ``NULL``, :data:`sys.pycache_prefix` is set to ``None``.
+ The site-specific directory prefix where the platform-dependent Python
+ files are installed: :data:`sys.exec_prefix`.
Default: ``NULL``.
- .. c:member:: int quiet
-
- Quiet mode. If greater than ``0``, don't display the copyright and version at
- Python startup in interactive mode.
-
- Incremented by the :option:`-q` command line option.
-
- Default: ``0``.
+ Part of the :ref:`Python Path Configuration <init-path-config>` output.
- .. c:member:: wchar_t* run_command
+ See also :c:member:`PyConfig.base_exec_prefix`.
- Value of the :option:`-c` command line option.
+ .. c:member:: wchar_t* executable
- Used by :c:func:`Py_RunMain`.
+ The absolute path of the executable binary for the Python interpreter:
+ :data:`sys.executable`.
Default: ``NULL``.
- .. c:member:: wchar_t* run_filename
+ Part of the :ref:`Python Path Configuration <init-path-config>` output.
- Filename passed on the command line: trailing command line argument
- without :option:`-c` or :option:`-m`. It is used by the
- :c:func:`Py_RunMain` function.
+ See also :c:member:`PyConfig.base_executable`.
- For example, it is set to ``script.py`` by the ``python3 script.py arg``
- command line.
+ .. c:member:: int faulthandler
- See also the :c:member:`PyConfig.skip_source_first_line` option.
+ Enable faulthandler?
- Default: ``NULL``.
+ If non-zero, call :func:`faulthandler.enable` at startup.
- .. c:member:: wchar_t* run_module
+ Set to ``1`` by :option:`-X faulthandler <-X>` and the
+ :envvar:`PYTHONFAULTHANDLER` environment variable.
- Value of the :option:`-m` command line option.
+ Default: ``-1`` in Python mode, ``0`` in isolated mode.
- Used by :c:func:`Py_RunMain`.
+ .. c:member:: wchar_t* filesystem_encoding
- Default: ``NULL``.
+ :term:`Filesystem encoding <filesystem encoding and error handler>`:
+ :func:`sys.getfilesystemencoding`.
- .. c:member:: wchar_t* run_presite
+ On macOS, Android and VxWorks: use ``"utf-8"`` by default.
- ``package.module`` path to module that should be imported before
- ``site.py`` is run.
+ On Windows: use ``"utf-8"`` by default, or ``"mbcs"`` if
+ :c:member:`~PyPreConfig.legacy_windows_fs_encoding` of
+ :c:type:`PyPreConfig` is non-zero.
- Set by the :option:`-X presite=package.module <-X>` command-line
- option and the :envvar:`PYTHON_PRESITE` environment variable.
- The command-line option takes precedence.
+ Default encoding on other platforms:
- Needs a :ref:`debug build of Python <debug-build>` (the ``Py_DEBUG`` macro
- must be defined).
+ * ``"utf-8"`` if :c:member:`PyPreConfig.utf8_mode` is non-zero.
+ * ``"ascii"`` if Python detects that ``nl_langinfo(CODESET)`` announces
+ the ASCII encoding, whereas the ``mbstowcs()`` function
+ decodes from a different encoding (usually Latin1).
+ * ``"utf-8"`` if ``nl_langinfo(CODESET)`` returns an empty string.
+ * Otherwise, use the :term:`locale encoding`:
+ ``nl_langinfo(CODESET)`` result.
- Default: ``NULL``.
+ At Python startup, the encoding name is normalized to the Python codec
+ name. For example, ``"ANSI_X3.4-1968"`` is replaced with ``"ascii"``.
- .. c:member:: int show_ref_count
+ See also the :c:member:`~PyConfig.filesystem_errors` member.
- Show total reference count at exit (excluding :term:`immortal` objects)?
+ .. c:member:: wchar_t* filesystem_errors
- Set to ``1`` by :option:`-X showrefcount <-X>` command line option.
+ :term:`Filesystem error handler <filesystem encoding and error handler>`:
+ :func:`sys.getfilesystemencodeerrors`.
- Needs a :ref:`debug build of Python <debug-build>` (the ``Py_REF_DEBUG``
- macro must be defined).
+ On Windows: use ``"surrogatepass"`` by default, or ``"replace"`` if
+ :c:member:`~PyPreConfig.legacy_windows_fs_encoding` of
+ :c:type:`PyPreConfig` is non-zero.
- Default: ``0``.
+ On other platforms: use ``"surrogateescape"`` by default.
- .. c:member:: int site_import
+ Supported error handlers:
- Import the :mod:`site` module at startup?
+ * ``"strict"``
+ * ``"surrogateescape"``
+ * ``"surrogatepass"`` (only supported with the UTF-8 encoding)
- If equal to zero, disable the import of the module site and the
- site-dependent manipulations of :data:`sys.path` that it entails.
+ See also the :c:member:`~PyConfig.filesystem_encoding` member.
- Also disable these manipulations if the :mod:`site` module is explicitly
- imported later (call :func:`site.main` if you want them to be triggered).
+ .. c:member:: unsigned long hash_seed
+ .. c:member:: int use_hash_seed
- Set to ``0`` by the :option:`-S` command line option.
+ Randomized hash function seed.
- :data:`sys.flags.no_site <sys.flags>` is set to the inverted value of
- :c:member:`~PyConfig.site_import`.
+ If :c:member:`~PyConfig.use_hash_seed` is zero, a seed is chosen randomly
+ at Python startup, and :c:member:`~PyConfig.hash_seed` is ignored.
- Default: ``1``.
+ Set by the :envvar:`PYTHONHASHSEED` environment variable.
- .. c:member:: int skip_source_first_line
+ Default *use_hash_seed* value: ``-1`` in Python mode, ``0`` in isolated
+ mode.
- If non-zero, skip the first line of the :c:member:`PyConfig.run_filename`
- source.
+ .. c:member:: wchar_t* home
- It allows the usage of non-Unix forms of ``#!cmd``. This is intended for
- a DOS specific hack only.
+ Set the default Python "home" directory, that is, the location of the
+ standard Python libraries (see :envvar:`PYTHONHOME`).
- Set to ``1`` by the :option:`-x` command line option.
+ Set by the :envvar:`PYTHONHOME` environment variable.
- Default: ``0``.
+ Default: ``NULL``.
- .. c:member:: wchar_t* stdio_encoding
- .. c:member:: wchar_t* stdio_errors
+ Part of the :ref:`Python Path Configuration <init-path-config>` input.
- Encoding and encoding errors of :data:`sys.stdin`, :data:`sys.stdout` and
- :data:`sys.stderr` (but :data:`sys.stderr` always uses
- ``"backslashreplace"`` error handler).
+ .. c:member:: int import_time
- Use the :envvar:`PYTHONIOENCODING` environment variable if it is
- non-empty.
+ If non-zero, profile import time.
- Default encoding:
+ Set the ``1`` by the :option:`-X importtime <-X>` option and the
+ :envvar:`PYTHONPROFILEIMPORTTIME` environment variable.
- * ``"UTF-8"`` if :c:member:`PyPreConfig.utf8_mode` is non-zero.
- * Otherwise, use the :term:`locale encoding`.
+ Default: ``0``.
- Default error handler:
+ .. c:member:: int inspect
- * On Windows: use ``"surrogateescape"``.
- * ``"surrogateescape"`` if :c:member:`PyPreConfig.utf8_mode` is non-zero,
- or if the LC_CTYPE locale is "C" or "POSIX".
- * ``"strict"`` otherwise.
+ Enter interactive mode after executing a script or a command.
- See also :c:member:`PyConfig.legacy_windows_stdio`.
+ If greater than ``0``, enable inspect: when a script is passed as first
+ argument or the -c option is used, enter interactive mode after executing
+ the script or the command, even when :data:`sys.stdin` does not appear to
+ be a terminal.
- .. c:member:: int tracemalloc
+ Incremented by the :option:`-i` command line option. Set to ``1`` if the
+ :envvar:`PYTHONINSPECT` environment variable is non-empty.
- Enable tracemalloc?
+ Default: ``0``.
- If non-zero, call :func:`tracemalloc.start` at startup.
+ .. c:member:: int install_signal_handlers
- Set by :option:`-X tracemalloc=N <-X>` command line option and by the
- :envvar:`PYTHONTRACEMALLOC` environment variable.
+ Install Python signal handlers?
- Default: ``-1`` in Python mode, ``0`` in isolated mode.
+ Default: ``1`` in Python mode, ``0`` in isolated mode.
- .. c:member:: int perf_profiling
+ .. c:member:: int interactive
- Enable the Linux ``perf`` profiler support?
+ If greater than ``0``, enable the interactive mode (REPL).
- If equals to ``1``, enable support for the Linux ``perf`` profiler.
+ Incremented by the :option:`-i` command line option.
- If equals to ``2``, enable support for the Linux ``perf`` profiler with
- DWARF JIT support.
+ Default: ``0``.
- Set to ``1`` by :option:`-X perf <-X>` command-line option and the
- :envvar:`PYTHONPERFSUPPORT` environment variable.
+ .. c:member:: int int_max_str_digits
- Set to ``2`` by the :option:`-X perf_jit <-X>` command-line option and
- the :envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable.
+ Configures the :ref:`integer string conversion length limitation
+ <int_max_str_digits>`. An initial value of ``-1`` means the value will
+ be taken from the command line or environment or otherwise default to
+ 4300 (:data:`sys.int_info.default_max_str_digits`). A value of ``0``
+ disables the limitation. Values greater than zero but less than 640
+ (:data:`sys.int_info.str_digits_check_threshold`) are unsupported and
+ will produce an error.
- Default: ``-1``.
+ Configured by the :option:`-X int_max_str_digits <-X>` command line
+ flag or the :envvar:`PYTHONINTMAXSTRDIGITS` environment variable.
- .. seealso::
- See :ref:`perf_profiling` for more information.
+ Default: ``-1`` in Python mode. 4300
+ (:data:`sys.int_info.default_max_str_digits`) in isolated mode.
.. versionadded:: 3.12
- .. c:member:: int use_environment
+ .. c:member:: int cpu_count
- Use :ref:`environment variables <using-on-envvars>`?
+ If the value of :c:member:`~PyConfig.cpu_count` is not ``-1`` then it will
+ override the return values of :func:`os.cpu_count`,
+ :func:`os.process_cpu_count`, and :func:`multiprocessing.cpu_count`.
- If equals to zero, ignore the :ref:`environment variables
- <using-on-envvars>`.
+ Configured by the :samp:`-X cpu_count={n|default}` command line
+ flag or the :envvar:`PYTHON_CPU_COUNT` environment variable.
- Set to ``0`` by the :option:`-E` environment variable.
+ Default: ``-1``.
- Default: ``1`` in Python config and ``0`` in isolated config.
+ .. versionadded:: 3.13
- .. c:member:: int use_system_logger
+ .. c:member:: int isolated
- If non-zero, ``stdout`` and ``stderr`` will be redirected to the system
- log.
+ If greater than ``0``, enable isolated mode:
- Only available on macOS 10.12 and later, and on iOS.
+ * Set :c:member:`~PyConfig.safe_path` to ``1``:
+ don't prepend a potentially unsafe path to :data:`sys.path` at Python
+ startup, such as the current directory, the script's directory or an
+ empty string.
+ * Set :c:member:`~PyConfig.use_environment` to ``0``: ignore ``PYTHON``
+ environment variables.
+ * Set :c:member:`~PyConfig.user_site_directory` to ``0``: don't add the user
+ site directory to :data:`sys.path`.
+ * Python REPL doesn't import :mod:`readline` nor enable default readline
+ configuration on interactive prompts.
- Default: ``0`` (don't use system log).
+ Set to ``1`` by the :option:`-I` command line option.
- .. versionadded:: 3.13.2
+ Default: ``0`` in Python mode, ``1`` in isolated mode.
- .. c:member:: int user_site_directory
+ See also the :ref:`Isolated Configuration <init-isolated-conf>` and
+ :c:member:`PyPreConfig.isolated`.
- If non-zero, add the user site directory to :data:`sys.path`.
+ .. c:member:: int legacy_windows_stdio
- Set to ``0`` by the :option:`-s` and :option:`-I` command line options.
+ If non-zero, use :class:`io.FileIO` instead of
+ :class:`!io._WindowsConsoleIO` for :data:`sys.stdin`, :data:`sys.stdout`
+ and :data:`sys.stderr`.
- Set to ``0`` by the :envvar:`PYTHONNOUSERSITE` environment variable.
+ Set to ``1`` if the :envvar:`PYTHONLEGACYWINDOWSSTDIO` environment
+ variable is set to a non-empty string.
- Default: ``1`` in Python mode, ``0`` in isolated mode.
+ Only available on Windows. ``#ifdef MS_WINDOWS`` macro can be used for
+ Windows specific code.
- .. c:member:: int verbose
+ Default: ``0``.
- Verbose mode. If greater than ``0``, print a message each time a module is
- imported, showing the place (filename or built-in module) from which
- it is loaded.
+ See also the :pep:`528` (Change Windows console encoding to UTF-8).
- If greater than or equal to ``2``, print a message for each file that is
- checked for when searching for a module. Also provides information on
- module cleanup at exit.
+ .. c:member:: int malloc_stats
- Incremented by the :option:`-v` command line option.
+ If non-zero, dump statistics on :ref:`Python pymalloc memory allocator
+ <pymalloc>` at exit.
- Set by the :envvar:`PYTHONVERBOSE` environment variable value.
+ Set to ``1`` by the :envvar:`PYTHONMALLOCSTATS` environment variable.
+
+ The option is ignored if Python is :option:`configured using
+ the --without-pymalloc option <--without-pymalloc>`.
Default: ``0``.
- .. c:member:: PyWideStringList warnoptions
+ .. c:member:: wchar_t* platlibdir
- Options of the :mod:`warnings` module to build warnings filters, lowest
- to highest priority: :data:`sys.warnoptions`.
+ Platform library directory name: :data:`sys.platlibdir`.
- The :mod:`warnings` module adds :data:`sys.warnoptions` in the reverse
- order: the last :c:member:`PyConfig.warnoptions` item becomes the first
- item of :data:`warnings.filters` which is checked first (highest
- priority).
+ Set by the :envvar:`PYTHONPLATLIBDIR` environment variable.
- The :option:`-W` command line options adds its value to
- :c:member:`~PyConfig.warnoptions`, it can be used multiple times.
+ Default: value of the ``PLATLIBDIR`` macro which is set by the
+ :option:`configure --with-platlibdir option <--with-platlibdir>`
+ (default: ``"lib"``, or ``"DLLs"`` on Windows).
- The :envvar:`PYTHONWARNINGS` environment variable can also be used to add
- warning options. Multiple options can be specified, separated by commas
- (``,``).
+ Part of the :ref:`Python Path Configuration <init-path-config>` input.
- Default: empty list.
+ .. versionadded:: 3.9
- .. c:member:: int write_bytecode
+ .. versionchanged:: 3.11
+ This macro is now used on Windows to locate the standard
+ library extension modules, typically under ``DLLs``. However,
+ for compatibility, note that this value is ignored for any
+ non-standard layouts, including in-tree builds and virtual
+ environments.
- If equal to ``0``, Python won't try to write ``.pyc`` files on the import of
- source modules.
+ .. c:member:: wchar_t* pythonpath_env
- Set to ``0`` by the :option:`-B` command line option and the
- :envvar:`PYTHONDONTWRITEBYTECODE` environment variable.
+ Module search paths (:data:`sys.path`) as a string separated by ``DELIM``
+ (:data:`os.pathsep`).
- :data:`sys.dont_write_bytecode` is initialized to the inverted value of
- :c:member:`~PyConfig.write_bytecode`.
+ Set by the :envvar:`PYTHONPATH` environment variable.
- Default: ``1``.
+ Default: ``NULL``.
- .. c:member:: PyWideStringList xoptions
+ Part of the :ref:`Python Path Configuration <init-path-config>` input.
- Values of the :option:`-X` command line options: :data:`sys._xoptions`.
+ .. c:member:: PyWideStringList module_search_paths
+ .. c:member:: int module_search_paths_set
- Default: empty list.
+ Module search paths: :data:`sys.path`.
-If :c:member:`~PyConfig.parse_argv` is non-zero, :c:member:`~PyConfig.argv`
-arguments are parsed the same way the regular Python parses :ref:`command line
-arguments <using-on-cmdline>`, and Python arguments are stripped from
-:c:member:`~PyConfig.argv`.
+ If :c:member:`~PyConfig.module_search_paths_set` is equal to ``0``,
+ :c:func:`Py_InitializeFromConfig` will replace
+ :c:member:`~PyConfig.module_search_paths` and sets
+ :c:member:`~PyConfig.module_search_paths_set` to ``1``.
-The :c:member:`~PyConfig.xoptions` options are parsed to set other options: see
-the :option:`-X` command line option.
+ Default: empty list (``module_search_paths``) and ``0``
+ (``module_search_paths_set``).
-.. versionchanged:: 3.9
+ Part of the :ref:`Python Path Configuration <init-path-config>` output.
- The ``show_alloc_count`` field has been removed.
+ .. c:member:: int optimization_level
+ Compilation optimization level:
-.. _init-from-config:
+ * ``0``: Peephole optimizer, set ``__debug__`` to ``True``.
+ * ``1``: Level 0, remove assertions, set ``__debug__`` to ``False``.
+ * ``2``: Level 1, strip docstrings.
-Initialization with PyConfig
-----------------------------
+ Incremented by the :option:`-O` command line option. Set to the
+ :envvar:`PYTHONOPTIMIZE` environment variable value.
-Initializing the interpreter from a populated configuration struct is handled
-by calling :c:func:`Py_InitializeFromConfig`.
+ Default: ``0``.
-The caller is responsible to handle exceptions (error or exit) using
-:c:func:`PyStatus_Exception` and :c:func:`Py_ExitStatusException`.
+ .. c:member:: PyWideStringList orig_argv
-If :c:func:`PyImport_FrozenModules`, :c:func:`PyImport_AppendInittab` or
-:c:func:`PyImport_ExtendInittab` are used, they must be set or called after
-Python preinitialization and before the Python initialization. If Python is
-initialized multiple times, :c:func:`PyImport_AppendInittab` or
-:c:func:`PyImport_ExtendInittab` must be called before each Python
-initialization.
+ The list of the original command line arguments passed to the Python
+ executable: :data:`sys.orig_argv`.
-The current configuration (``PyConfig`` type) is stored in
-``PyInterpreterState.config``.
+ If :c:member:`~PyConfig.orig_argv` list is empty and
+ :c:member:`~PyConfig.argv` is not a list only containing an empty
+ string, :c:func:`PyConfig_Read` copies :c:member:`~PyConfig.argv` into
+ :c:member:`~PyConfig.orig_argv` before modifying
+ :c:member:`~PyConfig.argv` (if :c:member:`~PyConfig.parse_argv` is
+ non-zero).
-Example setting the program name::
+ See also the :c:member:`~PyConfig.argv` member and the
+ :c:func:`Py_GetArgcArgv` function.
- void init_python(void)
- {
- PyStatus status;
+ Default: empty list.
- PyConfig config;
- PyConfig_InitPythonConfig(&config);
+ .. versionadded:: 3.10
- /* Set the program name. Implicitly preinitialize Python. */
- status = PyConfig_SetString(&config, &config.program_name,
- L"/path/to/my_program");
- if (PyStatus_Exception(status)) {
- goto exception;
- }
+ .. c:member:: int parse_argv
- status = Py_InitializeFromConfig(&config);
- if (PyStatus_Exception(status)) {
- goto exception;
- }
- PyConfig_Clear(&config);
- return;
+ Parse command line arguments?
- exception:
- PyConfig_Clear(&config);
- Py_ExitStatusException(status);
- }
+ If equals to ``1``, parse :c:member:`~PyConfig.argv` the same way the regular
+ Python parses :ref:`command line arguments <using-on-cmdline>`, and strip
+ Python arguments from :c:member:`~PyConfig.argv`.
-More complete example modifying the default configuration, read the
-configuration, and then override some parameters. Note that since
-3.11, many parameters are not calculated until initialization, and
-so values cannot be read from the configuration structure. Any values
-set before initialize is called will be left unchanged by
-initialization::
+ The :c:func:`PyConfig_Read` function only parses
+ :c:member:`PyConfig.argv` arguments once: :c:member:`PyConfig.parse_argv`
+ is set to ``2`` after arguments are parsed. Since Python arguments are
+ stripped from :c:member:`PyConfig.argv`, parsing arguments twice would
+ parse the application options as Python options.
- PyStatus init_python(const char *program_name)
- {
- PyStatus status;
+ Default: ``1`` in Python mode, ``0`` in isolated mode.
- PyConfig config;
- PyConfig_InitPythonConfig(&config);
+ .. versionchanged:: 3.10
+ The :c:member:`PyConfig.argv` arguments are now only parsed if
+ :c:member:`PyConfig.parse_argv` equals to ``1``.
- /* Set the program name before reading the configuration
- (decode byte string from the locale encoding).
+ .. c:member:: int parser_debug
- Implicitly preinitialize Python. */
- status = PyConfig_SetBytesString(&config, &config.program_name,
- program_name);
- if (PyStatus_Exception(status)) {
- goto done;
- }
+ Parser debug mode. If greater than ``0``, turn on parser debugging output (for expert only, depending
+ on compilation options).
- /* Read all configuration at once */
- status = PyConfig_Read(&config);
- if (PyStatus_Exception(status)) {
- goto done;
- }
+ Incremented by the :option:`-d` command line option. Set to the
+ :envvar:`PYTHONDEBUG` environment variable value.
- /* Specify sys.path explicitly */
- /* If you want to modify the default set of paths, finish
- initialization first and then use PySys_GetObject("path") */
- config.module_search_paths_set = 1;
- status = PyWideStringList_Append(&config.module_search_paths,
- L"/path/to/stdlib");
- if (PyStatus_Exception(status)) {
- goto done;
- }
- status = PyWideStringList_Append(&config.module_search_paths,
- L"/path/to/more/modules");
- if (PyStatus_Exception(status)) {
- goto done;
- }
+ Needs a :ref:`debug build of Python <debug-build>` (the ``Py_DEBUG`` macro
+ must be defined).
- /* Override executable computed by PyConfig_Read() */
- status = PyConfig_SetString(&config, &config.executable,
- L"/path/to/my_executable");
- if (PyStatus_Exception(status)) {
- goto done;
- }
+ Default: ``0``.
- status = Py_InitializeFromConfig(&config);
+ .. c:member:: int pathconfig_warnings
- done:
- PyConfig_Clear(&config);
- return status;
- }
+ If non-zero, calculation of path configuration is allowed to log
+ warnings into ``stderr``. If equals to ``0``, suppress these warnings.
+ Default: ``1`` in Python mode, ``0`` in isolated mode.
-.. _init-isolated-conf:
+ Part of the :ref:`Python Path Configuration <init-path-config>` input.
-Isolated Configuration
-----------------------
+ .. versionchanged:: 3.11
+ Now also applies on Windows.
-:c:func:`PyPreConfig_InitIsolatedConfig` and
-:c:func:`PyConfig_InitIsolatedConfig` functions create a configuration to
-isolate Python from the system. For example, to embed Python into an
-application.
+ .. c:member:: wchar_t* prefix
-This configuration ignores global configuration variables, environment
-variables, command line arguments (:c:member:`PyConfig.argv` is not parsed)
-and user site directory. The C standard streams (ex: ``stdout``) and the
-LC_CTYPE locale are left unchanged. Signal handlers are not installed.
-
-Configuration files are still used with this configuration to determine
-paths that are unspecified. Ensure :c:member:`PyConfig.home` is specified
-to avoid computing the default path configuration.
+ The site-specific directory prefix where the platform independent Python
+ files are installed: :data:`sys.prefix`.
+ Default: ``NULL``.
-.. _init-python-config:
+ Part of the :ref:`Python Path Configuration <init-path-config>` output.
-Python Configuration
---------------------
+ See also :c:member:`PyConfig.base_prefix`.
-:c:func:`PyPreConfig_InitPythonConfig` and :c:func:`PyConfig_InitPythonConfig`
-functions create a configuration to build a customized Python which behaves as
-the regular Python.
+ .. c:member:: wchar_t* program_name
-Environments variables and command line arguments are used to configure
-Python, whereas global configuration variables are ignored.
+ Program name used to initialize :c:member:`~PyConfig.executable` and in
+ early error messages during Python initialization.
-This function enables C locale coercion (:pep:`538`)
-and :ref:`Python UTF-8 Mode <utf8-mode>`
-(:pep:`540`) depending on the LC_CTYPE locale, :envvar:`PYTHONUTF8` and
-:envvar:`PYTHONCOERCECLOCALE` environment variables.
+ * On macOS, use :envvar:`PYTHONEXECUTABLE` environment variable if set.
+ * If the ``WITH_NEXT_FRAMEWORK`` macro is defined, use
+ :envvar:`__PYVENV_LAUNCHER__` environment variable if set.
+ * Use ``argv[0]`` of :c:member:`~PyConfig.argv` if available and
+ non-empty.
+ * Otherwise, use ``L"python"`` on Windows, or ``L"python3"`` on other
+ platforms.
+ Default: ``NULL``.
-.. _init-path-config:
+ Part of the :ref:`Python Path Configuration <init-path-config>` input.
-Python Path Configuration
--------------------------
+ .. c:member:: wchar_t* pycache_prefix
-:c:type:`PyConfig` contains multiple fields for the path configuration:
+ Directory where cached ``.pyc`` files are written:
+ :data:`sys.pycache_prefix`.
-* Path configuration inputs:
+ Set by the :option:`-X pycache_prefix=PATH <-X>` command line option and
+ the :envvar:`PYTHONPYCACHEPREFIX` environment variable.
+ The command-line option takes precedence.
- * :c:member:`PyConfig.home`
- * :c:member:`PyConfig.platlibdir`
- * :c:member:`PyConfig.pathconfig_warnings`
- * :c:member:`PyConfig.program_name`
- * :c:member:`PyConfig.pythonpath_env`
- * current working directory: to get absolute paths
- * ``PATH`` environment variable to get the program full path
- (from :c:member:`PyConfig.program_name`)
- * ``__PYVENV_LAUNCHER__`` environment variable
- * (Windows only) Application paths in the registry under
- "Software\Python\PythonCore\X.Y\PythonPath" of HKEY_CURRENT_USER and
- HKEY_LOCAL_MACHINE (where X.Y is the Python version).
+ If ``NULL``, :data:`sys.pycache_prefix` is set to ``None``.
-* Path configuration output fields:
+ Default: ``NULL``.
- * :c:member:`PyConfig.base_exec_prefix`
- * :c:member:`PyConfig.base_executable`
- * :c:member:`PyConfig.base_prefix`
- * :c:member:`PyConfig.exec_prefix`
- * :c:member:`PyConfig.executable`
- * :c:member:`PyConfig.module_search_paths_set`,
- :c:member:`PyConfig.module_search_paths`
- * :c:member:`PyConfig.prefix`
+ .. c:member:: int quiet
-If at least one "output field" is not set, Python calculates the path
-configuration to fill unset fields. If
-:c:member:`~PyConfig.module_search_paths_set` is equal to ``0``,
-:c:member:`~PyConfig.module_search_paths` is overridden and
-:c:member:`~PyConfig.module_search_paths_set` is set to ``1``.
+ Quiet mode. If greater than ``0``, don't display the copyright and version at
+ Python startup in interactive mode.
-It is possible to completely ignore the function calculating the default
-path configuration by setting explicitly all path configuration output
-fields listed above. A string is considered as set even if it is non-empty.
-``module_search_paths`` is considered as set if
-``module_search_paths_set`` is set to ``1``. In this case,
-``module_search_paths`` will be used without modification.
+ Incremented by the :option:`-q` command line option.
-Set :c:member:`~PyConfig.pathconfig_warnings` to ``0`` to suppress warnings when
-calculating the path configuration (Unix only, Windows does not log any warning).
+ Default: ``0``.
-If :c:member:`~PyConfig.base_prefix` or :c:member:`~PyConfig.base_exec_prefix`
-fields are not set, they inherit their value from :c:member:`~PyConfig.prefix`
-and :c:member:`~PyConfig.exec_prefix` respectively.
+ .. c:member:: wchar_t* run_command
-:c:func:`Py_RunMain` and :c:func:`Py_Main` modify :data:`sys.path`:
+ Value of the :option:`-c` command line option.
-* If :c:member:`~PyConfig.run_filename` is set and is a directory which contains a
- ``__main__.py`` script, prepend :c:member:`~PyConfig.run_filename` to
- :data:`sys.path`.
-* If :c:member:`~PyConfig.isolated` is zero:
+ Used by :c:func:`Py_RunMain`.
- * If :c:member:`~PyConfig.run_module` is set, prepend the current directory
- to :data:`sys.path`. Do nothing if the current directory cannot be read.
- * If :c:member:`~PyConfig.run_filename` is set, prepend the directory of the
- filename to :data:`sys.path`.
- * Otherwise, prepend an empty string to :data:`sys.path`.
+ Default: ``NULL``.
-If :c:member:`~PyConfig.site_import` is non-zero, :data:`sys.path` can be
-modified by the :mod:`site` module. If
-:c:member:`~PyConfig.user_site_directory` is non-zero and the user's
-site-package directory exists, the :mod:`site` module appends the user's
-site-package directory to :data:`sys.path`.
+ .. c:member:: wchar_t* run_filename
-The following configuration files are used by the path configuration:
+ Filename passed on the command line: trailing command line argument
+ without :option:`-c` or :option:`-m`. It is used by the
+ :c:func:`Py_RunMain` function.
-* ``pyvenv.cfg``
-* ``._pth`` file (ex: ``python._pth``)
-* ``pybuilddir.txt`` (Unix only)
+ For example, it is set to ``script.py`` by the ``python3 script.py arg``
+ command line.
-If a ``._pth`` file is present:
+ See also the :c:member:`PyConfig.skip_source_first_line` option.
-* Set :c:member:`~PyConfig.isolated` to ``1``.
-* Set :c:member:`~PyConfig.use_environment` to ``0``.
-* Set :c:member:`~PyConfig.site_import` to ``0``.
-* Set :c:member:`~PyConfig.safe_path` to ``1``.
+ Default: ``NULL``.
-If :c:member:`~PyConfig.home` is not set and a ``pyvenv.cfg`` file is present in
-the same directory as :c:member:`~PyConfig.executable`, or its parent,
-:c:member:`~PyConfig.prefix` and :c:member:`~PyConfig.exec_prefix` are set that
-location. When this happens, :c:member:`~PyConfig.base_prefix` and
-:c:member:`~PyConfig.base_exec_prefix` still keep their value, pointing to the
-base installation. See :ref:`sys-path-init-virtual-environments` for more
-information.
+ .. c:member:: wchar_t* run_module
-The ``__PYVENV_LAUNCHER__`` environment variable is used to set
-:c:member:`PyConfig.base_executable`.
+ Value of the :option:`-m` command line option.
-.. versionchanged:: 3.14
+ Used by :c:func:`Py_RunMain`.
- :c:member:`~PyConfig.prefix`, and :c:member:`~PyConfig.exec_prefix`, are now
- set to the ``pyvenv.cfg`` directory. This was previously done by :mod:`site`,
- therefore affected by :option:`-S`.
+ Default: ``NULL``.
-.. _pyinitconfig_api:
+ .. c:member:: wchar_t* run_presite
-PyInitConfig C API
-==================
+ ``package.module`` path to module that should be imported before
+ ``site.py`` is run.
-C API to configure the Python initialization (:pep:`741`).
+ Set by the :option:`-X presite=package.module <-X>` command-line
+ option and the :envvar:`PYTHON_PRESITE` environment variable.
+ The command-line option takes precedence.
-.. versionadded:: 3.14
+ Needs a :ref:`debug build of Python <debug-build>` (the ``Py_DEBUG`` macro
+ must be defined).
-Create Config
--------------
+ Default: ``NULL``.
-.. c:struct:: PyInitConfig
+ .. c:member:: int show_ref_count
- Opaque structure to configure the Python initialization.
+ Show total reference count at exit (excluding :term:`immortal` objects)?
+ Set to ``1`` by :option:`-X showrefcount <-X>` command line option.
-.. c:function:: PyInitConfig* PyInitConfig_Create(void)
+ Needs a :ref:`debug build of Python <debug-build>` (the ``Py_REF_DEBUG``
+ macro must be defined).
- Create a new initialization configuration using :ref:`Isolated Configuration
- <init-isolated-conf>` default values.
+ Default: ``0``.
- It must be freed by :c:func:`PyInitConfig_Free`.
+ .. c:member:: int site_import
- Return ``NULL`` on memory allocation failure.
+ Import the :mod:`site` module at startup?
+ If equal to zero, disable the import of the module site and the
+ site-dependent manipulations of :data:`sys.path` that it entails.
-.. c:function:: void PyInitConfig_Free(PyInitConfig *config)
+ Also disable these manipulations if the :mod:`site` module is explicitly
+ imported later (call :func:`site.main` if you want them to be triggered).
- Free memory of the initialization configuration *config*.
+ Set to ``0`` by the :option:`-S` command line option.
- If *config* is ``NULL``, no operation is performed.
+ :data:`sys.flags.no_site <sys.flags>` is set to the inverted value of
+ :c:member:`~PyConfig.site_import`.
+ Default: ``1``.
-Error Handling
---------------
+ .. c:member:: int skip_source_first_line
-.. c:function:: int PyInitConfig_GetError(PyInitConfig* config, const char **err_msg)
+ If non-zero, skip the first line of the :c:member:`PyConfig.run_filename`
+ source.
- Get the *config* error message.
+ It allows the usage of non-Unix forms of ``#!cmd``. This is intended for
+ a DOS specific hack only.
- * Set *\*err_msg* and return ``1`` if an error is set.
- * Set *\*err_msg* to ``NULL`` and return ``0`` otherwise.
+ Set to ``1`` by the :option:`-x` command line option.
- An error message is an UTF-8 encoded string.
+ Default: ``0``.
- If *config* has an exit code, format the exit code as an error
- message.
+ .. c:member:: wchar_t* stdio_encoding
+ .. c:member:: wchar_t* stdio_errors
- The error message remains valid until another ``PyInitConfig``
- function is called with *config*. The caller doesn't have to free the
- error message.
+ Encoding and encoding errors of :data:`sys.stdin`, :data:`sys.stdout` and
+ :data:`sys.stderr` (but :data:`sys.stderr` always uses
+ ``"backslashreplace"`` error handler).
+ Use the :envvar:`PYTHONIOENCODING` environment variable if it is
+ non-empty.
-.. c:function:: int PyInitConfig_GetExitCode(PyInitConfig* config, int *exitcode)
+ Default encoding:
- Get the *config* exit code.
+ * ``"UTF-8"`` if :c:member:`PyPreConfig.utf8_mode` is non-zero.
+ * Otherwise, use the :term:`locale encoding`.
- * Set *\*exitcode* and return ``1`` if *config* has an exit code set.
- * Return ``0`` if *config* has no exit code set.
+ Default error handler:
- Only the ``Py_InitializeFromInitConfig()`` function can set an exit
- code if the ``parse_argv`` option is non-zero.
+ * On Windows: use ``"surrogateescape"``.
+ * ``"surrogateescape"`` if :c:member:`PyPreConfig.utf8_mode` is non-zero,
+ or if the LC_CTYPE locale is "C" or "POSIX".
+ * ``"strict"`` otherwise.
- An exit code can be set when parsing the command line failed (exit
- code ``2``) or when a command line option asks to display the command
- line help (exit code ``0``).
+ See also :c:member:`PyConfig.legacy_windows_stdio`.
+ .. c:member:: int tracemalloc
-Get Options
------------
+ Enable tracemalloc?
-The configuration option *name* parameter must be a non-NULL
-null-terminated UTF-8 encoded string.
+ If non-zero, call :func:`tracemalloc.start` at startup.
-.. c:function:: int PyInitConfig_HasOption(PyInitConfig *config, const char *name)
+ Set by :option:`-X tracemalloc=N <-X>` command line option and by the
+ :envvar:`PYTHONTRACEMALLOC` environment variable.
- Test if the configuration has an option called *name*.
+ Default: ``-1`` in Python mode, ``0`` in isolated mode.
- Return ``1`` if the option exists, or return ``0`` otherwise.
+ .. c:member:: int perf_profiling
+ Enable the Linux ``perf`` profiler support?
-.. c:function:: int PyInitConfig_GetInt(PyInitConfig *config, const char *name, int64_t *value)
+ If equals to ``1``, enable support for the Linux ``perf`` profiler.
- Get an integer configuration option.
+ If equals to ``2``, enable support for the Linux ``perf`` profiler with
+ DWARF JIT support.
- * Set *\*value*, and return ``0`` on success.
- * Set an error in *config* and return ``-1`` on error.
+ Set to ``1`` by :option:`-X perf <-X>` command-line option and the
+ :envvar:`PYTHONPERFSUPPORT` environment variable.
+ Set to ``2`` by the :option:`-X perf_jit <-X>` command-line option and
+ the :envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable.
-.. c:function:: int PyInitConfig_GetStr(PyInitConfig *config, const char *name, char **value)
+ Default: ``-1``.
- Get a string configuration option as a null-terminated UTF-8
- encoded string.
+ .. seealso::
+ See :ref:`perf_profiling` for more information.
- * Set *\*value*, and return ``0`` on success.
- * Set an error in *config* and return ``-1`` on error.
+ .. versionadded:: 3.12
- *\*value* can be set to ``NULL`` if the option is an optional string and the
- option is unset.
+ .. c:member:: int use_environment
- On success, the string must be released with ``free(value)`` if it's not
- ``NULL``.
+ Use :ref:`environment variables <using-on-envvars>`?
+ If equals to zero, ignore the :ref:`environment variables
+ <using-on-envvars>`.
-.. c:function:: int PyInitConfig_GetStrList(PyInitConfig *config, const char *name, size_t *length, char ***items)
+ Set to ``0`` by the :option:`-E` environment variable.
- Get a string list configuration option as an array of
- null-terminated UTF-8 encoded strings.
+ Default: ``1`` in Python config and ``0`` in isolated config.
- * Set *\*length* and *\*value*, and return ``0`` on success.
- * Set an error in *config* and return ``-1`` on error.
+ .. c:member:: int use_system_logger
- On success, the string list must be released with
- ``PyInitConfig_FreeStrList(length, items)``.
+ If non-zero, ``stdout`` and ``stderr`` will be redirected to the system
+ log.
+ Only available on macOS 10.12 and later, and on iOS.
-.. c:function:: void PyInitConfig_FreeStrList(size_t length, char **items)
+ Default: ``0`` (don't use system log).
- Free memory of a string list created by
- ``PyInitConfig_GetStrList()``.
+ .. versionadded:: 3.13.2
+ .. c:member:: int user_site_directory
-Set Options
------------
+ If non-zero, add the user site directory to :data:`sys.path`.
-The configuration option *name* parameter must be a non-NULL null-terminated
-UTF-8 encoded string.
+ Set to ``0`` by the :option:`-s` and :option:`-I` command line options.
-Some configuration options have side effects on other options. This logic is
-only implemented when ``Py_InitializeFromInitConfig()`` is called, not by the
-"Set" functions below. For example, setting ``dev_mode`` to ``1`` does not set
-``faulthandler`` to ``1``.
+ Set to ``0`` by the :envvar:`PYTHONNOUSERSITE` environment variable.
-.. c:function:: int PyInitConfig_SetInt(PyInitConfig *config, const char *name, int64_t value)
+ Default: ``1`` in Python mode, ``0`` in isolated mode.
- Set an integer configuration option.
+ .. c:member:: int verbose
- * Return ``0`` on success.
- * Set an error in *config* and return ``-1`` on error.
+ Verbose mode. If greater than ``0``, print a message each time a module is
+ imported, showing the place (filename or built-in module) from which
+ it is loaded.
+ If greater than or equal to ``2``, print a message for each file that is
+ checked for when searching for a module. Also provides information on
+ module cleanup at exit.
-.. c:function:: int PyInitConfig_SetStr(PyInitConfig *config, const char *name, const char *value)
+ Incremented by the :option:`-v` command line option.
- Set a string configuration option from a null-terminated UTF-8
- encoded string. The string is copied.
+ Set by the :envvar:`PYTHONVERBOSE` environment variable value.
- * Return ``0`` on success.
- * Set an error in *config* and return ``-1`` on error.
+ Default: ``0``.
+ .. c:member:: PyWideStringList warnoptions
-.. c:function:: int PyInitConfig_SetStrList(PyInitConfig *config, const char *name, size_t length, char * const *items)
+ Options of the :mod:`warnings` module to build warnings filters, lowest
+ to highest priority: :data:`sys.warnoptions`.
- Set a string list configuration option from an array of
- null-terminated UTF-8 encoded strings. The string list is copied.
+ The :mod:`warnings` module adds :data:`sys.warnoptions` in the reverse
+ order: the last :c:member:`PyConfig.warnoptions` item becomes the first
+ item of :data:`warnings.filters` which is checked first (highest
+ priority).
- * Return ``0`` on success.
- * Set an error in *config* and return ``-1`` on error.
+ The :option:`-W` command line options adds its value to
+ :c:member:`~PyConfig.warnoptions`, it can be used multiple times.
+ The :envvar:`PYTHONWARNINGS` environment variable can also be used to add
+ warning options. Multiple options can be specified, separated by commas
+ (``,``).
-Module
-------
+ Default: empty list.
-.. c:function:: int PyInitConfig_AddModule(PyInitConfig *config, const char *name, PyObject* (*initfunc)(void))
+ .. c:member:: int write_bytecode
- Add a built-in extension module to the table of built-in modules.
+ If equal to ``0``, Python won't try to write ``.pyc`` files on the import of
+ source modules.
- The new module can be imported by the name *name*, and uses the function
- *initfunc* as the initialization function called on the first attempted
- import.
+ Set to ``0`` by the :option:`-B` command line option and the
+ :envvar:`PYTHONDONTWRITEBYTECODE` environment variable.
- * Return ``0`` on success.
- * Set an error in *config* and return ``-1`` on error.
+ :data:`sys.dont_write_bytecode` is initialized to the inverted value of
+ :c:member:`~PyConfig.write_bytecode`.
- If Python is initialized multiple times, ``PyInitConfig_AddModule()`` must
- be called at each Python initialization.
+ Default: ``1``.
- Similar to the :c:func:`PyImport_AppendInittab` function.
+ .. c:member:: PyWideStringList xoptions
+ Values of the :option:`-X` command line options: :data:`sys._xoptions`.
-Initialize Python
------------------
+ Default: empty list.
-.. c:function:: int Py_InitializeFromInitConfig(PyInitConfig *config)
+If :c:member:`~PyConfig.parse_argv` is non-zero, :c:member:`~PyConfig.argv`
+arguments are parsed the same way the regular Python parses :ref:`command line
+arguments <using-on-cmdline>`, and Python arguments are stripped from
+:c:member:`~PyConfig.argv`.
- Initialize Python from the initialization configuration.
+The :c:member:`~PyConfig.xoptions` options are parsed to set other options: see
+the :option:`-X` command line option.
- * Return ``0`` on success.
- * Set an error in *config* and return ``-1`` on error.
- * Set an exit code in *config* and return ``-1`` if Python wants to
- exit.
+.. versionchanged:: 3.9
- See ``PyInitConfig_GetExitcode()`` for the exit code case.
+ The ``show_alloc_count`` field has been removed.
-Example
--------
+.. _init-from-config:
-Example initializing Python, set configuration options of various types,
-return ``-1`` on error:
+Initialization with PyConfig
+----------------------------
-.. code-block:: c
+Initializing the interpreter from a populated configuration struct is handled
+by calling :c:func:`Py_InitializeFromConfig`.
- int init_python(void)
+The caller is responsible to handle exceptions (error or exit) using
+:c:func:`PyStatus_Exception` and :c:func:`Py_ExitStatusException`.
+
+If :c:func:`PyImport_FrozenModules`, :c:func:`PyImport_AppendInittab` or
+:c:func:`PyImport_ExtendInittab` are used, they must be set or called after
+Python preinitialization and before the Python initialization. If Python is
+initialized multiple times, :c:func:`PyImport_AppendInittab` or
+:c:func:`PyImport_ExtendInittab` must be called before each Python
+initialization.
+
+The current configuration (``PyConfig`` type) is stored in
+``PyInterpreterState.config``.
+
+Example setting the program name::
+
+ void init_python(void)
{
- PyInitConfig *config = PyInitConfig_Create();
- if (config == NULL) {
- printf("PYTHON INIT ERROR: memory allocation failed\n");
- return -1;
- }
+ PyStatus status;
- // Set an integer (dev mode)
- if (PyInitConfig_SetInt(config, "dev_mode", 1) < 0) {
- goto error;
+ PyConfig config;
+ PyConfig_InitPythonConfig(&config);
+
+ /* Set the program name. Implicitly preinitialize Python. */
+ status = PyConfig_SetString(&config, &config.program_name,
+ L"/path/to/my_program");
+ if (PyStatus_Exception(status)) {
+ goto exception;
}
- // Set a list of UTF-8 strings (argv)
- char *argv[] = {"my_program", "-c", "pass"};
- if (PyInitConfig_SetStrList(config, "argv",
- Py_ARRAY_LENGTH(argv), argv) < 0) {
- goto error;
+ status = Py_InitializeFromConfig(&config);
+ if (PyStatus_Exception(status)) {
+ goto exception;
}
+ PyConfig_Clear(&config);
+ return;
- // Set a UTF-8 string (program name)
- if (PyInitConfig_SetStr(config, "program_name", L"my_program") < 0) {
- goto error;
+ exception:
+ PyConfig_Clear(&config);
+ Py_ExitStatusException(status);
+ }
+
+More complete example modifying the default configuration, read the
+configuration, and then override some parameters. Note that since
+3.11, many parameters are not calculated until initialization, and
+so values cannot be read from the configuration structure. Any values
+set before initialize is called will be left unchanged by
+initialization::
+
+ PyStatus init_python(const char *program_name)
+ {
+ PyStatus status;
+
+ PyConfig config;
+ PyConfig_InitPythonConfig(&config);
+
+ /* Set the program name before reading the configuration
+ (decode byte string from the locale encoding).
+
+ Implicitly preinitialize Python. */
+ status = PyConfig_SetBytesString(&config, &config.program_name,
+ program_name);
+ if (PyStatus_Exception(status)) {
+ goto done;
}
- // Initialize Python with the configuration
- if (Py_InitializeFromInitConfig(config) < 0) {
- goto error;
+ /* Read all configuration at once */
+ status = PyConfig_Read(&config);
+ if (PyStatus_Exception(status)) {
+ goto done;
}
- PyInitConfig_Free(config);
- return 0;
- error:
- {
- // Display the error message
- // This uncommon braces style is used, because you cannot make
- // goto targets point to variable declarations.
- const char *err_msg;
- (void)PyInitConfig_GetError(config, &err_msg);
- printf("PYTHON INIT ERROR: %s\n", err_msg);
- PyInitConfig_Free(config);
+ /* Specify sys.path explicitly */
+ /* If you want to modify the default set of paths, finish
+ initialization first and then use PySys_GetObject("path") */
+ config.module_search_paths_set = 1;
+ status = PyWideStringList_Append(&config.module_search_paths,
+ L"/path/to/stdlib");
+ if (PyStatus_Exception(status)) {
+ goto done;
+ }
+ status = PyWideStringList_Append(&config.module_search_paths,
+ L"/path/to/more/modules");
+ if (PyStatus_Exception(status)) {
+ goto done;
+ }
- return -1;
+ /* Override executable computed by PyConfig_Read() */
+ status = PyConfig_SetString(&config, &config.executable,
+ L"/path/to/my_executable");
+ if (PyStatus_Exception(status)) {
+ goto done;
}
+
+ status = Py_InitializeFromConfig(&config);
+
+ done:
+ PyConfig_Clear(&config);
+ return status;
}
-Runtime Python configuration API
-================================
+.. _init-isolated-conf:
-The configuration option *name* parameter must be a non-NULL null-terminated
-UTF-8 encoded string.
+Isolated Configuration
+----------------------
-Some options are read from the :mod:`sys` attributes. For example, the option
-``"argv"`` is read from :data:`sys.argv`.
+:c:func:`PyPreConfig_InitIsolatedConfig` and
+:c:func:`PyConfig_InitIsolatedConfig` functions create a configuration to
+isolate Python from the system. For example, to embed Python into an
+application.
+This configuration ignores global configuration variables, environment
+variables, command line arguments (:c:member:`PyConfig.argv` is not parsed)
+and user site directory. The C standard streams (ex: ``stdout``) and the
+LC_CTYPE locale are left unchanged. Signal handlers are not installed.
-.. c:function:: PyObject* PyConfig_Get(const char *name)
+Configuration files are still used with this configuration to determine
+paths that are unspecified. Ensure :c:member:`PyConfig.home` is specified
+to avoid computing the default path configuration.
- Get the current runtime value of a configuration option as a Python object.
- * Return a new reference on success.
- * Set an exception and return ``NULL`` on error.
+.. _init-python-config:
- The object type depends on the configuration option. It can be:
+Python Configuration
+--------------------
- * ``bool``
- * ``int``
- * ``str``
- * ``list[str]``
- * ``dict[str, str]``
+:c:func:`PyPreConfig_InitPythonConfig` and :c:func:`PyConfig_InitPythonConfig`
+functions create a configuration to build a customized Python which behaves as
+the regular Python.
- The caller must hold the GIL. The function cannot be called before
- Python initialization nor after Python finalization.
+Environments variables and command line arguments are used to configure
+Python, whereas global configuration variables are ignored.
- .. versionadded:: 3.14
+This function enables C locale coercion (:pep:`538`)
+and :ref:`Python UTF-8 Mode <utf8-mode>`
+(:pep:`540`) depending on the LC_CTYPE locale, :envvar:`PYTHONUTF8` and
+:envvar:`PYTHONCOERCECLOCALE` environment variables.
-.. c:function:: int PyConfig_GetInt(const char *name, int *value)
+.. _init-path-config:
- Similar to :c:func:`PyConfig_Get`, but get the value as a C int.
+Python Path Configuration
+-------------------------
- * Return ``0`` on success.
- * Set an exception and return ``-1`` on error.
+:c:type:`PyConfig` contains multiple fields for the path configuration:
- .. versionadded:: 3.14
+* Path configuration inputs:
+ * :c:member:`PyConfig.home`
+ * :c:member:`PyConfig.platlibdir`
+ * :c:member:`PyConfig.pathconfig_warnings`
+ * :c:member:`PyConfig.program_name`
+ * :c:member:`PyConfig.pythonpath_env`
+ * current working directory: to get absolute paths
+ * ``PATH`` environment variable to get the program full path
+ (from :c:member:`PyConfig.program_name`)
+ * ``__PYVENV_LAUNCHER__`` environment variable
+ * (Windows only) Application paths in the registry under
+ "Software\Python\PythonCore\X.Y\PythonPath" of HKEY_CURRENT_USER and
+ HKEY_LOCAL_MACHINE (where X.Y is the Python version).
-.. c:function:: PyObject* PyConfig_Names(void)
+* Path configuration output fields:
- Get all configuration option names as a ``frozenset``.
+ * :c:member:`PyConfig.base_exec_prefix`
+ * :c:member:`PyConfig.base_executable`
+ * :c:member:`PyConfig.base_prefix`
+ * :c:member:`PyConfig.exec_prefix`
+ * :c:member:`PyConfig.executable`
+ * :c:member:`PyConfig.module_search_paths_set`,
+ :c:member:`PyConfig.module_search_paths`
+ * :c:member:`PyConfig.prefix`
- * Return a new reference on success.
- * Set an exception and return ``NULL`` on error.
+If at least one "output field" is not set, Python calculates the path
+configuration to fill unset fields. If
+:c:member:`~PyConfig.module_search_paths_set` is equal to ``0``,
+:c:member:`~PyConfig.module_search_paths` is overridden and
+:c:member:`~PyConfig.module_search_paths_set` is set to ``1``.
- The caller must hold the GIL. The function cannot be called before
- Python initialization nor after Python finalization.
+It is possible to completely ignore the function calculating the default
+path configuration by setting explicitly all path configuration output
+fields listed above. A string is considered as set even if it is non-empty.
+``module_search_paths`` is considered as set if
+``module_search_paths_set`` is set to ``1``. In this case,
+``module_search_paths`` will be used without modification.
- .. versionadded:: 3.14
+Set :c:member:`~PyConfig.pathconfig_warnings` to ``0`` to suppress warnings when
+calculating the path configuration (Unix only, Windows does not log any warning).
+If :c:member:`~PyConfig.base_prefix` or :c:member:`~PyConfig.base_exec_prefix`
+fields are not set, they inherit their value from :c:member:`~PyConfig.prefix`
+and :c:member:`~PyConfig.exec_prefix` respectively.
-.. c:function:: int PyConfig_Set(const char *name, PyObject *value)
+:c:func:`Py_RunMain` and :c:func:`Py_Main` modify :data:`sys.path`:
- Set the current runtime value of a configuration option.
+* If :c:member:`~PyConfig.run_filename` is set and is a directory which contains a
+ ``__main__.py`` script, prepend :c:member:`~PyConfig.run_filename` to
+ :data:`sys.path`.
+* If :c:member:`~PyConfig.isolated` is zero:
- * Raise a :exc:`ValueError` if there is no option *name*.
- * Raise a :exc:`ValueError` if *value* is an invalid value.
- * Raise a :exc:`ValueError` if the option is read-only (cannot be set).
- * Raise a :exc:`TypeError` if *value* has not the proper type.
+ * If :c:member:`~PyConfig.run_module` is set, prepend the current directory
+ to :data:`sys.path`. Do nothing if the current directory cannot be read.
+ * If :c:member:`~PyConfig.run_filename` is set, prepend the directory of the
+ filename to :data:`sys.path`.
+ * Otherwise, prepend an empty string to :data:`sys.path`.
- The caller must hold the GIL. The function cannot be called before
- Python initialization nor after Python finalization.
+If :c:member:`~PyConfig.site_import` is non-zero, :data:`sys.path` can be
+modified by the :mod:`site` module. If
+:c:member:`~PyConfig.user_site_directory` is non-zero and the user's
+site-package directory exists, the :mod:`site` module appends the user's
+site-package directory to :data:`sys.path`.
- .. versionadded:: 3.14
+The following configuration files are used by the path configuration:
+
+* ``pyvenv.cfg``
+* ``._pth`` file (ex: ``python._pth``)
+* ``pybuilddir.txt`` (Unix only)
+
+If a ``._pth`` file is present:
+
+* Set :c:member:`~PyConfig.isolated` to ``1``.
+* Set :c:member:`~PyConfig.use_environment` to ``0``.
+* Set :c:member:`~PyConfig.site_import` to ``0``.
+* Set :c:member:`~PyConfig.safe_path` to ``1``.
+
+If :c:member:`~PyConfig.home` is not set and a ``pyvenv.cfg`` file is present in
+the same directory as :c:member:`~PyConfig.executable`, or its parent,
+:c:member:`~PyConfig.prefix` and :c:member:`~PyConfig.exec_prefix` are set that
+location. When this happens, :c:member:`~PyConfig.base_prefix` and
+:c:member:`~PyConfig.base_exec_prefix` still keep their value, pointing to the
+base installation. See :ref:`sys-path-init-virtual-environments` for more
+information.
+
+The ``__PYVENV_LAUNCHER__`` environment variable is used to set
+:c:member:`PyConfig.base_executable`.
+
+.. versionchanged:: 3.14
+
+ :c:member:`~PyConfig.prefix`, and :c:member:`~PyConfig.exec_prefix`, are now
+ set to the ``pyvenv.cfg`` directory. This was previously done by :mod:`site`,
+ therefore affected by :option:`-S`.
Py_GetArgcArgv()
1
0
Jan. 20, 2025
https://github.com/python/cpython/commit/0351ed50499c3d7fbefe126d025d32eb86…
commit: 0351ed50499c3d7fbefe126d025d32eb865ad3f0
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: Eclips4 <kirill.bast9(a)mail.ru>
date: 2025-01-20T10:37:21Z
summary:
[3.13] Fix a typo in `syslog`'s error message (GH-129029) (#129049)
Fix a typo in `syslog`'s error message (GH-129029)
(cherry picked from commit 9b1c1817af30e609b7cbfacbe5b1e73e21dc9e37)
Co-authored-by: Tomas R <tomas.roun8(a)gmail.com>
files:
M Modules/syslogmodule.c
diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c
index 14e7ca591a076b..adbd2fcc6ed74d 100644
--- a/Modules/syslogmodule.c
+++ b/Modules/syslogmodule.c
@@ -258,7 +258,7 @@ syslog_closelog_impl(PyObject *module)
// Since the sys.closelog changes the process level state of syslog library,
// this operation is only allowed for the main interpreter.
if (!is_main_interpreter()) {
- PyErr_SetString(PyExc_RuntimeError, "sunbinterpreter can't use syslog.closelog()");
+ PyErr_SetString(PyExc_RuntimeError, "subinterpreter can't use syslog.closelog()");
return NULL;
}
1
0
Jan. 20, 2025
https://github.com/python/cpython/commit/7f68e7bf2a768489ece13054d0cf9566d1…
commit: 7f68e7bf2a768489ece13054d0cf9566d176c576
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: Eclips4 <kirill.bast9(a)mail.ru>
date: 2025-01-20T10:28:55Z
summary:
[3.12] Fix a typo in `syslog`'s error message (GH-129029) (#129050)
Fix a typo in `syslog`'s error message (GH-129029)
(cherry picked from commit 9b1c1817af30e609b7cbfacbe5b1e73e21dc9e37)
Co-authored-by: Tomas R <tomas.roun8(a)gmail.com>
files:
M Modules/syslogmodule.c
diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c
index 6db8de9c491dd9..722364e0751d9f 100644
--- a/Modules/syslogmodule.c
+++ b/Modules/syslogmodule.c
@@ -250,7 +250,7 @@ syslog_closelog_impl(PyObject *module)
// Since the sys.closelog changes the process level state of syslog library,
// this operation is only allowed for the main interpreter.
if (!is_main_interpreter()) {
- PyErr_SetString(PyExc_RuntimeError, "sunbinterpreter can't use syslog.closelog()");
+ PyErr_SetString(PyExc_RuntimeError, "subinterpreter can't use syslog.closelog()");
return NULL;
}
1
0
https://github.com/python/cpython/commit/9b1c1817af30e609b7cbfacbe5b1e73e21…
commit: 9b1c1817af30e609b7cbfacbe5b1e73e21dc9e37
branch: main
author: Tomas R. <tomas.roun8(a)gmail.com>
committer: Eclips4 <kirill.bast9(a)mail.ru>
date: 2025-01-20T10:11:08Z
summary:
Fix a typo in `syslog`'s error message (#129029)
files:
M Modules/syslogmodule.c
diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c
index 14e7ca591a076b..adbd2fcc6ed74d 100644
--- a/Modules/syslogmodule.c
+++ b/Modules/syslogmodule.c
@@ -258,7 +258,7 @@ syslog_closelog_impl(PyObject *module)
// Since the sys.closelog changes the process level state of syslog library,
// this operation is only allowed for the main interpreter.
if (!is_main_interpreter()) {
- PyErr_SetString(PyExc_RuntimeError, "sunbinterpreter can't use syslog.closelog()");
+ PyErr_SetString(PyExc_RuntimeError, "subinterpreter can't use syslog.closelog()");
return NULL;
}
1
0
https://github.com/python/cpython/commit/07c3518ffb27875b14a0f1637aa85f773f…
commit: 07c3518ffb27875b14a0f1637aa85f773ff2f9ff
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-20T10:03:22Z
summary:
gh-129033: Remove _Py_InitializeMain() function (#129034)
Co-authored-by: Alyssa Coghlan <ncoghlan(a)gmail.com>
files:
A Misc/NEWS.d/next/C_API/2025-01-19-23-17-58.gh-issue-129033.cpRivP.rst
M Doc/c-api/init_config.rst
M Doc/whatsnew/3.14.rst
M Include/cpython/pylifecycle.h
M Lib/test/test_embed.py
M Programs/_testembed.c
M Python/pylifecycle.c
diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst
index 6b33d93a9f2af9..85566631ca1676 100644
--- a/Doc/c-api/init_config.rst
+++ b/Doc/c-api/init_config.rst
@@ -1946,89 +1946,13 @@ Py_GetArgcArgv()
See also :c:member:`PyConfig.orig_argv` member.
+Delaying main module execution
+==============================
-Multi-Phase Initialization Private Provisional API
-==================================================
+In some embedding use cases, it may be desirable to separate interpreter initialization
+from the execution of the main module.
-This section is a private provisional API introducing multi-phase
-initialization, the core feature of :pep:`432`:
-
-* "Core" initialization phase, "bare minimum Python":
-
- * Builtin types;
- * Builtin exceptions;
- * Builtin and frozen modules;
- * The :mod:`sys` module is only partially initialized
- (ex: :data:`sys.path` doesn't exist yet).
-
-* "Main" initialization phase, Python is fully initialized:
-
- * Install and configure :mod:`importlib`;
- * Apply the :ref:`Path Configuration <init-path-config>`;
- * Install signal handlers;
- * Finish :mod:`sys` module initialization (ex: create :data:`sys.stdout`
- and :data:`sys.path`);
- * Enable optional features like :mod:`faulthandler` and :mod:`tracemalloc`;
- * Import the :mod:`site` module;
- * etc.
-
-Private provisional API:
-
-* :c:member:`PyConfig._init_main`: if set to ``0``,
- :c:func:`Py_InitializeFromConfig` stops at the "Core" initialization phase.
-
-.. c:function:: PyStatus _Py_InitializeMain(void)
-
- Move to the "Main" initialization phase, finish the Python initialization.
-
-No module is imported during the "Core" phase and the ``importlib`` module is
-not configured: the :ref:`Path Configuration <init-path-config>` is only
-applied during the "Main" phase. It may allow to customize Python in Python to
-override or tune the :ref:`Path Configuration <init-path-config>`, maybe
-install a custom :data:`sys.meta_path` importer or an import hook, etc.
-
-It may become possible to calculate the :ref:`Path Configuration
-<init-path-config>` in Python, after the Core phase and before the Main phase,
-which is one of the :pep:`432` motivation.
-
-The "Core" phase is not properly defined: what should be and what should
-not be available at this phase is not specified yet. The API is marked
-as private and provisional: the API can be modified or even be removed
-anytime until a proper public API is designed.
-
-Example running Python code between "Core" and "Main" initialization
-phases::
-
- void init_python(void)
- {
- PyStatus status;
-
- PyConfig config;
- PyConfig_InitPythonConfig(&config);
- config._init_main = 0;
-
- /* ... customize 'config' configuration ... */
-
- status = Py_InitializeFromConfig(&config);
- PyConfig_Clear(&config);
- if (PyStatus_Exception(status)) {
- Py_ExitStatusException(status);
- }
-
- /* Use sys.stderr because sys.stdout is only created
- by _Py_InitializeMain() */
- int res = PyRun_SimpleString(
- "import sys; "
- "print('Run Python code before _Py_InitializeMain', "
- "file=sys.stderr)");
- if (res < 0) {
- exit(1);
- }
-
- /* ... put more configuration code here ... */
-
- status = _Py_InitializeMain();
- if (PyStatus_Exception(status)) {
- Py_ExitStatusException(status);
- }
- }
+This separation can be achieved by setting ``PyConfig.run_command`` to the empty
+string during initialization (to prevent the interpreter from dropping into the
+interactive prompt), and then subsequently executing the desired main module
+code using ``__main__.__dict__`` as the global namespace.
diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst
index d6aa6b346417e5..7f149d5c03dfbb 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -1375,3 +1375,7 @@ Removed
* Creating :c:data:`immutable types <Py_TPFLAGS_IMMUTABLETYPE>` with mutable
bases was deprecated since 3.12 and now raises a :exc:`TypeError`.
+
+* Remove the private ``_Py_InitializeMain()`` function. It was a
+ :term:`provisional API` added to Python 3.8 by :pep:`587`.
+ (Contributed by Victor Stinner in :gh:`129033`.)
diff --git a/Include/cpython/pylifecycle.h b/Include/cpython/pylifecycle.h
index e46dfe59ec4630..86ce6e6f79824a 100644
--- a/Include/cpython/pylifecycle.h
+++ b/Include/cpython/pylifecycle.h
@@ -25,9 +25,6 @@ PyAPI_FUNC(PyStatus) Py_PreInitializeFromArgs(
PyAPI_FUNC(PyStatus) Py_InitializeFromConfig(
const PyConfig *config);
-// Python 3.8 provisional API (PEP 587)
-PyAPI_FUNC(PyStatus) _Py_InitializeMain(void);
-
PyAPI_FUNC(int) Py_RunMain(void);
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 1b55cd156d759d..a2400aa96c3ddd 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -1274,24 +1274,6 @@ def test_init_run_main(self):
}
self.check_all_configs("test_init_run_main", config, api=API_PYTHON)
- def test_init_main(self):
- code = ('import _testinternalcapi, json; '
- 'print(json.dumps(_testinternalcapi.get_configs()))')
- config = {
- 'argv': ['-c', 'arg2'],
- 'orig_argv': ['python3',
- '-c', code,
- 'arg2'],
- 'program_name': './python3',
- 'run_command': code + '\n',
- 'parse_argv': True,
- '_init_main': False,
- 'sys_path_0': '',
- }
- self.check_all_configs("test_init_main", config,
- api=API_PYTHON,
- stderr="Run Python code before _Py_InitializeMain")
-
def test_init_parse_argv(self):
config = {
'parse_argv': True,
@@ -1768,7 +1750,6 @@ def test_init_warnoptions(self):
def test_init_set_config(self):
config = {
- '_init_main': 0,
'bytes_warning': 2,
'warnoptions': ['error::BytesWarning'],
}
diff --git a/Misc/NEWS.d/next/C_API/2025-01-19-23-17-58.gh-issue-129033.cpRivP.rst b/Misc/NEWS.d/next/C_API/2025-01-19-23-17-58.gh-issue-129033.cpRivP.rst
new file mode 100644
index 00000000000000..3cd19cc48e3416
--- /dev/null
+++ b/Misc/NEWS.d/next/C_API/2025-01-19-23-17-58.gh-issue-129033.cpRivP.rst
@@ -0,0 +1,3 @@
+Remove the private ``_Py_InitializeMain()`` function. It was a
+:term:`provisional API` added to Python 3.8 by :pep:`587`. Patch by Victor
+Stinner.
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index d15dd519dbf6af..3681a89376638a 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -1818,7 +1818,6 @@ static int test_init_set_config(void)
PyConfig config;
PyConfig_InitIsolatedConfig(&config);
config_set_string(&config, &config.program_name, PROGRAM_NAME);
- config._init_main = 0;
config.bytes_warning = 0;
init_from_config_clear(&config);
@@ -1828,12 +1827,6 @@ static int test_init_set_config(void)
return 1;
}
- // Finish initialization: main part
- PyStatus status = _Py_InitializeMain();
- if (PyStatus_Exception(status)) {
- Py_ExitStatusException(status);
- }
-
dump_config();
Py_Finalize();
return 0;
@@ -2089,33 +2082,6 @@ static int test_init_run_main(void)
}
-static int test_init_main(void)
-{
- PyConfig config;
- PyConfig_InitPythonConfig(&config);
-
- configure_init_main(&config);
- config._init_main = 0;
- init_from_config_clear(&config);
-
- /* sys.stdout don't exist yet: it is created by _Py_InitializeMain() */
- int res = PyRun_SimpleString(
- "import sys; "
- "print('Run Python code before _Py_InitializeMain', "
- "file=sys.stderr)");
- if (res < 0) {
- exit(1);
- }
-
- PyStatus status = _Py_InitializeMain();
- if (PyStatus_Exception(status)) {
- Py_ExitStatusException(status);
- }
-
- return Py_RunMain();
-}
-
-
static int test_run_main(void)
{
PyConfig config;
@@ -2473,7 +2439,6 @@ static struct TestCase TestCases[] = {
{"test_preinit_dont_parse_argv", test_preinit_dont_parse_argv},
{"test_init_read_set", test_init_read_set},
{"test_init_run_main", test_init_run_main},
- {"test_init_main", test_init_main},
{"test_init_sys_add", test_init_sys_add},
{"test_init_setpath", test_init_setpath},
{"test_init_setpath_config", test_init_setpath_config},
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index f1ecee6a92e5a1..8ec12b437f8298 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1505,18 +1505,6 @@ Py_Initialize(void)
}
-PyStatus
-_Py_InitializeMain(void)
-{
- PyStatus status = _PyRuntime_Initialize();
- if (_PyStatus_EXCEPTION(status)) {
- return status;
- }
- PyThreadState *tstate = _PyThreadState_GET();
- return pyinit_main(tstate);
-}
-
-
static void
finalize_modules_delete_special(PyThreadState *tstate, int verbose)
{
1
0
Jan. 20, 2025
https://github.com/python/cpython/commit/c463270c73a61ef8106ee7bd0571c7c614…
commit: c463270c73a61ef8106ee7bd0571c7c6143e2c20
branch: main
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2025-01-20T11:22:33+02:00
summary:
gh-71339: Use new assertion methods in test_traceback (GH-128848)
files:
M Lib/test/test_traceback.py
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index abdfc4638f2e9c..a27a71c32ea521 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -86,7 +86,7 @@ def test_caret(self):
err = self.get_exception_format(self.syntax_error_with_caret,
SyntaxError)
self.assertEqual(len(err), 4)
- self.assertTrue(err[1].strip() == "return x!")
+ self.assertEqual(err[1].strip(), "return x!")
self.assertIn("^", err[2]) # third line has caret
self.assertEqual(err[1].find("!"), err[2].find("^")) # in the right place
self.assertEqual(err[2].count("^"), 1)
@@ -419,16 +419,10 @@ def do_test(firstlines, message, charset, lineno):
err_line = "raise RuntimeError('{0}')".format(message_ascii)
err_msg = "RuntimeError: {0}".format(message_ascii)
- self.assertIn(("line %s" % lineno), stdout[1],
- "Invalid line number: {0!r} instead of {1}".format(
- stdout[1], lineno))
- self.assertTrue(stdout[2].endswith(err_line),
- "Invalid traceback line: {0!r} instead of {1!r}".format(
- stdout[2], err_line))
+ self.assertIn("line %s" % lineno, stdout[1])
+ self.assertEndsWith(stdout[2], err_line)
actual_err_msg = stdout[3]
- self.assertTrue(actual_err_msg == err_msg,
- "Invalid error message: {0!r} instead of {1!r}".format(
- actual_err_msg, err_msg))
+ self.assertEqual(actual_err_msg, err_msg)
do_test("", "foo", "ascii", 3)
for charset in ("ascii", "iso-8859-1", "utf-8", "GBK"):
@@ -1809,9 +1803,9 @@ def check_traceback_format(self, cleanup_func=None):
banner = tb_lines[0]
self.assertEqual(len(tb_lines), 5)
location, source_line = tb_lines[-2], tb_lines[-1]
- self.assertTrue(banner.startswith('Traceback'))
- self.assertTrue(location.startswith(' File'))
- self.assertTrue(source_line.startswith(' raise'))
+ self.assertStartsWith(banner, 'Traceback')
+ self.assertStartsWith(location, ' File')
+ self.assertStartsWith(source_line, ' raise')
def test_traceback_format(self):
self.check_traceback_format()
@@ -2190,12 +2184,12 @@ def zero_div(self):
def check_zero_div(self, msg):
lines = msg.splitlines()
if has_no_debug_ranges():
- self.assertTrue(lines[-3].startswith(' File'))
+ self.assertStartsWith(lines[-3], ' File')
self.assertIn('1/0 # In zero_div', lines[-2])
else:
- self.assertTrue(lines[-4].startswith(' File'))
+ self.assertStartsWith(lines[-4], ' File')
self.assertIn('1/0 # In zero_div', lines[-3])
- self.assertTrue(lines[-1].startswith('ZeroDivisionError'), lines[-1])
+ self.assertStartsWith(lines[-1], 'ZeroDivisionError')
def test_simple(self):
try:
@@ -2205,12 +2199,12 @@ def test_simple(self):
lines = self.get_report(e).splitlines()
if has_no_debug_ranges():
self.assertEqual(len(lines), 4)
- self.assertTrue(lines[3].startswith('ZeroDivisionError'))
+ self.assertStartsWith(lines[3], 'ZeroDivisionError')
else:
self.assertEqual(len(lines), 5)
- self.assertTrue(lines[4].startswith('ZeroDivisionError'))
- self.assertTrue(lines[0].startswith('Traceback'))
- self.assertTrue(lines[1].startswith(' File'))
+ self.assertStartsWith(lines[4], 'ZeroDivisionError')
+ self.assertStartsWith(lines[0], 'Traceback')
+ self.assertStartsWith(lines[1], ' File')
self.assertIn('1/0 # Marker', lines[2])
def test_cause(self):
@@ -2251,9 +2245,9 @@ def test_context_suppression(self):
e = _
lines = self.get_report(e).splitlines()
self.assertEqual(len(lines), 4)
- self.assertTrue(lines[3].startswith('ZeroDivisionError'))
- self.assertTrue(lines[0].startswith('Traceback'))
- self.assertTrue(lines[1].startswith(' File'))
+ self.assertStartsWith(lines[3], 'ZeroDivisionError')
+ self.assertStartsWith(lines[0], 'Traceback')
+ self.assertStartsWith(lines[1], ' File')
self.assertIn('ZeroDivisionError from None', lines[2])
def test_cause_and_context(self):
1
0
gh-71339: Use assertIsSubclass() and assertNotIsSubclass() in test_decimal (GH-128827)
by serhiy-storchaka Jan. 20, 2025
by serhiy-storchaka Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/485d2e831ebf71a34634319adeeabdd1f9…
commit: 485d2e831ebf71a34634319adeeabdd1f9158bbe
branch: main
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2025-01-20T11:20:49+02:00
summary:
gh-71339: Use assertIsSubclass() and assertNotIsSubclass() in test_decimal (GH-128827)
files:
M Lib/test/test_decimal.py
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index bc6c6427740949..02d3fa985e75b9 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -752,7 +752,7 @@ def test_explicit_context_create_decimal(self):
for v in [-2**63-1, -2**63, -2**31-1, -2**31, 0,
2**31-1, 2**31, 2**63-1, 2**63]:
d = nc.create_decimal(v)
- self.assertTrue(isinstance(d, Decimal))
+ self.assertIsInstance(d, Decimal)
self.assertEqual(int(d), v)
nc.prec = 3
@@ -2590,8 +2590,8 @@ class PythonAPItests:
def test_abc(self):
Decimal = self.decimal.Decimal
- self.assertTrue(issubclass(Decimal, numbers.Number))
- self.assertFalse(issubclass(Decimal, numbers.Real))
+ self.assertIsSubclass(Decimal, numbers.Number)
+ self.assertNotIsSubclass(Decimal, numbers.Real)
self.assertIsInstance(Decimal(0), numbers.Number)
self.assertNotIsInstance(Decimal(0), numbers.Real)
@@ -2690,7 +2690,7 @@ class MyDecimal(Decimal):
def __init__(self, _):
self.x = 'y'
- self.assertTrue(issubclass(MyDecimal, Decimal))
+ self.assertIsSubclass(MyDecimal, Decimal)
r = MyDecimal.from_float(0.1)
self.assertEqual(type(r), MyDecimal)
@@ -2908,31 +2908,31 @@ def test_exception_hierarchy(self):
Rounded = decimal.Rounded
Clamped = decimal.Clamped
- self.assertTrue(issubclass(DecimalException, ArithmeticError))
-
- self.assertTrue(issubclass(InvalidOperation, DecimalException))
- self.assertTrue(issubclass(FloatOperation, DecimalException))
- self.assertTrue(issubclass(FloatOperation, TypeError))
- self.assertTrue(issubclass(DivisionByZero, DecimalException))
- self.assertTrue(issubclass(DivisionByZero, ZeroDivisionError))
- self.assertTrue(issubclass(Overflow, Rounded))
- self.assertTrue(issubclass(Overflow, Inexact))
- self.assertTrue(issubclass(Overflow, DecimalException))
- self.assertTrue(issubclass(Underflow, Inexact))
- self.assertTrue(issubclass(Underflow, Rounded))
- self.assertTrue(issubclass(Underflow, Subnormal))
- self.assertTrue(issubclass(Underflow, DecimalException))
-
- self.assertTrue(issubclass(Subnormal, DecimalException))
- self.assertTrue(issubclass(Inexact, DecimalException))
- self.assertTrue(issubclass(Rounded, DecimalException))
- self.assertTrue(issubclass(Clamped, DecimalException))
-
- self.assertTrue(issubclass(decimal.ConversionSyntax, InvalidOperation))
- self.assertTrue(issubclass(decimal.DivisionImpossible, InvalidOperation))
- self.assertTrue(issubclass(decimal.DivisionUndefined, InvalidOperation))
- self.assertTrue(issubclass(decimal.DivisionUndefined, ZeroDivisionError))
- self.assertTrue(issubclass(decimal.InvalidContext, InvalidOperation))
+ self.assertIsSubclass(DecimalException, ArithmeticError)
+
+ self.assertIsSubclass(InvalidOperation, DecimalException)
+ self.assertIsSubclass(FloatOperation, DecimalException)
+ self.assertIsSubclass(FloatOperation, TypeError)
+ self.assertIsSubclass(DivisionByZero, DecimalException)
+ self.assertIsSubclass(DivisionByZero, ZeroDivisionError)
+ self.assertIsSubclass(Overflow, Rounded)
+ self.assertIsSubclass(Overflow, Inexact)
+ self.assertIsSubclass(Overflow, DecimalException)
+ self.assertIsSubclass(Underflow, Inexact)
+ self.assertIsSubclass(Underflow, Rounded)
+ self.assertIsSubclass(Underflow, Subnormal)
+ self.assertIsSubclass(Underflow, DecimalException)
+
+ self.assertIsSubclass(Subnormal, DecimalException)
+ self.assertIsSubclass(Inexact, DecimalException)
+ self.assertIsSubclass(Rounded, DecimalException)
+ self.assertIsSubclass(Clamped, DecimalException)
+
+ self.assertIsSubclass(decimal.ConversionSyntax, InvalidOperation)
+ self.assertIsSubclass(decimal.DivisionImpossible, InvalidOperation)
+ self.assertIsSubclass(decimal.DivisionUndefined, InvalidOperation)
+ self.assertIsSubclass(decimal.DivisionUndefined, ZeroDivisionError)
+ self.assertIsSubclass(decimal.InvalidContext, InvalidOperation)
@requires_cdecimal
class CPythonAPItests(PythonAPItests, unittest.TestCase):
1
0
Jan. 20, 2025
https://github.com/python/cpython/commit/36aaf4137d55df3e324d98ec06b983b028…
commit: 36aaf4137d55df3e324d98ec06b983b0287d8949
branch: main
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2025-01-20T11:19:43+02:00
summary:
gh-71339: Use new assertion methods in test_abc (GH-128826)
files:
M Lib/test/test_abc.py
diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py
index 5ce57cc209ea85..e90a8dc617c094 100644
--- a/Lib/test/test_abc.py
+++ b/Lib/test/test_abc.py
@@ -20,7 +20,7 @@ def test_abstractproperty_basics(self):
def foo(self): pass
self.assertTrue(foo.__isabstractmethod__)
def bar(self): pass
- self.assertFalse(hasattr(bar, "__isabstractmethod__"))
+ self.assertNotHasAttr(bar, "__isabstractmethod__")
class C(metaclass=abc_ABCMeta):
@abc.abstractproperty
@@ -89,7 +89,7 @@ def test_abstractmethod_basics(self):
def foo(self): pass
self.assertTrue(foo.__isabstractmethod__)
def bar(self): pass
- self.assertFalse(hasattr(bar, "__isabstractmethod__"))
+ self.assertNotHasAttr(bar, "__isabstractmethod__")
def test_abstractproperty_basics(self):
@property
@@ -276,21 +276,21 @@ class A(metaclass=abc_ABCMeta):
class B(object):
pass
b = B()
- self.assertFalse(issubclass(B, A))
- self.assertFalse(issubclass(B, (A,)))
+ self.assertNotIsSubclass(B, A)
+ self.assertNotIsSubclass(B, (A,))
self.assertNotIsInstance(b, A)
self.assertNotIsInstance(b, (A,))
B1 = A.register(B)
- self.assertTrue(issubclass(B, A))
- self.assertTrue(issubclass(B, (A,)))
+ self.assertIsSubclass(B, A)
+ self.assertIsSubclass(B, (A,))
self.assertIsInstance(b, A)
self.assertIsInstance(b, (A,))
self.assertIs(B1, B)
class C(B):
pass
c = C()
- self.assertTrue(issubclass(C, A))
- self.assertTrue(issubclass(C, (A,)))
+ self.assertIsSubclass(C, A)
+ self.assertIsSubclass(C, (A,))
self.assertIsInstance(c, A)
self.assertIsInstance(c, (A,))
@@ -301,16 +301,16 @@ class A(metaclass=abc_ABCMeta):
class B(object):
pass
b = B()
- self.assertTrue(issubclass(B, A))
- self.assertTrue(issubclass(B, (A,)))
+ self.assertIsSubclass(B, A)
+ self.assertIsSubclass(B, (A,))
self.assertIsInstance(b, A)
self.assertIsInstance(b, (A,))
@A.register
class C(B):
pass
c = C()
- self.assertTrue(issubclass(C, A))
- self.assertTrue(issubclass(C, (A,)))
+ self.assertIsSubclass(C, A)
+ self.assertIsSubclass(C, (A,))
self.assertIsInstance(c, A)
self.assertIsInstance(c, (A,))
self.assertIs(C, A.register(C))
@@ -321,14 +321,14 @@ class A(metaclass=abc_ABCMeta):
class B:
pass
b = B()
- self.assertFalse(isinstance(b, A))
- self.assertFalse(isinstance(b, (A,)))
+ self.assertNotIsInstance(b, A)
+ self.assertNotIsInstance(b, (A,))
token_old = abc_get_cache_token()
A.register(B)
token_new = abc_get_cache_token()
self.assertGreater(token_new, token_old)
- self.assertTrue(isinstance(b, A))
- self.assertTrue(isinstance(b, (A,)))
+ self.assertIsInstance(b, A)
+ self.assertIsInstance(b, (A,))
def test_registration_builtins(self):
class A(metaclass=abc_ABCMeta):
@@ -336,18 +336,18 @@ class A(metaclass=abc_ABCMeta):
A.register(int)
self.assertIsInstance(42, A)
self.assertIsInstance(42, (A,))
- self.assertTrue(issubclass(int, A))
- self.assertTrue(issubclass(int, (A,)))
+ self.assertIsSubclass(int, A)
+ self.assertIsSubclass(int, (A,))
class B(A):
pass
B.register(str)
class C(str): pass
self.assertIsInstance("", A)
self.assertIsInstance("", (A,))
- self.assertTrue(issubclass(str, A))
- self.assertTrue(issubclass(str, (A,)))
- self.assertTrue(issubclass(C, A))
- self.assertTrue(issubclass(C, (A,)))
+ self.assertIsSubclass(str, A)
+ self.assertIsSubclass(str, (A,))
+ self.assertIsSubclass(C, A)
+ self.assertIsSubclass(C, (A,))
def test_registration_edge_cases(self):
class A(metaclass=abc_ABCMeta):
@@ -375,39 +375,39 @@ class A(metaclass=abc_ABCMeta):
def test_registration_transitiveness(self):
class A(metaclass=abc_ABCMeta):
pass
- self.assertTrue(issubclass(A, A))
- self.assertTrue(issubclass(A, (A,)))
+ self.assertIsSubclass(A, A)
+ self.assertIsSubclass(A, (A,))
class B(metaclass=abc_ABCMeta):
pass
- self.assertFalse(issubclass(A, B))
- self.assertFalse(issubclass(A, (B,)))
- self.assertFalse(issubclass(B, A))
- self.assertFalse(issubclass(B, (A,)))
+ self.assertNotIsSubclass(A, B)
+ self.assertNotIsSubclass(A, (B,))
+ self.assertNotIsSubclass(B, A)
+ self.assertNotIsSubclass(B, (A,))
class C(metaclass=abc_ABCMeta):
pass
A.register(B)
class B1(B):
pass
- self.assertTrue(issubclass(B1, A))
- self.assertTrue(issubclass(B1, (A,)))
+ self.assertIsSubclass(B1, A)
+ self.assertIsSubclass(B1, (A,))
class C1(C):
pass
B1.register(C1)
- self.assertFalse(issubclass(C, B))
- self.assertFalse(issubclass(C, (B,)))
- self.assertFalse(issubclass(C, B1))
- self.assertFalse(issubclass(C, (B1,)))
- self.assertTrue(issubclass(C1, A))
- self.assertTrue(issubclass(C1, (A,)))
- self.assertTrue(issubclass(C1, B))
- self.assertTrue(issubclass(C1, (B,)))
- self.assertTrue(issubclass(C1, B1))
- self.assertTrue(issubclass(C1, (B1,)))
+ self.assertNotIsSubclass(C, B)
+ self.assertNotIsSubclass(C, (B,))
+ self.assertNotIsSubclass(C, B1)
+ self.assertNotIsSubclass(C, (B1,))
+ self.assertIsSubclass(C1, A)
+ self.assertIsSubclass(C1, (A,))
+ self.assertIsSubclass(C1, B)
+ self.assertIsSubclass(C1, (B,))
+ self.assertIsSubclass(C1, B1)
+ self.assertIsSubclass(C1, (B1,))
C1.register(int)
class MyInt(int):
pass
- self.assertTrue(issubclass(MyInt, A))
- self.assertTrue(issubclass(MyInt, (A,)))
+ self.assertIsSubclass(MyInt, A)
+ self.assertIsSubclass(MyInt, (A,))
self.assertIsInstance(42, A)
self.assertIsInstance(42, (A,))
@@ -467,16 +467,16 @@ def __subclasshook__(cls, C):
if cls is A:
return 'foo' in C.__dict__
return NotImplemented
- self.assertFalse(issubclass(A, A))
- self.assertFalse(issubclass(A, (A,)))
+ self.assertNotIsSubclass(A, A)
+ self.assertNotIsSubclass(A, (A,))
class B:
foo = 42
- self.assertTrue(issubclass(B, A))
- self.assertTrue(issubclass(B, (A,)))
+ self.assertIsSubclass(B, A)
+ self.assertIsSubclass(B, (A,))
class C:
spam = 42
- self.assertFalse(issubclass(C, A))
- self.assertFalse(issubclass(C, (A,)))
+ self.assertNotIsSubclass(C, A)
+ self.assertNotIsSubclass(C, (A,))
def test_all_new_methods_are_called(self):
class A(metaclass=abc_ABCMeta):
@@ -493,7 +493,7 @@ class C(A, B):
self.assertEqual(B.counter, 1)
def test_ABC_has___slots__(self):
- self.assertTrue(hasattr(abc.ABC, '__slots__'))
+ self.assertHasAttr(abc.ABC, '__slots__')
def test_tricky_new_works(self):
def with_metaclass(meta, *bases):
@@ -515,7 +515,7 @@ def foo(self):
del A.foo
self.assertEqual(A.__abstractmethods__, {'foo'})
- self.assertFalse(hasattr(A, 'foo'))
+ self.assertNotHasAttr(A, 'foo')
abc.update_abstractmethods(A)
@@ -588,7 +588,7 @@ def updated_foo(self):
A.foo = updated_foo
abc.update_abstractmethods(A)
A()
- self.assertFalse(hasattr(A, '__abstractmethods__'))
+ self.assertNotHasAttr(A, '__abstractmethods__')
def test_update_del_implementation(self):
class A(metaclass=abc_ABCMeta):
1
0
[3.13] gh-71339: Add additional assertion methods in test.support (GH-128707) (GH-128815)
by serhiy-storchaka Jan. 20, 2025
by serhiy-storchaka Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/c6a566e47b9903d48e6e1e78a1af20e6c6…
commit: c6a566e47b9903d48e6e1e78a1af20e6c6c535cf
branch: 3.13
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2025-01-20T11:19:00+02:00
summary:
[3.13] gh-71339: Add additional assertion methods in test.support (GH-128707) (GH-128815)
Add a mix-in class ExtraAssertions containing the following methods:
* assertHasAttr() and assertNotHasAttr()
* assertIsSubclass() and assertNotIsSubclass()
* assertStartsWith() and assertNotStartsWith()
* assertEndsWith() and assertNotEndsWith()
(cherry picked from commit 06cad77a5b345adde88609be9c3c470c5cd9f417)
files:
M Lib/test/support/testcase.py
M Lib/test/test_descr.py
M Lib/test/test_gdb/util.py
M Lib/test/test_importlib/resources/test_functional.py
M Lib/test/test_pyclbr.py
M Lib/test/test_typing.py
M Lib/test/test_venv.py
diff --git a/Lib/test/support/testcase.py b/Lib/test/support/testcase.py
index fad1e4cb3499c0..fd32457d1467ca 100644
--- a/Lib/test/support/testcase.py
+++ b/Lib/test/support/testcase.py
@@ -1,6 +1,63 @@
from math import copysign, isnan
+class ExtraAssertions:
+
+ def assertIsSubclass(self, cls, superclass, msg=None):
+ if issubclass(cls, superclass):
+ return
+ standardMsg = f'{cls!r} is not a subclass of {superclass!r}'
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertNotIsSubclass(self, cls, superclass, msg=None):
+ if not issubclass(cls, superclass):
+ return
+ standardMsg = f'{cls!r} is a subclass of {superclass!r}'
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertHasAttr(self, obj, name, msg=None):
+ if not hasattr(obj, name):
+ if isinstance(obj, types.ModuleType):
+ standardMsg = f'module {obj.__name__!r} has no attribute {name!r}'
+ elif isinstance(obj, type):
+ standardMsg = f'type object {obj.__name__!r} has no attribute {name!r}'
+ else:
+ standardMsg = f'{type(obj).__name__!r} object has no attribute {name!r}'
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertNotHasAttr(self, obj, name, msg=None):
+ if hasattr(obj, name):
+ if isinstance(obj, types.ModuleType):
+ standardMsg = f'module {obj.__name__!r} has unexpected attribute {name!r}'
+ elif isinstance(obj, type):
+ standardMsg = f'type object {obj.__name__!r} has unexpected attribute {name!r}'
+ else:
+ standardMsg = f'{type(obj).__name__!r} object has unexpected attribute {name!r}'
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertStartsWith(self, s, prefix, msg=None):
+ if s.startswith(prefix):
+ return
+ standardMsg = f"{s!r} doesn't start with {prefix!r}"
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertNotStartsWith(self, s, prefix, msg=None):
+ if not s.startswith(prefix):
+ return
+ self.fail(self._formatMessage(msg, f"{s!r} starts with {prefix!r}"))
+
+ def assertEndsWith(self, s, suffix, msg=None):
+ if s.endswith(suffix):
+ return
+ standardMsg = f"{s!r} doesn't end with {suffix!r}"
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertNotEndsWith(self, s, suffix, msg=None):
+ if not s.endswith(suffix):
+ return
+ self.fail(self._formatMessage(msg, f"{s!r} ends with {suffix!r}"))
+
+
class ExceptionIsLikeMixin:
def assertExceptionIsLike(self, exc, template):
"""
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 14bd87eb9c8d84..dd1fa321ecf171 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -15,6 +15,7 @@
from copy import deepcopy
from contextlib import redirect_stdout
from test import support
+from test.support.testcase import ExtraAssertions
try:
import _testcapi
@@ -403,15 +404,7 @@ def test_wrap_lenfunc_bad_cast(self):
self.assertEqual(range(sys.maxsize).__len__(), sys.maxsize)
-class ClassPropertiesAndMethods(unittest.TestCase):
-
- def assertHasAttr(self, obj, name):
- self.assertTrue(hasattr(obj, name),
- '%r has no attribute %r' % (obj, name))
-
- def assertNotHasAttr(self, obj, name):
- self.assertFalse(hasattr(obj, name),
- '%r has unexpected attribute %r' % (obj, name))
+class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
def test_python_dicts(self):
# Testing Python subclass of dict...
diff --git a/Lib/test/test_gdb/util.py b/Lib/test/test_gdb/util.py
index 8fe9cfc543395e..54c6b2de7cc99d 100644
--- a/Lib/test/test_gdb/util.py
+++ b/Lib/test/test_gdb/util.py
@@ -7,6 +7,7 @@
import sysconfig
import unittest
from test import support
+from test.support.testcase import ExtraAssertions
GDB_PROGRAM = shutil.which('gdb') or 'gdb'
@@ -152,7 +153,7 @@ def setup_module():
print()
-class DebuggerTests(unittest.TestCase):
+class DebuggerTests(unittest.TestCase, ExtraAssertions):
"""Test that the debugger can debug Python."""
@@ -280,11 +281,6 @@ def get_stack_trace(self, source=None, script=None,
return out
- def assertEndsWith(self, actual, exp_end):
- '''Ensure that the given "actual" string ends with "exp_end"'''
- self.assertTrue(actual.endswith(exp_end),
- msg='%r did not end with %r' % (actual, exp_end))
-
def assertMultilineMatches(self, actual, pattern):
m = re.match(pattern, actual, re.DOTALL)
if not m:
diff --git a/Lib/test/test_importlib/resources/test_functional.py b/Lib/test/test_importlib/resources/test_functional.py
index 4317abf3162c52..3fc1ade35bef5a 100644
--- a/Lib/test/test_importlib/resources/test_functional.py
+++ b/Lib/test/test_importlib/resources/test_functional.py
@@ -3,6 +3,7 @@
import importlib
from test.support import warnings_helper
+from test.support.testcase import ExtraAssertions
from importlib import resources
@@ -28,7 +29,7 @@ def anchor02(self):
return importlib.import_module('data02')
-class FunctionalAPIBase(util.DiskSetup):
+class FunctionalAPIBase(util.DiskSetup, ExtraAssertions):
def setUp(self):
super().setUp()
self.load_fixture('data02')
@@ -43,12 +44,6 @@ def _gen_resourcetxt_path_parts(self):
with self.subTest(path_parts=path_parts):
yield path_parts
- def assertEndsWith(self, string, suffix):
- """Assert that `string` ends with `suffix`.
-
- Used to ignore an architecture-specific UTF-16 byte-order mark."""
- self.assertEqual(string[-len(suffix) :], suffix)
-
def test_read_text(self):
self.assertEqual(
resources.read_text(self.anchor01, 'utf-8.file'),
diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py
index d409a2d4a312e6..a65705aaf53abc 100644
--- a/Lib/test/test_pyclbr.py
+++ b/Lib/test/test_pyclbr.py
@@ -10,6 +10,7 @@
from unittest import TestCase, main as unittest_main
from test.test_importlib import util as test_importlib_util
import warnings
+from test.support.testcase import ExtraAssertions
StaticMethodType = type(staticmethod(lambda: None))
@@ -22,7 +23,7 @@
# is imperfect (as designed), testModule is called with a set of
# members to ignore.
-class PyclbrTest(TestCase):
+class PyclbrTest(TestCase, ExtraAssertions):
def assertListEq(self, l1, l2, ignore):
''' succeed iff {l1} - {ignore} == {l2} - {ignore} '''
@@ -31,14 +32,6 @@ def assertListEq(self, l1, l2, ignore):
print("l1=%r\nl2=%r\nignore=%r" % (l1, l2, ignore), file=sys.stderr)
self.fail("%r missing" % missing.pop())
- def assertHasattr(self, obj, attr, ignore):
- ''' succeed iff hasattr(obj,attr) or attr in ignore. '''
- if attr in ignore: return
- if not hasattr(obj, attr): print("???", attr)
- self.assertTrue(hasattr(obj, attr),
- 'expected hasattr(%r, %r)' % (obj, attr))
-
-
def assertHaskey(self, obj, key, ignore):
''' succeed iff key in obj or key in ignore. '''
if key in ignore: return
@@ -86,7 +79,7 @@ def ismethod(oclass, obj, name):
for name, value in dict.items():
if name in ignore:
continue
- self.assertHasattr(module, name, ignore)
+ self.assertHasAttr(module, name, ignore)
py_item = getattr(module, name)
if isinstance(value, pyclbr.Function):
self.assertIsInstance(py_item, (FunctionType, BuiltinFunctionType))
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 140ceb74735570..89a32c7a1a0d14 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -46,6 +46,7 @@
import types
from test.support import captured_stderr, cpython_only, infinite_recursion, requires_docstrings, import_helper
+from test.support.testcase import ExtraAssertions
from test.typinganndata import ann_module695, mod_generics_cache, _typed_dict_helper
@@ -54,21 +55,7 @@
CANNOT_SUBCLASS_INSTANCE = 'Cannot subclass an instance of %s'
-class BaseTestCase(TestCase):
-
- def assertIsSubclass(self, cls, class_or_tuple, msg=None):
- if not issubclass(cls, class_or_tuple):
- message = '%r is not a subclass of %r' % (cls, class_or_tuple)
- if msg is not None:
- message += ' : %s' % msg
- raise self.failureException(message)
-
- def assertNotIsSubclass(self, cls, class_or_tuple, msg=None):
- if issubclass(cls, class_or_tuple):
- message = '%r is a subclass of %r' % (cls, class_or_tuple)
- if msg is not None:
- message += ' : %s' % msg
- raise self.failureException(message)
+class BaseTestCase(TestCase, ExtraAssertions):
def clear_caches(self):
for f in typing._cleanups:
@@ -1249,10 +1236,6 @@ class Gen[*Ts]: ...
class TypeVarTupleTests(BaseTestCase):
- def assertEndsWith(self, string, tail):
- if not string.endswith(tail):
- self.fail(f"String {string!r} does not end with {tail!r}")
-
def test_name(self):
Ts = TypeVarTuple('Ts')
self.assertEqual(Ts.__name__, 'Ts')
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
index 0b09010c69d4ea..c39c83f9d0a5c3 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -26,6 +26,7 @@
requires_resource, copy_python_src_ignore)
from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree,
TESTFN, FakePath)
+from test.support.testcase import ExtraAssertions
import unittest
import venv
from unittest.mock import patch, Mock
@@ -64,7 +65,7 @@ def check_output(cmd, encoding=None):
)
return out, err
-class BaseTest(unittest.TestCase):
+class BaseTest(unittest.TestCase, ExtraAssertions):
"""Base class for venv tests."""
maxDiff = 80 * 50
@@ -111,10 +112,6 @@ def get_text_file_contents(self, *args, encoding='utf-8'):
result = f.read()
return result
- def assertEndsWith(self, string, tail):
- if not string.endswith(tail):
- self.fail(f"String {string!r} does not end with {tail!r}")
-
class BasicTest(BaseTest):
"""Test venv module functionality."""
1
0
gh-71339: Improve error report for types in assertHasAttr() and assertNotHasAttr() (GH-128818)
by serhiy-storchaka Jan. 20, 2025
by serhiy-storchaka Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/da122b5facbbae9197a108e0a3c4b3f059…
commit: da122b5facbbae9197a108e0a3c4b3f0594c5e92
branch: main
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2025-01-20T11:17:49+02:00
summary:
gh-71339: Improve error report for types in assertHasAttr() and assertNotHasAttr() (GH-128818)
files:
M Lib/test/test_unittest/test_case.py
M Lib/unittest/case.py
diff --git a/Lib/test/test_unittest/test_case.py b/Lib/test/test_unittest/test_case.py
index cd366496eedca3..df1381451b7ebc 100644
--- a/Lib/test/test_unittest/test_case.py
+++ b/Lib/test/test_unittest/test_case.py
@@ -795,7 +795,15 @@ def testAssertHasAttr(self):
with self.assertRaises(self.failureException) as cm:
self.assertHasAttr(a, 'y')
self.assertEqual(str(cm.exception),
- "List instance has no attribute 'y'")
+ "'List' object has no attribute 'y'")
+ with self.assertRaises(self.failureException) as cm:
+ self.assertHasAttr(List, 'spam')
+ self.assertEqual(str(cm.exception),
+ "type object 'List' has no attribute 'spam'")
+ with self.assertRaises(self.failureException) as cm:
+ self.assertHasAttr(sys, 'spam')
+ self.assertEqual(str(cm.exception),
+ "module 'sys' has no attribute 'spam'")
with self.assertRaises(self.failureException) as cm:
self.assertHasAttr(a, 'y', 'ababahalamaha')
@@ -811,7 +819,15 @@ def testAssertNotHasAttr(self):
with self.assertRaises(self.failureException) as cm:
self.assertNotHasAttr(a, 'x')
self.assertEqual(str(cm.exception),
- "List instance has unexpected attribute 'x'")
+ "'List' object has unexpected attribute 'x'")
+ with self.assertRaises(self.failureException) as cm:
+ self.assertNotHasAttr(List, 'append')
+ self.assertEqual(str(cm.exception),
+ "type object 'List' has unexpected attribute 'append'")
+ with self.assertRaises(self.failureException) as cm:
+ self.assertNotHasAttr(sys, 'modules')
+ self.assertEqual(str(cm.exception),
+ "module 'sys' has unexpected attribute 'modules'")
with self.assertRaises(self.failureException) as cm:
self.assertNotHasAttr(a, 'x', 'ababahalamaha')
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index e9ef551d0b3ded..10c3b7e122371e 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -1372,16 +1372,20 @@ def assertHasAttr(self, obj, name, msg=None):
if not hasattr(obj, name):
if isinstance(obj, types.ModuleType):
standardMsg = f'module {obj.__name__!r} has no attribute {name!r}'
+ elif isinstance(obj, type):
+ standardMsg = f'type object {obj.__name__!r} has no attribute {name!r}'
else:
- standardMsg = f'{type(obj).__name__} instance has no attribute {name!r}'
+ standardMsg = f'{type(obj).__name__!r} object has no attribute {name!r}'
self.fail(self._formatMessage(msg, standardMsg))
def assertNotHasAttr(self, obj, name, msg=None):
if hasattr(obj, name):
if isinstance(obj, types.ModuleType):
standardMsg = f'module {obj.__name__!r} has unexpected attribute {name!r}'
+ elif isinstance(obj, type):
+ standardMsg = f'type object {obj.__name__!r} has unexpected attribute {name!r}'
else:
- standardMsg = f'{type(obj).__name__} instance has unexpected attribute {name!r}'
+ standardMsg = f'{type(obj).__name__!r} object has unexpected attribute {name!r}'
self.fail(self._formatMessage(msg, standardMsg))
def assertRaisesRegex(self, expected_exception, expected_regex,
1
0
Jan. 20, 2025
https://github.com/python/cpython/commit/89c401fb9a612b9618bd513508e67deded…
commit: 89c401fb9a612b9618bd513508e67dededb0f031
branch: main
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2025-01-20T11:17:04+02:00
summary:
gh-71339: Use new assertion methods in test_functools (GH-128829)
files:
M Lib/test/test_functools.py
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 32224866082824..4beb4380c3ad6b 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -645,11 +645,11 @@ def test_bound_method_introspection(self):
def test_unbound_method_retrieval(self):
obj = self.A
- self.assertFalse(hasattr(obj.both, "__self__"))
- self.assertFalse(hasattr(obj.nested, "__self__"))
- self.assertFalse(hasattr(obj.over_partial, "__self__"))
- self.assertFalse(hasattr(obj.static, "__self__"))
- self.assertFalse(hasattr(self.a.static, "__self__"))
+ self.assertNotHasAttr(obj.both, "__self__")
+ self.assertNotHasAttr(obj.nested, "__self__")
+ self.assertNotHasAttr(obj.over_partial, "__self__")
+ self.assertNotHasAttr(obj.static, "__self__")
+ self.assertNotHasAttr(self.a.static, "__self__")
def test_descriptors(self):
for obj in [self.A, self.a]:
@@ -791,7 +791,7 @@ def wrapper():
self.assertNotEqual(wrapper.__qualname__, f.__qualname__)
self.assertEqual(wrapper.__doc__, None)
self.assertEqual(wrapper.__annotations__, {})
- self.assertFalse(hasattr(wrapper, 'attr'))
+ self.assertNotHasAttr(wrapper, 'attr')
def test_selective_update(self):
def f():
@@ -840,7 +840,7 @@ def wrapper():
pass
functools.update_wrapper(wrapper, max)
self.assertEqual(wrapper.__name__, 'max')
- self.assertTrue(wrapper.__doc__.startswith('max('))
+ self.assertStartsWith(wrapper.__doc__, 'max(')
self.assertEqual(wrapper.__annotations__, {})
def test_update_type_wrapper(self):
@@ -910,7 +910,7 @@ def wrapper():
self.assertEqual(wrapper.__name__, 'wrapper')
self.assertNotEqual(wrapper.__qualname__, f.__qualname__)
self.assertEqual(wrapper.__doc__, None)
- self.assertFalse(hasattr(wrapper, 'attr'))
+ self.assertNotHasAttr(wrapper, 'attr')
def test_selective_update(self):
def f():
@@ -2666,15 +2666,15 @@ def _(self, arg):
a.t(0)
self.assertEqual(a.arg, "int")
aa = A()
- self.assertFalse(hasattr(aa, 'arg'))
+ self.assertNotHasAttr(aa, 'arg')
a.t('')
self.assertEqual(a.arg, "str")
aa = A()
- self.assertFalse(hasattr(aa, 'arg'))
+ self.assertNotHasAttr(aa, 'arg')
a.t(0.0)
self.assertEqual(a.arg, "base")
aa = A()
- self.assertFalse(hasattr(aa, 'arg'))
+ self.assertNotHasAttr(aa, 'arg')
def test_staticmethod_register(self):
class A:
@@ -3036,16 +3036,16 @@ def i(arg):
@i.register(42)
def _(arg):
return "I annotated with a non-type"
- self.assertTrue(str(exc.exception).startswith(msg_prefix + "42"))
- self.assertTrue(str(exc.exception).endswith(msg_suffix))
+ self.assertStartsWith(str(exc.exception), msg_prefix + "42")
+ self.assertEndsWith(str(exc.exception), msg_suffix)
with self.assertRaises(TypeError) as exc:
@i.register
def _(arg):
return "I forgot to annotate"
- self.assertTrue(str(exc.exception).startswith(msg_prefix +
+ self.assertStartsWith(str(exc.exception), msg_prefix +
"<function TestSingleDispatch.test_invalid_registrations.<locals>._"
- ))
- self.assertTrue(str(exc.exception).endswith(msg_suffix))
+ )
+ self.assertEndsWith(str(exc.exception), msg_suffix)
with self.assertRaises(TypeError) as exc:
@i.register
@@ -3055,23 +3055,23 @@ def _(arg: typing.Iterable[str]):
# types from `typing`. Instead, annotate with regular types
# or ABCs.
return "I annotated with a generic collection"
- self.assertTrue(str(exc.exception).startswith(
+ self.assertStartsWith(str(exc.exception),
"Invalid annotation for 'arg'."
- ))
- self.assertTrue(str(exc.exception).endswith(
+ )
+ self.assertEndsWith(str(exc.exception),
'typing.Iterable[str] is not a class.'
- ))
+ )
with self.assertRaises(TypeError) as exc:
@i.register
def _(arg: typing.Union[int, typing.Iterable[str]]):
return "Invalid Union"
- self.assertTrue(str(exc.exception).startswith(
+ self.assertStartsWith(str(exc.exception),
"Invalid annotation for 'arg'."
- ))
- self.assertTrue(str(exc.exception).endswith(
+ )
+ self.assertEndsWith(str(exc.exception),
'typing.Union[int, typing.Iterable[str]] not all arguments are classes.'
- ))
+ )
def test_invalid_positional_argument(self):
@functools.singledispatch
1
0
gh-71339: Use assertIsSubclass() and assertNotIsSubclass() in test_collections (GH-128824)
by serhiy-storchaka Jan. 20, 2025
by serhiy-storchaka Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/887f2bcf48eaa13363f9276fdaa9e6b22d…
commit: 887f2bcf48eaa13363f9276fdaa9e6b22deaeb65
branch: main
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2025-01-20T11:16:32+02:00
summary:
gh-71339: Use assertIsSubclass() and assertNotIsSubclass() in test_collections (GH-128824)
files:
M Lib/test/test_collections.py
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index a24d3e3ea142b7..1e93530398be79 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -742,11 +742,11 @@ def validate_isinstance(self, abc, name):
C = type('C', (object,), {'__hash__': None})
setattr(C, name, stub)
self.assertIsInstance(C(), abc)
- self.assertTrue(issubclass(C, abc))
+ self.assertIsSubclass(C, abc)
C = type('C', (object,), {'__hash__': None})
self.assertNotIsInstance(C(), abc)
- self.assertFalse(issubclass(C, abc))
+ self.assertNotIsSubclass(C, abc)
def validate_comparison(self, instance):
ops = ['lt', 'gt', 'le', 'ge', 'ne', 'or', 'and', 'xor', 'sub']
@@ -812,12 +812,12 @@ def __await__(self):
non_samples = [None, int(), gen(), object()]
for x in non_samples:
self.assertNotIsInstance(x, Awaitable)
- self.assertFalse(issubclass(type(x), Awaitable), repr(type(x)))
+ self.assertNotIsSubclass(type(x), Awaitable)
samples = [Bar(), MinimalCoro()]
for x in samples:
self.assertIsInstance(x, Awaitable)
- self.assertTrue(issubclass(type(x), Awaitable))
+ self.assertIsSubclass(type(x), Awaitable)
c = coro()
# Iterable coroutines (generators with CO_ITERABLE_COROUTINE
@@ -831,8 +831,8 @@ def __await__(self):
class CoroLike: pass
Coroutine.register(CoroLike)
- self.assertTrue(isinstance(CoroLike(), Awaitable))
- self.assertTrue(issubclass(CoroLike, Awaitable))
+ self.assertIsInstance(CoroLike(), Awaitable)
+ self.assertIsSubclass(CoroLike, Awaitable)
CoroLike = None
support.gc_collect() # Kill CoroLike to clean-up ABCMeta cache
@@ -864,12 +864,12 @@ def __await__(self):
non_samples = [None, int(), gen(), object(), Bar()]
for x in non_samples:
self.assertNotIsInstance(x, Coroutine)
- self.assertFalse(issubclass(type(x), Coroutine), repr(type(x)))
+ self.assertNotIsSubclass(type(x), Coroutine)
samples = [MinimalCoro()]
for x in samples:
self.assertIsInstance(x, Awaitable)
- self.assertTrue(issubclass(type(x), Awaitable))
+ self.assertIsSubclass(type(x), Awaitable)
c = coro()
# Iterable coroutines (generators with CO_ITERABLE_COROUTINE
@@ -890,8 +890,8 @@ def close(self):
pass
def __await__(self):
pass
- self.assertTrue(isinstance(CoroLike(), Coroutine))
- self.assertTrue(issubclass(CoroLike, Coroutine))
+ self.assertIsInstance(CoroLike(), Coroutine)
+ self.assertIsSubclass(CoroLike, Coroutine)
class CoroLike:
def send(self, value):
@@ -900,15 +900,15 @@ def close(self):
pass
def __await__(self):
pass
- self.assertFalse(isinstance(CoroLike(), Coroutine))
- self.assertFalse(issubclass(CoroLike, Coroutine))
+ self.assertNotIsInstance(CoroLike(), Coroutine)
+ self.assertNotIsSubclass(CoroLike, Coroutine)
def test_Hashable(self):
# Check some non-hashables
non_samples = [bytearray(), list(), set(), dict()]
for x in non_samples:
self.assertNotIsInstance(x, Hashable)
- self.assertFalse(issubclass(type(x), Hashable), repr(type(x)))
+ self.assertNotIsSubclass(type(x), Hashable)
# Check some hashables
samples = [None,
int(), float(), complex(),
@@ -918,14 +918,14 @@ def test_Hashable(self):
]
for x in samples:
self.assertIsInstance(x, Hashable)
- self.assertTrue(issubclass(type(x), Hashable), repr(type(x)))
+ self.assertIsSubclass(type(x), Hashable)
self.assertRaises(TypeError, Hashable)
# Check direct subclassing
class H(Hashable):
def __hash__(self):
return super().__hash__()
self.assertEqual(hash(H()), 0)
- self.assertFalse(issubclass(int, H))
+ self.assertNotIsSubclass(int, H)
self.validate_abstract_methods(Hashable, '__hash__')
self.validate_isinstance(Hashable, '__hash__')
@@ -933,13 +933,13 @@ def test_AsyncIterable(self):
class AI:
def __aiter__(self):
return self
- self.assertTrue(isinstance(AI(), AsyncIterable))
- self.assertTrue(issubclass(AI, AsyncIterable))
+ self.assertIsInstance(AI(), AsyncIterable)
+ self.assertIsSubclass(AI, AsyncIterable)
# Check some non-iterables
non_samples = [None, object, []]
for x in non_samples:
self.assertNotIsInstance(x, AsyncIterable)
- self.assertFalse(issubclass(type(x), AsyncIterable), repr(type(x)))
+ self.assertNotIsSubclass(type(x), AsyncIterable)
self.validate_abstract_methods(AsyncIterable, '__aiter__')
self.validate_isinstance(AsyncIterable, '__aiter__')
@@ -949,13 +949,13 @@ def __aiter__(self):
return self
async def __anext__(self):
raise StopAsyncIteration
- self.assertTrue(isinstance(AI(), AsyncIterator))
- self.assertTrue(issubclass(AI, AsyncIterator))
+ self.assertIsInstance(AI(), AsyncIterator)
+ self.assertIsSubclass(AI, AsyncIterator)
non_samples = [None, object, []]
# Check some non-iterables
for x in non_samples:
self.assertNotIsInstance(x, AsyncIterator)
- self.assertFalse(issubclass(type(x), AsyncIterator), repr(type(x)))
+ self.assertNotIsSubclass(type(x), AsyncIterator)
# Similarly to regular iterators (see issue 10565)
class AnextOnly:
async def __anext__(self):
@@ -968,7 +968,7 @@ def test_Iterable(self):
non_samples = [None, 42, 3.14, 1j]
for x in non_samples:
self.assertNotIsInstance(x, Iterable)
- self.assertFalse(issubclass(type(x), Iterable), repr(type(x)))
+ self.assertNotIsSubclass(type(x), Iterable)
# Check some iterables
samples = [bytes(), str(),
tuple(), list(), set(), frozenset(), dict(),
@@ -978,13 +978,13 @@ def test_Iterable(self):
]
for x in samples:
self.assertIsInstance(x, Iterable)
- self.assertTrue(issubclass(type(x), Iterable), repr(type(x)))
+ self.assertIsSubclass(type(x), Iterable)
# Check direct subclassing
class I(Iterable):
def __iter__(self):
return super().__iter__()
self.assertEqual(list(I()), [])
- self.assertFalse(issubclass(str, I))
+ self.assertNotIsSubclass(str, I)
self.validate_abstract_methods(Iterable, '__iter__')
self.validate_isinstance(Iterable, '__iter__')
# Check None blocking
@@ -992,22 +992,22 @@ class It:
def __iter__(self): return iter([])
class ItBlocked(It):
__iter__ = None
- self.assertTrue(issubclass(It, Iterable))
- self.assertTrue(isinstance(It(), Iterable))
- self.assertFalse(issubclass(ItBlocked, Iterable))
- self.assertFalse(isinstance(ItBlocked(), Iterable))
+ self.assertIsSubclass(It, Iterable)
+ self.assertIsInstance(It(), Iterable)
+ self.assertNotIsSubclass(ItBlocked, Iterable)
+ self.assertNotIsInstance(ItBlocked(), Iterable)
def test_Reversible(self):
# Check some non-reversibles
non_samples = [None, 42, 3.14, 1j, set(), frozenset()]
for x in non_samples:
self.assertNotIsInstance(x, Reversible)
- self.assertFalse(issubclass(type(x), Reversible), repr(type(x)))
+ self.assertNotIsSubclass(type(x), Reversible)
# Check some non-reversible iterables
non_reversibles = [_test_gen(), (x for x in []), iter([]), reversed([])]
for x in non_reversibles:
self.assertNotIsInstance(x, Reversible)
- self.assertFalse(issubclass(type(x), Reversible), repr(type(x)))
+ self.assertNotIsSubclass(type(x), Reversible)
# Check some reversible iterables
samples = [bytes(), str(), tuple(), list(), OrderedDict(),
OrderedDict().keys(), OrderedDict().items(),
@@ -1016,11 +1016,11 @@ def test_Reversible(self):
dict().keys(), dict().items(), dict().values()]
for x in samples:
self.assertIsInstance(x, Reversible)
- self.assertTrue(issubclass(type(x), Reversible), repr(type(x)))
+ self.assertIsSubclass(type(x), Reversible)
# Check also Mapping, MutableMapping, and Sequence
- self.assertTrue(issubclass(Sequence, Reversible), repr(Sequence))
- self.assertFalse(issubclass(Mapping, Reversible), repr(Mapping))
- self.assertFalse(issubclass(MutableMapping, Reversible), repr(MutableMapping))
+ self.assertIsSubclass(Sequence, Reversible)
+ self.assertNotIsSubclass(Mapping, Reversible)
+ self.assertNotIsSubclass(MutableMapping, Reversible)
# Check direct subclassing
class R(Reversible):
def __iter__(self):
@@ -1028,17 +1028,17 @@ def __iter__(self):
def __reversed__(self):
return iter(list())
self.assertEqual(list(reversed(R())), [])
- self.assertFalse(issubclass(float, R))
+ self.assertNotIsSubclass(float, R)
self.validate_abstract_methods(Reversible, '__reversed__', '__iter__')
# Check reversible non-iterable (which is not Reversible)
class RevNoIter:
def __reversed__(self): return reversed([])
class RevPlusIter(RevNoIter):
def __iter__(self): return iter([])
- self.assertFalse(issubclass(RevNoIter, Reversible))
- self.assertFalse(isinstance(RevNoIter(), Reversible))
- self.assertTrue(issubclass(RevPlusIter, Reversible))
- self.assertTrue(isinstance(RevPlusIter(), Reversible))
+ self.assertNotIsSubclass(RevNoIter, Reversible)
+ self.assertNotIsInstance(RevNoIter(), Reversible)
+ self.assertIsSubclass(RevPlusIter, Reversible)
+ self.assertIsInstance(RevPlusIter(), Reversible)
# Check None blocking
class Rev:
def __iter__(self): return iter([])
@@ -1047,39 +1047,38 @@ class RevItBlocked(Rev):
__iter__ = None
class RevRevBlocked(Rev):
__reversed__ = None
- self.assertTrue(issubclass(Rev, Reversible))
- self.assertTrue(isinstance(Rev(), Reversible))
- self.assertFalse(issubclass(RevItBlocked, Reversible))
- self.assertFalse(isinstance(RevItBlocked(), Reversible))
- self.assertFalse(issubclass(RevRevBlocked, Reversible))
- self.assertFalse(isinstance(RevRevBlocked(), Reversible))
+ self.assertIsSubclass(Rev, Reversible)
+ self.assertIsInstance(Rev(), Reversible)
+ self.assertNotIsSubclass(RevItBlocked, Reversible)
+ self.assertNotIsInstance(RevItBlocked(), Reversible)
+ self.assertNotIsSubclass(RevRevBlocked, Reversible)
+ self.assertNotIsInstance(RevRevBlocked(), Reversible)
def test_Collection(self):
# Check some non-collections
non_collections = [None, 42, 3.14, 1j, lambda x: 2*x]
for x in non_collections:
self.assertNotIsInstance(x, Collection)
- self.assertFalse(issubclass(type(x), Collection), repr(type(x)))
+ self.assertNotIsSubclass(type(x), Collection)
# Check some non-collection iterables
non_col_iterables = [_test_gen(), iter(b''), iter(bytearray()),
(x for x in [])]
for x in non_col_iterables:
self.assertNotIsInstance(x, Collection)
- self.assertFalse(issubclass(type(x), Collection), repr(type(x)))
+ self.assertNotIsSubclass(type(x), Collection)
# Check some collections
samples = [set(), frozenset(), dict(), bytes(), str(), tuple(),
list(), dict().keys(), dict().items(), dict().values()]
for x in samples:
self.assertIsInstance(x, Collection)
- self.assertTrue(issubclass(type(x), Collection), repr(type(x)))
+ self.assertIsSubclass(type(x), Collection)
# Check also Mapping, MutableMapping, etc.
- self.assertTrue(issubclass(Sequence, Collection), repr(Sequence))
- self.assertTrue(issubclass(Mapping, Collection), repr(Mapping))
- self.assertTrue(issubclass(MutableMapping, Collection),
- repr(MutableMapping))
- self.assertTrue(issubclass(Set, Collection), repr(Set))
- self.assertTrue(issubclass(MutableSet, Collection), repr(MutableSet))
- self.assertTrue(issubclass(Sequence, Collection), repr(MutableSet))
+ self.assertIsSubclass(Sequence, Collection)
+ self.assertIsSubclass(Mapping, Collection)
+ self.assertIsSubclass(MutableMapping, Collection)
+ self.assertIsSubclass(Set, Collection)
+ self.assertIsSubclass(MutableSet, Collection)
+ self.assertIsSubclass(Sequence, Collection)
# Check direct subclassing
class Col(Collection):
def __iter__(self):
@@ -1090,13 +1089,13 @@ def __contains__(self, item):
return False
class DerCol(Col): pass
self.assertEqual(list(iter(Col())), [])
- self.assertFalse(issubclass(list, Col))
- self.assertFalse(issubclass(set, Col))
- self.assertFalse(issubclass(float, Col))
+ self.assertNotIsSubclass(list, Col)
+ self.assertNotIsSubclass(set, Col)
+ self.assertNotIsSubclass(float, Col)
self.assertEqual(list(iter(DerCol())), [])
- self.assertFalse(issubclass(list, DerCol))
- self.assertFalse(issubclass(set, DerCol))
- self.assertFalse(issubclass(float, DerCol))
+ self.assertNotIsSubclass(list, DerCol)
+ self.assertNotIsSubclass(set, DerCol)
+ self.assertNotIsSubclass(float, DerCol)
self.validate_abstract_methods(Collection, '__len__', '__iter__',
'__contains__')
# Check sized container non-iterable (which is not Collection) etc.
@@ -1109,12 +1108,12 @@ def __contains__(self, item): return False
class ColNoCont:
def __iter__(self): return iter([])
def __len__(self): return 0
- self.assertFalse(issubclass(ColNoIter, Collection))
- self.assertFalse(isinstance(ColNoIter(), Collection))
- self.assertFalse(issubclass(ColNoSize, Collection))
- self.assertFalse(isinstance(ColNoSize(), Collection))
- self.assertFalse(issubclass(ColNoCont, Collection))
- self.assertFalse(isinstance(ColNoCont(), Collection))
+ self.assertNotIsSubclass(ColNoIter, Collection)
+ self.assertNotIsInstance(ColNoIter(), Collection)
+ self.assertNotIsSubclass(ColNoSize, Collection)
+ self.assertNotIsInstance(ColNoSize(), Collection)
+ self.assertNotIsSubclass(ColNoCont, Collection)
+ self.assertNotIsInstance(ColNoCont(), Collection)
# Check None blocking
class SizeBlock:
def __iter__(self): return iter([])
@@ -1124,10 +1123,10 @@ class IterBlock:
def __len__(self): return 0
def __contains__(self): return True
__iter__ = None
- self.assertFalse(issubclass(SizeBlock, Collection))
- self.assertFalse(isinstance(SizeBlock(), Collection))
- self.assertFalse(issubclass(IterBlock, Collection))
- self.assertFalse(isinstance(IterBlock(), Collection))
+ self.assertNotIsSubclass(SizeBlock, Collection)
+ self.assertNotIsInstance(SizeBlock(), Collection)
+ self.assertNotIsSubclass(IterBlock, Collection)
+ self.assertNotIsInstance(IterBlock(), Collection)
# Check None blocking in subclass
class ColImpl:
def __iter__(self):
@@ -1138,15 +1137,15 @@ def __contains__(self, item):
return False
class NonCol(ColImpl):
__contains__ = None
- self.assertFalse(issubclass(NonCol, Collection))
- self.assertFalse(isinstance(NonCol(), Collection))
+ self.assertNotIsSubclass(NonCol, Collection)
+ self.assertNotIsInstance(NonCol(), Collection)
def test_Iterator(self):
non_samples = [None, 42, 3.14, 1j, b"", "", (), [], {}, set()]
for x in non_samples:
self.assertNotIsInstance(x, Iterator)
- self.assertFalse(issubclass(type(x), Iterator), repr(type(x)))
+ self.assertNotIsSubclass(type(x), Iterator)
samples = [iter(bytes()), iter(str()),
iter(tuple()), iter(list()), iter(dict()),
iter(set()), iter(frozenset()),
@@ -1157,7 +1156,7 @@ def test_Iterator(self):
]
for x in samples:
self.assertIsInstance(x, Iterator)
- self.assertTrue(issubclass(type(x), Iterator), repr(type(x)))
+ self.assertIsSubclass(type(x), Iterator)
self.validate_abstract_methods(Iterator, '__next__', '__iter__')
# Issue 10565
@@ -1190,7 +1189,7 @@ def throw(self, typ, val=None, tb=None): pass
iter(()), iter([]), NonGen1(), NonGen2(), NonGen3()]
for x in non_samples:
self.assertNotIsInstance(x, Generator)
- self.assertFalse(issubclass(type(x), Generator), repr(type(x)))
+ self.assertNotIsSubclass(type(x), Generator)
class Gen:
def __iter__(self): return self
@@ -1212,7 +1211,7 @@ def gen():
for x in samples:
self.assertIsInstance(x, Iterator)
self.assertIsInstance(x, Generator)
- self.assertTrue(issubclass(type(x), Generator), repr(type(x)))
+ self.assertIsSubclass(type(x), Generator)
self.validate_abstract_methods(Generator, 'send', 'throw')
# mixin tests
@@ -1261,7 +1260,7 @@ def athrow(self, typ, val=None, tb=None): pass
iter(()), iter([]), NonAGen1(), NonAGen2(), NonAGen3()]
for x in non_samples:
self.assertNotIsInstance(x, AsyncGenerator)
- self.assertFalse(issubclass(type(x), AsyncGenerator), repr(type(x)))
+ self.assertNotIsSubclass(type(x), AsyncGenerator)
class Gen:
def __aiter__(self): return self
@@ -1283,7 +1282,7 @@ async def gen():
for x in samples:
self.assertIsInstance(x, AsyncIterator)
self.assertIsInstance(x, AsyncGenerator)
- self.assertTrue(issubclass(type(x), AsyncGenerator), repr(type(x)))
+ self.assertIsSubclass(type(x), AsyncGenerator)
self.validate_abstract_methods(AsyncGenerator, 'asend', 'athrow')
def run_async(coro):
@@ -1326,14 +1325,14 @@ def test_Sized(self):
]
for x in non_samples:
self.assertNotIsInstance(x, Sized)
- self.assertFalse(issubclass(type(x), Sized), repr(type(x)))
+ self.assertNotIsSubclass(type(x), Sized)
samples = [bytes(), str(),
tuple(), list(), set(), frozenset(), dict(),
dict().keys(), dict().items(), dict().values(),
]
for x in samples:
self.assertIsInstance(x, Sized)
- self.assertTrue(issubclass(type(x), Sized), repr(type(x)))
+ self.assertIsSubclass(type(x), Sized)
self.validate_abstract_methods(Sized, '__len__')
self.validate_isinstance(Sized, '__len__')
@@ -1344,14 +1343,14 @@ def test_Container(self):
]
for x in non_samples:
self.assertNotIsInstance(x, Container)
- self.assertFalse(issubclass(type(x), Container), repr(type(x)))
+ self.assertNotIsSubclass(type(x), Container)
samples = [bytes(), str(),
tuple(), list(), set(), frozenset(), dict(),
dict().keys(), dict().items(),
]
for x in samples:
self.assertIsInstance(x, Container)
- self.assertTrue(issubclass(type(x), Container), repr(type(x)))
+ self.assertIsSubclass(type(x), Container)
self.validate_abstract_methods(Container, '__contains__')
self.validate_isinstance(Container, '__contains__')
@@ -1363,7 +1362,7 @@ def test_Callable(self):
]
for x in non_samples:
self.assertNotIsInstance(x, Callable)
- self.assertFalse(issubclass(type(x), Callable), repr(type(x)))
+ self.assertNotIsSubclass(type(x), Callable)
samples = [lambda: None,
type, int, object,
len,
@@ -1371,7 +1370,7 @@ def test_Callable(self):
]
for x in samples:
self.assertIsInstance(x, Callable)
- self.assertTrue(issubclass(type(x), Callable), repr(type(x)))
+ self.assertIsSubclass(type(x), Callable)
self.validate_abstract_methods(Callable, '__call__')
self.validate_isinstance(Callable, '__call__')
@@ -1379,16 +1378,16 @@ def test_direct_subclassing(self):
for B in Hashable, Iterable, Iterator, Reversible, Sized, Container, Callable:
class C(B):
pass
- self.assertTrue(issubclass(C, B))
- self.assertFalse(issubclass(int, C))
+ self.assertIsSubclass(C, B)
+ self.assertNotIsSubclass(int, C)
def test_registration(self):
for B in Hashable, Iterable, Iterator, Reversible, Sized, Container, Callable:
class C:
__hash__ = None # Make sure it isn't hashable by default
- self.assertFalse(issubclass(C, B), B.__name__)
+ self.assertNotIsSubclass(C, B)
B.register(C)
- self.assertTrue(issubclass(C, B))
+ self.assertIsSubclass(C, B)
class WithSet(MutableSet):
@@ -1419,7 +1418,7 @@ class TestCollectionABCs(ABCTestCase):
def test_Set(self):
for sample in [set, frozenset]:
self.assertIsInstance(sample(), Set)
- self.assertTrue(issubclass(sample, Set))
+ self.assertIsSubclass(sample, Set)
self.validate_abstract_methods(Set, '__contains__', '__iter__', '__len__')
class MySet(Set):
def __contains__(self, x):
@@ -1500,9 +1499,9 @@ def __len__(self):
def test_MutableSet(self):
self.assertIsInstance(set(), MutableSet)
- self.assertTrue(issubclass(set, MutableSet))
+ self.assertIsSubclass(set, MutableSet)
self.assertNotIsInstance(frozenset(), MutableSet)
- self.assertFalse(issubclass(frozenset, MutableSet))
+ self.assertNotIsSubclass(frozenset, MutableSet)
self.validate_abstract_methods(MutableSet, '__contains__', '__iter__', '__len__',
'add', 'discard')
@@ -1841,7 +1840,7 @@ def test_Set_hash_matches_frozenset(self):
def test_Mapping(self):
for sample in [dict]:
self.assertIsInstance(sample(), Mapping)
- self.assertTrue(issubclass(sample, Mapping))
+ self.assertIsSubclass(sample, Mapping)
self.validate_abstract_methods(Mapping, '__contains__', '__iter__', '__len__',
'__getitem__')
class MyMapping(Mapping):
@@ -1857,7 +1856,7 @@ def __iter__(self):
def test_MutableMapping(self):
for sample in [dict]:
self.assertIsInstance(sample(), MutableMapping)
- self.assertTrue(issubclass(sample, MutableMapping))
+ self.assertIsSubclass(sample, MutableMapping)
self.validate_abstract_methods(MutableMapping, '__contains__', '__iter__', '__len__',
'__getitem__', '__setitem__', '__delitem__')
@@ -1891,12 +1890,12 @@ def test_MutableMapping_subclass(self):
def test_Sequence(self):
for sample in [tuple, list, bytes, str]:
self.assertIsInstance(sample(), Sequence)
- self.assertTrue(issubclass(sample, Sequence))
+ self.assertIsSubclass(sample, Sequence)
self.assertIsInstance(range(10), Sequence)
- self.assertTrue(issubclass(range, Sequence))
+ self.assertIsSubclass(range, Sequence)
self.assertIsInstance(memoryview(b""), Sequence)
- self.assertTrue(issubclass(memoryview, Sequence))
- self.assertTrue(issubclass(str, Sequence))
+ self.assertIsSubclass(memoryview, Sequence)
+ self.assertIsSubclass(str, Sequence)
self.validate_abstract_methods(Sequence, '__contains__', '__iter__', '__len__',
'__getitem__')
@@ -1938,21 +1937,21 @@ def assert_index_same(seq1, seq2, index_args):
def test_Buffer(self):
for sample in [bytes, bytearray, memoryview]:
self.assertIsInstance(sample(b"x"), Buffer)
- self.assertTrue(issubclass(sample, Buffer))
+ self.assertIsSubclass(sample, Buffer)
for sample in [str, list, tuple]:
self.assertNotIsInstance(sample(), Buffer)
- self.assertFalse(issubclass(sample, Buffer))
+ self.assertNotIsSubclass(sample, Buffer)
self.validate_abstract_methods(Buffer, '__buffer__')
def test_MutableSequence(self):
for sample in [tuple, str, bytes]:
self.assertNotIsInstance(sample(), MutableSequence)
- self.assertFalse(issubclass(sample, MutableSequence))
+ self.assertNotIsSubclass(sample, MutableSequence)
for sample in [list, bytearray, deque]:
self.assertIsInstance(sample(), MutableSequence)
- self.assertTrue(issubclass(sample, MutableSequence))
- self.assertTrue(issubclass(array.array, MutableSequence))
- self.assertFalse(issubclass(str, MutableSequence))
+ self.assertIsSubclass(sample, MutableSequence)
+ self.assertIsSubclass(array.array, MutableSequence)
+ self.assertNotIsSubclass(str, MutableSequence)
self.validate_abstract_methods(MutableSequence, '__contains__', '__iter__',
'__len__', '__getitem__', '__setitem__', '__delitem__', 'insert')
@@ -2043,8 +2042,8 @@ def test_basics(self):
self.assertEqual(c, Counter(a=3, b=2, c=1))
self.assertIsInstance(c, dict)
self.assertIsInstance(c, Mapping)
- self.assertTrue(issubclass(Counter, dict))
- self.assertTrue(issubclass(Counter, Mapping))
+ self.assertIsSubclass(Counter, dict)
+ self.assertIsSubclass(Counter, Mapping)
self.assertEqual(len(c), 3)
self.assertEqual(sum(c.values()), 6)
self.assertEqual(list(c.values()), [3, 2, 1])
1
0
Jan. 20, 2025
https://github.com/python/cpython/commit/49b2f31a6b94dae1d986083ac5814b5e89…
commit: 49b2f31a6b94dae1d986083ac5814b5e89b2a710
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: hugovk <1324225+hugovk(a)users.noreply.github.com>
date: 2025-01-20T09:17:35+02:00
summary:
[3.12] GH-125722: Use long options for Sphinx (GH-129039) (#129042)
GH-125722: Use long options for Sphinx (GH-129039)
(cherry picked from commit 4967fa6a9c0db7ea3ade905d724a04688cfc7a5e)
Co-authored-by: Adam Turner <9087854+AA-Turner(a)users.noreply.github.com>
files:
M .github/workflows/reusable-docs.yml
M Doc/Makefile
M Doc/make.bat
diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml
index 6ac7d40c4aec27..d01c5e30a9b9fa 100644
--- a/.github/workflows/reusable-docs.yml
+++ b/.github/workflows/reusable-docs.yml
@@ -62,8 +62,8 @@ jobs:
continue-on-error: true
run: |
set -Eeuo pipefail
- # Build docs with the '-n' (nit-picky) option; write warnings to file
- make -C Doc/ PYTHON=../python SPHINXOPTS="-q -n -W --keep-going -w sphinx-warnings.txt" html
+ # Build docs with the nit-picky option; write warnings to file
+ make -C Doc/ PYTHON=../python SPHINXOPTS="--quiet --nitpicky --fail-on-warning --keep-going --warning-file sphinx-warnings.txt" html
- name: 'Check warnings'
if: github.event_name == 'pull_request'
run: |
@@ -98,4 +98,4 @@ jobs:
run: make -C Doc/ PYTHON=../python venv
# Use "xvfb-run" since some doctest tests open GUI windows
- name: 'Run documentation doctest'
- run: xvfb-run make -C Doc/ PYTHON=../python SPHINXERRORHANDLING="-W --keep-going" doctest
+ run: xvfb-run make -C Doc/ PYTHON=../python SPHINXERRORHANDLING="--fail-on-warning --keep-going" doctest
diff --git a/Doc/Makefile b/Doc/Makefile
index 4a704ad58b33d3..1a66642a4a03ed 100644
--- a/Doc/Makefile
+++ b/Doc/Makefile
@@ -14,15 +14,15 @@ PAPER =
SOURCES =
DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py)
REQUIREMENTS = requirements.txt
-SPHINXERRORHANDLING = -W
+SPHINXERRORHANDLING = --fail-on-warning
# Internal variables.
-PAPEROPT_a4 = -D latex_elements.papersize=a4paper
-PAPEROPT_letter = -D latex_elements.papersize=letterpaper
+PAPEROPT_a4 = --define latex_elements.papersize=a4paper
+PAPEROPT_letter = --define latex_elements.papersize=letterpaper
-ALLSPHINXOPTS = -b $(BUILDER) \
- -d build/doctrees \
- -j $(JOBS) \
+ALLSPHINXOPTS = --builder $(BUILDER) \
+ --doctree-dir build/doctrees \
+ --jobs $(JOBS) \
$(PAPEROPT_$(PAPER)) \
$(SPHINXOPTS) $(SPHINXERRORHANDLING) \
. build/$(BUILDER) $(SOURCES)
@@ -144,7 +144,7 @@ pydoc-topics: build
.PHONY: gettext
gettext: BUILDER = gettext
-gettext: override SPHINXOPTS := -d build/doctrees-gettext $(SPHINXOPTS)
+gettext: override SPHINXOPTS := --doctree-dir build/doctrees-gettext $(SPHINXOPTS)
gettext: build
.PHONY: htmlview
@@ -300,20 +300,20 @@ serve:
# By default, Sphinx only rebuilds pages where the page content has changed.
# This means it doesn't always pick up changes to preferred link targets, etc
# To ensure such changes are picked up, we build the published docs with
-# `-E` (to ignore the cached environment) and `-a` (to ignore already existing
-# output files)
+# ``--fresh-env`` (to ignore the cached environment) and ``--write-all``
+# (to ignore already existing output files)
# for development releases: always build
.PHONY: autobuild-dev
autobuild-dev: DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py --short)
autobuild-dev:
- $(MAKE) dist-no-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' DISTVERSION=$(DISTVERSION)
+ $(MAKE) dist-no-html SPHINXOPTS='$(SPHINXOPTS) --fresh-env --write-all --html-define daily=1' DISTVERSION=$(DISTVERSION)
# for HTML-only rebuilds
.PHONY: autobuild-dev-html
autobuild-dev-html: DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py --short)
autobuild-dev-html:
- $(MAKE) dist-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' DISTVERSION=$(DISTVERSION)
+ $(MAKE) dist-html SPHINXOPTS='$(SPHINXOPTS) --fresh-env --write-all --html-define daily=1' DISTVERSION=$(DISTVERSION)
# for stable releases: only build if not in pre-release stage (alpha, beta)
# release candidate downloads are okay, since the stable tree can be in that stage
diff --git a/Doc/make.bat b/Doc/make.bat
index 87d8359ef112bb..ede793ed3c6d70 100644
--- a/Doc/make.bat
+++ b/Doc/make.bat
@@ -144,12 +144,12 @@ if exist ..\Misc\NEWS (
)
if defined PAPER (
- set SPHINXOPTS=-D latex_elements.papersize=%PAPER% %SPHINXOPTS%
+ set SPHINXOPTS=--define latex_elements.papersize=%PAPER% %SPHINXOPTS%
)
if "%1" EQU "htmlhelp" (
- set SPHINXOPTS=-D html_theme_options.body_max_width=none %SPHINXOPTS%
+ set SPHINXOPTS=--define html_theme_options.body_max_width=none %SPHINXOPTS%
)
-cmd /S /C "%SPHINXBUILD% %SPHINXOPTS% -b%1 -dbuild\doctrees . "%BUILDDIR%\%1" %2 %3 %4 %5 %6 %7 %8 %9"
+cmd /S /C "%SPHINXBUILD% %SPHINXOPTS% --builder %1 --doctree-dir build\doctrees . "%BUILDDIR%\%1" %2 %3 %4 %5 %6 %7 %8 %9"
if "%1" EQU "htmlhelp" (
"%HTMLHELP%" "%BUILDDIR%\htmlhelp\python%DISTVERSION:.=%.hhp"
1
0
Jan. 20, 2025
https://github.com/python/cpython/commit/59b919b082bcb96a66eea2b64b6572ceb1…
commit: 59b919b082bcb96a66eea2b64b6572ceb1ce6210
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: hugovk <1324225+hugovk(a)users.noreply.github.com>
date: 2025-01-20T09:17:29+02:00
summary:
[3.13] GH-125722: Use long options for Sphinx (GH-129039) (#129041)
GH-125722: Use long options for Sphinx (GH-129039)
(cherry picked from commit 4967fa6a9c0db7ea3ade905d724a04688cfc7a5e)
Co-authored-by: Adam Turner <9087854+AA-Turner(a)users.noreply.github.com>
files:
M .github/workflows/reusable-docs.yml
M Doc/Makefile
M Doc/make.bat
diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml
index 84675fa62e1516..6738acc98c6565 100644
--- a/.github/workflows/reusable-docs.yml
+++ b/.github/workflows/reusable-docs.yml
@@ -65,8 +65,8 @@ jobs:
continue-on-error: true
run: |
set -Eeuo pipefail
- # Build docs with the '-n' (nit-picky) option; write warnings to file
- make -C Doc/ PYTHON=../python SPHINXOPTS="-q -n -W --keep-going -w sphinx-warnings.txt" html
+ # Build docs with the nit-picky option; write warnings to file
+ make -C Doc/ PYTHON=../python SPHINXOPTS="--quiet --nitpicky --fail-on-warning --keep-going --warning-file sphinx-warnings.txt" html
- name: 'Check warnings'
if: github.event_name == 'pull_request'
run: |
@@ -101,4 +101,4 @@ jobs:
run: make -C Doc/ PYTHON=../python venv
# Use "xvfb-run" since some doctest tests open GUI windows
- name: 'Run documentation doctest'
- run: xvfb-run make -C Doc/ PYTHON=../python SPHINXERRORHANDLING="-W --keep-going" doctest
+ run: xvfb-run make -C Doc/ PYTHON=../python SPHINXERRORHANDLING="--fail-on-warning --keep-going" doctest
diff --git a/Doc/Makefile b/Doc/Makefile
index 4a704ad58b33d3..1a66642a4a03ed 100644
--- a/Doc/Makefile
+++ b/Doc/Makefile
@@ -14,15 +14,15 @@ PAPER =
SOURCES =
DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py)
REQUIREMENTS = requirements.txt
-SPHINXERRORHANDLING = -W
+SPHINXERRORHANDLING = --fail-on-warning
# Internal variables.
-PAPEROPT_a4 = -D latex_elements.papersize=a4paper
-PAPEROPT_letter = -D latex_elements.papersize=letterpaper
+PAPEROPT_a4 = --define latex_elements.papersize=a4paper
+PAPEROPT_letter = --define latex_elements.papersize=letterpaper
-ALLSPHINXOPTS = -b $(BUILDER) \
- -d build/doctrees \
- -j $(JOBS) \
+ALLSPHINXOPTS = --builder $(BUILDER) \
+ --doctree-dir build/doctrees \
+ --jobs $(JOBS) \
$(PAPEROPT_$(PAPER)) \
$(SPHINXOPTS) $(SPHINXERRORHANDLING) \
. build/$(BUILDER) $(SOURCES)
@@ -144,7 +144,7 @@ pydoc-topics: build
.PHONY: gettext
gettext: BUILDER = gettext
-gettext: override SPHINXOPTS := -d build/doctrees-gettext $(SPHINXOPTS)
+gettext: override SPHINXOPTS := --doctree-dir build/doctrees-gettext $(SPHINXOPTS)
gettext: build
.PHONY: htmlview
@@ -300,20 +300,20 @@ serve:
# By default, Sphinx only rebuilds pages where the page content has changed.
# This means it doesn't always pick up changes to preferred link targets, etc
# To ensure such changes are picked up, we build the published docs with
-# `-E` (to ignore the cached environment) and `-a` (to ignore already existing
-# output files)
+# ``--fresh-env`` (to ignore the cached environment) and ``--write-all``
+# (to ignore already existing output files)
# for development releases: always build
.PHONY: autobuild-dev
autobuild-dev: DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py --short)
autobuild-dev:
- $(MAKE) dist-no-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' DISTVERSION=$(DISTVERSION)
+ $(MAKE) dist-no-html SPHINXOPTS='$(SPHINXOPTS) --fresh-env --write-all --html-define daily=1' DISTVERSION=$(DISTVERSION)
# for HTML-only rebuilds
.PHONY: autobuild-dev-html
autobuild-dev-html: DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py --short)
autobuild-dev-html:
- $(MAKE) dist-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' DISTVERSION=$(DISTVERSION)
+ $(MAKE) dist-html SPHINXOPTS='$(SPHINXOPTS) --fresh-env --write-all --html-define daily=1' DISTVERSION=$(DISTVERSION)
# for stable releases: only build if not in pre-release stage (alpha, beta)
# release candidate downloads are okay, since the stable tree can be in that stage
diff --git a/Doc/make.bat b/Doc/make.bat
index 87d8359ef112bb..ede793ed3c6d70 100644
--- a/Doc/make.bat
+++ b/Doc/make.bat
@@ -144,12 +144,12 @@ if exist ..\Misc\NEWS (
)
if defined PAPER (
- set SPHINXOPTS=-D latex_elements.papersize=%PAPER% %SPHINXOPTS%
+ set SPHINXOPTS=--define latex_elements.papersize=%PAPER% %SPHINXOPTS%
)
if "%1" EQU "htmlhelp" (
- set SPHINXOPTS=-D html_theme_options.body_max_width=none %SPHINXOPTS%
+ set SPHINXOPTS=--define html_theme_options.body_max_width=none %SPHINXOPTS%
)
-cmd /S /C "%SPHINXBUILD% %SPHINXOPTS% -b%1 -dbuild\doctrees . "%BUILDDIR%\%1" %2 %3 %4 %5 %6 %7 %8 %9"
+cmd /S /C "%SPHINXBUILD% %SPHINXOPTS% --builder %1 --doctree-dir build\doctrees . "%BUILDDIR%\%1" %2 %3 %4 %5 %6 %7 %8 %9"
if "%1" EQU "htmlhelp" (
"%HTMLHELP%" "%BUILDDIR%\htmlhelp\python%DISTVERSION:.=%.hhp"
1
0
https://github.com/python/cpython/commit/4967fa6a9c0db7ea3ade905d724a04688c…
commit: 4967fa6a9c0db7ea3ade905d724a04688cfc7a5e
branch: main
author: Adam Turner <9087854+AA-Turner(a)users.noreply.github.com>
committer: hugovk <1324225+hugovk(a)users.noreply.github.com>
date: 2025-01-20T08:11:22+02:00
summary:
GH-125722: Use long options for Sphinx (#129039)
files:
M .github/workflows/reusable-docs.yml
M Doc/Makefile
M Doc/make.bat
diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml
index 84675fa62e1516..6738acc98c6565 100644
--- a/.github/workflows/reusable-docs.yml
+++ b/.github/workflows/reusable-docs.yml
@@ -65,8 +65,8 @@ jobs:
continue-on-error: true
run: |
set -Eeuo pipefail
- # Build docs with the '-n' (nit-picky) option; write warnings to file
- make -C Doc/ PYTHON=../python SPHINXOPTS="-q -n -W --keep-going -w sphinx-warnings.txt" html
+ # Build docs with the nit-picky option; write warnings to file
+ make -C Doc/ PYTHON=../python SPHINXOPTS="--quiet --nitpicky --fail-on-warning --keep-going --warning-file sphinx-warnings.txt" html
- name: 'Check warnings'
if: github.event_name == 'pull_request'
run: |
@@ -101,4 +101,4 @@ jobs:
run: make -C Doc/ PYTHON=../python venv
# Use "xvfb-run" since some doctest tests open GUI windows
- name: 'Run documentation doctest'
- run: xvfb-run make -C Doc/ PYTHON=../python SPHINXERRORHANDLING="-W --keep-going" doctest
+ run: xvfb-run make -C Doc/ PYTHON=../python SPHINXERRORHANDLING="--fail-on-warning --keep-going" doctest
diff --git a/Doc/Makefile b/Doc/Makefile
index 4a704ad58b33d3..1a66642a4a03ed 100644
--- a/Doc/Makefile
+++ b/Doc/Makefile
@@ -14,15 +14,15 @@ PAPER =
SOURCES =
DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py)
REQUIREMENTS = requirements.txt
-SPHINXERRORHANDLING = -W
+SPHINXERRORHANDLING = --fail-on-warning
# Internal variables.
-PAPEROPT_a4 = -D latex_elements.papersize=a4paper
-PAPEROPT_letter = -D latex_elements.papersize=letterpaper
+PAPEROPT_a4 = --define latex_elements.papersize=a4paper
+PAPEROPT_letter = --define latex_elements.papersize=letterpaper
-ALLSPHINXOPTS = -b $(BUILDER) \
- -d build/doctrees \
- -j $(JOBS) \
+ALLSPHINXOPTS = --builder $(BUILDER) \
+ --doctree-dir build/doctrees \
+ --jobs $(JOBS) \
$(PAPEROPT_$(PAPER)) \
$(SPHINXOPTS) $(SPHINXERRORHANDLING) \
. build/$(BUILDER) $(SOURCES)
@@ -144,7 +144,7 @@ pydoc-topics: build
.PHONY: gettext
gettext: BUILDER = gettext
-gettext: override SPHINXOPTS := -d build/doctrees-gettext $(SPHINXOPTS)
+gettext: override SPHINXOPTS := --doctree-dir build/doctrees-gettext $(SPHINXOPTS)
gettext: build
.PHONY: htmlview
@@ -300,20 +300,20 @@ serve:
# By default, Sphinx only rebuilds pages where the page content has changed.
# This means it doesn't always pick up changes to preferred link targets, etc
# To ensure such changes are picked up, we build the published docs with
-# `-E` (to ignore the cached environment) and `-a` (to ignore already existing
-# output files)
+# ``--fresh-env`` (to ignore the cached environment) and ``--write-all``
+# (to ignore already existing output files)
# for development releases: always build
.PHONY: autobuild-dev
autobuild-dev: DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py --short)
autobuild-dev:
- $(MAKE) dist-no-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' DISTVERSION=$(DISTVERSION)
+ $(MAKE) dist-no-html SPHINXOPTS='$(SPHINXOPTS) --fresh-env --write-all --html-define daily=1' DISTVERSION=$(DISTVERSION)
# for HTML-only rebuilds
.PHONY: autobuild-dev-html
autobuild-dev-html: DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py --short)
autobuild-dev-html:
- $(MAKE) dist-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' DISTVERSION=$(DISTVERSION)
+ $(MAKE) dist-html SPHINXOPTS='$(SPHINXOPTS) --fresh-env --write-all --html-define daily=1' DISTVERSION=$(DISTVERSION)
# for stable releases: only build if not in pre-release stage (alpha, beta)
# release candidate downloads are okay, since the stable tree can be in that stage
diff --git a/Doc/make.bat b/Doc/make.bat
index 87d8359ef112bb..ede793ed3c6d70 100644
--- a/Doc/make.bat
+++ b/Doc/make.bat
@@ -144,12 +144,12 @@ if exist ..\Misc\NEWS (
)
if defined PAPER (
- set SPHINXOPTS=-D latex_elements.papersize=%PAPER% %SPHINXOPTS%
+ set SPHINXOPTS=--define latex_elements.papersize=%PAPER% %SPHINXOPTS%
)
if "%1" EQU "htmlhelp" (
- set SPHINXOPTS=-D html_theme_options.body_max_width=none %SPHINXOPTS%
+ set SPHINXOPTS=--define html_theme_options.body_max_width=none %SPHINXOPTS%
)
-cmd /S /C "%SPHINXBUILD% %SPHINXOPTS% -b%1 -dbuild\doctrees . "%BUILDDIR%\%1" %2 %3 %4 %5 %6 %7 %8 %9"
+cmd /S /C "%SPHINXBUILD% %SPHINXOPTS% --builder %1 --doctree-dir build\doctrees . "%BUILDDIR%\%1" %2 %3 %4 %5 %6 %7 %8 %9"
if "%1" EQU "htmlhelp" (
"%HTMLHELP%" "%BUILDDIR%\htmlhelp\python%DISTVERSION:.=%.hhp"
1
0
[3.13] GH-125722: Increase minimum supported Sphinx to 8.1.3 (GH-128922) (#129037)
by AA-Turner Jan. 20, 2025
by AA-Turner Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/5fe76505524c64c16c2ad8401d3de2ce39…
commit: 5fe76505524c64c16c2ad8401d3de2ce39d6fb14
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: AA-Turner <9087854+AA-Turner(a)users.noreply.github.com>
date: 2025-01-20T00:52:00Z
summary:
[3.13] GH-125722: Increase minimum supported Sphinx to 8.1.3 (GH-128922) (#129037)
(cherry picked from commit d46b577ec026c2e700a9f920f81cfbf698e53eb6)
Co-authored-by: Adam Turner <9087854+AA-Turner(a)users.noreply.github.com>
files:
A Misc/NEWS.d/next/Documentation/2025-01-16-18-59-11.gh-issue-125722.eHHRga.rst
D Doc/requirements-oldest-sphinx.txt
M .github/workflows/reusable-docs.yml
M Doc/conf.py
M Doc/constraints.txt
M Doc/requirements.txt
M Doc/tools/extensions/c_annotations.py
diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml
index 88da55bf08b8fe..84675fa62e1516 100644
--- a/.github/workflows/reusable-docs.yml
+++ b/.github/workflows/reusable-docs.yml
@@ -76,26 +76,6 @@ jobs:
--fail-if-improved \
--fail-if-new-news-nit
- # This build doesn't use problem matchers or check annotations
- build_doc_oldest_supported_sphinx:
- name: 'Docs (Oldest Sphinx)'
- runs-on: ubuntu-latest
- timeout-minutes: 60
- steps:
- - uses: actions/checkout@v4
- with:
- persist-credentials: false
- - name: 'Set up Python'
- uses: actions/setup-python@v5
- with:
- python-version: '3.13' # known to work with Sphinx 7.2.6
- cache: 'pip'
- cache-dependency-path: 'Doc/requirements-oldest-sphinx.txt'
- - name: 'Install build dependencies'
- run: make -C Doc/ venv REQUIREMENTS="requirements-oldest-sphinx.txt"
- - name: 'Build HTML documentation'
- run: make -C Doc/ SPHINXOPTS="-q" SPHINXERRORHANDLING="-W --keep-going" html
-
# Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release
doctest:
name: 'Doctest'
diff --git a/Doc/conf.py b/Doc/conf.py
index 829124c86c8b19..269a5007e0b6c9 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -9,9 +9,6 @@
import importlib
import os
import sys
-import time
-
-import sphinx
# Make our custom extensions available to Sphinx
sys.path.append(os.path.abspath('tools/extensions'))
@@ -67,10 +64,7 @@
# General substitutions.
project = 'Python'
-if sphinx.version_info[:2] >= (8, 1):
- copyright = "2001-%Y, Python Software Foundation"
-else:
- copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation"
+copyright = "2001-%Y, Python Software Foundation"
# We look for the Include/patchlevel.h file in the current Python source tree
# and replace the values accordingly.
@@ -93,7 +87,8 @@
highlight_language = 'python3'
# Minimum version of sphinx required
-needs_sphinx = '7.2.6'
+# Keep this version in sync with ``Doc/requirements.txt``.
+needs_sphinx = '8.1.3'
# Create table of contents entries for domain objects (e.g. functions, classes,
# attributes, etc.). Default is True.
@@ -372,13 +367,7 @@
# This 'Last updated on:' timestamp is inserted at the bottom of every page.
html_last_updated_fmt = '%b %d, %Y (%H:%M UTC)'
-if sphinx.version_info[:2] >= (8, 1):
- html_last_updated_use_utc = True
-else:
- html_time = int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))
- html_last_updated_fmt = time.strftime(
- html_last_updated_fmt, time.gmtime(html_time)
- )
+html_last_updated_use_utc = True
# Path to find HTML templates to override theme
templates_path = ['tools/templates']
@@ -615,16 +604,6 @@
}
extlinks_detect_hardcoded_links = True
-if sphinx.version_info[:2] < (8, 1):
- # Sphinx 8.1 has in-built CVE and CWE roles.
- extlinks |= {
- "cve": (
- "https://www.cve.org/CVERecord?id=CVE-%s",
- "CVE-%s",
- ),
- "cwe": ("https://cwe.mitre.org/data/definitions/%s.html", "CWE-%s"),
- }
-
# Options for c_annotations extension
# -----------------------------------
diff --git a/Doc/constraints.txt b/Doc/constraints.txt
index 26ac1862dbac0b..29cd4be1d3c8db 100644
--- a/Doc/constraints.txt
+++ b/Doc/constraints.txt
@@ -13,14 +13,12 @@ packaging<25
Pygments<3
requests<3
snowballstemmer<3
-# keep lower-bounds until Sphinx 8.1 is released
-# https://github.com/sphinx-doc/sphinx/pull/12756
-sphinxcontrib-applehelp>=1.0.7,<3
-sphinxcontrib-devhelp>=1.0.6,<3
-sphinxcontrib-htmlhelp>=2.0.6,<3
-sphinxcontrib-jsmath>=1.0.1,<2
-sphinxcontrib-qthelp>=1.0.6,<3
-sphinxcontrib-serializinghtml>=1.1.9,<3
+sphinxcontrib-applehelp<3
+sphinxcontrib-devhelp<3
+sphinxcontrib-htmlhelp<3
+sphinxcontrib-jsmath<2
+sphinxcontrib-qthelp<3
+sphinxcontrib-serializinghtml<3
# Direct dependencies of Jinja2 (Jinja is a dependency of Sphinx, see above)
MarkupSafe<3
diff --git a/Doc/requirements-oldest-sphinx.txt b/Doc/requirements-oldest-sphinx.txt
deleted file mode 100644
index c8027a05706c21..00000000000000
--- a/Doc/requirements-oldest-sphinx.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-# Requirements to build the Python documentation, for the oldest supported
-# Sphinx version.
-#
-# We pin Sphinx and all of its dependencies to ensure a consistent environment.
-
-blurb
-python-docs-theme>=2022.1
-
-# Generated from:
-# pip install "Sphinx~=7.2.6"
-# pip freeze
-#
-# Sphinx 7.2.6 comes from ``needs_sphinx = '7.2.6'`` in ``Doc/conf.py``.
-
-alabaster==0.7.16
-babel==2.16.0
-certifi==2024.12.14
-charset-normalizer==3.4.0
-docutils==0.20.1
-idna==3.10
-imagesize==1.4.1
-Jinja2==3.1.5
-MarkupSafe==3.0.2
-packaging==24.2
-Pygments==2.18.0
-requests==2.32.3
-snowballstemmer==2.2.0
-Sphinx==7.2.6
-sphinxcontrib-applehelp==2.0.0
-sphinxcontrib-devhelp==2.0.0
-sphinxcontrib-htmlhelp==2.1.0
-sphinxcontrib-jsmath==1.0.1
-sphinxcontrib-qthelp==2.0.0
-sphinxcontrib-serializinghtml==2.0.0
-urllib3==2.3.0
diff --git a/Doc/requirements.txt b/Doc/requirements.txt
index 5105786ccf283c..32ff8f74d05bb6 100644
--- a/Doc/requirements.txt
+++ b/Doc/requirements.txt
@@ -3,9 +3,10 @@
# Note that when updating this file, you will likely also have to update
# the Doc/constraints.txt file.
-# Sphinx version is pinned so that new versions that introduce new warnings
+# The Sphinx version is pinned so that new versions that introduce new warnings
# won't suddenly cause build failures. Updating the version is fine as long
# as no warnings are raised by doing so.
+# Keep this version in sync with ``Doc/conf.py``.
sphinx~=8.1.0
blurb
diff --git a/Doc/tools/extensions/c_annotations.py b/Doc/tools/extensions/c_annotations.py
index 50065d34a2c27a..089614a1f6c421 100644
--- a/Doc/tools/extensions/c_annotations.py
+++ b/Doc/tools/extensions/c_annotations.py
@@ -16,7 +16,6 @@
from pathlib import Path
from typing import TYPE_CHECKING
-import sphinx
from docutils import nodes
from docutils.statemachine import StringList
from sphinx import addnodes
@@ -285,16 +284,6 @@ def setup(app: Sphinx) -> ExtensionMetadata:
app.connect("builder-inited", init_annotations)
app.connect("doctree-read", add_annotations)
- if sphinx.version_info[:2] < (7, 2):
- from docutils.parsers.rst import directives
- from sphinx.domains.c import CObject
-
- # monkey-patch C object...
- CObject.option_spec |= {
- "no-index-entry": directives.flag,
- "no-contents-entry": directives.flag,
- }
-
return {
"version": "1.0",
"parallel_read_safe": True,
diff --git a/Misc/NEWS.d/next/Documentation/2025-01-16-18-59-11.gh-issue-125722.eHHRga.rst b/Misc/NEWS.d/next/Documentation/2025-01-16-18-59-11.gh-issue-125722.eHHRga.rst
new file mode 100644
index 00000000000000..bf6253eed2eb90
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2025-01-16-18-59-11.gh-issue-125722.eHHRga.rst
@@ -0,0 +1,2 @@
+Require Sphinx 8.1.3 or later to build the Python documentation. Patch by
+Adam Turner.
1
0
[3.12] GH-125722: Increase minimum supported Sphinx to 8.1.3 (GH-128922) (#129038)
by AA-Turner Jan. 20, 2025
by AA-Turner Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/6f19c6a705d4bdbf01f4e704e42f38d375…
commit: 6f19c6a705d4bdbf01f4e704e42f38d37597b60b
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: AA-Turner <9087854+AA-Turner(a)users.noreply.github.com>
date: 2025-01-20T00:46:05Z
summary:
[3.12] GH-125722: Increase minimum supported Sphinx to 8.1.3 (GH-128922) (#129038)
(cherry picked from commit d46b577ec026c2e700a9f920f81cfbf698e53eb6)
Co-authored-by: Adam Turner <9087854+AA-Turner(a)users.noreply.github.com>
files:
A Misc/NEWS.d/next/Documentation/2025-01-16-18-59-11.gh-issue-125722.eHHRga.rst
D Doc/requirements-oldest-sphinx.txt
M .github/workflows/reusable-docs.yml
M Doc/conf.py
M Doc/constraints.txt
M Doc/requirements.txt
M Doc/tools/extensions/c_annotations.py
diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml
index c5f71831a005fd..6ac7d40c4aec27 100644
--- a/.github/workflows/reusable-docs.yml
+++ b/.github/workflows/reusable-docs.yml
@@ -73,26 +73,6 @@ jobs:
--fail-if-improved \
--fail-if-new-news-nit
- # This build doesn't use problem matchers or check annotations
- build_doc_oldest_supported_sphinx:
- name: 'Docs (Oldest Sphinx)'
- runs-on: ubuntu-latest
- timeout-minutes: 60
- steps:
- - uses: actions/checkout@v4
- with:
- persist-credentials: false
- - name: 'Set up Python'
- uses: actions/setup-python@v5
- with:
- python-version: '3.13' # known to work with Sphinx 7.2.6
- cache: 'pip'
- cache-dependency-path: 'Doc/requirements-oldest-sphinx.txt'
- - name: 'Install build dependencies'
- run: make -C Doc/ venv REQUIREMENTS="requirements-oldest-sphinx.txt"
- - name: 'Build HTML documentation'
- run: make -C Doc/ SPHINXOPTS="-q" SPHINXERRORHANDLING="-W --keep-going" html
-
# Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release
doctest:
name: 'Doctest'
diff --git a/Doc/conf.py b/Doc/conf.py
index 4b18d02a943f62..4c74040976959c 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -9,9 +9,6 @@
import importlib
import os
import sys
-import time
-
-import sphinx
# Make our custom extensions available to Sphinx
sys.path.append(os.path.abspath('tools/extensions'))
@@ -61,10 +58,7 @@
# General substitutions.
project = 'Python'
-if sphinx.version_info[:2] >= (8, 1):
- copyright = "2001-%Y, Python Software Foundation"
-else:
- copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation"
+copyright = "2001-%Y, Python Software Foundation"
# We look for the Include/patchlevel.h file in the current Python source tree
# and replace the values accordingly.
@@ -85,7 +79,8 @@
highlight_language = 'python3'
# Minimum version of sphinx required
-needs_sphinx = '7.2.6'
+# Keep this version in sync with ``Doc/requirements.txt``.
+needs_sphinx = '8.1.3'
# Create table of contents entries for domain objects (e.g. functions, classes,
# attributes, etc.). Default is True.
@@ -350,13 +345,7 @@
# This 'Last updated on:' timestamp is inserted at the bottom of every page.
html_last_updated_fmt = '%b %d, %Y (%H:%M UTC)'
-if sphinx.version_info[:2] >= (8, 1):
- html_last_updated_use_utc = True
-else:
- html_time = int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))
- html_last_updated_fmt = time.strftime(
- html_last_updated_fmt, time.gmtime(html_time)
- )
+html_last_updated_use_utc = True
# Path to find HTML templates to override theme
templates_path = ['tools/templates']
@@ -594,16 +583,6 @@
}
extlinks_detect_hardcoded_links = True
-if sphinx.version_info[:2] < (8, 1):
- # Sphinx 8.1 has in-built CVE and CWE roles.
- extlinks |= {
- "cve": (
- "https://www.cve.org/CVERecord?id=CVE-%s",
- "CVE-%s",
- ),
- "cwe": ("https://cwe.mitre.org/data/definitions/%s.html", "CWE-%s"),
- }
-
# Options for c_annotations extension
# -----------------------------------
diff --git a/Doc/constraints.txt b/Doc/constraints.txt
index 26ac1862dbac0b..29cd4be1d3c8db 100644
--- a/Doc/constraints.txt
+++ b/Doc/constraints.txt
@@ -13,14 +13,12 @@ packaging<25
Pygments<3
requests<3
snowballstemmer<3
-# keep lower-bounds until Sphinx 8.1 is released
-# https://github.com/sphinx-doc/sphinx/pull/12756
-sphinxcontrib-applehelp>=1.0.7,<3
-sphinxcontrib-devhelp>=1.0.6,<3
-sphinxcontrib-htmlhelp>=2.0.6,<3
-sphinxcontrib-jsmath>=1.0.1,<2
-sphinxcontrib-qthelp>=1.0.6,<3
-sphinxcontrib-serializinghtml>=1.1.9,<3
+sphinxcontrib-applehelp<3
+sphinxcontrib-devhelp<3
+sphinxcontrib-htmlhelp<3
+sphinxcontrib-jsmath<2
+sphinxcontrib-qthelp<3
+sphinxcontrib-serializinghtml<3
# Direct dependencies of Jinja2 (Jinja is a dependency of Sphinx, see above)
MarkupSafe<3
diff --git a/Doc/requirements-oldest-sphinx.txt b/Doc/requirements-oldest-sphinx.txt
deleted file mode 100644
index c8027a05706c21..00000000000000
--- a/Doc/requirements-oldest-sphinx.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-# Requirements to build the Python documentation, for the oldest supported
-# Sphinx version.
-#
-# We pin Sphinx and all of its dependencies to ensure a consistent environment.
-
-blurb
-python-docs-theme>=2022.1
-
-# Generated from:
-# pip install "Sphinx~=7.2.6"
-# pip freeze
-#
-# Sphinx 7.2.6 comes from ``needs_sphinx = '7.2.6'`` in ``Doc/conf.py``.
-
-alabaster==0.7.16
-babel==2.16.0
-certifi==2024.12.14
-charset-normalizer==3.4.0
-docutils==0.20.1
-idna==3.10
-imagesize==1.4.1
-Jinja2==3.1.5
-MarkupSafe==3.0.2
-packaging==24.2
-Pygments==2.18.0
-requests==2.32.3
-snowballstemmer==2.2.0
-Sphinx==7.2.6
-sphinxcontrib-applehelp==2.0.0
-sphinxcontrib-devhelp==2.0.0
-sphinxcontrib-htmlhelp==2.1.0
-sphinxcontrib-jsmath==1.0.1
-sphinxcontrib-qthelp==2.0.0
-sphinxcontrib-serializinghtml==2.0.0
-urllib3==2.3.0
diff --git a/Doc/requirements.txt b/Doc/requirements.txt
index 5105786ccf283c..32ff8f74d05bb6 100644
--- a/Doc/requirements.txt
+++ b/Doc/requirements.txt
@@ -3,9 +3,10 @@
# Note that when updating this file, you will likely also have to update
# the Doc/constraints.txt file.
-# Sphinx version is pinned so that new versions that introduce new warnings
+# The Sphinx version is pinned so that new versions that introduce new warnings
# won't suddenly cause build failures. Updating the version is fine as long
# as no warnings are raised by doing so.
+# Keep this version in sync with ``Doc/conf.py``.
sphinx~=8.1.0
blurb
diff --git a/Doc/tools/extensions/c_annotations.py b/Doc/tools/extensions/c_annotations.py
index 50065d34a2c27a..089614a1f6c421 100644
--- a/Doc/tools/extensions/c_annotations.py
+++ b/Doc/tools/extensions/c_annotations.py
@@ -16,7 +16,6 @@
from pathlib import Path
from typing import TYPE_CHECKING
-import sphinx
from docutils import nodes
from docutils.statemachine import StringList
from sphinx import addnodes
@@ -285,16 +284,6 @@ def setup(app: Sphinx) -> ExtensionMetadata:
app.connect("builder-inited", init_annotations)
app.connect("doctree-read", add_annotations)
- if sphinx.version_info[:2] < (7, 2):
- from docutils.parsers.rst import directives
- from sphinx.domains.c import CObject
-
- # monkey-patch C object...
- CObject.option_spec |= {
- "no-index-entry": directives.flag,
- "no-contents-entry": directives.flag,
- }
-
return {
"version": "1.0",
"parallel_read_safe": True,
diff --git a/Misc/NEWS.d/next/Documentation/2025-01-16-18-59-11.gh-issue-125722.eHHRga.rst b/Misc/NEWS.d/next/Documentation/2025-01-16-18-59-11.gh-issue-125722.eHHRga.rst
new file mode 100644
index 00000000000000..bf6253eed2eb90
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2025-01-16-18-59-11.gh-issue-125722.eHHRga.rst
@@ -0,0 +1,2 @@
+Require Sphinx 8.1.3 or later to build the Python documentation. Patch by
+Adam Turner.
1
0
Jan. 20, 2025
https://github.com/python/cpython/commit/d46b577ec026c2e700a9f920f81cfbf698…
commit: d46b577ec026c2e700a9f920f81cfbf698e53eb6
branch: main
author: Adam Turner <9087854+AA-Turner(a)users.noreply.github.com>
committer: AA-Turner <9087854+AA-Turner(a)users.noreply.github.com>
date: 2025-01-20T00:26:24Z
summary:
GH-125722: Increase minimum supported Sphinx to 8.1.3 (#128922)
files:
A Misc/NEWS.d/next/Documentation/2025-01-16-18-59-11.gh-issue-125722.eHHRga.rst
D Doc/requirements-oldest-sphinx.txt
M .github/workflows/reusable-docs.yml
M Doc/conf.py
M Doc/constraints.txt
M Doc/requirements.txt
M Doc/tools/extensions/c_annotations.py
diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml
index 88da55bf08b8fe..84675fa62e1516 100644
--- a/.github/workflows/reusable-docs.yml
+++ b/.github/workflows/reusable-docs.yml
@@ -76,26 +76,6 @@ jobs:
--fail-if-improved \
--fail-if-new-news-nit
- # This build doesn't use problem matchers or check annotations
- build_doc_oldest_supported_sphinx:
- name: 'Docs (Oldest Sphinx)'
- runs-on: ubuntu-latest
- timeout-minutes: 60
- steps:
- - uses: actions/checkout@v4
- with:
- persist-credentials: false
- - name: 'Set up Python'
- uses: actions/setup-python@v5
- with:
- python-version: '3.13' # known to work with Sphinx 7.2.6
- cache: 'pip'
- cache-dependency-path: 'Doc/requirements-oldest-sphinx.txt'
- - name: 'Install build dependencies'
- run: make -C Doc/ venv REQUIREMENTS="requirements-oldest-sphinx.txt"
- - name: 'Build HTML documentation'
- run: make -C Doc/ SPHINXOPTS="-q" SPHINXERRORHANDLING="-W --keep-going" html
-
# Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release
doctest:
name: 'Doctest'
diff --git a/Doc/conf.py b/Doc/conf.py
index ae08c7fa288080..b4a924b7bf0857 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -9,9 +9,6 @@
import importlib
import os
import sys
-import time
-
-import sphinx
# Make our custom extensions available to Sphinx
sys.path.append(os.path.abspath('tools/extensions'))
@@ -97,7 +94,8 @@
highlight_language = 'python3'
# Minimum version of sphinx required
-needs_sphinx = '7.2.6'
+# Keep this version in sync with ``Doc/requirements.txt``.
+needs_sphinx = '8.1.3'
# Create table of contents entries for domain objects (e.g. functions, classes,
# attributes, etc.). Default is True.
@@ -376,13 +374,7 @@
# This 'Last updated on:' timestamp is inserted at the bottom of every page.
html_last_updated_fmt = '%b %d, %Y (%H:%M UTC)'
-if sphinx.version_info[:2] >= (8, 1):
- html_last_updated_use_utc = True
-else:
- html_time = int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))
- html_last_updated_fmt = time.strftime(
- html_last_updated_fmt, time.gmtime(html_time)
- )
+html_last_updated_use_utc = True
# Path to find HTML templates to override theme
templates_path = ['tools/templates']
@@ -619,16 +611,6 @@
}
extlinks_detect_hardcoded_links = True
-if sphinx.version_info[:2] < (8, 1):
- # Sphinx 8.1 has in-built CVE and CWE roles.
- extlinks |= {
- "cve": (
- "https://www.cve.org/CVERecord?id=CVE-%s",
- "CVE-%s",
- ),
- "cwe": ("https://cwe.mitre.org/data/definitions/%s.html", "CWE-%s"),
- }
-
# Options for c_annotations extension
# -----------------------------------
diff --git a/Doc/constraints.txt b/Doc/constraints.txt
index 26ac1862dbac0b..29cd4be1d3c8db 100644
--- a/Doc/constraints.txt
+++ b/Doc/constraints.txt
@@ -13,14 +13,12 @@ packaging<25
Pygments<3
requests<3
snowballstemmer<3
-# keep lower-bounds until Sphinx 8.1 is released
-# https://github.com/sphinx-doc/sphinx/pull/12756
-sphinxcontrib-applehelp>=1.0.7,<3
-sphinxcontrib-devhelp>=1.0.6,<3
-sphinxcontrib-htmlhelp>=2.0.6,<3
-sphinxcontrib-jsmath>=1.0.1,<2
-sphinxcontrib-qthelp>=1.0.6,<3
-sphinxcontrib-serializinghtml>=1.1.9,<3
+sphinxcontrib-applehelp<3
+sphinxcontrib-devhelp<3
+sphinxcontrib-htmlhelp<3
+sphinxcontrib-jsmath<2
+sphinxcontrib-qthelp<3
+sphinxcontrib-serializinghtml<3
# Direct dependencies of Jinja2 (Jinja is a dependency of Sphinx, see above)
MarkupSafe<3
diff --git a/Doc/requirements-oldest-sphinx.txt b/Doc/requirements-oldest-sphinx.txt
deleted file mode 100644
index c8027a05706c21..00000000000000
--- a/Doc/requirements-oldest-sphinx.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-# Requirements to build the Python documentation, for the oldest supported
-# Sphinx version.
-#
-# We pin Sphinx and all of its dependencies to ensure a consistent environment.
-
-blurb
-python-docs-theme>=2022.1
-
-# Generated from:
-# pip install "Sphinx~=7.2.6"
-# pip freeze
-#
-# Sphinx 7.2.6 comes from ``needs_sphinx = '7.2.6'`` in ``Doc/conf.py``.
-
-alabaster==0.7.16
-babel==2.16.0
-certifi==2024.12.14
-charset-normalizer==3.4.0
-docutils==0.20.1
-idna==3.10
-imagesize==1.4.1
-Jinja2==3.1.5
-MarkupSafe==3.0.2
-packaging==24.2
-Pygments==2.18.0
-requests==2.32.3
-snowballstemmer==2.2.0
-Sphinx==7.2.6
-sphinxcontrib-applehelp==2.0.0
-sphinxcontrib-devhelp==2.0.0
-sphinxcontrib-htmlhelp==2.1.0
-sphinxcontrib-jsmath==1.0.1
-sphinxcontrib-qthelp==2.0.0
-sphinxcontrib-serializinghtml==2.0.0
-urllib3==2.3.0
diff --git a/Doc/requirements.txt b/Doc/requirements.txt
index 5105786ccf283c..32ff8f74d05bb6 100644
--- a/Doc/requirements.txt
+++ b/Doc/requirements.txt
@@ -3,9 +3,10 @@
# Note that when updating this file, you will likely also have to update
# the Doc/constraints.txt file.
-# Sphinx version is pinned so that new versions that introduce new warnings
+# The Sphinx version is pinned so that new versions that introduce new warnings
# won't suddenly cause build failures. Updating the version is fine as long
# as no warnings are raised by doing so.
+# Keep this version in sync with ``Doc/conf.py``.
sphinx~=8.1.0
blurb
diff --git a/Doc/tools/extensions/c_annotations.py b/Doc/tools/extensions/c_annotations.py
index 50065d34a2c27a..089614a1f6c421 100644
--- a/Doc/tools/extensions/c_annotations.py
+++ b/Doc/tools/extensions/c_annotations.py
@@ -16,7 +16,6 @@
from pathlib import Path
from typing import TYPE_CHECKING
-import sphinx
from docutils import nodes
from docutils.statemachine import StringList
from sphinx import addnodes
@@ -285,16 +284,6 @@ def setup(app: Sphinx) -> ExtensionMetadata:
app.connect("builder-inited", init_annotations)
app.connect("doctree-read", add_annotations)
- if sphinx.version_info[:2] < (7, 2):
- from docutils.parsers.rst import directives
- from sphinx.domains.c import CObject
-
- # monkey-patch C object...
- CObject.option_spec |= {
- "no-index-entry": directives.flag,
- "no-contents-entry": directives.flag,
- }
-
return {
"version": "1.0",
"parallel_read_safe": True,
diff --git a/Misc/NEWS.d/next/Documentation/2025-01-16-18-59-11.gh-issue-125722.eHHRga.rst b/Misc/NEWS.d/next/Documentation/2025-01-16-18-59-11.gh-issue-125722.eHHRga.rst
new file mode 100644
index 00000000000000..bf6253eed2eb90
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2025-01-16-18-59-11.gh-issue-125722.eHHRga.rst
@@ -0,0 +1,2 @@
+Require Sphinx 8.1.3 or later to build the Python documentation. Patch by
+Adam Turner.
1
0
[3.12] gh-129020: Remove ambiguous sentence from `tokenize.untokenize` docs (GH-129021) (#129036)
by AA-Turner Jan. 20, 2025
by AA-Turner Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/22c1d895fc73c3142795d2b5e62579e8a5…
commit: 22c1d895fc73c3142795d2b5e62579e8a5225d1e
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: AA-Turner <9087854+AA-Turner(a)users.noreply.github.com>
date: 2025-01-20T00:12:39Z
summary:
[3.12] gh-129020: Remove ambiguous sentence from `tokenize.untokenize` docs (GH-129021) (#129036)
gh-129020: Remove ambiguous sentence from `tokenize.untokenize` docs (GH-129021)
(cherry picked from commit bca35f0e782848ae2acdcfbfb000cd4a2af49fbd)
Co-authored-by: Tomas R <tomas.roun8(a)gmail.com>
files:
M Doc/library/tokenize.rst
diff --git a/Doc/library/tokenize.rst b/Doc/library/tokenize.rst
index f719319a302a23..b80917eae66f8b 100644
--- a/Doc/library/tokenize.rst
+++ b/Doc/library/tokenize.rst
@@ -91,11 +91,10 @@ write back the modified script.
sequences with at least two elements, the token type and the token string.
Any additional sequence elements are ignored.
- The reconstructed script is returned as a single string. The result is
- guaranteed to tokenize back to match the input so that the conversion is
- lossless and round-trips are assured. The guarantee applies only to the
- token type and token string as the spacing between tokens (column
- positions) may change.
+ The result is guaranteed to tokenize back to match the input so that the
+ conversion is lossless and round-trips are assured. The guarantee applies
+ only to the token type and token string as the spacing between tokens
+ (column positions) may change.
It returns bytes, encoded using the :data:`~token.ENCODING` token, which
is the first token sequence output by :func:`.tokenize`. If there is no
1
0
[3.13] gh-129020: Remove ambiguous sentence from `tokenize.untokenize` docs (GH-129021) (#129035)
by AA-Turner Jan. 20, 2025
by AA-Turner Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/080d17e9453d1a4fc77025eb14a5dcf49b…
commit: 080d17e9453d1a4fc77025eb14a5dcf49b4f379c
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: AA-Turner <9087854+AA-Turner(a)users.noreply.github.com>
date: 2025-01-20T00:11:27Z
summary:
[3.13] gh-129020: Remove ambiguous sentence from `tokenize.untokenize` docs (GH-129021) (#129035)
gh-129020: Remove ambiguous sentence from `tokenize.untokenize` docs (GH-129021)
(cherry picked from commit bca35f0e782848ae2acdcfbfb000cd4a2af49fbd)
Co-authored-by: Tomas R <tomas.roun8(a)gmail.com>
files:
M Doc/library/tokenize.rst
diff --git a/Doc/library/tokenize.rst b/Doc/library/tokenize.rst
index f719319a302a23..b80917eae66f8b 100644
--- a/Doc/library/tokenize.rst
+++ b/Doc/library/tokenize.rst
@@ -91,11 +91,10 @@ write back the modified script.
sequences with at least two elements, the token type and the token string.
Any additional sequence elements are ignored.
- The reconstructed script is returned as a single string. The result is
- guaranteed to tokenize back to match the input so that the conversion is
- lossless and round-trips are assured. The guarantee applies only to the
- token type and token string as the spacing between tokens (column
- positions) may change.
+ The result is guaranteed to tokenize back to match the input so that the
+ conversion is lossless and round-trips are assured. The guarantee applies
+ only to the token type and token string as the spacing between tokens
+ (column positions) may change.
It returns bytes, encoded using the :data:`~token.ENCODING` token, which
is the first token sequence output by :func:`.tokenize`. If there is no
1
0
gh-129020: Remove ambiguous sentence from `tokenize.untokenize` docs (#129021)
by AA-Turner Jan. 20, 2025
by AA-Turner Jan. 20, 2025
Jan. 20, 2025
https://github.com/python/cpython/commit/bca35f0e782848ae2acdcfbfb000cd4a2a…
commit: bca35f0e782848ae2acdcfbfb000cd4a2af49fbd
branch: main
author: Tomas R. <tomas.roun8(a)gmail.com>
committer: AA-Turner <9087854+AA-Turner(a)users.noreply.github.com>
date: 2025-01-20T00:05:22Z
summary:
gh-129020: Remove ambiguous sentence from `tokenize.untokenize` docs (#129021)
files:
M Doc/library/tokenize.rst
diff --git a/Doc/library/tokenize.rst b/Doc/library/tokenize.rst
index f719319a302a23..b80917eae66f8b 100644
--- a/Doc/library/tokenize.rst
+++ b/Doc/library/tokenize.rst
@@ -91,11 +91,10 @@ write back the modified script.
sequences with at least two elements, the token type and the token string.
Any additional sequence elements are ignored.
- The reconstructed script is returned as a single string. The result is
- guaranteed to tokenize back to match the input so that the conversion is
- lossless and round-trips are assured. The guarantee applies only to the
- token type and token string as the spacing between tokens (column
- positions) may change.
+ The result is guaranteed to tokenize back to match the input so that the
+ conversion is lossless and round-trips are assured. The guarantee applies
+ only to the token type and token string as the spacing between tokens
+ (column positions) may change.
It returns bytes, encoded using the :data:`~token.ENCODING` token, which
is the first token sequence output by :func:`.tokenize`. If there is no
1
0
Jan. 20, 2025
https://github.com/python/cpython/commit/3b6a27c5607d2b199f127c2a5ef5316bbc…
commit: 3b6a27c5607d2b199f127c2a5ef5316bbc30ae42
branch: main
author: Eli Schwartz <eschwartz(a)gentoo.org>
committer: AA-Turner <9087854+AA-Turner(a)users.noreply.github.com>
date: 2025-01-20T00:03:19Z
summary:
gh-118761: Redudce the import time of ``optparse`` (#128899)
The same change was made, and for the same reason, by ``argparse`` back in
2017. The ``textwrap`` module is only used when printing help text, so most
invocations will never need it imported.
Co-authored-by: Adam Turner <9087854+AA-Turner(a)users.noreply.github.com>
files:
A Misc/NEWS.d/next/Library/2025-01-15-18-54-48.gh-issue-118761.G1dv6E.rst
M Lib/optparse.py
diff --git a/Lib/optparse.py b/Lib/optparse.py
index cbe3451ced8bc3..38cf16d21efffa 100644
--- a/Lib/optparse.py
+++ b/Lib/optparse.py
@@ -74,7 +74,6 @@
"""
import sys, os
-import textwrap
from gettext import gettext as _, ngettext
@@ -252,6 +251,7 @@ def _format_text(self, text):
Format a paragraph of free-form text for inclusion in the
help output at the current indentation level.
"""
+ import textwrap
text_width = max(self.width - self.current_indent, 11)
indent = " "*self.current_indent
return textwrap.fill(text,
@@ -308,6 +308,7 @@ def format_option(self, option):
indent_first = 0
result.append(opts)
if option.help:
+ import textwrap
help_text = self.expand_default(option)
help_lines = textwrap.wrap(help_text, self.help_width)
result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
diff --git a/Misc/NEWS.d/next/Library/2025-01-15-18-54-48.gh-issue-118761.G1dv6E.rst b/Misc/NEWS.d/next/Library/2025-01-15-18-54-48.gh-issue-118761.G1dv6E.rst
new file mode 100644
index 00000000000000..4144ef8f40e6dd
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-15-18-54-48.gh-issue-118761.G1dv6E.rst
@@ -0,0 +1,2 @@
+Reduce the import time of :mod:`optparse` when no help text is printed.
+Patch by Eli Schwartz.
1
0
Jan. 20, 2025
https://github.com/python/cpython/commit/c9c9fcb8fcc3ef43e1d8bd71ae0ed3d423…
commit: c9c9fcb8fcc3ef43e1d8bd71ae0ed3d4231a6013
branch: main
author: Eli Schwartz <eschwartz(a)gentoo.org>
committer: AA-Turner <9087854+AA-Turner(a)users.noreply.github.com>
date: 2025-01-20T00:01:20Z
summary:
gh-118761: Improve the import time of ``gettext`` (#128898)
``gettext`` is often imported in programs that may not end up translating
anything. In fact, the ``struct`` module already has a delayed import when
parsing ``GNUTranslations`` to speed up the no ``.mo`` files case. The re module
is also used in the same situation, but behind a function chain only
called by ``GNUTranslations``.
Cache the compiled regex globally the first time it is used. The
finditer function is converted to a method call on the compiled
object which is slightly more efficient, and necessary for the
delayed re import.
files:
A Misc/NEWS.d/next/Library/2025-01-15-19-16-50.gh-issue-118761.cbW2ZL.rst
M Lib/gettext.py
diff --git a/Lib/gettext.py b/Lib/gettext.py
index a0d81cf846a05c..4c1f9427459b14 100644
--- a/Lib/gettext.py
+++ b/Lib/gettext.py
@@ -48,7 +48,6 @@
import operator
import os
-import re
import sys
@@ -70,22 +69,26 @@
# https://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms
# http://git.savannah.gnu.org/cgit/gettext.git/tree/gettext-runtime/intl/plur…
-_token_pattern = re.compile(r"""
- (?P<WHITESPACES>[ \t]+) | # spaces and horizontal tabs
- (?P<NUMBER>[0-9]+\b) | # decimal integer
- (?P<NAME>n\b) | # only n is allowed
- (?P<PARENTHESIS>[()]) |
- (?P<OPERATOR>[-*/%+?:]|[><!]=?|==|&&|\|\|) | # !, *, /, %, +, -, <, >,
- # <=, >=, ==, !=, &&, ||,
- # ? :
- # unary and bitwise ops
- # not allowed
- (?P<INVALID>\w+|.) # invalid token
- """, re.VERBOSE|re.DOTALL)
-
+_token_pattern = None
def _tokenize(plural):
- for mo in re.finditer(_token_pattern, plural):
+ global _token_pattern
+ if _token_pattern is None:
+ import re
+ _token_pattern = re.compile(r"""
+ (?P<WHITESPACES>[ \t]+) | # spaces and horizontal tabs
+ (?P<NUMBER>[0-9]+\b) | # decimal integer
+ (?P<NAME>n\b) | # only n is allowed
+ (?P<PARENTHESIS>[()]) |
+ (?P<OPERATOR>[-*/%+?:]|[><!]=?|==|&&|\|\|) | # !, *, /, %, +, -, <, >,
+ # <=, >=, ==, !=, &&, ||,
+ # ? :
+ # unary and bitwise ops
+ # not allowed
+ (?P<INVALID>\w+|.) # invalid token
+ """, re.VERBOSE|re.DOTALL)
+
+ for mo in _token_pattern.finditer(plural):
kind = mo.lastgroup
if kind == 'WHITESPACES':
continue
diff --git a/Misc/NEWS.d/next/Library/2025-01-15-19-16-50.gh-issue-118761.cbW2ZL.rst b/Misc/NEWS.d/next/Library/2025-01-15-19-16-50.gh-issue-118761.cbW2ZL.rst
new file mode 100644
index 00000000000000..0eef8777512dd8
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-15-19-16-50.gh-issue-118761.cbW2ZL.rst
@@ -0,0 +1,3 @@
+Reduce import time of :mod:`gettext` by up to ten times, by importing
+:mod:`re` on demand. In particular, ``re`` is no longer implicitly
+exposed as ``gettext.re``. Patch by Eli Schwartz.
1
0
Jan. 19, 2025
https://github.com/python/cpython/commit/bbeb219354764aef85e660be6570f0f329…
commit: bbeb219354764aef85e660be6570f0f329e7227e
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-19T22:47:05+01:00
summary:
Complete doc of pending C API removals in Python 3.15 (#129032)
files:
M Doc/c-api/init.rst
M Doc/deprecations/c-api-pending-removal-in-3.15.rst
diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst
index 97996a6f69dd22..dc44f3eaf87765 100644
--- a/Doc/c-api/init.rst
+++ b/Doc/c-api/init.rst
@@ -109,7 +109,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
Set by the :option:`-b` option.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_DebugFlag
@@ -123,7 +123,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
Set by the :option:`-d` option and the :envvar:`PYTHONDEBUG` environment
variable.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_DontWriteBytecodeFlag
@@ -137,7 +137,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
Set by the :option:`-B` option and the :envvar:`PYTHONDONTWRITEBYTECODE`
environment variable.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_FrozenFlag
@@ -150,7 +150,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
Private flag used by ``_freeze_module`` and ``frozenmain`` programs.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_HashRandomizationFlag
@@ -165,7 +165,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
If the flag is non-zero, read the :envvar:`PYTHONHASHSEED` environment
variable to initialize the secret hash seed.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_IgnoreEnvironmentFlag
@@ -178,7 +178,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
Set by the :option:`-E` and :option:`-I` options.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_InspectFlag
@@ -193,7 +193,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
Set by the :option:`-i` option and the :envvar:`PYTHONINSPECT` environment
variable.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_InteractiveFlag
@@ -218,7 +218,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
.. versionadded:: 3.4
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_LegacyWindowsFSEncodingFlag
@@ -237,7 +237,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
.. availability:: Windows.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_LegacyWindowsStdioFlag
@@ -255,7 +255,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
.. availability:: Windows.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_NoSiteFlag
@@ -270,7 +270,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
Set by the :option:`-S` option.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_NoUserSiteDirectory
@@ -284,7 +284,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
Set by the :option:`-s` and :option:`-I` options, and the
:envvar:`PYTHONNOUSERSITE` environment variable.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_OptimizeFlag
@@ -295,7 +295,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
Set by the :option:`-O` option and the :envvar:`PYTHONOPTIMIZE` environment
variable.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_QuietFlag
@@ -309,7 +309,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
.. versionadded:: 3.2
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_UnbufferedStdioFlag
@@ -322,7 +322,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
Set by the :option:`-u` option and the :envvar:`PYTHONUNBUFFERED`
environment variable.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
.. c:var:: int Py_VerboseFlag
@@ -338,7 +338,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
Set by the :option:`-v` option and the :envvar:`PYTHONVERBOSE` environment
variable.
- .. deprecated-removed:: 3.12 3.14
+ .. deprecated-removed:: 3.12 3.15
Initializing and finalizing the interpreter
@@ -606,7 +606,7 @@ Process-wide parameters
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
:c:expr:`wchar_*` string.
- .. deprecated:: 3.11
+ .. deprecated-removed:: 3.11 3.15
.. c:function:: wchar_t* Py_GetProgramName()
@@ -868,7 +868,7 @@ Process-wide parameters
.. XXX impl. doesn't seem consistent in allowing ``0``/``NULL`` for the params;
check w/ Guido.
- .. deprecated:: 3.11
+ .. deprecated-removed:: 3.11 3.15
.. c:function:: void PySys_SetArgv(int argc, wchar_t **argv)
@@ -889,7 +889,7 @@ Process-wide parameters
.. versionchanged:: 3.4 The *updatepath* value depends on :option:`-I`.
- .. deprecated:: 3.11
+ .. deprecated-removed:: 3.11 3.15
.. c:function:: void Py_SetPythonHome(const wchar_t *home)
@@ -910,7 +910,7 @@ Process-wide parameters
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
:c:expr:`wchar_*` string.
- .. deprecated:: 3.11
+ .. deprecated-removed:: 3.11 3.15
.. c:function:: wchar_t* Py_GetPythonHome()
diff --git a/Doc/deprecations/c-api-pending-removal-in-3.15.rst b/Doc/deprecations/c-api-pending-removal-in-3.15.rst
index ba908f81b7f800..ac31b3cc8cd451 100644
--- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst
+++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst
@@ -5,7 +5,9 @@ Pending removal in Python 3.15
* The :c:func:`PyImport_ImportModuleNoBlock`:
Use :c:func:`PyImport_ImportModule` instead.
* :c:func:`PyWeakref_GetObject` and :c:func:`PyWeakref_GET_OBJECT`:
- Use :c:func:`PyWeakref_GetRef` instead.
+ Use :c:func:`PyWeakref_GetRef` instead. The `pythoncapi-compat project
+ <https://github.com/python/pythoncapi-compat/>`__ can be used to get
+ :c:func:`PyWeakref_GetRef` on Python 3.12 and older.
* :c:type:`Py_UNICODE` type and the :c:macro:`!Py_UNICODE_WIDE` macro:
Use :c:type:`wchar_t` instead.
* Python initialization functions:
@@ -23,9 +25,11 @@ Pending removal in Python 3.15
* :c:func:`Py_GetProgramName`:
Get :data:`sys.executable` instead.
* :c:func:`Py_GetPythonHome`:
- Get :c:member:`PyConfig.home`
+ Get :c:func:`PyConfig_Get("home") <PyConfig_Get>`
or the :envvar:`PYTHONHOME` environment variable instead.
+ See also the :c:func:`PyConfig_Get` function.
+
* Functions to configure Python's initialization, deprecated in Python 3.11:
* :c:func:`!PySys_SetArgvEx()`:
1
0
[3.12] gh-80222: Fix email address header folding with long quoted-string (GH-122753) (#129008)
by bitdancer Jan. 19, 2025
by bitdancer Jan. 19, 2025
Jan. 19, 2025
https://github.com/python/cpython/commit/b8170e58849a7728ebc9b58e222aa5bd05…
commit: b8170e58849a7728ebc9b58e222aa5bd051cf7c4
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: bitdancer <rdmurray(a)bitdance.com>
date: 2025-01-19T16:07:39-05:00
summary:
[3.12] gh-80222: Fix email address header folding with long quoted-string (GH-122753) (#129008)
gh-80222: Fix email address header folding with long quoted-string (GH-122753)
Email generators using email.policy.default could incorrectly omit the
quote ('"') characters from a quoted-string during header refolding,
leading to invalid address headers and enabling header spoofing. This
change restores the quote characters on a bare-quoted-string as the
header is refolded, and escapes backslash and quote chars in the string.
(cherry picked from commit 5aaf41685834901e4ed0a40f4c055b92991a0bb5)
Co-authored-by: Mike Edmunds <medmunds(a)gmail.com>
files:
A Misc/NEWS.d/next/Security/2024-08-06-11-43-08.gh-issue-80222.wfR4BU.rst
M Lib/email/_header_value_parser.py
M Lib/test/test_email/test__header_value_parser.py
diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py
index ec2215a5e5f33c..3d845c09d415f6 100644
--- a/Lib/email/_header_value_parser.py
+++ b/Lib/email/_header_value_parser.py
@@ -95,8 +95,16 @@
NLSET = {'\n', '\r'}
SPECIALSNL = SPECIALS | NLSET
+
+def make_quoted_pairs(value):
+ """Escape dquote and backslash for use within a quoted-string."""
+ return str(value).replace('\\', '\\\\').replace('"', '\\"')
+
+
def quote_string(value):
- return '"'+str(value).replace('\\', '\\\\').replace('"', r'\"')+'"'
+ escaped = make_quoted_pairs(value)
+ return f'"{escaped}"'
+
# Match a RFC 2047 word, looks like =?utf-8?q?someword?=
rfc2047_matcher = re.compile(r'''
@@ -2905,6 +2913,15 @@ def _refold_parse_tree(parse_tree, *, policy):
if not hasattr(part, 'encode'):
# It's not a terminal, try folding the subparts.
newparts = list(part)
+ if part.token_type == 'bare-quoted-string':
+ # To fold a quoted string we need to create a list of terminal
+ # tokens that will render the leading and trailing quotes
+ # and use quoted pairs in the value as appropriate.
+ newparts = (
+ [ValueTerminal('"', 'ptext')] +
+ [ValueTerminal(make_quoted_pairs(p), 'ptext')
+ for p in newparts] +
+ [ValueTerminal('"', 'ptext')])
if not part.as_ew_allowed:
wrap_as_ew_blocked += 1
newparts.append(end_ew_not_allowed)
diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py
index 5413319a414a62..efd1695711d7c1 100644
--- a/Lib/test/test_email/test__header_value_parser.py
+++ b/Lib/test/test_email/test__header_value_parser.py
@@ -3082,13 +3082,40 @@ def test_address_list_with_list_separator_after_fold(self):
self._test(parser.get_address_list(to)[0],
f'{a},\n =?utf-8?q?H=C3=BCbsch?= Kaktus <beautiful(a)example.com>\n')
- a = '.' * 79
+ a = '.' * 79 # ('.' is a special, so must be in quoted-string.)
to = f'"{a}" <xyz(a)example.com>, "Hübsch Kaktus" <beautiful(a)example.com>'
self._test(parser.get_address_list(to)[0],
- f'{a}\n'
+ f'"{a}"\n'
' <xyz(a)example.com>, =?utf-8?q?H=C3=BCbsch?= Kaktus '
'<beautiful(a)example.com>\n')
+ def test_address_list_with_specials_in_long_quoted_string(self):
+ # Regression for gh-80222.
+ policy = self.policy.clone(max_line_length=40)
+ cases = [
+ # (to, folded)
+ ('"Exfiltrator <spy(a)example.org> (unclosed comment?" <to(a)example.com>',
+ '"Exfiltrator <spy(a)example.org> (unclosed\n'
+ ' comment?" <to(a)example.com>\n'),
+ ('"Escaped \\" chars \\\\ in quoted-string stay escaped" <to(a)example.com>',
+ '"Escaped \\" chars \\\\ in quoted-string\n'
+ ' stay escaped" <to(a)example.com>\n'),
+ ('This long display name does not need quotes <to(a)example.com>',
+ 'This long display name does not need\n'
+ ' quotes <to(a)example.com>\n'),
+ ('"Quotes are not required but are retained here" <to(a)example.com>',
+ '"Quotes are not required but are\n'
+ ' retained here" <to(a)example.com>\n'),
+ ('"A quoted-string, it can be a valid local-part"@example.com',
+ '"A quoted-string, it can be a valid\n'
+ ' local-part"@example.com\n'),
+ ('"local-part-with-specials(a)but-no-fws.cannot-fold"@example.com',
+ '"local-part-with-specials(a)but-no-fws.cannot-fold"@example.com\n'),
+ ]
+ for (to, folded) in cases:
+ with self.subTest(to=to):
+ self._test(parser.get_address_list(to)[0], folded, policy=policy)
+
# XXX Need tests with comments on various sides of a unicode token,
# and with unicode tokens in the comments. Spaces inside the quotes
# currently don't do the right thing.
diff --git a/Misc/NEWS.d/next/Security/2024-08-06-11-43-08.gh-issue-80222.wfR4BU.rst b/Misc/NEWS.d/next/Security/2024-08-06-11-43-08.gh-issue-80222.wfR4BU.rst
new file mode 100644
index 00000000000000..0f0661d0b1cf4a
--- /dev/null
+++ b/Misc/NEWS.d/next/Security/2024-08-06-11-43-08.gh-issue-80222.wfR4BU.rst
@@ -0,0 +1,6 @@
+Fix bug in the folding of quoted strings when flattening an email message using
+a modern email policy. Previously when a quoted string was folded so that
+it spanned more than one line, the surrounding quotes and internal escapes
+would be omitted. This could theoretically be used to spoof header lines
+using a carefully constructed quoted string if the resulting rendered email
+was transmitted or re-parsed.
1
0
[3.13] gh-80222: Fix email address header folding with long quoted-string (GH-122753) (#129007)
by bitdancer Jan. 19, 2025
by bitdancer Jan. 19, 2025
Jan. 19, 2025
https://github.com/python/cpython/commit/21200895478b8076fc0bda6ee2c26f0d87…
commit: 21200895478b8076fc0bda6ee2c26f0d87c9404b
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: bitdancer <rdmurray(a)bitdance.com>
date: 2025-01-19T16:06:28-05:00
summary:
[3.13] gh-80222: Fix email address header folding with long quoted-string (GH-122753) (#129007)
gh-80222: Fix email address header folding with long quoted-string (GH-122753)
Email generators using email.policy.default could incorrectly omit the
quote ('"') characters from a quoted-string during header refolding,
leading to invalid address headers and enabling header spoofing. This
change restores the quote characters on a bare-quoted-string as the
header is refolded, and escapes backslash and quote chars in the string.
(cherry picked from commit 5aaf41685834901e4ed0a40f4c055b92991a0bb5)
Co-authored-by: Mike Edmunds <medmunds(a)gmail.com>
files:
A Misc/NEWS.d/next/Security/2024-08-06-11-43-08.gh-issue-80222.wfR4BU.rst
M Lib/email/_header_value_parser.py
M Lib/test/test_email/test__header_value_parser.py
diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py
index ec2215a5e5f33c..3d845c09d415f6 100644
--- a/Lib/email/_header_value_parser.py
+++ b/Lib/email/_header_value_parser.py
@@ -95,8 +95,16 @@
NLSET = {'\n', '\r'}
SPECIALSNL = SPECIALS | NLSET
+
+def make_quoted_pairs(value):
+ """Escape dquote and backslash for use within a quoted-string."""
+ return str(value).replace('\\', '\\\\').replace('"', '\\"')
+
+
def quote_string(value):
- return '"'+str(value).replace('\\', '\\\\').replace('"', r'\"')+'"'
+ escaped = make_quoted_pairs(value)
+ return f'"{escaped}"'
+
# Match a RFC 2047 word, looks like =?utf-8?q?someword?=
rfc2047_matcher = re.compile(r'''
@@ -2905,6 +2913,15 @@ def _refold_parse_tree(parse_tree, *, policy):
if not hasattr(part, 'encode'):
# It's not a terminal, try folding the subparts.
newparts = list(part)
+ if part.token_type == 'bare-quoted-string':
+ # To fold a quoted string we need to create a list of terminal
+ # tokens that will render the leading and trailing quotes
+ # and use quoted pairs in the value as appropriate.
+ newparts = (
+ [ValueTerminal('"', 'ptext')] +
+ [ValueTerminal(make_quoted_pairs(p), 'ptext')
+ for p in newparts] +
+ [ValueTerminal('"', 'ptext')])
if not part.as_ew_allowed:
wrap_as_ew_blocked += 1
newparts.append(end_ew_not_allowed)
diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py
index 5413319a414a62..efd1695711d7c1 100644
--- a/Lib/test/test_email/test__header_value_parser.py
+++ b/Lib/test/test_email/test__header_value_parser.py
@@ -3082,13 +3082,40 @@ def test_address_list_with_list_separator_after_fold(self):
self._test(parser.get_address_list(to)[0],
f'{a},\n =?utf-8?q?H=C3=BCbsch?= Kaktus <beautiful(a)example.com>\n')
- a = '.' * 79
+ a = '.' * 79 # ('.' is a special, so must be in quoted-string.)
to = f'"{a}" <xyz(a)example.com>, "Hübsch Kaktus" <beautiful(a)example.com>'
self._test(parser.get_address_list(to)[0],
- f'{a}\n'
+ f'"{a}"\n'
' <xyz(a)example.com>, =?utf-8?q?H=C3=BCbsch?= Kaktus '
'<beautiful(a)example.com>\n')
+ def test_address_list_with_specials_in_long_quoted_string(self):
+ # Regression for gh-80222.
+ policy = self.policy.clone(max_line_length=40)
+ cases = [
+ # (to, folded)
+ ('"Exfiltrator <spy(a)example.org> (unclosed comment?" <to(a)example.com>',
+ '"Exfiltrator <spy(a)example.org> (unclosed\n'
+ ' comment?" <to(a)example.com>\n'),
+ ('"Escaped \\" chars \\\\ in quoted-string stay escaped" <to(a)example.com>',
+ '"Escaped \\" chars \\\\ in quoted-string\n'
+ ' stay escaped" <to(a)example.com>\n'),
+ ('This long display name does not need quotes <to(a)example.com>',
+ 'This long display name does not need\n'
+ ' quotes <to(a)example.com>\n'),
+ ('"Quotes are not required but are retained here" <to(a)example.com>',
+ '"Quotes are not required but are\n'
+ ' retained here" <to(a)example.com>\n'),
+ ('"A quoted-string, it can be a valid local-part"@example.com',
+ '"A quoted-string, it can be a valid\n'
+ ' local-part"@example.com\n'),
+ ('"local-part-with-specials(a)but-no-fws.cannot-fold"@example.com',
+ '"local-part-with-specials(a)but-no-fws.cannot-fold"@example.com\n'),
+ ]
+ for (to, folded) in cases:
+ with self.subTest(to=to):
+ self._test(parser.get_address_list(to)[0], folded, policy=policy)
+
# XXX Need tests with comments on various sides of a unicode token,
# and with unicode tokens in the comments. Spaces inside the quotes
# currently don't do the right thing.
diff --git a/Misc/NEWS.d/next/Security/2024-08-06-11-43-08.gh-issue-80222.wfR4BU.rst b/Misc/NEWS.d/next/Security/2024-08-06-11-43-08.gh-issue-80222.wfR4BU.rst
new file mode 100644
index 00000000000000..0f0661d0b1cf4a
--- /dev/null
+++ b/Misc/NEWS.d/next/Security/2024-08-06-11-43-08.gh-issue-80222.wfR4BU.rst
@@ -0,0 +1,6 @@
+Fix bug in the folding of quoted strings when flattening an email message using
+a modern email policy. Previously when a quoted string was folded so that
+it spanned more than one line, the surrounding quotes and internal escapes
+would be omitted. This could theoretically be used to spoof header lines
+using a carefully constructed quoted string if the resulting rendered email
+was transmitted or re-parsed.
1
0
Jan. 19, 2025
https://github.com/python/cpython/commit/d57b2d83dd470c5d3a391f4388e4bb41c9…
commit: d57b2d83dd470c5d3a391f4388e4bb41c9843fad
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-19T20:51:17+01:00
summary:
gh-77782: Postpone Py_VerboseFlag removal to Python 3.15 (#129024)
Postpone the global configuration variables removal to Python 3.15.
Do the same for PySys_SetArgvEx(), PySys_SetArgv(),
Py_SetProgramName() and Py_SetPythonHome().
files:
M Doc/deprecations/c-api-pending-removal-in-3.14.rst
M Doc/deprecations/c-api-pending-removal-in-3.15.rst
diff --git a/Doc/deprecations/c-api-pending-removal-in-3.14.rst b/Doc/deprecations/c-api-pending-removal-in-3.14.rst
index 9e10bf2691e5c8..c805074669811a 100644
--- a/Doc/deprecations/c-api-pending-removal-in-3.14.rst
+++ b/Doc/deprecations/c-api-pending-removal-in-3.14.rst
@@ -6,67 +6,3 @@ Pending removal in Python 3.14
* Creating :c:data:`immutable types <Py_TPFLAGS_IMMUTABLETYPE>` with mutable
bases (:gh:`95388`).
-
-* Functions to configure Python's initialization, deprecated in Python 3.11:
-
- * :c:func:`!PySys_SetArgvEx()`:
- Set :c:member:`PyConfig.argv` instead.
- * :c:func:`!PySys_SetArgv()`:
- Set :c:member:`PyConfig.argv` instead.
- * :c:func:`!Py_SetProgramName()`:
- Set :c:member:`PyConfig.program_name` instead.
- * :c:func:`!Py_SetPythonHome()`:
- Set :c:member:`PyConfig.home` instead.
-
- The :c:func:`Py_InitializeFromConfig` API should be used with
- :c:type:`PyConfig` instead.
-
-* Global configuration variables:
-
- * :c:var:`Py_DebugFlag`:
- Use :c:member:`PyConfig.parser_debug` instead.
- * :c:var:`Py_VerboseFlag`:
- Use :c:member:`PyConfig.verbose` instead.
- * :c:var:`Py_QuietFlag`:
- Use :c:member:`PyConfig.quiet` instead.
- * :c:var:`Py_InteractiveFlag`:
- Use :c:member:`PyConfig.interactive` instead.
- * :c:var:`Py_InspectFlag`:
- Use :c:member:`PyConfig.inspect` instead.
- * :c:var:`Py_OptimizeFlag`:
- Use :c:member:`PyConfig.optimization_level` instead.
- * :c:var:`Py_NoSiteFlag`:
- Use :c:member:`PyConfig.site_import` instead.
- * :c:var:`Py_BytesWarningFlag`:
- Use :c:member:`PyConfig.bytes_warning` instead.
- * :c:var:`Py_FrozenFlag`:
- Use :c:member:`PyConfig.pathconfig_warnings` instead.
- * :c:var:`Py_IgnoreEnvironmentFlag`:
- Use :c:member:`PyConfig.use_environment` instead.
- * :c:var:`Py_DontWriteBytecodeFlag`:
- Use :c:member:`PyConfig.write_bytecode` instead.
- * :c:var:`Py_NoUserSiteDirectory`:
- Use :c:member:`PyConfig.user_site_directory` instead.
- * :c:var:`Py_UnbufferedStdioFlag`:
- Use :c:member:`PyConfig.buffered_stdio` instead.
- * :c:var:`Py_HashRandomizationFlag`:
- Use :c:member:`PyConfig.use_hash_seed`
- and :c:member:`PyConfig.hash_seed` instead.
- * :c:var:`Py_IsolatedFlag`:
- Use :c:member:`PyConfig.isolated` instead.
- * :c:var:`Py_LegacyWindowsFSEncodingFlag`:
- Use :c:member:`PyPreConfig.legacy_windows_fs_encoding` instead.
- * :c:var:`Py_LegacyWindowsStdioFlag`:
- Use :c:member:`PyConfig.legacy_windows_stdio` instead.
- * :c:var:`!Py_FileSystemDefaultEncoding`:
- Use :c:member:`PyConfig.filesystem_encoding` instead.
- * :c:var:`!Py_HasFileSystemDefaultEncoding`:
- Use :c:member:`PyConfig.filesystem_encoding` instead.
- * :c:var:`!Py_FileSystemDefaultEncodeErrors`:
- Use :c:member:`PyConfig.filesystem_errors` instead.
- * :c:var:`!Py_UTF8Mode`:
- Use :c:member:`PyPreConfig.utf8_mode` instead.
- (see :c:func:`Py_PreInitialize`)
-
- The :c:func:`Py_InitializeFromConfig` API should be used with
- :c:type:`PyConfig` instead.
diff --git a/Doc/deprecations/c-api-pending-removal-in-3.15.rst b/Doc/deprecations/c-api-pending-removal-in-3.15.rst
index 0ce0f9c118c094..ba908f81b7f800 100644
--- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst
+++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst
@@ -25,3 +25,86 @@ Pending removal in Python 3.15
* :c:func:`Py_GetPythonHome`:
Get :c:member:`PyConfig.home`
or the :envvar:`PYTHONHOME` environment variable instead.
+
+* Functions to configure Python's initialization, deprecated in Python 3.11:
+
+ * :c:func:`!PySys_SetArgvEx()`:
+ Set :c:member:`PyConfig.argv` instead.
+ * :c:func:`!PySys_SetArgv()`:
+ Set :c:member:`PyConfig.argv` instead.
+ * :c:func:`!Py_SetProgramName()`:
+ Set :c:member:`PyConfig.program_name` instead.
+ * :c:func:`!Py_SetPythonHome()`:
+ Set :c:member:`PyConfig.home` instead.
+
+ The :c:func:`Py_InitializeFromConfig` API should be used with
+ :c:type:`PyConfig` instead.
+
+* Global configuration variables:
+
+ * :c:var:`Py_DebugFlag`:
+ Use :c:member:`PyConfig.parser_debug` or
+ :c:func:`PyConfig_Get("parser_debug") <PyConfig_Get>` instead.
+ * :c:var:`Py_VerboseFlag`:
+ Use :c:member:`PyConfig.verbose` or
+ :c:func:`PyConfig_Get("verbose") <PyConfig_Get>` instead.
+ * :c:var:`Py_QuietFlag`:
+ Use :c:member:`PyConfig.quiet` or
+ :c:func:`PyConfig_Get("quiet") <PyConfig_Get>` instead.
+ * :c:var:`Py_InteractiveFlag`:
+ Use :c:member:`PyConfig.interactive` or
+ :c:func:`PyConfig_Get("interactive") <PyConfig_Get>` instead.
+ * :c:var:`Py_InspectFlag`:
+ Use :c:member:`PyConfig.inspect` or
+ :c:func:`PyConfig_Get("inspect") <PyConfig_Get>` instead.
+ * :c:var:`Py_OptimizeFlag`:
+ Use :c:member:`PyConfig.optimization_level` or
+ :c:func:`PyConfig_Get("optimization_level") <PyConfig_Get>` instead.
+ * :c:var:`Py_NoSiteFlag`:
+ Use :c:member:`PyConfig.site_import` or
+ :c:func:`PyConfig_Get("site_import") <PyConfig_Get>` instead.
+ * :c:var:`Py_BytesWarningFlag`:
+ Use :c:member:`PyConfig.bytes_warning` or
+ :c:func:`PyConfig_Get("bytes_warning") <PyConfig_Get>` instead.
+ * :c:var:`Py_FrozenFlag`:
+ Use :c:member:`PyConfig.pathconfig_warnings` or
+ :c:func:`PyConfig_Get("pathconfig_warnings") <PyConfig_Get>` instead.
+ * :c:var:`Py_IgnoreEnvironmentFlag`:
+ Use :c:member:`PyConfig.use_environment` or
+ :c:func:`PyConfig_Get("use_environment") <PyConfig_Get>` instead.
+ * :c:var:`Py_DontWriteBytecodeFlag`:
+ Use :c:member:`PyConfig.write_bytecode` or
+ :c:func:`PyConfig_Get("write_bytecode") <PyConfig_Get>` instead.
+ * :c:var:`Py_NoUserSiteDirectory`:
+ Use :c:member:`PyConfig.user_site_directory` or
+ :c:func:`PyConfig_Get("user_site_directory") <PyConfig_Get>` instead.
+ * :c:var:`Py_UnbufferedStdioFlag`:
+ Use :c:member:`PyConfig.buffered_stdio` or
+ :c:func:`PyConfig_Get("buffered_stdio") <PyConfig_Get>` instead.
+ * :c:var:`Py_HashRandomizationFlag`:
+ Use :c:member:`PyConfig.use_hash_seed`
+ and :c:member:`PyConfig.hash_seed` or
+ :c:func:`PyConfig_Get("hash_seed") <PyConfig_Get>` instead.
+ * :c:var:`Py_IsolatedFlag`:
+ Use :c:member:`PyConfig.isolated` or
+ :c:func:`PyConfig_Get("isolated") <PyConfig_Get>` instead.
+ * :c:var:`Py_LegacyWindowsFSEncodingFlag`:
+ Use :c:member:`PyPreConfig.legacy_windows_fs_encoding` or
+ :c:func:`PyConfig_Get("legacy_windows_fs_encoding") <PyConfig_Get>` instead.
+ * :c:var:`Py_LegacyWindowsStdioFlag`:
+ Use :c:member:`PyConfig.legacy_windows_stdio` or
+ :c:func:`PyConfig_Get("legacy_windows_stdio") <PyConfig_Get>` instead.
+ * :c:var:`!Py_FileSystemDefaultEncoding`, :c:var:`!Py_HasFileSystemDefaultEncoding`:
+ Use :c:member:`PyConfig.filesystem_encoding` or
+ :c:func:`PyConfig_Get("filesystem_encoding") <PyConfig_Get>` instead.
+ * :c:var:`!Py_FileSystemDefaultEncodeErrors`:
+ Use :c:member:`PyConfig.filesystem_errors` or
+ :c:func:`PyConfig_Get("filesystem_errors") <PyConfig_Get>` instead.
+ * :c:var:`!Py_UTF8Mode`:
+ Use :c:member:`PyPreConfig.utf8_mode` or
+ :c:func:`PyConfig_Get("utf8_mode") <PyConfig_Get>` instead.
+ (see :c:func:`Py_PreInitialize`)
+
+ The :c:func:`Py_InitializeFromConfig` API should be used with
+ :c:type:`PyConfig` to set these options. Or :c:func:`PyConfig_Get` can be
+ used to get these options at runtime.
1
0
[3.12] gh-111495: Add more tests on PyEval C APIs (#122789) (#128987) (#129023)
by vstinner Jan. 19, 2025
by vstinner Jan. 19, 2025
Jan. 19, 2025
https://github.com/python/cpython/commit/fceb8c31ddf8db2fddd92c8c6437094081…
commit: fceb8c31ddf8db2fddd92c8c6437094081c91ac8
branch: 3.12
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-19T13:51:53Z
summary:
[3.12] gh-111495: Add more tests on PyEval C APIs (#122789) (#128987) (#129023)
* Add Lib/test/test_capi/test_eval.py
* Add Modules/_testlimitedcapi/eval.c
(cherry picked from commit bf8b3746398ea756c97e3cf263d63ca3ce3a544e)
* gh-111495: Fix refleaks in test_capi.test_eval tests (#122851)
(cherry picked from commit b4a316087c32d83e375087fd35fc511bc430ee8b)
(cherry picked from commit 430ccbc009aa7a2da92b85d7aeadd39e1666e875)
files:
A Lib/test/test_capi/test_eval.py
A Modules/_testcapi/eval.c
M Lib/test/test_capi/test_misc.py
M Modules/Setup.stdlib.in
M Modules/_testcapi/parts.h
M Modules/_testcapimodule.c
M PCbuild/_testcapi.vcxproj
M PCbuild/_testcapi.vcxproj.filters
diff --git a/Lib/test/test_capi/test_eval.py b/Lib/test/test_capi/test_eval.py
new file mode 100644
index 00000000000000..1fedf2f2b4b23b
--- /dev/null
+++ b/Lib/test/test_capi/test_eval.py
@@ -0,0 +1,88 @@
+import sys
+import unittest
+from test.support import import_helper
+
+_testcapi = import_helper.import_module('_testcapi')
+
+
+class Tests(unittest.TestCase):
+ def test_eval_get_func_name(self):
+ eval_get_func_name = _testcapi.eval_get_func_name
+
+ def function_example(): ...
+
+ class A:
+ def method_example(self): ...
+
+ self.assertEqual(eval_get_func_name(function_example),
+ "function_example")
+ self.assertEqual(eval_get_func_name(A.method_example),
+ "method_example")
+ self.assertEqual(eval_get_func_name(A().method_example),
+ "method_example")
+ self.assertEqual(eval_get_func_name(sum), "sum") # c function
+ self.assertEqual(eval_get_func_name(A), "type")
+
+ def test_eval_get_func_desc(self):
+ eval_get_func_desc = _testcapi.eval_get_func_desc
+
+ def function_example(): ...
+
+ class A:
+ def method_example(self): ...
+
+ self.assertEqual(eval_get_func_desc(function_example),
+ "()")
+ self.assertEqual(eval_get_func_desc(A.method_example),
+ "()")
+ self.assertEqual(eval_get_func_desc(A().method_example),
+ "()")
+ self.assertEqual(eval_get_func_desc(sum), "()") # c function
+ self.assertEqual(eval_get_func_desc(A), " object")
+
+ def test_eval_getlocals(self):
+ # Test PyEval_GetLocals()
+ x = 1
+ self.assertEqual(_testcapi.eval_getlocals(),
+ {'self': self,
+ 'x': 1})
+
+ y = 2
+ self.assertEqual(_testcapi.eval_getlocals(),
+ {'self': self,
+ 'x': 1,
+ 'y': 2})
+
+ def test_eval_getglobals(self):
+ # Test PyEval_GetGlobals()
+ self.assertEqual(_testcapi.eval_getglobals(),
+ globals())
+
+ def test_eval_getbuiltins(self):
+ # Test PyEval_GetBuiltins()
+ self.assertEqual(_testcapi.eval_getbuiltins(),
+ globals()['__builtins__'])
+
+ def test_eval_getframe(self):
+ # Test PyEval_GetFrame()
+ self.assertEqual(_testcapi.eval_getframe(),
+ sys._getframe())
+
+ def test_eval_get_recursion_limit(self):
+ # Test Py_GetRecursionLimit()
+ self.assertEqual(_testcapi.eval_get_recursion_limit(),
+ sys.getrecursionlimit())
+
+ def test_eval_set_recursion_limit(self):
+ # Test Py_SetRecursionLimit()
+ old_limit = sys.getrecursionlimit()
+ try:
+ limit = old_limit + 123
+ _testcapi.eval_set_recursion_limit(limit)
+ self.assertEqual(sys.getrecursionlimit(), limit)
+ finally:
+ sys.setrecursionlimit(old_limit)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py
index 98c74a44e4cb27..f284e665d6fde0 100644
--- a/Lib/test/test_capi/test_misc.py
+++ b/Lib/test/test_capi/test_misc.py
@@ -879,36 +879,6 @@ def __init__(self):
_testcapi.clear_managed_dict(c)
self.assertEqual(c.__dict__, {})
- def test_eval_get_func_name(self):
- def function_example(): ...
-
- class A:
- def method_example(self): ...
-
- self.assertEqual(_testcapi.eval_get_func_name(function_example),
- "function_example")
- self.assertEqual(_testcapi.eval_get_func_name(A.method_example),
- "method_example")
- self.assertEqual(_testcapi.eval_get_func_name(A().method_example),
- "method_example")
- self.assertEqual(_testcapi.eval_get_func_name(sum), "sum") # c function
- self.assertEqual(_testcapi.eval_get_func_name(A), "type")
-
- def test_eval_get_func_desc(self):
- def function_example(): ...
-
- class A:
- def method_example(self): ...
-
- self.assertEqual(_testcapi.eval_get_func_desc(function_example),
- "()")
- self.assertEqual(_testcapi.eval_get_func_desc(A.method_example),
- "()")
- self.assertEqual(_testcapi.eval_get_func_desc(A().method_example),
- "()")
- self.assertEqual(_testcapi.eval_get_func_desc(sum), "()") # c function
- self.assertEqual(_testcapi.eval_get_func_desc(A), " object")
-
def test_function_get_code(self):
import types
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in
index d60afcf55dba4a..5e587dd3a5a397 100644
--- a/Modules/Setup.stdlib.in
+++ b/Modules/Setup.stdlib.in
@@ -168,7 +168,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/bytearray.c _testcapi/bytes.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/pytime.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyos.c _testcapi/run.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/heaptype_relative.c _testcapi/gc.c _testcapi/sys.c _testcapi/import.c
+@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/vectorcall_limited.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/bytearray.c _testcapi/bytes.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/pytime.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyos.c _testcapi/run.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/heaptype_relative.c _testcapi/gc.c _testcapi/sys.c _testcapi/import.c _testcapi/eval.c
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
# Some testing modules MUST be built as shared libraries.
diff --git a/Modules/_testcapi/eval.c b/Modules/_testcapi/eval.c
new file mode 100644
index 00000000000000..581b5579178910
--- /dev/null
+++ b/Modules/_testcapi/eval.c
@@ -0,0 +1,74 @@
+#include "parts.h"
+#include "util.h"
+
+static PyObject *
+eval_get_func_name(PyObject *self, PyObject *func)
+{
+ return PyUnicode_FromString(PyEval_GetFuncName(func));
+}
+
+static PyObject *
+eval_get_func_desc(PyObject *self, PyObject *func)
+{
+ return PyUnicode_FromString(PyEval_GetFuncDesc(func));
+}
+
+static PyObject *
+eval_getlocals(PyObject *module, PyObject *Py_UNUSED(args))
+{
+ return Py_XNewRef(PyEval_GetLocals());
+}
+
+static PyObject *
+eval_getglobals(PyObject *module, PyObject *Py_UNUSED(args))
+{
+ return Py_XNewRef(PyEval_GetGlobals());
+}
+
+static PyObject *
+eval_getbuiltins(PyObject *module, PyObject *Py_UNUSED(args))
+{
+ return Py_XNewRef(PyEval_GetBuiltins());
+}
+
+static PyObject *
+eval_getframe(PyObject *module, PyObject *Py_UNUSED(args))
+{
+ return Py_XNewRef(PyEval_GetFrame());
+}
+
+static PyObject *
+eval_get_recursion_limit(PyObject *module, PyObject *Py_UNUSED(args))
+{
+ int limit = Py_GetRecursionLimit();
+ return PyLong_FromLong(limit);
+}
+
+static PyObject *
+eval_set_recursion_limit(PyObject *module, PyObject *args)
+{
+ int limit;
+ if (!PyArg_ParseTuple(args, "i", &limit)) {
+ return NULL;
+ }
+ Py_SetRecursionLimit(limit);
+ Py_RETURN_NONE;
+}
+
+static PyMethodDef test_methods[] = {
+ {"eval_get_func_name", eval_get_func_name, METH_O, NULL},
+ {"eval_get_func_desc", eval_get_func_desc, METH_O, NULL},
+ {"eval_getlocals", eval_getlocals, METH_NOARGS},
+ {"eval_getglobals", eval_getglobals, METH_NOARGS},
+ {"eval_getbuiltins", eval_getbuiltins, METH_NOARGS},
+ {"eval_getframe", eval_getframe, METH_NOARGS},
+ {"eval_get_recursion_limit", eval_get_recursion_limit, METH_NOARGS},
+ {"eval_set_recursion_limit", eval_set_recursion_limit, METH_VARARGS},
+ {NULL},
+};
+
+int
+_PyTestCapi_Init_Eval(PyObject *m)
+{
+ return PyModule_AddFunctions(m, test_methods);
+}
diff --git a/Modules/_testcapi/parts.h b/Modules/_testcapi/parts.h
index bc348dc122c525..4ca46c800aa9eb 100644
--- a/Modules/_testcapi/parts.h
+++ b/Modules/_testcapi/parts.h
@@ -56,6 +56,7 @@ int _PyTestCapi_Init_Immortal(PyObject *module);
int _PyTestCapi_Init_GC(PyObject *module);
int _PyTestCapi_Init_Sys(PyObject *module);
int _PyTestCapi_Init_Import(PyObject *module);
+int _PyTestCapi_Init_Eval(PyObject *module);
#ifdef LIMITED_API_AVAILABLE
int _PyTestCapi_Init_VectorcallLimited(PyObject *module);
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 21d1228d79fe44..1fbeb58e3d404b 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2797,18 +2797,6 @@ test_frame_getvarstring(PyObject *self, PyObject *args)
}
-static PyObject *
-eval_get_func_name(PyObject *self, PyObject *func)
-{
- return PyUnicode_FromString(PyEval_GetFuncName(func));
-}
-
-static PyObject *
-eval_get_func_desc(PyObject *self, PyObject *func)
-{
- return PyUnicode_FromString(PyEval_GetFuncDesc(func));
-}
-
static PyObject *
gen_get_code(PyObject *self, PyObject *gen)
{
@@ -3460,8 +3448,6 @@ static PyMethodDef TestMethods[] = {
{"frame_new", frame_new, METH_VARARGS, NULL},
{"frame_getvar", test_frame_getvar, METH_VARARGS, NULL},
{"frame_getvarstring", test_frame_getvarstring, METH_VARARGS, NULL},
- {"eval_get_func_name", eval_get_func_name, METH_O, NULL},
- {"eval_get_func_desc", eval_get_func_desc, METH_O, NULL},
{"gen_get_code", gen_get_code, METH_O, NULL},
{"get_feature_macros", get_feature_macros, METH_NOARGS, NULL},
{"test_code_api", test_code_api, METH_NOARGS, NULL},
@@ -4174,6 +4160,9 @@ PyInit__testcapi(void)
if (_PyTestCapi_Init_Import(m) < 0) {
return NULL;
}
+ if (_PyTestCapi_Init_Eval(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 ec24c62903af90..06be7d291b17f3 100644
--- a/PCbuild/_testcapi.vcxproj
+++ b/PCbuild/_testcapi.vcxproj
@@ -128,6 +128,7 @@
<ClCompile Include="..\Modules\_testcapi\immortal.c" />
<ClCompile Include="..\Modules\_testcapi\gc.c" />
<ClCompile Include="..\Modules\_testcapi\run.c" />
+ <ClCompile Include="..\Modules\_testcapi\eval.c" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\PC\python_nt.rc" />
diff --git a/PCbuild/_testcapi.vcxproj.filters b/PCbuild/_testcapi.vcxproj.filters
index 99eefb7b565393..309a016da2d587 100644
--- a/PCbuild/_testcapi.vcxproj.filters
+++ b/PCbuild/_testcapi.vcxproj.filters
@@ -111,6 +111,9 @@
<ClCompile Include="..\Modules\_testcapi\import.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\Modules\_testcapi\eval.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\PC\python_nt.rc">
1
0
[3.12] gh-128679: Fix tracemalloc.stop() race conditions (#128897) (#129022)
by vstinner Jan. 19, 2025
by vstinner Jan. 19, 2025
Jan. 19, 2025
https://github.com/python/cpython/commit/6df22cbf6049d09f45e214e74345a5159f…
commit: 6df22cbf6049d09f45e214e74345a5159f7e202b
branch: 3.12
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-19T13:24:14Z
summary:
[3.12] gh-128679: Fix tracemalloc.stop() race conditions (#128897) (#129022)
[3.13] gh-128679: Fix tracemalloc.stop() race conditions (#128897)
tracemalloc_alloc(), tracemalloc_realloc(), PyTraceMalloc_Track(),
PyTraceMalloc_Untrack() and _PyTraceMalloc_TraceRef() now check
tracemalloc_config.tracing after calling TABLES_LOCK().
_PyTraceMalloc_Stop() now protects more code with TABLES_LOCK(),
especially setting tracemalloc_config.tracing to 1.
Add a test using PyTraceMalloc_Track() to test tracemalloc.stop()
race condition.
Call _PyTraceMalloc_Init() at Python startup.
(cherry picked from commit 6b47499510e47c0401d1f6cca2660fc12c496e39)
files:
A Misc/NEWS.d/next/Library/2025-01-10-15-43-52.gh-issue-128679.KcfVVR.rst
M Include/tracemalloc.h
M Lib/test/test_tracemalloc.py
M Modules/_testcapimodule.c
M Modules/_tracemalloc.c
M Python/pylifecycle.c
M Python/tracemalloc.c
diff --git a/Include/tracemalloc.h b/Include/tracemalloc.h
index 4db34b9509e7e2..2c88dbab7b8d35 100644
--- a/Include/tracemalloc.h
+++ b/Include/tracemalloc.h
@@ -50,7 +50,7 @@ PyAPI_FUNC(PyObject *) _PyTraceMalloc_GetTraces(void);
PyAPI_FUNC(PyObject *) _PyTraceMalloc_GetObjectTraceback(PyObject *obj);
/* Initialize tracemalloc */
-PyAPI_FUNC(int) _PyTraceMalloc_Init(void);
+PyAPI_FUNC(PyStatus) _PyTraceMalloc_Init(void);
/* Start tracemalloc */
PyAPI_FUNC(int) _PyTraceMalloc_Start(int max_nframe);
diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py
index 94bcee302fe730..97103a32e02ed0 100644
--- a/Lib/test/test_tracemalloc.py
+++ b/Lib/test/test_tracemalloc.py
@@ -8,6 +8,7 @@
interpreter_requires_environment)
from test import support
from test.support import os_helper
+from test.support import threading_helper
try:
import _testcapi
@@ -946,7 +947,6 @@ def check_env_var_invalid(self, nframe):
return
self.fail(f"unexpected output: {stderr!a}")
-
def test_env_var_invalid(self):
for nframe in INVALID_NFRAME:
with self.subTest(nframe=nframe):
@@ -1095,6 +1095,14 @@ def test_stop_untrack(self):
with self.assertRaises(RuntimeError):
self.untrack()
+ @unittest.skipIf(_testcapi is None, 'need _testcapi')
+ @threading_helper.requires_working_threading()
+ # gh-128679: Test crash on a debug build (especially on FreeBSD).
+ @unittest.skipIf(support.Py_DEBUG, 'need release build')
+ def test_tracemalloc_track_race(self):
+ # gh-128679: Test fix for tracemalloc.stop() race condition
+ _testcapi.tracemalloc_track_race()
+
if __name__ == "__main__":
unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2025-01-10-15-43-52.gh-issue-128679.KcfVVR.rst b/Misc/NEWS.d/next/Library/2025-01-10-15-43-52.gh-issue-128679.KcfVVR.rst
new file mode 100644
index 00000000000000..837f90df07a705
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-10-15-43-52.gh-issue-128679.KcfVVR.rst
@@ -0,0 +1,3 @@
+Fix :func:`tracemalloc.stop` race condition. Fix :mod:`tracemalloc` to
+support calling :func:`tracemalloc.stop` in one thread, while another thread
+is tracing memory allocations. Patch by Victor Stinner.
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 244bfab8d986f2..21d1228d79fe44 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -3238,6 +3238,105 @@ test_atexit(PyObject *self, PyObject *Py_UNUSED(args))
static PyObject *test_buildvalue_issue38913(PyObject *, PyObject *);
+
+static void
+tracemalloc_track_race_thread(void *data)
+{
+ PyTraceMalloc_Track(123, 10, 1);
+
+ PyThread_type_lock lock = (PyThread_type_lock)data;
+ PyThread_release_lock(lock);
+}
+
+// gh-128679: Test fix for tracemalloc.stop() race condition
+static PyObject *
+tracemalloc_track_race(PyObject *self, PyObject *args)
+{
+#define NTHREAD 50
+ PyObject *tracemalloc = NULL;
+ PyObject *stop = NULL;
+ PyThread_type_lock locks[NTHREAD];
+ memset(locks, 0, sizeof(locks));
+
+ // Call tracemalloc.start()
+ tracemalloc = PyImport_ImportModule("tracemalloc");
+ if (tracemalloc == NULL) {
+ goto error;
+ }
+ PyObject *start = PyObject_GetAttrString(tracemalloc, "start");
+ if (start == NULL) {
+ goto error;
+ }
+ PyObject *res = PyObject_CallNoArgs(start);
+ Py_DECREF(start);
+ if (res == NULL) {
+ goto error;
+ }
+ Py_DECREF(res);
+
+ stop = PyObject_GetAttrString(tracemalloc, "stop");
+ Py_CLEAR(tracemalloc);
+ if (stop == NULL) {
+ goto error;
+ }
+
+ // Start threads
+ for (size_t i = 0; i < NTHREAD; i++) {
+ PyThread_type_lock lock = PyThread_allocate_lock();
+ if (!lock) {
+ PyErr_NoMemory();
+ goto error;
+ }
+ locks[i] = lock;
+ PyThread_acquire_lock(lock, 1);
+
+ unsigned long thread;
+ thread = PyThread_start_new_thread(tracemalloc_track_race_thread,
+ (void*)lock);
+ if (thread == (unsigned long)-1) {
+ PyErr_SetString(PyExc_RuntimeError, "can't start new thread");
+ goto error;
+ }
+ }
+
+ // Call tracemalloc.stop() while threads are running
+ res = PyObject_CallNoArgs(stop);
+ Py_CLEAR(stop);
+ if (res == NULL) {
+ goto error;
+ }
+ Py_DECREF(res);
+
+ // Wait until threads complete with the GIL released
+ Py_BEGIN_ALLOW_THREADS
+ for (size_t i = 0; i < NTHREAD; i++) {
+ PyThread_type_lock lock = locks[i];
+ PyThread_acquire_lock(lock, 1);
+ PyThread_release_lock(lock);
+ }
+ Py_END_ALLOW_THREADS
+
+ // Free threads locks
+ for (size_t i=0; i < NTHREAD; i++) {
+ PyThread_type_lock lock = locks[i];
+ PyThread_free_lock(lock);
+ }
+ Py_RETURN_NONE;
+
+error:
+ Py_CLEAR(tracemalloc);
+ Py_CLEAR(stop);
+ for (size_t i=0; i < NTHREAD; i++) {
+ PyThread_type_lock lock = locks[i];
+ if (lock) {
+ PyThread_free_lock(lock);
+ }
+ }
+ return NULL;
+#undef NTHREAD
+}
+
+
static PyMethodDef TestMethods[] = {
{"set_errno", set_errno, METH_VARARGS},
{"test_config", test_config, METH_NOARGS},
@@ -3378,6 +3477,7 @@ static PyMethodDef TestMethods[] = {
{"function_get_kw_defaults", function_get_kw_defaults, METH_O, NULL},
{"function_set_kw_defaults", function_set_kw_defaults, METH_VARARGS, NULL},
{"test_atexit", test_atexit, METH_NOARGS},
+ {"tracemalloc_track_race", tracemalloc_track_race, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index f3f4af9aba08c1..3a4092c9d0859b 100644
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -219,10 +219,5 @@ PyInit__tracemalloc(void)
if (m == NULL)
return NULL;
- if (_PyTraceMalloc_Init() < 0) {
- Py_DECREF(m);
- return NULL;
- }
-
return m;
}
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index e9c1a0d72d6d4d..f301026fa5befd 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -654,6 +654,11 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
// didn't depend on interp->feature_flags being set already.
_PyObject_InitState(interp);
+ status = _PyTraceMalloc_Init();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
+ }
+
PyThreadState *tstate = _PyThreadState_New(interp);
if (tstate == NULL) {
return _PyStatus_ERR("can't make first thread");
diff --git a/Python/tracemalloc.c b/Python/tracemalloc.c
index e13064bd145e8e..9e653770c3eab5 100644
--- a/Python/tracemalloc.c
+++ b/Python/tracemalloc.c
@@ -2,6 +2,7 @@
#include "pycore_fileutils.h" // _Py_write_noraise()
#include "pycore_gc.h" // PyGC_Head
#include "pycore_hashtable.h" // _Py_hashtable_t
+#include "pycore_initconfig.h" // _PyStatus_NO_MEMORY()
#include "pycore_object.h" // _PyType_PreHeaderSize
#include "pycore_pymem.h" // _Py_tracemalloc_config
#include "pycore_runtime.h" // _Py_ID()
@@ -536,12 +537,16 @@ tracemalloc_alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
return NULL;
TABLES_LOCK();
- if (ADD_TRACE(ptr, nelem * elsize) < 0) {
- /* Failed to allocate a trace for the new memory block */
- TABLES_UNLOCK();
- alloc->free(alloc->ctx, ptr);
- return NULL;
+
+ if (tracemalloc_config.tracing) {
+ if (ADD_TRACE(ptr, nelem * elsize) < 0) {
+ /* Failed to allocate a trace for the new memory block */
+ alloc->free(alloc->ctx, ptr);
+ ptr = NULL;
+ }
}
+ // else: gh-128679: tracemalloc.stop() was called by another thread
+
TABLES_UNLOCK();
return ptr;
}
@@ -557,11 +562,15 @@ tracemalloc_realloc(void *ctx, void *ptr, size_t new_size)
if (ptr2 == NULL)
return NULL;
+ TABLES_LOCK();
+ if (!tracemalloc_config.tracing) {
+ // gh-128679: tracemalloc.stop() was called by another thread
+ goto done;
+ }
+
if (ptr != NULL) {
/* an existing memory block has been resized */
- TABLES_LOCK();
-
/* tracemalloc_add_trace() updates the trace if there is already
a trace at address ptr2 */
if (ptr2 != ptr) {
@@ -580,20 +589,19 @@ tracemalloc_realloc(void *ctx, void *ptr, size_t new_size)
allocating memory. */
Py_FatalError("tracemalloc_realloc() failed to allocate a trace");
}
- TABLES_UNLOCK();
}
else {
/* new allocation */
- TABLES_LOCK();
if (ADD_TRACE(ptr2, new_size) < 0) {
/* Failed to allocate a trace for the new memory block */
- TABLES_UNLOCK();
alloc->free(alloc->ctx, ptr2);
- return NULL;
+ ptr2 = NULL;
}
- TABLES_UNLOCK();
}
+
+done:
+ TABLES_UNLOCK();
return ptr2;
}
@@ -612,7 +620,12 @@ tracemalloc_free(void *ctx, void *ptr)
alloc->free(alloc->ctx, ptr);
TABLES_LOCK();
- REMOVE_TRACE(ptr);
+
+ if (tracemalloc_config.tracing) {
+ REMOVE_TRACE(ptr);
+ }
+ // else: gh-128679: tracemalloc.stop() was called by another thread
+
TABLES_UNLOCK();
}
@@ -671,7 +684,9 @@ tracemalloc_realloc_gil(void *ctx, void *ptr, size_t new_size)
ptr2 = alloc->realloc(alloc->ctx, ptr, new_size);
if (ptr2 != NULL && ptr != NULL) {
TABLES_LOCK();
- REMOVE_TRACE(ptr);
+ if (tracemalloc_config.tracing) {
+ REMOVE_TRACE(ptr);
+ }
TABLES_UNLOCK();
}
return ptr2;
@@ -746,7 +761,9 @@ tracemalloc_raw_realloc(void *ctx, void *ptr, size_t new_size)
if (ptr2 != NULL && ptr != NULL) {
TABLES_LOCK();
- REMOVE_TRACE(ptr);
+ if (tracemalloc_config.tracing) {
+ REMOVE_TRACE(ptr);
+ }
TABLES_UNLOCK();
}
return ptr2;
@@ -777,46 +794,36 @@ tracemalloc_clear_filename(void *value)
/* reentrant flag must be set to call this function and GIL must be held */
static void
-tracemalloc_clear_traces(void)
+tracemalloc_clear_traces_unlocked(void)
{
+ set_reentrant(1);
+
/* The GIL protects variables against concurrent access */
assert(PyGILState_Check());
- TABLES_LOCK();
_Py_hashtable_clear(tracemalloc_traces);
_Py_hashtable_clear(tracemalloc_domains);
tracemalloc_traced_memory = 0;
tracemalloc_peak_traced_memory = 0;
- TABLES_UNLOCK();
_Py_hashtable_clear(tracemalloc_tracebacks);
_Py_hashtable_clear(tracemalloc_filenames);
+
+ set_reentrant(0);
}
-int
+PyStatus
_PyTraceMalloc_Init(void)
{
- if (tracemalloc_config.initialized == TRACEMALLOC_FINALIZED) {
- PyErr_SetString(PyExc_RuntimeError,
- "the tracemalloc module has been unloaded");
- return -1;
- }
-
- if (tracemalloc_config.initialized == TRACEMALLOC_INITIALIZED)
- return 0;
+ assert(tracemalloc_config.initialized == TRACEMALLOC_NOT_INITIALIZED);
PyMem_GetAllocator(PYMEM_DOMAIN_RAW, &allocators.raw);
#ifdef REENTRANT_THREADLOCAL
if (PyThread_tss_create(&tracemalloc_reentrant_key) != 0) {
-#ifdef MS_WINDOWS
- PyErr_SetFromWindowsErr(0);
-#else
- PyErr_SetFromErrno(PyExc_OSError);
-#endif
- return -1;
+ return _PyStatus_NO_MEMORY();
}
#endif
@@ -824,8 +831,7 @@ _PyTraceMalloc_Init(void)
if (tables_lock == NULL) {
tables_lock = PyThread_allocate_lock();
if (tables_lock == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "cannot allocate lock");
- return -1;
+ return _PyStatus_NO_MEMORY();
}
}
#endif
@@ -842,9 +848,9 @@ _PyTraceMalloc_Init(void)
tracemalloc_domains = tracemalloc_create_domains_table();
if (tracemalloc_filenames == NULL || tracemalloc_tracebacks == NULL
- || tracemalloc_traces == NULL || tracemalloc_domains == NULL) {
- PyErr_NoMemory();
- return -1;
+ || tracemalloc_traces == NULL || tracemalloc_domains == NULL)
+ {
+ return _PyStatus_NO_MEMORY();
}
tracemalloc_empty_traceback.nframe = 1;
@@ -855,7 +861,7 @@ _PyTraceMalloc_Init(void)
tracemalloc_empty_traceback.hash = traceback_hash(&tracemalloc_empty_traceback);
tracemalloc_config.initialized = TRACEMALLOC_INITIALIZED;
- return 0;
+ return _PyStatus_OK();
}
@@ -900,10 +906,6 @@ _PyTraceMalloc_Start(int max_nframe)
return -1;
}
- if (_PyTraceMalloc_Init() < 0) {
- return -1;
- }
-
if (tracemalloc_config.tracing) {
/* hook already installed: do nothing */
return 0;
@@ -954,8 +956,13 @@ _PyTraceMalloc_Start(int max_nframe)
void
_PyTraceMalloc_Stop(void)
{
- if (!tracemalloc_config.tracing)
- return;
+ // Lock to synchronize with tracemalloc_free() which checks
+ // 'tracing' while holding the lock.
+ TABLES_LOCK();
+
+ if (!tracemalloc_config.tracing) {
+ goto done;
+ }
/* stop tracing Python memory allocations */
tracemalloc_config.tracing = 0;
@@ -967,11 +974,14 @@ _PyTraceMalloc_Stop(void)
PyMem_SetAllocator(PYMEM_DOMAIN_MEM, &allocators.mem);
PyMem_SetAllocator(PYMEM_DOMAIN_OBJ, &allocators.obj);
- tracemalloc_clear_traces();
+ tracemalloc_clear_traces_unlocked();
/* release memory */
raw_free(tracemalloc_traceback);
tracemalloc_traceback = NULL;
+
+done:
+ TABLES_UNLOCK();
}
@@ -1221,23 +1231,17 @@ tracemalloc_pyobject_decref(void *value)
static traceback_t*
-tracemalloc_get_traceback(unsigned int domain, uintptr_t ptr)
+tracemalloc_get_traceback_unlocked(unsigned int domain, uintptr_t ptr)
{
-
- if (!tracemalloc_config.tracing)
+ if (!tracemalloc_config.tracing) {
return NULL;
+ }
- trace_t *trace;
- TABLES_LOCK();
_Py_hashtable_t *traces = tracemalloc_get_traces_table(domain);
+ trace_t *trace = NULL;
if (traces) {
trace = _Py_hashtable_get(traces, TO_PTR(ptr));
}
- else {
- trace = NULL;
- }
- TABLES_UNLOCK();
-
if (!trace) {
return NULL;
}
@@ -1266,13 +1270,20 @@ _PyMem_DumpTraceback(int fd, const void *ptr)
traceback_t *traceback;
int i;
- if (!tracemalloc_config.tracing) {
+ TABLES_LOCK();
+
+ if (tracemalloc_config.tracing) {
+ traceback = tracemalloc_get_traceback_unlocked(DEFAULT_DOMAIN,
+ (uintptr_t)ptr);
+ }
+ else {
+ traceback = NULL;
PUTS(fd, "Enable tracemalloc to get the memory block "
"allocation traceback\n\n");
- return;
}
- traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (uintptr_t)ptr);
+ TABLES_UNLOCK();
+
if (traceback == NULL)
return;
@@ -1301,20 +1312,19 @@ int
PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr,
size_t size)
{
- int res;
- PyGILState_STATE gil_state;
+ PyGILState_STATE gil_state = PyGILState_Ensure();
+ TABLES_LOCK();
- if (!tracemalloc_config.tracing) {
- /* tracemalloc is not tracing: do nothing */
- return -2;
+ int res;
+ if (tracemalloc_config.tracing) {
+ res = tracemalloc_add_trace(domain, ptr, size);
+ }
+ else {
+ // gh-128679: tracemalloc.stop() was called by another thread
+ res = -2;
}
- gil_state = PyGILState_Ensure();
-
- TABLES_LOCK();
- res = tracemalloc_add_trace(domain, ptr, size);
TABLES_UNLOCK();
-
PyGILState_Release(gil_state);
return res;
}
@@ -1323,16 +1333,20 @@ PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr,
int
PyTraceMalloc_Untrack(unsigned int domain, uintptr_t ptr)
{
- if (!tracemalloc_config.tracing) {
+ TABLES_LOCK();
+
+ int result;
+ if (tracemalloc_config.tracing) {
+ tracemalloc_remove_trace(domain, ptr);
+ result = 0;
+ }
+ else {
/* tracemalloc is not tracing: do nothing */
- return -2;
+ result = -2;
}
- TABLES_LOCK();
- tracemalloc_remove_trace(domain, ptr);
TABLES_UNLOCK();
-
- return 0;
+ return result;
}
@@ -1366,6 +1380,12 @@ _PyTraceMalloc_NewReference(PyObject *op)
int res = -1;
TABLES_LOCK();
+
+ if (!tracemalloc_config.tracing) {
+ // gh-128679: tracemalloc.stop() was called by another thread
+ goto done;
+ }
+
trace_t *trace = _Py_hashtable_get(tracemalloc_traces, TO_PTR(ptr));
if (trace != NULL) {
/* update the traceback of the memory block */
@@ -1376,6 +1396,8 @@ _PyTraceMalloc_NewReference(PyObject *op)
}
}
/* else: cannot track the object, its memory block size is unknown */
+
+done:
TABLES_UNLOCK();
return res;
@@ -1387,7 +1409,9 @@ _PyTraceMalloc_GetTraceback(unsigned int domain, uintptr_t ptr)
{
traceback_t *traceback;
- traceback = tracemalloc_get_traceback(domain, ptr);
+ TABLES_LOCK();
+ traceback = tracemalloc_get_traceback_unlocked(domain, ptr);
+ TABLES_UNLOCK();
if (traceback == NULL)
Py_RETURN_NONE;
@@ -1397,19 +1421,20 @@ _PyTraceMalloc_GetTraceback(unsigned int domain, uintptr_t ptr)
int
_PyTraceMalloc_IsTracing(void)
{
- return tracemalloc_config.tracing;
+ TABLES_LOCK();
+ int tracing = tracemalloc_config.tracing;
+ TABLES_UNLOCK();
+ return tracing;
}
void
_PyTraceMalloc_ClearTraces(void)
{
-
- if (!tracemalloc_config.tracing) {
- return;
+ TABLES_LOCK();
+ if (tracemalloc_config.tracing) {
+ tracemalloc_clear_traces_unlocked();
}
- set_reentrant(1);
- tracemalloc_clear_traces();
- set_reentrant(0);
+ TABLES_UNLOCK();
}
PyObject *
@@ -1496,19 +1521,10 @@ PyObject *
_PyTraceMalloc_GetObjectTraceback(PyObject *obj)
/*[clinic end generated code: output=41ee0553a658b0aa input=29495f1b21c53212]*/
{
- PyTypeObject *type;
- traceback_t *traceback;
-
- type = Py_TYPE(obj);
+ PyTypeObject *type = Py_TYPE(obj);
const size_t presize = _PyType_PreHeaderSize(type);
uintptr_t ptr = (uintptr_t)((char *)obj - presize);
-
- traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, ptr);
- if (traceback == NULL) {
- Py_RETURN_NONE;
- }
-
- return traceback_to_pyobject(traceback, NULL);
+ return _PyTraceMalloc_GetTraceback(DEFAULT_DOMAIN, ptr);
}
int _PyTraceMalloc_GetTracebackLimit(void) {
@@ -1520,14 +1536,19 @@ _PyTraceMalloc_GetMemory(void) {
size_t size;
- size = _Py_hashtable_size(tracemalloc_tracebacks);
- size += _Py_hashtable_size(tracemalloc_filenames);
-
TABLES_LOCK();
- size += _Py_hashtable_size(tracemalloc_traces);
- _Py_hashtable_foreach(tracemalloc_domains,
- tracemalloc_get_tracemalloc_memory_cb, &size);
+ if (tracemalloc_config.tracing) {
+ size = _Py_hashtable_size(tracemalloc_tracebacks);
+ size += _Py_hashtable_size(tracemalloc_filenames);
+ size += _Py_hashtable_size(tracemalloc_traces);
+ _Py_hashtable_foreach(tracemalloc_domains,
+ tracemalloc_get_tracemalloc_memory_cb, &size);
+ }
+ else {
+ size = 0;
+ }
TABLES_UNLOCK();
+
return size;
}
@@ -1537,12 +1558,15 @@ _PyTraceMalloc_GetTracedMemory(void)
{
Py_ssize_t size, peak_size;
- if (!tracemalloc_config.tracing)
- return Py_BuildValue("ii", 0, 0);
-
TABLES_LOCK();
- size = tracemalloc_traced_memory;
- peak_size = tracemalloc_peak_traced_memory;
+ if (tracemalloc_config.tracing) {
+ size = tracemalloc_traced_memory;
+ peak_size = tracemalloc_peak_traced_memory;
+ }
+ else {
+ size = 0;
+ peak_size = 0;
+ }
TABLES_UNLOCK();
return Py_BuildValue("nn", size, peak_size);
@@ -1551,10 +1575,9 @@ _PyTraceMalloc_GetTracedMemory(void)
void
_PyTraceMalloc_ResetPeak(void)
{
- if (!tracemalloc_config.tracing) {
- return;
- }
TABLES_LOCK();
- tracemalloc_peak_traced_memory = tracemalloc_traced_memory;
+ if (tracemalloc_config.tracing) {
+ tracemalloc_peak_traced_memory = tracemalloc_traced_memory;
+ }
TABLES_UNLOCK();
}
1
0
[3.12] gh-128911: Add tests on the PyImport C API (GH-128915) (GH-128960) (#128989)
by vstinner Jan. 19, 2025
by vstinner Jan. 19, 2025
Jan. 19, 2025
https://github.com/python/cpython/commit/83de72e5ec9522a1b01d8259f574efa0d6…
commit: 83de72e5ec9522a1b01d8259f574efa0d6128d6a
branch: 3.12
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-19T14:21:55+01:00
summary:
[3.12] gh-128911: Add tests on the PyImport C API (GH-128915) (GH-128960) (#128989)
* Add Modules/_testlimitedcapi/import.c
* Add Lib/test/test_capi/test_import.py
* Remove _testcapi.check_pyimport_addmodule(): tests already covered
by newly added tests.
(cherry picked from commit 34ded1a1a10204635cad27830fcbee2f8547e8ed)
Co-authored-by: Victor Stinner <vstinner(a)python.org>
Co-authored-by: Serhiy Storchaka <storchaka(a)gmail.com>
(cherry picked from commit d95ba9fa1110534b7247fa2ff12b90e930c93256)
files:
A Lib/test/test_capi/test_import.py
A Modules/_testcapi/import.c
M Modules/Setup.stdlib.in
M Modules/_testcapi/parts.h
M Modules/_testcapimodule.c
M PCbuild/_testcapi.vcxproj
M PCbuild/_testcapi.vcxproj.filters
diff --git a/Lib/test/test_capi/test_import.py b/Lib/test/test_capi/test_import.py
new file mode 100644
index 00000000000000..bcecd6e8cc69ff
--- /dev/null
+++ b/Lib/test/test_capi/test_import.py
@@ -0,0 +1,313 @@
+import importlib.util
+import os.path
+import sys
+import types
+import unittest
+from test.support import os_helper
+from test.support import import_helper
+from test.support.warnings_helper import check_warnings
+
+_testcapi = import_helper.import_module('_testcapi')
+NULL = None
+
+
+class ImportTests(unittest.TestCase):
+ def test_getmagicnumber(self):
+ # Test PyImport_GetMagicNumber()
+ magic = _testcapi.PyImport_GetMagicNumber()
+ self.assertEqual(magic,
+ int.from_bytes(importlib.util.MAGIC_NUMBER, 'little'))
+
+ def test_getmagictag(self):
+ # Test PyImport_GetMagicTag()
+ tag = _testcapi.PyImport_GetMagicTag()
+ self.assertEqual(tag, sys.implementation.cache_tag)
+
+ def test_getmoduledict(self):
+ # Test PyImport_GetModuleDict()
+ modules = _testcapi.PyImport_GetModuleDict()
+ self.assertIs(modules, sys.modules)
+
+ def check_import_loaded_module(self, import_module):
+ for name in ('os', 'sys', 'test', 'unittest'):
+ with self.subTest(name=name):
+ self.assertIn(name, sys.modules)
+ old_module = sys.modules[name]
+ module = import_module(name)
+ self.assertIsInstance(module, types.ModuleType)
+ self.assertIs(module, old_module)
+
+ def check_import_fresh_module(self, import_module):
+ old_modules = dict(sys.modules)
+ try:
+ for name in ('colorsys', 'math'):
+ with self.subTest(name=name):
+ sys.modules.pop(name, None)
+ module = import_module(name)
+ self.assertIsInstance(module, types.ModuleType)
+ self.assertIs(module, sys.modules[name])
+ self.assertEqual(module.__name__, name)
+ finally:
+ sys.modules.clear()
+ sys.modules.update(old_modules)
+
+ def test_getmodule(self):
+ # Test PyImport_GetModule()
+ getmodule = _testcapi.PyImport_GetModule
+ self.check_import_loaded_module(getmodule)
+
+ nonexistent = 'nonexistent'
+ self.assertNotIn(nonexistent, sys.modules)
+ self.assertIs(getmodule(nonexistent), KeyError)
+ self.assertIs(getmodule(''), KeyError)
+ self.assertIs(getmodule(object()), KeyError)
+
+ self.assertRaises(TypeError, getmodule, []) # unhashable
+ # CRASHES getmodule(NULL)
+
+ def check_addmodule(self, add_module, accept_nonstr=False):
+ # create a new module
+ names = ['nonexistent']
+ if accept_nonstr:
+ names.append(b'\xff') # non-UTF-8
+ for name in names:
+ with self.subTest(name=name):
+ self.assertNotIn(name, sys.modules)
+ try:
+ module = add_module(name)
+ self.assertIsInstance(module, types.ModuleType)
+ self.assertEqual(module.__name__, name)
+ self.assertIs(module, sys.modules[name])
+ finally:
+ sys.modules.pop(name, None)
+
+ # get an existing module
+ self.check_import_loaded_module(add_module)
+
+ def test_addmoduleobject(self):
+ # Test PyImport_AddModuleObject()
+ addmoduleobject = _testcapi.PyImport_AddModuleObject
+ self.check_addmodule(addmoduleobject, accept_nonstr=True)
+
+ self.assertRaises(TypeError, addmoduleobject, []) # unhashable
+ # CRASHES addmoduleobject(NULL)
+
+ def test_addmodule(self):
+ # Test PyImport_AddModule()
+ addmodule = _testcapi.PyImport_AddModule
+ self.check_addmodule(addmodule)
+
+ self.assertRaises(UnicodeDecodeError, addmodule, b'\xff')
+ # CRASHES addmodule(NULL)
+
+ def check_import_func(self, import_module):
+ self.check_import_loaded_module(import_module)
+ self.check_import_fresh_module(import_module)
+ self.assertRaises(ModuleNotFoundError, import_module, 'nonexistent')
+ self.assertRaises(ValueError, import_module, '')
+
+ def test_import(self):
+ # Test PyImport_Import()
+ import_ = _testcapi.PyImport_Import
+ self.check_import_func(import_)
+
+ self.assertRaises(TypeError, import_, b'os')
+ self.assertRaises(SystemError, import_, NULL)
+
+ def test_importmodule(self):
+ # Test PyImport_ImportModule()
+ importmodule = _testcapi.PyImport_ImportModule
+ self.check_import_func(importmodule)
+
+ self.assertRaises(UnicodeDecodeError, importmodule, b'\xff')
+ # CRASHES importmodule(NULL)
+
+ def test_importmodulenoblock(self):
+ # Test deprecated PyImport_ImportModuleNoBlock()
+ importmodulenoblock = _testcapi.PyImport_ImportModuleNoBlock
+ self.check_import_func(importmodulenoblock)
+
+ self.assertRaises(UnicodeDecodeError, importmodulenoblock, b'\xff')
+ # CRASHES importmodulenoblock(NULL)
+
+ def check_frozen_import(self, import_frozen_module):
+ # Importing a frozen module executes its code, so start by unloading
+ # the module to execute the code in a new (temporary) module.
+ old_zipimport = sys.modules.pop('zipimport')
+ try:
+ self.assertEqual(import_frozen_module('zipimport'), 1)
+
+ # import zipimport again
+ self.assertEqual(import_frozen_module('zipimport'), 1)
+ finally:
+ sys.modules['zipimport'] = old_zipimport
+
+ # not a frozen module
+ self.assertEqual(import_frozen_module('sys'), 0)
+ self.assertEqual(import_frozen_module('nonexistent'), 0)
+ self.assertEqual(import_frozen_module(''), 0)
+
+ def test_importfrozenmodule(self):
+ # Test PyImport_ImportFrozenModule()
+ importfrozenmodule = _testcapi.PyImport_ImportFrozenModule
+ self.check_frozen_import(importfrozenmodule)
+
+ self.assertRaises(UnicodeDecodeError, importfrozenmodule, b'\xff')
+ # CRASHES importfrozenmodule(NULL)
+
+ def test_importfrozenmoduleobject(self):
+ # Test PyImport_ImportFrozenModuleObject()
+ importfrozenmoduleobject = _testcapi.PyImport_ImportFrozenModuleObject
+ self.check_frozen_import(importfrozenmoduleobject)
+ self.assertEqual(importfrozenmoduleobject(b'zipimport'), 0)
+ self.assertEqual(importfrozenmoduleobject(NULL), 0)
+
+ def test_importmoduleex(self):
+ # Test PyImport_ImportModuleEx()
+ importmoduleex = _testcapi.PyImport_ImportModuleEx
+ self.check_import_func(lambda name: importmoduleex(name, NULL, NULL, NULL))
+
+ self.assertRaises(ModuleNotFoundError, importmoduleex, 'nonexistent', NULL, NULL, NULL)
+ self.assertRaises(ValueError, importmoduleex, '', NULL, NULL, NULL)
+ self.assertRaises(UnicodeDecodeError, importmoduleex, b'\xff', NULL, NULL, NULL)
+ # CRASHES importmoduleex(NULL, NULL, NULL, NULL)
+
+ def check_importmodulelevel(self, importmodulelevel):
+ self.check_import_func(lambda name: importmodulelevel(name, NULL, NULL, NULL, 0))
+
+ self.assertRaises(ModuleNotFoundError, importmodulelevel, 'nonexistent', NULL, NULL, NULL, 0)
+ self.assertRaises(ValueError, importmodulelevel, '', NULL, NULL, NULL, 0)
+
+ if __package__:
+ self.assertIs(importmodulelevel('test_import', globals(), NULL, NULL, 1),
+ sys.modules['test.test_capi.test_import'])
+ self.assertIs(importmodulelevel('test_capi', globals(), NULL, NULL, 2),
+ sys.modules['test.test_capi'])
+ self.assertRaises(ValueError, importmodulelevel, 'os', NULL, NULL, NULL, -1)
+ with self.assertWarns(ImportWarning):
+ self.assertRaises(KeyError, importmodulelevel, 'test_import', {}, NULL, NULL, 1)
+ self.assertRaises(TypeError, importmodulelevel, 'test_import', [], NULL, NULL, 1)
+
+ def test_importmodulelevel(self):
+ # Test PyImport_ImportModuleLevel()
+ importmodulelevel = _testcapi.PyImport_ImportModuleLevel
+ self.check_importmodulelevel(importmodulelevel)
+
+ self.assertRaises(UnicodeDecodeError, importmodulelevel, b'\xff', NULL, NULL, NULL, 0)
+ # CRASHES importmodulelevel(NULL, NULL, NULL, NULL, 0)
+
+ def test_importmodulelevelobject(self):
+ # Test PyImport_ImportModuleLevelObject()
+ importmodulelevel = _testcapi.PyImport_ImportModuleLevelObject
+ self.check_importmodulelevel(importmodulelevel)
+
+ self.assertRaises(TypeError, importmodulelevel, b'os', NULL, NULL, NULL, 0)
+ self.assertRaises(ValueError, importmodulelevel, NULL, NULL, NULL, NULL, 0)
+
+ def check_executecodemodule(self, execute_code, *args):
+ name = 'test_import_executecode'
+ try:
+ # Create a temporary module where the code will be executed
+ self.assertNotIn(name, sys.modules)
+ module = _testcapi.PyImport_AddModule(name)
+ self.assertFalse(hasattr(module, 'attr'))
+
+ # Execute the code
+ code = compile('attr = 1', '<test>', 'exec')
+ module2 = execute_code(name, code, *args)
+ self.assertIs(module2, module)
+
+ # Check the function side effects
+ self.assertEqual(module.attr, 1)
+ finally:
+ sys.modules.pop(name, None)
+ return module.__spec__.origin
+
+ def test_executecodemodule(self):
+ # Test PyImport_ExecCodeModule()
+ execcodemodule = _testcapi.PyImport_ExecCodeModule
+ self.check_executecodemodule(execcodemodule)
+
+ code = compile('attr = 1', '<test>', 'exec')
+ self.assertRaises(UnicodeDecodeError, execcodemodule, b'\xff', code)
+ # CRASHES execcodemodule(NULL, code)
+ # CRASHES execcodemodule(name, NULL)
+
+ def test_executecodemoduleex(self):
+ # Test PyImport_ExecCodeModuleEx()
+ execcodemoduleex = _testcapi.PyImport_ExecCodeModuleEx
+
+ # Test NULL path (it should not crash)
+ self.check_executecodemodule(execcodemoduleex, NULL)
+
+ # Test non-NULL path
+ pathname = b'pathname'
+ origin = self.check_executecodemodule(execcodemoduleex, pathname)
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+
+ pathname = os_helper.TESTFN_UNDECODABLE
+ if pathname:
+ origin = self.check_executecodemodule(execcodemoduleex, pathname)
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+
+ code = compile('attr = 1', '<test>', 'exec')
+ self.assertRaises(UnicodeDecodeError, execcodemoduleex, b'\xff', code, NULL)
+ # CRASHES execcodemoduleex(NULL, code, NULL)
+ # CRASHES execcodemoduleex(name, NULL, NULL)
+
+ def check_executecode_pathnames(self, execute_code_func, object=False):
+ # Test non-NULL pathname and NULL cpathname
+
+ # Test NULL paths (it should not crash)
+ self.check_executecodemodule(execute_code_func, NULL, NULL)
+
+ pathname = 'pathname'
+ origin = self.check_executecodemodule(execute_code_func, pathname, NULL)
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+ origin = self.check_executecodemodule(execute_code_func, NULL, pathname)
+ if not object:
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+
+ pathname = os_helper.TESTFN_UNDECODABLE
+ if pathname:
+ if object:
+ pathname = os.fsdecode(pathname)
+ origin = self.check_executecodemodule(execute_code_func, pathname, NULL)
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+ self.check_executecodemodule(execute_code_func, NULL, pathname)
+
+ # Test NULL pathname and non-NULL cpathname
+ pyc_filename = importlib.util.cache_from_source(__file__)
+ py_filename = importlib.util.source_from_cache(pyc_filename)
+ origin = self.check_executecodemodule(execute_code_func, NULL, pyc_filename)
+ if not object:
+ self.assertEqual(origin, py_filename)
+
+ def test_executecodemodulewithpathnames(self):
+ # Test PyImport_ExecCodeModuleWithPathnames()
+ execute_code_func = _testcapi.PyImport_ExecCodeModuleWithPathnames
+ self.check_executecode_pathnames(execute_code_func)
+
+ code = compile('attr = 1', '<test>', 'exec')
+ self.assertRaises(UnicodeDecodeError, execute_code_func, b'\xff', code, NULL, NULL)
+ # CRASHES execute_code_func(NULL, code, NULL, NULL)
+ # CRASHES execute_code_func(name, NULL, NULL, NULL)
+
+ def test_executecodemoduleobject(self):
+ # Test PyImport_ExecCodeModuleObject()
+ execute_code_func = _testcapi.PyImport_ExecCodeModuleObject
+ self.check_executecode_pathnames(execute_code_func, object=True)
+
+ code = compile('attr = 1', '<test>', 'exec')
+ self.assertRaises(TypeError, execute_code_func, [], code, NULL, NULL)
+ # CRASHES execute_code_func(NULL, code, NULL, NULL)
+ # CRASHES execute_code_func(name, NULL, NULL, NULL)
+
+ # TODO: test PyImport_GetImporter()
+ # TODO: test PyImport_ReloadModule()
+ # TODO: test PyImport_ExtendInittab()
+ # PyImport_AppendInittab() is tested by test_embed
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in
index b68b8e4e347bbd..d60afcf55dba4a 100644
--- a/Modules/Setup.stdlib.in
+++ b/Modules/Setup.stdlib.in
@@ -168,7 +168,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/bytearray.c _testcapi/bytes.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/pytime.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyos.c _testcapi/run.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/heaptype_relative.c _testcapi/gc.c _testcapi/sys.c
+@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/vectorcall_limited.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/bytearray.c _testcapi/bytes.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/pytime.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyos.c _testcapi/run.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/heaptype_relative.c _testcapi/gc.c _testcapi/sys.c _testcapi/import.c
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
# Some testing modules MUST be built as shared libraries.
diff --git a/Modules/_testcapi/import.c b/Modules/_testcapi/import.c
new file mode 100644
index 00000000000000..c6b5caa65f31e1
--- /dev/null
+++ b/Modules/_testcapi/import.c
@@ -0,0 +1,287 @@
+#define PY_SSIZE_T_CLEAN
+
+#include "parts.h"
+#include "util.h"
+
+
+/* Test PyImport_GetMagicNumber() */
+static PyObject *
+pyimport_getmagicnumber(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
+{
+ long magic = PyImport_GetMagicNumber();
+ return PyLong_FromLong(magic);
+}
+
+
+/* Test PyImport_GetMagicTag() */
+static PyObject *
+pyimport_getmagictag(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
+{
+ const char *tag = PyImport_GetMagicTag();
+ return PyUnicode_FromString(tag);
+}
+
+
+/* Test PyImport_GetModuleDict() */
+static PyObject *
+pyimport_getmoduledict(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
+{
+ return Py_XNewRef(PyImport_GetModuleDict());
+}
+
+
+/* Test PyImport_GetModule() */
+static PyObject *
+pyimport_getmodule(PyObject *Py_UNUSED(module), PyObject *name)
+{
+ assert(!PyErr_Occurred());
+ NULLABLE(name);
+ PyObject *module = PyImport_GetModule(name);
+ if (module == NULL && !PyErr_Occurred()) {
+ return Py_NewRef(PyExc_KeyError);
+ }
+ return module;
+}
+
+
+/* Test PyImport_AddModuleObject() */
+static PyObject *
+pyimport_addmoduleobject(PyObject *Py_UNUSED(module), PyObject *name)
+{
+ NULLABLE(name);
+ return Py_XNewRef(PyImport_AddModuleObject(name));
+}
+
+
+/* Test PyImport_AddModule() */
+static PyObject *
+pyimport_addmodule(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ return Py_XNewRef(PyImport_AddModule(name));
+}
+
+
+/* Test PyImport_Import() */
+static PyObject *
+pyimport_import(PyObject *Py_UNUSED(module), PyObject *name)
+{
+ NULLABLE(name);
+ return PyImport_Import(name);
+}
+
+
+/* Test PyImport_ImportModule() */
+static PyObject *
+pyimport_importmodule(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ return PyImport_ImportModule(name);
+}
+
+
+/* Test PyImport_ImportModuleNoBlock() */
+static PyObject *
+pyimport_importmodulenoblock(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ _Py_COMP_DIAG_PUSH
+ _Py_COMP_DIAG_IGNORE_DEPR_DECLS
+ return PyImport_ImportModuleNoBlock(name);
+ _Py_COMP_DIAG_POP
+}
+
+
+/* Test PyImport_ImportModuleEx() */
+static PyObject *
+pyimport_importmoduleex(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *globals, *locals, *fromlist;
+ if (!PyArg_ParseTuple(args, "z#OOO",
+ &name, &size, &globals, &locals, &fromlist)) {
+ return NULL;
+ }
+ NULLABLE(globals);
+ NULLABLE(locals);
+ NULLABLE(fromlist);
+
+ return PyImport_ImportModuleEx(name, globals, locals, fromlist);
+}
+
+
+/* Test PyImport_ImportModuleLevel() */
+static PyObject *
+pyimport_importmodulelevel(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *globals, *locals, *fromlist;
+ int level;
+ if (!PyArg_ParseTuple(args, "z#OOOi",
+ &name, &size, &globals, &locals, &fromlist, &level)) {
+ return NULL;
+ }
+ NULLABLE(globals);
+ NULLABLE(locals);
+ NULLABLE(fromlist);
+
+ return PyImport_ImportModuleLevel(name, globals, locals, fromlist, level);
+}
+
+
+/* Test PyImport_ImportModuleLevelObject() */
+static PyObject *
+pyimport_importmodulelevelobject(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ PyObject *name, *globals, *locals, *fromlist;
+ int level;
+ if (!PyArg_ParseTuple(args, "OOOOi",
+ &name, &globals, &locals, &fromlist, &level)) {
+ return NULL;
+ }
+ NULLABLE(name);
+ NULLABLE(globals);
+ NULLABLE(locals);
+ NULLABLE(fromlist);
+
+ return PyImport_ImportModuleLevelObject(name, globals, locals, fromlist, level);
+}
+
+
+/* Test PyImport_ImportFrozenModule() */
+static PyObject *
+pyimport_importfrozenmodule(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ RETURN_INT(PyImport_ImportFrozenModule(name));
+}
+
+
+/* Test PyImport_ImportFrozenModuleObject() */
+static PyObject *
+pyimport_importfrozenmoduleobject(PyObject *Py_UNUSED(module), PyObject *name)
+{
+ NULLABLE(name);
+ RETURN_INT(PyImport_ImportFrozenModuleObject(name));
+}
+
+
+/* Test PyImport_ExecCodeModule() */
+static PyObject *
+pyimport_executecodemodule(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *code;
+ if (!PyArg_ParseTuple(args, "z#O", &name, &size, &code)) {
+ return NULL;
+ }
+ NULLABLE(code);
+
+ return PyImport_ExecCodeModule(name, code);
+}
+
+
+/* Test PyImport_ExecCodeModuleEx() */
+static PyObject *
+pyimport_executecodemoduleex(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *code;
+ const char *pathname;
+ if (!PyArg_ParseTuple(args, "z#Oz#", &name, &size, &code, &pathname, &size)) {
+ return NULL;
+ }
+ NULLABLE(code);
+
+ return PyImport_ExecCodeModuleEx(name, code, pathname);
+}
+
+
+/* Test PyImport_ExecCodeModuleWithPathnames() */
+static PyObject *
+pyimport_executecodemodulewithpathnames(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *code;
+ const char *pathname;
+ const char *cpathname;
+ if (!PyArg_ParseTuple(args, "z#Oz#z#", &name, &size, &code, &pathname, &size, &cpathname, &size)) {
+ return NULL;
+ }
+ NULLABLE(code);
+
+ return PyImport_ExecCodeModuleWithPathnames(name, code,
+ pathname, cpathname);
+}
+
+
+/* Test PyImport_ExecCodeModuleObject() */
+static PyObject *
+pyimport_executecodemoduleobject(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ PyObject *name, *code, *pathname, *cpathname;
+ if (!PyArg_ParseTuple(args, "OOOO", &name, &code, &pathname, &cpathname)) {
+ return NULL;
+ }
+ NULLABLE(name);
+ NULLABLE(code);
+ NULLABLE(pathname);
+ NULLABLE(cpathname);
+
+ return PyImport_ExecCodeModuleObject(name, code, pathname, cpathname);
+}
+
+
+static PyMethodDef test_methods[] = {
+ {"PyImport_GetMagicNumber", pyimport_getmagicnumber, METH_NOARGS},
+ {"PyImport_GetMagicTag", pyimport_getmagictag, METH_NOARGS},
+ {"PyImport_GetModuleDict", pyimport_getmoduledict, METH_NOARGS},
+ {"PyImport_GetModule", pyimport_getmodule, METH_O},
+ {"PyImport_AddModuleObject", pyimport_addmoduleobject, METH_O},
+ {"PyImport_AddModule", pyimport_addmodule, METH_VARARGS},
+ {"PyImport_Import", pyimport_import, METH_O},
+ {"PyImport_ImportModule", pyimport_importmodule, METH_VARARGS},
+ {"PyImport_ImportModuleNoBlock", pyimport_importmodulenoblock, METH_VARARGS},
+ {"PyImport_ImportModuleEx", pyimport_importmoduleex, METH_VARARGS},
+ {"PyImport_ImportModuleLevel", pyimport_importmodulelevel, METH_VARARGS},
+ {"PyImport_ImportModuleLevelObject", pyimport_importmodulelevelobject, METH_VARARGS},
+ {"PyImport_ImportFrozenModule", pyimport_importfrozenmodule, METH_VARARGS},
+ {"PyImport_ImportFrozenModuleObject", pyimport_importfrozenmoduleobject, METH_O},
+ {"PyImport_ExecCodeModule", pyimport_executecodemodule, METH_VARARGS},
+ {"PyImport_ExecCodeModuleEx", pyimport_executecodemoduleex, METH_VARARGS},
+ {"PyImport_ExecCodeModuleWithPathnames", pyimport_executecodemodulewithpathnames, METH_VARARGS},
+ {"PyImport_ExecCodeModuleObject", pyimport_executecodemoduleobject, METH_VARARGS},
+ {NULL},
+};
+
+
+int
+_PyTestCapi_Init_Import(PyObject *module)
+{
+ return PyModule_AddFunctions(module, test_methods);
+}
diff --git a/Modules/_testcapi/parts.h b/Modules/_testcapi/parts.h
index 496dd38fbad0bc..bc348dc122c525 100644
--- a/Modules/_testcapi/parts.h
+++ b/Modules/_testcapi/parts.h
@@ -55,6 +55,7 @@ int _PyTestCapi_Init_Codec(PyObject *module);
int _PyTestCapi_Init_Immortal(PyObject *module);
int _PyTestCapi_Init_GC(PyObject *module);
int _PyTestCapi_Init_Sys(PyObject *module);
+int _PyTestCapi_Init_Import(PyObject *module);
#ifdef LIMITED_API_AVAILABLE
int _PyTestCapi_Init_VectorcallLimited(PyObject *module);
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index aece635554daa0..244bfab8d986f2 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -4071,6 +4071,9 @@ PyInit__testcapi(void)
if (_PyTestCapi_Init_GC(m) < 0) {
return NULL;
}
+ if (_PyTestCapi_Init_Import(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 257562c75d103b..ec24c62903af90 100644
--- a/PCbuild/_testcapi.vcxproj
+++ b/PCbuild/_testcapi.vcxproj
@@ -105,6 +105,7 @@
<ClCompile Include="..\Modules\_testcapi\unicode.c" />
<ClCompile Include="..\Modules\_testcapi\dict.c" />
<ClCompile Include="..\Modules\_testcapi\set.c" />
+ <ClCompile Include="..\Modules\_testcapi\import.c" />
<ClCompile Include="..\Modules\_testcapi\list.c" />
<ClCompile Include="..\Modules\_testcapi\tuple.c" />
<ClCompile Include="..\Modules\_testcapi\pytime.c" />
diff --git a/PCbuild/_testcapi.vcxproj.filters b/PCbuild/_testcapi.vcxproj.filters
index 4d1e4330d43989..99eefb7b565393 100644
--- a/PCbuild/_testcapi.vcxproj.filters
+++ b/PCbuild/_testcapi.vcxproj.filters
@@ -108,6 +108,9 @@
<ClCompile Include="..\Modules\_testcapi\run.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\Modules\_testcapi\import.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\PC\python_nt.rc">
1
0
gh-100239: Handle NaN and zero division in guards for `BINARY_OP_EXTEND` (#128963)
by Eclips4 Jan. 19, 2025
by Eclips4 Jan. 19, 2025
Jan. 19, 2025
https://github.com/python/cpython/commit/6c52ada5512ccd1a0891c00cc84c7d3170…
commit: 6c52ada5512ccd1a0891c00cc84c7d3170d3328c
branch: main
author: Kirill Podoprigora <kirill.bast9(a)mail.ru>
committer: Eclips4 <kirill.bast9(a)mail.ru>
date: 2025-01-19T11:02:49Z
summary:
gh-100239: Handle NaN and zero division in guards for `BINARY_OP_EXTEND` (#128963)
Co-authored-by: Tomas R. <tomas.roun8(a)gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel(a)users.noreply.github.com>
files:
M Lib/test/test_opcache.py
M Python/specialize.c
diff --git a/Lib/test/test_opcache.py b/Lib/test/test_opcache.py
index 72b845fcc8fdbf..4d7304b1c9abb6 100644
--- a/Lib/test/test_opcache.py
+++ b/Lib/test/test_opcache.py
@@ -1362,6 +1362,53 @@ def binary_op_add_extend():
self.assert_specialized(binary_op_add_extend, "BINARY_OP_EXTEND")
self.assert_no_opcode(binary_op_add_extend, "BINARY_OP")
+ def binary_op_zero_division():
+ def compactlong_lhs(arg):
+ 42 / arg
+ def float_lhs(arg):
+ 42.0 / arg
+
+ with self.assertRaises(ZeroDivisionError):
+ compactlong_lhs(0)
+ with self.assertRaises(ZeroDivisionError):
+ compactlong_lhs(0.0)
+ with self.assertRaises(ZeroDivisionError):
+ float_lhs(0.0)
+ with self.assertRaises(ZeroDivisionError):
+ float_lhs(0)
+
+ self.assert_no_opcode(compactlong_lhs, "BINARY_OP_EXTEND")
+ self.assert_no_opcode(float_lhs, "BINARY_OP_EXTEND")
+
+ binary_op_zero_division()
+
+ def binary_op_nan():
+ def compactlong_lhs(arg):
+ return (
+ 42 + arg,
+ 42 - arg,
+ 42 * arg,
+ 42 / arg,
+ )
+ def compactlong_rhs(arg):
+ return (
+ arg + 42,
+ arg - 42,
+ arg * 2,
+ arg / 42,
+ )
+ nan = float('nan')
+ self.assertEqual(compactlong_lhs(1.0), (43.0, 41.0, 42.0, 42.0))
+ for _ in range(100):
+ self.assertTrue(all(filter(lambda x: x is nan, compactlong_lhs(nan))))
+ self.assertEqual(compactlong_rhs(42.0), (84.0, 0.0, 84.0, 1.0))
+ for _ in range(100):
+ self.assertTrue(all(filter(lambda x: x is nan, compactlong_rhs(nan))))
+
+ self.assert_no_opcode(compactlong_lhs, "BINARY_OP_EXTEND")
+ self.assert_no_opcode(compactlong_rhs, "BINARY_OP_EXTEND")
+
+ binary_op_nan()
@cpython_only
@requires_specialization_ft
diff --git a/Python/specialize.c b/Python/specialize.c
index 09bfcd34b5a543..fa022346bdea6a 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -2416,16 +2416,25 @@ binary_op_fail_kind(int oparg, PyObject *lhs, PyObject *rhs)
/* float-long */
-static int
+static inline int
float_compactlong_guard(PyObject *lhs, PyObject *rhs)
{
return (
PyFloat_CheckExact(lhs) &&
+ !isnan(PyFloat_AsDouble(lhs)) &&
PyLong_CheckExact(rhs) &&
_PyLong_IsCompact((PyLongObject *)rhs)
);
}
+static inline int
+nonzero_float_compactlong_guard(PyObject *lhs, PyObject *rhs)
+{
+ return (
+ float_compactlong_guard(lhs, rhs) && !PyLong_IsZero(rhs)
+ );
+}
+
#define FLOAT_LONG_ACTION(NAME, OP) \
static PyObject * \
(NAME)(PyObject *lhs, PyObject *rhs) \
@@ -2442,13 +2451,22 @@ FLOAT_LONG_ACTION(float_compactlong_true_div, /)
/* long-float */
-static int
+static inline int
compactlong_float_guard(PyObject *lhs, PyObject *rhs)
{
return (
- PyFloat_CheckExact(rhs) &&
PyLong_CheckExact(lhs) &&
- _PyLong_IsCompact((PyLongObject *)lhs)
+ _PyLong_IsCompact((PyLongObject *)lhs) &&
+ PyFloat_CheckExact(rhs) &&
+ !isnan(PyFloat_AsDouble(rhs))
+ );
+}
+
+static inline int
+nonzero_compactlong_float_guard(PyObject *lhs, PyObject *rhs)
+{
+ return (
+ compactlong_float_guard(lhs, rhs) && PyFloat_AsDouble(rhs) != 0.0
);
}
@@ -2469,14 +2487,14 @@ LONG_FLOAT_ACTION(compactlong_float_true_div, /)
static _PyBinaryOpSpecializationDescr float_compactlong_specs[NB_OPARG_LAST+1] = {
[NB_ADD] = {float_compactlong_guard, float_compactlong_add},
[NB_SUBTRACT] = {float_compactlong_guard, float_compactlong_subtract},
- [NB_TRUE_DIVIDE] = {float_compactlong_guard, float_compactlong_true_div},
+ [NB_TRUE_DIVIDE] = {nonzero_float_compactlong_guard, float_compactlong_true_div},
[NB_MULTIPLY] = {float_compactlong_guard, float_compactlong_multiply},
};
static _PyBinaryOpSpecializationDescr compactlong_float_specs[NB_OPARG_LAST+1] = {
[NB_ADD] = {compactlong_float_guard, compactlong_float_add},
[NB_SUBTRACT] = {compactlong_float_guard, compactlong_float_subtract},
- [NB_TRUE_DIVIDE] = {compactlong_float_guard, compactlong_float_true_div},
+ [NB_TRUE_DIVIDE] = {nonzero_compactlong_float_guard, compactlong_float_true_div},
[NB_MULTIPLY] = {compactlong_float_guard, compactlong_float_multiply},
};
1
0
gh-80222: Fix email address header folding with long quoted-string (#122753)
by bitdancer Jan. 19, 2025
by bitdancer Jan. 19, 2025
Jan. 19, 2025
https://github.com/python/cpython/commit/5aaf41685834901e4ed0a40f4c055b9299…
commit: 5aaf41685834901e4ed0a40f4c055b92991a0bb5
branch: main
author: Mike Edmunds <medmunds(a)gmail.com>
committer: bitdancer <rdmurray(a)bitdance.com>
date: 2025-01-18T19:50:52-05:00
summary:
gh-80222: Fix email address header folding with long quoted-string (#122753)
Email generators using email.policy.default could incorrectly omit the
quote ('"') characters from a quoted-string during header refolding,
leading to invalid address headers and enabling header spoofing. This
change restores the quote characters on a bare-quoted-string as the
header is refolded, and escapes backslash and quote chars in the string.
files:
A Misc/NEWS.d/next/Security/2024-08-06-11-43-08.gh-issue-80222.wfR4BU.rst
M Lib/email/_header_value_parser.py
M Lib/test/test_email/test__header_value_parser.py
diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py
index ec2215a5e5f33c..3d845c09d415f6 100644
--- a/Lib/email/_header_value_parser.py
+++ b/Lib/email/_header_value_parser.py
@@ -95,8 +95,16 @@
NLSET = {'\n', '\r'}
SPECIALSNL = SPECIALS | NLSET
+
+def make_quoted_pairs(value):
+ """Escape dquote and backslash for use within a quoted-string."""
+ return str(value).replace('\\', '\\\\').replace('"', '\\"')
+
+
def quote_string(value):
- return '"'+str(value).replace('\\', '\\\\').replace('"', r'\"')+'"'
+ escaped = make_quoted_pairs(value)
+ return f'"{escaped}"'
+
# Match a RFC 2047 word, looks like =?utf-8?q?someword?=
rfc2047_matcher = re.compile(r'''
@@ -2905,6 +2913,15 @@ def _refold_parse_tree(parse_tree, *, policy):
if not hasattr(part, 'encode'):
# It's not a terminal, try folding the subparts.
newparts = list(part)
+ if part.token_type == 'bare-quoted-string':
+ # To fold a quoted string we need to create a list of terminal
+ # tokens that will render the leading and trailing quotes
+ # and use quoted pairs in the value as appropriate.
+ newparts = (
+ [ValueTerminal('"', 'ptext')] +
+ [ValueTerminal(make_quoted_pairs(p), 'ptext')
+ for p in newparts] +
+ [ValueTerminal('"', 'ptext')])
if not part.as_ew_allowed:
wrap_as_ew_blocked += 1
newparts.append(end_ew_not_allowed)
diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py
index 95224e19f67ce5..d60a7039f9d4c6 100644
--- a/Lib/test/test_email/test__header_value_parser.py
+++ b/Lib/test/test_email/test__header_value_parser.py
@@ -3082,13 +3082,40 @@ def test_address_list_with_list_separator_after_fold(self):
self._test(parser.get_address_list(to)[0],
f'{a},\n =?utf-8?q?H=C3=BCbsch?= Kaktus <beautiful(a)example.com>\n')
- a = '.' * 79
+ a = '.' * 79 # ('.' is a special, so must be in quoted-string.)
to = f'"{a}" <xyz(a)example.com>, "Hübsch Kaktus" <beautiful(a)example.com>'
self._test(parser.get_address_list(to)[0],
- f'{a}\n'
+ f'"{a}"\n'
' <xyz(a)example.com>, =?utf-8?q?H=C3=BCbsch?= Kaktus '
'<beautiful(a)example.com>\n')
+ def test_address_list_with_specials_in_long_quoted_string(self):
+ # Regression for gh-80222.
+ policy = self.policy.clone(max_line_length=40)
+ cases = [
+ # (to, folded)
+ ('"Exfiltrator <spy(a)example.org> (unclosed comment?" <to(a)example.com>',
+ '"Exfiltrator <spy(a)example.org> (unclosed\n'
+ ' comment?" <to(a)example.com>\n'),
+ ('"Escaped \\" chars \\\\ in quoted-string stay escaped" <to(a)example.com>',
+ '"Escaped \\" chars \\\\ in quoted-string\n'
+ ' stay escaped" <to(a)example.com>\n'),
+ ('This long display name does not need quotes <to(a)example.com>',
+ 'This long display name does not need\n'
+ ' quotes <to(a)example.com>\n'),
+ ('"Quotes are not required but are retained here" <to(a)example.com>',
+ '"Quotes are not required but are\n'
+ ' retained here" <to(a)example.com>\n'),
+ ('"A quoted-string, it can be a valid local-part"@example.com',
+ '"A quoted-string, it can be a valid\n'
+ ' local-part"@example.com\n'),
+ ('"local-part-with-specials(a)but-no-fws.cannot-fold"@example.com',
+ '"local-part-with-specials(a)but-no-fws.cannot-fold"@example.com\n'),
+ ]
+ for (to, folded) in cases:
+ with self.subTest(to=to):
+ self._test(parser.get_address_list(to)[0], folded, policy=policy)
+
# XXX Need tests with comments on various sides of a unicode token,
# and with unicode tokens in the comments. Spaces inside the quotes
# currently don't do the right thing.
diff --git a/Misc/NEWS.d/next/Security/2024-08-06-11-43-08.gh-issue-80222.wfR4BU.rst b/Misc/NEWS.d/next/Security/2024-08-06-11-43-08.gh-issue-80222.wfR4BU.rst
new file mode 100644
index 00000000000000..0f0661d0b1cf4a
--- /dev/null
+++ b/Misc/NEWS.d/next/Security/2024-08-06-11-43-08.gh-issue-80222.wfR4BU.rst
@@ -0,0 +1,6 @@
+Fix bug in the folding of quoted strings when flattening an email message using
+a modern email policy. Previously when a quoted string was folded so that
+it spanned more than one line, the surrounding quotes and internal escapes
+would be omitted. This could theoretically be used to spoof header lines
+using a carefully constructed quoted string if the resulting rendered email
+was transmitted or re-parsed.
1
0
Jan. 18, 2025
https://github.com/python/cpython/commit/6b47499510e47c0401d1f6cca2660fc12c…
commit: 6b47499510e47c0401d1f6cca2660fc12c496e39
branch: 3.13
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-18T23:39:07Z
summary:
[3.13] gh-128679: Fix tracemalloc.stop() race conditions (#128897)
tracemalloc_alloc(), tracemalloc_realloc(), PyTraceMalloc_Track(),
PyTraceMalloc_Untrack() and _PyTraceMalloc_TraceRef() now check
tracemalloc_config.tracing after calling TABLES_LOCK().
_PyTraceMalloc_Stop() now protects more code with TABLES_LOCK(),
especially setting tracemalloc_config.tracing to 1.
Add a test using PyTraceMalloc_Track() to test tracemalloc.stop()
race condition.
Call _PyTraceMalloc_Init() at Python startup.
files:
A Misc/NEWS.d/next/Library/2025-01-10-15-43-52.gh-issue-128679.KcfVVR.rst
M Include/internal/pycore_tracemalloc.h
M Lib/test/test_tracemalloc.py
M Modules/_testcapimodule.c
M Modules/_tracemalloc.c
M Python/pylifecycle.c
M Python/tracemalloc.c
diff --git a/Include/internal/pycore_tracemalloc.h b/Include/internal/pycore_tracemalloc.h
index 7ddc5bac5d10af..f70d47074f813c 100644
--- a/Include/internal/pycore_tracemalloc.h
+++ b/Include/internal/pycore_tracemalloc.h
@@ -144,7 +144,7 @@ extern PyObject* _PyTraceMalloc_GetTraces(void);
extern PyObject* _PyTraceMalloc_GetObjectTraceback(PyObject *obj);
/* Initialize tracemalloc */
-extern int _PyTraceMalloc_Init(void);
+extern PyStatus _PyTraceMalloc_Init(void);
/* Start tracemalloc */
extern int _PyTraceMalloc_Start(int max_nframe);
diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py
index 5755f7697de91a..a848363fcd1de9 100644
--- a/Lib/test/test_tracemalloc.py
+++ b/Lib/test/test_tracemalloc.py
@@ -7,8 +7,9 @@
from test.support.script_helper import (assert_python_ok, assert_python_failure,
interpreter_requires_environment)
from test import support
-from test.support import os_helper
from test.support import force_not_colorized
+from test.support import os_helper
+from test.support import threading_helper
try:
import _testcapi
@@ -952,7 +953,6 @@ def check_env_var_invalid(self, nframe):
return
self.fail(f"unexpected output: {stderr!a}")
-
def test_env_var_invalid(self):
for nframe in INVALID_NFRAME:
with self.subTest(nframe=nframe):
@@ -1101,6 +1101,14 @@ def test_stop_untrack(self):
with self.assertRaises(RuntimeError):
self.untrack()
+ @unittest.skipIf(_testcapi is None, 'need _testcapi')
+ @threading_helper.requires_working_threading()
+ # gh-128679: Test crash on a debug build (especially on FreeBSD).
+ @unittest.skipIf(support.Py_DEBUG, 'need release build')
+ def test_tracemalloc_track_race(self):
+ # gh-128679: Test fix for tracemalloc.stop() race condition
+ _testcapi.tracemalloc_track_race()
+
if __name__ == "__main__":
unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2025-01-10-15-43-52.gh-issue-128679.KcfVVR.rst b/Misc/NEWS.d/next/Library/2025-01-10-15-43-52.gh-issue-128679.KcfVVR.rst
new file mode 100644
index 00000000000000..837f90df07a705
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-10-15-43-52.gh-issue-128679.KcfVVR.rst
@@ -0,0 +1,3 @@
+Fix :func:`tracemalloc.stop` race condition. Fix :mod:`tracemalloc` to
+support calling :func:`tracemalloc.stop` in one thread, while another thread
+is tracing memory allocations. Patch by Victor Stinner.
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 9f1a8faae7e8ed..633c53a26246a8 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -3322,6 +3322,104 @@ test_atexit(PyObject *self, PyObject *Py_UNUSED(args))
Py_RETURN_NONE;
}
+
+static void
+tracemalloc_track_race_thread(void *data)
+{
+ PyTraceMalloc_Track(123, 10, 1);
+
+ PyThread_type_lock lock = (PyThread_type_lock)data;
+ PyThread_release_lock(lock);
+}
+
+// gh-128679: Test fix for tracemalloc.stop() race condition
+static PyObject *
+tracemalloc_track_race(PyObject *self, PyObject *args)
+{
+#define NTHREAD 50
+ PyObject *tracemalloc = NULL;
+ PyObject *stop = NULL;
+ PyThread_type_lock locks[NTHREAD];
+ memset(locks, 0, sizeof(locks));
+
+ // Call tracemalloc.start()
+ tracemalloc = PyImport_ImportModule("tracemalloc");
+ if (tracemalloc == NULL) {
+ goto error;
+ }
+ PyObject *start = PyObject_GetAttrString(tracemalloc, "start");
+ if (start == NULL) {
+ goto error;
+ }
+ PyObject *res = PyObject_CallNoArgs(start);
+ Py_DECREF(start);
+ if (res == NULL) {
+ goto error;
+ }
+ Py_DECREF(res);
+
+ stop = PyObject_GetAttrString(tracemalloc, "stop");
+ Py_CLEAR(tracemalloc);
+ if (stop == NULL) {
+ goto error;
+ }
+
+ // Start threads
+ for (size_t i = 0; i < NTHREAD; i++) {
+ PyThread_type_lock lock = PyThread_allocate_lock();
+ if (!lock) {
+ PyErr_NoMemory();
+ goto error;
+ }
+ locks[i] = lock;
+ PyThread_acquire_lock(lock, 1);
+
+ unsigned long thread;
+ thread = PyThread_start_new_thread(tracemalloc_track_race_thread,
+ (void*)lock);
+ if (thread == (unsigned long)-1) {
+ PyErr_SetString(PyExc_RuntimeError, "can't start new thread");
+ goto error;
+ }
+ }
+
+ // Call tracemalloc.stop() while threads are running
+ res = PyObject_CallNoArgs(stop);
+ Py_CLEAR(stop);
+ if (res == NULL) {
+ goto error;
+ }
+ Py_DECREF(res);
+
+ // Wait until threads complete with the GIL released
+ Py_BEGIN_ALLOW_THREADS
+ for (size_t i = 0; i < NTHREAD; i++) {
+ PyThread_type_lock lock = locks[i];
+ PyThread_acquire_lock(lock, 1);
+ PyThread_release_lock(lock);
+ }
+ Py_END_ALLOW_THREADS
+
+ // Free threads locks
+ for (size_t i=0; i < NTHREAD; i++) {
+ PyThread_type_lock lock = locks[i];
+ PyThread_free_lock(lock);
+ }
+ Py_RETURN_NONE;
+
+error:
+ Py_CLEAR(tracemalloc);
+ Py_CLEAR(stop);
+ for (size_t i=0; i < NTHREAD; i++) {
+ PyThread_type_lock lock = locks[i];
+ if (lock) {
+ PyThread_free_lock(lock);
+ }
+ }
+ return NULL;
+#undef NTHREAD
+}
+
static PyMethodDef TestMethods[] = {
{"set_errno", set_errno, METH_VARARGS},
{"test_config", test_config, METH_NOARGS},
@@ -3464,6 +3562,7 @@ static PyMethodDef TestMethods[] = {
{"function_set_warning", function_set_warning, METH_NOARGS},
{"test_critical_sections", test_critical_sections, METH_NOARGS},
{"test_atexit", test_atexit, METH_NOARGS},
+ {"tracemalloc_track_race", tracemalloc_track_race, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index 887a1e820e250e..0b85187e5fce07 100644
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -223,10 +223,5 @@ PyInit__tracemalloc(void)
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif
- if (_PyTraceMalloc_Init() < 0) {
- Py_DECREF(m);
- return NULL;
- }
-
return m;
}
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index d545123a8a7e22..5255d137ccca89 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -706,6 +706,11 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
return _PyStatus_NO_MEMORY();
}
+ status = _PyTraceMalloc_Init();
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
+ }
+
PyThreadState *tstate = _PyThreadState_New(interp,
_PyThreadState_WHENCE_INIT);
if (tstate == NULL) {
diff --git a/Python/tracemalloc.c b/Python/tracemalloc.c
index e58b60ddd5e484..d86972b7bc0b97 100644
--- a/Python/tracemalloc.c
+++ b/Python/tracemalloc.c
@@ -2,6 +2,7 @@
#include "pycore_fileutils.h" // _Py_write_noraise()
#include "pycore_gc.h" // PyGC_Head
#include "pycore_hashtable.h" // _Py_hashtable_t
+#include "pycore_initconfig.h" // _PyStatus_NO_MEMORY()
#include "pycore_object.h" // _PyType_PreHeaderSize()
#include "pycore_pymem.h" // _Py_tracemalloc_config
#include "pycore_runtime.h" // _Py_ID()
@@ -538,12 +539,16 @@ tracemalloc_alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
return NULL;
TABLES_LOCK();
- if (ADD_TRACE(ptr, nelem * elsize) < 0) {
- /* Failed to allocate a trace for the new memory block */
- TABLES_UNLOCK();
- alloc->free(alloc->ctx, ptr);
- return NULL;
+
+ if (tracemalloc_config.tracing) {
+ if (ADD_TRACE(ptr, nelem * elsize) < 0) {
+ /* Failed to allocate a trace for the new memory block */
+ alloc->free(alloc->ctx, ptr);
+ ptr = NULL;
+ }
}
+ // else: gh-128679: tracemalloc.stop() was called by another thread
+
TABLES_UNLOCK();
return ptr;
}
@@ -559,11 +564,15 @@ tracemalloc_realloc(void *ctx, void *ptr, size_t new_size)
if (ptr2 == NULL)
return NULL;
+ TABLES_LOCK();
+ if (!tracemalloc_config.tracing) {
+ // gh-128679: tracemalloc.stop() was called by another thread
+ goto done;
+ }
+
if (ptr != NULL) {
/* an existing memory block has been resized */
- TABLES_LOCK();
-
/* tracemalloc_add_trace() updates the trace if there is already
a trace at address ptr2 */
if (ptr2 != ptr) {
@@ -582,20 +591,19 @@ tracemalloc_realloc(void *ctx, void *ptr, size_t new_size)
allocating memory. */
Py_FatalError("tracemalloc_realloc() failed to allocate a trace");
}
- TABLES_UNLOCK();
}
else {
/* new allocation */
- TABLES_LOCK();
if (ADD_TRACE(ptr2, new_size) < 0) {
/* Failed to allocate a trace for the new memory block */
- TABLES_UNLOCK();
alloc->free(alloc->ctx, ptr2);
- return NULL;
+ ptr2 = NULL;
}
- TABLES_UNLOCK();
}
+
+done:
+ TABLES_UNLOCK();
return ptr2;
}
@@ -614,7 +622,12 @@ tracemalloc_free(void *ctx, void *ptr)
alloc->free(alloc->ctx, ptr);
TABLES_LOCK();
- REMOVE_TRACE(ptr);
+
+ if (tracemalloc_config.tracing) {
+ REMOVE_TRACE(ptr);
+ }
+ // else: gh-128679: tracemalloc.stop() was called by another thread
+
TABLES_UNLOCK();
}
@@ -673,7 +686,9 @@ tracemalloc_realloc_gil(void *ctx, void *ptr, size_t new_size)
ptr2 = alloc->realloc(alloc->ctx, ptr, new_size);
if (ptr2 != NULL && ptr != NULL) {
TABLES_LOCK();
- REMOVE_TRACE(ptr);
+ if (tracemalloc_config.tracing) {
+ REMOVE_TRACE(ptr);
+ }
TABLES_UNLOCK();
}
return ptr2;
@@ -748,7 +763,9 @@ tracemalloc_raw_realloc(void *ctx, void *ptr, size_t new_size)
if (ptr2 != NULL && ptr != NULL) {
TABLES_LOCK();
- REMOVE_TRACE(ptr);
+ if (tracemalloc_config.tracing) {
+ REMOVE_TRACE(ptr);
+ }
TABLES_UNLOCK();
}
return ptr2;
@@ -779,46 +796,36 @@ tracemalloc_clear_filename(void *value)
/* reentrant flag must be set to call this function and GIL must be held */
static void
-tracemalloc_clear_traces(void)
+tracemalloc_clear_traces_unlocked(void)
{
+ set_reentrant(1);
+
/* The GIL protects variables against concurrent access */
assert(PyGILState_Check());
- TABLES_LOCK();
_Py_hashtable_clear(tracemalloc_traces);
_Py_hashtable_clear(tracemalloc_domains);
tracemalloc_traced_memory = 0;
tracemalloc_peak_traced_memory = 0;
- TABLES_UNLOCK();
_Py_hashtable_clear(tracemalloc_tracebacks);
_Py_hashtable_clear(tracemalloc_filenames);
+
+ set_reentrant(0);
}
-int
+PyStatus
_PyTraceMalloc_Init(void)
{
- if (tracemalloc_config.initialized == TRACEMALLOC_FINALIZED) {
- PyErr_SetString(PyExc_RuntimeError,
- "the tracemalloc module has been unloaded");
- return -1;
- }
-
- if (tracemalloc_config.initialized == TRACEMALLOC_INITIALIZED)
- return 0;
+ assert(tracemalloc_config.initialized == TRACEMALLOC_NOT_INITIALIZED);
PyMem_GetAllocator(PYMEM_DOMAIN_RAW, &allocators.raw);
#ifdef REENTRANT_THREADLOCAL
if (PyThread_tss_create(&tracemalloc_reentrant_key) != 0) {
-#ifdef MS_WINDOWS
- PyErr_SetFromWindowsErr(0);
-#else
- PyErr_SetFromErrno(PyExc_OSError);
-#endif
- return -1;
+ return _PyStatus_NO_MEMORY();
}
#endif
@@ -826,8 +833,7 @@ _PyTraceMalloc_Init(void)
if (tables_lock == NULL) {
tables_lock = PyThread_allocate_lock();
if (tables_lock == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "cannot allocate lock");
- return -1;
+ return _PyStatus_NO_MEMORY();
}
}
#endif
@@ -844,9 +850,9 @@ _PyTraceMalloc_Init(void)
tracemalloc_domains = tracemalloc_create_domains_table();
if (tracemalloc_filenames == NULL || tracemalloc_tracebacks == NULL
- || tracemalloc_traces == NULL || tracemalloc_domains == NULL) {
- PyErr_NoMemory();
- return -1;
+ || tracemalloc_traces == NULL || tracemalloc_domains == NULL)
+ {
+ return _PyStatus_NO_MEMORY();
}
tracemalloc_empty_traceback.nframe = 1;
@@ -857,7 +863,7 @@ _PyTraceMalloc_Init(void)
tracemalloc_empty_traceback.hash = traceback_hash(&tracemalloc_empty_traceback);
tracemalloc_config.initialized = TRACEMALLOC_INITIALIZED;
- return 0;
+ return _PyStatus_OK();
}
@@ -902,10 +908,6 @@ _PyTraceMalloc_Start(int max_nframe)
return -1;
}
- if (_PyTraceMalloc_Init() < 0) {
- return -1;
- }
-
if (PyRefTracer_SetTracer(_PyTraceMalloc_TraceRef, NULL) < 0) {
return -1;
}
@@ -960,8 +962,13 @@ _PyTraceMalloc_Start(int max_nframe)
void
_PyTraceMalloc_Stop(void)
{
- if (!tracemalloc_config.tracing)
- return;
+ // Lock to synchronize with tracemalloc_free() which checks
+ // 'tracing' while holding the lock.
+ TABLES_LOCK();
+
+ if (!tracemalloc_config.tracing) {
+ goto done;
+ }
/* stop tracing Python memory allocations */
tracemalloc_config.tracing = 0;
@@ -973,11 +980,14 @@ _PyTraceMalloc_Stop(void)
PyMem_SetAllocator(PYMEM_DOMAIN_MEM, &allocators.mem);
PyMem_SetAllocator(PYMEM_DOMAIN_OBJ, &allocators.obj);
- tracemalloc_clear_traces();
+ tracemalloc_clear_traces_unlocked();
/* release memory */
raw_free(tracemalloc_traceback);
tracemalloc_traceback = NULL;
+
+done:
+ TABLES_UNLOCK();
}
@@ -1227,23 +1237,17 @@ tracemalloc_pyobject_decref(void *value)
static traceback_t*
-tracemalloc_get_traceback(unsigned int domain, uintptr_t ptr)
+tracemalloc_get_traceback_unlocked(unsigned int domain, uintptr_t ptr)
{
-
- if (!tracemalloc_config.tracing)
+ if (!tracemalloc_config.tracing) {
return NULL;
+ }
- trace_t *trace;
- TABLES_LOCK();
_Py_hashtable_t *traces = tracemalloc_get_traces_table(domain);
+ trace_t *trace = NULL;
if (traces) {
trace = _Py_hashtable_get(traces, TO_PTR(ptr));
}
- else {
- trace = NULL;
- }
- TABLES_UNLOCK();
-
if (!trace) {
return NULL;
}
@@ -1272,13 +1276,20 @@ _PyMem_DumpTraceback(int fd, const void *ptr)
traceback_t *traceback;
int i;
- if (!tracemalloc_config.tracing) {
+ TABLES_LOCK();
+
+ if (tracemalloc_config.tracing) {
+ traceback = tracemalloc_get_traceback_unlocked(DEFAULT_DOMAIN,
+ (uintptr_t)ptr);
+ }
+ else {
+ traceback = NULL;
PUTS(fd, "Enable tracemalloc to get the memory block "
"allocation traceback\n\n");
- return;
}
- traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (uintptr_t)ptr);
+ TABLES_UNLOCK();
+
if (traceback == NULL)
return;
@@ -1307,20 +1318,19 @@ int
PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr,
size_t size)
{
- int res;
- PyGILState_STATE gil_state;
+ PyGILState_STATE gil_state = PyGILState_Ensure();
+ TABLES_LOCK();
- if (!tracemalloc_config.tracing) {
- /* tracemalloc is not tracing: do nothing */
- return -2;
+ int res;
+ if (tracemalloc_config.tracing) {
+ res = tracemalloc_add_trace(domain, ptr, size);
+ }
+ else {
+ // gh-128679: tracemalloc.stop() was called by another thread
+ res = -2;
}
- gil_state = PyGILState_Ensure();
-
- TABLES_LOCK();
- res = tracemalloc_add_trace(domain, ptr, size);
TABLES_UNLOCK();
-
PyGILState_Release(gil_state);
return res;
}
@@ -1329,16 +1339,20 @@ PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr,
int
PyTraceMalloc_Untrack(unsigned int domain, uintptr_t ptr)
{
- if (!tracemalloc_config.tracing) {
+ TABLES_LOCK();
+
+ int result;
+ if (tracemalloc_config.tracing) {
+ tracemalloc_remove_trace(domain, ptr);
+ result = 0;
+ }
+ else {
/* tracemalloc is not tracing: do nothing */
- return -2;
+ result = -2;
}
- TABLES_LOCK();
- tracemalloc_remove_trace(domain, ptr);
TABLES_UNLOCK();
-
- return 0;
+ return result;
}
@@ -1376,6 +1390,12 @@ _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event, void* Py_UNUSED(ig
int res = -1;
TABLES_LOCK();
+
+ if (!tracemalloc_config.tracing) {
+ // gh-128679: tracemalloc.stop() was called by another thread
+ goto done;
+ }
+
trace_t *trace = _Py_hashtable_get(tracemalloc_traces, TO_PTR(ptr));
if (trace != NULL) {
/* update the traceback of the memory block */
@@ -1386,6 +1406,8 @@ _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event, void* Py_UNUSED(ig
}
}
/* else: cannot track the object, its memory block size is unknown */
+
+done:
TABLES_UNLOCK();
return res;
@@ -1397,7 +1419,9 @@ _PyTraceMalloc_GetTraceback(unsigned int domain, uintptr_t ptr)
{
traceback_t *traceback;
- traceback = tracemalloc_get_traceback(domain, ptr);
+ TABLES_LOCK();
+ traceback = tracemalloc_get_traceback_unlocked(domain, ptr);
+ TABLES_UNLOCK();
if (traceback == NULL)
Py_RETURN_NONE;
@@ -1407,19 +1431,20 @@ _PyTraceMalloc_GetTraceback(unsigned int domain, uintptr_t ptr)
int
_PyTraceMalloc_IsTracing(void)
{
- return tracemalloc_config.tracing;
+ TABLES_LOCK();
+ int tracing = tracemalloc_config.tracing;
+ TABLES_UNLOCK();
+ return tracing;
}
void
_PyTraceMalloc_ClearTraces(void)
{
-
- if (!tracemalloc_config.tracing) {
- return;
+ TABLES_LOCK();
+ if (tracemalloc_config.tracing) {
+ tracemalloc_clear_traces_unlocked();
}
- set_reentrant(1);
- tracemalloc_clear_traces();
- set_reentrant(0);
+ TABLES_UNLOCK();
}
PyObject *
@@ -1506,19 +1531,10 @@ PyObject *
_PyTraceMalloc_GetObjectTraceback(PyObject *obj)
/*[clinic end generated code: output=41ee0553a658b0aa input=29495f1b21c53212]*/
{
- PyTypeObject *type;
- traceback_t *traceback;
-
- type = Py_TYPE(obj);
+ PyTypeObject *type = Py_TYPE(obj);
const size_t presize = _PyType_PreHeaderSize(type);
uintptr_t ptr = (uintptr_t)((char *)obj - presize);
-
- traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, ptr);
- if (traceback == NULL) {
- Py_RETURN_NONE;
- }
-
- return traceback_to_pyobject(traceback, NULL);
+ return _PyTraceMalloc_GetTraceback(DEFAULT_DOMAIN, ptr);
}
int _PyTraceMalloc_GetTracebackLimit(void) {
@@ -1530,14 +1546,19 @@ _PyTraceMalloc_GetMemory(void) {
size_t size;
- size = _Py_hashtable_size(tracemalloc_tracebacks);
- size += _Py_hashtable_size(tracemalloc_filenames);
-
TABLES_LOCK();
- size += _Py_hashtable_size(tracemalloc_traces);
- _Py_hashtable_foreach(tracemalloc_domains,
- tracemalloc_get_tracemalloc_memory_cb, &size);
+ if (tracemalloc_config.tracing) {
+ size = _Py_hashtable_size(tracemalloc_tracebacks);
+ size += _Py_hashtable_size(tracemalloc_filenames);
+ size += _Py_hashtable_size(tracemalloc_traces);
+ _Py_hashtable_foreach(tracemalloc_domains,
+ tracemalloc_get_tracemalloc_memory_cb, &size);
+ }
+ else {
+ size = 0;
+ }
TABLES_UNLOCK();
+
return size;
}
@@ -1547,12 +1568,15 @@ _PyTraceMalloc_GetTracedMemory(void)
{
Py_ssize_t size, peak_size;
- if (!tracemalloc_config.tracing)
- return Py_BuildValue("ii", 0, 0);
-
TABLES_LOCK();
- size = tracemalloc_traced_memory;
- peak_size = tracemalloc_peak_traced_memory;
+ if (tracemalloc_config.tracing) {
+ size = tracemalloc_traced_memory;
+ peak_size = tracemalloc_peak_traced_memory;
+ }
+ else {
+ size = 0;
+ peak_size = 0;
+ }
TABLES_UNLOCK();
return Py_BuildValue("nn", size, peak_size);
@@ -1561,10 +1585,9 @@ _PyTraceMalloc_GetTracedMemory(void)
void
_PyTraceMalloc_ResetPeak(void)
{
- if (!tracemalloc_config.tracing) {
- return;
- }
TABLES_LOCK();
- tracemalloc_peak_traced_memory = tracemalloc_traced_memory;
+ if (tracemalloc_config.tracing) {
+ tracemalloc_peak_traced_memory = tracemalloc_traced_memory;
+ }
TABLES_UNLOCK();
}
1
0
[3.12] gh-128991: Release the enter frame reference within bdb callba… (#129003)
by gaogaotiantian Jan. 18, 2025
by gaogaotiantian Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/6d638c2655374f2fbd80779aff349324db…
commit: 6d638c2655374f2fbd80779aff349324dbc857f8
branch: 3.12
author: Tian Gao <gaogaotiantian(a)hotmail.com>
committer: gaogaotiantian <gaogaotiantian(a)hotmail.com>
date: 2025-01-18T17:21:34-05:00
summary:
[3.12] gh-128991: Release the enter frame reference within bdb callba… (#129003)
[3.12] gh-128991: Release the enter frame reference within bdb callback (GH-128992)
* Release the enter frame reference within bdb callback
* 📜🤖 Added by blurb_it.
---------
(cherry picked from commit 61b35f74aa4a6ac606635e245147ff3658628d99)
files:
A Misc/NEWS.d/next/Library/2025-01-18-16-58-10.gh-issue-128991.EzJit9.rst
M Lib/bdb.py
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 3486deacd86a7c..8b63d9eca6da5f 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -3,6 +3,7 @@
import fnmatch
import sys
import os
+from contextlib import contextmanager
from inspect import CO_GENERATOR, CO_COROUTINE, CO_ASYNC_GENERATOR
__all__ = ["BdbQuit", "Bdb", "Breakpoint"]
@@ -60,6 +61,12 @@ def reset(self):
self.botframe = None
self._set_stopinfo(None, None)
+ @contextmanager
+ def set_enterframe(self, frame):
+ self.enterframe = frame
+ yield
+ self.enterframe = None
+
def trace_dispatch(self, frame, event, arg):
"""Dispatch a trace function for debugged frames based on the event.
@@ -84,24 +91,26 @@ def trace_dispatch(self, frame, event, arg):
The arg parameter depends on the previous event.
"""
- if self.quitting:
- return # None
- if event == 'line':
- return self.dispatch_line(frame)
- if event == 'call':
- return self.dispatch_call(frame, arg)
- if event == 'return':
- return self.dispatch_return(frame, arg)
- if event == 'exception':
- return self.dispatch_exception(frame, arg)
- if event == 'c_call':
- return self.trace_dispatch
- if event == 'c_exception':
- return self.trace_dispatch
- if event == 'c_return':
+
+ with self.set_enterframe(frame):
+ if self.quitting:
+ return # None
+ if event == 'line':
+ return self.dispatch_line(frame)
+ if event == 'call':
+ return self.dispatch_call(frame, arg)
+ if event == 'return':
+ return self.dispatch_return(frame, arg)
+ if event == 'exception':
+ return self.dispatch_exception(frame, arg)
+ if event == 'c_call':
+ return self.trace_dispatch
+ if event == 'c_exception':
+ return self.trace_dispatch
+ if event == 'c_return':
+ return self.trace_dispatch
+ print('bdb.Bdb.dispatch: unknown debugging event:', repr(event))
return self.trace_dispatch
- print('bdb.Bdb.dispatch: unknown debugging event:', repr(event))
- return self.trace_dispatch
def dispatch_line(self, frame):
"""Invoke user function and return trace function for line event.
@@ -335,12 +344,12 @@ def set_trace(self, frame=None):
if frame is None:
frame = sys._getframe().f_back
self.reset()
- while frame:
- frame.f_trace = self.trace_dispatch
- self.botframe = frame
- frame = frame.f_back
- self.set_step()
- self.enterframe = None
+ with self.set_enterframe(frame):
+ while frame:
+ frame.f_trace = self.trace_dispatch
+ self.botframe = frame
+ frame = frame.f_back
+ self.set_step()
sys.settrace(self.trace_dispatch)
def set_continue(self):
@@ -357,7 +366,6 @@ def set_continue(self):
while frame and frame is not self.botframe:
del frame.f_trace
frame = frame.f_back
- self.enterframe = None
def set_quit(self):
"""Set quitting attribute to True.
diff --git a/Misc/NEWS.d/next/Library/2025-01-18-16-58-10.gh-issue-128991.EzJit9.rst b/Misc/NEWS.d/next/Library/2025-01-18-16-58-10.gh-issue-128991.EzJit9.rst
new file mode 100644
index 00000000000000..64fa04fb53e89c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-18-16-58-10.gh-issue-128991.EzJit9.rst
@@ -0,0 +1 @@
+Release the enter frame reference within :mod:`bdb` callback
1
0
[3.13] gh-128991: Release the enter frame reference within bdb callba… (#129002)
by gaogaotiantian Jan. 18, 2025
by gaogaotiantian Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/ef9961840b546aba33b168fd8f5788e1ea…
commit: ef9961840b546aba33b168fd8f5788e1ea1960e8
branch: 3.13
author: Tian Gao <gaogaotiantian(a)hotmail.com>
committer: gaogaotiantian <gaogaotiantian(a)hotmail.com>
date: 2025-01-18T17:21:23-05:00
summary:
[3.13] gh-128991: Release the enter frame reference within bdb callba… (#129002)
[3.13] gh-128991: Release the enter frame reference within bdb callback (GH-128992)
* Release the enter frame reference within bdb callback
* 📜🤖 Added by blurb_it.
---------
(cherry picked from commit 61b35f74aa4a6ac606635e245147ff3658628d99)
files:
A Misc/NEWS.d/next/Library/2025-01-18-16-58-10.gh-issue-128991.EzJit9.rst
M Lib/bdb.py
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 3a4453d95f6596..0a3b6dfbfc6025 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -3,6 +3,7 @@
import fnmatch
import sys
import os
+from contextlib import contextmanager
from inspect import CO_GENERATOR, CO_COROUTINE, CO_ASYNC_GENERATOR
__all__ = ["BdbQuit", "Bdb", "Breakpoint"]
@@ -63,6 +64,12 @@ def reset(self):
self.botframe = None
self._set_stopinfo(None, None)
+ @contextmanager
+ def set_enterframe(self, frame):
+ self.enterframe = frame
+ yield
+ self.enterframe = None
+
def trace_dispatch(self, frame, event, arg):
"""Dispatch a trace function for debugged frames based on the event.
@@ -88,28 +95,27 @@ def trace_dispatch(self, frame, event, arg):
The arg parameter depends on the previous event.
"""
- self.enterframe = frame
-
- if self.quitting:
- return # None
- if event == 'line':
- return self.dispatch_line(frame)
- if event == 'call':
- return self.dispatch_call(frame, arg)
- if event == 'return':
- return self.dispatch_return(frame, arg)
- if event == 'exception':
- return self.dispatch_exception(frame, arg)
- if event == 'c_call':
- return self.trace_dispatch
- if event == 'c_exception':
- return self.trace_dispatch
- if event == 'c_return':
+ with self.set_enterframe(frame):
+ if self.quitting:
+ return # None
+ if event == 'line':
+ return self.dispatch_line(frame)
+ if event == 'call':
+ return self.dispatch_call(frame, arg)
+ if event == 'return':
+ return self.dispatch_return(frame, arg)
+ if event == 'exception':
+ return self.dispatch_exception(frame, arg)
+ if event == 'c_call':
+ return self.trace_dispatch
+ if event == 'c_exception':
+ return self.trace_dispatch
+ if event == 'c_return':
+ return self.trace_dispatch
+ if event == 'opcode':
+ return self.dispatch_opcode(frame, arg)
+ print('bdb.Bdb.dispatch: unknown debugging event:', repr(event))
return self.trace_dispatch
- if event == 'opcode':
- return self.dispatch_opcode(frame, arg)
- print('bdb.Bdb.dispatch: unknown debugging event:', repr(event))
- return self.trace_dispatch
def dispatch_line(self, frame):
"""Invoke user function and return trace function for line event.
@@ -373,16 +379,15 @@ def set_trace(self, frame=None):
if frame is None:
frame = sys._getframe().f_back
self.reset()
- self.enterframe = frame
- while frame:
- frame.f_trace = self.trace_dispatch
- self.botframe = frame
- self.frame_trace_lines_opcodes[frame] = (frame.f_trace_lines, frame.f_trace_opcodes)
- # We need f_trace_lines == True for the debugger to work
- frame.f_trace_lines = True
- frame = frame.f_back
- self.set_stepinstr()
- self.enterframe = None
+ with self.set_enterframe(frame):
+ while frame:
+ frame.f_trace = self.trace_dispatch
+ self.botframe = frame
+ self.frame_trace_lines_opcodes[frame] = (frame.f_trace_lines, frame.f_trace_opcodes)
+ # We need f_trace_lines == True for the debugger to work
+ frame.f_trace_lines = True
+ frame = frame.f_back
+ self.set_stepinstr()
sys.settrace(self.trace_dispatch)
def set_continue(self):
@@ -402,7 +407,6 @@ def set_continue(self):
for frame, (trace_lines, trace_opcodes) in self.frame_trace_lines_opcodes.items():
frame.f_trace_lines, frame.f_trace_opcodes = trace_lines, trace_opcodes
self.frame_trace_lines_opcodes = {}
- self.enterframe = None
def set_quit(self):
"""Set quitting attribute to True.
diff --git a/Misc/NEWS.d/next/Library/2025-01-18-16-58-10.gh-issue-128991.EzJit9.rst b/Misc/NEWS.d/next/Library/2025-01-18-16-58-10.gh-issue-128991.EzJit9.rst
new file mode 100644
index 00000000000000..64fa04fb53e89c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-18-16-58-10.gh-issue-128991.EzJit9.rst
@@ -0,0 +1 @@
+Release the enter frame reference within :mod:`bdb` callback
1
0
gh-128991: Release the enter frame reference within bdb callback (#128992)
by gaogaotiantian Jan. 18, 2025
by gaogaotiantian Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/61b35f74aa4a6ac606635e245147ff3658…
commit: 61b35f74aa4a6ac606635e245147ff3658628d99
branch: main
author: Tian Gao <gaogaotiantian(a)hotmail.com>
committer: gaogaotiantian <gaogaotiantian(a)hotmail.com>
date: 2025-01-18T16:53:06-05:00
summary:
gh-128991: Release the enter frame reference within bdb callback (#128992)
* Release the enter frame reference within bdb callback
* 📜🤖 Added by blurb_it.
---------
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot](a)users.noreply.github.com>
files:
A Misc/NEWS.d/next/Library/2025-01-18-16-58-10.gh-issue-128991.EzJit9.rst
M Lib/bdb.py
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 73e249621a053b..a741628e32a981 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -4,6 +4,7 @@
import sys
import os
import weakref
+from contextlib import contextmanager
from inspect import CO_GENERATOR, CO_COROUTINE, CO_ASYNC_GENERATOR
__all__ = ["BdbQuit", "Bdb", "Breakpoint"]
@@ -65,6 +66,12 @@ def reset(self):
self.botframe = None
self._set_stopinfo(None, None)
+ @contextmanager
+ def set_enterframe(self, frame):
+ self.enterframe = frame
+ yield
+ self.enterframe = None
+
def trace_dispatch(self, frame, event, arg):
"""Dispatch a trace function for debugged frames based on the event.
@@ -90,28 +97,27 @@ def trace_dispatch(self, frame, event, arg):
The arg parameter depends on the previous event.
"""
- self.enterframe = frame
-
- if self.quitting:
- return # None
- if event == 'line':
- return self.dispatch_line(frame)
- if event == 'call':
- return self.dispatch_call(frame, arg)
- if event == 'return':
- return self.dispatch_return(frame, arg)
- if event == 'exception':
- return self.dispatch_exception(frame, arg)
- if event == 'c_call':
- return self.trace_dispatch
- if event == 'c_exception':
- return self.trace_dispatch
- if event == 'c_return':
+ with self.set_enterframe(frame):
+ if self.quitting:
+ return # None
+ if event == 'line':
+ return self.dispatch_line(frame)
+ if event == 'call':
+ return self.dispatch_call(frame, arg)
+ if event == 'return':
+ return self.dispatch_return(frame, arg)
+ if event == 'exception':
+ return self.dispatch_exception(frame, arg)
+ if event == 'c_call':
+ return self.trace_dispatch
+ if event == 'c_exception':
+ return self.trace_dispatch
+ if event == 'c_return':
+ return self.trace_dispatch
+ if event == 'opcode':
+ return self.dispatch_opcode(frame, arg)
+ print('bdb.Bdb.dispatch: unknown debugging event:', repr(event))
return self.trace_dispatch
- if event == 'opcode':
- return self.dispatch_opcode(frame, arg)
- print('bdb.Bdb.dispatch: unknown debugging event:', repr(event))
- return self.trace_dispatch
def dispatch_line(self, frame):
"""Invoke user function and return trace function for line event.
@@ -395,16 +401,15 @@ def set_trace(self, frame=None):
if frame is None:
frame = sys._getframe().f_back
self.reset()
- self.enterframe = frame
- while frame:
- frame.f_trace = self.trace_dispatch
- self.botframe = frame
- self.frame_trace_lines_opcodes[frame] = (frame.f_trace_lines, frame.f_trace_opcodes)
- # We need f_trace_lines == True for the debugger to work
- frame.f_trace_lines = True
- frame = frame.f_back
- self.set_stepinstr()
- self.enterframe = None
+ with self.set_enterframe(frame):
+ while frame:
+ frame.f_trace = self.trace_dispatch
+ self.botframe = frame
+ self.frame_trace_lines_opcodes[frame] = (frame.f_trace_lines, frame.f_trace_opcodes)
+ # We need f_trace_lines == True for the debugger to work
+ frame.f_trace_lines = True
+ frame = frame.f_back
+ self.set_stepinstr()
sys.settrace(self.trace_dispatch)
def set_continue(self):
@@ -424,7 +429,6 @@ def set_continue(self):
for frame, (trace_lines, trace_opcodes) in self.frame_trace_lines_opcodes.items():
frame.f_trace_lines, frame.f_trace_opcodes = trace_lines, trace_opcodes
self.frame_trace_lines_opcodes = {}
- self.enterframe = None
def set_quit(self):
"""Set quitting attribute to True.
diff --git a/Misc/NEWS.d/next/Library/2025-01-18-16-58-10.gh-issue-128991.EzJit9.rst b/Misc/NEWS.d/next/Library/2025-01-18-16-58-10.gh-issue-128991.EzJit9.rst
new file mode 100644
index 00000000000000..64fa04fb53e89c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-18-16-58-10.gh-issue-128991.EzJit9.rst
@@ -0,0 +1 @@
+Release the enter frame reference within :mod:`bdb` callback
1
0
[3.12] gh-128998: Fix indentation of numbered list and literal block (GH-128999) (#129001)
by AA-Turner Jan. 18, 2025
by AA-Turner Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/ae8c8b7ffd4d50714342b8f011064ba69c…
commit: ae8c8b7ffd4d50714342b8f011064ba69c2df358
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: AA-Turner <9087854+AA-Turner(a)users.noreply.github.com>
date: 2025-01-18T21:00:14Z
summary:
[3.12] gh-128998: Fix indentation of numbered list and literal block (GH-128999) (#129001)
gh-128998: Fix indentation of numbered list and literal block (GH-128999)
(cherry picked from commit e8092e5cdcd6707ac0b16d8fb37fa080a88bcc97)
Co-authored-by: Rafael Fontenelle <rffontenelle(a)users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner(a)users.noreply.github.com>
files:
M Doc/faq/programming.rst
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
index 7a86701116413b..4b52404671d666 100644
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -1906,28 +1906,30 @@ In the standard library code, you will see several common patterns for
correctly using identity tests:
1) As recommended by :pep:`8`, an identity test is the preferred way to check
-for ``None``. This reads like plain English in code and avoids confusion with
-other objects that may have boolean values that evaluate to false.
+ for ``None``. This reads like plain English in code and avoids confusion
+ with other objects that may have boolean values that evaluate to false.
2) Detecting optional arguments can be tricky when ``None`` is a valid input
-value. In those situations, you can create a singleton sentinel object
-guaranteed to be distinct from other objects. For example, here is how
-to implement a method that behaves like :meth:`dict.pop`::
+ value. In those situations, you can create a singleton sentinel object
+ guaranteed to be distinct from other objects. For example, here is how
+ to implement a method that behaves like :meth:`dict.pop`:
- _sentinel = object()
+ .. code-block:: python
- def pop(self, key, default=_sentinel):
- if key in self:
- value = self[key]
- del self[key]
- return value
- if default is _sentinel:
- raise KeyError(key)
- return default
+ _sentinel = object()
+
+ def pop(self, key, default=_sentinel):
+ if key in self:
+ value = self[key]
+ del self[key]
+ return value
+ if default is _sentinel:
+ raise KeyError(key)
+ return default
3) Container implementations sometimes need to augment equality tests with
-identity tests. This prevents the code from being confused by objects such as
-``float('NaN')`` that are not equal to themselves.
+ identity tests. This prevents the code from being confused by objects
+ such as ``float('NaN')`` that are not equal to themselves.
For example, here is the implementation of
:meth:`!collections.abc.Sequence.__contains__`::
1
0
[3.13] gh-128998: Fix indentation of numbered list and literal block (GH-128999) (#129000)
by AA-Turner Jan. 18, 2025
by AA-Turner Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/03ee311e5a454dce665f14deac91687a75…
commit: 03ee311e5a454dce665f14deac91687a752e1679
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: AA-Turner <9087854+AA-Turner(a)users.noreply.github.com>
date: 2025-01-18T20:58:20Z
summary:
[3.13] gh-128998: Fix indentation of numbered list and literal block (GH-128999) (#129000)
gh-128998: Fix indentation of numbered list and literal block (GH-128999)
(cherry picked from commit e8092e5cdcd6707ac0b16d8fb37fa080a88bcc97)
Co-authored-by: Rafael Fontenelle <rffontenelle(a)users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner(a)users.noreply.github.com>
files:
M Doc/faq/programming.rst
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
index fa7b22bde1dc6f..776bab1ed5b779 100644
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -1906,28 +1906,30 @@ In the standard library code, you will see several common patterns for
correctly using identity tests:
1) As recommended by :pep:`8`, an identity test is the preferred way to check
-for ``None``. This reads like plain English in code and avoids confusion with
-other objects that may have boolean values that evaluate to false.
+ for ``None``. This reads like plain English in code and avoids confusion
+ with other objects that may have boolean values that evaluate to false.
2) Detecting optional arguments can be tricky when ``None`` is a valid input
-value. In those situations, you can create a singleton sentinel object
-guaranteed to be distinct from other objects. For example, here is how
-to implement a method that behaves like :meth:`dict.pop`::
+ value. In those situations, you can create a singleton sentinel object
+ guaranteed to be distinct from other objects. For example, here is how
+ to implement a method that behaves like :meth:`dict.pop`:
- _sentinel = object()
+ .. code-block:: python
- def pop(self, key, default=_sentinel):
- if key in self:
- value = self[key]
- del self[key]
- return value
- if default is _sentinel:
- raise KeyError(key)
- return default
+ _sentinel = object()
+
+ def pop(self, key, default=_sentinel):
+ if key in self:
+ value = self[key]
+ del self[key]
+ return value
+ if default is _sentinel:
+ raise KeyError(key)
+ return default
3) Container implementations sometimes need to augment equality tests with
-identity tests. This prevents the code from being confused by objects such as
-``float('NaN')`` that are not equal to themselves.
+ identity tests. This prevents the code from being confused by objects
+ such as ``float('NaN')`` that are not equal to themselves.
For example, here is the implementation of
:meth:`!collections.abc.Sequence.__contains__`::
1
0
Jan. 18, 2025
https://github.com/python/cpython/commit/e8092e5cdcd6707ac0b16d8fb37fa080a8…
commit: e8092e5cdcd6707ac0b16d8fb37fa080a88bcc97
branch: main
author: Rafael Fontenelle <rffontenelle(a)users.noreply.github.com>
committer: AA-Turner <9087854+AA-Turner(a)users.noreply.github.com>
date: 2025-01-18T20:52:30Z
summary:
gh-128998: Fix indentation of numbered list and literal block (#128999)
Co-authored-by: Adam Turner <9087854+AA-Turner(a)users.noreply.github.com>
files:
M Doc/faq/programming.rst
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
index fa7b22bde1dc6f..776bab1ed5b779 100644
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -1906,28 +1906,30 @@ In the standard library code, you will see several common patterns for
correctly using identity tests:
1) As recommended by :pep:`8`, an identity test is the preferred way to check
-for ``None``. This reads like plain English in code and avoids confusion with
-other objects that may have boolean values that evaluate to false.
+ for ``None``. This reads like plain English in code and avoids confusion
+ with other objects that may have boolean values that evaluate to false.
2) Detecting optional arguments can be tricky when ``None`` is a valid input
-value. In those situations, you can create a singleton sentinel object
-guaranteed to be distinct from other objects. For example, here is how
-to implement a method that behaves like :meth:`dict.pop`::
+ value. In those situations, you can create a singleton sentinel object
+ guaranteed to be distinct from other objects. For example, here is how
+ to implement a method that behaves like :meth:`dict.pop`:
- _sentinel = object()
+ .. code-block:: python
- def pop(self, key, default=_sentinel):
- if key in self:
- value = self[key]
- del self[key]
- return value
- if default is _sentinel:
- raise KeyError(key)
- return default
+ _sentinel = object()
+
+ def pop(self, key, default=_sentinel):
+ if key in self:
+ value = self[key]
+ del self[key]
+ return value
+ if default is _sentinel:
+ raise KeyError(key)
+ return default
3) Container implementations sometimes need to augment equality tests with
-identity tests. This prevents the code from being confused by objects such as
-``float('NaN')`` that are not equal to themselves.
+ identity tests. This prevents the code from being confused by objects
+ such as ``float('NaN')`` that are not equal to themselves.
For example, here is the implementation of
:meth:`!collections.abc.Sequence.__contains__`::
1
0
[3.12] Pre-commit: Drop specific language version and bump hooks (GH-128801) (#128997)
by hugovk Jan. 18, 2025
by hugovk Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/4219cda83d36892efcf945ff62211742bc…
commit: 4219cda83d36892efcf945ff62211742bc051007
branch: 3.12
author: Peter Bierma <zintensitydev(a)gmail.com>
committer: hugovk <1324225+hugovk(a)users.noreply.github.com>
date: 2025-01-18T22:52:24+02:00
summary:
[3.12] Pre-commit: Drop specific language version and bump hooks (GH-128801) (#128997)
files:
M .pre-commit-config.yaml
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 30c4395e17b3c9..ad91fe68a33cf6 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
- rev: v0.8.2
+ rev: v0.9.1
hooks:
- id: ruff
name: Run Ruff (lint) on Doc/
@@ -34,7 +34,7 @@ repos:
types_or: [c, inc, python, rst]
- repo: https://github.com/woodruffw/zizmor-pre-commit
- rev: v0.8.0
+ rev: v1.1.1
hooks:
- id: zizmor
1
0
[3.13] Pre-commit: Drop specific language version and bump hooks (GH-128801) (#128994)
by hugovk Jan. 18, 2025
by hugovk Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/453eaa9ffcef1ab1910648d8c4b2236f0b…
commit: 453eaa9ffcef1ab1910648d8c4b2236f0b5830c1
branch: 3.13
author: Peter Bierma <zintensitydev(a)gmail.com>
committer: hugovk <1324225+hugovk(a)users.noreply.github.com>
date: 2025-01-18T22:52:07+02:00
summary:
[3.13] Pre-commit: Drop specific language version and bump hooks (GH-128801) (#128994)
Co-authored-by: Peter Bierma <zintensitydev(a)gmail.com>
files:
M .pre-commit-config.yaml
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index e2f00bae944f2f..7f38c3e848f03d 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
- rev: v0.8.2
+ rev: v0.9.1
hooks:
- id: ruff
name: Run Ruff (lint) on Doc/
@@ -25,7 +25,6 @@ repos:
- id: black
name: Run Black on Tools/jit/
files: ^Tools/jit/
- language_version: python3.12
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
@@ -42,7 +41,7 @@ repos:
types_or: [c, inc, python, rst]
- repo: https://github.com/woodruffw/zizmor-pre-commit
- rev: v0.8.0
+ rev: v1.1.1
hooks:
- id: zizmor
1
0
[3.12] gh-121542: Document trailing newline behavior in `set_content()` (GH-121543) (#128996)
by Eclips4 Jan. 18, 2025
by Eclips4 Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/104d37ad99389648bc270d9d32aaa6b764…
commit: 104d37ad99389648bc270d9d32aaa6b764e6e04f
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: Eclips4 <kirill.bast9(a)mail.ru>
date: 2025-01-18T18:41:59Z
summary:
[3.12] gh-121542: Document trailing newline behavior in `set_content()` (GH-121543) (#128996)
gh-121542: Document trailing newline behavior in `set_content()` (GH-121543)
(cherry picked from commit fba475ae6f932d0aaee6832b4102b2d4c50df70f)
Co-authored-by: Peter Bierma <zintensitydev(a)gmail.com>
Co-authored-by: Yizheng Meng <dev(a)rapidcow.org>
files:
M Doc/library/email.contentmanager.rst
diff --git a/Doc/library/email.contentmanager.rst b/Doc/library/email.contentmanager.rst
index a86e227429b06d..b33fe82a6e4c9f 100644
--- a/Doc/library/email.contentmanager.rst
+++ b/Doc/library/email.contentmanager.rst
@@ -157,7 +157,13 @@ Currently the email package provides only one concrete content manager,
:exc:`ValueError`.
* For ``str`` objects, if *cte* is not set use heuristics to
- determine the most compact encoding.
+ determine the most compact encoding. Prior to encoding,
+ :meth:`str.splitlines` is used to normalize all line boundaries,
+ ensuring that each line of the payload is terminated by the
+ current policy's :data:`~email.policy.Policy.linesep` property
+ (even if the original string did not end with one).
+ * For ``bytes`` objects, *cte* is taken to be base64 if not set,
+ and the aforementioned newline translation is not performed.
* For :class:`~email.message.EmailMessage`, per :rfc:`2046`, raise
an error if a *cte* of ``quoted-printable`` or ``base64`` is
requested for *subtype* ``rfc822``, and for any *cte* other than
1
0
[3.13] gh-121542: Document trailing newline behavior in `set_content()` (GH-121543) (#128995)
by Eclips4 Jan. 18, 2025
by Eclips4 Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/b7ddcc3efb4e3610471880e1e904f42f39…
commit: b7ddcc3efb4e3610471880e1e904f42f39bbb2f4
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: Eclips4 <kirill.bast9(a)mail.ru>
date: 2025-01-18T18:40:30Z
summary:
[3.13] gh-121542: Document trailing newline behavior in `set_content()` (GH-121543) (#128995)
gh-121542: Document trailing newline behavior in `set_content()` (GH-121543)
(cherry picked from commit fba475ae6f932d0aaee6832b4102b2d4c50df70f)
Co-authored-by: Peter Bierma <zintensitydev(a)gmail.com>
Co-authored-by: Yizheng Meng <dev(a)rapidcow.org>
files:
M Doc/library/email.contentmanager.rst
diff --git a/Doc/library/email.contentmanager.rst b/Doc/library/email.contentmanager.rst
index a86e227429b06d..b33fe82a6e4c9f 100644
--- a/Doc/library/email.contentmanager.rst
+++ b/Doc/library/email.contentmanager.rst
@@ -157,7 +157,13 @@ Currently the email package provides only one concrete content manager,
:exc:`ValueError`.
* For ``str`` objects, if *cte* is not set use heuristics to
- determine the most compact encoding.
+ determine the most compact encoding. Prior to encoding,
+ :meth:`str.splitlines` is used to normalize all line boundaries,
+ ensuring that each line of the payload is terminated by the
+ current policy's :data:`~email.policy.Policy.linesep` property
+ (even if the original string did not end with one).
+ * For ``bytes`` objects, *cte* is taken to be base64 if not set,
+ and the aforementioned newline translation is not performed.
* For :class:`~email.message.EmailMessage`, per :rfc:`2046`, raise
an error if a *cte* of ``quoted-printable`` or ``base64`` is
requested for *subtype* ``rfc822``, and for any *cte* other than
1
0
Jan. 18, 2025
https://github.com/python/cpython/commit/fba475ae6f932d0aaee6832b4102b2d4c5…
commit: fba475ae6f932d0aaee6832b4102b2d4c50df70f
branch: main
author: Peter Bierma <zintensitydev(a)gmail.com>
committer: Eclips4 <kirill.bast9(a)mail.ru>
date: 2025-01-18T20:34:40+02:00
summary:
gh-121542: Document trailing newline behavior in `set_content()` (#121543)
Co-authored-by: Yizheng Meng <dev(a)rapidcow.org>
files:
M Doc/library/email.contentmanager.rst
diff --git a/Doc/library/email.contentmanager.rst b/Doc/library/email.contentmanager.rst
index a86e227429b06d..b33fe82a6e4c9f 100644
--- a/Doc/library/email.contentmanager.rst
+++ b/Doc/library/email.contentmanager.rst
@@ -157,7 +157,13 @@ Currently the email package provides only one concrete content manager,
:exc:`ValueError`.
* For ``str`` objects, if *cte* is not set use heuristics to
- determine the most compact encoding.
+ determine the most compact encoding. Prior to encoding,
+ :meth:`str.splitlines` is used to normalize all line boundaries,
+ ensuring that each line of the payload is terminated by the
+ current policy's :data:`~email.policy.Policy.linesep` property
+ (even if the original string did not end with one).
+ * For ``bytes`` objects, *cte* is taken to be base64 if not set,
+ and the aforementioned newline translation is not performed.
* For :class:`~email.message.EmailMessage`, per :rfc:`2046`, raise
an error if a *cte* of ``quoted-printable`` or ``base64`` is
requested for *subtype* ``rfc822``, and for any *cte* other than
1
0
Jan. 18, 2025
https://github.com/python/cpython/commit/3de7cc15c2f3186b84c0fb105bc84c27e9…
commit: 3de7cc15c2f3186b84c0fb105bc84c27e9589902
branch: main
author: Peter Bierma <zintensitydev(a)gmail.com>
committer: hugovk <1324225+hugovk(a)users.noreply.github.com>
date: 2025-01-18T19:53:17+02:00
summary:
Pre-commit: Drop specific language version and bump hooks (#128801)
files:
M .pre-commit-config.yaml
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index af6accd89b5bd4..74b56f060342bf 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
- rev: v0.8.2
+ rev: v0.9.1
hooks:
- id: ruff
name: Run Ruff (lint) on Doc/
@@ -29,12 +29,10 @@ repos:
- id: black
name: Run Black on Tools/build/check_warnings.py
files: ^Tools/build/check_warnings.py
- language_version: python3.12
args: [--line-length=79]
- id: black
name: Run Black on Tools/jit/
files: ^Tools/jit/
- language_version: python3.12
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
@@ -51,19 +49,19 @@ repos:
types_or: [c, inc, python, rst]
- repo: https://github.com/python-jsonschema/check-jsonschema
- rev: 0.30.0
+ rev: 0.31.0
hooks:
- id: check-dependabot
- id: check-github-workflows
- id: check-readthedocs
- repo: https://github.com/rhysd/actionlint
- rev: v1.7.4
+ rev: v1.7.6
hooks:
- id: actionlint
- repo: https://github.com/woodruffw/zizmor-pre-commit
- rev: v0.8.0
+ rev: v1.1.1
hooks:
- id: zizmor
1
0
[3.13] gh-127599: Fix _Py_RefcntAdd missing calls to _Py_INCREF_STAT_INC/_Py_INCREF_IMMORTAL_STAT_INC (GH-127717) (#128713)
by Eclips4 Jan. 18, 2025
by Eclips4 Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/fdac3629e9e82f6908a8f2b7f4a88f7a04…
commit: fdac3629e9e82f6908a8f2b7f4a88f7a0488229b
branch: 3.13
author: Ed Nutting <github(a)ednutting.com>
committer: Eclips4 <kirill.bast9(a)mail.ru>
date: 2025-01-18T19:00:46+02:00
summary:
[3.13] gh-127599: Fix _Py_RefcntAdd missing calls to _Py_INCREF_STAT_INC/_Py_INCREF_IMMORTAL_STAT_INC (GH-127717) (#128713)
Previously, `_Py_RefcntAdd` hasn't called
`_Py_INCREF_STAT_INC/_Py_INCREF_IMMORTAL_STAT_INC` which is incorrect.
Now it has been fixed.
(cherry picked from commit ab05beb8cea62636bd86f6f7cf1a82d7efca7162)
files:
A Misc/NEWS.d/next/Core_and_Builtins/2024-12-07-13-06-09.gh-issue-127599.tXCZb_.rst
M Include/cpython/pystats.h
M Include/internal/pycore_object.h
diff --git a/Include/cpython/pystats.h b/Include/cpython/pystats.h
index c4480758f48514..378c2760ec3f55 100644
--- a/Include/cpython/pystats.h
+++ b/Include/cpython/pystats.h
@@ -18,6 +18,12 @@
//
// Define _PY_INTERPRETER macro to increment interpreter_increfs and
// interpreter_decrefs. Otherwise, increment increfs and decrefs.
+//
+// The number of incref operations counted by `incref` and
+// `interpreter_incref` is the number of increment operations, which is
+// not equal to the total of all reference counts. A single increment
+// operation may increase the reference count of an object by more than
+// one. For example, see `_Py_RefcntAdd`.
#ifndef Py_CPYTHON_PYSTATS_H
# error "this header file must not be included directly"
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 43a7e102ab3859..07b5a95ae1a037 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -155,6 +155,10 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
_Py_atomic_add_ssize(&op->ob_ref_shared, (n << _Py_REF_SHARED_SHIFT));
}
#endif
+ // Although the ref count was increased by `n` (which may be greater than 1)
+ // it is only a single increment (i.e. addition) operation, so only 1 refcnt
+ // increment operation is counted.
+ _Py_INCREF_STAT_INC();
}
#define _Py_RefcntAdd(op, n) _Py_RefcntAdd(_PyObject_CAST(op), n)
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-12-07-13-06-09.gh-issue-127599.tXCZb_.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-12-07-13-06-09.gh-issue-127599.tXCZb_.rst
new file mode 100644
index 00000000000000..565ecb82c71926
--- /dev/null
+++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-12-07-13-06-09.gh-issue-127599.tXCZb_.rst
@@ -0,0 +1,2 @@
+Fix statistics for increments of object reference counts (in particular, when
+a reference count was increased by more than 1 in a single operation).
1
0
[3.12] gh-127599: Fix _Py_RefcntAdd missing calls to _Py_INCREF_STAT_INC/_Py_INCREF_IMMORTAL_STAT_INC (GH-127717) (#128712)
by Eclips4 Jan. 18, 2025
by Eclips4 Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/bca489076f1834fc9544a9581aeb2df565…
commit: bca489076f1834fc9544a9581aeb2df565af954c
branch: 3.12
author: Ed Nutting <github(a)ednutting.com>
committer: Eclips4 <kirill.bast9(a)mail.ru>
date: 2025-01-18T19:00:18+02:00
summary:
[3.12] gh-127599: Fix _Py_RefcntAdd missing calls to _Py_INCREF_STAT_INC/_Py_INCREF_IMMORTAL_STAT_INC (GH-127717) (#128712)
Previously, `_Py_RefcntAdd` hasn't called
`_Py_INCREF_STAT_INC/_Py_INCREF_IMMORTAL_STAT_INC` which is incorrect.
Now it has been fixed.
(cherry picked from commit ab05beb8cea62636bd86f6f7cf1a82d7efca7162)
files:
A Misc/NEWS.d/next/Core_and_Builtins/2024-12-07-13-06-09.gh-issue-127599.tXCZb_.rst
M Include/internal/pycore_object.h
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 546f98d96d36ec..de82d9e76f3ca1 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -65,6 +65,11 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
_Py_AddRefTotal(_PyInterpreterState_GET(), n);
#endif
op->ob_refcnt += n;
+
+ // Although the ref count was increased by `n` (which may be greater than 1)
+ // it is only a single increment (i.e. addition) operation, so only 1 refcnt
+ // increment operation is counted.
+ _Py_INCREF_STAT_INC();
}
#define _Py_RefcntAdd(op, n) _Py_RefcntAdd(_PyObject_CAST(op), n)
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-12-07-13-06-09.gh-issue-127599.tXCZb_.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-12-07-13-06-09.gh-issue-127599.tXCZb_.rst
new file mode 100644
index 00000000000000..565ecb82c71926
--- /dev/null
+++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-12-07-13-06-09.gh-issue-127599.tXCZb_.rst
@@ -0,0 +1,2 @@
+Fix statistics for increments of object reference counts (in particular, when
+a reference count was increased by more than 1 in a single operation).
1
0
Jan. 18, 2025
https://github.com/python/cpython/commit/9bc19643ed54b2aa8558e87fd3a04e8bd1…
commit: 9bc19643ed54b2aa8558e87fd3a04e8bd1ea7fb2
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-18T15:13:54Z
summary:
gh-128679: Skip test_tracemalloc_track_race() on debug build (#128988)
There is a race condition between PyMem_SetAllocator() and
PyMem_RawMalloc()/PyMem_RawFree(). While PyMem_SetAllocator() write
is protected by a lock, PyMem_RawMalloc()/PyMem_RawFree() reads are
not protected by a lock. PyMem_RawMalloc()/PyMem_RawFree() can be
called with an old context and the new function pointer.
On a release build, it's not an issue since the context is not used.
On a debug build, the debug hooks use the context and so can crash.
files:
M Lib/test/test_tracemalloc.py
diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py
index da2db28775578a..a848363fcd1de9 100644
--- a/Lib/test/test_tracemalloc.py
+++ b/Lib/test/test_tracemalloc.py
@@ -1103,6 +1103,8 @@ def test_stop_untrack(self):
@unittest.skipIf(_testcapi is None, 'need _testcapi')
@threading_helper.requires_working_threading()
+ # gh-128679: Test crash on a debug build (especially on FreeBSD).
+ @unittest.skipIf(support.Py_DEBUG, 'need release build')
def test_tracemalloc_track_race(self):
# gh-128679: Test fix for tracemalloc.stop() race condition
_testcapi.tracemalloc_track_race()
1
0
https://github.com/python/cpython/commit/81159fce3643d2b5b265c441f307916620…
commit: 81159fce3643d2b5b265c441f3079166203e873e
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-18T15:10:29Z
summary:
gh-59705: Make PYTHREAD_NAME_MAXLEN macro private (#128945)
Rename PYTHREAD_NAME_MAXLEN to _PYTHREAD_NAME_MAXLEN.
files:
M Modules/_threadmodule.c
M PC/pyconfig.h.in
M configure
M configure.ac
M pyconfig.h.in
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 586ed368024fb1..dbc574f7816b85 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -2450,12 +2450,12 @@ _thread_set_name_impl(PyObject *module, PyObject *name_obj)
return NULL;
}
-#ifdef PYTHREAD_NAME_MAXLEN
- // Truncate to PYTHREAD_NAME_MAXLEN bytes + the NUL byte if needed
- if (PyBytes_GET_SIZE(name_encoded) > PYTHREAD_NAME_MAXLEN) {
+#ifdef _PYTHREAD_NAME_MAXLEN
+ // Truncate to _PYTHREAD_NAME_MAXLEN bytes + the NUL byte if needed
+ if (PyBytes_GET_SIZE(name_encoded) > _PYTHREAD_NAME_MAXLEN) {
PyObject *truncated;
truncated = PyBytes_FromStringAndSize(PyBytes_AS_STRING(name_encoded),
- PYTHREAD_NAME_MAXLEN);
+ _PYTHREAD_NAME_MAXLEN);
if (truncated == NULL) {
Py_DECREF(name_encoded);
return NULL;
@@ -2490,14 +2490,14 @@ _thread_set_name_impl(PyObject *module, PyObject *name_obj)
return NULL;
}
- if (len > PYTHREAD_NAME_MAXLEN) {
+ if (len > _PYTHREAD_NAME_MAXLEN) {
// Truncate the name
- Py_UCS4 ch = name[PYTHREAD_NAME_MAXLEN-1];
+ Py_UCS4 ch = name[_PYTHREAD_NAME_MAXLEN-1];
if (Py_UNICODE_IS_HIGH_SURROGATE(ch)) {
- name[PYTHREAD_NAME_MAXLEN-1] = 0;
+ name[_PYTHREAD_NAME_MAXLEN-1] = 0;
}
else {
- name[PYTHREAD_NAME_MAXLEN] = 0;
+ name[_PYTHREAD_NAME_MAXLEN] = 0;
}
}
@@ -2645,9 +2645,9 @@ thread_module_exec(PyObject *module)
llist_init(&state->shutdown_handles);
-#ifdef PYTHREAD_NAME_MAXLEN
+#ifdef _PYTHREAD_NAME_MAXLEN
if (PyModule_AddIntConstant(module, "_NAME_MAXLEN",
- PYTHREAD_NAME_MAXLEN) < 0) {
+ _PYTHREAD_NAME_MAXLEN) < 0) {
return -1;
}
#endif
diff --git a/PC/pyconfig.h.in b/PC/pyconfig.h.in
index 837461d0e884bc..f4f57c5d270028 100644
--- a/PC/pyconfig.h.in
+++ b/PC/pyconfig.h.in
@@ -753,8 +753,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
/* Define if libssl has X509_VERIFY_PARAM_set1_host and related function */
#define HAVE_X509_VERIFY_PARAM_SET1_HOST 1
-// Truncate the thread name to 64 characters. The OS limit is 32766 wide
-// characters, but long names aren't of practical use.
-#define PYTHREAD_NAME_MAXLEN 32766
+// Truncate the thread name to 32766 characters.
+#define _PYTHREAD_NAME_MAXLEN 32766
#endif /* !Py_CONFIG_H */
diff --git a/configure b/configure
index 70581e11b60682..ae1b649630171f 100755
--- a/configure
+++ b/configure
@@ -814,7 +814,7 @@ MODULE_TIME_TRUE
MODULE__IO_FALSE
MODULE__IO_TRUE
MODULE_BUILDTYPE
-PYTHREAD_NAME_MAXLEN
+_PYTHREAD_NAME_MAXLEN
TEST_MODULES
OPENSSL_LDFLAGS
OPENSSL_LIBS
@@ -30403,17 +30403,17 @@ CPPFLAGS=$save_CPPFLAGS
# gh-59705: Maximum length in bytes of a thread name
case "$ac_sys_system" in
- Linux*) PYTHREAD_NAME_MAXLEN=15;; # Linux and Android
- SunOS*) PYTHREAD_NAME_MAXLEN=31;;
- NetBSD*) PYTHREAD_NAME_MAXLEN=31;;
- Darwin) PYTHREAD_NAME_MAXLEN=63;;
- iOS) PYTHREAD_NAME_MAXLEN=63;;
- FreeBSD*) PYTHREAD_NAME_MAXLEN=98;;
- *) PYTHREAD_NAME_MAXLEN=;;
+ Linux*) _PYTHREAD_NAME_MAXLEN=15;; # Linux and Android
+ SunOS*) _PYTHREAD_NAME_MAXLEN=31;;
+ NetBSD*) _PYTHREAD_NAME_MAXLEN=31;;
+ Darwin) _PYTHREAD_NAME_MAXLEN=63;;
+ iOS) _PYTHREAD_NAME_MAXLEN=63;;
+ FreeBSD*) _PYTHREAD_NAME_MAXLEN=98;;
+ *) _PYTHREAD_NAME_MAXLEN=;;
esac
-if test -n "$PYTHREAD_NAME_MAXLEN"; then
+if test -n "$_PYTHREAD_NAME_MAXLEN"; then
-printf "%s\n" "#define PYTHREAD_NAME_MAXLEN $PYTHREAD_NAME_MAXLEN" >>confdefs.h
+printf "%s\n" "#define _PYTHREAD_NAME_MAXLEN $_PYTHREAD_NAME_MAXLEN" >>confdefs.h
fi
diff --git a/configure.ac b/configure.ac
index d7c3920d049d67..cc499dfbc502f1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7539,19 +7539,19 @@ _RESTORE_VAR([CPPFLAGS])
# gh-59705: Maximum length in bytes of a thread name
case "$ac_sys_system" in
- Linux*) PYTHREAD_NAME_MAXLEN=15;; # Linux and Android
- SunOS*) PYTHREAD_NAME_MAXLEN=31;;
- NetBSD*) PYTHREAD_NAME_MAXLEN=31;;
- Darwin) PYTHREAD_NAME_MAXLEN=63;;
- iOS) PYTHREAD_NAME_MAXLEN=63;;
- FreeBSD*) PYTHREAD_NAME_MAXLEN=98;;
- *) PYTHREAD_NAME_MAXLEN=;;
+ Linux*) _PYTHREAD_NAME_MAXLEN=15;; # Linux and Android
+ SunOS*) _PYTHREAD_NAME_MAXLEN=31;;
+ NetBSD*) _PYTHREAD_NAME_MAXLEN=31;;
+ Darwin) _PYTHREAD_NAME_MAXLEN=63;;
+ iOS) _PYTHREAD_NAME_MAXLEN=63;;
+ FreeBSD*) _PYTHREAD_NAME_MAXLEN=98;;
+ *) _PYTHREAD_NAME_MAXLEN=;;
esac
-if test -n "$PYTHREAD_NAME_MAXLEN"; then
- AC_DEFINE_UNQUOTED([PYTHREAD_NAME_MAXLEN], [$PYTHREAD_NAME_MAXLEN],
+if test -n "$_PYTHREAD_NAME_MAXLEN"; then
+ AC_DEFINE_UNQUOTED([_PYTHREAD_NAME_MAXLEN], [$_PYTHREAD_NAME_MAXLEN],
[Maximum length in bytes of a thread name])
fi
-AC_SUBST([PYTHREAD_NAME_MAXLEN])
+AC_SUBST([_PYTHREAD_NAME_MAXLEN])
# stdlib
diff --git a/pyconfig.h.in b/pyconfig.h.in
index aaf52168c3d39d..30e55158bad4d6 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -1662,9 +1662,6 @@
/* Define as the preferred size in bits of long digits */
#undef PYLONG_BITS_IN_DIGIT
-/* Maximum length in bytes of a thread name */
-#undef PYTHREAD_NAME_MAXLEN
-
/* enabled builtin hash modules */
#undef PY_BUILTIN_HASHLIB_HASHES
@@ -1980,6 +1977,9 @@
/* framework name */
#undef _PYTHONFRAMEWORK
+/* Maximum length in bytes of a thread name */
+#undef _PYTHREAD_NAME_MAXLEN
+
/* Define to force use of thread-safe errno, h_errno, and other functions */
#undef _REENTRANT
1
0
Jan. 18, 2025
https://github.com/python/cpython/commit/430ccbc009aa7a2da92b85d7aeadd39e16…
commit: 430ccbc009aa7a2da92b85d7aeadd39e1666e875
branch: 3.13
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-18T14:49:55Z
summary:
[3.13] gh-111495: Add more tests on PyEval C APIs (#122789) (#128987)
* gh-111495: Add more tests on PyEval C APIs (#122789)
* Add Lib/test/test_capi/test_eval.py
* Add Modules/_testlimitedcapi/eval.c
(cherry picked from commit bf8b3746398ea756c97e3cf263d63ca3ce3a544e)
* gh-111495: Fix refleaks in test_capi.test_eval tests (#122851)
(cherry picked from commit b4a316087c32d83e375087fd35fc511bc430ee8b)
files:
A Lib/test/test_capi/test_eval.py
A Modules/_testlimitedcapi/eval.c
M Lib/test/test_capi/test_misc.py
M Modules/Setup.stdlib.in
M Modules/_testcapimodule.c
M Modules/_testlimitedcapi.c
M Modules/_testlimitedcapi/parts.h
M PCbuild/_testlimitedcapi.vcxproj
M PCbuild/_testlimitedcapi.vcxproj.filters
diff --git a/Lib/test/test_capi/test_eval.py b/Lib/test/test_capi/test_eval.py
new file mode 100644
index 00000000000000..20ef2695ef3e27
--- /dev/null
+++ b/Lib/test/test_capi/test_eval.py
@@ -0,0 +1,103 @@
+import sys
+import unittest
+from test.support import import_helper
+
+_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
+
+
+class Tests(unittest.TestCase):
+ def test_eval_get_func_name(self):
+ eval_get_func_name = _testlimitedcapi.eval_get_func_name
+
+ def function_example(): ...
+
+ class A:
+ def method_example(self): ...
+
+ self.assertEqual(eval_get_func_name(function_example),
+ "function_example")
+ self.assertEqual(eval_get_func_name(A.method_example),
+ "method_example")
+ self.assertEqual(eval_get_func_name(A().method_example),
+ "method_example")
+ self.assertEqual(eval_get_func_name(sum), "sum") # c function
+ self.assertEqual(eval_get_func_name(A), "type")
+
+ def test_eval_get_func_desc(self):
+ eval_get_func_desc = _testlimitedcapi.eval_get_func_desc
+
+ def function_example(): ...
+
+ class A:
+ def method_example(self): ...
+
+ self.assertEqual(eval_get_func_desc(function_example),
+ "()")
+ self.assertEqual(eval_get_func_desc(A.method_example),
+ "()")
+ self.assertEqual(eval_get_func_desc(A().method_example),
+ "()")
+ self.assertEqual(eval_get_func_desc(sum), "()") # c function
+ self.assertEqual(eval_get_func_desc(A), " object")
+
+ def test_eval_getlocals(self):
+ # Test PyEval_GetLocals()
+ x = 1
+ self.assertEqual(_testlimitedcapi.eval_getlocals(),
+ {'self': self,
+ 'x': 1})
+
+ y = 2
+ self.assertEqual(_testlimitedcapi.eval_getlocals(),
+ {'self': self,
+ 'x': 1,
+ 'y': 2})
+
+ def test_eval_getglobals(self):
+ # Test PyEval_GetGlobals()
+ self.assertEqual(_testlimitedcapi.eval_getglobals(),
+ globals())
+
+ def test_eval_getbuiltins(self):
+ # Test PyEval_GetBuiltins()
+ self.assertEqual(_testlimitedcapi.eval_getbuiltins(),
+ globals()['__builtins__'])
+
+ def test_eval_getframe(self):
+ # Test PyEval_GetFrame()
+ self.assertEqual(_testlimitedcapi.eval_getframe(),
+ sys._getframe())
+
+ def test_eval_getframe_builtins(self):
+ # Test PyEval_GetFrameBuiltins()
+ self.assertEqual(_testlimitedcapi.eval_getframe_builtins(),
+ sys._getframe().f_builtins)
+
+ def test_eval_getframe_globals(self):
+ # Test PyEval_GetFrameGlobals()
+ self.assertEqual(_testlimitedcapi.eval_getframe_globals(),
+ sys._getframe().f_globals)
+
+ def test_eval_getframe_locals(self):
+ # Test PyEval_GetFrameLocals()
+ self.assertEqual(_testlimitedcapi.eval_getframe_locals(),
+ sys._getframe().f_locals)
+
+ def test_eval_get_recursion_limit(self):
+ # Test Py_GetRecursionLimit()
+ self.assertEqual(_testlimitedcapi.eval_get_recursion_limit(),
+ sys.getrecursionlimit())
+
+ def test_eval_set_recursion_limit(self):
+ # Test Py_SetRecursionLimit()
+ old_limit = sys.getrecursionlimit()
+ try:
+ limit = old_limit + 123
+ _testlimitedcapi.eval_set_recursion_limit(limit)
+ self.assertEqual(sys.getrecursionlimit(), limit)
+ finally:
+ sys.setrecursionlimit(old_limit)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py
index 080b3e65332af4..ec37942bdb2825 100644
--- a/Lib/test/test_capi/test_misc.py
+++ b/Lib/test/test_capi/test_misc.py
@@ -892,36 +892,6 @@ def __init__(self):
_testcapi.clear_managed_dict(c)
self.assertEqual(c.__dict__, {})
- def test_eval_get_func_name(self):
- def function_example(): ...
-
- class A:
- def method_example(self): ...
-
- self.assertEqual(_testcapi.eval_get_func_name(function_example),
- "function_example")
- self.assertEqual(_testcapi.eval_get_func_name(A.method_example),
- "method_example")
- self.assertEqual(_testcapi.eval_get_func_name(A().method_example),
- "method_example")
- self.assertEqual(_testcapi.eval_get_func_name(sum), "sum") # c function
- self.assertEqual(_testcapi.eval_get_func_name(A), "type")
-
- def test_eval_get_func_desc(self):
- def function_example(): ...
-
- class A:
- def method_example(self): ...
-
- self.assertEqual(_testcapi.eval_get_func_desc(function_example),
- "()")
- self.assertEqual(_testcapi.eval_get_func_desc(A.method_example),
- "()")
- self.assertEqual(_testcapi.eval_get_func_desc(A().method_example),
- "()")
- self.assertEqual(_testcapi.eval_get_func_desc(sum), "()") # c function
- self.assertEqual(_testcapi.eval_get_func_desc(A), " object")
-
def test_function_get_code(self):
import types
@@ -1180,19 +1150,6 @@ def genf(): yield
gen = genf()
self.assertEqual(_testcapi.gen_get_code(gen), gen.gi_code)
- def test_pyeval_getlocals(self):
- # Test PyEval_GetLocals()
- x = 1
- self.assertEqual(_testcapi.pyeval_getlocals(),
- {'self': self,
- 'x': 1})
-
- y = 2
- self.assertEqual(_testcapi.pyeval_getlocals(),
- {'self': self,
- 'x': 1,
- 'y': 2})
-
@requires_limited_api
class TestHeapTypeRelative(unittest.TestCase):
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in
index 89a8e5a34de65a..0dc7cf4ea0957d 100644
--- a/Modules/Setup.stdlib.in
+++ b/Modules/Setup.stdlib.in
@@ -164,7 +164,7 @@
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c
@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/run.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/hash.c _testcapi/time.c _testcapi/bytes.c _testcapi/object.c _testcapi/monitoring.c
-@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/import.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/tuple.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c
+@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/eval.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/import.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/tuple.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
@MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 1feaaa78a75bfd..9f1a8faae7e8ed 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2646,18 +2646,6 @@ test_frame_getvarstring(PyObject *self, PyObject *args)
}
-static PyObject *
-eval_get_func_name(PyObject *self, PyObject *func)
-{
- return PyUnicode_FromString(PyEval_GetFuncName(func));
-}
-
-static PyObject *
-eval_get_func_desc(PyObject *self, PyObject *func)
-{
- return PyUnicode_FromString(PyEval_GetFuncDesc(func));
-}
-
static PyObject *
gen_get_code(PyObject *self, PyObject *gen)
{
@@ -3286,12 +3274,6 @@ test_critical_sections(PyObject *module, PyObject *Py_UNUSED(args))
Py_RETURN_NONE;
}
-static PyObject *
-pyeval_getlocals(PyObject *module, PyObject *Py_UNUSED(args))
-{
- return Py_XNewRef(PyEval_GetLocals());
-}
-
struct atexit_data {
int called;
PyThreadState *tstate;
@@ -3462,8 +3444,6 @@ static PyMethodDef TestMethods[] = {
{"frame_new", frame_new, METH_VARARGS, NULL},
{"frame_getvar", test_frame_getvar, METH_VARARGS, NULL},
{"frame_getvarstring", test_frame_getvarstring, METH_VARARGS, NULL},
- {"eval_get_func_name", eval_get_func_name, METH_O, NULL},
- {"eval_get_func_desc", eval_get_func_desc, METH_O, NULL},
{"gen_get_code", gen_get_code, METH_O, NULL},
{"get_feature_macros", get_feature_macros, METH_NOARGS, NULL},
{"test_code_api", test_code_api, METH_NOARGS, NULL},
@@ -3483,7 +3463,6 @@ static PyMethodDef TestMethods[] = {
{"test_weakref_capi", test_weakref_capi, METH_NOARGS},
{"function_set_warning", function_set_warning, METH_NOARGS},
{"test_critical_sections", test_critical_sections, METH_NOARGS},
- {"pyeval_getlocals", pyeval_getlocals, METH_NOARGS},
{"test_atexit", test_atexit, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
diff --git a/Modules/_testlimitedcapi.c b/Modules/_testlimitedcapi.c
index 2eeb1cf135f2cb..b8edf8078a741d 100644
--- a/Modules/_testlimitedcapi.c
+++ b/Modules/_testlimitedcapi.c
@@ -44,6 +44,9 @@ PyInit__testlimitedcapi(void)
if (_PyTestLimitedCAPI_Init_Dict(mod) < 0) {
return NULL;
}
+ if (_PyTestLimitedCAPI_Init_Eval(mod) < 0) {
+ return NULL;
+ }
if (_PyTestLimitedCAPI_Init_Float(mod) < 0) {
return NULL;
}
diff --git a/Modules/_testlimitedcapi/eval.c b/Modules/_testlimitedcapi/eval.c
new file mode 100644
index 00000000000000..28f5746dfb1783
--- /dev/null
+++ b/Modules/_testlimitedcapi/eval.c
@@ -0,0 +1,95 @@
+#include "parts.h"
+#include "util.h"
+
+static PyObject *
+eval_get_func_name(PyObject *self, PyObject *func)
+{
+ return PyUnicode_FromString(PyEval_GetFuncName(func));
+}
+
+static PyObject *
+eval_get_func_desc(PyObject *self, PyObject *func)
+{
+ return PyUnicode_FromString(PyEval_GetFuncDesc(func));
+}
+
+static PyObject *
+eval_getlocals(PyObject *module, PyObject *Py_UNUSED(args))
+{
+ return Py_XNewRef(PyEval_GetLocals());
+}
+
+static PyObject *
+eval_getglobals(PyObject *module, PyObject *Py_UNUSED(args))
+{
+ return Py_XNewRef(PyEval_GetGlobals());
+}
+
+static PyObject *
+eval_getbuiltins(PyObject *module, PyObject *Py_UNUSED(args))
+{
+ return Py_XNewRef(PyEval_GetBuiltins());
+}
+
+static PyObject *
+eval_getframe(PyObject *module, PyObject *Py_UNUSED(args))
+{
+ return Py_XNewRef(PyEval_GetFrame());
+}
+
+static PyObject *
+eval_getframe_builtins(PyObject *module, PyObject *Py_UNUSED(args))
+{
+ return PyEval_GetFrameBuiltins();
+}
+
+static PyObject *
+eval_getframe_globals(PyObject *module, PyObject *Py_UNUSED(args))
+{
+ return PyEval_GetFrameGlobals();
+}
+
+static PyObject *
+eval_getframe_locals(PyObject *module, PyObject *Py_UNUSED(args))
+{
+ return PyEval_GetFrameLocals();
+}
+
+static PyObject *
+eval_get_recursion_limit(PyObject *module, PyObject *Py_UNUSED(args))
+{
+ int limit = Py_GetRecursionLimit();
+ return PyLong_FromLong(limit);
+}
+
+static PyObject *
+eval_set_recursion_limit(PyObject *module, PyObject *args)
+{
+ int limit;
+ if (!PyArg_ParseTuple(args, "i", &limit)) {
+ return NULL;
+ }
+ Py_SetRecursionLimit(limit);
+ Py_RETURN_NONE;
+}
+
+static PyMethodDef test_methods[] = {
+ {"eval_get_func_name", eval_get_func_name, METH_O, NULL},
+ {"eval_get_func_desc", eval_get_func_desc, METH_O, NULL},
+ {"eval_getlocals", eval_getlocals, METH_NOARGS},
+ {"eval_getglobals", eval_getglobals, METH_NOARGS},
+ {"eval_getbuiltins", eval_getbuiltins, METH_NOARGS},
+ {"eval_getframe", eval_getframe, METH_NOARGS},
+ {"eval_getframe_builtins", eval_getframe_builtins, METH_NOARGS},
+ {"eval_getframe_globals", eval_getframe_globals, METH_NOARGS},
+ {"eval_getframe_locals", eval_getframe_locals, METH_NOARGS},
+ {"eval_get_recursion_limit", eval_get_recursion_limit, METH_NOARGS},
+ {"eval_set_recursion_limit", eval_set_recursion_limit, METH_VARARGS},
+ {NULL},
+};
+
+int
+_PyTestLimitedCAPI_Init_Eval(PyObject *m)
+{
+ return PyModule_AddFunctions(m, test_methods);
+}
diff --git a/Modules/_testlimitedcapi/parts.h b/Modules/_testlimitedcapi/parts.h
index ac938a13d5984e..1d4cbcdfa94320 100644
--- a/Modules/_testlimitedcapi/parts.h
+++ b/Modules/_testlimitedcapi/parts.h
@@ -27,6 +27,7 @@ int _PyTestLimitedCAPI_Init_ByteArray(PyObject *module);
int _PyTestLimitedCAPI_Init_Bytes(PyObject *module);
int _PyTestLimitedCAPI_Init_Complex(PyObject *module);
int _PyTestLimitedCAPI_Init_Dict(PyObject *module);
+int _PyTestLimitedCAPI_Init_Eval(PyObject *module);
int _PyTestLimitedCAPI_Init_Float(PyObject *module);
int _PyTestLimitedCAPI_Init_HeaptypeRelative(PyObject *module);
int _PyTestLimitedCAPI_Init_Import(PyObject *module);
diff --git a/PCbuild/_testlimitedcapi.vcxproj b/PCbuild/_testlimitedcapi.vcxproj
index afadfb9d060bf2..9cff1bb481ff40 100644
--- a/PCbuild/_testlimitedcapi.vcxproj
+++ b/PCbuild/_testlimitedcapi.vcxproj
@@ -99,6 +99,7 @@
<ClCompile Include="..\Modules\_testlimitedcapi\bytes.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\complex.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\dict.c" />
+ <ClCompile Include="..\Modules\_testlimitedcapi\eval.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\import.c" />
diff --git a/PCbuild/_testlimitedcapi.vcxproj.filters b/PCbuild/_testlimitedcapi.vcxproj.filters
index 89559a27d647fc..78828c28d98f22 100644
--- a/PCbuild/_testlimitedcapi.vcxproj.filters
+++ b/PCbuild/_testlimitedcapi.vcxproj.filters
@@ -14,6 +14,7 @@
<ClCompile Include="..\Modules\_testlimitedcapi\bytes.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\complex.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\dict.c" />
+ <ClCompile Include="..\Modules\_testlimitedcapi\eval.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\import.c" />
1
0
[3.12] gh-125997: suggest efficient alternatives for `time.sleep(0)` (GH-128752) (#128985)
by picnixz Jan. 18, 2025
by picnixz Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/3d9b14c19bb004619680bd972f641486e1…
commit: 3d9b14c19bb004619680bd972f641486e1fec1b7
branch: 3.12
author: Bénédikt Tran <10796600+picnixz(a)users.noreply.github.com>
committer: picnixz <10796600+picnixz(a)users.noreply.github.com>
date: 2025-01-18T11:13:03Z
summary:
[3.12] gh-125997: suggest efficient alternatives for `time.sleep(0)` (GH-128752) (#128985)
files:
M Doc/library/os.rst
M Doc/library/time.rst
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index 18e58249a81b08..0c53e4bdc1c694 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -5058,6 +5058,8 @@ information, consult your Unix manpages.
The following scheduling policies are exposed if they are supported by the
operating system.
+.. _os-scheduling-policy:
+
.. data:: SCHED_OTHER
The default scheduling policy.
@@ -5149,7 +5151,7 @@ operating system.
.. function:: sched_yield()
- Voluntarily relinquish the CPU.
+ Voluntarily relinquish the CPU. See :manpage:`sched_yield(2)` for details.
.. function:: sched_setaffinity(pid, mask, /)
diff --git a/Doc/library/time.rst b/Doc/library/time.rst
index db53296e2a5698..ebc1ef1abac23b 100644
--- a/Doc/library/time.rst
+++ b/Doc/library/time.rst
@@ -367,6 +367,8 @@ Functions
The suspension time may be longer than requested by an arbitrary amount,
because of the scheduling of other activity in the system.
+ .. rubric:: Windows implementation
+
On Windows, if *secs* is zero, the thread relinquishes the remainder of its
time slice to any other thread that is ready to run. If there are no other
threads ready to run, the function returns immediately, and the thread
@@ -375,12 +377,19 @@ Functions
<https://learn.microsoft.com/windows-hardware/drivers/kernel/high-resolution…>`_
which provides resolution of 100 nanoseconds. If *secs* is zero, ``Sleep(0)`` is used.
- Unix implementation:
+ .. rubric:: Unix implementation
* Use ``clock_nanosleep()`` if available (resolution: 1 nanosecond);
* Or use ``nanosleep()`` if available (resolution: 1 nanosecond);
* Or use ``select()`` (resolution: 1 microsecond).
+ .. note::
+
+ To emulate a "no-op", use :keyword:`pass` instead of ``time.sleep(0)``.
+
+ To voluntarily relinquish the CPU, specify a real-time :ref:`scheduling
+ policy <os-scheduling-policy>` and use :func:`os.sched_yield` instead.
+
.. versionchanged:: 3.5
The function now sleeps at least *secs* even if the sleep is interrupted
by a signal, except if the signal handler raises an exception (see
1
0
[3.13] gh-125997: suggest efficient alternatives for `time.sleep(0)` (GH-128752) (#128984)
by picnixz Jan. 18, 2025
by picnixz Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/fff334e5384960426586329b5fe3f28745…
commit: fff334e5384960426586329b5fe3f28745c871f4
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: picnixz <10796600+picnixz(a)users.noreply.github.com>
date: 2025-01-18T11:08:42Z
summary:
[3.13] gh-125997: suggest efficient alternatives for `time.sleep(0)` (GH-128752) (#128984)
gh-125997: suggest efficient alternatives for `time.sleep(0)` (GH-128752)
(cherry picked from commit f4afaa6f1190fbbea3e27c590096951d8ffdfb71)
Co-authored-by: Bénédikt Tran <10796600+picnixz(a)users.noreply.github.com>
files:
M Doc/library/os.rst
M Doc/library/time.rst
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index 454e6d769fa555..bc9efd8e6ca450 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -5358,6 +5358,8 @@ information, consult your Unix manpages.
The following scheduling policies are exposed if they are supported by the
operating system.
+.. _os-scheduling-policy:
+
.. data:: SCHED_OTHER
The default scheduling policy.
@@ -5449,7 +5451,7 @@ operating system.
.. function:: sched_yield()
- Voluntarily relinquish the CPU.
+ Voluntarily relinquish the CPU. See :manpage:`sched_yield(2)` for details.
.. function:: sched_setaffinity(pid, mask, /)
diff --git a/Doc/library/time.rst b/Doc/library/time.rst
index 6265c2214eaa0d..804e2679027bd4 100644
--- a/Doc/library/time.rst
+++ b/Doc/library/time.rst
@@ -385,6 +385,8 @@ Functions
The suspension time may be longer than requested by an arbitrary amount,
because of the scheduling of other activity in the system.
+ .. rubric:: Windows implementation
+
On Windows, if *secs* is zero, the thread relinquishes the remainder of its
time slice to any other thread that is ready to run. If there are no other
threads ready to run, the function returns immediately, and the thread
@@ -393,12 +395,19 @@ Functions
<https://learn.microsoft.com/windows-hardware/drivers/kernel/high-resolution…>`_
which provides resolution of 100 nanoseconds. If *secs* is zero, ``Sleep(0)`` is used.
- Unix implementation:
+ .. rubric:: Unix implementation
* Use ``clock_nanosleep()`` if available (resolution: 1 nanosecond);
* Or use ``nanosleep()`` if available (resolution: 1 nanosecond);
* Or use ``select()`` (resolution: 1 microsecond).
+ .. note::
+
+ To emulate a "no-op", use :keyword:`pass` instead of ``time.sleep(0)``.
+
+ To voluntarily relinquish the CPU, specify a real-time :ref:`scheduling
+ policy <os-scheduling-policy>` and use :func:`os.sched_yield` instead.
+
.. audit-event:: time.sleep secs
.. versionchanged:: 3.5
1
0
Jan. 18, 2025
https://github.com/python/cpython/commit/f4afaa6f1190fbbea3e27c590096951d8f…
commit: f4afaa6f1190fbbea3e27c590096951d8ffdfb71
branch: main
author: Bénédikt Tran <10796600+picnixz(a)users.noreply.github.com>
committer: picnixz <10796600+picnixz(a)users.noreply.github.com>
date: 2025-01-18T12:02:43+01:00
summary:
gh-125997: suggest efficient alternatives for `time.sleep(0)` (#128752)
files:
M Doc/library/os.rst
M Doc/library/time.rst
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index 6fec27bc6f68a2..2445b008eb5a75 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -5411,6 +5411,8 @@ information, consult your Unix manpages.
The following scheduling policies are exposed if they are supported by the
operating system.
+.. _os-scheduling-policy:
+
.. data:: SCHED_OTHER
The default scheduling policy.
@@ -5514,7 +5516,7 @@ operating system.
.. function:: sched_yield()
- Voluntarily relinquish the CPU.
+ Voluntarily relinquish the CPU. See :manpage:`sched_yield(2)` for details.
.. function:: sched_setaffinity(pid, mask, /)
diff --git a/Doc/library/time.rst b/Doc/library/time.rst
index 6265c2214eaa0d..804e2679027bd4 100644
--- a/Doc/library/time.rst
+++ b/Doc/library/time.rst
@@ -385,6 +385,8 @@ Functions
The suspension time may be longer than requested by an arbitrary amount,
because of the scheduling of other activity in the system.
+ .. rubric:: Windows implementation
+
On Windows, if *secs* is zero, the thread relinquishes the remainder of its
time slice to any other thread that is ready to run. If there are no other
threads ready to run, the function returns immediately, and the thread
@@ -393,12 +395,19 @@ Functions
<https://learn.microsoft.com/windows-hardware/drivers/kernel/high-resolution…>`_
which provides resolution of 100 nanoseconds. If *secs* is zero, ``Sleep(0)`` is used.
- Unix implementation:
+ .. rubric:: Unix implementation
* Use ``clock_nanosleep()`` if available (resolution: 1 nanosecond);
* Or use ``nanosleep()`` if available (resolution: 1 nanosecond);
* Or use ``select()`` (resolution: 1 microsecond).
+ .. note::
+
+ To emulate a "no-op", use :keyword:`pass` instead of ``time.sleep(0)``.
+
+ To voluntarily relinquish the CPU, specify a real-time :ref:`scheduling
+ policy <os-scheduling-policy>` and use :func:`os.sched_yield` instead.
+
.. audit-event:: time.sleep secs
.. versionchanged:: 3.5
1
0
[3.12] gh-127637: add tests for `dis` command-line interface (#127759) (#127780)
by picnixz Jan. 18, 2025
by picnixz Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/fbbef609d18fffd87ea1c16f3f6cd0bb08…
commit: fbbef609d18fffd87ea1c16f3f6cd0bb08803489
branch: 3.12
author: Bénédikt Tran <10796600+picnixz(a)users.noreply.github.com>
committer: picnixz <10796600+picnixz(a)users.noreply.github.com>
date: 2025-01-18T12:01:56+01:00
summary:
[3.12] gh-127637: add tests for `dis` command-line interface (#127759) (#127780)
files:
A Misc/NEWS.d/next/Tests/2024-12-09-12-35-44.gh-issue-127637.KLx-9I.rst
M Lib/dis.py
M Lib/test/test_dis.py
diff --git a/Lib/dis.py b/Lib/dis.py
index 320dec03d25b0c..b1069c825289cf 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -790,12 +790,12 @@ def dis(self):
return output.getvalue()
-def main():
+def main(args=None):
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('infile', type=argparse.FileType('rb'), nargs='?', default='-')
- args = parser.parse_args()
+ args = parser.parse_args(args=args)
with args.infile as infile:
source = infile.read()
code = compile(source, args.infile.name, "exec")
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index c90702a408eb33..de7def164187e4 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -3,16 +3,17 @@
import contextlib
import dis
import io
+import opcode
import re
import sys
+import tempfile
import types
import unittest
from test.support import (captured_stdout, requires_debug_ranges,
- requires_specialization, cpython_only)
+ requires_specialization, cpython_only,
+ os_helper)
from test.support.bytecode_helper import BytecodeTestCase
-import opcode
-
def get_tb():
def _error():
@@ -2069,5 +2070,18 @@ def get_disassembly(self, tb):
return output.getvalue()
+class TestDisCLI(unittest.TestCase):
+
+ def setUp(self):
+ self.filename = tempfile.mktemp()
+ self.addCleanup(os_helper.unlink, self.filename)
+
+ def test_invocation(self):
+ with self.assertRaises(SystemExit):
+ # suppress argparse error message
+ with contextlib.redirect_stderr(io.StringIO()):
+ dis.main(args=['--unknown', self.filename])
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/Misc/NEWS.d/next/Tests/2024-12-09-12-35-44.gh-issue-127637.KLx-9I.rst b/Misc/NEWS.d/next/Tests/2024-12-09-12-35-44.gh-issue-127637.KLx-9I.rst
new file mode 100644
index 00000000000000..ac5d9827b07199
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2024-12-09-12-35-44.gh-issue-127637.KLx-9I.rst
@@ -0,0 +1 @@
+Add tests for the :mod:`dis` command-line interface. Patch by Bénédikt Tran.
1
0
https://github.com/python/cpython/commit/d5e9aa690a190bcfa9b43cd3858e26b7b2…
commit: d5e9aa690a190bcfa9b43cd3858e26b7b2f72d4f
branch: main
author: Bénédikt Tran <10796600+picnixz(a)users.noreply.github.com>
committer: picnixz <10796600+picnixz(a)users.noreply.github.com>
date: 2025-01-18T11:45:18+01:00
summary:
gh-118761: Improve import time for `csv` (#128858)
This reduces the import time of the `csv` module by up to five times,
by importing `re` on demand.
In particular, the `re` module is no more implicitly exposed as `csv.re`.
files:
A Misc/NEWS.d/next/Library/2025-01-15-09-45-43.gh-issue-118761.TvAC8E.rst
M Lib/csv.py
diff --git a/Lib/csv.py b/Lib/csv.py
index cd202659873811..0a627ba7a512fa 100644
--- a/Lib/csv.py
+++ b/Lib/csv.py
@@ -63,7 +63,6 @@ class excel:
written as two quotes
"""
-import re
import types
from _csv import Error, writer, reader, register_dialect, \
unregister_dialect, get_dialect, list_dialects, \
@@ -281,6 +280,7 @@ def _guess_quote_and_delimiter(self, data, delimiters):
If there is no quotechar the delimiter can't be determined
this way.
"""
+ import re
matches = []
for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
diff --git a/Misc/NEWS.d/next/Library/2025-01-15-09-45-43.gh-issue-118761.TvAC8E.rst b/Misc/NEWS.d/next/Library/2025-01-15-09-45-43.gh-issue-118761.TvAC8E.rst
new file mode 100644
index 00000000000000..38d18b7f4ca05e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-15-09-45-43.gh-issue-118761.TvAC8E.rst
@@ -0,0 +1,3 @@
+Reduce the import time of :mod:`csv` by up to five times, by importing
+:mod:`re` on demand. In particular, ``re`` is no more implicitly exposed
+as ``csv.re``. Patch by Bénédikt Tran.
1
0
gh-126349: Add 'fill', 'poly', and 'no_animation' context managers to turtle (#126350)
by erlend-aasland Jan. 18, 2025
by erlend-aasland Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/d3adf02c90a570c5ee5d9b8cefe9b10305…
commit: d3adf02c90a570c5ee5d9b8cefe9b10305cff9e6
branch: main
author: Marie Roald <roald.marie(a)gmail.com>
committer: erlend-aasland <erlend.aasland(a)protonmail.com>
date: 2025-01-18T11:27:22+01:00
summary:
gh-126349: Add 'fill', 'poly', and 'no_animation' context managers to turtle (#126350)
Co-authored-by: Marie Roald <roald.marie(a)gmail.com>
Co-authored-by: Yngve Mardal Moe <yngve.m.moe(a)gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk(a)users.noreply.github.com>
Co-authored-by: Daniel Hollas <danekhollas(a)gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz(a)users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend(a)python.org>
files:
A Misc/NEWS.d/next/Core_and_Builtins/2024-11-03-06-05-16.gh-issue-126349.7YwWsI.rst
M Doc/library/turtle.rst
M Doc/whatsnew/3.14.rst
M Lib/test/test_turtle.py
M Lib/turtle.py
diff --git a/Doc/library/turtle.rst b/Doc/library/turtle.rst
index 548b9d3543fb94..98dfa0f53bc6a5 100644
--- a/Doc/library/turtle.rst
+++ b/Doc/library/turtle.rst
@@ -213,6 +213,31 @@ useful when working with learners for whom typing is not a skill.
use turtle graphics with a learner.
+Automatically begin and end filling
+-----------------------------------
+
+Starting with Python 3.14, you can use the :func:`fill` :term:`context manager`
+instead of :func:`begin_fill` and :func:`end_fill` to automatically begin and
+end fill. Here is an example::
+
+ with fill():
+ for i in range(4):
+ forward(100)
+ right(90)
+
+ forward(200)
+
+The code above is equivalent to::
+
+ begin_fill()
+ for i in range(4):
+ forward(100)
+ right(90)
+ end_fill()
+
+ forward(200)
+
+
Use the ``turtle`` module namespace
-----------------------------------
@@ -351,6 +376,7 @@ Pen control
Filling
| :func:`filling`
+ | :func:`fill`
| :func:`begin_fill`
| :func:`end_fill`
@@ -381,6 +407,7 @@ Using events
| :func:`ondrag`
Special Turtle methods
+ | :func:`poly`
| :func:`begin_poly`
| :func:`end_poly`
| :func:`get_poly`
@@ -403,6 +430,7 @@ Window control
| :func:`setworldcoordinates`
Animation control
+ | :func:`no_animation`
| :func:`delay`
| :func:`tracer`
| :func:`update`
@@ -1275,6 +1303,29 @@ Filling
... else:
... turtle.pensize(3)
+.. function:: fill()
+
+ Fill the shape drawn in the ``with turtle.fill():`` block.
+
+ .. doctest::
+ :skipif: _tkinter is None
+
+ >>> turtle.color("black", "red")
+ >>> with turtle.fill():
+ ... turtle.circle(80)
+
+ Using :func:`!fill` is equivalent to adding the :func:`begin_fill` before the
+ fill-block and :func:`end_fill` after the fill-block:
+
+ .. doctest::
+ :skipif: _tkinter is None
+
+ >>> turtle.color("black", "red")
+ >>> turtle.begin_fill()
+ >>> turtle.circle(80)
+ >>> turtle.end_fill()
+
+ .. versionadded:: next
.. function:: begin_fill()
@@ -1648,6 +1699,23 @@ Using events
Special Turtle methods
----------------------
+
+.. function:: poly()
+
+ Record the vertices of a polygon drawn in the ``with turtle.poly():`` block.
+ The first and last vertices will be connected.
+
+ .. doctest::
+ :skipif: _tkinter is None
+
+ >>> with turtle.poly():
+ ... turtle.forward(100)
+ ... turtle.right(60)
+ ... turtle.forward(100)
+
+ .. versionadded:: next
+
+
.. function:: begin_poly()
Start recording the vertices of a polygon. Current turtle position is first
@@ -1926,6 +1994,23 @@ Window control
Animation control
-----------------
+.. function:: no_animation()
+
+ Temporarily disable turtle animation. The code written inside the
+ ``no_animation`` block will not be animated;
+ once the code block is exited, the drawing will appear.
+
+ .. doctest::
+ :skipif: _tkinter is None
+
+ >>> with screen.no_animation():
+ ... for dist in range(2, 400, 2):
+ ... fd(dist)
+ ... rt(90)
+
+ .. versionadded:: next
+
+
.. function:: delay(delay=None)
:param delay: positive integer
diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst
index 9f7ef101e56478..d6aa6b346417e5 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -660,6 +660,14 @@ tkinter
(Contributed by Zhikang Yan in :gh:`126899`.)
+turtle
+------
+
+* Add context managers for :func:`turtle.fill`, :func:`turtle.poly`
+ and :func:`turtle.no_animation`.
+ (Contributed by Marie Roald and Yngve Mardal Moe in :gh:`126350`.)
+
+
unicodedata
-----------
diff --git a/Lib/test/test_turtle.py b/Lib/test/test_turtle.py
index c75a002a89b4c4..de6508ff8c791d 100644
--- a/Lib/test/test_turtle.py
+++ b/Lib/test/test_turtle.py
@@ -1,9 +1,9 @@
import os
import pickle
import re
+import tempfile
import unittest
import unittest.mock
-import tempfile
from test import support
from test.support import import_helper
from test.support import os_helper
@@ -54,6 +54,21 @@
"""
+def patch_screen():
+ """Patch turtle._Screen for testing without a display.
+
+ We must patch the _Screen class itself instead of the _Screen
+ instance because instantiating it requires a display.
+ """
+ return unittest.mock.patch(
+ "turtle._Screen.__new__",
+ **{
+ "return_value.__class__": turtle._Screen,
+ "return_value.mode.return_value": "standard",
+ },
+ )
+
+
class TurtleConfigTest(unittest.TestCase):
def get_cfg_file(self, cfg_str):
@@ -513,7 +528,7 @@ def test_save_overwrites_if_specified(self) -> None:
turtle.TurtleScreen.save(screen, file_path, overwrite=True)
with open(file_path) as f:
- assert f.read() == "postscript"
+ self.assertEqual(f.read(), "postscript")
def test_save(self) -> None:
screen = unittest.mock.Mock()
@@ -524,7 +539,98 @@ def test_save(self) -> None:
turtle.TurtleScreen.save(screen, file_path)
with open(file_path) as f:
- assert f.read() == "postscript"
+ self.assertEqual(f.read(), "postscript")
+
+ def test_no_animation_sets_tracer_0(self):
+ s = turtle.TurtleScreen(cv=unittest.mock.MagicMock())
+
+ with s.no_animation():
+ self.assertEqual(s.tracer(), 0)
+
+ def test_no_animation_resets_tracer_to_old_value(self):
+ s = turtle.TurtleScreen(cv=unittest.mock.MagicMock())
+
+ for tracer in [0, 1, 5]:
+ s.tracer(tracer)
+ with s.no_animation():
+ pass
+ self.assertEqual(s.tracer(), tracer)
+
+ def test_no_animation_calls_update_at_exit(self):
+ s = turtle.TurtleScreen(cv=unittest.mock.MagicMock())
+ s.update = unittest.mock.MagicMock()
+
+ with s.no_animation():
+ s.update.assert_not_called()
+ s.update.assert_called_once()
+
+
+class TestTurtle(unittest.TestCase):
+ def setUp(self):
+ with patch_screen():
+ self.turtle = turtle.Turtle()
+
+ def test_begin_end_fill(self):
+ self.assertFalse(self.turtle.filling())
+ self.turtle.begin_fill()
+ self.assertTrue(self.turtle.filling())
+ self.turtle.end_fill()
+ self.assertFalse(self.turtle.filling())
+
+ def test_fill(self):
+ # The context manager behaves like begin_fill and end_fill.
+ self.assertFalse(self.turtle.filling())
+ with self.turtle.fill():
+ self.assertTrue(self.turtle.filling())
+ self.assertFalse(self.turtle.filling())
+
+ def test_fill_resets_after_exception(self):
+ # The context manager cleans up correctly after exceptions.
+ try:
+ with self.turtle.fill():
+ self.assertTrue(self.turtle.filling())
+ raise ValueError
+ except ValueError:
+ self.assertFalse(self.turtle.filling())
+
+ def test_fill_context_when_filling(self):
+ # The context manager works even when the turtle is already filling.
+ self.turtle.begin_fill()
+ self.assertTrue(self.turtle.filling())
+ with self.turtle.fill():
+ self.assertTrue(self.turtle.filling())
+ self.assertFalse(self.turtle.filling())
+
+ def test_begin_end_poly(self):
+ self.assertFalse(self.turtle._creatingPoly)
+ self.turtle.begin_poly()
+ self.assertTrue(self.turtle._creatingPoly)
+ self.turtle.end_poly()
+ self.assertFalse(self.turtle._creatingPoly)
+
+ def test_poly(self):
+ # The context manager behaves like begin_poly and end_poly.
+ self.assertFalse(self.turtle._creatingPoly)
+ with self.turtle.poly():
+ self.assertTrue(self.turtle._creatingPoly)
+ self.assertFalse(self.turtle._creatingPoly)
+
+ def test_poly_resets_after_exception(self):
+ # The context manager cleans up correctly after exceptions.
+ try:
+ with self.turtle.poly():
+ self.assertTrue(self.turtle._creatingPoly)
+ raise ValueError
+ except ValueError:
+ self.assertFalse(self.turtle._creatingPoly)
+
+ def test_poly_context_when_creating_poly(self):
+ # The context manager works when the turtle is already creating poly.
+ self.turtle.begin_poly()
+ self.assertTrue(self.turtle._creatingPoly)
+ with self.turtle.poly():
+ self.assertTrue(self.turtle._creatingPoly)
+ self.assertFalse(self.turtle._creatingPoly)
class TestModuleLevel(unittest.TestCase):
diff --git a/Lib/turtle.py b/Lib/turtle.py
index 1320cfd93fd6db..e88981d298ad52 100644
--- a/Lib/turtle.py
+++ b/Lib/turtle.py
@@ -107,6 +107,7 @@
from os.path import isfile, split, join
from pathlib import Path
+from contextlib import contextmanager
from copy import deepcopy
from tkinter import simpledialog
@@ -114,23 +115,24 @@
'RawTurtle', 'Turtle', 'RawPen', 'Pen', 'Shape', 'Vec2D']
_tg_screen_functions = ['addshape', 'bgcolor', 'bgpic', 'bye',
'clearscreen', 'colormode', 'delay', 'exitonclick', 'getcanvas',
- 'getshapes', 'listen', 'mainloop', 'mode', 'numinput',
+ 'getshapes', 'listen', 'mainloop', 'mode', 'no_animation', 'numinput',
'onkey', 'onkeypress', 'onkeyrelease', 'onscreenclick', 'ontimer',
'register_shape', 'resetscreen', 'screensize', 'save', 'setup',
- 'setworldcoordinates', 'textinput', 'title', 'tracer', 'turtles', 'update',
- 'window_height', 'window_width']
+ 'setworldcoordinates', 'textinput', 'title', 'tracer', 'turtles',
+ 'update', 'window_height', 'window_width']
_tg_turtle_functions = ['back', 'backward', 'begin_fill', 'begin_poly', 'bk',
'circle', 'clear', 'clearstamp', 'clearstamps', 'clone', 'color',
'degrees', 'distance', 'dot', 'down', 'end_fill', 'end_poly', 'fd',
- 'fillcolor', 'filling', 'forward', 'get_poly', 'getpen', 'getscreen', 'get_shapepoly',
- 'getturtle', 'goto', 'heading', 'hideturtle', 'home', 'ht', 'isdown',
- 'isvisible', 'left', 'lt', 'onclick', 'ondrag', 'onrelease', 'pd',
- 'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pos', 'position',
- 'pu', 'radians', 'right', 'reset', 'resizemode', 'rt',
- 'seth', 'setheading', 'setpos', 'setposition',
- 'setundobuffer', 'setx', 'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle',
- 'speed', 'st', 'stamp', 'teleport', 'tilt', 'tiltangle', 'towards',
- 'turtlesize', 'undo', 'undobufferentries', 'up', 'width',
+ 'fillcolor', 'fill', 'filling', 'forward', 'get_poly', 'getpen',
+ 'getscreen', 'get_shapepoly', 'getturtle', 'goto', 'heading',
+ 'hideturtle', 'home', 'ht', 'isdown', 'isvisible', 'left', 'lt',
+ 'onclick', 'ondrag', 'onrelease', 'pd', 'pen', 'pencolor', 'pendown',
+ 'pensize', 'penup', 'poly', 'pos', 'position', 'pu', 'radians', 'right',
+ 'reset', 'resizemode', 'rt', 'seth', 'setheading', 'setpos',
+ 'setposition', 'setundobuffer', 'setx', 'sety', 'shape', 'shapesize',
+ 'shapetransform', 'shearfactor', 'showturtle', 'speed', 'st', 'stamp',
+ 'teleport', 'tilt', 'tiltangle', 'towards', 'turtlesize', 'undo',
+ 'undobufferentries', 'up', 'width',
'write', 'xcor', 'ycor']
_tg_utilities = ['write_docstringdict', 'done']
@@ -1275,6 +1277,26 @@ def delay(self, delay=None):
return self._delayvalue
self._delayvalue = int(delay)
+ @contextmanager
+ def no_animation(self):
+ """Temporarily turn off auto-updating the screen.
+
+ This is useful for drawing complex shapes where even the fastest setting
+ is too slow. Once this context manager is exited, the drawing will
+ be displayed.
+
+ Example (for a TurtleScreen instance named screen
+ and a Turtle instance named turtle):
+ >>> with screen.no_animation():
+ ... turtle.circle(50)
+ """
+ tracer = self.tracer()
+ try:
+ self.tracer(0)
+ yield
+ finally:
+ self.tracer(tracer)
+
def _incrementudc(self):
"""Increment update counter."""
if not TurtleScreen._RUNNING:
@@ -3380,6 +3402,24 @@ def filling(self):
"""
return isinstance(self._fillpath, list)
+ @contextmanager
+ def fill(self):
+ """A context manager for filling a shape.
+
+ Implicitly ensures the code block is wrapped with
+ begin_fill() and end_fill().
+
+ Example (for a Turtle instance named turtle):
+ >>> turtle.color("black", "red")
+ >>> with turtle.fill():
+ ... turtle.circle(60)
+ """
+ self.begin_fill()
+ try:
+ yield
+ finally:
+ self.end_fill()
+
def begin_fill(self):
"""Called just before drawing a shape to be filled.
@@ -3400,7 +3440,6 @@ def begin_fill(self):
self.undobuffer.push(("beginfill", self._fillitem))
self._update()
-
def end_fill(self):
"""Fill the shape drawn after the call begin_fill().
@@ -3504,6 +3543,27 @@ def write(self, arg, move=False, align="left", font=("Arial", 8, "normal")):
if self.undobuffer:
self.undobuffer.cumulate = False
+ @contextmanager
+ def poly(self):
+ """A context manager for recording the vertices of a polygon.
+
+ Implicitly ensures that the code block is wrapped with
+ begin_poly() and end_poly()
+
+ Example (for a Turtle instance named turtle) where we create a
+ triangle as the polygon and move the turtle 100 steps forward:
+ >>> with turtle.poly():
+ ... for side in range(3)
+ ... turtle.forward(50)
+ ... turtle.right(60)
+ >>> turtle.forward(100)
+ """
+ self.begin_poly()
+ try:
+ yield
+ finally:
+ self.end_poly()
+
def begin_poly(self):
"""Start recording the vertices of a polygon.
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-11-03-06-05-16.gh-issue-126349.7YwWsI.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-11-03-06-05-16.gh-issue-126349.7YwWsI.rst
new file mode 100644
index 00000000000000..aecc8c9abf3ce9
--- /dev/null
+++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-11-03-06-05-16.gh-issue-126349.7YwWsI.rst
@@ -0,0 +1,2 @@
+Add :func:`turtle.fill`, :func:`turtle.poly` and :func:`turtle.no_animation` context managers.
+Patch by Marie Roald and Yngve Mardal Moe.
1
0
[3.13] gh-128961: Fix exhausted array iterator crash in __setstate__() (GH-128962) (#128976)
by erlend-aasland Jan. 18, 2025
by erlend-aasland Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/c75894a36b13f2dd1bfdd72695dd904260…
commit: c75894a36b13f2dd1bfdd72695dd904260b7ef78
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: erlend-aasland <erlend.aasland(a)protonmail.com>
date: 2025-01-18T10:17:42Z
summary:
[3.13] gh-128961: Fix exhausted array iterator crash in __setstate__() (GH-128962) (#128976)
(cherry picked from commit 4dade055f4e18a7e91bc70293abb4db745ad16ca)
Co-authored-by: Tomasz Pytel <tompytel(a)gmail.com>
files:
A Misc/NEWS.d/next/Library/2025-01-17-21-33-11.gh-issue-128961.XwvyIZ.rst
M Lib/test/test_array.py
M Modules/arraymodule.c
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index 47cbe60bfca4e4..f0e32befd6628d 100755
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -1665,5 +1665,13 @@ def test_tolist(self, size):
self.assertEqual(ls[:8], list(example[:8]))
self.assertEqual(ls[-8:], list(example[-8:]))
+ def test_gh_128961(self):
+ a = array.array('i')
+ it = iter(a)
+ list(it)
+ it.__setstate__(0)
+ self.assertRaises(StopIteration, next, it)
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2025-01-17-21-33-11.gh-issue-128961.XwvyIZ.rst b/Misc/NEWS.d/next/Library/2025-01-17-21-33-11.gh-issue-128961.XwvyIZ.rst
new file mode 100644
index 00000000000000..9c985df77743da
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-17-21-33-11.gh-issue-128961.XwvyIZ.rst
@@ -0,0 +1 @@
+Fix a crash when setting state on an exhausted :class:`array.array` iterator.
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 679222c3f03d23..600302e1183f99 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -3074,11 +3074,16 @@ array_arrayiterator___setstate__(arrayiterobject *self, PyObject *state)
Py_ssize_t index = PyLong_AsSsize_t(state);
if (index == -1 && PyErr_Occurred())
return NULL;
- if (index < 0)
- index = 0;
- else if (index > Py_SIZE(self->ao))
- index = Py_SIZE(self->ao); /* iterator exhausted */
- self->index = index;
+ arrayobject *ao = self->ao;
+ if (ao != NULL) {
+ if (index < 0) {
+ index = 0;
+ }
+ else if (index > Py_SIZE(ao)) {
+ index = Py_SIZE(ao); /* iterator exhausted */
+ }
+ self->index = index;
+ }
Py_RETURN_NONE;
}
1
0
[3.12] gh-128961: Fix exhausted array iterator crash in __setstate__() (GH-128962) (#128977)
by erlend-aasland Jan. 18, 2025
by erlend-aasland Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/405f6d72bb21c94cd4491559d2377db5b4…
commit: 405f6d72bb21c94cd4491559d2377db5b41091f0
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: erlend-aasland <erlend.aasland(a)protonmail.com>
date: 2025-01-18T10:14:07Z
summary:
[3.12] gh-128961: Fix exhausted array iterator crash in __setstate__() (GH-128962) (#128977)
(cherry picked from commit 4dade055f4e18a7e91bc70293abb4db745ad16ca)
Co-authored-by: Tomasz Pytel <tompytel(a)gmail.com>
files:
A Misc/NEWS.d/next/Library/2025-01-17-21-33-11.gh-issue-128961.XwvyIZ.rst
M Lib/test/test_array.py
M Modules/arraymodule.c
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index 9c21cf035b1975..9b4847bf11abc7 100755
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -1609,5 +1609,13 @@ def test_tolist(self, size):
self.assertEqual(ls[:8], list(example[:8]))
self.assertEqual(ls[-8:], list(example[-8:]))
+ def test_gh_128961(self):
+ a = array.array('i')
+ it = iter(a)
+ list(it)
+ it.__setstate__(0)
+ self.assertRaises(StopIteration, next, it)
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2025-01-17-21-33-11.gh-issue-128961.XwvyIZ.rst b/Misc/NEWS.d/next/Library/2025-01-17-21-33-11.gh-issue-128961.XwvyIZ.rst
new file mode 100644
index 00000000000000..9c985df77743da
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-17-21-33-11.gh-issue-128961.XwvyIZ.rst
@@ -0,0 +1 @@
+Fix a crash when setting state on an exhausted :class:`array.array` iterator.
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index d24c5989af36fc..090a7b841c93ea 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -2966,11 +2966,16 @@ array_arrayiterator___setstate__(arrayiterobject *self, PyObject *state)
Py_ssize_t index = PyLong_AsSsize_t(state);
if (index == -1 && PyErr_Occurred())
return NULL;
- if (index < 0)
- index = 0;
- else if (index > Py_SIZE(self->ao))
- index = Py_SIZE(self->ao); /* iterator exhausted */
- self->index = index;
+ arrayobject *ao = self->ao;
+ if (ao != NULL) {
+ if (index < 0) {
+ index = 0;
+ }
+ else if (index > Py_SIZE(ao)) {
+ index = Py_SIZE(ao); /* iterator exhausted */
+ }
+ self->index = index;
+ }
Py_RETURN_NONE;
}
1
0
gh-128961: Fix exhausted array iterator crash in __setstate__() (#128962)
by erlend-aasland Jan. 18, 2025
by erlend-aasland Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/4dade055f4e18a7e91bc70293abb4db745…
commit: 4dade055f4e18a7e91bc70293abb4db745ad16ca
branch: main
author: Tomasz Pytel <tompytel(a)gmail.com>
committer: erlend-aasland <erlend.aasland(a)protonmail.com>
date: 2025-01-18T10:55:29+01:00
summary:
gh-128961: Fix exhausted array iterator crash in __setstate__() (#128962)
files:
A Misc/NEWS.d/next/Library/2025-01-17-21-33-11.gh-issue-128961.XwvyIZ.rst
M Lib/test/test_array.py
M Modules/arraymodule.c
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index f621f343eb062a..58ea89c4fac833 100755
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -1665,5 +1665,13 @@ def test_tolist(self, size):
self.assertEqual(ls[:8], list(example[:8]))
self.assertEqual(ls[-8:], list(example[-8:]))
+ def test_gh_128961(self):
+ a = array.array('i')
+ it = iter(a)
+ list(it)
+ it.__setstate__(0)
+ self.assertRaises(StopIteration, next, it)
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2025-01-17-21-33-11.gh-issue-128961.XwvyIZ.rst b/Misc/NEWS.d/next/Library/2025-01-17-21-33-11.gh-issue-128961.XwvyIZ.rst
new file mode 100644
index 00000000000000..9c985df77743da
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-17-21-33-11.gh-issue-128961.XwvyIZ.rst
@@ -0,0 +1 @@
+Fix a crash when setting state on an exhausted :class:`array.array` iterator.
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index b80c964f20d65e..fdbb0f0e8d6691 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -3090,11 +3090,16 @@ array_arrayiterator___setstate__(arrayiterobject *self, PyObject *state)
Py_ssize_t index = PyLong_AsSsize_t(state);
if (index == -1 && PyErr_Occurred())
return NULL;
- if (index < 0)
- index = 0;
- else if (index > Py_SIZE(self->ao))
- index = Py_SIZE(self->ao); /* iterator exhausted */
- self->index = index;
+ arrayobject *ao = self->ao;
+ if (ao != NULL) {
+ if (index < 0) {
+ index = 0;
+ }
+ else if (index > Py_SIZE(ao)) {
+ index = Py_SIZE(ao); /* iterator exhausted */
+ }
+ self->index = index;
+ }
Py_RETURN_NONE;
}
1
0
https://github.com/python/cpython/commit/9ed7bf2cd783b78b28f18abc090f43467a…
commit: 9ed7bf2cd783b78b28f18abc090f43467a28f4aa
branch: main
author: Zanie Blue <contact(a)zanie.dev>
committer: corona10 <donghee.na92(a)gmail.com>
date: 2025-01-18T07:32:23Z
summary:
gh-128515: Add BOLT build to CI (gh-128845)
files:
M .github/workflows/build.yml
M .github/workflows/reusable-ubuntu.yml
M Lib/test/test_perf_profiler.py
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 9adf860632e8a2..8a70cde3d8bc13 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -231,10 +231,14 @@ jobs:
name: >-
Ubuntu
${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }}
+ ${{ fromJSON(matrix.bolt) && '(bolt)' || '' }}
needs: check_source
if: needs.check_source.outputs.run_tests == 'true'
strategy:
matrix:
+ bolt:
+ - false
+ - true
free-threading:
- false
- true
@@ -246,9 +250,16 @@ jobs:
exclude:
- os: ubuntu-24.04-aarch64
is-fork: true
+ # Do not test BOLT with free-threading, to conserve resources
+ - bolt: true
+ free-threading: true
+ # BOLT currently crashes during instrumentation on aarch64
+ - os: ubuntu-24.04-aarch64
+ bolt: true
uses: ./.github/workflows/reusable-ubuntu.yml
with:
config_hash: ${{ needs.check_source.outputs.config_hash }}
+ bolt-optimizations: ${{ matrix.bolt }}
free-threading: ${{ matrix.free-threading }}
os: ${{ matrix.os }}
diff --git a/.github/workflows/reusable-ubuntu.yml b/.github/workflows/reusable-ubuntu.yml
index 46c542940c8483..686e8fe1abc980 100644
--- a/.github/workflows/reusable-ubuntu.yml
+++ b/.github/workflows/reusable-ubuntu.yml
@@ -6,6 +6,11 @@ on:
config_hash:
required: true
type: string
+ bolt-optimizations:
+ description: Whether to enable BOLT optimizations
+ required: false
+ type: boolean
+ default: false
free-threading:
description: Whether to use free-threaded mode
required: false
@@ -34,6 +39,12 @@ jobs:
run: echo "::add-matcher::.github/problem-matchers/gcc.json"
- name: Install dependencies
run: sudo ./.github/workflows/posix-deps-apt.sh
+ - name: Install Clang and BOLT
+ if: ${{ fromJSON(inputs.bolt-optimizations) }}
+ run: |
+ sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh 19
+ sudo apt-get install bolt-19
+ echo PATH="$(llvm-config-19 --bindir):$PATH" >> $GITHUB_ENV
- name: Configure OpenSSL env vars
run: |
echo "MULTISSL_DIR=${GITHUB_WORKSPACE}/multissl" >> "$GITHUB_ENV"
@@ -73,7 +84,10 @@ jobs:
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ inputs.config_hash }}
- name: Configure CPython out-of-tree
working-directory: ${{ env.CPYTHON_BUILDDIR }}
+ # `test_unpickle_module_race` writes to the source directory, which is
+ # read-only during builds — so we exclude it from profiling with BOLT.
run: >-
+ PROFILE_TASK='-m test --pgo --ignore test_unpickle_module_race'
../cpython-ro-srcdir/configure
--config-cache
--with-pydebug
@@ -81,6 +95,7 @@ jobs:
--enable-safety
--with-openssl="$OPENSSL_DIR"
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}
+ ${{ fromJSON(inputs.bolt-optimizations) && '--enable-bolt' || '' }}
- name: Build CPython out-of-tree
if: ${{ inputs.free-threading }}
working-directory: ${{ env.CPYTHON_BUILDDIR }}
diff --git a/Lib/test/test_perf_profiler.py b/Lib/test/test_perf_profiler.py
index 1e74990878007a..6f1fd8d38e4ea0 100644
--- a/Lib/test/test_perf_profiler.py
+++ b/Lib/test/test_perf_profiler.py
@@ -47,6 +47,7 @@ def tearDown(self) -> None:
for file in files_to_delete:
file.unlink()
+ @unittest.skipIf(support.check_bolt_optimized, "fails on BOLT instrumented binaries")
def test_trampoline_works(self):
code = """if 1:
def foo():
@@ -100,6 +101,7 @@ def baz():
"Address should contain only hex characters",
)
+ @unittest.skipIf(support.check_bolt_optimized, "fails on BOLT instrumented binaries")
def test_trampoline_works_with_forks(self):
code = """if 1:
import os, sys
@@ -160,6 +162,7 @@ def baz():
self.assertIn(f"py::bar_fork:{script}", child_perf_file_contents)
self.assertIn(f"py::baz_fork:{script}", child_perf_file_contents)
+ @unittest.skipIf(support.check_bolt_optimized, "fails on BOLT instrumented binaries")
def test_sys_api(self):
code = """if 1:
import sys
1
0
[3.13] gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets (GH-128933) (#128969)
by gpshead Jan. 18, 2025
by gpshead Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/d8a442637bf3ce588ea6023439317954c9…
commit: d8a442637bf3ce588ea6023439317954c9fa8a58
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: gpshead <greg(a)krypto.org>
date: 2025-01-18T03:45:42Z
summary:
[3.13] gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets (GH-128933) (#128969)
gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets (GH-128933)
* gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets
Do not attempt to set ``SO_REUSEPORT`` on sockets of address familifies other
than ``AF_INET`` and ``AF_INET6``, as it is meaningless with these address
families, and the call with fail with Linux kernel 6.12.9 and newer.
* Apply suggestions from code review
---------
(cherry picked from commit 3829104ab412a47bf3f36b8c133c886d2cc9a6d4)
Co-authored-by: Michał Górny <mgorny(a)gentoo.org>
Co-authored-by: Vinay Sajip <vinay_sajip(a)yahoo.co.uk>
files:
A Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst
M Lib/asyncio/base_events.py
M Lib/socket.py
M Lib/socketserver.py
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index ca29792dc89825..910fc76e884d2c 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -1590,7 +1590,9 @@ async def create_server(
if reuse_address:
sock.setsockopt(
socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
- if reuse_port:
+ # Since Linux 6.12.9, SO_REUSEPORT is not allowed
+ # on other address families than AF_INET/AF_INET6.
+ if reuse_port and af in (socket.AF_INET, socket.AF_INET6):
_set_reuseport(sock)
if keep_alive:
sock.setsockopt(
diff --git a/Lib/socket.py b/Lib/socket.py
index 9207101dcf9d58..35d87eff34deb1 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -931,7 +931,9 @@ def create_server(address, *, family=AF_INET, backlog=None, reuse_port=False,
# Fail later on bind(), for platforms which may not
# support this option.
pass
- if reuse_port:
+ # Since Linux 6.12.9, SO_REUSEPORT is not allowed
+ # on other address families than AF_INET/AF_INET6.
+ if reuse_port and family in (AF_INET, AF_INET6):
sock.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1)
if has_ipv6 and family == AF_INET6:
if dualstack_ipv6:
diff --git a/Lib/socketserver.py b/Lib/socketserver.py
index cd028ef1c63b85..35b2723de3babe 100644
--- a/Lib/socketserver.py
+++ b/Lib/socketserver.py
@@ -468,7 +468,12 @@ def server_bind(self):
"""
if self.allow_reuse_address and hasattr(socket, "SO_REUSEADDR"):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- if self.allow_reuse_port and hasattr(socket, "SO_REUSEPORT"):
+ # Since Linux 6.12.9, SO_REUSEPORT is not allowed
+ # on other address families than AF_INET/AF_INET6.
+ if (
+ self.allow_reuse_port and hasattr(socket, "SO_REUSEPORT")
+ and self.address_family in (socket.AF_INET, socket.AF_INET6)
+ ):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
self.socket.bind(self.server_address)
self.server_address = self.socket.getsockname()
diff --git a/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst b/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst
new file mode 100644
index 00000000000000..f2db341ef81621
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst
@@ -0,0 +1,3 @@
+Do not attempt to set ``SO_REUSEPORT`` on sockets of address families
+other than ``AF_INET`` and ``AF_INET6``, as it is meaningless with these
+address families, and the call with fail with Linux kernel 6.12.9 and newer.
1
0
[3.12] gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets (GH-128933) (#128970)
by gpshead Jan. 18, 2025
by gpshead Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/8a8f5d636d06c122bc1db0ee6b11a883e5…
commit: 8a8f5d636d06c122bc1db0ee6b11a883e550a803
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: gpshead <greg(a)krypto.org>
date: 2025-01-18T01:06:45Z
summary:
[3.12] gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets (GH-128933) (#128970)
gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets (GH-128933)
* gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets
Do not attempt to set ``SO_REUSEPORT`` on sockets of address familifies other
than ``AF_INET`` and ``AF_INET6``, as it is meaningless with these address
families, and the call with fail with Linux kernel 6.12.9 and newer.
* Apply suggestions from code review
---------
(cherry picked from commit 3829104ab412a47bf3f36b8c133c886d2cc9a6d4)
Co-authored-by: Michał Górny <mgorny(a)gentoo.org>
Co-authored-by: Vinay Sajip <vinay_sajip(a)yahoo.co.uk>
files:
A Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst
M Lib/asyncio/base_events.py
M Lib/socket.py
M Lib/socketserver.py
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 3146f7f3f65503..9cbed30449688e 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -1550,7 +1550,9 @@ async def create_server(
if reuse_address:
sock.setsockopt(
socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
- if reuse_port:
+ # Since Linux 6.12.9, SO_REUSEPORT is not allowed
+ # on other address families than AF_INET/AF_INET6.
+ if reuse_port and af in (socket.AF_INET, socket.AF_INET6):
_set_reuseport(sock)
# Disable IPv4/IPv6 dual stack support (enabled by
# default on Linux) which makes a single socket
diff --git a/Lib/socket.py b/Lib/socket.py
index c1880c4ea512cf..91782b30ae8d09 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -932,7 +932,9 @@ def create_server(address, *, family=AF_INET, backlog=None, reuse_port=False,
# Fail later on bind(), for platforms which may not
# support this option.
pass
- if reuse_port:
+ # Since Linux 6.12.9, SO_REUSEPORT is not allowed
+ # on other address families than AF_INET/AF_INET6.
+ if reuse_port and family in (AF_INET, AF_INET6):
sock.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1)
if has_ipv6 and family == AF_INET6:
if dualstack_ipv6:
diff --git a/Lib/socketserver.py b/Lib/socketserver.py
index cd028ef1c63b85..35b2723de3babe 100644
--- a/Lib/socketserver.py
+++ b/Lib/socketserver.py
@@ -468,7 +468,12 @@ def server_bind(self):
"""
if self.allow_reuse_address and hasattr(socket, "SO_REUSEADDR"):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- if self.allow_reuse_port and hasattr(socket, "SO_REUSEPORT"):
+ # Since Linux 6.12.9, SO_REUSEPORT is not allowed
+ # on other address families than AF_INET/AF_INET6.
+ if (
+ self.allow_reuse_port and hasattr(socket, "SO_REUSEPORT")
+ and self.address_family in (socket.AF_INET, socket.AF_INET6)
+ ):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
self.socket.bind(self.server_address)
self.server_address = self.socket.getsockname()
diff --git a/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst b/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst
new file mode 100644
index 00000000000000..f2db341ef81621
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst
@@ -0,0 +1,3 @@
+Do not attempt to set ``SO_REUSEPORT`` on sockets of address families
+other than ``AF_INET`` and ``AF_INET6``, as it is meaningless with these
+address families, and the call with fail with Linux kernel 6.12.9 and newer.
1
0
[3.12] Fix definition of a `generator iterator` in `glossary.rst` (GH-128952) (#128968)
by gpshead Jan. 18, 2025
by gpshead Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/8ee250bdd984c290f4c396657e937ce5d4…
commit: 8ee250bdd984c290f4c396657e937ce5d4ffdcff
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: gpshead <greg(a)krypto.org>
date: 2025-01-18T00:53:29Z
summary:
[3.12] Fix definition of a `generator iterator` in `glossary.rst` (GH-128952) (#128968)
Fix definition of a `generator iterator` in `glossary.rst` (GH-128952)
Fix possible typo/grammar in glossary.rst
As discussed in https://discuss.python.org/t/typo-in-glossary-entry-for-generator-iterator/…
(cherry picked from commit 8174770d311ba09c07a47cc3ae90a1db2e7d7708)
Co-authored-by: Daniel F Moisset <dfmoisset(a)gmail.com>
files:
M Doc/glossary.rst
diff --git a/Doc/glossary.rst b/Doc/glossary.rst
index 9b29699e866433..50ed5fc2bc096c 100644
--- a/Doc/glossary.rst
+++ b/Doc/glossary.rst
@@ -118,7 +118,7 @@ Glossary
:keyword:`yield` expression.
Each :keyword:`yield` temporarily suspends processing, remembering the
- location execution state (including local variables and pending
+ execution state (including local variables and pending
try-statements). When the *asynchronous generator iterator* effectively
resumes with another awaitable returned by :meth:`~object.__anext__`, it
picks up where it left off. See :pep:`492` and :pep:`525`.
@@ -505,7 +505,7 @@ Glossary
An object created by a :term:`generator` function.
Each :keyword:`yield` temporarily suspends processing, remembering the
- location execution state (including local variables and pending
+ execution state (including local variables and pending
try-statements). When the *generator iterator* resumes, it picks up where
it left off (in contrast to functions which start fresh on every
invocation).
1
0
[3.13] Fix definition of a `generator iterator` in `glossary.rst` (GH-128952) (#128967)
by gpshead Jan. 18, 2025
by gpshead Jan. 18, 2025
Jan. 18, 2025
https://github.com/python/cpython/commit/77e29c75da6598d8e2bb8704ae42a69e44…
commit: 77e29c75da6598d8e2bb8704ae42a69e44e2d874
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: gpshead <greg(a)krypto.org>
date: 2025-01-18T00:52:10Z
summary:
[3.13] Fix definition of a `generator iterator` in `glossary.rst` (GH-128952) (#128967)
Fix definition of a `generator iterator` in `glossary.rst` (GH-128952)
Fix possible typo/grammar in glossary.rst
As discussed in https://discuss.python.org/t/typo-in-glossary-entry-for-generator-iterator/…
(cherry picked from commit 8174770d311ba09c07a47cc3ae90a1db2e7d7708)
Co-authored-by: Daniel F Moisset <dfmoisset(a)gmail.com>
files:
M Doc/glossary.rst
diff --git a/Doc/glossary.rst b/Doc/glossary.rst
index 5c56c419514da1..d8488ca99246d2 100644
--- a/Doc/glossary.rst
+++ b/Doc/glossary.rst
@@ -110,7 +110,7 @@ Glossary
:keyword:`yield` expression.
Each :keyword:`yield` temporarily suspends processing, remembering the
- location execution state (including local variables and pending
+ execution state (including local variables and pending
try-statements). When the *asynchronous generator iterator* effectively
resumes with another awaitable returned by :meth:`~object.__anext__`, it
picks up where it left off. See :pep:`492` and :pep:`525`.
@@ -554,7 +554,7 @@ Glossary
An object created by a :term:`generator` function.
Each :keyword:`yield` temporarily suspends processing, remembering the
- location execution state (including local variables and pending
+ execution state (including local variables and pending
try-statements). When the *generator iterator* resumes, it picks up where
it left off (in contrast to functions which start fresh on every
invocation).
1
0
Jan. 18, 2025
https://github.com/python/cpython/commit/3829104ab412a47bf3f36b8c133c886d2c…
commit: 3829104ab412a47bf3f36b8c133c886d2cc9a6d4
branch: main
author: Michał Górny <mgorny(a)gentoo.org>
committer: gpshead <greg(a)krypto.org>
date: 2025-01-17T16:49:16-08:00
summary:
gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets (GH-128933)
* gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets
Do not attempt to set ``SO_REUSEPORT`` on sockets of address familifies other
than ``AF_INET`` and ``AF_INET6``, as it is meaningless with these address
families, and the call with fail with Linux kernel 6.12.9 and newer.
* Apply suggestions from code review
Co-authored-by: Vinay Sajip <vinay_sajip(a)yahoo.co.uk>
---------
Co-authored-by: Vinay Sajip <vinay_sajip(a)yahoo.co.uk>
files:
A Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst
M Lib/asyncio/base_events.py
M Lib/socket.py
M Lib/socketserver.py
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 6e6e5aaac15caf..85018797db33bb 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -1593,7 +1593,9 @@ async def create_server(
if reuse_address:
sock.setsockopt(
socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
- if reuse_port:
+ # Since Linux 6.12.9, SO_REUSEPORT is not allowed
+ # on other address families than AF_INET/AF_INET6.
+ if reuse_port and af in (socket.AF_INET, socket.AF_INET6):
_set_reuseport(sock)
if keep_alive:
sock.setsockopt(
diff --git a/Lib/socket.py b/Lib/socket.py
index be37c24d6174a2..727b0e75f03595 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -937,7 +937,9 @@ def create_server(address, *, family=AF_INET, backlog=None, reuse_port=False,
# Fail later on bind(), for platforms which may not
# support this option.
pass
- if reuse_port:
+ # Since Linux 6.12.9, SO_REUSEPORT is not allowed
+ # on other address families than AF_INET/AF_INET6.
+ if reuse_port and family in (AF_INET, AF_INET6):
sock.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1)
if has_ipv6 and family == AF_INET6:
if dualstack_ipv6:
diff --git a/Lib/socketserver.py b/Lib/socketserver.py
index cd028ef1c63b85..35b2723de3babe 100644
--- a/Lib/socketserver.py
+++ b/Lib/socketserver.py
@@ -468,7 +468,12 @@ def server_bind(self):
"""
if self.allow_reuse_address and hasattr(socket, "SO_REUSEADDR"):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- if self.allow_reuse_port and hasattr(socket, "SO_REUSEPORT"):
+ # Since Linux 6.12.9, SO_REUSEPORT is not allowed
+ # on other address families than AF_INET/AF_INET6.
+ if (
+ self.allow_reuse_port and hasattr(socket, "SO_REUSEPORT")
+ and self.address_family in (socket.AF_INET, socket.AF_INET6)
+ ):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
self.socket.bind(self.server_address)
self.server_address = self.socket.getsockname()
diff --git a/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst b/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst
new file mode 100644
index 00000000000000..f2db341ef81621
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst
@@ -0,0 +1,3 @@
+Do not attempt to set ``SO_REUSEPORT`` on sockets of address families
+other than ``AF_INET`` and ``AF_INET6``, as it is meaningless with these
+address families, and the call with fail with Linux kernel 6.12.9 and newer.
1
0
Jan. 18, 2025
https://github.com/python/cpython/commit/8174770d311ba09c07a47cc3ae90a1db2e…
commit: 8174770d311ba09c07a47cc3ae90a1db2e7d7708
branch: main
author: Daniel F Moisset <dfmoisset(a)gmail.com>
committer: gpshead <greg(a)krypto.org>
date: 2025-01-17T16:46:19-08:00
summary:
Fix definition of a `generator iterator` in `glossary.rst` (GH-128952)
Fix possible typo/grammar in glossary.rst
As discussed in https://discuss.python.org/t/typo-in-glossary-entry-for-generator-iterator/…
files:
M Doc/glossary.rst
diff --git a/Doc/glossary.rst b/Doc/glossary.rst
index f67f3ecad0bc40..33e77c9de211eb 100644
--- a/Doc/glossary.rst
+++ b/Doc/glossary.rst
@@ -115,7 +115,7 @@ Glossary
:keyword:`yield` expression.
Each :keyword:`yield` temporarily suspends processing, remembering the
- location execution state (including local variables and pending
+ execution state (including local variables and pending
try-statements). When the *asynchronous generator iterator* effectively
resumes with another awaitable returned by :meth:`~object.__anext__`, it
picks up where it left off. See :pep:`492` and :pep:`525`.
@@ -564,7 +564,7 @@ Glossary
An object created by a :term:`generator` function.
Each :keyword:`yield` temporarily suspends processing, remembering the
- location execution state (including local variables and pending
+ execution state (including local variables and pending
try-statements). When the *generator iterator* resumes, it picks up where
it left off (in contrast to functions which start fresh on every
invocation).
1
0
gh-128923: fix test_pydoc for object subclasses without `__module__` (#128951)
by Yhg1s Jan. 17, 2025
by Yhg1s Jan. 17, 2025
Jan. 17, 2025
https://github.com/python/cpython/commit/d4544cb232dee5f836a64b9126fbbefcbb…
commit: d4544cb232dee5f836a64b9126fbbefcbb6099de
branch: main
author: T. Wouters <thomas(a)python.org>
committer: Yhg1s <thomas(a)python.org>
date: 2025-01-17T23:43:17+01:00
summary:
gh-128923: fix test_pydoc for object subclasses without `__module__` (#128951)
Fix pydoc's docclass() for classes inheriting from object without the `__module__` attribute, like `_testcapi.HeapType`.
files:
M Lib/pydoc.py
M Lib/test/test_pydoc/test_pydoc.py
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 9e84292aaf825f..922946e5fa7ddb 100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1435,7 +1435,8 @@ def makename(c, m=object.__module__):
# List the built-in subclasses, if any:
subclasses = sorted(
(str(cls.__name__) for cls in type.__subclasses__(object)
- if not cls.__name__.startswith("_") and cls.__module__ == "builtins"),
+ if (not cls.__name__.startswith("_") and
+ getattr(cls, '__module__', '') == "builtins")),
key=str.lower
)
no_of_subclasses = len(subclasses)
diff --git a/Lib/test/test_pydoc/test_pydoc.py b/Lib/test/test_pydoc/test_pydoc.py
index cec18aa9440c9e..b02ba3aafd4d20 100644
--- a/Lib/test/test_pydoc/test_pydoc.py
+++ b/Lib/test/test_pydoc/test_pydoc.py
@@ -556,6 +556,14 @@ class object
| ... and 82 other subclasses
"""
doc = pydoc.TextDoc()
+ try:
+ # Make sure HeapType, which has no __module__ attribute, is one
+ # of the known subclasses of object. (doc.docclass() used to
+ # fail if HeapType was imported before running this test, like
+ # when running tests sequentially.)
+ from _testcapi import HeapType
+ except ImportError:
+ pass
text = doc.docclass(object)
snip = (" | Built-in subclasses:\n"
" | async_generator\n"
1
0
Jan. 17, 2025
https://github.com/python/cpython/commit/34ded1a1a10204635cad27830fcbee2f85…
commit: 34ded1a1a10204635cad27830fcbee2f8547e8ed
branch: 3.13
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-17T22:44:51+01:00
summary:
[3.13] gh-128911: Add tests on the PyImport C API (#128915) (#128960)
gh-128911: Add tests on the PyImport C API (#128915)
* Add Modules/_testlimitedcapi/import.c
* Add Lib/test/test_capi/test_import.py
* Remove _testcapi.check_pyimport_addmodule(): tests already covered
by newly added tests.
Co-authored-by: Serhiy Storchaka <storchaka(a)gmail.com>
(cherry picked from commit d95ba9fa1110534b7247fa2ff12b90e930c93256)
files:
A Lib/test/test_capi/test_import.py
A Modules/_testlimitedcapi/import.c
M Lib/test/test_import/__init__.py
M Modules/Setup.stdlib.in
M Modules/_testcapimodule.c
M Modules/_testlimitedcapi.c
M Modules/_testlimitedcapi/parts.h
M PCbuild/_testlimitedcapi.vcxproj
M PCbuild/_testlimitedcapi.vcxproj.filters
diff --git a/Lib/test/test_capi/test_import.py b/Lib/test/test_capi/test_import.py
new file mode 100644
index 00000000000000..3abd1cd7470111
--- /dev/null
+++ b/Lib/test/test_capi/test_import.py
@@ -0,0 +1,322 @@
+import importlib.util
+import os.path
+import sys
+import types
+import unittest
+from test.support import os_helper
+from test.support import import_helper
+from test.support.warnings_helper import check_warnings
+
+_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
+NULL = None
+
+
+class ImportTests(unittest.TestCase):
+ def test_getmagicnumber(self):
+ # Test PyImport_GetMagicNumber()
+ magic = _testlimitedcapi.PyImport_GetMagicNumber()
+ self.assertEqual(magic,
+ int.from_bytes(importlib.util.MAGIC_NUMBER, 'little'))
+
+ def test_getmagictag(self):
+ # Test PyImport_GetMagicTag()
+ tag = _testlimitedcapi.PyImport_GetMagicTag()
+ self.assertEqual(tag, sys.implementation.cache_tag)
+
+ def test_getmoduledict(self):
+ # Test PyImport_GetModuleDict()
+ modules = _testlimitedcapi.PyImport_GetModuleDict()
+ self.assertIs(modules, sys.modules)
+
+ def check_import_loaded_module(self, import_module):
+ for name in ('os', 'sys', 'test', 'unittest'):
+ with self.subTest(name=name):
+ self.assertIn(name, sys.modules)
+ old_module = sys.modules[name]
+ module = import_module(name)
+ self.assertIsInstance(module, types.ModuleType)
+ self.assertIs(module, old_module)
+
+ def check_import_fresh_module(self, import_module):
+ old_modules = dict(sys.modules)
+ try:
+ for name in ('colorsys', 'math'):
+ with self.subTest(name=name):
+ sys.modules.pop(name, None)
+ module = import_module(name)
+ self.assertIsInstance(module, types.ModuleType)
+ self.assertIs(module, sys.modules[name])
+ self.assertEqual(module.__name__, name)
+ finally:
+ sys.modules.clear()
+ sys.modules.update(old_modules)
+
+ def test_getmodule(self):
+ # Test PyImport_GetModule()
+ getmodule = _testlimitedcapi.PyImport_GetModule
+ self.check_import_loaded_module(getmodule)
+
+ nonexistent = 'nonexistent'
+ self.assertNotIn(nonexistent, sys.modules)
+ self.assertIs(getmodule(nonexistent), KeyError)
+ self.assertIs(getmodule(''), KeyError)
+ self.assertIs(getmodule(object()), KeyError)
+
+ self.assertRaises(TypeError, getmodule, []) # unhashable
+ # CRASHES getmodule(NULL)
+
+ def check_addmodule(self, add_module, accept_nonstr=False):
+ # create a new module
+ names = ['nonexistent']
+ if accept_nonstr:
+ names.append(b'\xff') # non-UTF-8
+ for name in names:
+ with self.subTest(name=name):
+ self.assertNotIn(name, sys.modules)
+ try:
+ module = add_module(name)
+ self.assertIsInstance(module, types.ModuleType)
+ self.assertEqual(module.__name__, name)
+ self.assertIs(module, sys.modules[name])
+ finally:
+ sys.modules.pop(name, None)
+
+ # get an existing module
+ self.check_import_loaded_module(add_module)
+
+ def test_addmoduleobject(self):
+ # Test PyImport_AddModuleObject()
+ addmoduleobject = _testlimitedcapi.PyImport_AddModuleObject
+ self.check_addmodule(addmoduleobject, accept_nonstr=True)
+
+ self.assertRaises(TypeError, addmoduleobject, []) # unhashable
+ # CRASHES addmoduleobject(NULL)
+
+ def test_addmodule(self):
+ # Test PyImport_AddModule()
+ addmodule = _testlimitedcapi.PyImport_AddModule
+ self.check_addmodule(addmodule)
+
+ self.assertRaises(UnicodeDecodeError, addmodule, b'\xff')
+ # CRASHES addmodule(NULL)
+
+ def test_addmoduleref(self):
+ # Test PyImport_AddModuleRef()
+ addmoduleref = _testlimitedcapi.PyImport_AddModuleRef
+ self.check_addmodule(addmoduleref)
+
+ self.assertRaises(UnicodeDecodeError, addmoduleref, b'\xff')
+ # CRASHES addmoduleref(NULL)
+
+ def check_import_func(self, import_module):
+ self.check_import_loaded_module(import_module)
+ self.check_import_fresh_module(import_module)
+ self.assertRaises(ModuleNotFoundError, import_module, 'nonexistent')
+ self.assertRaises(ValueError, import_module, '')
+
+ def test_import(self):
+ # Test PyImport_Import()
+ import_ = _testlimitedcapi.PyImport_Import
+ self.check_import_func(import_)
+
+ self.assertRaises(TypeError, import_, b'os')
+ self.assertRaises(SystemError, import_, NULL)
+
+ def test_importmodule(self):
+ # Test PyImport_ImportModule()
+ importmodule = _testlimitedcapi.PyImport_ImportModule
+ self.check_import_func(importmodule)
+
+ self.assertRaises(UnicodeDecodeError, importmodule, b'\xff')
+ # CRASHES importmodule(NULL)
+
+ def test_importmodulenoblock(self):
+ # Test deprecated PyImport_ImportModuleNoBlock()
+ importmodulenoblock = _testlimitedcapi.PyImport_ImportModuleNoBlock
+ with check_warnings(('', DeprecationWarning)):
+ self.check_import_func(importmodulenoblock)
+ self.assertRaises(UnicodeDecodeError, importmodulenoblock, b'\xff')
+
+ # CRASHES importmodulenoblock(NULL)
+
+ def check_frozen_import(self, import_frozen_module):
+ # Importing a frozen module executes its code, so start by unloading
+ # the module to execute the code in a new (temporary) module.
+ old_zipimport = sys.modules.pop('zipimport')
+ try:
+ self.assertEqual(import_frozen_module('zipimport'), 1)
+
+ # import zipimport again
+ self.assertEqual(import_frozen_module('zipimport'), 1)
+ finally:
+ sys.modules['zipimport'] = old_zipimport
+
+ # not a frozen module
+ self.assertEqual(import_frozen_module('sys'), 0)
+ self.assertEqual(import_frozen_module('nonexistent'), 0)
+ self.assertEqual(import_frozen_module(''), 0)
+
+ def test_importfrozenmodule(self):
+ # Test PyImport_ImportFrozenModule()
+ importfrozenmodule = _testlimitedcapi.PyImport_ImportFrozenModule
+ self.check_frozen_import(importfrozenmodule)
+
+ self.assertRaises(UnicodeDecodeError, importfrozenmodule, b'\xff')
+ # CRASHES importfrozenmodule(NULL)
+
+ def test_importfrozenmoduleobject(self):
+ # Test PyImport_ImportFrozenModuleObject()
+ importfrozenmoduleobject = _testlimitedcapi.PyImport_ImportFrozenModuleObject
+ self.check_frozen_import(importfrozenmoduleobject)
+ self.assertEqual(importfrozenmoduleobject(b'zipimport'), 0)
+ self.assertEqual(importfrozenmoduleobject(NULL), 0)
+
+ def test_importmoduleex(self):
+ # Test PyImport_ImportModuleEx()
+ importmoduleex = _testlimitedcapi.PyImport_ImportModuleEx
+ self.check_import_func(lambda name: importmoduleex(name, NULL, NULL, NULL))
+
+ self.assertRaises(ModuleNotFoundError, importmoduleex, 'nonexistent', NULL, NULL, NULL)
+ self.assertRaises(ValueError, importmoduleex, '', NULL, NULL, NULL)
+ self.assertRaises(UnicodeDecodeError, importmoduleex, b'\xff', NULL, NULL, NULL)
+ # CRASHES importmoduleex(NULL, NULL, NULL, NULL)
+
+ def check_importmodulelevel(self, importmodulelevel):
+ self.check_import_func(lambda name: importmodulelevel(name, NULL, NULL, NULL, 0))
+
+ self.assertRaises(ModuleNotFoundError, importmodulelevel, 'nonexistent', NULL, NULL, NULL, 0)
+ self.assertRaises(ValueError, importmodulelevel, '', NULL, NULL, NULL, 0)
+
+ if __package__:
+ self.assertIs(importmodulelevel('test_import', globals(), NULL, NULL, 1),
+ sys.modules['test.test_capi.test_import'])
+ self.assertIs(importmodulelevel('test_capi', globals(), NULL, NULL, 2),
+ sys.modules['test.test_capi'])
+ self.assertRaises(ValueError, importmodulelevel, 'os', NULL, NULL, NULL, -1)
+ with self.assertWarns(ImportWarning):
+ self.assertRaises(KeyError, importmodulelevel, 'test_import', {}, NULL, NULL, 1)
+ self.assertRaises(TypeError, importmodulelevel, 'test_import', [], NULL, NULL, 1)
+
+ def test_importmodulelevel(self):
+ # Test PyImport_ImportModuleLevel()
+ importmodulelevel = _testlimitedcapi.PyImport_ImportModuleLevel
+ self.check_importmodulelevel(importmodulelevel)
+
+ self.assertRaises(UnicodeDecodeError, importmodulelevel, b'\xff', NULL, NULL, NULL, 0)
+ # CRASHES importmodulelevel(NULL, NULL, NULL, NULL, 0)
+
+ def test_importmodulelevelobject(self):
+ # Test PyImport_ImportModuleLevelObject()
+ importmodulelevel = _testlimitedcapi.PyImport_ImportModuleLevelObject
+ self.check_importmodulelevel(importmodulelevel)
+
+ self.assertRaises(TypeError, importmodulelevel, b'os', NULL, NULL, NULL, 0)
+ self.assertRaises(ValueError, importmodulelevel, NULL, NULL, NULL, NULL, 0)
+
+ def check_executecodemodule(self, execute_code, *args):
+ name = 'test_import_executecode'
+ try:
+ # Create a temporary module where the code will be executed
+ self.assertNotIn(name, sys.modules)
+ module = _testlimitedcapi.PyImport_AddModuleRef(name)
+ self.assertFalse(hasattr(module, 'attr'))
+
+ # Execute the code
+ code = compile('attr = 1', '<test>', 'exec')
+ module2 = execute_code(name, code, *args)
+ self.assertIs(module2, module)
+
+ # Check the function side effects
+ self.assertEqual(module.attr, 1)
+ finally:
+ sys.modules.pop(name, None)
+ return module.__spec__.origin
+
+ def test_executecodemodule(self):
+ # Test PyImport_ExecCodeModule()
+ execcodemodule = _testlimitedcapi.PyImport_ExecCodeModule
+ self.check_executecodemodule(execcodemodule)
+
+ code = compile('attr = 1', '<test>', 'exec')
+ self.assertRaises(UnicodeDecodeError, execcodemodule, b'\xff', code)
+ # CRASHES execcodemodule(NULL, code)
+ # CRASHES execcodemodule(name, NULL)
+
+ def test_executecodemoduleex(self):
+ # Test PyImport_ExecCodeModuleEx()
+ execcodemoduleex = _testlimitedcapi.PyImport_ExecCodeModuleEx
+
+ # Test NULL path (it should not crash)
+ self.check_executecodemodule(execcodemoduleex, NULL)
+
+ # Test non-NULL path
+ pathname = b'pathname'
+ origin = self.check_executecodemodule(execcodemoduleex, pathname)
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+
+ pathname = os_helper.TESTFN_UNDECODABLE
+ if pathname:
+ origin = self.check_executecodemodule(execcodemoduleex, pathname)
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+
+ code = compile('attr = 1', '<test>', 'exec')
+ self.assertRaises(UnicodeDecodeError, execcodemoduleex, b'\xff', code, NULL)
+ # CRASHES execcodemoduleex(NULL, code, NULL)
+ # CRASHES execcodemoduleex(name, NULL, NULL)
+
+ def check_executecode_pathnames(self, execute_code_func, object=False):
+ # Test non-NULL pathname and NULL cpathname
+
+ # Test NULL paths (it should not crash)
+ self.check_executecodemodule(execute_code_func, NULL, NULL)
+
+ pathname = 'pathname'
+ origin = self.check_executecodemodule(execute_code_func, pathname, NULL)
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+ origin = self.check_executecodemodule(execute_code_func, NULL, pathname)
+ if not object:
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+
+ pathname = os_helper.TESTFN_UNDECODABLE
+ if pathname:
+ if object:
+ pathname = os.fsdecode(pathname)
+ origin = self.check_executecodemodule(execute_code_func, pathname, NULL)
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+ self.check_executecodemodule(execute_code_func, NULL, pathname)
+
+ # Test NULL pathname and non-NULL cpathname
+ pyc_filename = importlib.util.cache_from_source(__file__)
+ py_filename = importlib.util.source_from_cache(pyc_filename)
+ origin = self.check_executecodemodule(execute_code_func, NULL, pyc_filename)
+ if not object:
+ self.assertEqual(origin, py_filename)
+
+ def test_executecodemodulewithpathnames(self):
+ # Test PyImport_ExecCodeModuleWithPathnames()
+ execute_code_func = _testlimitedcapi.PyImport_ExecCodeModuleWithPathnames
+ self.check_executecode_pathnames(execute_code_func)
+
+ code = compile('attr = 1', '<test>', 'exec')
+ self.assertRaises(UnicodeDecodeError, execute_code_func, b'\xff', code, NULL, NULL)
+ # CRASHES execute_code_func(NULL, code, NULL, NULL)
+ # CRASHES execute_code_func(name, NULL, NULL, NULL)
+
+ def test_executecodemoduleobject(self):
+ # Test PyImport_ExecCodeModuleObject()
+ execute_code_func = _testlimitedcapi.PyImport_ExecCodeModuleObject
+ self.check_executecode_pathnames(execute_code_func, object=True)
+
+ code = compile('attr = 1', '<test>', 'exec')
+ self.assertRaises(TypeError, execute_code_func, [], code, NULL, NULL)
+ # CRASHES execute_code_func(NULL, code, NULL, NULL)
+ # CRASHES execute_code_func(name, NULL, NULL, NULL)
+
+ # TODO: test PyImport_GetImporter()
+ # TODO: test PyImport_ReloadModule()
+ # TODO: test PyImport_ExtendInittab()
+ # PyImport_AppendInittab() is tested by test_embed
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py
index 364ff08f03533b..df712ec5a9d97d 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -3330,30 +3330,6 @@ def test_basic_multiple_interpreters_reset_each(self):
# * module's global state was initialized, not reset
-@cpython_only
-class CAPITests(unittest.TestCase):
- def test_pyimport_addmodule(self):
- # gh-105922: Test PyImport_AddModuleRef(), PyImport_AddModule()
- # and PyImport_AddModuleObject()
- _testcapi = import_module("_testcapi")
- for name in (
- 'sys', # frozen module
- 'test', # package
- __name__, # package.module
- ):
- _testcapi.check_pyimport_addmodule(name)
-
- def test_pyimport_addmodule_create(self):
- # gh-105922: Test PyImport_AddModuleRef(), create a new module
- _testcapi = import_module("_testcapi")
- name = 'dontexist'
- self.assertNotIn(name, sys.modules)
- self.addCleanup(unload, name)
-
- mod = _testcapi.check_pyimport_addmodule(name)
- self.assertIs(mod, sys.modules[name])
-
-
if __name__ == '__main__':
# Test needs to be a package, so we can do relative imports.
unittest.main()
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in
index 06b30feef43e40..89a8e5a34de65a 100644
--- a/Modules/Setup.stdlib.in
+++ b/Modules/Setup.stdlib.in
@@ -164,7 +164,7 @@
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c
@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/run.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/hash.c _testcapi/time.c _testcapi/bytes.c _testcapi/object.c _testcapi/monitoring.c
-@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/tuple.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c
+@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/import.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/tuple.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
@MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index b8c13c63f95153..1feaaa78a75bfd 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -3081,52 +3081,6 @@ function_set_closure(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
-static PyObject *
-check_pyimport_addmodule(PyObject *self, PyObject *args)
-{
- const char *name;
- if (!PyArg_ParseTuple(args, "s", &name)) {
- return NULL;
- }
-
- // test PyImport_AddModuleRef()
- PyObject *module = PyImport_AddModuleRef(name);
- if (module == NULL) {
- return NULL;
- }
- assert(PyModule_Check(module));
- // module is a strong reference
-
- // test PyImport_AddModule()
- PyObject *module2 = PyImport_AddModule(name);
- if (module2 == NULL) {
- goto error;
- }
- assert(PyModule_Check(module2));
- assert(module2 == module);
- // module2 is a borrowed ref
-
- // test PyImport_AddModuleObject()
- PyObject *name_obj = PyUnicode_FromString(name);
- if (name_obj == NULL) {
- goto error;
- }
- PyObject *module3 = PyImport_AddModuleObject(name_obj);
- Py_DECREF(name_obj);
- if (module3 == NULL) {
- goto error;
- }
- assert(PyModule_Check(module3));
- assert(module3 == module);
- // module3 is a borrowed ref
-
- return module;
-
-error:
- Py_DECREF(module);
- return NULL;
-}
-
static PyObject *
test_weakref_capi(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
@@ -3526,7 +3480,6 @@ static PyMethodDef TestMethods[] = {
{"function_set_kw_defaults", function_set_kw_defaults, METH_VARARGS, NULL},
{"function_get_closure", function_get_closure, METH_O, NULL},
{"function_set_closure", function_set_closure, METH_VARARGS, NULL},
- {"check_pyimport_addmodule", check_pyimport_addmodule, METH_VARARGS},
{"test_weakref_capi", test_weakref_capi, METH_NOARGS},
{"function_set_warning", function_set_warning, METH_NOARGS},
{"test_critical_sections", test_critical_sections, METH_NOARGS},
diff --git a/Modules/_testlimitedcapi.c b/Modules/_testlimitedcapi.c
index ec19da217d8223..2eeb1cf135f2cb 100644
--- a/Modules/_testlimitedcapi.c
+++ b/Modules/_testlimitedcapi.c
@@ -50,6 +50,9 @@ PyInit__testlimitedcapi(void)
if (_PyTestLimitedCAPI_Init_HeaptypeRelative(mod) < 0) {
return NULL;
}
+ if (_PyTestLimitedCAPI_Init_Import(mod) < 0) {
+ return NULL;
+ }
if (_PyTestLimitedCAPI_Init_List(mod) < 0) {
return NULL;
}
diff --git a/Modules/_testlimitedcapi/import.c b/Modules/_testlimitedcapi/import.c
new file mode 100644
index 00000000000000..3707dbedeea0d9
--- /dev/null
+++ b/Modules/_testlimitedcapi/import.c
@@ -0,0 +1,306 @@
+// Need limited C API version 3.13 for PyImport_AddModuleRef()
+#include "pyconfig.h" // Py_GIL_DISABLED
+#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
+# define Py_LIMITED_API 0x030d0000
+#endif
+
+#include "parts.h"
+#include "util.h"
+
+
+/* Test PyImport_GetMagicNumber() */
+static PyObject *
+pyimport_getmagicnumber(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
+{
+ long magic = PyImport_GetMagicNumber();
+ return PyLong_FromLong(magic);
+}
+
+
+/* Test PyImport_GetMagicTag() */
+static PyObject *
+pyimport_getmagictag(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
+{
+ const char *tag = PyImport_GetMagicTag();
+ return PyUnicode_FromString(tag);
+}
+
+
+/* Test PyImport_GetModuleDict() */
+static PyObject *
+pyimport_getmoduledict(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
+{
+ return Py_XNewRef(PyImport_GetModuleDict());
+}
+
+
+/* Test PyImport_GetModule() */
+static PyObject *
+pyimport_getmodule(PyObject *Py_UNUSED(module), PyObject *name)
+{
+ assert(!PyErr_Occurred());
+ NULLABLE(name);
+ PyObject *module = PyImport_GetModule(name);
+ if (module == NULL && !PyErr_Occurred()) {
+ return Py_NewRef(PyExc_KeyError);
+ }
+ return module;
+}
+
+
+/* Test PyImport_AddModuleObject() */
+static PyObject *
+pyimport_addmoduleobject(PyObject *Py_UNUSED(module), PyObject *name)
+{
+ NULLABLE(name);
+ return Py_XNewRef(PyImport_AddModuleObject(name));
+}
+
+
+/* Test PyImport_AddModule() */
+static PyObject *
+pyimport_addmodule(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ return Py_XNewRef(PyImport_AddModule(name));
+}
+
+
+/* Test PyImport_AddModuleRef() */
+static PyObject *
+pyimport_addmoduleref(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ return PyImport_AddModuleRef(name);
+}
+
+
+/* Test PyImport_Import() */
+static PyObject *
+pyimport_import(PyObject *Py_UNUSED(module), PyObject *name)
+{
+ NULLABLE(name);
+ return PyImport_Import(name);
+}
+
+
+/* Test PyImport_ImportModule() */
+static PyObject *
+pyimport_importmodule(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ return PyImport_ImportModule(name);
+}
+
+
+/* Test PyImport_ImportModuleNoBlock() */
+static PyObject *
+pyimport_importmodulenoblock(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ _Py_COMP_DIAG_PUSH
+ _Py_COMP_DIAG_IGNORE_DEPR_DECLS
+ return PyImport_ImportModuleNoBlock(name);
+ _Py_COMP_DIAG_POP
+}
+
+
+/* Test PyImport_ImportModuleEx() */
+static PyObject *
+pyimport_importmoduleex(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *globals, *locals, *fromlist;
+ if (!PyArg_ParseTuple(args, "z#OOO",
+ &name, &size, &globals, &locals, &fromlist)) {
+ return NULL;
+ }
+ NULLABLE(globals);
+ NULLABLE(locals);
+ NULLABLE(fromlist);
+
+ return PyImport_ImportModuleEx(name, globals, locals, fromlist);
+}
+
+
+/* Test PyImport_ImportModuleLevel() */
+static PyObject *
+pyimport_importmodulelevel(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *globals, *locals, *fromlist;
+ int level;
+ if (!PyArg_ParseTuple(args, "z#OOOi",
+ &name, &size, &globals, &locals, &fromlist, &level)) {
+ return NULL;
+ }
+ NULLABLE(globals);
+ NULLABLE(locals);
+ NULLABLE(fromlist);
+
+ return PyImport_ImportModuleLevel(name, globals, locals, fromlist, level);
+}
+
+
+/* Test PyImport_ImportModuleLevelObject() */
+static PyObject *
+pyimport_importmodulelevelobject(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ PyObject *name, *globals, *locals, *fromlist;
+ int level;
+ if (!PyArg_ParseTuple(args, "OOOOi",
+ &name, &globals, &locals, &fromlist, &level)) {
+ return NULL;
+ }
+ NULLABLE(name);
+ NULLABLE(globals);
+ NULLABLE(locals);
+ NULLABLE(fromlist);
+
+ return PyImport_ImportModuleLevelObject(name, globals, locals, fromlist, level);
+}
+
+
+/* Test PyImport_ImportFrozenModule() */
+static PyObject *
+pyimport_importfrozenmodule(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ RETURN_INT(PyImport_ImportFrozenModule(name));
+}
+
+
+/* Test PyImport_ImportFrozenModuleObject() */
+static PyObject *
+pyimport_importfrozenmoduleobject(PyObject *Py_UNUSED(module), PyObject *name)
+{
+ NULLABLE(name);
+ RETURN_INT(PyImport_ImportFrozenModuleObject(name));
+}
+
+
+/* Test PyImport_ExecCodeModule() */
+static PyObject *
+pyimport_executecodemodule(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *code;
+ if (!PyArg_ParseTuple(args, "z#O", &name, &size, &code)) {
+ return NULL;
+ }
+ NULLABLE(code);
+
+ return PyImport_ExecCodeModule(name, code);
+}
+
+
+/* Test PyImport_ExecCodeModuleEx() */
+static PyObject *
+pyimport_executecodemoduleex(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *code;
+ const char *pathname;
+ if (!PyArg_ParseTuple(args, "z#Oz#", &name, &size, &code, &pathname, &size)) {
+ return NULL;
+ }
+ NULLABLE(code);
+
+ return PyImport_ExecCodeModuleEx(name, code, pathname);
+}
+
+
+/* Test PyImport_ExecCodeModuleWithPathnames() */
+static PyObject *
+pyimport_executecodemodulewithpathnames(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *code;
+ const char *pathname;
+ const char *cpathname;
+ if (!PyArg_ParseTuple(args, "z#Oz#z#", &name, &size, &code, &pathname, &size, &cpathname, &size)) {
+ return NULL;
+ }
+ NULLABLE(code);
+
+ return PyImport_ExecCodeModuleWithPathnames(name, code,
+ pathname, cpathname);
+}
+
+
+/* Test PyImport_ExecCodeModuleObject() */
+static PyObject *
+pyimport_executecodemoduleobject(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ PyObject *name, *code, *pathname, *cpathname;
+ if (!PyArg_ParseTuple(args, "OOOO", &name, &code, &pathname, &cpathname)) {
+ return NULL;
+ }
+ NULLABLE(name);
+ NULLABLE(code);
+ NULLABLE(pathname);
+ NULLABLE(cpathname);
+
+ return PyImport_ExecCodeModuleObject(name, code, pathname, cpathname);
+}
+
+
+static PyMethodDef test_methods[] = {
+ {"PyImport_GetMagicNumber", pyimport_getmagicnumber, METH_NOARGS},
+ {"PyImport_GetMagicTag", pyimport_getmagictag, METH_NOARGS},
+ {"PyImport_GetModuleDict", pyimport_getmoduledict, METH_NOARGS},
+ {"PyImport_GetModule", pyimport_getmodule, METH_O},
+ {"PyImport_AddModuleObject", pyimport_addmoduleobject, METH_O},
+ {"PyImport_AddModule", pyimport_addmodule, METH_VARARGS},
+ {"PyImport_AddModuleRef", pyimport_addmoduleref, METH_VARARGS},
+ {"PyImport_Import", pyimport_import, METH_O},
+ {"PyImport_ImportModule", pyimport_importmodule, METH_VARARGS},
+ {"PyImport_ImportModuleNoBlock", pyimport_importmodulenoblock, METH_VARARGS},
+ {"PyImport_ImportModuleEx", pyimport_importmoduleex, METH_VARARGS},
+ {"PyImport_ImportModuleLevel", pyimport_importmodulelevel, METH_VARARGS},
+ {"PyImport_ImportModuleLevelObject", pyimport_importmodulelevelobject, METH_VARARGS},
+ {"PyImport_ImportFrozenModule", pyimport_importfrozenmodule, METH_VARARGS},
+ {"PyImport_ImportFrozenModuleObject", pyimport_importfrozenmoduleobject, METH_O},
+ {"PyImport_ExecCodeModule", pyimport_executecodemodule, METH_VARARGS},
+ {"PyImport_ExecCodeModuleEx", pyimport_executecodemoduleex, METH_VARARGS},
+ {"PyImport_ExecCodeModuleWithPathnames", pyimport_executecodemodulewithpathnames, METH_VARARGS},
+ {"PyImport_ExecCodeModuleObject", pyimport_executecodemoduleobject, METH_VARARGS},
+ {NULL},
+};
+
+
+int
+_PyTestLimitedCAPI_Init_Import(PyObject *module)
+{
+ return PyModule_AddFunctions(module, test_methods);
+}
diff --git a/Modules/_testlimitedcapi/parts.h b/Modules/_testlimitedcapi/parts.h
index 140396d6b990ff..ac938a13d5984e 100644
--- a/Modules/_testlimitedcapi/parts.h
+++ b/Modules/_testlimitedcapi/parts.h
@@ -29,6 +29,7 @@ int _PyTestLimitedCAPI_Init_Complex(PyObject *module);
int _PyTestLimitedCAPI_Init_Dict(PyObject *module);
int _PyTestLimitedCAPI_Init_Float(PyObject *module);
int _PyTestLimitedCAPI_Init_HeaptypeRelative(PyObject *module);
+int _PyTestLimitedCAPI_Init_Import(PyObject *module);
int _PyTestLimitedCAPI_Init_Object(PyObject *module);
int _PyTestLimitedCAPI_Init_List(PyObject *module);
int _PyTestLimitedCAPI_Init_Long(PyObject *module);
diff --git a/PCbuild/_testlimitedcapi.vcxproj b/PCbuild/_testlimitedcapi.vcxproj
index 7e5809fec31791..afadfb9d060bf2 100644
--- a/PCbuild/_testlimitedcapi.vcxproj
+++ b/PCbuild/_testlimitedcapi.vcxproj
@@ -101,6 +101,7 @@
<ClCompile Include="..\Modules\_testlimitedcapi\dict.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />
+ <ClCompile Include="..\Modules\_testlimitedcapi\import.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\list.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\long.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\object.c" />
diff --git a/PCbuild/_testlimitedcapi.vcxproj.filters b/PCbuild/_testlimitedcapi.vcxproj.filters
index 47f059040bed91..89559a27d647fc 100644
--- a/PCbuild/_testlimitedcapi.vcxproj.filters
+++ b/PCbuild/_testlimitedcapi.vcxproj.filters
@@ -16,6 +16,7 @@
<ClCompile Include="..\Modules\_testlimitedcapi\dict.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />
+ <ClCompile Include="..\Modules\_testlimitedcapi\import.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\list.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\long.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\object.c" />
1
0
gh-128955: Fix goto if tlbc creation fails when throwing into a generator (#128957)
by mpage Jan. 17, 2025
by mpage Jan. 17, 2025
Jan. 17, 2025
https://github.com/python/cpython/commit/13c4def692228f09df0b30c5f93bc515e8…
commit: 13c4def692228f09df0b30c5f93bc515e89fc77f
branch: main
author: mpage <mpage(a)meta.com>
committer: mpage <mpage(a)cs.stanford.edu>
date: 2025-01-17T12:53:29-08:00
summary:
gh-128955: Fix goto if tlbc creation fails when throwing into a generator (#128957)
We don't have the correct copy of the bytecode and can't update next_instr
appropriately, so just unwind.
files:
M Python/ceval.c
diff --git a/Python/ceval.c b/Python/ceval.c
index e0362c3c89fe6a..28b0b4c6de39a7 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -846,7 +846,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
_Py_CODEUNIT *bytecode =
_PyEval_GetExecutableCode(tstate, _PyFrame_GetCode(frame));
if (bytecode == NULL) {
- goto error;
+ goto exit_unwind;
}
ptrdiff_t off = frame->instr_ptr - _PyFrame_GetBytecode(frame);
frame->tlbc_index = ((_PyThreadStateImpl *)tstate)->tlbc_index;
1
0
Jan. 17, 2025
https://github.com/python/cpython/commit/f45da82c11a0fcbc28c099af27e47806f5…
commit: f45da82c11a0fcbc28c099af27e47806f530a97b
branch: 3.12
author: Tian Gao <gaogaotiantian(a)hotmail.com>
committer: gaogaotiantian <gaogaotiantian(a)hotmail.com>
date: 2025-01-17T14:19:37-05:00
summary:
[3.12] gh-58956: Fix a frame refleak in bdb (GH-128190) (#128953)
* [3.12] gh-58956: Fix a frame refleak in bdb (GH-128190)
(cherry picked from commit 767c89ba7c5a70626df6e75eb56b546bf911b997)
Co-authored-by: Tian Gao <gaogaotiantian(a)hotmail.com>
files:
A Misc/NEWS.d/next/Library/2024-12-23-02-09-44.gh-issue-58956.4OdMdT.rst
M Lib/bdb.py
M Lib/pdb.py
M Lib/test/test_pdb.py
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 196e6b178cb9fd..3486deacd86a7c 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -340,6 +340,7 @@ def set_trace(self, frame=None):
self.botframe = frame
frame = frame.f_back
self.set_step()
+ self.enterframe = None
sys.settrace(self.trace_dispatch)
def set_continue(self):
@@ -356,6 +357,7 @@ def set_continue(self):
while frame and frame is not self.botframe:
del frame.f_trace
frame = frame.f_back
+ self.enterframe = None
def set_quit(self):
"""Set quitting attribute to True.
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 1e1b5ea4f0a184..2a6e994dac1073 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -281,6 +281,7 @@ def forget(self):
if hasattr(self, 'curframe') and self.curframe:
self.curframe.f_globals.pop('__pdb_convenience_variables', None)
self.curframe = None
+ self.curframe_locals = {}
self.tb_lineno.clear()
def setup(self, f, tb):
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index bd61de0ad3494c..778aa03a63ab63 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -1981,6 +1981,58 @@ def test_pdb_ambiguous_statements():
(Pdb) continue
"""
+def test_pdb_frame_refleak():
+ """
+ pdb should not leak reference to frames
+
+ >>> def frame_leaker(container):
+ ... import sys
+ ... container.append(sys._getframe())
+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ ... pass
+
+ >>> def test_function():
+ ... import gc
+ ... container = []
+ ... frame_leaker(container) # c
+ ... print(len(gc.get_referrers(container[0])))
+ ... container = []
+ ... frame_leaker(container) # n c
+ ... print(len(gc.get_referrers(container[0])))
+ ... container = []
+ ... frame_leaker(container) # r c
+ ... print(len(gc.get_referrers(container[0])))
+
+ >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
+ ... 'continue',
+ ... 'next',
+ ... 'continue',
+ ... 'return',
+ ... 'continue',
+ ... ]):
+ ... test_function()
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(5)frame_leaker()
+ -> pass
+ (Pdb) continue
+ 1
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(5)frame_leaker()
+ -> pass
+ (Pdb) next
+ --Return--
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(5)frame_leaker()->None
+ -> pass
+ (Pdb) continue
+ 1
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(5)frame_leaker()
+ -> pass
+ (Pdb) return
+ --Return--
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(5)frame_leaker()->None
+ -> pass
+ (Pdb) continue
+ 1
+ """
+
def test_pdb_issue_gh_65052():
"""See GH-65052
diff --git a/Misc/NEWS.d/next/Library/2024-12-23-02-09-44.gh-issue-58956.4OdMdT.rst b/Misc/NEWS.d/next/Library/2024-12-23-02-09-44.gh-issue-58956.4OdMdT.rst
new file mode 100644
index 00000000000000..b78bc5aaf44217
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-12-23-02-09-44.gh-issue-58956.4OdMdT.rst
@@ -0,0 +1 @@
+Fixed a frame reference leak in :mod:`bdb`.
1
0
https://github.com/python/cpython/commit/d95ba9fa1110534b7247fa2ff12b90e930…
commit: d95ba9fa1110534b7247fa2ff12b90e930c93256
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-17T17:52:18Z
summary:
gh-128911: Add tests on the PyImport C API (#128915)
* Add Modules/_testlimitedcapi/import.c
* Add Lib/test/test_capi/test_import.py
* Remove _testcapi.check_pyimport_addmodule(): tests already covered
by newly added tests.
Co-authored-by: Serhiy Storchaka <storchaka(a)gmail.com>
files:
A Lib/test/test_capi/test_import.py
A Modules/_testlimitedcapi/import.c
M Lib/test/test_import/__init__.py
M Modules/Setup.stdlib.in
M Modules/_testcapimodule.c
M Modules/_testlimitedcapi.c
M Modules/_testlimitedcapi/parts.h
M PCbuild/_testlimitedcapi.vcxproj
M PCbuild/_testlimitedcapi.vcxproj.filters
diff --git a/Lib/test/test_capi/test_import.py b/Lib/test/test_capi/test_import.py
new file mode 100644
index 00000000000000..94f96728d9174b
--- /dev/null
+++ b/Lib/test/test_capi/test_import.py
@@ -0,0 +1,327 @@
+import importlib.util
+import os.path
+import sys
+import types
+import unittest
+from test.support import os_helper
+from test.support import import_helper
+from test.support.warnings_helper import check_warnings
+
+_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
+NULL = None
+
+
+class ImportTests(unittest.TestCase):
+ def test_getmagicnumber(self):
+ # Test PyImport_GetMagicNumber()
+ magic = _testlimitedcapi.PyImport_GetMagicNumber()
+ self.assertEqual(magic,
+ int.from_bytes(importlib.util.MAGIC_NUMBER, 'little'))
+
+ def test_getmagictag(self):
+ # Test PyImport_GetMagicTag()
+ tag = _testlimitedcapi.PyImport_GetMagicTag()
+ self.assertEqual(tag, sys.implementation.cache_tag)
+
+ def test_getmoduledict(self):
+ # Test PyImport_GetModuleDict()
+ modules = _testlimitedcapi.PyImport_GetModuleDict()
+ self.assertIs(modules, sys.modules)
+
+ def check_import_loaded_module(self, import_module):
+ for name in ('os', 'sys', 'test', 'unittest'):
+ with self.subTest(name=name):
+ self.assertIn(name, sys.modules)
+ old_module = sys.modules[name]
+ module = import_module(name)
+ self.assertIsInstance(module, types.ModuleType)
+ self.assertIs(module, old_module)
+
+ def check_import_fresh_module(self, import_module):
+ old_modules = dict(sys.modules)
+ try:
+ for name in ('colorsys', 'math'):
+ with self.subTest(name=name):
+ sys.modules.pop(name, None)
+ module = import_module(name)
+ self.assertIsInstance(module, types.ModuleType)
+ self.assertIs(module, sys.modules[name])
+ self.assertEqual(module.__name__, name)
+ finally:
+ sys.modules.clear()
+ sys.modules.update(old_modules)
+
+ def test_getmodule(self):
+ # Test PyImport_GetModule()
+ getmodule = _testlimitedcapi.PyImport_GetModule
+ self.check_import_loaded_module(getmodule)
+
+ nonexistent = 'nonexistent'
+ self.assertNotIn(nonexistent, sys.modules)
+ self.assertIs(getmodule(nonexistent), KeyError)
+ self.assertIs(getmodule(''), KeyError)
+ self.assertIs(getmodule(object()), KeyError)
+
+ self.assertRaises(TypeError, getmodule, []) # unhashable
+ # CRASHES getmodule(NULL)
+
+ def check_addmodule(self, add_module, accept_nonstr=False):
+ # create a new module
+ names = ['nonexistent']
+ if accept_nonstr:
+ names.append(b'\xff') # non-UTF-8
+ # PyImport_AddModuleObject() accepts non-string names
+ names.append(tuple(['hashable non-string']))
+ for name in names:
+ with self.subTest(name=name):
+ self.assertNotIn(name, sys.modules)
+ try:
+ module = add_module(name)
+ self.assertIsInstance(module, types.ModuleType)
+ self.assertEqual(module.__name__, name)
+ self.assertIs(module, sys.modules[name])
+ finally:
+ sys.modules.pop(name, None)
+
+ # get an existing module
+ self.check_import_loaded_module(add_module)
+
+ def test_addmoduleobject(self):
+ # Test PyImport_AddModuleObject()
+ addmoduleobject = _testlimitedcapi.PyImport_AddModuleObject
+ self.check_addmodule(addmoduleobject, accept_nonstr=True)
+
+ self.assertRaises(TypeError, addmoduleobject, []) # unhashable
+ # CRASHES addmoduleobject(NULL)
+
+ def test_addmodule(self):
+ # Test PyImport_AddModule()
+ addmodule = _testlimitedcapi.PyImport_AddModule
+ self.check_addmodule(addmodule)
+
+ self.assertRaises(UnicodeDecodeError, addmodule, b'\xff')
+ # CRASHES addmodule(NULL)
+
+ def test_addmoduleref(self):
+ # Test PyImport_AddModuleRef()
+ addmoduleref = _testlimitedcapi.PyImport_AddModuleRef
+ self.check_addmodule(addmoduleref)
+
+ self.assertRaises(UnicodeDecodeError, addmoduleref, b'\xff')
+ # CRASHES addmoduleref(NULL)
+
+ def check_import_func(self, import_module):
+ self.check_import_loaded_module(import_module)
+ self.check_import_fresh_module(import_module)
+ self.assertRaises(ModuleNotFoundError, import_module, 'nonexistent')
+ self.assertRaises(ValueError, import_module, '')
+
+ def test_import(self):
+ # Test PyImport_Import()
+ import_ = _testlimitedcapi.PyImport_Import
+ self.check_import_func(import_)
+
+ self.assertRaises(TypeError, import_, b'os')
+ self.assertRaises(SystemError, import_, NULL)
+
+ def test_importmodule(self):
+ # Test PyImport_ImportModule()
+ importmodule = _testlimitedcapi.PyImport_ImportModule
+ self.check_import_func(importmodule)
+
+ self.assertRaises(UnicodeDecodeError, importmodule, b'\xff')
+ # CRASHES importmodule(NULL)
+
+ def test_importmodulenoblock(self):
+ # Test deprecated PyImport_ImportModuleNoBlock()
+ importmodulenoblock = _testlimitedcapi.PyImport_ImportModuleNoBlock
+ with check_warnings(('', DeprecationWarning)):
+ self.check_import_func(importmodulenoblock)
+ self.assertRaises(UnicodeDecodeError, importmodulenoblock, b'\xff')
+
+ # CRASHES importmodulenoblock(NULL)
+
+ def check_frozen_import(self, import_frozen_module):
+ # Importing a frozen module executes its code, so start by unloading
+ # the module to execute the code in a new (temporary) module.
+ old_zipimport = sys.modules.pop('zipimport')
+ try:
+ self.assertEqual(import_frozen_module('zipimport'), 1)
+
+ # import zipimport again
+ self.assertEqual(import_frozen_module('zipimport'), 1)
+ finally:
+ sys.modules['zipimport'] = old_zipimport
+
+ # not a frozen module
+ self.assertEqual(import_frozen_module('sys'), 0)
+ self.assertEqual(import_frozen_module('nonexistent'), 0)
+ self.assertEqual(import_frozen_module(''), 0)
+
+ def test_importfrozenmodule(self):
+ # Test PyImport_ImportFrozenModule()
+ importfrozenmodule = _testlimitedcapi.PyImport_ImportFrozenModule
+ self.check_frozen_import(importfrozenmodule)
+
+ self.assertRaises(UnicodeDecodeError, importfrozenmodule, b'\xff')
+ # CRASHES importfrozenmodule(NULL)
+
+ def test_importfrozenmoduleobject(self):
+ # Test PyImport_ImportFrozenModuleObject()
+ importfrozenmoduleobject = _testlimitedcapi.PyImport_ImportFrozenModuleObject
+ self.check_frozen_import(importfrozenmoduleobject)
+ self.assertEqual(importfrozenmoduleobject(b'zipimport'), 0)
+ self.assertEqual(importfrozenmoduleobject(NULL), 0)
+
+ def test_importmoduleex(self):
+ # Test PyImport_ImportModuleEx()
+ importmoduleex = _testlimitedcapi.PyImport_ImportModuleEx
+ self.check_import_func(lambda name: importmoduleex(name, NULL, NULL, NULL))
+
+ self.assertRaises(ModuleNotFoundError, importmoduleex, 'nonexistent', NULL, NULL, NULL)
+ self.assertRaises(ValueError, importmoduleex, '', NULL, NULL, NULL)
+ self.assertRaises(UnicodeDecodeError, importmoduleex, b'\xff', NULL, NULL, NULL)
+ # CRASHES importmoduleex(NULL, NULL, NULL, NULL)
+
+ def check_importmodulelevel(self, importmodulelevel):
+ self.check_import_func(lambda name: importmodulelevel(name, NULL, NULL, NULL, 0))
+
+ self.assertRaises(ModuleNotFoundError, importmodulelevel, 'nonexistent', NULL, NULL, NULL, 0)
+ self.assertRaises(ValueError, importmodulelevel, '', NULL, NULL, NULL, 0)
+
+ if __package__:
+ self.assertIs(importmodulelevel('test_import', globals(), NULL, NULL, 1),
+ sys.modules['test.test_capi.test_import'])
+ self.assertIs(importmodulelevel('test_capi', globals(), NULL, NULL, 2),
+ sys.modules['test.test_capi'])
+ self.assertRaises(ValueError, importmodulelevel, 'os', NULL, NULL, NULL, -1)
+ with self.assertWarns(ImportWarning):
+ self.assertRaises(KeyError, importmodulelevel, 'test_import', {}, NULL, NULL, 1)
+ self.assertRaises(TypeError, importmodulelevel, 'test_import', [], NULL, NULL, 1)
+
+ def test_importmodulelevel(self):
+ # Test PyImport_ImportModuleLevel()
+ importmodulelevel = _testlimitedcapi.PyImport_ImportModuleLevel
+ self.check_importmodulelevel(importmodulelevel)
+
+ self.assertRaises(UnicodeDecodeError, importmodulelevel, b'\xff', NULL, NULL, NULL, 0)
+ # CRASHES importmodulelevel(NULL, NULL, NULL, NULL, 0)
+
+ def test_importmodulelevelobject(self):
+ # Test PyImport_ImportModuleLevelObject()
+ importmodulelevel = _testlimitedcapi.PyImport_ImportModuleLevelObject
+ self.check_importmodulelevel(importmodulelevel)
+
+ self.assertRaises(TypeError, importmodulelevel, b'os', NULL, NULL, NULL, 0)
+ self.assertRaises(ValueError, importmodulelevel, NULL, NULL, NULL, NULL, 0)
+
+ def check_executecodemodule(self, execute_code, *args):
+ name = 'test_import_executecode'
+ try:
+ # Create a temporary module where the code will be executed
+ self.assertNotIn(name, sys.modules)
+ module = _testlimitedcapi.PyImport_AddModuleRef(name)
+ self.assertNotHasAttr(module, 'attr')
+
+ # Execute the code
+ code = compile('attr = 1', '<test>', 'exec')
+ module2 = execute_code(name, code, *args)
+ self.assertIs(module2, module)
+
+ # Check the function side effects
+ self.assertEqual(module.attr, 1)
+ finally:
+ sys.modules.pop(name, None)
+ return module.__spec__.origin
+
+ def test_executecodemodule(self):
+ # Test PyImport_ExecCodeModule()
+ execcodemodule = _testlimitedcapi.PyImport_ExecCodeModule
+ self.check_executecodemodule(execcodemodule)
+
+ code = compile('attr = 1', '<test>', 'exec')
+ self.assertRaises(UnicodeDecodeError, execcodemodule, b'\xff', code)
+ # CRASHES execcodemodule(NULL, code)
+ # CRASHES execcodemodule(name, NULL)
+
+ def test_executecodemoduleex(self):
+ # Test PyImport_ExecCodeModuleEx()
+ execcodemoduleex = _testlimitedcapi.PyImport_ExecCodeModuleEx
+
+ # Test NULL path (it should not crash)
+ self.check_executecodemodule(execcodemoduleex, NULL)
+
+ # Test non-NULL path
+ pathname = b'pathname'
+ origin = self.check_executecodemodule(execcodemoduleex, pathname)
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+
+ pathname = os_helper.TESTFN_UNDECODABLE
+ if pathname:
+ origin = self.check_executecodemodule(execcodemoduleex, pathname)
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+
+ code = compile('attr = 1', '<test>', 'exec')
+ self.assertRaises(UnicodeDecodeError, execcodemoduleex, b'\xff', code, NULL)
+ # CRASHES execcodemoduleex(NULL, code, NULL)
+ # CRASHES execcodemoduleex(name, NULL, NULL)
+
+ def check_executecode_pathnames(self, execute_code_func, object=False):
+ # Test non-NULL pathname and NULL cpathname
+
+ # Test NULL paths (it should not crash)
+ self.check_executecodemodule(execute_code_func, NULL, NULL)
+
+ pathname = 'pathname'
+ origin = self.check_executecodemodule(execute_code_func, pathname, NULL)
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+ origin = self.check_executecodemodule(execute_code_func, NULL, pathname)
+ if not object:
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+
+ pathname = os_helper.TESTFN_UNDECODABLE
+ if pathname:
+ if object:
+ pathname = os.fsdecode(pathname)
+ origin = self.check_executecodemodule(execute_code_func, pathname, NULL)
+ self.assertEqual(origin, os.path.abspath(os.fsdecode(pathname)))
+ self.check_executecodemodule(execute_code_func, NULL, pathname)
+
+ # Test NULL pathname and non-NULL cpathname
+ pyc_filename = importlib.util.cache_from_source(__file__)
+ py_filename = importlib.util.source_from_cache(pyc_filename)
+ origin = self.check_executecodemodule(execute_code_func, NULL, pyc_filename)
+ if not object:
+ self.assertEqual(origin, py_filename)
+
+ def test_executecodemodulewithpathnames(self):
+ # Test PyImport_ExecCodeModuleWithPathnames()
+ execute_code_func = _testlimitedcapi.PyImport_ExecCodeModuleWithPathnames
+ self.check_executecode_pathnames(execute_code_func)
+
+ code = compile('attr = 1', '<test>', 'exec')
+ self.assertRaises(UnicodeDecodeError, execute_code_func, b'\xff', code, NULL, NULL)
+ # CRASHES execute_code_func(NULL, code, NULL, NULL)
+ # CRASHES execute_code_func(name, NULL, NULL, NULL)
+
+ def test_executecodemoduleobject(self):
+ # Test PyImport_ExecCodeModuleObject()
+ execute_code_func = _testlimitedcapi.PyImport_ExecCodeModuleObject
+ self.check_executecode_pathnames(execute_code_func, object=True)
+
+ code = compile('attr = 1', '<test>', 'exec')
+ self.assertRaises(TypeError, execute_code_func, [], code, NULL, NULL)
+ nonstring = tuple(['hashable non-string'])
+ self.assertRaises(AttributeError, execute_code_func, nonstring, code, NULL, NULL)
+ sys.modules.pop(nonstring, None)
+ # CRASHES execute_code_func(NULL, code, NULL, NULL)
+ # CRASHES execute_code_func(name, NULL, NULL, NULL)
+
+ # TODO: test PyImport_GetImporter()
+ # TODO: test PyImport_ReloadModule()
+ # TODO: test PyImport_ExtendInittab()
+ # PyImport_AppendInittab() is tested by test_embed
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py
index c2cec6444cb43a..1e706023c795b6 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -3311,30 +3311,6 @@ def test_basic_multiple_interpreters_reset_each(self):
# * module's global state was initialized, not reset
-@cpython_only
-class CAPITests(unittest.TestCase):
- def test_pyimport_addmodule(self):
- # gh-105922: Test PyImport_AddModuleRef(), PyImport_AddModule()
- # and PyImport_AddModuleObject()
- _testcapi = import_module("_testcapi")
- for name in (
- 'sys', # frozen module
- 'test', # package
- __name__, # package.module
- ):
- _testcapi.check_pyimport_addmodule(name)
-
- def test_pyimport_addmodule_create(self):
- # gh-105922: Test PyImport_AddModuleRef(), create a new module
- _testcapi = import_module("_testcapi")
- name = 'dontexist'
- self.assertNotIn(name, sys.modules)
- self.addCleanup(unload, name)
-
- mod = _testcapi.check_pyimport_addmodule(name)
- self.assertIs(mod, sys.modules[name])
-
-
@cpython_only
class TestMagicNumber(unittest.TestCase):
def test_magic_number_endianness(self):
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in
index b7357f41768a2f..6b6a8ae57a5119 100644
--- a/Modules/Setup.stdlib.in
+++ b/Modules/Setup.stdlib.in
@@ -163,7 +163,7 @@
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c
@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/run.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/hash.c _testcapi/time.c _testcapi/bytes.c _testcapi/object.c _testcapi/monitoring.c _testcapi/config.c
-@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/codec.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/eval.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/tuple.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c _testlimitedcapi/version.c
+@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/codec.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/eval.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/import.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/tuple.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c _testlimitedcapi/version.c
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
@MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index b657bb665bd5c5..996b96bc000450 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -3059,52 +3059,6 @@ function_set_closure(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
-static PyObject *
-check_pyimport_addmodule(PyObject *self, PyObject *args)
-{
- const char *name;
- if (!PyArg_ParseTuple(args, "s", &name)) {
- return NULL;
- }
-
- // test PyImport_AddModuleRef()
- PyObject *module = PyImport_AddModuleRef(name);
- if (module == NULL) {
- return NULL;
- }
- assert(PyModule_Check(module));
- // module is a strong reference
-
- // test PyImport_AddModule()
- PyObject *module2 = PyImport_AddModule(name);
- if (module2 == NULL) {
- goto error;
- }
- assert(PyModule_Check(module2));
- assert(module2 == module);
- // module2 is a borrowed ref
-
- // test PyImport_AddModuleObject()
- PyObject *name_obj = PyUnicode_FromString(name);
- if (name_obj == NULL) {
- goto error;
- }
- PyObject *module3 = PyImport_AddModuleObject(name_obj);
- Py_DECREF(name_obj);
- if (module3 == NULL) {
- goto error;
- }
- assert(PyModule_Check(module3));
- assert(module3 == module);
- // module3 is a borrowed ref
-
- return module;
-
-error:
- Py_DECREF(module);
- return NULL;
-}
-
static PyObject *
test_weakref_capi(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
@@ -3668,7 +3622,6 @@ static PyMethodDef TestMethods[] = {
{"function_set_kw_defaults", function_set_kw_defaults, METH_VARARGS, NULL},
{"function_get_closure", function_get_closure, METH_O, NULL},
{"function_set_closure", function_set_closure, METH_VARARGS, NULL},
- {"check_pyimport_addmodule", check_pyimport_addmodule, METH_VARARGS},
{"test_weakref_capi", test_weakref_capi, METH_NOARGS},
{"function_set_warning", function_set_warning, METH_NOARGS},
{"test_critical_sections", test_critical_sections, METH_NOARGS},
diff --git a/Modules/_testlimitedcapi.c b/Modules/_testlimitedcapi.c
index bcc69a339ec5c4..82dac1c999470f 100644
--- a/Modules/_testlimitedcapi.c
+++ b/Modules/_testlimitedcapi.c
@@ -56,6 +56,9 @@ PyInit__testlimitedcapi(void)
if (_PyTestLimitedCAPI_Init_HeaptypeRelative(mod) < 0) {
return NULL;
}
+ if (_PyTestLimitedCAPI_Init_Import(mod) < 0) {
+ return NULL;
+ }
if (_PyTestLimitedCAPI_Init_List(mod) < 0) {
return NULL;
}
diff --git a/Modules/_testlimitedcapi/import.c b/Modules/_testlimitedcapi/import.c
new file mode 100644
index 00000000000000..3707dbedeea0d9
--- /dev/null
+++ b/Modules/_testlimitedcapi/import.c
@@ -0,0 +1,306 @@
+// Need limited C API version 3.13 for PyImport_AddModuleRef()
+#include "pyconfig.h" // Py_GIL_DISABLED
+#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
+# define Py_LIMITED_API 0x030d0000
+#endif
+
+#include "parts.h"
+#include "util.h"
+
+
+/* Test PyImport_GetMagicNumber() */
+static PyObject *
+pyimport_getmagicnumber(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
+{
+ long magic = PyImport_GetMagicNumber();
+ return PyLong_FromLong(magic);
+}
+
+
+/* Test PyImport_GetMagicTag() */
+static PyObject *
+pyimport_getmagictag(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
+{
+ const char *tag = PyImport_GetMagicTag();
+ return PyUnicode_FromString(tag);
+}
+
+
+/* Test PyImport_GetModuleDict() */
+static PyObject *
+pyimport_getmoduledict(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
+{
+ return Py_XNewRef(PyImport_GetModuleDict());
+}
+
+
+/* Test PyImport_GetModule() */
+static PyObject *
+pyimport_getmodule(PyObject *Py_UNUSED(module), PyObject *name)
+{
+ assert(!PyErr_Occurred());
+ NULLABLE(name);
+ PyObject *module = PyImport_GetModule(name);
+ if (module == NULL && !PyErr_Occurred()) {
+ return Py_NewRef(PyExc_KeyError);
+ }
+ return module;
+}
+
+
+/* Test PyImport_AddModuleObject() */
+static PyObject *
+pyimport_addmoduleobject(PyObject *Py_UNUSED(module), PyObject *name)
+{
+ NULLABLE(name);
+ return Py_XNewRef(PyImport_AddModuleObject(name));
+}
+
+
+/* Test PyImport_AddModule() */
+static PyObject *
+pyimport_addmodule(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ return Py_XNewRef(PyImport_AddModule(name));
+}
+
+
+/* Test PyImport_AddModuleRef() */
+static PyObject *
+pyimport_addmoduleref(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ return PyImport_AddModuleRef(name);
+}
+
+
+/* Test PyImport_Import() */
+static PyObject *
+pyimport_import(PyObject *Py_UNUSED(module), PyObject *name)
+{
+ NULLABLE(name);
+ return PyImport_Import(name);
+}
+
+
+/* Test PyImport_ImportModule() */
+static PyObject *
+pyimport_importmodule(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ return PyImport_ImportModule(name);
+}
+
+
+/* Test PyImport_ImportModuleNoBlock() */
+static PyObject *
+pyimport_importmodulenoblock(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ _Py_COMP_DIAG_PUSH
+ _Py_COMP_DIAG_IGNORE_DEPR_DECLS
+ return PyImport_ImportModuleNoBlock(name);
+ _Py_COMP_DIAG_POP
+}
+
+
+/* Test PyImport_ImportModuleEx() */
+static PyObject *
+pyimport_importmoduleex(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *globals, *locals, *fromlist;
+ if (!PyArg_ParseTuple(args, "z#OOO",
+ &name, &size, &globals, &locals, &fromlist)) {
+ return NULL;
+ }
+ NULLABLE(globals);
+ NULLABLE(locals);
+ NULLABLE(fromlist);
+
+ return PyImport_ImportModuleEx(name, globals, locals, fromlist);
+}
+
+
+/* Test PyImport_ImportModuleLevel() */
+static PyObject *
+pyimport_importmodulelevel(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *globals, *locals, *fromlist;
+ int level;
+ if (!PyArg_ParseTuple(args, "z#OOOi",
+ &name, &size, &globals, &locals, &fromlist, &level)) {
+ return NULL;
+ }
+ NULLABLE(globals);
+ NULLABLE(locals);
+ NULLABLE(fromlist);
+
+ return PyImport_ImportModuleLevel(name, globals, locals, fromlist, level);
+}
+
+
+/* Test PyImport_ImportModuleLevelObject() */
+static PyObject *
+pyimport_importmodulelevelobject(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ PyObject *name, *globals, *locals, *fromlist;
+ int level;
+ if (!PyArg_ParseTuple(args, "OOOOi",
+ &name, &globals, &locals, &fromlist, &level)) {
+ return NULL;
+ }
+ NULLABLE(name);
+ NULLABLE(globals);
+ NULLABLE(locals);
+ NULLABLE(fromlist);
+
+ return PyImport_ImportModuleLevelObject(name, globals, locals, fromlist, level);
+}
+
+
+/* Test PyImport_ImportFrozenModule() */
+static PyObject *
+pyimport_importfrozenmodule(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_ParseTuple(args, "z#", &name, &size)) {
+ return NULL;
+ }
+
+ RETURN_INT(PyImport_ImportFrozenModule(name));
+}
+
+
+/* Test PyImport_ImportFrozenModuleObject() */
+static PyObject *
+pyimport_importfrozenmoduleobject(PyObject *Py_UNUSED(module), PyObject *name)
+{
+ NULLABLE(name);
+ RETURN_INT(PyImport_ImportFrozenModuleObject(name));
+}
+
+
+/* Test PyImport_ExecCodeModule() */
+static PyObject *
+pyimport_executecodemodule(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *code;
+ if (!PyArg_ParseTuple(args, "z#O", &name, &size, &code)) {
+ return NULL;
+ }
+ NULLABLE(code);
+
+ return PyImport_ExecCodeModule(name, code);
+}
+
+
+/* Test PyImport_ExecCodeModuleEx() */
+static PyObject *
+pyimport_executecodemoduleex(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *code;
+ const char *pathname;
+ if (!PyArg_ParseTuple(args, "z#Oz#", &name, &size, &code, &pathname, &size)) {
+ return NULL;
+ }
+ NULLABLE(code);
+
+ return PyImport_ExecCodeModuleEx(name, code, pathname);
+}
+
+
+/* Test PyImport_ExecCodeModuleWithPathnames() */
+static PyObject *
+pyimport_executecodemodulewithpathnames(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *code;
+ const char *pathname;
+ const char *cpathname;
+ if (!PyArg_ParseTuple(args, "z#Oz#z#", &name, &size, &code, &pathname, &size, &cpathname, &size)) {
+ return NULL;
+ }
+ NULLABLE(code);
+
+ return PyImport_ExecCodeModuleWithPathnames(name, code,
+ pathname, cpathname);
+}
+
+
+/* Test PyImport_ExecCodeModuleObject() */
+static PyObject *
+pyimport_executecodemoduleobject(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ PyObject *name, *code, *pathname, *cpathname;
+ if (!PyArg_ParseTuple(args, "OOOO", &name, &code, &pathname, &cpathname)) {
+ return NULL;
+ }
+ NULLABLE(name);
+ NULLABLE(code);
+ NULLABLE(pathname);
+ NULLABLE(cpathname);
+
+ return PyImport_ExecCodeModuleObject(name, code, pathname, cpathname);
+}
+
+
+static PyMethodDef test_methods[] = {
+ {"PyImport_GetMagicNumber", pyimport_getmagicnumber, METH_NOARGS},
+ {"PyImport_GetMagicTag", pyimport_getmagictag, METH_NOARGS},
+ {"PyImport_GetModuleDict", pyimport_getmoduledict, METH_NOARGS},
+ {"PyImport_GetModule", pyimport_getmodule, METH_O},
+ {"PyImport_AddModuleObject", pyimport_addmoduleobject, METH_O},
+ {"PyImport_AddModule", pyimport_addmodule, METH_VARARGS},
+ {"PyImport_AddModuleRef", pyimport_addmoduleref, METH_VARARGS},
+ {"PyImport_Import", pyimport_import, METH_O},
+ {"PyImport_ImportModule", pyimport_importmodule, METH_VARARGS},
+ {"PyImport_ImportModuleNoBlock", pyimport_importmodulenoblock, METH_VARARGS},
+ {"PyImport_ImportModuleEx", pyimport_importmoduleex, METH_VARARGS},
+ {"PyImport_ImportModuleLevel", pyimport_importmodulelevel, METH_VARARGS},
+ {"PyImport_ImportModuleLevelObject", pyimport_importmodulelevelobject, METH_VARARGS},
+ {"PyImport_ImportFrozenModule", pyimport_importfrozenmodule, METH_VARARGS},
+ {"PyImport_ImportFrozenModuleObject", pyimport_importfrozenmoduleobject, METH_O},
+ {"PyImport_ExecCodeModule", pyimport_executecodemodule, METH_VARARGS},
+ {"PyImport_ExecCodeModuleEx", pyimport_executecodemoduleex, METH_VARARGS},
+ {"PyImport_ExecCodeModuleWithPathnames", pyimport_executecodemodulewithpathnames, METH_VARARGS},
+ {"PyImport_ExecCodeModuleObject", pyimport_executecodemoduleobject, METH_VARARGS},
+ {NULL},
+};
+
+
+int
+_PyTestLimitedCAPI_Init_Import(PyObject *module)
+{
+ return PyModule_AddFunctions(module, test_methods);
+}
diff --git a/Modules/_testlimitedcapi/parts.h b/Modules/_testlimitedcapi/parts.h
index 56d566b66565a3..9efcd8dcb71e5b 100644
--- a/Modules/_testlimitedcapi/parts.h
+++ b/Modules/_testlimitedcapi/parts.h
@@ -31,6 +31,7 @@ int _PyTestLimitedCAPI_Init_Dict(PyObject *module);
int _PyTestLimitedCAPI_Init_Eval(PyObject *module);
int _PyTestLimitedCAPI_Init_Float(PyObject *module);
int _PyTestLimitedCAPI_Init_HeaptypeRelative(PyObject *module);
+int _PyTestLimitedCAPI_Init_Import(PyObject *module);
int _PyTestLimitedCAPI_Init_Object(PyObject *module);
int _PyTestLimitedCAPI_Init_List(PyObject *module);
int _PyTestLimitedCAPI_Init_Long(PyObject *module);
diff --git a/PCbuild/_testlimitedcapi.vcxproj b/PCbuild/_testlimitedcapi.vcxproj
index 0ea5edba3aa9a7..87abff52493098 100644
--- a/PCbuild/_testlimitedcapi.vcxproj
+++ b/PCbuild/_testlimitedcapi.vcxproj
@@ -103,6 +103,7 @@
<ClCompile Include="..\Modules\_testlimitedcapi\eval.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />
+ <ClCompile Include="..\Modules\_testlimitedcapi\import.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\list.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\long.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\object.c" />
diff --git a/PCbuild/_testlimitedcapi.vcxproj.filters b/PCbuild/_testlimitedcapi.vcxproj.filters
index b379090eb599f5..a975a508506905 100644
--- a/PCbuild/_testlimitedcapi.vcxproj.filters
+++ b/PCbuild/_testlimitedcapi.vcxproj.filters
@@ -18,6 +18,7 @@
<ClCompile Include="..\Modules\_testlimitedcapi\eval.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />
+ <ClCompile Include="..\Modules\_testlimitedcapi\import.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\list.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\long.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\object.c" />
1
0
Jan. 17, 2025
https://github.com/python/cpython/commit/dc77f1914d614bab04769616d7bc6674ee…
commit: dc77f1914d614bab04769616d7bc6674ee723f47
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: gaogaotiantian <gaogaotiantian(a)hotmail.com>
date: 2025-01-17T12:49:15-05:00
summary:
[3.13] gh-58956: Fix a frame refleak in bdb (GH-128190) (#128947)
* gh-58956: Fix a frame refleak in bdb (GH-128190)
(cherry picked from commit 767c89ba7c5a70626df6e75eb56b546bf911b997)
Co-authored-by: Tian Gao <gaogaotiantian(a)hotmail.com>
files:
A Misc/NEWS.d/next/Library/2024-12-23-02-09-44.gh-issue-58956.4OdMdT.rst
M Lib/bdb.py
M Lib/pdb.py
M Lib/test/test_pdb.py
diff --git a/Lib/bdb.py b/Lib/bdb.py
index ece0a29fe9f3b1..3a4453d95f6596 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -382,6 +382,7 @@ def set_trace(self, frame=None):
frame.f_trace_lines = True
frame = frame.f_back
self.set_stepinstr()
+ self.enterframe = None
sys.settrace(self.trace_dispatch)
def set_continue(self):
@@ -401,6 +402,7 @@ def set_continue(self):
for frame, (trace_lines, trace_opcodes) in self.frame_trace_lines_opcodes.items():
frame.f_trace_lines, frame.f_trace_opcodes = trace_lines, trace_opcodes
self.frame_trace_lines_opcodes = {}
+ self.enterframe = None
def set_quit(self):
"""Set quitting attribute to True.
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 9b6dffda1cfcd1..cb0a3405c58e55 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -383,6 +383,7 @@ def forget(self):
if hasattr(self, 'curframe') and self.curframe:
self.curframe.f_globals.pop('__pdb_convenience_variables', None)
self.curframe = None
+ self.curframe_locals = {}
self.tb_lineno.clear()
def setup(self, f, tb):
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 5b25f514b9e772..c34046f0e5bb6f 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -2810,6 +2810,57 @@ def test_pdb_f_trace_lines():
(Pdb) continue
"""
+def test_pdb_frame_refleak():
+ """
+ pdb should not leak reference to frames
+
+ >>> def frame_leaker(container):
+ ... import sys
+ ... container.append(sys._getframe())
+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ ... pass
+
+ >>> def test_function():
+ ... import gc
+ ... container = []
+ ... frame_leaker(container) # c
+ ... print(len(gc.get_referrers(container[0])))
+ ... container = []
+ ... frame_leaker(container) # n c
+ ... print(len(gc.get_referrers(container[0])))
+ ... container = []
+ ... frame_leaker(container) # r c
+ ... print(len(gc.get_referrers(container[0])))
+
+ >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
+ ... 'continue',
+ ... 'next',
+ ... 'continue',
+ ... 'return',
+ ... 'continue',
+ ... ]):
+ ... test_function()
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(4)frame_leaker()
+ -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ (Pdb) continue
+ 1
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(4)frame_leaker()
+ -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ (Pdb) next
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(5)frame_leaker()
+ -> pass
+ (Pdb) continue
+ 1
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(4)frame_leaker()
+ -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ (Pdb) return
+ --Return--
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(5)frame_leaker()->None
+ -> pass
+ (Pdb) continue
+ 1
+ """
+
def test_pdb_function_break():
"""Testing the line number of break on function
diff --git a/Misc/NEWS.d/next/Library/2024-12-23-02-09-44.gh-issue-58956.4OdMdT.rst b/Misc/NEWS.d/next/Library/2024-12-23-02-09-44.gh-issue-58956.4OdMdT.rst
new file mode 100644
index 00000000000000..b78bc5aaf44217
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-12-23-02-09-44.gh-issue-58956.4OdMdT.rst
@@ -0,0 +1 @@
+Fixed a frame reference leak in :mod:`bdb`.
1
0
https://github.com/python/cpython/commit/b5558cd63c62855ed43d66a55907f9d439…
commit: b5558cd63c62855ed43d66a55907f9d4398134e3
branch: main
author: Mark Shannon <mark(a)hotpy.org>
committer: markshannon <mark(a)hotpy.org>
date: 2025-01-17T16:59:30Z
summary:
Refactor code generators a bit (GH-128920)
Refactor code generators a bit to avoid passing stack property around all over the place
files:
M Tools/cases_generator/optimizer_generator.py
M Tools/cases_generator/stack.py
diff --git a/Tools/cases_generator/optimizer_generator.py b/Tools/cases_generator/optimizer_generator.py
index d08b621aed552b..2928440fecca0c 100644
--- a/Tools/cases_generator/optimizer_generator.py
+++ b/Tools/cases_generator/optimizer_generator.py
@@ -126,7 +126,7 @@ def write_uop(
try:
out.start_line()
if override:
- code_list, storage = Storage.for_uop(stack, prototype, extract_bits=False)
+ code_list, storage = Storage.for_uop(stack, prototype)
for code in code_list:
out.emit(code)
if debug:
@@ -151,11 +151,11 @@ def write_uop(
var.defined = False
storage = emitter.emit_tokens(override, storage, None)
out.start_line()
- storage.flush(out, cast_type="_Py_UopsSymbol *", extract_bits=False)
+ storage.flush(out, cast_type="_Py_UopsSymbol *")
else:
emit_default(out, uop, stack)
out.start_line()
- stack.flush(out, cast_type="_Py_UopsSymbol *", extract_bits=False)
+ stack.flush(out, cast_type="_Py_UopsSymbol *")
except StackError as ex:
raise analysis_error(ex.args[0], prototype.body[0]) # from None
@@ -198,7 +198,7 @@ def generate_abstract_interpreter(
declare_variables(override, out, skip_inputs=False)
else:
declare_variables(uop, out, skip_inputs=True)
- stack = Stack()
+ stack = Stack(False)
write_uop(override, uop, out, stack, debug, skip_inputs=(override is None))
out.start_line()
out.emit("break;\n")
diff --git a/Tools/cases_generator/stack.py b/Tools/cases_generator/stack.py
index 286f47d0cfb11b..5121837ed8334b 100644
--- a/Tools/cases_generator/stack.py
+++ b/Tools/cases_generator/stack.py
@@ -224,13 +224,14 @@ def array_or_scalar(var: StackItem | Local) -> str:
return "array" if var.is_array() else "scalar"
class Stack:
- def __init__(self) -> None:
+ def __init__(self, extract_bits: bool=True) -> None:
self.top_offset = StackOffset.empty()
self.base_offset = StackOffset.empty()
self.variables: list[Local] = []
self.defined: set[str] = set()
+ self.extract_bits = extract_bits
- def pop(self, var: StackItem, extract_bits: bool = True) -> tuple[str, Local]:
+ def pop(self, var: StackItem) -> tuple[str, Local]:
self.top_offset.pop(var)
indirect = "&" if var.is_array() else ""
if self.variables:
@@ -272,7 +273,7 @@ def pop(self, var: StackItem, extract_bits: bool = True) -> tuple[str, Local]:
return "", Local.unused(var)
self.defined.add(var.name)
cast = f"({var.type})" if (not indirect and var.type) else ""
- bits = ".bits" if cast and extract_bits else ""
+ bits = ".bits" if cast and self.extract_bits else ""
assign = f"{var.name} = {cast}{indirect}stack_pointer[{self.base_offset.to_c()}]{bits};"
if var.condition:
if var.condition == "1":
@@ -315,7 +316,7 @@ def _adjust_stack_pointer(self, out: CWriter, number: str) -> None:
out.emit("assert(WITHIN_STACK_BOUNDS());\n")
def flush(
- self, out: CWriter, cast_type: str = "uintptr_t", extract_bits: bool = True
+ self, out: CWriter, cast_type: str = "uintptr_t"
) -> None:
out.start_line()
var_offset = self.base_offset.copy()
@@ -324,7 +325,7 @@ def flush(
var.defined and
not var.in_memory
):
- Stack._do_emit(out, var.item, var_offset, cast_type, extract_bits)
+ Stack._do_emit(out, var.item, var_offset, cast_type, self.extract_bits)
var.in_memory = True
var_offset.push(var.item)
number = self.top_offset.to_c()
@@ -346,7 +347,7 @@ def as_comment(self) -> str:
)
def copy(self) -> "Stack":
- other = Stack()
+ other = Stack(self.extract_bits)
other.top_offset = self.top_offset.copy()
other.base_offset = self.base_offset.copy()
other.variables = [var.copy() for var in self.variables]
@@ -507,10 +508,10 @@ def locals_cached(self) -> bool:
return True
return False
- def flush(self, out: CWriter, cast_type: str = "uintptr_t", extract_bits: bool = True) -> None:
+ def flush(self, out: CWriter, cast_type: str = "uintptr_t") -> None:
self.clear_dead_inputs()
self._push_defined_outputs()
- self.stack.flush(out, cast_type, extract_bits)
+ self.stack.flush(out, cast_type)
def save(self, out: CWriter) -> None:
assert self.spilled >= 0
@@ -530,12 +531,12 @@ def reload(self, out: CWriter) -> None:
out.emit("stack_pointer = _PyFrame_GetStackPointer(frame);\n")
@staticmethod
- def for_uop(stack: Stack, uop: Uop, extract_bits: bool = True) -> tuple[list[str], "Storage"]:
+ def for_uop(stack: Stack, uop: Uop) -> tuple[list[str], "Storage"]:
code_list: list[str] = []
inputs: list[Local] = []
peeks: list[Local] = []
for input in reversed(uop.stack.inputs):
- code, local = stack.pop(input, extract_bits)
+ code, local = stack.pop(input)
code_list.append(code)
if input.peek:
peeks.append(local)
1
0
[3.13] gh-128017: Make a note that sys variables are read-only (GH-128887) (#128908)
by hugovk Jan. 17, 2025
by hugovk Jan. 17, 2025
Jan. 17, 2025
https://github.com/python/cpython/commit/9974e7185dcbf86c9cfe80cde62fbfff8e…
commit: 9974e7185dcbf86c9cfe80cde62fbfff8e43be69
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: hugovk <1324225+hugovk(a)users.noreply.github.com>
date: 2025-01-17T18:04:00+02:00
summary:
[3.13] gh-128017: Make a note that sys variables are read-only (GH-128887) (#128908)
Co-authored-by: Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి) <thatiparthysreenivas(a)gmail.com>
files:
M Doc/library/sys.rst
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
index fdacf5aff8c455..7af7a7c0d7c47b 100644
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -8,7 +8,7 @@
This module provides access to some variables used or maintained by the
interpreter and to functions that interact strongly with the interpreter. It is
-always available.
+always available. Unless explicitly noted otherwise, all variables are read-only.
.. data:: abiflags
1
0
https://github.com/python/cpython/commit/d66c08aa757f221c0e8893300edac105df…
commit: d66c08aa757f221c0e8893300edac105dfcde7e8
branch: main
author: Sam Gross <colesbury(a)gmail.com>
committer: Yhg1s <thomas(a)python.org>
date: 2025-01-17T16:42:27+01:00
summary:
gh-128923: Use zero to indicate unassigned unique id (#128925)
In the free threading build, the per thread reference counting uses a
unique id for some objects to index into the local reference count
table. Use 0 instead of -1 to indicate that the id is not assigned. This
avoids bugs where zero-initialized heap type objects look like they have
a unique id assigned.
files:
M Include/internal/pycore_dict.h
M Include/internal/pycore_object.h
M Include/internal/pycore_uniqueid.h
M Lib/test/test_capi/test_type.py
M Modules/_testcapimodule.c
M Objects/codeobject.c
M Objects/dictobject.c
M Objects/typeobject.c
M Python/uniqueid.c
diff --git a/Include/internal/pycore_dict.h b/Include/internal/pycore_dict.h
index 74ac8f2148174c..f4c55ca6cf64d2 100644
--- a/Include/internal/pycore_dict.h
+++ b/Include/internal/pycore_dict.h
@@ -347,8 +347,7 @@ PyDictObject *_PyObject_MaterializeManagedDict_LockHeld(PyObject *);
static inline Py_ssize_t
_PyDict_UniqueId(PyDictObject *mp)
{
- // Offset by one so that _ma_watcher_tag=0 represents an unassigned id
- return (Py_ssize_t)(mp->_ma_watcher_tag >> DICT_UNIQUE_ID_SHIFT) - 1;
+ return (Py_ssize_t)(mp->_ma_watcher_tag >> DICT_UNIQUE_ID_SHIFT);
}
static inline void
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 322305bc8c664a..19d657070ff221 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -336,20 +336,20 @@ _Py_THREAD_INCREF_OBJECT(PyObject *obj, Py_ssize_t unique_id)
{
_PyThreadStateImpl *tstate = (_PyThreadStateImpl *)_PyThreadState_GET();
- // Unsigned comparison so that `unique_id=-1`, which indicates that
- // per-thread refcounting has been disabled on this object, is handled by
- // the "else".
- if ((size_t)unique_id < (size_t)tstate->refcounts.size) {
+ // The table index is `unique_id - 1` because 0 is not a valid unique id.
+ // Unsigned comparison so that `idx=-1` is handled by the "else".
+ size_t idx = (size_t)(unique_id - 1);
+ if (idx < (size_t)tstate->refcounts.size) {
# ifdef Py_REF_DEBUG
_Py_INCREF_IncRefTotal();
# endif
_Py_INCREF_STAT_INC();
- tstate->refcounts.values[unique_id]++;
+ tstate->refcounts.values[idx]++;
}
else {
// The slow path resizes the per-thread refcount array if necessary.
- // It handles the unique_id=-1 case to keep the inlinable function smaller.
- _PyObject_ThreadIncrefSlow(obj, unique_id);
+ // It handles the unique_id=0 case to keep the inlinable function smaller.
+ _PyObject_ThreadIncrefSlow(obj, idx);
}
}
@@ -386,15 +386,15 @@ _Py_THREAD_DECREF_OBJECT(PyObject *obj, Py_ssize_t unique_id)
{
_PyThreadStateImpl *tstate = (_PyThreadStateImpl *)_PyThreadState_GET();
- // Unsigned comparison so that `unique_id=-1`, which indicates that
- // per-thread refcounting has been disabled on this object, is handled by
- // the "else".
- if ((size_t)unique_id < (size_t)tstate->refcounts.size) {
+ // The table index is `unique_id - 1` because 0 is not a valid unique id.
+ // Unsigned comparison so that `idx=-1` is handled by the "else".
+ size_t idx = (size_t)(unique_id - 1);
+ if (idx < (size_t)tstate->refcounts.size) {
# ifdef Py_REF_DEBUG
_Py_DECREF_DecRefTotal();
# endif
_Py_DECREF_STAT_INC();
- tstate->refcounts.values[unique_id]--;
+ tstate->refcounts.values[idx]--;
}
else {
// Directly decref the object if the id is not assigned or if
diff --git a/Include/internal/pycore_uniqueid.h b/Include/internal/pycore_uniqueid.h
index d3db49ddb78103..9d3c866a704894 100644
--- a/Include/internal/pycore_uniqueid.h
+++ b/Include/internal/pycore_uniqueid.h
@@ -16,7 +16,7 @@ extern "C" {
// Per-thread reference counting is used along with deferred reference
// counting to avoid scaling bottlenecks due to reference count contention.
//
-// An id of -1 is used to indicate that an object doesn't use per-thread
+// An id of 0 is used to indicate that an object doesn't use per-thread
// refcounting. This value is used when the object is finalized by the GC
// and during interpreter shutdown to allow the object to be
// deallocated promptly when the object's refcount reaches zero.
@@ -45,6 +45,8 @@ struct _Py_unique_id_pool {
Py_ssize_t size;
};
+#define _Py_INVALID_UNIQUE_ID 0
+
// Assigns the next id from the pool of ids.
extern Py_ssize_t _PyObject_AssignUniqueId(PyObject *obj);
@@ -65,7 +67,7 @@ extern void _PyObject_FinalizePerThreadRefcounts(_PyThreadStateImpl *tstate);
extern void _PyObject_FinalizeUniqueIdPool(PyInterpreterState *interp);
// Increfs the object, resizing the thread-local refcount array if necessary.
-PyAPI_FUNC(void) _PyObject_ThreadIncrefSlow(PyObject *obj, Py_ssize_t unique_id);
+PyAPI_FUNC(void) _PyObject_ThreadIncrefSlow(PyObject *obj, size_t idx);
#endif /* Py_GIL_DISABLED */
diff --git a/Lib/test/test_capi/test_type.py b/Lib/test/test_capi/test_type.py
index 92d056e802eeed..ffcaae73bca236 100644
--- a/Lib/test/test_capi/test_type.py
+++ b/Lib/test/test_capi/test_type.py
@@ -67,3 +67,10 @@ class FreezeThis(metaclass=Meta):
Base.value = 3
type_freeze(FreezeThis)
self.assertEqual(FreezeThis.value, 2)
+
+ def test_manual_heap_type(self):
+ # gh-128923: test that a manually allocated and initailized heap type
+ # works correctly
+ ManualHeapType = _testcapi.ManualHeapType
+ for i in range(100):
+ self.assertIsInstance(ManualHeapType(), ManualHeapType)
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 7d304add5999d1..b657bb665bd5c5 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -4149,6 +4149,61 @@ static PyTypeObject ContainerNoGC_type = {
.tp_new = ContainerNoGC_new,
};
+/* Manually allocated heap type */
+
+typedef struct {
+ PyObject_HEAD
+ PyObject *dict;
+} ManualHeapType;
+
+static int
+ManualHeapType_traverse(PyObject *self, visitproc visit, void *arg)
+{
+ ManualHeapType *mht = (ManualHeapType *)self;
+ Py_VISIT(mht->dict);
+ return 0;
+}
+
+static void
+ManualHeapType_dealloc(PyObject *self)
+{
+ ManualHeapType *mht = (ManualHeapType *)self;
+ PyObject_GC_UnTrack(self);
+ Py_XDECREF(mht->dict);
+ PyTypeObject *type = Py_TYPE(self);
+ Py_TYPE(self)->tp_free(self);
+ Py_DECREF(type);
+}
+
+static PyObject *
+create_manual_heap_type(void)
+{
+ // gh-128923: Ensure that a heap type allocated through PyType_Type.tp_alloc
+ // with minimal initialization works correctly.
+ PyHeapTypeObject *heap_type = (PyHeapTypeObject *)PyType_Type.tp_alloc(&PyType_Type, 0);
+ if (heap_type == NULL) {
+ return NULL;
+ }
+ PyTypeObject* type = &heap_type->ht_type;
+ type->tp_basicsize = sizeof(ManualHeapType);
+ type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE | Py_TPFLAGS_HAVE_GC;
+ type->tp_new = PyType_GenericNew;
+ type->tp_name = "ManualHeapType";
+ type->tp_dictoffset = offsetof(ManualHeapType, dict);
+ type->tp_traverse = ManualHeapType_traverse;
+ type->tp_dealloc = ManualHeapType_dealloc;
+ heap_type->ht_name = PyUnicode_FromString(type->tp_name);
+ if (!heap_type->ht_name) {
+ Py_DECREF(type);
+ return NULL;
+ }
+ heap_type->ht_qualname = Py_NewRef(heap_type->ht_name);
+ if (PyType_Ready(type) < 0) {
+ Py_DECREF(type);
+ return NULL;
+ }
+ return (PyObject *)type;
+}
static struct PyModuleDef _testcapimodule = {
PyModuleDef_HEAD_INIT,
@@ -4283,6 +4338,15 @@ PyInit__testcapi(void)
(PyObject *) &ContainerNoGC_type) < 0)
return NULL;
+ PyObject *manual_heap_type = create_manual_heap_type();
+ if (manual_heap_type == NULL) {
+ return NULL;
+ }
+ if (PyModule_Add(m, "ManualHeapType", manual_heap_type) < 0) {
+ return NULL;
+ }
+
+
/* Include tests from the _testcapi/ directory */
if (_PyTestCapi_Init_Vectorcall(m) < 0) {
return NULL;
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 15b36a868a47df..539200c97c1206 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -1911,7 +1911,7 @@ code_dealloc(PyObject *self)
Py_XDECREF(co->co_linetable);
Py_XDECREF(co->co_exceptiontable);
#ifdef Py_GIL_DISABLED
- assert(co->_co_unique_id == -1);
+ assert(co->_co_unique_id == _Py_INVALID_UNIQUE_ID);
#endif
if (co->_co_cached != NULL) {
Py_XDECREF(co->_co_cached->_co_code);
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 82789d5e56f523..504e65b01ca959 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1659,6 +1659,9 @@ _PyDict_EnablePerThreadRefcounting(PyObject *op)
assert(PyDict_Check(op));
#ifdef Py_GIL_DISABLED
Py_ssize_t id = _PyObject_AssignUniqueId(op);
+ if (id == _Py_INVALID_UNIQUE_ID) {
+ return;
+ }
if ((uint64_t)id >= (uint64_t)DICT_UNIQUE_ID_MAX) {
_PyObject_ReleaseUniqueId(id);
return;
@@ -1666,8 +1669,7 @@ _PyDict_EnablePerThreadRefcounting(PyObject *op)
PyDictObject *mp = (PyDictObject *)op;
assert((mp->_ma_watcher_tag >> DICT_UNIQUE_ID_SHIFT) == 0);
- // Plus 1 so that _ma_watcher_tag=0 represents an unassigned id
- mp->_ma_watcher_tag += ((uint64_t)id + 1) << DICT_UNIQUE_ID_SHIFT;
+ mp->_ma_watcher_tag += (uint64_t)id << DICT_UNIQUE_ID_SHIFT;
#endif
}
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index d8f5f6d9cb2366..93920341a179e8 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -6160,7 +6160,7 @@ type_dealloc(PyObject *self)
Py_XDECREF(et->ht_module);
PyMem_Free(et->_ht_tpname);
#ifdef Py_GIL_DISABLED
- assert(et->unique_id == -1);
+ assert(et->unique_id == _Py_INVALID_UNIQUE_ID);
#endif
et->ht_token = NULL;
Py_TYPE(type)->tp_free((PyObject *)type);
diff --git a/Python/uniqueid.c b/Python/uniqueid.c
index b9f30713feeb57..64c3e6cfbbe825 100644
--- a/Python/uniqueid.c
+++ b/Python/uniqueid.c
@@ -86,7 +86,7 @@ _PyObject_AssignUniqueId(PyObject *obj)
if (pool->freelist == NULL) {
if (resize_interp_type_id_pool(pool) < 0) {
UNLOCK_POOL(pool);
- return -1;
+ return _Py_INVALID_UNIQUE_ID;
}
}
@@ -94,7 +94,9 @@ _PyObject_AssignUniqueId(PyObject *obj)
pool->freelist = entry->next;
entry->obj = obj;
_PyObject_SetDeferredRefcount(obj);
- Py_ssize_t unique_id = (entry - pool->table);
+ // The unique id is one plus the index of the entry in the table.
+ Py_ssize_t unique_id = (entry - pool->table) + 1;
+ assert(unique_id > 0);
UNLOCK_POOL(pool);
return unique_id;
}
@@ -106,8 +108,9 @@ _PyObject_ReleaseUniqueId(Py_ssize_t unique_id)
struct _Py_unique_id_pool *pool = &interp->unique_ids;
LOCK_POOL(pool);
- assert(unique_id >= 0 && unique_id < pool->size);
- _Py_unique_id_entry *entry = &pool->table[unique_id];
+ assert(unique_id > 0 && unique_id <= pool->size);
+ Py_ssize_t idx = unique_id - 1;
+ _Py_unique_id_entry *entry = &pool->table[idx];
entry->next = pool->freelist;
pool->freelist = entry;
UNLOCK_POOL(pool);
@@ -116,18 +119,18 @@ _PyObject_ReleaseUniqueId(Py_ssize_t unique_id)
static Py_ssize_t
clear_unique_id(PyObject *obj)
{
- Py_ssize_t id = -1;
+ Py_ssize_t id = _Py_INVALID_UNIQUE_ID;
if (PyType_Check(obj)) {
if (PyType_HasFeature((PyTypeObject *)obj, Py_TPFLAGS_HEAPTYPE)) {
PyHeapTypeObject *ht = (PyHeapTypeObject *)obj;
id = ht->unique_id;
- ht->unique_id = -1;
+ ht->unique_id = _Py_INVALID_UNIQUE_ID;
}
}
else if (PyCode_Check(obj)) {
PyCodeObject *co = (PyCodeObject *)obj;
id = co->_co_unique_id;
- co->_co_unique_id = -1;
+ co->_co_unique_id = _Py_INVALID_UNIQUE_ID;
}
else if (PyDict_Check(obj)) {
PyDictObject *mp = (PyDictObject *)obj;
@@ -141,23 +144,23 @@ void
_PyObject_DisablePerThreadRefcounting(PyObject *obj)
{
Py_ssize_t id = clear_unique_id(obj);
- if (id >= 0) {
+ if (id != _Py_INVALID_UNIQUE_ID) {
_PyObject_ReleaseUniqueId(id);
}
}
void
-_PyObject_ThreadIncrefSlow(PyObject *obj, Py_ssize_t unique_id)
+_PyObject_ThreadIncrefSlow(PyObject *obj, size_t idx)
{
_PyThreadStateImpl *tstate = (_PyThreadStateImpl *)_PyThreadState_GET();
- if (unique_id < 0 || resize_local_refcounts(tstate) < 0) {
+ if (((Py_ssize_t)idx) < 0 || resize_local_refcounts(tstate) < 0) {
// just incref the object directly.
Py_INCREF(obj);
return;
}
- assert(unique_id < tstate->refcounts.size);
- tstate->refcounts.values[unique_id]++;
+ assert(idx < (size_t)tstate->refcounts.size);
+ tstate->refcounts.values[idx]++;
#ifdef Py_REF_DEBUG
_Py_IncRefTotal((PyThreadState *)tstate);
#endif
@@ -217,7 +220,7 @@ _PyObject_FinalizeUniqueIdPool(PyInterpreterState *interp)
if (obj != NULL) {
Py_ssize_t id = clear_unique_id(obj);
(void)id;
- assert(id == i);
+ assert(id == i + 1);
}
}
PyMem_Free(pool->table);
1
0
https://github.com/python/cpython/commit/767c89ba7c5a70626df6e75eb56b546bf9…
commit: 767c89ba7c5a70626df6e75eb56b546bf911b997
branch: main
author: Tian Gao <gaogaotiantian(a)hotmail.com>
committer: gaogaotiantian <gaogaotiantian(a)hotmail.com>
date: 2025-01-17T10:33:04-05:00
summary:
gh-58956: Fix a frame refleak in bdb (#128190)
files:
A Misc/NEWS.d/next/Library/2024-12-23-02-09-44.gh-issue-58956.4OdMdT.rst
M Lib/bdb.py
M Lib/test/test_pdb.py
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 81bba8a130f97c..73e249621a053b 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -404,6 +404,7 @@ def set_trace(self, frame=None):
frame.f_trace_lines = True
frame = frame.f_back
self.set_stepinstr()
+ self.enterframe = None
sys.settrace(self.trace_dispatch)
def set_continue(self):
@@ -423,6 +424,7 @@ def set_continue(self):
for frame, (trace_lines, trace_opcodes) in self.frame_trace_lines_opcodes.items():
frame.f_trace_lines, frame.f_trace_opcodes = trace_lines, trace_opcodes
self.frame_trace_lines_opcodes = {}
+ self.enterframe = None
def set_quit(self):
"""Set quitting attribute to True.
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index ace5544f4106d0..09601623b29ac1 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -3009,6 +3009,57 @@ def test_pdb_f_trace_lines():
(Pdb) continue
"""
+def test_pdb_frame_refleak():
+ """
+ pdb should not leak reference to frames
+
+ >>> def frame_leaker(container):
+ ... import sys
+ ... container.append(sys._getframe())
+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ ... pass
+
+ >>> def test_function():
+ ... import gc
+ ... container = []
+ ... frame_leaker(container) # c
+ ... print(len(gc.get_referrers(container[0])))
+ ... container = []
+ ... frame_leaker(container) # n c
+ ... print(len(gc.get_referrers(container[0])))
+ ... container = []
+ ... frame_leaker(container) # r c
+ ... print(len(gc.get_referrers(container[0])))
+
+ >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
+ ... 'continue',
+ ... 'next',
+ ... 'continue',
+ ... 'return',
+ ... 'continue',
+ ... ]):
+ ... test_function()
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(4)frame_leaker()
+ -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ (Pdb) continue
+ 1
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(4)frame_leaker()
+ -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ (Pdb) next
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(5)frame_leaker()
+ -> pass
+ (Pdb) continue
+ 1
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(4)frame_leaker()
+ -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ (Pdb) return
+ --Return--
+ > <doctest test.test_pdb.test_pdb_frame_refleak[0]>(5)frame_leaker()->None
+ -> pass
+ (Pdb) continue
+ 1
+ """
+
def test_pdb_function_break():
"""Testing the line number of break on function
diff --git a/Misc/NEWS.d/next/Library/2024-12-23-02-09-44.gh-issue-58956.4OdMdT.rst b/Misc/NEWS.d/next/Library/2024-12-23-02-09-44.gh-issue-58956.4OdMdT.rst
new file mode 100644
index 00000000000000..b78bc5aaf44217
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-12-23-02-09-44.gh-issue-58956.4OdMdT.rst
@@ -0,0 +1 @@
+Fixed a frame reference leak in :mod:`bdb`.
1
0
https://github.com/python/cpython/commit/d7f703d54d64c5a380f43e2363c439f7da…
commit: d7f703d54d64c5a380f43e2363c439f7dab0d09d
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-17T14:55:43+01:00
summary:
gh-59705: Implement _thread.set_name() on Windows (#128675)
Implement set_name() with SetThreadDescription() and _get_name() with
GetThreadDescription(). If SetThreadDescription() or
GetThreadDescription() is not available in kernelbase.dll, delete the
method when the _thread module is imported.
Truncate the thread name to 32766 characters.
Co-authored-by: Eryk Sun <eryksun(a)gmail.com>
files:
M Lib/test/test_threading.py
M Modules/_threadmodule.c
M Modules/clinic/_threadmodule.c.h
M PC/pyconfig.h.in
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 3e164a12581dd1..214e1ba0b53dd2 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -2130,6 +2130,15 @@ def test_set_name(self):
# Test long non-ASCII name (truncated)
"x" * (limit - 1) + "é€",
+
+ # Test long non-BMP names (truncated) creating surrogate pairs
+ # on Windows
+ "x" * (limit - 1) + "\U0010FFFF",
+ "x" * (limit - 2) + "\U0010FFFF" * 2,
+ "x" + "\U0001f40d" * limit,
+ "xx" + "\U0001f40d" * limit,
+ "xxx" + "\U0001f40d" * limit,
+ "xxxx" + "\U0001f40d" * limit,
]
if os_helper.FS_NONASCII:
tests.append(f"nonascii:{os_helper.FS_NONASCII}")
@@ -2146,15 +2155,31 @@ def work():
work_name = _thread._get_name()
for name in tests:
- encoded = name.encode(encoding, "replace")
- if b'\0' in encoded:
- encoded = encoded.split(b'\0', 1)[0]
- if truncate is not None:
- encoded = encoded[:truncate]
- if sys.platform.startswith("solaris"):
- expected = encoded.decode("utf-8", "surrogateescape")
+ if not support.MS_WINDOWS:
+ encoded = name.encode(encoding, "replace")
+ if b'\0' in encoded:
+ encoded = encoded.split(b'\0', 1)[0]
+ if truncate is not None:
+ encoded = encoded[:truncate]
+ if sys.platform.startswith("solaris"):
+ expected = encoded.decode("utf-8", "surrogateescape")
+ else:
+ expected = os.fsdecode(encoded)
else:
- expected = os.fsdecode(encoded)
+ size = 0
+ chars = []
+ for ch in name:
+ if ord(ch) > 0xFFFF:
+ size += 2
+ else:
+ size += 1
+ if size > truncate:
+ break
+ chars.append(ch)
+ expected = ''.join(chars)
+
+ if '\0' in expected:
+ expected = expected.split('\0', 1)[0]
with self.subTest(name=name, expected=expected):
work_name = None
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index d19ae326bd6b48..586ed368024fb1 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -47,6 +47,14 @@ get_thread_state(PyObject *module)
}
+#ifdef MS_WINDOWS
+typedef HRESULT (WINAPI *PF_GET_THREAD_DESCRIPTION)(HANDLE, PCWSTR*);
+typedef HRESULT (WINAPI *PF_SET_THREAD_DESCRIPTION)(HANDLE, PCWSTR);
+static PF_GET_THREAD_DESCRIPTION pGetThreadDescription = NULL;
+static PF_SET_THREAD_DESCRIPTION pSetThreadDescription = NULL;
+#endif
+
+
/*[clinic input]
module _thread
[clinic start generated code]*/
@@ -2368,7 +2376,7 @@ Internal only. Return a non-zero integer that uniquely identifies the main threa
of the main interpreter.");
-#ifdef HAVE_PTHREAD_GETNAME_NP
+#if defined(HAVE_PTHREAD_GETNAME_NP) || defined(MS_WINDOWS)
/*[clinic input]
_thread._get_name
@@ -2379,6 +2387,7 @@ static PyObject *
_thread__get_name_impl(PyObject *module)
/*[clinic end generated code: output=20026e7ee3da3dd7 input=35cec676833d04c8]*/
{
+#ifndef MS_WINDOWS
// Linux and macOS are limited to respectively 16 and 64 bytes
char name[100];
pthread_t thread = pthread_self();
@@ -2393,11 +2402,26 @@ _thread__get_name_impl(PyObject *module)
#else
return PyUnicode_DecodeFSDefault(name);
#endif
+#else
+ // Windows implementation
+ assert(pGetThreadDescription != NULL);
+
+ wchar_t *name;
+ HRESULT hr = pGetThreadDescription(GetCurrentThread(), &name);
+ if (FAILED(hr)) {
+ PyErr_SetFromWindowsErr(0);
+ return NULL;
+ }
+
+ PyObject *name_obj = PyUnicode_FromWideChar(name, -1);
+ LocalFree(name);
+ return name_obj;
+#endif
}
#endif // HAVE_PTHREAD_GETNAME_NP
-#ifdef HAVE_PTHREAD_SETNAME_NP
+#if defined(HAVE_PTHREAD_SETNAME_NP) || defined(MS_WINDOWS)
/*[clinic input]
_thread.set_name
@@ -2410,6 +2434,7 @@ static PyObject *
_thread_set_name_impl(PyObject *module, PyObject *name_obj)
/*[clinic end generated code: output=402b0c68e0c0daed input=7e7acd98261be82f]*/
{
+#ifndef MS_WINDOWS
#ifdef __sun
// Solaris always uses UTF-8
const char *encoding = "utf-8";
@@ -2455,6 +2480,35 @@ _thread_set_name_impl(PyObject *module, PyObject *name_obj)
return PyErr_SetFromErrno(PyExc_OSError);
}
Py_RETURN_NONE;
+#else
+ // Windows implementation
+ assert(pSetThreadDescription != NULL);
+
+ Py_ssize_t len;
+ wchar_t *name = PyUnicode_AsWideCharString(name_obj, &len);
+ if (name == NULL) {
+ return NULL;
+ }
+
+ if (len > PYTHREAD_NAME_MAXLEN) {
+ // Truncate the name
+ Py_UCS4 ch = name[PYTHREAD_NAME_MAXLEN-1];
+ if (Py_UNICODE_IS_HIGH_SURROGATE(ch)) {
+ name[PYTHREAD_NAME_MAXLEN-1] = 0;
+ }
+ else {
+ name[PYTHREAD_NAME_MAXLEN] = 0;
+ }
+ }
+
+ HRESULT hr = pSetThreadDescription(GetCurrentThread(), name);
+ PyMem_Free(name);
+ if (FAILED(hr)) {
+ PyErr_SetFromWindowsErr((int)hr);
+ return NULL;
+ }
+ Py_RETURN_NONE;
+#endif
}
#endif // HAVE_PTHREAD_SETNAME_NP
@@ -2598,6 +2652,31 @@ thread_module_exec(PyObject *module)
}
#endif
+#ifdef MS_WINDOWS
+ HMODULE kernelbase = GetModuleHandleW(L"kernelbase.dll");
+ if (kernelbase != NULL) {
+ if (pGetThreadDescription == NULL) {
+ pGetThreadDescription = (PF_GET_THREAD_DESCRIPTION)GetProcAddress(
+ kernelbase, "GetThreadDescription");
+ }
+ if (pSetThreadDescription == NULL) {
+ pSetThreadDescription = (PF_SET_THREAD_DESCRIPTION)GetProcAddress(
+ kernelbase, "SetThreadDescription");
+ }
+ }
+
+ if (pGetThreadDescription == NULL) {
+ if (PyObject_DelAttrString(module, "_get_name") < 0) {
+ return -1;
+ }
+ }
+ if (pSetThreadDescription == NULL) {
+ if (PyObject_DelAttrString(module, "set_name") < 0) {
+ return -1;
+ }
+ }
+#endif
+
return 0;
}
diff --git a/Modules/clinic/_threadmodule.c.h b/Modules/clinic/_threadmodule.c.h
index 8f0507d40285b3..09b7afebd6d8d9 100644
--- a/Modules/clinic/_threadmodule.c.h
+++ b/Modules/clinic/_threadmodule.c.h
@@ -8,7 +8,7 @@ preserve
#endif
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
-#if defined(HAVE_PTHREAD_GETNAME_NP)
+#if (defined(HAVE_PTHREAD_GETNAME_NP) || defined(MS_WINDOWS))
PyDoc_STRVAR(_thread__get_name__doc__,
"_get_name($module, /)\n"
@@ -28,9 +28,9 @@ _thread__get_name(PyObject *module, PyObject *Py_UNUSED(ignored))
return _thread__get_name_impl(module);
}
-#endif /* defined(HAVE_PTHREAD_GETNAME_NP) */
+#endif /* (defined(HAVE_PTHREAD_GETNAME_NP) || defined(MS_WINDOWS)) */
-#if defined(HAVE_PTHREAD_SETNAME_NP)
+#if (defined(HAVE_PTHREAD_SETNAME_NP) || defined(MS_WINDOWS))
PyDoc_STRVAR(_thread_set_name__doc__,
"set_name($module, /, name)\n"
@@ -92,7 +92,7 @@ _thread_set_name(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb
return return_value;
}
-#endif /* defined(HAVE_PTHREAD_SETNAME_NP) */
+#endif /* (defined(HAVE_PTHREAD_SETNAME_NP) || defined(MS_WINDOWS)) */
#ifndef _THREAD__GET_NAME_METHODDEF
#define _THREAD__GET_NAME_METHODDEF
@@ -101,4 +101,4 @@ _thread_set_name(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb
#ifndef _THREAD_SET_NAME_METHODDEF
#define _THREAD_SET_NAME_METHODDEF
#endif /* !defined(_THREAD_SET_NAME_METHODDEF) */
-/*[clinic end generated code: output=b5cb85aaccc45bf6 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6e88ef6b126cece8 input=a9049054013a1b77]*/
diff --git a/PC/pyconfig.h.in b/PC/pyconfig.h.in
index 010f5fe5646630..837461d0e884bc 100644
--- a/PC/pyconfig.h.in
+++ b/PC/pyconfig.h.in
@@ -753,4 +753,8 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
/* Define if libssl has X509_VERIFY_PARAM_set1_host and related function */
#define HAVE_X509_VERIFY_PARAM_SET1_HOST 1
+// Truncate the thread name to 64 characters. The OS limit is 32766 wide
+// characters, but long names aren't of practical use.
+#define PYTHREAD_NAME_MAXLEN 32766
+
#endif /* !Py_CONFIG_H */
1
0
Revert "gh-128770: raise warnings as errors in test suite - except for test_socket which still logs warnings (#128726)" (#128936)
by hugovk Jan. 17, 2025
by hugovk Jan. 17, 2025
Jan. 17, 2025
https://github.com/python/cpython/commit/76856ae1659dbba066e51f353b31cb7cf0…
commit: 76856ae1659dbba066e51f353b31cb7cf0a8a5fe
branch: main
author: Hugo van Kemenade <1324225+hugovk(a)users.noreply.github.com>
committer: hugovk <1324225+hugovk(a)users.noreply.github.com>
date: 2025-01-17T15:16:10+02:00
summary:
Revert "gh-128770: raise warnings as errors in test suite - except for test_socket which still logs warnings (#128726)" (#128936)
files:
M Lib/test/libregrtest/main.py
M Lib/test/test_pyrepl/test_pyrepl.py
M Lib/test/test_socket.py
diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py
index cd4d512771e05f..dcbcc6790c68d8 100644
--- a/Lib/test/libregrtest/main.py
+++ b/Lib/test/libregrtest/main.py
@@ -642,9 +642,9 @@ def _add_ci_python_opts(self, python_opts, keep_environ):
if not sys.stdout.write_through:
python_opts.append('-u')
- # Add warnings filter 'error'
+ # Add warnings filter 'default'
if 'default' not in sys.warnoptions:
- python_opts.extend(('-W', 'error'))
+ python_opts.extend(('-W', 'default'))
# Error on bytes/str comparison
if sys.flags.bytes_warning < 2:
diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py
index 113ea1d2fe709f..f29a7ffbd7cafd 100644
--- a/Lib/test/test_pyrepl/test_pyrepl.py
+++ b/Lib/test/test_pyrepl/test_pyrepl.py
@@ -1324,21 +1324,22 @@ def test_readline_history_file(self):
if readline.backend != "editline":
self.skipTest("GNU readline is not affected by this issue")
- with tempfile.NamedTemporaryFile() as hfile:
- env = os.environ.copy()
- env["PYTHON_HISTORY"] = hfile.name
-
- env["PYTHON_BASIC_REPL"] = "1"
- output, exit_code = self.run_repl("spam \nexit()\n", env=env)
- self.assertEqual(exit_code, 0)
- self.assertIn("spam ", output)
- self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
- self.assertIn("spam\\040", pathlib.Path(hfile.name).read_text())
-
- env.pop("PYTHON_BASIC_REPL", None)
- output, exit_code = self.run_repl("exit\n", env=env)
- self.assertEqual(exit_code, 0)
- self.assertNotIn("\\040", pathlib.Path(hfile.name).read_text())
+ hfile = tempfile.NamedTemporaryFile()
+ self.addCleanup(unlink, hfile.name)
+ env = os.environ.copy()
+ env["PYTHON_HISTORY"] = hfile.name
+
+ env["PYTHON_BASIC_REPL"] = "1"
+ output, exit_code = self.run_repl("spam \nexit()\n", env=env)
+ self.assertEqual(exit_code, 0)
+ self.assertIn("spam ", output)
+ self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
+ self.assertIn("spam\\040", pathlib.Path(hfile.name).read_text())
+
+ env.pop("PYTHON_BASIC_REPL", None)
+ output, exit_code = self.run_repl("exit\n", env=env)
+ self.assertEqual(exit_code, 0)
+ self.assertNotIn("\\040", pathlib.Path(hfile.name).read_text())
def test_keyboard_interrupt_after_isearch(self):
output, exit_code = self.run_repl(["\x12", "\x03", "exit"])
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 7233847f37bf39..faf326d9164e1b 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1,8 +1,7 @@
import unittest
-import warnings
from test import support
from test.support import (
- is_apple, os_helper, refleak_helper, socket_helper, threading_helper,
+ is_apple, os_helper, refleak_helper, socket_helper, threading_helper
)
import _thread as thread
import array
@@ -199,24 +198,6 @@ def socket_setdefaulttimeout(timeout):
socket.setdefaulttimeout(old_timeout)
-(a)contextlib.contextmanager
-def downgrade_malformed_data_warning():
- # This warning happens on macos and win, but does not always happen on linux.
- if sys.platform not in {"win32", "darwin"}:
- yield
- return
-
- with warnings.catch_warnings():
- # TODO: gh-110012, we should investigate why this warning is happening
- # and fix it properly.
- warnings.filterwarnings(
- action="always",
- message=r"received malformed or improperly-truncated ancillary data",
- category=RuntimeWarning,
- )
- yield
-
-
HAVE_SOCKET_CAN = _have_socket_can()
HAVE_SOCKET_CAN_ISOTP = _have_socket_can_isotp()
@@ -3965,9 +3946,8 @@ def checkTruncatedArray(self, ancbuf, maxdata, mindata=0):
# mindata and maxdata bytes when received with buffer size
# ancbuf, and that any complete file descriptor numbers are
# valid.
- with downgrade_malformed_data_warning(): # TODO: gh-110012
- msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock,
- len(MSG), ancbuf)
+ msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock,
+ len(MSG), ancbuf)
self.assertEqual(msg, MSG)
self.checkRecvmsgAddress(addr, self.cli_addr)
self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC)
@@ -4318,9 +4298,8 @@ def testSingleCmsgTruncInData(self):
self.serv_sock.setsockopt(socket.IPPROTO_IPV6,
socket.IPV6_RECVHOPLIMIT, 1)
self.misc_event.set()
- with downgrade_malformed_data_warning(): # TODO: gh-110012
- msg, ancdata, flags, addr = self.doRecvmsg(
- self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1)
+ msg, ancdata, flags, addr = self.doRecvmsg(
+ self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1)
self.assertEqual(msg, MSG)
self.checkRecvmsgAddress(addr, self.cli_addr)
@@ -4423,10 +4402,9 @@ def testSecondCmsgTruncInData(self):
self.serv_sock.setsockopt(socket.IPPROTO_IPV6,
socket.IPV6_RECVTCLASS, 1)
self.misc_event.set()
- with downgrade_malformed_data_warning(): # TODO: gh-110012
- msg, ancdata, flags, addr = self.doRecvmsg(
- self.serv_sock, len(MSG),
- socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1)
+ msg, ancdata, flags, addr = self.doRecvmsg(
+ self.serv_sock, len(MSG),
+ socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1)
self.assertEqual(msg, MSG)
self.checkRecvmsgAddress(addr, self.cli_addr)
1
0
[3.13] gh-58689: Fix os.kill() error handling on Windows (GH-128932) (#128937)
by vstinner Jan. 17, 2025
by vstinner Jan. 17, 2025
Jan. 17, 2025
https://github.com/python/cpython/commit/d997ba45ed9155279bd91752ffb4be8b8c…
commit: d997ba45ed9155279bd91752ffb4be8b8ce69dd6
branch: 3.13
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-17T12:55:07Z
summary:
[3.13] gh-58689: Fix os.kill() error handling on Windows (GH-128932) (#128937)
gh-58689: Fix os.kill() error handling on Windows (GH-128932)
(cherry picked from commit 939df0f9f6a76e0916b3ba53841e1413ab90952e)
Co-authored-by: Victor Stinner <vstinner(a)python.org>
files:
M Modules/posixmodule.c
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index d1d6b247d1ed58..6b2cb96629dc6c 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -9533,42 +9533,33 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal)
Py_RETURN_NONE;
#else /* !MS_WINDOWS */
- PyObject *result;
DWORD sig = (DWORD)signal;
- DWORD err;
- HANDLE handle;
#ifdef HAVE_WINDOWS_CONSOLE_IO
/* Console processes which share a common console can be sent CTRL+C or
CTRL+BREAK events, provided they handle said events. */
if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) {
if (GenerateConsoleCtrlEvent(sig, (DWORD)pid) == 0) {
- err = GetLastError();
- PyErr_SetFromWindowsErr(err);
- }
- else {
- Py_RETURN_NONE;
+ return PyErr_SetFromWindowsErr(0);
}
+ Py_RETURN_NONE;
}
#endif /* HAVE_WINDOWS_CONSOLE_IO */
/* If the signal is outside of what GenerateConsoleCtrlEvent can use,
attempt to open and terminate the process. */
- handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
+ HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
if (handle == NULL) {
- err = GetLastError();
- return PyErr_SetFromWindowsErr(err);
+ return PyErr_SetFromWindowsErr(0);
}
- if (TerminateProcess(handle, sig) == 0) {
- err = GetLastError();
- result = PyErr_SetFromWindowsErr(err);
- } else {
- result = Py_NewRef(Py_None);
+ BOOL res = TerminateProcess(handle, sig);
+ CloseHandle(handle);
+ if (res == 0) {
+ return PyErr_SetFromWindowsErr(0);
}
- CloseHandle(handle);
- return result;
+ Py_RETURN_NONE;
#endif /* !MS_WINDOWS */
}
#endif /* HAVE_KILL */
1
0
[3.12] gh-58689: Fix os.kill() error handling on Windows (GH-128932) (#128938)
by vstinner Jan. 17, 2025
by vstinner Jan. 17, 2025
Jan. 17, 2025
https://github.com/python/cpython/commit/dfd75dfeed60144978ed0e33978242b952…
commit: dfd75dfeed60144978ed0e33978242b95276f056
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-17T12:48:24Z
summary:
[3.12] gh-58689: Fix os.kill() error handling on Windows (GH-128932) (#128938)
gh-58689: Fix os.kill() error handling on Windows (GH-128932)
(cherry picked from commit 939df0f9f6a76e0916b3ba53841e1413ab90952e)
Co-authored-by: Victor Stinner <vstinner(a)python.org>
files:
M Modules/posixmodule.c
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index deabc103056642..c386f15b1714e1 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -8981,42 +8981,33 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal)
Py_RETURN_NONE;
#else /* !MS_WINDOWS */
- PyObject *result;
DWORD sig = (DWORD)signal;
- DWORD err;
- HANDLE handle;
#ifdef HAVE_WINDOWS_CONSOLE_IO
/* Console processes which share a common console can be sent CTRL+C or
CTRL+BREAK events, provided they handle said events. */
if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) {
if (GenerateConsoleCtrlEvent(sig, (DWORD)pid) == 0) {
- err = GetLastError();
- PyErr_SetFromWindowsErr(err);
- }
- else {
- Py_RETURN_NONE;
+ return PyErr_SetFromWindowsErr(0);
}
+ Py_RETURN_NONE;
}
#endif /* HAVE_WINDOWS_CONSOLE_IO */
/* If the signal is outside of what GenerateConsoleCtrlEvent can use,
attempt to open and terminate the process. */
- handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
+ HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
if (handle == NULL) {
- err = GetLastError();
- return PyErr_SetFromWindowsErr(err);
+ return PyErr_SetFromWindowsErr(0);
}
- if (TerminateProcess(handle, sig) == 0) {
- err = GetLastError();
- result = PyErr_SetFromWindowsErr(err);
- } else {
- result = Py_NewRef(Py_None);
+ BOOL res = TerminateProcess(handle, sig);
+ CloseHandle(handle);
+ if (res == 0) {
+ return PyErr_SetFromWindowsErr(0);
}
- CloseHandle(handle);
- return result;
+ Py_RETURN_NONE;
#endif /* !MS_WINDOWS */
}
#endif /* HAVE_KILL */
1
0
https://github.com/python/cpython/commit/939df0f9f6a76e0916b3ba53841e1413ab…
commit: 939df0f9f6a76e0916b3ba53841e1413ab90952e
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-17T13:30:40+01:00
summary:
gh-58689: Fix os.kill() error handling on Windows (#128932)
files:
M Modules/posixmodule.c
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index bb8d698bfed375..fb9e55a57703fc 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -9582,42 +9582,33 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal)
Py_RETURN_NONE;
#else /* !MS_WINDOWS */
- PyObject *result;
DWORD sig = (DWORD)signal;
- DWORD err;
- HANDLE handle;
#ifdef HAVE_WINDOWS_CONSOLE_IO
/* Console processes which share a common console can be sent CTRL+C or
CTRL+BREAK events, provided they handle said events. */
if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) {
if (GenerateConsoleCtrlEvent(sig, (DWORD)pid) == 0) {
- err = GetLastError();
- PyErr_SetFromWindowsErr(err);
- }
- else {
- Py_RETURN_NONE;
+ return PyErr_SetFromWindowsErr(0);
}
+ Py_RETURN_NONE;
}
#endif /* HAVE_WINDOWS_CONSOLE_IO */
/* If the signal is outside of what GenerateConsoleCtrlEvent can use,
attempt to open and terminate the process. */
- handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
+ HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
if (handle == NULL) {
- err = GetLastError();
- return PyErr_SetFromWindowsErr(err);
+ return PyErr_SetFromWindowsErr(0);
}
- if (TerminateProcess(handle, sig) == 0) {
- err = GetLastError();
- result = PyErr_SetFromWindowsErr(err);
- } else {
- result = Py_NewRef(Py_None);
+ BOOL res = TerminateProcess(handle, sig);
+ CloseHandle(handle);
+ if (res == 0) {
+ return PyErr_SetFromWindowsErr(0);
}
- CloseHandle(handle);
- return result;
+ Py_RETURN_NONE;
#endif /* !MS_WINDOWS */
}
#endif /* HAVE_KILL */
1
0
gh-128770: raise warnings as errors in test suite - except for test_socket which still logs warnings (#128726)
by hugovk Jan. 17, 2025
by hugovk Jan. 17, 2025
Jan. 17, 2025
https://github.com/python/cpython/commit/7807b407306d3c311bcc601cc279623180…
commit: 7807b407306d3c311bcc601cc279623180f8da05
branch: main
author: Thomas Grainger <tagrain(a)gmail.com>
committer: hugovk <1324225+hugovk(a)users.noreply.github.com>
date: 2025-01-17T13:39:16+02:00
summary:
gh-128770: raise warnings as errors in test suite - except for test_socket which still logs warnings (#128726)
Co-authored-by: sobolevn <mail(a)sobolevn.me>
Co-authored-by: Brett Cannon <brett(a)python.org>
files:
M Lib/test/libregrtest/main.py
M Lib/test/test_pyrepl/test_pyrepl.py
M Lib/test/test_socket.py
diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py
index dcbcc6790c68d8..cd4d512771e05f 100644
--- a/Lib/test/libregrtest/main.py
+++ b/Lib/test/libregrtest/main.py
@@ -642,9 +642,9 @@ def _add_ci_python_opts(self, python_opts, keep_environ):
if not sys.stdout.write_through:
python_opts.append('-u')
- # Add warnings filter 'default'
+ # Add warnings filter 'error'
if 'default' not in sys.warnoptions:
- python_opts.extend(('-W', 'default'))
+ python_opts.extend(('-W', 'error'))
# Error on bytes/str comparison
if sys.flags.bytes_warning < 2:
diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py
index f29a7ffbd7cafd..113ea1d2fe709f 100644
--- a/Lib/test/test_pyrepl/test_pyrepl.py
+++ b/Lib/test/test_pyrepl/test_pyrepl.py
@@ -1324,22 +1324,21 @@ def test_readline_history_file(self):
if readline.backend != "editline":
self.skipTest("GNU readline is not affected by this issue")
- hfile = tempfile.NamedTemporaryFile()
- self.addCleanup(unlink, hfile.name)
- env = os.environ.copy()
- env["PYTHON_HISTORY"] = hfile.name
-
- env["PYTHON_BASIC_REPL"] = "1"
- output, exit_code = self.run_repl("spam \nexit()\n", env=env)
- self.assertEqual(exit_code, 0)
- self.assertIn("spam ", output)
- self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
- self.assertIn("spam\\040", pathlib.Path(hfile.name).read_text())
-
- env.pop("PYTHON_BASIC_REPL", None)
- output, exit_code = self.run_repl("exit\n", env=env)
- self.assertEqual(exit_code, 0)
- self.assertNotIn("\\040", pathlib.Path(hfile.name).read_text())
+ with tempfile.NamedTemporaryFile() as hfile:
+ env = os.environ.copy()
+ env["PYTHON_HISTORY"] = hfile.name
+
+ env["PYTHON_BASIC_REPL"] = "1"
+ output, exit_code = self.run_repl("spam \nexit()\n", env=env)
+ self.assertEqual(exit_code, 0)
+ self.assertIn("spam ", output)
+ self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
+ self.assertIn("spam\\040", pathlib.Path(hfile.name).read_text())
+
+ env.pop("PYTHON_BASIC_REPL", None)
+ output, exit_code = self.run_repl("exit\n", env=env)
+ self.assertEqual(exit_code, 0)
+ self.assertNotIn("\\040", pathlib.Path(hfile.name).read_text())
def test_keyboard_interrupt_after_isearch(self):
output, exit_code = self.run_repl(["\x12", "\x03", "exit"])
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index faf326d9164e1b..7233847f37bf39 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1,7 +1,8 @@
import unittest
+import warnings
from test import support
from test.support import (
- is_apple, os_helper, refleak_helper, socket_helper, threading_helper
+ is_apple, os_helper, refleak_helper, socket_helper, threading_helper,
)
import _thread as thread
import array
@@ -198,6 +199,24 @@ def socket_setdefaulttimeout(timeout):
socket.setdefaulttimeout(old_timeout)
+(a)contextlib.contextmanager
+def downgrade_malformed_data_warning():
+ # This warning happens on macos and win, but does not always happen on linux.
+ if sys.platform not in {"win32", "darwin"}:
+ yield
+ return
+
+ with warnings.catch_warnings():
+ # TODO: gh-110012, we should investigate why this warning is happening
+ # and fix it properly.
+ warnings.filterwarnings(
+ action="always",
+ message=r"received malformed or improperly-truncated ancillary data",
+ category=RuntimeWarning,
+ )
+ yield
+
+
HAVE_SOCKET_CAN = _have_socket_can()
HAVE_SOCKET_CAN_ISOTP = _have_socket_can_isotp()
@@ -3946,8 +3965,9 @@ def checkTruncatedArray(self, ancbuf, maxdata, mindata=0):
# mindata and maxdata bytes when received with buffer size
# ancbuf, and that any complete file descriptor numbers are
# valid.
- msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock,
- len(MSG), ancbuf)
+ with downgrade_malformed_data_warning(): # TODO: gh-110012
+ msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock,
+ len(MSG), ancbuf)
self.assertEqual(msg, MSG)
self.checkRecvmsgAddress(addr, self.cli_addr)
self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC)
@@ -4298,8 +4318,9 @@ def testSingleCmsgTruncInData(self):
self.serv_sock.setsockopt(socket.IPPROTO_IPV6,
socket.IPV6_RECVHOPLIMIT, 1)
self.misc_event.set()
- msg, ancdata, flags, addr = self.doRecvmsg(
- self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1)
+ with downgrade_malformed_data_warning(): # TODO: gh-110012
+ msg, ancdata, flags, addr = self.doRecvmsg(
+ self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1)
self.assertEqual(msg, MSG)
self.checkRecvmsgAddress(addr, self.cli_addr)
@@ -4402,9 +4423,10 @@ def testSecondCmsgTruncInData(self):
self.serv_sock.setsockopt(socket.IPPROTO_IPV6,
socket.IPV6_RECVTCLASS, 1)
self.misc_event.set()
- msg, ancdata, flags, addr = self.doRecvmsg(
- self.serv_sock, len(MSG),
- socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1)
+ with downgrade_malformed_data_warning(): # TODO: gh-110012
+ msg, ancdata, flags, addr = self.doRecvmsg(
+ self.serv_sock, len(MSG),
+ socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1)
self.assertEqual(msg, MSG)
self.checkRecvmsgAddress(addr, self.cli_addr)
1
0
https://github.com/python/cpython/commit/ea6cc26e759704ac69cda07740cd484bf9…
commit: ea6cc26e759704ac69cda07740cd484bf96596ca
branch: main
author: Taneli Hukkinen <3275109+hukkin(a)users.noreply.github.com>
committer: gpshead <greg(a)krypto.org>
date: 2025-01-16T18:48:42-08:00
summary:
gh-118761: Improve import time of `tomllib` (#128907)
Improve import time of `tomllib` (in sync with upstream)
files:
A Misc/NEWS.d/next/Library/2025-01-16-10-06-40.gh-issue-118761.z100LC.rst
M Lib/test/test_tomllib/test_misc.py
M Lib/tomllib/_parser.py
M Lib/tomllib/_re.py
diff --git a/Lib/test/test_tomllib/test_misc.py b/Lib/test/test_tomllib/test_misc.py
index 9e677a337a2835..59116afa1f36ad 100644
--- a/Lib/test/test_tomllib/test_misc.py
+++ b/Lib/test/test_tomllib/test_misc.py
@@ -5,6 +5,7 @@
import copy
import datetime
from decimal import Decimal as D
+import importlib
from pathlib import Path
import sys
import tempfile
@@ -113,3 +114,11 @@ def test_inline_table_recursion_limit(self):
nest_count=nest_count):
recursive_table_toml = nest_count * "key = {" + nest_count * "}"
tomllib.loads(recursive_table_toml)
+
+ def test_types_import(self):
+ """Test that `_types` module runs.
+
+ The module is for type annotations only, so it is otherwise
+ never imported by tests.
+ """
+ importlib.import_module(f"{tomllib.__name__}._types")
diff --git a/Lib/tomllib/_parser.py b/Lib/tomllib/_parser.py
index 4d208bcfb4a9a6..0e522c3a69e6fe 100644
--- a/Lib/tomllib/_parser.py
+++ b/Lib/tomllib/_parser.py
@@ -4,11 +4,7 @@
from __future__ import annotations
-from collections.abc import Iterable
-import string
from types import MappingProxyType
-from typing import Any, BinaryIO, NamedTuple
-import warnings
from ._re import (
RE_DATETIME,
@@ -18,7 +14,13 @@
match_to_localtime,
match_to_number,
)
-from ._types import Key, ParseFloat, Pos
+
+TYPE_CHECKING = False
+if TYPE_CHECKING:
+ from collections.abc import Iterable
+ from typing import IO, Any
+
+ from ._types import Key, ParseFloat, Pos
ASCII_CTRL = frozenset(chr(i) for i in range(32)) | frozenset(chr(127))
@@ -34,9 +36,11 @@
TOML_WS = frozenset(" \t")
TOML_WS_AND_NEWLINE = TOML_WS | frozenset("\n")
-BARE_KEY_CHARS = frozenset(string.ascii_letters + string.digits + "-_")
+BARE_KEY_CHARS = frozenset(
+ "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "-_"
+)
KEY_INITIAL_CHARS = BARE_KEY_CHARS | frozenset("\"'")
-HEXDIGIT_CHARS = frozenset(string.hexdigits)
+HEXDIGIT_CHARS = frozenset("abcdef" "ABCDEF" "0123456789")
BASIC_STR_ESCAPE_REPLACEMENTS = MappingProxyType(
{
@@ -80,6 +84,8 @@ def __init__(
or not isinstance(doc, str)
or not isinstance(pos, int)
):
+ import warnings
+
warnings.warn(
"Free-form arguments for TOMLDecodeError are deprecated. "
"Please set 'msg' (str), 'doc' (str) and 'pos' (int) arguments only.",
@@ -115,7 +121,7 @@ def __init__(
self.colno = colno
-def load(fp: BinaryIO, /, *, parse_float: ParseFloat = float) -> dict[str, Any]:
+def load(fp: IO[bytes], /, *, parse_float: ParseFloat = float) -> dict[str, Any]:
"""Parse TOML from a binary file object."""
b = fp.read()
try:
@@ -139,7 +145,7 @@ def loads(s: str, /, *, parse_float: ParseFloat = float) -> dict[str, Any]: # n
f"Expected str object, not '{type(s).__qualname__}'"
) from None
pos = 0
- out = Output(NestedDict(), Flags())
+ out = Output()
header: Key = ()
parse_float = make_safe_parse_float(parse_float)
@@ -290,9 +296,10 @@ def append_nest_to_list(self, key: Key) -> None:
cont[last_key] = [{}]
-class Output(NamedTuple):
- data: NestedDict
- flags: Flags
+class Output:
+ def __init__(self) -> None:
+ self.data = NestedDict()
+ self.flags = Flags()
def skip_chars(src: str, pos: Pos, chars: Iterable[str]) -> Pos:
diff --git a/Lib/tomllib/_re.py b/Lib/tomllib/_re.py
index 9eacefc729544e..1ca6bef77a0b03 100644
--- a/Lib/tomllib/_re.py
+++ b/Lib/tomllib/_re.py
@@ -7,9 +7,12 @@
from datetime import date, datetime, time, timedelta, timezone, tzinfo
from functools import lru_cache
import re
-from typing import Any
-from ._types import ParseFloat
+TYPE_CHECKING = False
+if TYPE_CHECKING:
+ from typing import Any
+
+ from ._types import ParseFloat
# E.g.
# - 00:32:00.999999
diff --git a/Misc/NEWS.d/next/Library/2025-01-16-10-06-40.gh-issue-118761.z100LC.rst b/Misc/NEWS.d/next/Library/2025-01-16-10-06-40.gh-issue-118761.z100LC.rst
new file mode 100644
index 00000000000000..ea71ecaaeb2936
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-16-10-06-40.gh-issue-118761.z100LC.rst
@@ -0,0 +1,2 @@
+Improve import time of :mod:`tomllib` by removing ``typing``, ``string``,
+and ``tomllib._types`` imports. Patch by Taneli Hukkinen.
1
0
https://github.com/python/cpython/commit/c879de71eb4d5e88c289b654a08fc4e4da…
commit: c879de71eb4d5e88c289b654a08fc4e4dafa3b05
branch: main
author: Stan Ulbrych <89152624+StanFromIreland(a)users.noreply.github.com>
committer: gpshead <greg(a)krypto.org>
date: 2025-01-17T02:45:46Z
summary:
ACKS: Add myself (#128924)
files:
M Misc/ACKS
diff --git a/Misc/ACKS b/Misc/ACKS
index deda334bee7417..7759bd0b95ed8b 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1922,6 +1922,7 @@ Bill Tutt
Fraser Tweedale
Doobee R. Tzeck
Eren Türkay
+Stan Ulbrych
Lionel Ulmer
Adnan Umer
Utkarsh Upadhyay
1
0
Jan. 16, 2025
https://github.com/python/cpython/commit/b44ff6d0df9ec2d60be63e5a106ca07946…
commit: b44ff6d0df9ec2d60be63e5a106ca079464ece52
branch: main
author: Xuanteng Huang <44627253+xuantengh(a)users.noreply.github.com>
committer: brandtbucher <brandtbucher(a)gmail.com>
date: 2025-01-16T15:57:04-08:00
summary:
GH-126599: Remove the "counter" optimizer/executor (GH-126853)
files:
A Misc/NEWS.d/next/C_API/2025-01-01-03-25-38.gh-issue-126599.MRCYlH.rst
M Include/internal/pycore_optimizer.h
M Include/internal/pycore_uop_ids.h
M Include/internal/pycore_uop_metadata.h
M Lib/test/test_capi/test_opt.py
M Lib/test/test_monitoring.py
M Modules/_testinternalcapi.c
M Objects/object.c
M Python/bytecodes.c
M Python/executor_cases.c.h
M Python/optimizer.c
M Python/optimizer_cases.c.h
M Tools/c-analyzer/cpython/ignored.tsv
diff --git a/Include/internal/pycore_optimizer.h b/Include/internal/pycore_optimizer.h
index bc7cfcde613d65..a02b9ab4291bfc 100644
--- a/Include/internal/pycore_optimizer.h
+++ b/Include/internal/pycore_optimizer.h
@@ -98,11 +98,6 @@ struct _PyOptimizerObject {
};
/** Test support **/
-typedef struct {
- _PyOptimizerObject base;
- int64_t count;
-} _PyCounterOptimizerObject;
-
_PyOptimizerObject *_Py_SetOptimizer(PyInterpreterState *interp, _PyOptimizerObject* optimizer);
@@ -119,7 +114,6 @@ PyAPI_FUNC(void) _Py_Executor_DependsOn(_PyExecutorObject *executor, void *obj);
// Export for '_testinternalcapi' shared extension.
PyAPI_FUNC(_PyOptimizerObject *) _Py_GetOptimizer(void);
PyAPI_FUNC(int) _Py_SetTier2Optimizer(_PyOptimizerObject* optimizer);
-PyAPI_FUNC(PyObject *) _PyOptimizer_NewCounter(void);
PyAPI_FUNC(PyObject *) _PyOptimizer_NewUOpOptimizer(void);
#define _Py_MAX_ALLOWED_BUILTINS_MODIFICATIONS 3
@@ -150,8 +144,6 @@ int _Py_uop_analyze_and_optimize(struct _PyInterpreterFrame *frame,
_PyUOpInstruction *trace, int trace_len, int curr_stackentries,
_PyBloomFilter *dependencies);
-extern PyTypeObject _PyCounterExecutor_Type;
-extern PyTypeObject _PyCounterOptimizer_Type;
extern PyTypeObject _PyDefaultOptimizer_Type;
extern PyTypeObject _PyUOpExecutor_Type;
extern PyTypeObject _PyUOpOptimizer_Type;
diff --git a/Include/internal/pycore_uop_ids.h b/Include/internal/pycore_uop_ids.h
index f95defbc364aed..066165a2c810d5 100644
--- a/Include/internal/pycore_uop_ids.h
+++ b/Include/internal/pycore_uop_ids.h
@@ -164,144 +164,143 @@ extern "C" {
#define _INSTRUMENTED_POP_JUMP_IF_NONE INSTRUMENTED_POP_JUMP_IF_NONE
#define _INSTRUMENTED_POP_JUMP_IF_NOT_NONE INSTRUMENTED_POP_JUMP_IF_NOT_NONE
#define _INSTRUMENTED_POP_JUMP_IF_TRUE INSTRUMENTED_POP_JUMP_IF_TRUE
-#define _INTERNAL_INCREMENT_OPT_COUNTER 399
-#define _IS_NONE 400
+#define _IS_NONE 399
#define _IS_OP IS_OP
-#define _ITER_CHECK_LIST 401
-#define _ITER_CHECK_RANGE 402
-#define _ITER_CHECK_TUPLE 403
-#define _ITER_JUMP_LIST 404
-#define _ITER_JUMP_RANGE 405
-#define _ITER_JUMP_TUPLE 406
-#define _ITER_NEXT_LIST 407
-#define _ITER_NEXT_RANGE 408
-#define _ITER_NEXT_TUPLE 409
-#define _JUMP_TO_TOP 410
+#define _ITER_CHECK_LIST 400
+#define _ITER_CHECK_RANGE 401
+#define _ITER_CHECK_TUPLE 402
+#define _ITER_JUMP_LIST 403
+#define _ITER_JUMP_RANGE 404
+#define _ITER_JUMP_TUPLE 405
+#define _ITER_NEXT_LIST 406
+#define _ITER_NEXT_RANGE 407
+#define _ITER_NEXT_TUPLE 408
+#define _JUMP_TO_TOP 409
#define _LIST_APPEND LIST_APPEND
#define _LIST_EXTEND LIST_EXTEND
-#define _LOAD_ATTR 411
-#define _LOAD_ATTR_CLASS 412
-#define _LOAD_ATTR_CLASS_0 413
-#define _LOAD_ATTR_CLASS_1 414
+#define _LOAD_ATTR 410
+#define _LOAD_ATTR_CLASS 411
+#define _LOAD_ATTR_CLASS_0 412
+#define _LOAD_ATTR_CLASS_1 413
#define _LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN
-#define _LOAD_ATTR_INSTANCE_VALUE 415
-#define _LOAD_ATTR_INSTANCE_VALUE_0 416
-#define _LOAD_ATTR_INSTANCE_VALUE_1 417
-#define _LOAD_ATTR_METHOD_LAZY_DICT 418
-#define _LOAD_ATTR_METHOD_NO_DICT 419
-#define _LOAD_ATTR_METHOD_WITH_VALUES 420
-#define _LOAD_ATTR_MODULE 421
-#define _LOAD_ATTR_MODULE_FROM_KEYS 422
-#define _LOAD_ATTR_NONDESCRIPTOR_NO_DICT 423
-#define _LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 424
-#define _LOAD_ATTR_PROPERTY_FRAME 425
-#define _LOAD_ATTR_SLOT 426
-#define _LOAD_ATTR_SLOT_0 427
-#define _LOAD_ATTR_SLOT_1 428
-#define _LOAD_ATTR_WITH_HINT 429
+#define _LOAD_ATTR_INSTANCE_VALUE 414
+#define _LOAD_ATTR_INSTANCE_VALUE_0 415
+#define _LOAD_ATTR_INSTANCE_VALUE_1 416
+#define _LOAD_ATTR_METHOD_LAZY_DICT 417
+#define _LOAD_ATTR_METHOD_NO_DICT 418
+#define _LOAD_ATTR_METHOD_WITH_VALUES 419
+#define _LOAD_ATTR_MODULE 420
+#define _LOAD_ATTR_MODULE_FROM_KEYS 421
+#define _LOAD_ATTR_NONDESCRIPTOR_NO_DICT 422
+#define _LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 423
+#define _LOAD_ATTR_PROPERTY_FRAME 424
+#define _LOAD_ATTR_SLOT 425
+#define _LOAD_ATTR_SLOT_0 426
+#define _LOAD_ATTR_SLOT_1 427
+#define _LOAD_ATTR_WITH_HINT 428
#define _LOAD_BUILD_CLASS LOAD_BUILD_CLASS
-#define _LOAD_BYTECODE 430
+#define _LOAD_BYTECODE 429
#define _LOAD_COMMON_CONSTANT LOAD_COMMON_CONSTANT
#define _LOAD_CONST LOAD_CONST
#define _LOAD_CONST_IMMORTAL LOAD_CONST_IMMORTAL
-#define _LOAD_CONST_INLINE 431
-#define _LOAD_CONST_INLINE_BORROW 432
-#define _LOAD_CONST_INLINE_BORROW_WITH_NULL 433
-#define _LOAD_CONST_INLINE_WITH_NULL 434
+#define _LOAD_CONST_INLINE 430
+#define _LOAD_CONST_INLINE_BORROW 431
+#define _LOAD_CONST_INLINE_BORROW_WITH_NULL 432
+#define _LOAD_CONST_INLINE_WITH_NULL 433
#define _LOAD_CONST_MORTAL LOAD_CONST_MORTAL
#define _LOAD_DEREF LOAD_DEREF
-#define _LOAD_FAST 435
-#define _LOAD_FAST_0 436
-#define _LOAD_FAST_1 437
-#define _LOAD_FAST_2 438
-#define _LOAD_FAST_3 439
-#define _LOAD_FAST_4 440
-#define _LOAD_FAST_5 441
-#define _LOAD_FAST_6 442
-#define _LOAD_FAST_7 443
+#define _LOAD_FAST 434
+#define _LOAD_FAST_0 435
+#define _LOAD_FAST_1 436
+#define _LOAD_FAST_2 437
+#define _LOAD_FAST_3 438
+#define _LOAD_FAST_4 439
+#define _LOAD_FAST_5 440
+#define _LOAD_FAST_6 441
+#define _LOAD_FAST_7 442
#define _LOAD_FAST_AND_CLEAR LOAD_FAST_AND_CLEAR
#define _LOAD_FAST_CHECK LOAD_FAST_CHECK
#define _LOAD_FAST_LOAD_FAST LOAD_FAST_LOAD_FAST
#define _LOAD_FROM_DICT_OR_DEREF LOAD_FROM_DICT_OR_DEREF
#define _LOAD_FROM_DICT_OR_GLOBALS LOAD_FROM_DICT_OR_GLOBALS
-#define _LOAD_GLOBAL 444
-#define _LOAD_GLOBAL_BUILTINS 445
-#define _LOAD_GLOBAL_BUILTINS_FROM_KEYS 446
-#define _LOAD_GLOBAL_MODULE 447
-#define _LOAD_GLOBAL_MODULE_FROM_KEYS 448
+#define _LOAD_GLOBAL 443
+#define _LOAD_GLOBAL_BUILTINS 444
+#define _LOAD_GLOBAL_BUILTINS_FROM_KEYS 445
+#define _LOAD_GLOBAL_MODULE 446
+#define _LOAD_GLOBAL_MODULE_FROM_KEYS 447
#define _LOAD_LOCALS LOAD_LOCALS
#define _LOAD_NAME LOAD_NAME
-#define _LOAD_SMALL_INT 449
-#define _LOAD_SMALL_INT_0 450
-#define _LOAD_SMALL_INT_1 451
-#define _LOAD_SMALL_INT_2 452
-#define _LOAD_SMALL_INT_3 453
+#define _LOAD_SMALL_INT 448
+#define _LOAD_SMALL_INT_0 449
+#define _LOAD_SMALL_INT_1 450
+#define _LOAD_SMALL_INT_2 451
+#define _LOAD_SMALL_INT_3 452
#define _LOAD_SPECIAL LOAD_SPECIAL
#define _LOAD_SUPER_ATTR_ATTR LOAD_SUPER_ATTR_ATTR
#define _LOAD_SUPER_ATTR_METHOD LOAD_SUPER_ATTR_METHOD
-#define _MAKE_CALLARGS_A_TUPLE 454
+#define _MAKE_CALLARGS_A_TUPLE 453
#define _MAKE_CELL MAKE_CELL
#define _MAKE_FUNCTION MAKE_FUNCTION
-#define _MAKE_WARM 455
+#define _MAKE_WARM 454
#define _MAP_ADD MAP_ADD
#define _MATCH_CLASS MATCH_CLASS
#define _MATCH_KEYS MATCH_KEYS
#define _MATCH_MAPPING MATCH_MAPPING
#define _MATCH_SEQUENCE MATCH_SEQUENCE
-#define _MAYBE_EXPAND_METHOD 456
-#define _MAYBE_EXPAND_METHOD_KW 457
-#define _MONITOR_CALL 458
-#define _MONITOR_JUMP_BACKWARD 459
-#define _MONITOR_RESUME 460
+#define _MAYBE_EXPAND_METHOD 455
+#define _MAYBE_EXPAND_METHOD_KW 456
+#define _MONITOR_CALL 457
+#define _MONITOR_JUMP_BACKWARD 458
+#define _MONITOR_RESUME 459
#define _NOP NOP
#define _POP_EXCEPT POP_EXCEPT
-#define _POP_JUMP_IF_FALSE 461
-#define _POP_JUMP_IF_TRUE 462
+#define _POP_JUMP_IF_FALSE 460
+#define _POP_JUMP_IF_TRUE 461
#define _POP_TOP POP_TOP
-#define _POP_TOP_LOAD_CONST_INLINE_BORROW 463
+#define _POP_TOP_LOAD_CONST_INLINE_BORROW 462
#define _PUSH_EXC_INFO PUSH_EXC_INFO
-#define _PUSH_FRAME 464
+#define _PUSH_FRAME 463
#define _PUSH_NULL PUSH_NULL
-#define _PY_FRAME_GENERAL 465
-#define _PY_FRAME_KW 466
-#define _QUICKEN_RESUME 467
-#define _REPLACE_WITH_TRUE 468
+#define _PY_FRAME_GENERAL 464
+#define _PY_FRAME_KW 465
+#define _QUICKEN_RESUME 466
+#define _REPLACE_WITH_TRUE 467
#define _RESUME_CHECK RESUME_CHECK
#define _RETURN_GENERATOR RETURN_GENERATOR
#define _RETURN_VALUE RETURN_VALUE
-#define _SAVE_RETURN_OFFSET 469
-#define _SEND 470
-#define _SEND_GEN_FRAME 471
+#define _SAVE_RETURN_OFFSET 468
+#define _SEND 469
+#define _SEND_GEN_FRAME 470
#define _SETUP_ANNOTATIONS SETUP_ANNOTATIONS
#define _SET_ADD SET_ADD
#define _SET_FUNCTION_ATTRIBUTE SET_FUNCTION_ATTRIBUTE
#define _SET_UPDATE SET_UPDATE
-#define _START_EXECUTOR 472
-#define _STORE_ATTR 473
-#define _STORE_ATTR_INSTANCE_VALUE 474
-#define _STORE_ATTR_SLOT 475
-#define _STORE_ATTR_WITH_HINT 476
+#define _START_EXECUTOR 471
+#define _STORE_ATTR 472
+#define _STORE_ATTR_INSTANCE_VALUE 473
+#define _STORE_ATTR_SLOT 474
+#define _STORE_ATTR_WITH_HINT 475
#define _STORE_DEREF STORE_DEREF
-#define _STORE_FAST 477
-#define _STORE_FAST_0 478
-#define _STORE_FAST_1 479
-#define _STORE_FAST_2 480
-#define _STORE_FAST_3 481
-#define _STORE_FAST_4 482
-#define _STORE_FAST_5 483
-#define _STORE_FAST_6 484
-#define _STORE_FAST_7 485
+#define _STORE_FAST 476
+#define _STORE_FAST_0 477
+#define _STORE_FAST_1 478
+#define _STORE_FAST_2 479
+#define _STORE_FAST_3 480
+#define _STORE_FAST_4 481
+#define _STORE_FAST_5 482
+#define _STORE_FAST_6 483
+#define _STORE_FAST_7 484
#define _STORE_FAST_LOAD_FAST STORE_FAST_LOAD_FAST
#define _STORE_FAST_STORE_FAST STORE_FAST_STORE_FAST
#define _STORE_GLOBAL STORE_GLOBAL
#define _STORE_NAME STORE_NAME
-#define _STORE_SLICE 486
-#define _STORE_SUBSCR 487
+#define _STORE_SLICE 485
+#define _STORE_SUBSCR 486
#define _STORE_SUBSCR_DICT STORE_SUBSCR_DICT
#define _STORE_SUBSCR_LIST_INT STORE_SUBSCR_LIST_INT
#define _SWAP SWAP
-#define _TIER2_RESUME_CHECK 488
-#define _TO_BOOL 489
+#define _TIER2_RESUME_CHECK 487
+#define _TO_BOOL 488
#define _TO_BOOL_BOOL TO_BOOL_BOOL
#define _TO_BOOL_INT TO_BOOL_INT
#define _TO_BOOL_LIST TO_BOOL_LIST
@@ -311,13 +310,13 @@ extern "C" {
#define _UNARY_NEGATIVE UNARY_NEGATIVE
#define _UNARY_NOT UNARY_NOT
#define _UNPACK_EX UNPACK_EX
-#define _UNPACK_SEQUENCE 490
+#define _UNPACK_SEQUENCE 489
#define _UNPACK_SEQUENCE_LIST UNPACK_SEQUENCE_LIST
#define _UNPACK_SEQUENCE_TUPLE UNPACK_SEQUENCE_TUPLE
#define _UNPACK_SEQUENCE_TWO_TUPLE UNPACK_SEQUENCE_TWO_TUPLE
#define _WITH_EXCEPT_START WITH_EXCEPT_START
#define _YIELD_VALUE YIELD_VALUE
-#define MAX_UOP_ID 490
+#define MAX_UOP_ID 489
#ifdef __cplusplus
}
diff --git a/Include/internal/pycore_uop_metadata.h b/Include/internal/pycore_uop_metadata.h
index 298e918b872c62..7b28667a26e94d 100644
--- a/Include/internal/pycore_uop_metadata.h
+++ b/Include/internal/pycore_uop_metadata.h
@@ -288,7 +288,6 @@ const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = {
[_LOAD_GLOBAL_MODULE] = HAS_ARG_FLAG | HAS_DEOPT_FLAG,
[_LOAD_GLOBAL_BUILTINS] = HAS_ARG_FLAG | HAS_DEOPT_FLAG,
[_LOAD_ATTR_MODULE] = HAS_ARG_FLAG | HAS_DEOPT_FLAG,
- [_INTERNAL_INCREMENT_OPT_COUNTER] = 0,
[_DYNAMIC_EXIT] = HAS_ESCAPES_FLAG,
[_START_EXECUTOR] = HAS_ESCAPES_FLAG,
[_MAKE_WARM] = 0,
@@ -445,7 +444,6 @@ const char *const _PyOpcode_uop_name[MAX_UOP_ID+1] = {
[_INIT_CALL_PY_EXACT_ARGS_2] = "_INIT_CALL_PY_EXACT_ARGS_2",
[_INIT_CALL_PY_EXACT_ARGS_3] = "_INIT_CALL_PY_EXACT_ARGS_3",
[_INIT_CALL_PY_EXACT_ARGS_4] = "_INIT_CALL_PY_EXACT_ARGS_4",
- [_INTERNAL_INCREMENT_OPT_COUNTER] = "_INTERNAL_INCREMENT_OPT_COUNTER",
[_IS_NONE] = "_IS_NONE",
[_IS_OP] = "_IS_OP",
[_ITER_CHECK_LIST] = "_ITER_CHECK_LIST",
@@ -1127,8 +1125,6 @@ int _PyUop_num_popped(int opcode, int oparg)
return 0;
case _LOAD_ATTR_MODULE:
return 1;
- case _INTERNAL_INCREMENT_OPT_COUNTER:
- return 1;
case _DYNAMIC_EXIT:
return 0;
case _START_EXECUTOR:
diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py
index 12542d8b7fa62e..a74b8fdd3923b7 100644
--- a/Lib/test/test_capi/test_opt.py
+++ b/Lib/test/test_capi/test_opt.py
@@ -35,90 +35,6 @@ def clear_executors(func):
func.__code__ = func.__code__.replace()
-@requires_specialization
-(a)unittest.skipIf(Py_GIL_DISABLED, "optimizer not yet supported in free-threaded builds")
-(a)unittest.skipUnless(hasattr(_testinternalcapi, "get_optimizer"),
- "Requires optimizer infrastructure")
-class TestOptimizerAPI(unittest.TestCase):
-
- def test_new_counter_optimizer_dealloc(self):
- # See gh-108727
- def f():
- _testinternalcapi.new_counter_optimizer()
-
- f()
-
- def test_get_set_optimizer(self):
- old = _testinternalcapi.get_optimizer()
- opt = _testinternalcapi.new_counter_optimizer()
- try:
- _testinternalcapi.set_optimizer(opt)
- self.assertEqual(_testinternalcapi.get_optimizer(), opt)
- _testinternalcapi.set_optimizer(None)
- self.assertEqual(_testinternalcapi.get_optimizer(), None)
- finally:
- _testinternalcapi.set_optimizer(old)
-
-
- def test_counter_optimizer(self):
- # Generate a new function at each call
- ns = {}
- exec(textwrap.dedent(f"""
- def loop():
- for _ in range({TIER2_THRESHOLD + 1000}):
- pass
- """), ns, ns)
- loop = ns['loop']
-
- for repeat in range(5):
- opt = _testinternalcapi.new_counter_optimizer()
- with temporary_optimizer(opt):
- self.assertEqual(opt.get_count(), 0)
- with clear_executors(loop):
- loop()
- self.assertEqual(opt.get_count(), 1001)
-
- def test_long_loop(self):
- "Check that we aren't confused by EXTENDED_ARG"
-
- # Generate a new function at each call
- ns = {}
- exec(textwrap.dedent(f"""
- def nop():
- pass
-
- def long_loop():
- for _ in range({TIER2_THRESHOLD + 20}):
- nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
- nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
- nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
- nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
- nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
- nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
- nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
- """), ns, ns)
- long_loop = ns['long_loop']
-
- opt = _testinternalcapi.new_counter_optimizer()
- with temporary_optimizer(opt):
- self.assertEqual(opt.get_count(), 0)
- long_loop()
- self.assertEqual(opt.get_count(), 21) # Need iterations to warm up
-
- def test_code_restore_for_ENTER_EXECUTOR(self):
- def testfunc(x):
- i = 0
- while i < x:
- i += 1
-
- opt = _testinternalcapi.new_counter_optimizer()
- with temporary_optimizer(opt):
- testfunc(1000)
- code, replace_code = testfunc.__code__, testfunc.__code__.replace()
- self.assertEqual(code, replace_code)
- self.assertEqual(hash(code), hash(replace_code))
-
-
def get_first_executor(func):
code = func.__code__
co_code = code.co_code
@@ -145,14 +61,6 @@ def get_opnames(ex):
"Requires optimizer infrastructure")
class TestExecutorInvalidation(unittest.TestCase):
- def setUp(self):
- self.old = _testinternalcapi.get_optimizer()
- self.opt = _testinternalcapi.new_counter_optimizer()
- _testinternalcapi.set_optimizer(self.opt)
-
- def tearDown(self):
- _testinternalcapi.set_optimizer(self.old)
-
def test_invalidate_object(self):
# Generate a new set of functions at each call
ns = {}
@@ -167,8 +75,10 @@ def f{n}():
funcs = [ ns[f'f{n}'] for n in range(5)]
objects = [object() for _ in range(5)]
- for f in funcs:
- f()
+ opt = _testinternalcapi.new_uop_optimizer()
+ with temporary_optimizer(opt):
+ for f in funcs:
+ f()
executors = [get_first_executor(f) for f in funcs]
# Set things up so each executor depends on the objects
# with an equal or lower index.
diff --git a/Lib/test/test_monitoring.py b/Lib/test/test_monitoring.py
index bea0e48883bf9a..364381e7dce00a 100644
--- a/Lib/test/test_monitoring.py
+++ b/Lib/test/test_monitoring.py
@@ -12,7 +12,6 @@
import test.support
from test.support import requires_specialization_ft, script_helper
-from test.support.import_helper import import_module
_testcapi = test.support.import_helper.import_module("_testcapi")
@@ -2087,20 +2086,6 @@ def callback(code, instruction_offset):
class TestOptimizer(MonitoringTestBase, unittest.TestCase):
- def setUp(self):
- _testinternalcapi = import_module("_testinternalcapi")
- if hasattr(_testinternalcapi, "get_optimizer"):
- self.old_opt = _testinternalcapi.get_optimizer()
- opt = _testinternalcapi.new_counter_optimizer()
- _testinternalcapi.set_optimizer(opt)
- super(TestOptimizer, self).setUp()
-
- def tearDown(self):
- super(TestOptimizer, self).tearDown()
- import _testinternalcapi
- if hasattr(_testinternalcapi, "get_optimizer"):
- _testinternalcapi.set_optimizer(self.old_opt)
-
def test_for_loop(self):
def test_func(x):
i = 0
diff --git a/Misc/NEWS.d/next/C_API/2025-01-01-03-25-38.gh-issue-126599.MRCYlH.rst b/Misc/NEWS.d/next/C_API/2025-01-01-03-25-38.gh-issue-126599.MRCYlH.rst
new file mode 100644
index 00000000000000..8362ee3a2b1760
--- /dev/null
+++ b/Misc/NEWS.d/next/C_API/2025-01-01-03-25-38.gh-issue-126599.MRCYlH.rst
@@ -0,0 +1 @@
+Remove some internal test APIs for the experimental JIT compiler.
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index 150d34d168f5e4..98aea5b596e920 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -989,12 +989,6 @@ get_co_framesize(PyObject *self, PyObject *arg)
#ifdef _Py_TIER2
-static PyObject *
-new_counter_optimizer(PyObject *self, PyObject *arg)
-{
- return _PyOptimizer_NewCounter();
-}
-
static PyObject *
new_uop_optimizer(PyObject *self, PyObject *arg)
{
@@ -1034,12 +1028,6 @@ add_executor_dependency(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "OO", &exec, &obj)) {
return NULL;
}
- /* No way to tell in general if exec is an executor, so we only accept
- * counting_executor */
- if (strcmp(Py_TYPE(exec)->tp_name, "counting_executor")) {
- PyErr_SetString(PyExc_TypeError, "argument must be a counting_executor");
- return NULL;
- }
_Py_Executor_DependsOn((_PyExecutorObject *)exec, obj);
Py_RETURN_NONE;
}
@@ -2101,7 +2089,6 @@ static PyMethodDef module_functions[] = {
#ifdef _Py_TIER2
{"get_optimizer", get_optimizer, METH_NOARGS, NULL},
{"set_optimizer", set_optimizer, METH_O, NULL},
- {"new_counter_optimizer", new_counter_optimizer, METH_NOARGS, NULL},
{"new_uop_optimizer", new_uop_optimizer, METH_NOARGS, NULL},
{"add_executor_dependency", add_executor_dependency, METH_VARARGS, NULL},
{"invalidate_executors", invalidate_executors, METH_O, NULL},
diff --git a/Objects/object.c b/Objects/object.c
index 9befd92e3231c8..4e900d8e79d91a 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -2380,8 +2380,6 @@ static PyTypeObject* static_types[] = {
&_PyContextTokenMissing_Type,
&_PyCoroWrapper_Type,
#ifdef _Py_TIER2
- &_PyCounterExecutor_Type,
- &_PyCounterOptimizer_Type,
&_PyDefaultOptimizer_Type,
#endif
&_Py_GenericAliasIterType,
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index b1d61a8707bd4c..c0ef767a9dd68b 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -5076,13 +5076,6 @@ dummy_func(
DECREF_INPUTS();
}
- /* Internal -- for testing executors */
- op(_INTERNAL_INCREMENT_OPT_COUNTER, (opt --)) {
- _PyCounterOptimizerObject *exe = (_PyCounterOptimizerObject *)PyStackRef_AsPyObjectBorrow(opt);
- exe->count++;
- DEAD(opt);
- }
-
tier2 op(_DYNAMIC_EXIT, (exit_p/4 --)) {
tstate->previous_executor = (PyObject *)current_executor;
_PyExitData *exit = (_PyExitData *)exit_p;
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index ad825881c8228c..e2eaca2c90fa76 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -6209,16 +6209,6 @@
break;
}
- case _INTERNAL_INCREMENT_OPT_COUNTER: {
- _PyStackRef opt;
- opt = stack_pointer[-1];
- _PyCounterOptimizerObject *exe = (_PyCounterOptimizerObject *)PyStackRef_AsPyObjectBorrow(opt);
- exe->count++;
- stack_pointer += -1;
- assert(WITHIN_STACK_BOUNDS());
- break;
- }
-
case _DYNAMIC_EXIT: {
PyObject *exit_p = (PyObject *)CURRENT_OPERAND0();
tstate->previous_executor = (PyObject *)current_executor;
diff --git a/Python/optimizer.c b/Python/optimizer.c
index 52b3f0a84afedf..9beb47246eb3d6 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -132,8 +132,6 @@ _Py_GetOptimizer(void)
static _PyExecutorObject *
make_executor_from_uops(_PyUOpInstruction *buffer, int length, const _PyBloomFilter *dependencies);
-static const _PyBloomFilter EMPTY_FILTER = { 0 };
-
_PyOptimizerObject *
_Py_SetOptimizer(PyInterpreterState *interp, _PyOptimizerObject *optimizer)
{
@@ -251,13 +249,6 @@ get_oparg(PyObject *self, PyObject *Py_UNUSED(ignored))
return PyLong_FromUnsignedLong(((_PyExecutorObject *)self)->vm_data.oparg);
}
-static PyMethodDef executor_methods[] = {
- { "is_valid", is_valid, METH_NOARGS, NULL },
- { "get_opcode", get_opcode, METH_NOARGS, NULL },
- { "get_oparg", get_oparg, METH_NOARGS, NULL },
- { NULL, NULL },
-};
-
///////////////////// Experimental UOp Optimizer /////////////////////
static int executor_clear(_PyExecutorObject *executor);
@@ -1332,96 +1323,6 @@ _PyOptimizer_NewUOpOptimizer(void)
return (PyObject *)opt;
}
-static void
-counter_dealloc(_PyExecutorObject *self) {
- /* The optimizer is the operand of the second uop. */
- PyObject *opt = (PyObject *)self->trace[1].operand0;
- Py_DECREF(opt);
- uop_dealloc(self);
-}
-
-PyTypeObject _PyCounterExecutor_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- .tp_name = "counting_executor",
- .tp_basicsize = offsetof(_PyExecutorObject, exits),
- .tp_itemsize = 1,
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_HAVE_GC,
- .tp_dealloc = (destructor)counter_dealloc,
- .tp_methods = executor_methods,
- .tp_traverse = executor_traverse,
- .tp_clear = (inquiry)executor_clear,
-};
-
-static int
-counter_optimize(
- _PyOptimizerObject* self,
- _PyInterpreterFrame *frame,
- _Py_CODEUNIT *instr,
- _PyExecutorObject **exec_ptr,
- int Py_UNUSED(curr_stackentries),
- bool Py_UNUSED(progress_needed)
-)
-{
- PyCodeObject *code = _PyFrame_GetCode(frame);
- int oparg = instr->op.arg;
- while (instr->op.code == EXTENDED_ARG) {
- instr++;
- oparg = (oparg << 8) | instr->op.arg;
- }
- if (instr->op.code != JUMP_BACKWARD) {
- /* Counter optimizer can only handle backward edges */
- return 0;
- }
- _Py_CODEUNIT *target = instr + 1 + _PyOpcode_Caches[JUMP_BACKWARD] - oparg;
- _PyUOpInstruction buffer[4] = {
- { .opcode = _START_EXECUTOR, .jump_target = 3, .format=UOP_FORMAT_JUMP },
- { .opcode = _LOAD_CONST_INLINE, .operand0 = (uintptr_t)self },
- { .opcode = _INTERNAL_INCREMENT_OPT_COUNTER },
- { .opcode = _EXIT_TRACE, .target = (uint32_t)(target - _PyCode_CODE(code)), .format=UOP_FORMAT_TARGET }
- };
- _PyExecutorObject *executor = make_executor_from_uops(buffer, 4, &EMPTY_FILTER);
- if (executor == NULL) {
- return -1;
- }
- Py_INCREF(self);
- Py_SET_TYPE(executor, &_PyCounterExecutor_Type);
- *exec_ptr = executor;
- return 1;
-}
-
-static PyObject *
-counter_get_counter(PyObject *self, PyObject *args)
-{
- return PyLong_FromLongLong(((_PyCounterOptimizerObject *)self)->count);
-}
-
-static PyMethodDef counter_optimizer_methods[] = {
- { "get_count", counter_get_counter, METH_NOARGS, NULL },
- { NULL, NULL },
-};
-
-PyTypeObject _PyCounterOptimizer_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- .tp_name = "Counter optimizer",
- .tp_basicsize = sizeof(_PyCounterOptimizerObject),
- .tp_itemsize = 0,
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
- .tp_methods = counter_optimizer_methods,
- .tp_dealloc = (destructor)PyObject_Free,
-};
-
-PyObject *
-_PyOptimizer_NewCounter(void)
-{
- _PyCounterOptimizerObject *opt = (_PyCounterOptimizerObject *)_PyObject_New(&_PyCounterOptimizer_Type);
- if (opt == NULL) {
- return NULL;
- }
- opt->base.optimize = counter_optimize;
- opt->count = 0;
- return (PyObject *)opt;
-}
-
/*****************************************
* Executor management
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index 90838d274a5e87..1f2b29c947434f 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -2667,12 +2667,6 @@
break;
}
- case _INTERNAL_INCREMENT_OPT_COUNTER: {
- stack_pointer += -1;
- assert(WITHIN_STACK_BOUNDS());
- break;
- }
-
case _DYNAMIC_EXIT: {
break;
}
diff --git a/Tools/c-analyzer/cpython/ignored.tsv b/Tools/c-analyzer/cpython/ignored.tsv
index 213165b06866b5..da2cfedfd802c8 100644
--- a/Tools/c-analyzer/cpython/ignored.tsv
+++ b/Tools/c-analyzer/cpython/ignored.tsv
@@ -386,8 +386,6 @@ Python/sysmodule.c - _PySys_ImplCacheTag -
Python/sysmodule.c - _PySys_ImplName -
Python/sysmodule.c - whatstrings -
Python/optimizer.c - _PyDefaultOptimizer_Type -
-Python/optimizer.c - _PyCounterExecutor_Type -
-Python/optimizer.c - _PyCounterOptimizer_Type -
Python/optimizer.c - _PyUOpExecutor_Type -
Python/optimizer.c - _PyUOpOptimizer_Type -
Python/optimizer.c - _PyOptimizer_Default -
1
0
gh-121604: fix warnings in test_importlib.test_abc and test_importlib.test_windows (GH-128904)
by brettcannon Jan. 16, 2025
by brettcannon Jan. 16, 2025
Jan. 16, 2025
https://github.com/python/cpython/commit/27494dd9ad6032c29e273cd7f45c204c00…
commit: 27494dd9ad6032c29e273cd7f45c204c00d6512c
branch: main
author: Thomas Grainger <tagrain(a)gmail.com>
committer: brettcannon <brett(a)python.org>
date: 2025-01-16T13:29:16-08:00
summary:
gh-121604: fix warnings in test_importlib.test_abc and test_importlib.test_windows (GH-128904)
files:
M Lib/test/test_importlib/test_abc.py
M Lib/test/test_importlib/test_windows.py
diff --git a/Lib/test/test_importlib/test_abc.py b/Lib/test/test_importlib/test_abc.py
index 00af2dd712425a..92a77e079e57e7 100644
--- a/Lib/test/test_importlib/test_abc.py
+++ b/Lib/test/test_importlib/test_abc.py
@@ -226,7 +226,15 @@ class ResourceLoaderDefaultsTests(ABCTestHarness):
SPLIT = make_abc_subclasses(ResourceLoader)
def test_get_data(self):
- with self.assertRaises(IOError):
+ with (
+ self.assertRaises(IOError),
+ self.assertWarnsRegex(
+ DeprecationWarning,
+ r"importlib\.abc\.ResourceLoader is deprecated in favour of "
+ r"supporting resource loading through importlib\.resources"
+ r"\.abc\.TraversableResources.",
+ ),
+ ):
self.ins.get_data('/some/path')
@@ -927,9 +935,19 @@ def get_filename(self, fullname):
def path_stats(self, path):
return {'mtime': 1}
-
- loader = DummySourceLoader()
- with self.assertWarns(DeprecationWarning):
+ with self.assertWarnsRegex(
+ DeprecationWarning,
+ r"importlib\.abc\.ResourceLoader is deprecated in favour of "
+ r"supporting resource loading through importlib\.resources"
+ r"\.abc\.TraversableResources.",
+ ):
+ loader = DummySourceLoader()
+
+ with self.assertWarnsRegex(
+ DeprecationWarning,
+ r"SourceLoader\.path_mtime is deprecated in favour of "
+ r"SourceLoader\.path_stats\(\)\."
+ ):
loader.path_mtime('foo.py')
diff --git a/Lib/test/test_importlib/test_windows.py b/Lib/test/test_importlib/test_windows.py
index f32680bdbeb9e3..bef4fb46f859a4 100644
--- a/Lib/test/test_importlib/test_windows.py
+++ b/Lib/test/test_importlib/test_windows.py
@@ -91,23 +91,46 @@ class WindowsRegistryFinderTests:
test_module = "spamham{}".format(os.getpid())
def test_find_spec_missing(self):
- spec = self.machinery.WindowsRegistryFinder.find_spec('spam')
+ with self.assertWarnsRegex(
+ DeprecationWarning,
+ r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
+ r"use site configuration instead\. Future versions of Python may "
+ r"not enable this finder by default\."
+ ):
+ spec = self.machinery.WindowsRegistryFinder.find_spec('spam')
self.assertIsNone(spec)
def test_module_found(self):
with setup_module(self.machinery, self.test_module):
- spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
+ with self.assertWarnsRegex(
+ DeprecationWarning,
+ r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
+ r"use site configuration instead\. Future versions of Python may "
+ r"not enable this finder by default\."
+ ):
+ spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
self.assertIsNotNone(spec)
def test_module_not_found(self):
with setup_module(self.machinery, self.test_module, path="."):
- spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
+ with self.assertWarnsRegex(
+ DeprecationWarning,
+ r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
+ r"use site configuration instead\. Future versions of Python may "
+ r"not enable this finder by default\."
+ ):
+ spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
self.assertIsNone(spec)
def test_raises_deprecation_warning(self):
# WindowsRegistryFinder is not meant to be instantiated, so the
# deprecation warning is raised in the 'find_spec' method instead.
- with self.assertWarns(DeprecationWarning):
+ with self.assertWarnsRegex(
+ DeprecationWarning,
+ r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
+ r"use site configuration instead\. Future versions of Python may "
+ r"not enable this finder by default\."
+ ):
self.machinery.WindowsRegistryFinder.find_spec('spam')
(Frozen_WindowsRegistryFinderTests,
1
0
https://github.com/python/cpython/commit/211f41316b7f205d18eb65c1ececd7f7fb…
commit: 211f41316b7f205d18eb65c1ececd7f7fb30b02d
branch: main
author: Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి) <thatiparthysreenivas(a)gmail.com>
committer: iritkatriel <1055913+iritkatriel(a)users.noreply.github.com>
date: 2025-01-16T16:32:17Z
summary:
Fix typo in doc (#128917)
files:
M InternalDocs/generators.md
diff --git a/InternalDocs/generators.md b/InternalDocs/generators.md
index 608bd215aae65a..87fbb91236844b 100644
--- a/InternalDocs/generators.md
+++ b/InternalDocs/generators.md
@@ -11,7 +11,7 @@ execution state.
A generator object resumes execution in its frame when its `send()`
method is called. This is analogous to a function executing in its own
-fram when it is called, but a function returns to the calling frame only once,
+frame when it is called, but a function returns to the calling frame only once,
while a generator "returns" execution to the caller's frame every time
it emits a new item with a
[`yield` expression](https://docs.python.org/dev/reference/expressions.html#yield-ex….
1
0
gh-128910: Remove `_PyTrash_begin` and `_PyTrash_end` C-API functions (#128919)
by sobolevn Jan. 16, 2025
by sobolevn Jan. 16, 2025
Jan. 16, 2025
https://github.com/python/cpython/commit/f48702dade921beed3e227d2a5ac82a9ae…
commit: f48702dade921beed3e227d2a5ac82a9ae2533d0
branch: main
author: sobolevn <mail(a)sobolevn.me>
committer: sobolevn <mail(a)sobolevn.me>
date: 2025-01-16T15:41:40Z
summary:
gh-128910: Remove `_PyTrash_begin` and `_PyTrash_end` C-API functions (#128919)
files:
A Misc/NEWS.d/next/Core_and_Builtins/2025-01-16-18-16-18.gh-issue-128910.9pqfab.rst
M Include/cpython/object.h
diff --git a/Include/cpython/object.h b/Include/cpython/object.h
index c8c6bc97fa32ee..ba31e2464abf84 100644
--- a/Include/cpython/object.h
+++ b/Include/cpython/object.h
@@ -475,9 +475,6 @@ partially-deallocated object. To check this, the tp_dealloc function must be
passed as second argument to Py_TRASHCAN_BEGIN().
*/
-/* Python 3.9 private API, invoked by the macros below. */
-PyAPI_FUNC(int) _PyTrash_begin(PyThreadState *tstate, PyObject *op);
-PyAPI_FUNC(void) _PyTrash_end(PyThreadState *tstate);
PyAPI_FUNC(void) _PyTrash_thread_deposit_object(PyThreadState *tstate, PyObject *op);
PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(PyThreadState *tstate);
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-01-16-18-16-18.gh-issue-128910.9pqfab.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-01-16-18-16-18.gh-issue-128910.9pqfab.rst
new file mode 100644
index 00000000000000..e095ba9ebf6be4
--- /dev/null
+++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-01-16-18-16-18.gh-issue-128910.9pqfab.rst
@@ -0,0 +1,2 @@
+Undocumented and unused private C-API functions ``_PyTrash_begin`` and
+``_PyTrash_end`` are removed.
1
0
Jan. 16, 2025
https://github.com/python/cpython/commit/3893a92d956363fa2443bc5e47d4bae3de…
commit: 3893a92d956363fa2443bc5e47d4bae3deddacef
branch: main
author: Irit Katriel <1055913+iritkatriel(a)users.noreply.github.com>
committer: iritkatriel <1055913+iritkatriel(a)users.noreply.github.com>
date: 2025-01-16T15:22:13Z
summary:
gh-100239: specialize long tail of binary operations (#128722)
files:
A Misc/NEWS.d/next/Core_and_Builtins/2025-01-10-23-54-16.gh-issue-100239.ijOOUs.rst
M Include/internal/pycore_code.h
M Include/internal/pycore_magic_number.h
M Include/internal/pycore_opcode_metadata.h
M Include/internal/pycore_uop_ids.h
M Include/internal/pycore_uop_metadata.h
M Include/opcode_ids.h
M Lib/_opcode_metadata.py
M Lib/opcode.py
M Lib/test/test_code.py
M Lib/test/test_dis.py
M Lib/test/test_monitoring.py
M Lib/test/test_opcache.py
M Python/bytecodes.c
M Python/executor_cases.c.h
M Python/generated_cases.c.h
M Python/opcode_targets.h
M Python/optimizer_cases.c.h
M Python/specialize.c
M Tools/c-analyzer/cpython/ignored.tsv
M Tools/cases_generator/parsing.py
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index d97fe81a2fc54a..01d41446fdb0cf 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -100,6 +100,7 @@ typedef struct {
typedef struct {
_Py_BackoffCounter counter;
+ uint16_t external_cache[4];
} _PyBinaryOpCache;
#define INLINE_CACHE_ENTRIES_BINARY_OP CACHE_ENTRIES(_PyBinaryOpCache)
@@ -438,7 +439,7 @@ write_u64(uint16_t *p, uint64_t val)
}
static inline void
-write_obj(uint16_t *p, PyObject *val)
+write_ptr(uint16_t *p, void *val)
{
memcpy(p, &val, sizeof(val));
}
@@ -576,6 +577,16 @@ adaptive_counter_backoff(_Py_BackoffCounter counter) {
return restart_backoff_counter(counter);
}
+/* Specialization Extensions */
+
+/* callbacks for an external specialization */
+typedef int (*binaryopguardfunc)(PyObject *lhs, PyObject *rhs);
+typedef PyObject *(*binaryopactionfunc)(PyObject *lhs, PyObject *rhs);
+
+typedef struct {
+ binaryopguardfunc guard;
+ binaryopactionfunc action;
+} _PyBinaryOpSpecializationDescr;
/* Comparison bit masks. */
diff --git a/Include/internal/pycore_magic_number.h b/Include/internal/pycore_magic_number.h
index 8b3d6285c1e4e7..1dd155abf3babf 100644
--- a/Include/internal/pycore_magic_number.h
+++ b/Include/internal/pycore_magic_number.h
@@ -266,6 +266,7 @@ Known values:
Python 3.14a4 3611 (Add NOT_TAKEN instruction)
Python 3.14a4 3612 (Add POP_ITER and INSTRUMENTED_POP_ITER)
Python 3.14a4 3613 (Add LOAD_CONST_MORTAL instruction)
+ Python 3.14a5 3614 (Add BINARY_OP_EXTEND)
Python 3.15 will start with 3650
@@ -278,7 +279,7 @@ PC/launcher.c must also be updated.
*/
-#define PYC_MAGIC_NUMBER 3613
+#define PYC_MAGIC_NUMBER 3614
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
(little-endian) and then appending b'\r\n'. */
#define PYC_MAGIC_NUMBER_TOKEN \
diff --git a/Include/internal/pycore_opcode_metadata.h b/Include/internal/pycore_opcode_metadata.h
index 0c0a6145bdbb27..f7c23ad634d6be 100644
--- a/Include/internal/pycore_opcode_metadata.h
+++ b/Include/internal/pycore_opcode_metadata.h
@@ -43,6 +43,8 @@ int _PyOpcode_num_popped(int opcode, int oparg) {
return 2;
case BINARY_OP_ADD_UNICODE:
return 2;
+ case BINARY_OP_EXTEND:
+ return 2;
case BINARY_OP_INPLACE_ADD_UNICODE:
return 2;
case BINARY_OP_MULTIPLY_FLOAT:
@@ -512,6 +514,8 @@ int _PyOpcode_num_pushed(int opcode, int oparg) {
return 1;
case BINARY_OP_ADD_UNICODE:
return 1;
+ case BINARY_OP_EXTEND:
+ return 1;
case BINARY_OP_INPLACE_ADD_UNICODE:
return 0;
case BINARY_OP_MULTIPLY_FLOAT:
@@ -989,6 +993,10 @@ int _PyOpcode_max_stack_effect(int opcode, int oparg, int *effect) {
*effect = 0;
return 0;
}
+ case BINARY_OP_EXTEND: {
+ *effect = 0;
+ return 0;
+ }
case BINARY_OP_INPLACE_ADD_UNICODE: {
*effect = 0;
return 0;
@@ -1919,11 +1927,13 @@ enum InstructionFormat {
INSTR_FMT_IBC = 2,
INSTR_FMT_IBC00 = 3,
INSTR_FMT_IBC000 = 4,
- INSTR_FMT_IBC00000000 = 5,
- INSTR_FMT_IX = 6,
- INSTR_FMT_IXC = 7,
- INSTR_FMT_IXC00 = 8,
- INSTR_FMT_IXC000 = 9,
+ INSTR_FMT_IBC0000 = 5,
+ INSTR_FMT_IBC00000000 = 6,
+ INSTR_FMT_IX = 7,
+ INSTR_FMT_IXC = 8,
+ INSTR_FMT_IXC00 = 9,
+ INSTR_FMT_IXC000 = 10,
+ INSTR_FMT_IXC0000 = 11,
};
#define IS_VALID_OPCODE(OP) \
@@ -1981,15 +1991,16 @@ struct opcode_metadata {
extern const struct opcode_metadata _PyOpcode_opcode_metadata[266];
#ifdef NEED_OPCODE_METADATA
const struct opcode_metadata _PyOpcode_opcode_metadata[266] = {
- [BINARY_OP] = { true, INSTR_FMT_IBC, HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
- [BINARY_OP_ADD_FLOAT] = { true, INSTR_FMT_IXC, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
- [BINARY_OP_ADD_INT] = { true, INSTR_FMT_IXC, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
- [BINARY_OP_ADD_UNICODE] = { true, INSTR_FMT_IXC, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
- [BINARY_OP_INPLACE_ADD_UNICODE] = { true, INSTR_FMT_IXC, HAS_LOCAL_FLAG | HAS_DEOPT_FLAG | HAS_EXIT_FLAG | HAS_ERROR_FLAG },
- [BINARY_OP_MULTIPLY_FLOAT] = { true, INSTR_FMT_IXC, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
- [BINARY_OP_MULTIPLY_INT] = { true, INSTR_FMT_IXC, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
- [BINARY_OP_SUBTRACT_FLOAT] = { true, INSTR_FMT_IXC, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
- [BINARY_OP_SUBTRACT_INT] = { true, INSTR_FMT_IXC, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
+ [BINARY_OP] = { true, INSTR_FMT_IBC0000, HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
+ [BINARY_OP_ADD_FLOAT] = { true, INSTR_FMT_IXC0000, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
+ [BINARY_OP_ADD_INT] = { true, INSTR_FMT_IXC0000, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
+ [BINARY_OP_ADD_UNICODE] = { true, INSTR_FMT_IXC0000, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
+ [BINARY_OP_EXTEND] = { true, INSTR_FMT_IXC0000, HAS_EXIT_FLAG | HAS_ESCAPES_FLAG },
+ [BINARY_OP_INPLACE_ADD_UNICODE] = { true, INSTR_FMT_IXC0000, HAS_LOCAL_FLAG | HAS_DEOPT_FLAG | HAS_EXIT_FLAG | HAS_ERROR_FLAG },
+ [BINARY_OP_MULTIPLY_FLOAT] = { true, INSTR_FMT_IXC0000, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
+ [BINARY_OP_MULTIPLY_INT] = { true, INSTR_FMT_IXC0000, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
+ [BINARY_OP_SUBTRACT_FLOAT] = { true, INSTR_FMT_IXC0000, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
+ [BINARY_OP_SUBTRACT_INT] = { true, INSTR_FMT_IXC0000, HAS_EXIT_FLAG | HAS_ERROR_FLAG },
[BINARY_SLICE] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
[BINARY_SUBSCR] = { true, INSTR_FMT_IXC, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
[BINARY_SUBSCR_DICT] = { true, INSTR_FMT_IXC, HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
@@ -2227,6 +2238,7 @@ _PyOpcode_macro_expansion[256] = {
[BINARY_OP_ADD_FLOAT] = { .nuops = 2, .uops = { { _GUARD_BOTH_FLOAT, 0, 0 }, { _BINARY_OP_ADD_FLOAT, 0, 0 } } },
[BINARY_OP_ADD_INT] = { .nuops = 2, .uops = { { _GUARD_BOTH_INT, 0, 0 }, { _BINARY_OP_ADD_INT, 0, 0 } } },
[BINARY_OP_ADD_UNICODE] = { .nuops = 2, .uops = { { _GUARD_BOTH_UNICODE, 0, 0 }, { _BINARY_OP_ADD_UNICODE, 0, 0 } } },
+ [BINARY_OP_EXTEND] = { .nuops = 2, .uops = { { _GUARD_BINARY_OP_EXTEND, 4, 1 }, { _BINARY_OP_EXTEND, 4, 1 } } },
[BINARY_OP_INPLACE_ADD_UNICODE] = { .nuops = 2, .uops = { { _GUARD_BOTH_UNICODE, 0, 0 }, { _BINARY_OP_INPLACE_ADD_UNICODE, 0, 0 } } },
[BINARY_OP_MULTIPLY_FLOAT] = { .nuops = 2, .uops = { { _GUARD_BOTH_FLOAT, 0, 0 }, { _BINARY_OP_MULTIPLY_FLOAT, 0, 0 } } },
[BINARY_OP_MULTIPLY_INT] = { .nuops = 2, .uops = { { _GUARD_BOTH_INT, 0, 0 }, { _BINARY_OP_MULTIPLY_INT, 0, 0 } } },
@@ -2411,6 +2423,7 @@ const char *_PyOpcode_OpName[266] = {
[BINARY_OP_ADD_FLOAT] = "BINARY_OP_ADD_FLOAT",
[BINARY_OP_ADD_INT] = "BINARY_OP_ADD_INT",
[BINARY_OP_ADD_UNICODE] = "BINARY_OP_ADD_UNICODE",
+ [BINARY_OP_EXTEND] = "BINARY_OP_EXTEND",
[BINARY_OP_INPLACE_ADD_UNICODE] = "BINARY_OP_INPLACE_ADD_UNICODE",
[BINARY_OP_MULTIPLY_FLOAT] = "BINARY_OP_MULTIPLY_FLOAT",
[BINARY_OP_MULTIPLY_INT] = "BINARY_OP_MULTIPLY_INT",
@@ -2661,7 +2674,7 @@ const uint8_t _PyOpcode_Caches[256] = {
[FOR_ITER] = 1,
[CALL] = 3,
[CALL_KW] = 3,
- [BINARY_OP] = 1,
+ [BINARY_OP] = 5,
};
#endif
@@ -2672,6 +2685,7 @@ const uint8_t _PyOpcode_Deopt[256] = {
[BINARY_OP_ADD_FLOAT] = BINARY_OP,
[BINARY_OP_ADD_INT] = BINARY_OP,
[BINARY_OP_ADD_UNICODE] = BINARY_OP,
+ [BINARY_OP_EXTEND] = BINARY_OP,
[BINARY_OP_INPLACE_ADD_UNICODE] = BINARY_OP,
[BINARY_OP_MULTIPLY_FLOAT] = BINARY_OP,
[BINARY_OP_MULTIPLY_INT] = BINARY_OP,
@@ -2923,7 +2937,6 @@ const uint8_t _PyOpcode_Deopt[256] = {
case 146: \
case 147: \
case 148: \
- case 229: \
case 230: \
case 231: \
case 232: \
diff --git a/Include/internal/pycore_uop_ids.h b/Include/internal/pycore_uop_ids.h
index 3841363b411eed..f95defbc364aed 100644
--- a/Include/internal/pycore_uop_ids.h
+++ b/Include/internal/pycore_uop_ids.h
@@ -15,16 +15,17 @@ extern "C" {
#define _BINARY_OP_ADD_FLOAT 303
#define _BINARY_OP_ADD_INT 304
#define _BINARY_OP_ADD_UNICODE 305
-#define _BINARY_OP_INPLACE_ADD_UNICODE 306
-#define _BINARY_OP_MULTIPLY_FLOAT 307
-#define _BINARY_OP_MULTIPLY_INT 308
-#define _BINARY_OP_SUBTRACT_FLOAT 309
-#define _BINARY_OP_SUBTRACT_INT 310
-#define _BINARY_SLICE 311
-#define _BINARY_SUBSCR 312
-#define _BINARY_SUBSCR_CHECK_FUNC 313
+#define _BINARY_OP_EXTEND 306
+#define _BINARY_OP_INPLACE_ADD_UNICODE 307
+#define _BINARY_OP_MULTIPLY_FLOAT 308
+#define _BINARY_OP_MULTIPLY_INT 309
+#define _BINARY_OP_SUBTRACT_FLOAT 310
+#define _BINARY_OP_SUBTRACT_INT 311
+#define _BINARY_SLICE 312
+#define _BINARY_SUBSCR 313
+#define _BINARY_SUBSCR_CHECK_FUNC 314
#define _BINARY_SUBSCR_DICT BINARY_SUBSCR_DICT
-#define _BINARY_SUBSCR_INIT_CALL 314
+#define _BINARY_SUBSCR_INIT_CALL 315
#define _BINARY_SUBSCR_LIST_INT BINARY_SUBSCR_LIST_INT
#define _BINARY_SUBSCR_STR_INT BINARY_SUBSCR_STR_INT
#define _BINARY_SUBSCR_TUPLE_INT BINARY_SUBSCR_TUPLE_INT
@@ -34,122 +35,123 @@ extern "C" {
#define _BUILD_SLICE BUILD_SLICE
#define _BUILD_STRING BUILD_STRING
#define _BUILD_TUPLE BUILD_TUPLE
-#define _CALL_BUILTIN_CLASS 315
-#define _CALL_BUILTIN_FAST 316
-#define _CALL_BUILTIN_FAST_WITH_KEYWORDS 317
-#define _CALL_BUILTIN_O 318
+#define _CALL_BUILTIN_CLASS 316
+#define _CALL_BUILTIN_FAST 317
+#define _CALL_BUILTIN_FAST_WITH_KEYWORDS 318
+#define _CALL_BUILTIN_O 319
#define _CALL_INTRINSIC_1 CALL_INTRINSIC_1
#define _CALL_INTRINSIC_2 CALL_INTRINSIC_2
#define _CALL_ISINSTANCE CALL_ISINSTANCE
-#define _CALL_KW_NON_PY 319
+#define _CALL_KW_NON_PY 320
#define _CALL_LEN CALL_LEN
#define _CALL_LIST_APPEND CALL_LIST_APPEND
-#define _CALL_METHOD_DESCRIPTOR_FAST 320
-#define _CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS 321
-#define _CALL_METHOD_DESCRIPTOR_NOARGS 322
-#define _CALL_METHOD_DESCRIPTOR_O 323
-#define _CALL_NON_PY_GENERAL 324
-#define _CALL_STR_1 325
-#define _CALL_TUPLE_1 326
+#define _CALL_METHOD_DESCRIPTOR_FAST 321
+#define _CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS 322
+#define _CALL_METHOD_DESCRIPTOR_NOARGS 323
+#define _CALL_METHOD_DESCRIPTOR_O 324
+#define _CALL_NON_PY_GENERAL 325
+#define _CALL_STR_1 326
+#define _CALL_TUPLE_1 327
#define _CALL_TYPE_1 CALL_TYPE_1
-#define _CHECK_AND_ALLOCATE_OBJECT 327
-#define _CHECK_ATTR_CLASS 328
-#define _CHECK_ATTR_METHOD_LAZY_DICT 329
-#define _CHECK_ATTR_MODULE_PUSH_KEYS 330
-#define _CHECK_ATTR_WITH_HINT 331
-#define _CHECK_CALL_BOUND_METHOD_EXACT_ARGS 332
+#define _CHECK_AND_ALLOCATE_OBJECT 328
+#define _CHECK_ATTR_CLASS 329
+#define _CHECK_ATTR_METHOD_LAZY_DICT 330
+#define _CHECK_ATTR_MODULE_PUSH_KEYS 331
+#define _CHECK_ATTR_WITH_HINT 332
+#define _CHECK_CALL_BOUND_METHOD_EXACT_ARGS 333
#define _CHECK_EG_MATCH CHECK_EG_MATCH
#define _CHECK_EXC_MATCH CHECK_EXC_MATCH
-#define _CHECK_FUNCTION 333
-#define _CHECK_FUNCTION_EXACT_ARGS 334
-#define _CHECK_FUNCTION_VERSION 335
-#define _CHECK_FUNCTION_VERSION_INLINE 336
-#define _CHECK_FUNCTION_VERSION_KW 337
-#define _CHECK_IS_NOT_PY_CALLABLE 338
-#define _CHECK_IS_NOT_PY_CALLABLE_KW 339
-#define _CHECK_MANAGED_OBJECT_HAS_VALUES 340
-#define _CHECK_METHOD_VERSION 341
-#define _CHECK_METHOD_VERSION_KW 342
-#define _CHECK_PEP_523 343
-#define _CHECK_PERIODIC 344
-#define _CHECK_PERIODIC_IF_NOT_YIELD_FROM 345
-#define _CHECK_STACK_SPACE 346
-#define _CHECK_STACK_SPACE_OPERAND 347
-#define _CHECK_VALIDITY 348
-#define _CHECK_VALIDITY_AND_SET_IP 349
-#define _COMPARE_OP 350
-#define _COMPARE_OP_FLOAT 351
-#define _COMPARE_OP_INT 352
-#define _COMPARE_OP_STR 353
-#define _CONTAINS_OP 354
+#define _CHECK_FUNCTION 334
+#define _CHECK_FUNCTION_EXACT_ARGS 335
+#define _CHECK_FUNCTION_VERSION 336
+#define _CHECK_FUNCTION_VERSION_INLINE 337
+#define _CHECK_FUNCTION_VERSION_KW 338
+#define _CHECK_IS_NOT_PY_CALLABLE 339
+#define _CHECK_IS_NOT_PY_CALLABLE_KW 340
+#define _CHECK_MANAGED_OBJECT_HAS_VALUES 341
+#define _CHECK_METHOD_VERSION 342
+#define _CHECK_METHOD_VERSION_KW 343
+#define _CHECK_PEP_523 344
+#define _CHECK_PERIODIC 345
+#define _CHECK_PERIODIC_IF_NOT_YIELD_FROM 346
+#define _CHECK_STACK_SPACE 347
+#define _CHECK_STACK_SPACE_OPERAND 348
+#define _CHECK_VALIDITY 349
+#define _CHECK_VALIDITY_AND_SET_IP 350
+#define _COMPARE_OP 351
+#define _COMPARE_OP_FLOAT 352
+#define _COMPARE_OP_INT 353
+#define _COMPARE_OP_STR 354
+#define _CONTAINS_OP 355
#define _CONTAINS_OP_DICT CONTAINS_OP_DICT
#define _CONTAINS_OP_SET CONTAINS_OP_SET
#define _CONVERT_VALUE CONVERT_VALUE
#define _COPY COPY
#define _COPY_FREE_VARS COPY_FREE_VARS
-#define _CREATE_INIT_FRAME 355
+#define _CREATE_INIT_FRAME 356
#define _DELETE_ATTR DELETE_ATTR
#define _DELETE_DEREF DELETE_DEREF
#define _DELETE_FAST DELETE_FAST
#define _DELETE_GLOBAL DELETE_GLOBAL
#define _DELETE_NAME DELETE_NAME
#define _DELETE_SUBSCR DELETE_SUBSCR
-#define _DEOPT 356
+#define _DEOPT 357
#define _DICT_MERGE DICT_MERGE
#define _DICT_UPDATE DICT_UPDATE
-#define _DO_CALL 357
-#define _DO_CALL_FUNCTION_EX 358
-#define _DO_CALL_KW 359
-#define _DYNAMIC_EXIT 360
+#define _DO_CALL 358
+#define _DO_CALL_FUNCTION_EX 359
+#define _DO_CALL_KW 360
+#define _DYNAMIC_EXIT 361
#define _END_FOR END_FOR
#define _END_SEND END_SEND
-#define _ERROR_POP_N 361
+#define _ERROR_POP_N 362
#define _EXIT_INIT_CHECK EXIT_INIT_CHECK
-#define _EXPAND_METHOD 362
-#define _EXPAND_METHOD_KW 363
-#define _FATAL_ERROR 364
+#define _EXPAND_METHOD 363
+#define _EXPAND_METHOD_KW 364
+#define _FATAL_ERROR 365
#define _FORMAT_SIMPLE FORMAT_SIMPLE
#define _FORMAT_WITH_SPEC FORMAT_WITH_SPEC
-#define _FOR_ITER 365
-#define _FOR_ITER_GEN_FRAME 366
-#define _FOR_ITER_TIER_TWO 367
+#define _FOR_ITER 366
+#define _FOR_ITER_GEN_FRAME 367
+#define _FOR_ITER_TIER_TWO 368
#define _GET_AITER GET_AITER
#define _GET_ANEXT GET_ANEXT
#define _GET_AWAITABLE GET_AWAITABLE
#define _GET_ITER GET_ITER
#define _GET_LEN GET_LEN
#define _GET_YIELD_FROM_ITER GET_YIELD_FROM_ITER
-#define _GUARD_BOTH_FLOAT 368
-#define _GUARD_BOTH_INT 369
-#define _GUARD_BOTH_UNICODE 370
-#define _GUARD_BUILTINS_VERSION_PUSH_KEYS 371
-#define _GUARD_DORV_NO_DICT 372
-#define _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT 373
-#define _GUARD_GLOBALS_VERSION 374
-#define _GUARD_GLOBALS_VERSION_PUSH_KEYS 375
-#define _GUARD_IS_FALSE_POP 376
-#define _GUARD_IS_NONE_POP 377
-#define _GUARD_IS_NOT_NONE_POP 378
-#define _GUARD_IS_TRUE_POP 379
-#define _GUARD_KEYS_VERSION 380
-#define _GUARD_NOS_FLOAT 381
-#define _GUARD_NOS_INT 382
-#define _GUARD_NOT_EXHAUSTED_LIST 383
-#define _GUARD_NOT_EXHAUSTED_RANGE 384
-#define _GUARD_NOT_EXHAUSTED_TUPLE 385
-#define _GUARD_TOS_FLOAT 386
-#define _GUARD_TOS_INT 387
-#define _GUARD_TYPE_VERSION 388
-#define _GUARD_TYPE_VERSION_AND_LOCK 389
+#define _GUARD_BINARY_OP_EXTEND 369
+#define _GUARD_BOTH_FLOAT 370
+#define _GUARD_BOTH_INT 371
+#define _GUARD_BOTH_UNICODE 372
+#define _GUARD_BUILTINS_VERSION_PUSH_KEYS 373
+#define _GUARD_DORV_NO_DICT 374
+#define _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT 375
+#define _GUARD_GLOBALS_VERSION 376
+#define _GUARD_GLOBALS_VERSION_PUSH_KEYS 377
+#define _GUARD_IS_FALSE_POP 378
+#define _GUARD_IS_NONE_POP 379
+#define _GUARD_IS_NOT_NONE_POP 380
+#define _GUARD_IS_TRUE_POP 381
+#define _GUARD_KEYS_VERSION 382
+#define _GUARD_NOS_FLOAT 383
+#define _GUARD_NOS_INT 384
+#define _GUARD_NOT_EXHAUSTED_LIST 385
+#define _GUARD_NOT_EXHAUSTED_RANGE 386
+#define _GUARD_NOT_EXHAUSTED_TUPLE 387
+#define _GUARD_TOS_FLOAT 388
+#define _GUARD_TOS_INT 389
+#define _GUARD_TYPE_VERSION 390
+#define _GUARD_TYPE_VERSION_AND_LOCK 391
#define _IMPORT_FROM IMPORT_FROM
#define _IMPORT_NAME IMPORT_NAME
-#define _INIT_CALL_BOUND_METHOD_EXACT_ARGS 390
-#define _INIT_CALL_PY_EXACT_ARGS 391
-#define _INIT_CALL_PY_EXACT_ARGS_0 392
-#define _INIT_CALL_PY_EXACT_ARGS_1 393
-#define _INIT_CALL_PY_EXACT_ARGS_2 394
-#define _INIT_CALL_PY_EXACT_ARGS_3 395
-#define _INIT_CALL_PY_EXACT_ARGS_4 396
+#define _INIT_CALL_BOUND_METHOD_EXACT_ARGS 392
+#define _INIT_CALL_PY_EXACT_ARGS 393
+#define _INIT_CALL_PY_EXACT_ARGS_0 394
+#define _INIT_CALL_PY_EXACT_ARGS_1 395
+#define _INIT_CALL_PY_EXACT_ARGS_2 396
+#define _INIT_CALL_PY_EXACT_ARGS_3 397
+#define _INIT_CALL_PY_EXACT_ARGS_4 398
#define _INSTRUMENTED_CALL_FUNCTION_EX INSTRUMENTED_CALL_FUNCTION_EX
#define _INSTRUMENTED_CALL_KW INSTRUMENTED_CALL_KW
#define _INSTRUMENTED_FOR_ITER INSTRUMENTED_FOR_ITER
@@ -162,144 +164,144 @@ extern "C" {
#define _INSTRUMENTED_POP_JUMP_IF_NONE INSTRUMENTED_POP_JUMP_IF_NONE
#define _INSTRUMENTED_POP_JUMP_IF_NOT_NONE INSTRUMENTED_POP_JUMP_IF_NOT_NONE
#define _INSTRUMENTED_POP_JUMP_IF_TRUE INSTRUMENTED_POP_JUMP_IF_TRUE
-#define _INTERNAL_INCREMENT_OPT_COUNTER 397
-#define _IS_NONE 398
+#define _INTERNAL_INCREMENT_OPT_COUNTER 399
+#define _IS_NONE 400
#define _IS_OP IS_OP
-#define _ITER_CHECK_LIST 399
-#define _ITER_CHECK_RANGE 400
-#define _ITER_CHECK_TUPLE 401
-#define _ITER_JUMP_LIST 402
-#define _ITER_JUMP_RANGE 403
-#define _ITER_JUMP_TUPLE 404
-#define _ITER_NEXT_LIST 405
-#define _ITER_NEXT_RANGE 406
-#define _ITER_NEXT_TUPLE 407
-#define _JUMP_TO_TOP 408
+#define _ITER_CHECK_LIST 401
+#define _ITER_CHECK_RANGE 402
+#define _ITER_CHECK_TUPLE 403
+#define _ITER_JUMP_LIST 404
+#define _ITER_JUMP_RANGE 405
+#define _ITER_JUMP_TUPLE 406
+#define _ITER_NEXT_LIST 407
+#define _ITER_NEXT_RANGE 408
+#define _ITER_NEXT_TUPLE 409
+#define _JUMP_TO_TOP 410
#define _LIST_APPEND LIST_APPEND
#define _LIST_EXTEND LIST_EXTEND
-#define _LOAD_ATTR 409
-#define _LOAD_ATTR_CLASS 410
-#define _LOAD_ATTR_CLASS_0 411
-#define _LOAD_ATTR_CLASS_1 412
+#define _LOAD_ATTR 411
+#define _LOAD_ATTR_CLASS 412
+#define _LOAD_ATTR_CLASS_0 413
+#define _LOAD_ATTR_CLASS_1 414
#define _LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN
-#define _LOAD_ATTR_INSTANCE_VALUE 413
-#define _LOAD_ATTR_INSTANCE_VALUE_0 414
-#define _LOAD_ATTR_INSTANCE_VALUE_1 415
-#define _LOAD_ATTR_METHOD_LAZY_DICT 416
-#define _LOAD_ATTR_METHOD_NO_DICT 417
-#define _LOAD_ATTR_METHOD_WITH_VALUES 418
-#define _LOAD_ATTR_MODULE 419
-#define _LOAD_ATTR_MODULE_FROM_KEYS 420
-#define _LOAD_ATTR_NONDESCRIPTOR_NO_DICT 421
-#define _LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 422
-#define _LOAD_ATTR_PROPERTY_FRAME 423
-#define _LOAD_ATTR_SLOT 424
-#define _LOAD_ATTR_SLOT_0 425
-#define _LOAD_ATTR_SLOT_1 426
-#define _LOAD_ATTR_WITH_HINT 427
+#define _LOAD_ATTR_INSTANCE_VALUE 415
+#define _LOAD_ATTR_INSTANCE_VALUE_0 416
+#define _LOAD_ATTR_INSTANCE_VALUE_1 417
+#define _LOAD_ATTR_METHOD_LAZY_DICT 418
+#define _LOAD_ATTR_METHOD_NO_DICT 419
+#define _LOAD_ATTR_METHOD_WITH_VALUES 420
+#define _LOAD_ATTR_MODULE 421
+#define _LOAD_ATTR_MODULE_FROM_KEYS 422
+#define _LOAD_ATTR_NONDESCRIPTOR_NO_DICT 423
+#define _LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 424
+#define _LOAD_ATTR_PROPERTY_FRAME 425
+#define _LOAD_ATTR_SLOT 426
+#define _LOAD_ATTR_SLOT_0 427
+#define _LOAD_ATTR_SLOT_1 428
+#define _LOAD_ATTR_WITH_HINT 429
#define _LOAD_BUILD_CLASS LOAD_BUILD_CLASS
-#define _LOAD_BYTECODE 428
+#define _LOAD_BYTECODE 430
#define _LOAD_COMMON_CONSTANT LOAD_COMMON_CONSTANT
#define _LOAD_CONST LOAD_CONST
#define _LOAD_CONST_IMMORTAL LOAD_CONST_IMMORTAL
-#define _LOAD_CONST_INLINE 429
-#define _LOAD_CONST_INLINE_BORROW 430
-#define _LOAD_CONST_INLINE_BORROW_WITH_NULL 431
-#define _LOAD_CONST_INLINE_WITH_NULL 432
+#define _LOAD_CONST_INLINE 431
+#define _LOAD_CONST_INLINE_BORROW 432
+#define _LOAD_CONST_INLINE_BORROW_WITH_NULL 433
+#define _LOAD_CONST_INLINE_WITH_NULL 434
#define _LOAD_CONST_MORTAL LOAD_CONST_MORTAL
#define _LOAD_DEREF LOAD_DEREF
-#define _LOAD_FAST 433
-#define _LOAD_FAST_0 434
-#define _LOAD_FAST_1 435
-#define _LOAD_FAST_2 436
-#define _LOAD_FAST_3 437
-#define _LOAD_FAST_4 438
-#define _LOAD_FAST_5 439
-#define _LOAD_FAST_6 440
-#define _LOAD_FAST_7 441
+#define _LOAD_FAST 435
+#define _LOAD_FAST_0 436
+#define _LOAD_FAST_1 437
+#define _LOAD_FAST_2 438
+#define _LOAD_FAST_3 439
+#define _LOAD_FAST_4 440
+#define _LOAD_FAST_5 441
+#define _LOAD_FAST_6 442
+#define _LOAD_FAST_7 443
#define _LOAD_FAST_AND_CLEAR LOAD_FAST_AND_CLEAR
#define _LOAD_FAST_CHECK LOAD_FAST_CHECK
#define _LOAD_FAST_LOAD_FAST LOAD_FAST_LOAD_FAST
#define _LOAD_FROM_DICT_OR_DEREF LOAD_FROM_DICT_OR_DEREF
#define _LOAD_FROM_DICT_OR_GLOBALS LOAD_FROM_DICT_OR_GLOBALS
-#define _LOAD_GLOBAL 442
-#define _LOAD_GLOBAL_BUILTINS 443
-#define _LOAD_GLOBAL_BUILTINS_FROM_KEYS 444
-#define _LOAD_GLOBAL_MODULE 445
-#define _LOAD_GLOBAL_MODULE_FROM_KEYS 446
+#define _LOAD_GLOBAL 444
+#define _LOAD_GLOBAL_BUILTINS 445
+#define _LOAD_GLOBAL_BUILTINS_FROM_KEYS 446
+#define _LOAD_GLOBAL_MODULE 447
+#define _LOAD_GLOBAL_MODULE_FROM_KEYS 448
#define _LOAD_LOCALS LOAD_LOCALS
#define _LOAD_NAME LOAD_NAME
-#define _LOAD_SMALL_INT 447
-#define _LOAD_SMALL_INT_0 448
-#define _LOAD_SMALL_INT_1 449
-#define _LOAD_SMALL_INT_2 450
-#define _LOAD_SMALL_INT_3 451
+#define _LOAD_SMALL_INT 449
+#define _LOAD_SMALL_INT_0 450
+#define _LOAD_SMALL_INT_1 451
+#define _LOAD_SMALL_INT_2 452
+#define _LOAD_SMALL_INT_3 453
#define _LOAD_SPECIAL LOAD_SPECIAL
#define _LOAD_SUPER_ATTR_ATTR LOAD_SUPER_ATTR_ATTR
#define _LOAD_SUPER_ATTR_METHOD LOAD_SUPER_ATTR_METHOD
-#define _MAKE_CALLARGS_A_TUPLE 452
+#define _MAKE_CALLARGS_A_TUPLE 454
#define _MAKE_CELL MAKE_CELL
#define _MAKE_FUNCTION MAKE_FUNCTION
-#define _MAKE_WARM 453
+#define _MAKE_WARM 455
#define _MAP_ADD MAP_ADD
#define _MATCH_CLASS MATCH_CLASS
#define _MATCH_KEYS MATCH_KEYS
#define _MATCH_MAPPING MATCH_MAPPING
#define _MATCH_SEQUENCE MATCH_SEQUENCE
-#define _MAYBE_EXPAND_METHOD 454
-#define _MAYBE_EXPAND_METHOD_KW 455
-#define _MONITOR_CALL 456
-#define _MONITOR_JUMP_BACKWARD 457
-#define _MONITOR_RESUME 458
+#define _MAYBE_EXPAND_METHOD 456
+#define _MAYBE_EXPAND_METHOD_KW 457
+#define _MONITOR_CALL 458
+#define _MONITOR_JUMP_BACKWARD 459
+#define _MONITOR_RESUME 460
#define _NOP NOP
#define _POP_EXCEPT POP_EXCEPT
-#define _POP_JUMP_IF_FALSE 459
-#define _POP_JUMP_IF_TRUE 460
+#define _POP_JUMP_IF_FALSE 461
+#define _POP_JUMP_IF_TRUE 462
#define _POP_TOP POP_TOP
-#define _POP_TOP_LOAD_CONST_INLINE_BORROW 461
+#define _POP_TOP_LOAD_CONST_INLINE_BORROW 463
#define _PUSH_EXC_INFO PUSH_EXC_INFO
-#define _PUSH_FRAME 462
+#define _PUSH_FRAME 464
#define _PUSH_NULL PUSH_NULL
-#define _PY_FRAME_GENERAL 463
-#define _PY_FRAME_KW 464
-#define _QUICKEN_RESUME 465
-#define _REPLACE_WITH_TRUE 466
+#define _PY_FRAME_GENERAL 465
+#define _PY_FRAME_KW 466
+#define _QUICKEN_RESUME 467
+#define _REPLACE_WITH_TRUE 468
#define _RESUME_CHECK RESUME_CHECK
#define _RETURN_GENERATOR RETURN_GENERATOR
#define _RETURN_VALUE RETURN_VALUE
-#define _SAVE_RETURN_OFFSET 467
-#define _SEND 468
-#define _SEND_GEN_FRAME 469
+#define _SAVE_RETURN_OFFSET 469
+#define _SEND 470
+#define _SEND_GEN_FRAME 471
#define _SETUP_ANNOTATIONS SETUP_ANNOTATIONS
#define _SET_ADD SET_ADD
#define _SET_FUNCTION_ATTRIBUTE SET_FUNCTION_ATTRIBUTE
#define _SET_UPDATE SET_UPDATE
-#define _START_EXECUTOR 470
-#define _STORE_ATTR 471
-#define _STORE_ATTR_INSTANCE_VALUE 472
-#define _STORE_ATTR_SLOT 473
-#define _STORE_ATTR_WITH_HINT 474
+#define _START_EXECUTOR 472
+#define _STORE_ATTR 473
+#define _STORE_ATTR_INSTANCE_VALUE 474
+#define _STORE_ATTR_SLOT 475
+#define _STORE_ATTR_WITH_HINT 476
#define _STORE_DEREF STORE_DEREF
-#define _STORE_FAST 475
-#define _STORE_FAST_0 476
-#define _STORE_FAST_1 477
-#define _STORE_FAST_2 478
-#define _STORE_FAST_3 479
-#define _STORE_FAST_4 480
-#define _STORE_FAST_5 481
-#define _STORE_FAST_6 482
-#define _STORE_FAST_7 483
+#define _STORE_FAST 477
+#define _STORE_FAST_0 478
+#define _STORE_FAST_1 479
+#define _STORE_FAST_2 480
+#define _STORE_FAST_3 481
+#define _STORE_FAST_4 482
+#define _STORE_FAST_5 483
+#define _STORE_FAST_6 484
+#define _STORE_FAST_7 485
#define _STORE_FAST_LOAD_FAST STORE_FAST_LOAD_FAST
#define _STORE_FAST_STORE_FAST STORE_FAST_STORE_FAST
#define _STORE_GLOBAL STORE_GLOBAL
#define _STORE_NAME STORE_NAME
-#define _STORE_SLICE 484
-#define _STORE_SUBSCR 485
+#define _STORE_SLICE 486
+#define _STORE_SUBSCR 487
#define _STORE_SUBSCR_DICT STORE_SUBSCR_DICT
#define _STORE_SUBSCR_LIST_INT STORE_SUBSCR_LIST_INT
#define _SWAP SWAP
-#define _TIER2_RESUME_CHECK 486
-#define _TO_BOOL 487
+#define _TIER2_RESUME_CHECK 488
+#define _TO_BOOL 489
#define _TO_BOOL_BOOL TO_BOOL_BOOL
#define _TO_BOOL_INT TO_BOOL_INT
#define _TO_BOOL_LIST TO_BOOL_LIST
@@ -309,13 +311,13 @@ extern "C" {
#define _UNARY_NEGATIVE UNARY_NEGATIVE
#define _UNARY_NOT UNARY_NOT
#define _UNPACK_EX UNPACK_EX
-#define _UNPACK_SEQUENCE 488
+#define _UNPACK_SEQUENCE 490
#define _UNPACK_SEQUENCE_LIST UNPACK_SEQUENCE_LIST
#define _UNPACK_SEQUENCE_TUPLE UNPACK_SEQUENCE_TUPLE
#define _UNPACK_SEQUENCE_TWO_TUPLE UNPACK_SEQUENCE_TWO_TUPLE
#define _WITH_EXCEPT_START WITH_EXCEPT_START
#define _YIELD_VALUE YIELD_VALUE
-#define MAX_UOP_ID 488
+#define MAX_UOP_ID 490
#ifdef __cplusplus
}
diff --git a/Include/internal/pycore_uop_metadata.h b/Include/internal/pycore_uop_metadata.h
index 5670fe26f72071..298e918b872c62 100644
--- a/Include/internal/pycore_uop_metadata.h
+++ b/Include/internal/pycore_uop_metadata.h
@@ -82,6 +82,8 @@ const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = {
[_GUARD_BOTH_UNICODE] = HAS_EXIT_FLAG,
[_BINARY_OP_ADD_UNICODE] = HAS_ERROR_FLAG | HAS_PURE_FLAG,
[_BINARY_OP_INPLACE_ADD_UNICODE] = HAS_LOCAL_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG,
+ [_GUARD_BINARY_OP_EXTEND] = HAS_EXIT_FLAG | HAS_ESCAPES_FLAG,
+ [_BINARY_OP_EXTEND] = HAS_ESCAPES_FLAG | HAS_PURE_FLAG,
[_BINARY_SUBSCR] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG,
[_BINARY_SLICE] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG,
[_STORE_SLICE] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG,
@@ -309,6 +311,7 @@ const char *const _PyOpcode_uop_name[MAX_UOP_ID+1] = {
[_BINARY_OP_ADD_FLOAT] = "_BINARY_OP_ADD_FLOAT",
[_BINARY_OP_ADD_INT] = "_BINARY_OP_ADD_INT",
[_BINARY_OP_ADD_UNICODE] = "_BINARY_OP_ADD_UNICODE",
+ [_BINARY_OP_EXTEND] = "_BINARY_OP_EXTEND",
[_BINARY_OP_INPLACE_ADD_UNICODE] = "_BINARY_OP_INPLACE_ADD_UNICODE",
[_BINARY_OP_MULTIPLY_FLOAT] = "_BINARY_OP_MULTIPLY_FLOAT",
[_BINARY_OP_MULTIPLY_INT] = "_BINARY_OP_MULTIPLY_INT",
@@ -410,6 +413,7 @@ const char *const _PyOpcode_uop_name[MAX_UOP_ID+1] = {
[_GET_ITER] = "_GET_ITER",
[_GET_LEN] = "_GET_LEN",
[_GET_YIELD_FROM_ITER] = "_GET_YIELD_FROM_ITER",
+ [_GUARD_BINARY_OP_EXTEND] = "_GUARD_BINARY_OP_EXTEND",
[_GUARD_BOTH_FLOAT] = "_GUARD_BOTH_FLOAT",
[_GUARD_BOTH_INT] = "_GUARD_BOTH_INT",
[_GUARD_BOTH_UNICODE] = "_GUARD_BOTH_UNICODE",
@@ -711,6 +715,10 @@ int _PyUop_num_popped(int opcode, int oparg)
return 2;
case _BINARY_OP_INPLACE_ADD_UNICODE:
return 2;
+ case _GUARD_BINARY_OP_EXTEND:
+ return 0;
+ case _BINARY_OP_EXTEND:
+ return 2;
case _BINARY_SUBSCR:
return 2;
case _BINARY_SLICE:
diff --git a/Include/opcode_ids.h b/Include/opcode_ids.h
index f2d8963a1813c5..06b207b347e504 100644
--- a/Include/opcode_ids.h
+++ b/Include/opcode_ids.h
@@ -132,82 +132,83 @@ extern "C" {
#define BINARY_OP_ADD_FLOAT 150
#define BINARY_OP_ADD_INT 151
#define BINARY_OP_ADD_UNICODE 152
-#define BINARY_OP_MULTIPLY_FLOAT 153
-#define BINARY_OP_MULTIPLY_INT 154
-#define BINARY_OP_SUBTRACT_FLOAT 155
-#define BINARY_OP_SUBTRACT_INT 156
-#define BINARY_SUBSCR_DICT 157
-#define BINARY_SUBSCR_GETITEM 158
-#define BINARY_SUBSCR_LIST_INT 159
-#define BINARY_SUBSCR_STR_INT 160
-#define BINARY_SUBSCR_TUPLE_INT 161
-#define CALL_ALLOC_AND_ENTER_INIT 162
-#define CALL_BOUND_METHOD_EXACT_ARGS 163
-#define CALL_BOUND_METHOD_GENERAL 164
-#define CALL_BUILTIN_CLASS 165
-#define CALL_BUILTIN_FAST 166
-#define CALL_BUILTIN_FAST_WITH_KEYWORDS 167
-#define CALL_BUILTIN_O 168
-#define CALL_ISINSTANCE 169
-#define CALL_KW_BOUND_METHOD 170
-#define CALL_KW_NON_PY 171
-#define CALL_KW_PY 172
-#define CALL_LEN 173
-#define CALL_LIST_APPEND 174
-#define CALL_METHOD_DESCRIPTOR_FAST 175
-#define CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS 176
-#define CALL_METHOD_DESCRIPTOR_NOARGS 177
-#define CALL_METHOD_DESCRIPTOR_O 178
-#define CALL_NON_PY_GENERAL 179
-#define CALL_PY_EXACT_ARGS 180
-#define CALL_PY_GENERAL 181
-#define CALL_STR_1 182
-#define CALL_TUPLE_1 183
-#define CALL_TYPE_1 184
-#define COMPARE_OP_FLOAT 185
-#define COMPARE_OP_INT 186
-#define COMPARE_OP_STR 187
-#define CONTAINS_OP_DICT 188
-#define CONTAINS_OP_SET 189
-#define FOR_ITER_GEN 190
-#define FOR_ITER_LIST 191
-#define FOR_ITER_RANGE 192
-#define FOR_ITER_TUPLE 193
-#define LOAD_ATTR_CLASS 194
-#define LOAD_ATTR_CLASS_WITH_METACLASS_CHECK 195
-#define LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN 196
-#define LOAD_ATTR_INSTANCE_VALUE 197
-#define LOAD_ATTR_METHOD_LAZY_DICT 198
-#define LOAD_ATTR_METHOD_NO_DICT 199
-#define LOAD_ATTR_METHOD_WITH_VALUES 200
-#define LOAD_ATTR_MODULE 201
-#define LOAD_ATTR_NONDESCRIPTOR_NO_DICT 202
-#define LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 203
-#define LOAD_ATTR_PROPERTY 204
-#define LOAD_ATTR_SLOT 205
-#define LOAD_ATTR_WITH_HINT 206
-#define LOAD_CONST_IMMORTAL 207
-#define LOAD_CONST_MORTAL 208
-#define LOAD_GLOBAL_BUILTIN 209
-#define LOAD_GLOBAL_MODULE 210
-#define LOAD_SUPER_ATTR_ATTR 211
-#define LOAD_SUPER_ATTR_METHOD 212
-#define RESUME_CHECK 213
-#define SEND_GEN 214
-#define STORE_ATTR_INSTANCE_VALUE 215
-#define STORE_ATTR_SLOT 216
-#define STORE_ATTR_WITH_HINT 217
-#define STORE_SUBSCR_DICT 218
-#define STORE_SUBSCR_LIST_INT 219
-#define TO_BOOL_ALWAYS_TRUE 220
-#define TO_BOOL_BOOL 221
-#define TO_BOOL_INT 222
-#define TO_BOOL_LIST 223
-#define TO_BOOL_NONE 224
-#define TO_BOOL_STR 225
-#define UNPACK_SEQUENCE_LIST 226
-#define UNPACK_SEQUENCE_TUPLE 227
-#define UNPACK_SEQUENCE_TWO_TUPLE 228
+#define BINARY_OP_EXTEND 153
+#define BINARY_OP_MULTIPLY_FLOAT 154
+#define BINARY_OP_MULTIPLY_INT 155
+#define BINARY_OP_SUBTRACT_FLOAT 156
+#define BINARY_OP_SUBTRACT_INT 157
+#define BINARY_SUBSCR_DICT 158
+#define BINARY_SUBSCR_GETITEM 159
+#define BINARY_SUBSCR_LIST_INT 160
+#define BINARY_SUBSCR_STR_INT 161
+#define BINARY_SUBSCR_TUPLE_INT 162
+#define CALL_ALLOC_AND_ENTER_INIT 163
+#define CALL_BOUND_METHOD_EXACT_ARGS 164
+#define CALL_BOUND_METHOD_GENERAL 165
+#define CALL_BUILTIN_CLASS 166
+#define CALL_BUILTIN_FAST 167
+#define CALL_BUILTIN_FAST_WITH_KEYWORDS 168
+#define CALL_BUILTIN_O 169
+#define CALL_ISINSTANCE 170
+#define CALL_KW_BOUND_METHOD 171
+#define CALL_KW_NON_PY 172
+#define CALL_KW_PY 173
+#define CALL_LEN 174
+#define CALL_LIST_APPEND 175
+#define CALL_METHOD_DESCRIPTOR_FAST 176
+#define CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS 177
+#define CALL_METHOD_DESCRIPTOR_NOARGS 178
+#define CALL_METHOD_DESCRIPTOR_O 179
+#define CALL_NON_PY_GENERAL 180
+#define CALL_PY_EXACT_ARGS 181
+#define CALL_PY_GENERAL 182
+#define CALL_STR_1 183
+#define CALL_TUPLE_1 184
+#define CALL_TYPE_1 185
+#define COMPARE_OP_FLOAT 186
+#define COMPARE_OP_INT 187
+#define COMPARE_OP_STR 188
+#define CONTAINS_OP_DICT 189
+#define CONTAINS_OP_SET 190
+#define FOR_ITER_GEN 191
+#define FOR_ITER_LIST 192
+#define FOR_ITER_RANGE 193
+#define FOR_ITER_TUPLE 194
+#define LOAD_ATTR_CLASS 195
+#define LOAD_ATTR_CLASS_WITH_METACLASS_CHECK 196
+#define LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN 197
+#define LOAD_ATTR_INSTANCE_VALUE 198
+#define LOAD_ATTR_METHOD_LAZY_DICT 199
+#define LOAD_ATTR_METHOD_NO_DICT 200
+#define LOAD_ATTR_METHOD_WITH_VALUES 201
+#define LOAD_ATTR_MODULE 202
+#define LOAD_ATTR_NONDESCRIPTOR_NO_DICT 203
+#define LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 204
+#define LOAD_ATTR_PROPERTY 205
+#define LOAD_ATTR_SLOT 206
+#define LOAD_ATTR_WITH_HINT 207
+#define LOAD_CONST_IMMORTAL 208
+#define LOAD_CONST_MORTAL 209
+#define LOAD_GLOBAL_BUILTIN 210
+#define LOAD_GLOBAL_MODULE 211
+#define LOAD_SUPER_ATTR_ATTR 212
+#define LOAD_SUPER_ATTR_METHOD 213
+#define RESUME_CHECK 214
+#define SEND_GEN 215
+#define STORE_ATTR_INSTANCE_VALUE 216
+#define STORE_ATTR_SLOT 217
+#define STORE_ATTR_WITH_HINT 218
+#define STORE_SUBSCR_DICT 219
+#define STORE_SUBSCR_LIST_INT 220
+#define TO_BOOL_ALWAYS_TRUE 221
+#define TO_BOOL_BOOL 222
+#define TO_BOOL_INT 223
+#define TO_BOOL_LIST 224
+#define TO_BOOL_NONE 225
+#define TO_BOOL_STR 226
+#define UNPACK_SEQUENCE_LIST 227
+#define UNPACK_SEQUENCE_TUPLE 228
+#define UNPACK_SEQUENCE_TWO_TUPLE 229
#define INSTRUMENTED_END_FOR 235
#define INSTRUMENTED_POP_ITER 236
#define INSTRUMENTED_END_SEND 237
diff --git a/Lib/_opcode_metadata.py b/Lib/_opcode_metadata.py
index d93e8d8df8fe4b..7dd528ef74df33 100644
--- a/Lib/_opcode_metadata.py
+++ b/Lib/_opcode_metadata.py
@@ -26,6 +26,7 @@
"BINARY_OP_ADD_FLOAT",
"BINARY_OP_SUBTRACT_FLOAT",
"BINARY_OP_ADD_UNICODE",
+ "BINARY_OP_EXTEND",
"BINARY_OP_INPLACE_ADD_UNICODE",
],
"BINARY_SUBSCR": [
@@ -123,83 +124,84 @@
'BINARY_OP_ADD_FLOAT': 150,
'BINARY_OP_ADD_INT': 151,
'BINARY_OP_ADD_UNICODE': 152,
+ 'BINARY_OP_EXTEND': 153,
'BINARY_OP_INPLACE_ADD_UNICODE': 3,
- 'BINARY_OP_MULTIPLY_FLOAT': 153,
- 'BINARY_OP_MULTIPLY_INT': 154,
- 'BINARY_OP_SUBTRACT_FLOAT': 155,
- 'BINARY_OP_SUBTRACT_INT': 156,
- 'BINARY_SUBSCR_DICT': 157,
- 'BINARY_SUBSCR_GETITEM': 158,
- 'BINARY_SUBSCR_LIST_INT': 159,
- 'BINARY_SUBSCR_STR_INT': 160,
- 'BINARY_SUBSCR_TUPLE_INT': 161,
- 'CALL_ALLOC_AND_ENTER_INIT': 162,
- 'CALL_BOUND_METHOD_EXACT_ARGS': 163,
- 'CALL_BOUND_METHOD_GENERAL': 164,
- 'CALL_BUILTIN_CLASS': 165,
- 'CALL_BUILTIN_FAST': 166,
- 'CALL_BUILTIN_FAST_WITH_KEYWORDS': 167,
- 'CALL_BUILTIN_O': 168,
- 'CALL_ISINSTANCE': 169,
- 'CALL_KW_BOUND_METHOD': 170,
- 'CALL_KW_NON_PY': 171,
- 'CALL_KW_PY': 172,
- 'CALL_LEN': 173,
- 'CALL_LIST_APPEND': 174,
- 'CALL_METHOD_DESCRIPTOR_FAST': 175,
- 'CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS': 176,
- 'CALL_METHOD_DESCRIPTOR_NOARGS': 177,
- 'CALL_METHOD_DESCRIPTOR_O': 178,
- 'CALL_NON_PY_GENERAL': 179,
- 'CALL_PY_EXACT_ARGS': 180,
- 'CALL_PY_GENERAL': 181,
- 'CALL_STR_1': 182,
- 'CALL_TUPLE_1': 183,
- 'CALL_TYPE_1': 184,
- 'COMPARE_OP_FLOAT': 185,
- 'COMPARE_OP_INT': 186,
- 'COMPARE_OP_STR': 187,
- 'CONTAINS_OP_DICT': 188,
- 'CONTAINS_OP_SET': 189,
- 'FOR_ITER_GEN': 190,
- 'FOR_ITER_LIST': 191,
- 'FOR_ITER_RANGE': 192,
- 'FOR_ITER_TUPLE': 193,
- 'LOAD_ATTR_CLASS': 194,
- 'LOAD_ATTR_CLASS_WITH_METACLASS_CHECK': 195,
- 'LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN': 196,
- 'LOAD_ATTR_INSTANCE_VALUE': 197,
- 'LOAD_ATTR_METHOD_LAZY_DICT': 198,
- 'LOAD_ATTR_METHOD_NO_DICT': 199,
- 'LOAD_ATTR_METHOD_WITH_VALUES': 200,
- 'LOAD_ATTR_MODULE': 201,
- 'LOAD_ATTR_NONDESCRIPTOR_NO_DICT': 202,
- 'LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES': 203,
- 'LOAD_ATTR_PROPERTY': 204,
- 'LOAD_ATTR_SLOT': 205,
- 'LOAD_ATTR_WITH_HINT': 206,
- 'LOAD_CONST_IMMORTAL': 207,
- 'LOAD_CONST_MORTAL': 208,
- 'LOAD_GLOBAL_BUILTIN': 209,
- 'LOAD_GLOBAL_MODULE': 210,
- 'LOAD_SUPER_ATTR_ATTR': 211,
- 'LOAD_SUPER_ATTR_METHOD': 212,
- 'RESUME_CHECK': 213,
- 'SEND_GEN': 214,
- 'STORE_ATTR_INSTANCE_VALUE': 215,
- 'STORE_ATTR_SLOT': 216,
- 'STORE_ATTR_WITH_HINT': 217,
- 'STORE_SUBSCR_DICT': 218,
- 'STORE_SUBSCR_LIST_INT': 219,
- 'TO_BOOL_ALWAYS_TRUE': 220,
- 'TO_BOOL_BOOL': 221,
- 'TO_BOOL_INT': 222,
- 'TO_BOOL_LIST': 223,
- 'TO_BOOL_NONE': 224,
- 'TO_BOOL_STR': 225,
- 'UNPACK_SEQUENCE_LIST': 226,
- 'UNPACK_SEQUENCE_TUPLE': 227,
- 'UNPACK_SEQUENCE_TWO_TUPLE': 228,
+ 'BINARY_OP_MULTIPLY_FLOAT': 154,
+ 'BINARY_OP_MULTIPLY_INT': 155,
+ 'BINARY_OP_SUBTRACT_FLOAT': 156,
+ 'BINARY_OP_SUBTRACT_INT': 157,
+ 'BINARY_SUBSCR_DICT': 158,
+ 'BINARY_SUBSCR_GETITEM': 159,
+ 'BINARY_SUBSCR_LIST_INT': 160,
+ 'BINARY_SUBSCR_STR_INT': 161,
+ 'BINARY_SUBSCR_TUPLE_INT': 162,
+ 'CALL_ALLOC_AND_ENTER_INIT': 163,
+ 'CALL_BOUND_METHOD_EXACT_ARGS': 164,
+ 'CALL_BOUND_METHOD_GENERAL': 165,
+ 'CALL_BUILTIN_CLASS': 166,
+ 'CALL_BUILTIN_FAST': 167,
+ 'CALL_BUILTIN_FAST_WITH_KEYWORDS': 168,
+ 'CALL_BUILTIN_O': 169,
+ 'CALL_ISINSTANCE': 170,
+ 'CALL_KW_BOUND_METHOD': 171,
+ 'CALL_KW_NON_PY': 172,
+ 'CALL_KW_PY': 173,
+ 'CALL_LEN': 174,
+ 'CALL_LIST_APPEND': 175,
+ 'CALL_METHOD_DESCRIPTOR_FAST': 176,
+ 'CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS': 177,
+ 'CALL_METHOD_DESCRIPTOR_NOARGS': 178,
+ 'CALL_METHOD_DESCRIPTOR_O': 179,
+ 'CALL_NON_PY_GENERAL': 180,
+ 'CALL_PY_EXACT_ARGS': 181,
+ 'CALL_PY_GENERAL': 182,
+ 'CALL_STR_1': 183,
+ 'CALL_TUPLE_1': 184,
+ 'CALL_TYPE_1': 185,
+ 'COMPARE_OP_FLOAT': 186,
+ 'COMPARE_OP_INT': 187,
+ 'COMPARE_OP_STR': 188,
+ 'CONTAINS_OP_DICT': 189,
+ 'CONTAINS_OP_SET': 190,
+ 'FOR_ITER_GEN': 191,
+ 'FOR_ITER_LIST': 192,
+ 'FOR_ITER_RANGE': 193,
+ 'FOR_ITER_TUPLE': 194,
+ 'LOAD_ATTR_CLASS': 195,
+ 'LOAD_ATTR_CLASS_WITH_METACLASS_CHECK': 196,
+ 'LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN': 197,
+ 'LOAD_ATTR_INSTANCE_VALUE': 198,
+ 'LOAD_ATTR_METHOD_LAZY_DICT': 199,
+ 'LOAD_ATTR_METHOD_NO_DICT': 200,
+ 'LOAD_ATTR_METHOD_WITH_VALUES': 201,
+ 'LOAD_ATTR_MODULE': 202,
+ 'LOAD_ATTR_NONDESCRIPTOR_NO_DICT': 203,
+ 'LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES': 204,
+ 'LOAD_ATTR_PROPERTY': 205,
+ 'LOAD_ATTR_SLOT': 206,
+ 'LOAD_ATTR_WITH_HINT': 207,
+ 'LOAD_CONST_IMMORTAL': 208,
+ 'LOAD_CONST_MORTAL': 209,
+ 'LOAD_GLOBAL_BUILTIN': 210,
+ 'LOAD_GLOBAL_MODULE': 211,
+ 'LOAD_SUPER_ATTR_ATTR': 212,
+ 'LOAD_SUPER_ATTR_METHOD': 213,
+ 'RESUME_CHECK': 214,
+ 'SEND_GEN': 215,
+ 'STORE_ATTR_INSTANCE_VALUE': 216,
+ 'STORE_ATTR_SLOT': 217,
+ 'STORE_ATTR_WITH_HINT': 218,
+ 'STORE_SUBSCR_DICT': 219,
+ 'STORE_SUBSCR_LIST_INT': 220,
+ 'TO_BOOL_ALWAYS_TRUE': 221,
+ 'TO_BOOL_BOOL': 222,
+ 'TO_BOOL_INT': 223,
+ 'TO_BOOL_LIST': 224,
+ 'TO_BOOL_NONE': 225,
+ 'TO_BOOL_STR': 226,
+ 'UNPACK_SEQUENCE_LIST': 227,
+ 'UNPACK_SEQUENCE_TUPLE': 228,
+ 'UNPACK_SEQUENCE_TWO_TUPLE': 229,
}
opmap = {
diff --git a/Lib/opcode.py b/Lib/opcode.py
index aba66153af1b2e..4ee0d64026bd0a 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -52,6 +52,7 @@
},
"BINARY_OP": {
"counter": 1,
+ "descr": 4,
},
"UNPACK_SEQUENCE": {
"counter": 1,
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py
index 7ffa4eb8639add..69c1ee0690d269 100644
--- a/Lib/test/test_code.py
+++ b/Lib/test/test_code.py
@@ -429,14 +429,14 @@ def test_invalid_bytecode(self):
def foo():
pass
- # assert that opcode 229 is invalid
- self.assertEqual(opname[229], '<229>')
+ # assert that opcode 135 is invalid
+ self.assertEqual(opname[135], '<135>')
- # change first opcode to 0xeb (=229)
+ # change first opcode to 0x87 (=135)
foo.__code__ = foo.__code__.replace(
- co_code=b'\xe5' + foo.__code__.co_code[1:])
+ co_code=b'\x87' + foo.__code__.co_code[1:])
- msg = "unknown opcode 229"
+ msg = "unknown opcode 135"
with self.assertRaisesRegex(SystemError, msg):
foo()
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 8afe9653f19f6e..da57aad2f84fbd 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -438,7 +438,7 @@ def foo(a: int, b: str) -> str:
LOAD_SMALL_INT 1
BINARY_OP 13 (+=)
STORE_NAME 0 (x)
- JUMP_BACKWARD 8 (to L1)
+ JUMP_BACKWARD 12 (to L1)
"""
dis_traceback = """\
@@ -843,7 +843,7 @@ def foo(x):
L1: RESUME 0
LOAD_FAST 0 (.0)
GET_ITER
- L2: FOR_ITER 10 (to L3)
+ L2: FOR_ITER 14 (to L3)
STORE_FAST 1 (z)
LOAD_DEREF 2 (x)
LOAD_FAST 1 (z)
@@ -851,7 +851,7 @@ def foo(x):
YIELD_VALUE 0
RESUME 5
POP_TOP
- JUMP_BACKWARD 12 (to L2)
+ JUMP_BACKWARD 16 (to L2)
L3: END_FOR
POP_ITER
LOAD_CONST 0 (None)
@@ -1807,7 +1807,7 @@ def _prepare_test_cases():
Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=116, start_offset=116, starts_line=False, line_number=10, label=None, positions=None, cache_info=None),
Instruction(opname='LOAD_FAST_CHECK', opcode=85, arg=0, argval='i', argrepr='i', offset=118, start_offset=118, starts_line=True, line_number=11, label=5, positions=None, cache_info=None),
Instruction(opname='TO_BOOL', opcode=39, arg=None, argval=None, argrepr='', offset=120, start_offset=120, starts_line=False, line_number=11, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('version', 2, b'\x00\x00\x00\x00')]),
- Instruction(opname='POP_JUMP_IF_FALSE', opcode=97, arg=36, argval=204, argrepr='to L8', offset=128, start_offset=128, starts_line=False, line_number=11, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
+ Instruction(opname='POP_JUMP_IF_FALSE', opcode=97, arg=40, argval=212, argrepr='to L8', offset=128, start_offset=128, starts_line=False, line_number=11, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
Instruction(opname='NOT_TAKEN', opcode=28, arg=None, argval=None, argrepr='', offset=132, start_offset=132, starts_line=False, line_number=11, label=None, positions=None, cache_info=None),
Instruction(opname='LOAD_GLOBAL', opcode=89, arg=3, argval='print', argrepr='print + NULL', offset=134, start_offset=134, starts_line=True, line_number=12, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('index', 1, b'\x00\x00'), ('module_keys_version', 1, b'\x00\x00'), ('builtin_keys_version', 1, b'\x00\x00')]),
Instruction(opname='LOAD_FAST', opcode=83, arg=0, argval='i', argrepr='i', offset=144, start_offset=144, starts_line=False, line_number=12, label=None, positions=None, cache_info=None),
@@ -1815,93 +1815,93 @@ def _prepare_test_cases():
Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=154, start_offset=154, starts_line=False, line_number=12, label=None, positions=None, cache_info=None),
Instruction(opname='LOAD_FAST', opcode=83, arg=0, argval='i', argrepr='i', offset=156, start_offset=156, starts_line=True, line_number=13, label=None, positions=None, cache_info=None),
Instruction(opname='LOAD_SMALL_INT', opcode=91, arg=1, argval=1, argrepr='', offset=158, start_offset=158, starts_line=False, line_number=13, label=None, positions=None, cache_info=None),
- Instruction(opname='BINARY_OP', opcode=44, arg=23, argval=23, argrepr='-=', offset=160, start_offset=160, starts_line=False, line_number=13, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
- Instruction(opname='STORE_FAST', opcode=109, arg=0, argval='i', argrepr='i', offset=164, start_offset=164, starts_line=False, line_number=13, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_FAST', opcode=83, arg=0, argval='i', argrepr='i', offset=166, start_offset=166, starts_line=True, line_number=14, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_SMALL_INT', opcode=91, arg=6, argval=6, argrepr='', offset=168, start_offset=168, starts_line=False, line_number=14, label=None, positions=None, cache_info=None),
- Instruction(opname='COMPARE_OP', opcode=56, arg=148, argval='>', argrepr='bool(>)', offset=170, start_offset=170, starts_line=False, line_number=14, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
- Instruction(opname='POP_JUMP_IF_FALSE', opcode=97, arg=3, argval=184, argrepr='to L6', offset=174, start_offset=174, starts_line=False, line_number=14, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
- Instruction(opname='NOT_TAKEN', opcode=28, arg=None, argval=None, argrepr='', offset=178, start_offset=178, starts_line=False, line_number=14, label=None, positions=None, cache_info=None),
- Instruction(opname='JUMP_BACKWARD', opcode=74, arg=33, argval=118, argrepr='to L5', offset=180, start_offset=180, starts_line=True, line_number=15, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
- Instruction(opname='LOAD_FAST', opcode=83, arg=0, argval='i', argrepr='i', offset=184, start_offset=184, starts_line=True, line_number=16, label=6, positions=None, cache_info=None),
- Instruction(opname='LOAD_SMALL_INT', opcode=91, arg=4, argval=4, argrepr='', offset=186, start_offset=186, starts_line=False, line_number=16, label=None, positions=None, cache_info=None),
- Instruction(opname='COMPARE_OP', opcode=56, arg=18, argval='<', argrepr='bool(<)', offset=188, start_offset=188, starts_line=False, line_number=16, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
- Instruction(opname='POP_JUMP_IF_TRUE', opcode=100, arg=3, argval=202, argrepr='to L7', offset=192, start_offset=192, starts_line=False, line_number=16, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
- Instruction(opname='NOT_TAKEN', opcode=28, arg=None, argval=None, argrepr='', offset=196, start_offset=196, starts_line=False, line_number=16, label=None, positions=None, cache_info=None),
- Instruction(opname='JUMP_BACKWARD', opcode=74, arg=42, argval=118, argrepr='to L5', offset=198, start_offset=198, starts_line=False, line_number=16, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
- Instruction(opname='JUMP_FORWARD', opcode=76, arg=11, argval=226, argrepr='to L9', offset=202, start_offset=202, starts_line=True, line_number=17, label=7, positions=None, cache_info=None),
- Instruction(opname='LOAD_GLOBAL', opcode=89, arg=3, argval='print', argrepr='print + NULL', offset=204, start_offset=204, starts_line=True, line_number=19, label=8, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('index', 1, b'\x00\x00'), ('module_keys_version', 1, b'\x00\x00'), ('builtin_keys_version', 1, b'\x00\x00')]),
- Instruction(opname='LOAD_CONST', opcode=81, arg=1, argval='Who let lolcatz into this test suite?', argrepr="'Who let lolcatz into this test suite?'", offset=214, start_offset=214, starts_line=False, line_number=19, label=None, positions=None, cache_info=None),
- Instruction(opname='CALL', opcode=51, arg=1, argval=1, argrepr='', offset=216, start_offset=216, starts_line=False, line_number=19, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
- Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=224, start_offset=224, starts_line=False, line_number=19, label=None, positions=None, cache_info=None),
- Instruction(opname='NOP', opcode=27, arg=None, argval=None, argrepr='', offset=226, start_offset=226, starts_line=True, line_number=20, label=9, positions=None, cache_info=None),
- Instruction(opname='LOAD_SMALL_INT', opcode=91, arg=1, argval=1, argrepr='', offset=228, start_offset=228, starts_line=True, line_number=21, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_SMALL_INT', opcode=91, arg=0, argval=0, argrepr='', offset=230, start_offset=230, starts_line=False, line_number=21, label=None, positions=None, cache_info=None),
- Instruction(opname='BINARY_OP', opcode=44, arg=11, argval=11, argrepr='/', offset=232, start_offset=232, starts_line=False, line_number=21, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
- Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=236, start_offset=236, starts_line=False, line_number=21, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_FAST', opcode=83, arg=0, argval='i', argrepr='i', offset=238, start_offset=238, starts_line=True, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='COPY', opcode=59, arg=1, argval=1, argrepr='', offset=240, start_offset=240, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_SPECIAL', opcode=92, arg=1, argval=1, argrepr='__exit__', offset=242, start_offset=242, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='SWAP', opcode=114, arg=2, argval=2, argrepr='', offset=244, start_offset=244, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='SWAP', opcode=114, arg=3, argval=3, argrepr='', offset=246, start_offset=246, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_SPECIAL', opcode=92, arg=0, argval=0, argrepr='__enter__', offset=248, start_offset=248, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='CALL', opcode=51, arg=0, argval=0, argrepr='', offset=250, start_offset=250, starts_line=False, line_number=25, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
- Instruction(opname='STORE_FAST', opcode=109, arg=1, argval='dodgy', argrepr='dodgy', offset=258, start_offset=258, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_GLOBAL', opcode=89, arg=3, argval='print', argrepr='print + NULL', offset=260, start_offset=260, starts_line=True, line_number=26, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('index', 1, b'\x00\x00'), ('module_keys_version', 1, b'\x00\x00'), ('builtin_keys_version', 1, b'\x00\x00')]),
- Instruction(opname='LOAD_CONST', opcode=81, arg=2, argval='Never reach this', argrepr="'Never reach this'", offset=270, start_offset=270, starts_line=False, line_number=26, label=None, positions=None, cache_info=None),
- Instruction(opname='CALL', opcode=51, arg=1, argval=1, argrepr='', offset=272, start_offset=272, starts_line=False, line_number=26, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
- Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=280, start_offset=280, starts_line=False, line_number=26, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_CONST', opcode=81, arg=3, argval=None, argrepr='None', offset=282, start_offset=282, starts_line=True, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_CONST', opcode=81, arg=3, argval=None, argrepr='None', offset=284, start_offset=284, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_CONST', opcode=81, arg=3, argval=None, argrepr='None', offset=286, start_offset=286, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='CALL', opcode=51, arg=3, argval=3, argrepr='', offset=288, start_offset=288, starts_line=False, line_number=25, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
- Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=296, start_offset=296, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_GLOBAL', opcode=89, arg=3, argval='print', argrepr='print + NULL', offset=298, start_offset=298, starts_line=True, line_number=28, label=10, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('index', 1, b'\x00\x00'), ('module_keys_version', 1, b'\x00\x00'), ('builtin_keys_version', 1, b'\x00\x00')]),
- Instruction(opname='LOAD_CONST', opcode=81, arg=5, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=308, start_offset=308, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
- Instruction(opname='CALL', opcode=51, arg=1, argval=1, argrepr='', offset=310, start_offset=310, starts_line=False, line_number=28, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
- Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=318, start_offset=318, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_CONST', opcode=81, arg=3, argval=None, argrepr='None', offset=320, start_offset=320, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
- Instruction(opname='RETURN_VALUE', opcode=35, arg=None, argval=None, argrepr='', offset=322, start_offset=322, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
- Instruction(opname='PUSH_EXC_INFO', opcode=32, arg=None, argval=None, argrepr='', offset=324, start_offset=324, starts_line=True, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='WITH_EXCEPT_START', opcode=43, arg=None, argval=None, argrepr='', offset=326, start_offset=326, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='TO_BOOL', opcode=39, arg=None, argval=None, argrepr='', offset=328, start_offset=328, starts_line=False, line_number=25, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('version', 2, b'\x00\x00\x00\x00')]),
- Instruction(opname='POP_JUMP_IF_TRUE', opcode=100, arg=2, argval=344, argrepr='to L11', offset=336, start_offset=336, starts_line=False, line_number=25, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
- Instruction(opname='NOT_TAKEN', opcode=28, arg=None, argval=None, argrepr='', offset=340, start_offset=340, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='RERAISE', opcode=102, arg=2, argval=2, argrepr='', offset=342, start_offset=342, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=344, start_offset=344, starts_line=False, line_number=25, label=11, positions=None, cache_info=None),
- Instruction(opname='POP_EXCEPT', opcode=29, arg=None, argval=None, argrepr='', offset=346, start_offset=346, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=348, start_offset=348, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=350, start_offset=350, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=352, start_offset=352, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='JUMP_BACKWARD_NO_INTERRUPT', opcode=75, arg=29, argval=298, argrepr='to L10', offset=354, start_offset=354, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
- Instruction(opname='COPY', opcode=59, arg=3, argval=3, argrepr='', offset=356, start_offset=356, starts_line=True, line_number=None, label=None, positions=None, cache_info=None),
- Instruction(opname='POP_EXCEPT', opcode=29, arg=None, argval=None, argrepr='', offset=358, start_offset=358, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
- Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=360, start_offset=360, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
- Instruction(opname='PUSH_EXC_INFO', opcode=32, arg=None, argval=None, argrepr='', offset=362, start_offset=362, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_GLOBAL', opcode=89, arg=4, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=364, start_offset=364, starts_line=True, line_number=22, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('index', 1, b'\x00\x00'), ('module_keys_version', 1, b'\x00\x00'), ('builtin_keys_version', 1, b'\x00\x00')]),
- Instruction(opname='CHECK_EXC_MATCH', opcode=5, arg=None, argval=None, argrepr='', offset=374, start_offset=374, starts_line=False, line_number=22, label=None, positions=None, cache_info=None),
- Instruction(opname='POP_JUMP_IF_FALSE', opcode=97, arg=15, argval=410, argrepr='to L12', offset=376, start_offset=376, starts_line=False, line_number=22, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
- Instruction(opname='NOT_TAKEN', opcode=28, arg=None, argval=None, argrepr='', offset=380, start_offset=380, starts_line=False, line_number=22, label=None, positions=None, cache_info=None),
- Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=382, start_offset=382, starts_line=False, line_number=22, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_GLOBAL', opcode=89, arg=3, argval='print', argrepr='print + NULL', offset=384, start_offset=384, starts_line=True, line_number=23, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('index', 1, b'\x00\x00'), ('module_keys_version', 1, b'\x00\x00'), ('builtin_keys_version', 1, b'\x00\x00')]),
- Instruction(opname='LOAD_CONST', opcode=81, arg=4, argval='Here we go, here we go, here we go...', argrepr="'Here we go, here we go, here we go...'", offset=394, start_offset=394, starts_line=False, line_number=23, label=None, positions=None, cache_info=None),
- Instruction(opname='CALL', opcode=51, arg=1, argval=1, argrepr='', offset=396, start_offset=396, starts_line=False, line_number=23, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
- Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=404, start_offset=404, starts_line=False, line_number=23, label=None, positions=None, cache_info=None),
- Instruction(opname='POP_EXCEPT', opcode=29, arg=None, argval=None, argrepr='', offset=406, start_offset=406, starts_line=False, line_number=23, label=None, positions=None, cache_info=None),
- Instruction(opname='JUMP_BACKWARD_NO_INTERRUPT', opcode=75, arg=56, argval=298, argrepr='to L10', offset=408, start_offset=408, starts_line=False, line_number=23, label=None, positions=None, cache_info=None),
- Instruction(opname='RERAISE', opcode=102, arg=0, argval=0, argrepr='', offset=410, start_offset=410, starts_line=True, line_number=22, label=12, positions=None, cache_info=None),
- Instruction(opname='COPY', opcode=59, arg=3, argval=3, argrepr='', offset=412, start_offset=412, starts_line=True, line_number=None, label=None, positions=None, cache_info=None),
- Instruction(opname='POP_EXCEPT', opcode=29, arg=None, argval=None, argrepr='', offset=414, start_offset=414, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
- Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=416, start_offset=416, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
- Instruction(opname='PUSH_EXC_INFO', opcode=32, arg=None, argval=None, argrepr='', offset=418, start_offset=418, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
- Instruction(opname='LOAD_GLOBAL', opcode=89, arg=3, argval='print', argrepr='print + NULL', offset=420, start_offset=420, starts_line=True, line_number=28, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('index', 1, b'\x00\x00'), ('module_keys_version', 1, b'\x00\x00'), ('builtin_keys_version', 1, b'\x00\x00')]),
- Instruction(opname='LOAD_CONST', opcode=81, arg=5, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=430, start_offset=430, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
- Instruction(opname='CALL', opcode=51, arg=1, argval=1, argrepr='', offset=432, start_offset=432, starts_line=False, line_number=28, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
- Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=440, start_offset=440, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
- Instruction(opname='RERAISE', opcode=102, arg=0, argval=0, argrepr='', offset=442, start_offset=442, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
- Instruction(opname='COPY', opcode=59, arg=3, argval=3, argrepr='', offset=444, start_offset=444, starts_line=True, line_number=None, label=None, positions=None, cache_info=None),
- Instruction(opname='POP_EXCEPT', opcode=29, arg=None, argval=None, argrepr='', offset=446, start_offset=446, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
- Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=448, start_offset=448, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
+ Instruction(opname='BINARY_OP', opcode=44, arg=23, argval=23, argrepr='-=', offset=160, start_offset=160, starts_line=False, line_number=13, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('descr', 4, b'\x00\x00\x00\x00\x00\x00\x00\x00')]),
+ Instruction(opname='STORE_FAST', opcode=109, arg=0, argval='i', argrepr='i', offset=172, start_offset=172, starts_line=False, line_number=13, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_FAST', opcode=83, arg=0, argval='i', argrepr='i', offset=174, start_offset=174, starts_line=True, line_number=14, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_SMALL_INT', opcode=91, arg=6, argval=6, argrepr='', offset=176, start_offset=176, starts_line=False, line_number=14, label=None, positions=None, cache_info=None),
+ Instruction(opname='COMPARE_OP', opcode=56, arg=148, argval='>', argrepr='bool(>)', offset=178, start_offset=178, starts_line=False, line_number=14, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
+ Instruction(opname='POP_JUMP_IF_FALSE', opcode=97, arg=3, argval=192, argrepr='to L6', offset=182, start_offset=182, starts_line=False, line_number=14, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
+ Instruction(opname='NOT_TAKEN', opcode=28, arg=None, argval=None, argrepr='', offset=186, start_offset=186, starts_line=False, line_number=14, label=None, positions=None, cache_info=None),
+ Instruction(opname='JUMP_BACKWARD', opcode=74, arg=37, argval=118, argrepr='to L5', offset=188, start_offset=188, starts_line=True, line_number=15, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
+ Instruction(opname='LOAD_FAST', opcode=83, arg=0, argval='i', argrepr='i', offset=192, start_offset=192, starts_line=True, line_number=16, label=6, positions=None, cache_info=None),
+ Instruction(opname='LOAD_SMALL_INT', opcode=91, arg=4, argval=4, argrepr='', offset=194, start_offset=194, starts_line=False, line_number=16, label=None, positions=None, cache_info=None),
+ Instruction(opname='COMPARE_OP', opcode=56, arg=18, argval='<', argrepr='bool(<)', offset=196, start_offset=196, starts_line=False, line_number=16, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
+ Instruction(opname='POP_JUMP_IF_TRUE', opcode=100, arg=3, argval=210, argrepr='to L7', offset=200, start_offset=200, starts_line=False, line_number=16, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
+ Instruction(opname='NOT_TAKEN', opcode=28, arg=None, argval=None, argrepr='', offset=204, start_offset=204, starts_line=False, line_number=16, label=None, positions=None, cache_info=None),
+ Instruction(opname='JUMP_BACKWARD', opcode=74, arg=46, argval=118, argrepr='to L5', offset=206, start_offset=206, starts_line=False, line_number=16, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
+ Instruction(opname='JUMP_FORWARD', opcode=76, arg=11, argval=234, argrepr='to L9', offset=210, start_offset=210, starts_line=True, line_number=17, label=7, positions=None, cache_info=None),
+ Instruction(opname='LOAD_GLOBAL', opcode=89, arg=3, argval='print', argrepr='print + NULL', offset=212, start_offset=212, starts_line=True, line_number=19, label=8, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('index', 1, b'\x00\x00'), ('module_keys_version', 1, b'\x00\x00'), ('builtin_keys_version', 1, b'\x00\x00')]),
+ Instruction(opname='LOAD_CONST', opcode=81, arg=1, argval='Who let lolcatz into this test suite?', argrepr="'Who let lolcatz into this test suite?'", offset=222, start_offset=222, starts_line=False, line_number=19, label=None, positions=None, cache_info=None),
+ Instruction(opname='CALL', opcode=51, arg=1, argval=1, argrepr='', offset=224, start_offset=224, starts_line=False, line_number=19, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
+ Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=232, start_offset=232, starts_line=False, line_number=19, label=None, positions=None, cache_info=None),
+ Instruction(opname='NOP', opcode=27, arg=None, argval=None, argrepr='', offset=234, start_offset=234, starts_line=True, line_number=20, label=9, positions=None, cache_info=None),
+ Instruction(opname='LOAD_SMALL_INT', opcode=91, arg=1, argval=1, argrepr='', offset=236, start_offset=236, starts_line=True, line_number=21, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_SMALL_INT', opcode=91, arg=0, argval=0, argrepr='', offset=238, start_offset=238, starts_line=False, line_number=21, label=None, positions=None, cache_info=None),
+ Instruction(opname='BINARY_OP', opcode=44, arg=11, argval=11, argrepr='/', offset=240, start_offset=240, starts_line=False, line_number=21, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('descr', 4, b'\x00\x00\x00\x00\x00\x00\x00\x00')]),
+ Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=252, start_offset=252, starts_line=False, line_number=21, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_FAST', opcode=83, arg=0, argval='i', argrepr='i', offset=254, start_offset=254, starts_line=True, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='COPY', opcode=59, arg=1, argval=1, argrepr='', offset=256, start_offset=256, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_SPECIAL', opcode=92, arg=1, argval=1, argrepr='__exit__', offset=258, start_offset=258, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='SWAP', opcode=114, arg=2, argval=2, argrepr='', offset=260, start_offset=260, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='SWAP', opcode=114, arg=3, argval=3, argrepr='', offset=262, start_offset=262, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_SPECIAL', opcode=92, arg=0, argval=0, argrepr='__enter__', offset=264, start_offset=264, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='CALL', opcode=51, arg=0, argval=0, argrepr='', offset=266, start_offset=266, starts_line=False, line_number=25, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
+ Instruction(opname='STORE_FAST', opcode=109, arg=1, argval='dodgy', argrepr='dodgy', offset=274, start_offset=274, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_GLOBAL', opcode=89, arg=3, argval='print', argrepr='print + NULL', offset=276, start_offset=276, starts_line=True, line_number=26, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('index', 1, b'\x00\x00'), ('module_keys_version', 1, b'\x00\x00'), ('builtin_keys_version', 1, b'\x00\x00')]),
+ Instruction(opname='LOAD_CONST', opcode=81, arg=2, argval='Never reach this', argrepr="'Never reach this'", offset=286, start_offset=286, starts_line=False, line_number=26, label=None, positions=None, cache_info=None),
+ Instruction(opname='CALL', opcode=51, arg=1, argval=1, argrepr='', offset=288, start_offset=288, starts_line=False, line_number=26, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
+ Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=296, start_offset=296, starts_line=False, line_number=26, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_CONST', opcode=81, arg=3, argval=None, argrepr='None', offset=298, start_offset=298, starts_line=True, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_CONST', opcode=81, arg=3, argval=None, argrepr='None', offset=300, start_offset=300, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_CONST', opcode=81, arg=3, argval=None, argrepr='None', offset=302, start_offset=302, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='CALL', opcode=51, arg=3, argval=3, argrepr='', offset=304, start_offset=304, starts_line=False, line_number=25, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
+ Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=312, start_offset=312, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_GLOBAL', opcode=89, arg=3, argval='print', argrepr='print + NULL', offset=314, start_offset=314, starts_line=True, line_number=28, label=10, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('index', 1, b'\x00\x00'), ('module_keys_version', 1, b'\x00\x00'), ('builtin_keys_version', 1, b'\x00\x00')]),
+ Instruction(opname='LOAD_CONST', opcode=81, arg=5, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=324, start_offset=324, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
+ Instruction(opname='CALL', opcode=51, arg=1, argval=1, argrepr='', offset=326, start_offset=326, starts_line=False, line_number=28, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
+ Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=334, start_offset=334, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_CONST', opcode=81, arg=3, argval=None, argrepr='None', offset=336, start_offset=336, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
+ Instruction(opname='RETURN_VALUE', opcode=35, arg=None, argval=None, argrepr='', offset=338, start_offset=338, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
+ Instruction(opname='PUSH_EXC_INFO', opcode=32, arg=None, argval=None, argrepr='', offset=340, start_offset=340, starts_line=True, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='WITH_EXCEPT_START', opcode=43, arg=None, argval=None, argrepr='', offset=342, start_offset=342, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='TO_BOOL', opcode=39, arg=None, argval=None, argrepr='', offset=344, start_offset=344, starts_line=False, line_number=25, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('version', 2, b'\x00\x00\x00\x00')]),
+ Instruction(opname='POP_JUMP_IF_TRUE', opcode=100, arg=2, argval=360, argrepr='to L11', offset=352, start_offset=352, starts_line=False, line_number=25, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
+ Instruction(opname='NOT_TAKEN', opcode=28, arg=None, argval=None, argrepr='', offset=356, start_offset=356, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='RERAISE', opcode=102, arg=2, argval=2, argrepr='', offset=358, start_offset=358, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=360, start_offset=360, starts_line=False, line_number=25, label=11, positions=None, cache_info=None),
+ Instruction(opname='POP_EXCEPT', opcode=29, arg=None, argval=None, argrepr='', offset=362, start_offset=362, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=364, start_offset=364, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=366, start_offset=366, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=368, start_offset=368, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='JUMP_BACKWARD_NO_INTERRUPT', opcode=75, arg=29, argval=314, argrepr='to L10', offset=370, start_offset=370, starts_line=False, line_number=25, label=None, positions=None, cache_info=None),
+ Instruction(opname='COPY', opcode=59, arg=3, argval=3, argrepr='', offset=372, start_offset=372, starts_line=True, line_number=None, label=None, positions=None, cache_info=None),
+ Instruction(opname='POP_EXCEPT', opcode=29, arg=None, argval=None, argrepr='', offset=374, start_offset=374, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
+ Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=376, start_offset=376, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
+ Instruction(opname='PUSH_EXC_INFO', opcode=32, arg=None, argval=None, argrepr='', offset=378, start_offset=378, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_GLOBAL', opcode=89, arg=4, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=380, start_offset=380, starts_line=True, line_number=22, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('index', 1, b'\x00\x00'), ('module_keys_version', 1, b'\x00\x00'), ('builtin_keys_version', 1, b'\x00\x00')]),
+ Instruction(opname='CHECK_EXC_MATCH', opcode=5, arg=None, argval=None, argrepr='', offset=390, start_offset=390, starts_line=False, line_number=22, label=None, positions=None, cache_info=None),
+ Instruction(opname='POP_JUMP_IF_FALSE', opcode=97, arg=15, argval=426, argrepr='to L12', offset=392, start_offset=392, starts_line=False, line_number=22, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00')]),
+ Instruction(opname='NOT_TAKEN', opcode=28, arg=None, argval=None, argrepr='', offset=396, start_offset=396, starts_line=False, line_number=22, label=None, positions=None, cache_info=None),
+ Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=398, start_offset=398, starts_line=False, line_number=22, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_GLOBAL', opcode=89, arg=3, argval='print', argrepr='print + NULL', offset=400, start_offset=400, starts_line=True, line_number=23, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('index', 1, b'\x00\x00'), ('module_keys_version', 1, b'\x00\x00'), ('builtin_keys_version', 1, b'\x00\x00')]),
+ Instruction(opname='LOAD_CONST', opcode=81, arg=4, argval='Here we go, here we go, here we go...', argrepr="'Here we go, here we go, here we go...'", offset=410, start_offset=410, starts_line=False, line_number=23, label=None, positions=None, cache_info=None),
+ Instruction(opname='CALL', opcode=51, arg=1, argval=1, argrepr='', offset=412, start_offset=412, starts_line=False, line_number=23, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
+ Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=420, start_offset=420, starts_line=False, line_number=23, label=None, positions=None, cache_info=None),
+ Instruction(opname='POP_EXCEPT', opcode=29, arg=None, argval=None, argrepr='', offset=422, start_offset=422, starts_line=False, line_number=23, label=None, positions=None, cache_info=None),
+ Instruction(opname='JUMP_BACKWARD_NO_INTERRUPT', opcode=75, arg=56, argval=314, argrepr='to L10', offset=424, start_offset=424, starts_line=False, line_number=23, label=None, positions=None, cache_info=None),
+ Instruction(opname='RERAISE', opcode=102, arg=0, argval=0, argrepr='', offset=426, start_offset=426, starts_line=True, line_number=22, label=12, positions=None, cache_info=None),
+ Instruction(opname='COPY', opcode=59, arg=3, argval=3, argrepr='', offset=428, start_offset=428, starts_line=True, line_number=None, label=None, positions=None, cache_info=None),
+ Instruction(opname='POP_EXCEPT', opcode=29, arg=None, argval=None, argrepr='', offset=430, start_offset=430, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
+ Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=432, start_offset=432, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
+ Instruction(opname='PUSH_EXC_INFO', opcode=32, arg=None, argval=None, argrepr='', offset=434, start_offset=434, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
+ Instruction(opname='LOAD_GLOBAL', opcode=89, arg=3, argval='print', argrepr='print + NULL', offset=436, start_offset=436, starts_line=True, line_number=28, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('index', 1, b'\x00\x00'), ('module_keys_version', 1, b'\x00\x00'), ('builtin_keys_version', 1, b'\x00\x00')]),
+ Instruction(opname='LOAD_CONST', opcode=81, arg=5, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=446, start_offset=446, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
+ Instruction(opname='CALL', opcode=51, arg=1, argval=1, argrepr='', offset=448, start_offset=448, starts_line=False, line_number=28, label=None, positions=None, cache_info=[('counter', 1, b'\x00\x00'), ('func_version', 2, b'\x00\x00\x00\x00')]),
+ Instruction(opname='POP_TOP', opcode=31, arg=None, argval=None, argrepr='', offset=456, start_offset=456, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
+ Instruction(opname='RERAISE', opcode=102, arg=0, argval=0, argrepr='', offset=458, start_offset=458, starts_line=False, line_number=28, label=None, positions=None, cache_info=None),
+ Instruction(opname='COPY', opcode=59, arg=3, argval=3, argrepr='', offset=460, start_offset=460, starts_line=True, line_number=None, label=None, positions=None, cache_info=None),
+ Instruction(opname='POP_EXCEPT', opcode=29, arg=None, argval=None, argrepr='', offset=462, start_offset=462, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
+ Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=464, start_offset=464, starts_line=False, line_number=None, label=None, positions=None, cache_info=None),
]
# One last piece of inspect fodder to check the default line number handling
diff --git a/Lib/test/test_monitoring.py b/Lib/test/test_monitoring.py
index 43e3e56639db62..bea0e48883bf9a 100644
--- a/Lib/test/test_monitoring.py
+++ b/Lib/test/test_monitoring.py
@@ -1649,7 +1649,7 @@ def foo(n=0):
return None
in_loop = ('branch left', 'foo', 10, 16)
- exit_loop = ('branch right', 'foo', 10, 32)
+ exit_loop = ('branch right', 'foo', 10, 40)
self.check_events(foo, recorders = BRANCH_OFFSET_RECORDERS, expected = [
in_loop,
in_loop,
diff --git a/Lib/test/test_opcache.py b/Lib/test/test_opcache.py
index b80ccbf17f1ee6..72b845fcc8fdbf 100644
--- a/Lib/test/test_opcache.py
+++ b/Lib/test/test_opcache.py
@@ -1338,6 +1338,31 @@ def binary_op_add_unicode():
self.assert_specialized(binary_op_add_unicode, "BINARY_OP_ADD_UNICODE")
self.assert_no_opcode(binary_op_add_unicode, "BINARY_OP")
+ def binary_op_add_extend():
+ for _ in range(100):
+ a, b = 6, 3.0
+ c = a + b
+ self.assertEqual(c, 9.0)
+ c = b + a
+ self.assertEqual(c, 9.0)
+ c = a - b
+ self.assertEqual(c, 3.0)
+ c = b - a
+ self.assertEqual(c, -3.0)
+ c = a * b
+ self.assertEqual(c, 18.0)
+ c = b * a
+ self.assertEqual(c, 18.0)
+ c = a / b
+ self.assertEqual(c, 2.0)
+ c = b / a
+ self.assertEqual(c, 0.5)
+
+ binary_op_add_extend()
+ self.assert_specialized(binary_op_add_extend, "BINARY_OP_EXTEND")
+ self.assert_no_opcode(binary_op_add_extend, "BINARY_OP")
+
+
@cpython_only
@requires_specialization_ft
def test_load_super_attr(self):
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-01-10-23-54-16.gh-issue-100239.ijOOUs.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-01-10-23-54-16.gh-issue-100239.ijOOUs.rst
new file mode 100644
index 00000000000000..f58c1fc767515e
--- /dev/null
+++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-01-10-23-54-16.gh-issue-100239.ijOOUs.rst
@@ -0,0 +1,2 @@
+Add opcode ``BINARY_OP_EXTEND`` which executes a pair of functions (guard and
+specialization functions) accessed from the inline cache.
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index a906ded365650c..b1d61a8707bd4c 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -522,6 +522,7 @@ dummy_func(
BINARY_OP_SUBTRACT_FLOAT,
BINARY_OP_ADD_UNICODE,
// BINARY_OP_INPLACE_ADD_UNICODE, // See comments at that opcode.
+ BINARY_OP_EXTEND,
};
op(_GUARD_BOTH_INT, (left, right -- left, right)) {
@@ -587,11 +588,11 @@ dummy_func(
}
macro(BINARY_OP_MULTIPLY_INT) =
- _GUARD_BOTH_INT + unused/1 + _BINARY_OP_MULTIPLY_INT;
+ _GUARD_BOTH_INT + unused/5 + _BINARY_OP_MULTIPLY_INT;
macro(BINARY_OP_ADD_INT) =
- _GUARD_BOTH_INT + unused/1 + _BINARY_OP_ADD_INT;
+ _GUARD_BOTH_INT + unused/5 + _BINARY_OP_ADD_INT;
macro(BINARY_OP_SUBTRACT_INT) =
- _GUARD_BOTH_INT + unused/1 + _BINARY_OP_SUBTRACT_INT;
+ _GUARD_BOTH_INT + unused/5 + _BINARY_OP_SUBTRACT_INT;
op(_GUARD_BOTH_FLOAT, (left, right -- left, right)) {
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -659,11 +660,11 @@ dummy_func(
}
macro(BINARY_OP_MULTIPLY_FLOAT) =
- _GUARD_BOTH_FLOAT + unused/1 + _BINARY_OP_MULTIPLY_FLOAT;
+ _GUARD_BOTH_FLOAT + unused/5 + _BINARY_OP_MULTIPLY_FLOAT;
macro(BINARY_OP_ADD_FLOAT) =
- _GUARD_BOTH_FLOAT + unused/1 + _BINARY_OP_ADD_FLOAT;
+ _GUARD_BOTH_FLOAT + unused/5 + _BINARY_OP_ADD_FLOAT;
macro(BINARY_OP_SUBTRACT_FLOAT) =
- _GUARD_BOTH_FLOAT + unused/1 + _BINARY_OP_SUBTRACT_FLOAT;
+ _GUARD_BOTH_FLOAT + unused/5 + _BINARY_OP_SUBTRACT_FLOAT;
op(_GUARD_BOTH_UNICODE, (left, right -- left, right)) {
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -689,7 +690,7 @@ dummy_func(
}
macro(BINARY_OP_ADD_UNICODE) =
- _GUARD_BOTH_UNICODE + unused/1 + _BINARY_OP_ADD_UNICODE;
+ _GUARD_BOTH_UNICODE + unused/5 + _BINARY_OP_ADD_UNICODE;
// This is a subtle one. It's a super-instruction for
// BINARY_OP_ADD_UNICODE followed by STORE_FAST
@@ -741,8 +742,34 @@ dummy_func(
#endif
}
+ op(_GUARD_BINARY_OP_EXTEND, (descr/4, left, right -- left, right)) {
+ PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
+ PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
+ _PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr*)descr;
+ assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5);
+ assert(d && d->guard);
+ int res = d->guard(left_o, right_o);
+ EXIT_IF(!res);
+ }
+
+ pure op(_BINARY_OP_EXTEND, (descr/4, left, right -- res)) {
+ PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
+ PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
+ assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5);
+ _PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr*)descr;
+
+ STAT_INC(BINARY_OP, hit);
+
+ PyObject *res_o = d->action(left_o, right_o);
+ DECREF_INPUTS();
+ res = PyStackRef_FromPyObjectSteal(res_o);
+ }
+
+ macro(BINARY_OP_EXTEND) =
+ unused/1 + _GUARD_BINARY_OP_EXTEND + rewind/-4 + _BINARY_OP_EXTEND;
+
macro(BINARY_OP_INPLACE_ADD_UNICODE) =
- _GUARD_BOTH_UNICODE + unused/1 + _BINARY_OP_INPLACE_ADD_UNICODE;
+ _GUARD_BOTH_UNICODE + unused/5 + _BINARY_OP_INPLACE_ADD_UNICODE;
family(BINARY_SUBSCR, INLINE_CACHE_ENTRIES_BINARY_SUBSCR) = {
BINARY_SUBSCR_DICT,
@@ -4742,7 +4769,7 @@ dummy_func(
res = PyStackRef_FromPyObjectSteal(res_o);
}
- macro(BINARY_OP) = _SPECIALIZE_BINARY_OP + _BINARY_OP;
+ macro(BINARY_OP) = _SPECIALIZE_BINARY_OP + unused/4 + _BINARY_OP;
pure inst(SWAP, (bottom_in, unused[oparg-2], top_in --
top_out, unused[oparg-2], bottom_out)) {
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index cda01bb768c269..ad825881c8228c 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -899,6 +899,51 @@
break;
}
+ case _GUARD_BINARY_OP_EXTEND: {
+ _PyStackRef right;
+ _PyStackRef left;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
+ PyObject *descr = (PyObject *)CURRENT_OPERAND0();
+ PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
+ PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
+ _PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr*)descr;
+ assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5);
+ assert(d && d->guard);
+ _PyFrame_SetStackPointer(frame, stack_pointer);
+ int res = d->guard(left_o, right_o);
+ stack_pointer = _PyFrame_GetStackPointer(frame);
+ if (!res) {
+ UOP_STAT_INC(uopcode, miss);
+ JUMP_TO_JUMP_TARGET();
+ }
+ break;
+ }
+
+ case _BINARY_OP_EXTEND: {
+ _PyStackRef right;
+ _PyStackRef left;
+ _PyStackRef res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
+ PyObject *descr = (PyObject *)CURRENT_OPERAND0();
+ PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
+ PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
+ assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5);
+ _PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr*)descr;
+ STAT_INC(BINARY_OP, hit);
+ _PyFrame_SetStackPointer(frame, stack_pointer);
+ PyObject *res_o = d->action(left_o, right_o);
+ stack_pointer = _PyFrame_GetStackPointer(frame);
+ PyStackRef_CLOSE(left);
+ PyStackRef_CLOSE(right);
+ res = PyStackRef_FromPyObjectSteal(res_o);
+ stack_pointer[-2] = res;
+ stack_pointer += -1;
+ assert(WITHIN_STACK_BOUNDS());
+ break;
+ }
+
case _BINARY_SUBSCR: {
_PyStackRef sub;
_PyStackRef container;
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 81408380d6b2b8..dc90f75f2645e1 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -11,10 +11,10 @@
TARGET(BINARY_OP) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP);
PREDICTED(BINARY_OP);
- _Py_CODEUNIT* const this_instr = next_instr - 2;
+ _Py_CODEUNIT* const this_instr = next_instr - 6;
(void)this_instr;
_PyStackRef lhs;
_PyStackRef rhs;
@@ -39,6 +39,7 @@
assert(NB_ADD <= oparg);
assert(oparg <= NB_INPLACE_XOR);
}
+ /* Skip 4 cache entries */
// _BINARY_OP
{
PyObject *lhs_o = PyStackRef_AsPyObjectBorrow(lhs);
@@ -60,9 +61,9 @@
TARGET(BINARY_OP_ADD_FLOAT) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_ADD_FLOAT);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -75,7 +76,7 @@
DEOPT_IF(!PyFloat_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyFloat_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_ADD_FLOAT
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -98,9 +99,9 @@
TARGET(BINARY_OP_ADD_INT) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_ADD_INT);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -113,7 +114,7 @@
DEOPT_IF(!PyLong_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyLong_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_ADD_INT
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -135,9 +136,9 @@
TARGET(BINARY_OP_ADD_UNICODE) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_ADD_UNICODE);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -150,7 +151,7 @@
DEOPT_IF(!PyUnicode_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyUnicode_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_ADD_UNICODE
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -170,11 +171,57 @@
DISPATCH();
}
+ TARGET(BINARY_OP_EXTEND) {
+ _Py_CODEUNIT* const this_instr = frame->instr_ptr = next_instr;
+ next_instr += 6;
+ INSTRUCTION_STATS(BINARY_OP_EXTEND);
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
+ _PyStackRef left;
+ _PyStackRef right;
+ _PyStackRef res;
+ /* Skip 1 cache entry */
+ // _GUARD_BINARY_OP_EXTEND
+ {
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
+ PyObject *descr = read_obj(&this_instr[2].cache);
+ PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
+ PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
+ _PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr*)descr;
+ assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5);
+ assert(d && d->guard);
+ _PyFrame_SetStackPointer(frame, stack_pointer);
+ int res = d->guard(left_o, right_o);
+ stack_pointer = _PyFrame_GetStackPointer(frame);
+ DEOPT_IF(!res, BINARY_OP);
+ }
+ /* Skip -4 cache entry */
+ // _BINARY_OP_EXTEND
+ {
+ PyObject *descr = read_obj(&this_instr[2].cache);
+ PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
+ PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
+ assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5);
+ _PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr*)descr;
+ STAT_INC(BINARY_OP, hit);
+ _PyFrame_SetStackPointer(frame, stack_pointer);
+ PyObject *res_o = d->action(left_o, right_o);
+ stack_pointer = _PyFrame_GetStackPointer(frame);
+ PyStackRef_CLOSE(left);
+ PyStackRef_CLOSE(right);
+ res = PyStackRef_FromPyObjectSteal(res_o);
+ }
+ stack_pointer[-2] = res;
+ stack_pointer += -1;
+ assert(WITHIN_STACK_BOUNDS());
+ DISPATCH();
+ }
+
TARGET(BINARY_OP_INPLACE_ADD_UNICODE) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_INPLACE_ADD_UNICODE);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
// _GUARD_BOTH_UNICODE
@@ -186,7 +233,7 @@
DEOPT_IF(!PyUnicode_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyUnicode_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_INPLACE_ADD_UNICODE
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -235,9 +282,9 @@
TARGET(BINARY_OP_MULTIPLY_FLOAT) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_MULTIPLY_FLOAT);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -250,7 +297,7 @@
DEOPT_IF(!PyFloat_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyFloat_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_MULTIPLY_FLOAT
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -273,9 +320,9 @@
TARGET(BINARY_OP_MULTIPLY_INT) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_MULTIPLY_INT);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -288,7 +335,7 @@
DEOPT_IF(!PyLong_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyLong_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_MULTIPLY_INT
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -310,9 +357,9 @@
TARGET(BINARY_OP_SUBTRACT_FLOAT) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_SUBTRACT_FLOAT);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -325,7 +372,7 @@
DEOPT_IF(!PyFloat_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyFloat_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_SUBTRACT_FLOAT
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -348,9 +395,9 @@
TARGET(BINARY_OP_SUBTRACT_INT) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_SUBTRACT_INT);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -363,7 +410,7 @@
DEOPT_IF(!PyLong_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyLong_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_SUBTRACT_INT
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index c5c008fcbe574e..cb6c33f01d3598 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -152,6 +152,7 @@ static void *opcode_targets[256] = {
&&TARGET_BINARY_OP_ADD_FLOAT,
&&TARGET_BINARY_OP_ADD_INT,
&&TARGET_BINARY_OP_ADD_UNICODE,
+ &&TARGET_BINARY_OP_EXTEND,
&&TARGET_BINARY_OP_MULTIPLY_FLOAT,
&&TARGET_BINARY_OP_MULTIPLY_INT,
&&TARGET_BINARY_OP_SUBTRACT_FLOAT,
@@ -233,7 +234,6 @@ static void *opcode_targets[256] = {
&&_unknown_opcode,
&&_unknown_opcode,
&&_unknown_opcode,
- &&_unknown_opcode,
&&TARGET_INSTRUMENTED_END_FOR,
&&TARGET_INSTRUMENTED_POP_ITER,
&&TARGET_INSTRUMENTED_END_SEND,
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index aff4493fdc4dd7..90838d274a5e87 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -562,6 +562,19 @@
break;
}
+ case _GUARD_BINARY_OP_EXTEND: {
+ break;
+ }
+
+ case _BINARY_OP_EXTEND: {
+ _Py_UopsSymbol *res;
+ res = sym_new_not_null(ctx);
+ stack_pointer[-2] = res;
+ stack_pointer += -1;
+ assert(WITHIN_STACK_BOUNDS());
+ break;
+ }
+
case _BINARY_SUBSCR: {
_Py_UopsSymbol *res;
res = sym_new_not_null(ctx);
diff --git a/Python/specialize.c b/Python/specialize.c
index 8d9f19c8895187..09bfcd34b5a543 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1174,7 +1174,7 @@ do_specialize_instance_load_attr(PyObject* owner, _Py_CODEUNIT* instr, PyObject*
assert(tp_version != 0);
write_u32(lm_cache->type_version, tp_version);
/* borrowed */
- write_obj(lm_cache->descr, fget);
+ write_ptr(lm_cache->descr, fget);
specialize(instr, LOAD_ATTR_PROPERTY);
return 0;
}
@@ -1254,7 +1254,7 @@ do_specialize_instance_load_attr(PyObject* owner, _Py_CODEUNIT* instr, PyObject*
#endif
write_u32(lm_cache->keys_version, version);
/* borrowed */
- write_obj(lm_cache->descr, descr);
+ write_ptr(lm_cache->descr, descr);
write_u32(lm_cache->type_version, tp_version);
specialize(instr, LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN);
return 0;
@@ -1534,7 +1534,7 @@ specialize_class_load_attr(PyObject *owner, _Py_CODEUNIT *instr,
}
#endif
write_u32(cache->type_version, tp_version);
- write_obj(cache->descr, descr);
+ write_ptr(cache->descr, descr);
if (metaclass_check) {
write_u32(cache->keys_version, meta_version);
specialize(instr, LOAD_ATTR_CLASS_WITH_METACLASS_CHECK);
@@ -1642,7 +1642,7 @@ specialize_attr_loadclassattr(PyObject *owner, _Py_CODEUNIT *instr,
* working since Python 2.6 and it's battle-tested.
*/
write_u32(cache->type_version, tp_version);
- write_obj(cache->descr, descr);
+ write_ptr(cache->descr, descr);
return 1;
}
@@ -2412,6 +2412,92 @@ binary_op_fail_kind(int oparg, PyObject *lhs, PyObject *rhs)
}
#endif
+/** Binary Op Specialization Extensions */
+
+/* float-long */
+
+static int
+float_compactlong_guard(PyObject *lhs, PyObject *rhs)
+{
+ return (
+ PyFloat_CheckExact(lhs) &&
+ PyLong_CheckExact(rhs) &&
+ _PyLong_IsCompact((PyLongObject *)rhs)
+ );
+}
+
+#define FLOAT_LONG_ACTION(NAME, OP) \
+ static PyObject * \
+ (NAME)(PyObject *lhs, PyObject *rhs) \
+ { \
+ double lhs_val = PyFloat_AsDouble(lhs); \
+ Py_ssize_t rhs_val = _PyLong_CompactValue((PyLongObject *)rhs); \
+ return PyFloat_FromDouble(lhs_val OP rhs_val); \
+ }
+FLOAT_LONG_ACTION(float_compactlong_add, +)
+FLOAT_LONG_ACTION(float_compactlong_subtract, -)
+FLOAT_LONG_ACTION(float_compactlong_multiply, *)
+FLOAT_LONG_ACTION(float_compactlong_true_div, /)
+#undef FLOAT_LONG_ACTION
+
+/* long-float */
+
+static int
+compactlong_float_guard(PyObject *lhs, PyObject *rhs)
+{
+ return (
+ PyFloat_CheckExact(rhs) &&
+ PyLong_CheckExact(lhs) &&
+ _PyLong_IsCompact((PyLongObject *)lhs)
+ );
+}
+
+#define LONG_FLOAT_ACTION(NAME, OP) \
+ static PyObject * \
+ (NAME)(PyObject *lhs, PyObject *rhs) \
+ { \
+ double rhs_val = PyFloat_AsDouble(rhs); \
+ Py_ssize_t lhs_val = _PyLong_CompactValue((PyLongObject *)lhs); \
+ return PyFloat_FromDouble(lhs_val OP rhs_val); \
+ }
+LONG_FLOAT_ACTION(compactlong_float_add, +)
+LONG_FLOAT_ACTION(compactlong_float_subtract, -)
+LONG_FLOAT_ACTION(compactlong_float_multiply, *)
+LONG_FLOAT_ACTION(compactlong_float_true_div, /)
+#undef LONG_FLOAT_ACTION
+
+static _PyBinaryOpSpecializationDescr float_compactlong_specs[NB_OPARG_LAST+1] = {
+ [NB_ADD] = {float_compactlong_guard, float_compactlong_add},
+ [NB_SUBTRACT] = {float_compactlong_guard, float_compactlong_subtract},
+ [NB_TRUE_DIVIDE] = {float_compactlong_guard, float_compactlong_true_div},
+ [NB_MULTIPLY] = {float_compactlong_guard, float_compactlong_multiply},
+};
+
+static _PyBinaryOpSpecializationDescr compactlong_float_specs[NB_OPARG_LAST+1] = {
+ [NB_ADD] = {compactlong_float_guard, compactlong_float_add},
+ [NB_SUBTRACT] = {compactlong_float_guard, compactlong_float_subtract},
+ [NB_TRUE_DIVIDE] = {compactlong_float_guard, compactlong_float_true_div},
+ [NB_MULTIPLY] = {compactlong_float_guard, compactlong_float_multiply},
+};
+
+static int
+binary_op_extended_specialization(PyObject *lhs, PyObject *rhs, int oparg,
+ _PyBinaryOpSpecializationDescr **descr)
+{
+#define LOOKUP_SPEC(TABLE, OPARG) \
+ if ((TABLE)[(OPARG)].action) { \
+ if ((TABLE)[(OPARG)].guard(lhs, rhs)) { \
+ *descr = &((TABLE)[OPARG]); \
+ return 1; \
+ } \
+ }
+
+ LOOKUP_SPEC(compactlong_float_specs, oparg);
+ LOOKUP_SPEC(float_compactlong_specs, oparg);
+#undef LOOKUP_SPEC
+ return 0;
+}
+
void
_Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *instr,
int oparg, _PyStackRef *locals)
@@ -2420,6 +2506,12 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
PyObject *rhs = PyStackRef_AsPyObjectBorrow(rhs_st);
assert(ENABLE_SPECIALIZATION_FT);
assert(_PyOpcode_Caches[BINARY_OP] == INLINE_CACHE_ENTRIES_BINARY_OP);
+
+ _PyBinaryOpCache *cache = (_PyBinaryOpCache *)(instr + 1);
+ if (instr->op.code == BINARY_OP_EXTEND) {
+ write_ptr(cache->external_cache, NULL);
+ }
+
switch (oparg) {
case NB_ADD:
case NB_INPLACE_ADD:
@@ -2474,8 +2566,17 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
}
break;
}
+
+ _PyBinaryOpSpecializationDescr *descr;
+ if (binary_op_extended_specialization(lhs, rhs, oparg, &descr)) {
+ specialize(instr, BINARY_OP_EXTEND);
+ write_ptr(cache->external_cache, (void*)descr);
+ return;
+ }
+
SPECIALIZATION_FAIL(BINARY_OP, binary_op_fail_kind(oparg, lhs, rhs));
unspecialize(instr);
+ return;
}
diff --git a/Tools/c-analyzer/cpython/ignored.tsv b/Tools/c-analyzer/cpython/ignored.tsv
index c8c30a7985aa2e..213165b06866b5 100644
--- a/Tools/c-analyzer/cpython/ignored.tsv
+++ b/Tools/c-analyzer/cpython/ignored.tsv
@@ -378,6 +378,8 @@ Python/pylifecycle.c - INTERPRETER_TRAMPOLINE_CODEDEF -
Python/pystate.c - initial -
Python/specialize.c - adaptive_opcodes -
Python/specialize.c - cache_requirements -
+Python/specialize.c - float_compactlong_specs -
+Python/specialize.c - compactlong_float_specs -
Python/stdlib_module_names.h - _Py_stdlib_module_names -
Python/sysmodule.c - perf_map_state -
Python/sysmodule.c - _PySys_ImplCacheTag -
diff --git a/Tools/cases_generator/parsing.py b/Tools/cases_generator/parsing.py
index de31d9b232f9df..41b36b6a546360 100644
--- a/Tools/cases_generator/parsing.py
+++ b/Tools/cases_generator/parsing.py
@@ -357,9 +357,12 @@ def uops(self) -> list[UOp] | None:
def uop(self) -> UOp | None:
if tkn := self.expect(lx.IDENTIFIER):
if self.expect(lx.DIVIDE):
+ sign = 1
+ if negate := self.expect(lx.MINUS):
+ sign = -1
if num := self.expect(lx.NUMBER):
try:
- size = int(num.text)
+ size = sign * int(num.text)
except ValueError:
raise self.make_syntax_error(
f"Expected integer, got {num.text!r}"
1
0
https://github.com/python/cpython/commit/e81fe940c9bd092f6de558fa965100502b…
commit: e81fe940c9bd092f6de558fa965100502b78da0f
branch: main
author: Irit Katriel <1055913+iritkatriel(a)users.noreply.github.com>
committer: iritkatriel <1055913+iritkatriel(a)users.noreply.github.com>
date: 2025-01-16T13:15:52Z
summary:
gh-119786: added InternalDocs/generators.md (#128524)
files:
M InternalDocs/README.md
M InternalDocs/generators.md
diff --git a/InternalDocs/README.md b/InternalDocs/README.md
index 794b4f3c6aad42..4502902307cd5c 100644
--- a/InternalDocs/README.md
+++ b/InternalDocs/README.md
@@ -25,7 +25,7 @@ Runtime Objects
- [Code Objects](code_objects.md)
-- [Generators (coming soon)](generators.md)
+- [Generators](generators.md)
- [Frames](frames.md)
diff --git a/InternalDocs/generators.md b/InternalDocs/generators.md
index afa8b8f4bb8040..608bd215aae65a 100644
--- a/InternalDocs/generators.md
+++ b/InternalDocs/generators.md
@@ -1,8 +1,106 @@
+
+Generators and Coroutines
+=========================
+
Generators
-==========
+----------
+
+Generators in CPython are implemented with the struct `PyGenObject`.
+They consist of a [`frame`](frames.md) and metadata about the generator's
+execution state.
+
+A generator object resumes execution in its frame when its `send()`
+method is called. This is analogous to a function executing in its own
+fram when it is called, but a function returns to the calling frame only once,
+while a generator "returns" execution to the caller's frame every time
+it emits a new item with a
+[`yield` expression](https://docs.python.org/dev/reference/expressions.html#yield-ex….
+This is implemented by the
+[`YIELD_VALUE`](https://docs.python.org/dev/library/dis.html#opcode-YIELD_VALUE)
+bytecode, which is similar to
+[`RETURN_VALUE`](https://docs.python.org/dev/library/dis.html#opcode-RETURN_VALUE)
+in the sense that it puts a value on the stack and returns execution to the
+calling frame, but it also needs to perform additional work to leave the generator
+frame in a state that allows it to be resumed. In particular, it updates the frame's
+instruction pointer and stores the interpreter's exception state on the generator
+object. When the generator is resumed, this exception state is copied back to the
+interpreter state.
+
+The `frame` of a generator is embedded in the generator object struct as a
+[`_PyInterpreterFrame`](frames.md) (see `_PyGenObject_HEAD` in
+[`pycore_genobject.h`](../Include/internal/pycore_genobject.h)).
+This means that we can get the frame from the generator or the generator
+from the frame (see `_PyGen_GetGeneratorFromFrame` in the same file).
+Other fields of the generator struct include metadata (such as the name of
+the generator function) and runtime state information (such as whether its
+frame is executing, suspended, cleared, etc.).
+
+Generator Object Creation and Destruction
+-----------------------------------------
+
+The bytecode of a generator function begins with a
+[`RETURN_GENERATOR`](https://docs.python.org/dev/library/dis.html#opcode-RETURN_GENERATOR)
+instruction, which creates a generator object, including its embedded frame.
+The generator's frame is initialized as a copy of the frame in which
+`RETURN_GENERATOR` is executing, but its `owner` field is overwritten to indicate
+that it is owned by a generator. Finally, `RETURN_GENERATOR` pushes the new generator
+object to the stack and returns to the caller of the generator function (at
+which time its frame is destroyed). When the generator is next resumed by
+[`gen_send_ex2()`](../Objects/genobject.c), `_PyEval_EvalFrame()` is called
+to continue executing the generator function, in the frame that is embedded in
+the generator object.
+
+When a generator object is destroyed in [`gen_dealloc`](../Objects/genobject.c),
+its embedded `_PyInterpreterFrame` field may need to be preserved, if it is exposed
+to Python as part of a [`PyFrameObject`](frames.md#frame-objects). This is detected
+in [`_PyFrame_ClearExceptCode`](../Python/frame.c) by the fact that the interpreter
+frame's `frame_obj` field is set, and the frame object it points to has refcount
+greater than 1. If so, the `take_ownership()` function is called to create a new
+copy of the interpreter frame and transfer ownership of it from the generator to
+the frame object.
+
+Iteration
+---------
+
+The [`FOR_ITER`](https://docs.python.org/dev/library/dis.html#opcode-FOR_ITER)
+instruction calls `__next__` on the iterator which is on the top of the stack,
+and pushes the result to the stack. It has [`specializations`](adaptive.md)
+for a few common iterator types, including `FOR_ITER_GEN`, for iterating over
+a generator. `FOR_ITER_GEN` bypasses the call to `__next__`, and instead
+directly pushes the generator stack and resumes its execution from the
+instruction that follows the last yield.
+
+Chained Generators
+------------------
+
+A `yield from` expression creates a generator that efficiently yields the
+sequence created by another generator. This is implemented with the
+[`SEND` instruction](https://docs.python.org/dev/library/dis.html#opcode-SEND),
+which pushes the value of its arg to the stack of the generator's frame, sets
+the exception state on this frame, and resumes execution of the chained generator.
+On return from `SEND`, the value at the top of the stack is sent back up
+the generator chain with a `YIELD_VALUE`. This sequence of `SEND` followed by
+`YIELD_VALUE` is repeated in a loop, until a `StopIteration` exception is
+raised to indicate that the generator has no more values to emit.
+
+The [`CLEANUP_THROW`](https://docs.python.org/dev/library/dis.html#opcode-CLEANUP_THROW)
+instruction is used to handle exceptions raised from the send-yield loop.
+Exceptions of type `StopIteration` is handled, their `value` field hold the
+value to be returned by the generator's `close()` function. Any other
+exception is re-raised by `CLEANUP_THROW`.
+
+Coroutines
+----------
-Coming soon.
+Coroutines are generators that use the value returned from a `yield` expression,
+i.e., the argument that was passed to the `.send()` call that resumed it after
+it yielded. This makes it possible for data to flow in both directions: from
+the generator to the caller via the argument of the `yield` expression, and
+from the caller to the generator via the send argument to the `send()` call.
+A `yield from` expression passes the `send` argument to the chained generator,
+so this data flow works along the chain (see `gen_send_ex2()` in
+[`genobject.c`](../Objects/genobject.c)).
-<!--
-- Generators, async functions, async generators, and ``yield from`` (next, send, throw, close; and await; and how this code breaks the interpreter abstraction)
--->
+Recall that a generator's `__next__` function simply calls `self.send(None)`,
+so all this works the same in generators and coroutines, but only coroutines
+use the value of the argument to `send`.
1
0
https://github.com/python/cpython/commit/3193cb5ef87b77158d5c9bef99ae445cb8…
commit: 3193cb5ef87b77158d5c9bef99ae445cb82727de
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-16T13:53:18+01:00
summary:
gh-128679: Fix tracemalloc.stop() race conditions (#128893)
tracemalloc_alloc(), tracemalloc_realloc(), tracemalloc_free(),
_PyTraceMalloc_TraceRef() and _PyTraceMalloc_GetMemory() now check
'tracemalloc_config.tracing' after calling TABLES_LOCK().
_PyTraceMalloc_TraceRef() now always returns 0.
files:
A Misc/NEWS.d/next/Library/2025-01-15-21-41-51.gh-issue-128679.tq10F2.rst
M Lib/test/test_tracemalloc.py
M Modules/_testcapimodule.c
M Python/tracemalloc.c
diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py
index 5755f7697de91a..da2db28775578a 100644
--- a/Lib/test/test_tracemalloc.py
+++ b/Lib/test/test_tracemalloc.py
@@ -7,8 +7,9 @@
from test.support.script_helper import (assert_python_ok, assert_python_failure,
interpreter_requires_environment)
from test import support
-from test.support import os_helper
from test.support import force_not_colorized
+from test.support import os_helper
+from test.support import threading_helper
try:
import _testcapi
@@ -952,7 +953,6 @@ def check_env_var_invalid(self, nframe):
return
self.fail(f"unexpected output: {stderr!a}")
-
def test_env_var_invalid(self):
for nframe in INVALID_NFRAME:
with self.subTest(nframe=nframe):
@@ -1101,6 +1101,12 @@ def test_stop_untrack(self):
with self.assertRaises(RuntimeError):
self.untrack()
+ @unittest.skipIf(_testcapi is None, 'need _testcapi')
+ @threading_helper.requires_working_threading()
+ def test_tracemalloc_track_race(self):
+ # gh-128679: Test fix for tracemalloc.stop() race condition
+ _testcapi.tracemalloc_track_race()
+
if __name__ == "__main__":
unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2025-01-15-21-41-51.gh-issue-128679.tq10F2.rst b/Misc/NEWS.d/next/Library/2025-01-15-21-41-51.gh-issue-128679.tq10F2.rst
new file mode 100644
index 00000000000000..5c108da5703c00
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-15-21-41-51.gh-issue-128679.tq10F2.rst
@@ -0,0 +1,3 @@
+:mod:`tracemalloc`: Fix race conditions when :func:`tracemalloc.stop` is
+called by a thread, while other threads are tracing memory allocations.
+Patch by Victor Stinner.
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index a0a1f8af6710a3..7d304add5999d1 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -3435,6 +3435,104 @@ code_offset_to_line(PyObject* self, PyObject* const* args, Py_ssize_t nargsf)
return PyLong_FromInt32(PyCode_Addr2Line(code, offset));
}
+
+static void
+tracemalloc_track_race_thread(void *data)
+{
+ PyTraceMalloc_Track(123, 10, 1);
+
+ PyThread_type_lock lock = (PyThread_type_lock)data;
+ PyThread_release_lock(lock);
+}
+
+// gh-128679: Test fix for tracemalloc.stop() race condition
+static PyObject *
+tracemalloc_track_race(PyObject *self, PyObject *args)
+{
+#define NTHREAD 50
+ PyObject *tracemalloc = NULL;
+ PyObject *stop = NULL;
+ PyThread_type_lock locks[NTHREAD];
+ memset(locks, 0, sizeof(locks));
+
+ // Call tracemalloc.start()
+ tracemalloc = PyImport_ImportModule("tracemalloc");
+ if (tracemalloc == NULL) {
+ goto error;
+ }
+ PyObject *start = PyObject_GetAttrString(tracemalloc, "start");
+ if (start == NULL) {
+ goto error;
+ }
+ PyObject *res = PyObject_CallNoArgs(start);
+ Py_DECREF(start);
+ if (res == NULL) {
+ goto error;
+ }
+ Py_DECREF(res);
+
+ stop = PyObject_GetAttrString(tracemalloc, "stop");
+ Py_CLEAR(tracemalloc);
+ if (stop == NULL) {
+ goto error;
+ }
+
+ // Start threads
+ for (size_t i = 0; i < NTHREAD; i++) {
+ PyThread_type_lock lock = PyThread_allocate_lock();
+ if (!lock) {
+ PyErr_NoMemory();
+ goto error;
+ }
+ locks[i] = lock;
+ PyThread_acquire_lock(lock, 1);
+
+ unsigned long thread;
+ thread = PyThread_start_new_thread(tracemalloc_track_race_thread,
+ (void*)lock);
+ if (thread == (unsigned long)-1) {
+ PyErr_SetString(PyExc_RuntimeError, "can't start new thread");
+ goto error;
+ }
+ }
+
+ // Call tracemalloc.stop() while threads are running
+ res = PyObject_CallNoArgs(stop);
+ Py_CLEAR(stop);
+ if (res == NULL) {
+ goto error;
+ }
+ Py_DECREF(res);
+
+ // Wait until threads complete with the GIL released
+ Py_BEGIN_ALLOW_THREADS
+ for (size_t i = 0; i < NTHREAD; i++) {
+ PyThread_type_lock lock = locks[i];
+ PyThread_acquire_lock(lock, 1);
+ PyThread_release_lock(lock);
+ }
+ Py_END_ALLOW_THREADS
+
+ // Free threads locks
+ for (size_t i=0; i < NTHREAD; i++) {
+ PyThread_type_lock lock = locks[i];
+ PyThread_free_lock(lock);
+ }
+ Py_RETURN_NONE;
+
+error:
+ Py_CLEAR(tracemalloc);
+ Py_CLEAR(stop);
+ for (size_t i=0; i < NTHREAD; i++) {
+ PyThread_type_lock lock = locks[i];
+ if (lock) {
+ PyThread_free_lock(lock);
+ }
+ }
+ return NULL;
+#undef NTHREAD
+}
+
static PyMethodDef TestMethods[] = {
{"set_errno", set_errno, METH_VARARGS},
{"test_config", test_config, METH_NOARGS},
@@ -3578,6 +3676,7 @@ static PyMethodDef TestMethods[] = {
{"type_freeze", type_freeze, METH_VARARGS},
{"test_atexit", test_atexit, METH_NOARGS},
{"code_offset_to_line", _PyCFunction_CAST(code_offset_to_line), METH_FASTCALL},
+ {"tracemalloc_track_race", tracemalloc_track_race, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
diff --git a/Python/tracemalloc.c b/Python/tracemalloc.c
index 68b641c51868b9..919c564ee72967 100644
--- a/Python/tracemalloc.c
+++ b/Python/tracemalloc.c
@@ -567,11 +567,14 @@ tracemalloc_alloc(int need_gil, int use_calloc,
}
TABLES_LOCK();
- if (ADD_TRACE(ptr, nelem * elsize) < 0) {
- // Failed to allocate a trace for the new memory block
- alloc->free(alloc->ctx, ptr);
- ptr = NULL;
+ if (tracemalloc_config.tracing) {
+ if (ADD_TRACE(ptr, nelem * elsize) < 0) {
+ // Failed to allocate a trace for the new memory block
+ alloc->free(alloc->ctx, ptr);
+ ptr = NULL;
+ }
}
+ // else: gh-128679: tracemalloc.stop() was called by another thread
TABLES_UNLOCK();
if (need_gil) {
@@ -614,6 +617,11 @@ tracemalloc_realloc(int need_gil, void *ctx, void *ptr, size_t new_size)
}
TABLES_LOCK();
+ if (!tracemalloc_config.tracing) {
+ // gh-128679: tracemalloc.stop() was called by another thread
+ goto unlock;
+ }
+
if (ptr != NULL) {
// An existing memory block has been resized
@@ -646,6 +654,7 @@ tracemalloc_realloc(int need_gil, void *ctx, void *ptr, size_t new_size)
}
}
+unlock:
TABLES_UNLOCK();
if (need_gil) {
PyGILState_Release(gil_state);
@@ -674,7 +683,12 @@ tracemalloc_free(void *ctx, void *ptr)
}
TABLES_LOCK();
- REMOVE_TRACE(ptr);
+
+ if (tracemalloc_config.tracing) {
+ REMOVE_TRACE(ptr);
+ }
+ // else: gh-128679: tracemalloc.stop() was called by another thread
+
TABLES_UNLOCK();
}
@@ -1312,8 +1326,9 @@ _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event,
assert(PyGILState_Check());
TABLES_LOCK();
- int result = -1;
- assert(tracemalloc_config.tracing);
+ if (!tracemalloc_config.tracing) {
+ goto done;
+ }
PyTypeObject *type = Py_TYPE(op);
const size_t presize = _PyType_PreHeaderSize(type);
@@ -1325,13 +1340,13 @@ _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event,
traceback_t *traceback = traceback_new();
if (traceback != NULL) {
trace->traceback = traceback;
- result = 0;
}
}
/* else: cannot track the object, its memory block size is unknown */
+done:
TABLES_UNLOCK();
- return result;
+ return 0;
}
@@ -1472,13 +1487,19 @@ int _PyTraceMalloc_GetTracebackLimit(void)
size_t
_PyTraceMalloc_GetMemory(void)
{
- size_t size = _Py_hashtable_size(tracemalloc_tracebacks);
- size += _Py_hashtable_size(tracemalloc_filenames);
-
TABLES_LOCK();
- size += _Py_hashtable_size(tracemalloc_traces);
- _Py_hashtable_foreach(tracemalloc_domains,
- tracemalloc_get_tracemalloc_memory_cb, &size);
+ size_t size;
+ if (tracemalloc_config.tracing) {
+ size = _Py_hashtable_size(tracemalloc_tracebacks);
+ size += _Py_hashtable_size(tracemalloc_filenames);
+
+ size += _Py_hashtable_size(tracemalloc_traces);
+ _Py_hashtable_foreach(tracemalloc_domains,
+ tracemalloc_get_tracemalloc_memory_cb, &size);
+ }
+ else {
+ size = 0;
+ }
TABLES_UNLOCK();
return size;
}
1
0
[3.12] gh-128017: Make a note that sys variables are read-only (GH-128887) (#128909)
by vstinner Jan. 16, 2025
by vstinner Jan. 16, 2025
Jan. 16, 2025
https://github.com/python/cpython/commit/1c85f1bc4424b1ed43f1594442e4102209…
commit: 1c85f1bc4424b1ed43f1594442e41022099f05e3
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: vstinner <vstinner(a)python.org>
date: 2025-01-16T10:23:48Z
summary:
[3.12] gh-128017: Make a note that sys variables are read-only (GH-128887) (#128909)
gh-128017: Make a note that sys variables are read-only (GH-128887)
(cherry picked from commit 313b96eb8b8d0ad3bac58d633822a0a3705ce60b)
Co-authored-by: Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి) <thatiparthysreenivas(a)gmail.com>
files:
M Doc/library/sys.rst
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
index 90c794e3f3c58d..70844d4d26b1cb 100644
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -8,7 +8,7 @@
This module provides access to some variables used or maintained by the
interpreter and to functions that interact strongly with the interpreter. It is
-always available.
+always available. Unless explicitly noted otherwise, all variables are read-only.
.. data:: abiflags
1
0