This commit is contained in:
Hugo van Kemenade 2025-01-14 17:12:21 +02:00
commit 7fc0f86098
13 changed files with 393 additions and 352 deletions

View file

@ -728,6 +728,15 @@ asyncio
reduces memory usage. reduces memory usage.
(Contributed by Kumar Aditya in :gh:`107803`.) (Contributed by Kumar Aditya in :gh:`107803`.)
base64
------
* Improve the performance of :func:`base64.b16decode` by up to ten times,
and reduce the import time of :mod:`base64` by up to six times.
(Contributed by Bénédikt Tran, Chris Markiewicz, and Adam Turner in :gh:`118761`.)
io io
--- ---
* :mod:`io` which provides the built-in :func:`open` makes less system calls * :mod:`io` which provides the built-in :func:`open` makes less system calls

View file

@ -4,7 +4,6 @@
# Modified 30-Dec-2003 by Barry Warsaw to add full RFC 3548 support # Modified 30-Dec-2003 by Barry Warsaw to add full RFC 3548 support
# Modified 22-May-2007 by Guido van Rossum to use bytes everywhere # Modified 22-May-2007 by Guido van Rossum to use bytes everywhere
import re
import struct import struct
import binascii import binascii
@ -284,7 +283,7 @@ def b16decode(s, casefold=False):
s = _bytes_from_decode_data(s) s = _bytes_from_decode_data(s)
if casefold: if casefold:
s = s.upper() s = s.upper()
if re.search(b'[^0-9A-F]', s): if s.translate(None, delete=b'0123456789ABCDEF'):
raise binascii.Error('Non-base16 digit found') raise binascii.Error('Non-base16 digit found')
return binascii.unhexlify(s) return binascii.unhexlify(s)

View file

@ -90,14 +90,14 @@ class InteractiveSession(unittest.TestCase):
out, err = self.run_cli() out, err = self.run_cli()
self.assertIn(self.MEMORY_DB_MSG, err) self.assertIn(self.MEMORY_DB_MSG, err)
self.assertIn(self.MEMORY_DB_MSG, err) self.assertIn(self.MEMORY_DB_MSG, err)
self.assertTrue(out.endswith(self.PS1)) self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 1) self.assertEqual(out.count(self.PS1), 1)
self.assertEqual(out.count(self.PS2), 0) self.assertEqual(out.count(self.PS2), 0)
def test_interact_quit(self): def test_interact_quit(self):
out, err = self.run_cli(commands=(".quit",)) out, err = self.run_cli(commands=(".quit",))
self.assertIn(self.MEMORY_DB_MSG, err) self.assertIn(self.MEMORY_DB_MSG, err)
self.assertTrue(out.endswith(self.PS1)) self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 1) self.assertEqual(out.count(self.PS1), 1)
self.assertEqual(out.count(self.PS2), 0) self.assertEqual(out.count(self.PS2), 0)
@ -105,7 +105,7 @@ class InteractiveSession(unittest.TestCase):
out, err = self.run_cli(commands=(".version",)) out, err = self.run_cli(commands=(".version",))
self.assertIn(self.MEMORY_DB_MSG, err) self.assertIn(self.MEMORY_DB_MSG, err)
self.assertIn(sqlite3.sqlite_version + "\n", out) self.assertIn(sqlite3.sqlite_version + "\n", out)
self.assertTrue(out.endswith(self.PS1)) self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 2) self.assertEqual(out.count(self.PS1), 2)
self.assertEqual(out.count(self.PS2), 0) self.assertEqual(out.count(self.PS2), 0)
self.assertIn(sqlite3.sqlite_version, out) self.assertIn(sqlite3.sqlite_version, out)
@ -114,14 +114,14 @@ class InteractiveSession(unittest.TestCase):
out, err = self.run_cli(commands=("SELECT 1;",)) out, err = self.run_cli(commands=("SELECT 1;",))
self.assertIn(self.MEMORY_DB_MSG, err) self.assertIn(self.MEMORY_DB_MSG, err)
self.assertIn("(1,)\n", out) self.assertIn("(1,)\n", out)
self.assertTrue(out.endswith(self.PS1)) self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 2) self.assertEqual(out.count(self.PS1), 2)
self.assertEqual(out.count(self.PS2), 0) self.assertEqual(out.count(self.PS2), 0)
def test_interact_incomplete_multiline_sql(self): def test_interact_incomplete_multiline_sql(self):
out, err = self.run_cli(commands=("SELECT 1",)) out, err = self.run_cli(commands=("SELECT 1",))
self.assertIn(self.MEMORY_DB_MSG, err) self.assertIn(self.MEMORY_DB_MSG, err)
self.assertTrue(out.endswith(self.PS2)) self.assertEndsWith(out, self.PS2)
self.assertEqual(out.count(self.PS1), 1) self.assertEqual(out.count(self.PS1), 1)
self.assertEqual(out.count(self.PS2), 1) self.assertEqual(out.count(self.PS2), 1)
@ -130,7 +130,7 @@ class InteractiveSession(unittest.TestCase):
self.assertIn(self.MEMORY_DB_MSG, err) self.assertIn(self.MEMORY_DB_MSG, err)
self.assertIn(self.PS2, out) self.assertIn(self.PS2, out)
self.assertIn("(1,)\n", out) self.assertIn("(1,)\n", out)
self.assertTrue(out.endswith(self.PS1)) self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 2) self.assertEqual(out.count(self.PS1), 2)
self.assertEqual(out.count(self.PS2), 1) self.assertEqual(out.count(self.PS2), 1)
@ -138,7 +138,7 @@ class InteractiveSession(unittest.TestCase):
out, err = self.run_cli(commands=("sel;",)) out, err = self.run_cli(commands=("sel;",))
self.assertIn(self.MEMORY_DB_MSG, err) self.assertIn(self.MEMORY_DB_MSG, err)
self.assertIn("OperationalError (SQLITE_ERROR)", err) self.assertIn("OperationalError (SQLITE_ERROR)", err)
self.assertTrue(out.endswith(self.PS1)) self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 2) self.assertEqual(out.count(self.PS1), 2)
self.assertEqual(out.count(self.PS2), 0) self.assertEqual(out.count(self.PS2), 0)
@ -147,7 +147,7 @@ class InteractiveSession(unittest.TestCase):
out, err = self.run_cli(TESTFN, commands=("CREATE TABLE t(t);",)) out, err = self.run_cli(TESTFN, commands=("CREATE TABLE t(t);",))
self.assertIn(TESTFN, err) self.assertIn(TESTFN, err)
self.assertTrue(out.endswith(self.PS1)) self.assertEndsWith(out, self.PS1)
out, _ = self.run_cli(TESTFN, commands=("SELECT count(t) FROM t;",)) out, _ = self.run_cli(TESTFN, commands=("SELECT count(t) FROM t;",))
self.assertIn("(0,)\n", out) self.assertIn("(0,)\n", out)

View file

@ -59,45 +59,34 @@ class ModuleTests(unittest.TestCase):
sqlite.paramstyle) sqlite.paramstyle)
def test_warning(self): def test_warning(self):
self.assertTrue(issubclass(sqlite.Warning, Exception), self.assertIsSubclass(sqlite.Warning, Exception)
"Warning is not a subclass of Exception")
def test_error(self): def test_error(self):
self.assertTrue(issubclass(sqlite.Error, Exception), self.assertIsSubclass(sqlite.Error, Exception)
"Error is not a subclass of Exception")
def test_interface_error(self): def test_interface_error(self):
self.assertTrue(issubclass(sqlite.InterfaceError, sqlite.Error), self.assertIsSubclass(sqlite.InterfaceError, sqlite.Error)
"InterfaceError is not a subclass of Error")
def test_database_error(self): def test_database_error(self):
self.assertTrue(issubclass(sqlite.DatabaseError, sqlite.Error), self.assertIsSubclass(sqlite.DatabaseError, sqlite.Error)
"DatabaseError is not a subclass of Error")
def test_data_error(self): def test_data_error(self):
self.assertTrue(issubclass(sqlite.DataError, sqlite.DatabaseError), self.assertIsSubclass(sqlite.DataError, sqlite.DatabaseError)
"DataError is not a subclass of DatabaseError")
def test_operational_error(self): def test_operational_error(self):
self.assertTrue(issubclass(sqlite.OperationalError, sqlite.DatabaseError), self.assertIsSubclass(sqlite.OperationalError, sqlite.DatabaseError)
"OperationalError is not a subclass of DatabaseError")
def test_integrity_error(self): def test_integrity_error(self):
self.assertTrue(issubclass(sqlite.IntegrityError, sqlite.DatabaseError), self.assertIsSubclass(sqlite.IntegrityError, sqlite.DatabaseError)
"IntegrityError is not a subclass of DatabaseError")
def test_internal_error(self): def test_internal_error(self):
self.assertTrue(issubclass(sqlite.InternalError, sqlite.DatabaseError), self.assertIsSubclass(sqlite.InternalError, sqlite.DatabaseError)
"InternalError is not a subclass of DatabaseError")
def test_programming_error(self): def test_programming_error(self):
self.assertTrue(issubclass(sqlite.ProgrammingError, sqlite.DatabaseError), self.assertIsSubclass(sqlite.ProgrammingError, sqlite.DatabaseError)
"ProgrammingError is not a subclass of DatabaseError")
def test_not_supported_error(self): def test_not_supported_error(self):
self.assertTrue(issubclass(sqlite.NotSupportedError, self.assertIsSubclass(sqlite.NotSupportedError, sqlite.DatabaseError)
sqlite.DatabaseError),
"NotSupportedError is not a subclass of DatabaseError")
def test_module_constants(self): def test_module_constants(self):
consts = [ consts = [
@ -274,7 +263,7 @@ class ModuleTests(unittest.TestCase):
consts.append("SQLITE_IOERR_CORRUPTFS") consts.append("SQLITE_IOERR_CORRUPTFS")
for const in consts: for const in consts:
with self.subTest(const=const): with self.subTest(const=const):
self.assertTrue(hasattr(sqlite, const)) self.assertHasAttr(sqlite, const)
def test_error_code_on_exception(self): def test_error_code_on_exception(self):
err_msg = "unable to open database file" err_msg = "unable to open database file"
@ -288,7 +277,7 @@ class ModuleTests(unittest.TestCase):
sqlite.connect(db) sqlite.connect(db)
e = cm.exception e = cm.exception
self.assertEqual(e.sqlite_errorcode, err_code) self.assertEqual(e.sqlite_errorcode, err_code)
self.assertTrue(e.sqlite_errorname.startswith("SQLITE_CANTOPEN")) self.assertStartsWith(e.sqlite_errorname, "SQLITE_CANTOPEN")
def test_extended_error_code_on_exception(self): def test_extended_error_code_on_exception(self):
with memory_database() as con: with memory_database() as con:
@ -425,7 +414,7 @@ class ConnectionTests(unittest.TestCase):
] ]
for exc in exceptions: for exc in exceptions:
with self.subTest(exc=exc): with self.subTest(exc=exc):
self.assertTrue(hasattr(self.cx, exc)) self.assertHasAttr(self.cx, exc)
self.assertIs(getattr(sqlite, exc), getattr(self.cx, exc)) self.assertIs(getattr(sqlite, exc), getattr(self.cx, exc))
def test_interrupt_on_closed_db(self): def test_interrupt_on_closed_db(self):

View file

@ -280,7 +280,7 @@ class TextFactoryTests(MemoryDatabaseMixin, unittest.TestCase):
austria = "Österreich" austria = "Österreich"
row = self.con.execute("select ?", (austria,)).fetchone() row = self.con.execute("select ?", (austria,)).fetchone()
self.assertEqual(type(row[0]), str, "type of row[0] must be unicode") self.assertEqual(type(row[0]), str, "type of row[0] must be unicode")
self.assertTrue(row[0].endswith("reich"), "column must contain original data") self.assertEndsWith(row[0], "reich", "column must contain original data")
class TextFactoryTestsWithEmbeddedZeroBytes(unittest.TestCase): class TextFactoryTestsWithEmbeddedZeroBytes(unittest.TestCase):

View file

@ -115,18 +115,18 @@ class AnyTests(BaseTestCase):
def test_can_subclass(self): def test_can_subclass(self):
class Mock(Any): pass class Mock(Any): pass
self.assertTrue(issubclass(Mock, Any)) self.assertIsSubclass(Mock, Any)
self.assertIsInstance(Mock(), Mock) self.assertIsInstance(Mock(), Mock)
class Something: pass class Something: pass
self.assertFalse(issubclass(Something, Any)) self.assertNotIsSubclass(Something, Any)
self.assertNotIsInstance(Something(), Mock) self.assertNotIsInstance(Something(), Mock)
class MockSomething(Something, Mock): pass class MockSomething(Something, Mock): pass
self.assertTrue(issubclass(MockSomething, Any)) self.assertIsSubclass(MockSomething, Any)
self.assertTrue(issubclass(MockSomething, MockSomething)) self.assertIsSubclass(MockSomething, MockSomething)
self.assertTrue(issubclass(MockSomething, Something)) self.assertIsSubclass(MockSomething, Something)
self.assertTrue(issubclass(MockSomething, Mock)) self.assertIsSubclass(MockSomething, Mock)
ms = MockSomething() ms = MockSomething()
self.assertIsInstance(ms, MockSomething) self.assertIsInstance(ms, MockSomething)
self.assertIsInstance(ms, Something) self.assertIsInstance(ms, Something)
@ -1997,11 +1997,11 @@ class UnionTests(BaseTestCase):
self.assertNotEqual(u, Union) self.assertNotEqual(u, Union)
def test_union_isinstance(self): def test_union_isinstance(self):
self.assertTrue(isinstance(42, Union[int, str])) self.assertIsInstance(42, Union[int, str])
self.assertTrue(isinstance('abc', Union[int, str])) self.assertIsInstance('abc', Union[int, str])
self.assertFalse(isinstance(3.14, Union[int, str])) self.assertNotIsInstance(3.14, Union[int, str])
self.assertTrue(isinstance(42, Union[int, list[int]])) self.assertIsInstance(42, Union[int, list[int]])
self.assertTrue(isinstance(42, Union[int, Any])) self.assertIsInstance(42, Union[int, Any])
def test_union_isinstance_type_error(self): def test_union_isinstance_type_error(self):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
@ -2018,9 +2018,9 @@ class UnionTests(BaseTestCase):
isinstance(42, Union[Any, str]) isinstance(42, Union[Any, str])
def test_optional_isinstance(self): def test_optional_isinstance(self):
self.assertTrue(isinstance(42, Optional[int])) self.assertIsInstance(42, Optional[int])
self.assertTrue(isinstance(None, Optional[int])) self.assertIsInstance(None, Optional[int])
self.assertFalse(isinstance('abc', Optional[int])) self.assertNotIsInstance('abc', Optional[int])
def test_optional_isinstance_type_error(self): def test_optional_isinstance_type_error(self):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
@ -2033,14 +2033,14 @@ class UnionTests(BaseTestCase):
isinstance(None, Optional[Any]) isinstance(None, Optional[Any])
def test_union_issubclass(self): def test_union_issubclass(self):
self.assertTrue(issubclass(int, Union[int, str])) self.assertIsSubclass(int, Union[int, str])
self.assertTrue(issubclass(str, Union[int, str])) self.assertIsSubclass(str, Union[int, str])
self.assertFalse(issubclass(float, Union[int, str])) self.assertNotIsSubclass(float, Union[int, str])
self.assertTrue(issubclass(int, Union[int, list[int]])) self.assertIsSubclass(int, Union[int, list[int]])
self.assertTrue(issubclass(int, Union[int, Any])) self.assertIsSubclass(int, Union[int, Any])
self.assertFalse(issubclass(int, Union[str, Any])) self.assertNotIsSubclass(int, Union[str, Any])
self.assertTrue(issubclass(int, Union[Any, int])) self.assertIsSubclass(int, Union[Any, int])
self.assertFalse(issubclass(int, Union[Any, str])) self.assertNotIsSubclass(int, Union[Any, str])
def test_union_issubclass_type_error(self): def test_union_issubclass_type_error(self):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
@ -2057,12 +2057,12 @@ class UnionTests(BaseTestCase):
issubclass(int, Union[list[int], str]) issubclass(int, Union[list[int], str])
def test_optional_issubclass(self): def test_optional_issubclass(self):
self.assertTrue(issubclass(int, Optional[int])) self.assertIsSubclass(int, Optional[int])
self.assertTrue(issubclass(type(None), Optional[int])) self.assertIsSubclass(type(None), Optional[int])
self.assertFalse(issubclass(str, Optional[int])) self.assertNotIsSubclass(str, Optional[int])
self.assertTrue(issubclass(Any, Optional[Any])) self.assertIsSubclass(Any, Optional[Any])
self.assertTrue(issubclass(type(None), Optional[Any])) self.assertIsSubclass(type(None), Optional[Any])
self.assertFalse(issubclass(int, Optional[Any])) self.assertNotIsSubclass(int, Optional[Any])
def test_optional_issubclass_type_error(self): def test_optional_issubclass_type_error(self):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
@ -4050,8 +4050,8 @@ class ProtocolTests(BaseTestCase):
class P(Protocol[T, S]): pass class P(Protocol[T, S]): pass
self.assertTrue(repr(P[T, S]).endswith('P[~T, ~S]')) self.assertEndsWith(repr(P[T, S]), 'P[~T, ~S]')
self.assertTrue(repr(P[int, str]).endswith('P[int, str]')) self.assertEndsWith(repr(P[int, str]), 'P[int, str]')
def test_generic_protocols_eq(self): def test_generic_protocols_eq(self):
T = TypeVar('T') T = TypeVar('T')
@ -4641,8 +4641,7 @@ class GenericTests(BaseTestCase):
self.assertNotEqual(Z, Y[int]) self.assertNotEqual(Z, Y[int])
self.assertNotEqual(Z, Y[T]) self.assertNotEqual(Z, Y[T])
self.assertTrue(str(Z).endswith( self.assertEndsWith(str(Z), '.C[typing.Tuple[str, int]]')
'.C[typing.Tuple[str, int]]'))
def test_new_repr(self): def test_new_repr(self):
T = TypeVar('T') T = TypeVar('T')
@ -4870,12 +4869,12 @@ class GenericTests(BaseTestCase):
self.assertNotEqual(typing.FrozenSet[A[str]], self.assertNotEqual(typing.FrozenSet[A[str]],
typing.FrozenSet[mod_generics_cache.B.A[str]]) typing.FrozenSet[mod_generics_cache.B.A[str]])
self.assertTrue(repr(Tuple[A[str]]).endswith('<locals>.A[str]]')) self.assertEndsWith(repr(Tuple[A[str]]), '<locals>.A[str]]')
self.assertTrue(repr(Tuple[B.A[str]]).endswith('<locals>.B.A[str]]')) self.assertEndsWith(repr(Tuple[B.A[str]]), '<locals>.B.A[str]]')
self.assertTrue(repr(Tuple[mod_generics_cache.A[str]]) self.assertEndsWith(repr(Tuple[mod_generics_cache.A[str]]),
.endswith('mod_generics_cache.A[str]]')) 'mod_generics_cache.A[str]]')
self.assertTrue(repr(Tuple[mod_generics_cache.B.A[str]]) self.assertEndsWith(repr(Tuple[mod_generics_cache.B.A[str]]),
.endswith('mod_generics_cache.B.A[str]]')) 'mod_generics_cache.B.A[str]]')
def test_extended_generic_rules_eq(self): def test_extended_generic_rules_eq(self):
T = TypeVar('T') T = TypeVar('T')
@ -5817,7 +5816,7 @@ class FinalDecoratorTests(BaseTestCase):
@Wrapper @Wrapper
def wrapped(): ... def wrapped(): ...
self.assertIsInstance(wrapped, Wrapper) self.assertIsInstance(wrapped, Wrapper)
self.assertIs(False, hasattr(wrapped, "__final__")) self.assertNotHasAttr(wrapped, "__final__")
class Meta(type): class Meta(type):
@property @property
@ -5829,7 +5828,7 @@ class FinalDecoratorTests(BaseTestCase):
# Builtin classes throw TypeError if you try to set an # Builtin classes throw TypeError if you try to set an
# attribute. # attribute.
final(int) final(int)
self.assertIs(False, hasattr(int, "__final__")) self.assertNotHasAttr(int, "__final__")
# Make sure it works with common builtin decorators # Make sure it works with common builtin decorators
class Methods: class Methods:
@ -5910,19 +5909,19 @@ class OverrideDecoratorTests(BaseTestCase):
self.assertEqual(Derived.class_method_good_order(), 42) self.assertEqual(Derived.class_method_good_order(), 42)
self.assertIs(True, Derived.class_method_good_order.__override__) self.assertIs(True, Derived.class_method_good_order.__override__)
self.assertEqual(Derived.class_method_bad_order(), 42) self.assertEqual(Derived.class_method_bad_order(), 42)
self.assertIs(False, hasattr(Derived.class_method_bad_order, "__override__")) self.assertNotHasAttr(Derived.class_method_bad_order, "__override__")
self.assertEqual(Derived.static_method_good_order(), 42) self.assertEqual(Derived.static_method_good_order(), 42)
self.assertIs(True, Derived.static_method_good_order.__override__) self.assertIs(True, Derived.static_method_good_order.__override__)
self.assertEqual(Derived.static_method_bad_order(), 42) self.assertEqual(Derived.static_method_bad_order(), 42)
self.assertIs(False, hasattr(Derived.static_method_bad_order, "__override__")) self.assertNotHasAttr(Derived.static_method_bad_order, "__override__")
# Base object is not changed: # Base object is not changed:
self.assertIs(False, hasattr(Base.normal_method, "__override__")) self.assertNotHasAttr(Base.normal_method, "__override__")
self.assertIs(False, hasattr(Base.class_method_good_order, "__override__")) self.assertNotHasAttr(Base.class_method_good_order, "__override__")
self.assertIs(False, hasattr(Base.class_method_bad_order, "__override__")) self.assertNotHasAttr(Base.class_method_bad_order, "__override__")
self.assertIs(False, hasattr(Base.static_method_good_order, "__override__")) self.assertNotHasAttr(Base.static_method_good_order, "__override__")
self.assertIs(False, hasattr(Base.static_method_bad_order, "__override__")) self.assertNotHasAttr(Base.static_method_bad_order, "__override__")
def test_property(self): def test_property(self):
class Base: class Base:
@ -5947,8 +5946,8 @@ class OverrideDecoratorTests(BaseTestCase):
self.assertEqual(instance.correct, 2) self.assertEqual(instance.correct, 2)
self.assertTrue(Child.correct.fget.__override__) self.assertTrue(Child.correct.fget.__override__)
self.assertEqual(instance.wrong, 2) self.assertEqual(instance.wrong, 2)
self.assertFalse(hasattr(Child.wrong, "__override__")) self.assertNotHasAttr(Child.wrong, "__override__")
self.assertFalse(hasattr(Child.wrong.fset, "__override__")) self.assertNotHasAttr(Child.wrong.fset, "__override__")
def test_silent_failure(self): def test_silent_failure(self):
class CustomProp: class CustomProp:
@ -5965,7 +5964,7 @@ class OverrideDecoratorTests(BaseTestCase):
return 1 return 1
self.assertEqual(WithOverride.some, 1) self.assertEqual(WithOverride.some, 1)
self.assertFalse(hasattr(WithOverride.some, "__override__")) self.assertNotHasAttr(WithOverride.some, "__override__")
def test_multiple_decorators(self): def test_multiple_decorators(self):
def with_wraps(f): # similar to `lru_cache` definition def with_wraps(f): # similar to `lru_cache` definition
@ -10474,7 +10473,7 @@ class SpecialAttrsTests(BaseTestCase):
# to the variable name to which it is assigned". Thus, providing # to the variable name to which it is assigned". Thus, providing
# __qualname__ is unnecessary. # __qualname__ is unnecessary.
self.assertEqual(SpecialAttrsT.__name__, 'SpecialAttrsT') self.assertEqual(SpecialAttrsT.__name__, 'SpecialAttrsT')
self.assertFalse(hasattr(SpecialAttrsT, '__qualname__')) self.assertNotHasAttr(SpecialAttrsT, '__qualname__')
self.assertEqual(SpecialAttrsT.__module__, __name__) self.assertEqual(SpecialAttrsT.__module__, __name__)
# Module-level type variables are picklable. # Module-level type variables are picklable.
for proto in range(pickle.HIGHEST_PROTOCOL + 1): for proto in range(pickle.HIGHEST_PROTOCOL + 1):
@ -10483,7 +10482,7 @@ class SpecialAttrsTests(BaseTestCase):
self.assertIs(SpecialAttrsT, loaded) self.assertIs(SpecialAttrsT, loaded)
self.assertEqual(SpecialAttrsP.__name__, 'SpecialAttrsP') self.assertEqual(SpecialAttrsP.__name__, 'SpecialAttrsP')
self.assertFalse(hasattr(SpecialAttrsP, '__qualname__')) self.assertNotHasAttr(SpecialAttrsP, '__qualname__')
self.assertEqual(SpecialAttrsP.__module__, __name__) self.assertEqual(SpecialAttrsP.__module__, __name__)
# Module-level ParamSpecs are picklable. # Module-level ParamSpecs are picklable.
for proto in range(pickle.HIGHEST_PROTOCOL + 1): for proto in range(pickle.HIGHEST_PROTOCOL + 1):

View file

@ -0,0 +1,5 @@
Improve the performance of :func:`base64.b16decode` by up to ten times
by more efficiently checking the byte-string for hexadecimal digits.
Reduce the import time of :mod:`base64` by up to six times,
by no longer importing :mod:`re`.
Patch by Bénédikt Tran, Chris Markiewicz, and Adam Turner.

View file

@ -1004,10 +1004,10 @@ dummy_func(
PyList_SET_ITEM(list, index, PyStackRef_AsPyObjectSteal(value)); PyList_SET_ITEM(list, index, PyStackRef_AsPyObjectSteal(value));
assert(old_value != NULL); assert(old_value != NULL);
UNLOCK_OBJECT(list); // unlock before decrefs! UNLOCK_OBJECT(list); // unlock before decrefs!
Py_DECREF(old_value);
PyStackRef_CLOSE_SPECIALIZED(sub_st, _PyLong_ExactDealloc); PyStackRef_CLOSE_SPECIALIZED(sub_st, _PyLong_ExactDealloc);
DEAD(sub_st); DEAD(sub_st);
PyStackRef_CLOSE(list_st); PyStackRef_CLOSE(list_st);
Py_DECREF(old_value);
} }
inst(STORE_SUBSCR_DICT, (unused/1, value, dict_st, sub -- )) { inst(STORE_SUBSCR_DICT, (unused/1, value, dict_st, sub -- )) {
@ -1885,9 +1885,8 @@ dummy_func(
if (err == 0) { if (err == 0) {
err = PySet_Add(set_o, PyStackRef_AsPyObjectBorrow(values[i])); err = PySet_Add(set_o, PyStackRef_AsPyObjectBorrow(values[i]));
} }
PyStackRef_CLOSE(values[i]);
} }
DEAD(values); DECREF_INPUTS();
if (err != 0) { if (err != 0) {
Py_DECREF(set_o); Py_DECREF(set_o);
ERROR_IF(true, error); ERROR_IF(true, error);
@ -2412,8 +2411,8 @@ dummy_func(
_PyDictValues_AddToInsertionOrder(values, index); _PyDictValues_AddToInsertionOrder(values, index);
} }
UNLOCK_OBJECT(owner_o); UNLOCK_OBJECT(owner_o);
Py_XDECREF(old_value);
PyStackRef_CLOSE(owner); PyStackRef_CLOSE(owner);
Py_XDECREF(old_value);
} }
macro(STORE_ATTR_INSTANCE_VALUE) = macro(STORE_ATTR_INSTANCE_VALUE) =
@ -2457,9 +2456,9 @@ dummy_func(
// old_value should be DECREFed after GC track checking is done, if not, it could raise a segmentation fault, // old_value should be DECREFed after GC track checking is done, if not, it could raise a segmentation fault,
// when dict only holds the strong reference to value in ep->me_value. // when dict only holds the strong reference to value in ep->me_value.
Py_XDECREF(old_value);
STAT_INC(STORE_ATTR, hit); STAT_INC(STORE_ATTR, hit);
PyStackRef_CLOSE(owner); PyStackRef_CLOSE(owner);
Py_XDECREF(old_value);
} }
macro(STORE_ATTR_WITH_HINT) = macro(STORE_ATTR_WITH_HINT) =
@ -2476,8 +2475,8 @@ dummy_func(
PyObject *old_value = *(PyObject **)addr; PyObject *old_value = *(PyObject **)addr;
FT_ATOMIC_STORE_PTR_RELEASE(*(PyObject **)addr, PyStackRef_AsPyObjectSteal(value)); FT_ATOMIC_STORE_PTR_RELEASE(*(PyObject **)addr, PyStackRef_AsPyObjectSteal(value));
UNLOCK_OBJECT(owner_o); UNLOCK_OBJECT(owner_o);
Py_XDECREF(old_value);
PyStackRef_CLOSE(owner); PyStackRef_CLOSE(owner);
Py_XDECREF(old_value);
} }
macro(STORE_ATTR_SLOT) = macro(STORE_ATTR_SLOT) =
@ -3435,8 +3434,9 @@ dummy_func(
// oparg counts all of the args, but *not* self: // oparg counts all of the args, but *not* self:
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
// Check if the call can be inlined or not // Check if the call can be inlined or not
@ -3448,7 +3448,7 @@ dummy_func(
PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef(PyFunction_GET_GLOBALS(callable_o)); PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef(PyFunction_GET_GLOBALS(callable_o));
_PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit( _PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit(
tstate, callable[0], locals, tstate, callable[0], locals,
args, total_args, NULL, frame arguments, total_args, NULL, frame
); );
// Manipulate stack directly since we leave using DISPATCH_INLINED(). // Manipulate stack directly since we leave using DISPATCH_INLINED().
SYNC_SP(); SYNC_SP();
@ -3461,13 +3461,9 @@ dummy_func(
DISPATCH_INLINED(new_frame); DISPATCH_INLINED(new_frame);
} }
/* Callable is not a normal Python function */ /* Callable is not a normal Python function */
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
for (int i = 0; i < total_args; i++) { DECREF_INPUTS();
PyStackRef_CLOSE(args[i]);
}
DEAD(self_or_null);
PyStackRef_CLOSE(callable[0]);
ERROR_IF(true, error); ERROR_IF(true, error);
} }
PyObject *res_o = PyObject_Vectorcall( PyObject *res_o = PyObject_Vectorcall(
@ -3477,7 +3473,7 @@ dummy_func(
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
if (opcode == INSTRUMENTED_CALL) { if (opcode == INSTRUMENTED_CALL) {
PyObject *arg = total_args == 0 ? PyObject *arg = total_args == 0 ?
&_PyInstrumentation_MISSING : PyStackRef_AsPyObjectBorrow(args[0]); &_PyInstrumentation_MISSING : PyStackRef_AsPyObjectBorrow(arguments[0]);
if (res_o == NULL) { if (res_o == NULL) {
_Py_call_instrumentation_exc2( _Py_call_instrumentation_exc2(
tstate, PY_MONITORING_EVENT_C_RAISE, tstate, PY_MONITORING_EVENT_C_RAISE,
@ -3493,11 +3489,7 @@ dummy_func(
} }
} }
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
for (int i = 0; i < total_args; i++) { DECREF_INPUTS();
PyStackRef_CLOSE(args[i]);
}
DEAD(self_or_null);
PyStackRef_CLOSE(callable[0]);
ERROR_IF(res_o == NULL, error); ERROR_IF(res_o == NULL, error);
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
} }
@ -3617,12 +3609,13 @@ dummy_func(
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
/* Callable is not a normal Python function */ /* Callable is not a normal Python function */
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS(); DECREF_INPUTS();
ERROR_IF(true, error); ERROR_IF(true, error);
@ -3633,11 +3626,7 @@ dummy_func(
NULL); NULL);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
for (int i = 0; i < total_args; i++) { DECREF_INPUTS();
PyStackRef_CLOSE(args[i]);
}
DEAD(self_or_null);
PyStackRef_CLOSE(callable[0]);
ERROR_IF(res_o == NULL, error); ERROR_IF(res_o == NULL, error);
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
} }
@ -3877,15 +3866,9 @@ dummy_func(
DECREF_INPUTS(); DECREF_INPUTS();
ERROR_IF(true, error); ERROR_IF(true, error);
} }
DEAD(self_or_null);
PyObject *res_o = tp->tp_vectorcall((PyObject *)tp, args_o, total_args, NULL); PyObject *res_o = tp->tp_vectorcall((PyObject *)tp, args_o, total_args, NULL);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
/* Free the arguments. */ DECREF_INPUTS();
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(arguments[i]);
}
DEAD(args);
PyStackRef_CLOSE(callable[0]);
ERROR_IF(res_o == NULL, error); ERROR_IF(res_o == NULL, error);
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
} }
@ -3952,20 +3935,13 @@ dummy_func(
DECREF_INPUTS(); DECREF_INPUTS();
ERROR_IF(true, error); ERROR_IF(true, error);
} }
DEAD(self_or_null);
PyObject *res_o = ((PyCFunctionFast)(void(*)(void))cfunc)( PyObject *res_o = ((PyCFunctionFast)(void(*)(void))cfunc)(
PyCFunction_GET_SELF(callable_o), PyCFunction_GET_SELF(callable_o),
args_o, args_o,
total_args); total_args);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
DECREF_INPUTS();
/* Free the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(arguments[i]);
}
DEAD(args);
PyStackRef_CLOSE(callable[0]);
ERROR_IF(res_o == NULL, error); ERROR_IF(res_o == NULL, error);
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
} }
@ -3981,34 +3957,28 @@ dummy_func(
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
DEOPT_IF(!PyCFunction_CheckExact(callable_o)); DEOPT_IF(!PyCFunction_CheckExact(callable_o));
DEOPT_IF(PyCFunction_GET_FLAGS(callable_o) != (METH_FASTCALL | METH_KEYWORDS)); DEOPT_IF(PyCFunction_GET_FLAGS(callable_o) != (METH_FASTCALL | METH_KEYWORDS));
STAT_INC(CALL, hit); STAT_INC(CALL, hit);
/* res = func(self, args, nargs, kwnames) */ /* res = func(self, arguments, nargs, kwnames) */
PyCFunctionFastWithKeywords cfunc = PyCFunctionFastWithKeywords cfunc =
(PyCFunctionFastWithKeywords)(void(*)(void)) (PyCFunctionFastWithKeywords)(void(*)(void))
PyCFunction_GET_FUNCTION(callable_o); PyCFunction_GET_FUNCTION(callable_o);
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS(); DECREF_INPUTS();
ERROR_IF(true, error); ERROR_IF(true, error);
} }
PyObject *res_o = cfunc(PyCFunction_GET_SELF(callable_o), args_o, total_args, NULL); PyObject *res_o = cfunc(PyCFunction_GET_SELF(callable_o), args_o, total_args, NULL);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
DECREF_INPUTS();
/* Free the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
DEAD(self_or_null);
PyStackRef_CLOSE(callable[0]);
ERROR_IF(res_o == NULL, error); ERROR_IF(res_o == NULL, error);
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
} }
@ -4147,8 +4117,9 @@ dummy_func(
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o; PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
@ -4156,12 +4127,12 @@ dummy_func(
PyMethodDef *meth = method->d_method; PyMethodDef *meth = method->d_method;
EXIT_IF(meth->ml_flags != (METH_FASTCALL|METH_KEYWORDS)); EXIT_IF(meth->ml_flags != (METH_FASTCALL|METH_KEYWORDS));
PyTypeObject *d_type = method->d_common.d_type; PyTypeObject *d_type = method->d_common.d_type;
PyObject *self = PyStackRef_AsPyObjectBorrow(args[0]); PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
EXIT_IF(!Py_IS_TYPE(self, d_type)); EXIT_IF(!Py_IS_TYPE(self, d_type));
STAT_INC(CALL, hit); STAT_INC(CALL, hit);
int nargs = total_args - 1; int nargs = total_args - 1;
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS(); DECREF_INPUTS();
ERROR_IF(true, error); ERROR_IF(true, error);
@ -4171,13 +4142,7 @@ dummy_func(
PyObject *res_o = cfunc(self, (args_o + 1), nargs, NULL); PyObject *res_o = cfunc(self, (args_o + 1), nargs, NULL);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
DECREF_INPUTS();
/* Free the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
DEAD(self_or_null);
PyStackRef_CLOSE(callable[0]);
ERROR_IF(res_o == NULL, error); ERROR_IF(res_o == NULL, error);
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
} }
@ -4231,8 +4196,9 @@ dummy_func(
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o; PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
@ -4240,12 +4206,12 @@ dummy_func(
EXIT_IF(!Py_IS_TYPE(method, &PyMethodDescr_Type)); EXIT_IF(!Py_IS_TYPE(method, &PyMethodDescr_Type));
PyMethodDef *meth = method->d_method; PyMethodDef *meth = method->d_method;
EXIT_IF(meth->ml_flags != METH_FASTCALL); EXIT_IF(meth->ml_flags != METH_FASTCALL);
PyObject *self = PyStackRef_AsPyObjectBorrow(args[0]); PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
EXIT_IF(!Py_IS_TYPE(self, method->d_common.d_type)); EXIT_IF(!Py_IS_TYPE(self, method->d_common.d_type));
STAT_INC(CALL, hit); STAT_INC(CALL, hit);
int nargs = total_args - 1; int nargs = total_args - 1;
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS(); DECREF_INPUTS();
ERROR_IF(true, error); ERROR_IF(true, error);
@ -4255,13 +4221,7 @@ dummy_func(
PyObject *res_o = cfunc(self, (args_o + 1), nargs); PyObject *res_o = cfunc(self, (args_o + 1), nargs);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
DECREF_INPUTS();
/* Clear the stack of the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
DEAD(self_or_null);
PyStackRef_CLOSE(callable[0]);
ERROR_IF(res_o == NULL, error); ERROR_IF(res_o == NULL, error);
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
} }
@ -4313,8 +4273,9 @@ dummy_func(
// oparg counts all of the args, but *not* self: // oparg counts all of the args, but *not* self:
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
int positional_args = total_args - (int)PyTuple_GET_SIZE(kwnames_o); int positional_args = total_args - (int)PyTuple_GET_SIZE(kwnames_o);
@ -4327,7 +4288,7 @@ dummy_func(
PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef(PyFunction_GET_GLOBALS(callable_o)); PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef(PyFunction_GET_GLOBALS(callable_o));
_PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit( _PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit(
tstate, callable[0], locals, tstate, callable[0], locals,
args, positional_args, kwnames_o, frame arguments, positional_args, kwnames_o, frame
); );
PyStackRef_CLOSE(kwnames); PyStackRef_CLOSE(kwnames);
// Sync stack explicitly since we leave using DISPATCH_INLINED(). // Sync stack explicitly since we leave using DISPATCH_INLINED().
@ -4342,7 +4303,7 @@ dummy_func(
DISPATCH_INLINED(new_frame); DISPATCH_INLINED(new_frame);
} }
/* Callable is not a normal Python function */ /* Callable is not a normal Python function */
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS(); DECREF_INPUTS();
ERROR_IF(true, error); ERROR_IF(true, error);
@ -4354,7 +4315,7 @@ dummy_func(
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
if (opcode == INSTRUMENTED_CALL_KW) { if (opcode == INSTRUMENTED_CALL_KW) {
PyObject *arg = total_args == 0 ? PyObject *arg = total_args == 0 ?
&_PyInstrumentation_MISSING : PyStackRef_AsPyObjectBorrow(args[0]); &_PyInstrumentation_MISSING : PyStackRef_AsPyObjectBorrow(arguments[0]);
if (res_o == NULL) { if (res_o == NULL) {
_Py_call_instrumentation_exc2( _Py_call_instrumentation_exc2(
tstate, PY_MONITORING_EVENT_C_RAISE, tstate, PY_MONITORING_EVENT_C_RAISE,
@ -4369,13 +4330,7 @@ dummy_func(
} }
} }
} }
PyStackRef_CLOSE(kwnames); DECREF_INPUTS();
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
DEAD(self_or_null);
PyStackRef_CLOSE(callable[0]);
ERROR_IF(res_o == NULL, error); ERROR_IF(res_o == NULL, error);
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
} }
@ -4385,8 +4340,9 @@ dummy_func(
// oparg counts all of the args, but *not* self: // oparg counts all of the args, but *not* self:
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
PyObject *kwnames_o = PyStackRef_AsPyObjectBorrow(kwnames); PyObject *kwnames_o = PyStackRef_AsPyObjectBorrow(kwnames);
@ -4396,7 +4352,7 @@ dummy_func(
PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef(PyFunction_GET_GLOBALS(callable_o)); PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef(PyFunction_GET_GLOBALS(callable_o));
_PyInterpreterFrame *temp = _PyEvalFramePushAndInit( _PyInterpreterFrame *temp = _PyEvalFramePushAndInit(
tstate, callable[0], locals, tstate, callable[0], locals,
args, positional_args, kwnames_o, frame arguments, positional_args, kwnames_o, frame
); );
PyStackRef_CLOSE(kwnames); PyStackRef_CLOSE(kwnames);
// The frame has stolen all the arguments from the stack, // The frame has stolen all the arguments from the stack,
@ -4487,12 +4443,13 @@ dummy_func(
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
/* Callable is not a normal Python function */ /* Callable is not a normal Python function */
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS(); DECREF_INPUTS();
ERROR_IF(true, error); ERROR_IF(true, error);
@ -4506,11 +4463,7 @@ dummy_func(
PyStackRef_CLOSE(kwnames); PyStackRef_CLOSE(kwnames);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
for (int i = 0; i < total_args; i++) { DECREF_INPUTS();
PyStackRef_CLOSE(args[i]);
}
DEAD(self_or_null);
PyStackRef_CLOSE(callable[0]);
ERROR_IF(res_o == NULL, error); ERROR_IF(res_o == NULL, error);
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
} }

View file

@ -943,8 +943,8 @@
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
res_o = PyObject_GetItem(PyStackRef_AsPyObjectBorrow(container), slice); res_o = PyObject_GetItem(PyStackRef_AsPyObjectBorrow(container), slice);
stack_pointer = _PyFrame_GetStackPointer(frame);
Py_DECREF(slice); Py_DECREF(slice);
stack_pointer = _PyFrame_GetStackPointer(frame);
stack_pointer += 2; stack_pointer += 2;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
} }
@ -979,8 +979,8 @@
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
err = PyObject_SetItem(PyStackRef_AsPyObjectBorrow(container), slice, PyStackRef_AsPyObjectBorrow(v)); err = PyObject_SetItem(PyStackRef_AsPyObjectBorrow(container), slice, PyStackRef_AsPyObjectBorrow(v));
stack_pointer = _PyFrame_GetStackPointer(frame);
Py_DECREF(slice); Py_DECREF(slice);
stack_pointer = _PyFrame_GetStackPointer(frame);
stack_pointer += 2; stack_pointer += 2;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
} }
@ -1300,11 +1300,13 @@
PyList_SET_ITEM(list, index, PyStackRef_AsPyObjectSteal(value)); PyList_SET_ITEM(list, index, PyStackRef_AsPyObjectSteal(value));
assert(old_value != NULL); assert(old_value != NULL);
UNLOCK_OBJECT(list); // unlock before decrefs! UNLOCK_OBJECT(list); // unlock before decrefs!
Py_DECREF(old_value);
PyStackRef_CLOSE_SPECIALIZED(sub_st, _PyLong_ExactDealloc); PyStackRef_CLOSE_SPECIALIZED(sub_st, _PyLong_ExactDealloc);
PyStackRef_CLOSE(list_st); PyStackRef_CLOSE(list_st);
stack_pointer += -3; stack_pointer += -3;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(old_value);
stack_pointer = _PyFrame_GetStackPointer(frame);
break; break;
} }
@ -1452,8 +1454,8 @@
"'async for' received an object from __aiter__ " "'async for' received an object from __aiter__ "
"that does not implement __anext__: %.100s", "that does not implement __anext__: %.100s",
Py_TYPE(iter_o)->tp_name); Py_TYPE(iter_o)->tp_name);
stack_pointer = _PyFrame_GetStackPointer(frame);
Py_DECREF(iter_o); Py_DECREF(iter_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (true) JUMP_TO_ERROR(); if (true) JUMP_TO_ERROR();
} }
iter = PyStackRef_FromPyObjectSteal(iter_o); iter = PyStackRef_FromPyObjectSteal(iter_o);
@ -2092,7 +2094,9 @@
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
JUMP_TO_ERROR(); JUMP_TO_ERROR();
} }
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(oldobj); Py_DECREF(oldobj);
stack_pointer = _PyFrame_GetStackPointer(frame);
break; break;
} }
@ -2302,10 +2306,16 @@
err = PySet_Add(set_o, PyStackRef_AsPyObjectBorrow(values[i])); err = PySet_Add(set_o, PyStackRef_AsPyObjectBorrow(values[i]));
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
} }
PyStackRef_CLOSE(values[i]); }
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(values[_i]);
} }
if (err != 0) { if (err != 0) {
stack_pointer += -oparg;
assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(set_o); Py_DECREF(set_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (true) JUMP_TO_ERROR(); if (true) JUMP_TO_ERROR();
} }
set = PyStackRef_FromPyObjectSteal(set_o); set = PyStackRef_FromPyObjectSteal(set_o);
@ -2367,12 +2377,14 @@
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
err = PyObject_SetItem(LOCALS(), &_Py_ID(__annotations__), err = PyObject_SetItem(LOCALS(), &_Py_ID(__annotations__),
ann_dict); ann_dict);
stack_pointer = _PyFrame_GetStackPointer(frame);
Py_DECREF(ann_dict); Py_DECREF(ann_dict);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (err) JUMP_TO_ERROR(); if (err) JUMP_TO_ERROR();
} }
else { else {
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(ann_dict); Py_DECREF(ann_dict);
stack_pointer = _PyFrame_GetStackPointer(frame);
} }
break; break;
} }
@ -2992,10 +3004,12 @@
_PyDictValues_AddToInsertionOrder(values, index); _PyDictValues_AddToInsertionOrder(values, index);
} }
UNLOCK_OBJECT(owner_o); UNLOCK_OBJECT(owner_o);
Py_XDECREF(old_value);
PyStackRef_CLOSE(owner); PyStackRef_CLOSE(owner);
stack_pointer += -2; stack_pointer += -2;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_XDECREF(old_value);
stack_pointer = _PyFrame_GetStackPointer(frame);
break; break;
} }
@ -3059,11 +3073,13 @@
UNLOCK_OBJECT(dict); UNLOCK_OBJECT(dict);
// old_value should be DECREFed after GC track checking is done, if not, it could raise a segmentation fault, // old_value should be DECREFed after GC track checking is done, if not, it could raise a segmentation fault,
// when dict only holds the strong reference to value in ep->me_value. // when dict only holds the strong reference to value in ep->me_value.
Py_XDECREF(old_value);
STAT_INC(STORE_ATTR, hit); STAT_INC(STORE_ATTR, hit);
PyStackRef_CLOSE(owner); PyStackRef_CLOSE(owner);
stack_pointer += -2; stack_pointer += -2;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_XDECREF(old_value);
stack_pointer = _PyFrame_GetStackPointer(frame);
break; break;
} }
@ -3083,10 +3099,12 @@
PyObject *old_value = *(PyObject **)addr; PyObject *old_value = *(PyObject **)addr;
FT_ATOMIC_STORE_PTR_RELEASE(*(PyObject **)addr, PyStackRef_AsPyObjectSteal(value)); FT_ATOMIC_STORE_PTR_RELEASE(*(PyObject **)addr, PyStackRef_AsPyObjectSteal(value));
UNLOCK_OBJECT(owner_o); UNLOCK_OBJECT(owner_o);
Py_XDECREF(old_value);
PyStackRef_CLOSE(owner); PyStackRef_CLOSE(owner);
stack_pointer += -2; stack_pointer += -2;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_XDECREF(old_value);
stack_pointer = _PyFrame_GetStackPointer(frame);
break; break;
} }
@ -3111,8 +3129,8 @@
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
int res_bool = PyObject_IsTrue(res_o); int res_bool = PyObject_IsTrue(res_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
Py_DECREF(res_o); Py_DECREF(res_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (res_bool < 0) JUMP_TO_ERROR(); if (res_bool < 0) JUMP_TO_ERROR();
res = res_bool ? PyStackRef_True : PyStackRef_False; res = res_bool ? PyStackRef_True : PyStackRef_False;
} }
@ -3859,7 +3877,9 @@
tb = Py_None; tb = Py_None;
} }
else { else {
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(tb); Py_DECREF(tb);
stack_pointer = _PyFrame_GetStackPointer(frame);
} }
assert(PyStackRef_LongCheck(lasti)); assert(PyStackRef_LongCheck(lasti));
(void)lasti; // Shut up compiler warning if asserts are off (void)lasti; // Shut up compiler warning if asserts are off
@ -4206,12 +4226,13 @@
#endif #endif
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
/* Callable is not a normal Python function */ /* Callable is not a normal Python function */
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]); PyStackRef_XCLOSE(self_or_null[0]);
@ -4228,10 +4249,11 @@
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) JUMP_TO_ERROR(); if (res_o == NULL) JUMP_TO_ERROR();
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
stack_pointer[-2 - oparg] = res; stack_pointer[-2 - oparg] = res;
@ -4723,11 +4745,11 @@
PyObject *res_o = tp->tp_vectorcall((PyObject *)tp, args_o, total_args, NULL); PyObject *res_o = tp->tp_vectorcall((PyObject *)tp, args_o, total_args, NULL);
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
/* Free the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(arguments[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) JUMP_TO_ERROR(); if (res_o == NULL) JUMP_TO_ERROR();
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
stack_pointer[-2 - oparg] = res; stack_pointer[-2 - oparg] = res;
@ -4833,11 +4855,11 @@
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
/* Free the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(arguments[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) JUMP_TO_ERROR(); if (res_o == NULL) JUMP_TO_ERROR();
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
stack_pointer[-2 - oparg] = res; stack_pointer[-2 - oparg] = res;
@ -4858,8 +4880,9 @@
/* Builtin METH_FASTCALL | METH_KEYWORDS functions */ /* Builtin METH_FASTCALL | METH_KEYWORDS functions */
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
if (!PyCFunction_CheckExact(callable_o)) { if (!PyCFunction_CheckExact(callable_o)) {
@ -4871,13 +4894,13 @@
JUMP_TO_JUMP_TARGET(); JUMP_TO_JUMP_TARGET();
} }
STAT_INC(CALL, hit); STAT_INC(CALL, hit);
/* res = func(self, args, nargs, kwnames) */ /* res = func(self, arguments, nargs, kwnames) */
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
PyCFunctionFastWithKeywords cfunc = PyCFunctionFastWithKeywords cfunc =
(PyCFunctionFastWithKeywords)(void(*)(void)) (PyCFunctionFastWithKeywords)(void(*)(void))
PyCFunction_GET_FUNCTION(callable_o); PyCFunction_GET_FUNCTION(callable_o);
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]); PyStackRef_XCLOSE(self_or_null[0]);
@ -4891,11 +4914,11 @@
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
/* Free the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) JUMP_TO_ERROR(); if (res_o == NULL) JUMP_TO_ERROR();
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
stack_pointer[-2 - oparg] = res; stack_pointer[-2 - oparg] = res;
@ -5115,8 +5138,9 @@
callable = &stack_pointer[-2 - oparg]; callable = &stack_pointer[-2 - oparg];
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o; PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
@ -5130,14 +5154,14 @@
JUMP_TO_JUMP_TARGET(); JUMP_TO_JUMP_TARGET();
} }
PyTypeObject *d_type = method->d_common.d_type; PyTypeObject *d_type = method->d_common.d_type;
PyObject *self = PyStackRef_AsPyObjectBorrow(args[0]); PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
if (!Py_IS_TYPE(self, d_type)) { if (!Py_IS_TYPE(self, d_type)) {
UOP_STAT_INC(uopcode, miss); UOP_STAT_INC(uopcode, miss);
JUMP_TO_JUMP_TARGET(); JUMP_TO_JUMP_TARGET();
} }
STAT_INC(CALL, hit); STAT_INC(CALL, hit);
int nargs = total_args - 1; int nargs = total_args - 1;
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]); PyStackRef_XCLOSE(self_or_null[0]);
@ -5153,11 +5177,11 @@
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
/* Free the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) JUMP_TO_ERROR(); if (res_o == NULL) JUMP_TO_ERROR();
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
stack_pointer[-2 - oparg] = res; stack_pointer[-2 - oparg] = res;
@ -5236,8 +5260,9 @@
callable = &stack_pointer[-2 - oparg]; callable = &stack_pointer[-2 - oparg];
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o; PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
@ -5251,14 +5276,14 @@
UOP_STAT_INC(uopcode, miss); UOP_STAT_INC(uopcode, miss);
JUMP_TO_JUMP_TARGET(); JUMP_TO_JUMP_TARGET();
} }
PyObject *self = PyStackRef_AsPyObjectBorrow(args[0]); PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
if (!Py_IS_TYPE(self, method->d_common.d_type)) { if (!Py_IS_TYPE(self, method->d_common.d_type)) {
UOP_STAT_INC(uopcode, miss); UOP_STAT_INC(uopcode, miss);
JUMP_TO_JUMP_TARGET(); JUMP_TO_JUMP_TARGET();
} }
STAT_INC(CALL, hit); STAT_INC(CALL, hit);
int nargs = total_args - 1; int nargs = total_args - 1;
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]); PyStackRef_XCLOSE(self_or_null[0]);
@ -5274,11 +5299,11 @@
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
/* Clear the stack of the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) JUMP_TO_ERROR(); if (res_o == NULL) JUMP_TO_ERROR();
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
stack_pointer[-2 - oparg] = res; stack_pointer[-2 - oparg] = res;
@ -5334,8 +5359,9 @@
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
// oparg counts all of the args, but *not* self: // oparg counts all of the args, but *not* self:
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
PyObject *kwnames_o = PyStackRef_AsPyObjectBorrow(kwnames); PyObject *kwnames_o = PyStackRef_AsPyObjectBorrow(kwnames);
@ -5346,7 +5372,7 @@
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
_PyInterpreterFrame *temp = _PyEvalFramePushAndInit( _PyInterpreterFrame *temp = _PyEvalFramePushAndInit(
tstate, callable[0], locals, tstate, callable[0], locals,
args, positional_args, kwnames_o, frame arguments, positional_args, kwnames_o, frame
); );
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
PyStackRef_CLOSE(kwnames); PyStackRef_CLOSE(kwnames);
@ -5463,12 +5489,13 @@
#endif #endif
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
/* Callable is not a normal Python function */ /* Callable is not a normal Python function */
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]); PyStackRef_XCLOSE(self_or_null[0]);
@ -5489,10 +5516,11 @@
PyStackRef_CLOSE(kwnames); PyStackRef_CLOSE(kwnames);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) JUMP_TO_ERROR(); if (res_o == NULL) JUMP_TO_ERROR();
res = PyStackRef_FromPyObjectSteal(res_o); res = PyStackRef_FromPyObjectSteal(res_o);
stack_pointer[-3 - oparg] = res; stack_pointer[-3 - oparg] = res;
@ -6128,7 +6156,9 @@
case _START_EXECUTOR: { case _START_EXECUTOR: {
PyObject *executor = (PyObject *)CURRENT_OPERAND0(); PyObject *executor = (PyObject *)CURRENT_OPERAND0();
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(tstate->previous_executor); Py_DECREF(tstate->previous_executor);
stack_pointer = _PyFrame_GetStackPointer(frame);
tstate->previous_executor = NULL; tstate->previous_executor = NULL;
#ifndef _Py_JIT #ifndef _Py_JIT
current_executor = (_PyExecutorObject*)executor; current_executor = (_PyExecutorObject*)executor;

View file

@ -418,8 +418,8 @@
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
res_o = PyObject_GetItem(PyStackRef_AsPyObjectBorrow(container), slice); res_o = PyObject_GetItem(PyStackRef_AsPyObjectBorrow(container), slice);
stack_pointer = _PyFrame_GetStackPointer(frame);
Py_DECREF(slice); Py_DECREF(slice);
stack_pointer = _PyFrame_GetStackPointer(frame);
stack_pointer += 2; stack_pointer += 2;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
} }
@ -765,16 +765,18 @@
err = PySet_Add(set_o, PyStackRef_AsPyObjectBorrow(values[i])); err = PySet_Add(set_o, PyStackRef_AsPyObjectBorrow(values[i]));
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
} }
PyStackRef_CLOSE(values[i]); }
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(values[_i]);
} }
if (err != 0) { if (err != 0) {
Py_DECREF(set_o);
{
stack_pointer += -oparg; stack_pointer += -oparg;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(set_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
goto error; goto error;
} }
}
set = PyStackRef_FromPyObjectSteal(set_o); set = PyStackRef_FromPyObjectSteal(set_o);
stack_pointer[-oparg] = set; stack_pointer[-oparg] = set;
stack_pointer += 1 - oparg; stack_pointer += 1 - oparg;
@ -931,8 +933,9 @@
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
// oparg counts all of the args, but *not* self: // oparg counts all of the args, but *not* self:
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
// Check if the call can be inlined or not // Check if the call can be inlined or not
@ -945,7 +948,7 @@
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
_PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit( _PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit(
tstate, callable[0], locals, tstate, callable[0], locals,
args, total_args, NULL, frame arguments, total_args, NULL, frame
); );
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
// Manipulate stack directly since we leave using DISPATCH_INLINED(). // Manipulate stack directly since we leave using DISPATCH_INLINED().
@ -960,12 +963,13 @@
DISPATCH_INLINED(new_frame); DISPATCH_INLINED(new_frame);
} }
/* Callable is not a normal Python function */ /* Callable is not a normal Python function */
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
{ {
stack_pointer += -2 - oparg; stack_pointer += -2 - oparg;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
@ -981,7 +985,7 @@
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
if (opcode == INSTRUMENTED_CALL) { if (opcode == INSTRUMENTED_CALL) {
PyObject *arg = total_args == 0 ? PyObject *arg = total_args == 0 ?
&_PyInstrumentation_MISSING : PyStackRef_AsPyObjectBorrow(args[0]); &_PyInstrumentation_MISSING : PyStackRef_AsPyObjectBorrow(arguments[0]);
if (res_o == NULL) { if (res_o == NULL) {
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
_Py_call_instrumentation_exc2( _Py_call_instrumentation_exc2(
@ -1001,10 +1005,11 @@
} }
} }
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) { if (res_o == NULL) {
stack_pointer += -2 - oparg; stack_pointer += -2 - oparg;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
@ -1378,11 +1383,11 @@
PyObject *res_o = tp->tp_vectorcall((PyObject *)tp, args_o, total_args, NULL); PyObject *res_o = tp->tp_vectorcall((PyObject *)tp, args_o, total_args, NULL);
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
/* Free the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(arguments[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) { if (res_o == NULL) {
stack_pointer += -2 - oparg; stack_pointer += -2 - oparg;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
@ -1462,11 +1467,11 @@
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
/* Free the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(arguments[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) { if (res_o == NULL) {
stack_pointer += -2 - oparg; stack_pointer += -2 - oparg;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
@ -1515,20 +1520,21 @@
/* Builtin METH_FASTCALL | METH_KEYWORDS functions */ /* Builtin METH_FASTCALL | METH_KEYWORDS functions */
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
DEOPT_IF(!PyCFunction_CheckExact(callable_o), CALL); DEOPT_IF(!PyCFunction_CheckExact(callable_o), CALL);
DEOPT_IF(PyCFunction_GET_FLAGS(callable_o) != (METH_FASTCALL | METH_KEYWORDS), CALL); DEOPT_IF(PyCFunction_GET_FLAGS(callable_o) != (METH_FASTCALL | METH_KEYWORDS), CALL);
STAT_INC(CALL, hit); STAT_INC(CALL, hit);
/* res = func(self, args, nargs, kwnames) */ /* res = func(self, arguments, nargs, kwnames) */
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
PyCFunctionFastWithKeywords cfunc = PyCFunctionFastWithKeywords cfunc =
(PyCFunctionFastWithKeywords)(void(*)(void)) (PyCFunctionFastWithKeywords)(void(*)(void))
PyCFunction_GET_FUNCTION(callable_o); PyCFunction_GET_FUNCTION(callable_o);
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]); PyStackRef_XCLOSE(self_or_null[0]);
@ -1546,11 +1552,11 @@
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
/* Free the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) { if (res_o == NULL) {
stack_pointer += -2 - oparg; stack_pointer += -2 - oparg;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
@ -1967,8 +1973,9 @@
PyObject *kwnames_o = PyStackRef_AsPyObjectBorrow(kwnames); PyObject *kwnames_o = PyStackRef_AsPyObjectBorrow(kwnames);
// oparg counts all of the args, but *not* self: // oparg counts all of the args, but *not* self:
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
int positional_args = total_args - (int)PyTuple_GET_SIZE(kwnames_o); int positional_args = total_args - (int)PyTuple_GET_SIZE(kwnames_o);
@ -1983,7 +1990,7 @@
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
_PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit( _PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit(
tstate, callable[0], locals, tstate, callable[0], locals,
args, positional_args, kwnames_o, frame arguments, positional_args, kwnames_o, frame
); );
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
PyStackRef_CLOSE(kwnames); PyStackRef_CLOSE(kwnames);
@ -2000,7 +2007,7 @@
DISPATCH_INLINED(new_frame); DISPATCH_INLINED(new_frame);
} }
/* Callable is not a normal Python function */ /* Callable is not a normal Python function */
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]); PyStackRef_XCLOSE(self_or_null[0]);
@ -2024,7 +2031,7 @@
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
if (opcode == INSTRUMENTED_CALL_KW) { if (opcode == INSTRUMENTED_CALL_KW) {
PyObject *arg = total_args == 0 ? PyObject *arg = total_args == 0 ?
&_PyInstrumentation_MISSING : PyStackRef_AsPyObjectBorrow(args[0]); &_PyInstrumentation_MISSING : PyStackRef_AsPyObjectBorrow(arguments[0]);
if (res_o == NULL) { if (res_o == NULL) {
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
_Py_call_instrumentation_exc2( _Py_call_instrumentation_exc2(
@ -2043,12 +2050,12 @@
} }
} }
} }
PyStackRef_CLOSE(kwnames);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
PyStackRef_CLOSE(kwnames);
if (res_o == NULL) { if (res_o == NULL) {
stack_pointer += -3 - oparg; stack_pointer += -3 - oparg;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
@ -2115,8 +2122,9 @@
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
// oparg counts all of the args, but *not* self: // oparg counts all of the args, but *not* self:
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
PyObject *kwnames_o = PyStackRef_AsPyObjectBorrow(kwnames); PyObject *kwnames_o = PyStackRef_AsPyObjectBorrow(kwnames);
@ -2127,7 +2135,7 @@
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
_PyInterpreterFrame *temp = _PyEvalFramePushAndInit( _PyInterpreterFrame *temp = _PyEvalFramePushAndInit(
tstate, callable[0], locals, tstate, callable[0], locals,
args, positional_args, kwnames_o, frame arguments, positional_args, kwnames_o, frame
); );
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
PyStackRef_CLOSE(kwnames); PyStackRef_CLOSE(kwnames);
@ -2196,12 +2204,13 @@
#endif #endif
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
/* Callable is not a normal Python function */ /* Callable is not a normal Python function */
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]); PyStackRef_XCLOSE(self_or_null[0]);
@ -2226,10 +2235,11 @@
PyStackRef_CLOSE(kwnames); PyStackRef_CLOSE(kwnames);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) { if (res_o == NULL) {
stack_pointer += -3 - oparg; stack_pointer += -3 - oparg;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
@ -2291,8 +2301,9 @@
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
// oparg counts all of the args, but *not* self: // oparg counts all of the args, but *not* self:
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
PyObject *kwnames_o = PyStackRef_AsPyObjectBorrow(kwnames); PyObject *kwnames_o = PyStackRef_AsPyObjectBorrow(kwnames);
@ -2303,7 +2314,7 @@
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
_PyInterpreterFrame *temp = _PyEvalFramePushAndInit( _PyInterpreterFrame *temp = _PyEvalFramePushAndInit(
tstate, callable[0], locals, tstate, callable[0], locals,
args, positional_args, kwnames_o, frame arguments, positional_args, kwnames_o, frame
); );
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
PyStackRef_CLOSE(kwnames); PyStackRef_CLOSE(kwnames);
@ -2446,8 +2457,9 @@
callable = &stack_pointer[-2 - oparg]; callable = &stack_pointer[-2 - oparg];
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o; PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
@ -2455,11 +2467,11 @@
DEOPT_IF(!Py_IS_TYPE(method, &PyMethodDescr_Type), CALL); DEOPT_IF(!Py_IS_TYPE(method, &PyMethodDescr_Type), CALL);
PyMethodDef *meth = method->d_method; PyMethodDef *meth = method->d_method;
DEOPT_IF(meth->ml_flags != METH_FASTCALL, CALL); DEOPT_IF(meth->ml_flags != METH_FASTCALL, CALL);
PyObject *self = PyStackRef_AsPyObjectBorrow(args[0]); PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
DEOPT_IF(!Py_IS_TYPE(self, method->d_common.d_type), CALL); DEOPT_IF(!Py_IS_TYPE(self, method->d_common.d_type), CALL);
STAT_INC(CALL, hit); STAT_INC(CALL, hit);
int nargs = total_args - 1; int nargs = total_args - 1;
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]); PyStackRef_XCLOSE(self_or_null[0]);
@ -2479,11 +2491,11 @@
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
/* Clear the stack of the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) { if (res_o == NULL) {
stack_pointer += -2 - oparg; stack_pointer += -2 - oparg;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
@ -2531,8 +2543,9 @@
callable = &stack_pointer[-2 - oparg]; callable = &stack_pointer[-2 - oparg];
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o; PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
@ -2540,11 +2553,11 @@
PyMethodDef *meth = method->d_method; PyMethodDef *meth = method->d_method;
DEOPT_IF(meth->ml_flags != (METH_FASTCALL|METH_KEYWORDS), CALL); DEOPT_IF(meth->ml_flags != (METH_FASTCALL|METH_KEYWORDS), CALL);
PyTypeObject *d_type = method->d_common.d_type; PyTypeObject *d_type = method->d_common.d_type;
PyObject *self = PyStackRef_AsPyObjectBorrow(args[0]); PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
DEOPT_IF(!Py_IS_TYPE(self, d_type), CALL); DEOPT_IF(!Py_IS_TYPE(self, d_type), CALL);
STAT_INC(CALL, hit); STAT_INC(CALL, hit);
int nargs = total_args - 1; int nargs = total_args - 1;
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]); PyStackRef_XCLOSE(self_or_null[0]);
@ -2564,11 +2577,11 @@
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
/* Free the arguments. */
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) { if (res_o == NULL) {
stack_pointer += -2 - oparg; stack_pointer += -2 - oparg;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
@ -2772,12 +2785,13 @@
#endif #endif
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
/* Callable is not a normal Python function */ /* Callable is not a normal Python function */
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]); PyStackRef_XCLOSE(self_or_null[0]);
@ -2798,10 +2812,11 @@
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) { if (res_o == NULL) {
stack_pointer += -2 - oparg; stack_pointer += -2 - oparg;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
@ -3279,8 +3294,8 @@
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
int res_bool = PyObject_IsTrue(res_o); int res_bool = PyObject_IsTrue(res_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
Py_DECREF(res_o); Py_DECREF(res_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (res_bool < 0) goto error; if (res_bool < 0) goto error;
res = res_bool ? PyStackRef_True : PyStackRef_False; res = res_bool ? PyStackRef_True : PyStackRef_False;
} }
@ -3602,7 +3617,9 @@
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
goto error; goto error;
} }
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(oldobj); Py_DECREF(oldobj);
stack_pointer = _PyFrame_GetStackPointer(frame);
DISPATCH(); DISPATCH();
} }
@ -4069,7 +4086,9 @@
#ifndef Py_GIL_DISABLED #ifndef Py_GIL_DISABLED
if (seq != NULL) { if (seq != NULL) {
it->it_seq = NULL; it->it_seq = NULL;
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(seq); Py_DECREF(seq);
stack_pointer = _PyFrame_GetStackPointer(frame);
} }
#endif #endif
/* Jump forward oparg, then skip following END_FOR instruction */ /* Jump forward oparg, then skip following END_FOR instruction */
@ -4159,7 +4178,9 @@
if (seq == NULL || it->it_index >= PyTuple_GET_SIZE(seq)) { if (seq == NULL || it->it_index >= PyTuple_GET_SIZE(seq)) {
if (seq != NULL) { if (seq != NULL) {
it->it_seq = NULL; it->it_seq = NULL;
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(seq); Py_DECREF(seq);
stack_pointer = _PyFrame_GetStackPointer(frame);
} }
/* Jump forward oparg, then skip following END_FOR instruction */ /* Jump forward oparg, then skip following END_FOR instruction */
JUMPBY(oparg + 1); JUMPBY(oparg + 1);
@ -4220,8 +4241,8 @@
"'async for' received an object from __aiter__ " "'async for' received an object from __aiter__ "
"that does not implement __anext__: %.100s", "that does not implement __anext__: %.100s",
Py_TYPE(iter_o)->tp_name); Py_TYPE(iter_o)->tp_name);
stack_pointer = _PyFrame_GetStackPointer(frame);
Py_DECREF(iter_o); Py_DECREF(iter_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
goto error; goto error;
} }
iter = PyStackRef_FromPyObjectSteal(iter_o); iter = PyStackRef_FromPyObjectSteal(iter_o);
@ -4455,8 +4476,9 @@
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]); PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
// oparg counts all of the args, but *not* self: // oparg counts all of the args, but *not* self:
int total_args = oparg; int total_args = oparg;
_PyStackRef *arguments = args;
if (!PyStackRef_IsNull(self_or_null[0])) { if (!PyStackRef_IsNull(self_or_null[0])) {
args--; arguments--;
total_args++; total_args++;
} }
// Check if the call can be inlined or not // Check if the call can be inlined or not
@ -4469,7 +4491,7 @@
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
_PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit( _PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit(
tstate, callable[0], locals, tstate, callable[0], locals,
args, total_args, NULL, frame arguments, total_args, NULL, frame
); );
stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer = _PyFrame_GetStackPointer(frame);
// Manipulate stack directly since we leave using DISPATCH_INLINED(). // Manipulate stack directly since we leave using DISPATCH_INLINED().
@ -4484,12 +4506,13 @@
DISPATCH_INLINED(new_frame); DISPATCH_INLINED(new_frame);
} }
/* Callable is not a normal Python function */ /* Callable is not a normal Python function */
STACKREFS_TO_PYOBJECTS(args, total_args, args_o); STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
if (CONVERSION_FAILED(args_o)) { if (CONVERSION_FAILED(args_o)) {
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
{ {
stack_pointer += -2 - oparg; stack_pointer += -2 - oparg;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
@ -4505,7 +4528,7 @@
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o); STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
if (opcode == INSTRUMENTED_CALL) { if (opcode == INSTRUMENTED_CALL) {
PyObject *arg = total_args == 0 ? PyObject *arg = total_args == 0 ?
&_PyInstrumentation_MISSING : PyStackRef_AsPyObjectBorrow(args[0]); &_PyInstrumentation_MISSING : PyStackRef_AsPyObjectBorrow(arguments[0]);
if (res_o == NULL) { if (res_o == NULL) {
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
_Py_call_instrumentation_exc2( _Py_call_instrumentation_exc2(
@ -4525,10 +4548,11 @@
} }
} }
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
PyStackRef_CLOSE(callable[0]); PyStackRef_CLOSE(callable[0]);
PyStackRef_XCLOSE(self_or_null[0]);
for (int _i = oparg; --_i >= 0;) {
PyStackRef_CLOSE(args[_i]);
}
if (res_o == NULL) { if (res_o == NULL) {
stack_pointer += -2 - oparg; stack_pointer += -2 - oparg;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
@ -6470,8 +6494,8 @@
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
PyObject *attr_o = PyObject_GetAttr(super, name); PyObject *attr_o = PyObject_GetAttr(super, name);
stack_pointer = _PyFrame_GetStackPointer(frame);
Py_DECREF(super); Py_DECREF(super);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (attr_o == NULL) goto error; if (attr_o == NULL) goto error;
attr = PyStackRef_FromPyObjectSteal(attr_o); attr = PyStackRef_FromPyObjectSteal(attr_o);
null = PyStackRef_NULL; null = PyStackRef_NULL;
@ -6961,8 +6985,8 @@
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
_PyErr_SetString(tstate, PyExc_SystemError, "lasti is not an int"); _PyErr_SetString(tstate, PyExc_SystemError, "lasti is not an int");
stack_pointer = _PyFrame_GetStackPointer(frame);
Py_DECREF(exc); Py_DECREF(exc);
stack_pointer = _PyFrame_GetStackPointer(frame);
goto error; goto error;
} }
stack_pointer += 1; stack_pointer += 1;
@ -7307,12 +7331,14 @@
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
err = PyObject_SetItem(LOCALS(), &_Py_ID(__annotations__), err = PyObject_SetItem(LOCALS(), &_Py_ID(__annotations__),
ann_dict); ann_dict);
stack_pointer = _PyFrame_GetStackPointer(frame);
Py_DECREF(ann_dict); Py_DECREF(ann_dict);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (err) goto error; if (err) goto error;
} }
else { else {
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(ann_dict); Py_DECREF(ann_dict);
stack_pointer = _PyFrame_GetStackPointer(frame);
} }
DISPATCH(); DISPATCH();
} }
@ -7472,11 +7498,13 @@
_PyDictValues_AddToInsertionOrder(values, index); _PyDictValues_AddToInsertionOrder(values, index);
} }
UNLOCK_OBJECT(owner_o); UNLOCK_OBJECT(owner_o);
Py_XDECREF(old_value);
PyStackRef_CLOSE(owner); PyStackRef_CLOSE(owner);
}
stack_pointer += -2; stack_pointer += -2;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_XDECREF(old_value);
stack_pointer = _PyFrame_GetStackPointer(frame);
}
DISPATCH(); DISPATCH();
} }
@ -7507,11 +7535,13 @@
PyObject *old_value = *(PyObject **)addr; PyObject *old_value = *(PyObject **)addr;
FT_ATOMIC_STORE_PTR_RELEASE(*(PyObject **)addr, PyStackRef_AsPyObjectSteal(value)); FT_ATOMIC_STORE_PTR_RELEASE(*(PyObject **)addr, PyStackRef_AsPyObjectSteal(value));
UNLOCK_OBJECT(owner_o); UNLOCK_OBJECT(owner_o);
Py_XDECREF(old_value);
PyStackRef_CLOSE(owner); PyStackRef_CLOSE(owner);
}
stack_pointer += -2; stack_pointer += -2;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_XDECREF(old_value);
stack_pointer = _PyFrame_GetStackPointer(frame);
}
DISPATCH(); DISPATCH();
} }
@ -7570,12 +7600,14 @@
UNLOCK_OBJECT(dict); UNLOCK_OBJECT(dict);
// old_value should be DECREFed after GC track checking is done, if not, it could raise a segmentation fault, // old_value should be DECREFed after GC track checking is done, if not, it could raise a segmentation fault,
// when dict only holds the strong reference to value in ep->me_value. // when dict only holds the strong reference to value in ep->me_value.
Py_XDECREF(old_value);
STAT_INC(STORE_ATTR, hit); STAT_INC(STORE_ATTR, hit);
PyStackRef_CLOSE(owner); PyStackRef_CLOSE(owner);
}
stack_pointer += -2; stack_pointer += -2;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_XDECREF(old_value);
stack_pointer = _PyFrame_GetStackPointer(frame);
}
DISPATCH(); DISPATCH();
} }
@ -7723,8 +7755,8 @@
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer); _PyFrame_SetStackPointer(frame, stack_pointer);
err = PyObject_SetItem(PyStackRef_AsPyObjectBorrow(container), slice, PyStackRef_AsPyObjectBorrow(v)); err = PyObject_SetItem(PyStackRef_AsPyObjectBorrow(container), slice, PyStackRef_AsPyObjectBorrow(v));
stack_pointer = _PyFrame_GetStackPointer(frame);
Py_DECREF(slice); Py_DECREF(slice);
stack_pointer = _PyFrame_GetStackPointer(frame);
stack_pointer += 2; stack_pointer += 2;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
} }
@ -7839,11 +7871,13 @@
PyList_SET_ITEM(list, index, PyStackRef_AsPyObjectSteal(value)); PyList_SET_ITEM(list, index, PyStackRef_AsPyObjectSteal(value));
assert(old_value != NULL); assert(old_value != NULL);
UNLOCK_OBJECT(list); // unlock before decrefs! UNLOCK_OBJECT(list); // unlock before decrefs!
Py_DECREF(old_value);
PyStackRef_CLOSE_SPECIALIZED(sub_st, _PyLong_ExactDealloc); PyStackRef_CLOSE_SPECIALIZED(sub_st, _PyLong_ExactDealloc);
PyStackRef_CLOSE(list_st); PyStackRef_CLOSE(list_st);
stack_pointer += -3; stack_pointer += -3;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(old_value);
stack_pointer = _PyFrame_GetStackPointer(frame);
DISPATCH(); DISPATCH();
} }
@ -8254,7 +8288,9 @@
tb = Py_None; tb = Py_None;
} }
else { else {
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(tb); Py_DECREF(tb);
stack_pointer = _PyFrame_GetStackPointer(frame);
} }
assert(PyStackRef_LongCheck(lasti)); assert(PyStackRef_LongCheck(lasti));
(void)lasti; // Shut up compiler warning if asserts are off (void)lasti; // Shut up compiler warning if asserts are off

View file

@ -279,16 +279,19 @@
goto error; goto error;
} }
res = sym_new_const(ctx, temp); res = sym_new_const(ctx, temp);
stack_pointer[-2] = res;
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
Py_DECREF(temp); Py_DECREF(temp);
// TODO gh-115506: // TODO gh-115506:
// replace opcode with constant propagated one and add tests! // replace opcode with constant propagated one and add tests!
} }
else { else {
res = sym_new_type(ctx, &PyLong_Type); res = sym_new_type(ctx, &PyLong_Type);
}
stack_pointer[-2] = res;
stack_pointer += -1; stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
}
stack_pointer[-1] = res;
break; break;
} }
@ -309,16 +312,19 @@
goto error; goto error;
} }
res = sym_new_const(ctx, temp); res = sym_new_const(ctx, temp);
stack_pointer[-2] = res;
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
Py_DECREF(temp); Py_DECREF(temp);
// TODO gh-115506: // TODO gh-115506:
// replace opcode with constant propagated one and add tests! // replace opcode with constant propagated one and add tests!
} }
else { else {
res = sym_new_type(ctx, &PyLong_Type); res = sym_new_type(ctx, &PyLong_Type);
}
stack_pointer[-2] = res;
stack_pointer += -1; stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
}
stack_pointer[-1] = res;
break; break;
} }
@ -339,16 +345,19 @@
goto error; goto error;
} }
res = sym_new_const(ctx, temp); res = sym_new_const(ctx, temp);
stack_pointer[-2] = res;
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
Py_DECREF(temp); Py_DECREF(temp);
// TODO gh-115506: // TODO gh-115506:
// replace opcode with constant propagated one and add tests! // replace opcode with constant propagated one and add tests!
} }
else { else {
res = sym_new_type(ctx, &PyLong_Type); res = sym_new_type(ctx, &PyLong_Type);
}
stack_pointer[-2] = res;
stack_pointer += -1; stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
}
stack_pointer[-1] = res;
break; break;
} }
@ -401,16 +410,19 @@
goto error; goto error;
} }
res = sym_new_const(ctx, temp); res = sym_new_const(ctx, temp);
stack_pointer[-2] = res;
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
Py_DECREF(temp); Py_DECREF(temp);
// TODO gh-115506: // TODO gh-115506:
// replace opcode with constant propagated one and update tests! // replace opcode with constant propagated one and update tests!
} }
else { else {
res = sym_new_type(ctx, &PyFloat_Type); res = sym_new_type(ctx, &PyFloat_Type);
}
stack_pointer[-2] = res;
stack_pointer += -1; stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
}
stack_pointer[-1] = res;
break; break;
} }
@ -432,16 +444,19 @@
goto error; goto error;
} }
res = sym_new_const(ctx, temp); res = sym_new_const(ctx, temp);
stack_pointer[-2] = res;
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
Py_DECREF(temp); Py_DECREF(temp);
// TODO gh-115506: // TODO gh-115506:
// replace opcode with constant propagated one and update tests! // replace opcode with constant propagated one and update tests!
} }
else { else {
res = sym_new_type(ctx, &PyFloat_Type); res = sym_new_type(ctx, &PyFloat_Type);
}
stack_pointer[-2] = res;
stack_pointer += -1; stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
}
stack_pointer[-1] = res;
break; break;
} }
@ -463,16 +478,19 @@
goto error; goto error;
} }
res = sym_new_const(ctx, temp); res = sym_new_const(ctx, temp);
stack_pointer[-2] = res;
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
Py_DECREF(temp); Py_DECREF(temp);
// TODO gh-115506: // TODO gh-115506:
// replace opcode with constant propagated one and update tests! // replace opcode with constant propagated one and update tests!
} }
else { else {
res = sym_new_type(ctx, &PyFloat_Type); res = sym_new_type(ctx, &PyFloat_Type);
}
stack_pointer[-2] = res;
stack_pointer += -1; stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
}
stack_pointer[-1] = res;
break; break;
} }
@ -503,14 +521,17 @@
goto error; goto error;
} }
res = sym_new_const(ctx, temp); res = sym_new_const(ctx, temp);
stack_pointer[-2] = res;
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
Py_DECREF(temp); Py_DECREF(temp);
} }
else { else {
res = sym_new_type(ctx, &PyUnicode_Type); res = sym_new_type(ctx, &PyUnicode_Type);
}
stack_pointer[-2] = res;
stack_pointer += -1; stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS()); assert(WITHIN_STACK_BOUNDS());
}
stack_pointer[-1] = res;
break; break;
} }
@ -527,15 +548,17 @@
goto error; goto error;
} }
res = sym_new_const(ctx, temp); res = sym_new_const(ctx, temp);
stack_pointer += -2;
assert(WITHIN_STACK_BOUNDS());
Py_DECREF(temp); Py_DECREF(temp);
} }
else { else {
res = sym_new_type(ctx, &PyUnicode_Type); res = sym_new_type(ctx, &PyUnicode_Type);
stack_pointer += -2;
assert(WITHIN_STACK_BOUNDS());
} }
// _STORE_FAST: // _STORE_FAST:
GETLOCAL(this_instr->operand0) = res; GETLOCAL(this_instr->operand0) = res;
stack_pointer += -2;
assert(WITHIN_STACK_BOUNDS());
break; break;
} }

View file

@ -567,7 +567,6 @@ NON_ESCAPING_FUNCTIONS = (
"PyUnicode_READ_CHAR", "PyUnicode_READ_CHAR",
"Py_ARRAY_LENGTH", "Py_ARRAY_LENGTH",
"Py_CLEAR", "Py_CLEAR",
"Py_DECREF",
"Py_FatalError", "Py_FatalError",
"Py_INCREF", "Py_INCREF",
"Py_IS_TYPE", "Py_IS_TYPE",
@ -577,7 +576,6 @@ NON_ESCAPING_FUNCTIONS = (
"Py_TYPE", "Py_TYPE",
"Py_UNREACHABLE", "Py_UNREACHABLE",
"Py_Unicode_GET_LENGTH", "Py_Unicode_GET_LENGTH",
"Py_XDECREF",
"_PyCode_CODE", "_PyCode_CODE",
"_PyDictValues_AddToInsertionOrder", "_PyDictValues_AddToInsertionOrder",
"_PyErr_Occurred", "_PyErr_Occurred",
@ -620,7 +618,6 @@ NON_ESCAPING_FUNCTIONS = (
"_PyUnicode_JoinArray", "_PyUnicode_JoinArray",
"_Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY", "_Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY",
"_Py_DECREF_NO_DEALLOC", "_Py_DECREF_NO_DEALLOC",
"_Py_DECREF_SPECIALIZED",
"_Py_EnterRecursiveCallTstateUnchecked", "_Py_EnterRecursiveCallTstateUnchecked",
"_Py_ID", "_Py_ID",
"_Py_IsImmortal", "_Py_IsImmortal",

View file

@ -121,6 +121,7 @@ class Emitter:
"SAVE_STACK": self.save_stack, "SAVE_STACK": self.save_stack,
"RELOAD_STACK": self.reload_stack, "RELOAD_STACK": self.reload_stack,
"PyStackRef_CLOSE": self.stackref_close, "PyStackRef_CLOSE": self.stackref_close,
"PyStackRef_XCLOSE": self.stackref_close,
"PyStackRef_CLOSE_SPECIALIZED": self.stackref_close_specialized, "PyStackRef_CLOSE_SPECIALIZED": self.stackref_close_specialized,
"PyStackRef_AsPyObjectSteal": self.stackref_steal, "PyStackRef_AsPyObjectSteal": self.stackref_steal,
"DISPATCH": self.dispatch, "DISPATCH": self.dispatch,