diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index adec905df4f762..52f7d0d2b3df95 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -134,6 +134,33 @@ jobs: make all --jobs 4 ./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3 + no-opt-jit: + name: JIT without optimizations (Debug) + needs: interpreter + runs-on: ubuntu-24.04 + timeout-minutes: 90 + strategy: + fail-fast: false + matrix: + llvm: + - 19 + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + - name: Build with JIT + run: | + sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }} + export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH" + ./configure --enable-experimental-jit --with-pydebug + make all --jobs 4 + - name: Run tests without optimizations + run: | + PYTHON_UOPS_OPTIMIZE=0 ./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3 + # XXX: GH-133171 # jit-with-disabled-gil: # name: Free-Threaded (Debug) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index 199b64387266bf..4b8884f48e8b28 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -1834,6 +1834,10 @@ pointer and a void pointer argument. called from the main interpreter. Each subinterpreter now has its own list of scheduled calls. + .. versionchanged:: 3.12 + This function now always schedules *func* to be run in the main + interpreter. + .. _profiling: Profiling and Tracing diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 2e04fbb6f63fd3..b7fa365166d608 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1501,6 +1501,7 @@ or `the MSDN `_ on Windo - :data:`RWF_HIPRI` - :data:`RWF_NOWAIT` + - :data:`RWF_DONTCACHE` Return the total number of bytes actually read which can be less than the total capacity of all the objects. @@ -1546,6 +1547,15 @@ or `the MSDN `_ on Windo .. versionadded:: 3.7 +.. data:: RWF_DONTCACHE + + Use uncached buffered IO. + + .. availability:: Linux >= 6.14 + + .. versionadded:: next + + .. function:: ptsname(fd, /) Return the name of the slave pseudo-terminal device associated with the @@ -1587,6 +1597,7 @@ or `the MSDN `_ on Windo - :data:`RWF_DSYNC` - :data:`RWF_SYNC` - :data:`RWF_APPEND` + - :data:`RWF_DONTCACHE` Return the total number of bytes actually written. diff --git a/Doc/using/android.rst b/Doc/using/android.rst index cb762310328f1c..45345d045ddfd9 100644 --- a/Doc/using/android.rst +++ b/Doc/using/android.rst @@ -40,8 +40,15 @@ If you're sure you want to do all of this manually, read on. You can use the :source:`testbed app ` as a guide; each step below contains a link to the relevant file. -* Build Python by following the instructions in :source:`Android/README.md`. - This will create the directory ``cross-build/HOST/prefix``. +* First, acquire a build of Python for Android: + + * The easiest way is to download an Android release from `python.org + `__. The ``prefix`` directory + mentioned below is at the top level of the package. + + * Or if you want to build it yourself, follow the instructions in + :source:`Android/README.md`. The ``prefix`` directory will be created under + :samp:`cross-build/{HOST}`. * Add code to your :source:`build.gradle ` file to copy the following items into your project. All except your own Python diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index bd9d8aaefe5400..ac8798ff6129a0 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -107,6 +107,7 @@ struct _ts { # define _PyThreadState_WHENCE_THREADING 3 # define _PyThreadState_WHENCE_GILSTATE 4 # define _PyThreadState_WHENCE_EXEC 5 +# define _PyThreadState_WHENCE_THREADING_DAEMON 6 #endif /* Currently holds the GIL. Must be its own field to avoid data races */ diff --git a/Lib/_android_support.py b/Lib/_android_support.py index ae506f6a4b57b8..a439d03a144dd2 100644 --- a/Lib/_android_support.py +++ b/Lib/_android_support.py @@ -29,15 +29,19 @@ def init_streams(android_log_write, stdout_prio, stderr_prio): global logcat logcat = Logcat(android_log_write) - - sys.stdout = TextLogStream( - stdout_prio, "python.stdout", sys.stdout.fileno()) - sys.stderr = TextLogStream( - stderr_prio, "python.stderr", sys.stderr.fileno()) + sys.stdout = TextLogStream(stdout_prio, "python.stdout", sys.stdout) + sys.stderr = TextLogStream(stderr_prio, "python.stderr", sys.stderr) class TextLogStream(io.TextIOWrapper): - def __init__(self, prio, tag, fileno=None, **kwargs): + def __init__(self, prio, tag, original=None, **kwargs): + # Respect the -u option. + if original: + kwargs.setdefault("write_through", original.write_through) + fileno = original.fileno() + else: + fileno = None + # The default is surrogateescape for stdout and backslashreplace for # stderr, but in the context of an Android log, readability is more # important than reversibility. diff --git a/Lib/concurrent/interpreters/__init__.py b/Lib/concurrent/interpreters/__init__.py index aa46a2b37a48d5..ea4147ee9a25da 100644 --- a/Lib/concurrent/interpreters/__init__.py +++ b/Lib/concurrent/interpreters/__init__.py @@ -149,12 +149,17 @@ def __del__(self): def __reduce__(self): return (type(self), (self._id,)) - def _decref(self): + # gh-135729: Globals might be destroyed by the time this is called, so we + # need to keep references ourself + def _decref(self, *, + InterpreterNotFoundError=InterpreterNotFoundError, + _interp_decref=_interpreters.decref, + ): if not self._ownsref: return self._ownsref = False try: - _interpreters.decref(self._id) + _interp_decref(self._id) except InterpreterNotFoundError: pass diff --git a/Lib/test/test_android.py b/Lib/test/test_android.py index de83ce081c2790..c6c4a15a7ee34d 100644 --- a/Lib/test/test_android.py +++ b/Lib/test/test_android.py @@ -91,34 +91,38 @@ def tearDown(self): self.logcat_thread = None @contextmanager - def unbuffered(self, stream): - stream.reconfigure(write_through=True) + def reconfigure(self, stream, **settings): + original_settings = {key: getattr(stream, key, None) for key in settings.keys()} + stream.reconfigure(**settings) try: yield finally: - stream.reconfigure(write_through=False) + stream.reconfigure(**original_settings) - # In --verbose3 mode, sys.stdout and sys.stderr are captured, so we can't - # test them directly. Detect this mode and use some temporary streams with - # the same properties. def stream_context(self, stream_name, level): - # https://developer.android.com/ndk/reference/group/logging - prio = {"I": 4, "W": 5}[level] - stack = ExitStack() stack.enter_context(self.subTest(stream_name)) + + # In --verbose3 mode, sys.stdout and sys.stderr are captured, so we can't + # test them directly. Detect this mode and use some temporary streams with + # the same properties. stream = getattr(sys, stream_name) native_stream = getattr(sys, f"__{stream_name}__") if isinstance(stream, io.StringIO): + # https://developer.android.com/ndk/reference/group/logging + prio = {"I": 4, "W": 5}[level] stack.enter_context( patch( f"sys.{stream_name}", - TextLogStream( - prio, f"python.{stream_name}", native_stream.fileno(), - errors="backslashreplace" + stream := TextLogStream( + prio, f"python.{stream_name}", native_stream, ), ) ) + + # The tests assume the stream is initially buffered. + stack.enter_context(self.reconfigure(stream, write_through=False)) + return stack def test_str(self): @@ -145,7 +149,7 @@ def write(s, lines=None, *, write_len=None): self.assert_logs(level, tag, lines) # Single-line messages, - with self.unbuffered(stream): + with self.reconfigure(stream, write_through=True): write("", []) write("a") @@ -192,7 +196,7 @@ def write(s, lines=None, *, write_len=None): # However, buffering can be turned off completely if you want a # flush after every write. - with self.unbuffered(stream): + with self.reconfigure(stream, write_through=True): write("\nx", ["", "x"]) write("\na\n", ["", "a"]) write("\n", [""]) diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py index eb01da6e88a8bc..66142a108d5d93 100644 --- a/Lib/test/test_atexit.py +++ b/Lib/test/test_atexit.py @@ -79,6 +79,62 @@ def thready(): # want them to affect the rest of the tests. script_helper.assert_python_ok("-c", textwrap.dedent(source)) + @threading_helper.requires_working_threading() + def test_thread_created_in_atexit(self): + source = """if True: + import atexit + import threading + import time + + + def run(): + print(24) + time.sleep(1) + print(42) + + @atexit.register + def start_thread(): + threading.Thread(target=run).start() + """ + return_code, stdout, stderr = script_helper.assert_python_ok("-c", source) + self.assertEqual(return_code, 0) + self.assertEqual(stdout, f"24{os.linesep}42{os.linesep}".encode("utf-8")) + self.assertEqual(stderr, b"") + + @threading_helper.requires_working_threading() + @unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()") + def test_thread_created_in_atexit_subinterpreter(self): + try: + from concurrent import interpreters + except ImportError: + self.skipTest("subinterpreters are not available") + + read, write = os.pipe() + source = f"""if True: + import atexit + import threading + import time + import os + + def run(): + os.write({write}, b'spanish') + time.sleep(1) + os.write({write}, b'inquisition') + + @atexit.register + def start_thread(): + threading.Thread(target=run).start() + """ + interp = interpreters.create() + try: + interp.exec(source) + + # Close the interpreter to invoke atexit callbacks + interp.close() + self.assertEqual(os.read(read, 100), b"spanishinquisition") + finally: + os.close(read) + os.close(write) @support.cpython_only class SubinterpreterTest(unittest.TestCase): diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py index ef950f5df04ad3..fe1287167d3e74 100644 --- a/Lib/test/test_capi/test_misc.py +++ b/Lib/test/test_capi/test_misc.py @@ -22,6 +22,7 @@ from test import support from test.support import MISSING_C_DOCSTRINGS from test.support import import_helper +from test.support import script_helper from test.support import threading_helper from test.support import warnings_helper from test.support import requires_limited_api @@ -1641,6 +1642,36 @@ def subthread(): self.assertEqual(actual, int(interpid)) + @threading_helper.requires_working_threading() + def test_pending_call_creates_thread(self): + source = """ + import _testinternalcapi + import threading + import time + + + def output(): + print(24) + time.sleep(1) + print(42) + + + def callback(): + threading.Thread(target=output).start() + + + def create_pending_call(): + time.sleep(1) + _testinternalcapi.simple_pending_call(callback) + + + threading.Thread(target=create_pending_call).start() + """ + return_code, stdout, stderr = script_helper.assert_python_ok('-c', textwrap.dedent(source)) + self.assertEqual(return_code, 0) + self.assertEqual(stdout, f"24{os.linesep}42{os.linesep}".encode("utf-8")) + self.assertEqual(stderr, b"") + class SubinterpreterTest(unittest.TestCase): @@ -1949,6 +1980,41 @@ def test_module_state_shared_in_global(self): subinterp_attr_id = os.read(r, 100) self.assertEqual(main_attr_id, subinterp_attr_id) + @threading_helper.requires_working_threading() + @unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()") + @requires_subinterpreters + def test_pending_call_creates_thread_subinterpreter(self): + interpreters = import_helper.import_module("concurrent.interpreters") + r, w = os.pipe() + source = f"""if True: + import _testinternalcapi + import threading + import time + import os + + + def output(): + time.sleep(1) + os.write({w}, b"x") + + + def callback(): + threading.Thread(target=output).start() + + + def create_pending_call(): + time.sleep(1) + _testinternalcapi.simple_pending_call(callback) + + + threading.Thread(target=create_pending_call).start() + """ + interp = interpreters.create() + interp.exec(source) + interp.close() + data = os.read(r, 1) + self.assertEqual(data, b"x") + @requires_subinterpreters class InterpreterConfigTests(unittest.TestCase): diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 2cc1aaea0ecbe7..d54dd546ea36fb 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -357,6 +357,32 @@ def test_vararg_after_star(self): """ self.expect_failure(block, err, lineno=6) + def test_double_star_after_var_keyword(self): + err = "Function 'my_test_func' has an invalid parameter declaration (**kwargs?): '**kwds: dict'" + block = """ + /*[clinic input] + my_test_func + + pos_arg: object + **kwds: dict + ** + [clinic start generated code]*/ + """ + self.expect_failure(block, err, lineno=5) + + def test_var_keyword_after_star(self): + err = "Function 'my_test_func' has an invalid parameter declaration: '**'" + block = """ + /*[clinic input] + my_test_func + + pos_arg: object + ** + **kwds: dict + [clinic start generated code]*/ + """ + self.expect_failure(block, err, lineno=5) + def test_module_already_got_one(self): err = "Already defined module 'm'!" block = """ @@ -748,6 +774,16 @@ def test_ignore_preprocessor_in_comments(self): """) self.clinic.parse(raw) + def test_var_keyword_non_dict(self): + err = "'var_keyword_object' is not a valid converter" + block = """ + /*[clinic input] + my_test_func + + **kwds: object + [clinic start generated code]*/ + """ + self.expect_failure(block, err, lineno=4) class ParseFileUnitTest(TestCase): def expect_parsing_failure( @@ -1608,6 +1644,11 @@ def test_disallowed_grouping__must_be_position_only(self): [ a: object ] + """, """ + with_kwds + [ + **kwds: dict + ] """) err = ( "You cannot use optional groups ('[' and ']') unless all " @@ -1991,6 +2032,44 @@ def test_slash_after_vararg(self): err = "Function 'bar': '/' must precede '*'" self.expect_failure(block, err) + def test_slash_after_var_keyword(self): + block = """ + module foo + foo.bar + x: int + y: int + **kwds: dict + z: int + / + """ + err = "Function 'bar' has an invalid parameter declaration (**kwargs?): '**kwds: dict'" + self.expect_failure(block, err) + + def test_star_after_var_keyword(self): + block = """ + module foo + foo.bar + x: int + y: int + **kwds: dict + z: int + * + """ + err = "Function 'bar' has an invalid parameter declaration (**kwargs?): '**kwds: dict'" + self.expect_failure(block, err) + + def test_parameter_after_var_keyword(self): + block = """ + module foo + foo.bar + x: int + y: int + **kwds: dict + z: int + """ + err = "Function 'bar' has an invalid parameter declaration (**kwargs?): '**kwds: dict'" + self.expect_failure(block, err) + def test_depr_star_must_come_after_slash(self): block = """ module foo @@ -2079,6 +2158,16 @@ def test_parameters_no_more_than_one_vararg(self): """ self.expect_failure(block, err, lineno=3) + def test_parameters_no_more_than_one_var_keyword(self): + err = "Encountered parameter line when not expecting parameters: **var_keyword_2: dict" + block = """ + module foo + foo.bar + **var_keyword_1: dict + **var_keyword_2: dict + """ + self.expect_failure(block, err, lineno=3) + def test_function_not_at_column_0(self): function = self.parse_function(""" module foo @@ -2513,6 +2602,14 @@ def test_vararg_cannot_take_default_value(self): """ self.expect_failure(block, err, lineno=1) + def test_var_keyword_cannot_take_default_value(self): + err = "Function 'fn' has an invalid parameter declaration:" + block = """ + fn + **kwds: dict = None + """ + self.expect_failure(block, err, lineno=1) + def test_default_is_not_of_correct_type(self): err = ("int_converter: default value 2.5 for field 'a' " "is not of type 'int'") @@ -2610,6 +2707,43 @@ def test_disallow_defining_class_at_module_level(self): """ self.expect_failure(block, err, lineno=2) + def test_var_keyword_with_pos_or_kw(self): + block = """ + module foo + foo.bar + x: int + **kwds: dict + """ + err = "Function 'bar' has an invalid parameter declaration (**kwargs?): '**kwds: dict'" + self.expect_failure(block, err) + + def test_var_keyword_with_kw_only(self): + block = """ + module foo + foo.bar + x: int + / + * + y: int + **kwds: dict + """ + err = "Function 'bar' has an invalid parameter declaration (**kwargs?): '**kwds: dict'" + self.expect_failure(block, err) + + def test_var_keyword_with_pos_or_kw_and_kw_only(self): + block = """ + module foo + foo.bar + x: int + / + y: int + * + z: int + **kwds: dict + """ + err = "Function 'bar' has an invalid parameter declaration (**kwargs?): '**kwds: dict'" + self.expect_failure(block, err) + def test_allow_negative_accepted_by_py_ssize_t_converter_only(self): errmsg = re.escape("converter_init() got an unexpected keyword argument 'allow_negative'") unsupported_converters = [converter_name for converter_name in converters.keys() @@ -3954,6 +4088,49 @@ def test_depr_multi(self): check("a", b="b", c="c", d="d", e="e", f="f", g="g") self.assertRaises(TypeError, fn, a="a", b="b", c="c", d="d", e="e", f="f", g="g") + def test_lone_kwds(self): + with self.assertRaises(TypeError): + ac_tester.lone_kwds(1, 2) + self.assertEqual(ac_tester.lone_kwds(), ({},)) + self.assertEqual(ac_tester.lone_kwds(y='y'), ({'y': 'y'},)) + kwds = {'y': 'y', 'z': 'z'} + self.assertEqual(ac_tester.lone_kwds(y='y', z='z'), (kwds,)) + self.assertEqual(ac_tester.lone_kwds(**kwds), (kwds,)) + + def test_kwds_with_pos_only(self): + with self.assertRaises(TypeError): + ac_tester.kwds_with_pos_only() + with self.assertRaises(TypeError): + ac_tester.kwds_with_pos_only(y='y') + with self.assertRaises(TypeError): + ac_tester.kwds_with_pos_only(1, y='y') + self.assertEqual(ac_tester.kwds_with_pos_only(1, 2), (1, 2, {})) + self.assertEqual(ac_tester.kwds_with_pos_only(1, 2, y='y'), (1, 2, {'y': 'y'})) + kwds = {'y': 'y', 'z': 'z'} + self.assertEqual(ac_tester.kwds_with_pos_only(1, 2, y='y', z='z'), (1, 2, kwds)) + self.assertEqual(ac_tester.kwds_with_pos_only(1, 2, **kwds), (1, 2, kwds)) + + def test_kwds_with_stararg(self): + self.assertEqual(ac_tester.kwds_with_stararg(), ((), {})) + self.assertEqual(ac_tester.kwds_with_stararg(1, 2), ((1, 2), {})) + self.assertEqual(ac_tester.kwds_with_stararg(y='y'), ((), {'y': 'y'})) + args = (1, 2) + kwds = {'y': 'y', 'z': 'z'} + self.assertEqual(ac_tester.kwds_with_stararg(1, 2, y='y', z='z'), (args, kwds)) + self.assertEqual(ac_tester.kwds_with_stararg(*args, **kwds), (args, kwds)) + + def test_kwds_with_pos_only_and_stararg(self): + with self.assertRaises(TypeError): + ac_tester.kwds_with_pos_only_and_stararg() + with self.assertRaises(TypeError): + ac_tester.kwds_with_pos_only_and_stararg(y='y') + self.assertEqual(ac_tester.kwds_with_pos_only_and_stararg(1, 2), (1, 2, (), {})) + self.assertEqual(ac_tester.kwds_with_pos_only_and_stararg(1, 2, y='y'), (1, 2, (), {'y': 'y'})) + args = ('lobster', 'thermidor') + kwds = {'y': 'y', 'z': 'z'} + self.assertEqual(ac_tester.kwds_with_pos_only_and_stararg(1, 2, 'lobster', 'thermidor', y='y', z='z'), (1, 2, args, kwds)) + self.assertEqual(ac_tester.kwds_with_pos_only_and_stararg(1, 2, *args, **kwds), (1, 2, args, kwds)) + class LimitedCAPIOutputTests(unittest.TestCase): diff --git a/Lib/test/test_generated_cases.py b/Lib/test/test_generated_cases.py index 6e0e2eafd3281c..09ce329bdcd14d 100644 --- a/Lib/test/test_generated_cases.py +++ b/Lib/test/test_generated_cases.py @@ -132,7 +132,7 @@ def test_inst_no_args(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -154,7 +154,7 @@ def test_inst_one_pop(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -179,7 +179,7 @@ def test_inst_one_push(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -205,7 +205,7 @@ def test_inst_one_push_one_pop(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -232,7 +232,7 @@ def test_binary_op(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -262,7 +262,7 @@ def test_overlap(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -296,7 +296,7 @@ def test_predictions(self): """ output = """ TARGET(OP1) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP1; (void)(opcode); #endif @@ -313,7 +313,7 @@ def test_predictions(self): } TARGET(OP3) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP3; (void)(opcode); #endif @@ -355,7 +355,7 @@ def test_sync_sp(self): """ output = """ TARGET(A) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = A; (void)(opcode); #endif @@ -378,7 +378,7 @@ def test_sync_sp(self): } TARGET(B) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = B; (void)(opcode); #endif @@ -421,7 +421,7 @@ def test_error_if_plain(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -444,7 +444,7 @@ def test_error_if_plain_with_comment(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -470,7 +470,7 @@ def test_error_if_pop(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -505,7 +505,7 @@ def test_error_if_pop_with_result(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -537,7 +537,7 @@ def test_cache_effect(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -570,7 +570,7 @@ def test_suppress_dispatch(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -604,7 +604,7 @@ def test_macro_instruction(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -645,7 +645,7 @@ def test_macro_instruction(self): } TARGET(OP1) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP1; (void)(opcode); #endif @@ -667,7 +667,7 @@ def test_macro_instruction(self): } TARGET(OP3) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP3; (void)(opcode); #endif @@ -702,7 +702,7 @@ def test_unused_caches(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -728,7 +728,7 @@ def test_pseudo_instruction_no_flags(self): """ output = """ TARGET(OP1) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP1; (void)(opcode); #endif @@ -751,7 +751,7 @@ def test_pseudo_instruction_with_flags(self): """ output = """ TARGET(OP1) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP1; (void)(opcode); #endif @@ -777,7 +777,7 @@ def test_pseudo_instruction_as_sequence(self): """ output = """ TARGET(OP1) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP1; (void)(opcode); #endif @@ -788,7 +788,7 @@ def test_pseudo_instruction_as_sequence(self): } TARGET(OP2) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP2; (void)(opcode); #endif @@ -812,7 +812,7 @@ def test_array_input(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -843,7 +843,7 @@ def test_array_output(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -875,7 +875,7 @@ def test_array_input_output(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -905,7 +905,7 @@ def test_array_error_if(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -940,7 +940,7 @@ def test_macro_push_push(self): """ output = """ TARGET(M) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = M; (void)(opcode); #endif @@ -977,7 +977,7 @@ def test_override_inst(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -1002,7 +1002,7 @@ def test_override_op(self): """ output = """ TARGET(M) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = M; (void)(opcode); #endif @@ -1023,7 +1023,7 @@ def test_annotated_inst(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -1045,7 +1045,7 @@ def test_annotated_op(self): """ output = """ TARGET(M) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = M; (void)(opcode); #endif @@ -1086,7 +1086,7 @@ def test_array_of_one(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -1128,7 +1128,7 @@ def test_unused_named_values(self): """ output = """ TARGET(INST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INST; (void)(opcode); #endif @@ -1158,7 +1158,7 @@ def test_used_unused_used(self): """ output = """ TARGET(TEST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = TEST; (void)(opcode); #endif @@ -1202,7 +1202,7 @@ def test_unused_used_used(self): """ output = """ TARGET(TEST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = TEST; (void)(opcode); #endif @@ -1245,7 +1245,7 @@ def test_flush(self): """ output = """ TARGET(TEST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = TEST; (void)(opcode); #endif @@ -1297,7 +1297,7 @@ def test_pop_on_error_peeks(self): """ output = """ TARGET(TEST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = TEST; (void)(opcode); #endif @@ -1348,7 +1348,7 @@ def test_push_then_error(self): output = """ TARGET(TEST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = TEST; (void)(opcode); #endif @@ -1393,7 +1393,7 @@ def test_error_if_true(self): """ output = """ TARGET(OP1) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP1; (void)(opcode); #endif @@ -1404,7 +1404,7 @@ def test_error_if_true(self): } TARGET(OP2) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP2; (void)(opcode); #endif @@ -1466,7 +1466,7 @@ def test_stack_save_reload(self): output = """ TARGET(BALANCED) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BALANCED; (void)(opcode); #endif @@ -1492,7 +1492,7 @@ def test_stack_save_reload_paired(self): output = """ TARGET(BALANCED) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BALANCED; (void)(opcode); #endif @@ -1514,7 +1514,7 @@ def test_stack_reload_only(self): output = """ TARGET(BALANCED) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BALANCED; (void)(opcode); #endif @@ -1539,7 +1539,7 @@ def test_stack_save_only(self): output = """ TARGET(BALANCED) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BALANCED; (void)(opcode); #endif @@ -1565,7 +1565,7 @@ def test_instruction_size_macro(self): output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -1604,7 +1604,7 @@ def test_escaping_call_next_to_cmacro(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -1642,7 +1642,7 @@ def test_pystackref_frompyobject_new_next_to_cmacro(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -1840,7 +1840,7 @@ def test_reassigning_live_inputs(self): output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif @@ -1867,7 +1867,7 @@ def test_reassigning_dead_inputs(self): """ output = """ TARGET(OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = OP; (void)(opcode); #endif diff --git a/Lib/test/test_interpreters/test_api.py b/Lib/test/test_interpreters/test_api.py index 3fee98ea93e637..1f38a43be51e7a 100644 --- a/Lib/test/test_interpreters/test_api.py +++ b/Lib/test/test_interpreters/test_api.py @@ -419,6 +419,22 @@ def test_pickle(self): unpickled = pickle.loads(data) self.assertEqual(unpickled, interp) + @support.requires_subprocess() + @force_not_colorized + def test_cleanup_in_repl(self): + # GH-135729: Using a subinterpreter in the REPL would lead to an unraisable + # exception during finalization + repl = script_helper.spawn_python("-i") + script = b"""if True: + from concurrent import interpreters + interpreters.create() + exit()""" + stdout, stderr = repl.communicate(script) + self.assertIsNone(stderr) + self.assertIn(b"remaining subinterpreters", stdout) + self.assertNotIn(b"Traceback", stdout) + + class TestInterpreterIsRunning(TestBase): diff --git a/Lib/test/test_io/test_general.py b/Lib/test/test_io/test_general.py index c2f0e1877a6901..b9abea71e01f0b 100644 --- a/Lib/test/test_io/test_general.py +++ b/Lib/test/test_io/test_general.py @@ -1980,6 +1980,10 @@ def test_readinto(self): self.assertEqual(getattr(pair, method)(data), 5) self.assertEqual(bytes(data), b"abcde") + # gh-138720: C BufferedRWPair would destruct in a bad order resulting in + # an unraisable exception. + support.gc_collect() + def test_write(self): w = self.MockRawIO() pair = self.tp(self.MockRawIO(), w) diff --git a/Lib/test/test_peg_generator/test_pegen.py b/Lib/test/test_peg_generator/test_pegen.py index 0387b9395611b0..d03ba07975a616 100644 --- a/Lib/test/test_peg_generator/test_pegen.py +++ b/Lib/test/test_peg_generator/test_pegen.py @@ -1131,24 +1131,28 @@ def test_rule_flags(self) -> None: # Test memo-only rule simple_rule = rules['simple_rule'] - self.assertTrue(simple_rule.memo, "simple_rule should have memo=True") + self.assertTrue('memo' in simple_rule.flags, + "simple_rule should have memo") self.assertEqual(simple_rule.flags, frozenset(['memo']), f"simple_rule flags should be {'memo'}, got {simple_rule.flags}") # Test multi-flag rule multi_flag_rule = rules['multi_flag_rule'] - self.assertTrue(multi_flag_rule.memo, "multi_flag_rule should have memo=True") + self.assertTrue('memo' in simple_rule.flags, + "multi_flag_rule should have memo") self.assertEqual(multi_flag_rule.flags, frozenset({'memo', 'custom', 'test'}), f"multi_flag_rule flags should contain memo, custom, test, got {multi_flag_rule.flags}") # Test single custom flag rule single_custom_rule = rules['single_custom_flag'] - self.assertFalse(single_custom_rule.memo, "single_custom_flag should have memo=False") + self.assertFalse('memo' not in simple_rule.flags, + "single_custom_flag should not have memo") self.assertEqual(single_custom_rule.flags, frozenset(['custom']), f"single_custom_flag flags should be {'custom'}, got {single_custom_rule.flags}") # Test no flags rule no_flags_rule = rules['no_flags_rule'] - self.assertFalse(no_flags_rule.memo, "no_flags_rule should have memo=False") - self.assertEqual(no_flags_rule.flags, [], + self.assertFalse('memo' not in simple_rule.flags, + "no_flags_rule should not have memo") + self.assertEqual(no_flags_rule.flags, frozenset(), f"no_flags_rule flags should be the empty set, got {no_flags_rule.flags}") diff --git a/Lib/threading.py b/Lib/threading.py index b3e24fe7ddaa0c..fac88d8b20c60d 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -1557,8 +1557,9 @@ def _shutdown(): # normally - that won't happen until the interpreter is nearly dead. So # mark it done here. if _main_thread._os_thread_handle.is_done() and _is_main_interpreter(): - # _shutdown() was already called - return + # _shutdown() was already called, but threads might have started + # in the meantime. + return _thread_shutdown() global _SHUTTING_DOWN _SHUTTING_DOWN = True diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-06-26-18-44-34.gh-issue-136003.sln51d.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-06-26-18-44-34.gh-issue-136003.sln51d.rst new file mode 100644 index 00000000000000..a1344d2264f665 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-06-26-18-44-34.gh-issue-136003.sln51d.rst @@ -0,0 +1,3 @@ +Fix :class:`threading.Thread` objects becoming incorrectly daemon when +created from an :mod:`atexit` callback or a pending call +(:c:func:`Py_AddPendingCall`). diff --git a/Misc/NEWS.d/next/Library/2025-09-09-17-57-49.gh-issue-138720.hAtsm-.rst b/Misc/NEWS.d/next/Library/2025-09-09-17-57-49.gh-issue-138720.hAtsm-.rst new file mode 100644 index 00000000000000..4f3f54e1deb89f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-09-09-17-57-49.gh-issue-138720.hAtsm-.rst @@ -0,0 +1,4 @@ +Fix an issue where :class:`io.BufferedWriter` and :class:`io.BufferedRandom` +had different definitions of "closed" for :meth:`~io.IOBase.close` and +:meth:`~io.IOBase.flush` which resulted in an exception when close called +flush but flush thought the file was already closed. diff --git a/Misc/NEWS.d/next/Library/2025-09-17-21-52-30.gh-issue-139090.W7vbhF.rst b/Misc/NEWS.d/next/Library/2025-09-17-21-52-30.gh-issue-139090.W7vbhF.rst new file mode 100644 index 00000000000000..129914abb10168 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-09-17-21-52-30.gh-issue-139090.W7vbhF.rst @@ -0,0 +1 @@ +Add :data:`os.RWF_DONTCACHE` constant for Linux 6.14+. diff --git a/Misc/NEWS.d/next/Library/2025-09-18-05-32-18.gh-issue-135729.8AmMza.rst b/Misc/NEWS.d/next/Library/2025-09-18-05-32-18.gh-issue-135729.8AmMza.rst new file mode 100644 index 00000000000000..1777839a1bf633 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-09-18-05-32-18.gh-issue-135729.8AmMza.rst @@ -0,0 +1,2 @@ +Fix unraisable exception during finalization when using +:mod:`concurrent.interpreters` in the REPL. diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index 50994be2968d35..0696c150cd42fb 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -1007,16 +1007,19 @@ context_setemax(PyObject *self, PyObject *value, void *Py_UNUSED(closure)) } #ifdef CONFIG_32 +/*[clinic input] +_decimal.Context._unsafe_setprec + + x: Py_ssize_t + / + +[clinic start generated code]*/ + static PyObject * -context_unsafe_setprec(PyObject *self, PyObject *value) +_decimal_Context__unsafe_setprec_impl(PyObject *self, Py_ssize_t x) +/*[clinic end generated code: output=dd838edf08e12dd9 input=23a1b19ceb1569be]*/ { mpd_context_t *ctx = CTX(self); - mpd_ssize_t x; - - x = PyLong_AsSsize_t(value); - if (x == -1 && PyErr_Occurred()) { - return NULL; - } if (x < 1 || x > 1070000000L) { return value_error_ptr( @@ -1027,16 +1030,19 @@ context_unsafe_setprec(PyObject *self, PyObject *value) Py_RETURN_NONE; } +/*[clinic input] +_decimal.Context._unsafe_setemin + + x: Py_ssize_t + / + +[clinic start generated code]*/ + static PyObject * -context_unsafe_setemin(PyObject *self, PyObject *value) +_decimal_Context__unsafe_setemin_impl(PyObject *self, Py_ssize_t x) +/*[clinic end generated code: output=0c49cafee8a65846 input=652f1ecacca7e0ce]*/ { mpd_context_t *ctx = CTX(self); - mpd_ssize_t x; - - x = PyLong_AsSsize_t(value); - if (x == -1 && PyErr_Occurred()) { - return NULL; - } if (x < -1070000000L || x > 0) { return value_error_ptr( @@ -1047,16 +1053,19 @@ context_unsafe_setemin(PyObject *self, PyObject *value) Py_RETURN_NONE; } +/*[clinic input] +_decimal.Context._unsafe_setemax + + x: Py_ssize_t + / + +[clinic start generated code]*/ + static PyObject * -context_unsafe_setemax(PyObject *self, PyObject *value) +_decimal_Context__unsafe_setemax_impl(PyObject *self, Py_ssize_t x) +/*[clinic end generated code: output=776563e0377a00e8 input=b2a32a9a2750e7a8]*/ { mpd_context_t *ctx = CTX(self); - mpd_ssize_t x; - - x = PyLong_AsSsize_t(value); - if (x == -1 && PyErr_Occurred()) { - return NULL; - } if (x < 0 || x > 1070000000L) { return value_error_ptr( @@ -1641,45 +1650,68 @@ _decimal_IEEEContext_impl(PyObject *module, Py_ssize_t bits) return NULL; } -/*[clinic input] -_decimal.Context.copy - -Return a duplicate of the context with all flags cleared. -[clinic start generated code]*/ - static PyObject * -_decimal_Context_copy_impl(PyObject *self) -/*[clinic end generated code: output=f99649a60a9c10f8 input=2589aa46b77cbc28]*/ +context_copy(decimal_state *state, PyObject *v) { - PyObject *copy; + PyObject *copy = + PyObject_CallObject((PyObject *)state->PyDecContext_Type, NULL); - decimal_state *state = get_module_state_from_ctx(self); - copy = PyObject_CallObject((PyObject *)state->PyDecContext_Type, NULL); if (copy == NULL) { return NULL; } - *CTX(copy) = *CTX(self); + *CTX(copy) = *CTX(v); CTX(copy)->newtrap = 0; - CtxCaps(copy) = CtxCaps(self); + CtxCaps(copy) = CtxCaps(v); return copy; } +/*[clinic input] +_decimal.Context.copy + + cls: defining_class + +Return a duplicate of the context with all flags cleared. +[clinic start generated code]*/ + +static PyObject * +_decimal_Context_copy_impl(PyObject *self, PyTypeObject *cls) +/*[clinic end generated code: output=31c9c8eeb0c0cf77 input=aef1c0bddabdf8f0]*/ +{ + decimal_state *state = PyType_GetModuleState(cls); + + return context_copy(state, self); +} + +/*[clinic input] +_decimal.Context.__copy__ = _decimal.Context.copy + +[clinic start generated code]*/ + static PyObject * -context_copy(PyObject *self, PyObject *Py_UNUSED(dummy)) +_decimal_Context___copy___impl(PyObject *self, PyTypeObject *cls) +/*[clinic end generated code: output=93552486e5fb0ab4 input=4a55dd22f6d31bcc]*/ { - return _decimal_Context_copy_impl(self); + decimal_state *state = PyType_GetModuleState(cls); + + return context_copy(state, self); } +/*[clinic input] +_decimal.Context.__reduce__ = _decimal.Context.copy + +[clinic start generated code]*/ + static PyObject * -context_reduce(PyObject *self, PyObject *Py_UNUSED(dummy)) +_decimal_Context___reduce___impl(PyObject *self, PyTypeObject *cls) +/*[clinic end generated code: output=4e77de55efdbb56a input=787683f13d047ce8]*/ { PyObject *flags; PyObject *traps; PyObject *ret; mpd_context_t *ctx; - decimal_state *state = get_module_state_from_ctx(self); + decimal_state *state = PyType_GetModuleState(cls); ctx = CTX(self); @@ -1782,7 +1814,7 @@ current_context_from_dict(decimal_state *modstate) } /* Set up a new thread local context. */ - tl_context = context_copy(modstate->default_context_template, NULL); + tl_context = context_copy(modstate, modstate->default_context_template); if (tl_context == NULL) { return NULL; } @@ -1858,7 +1890,7 @@ PyDec_SetCurrentContext(PyObject *self, PyObject *v) if (v == state->default_context_template || v == state->basic_context_template || v == state->extended_context_template) { - v = context_copy(v, NULL); + v = context_copy(state, v); if (v == NULL) { return NULL; } @@ -1881,7 +1913,7 @@ PyDec_SetCurrentContext(PyObject *self, PyObject *v) static PyObject * init_current_context(decimal_state *state) { - PyObject *tl_context = context_copy(state->default_context_template, NULL); + PyObject *tl_context = context_copy(state, state->default_context_template); if (tl_context == NULL) { return NULL; } @@ -1942,7 +1974,7 @@ PyDec_SetCurrentContext(PyObject *self, PyObject *v) if (v == state->default_context_template || v == state->basic_context_template || v == state->extended_context_template) { - v = context_copy(v, NULL); + v = context_copy(state, v); if (v == NULL) { return NULL; } @@ -2039,7 +2071,7 @@ _decimal_localcontext_impl(PyObject *module, PyObject *local, PyObject *prec, return NULL; } - PyObject *local_copy = context_copy(local, NULL); + PyObject *local_copy = context_copy(state, local); if (local_copy == NULL) { return NULL; } @@ -2964,6 +2996,7 @@ PyDecType_FromSequenceExact(PyTypeObject *type, PyObject *v, @classmethod _decimal.Decimal.from_float + cls: defining_class f as pyfloat: object / @@ -2983,13 +3016,14 @@ Decimal.from_float(0.1) is not the same as Decimal('0.1'). [clinic start generated code]*/ static PyObject * -_decimal_Decimal_from_float_impl(PyTypeObject *type, PyObject *pyfloat) -/*[clinic end generated code: output=e62775271ac469e6 input=052036648342f8c8]*/ +_decimal_Decimal_from_float_impl(PyTypeObject *type, PyTypeObject *cls, + PyObject *pyfloat) +/*[clinic end generated code: output=fcb7d55d2f9dc790 input=03bc8dbe963e52ca]*/ { PyObject *context; PyObject *result; - decimal_state *state = get_module_state_by_def(type); + decimal_state *state = PyType_GetModuleState(cls); CURRENT_CONTEXT(state, context); result = PyDecType_FromFloatExact(state->PyDec_Type, pyfloat, context); if (type != state->PyDec_Type && result != NULL) { @@ -3004,9 +3038,10 @@ _decimal_Decimal_from_float_impl(PyTypeObject *type, PyObject *pyfloat) an exact conversion. If the result does not meet the restrictions for an mpd_t, fail with InvalidOperation. */ static PyObject * -PyDecType_FromNumberExact(PyTypeObject *type, PyObject *v, PyObject *context) +PyDecType_FromNumberExact(PyTypeObject *type, PyTypeObject *cls, + PyObject *v, PyObject *context) { - decimal_state *state = get_module_state_by_def(type); + decimal_state *state = PyType_GetModuleState(cls); assert(v != NULL); if (PyDec_Check(state, v)) { return PyDecType_FromDecimalExact(type, v, context); @@ -3032,6 +3067,7 @@ PyDecType_FromNumberExact(PyTypeObject *type, PyObject *v, PyObject *context) @classmethod _decimal.Decimal.from_number + cls: defining_class number: object / @@ -3046,15 +3082,16 @@ Class method that converts a real number to a decimal number, exactly. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_from_number_impl(PyTypeObject *type, PyObject *number) -/*[clinic end generated code: output=41885304e5beea0a input=c58b678e8916f66b]*/ +_decimal_Decimal_from_number_impl(PyTypeObject *type, PyTypeObject *cls, + PyObject *number) +/*[clinic end generated code: output=4d3ec722b7acfd8b input=271cb4feb3148804]*/ { PyObject *context; PyObject *result; - decimal_state *state = get_module_state_by_def(type); + decimal_state *state = PyType_GetModuleState(cls); CURRENT_CONTEXT(state, context); - result = PyDecType_FromNumberExact(state->PyDec_Type, number, context); + result = PyDecType_FromNumberExact(state->PyDec_Type, cls, number, context); if (type != state->PyDec_Type && result != NULL) { Py_SETREF(result, PyObject_CallFunctionObjArgs((PyObject *)type, result, NULL)); @@ -3069,6 +3106,7 @@ _decimal_Decimal_from_number_impl(PyTypeObject *type, PyObject *number) _decimal.Context.create_decimal_from_float self as context: self + cls: defining_class f: object / @@ -3079,10 +3117,12 @@ the context limits. [clinic start generated code]*/ static PyObject * -_decimal_Context_create_decimal_from_float(PyObject *context, PyObject *f) -/*[clinic end generated code: output=c660c343f6f7158b input=05a8c54b7a5b457b]*/ +_decimal_Context_create_decimal_from_float_impl(PyObject *context, + PyTypeObject *cls, + PyObject *f) +/*[clinic end generated code: output=a5548f5140fa0870 input=8c66eeb22b01ddd4]*/ { - decimal_state *state = get_module_state_from_ctx(context); + decimal_state *state = PyType_GetModuleState(cls); return PyDec_FromFloat(state, f, context); } @@ -3688,6 +3728,7 @@ pydec_format(PyObject *dec, PyObject *context, PyObject *fmt, decimal_state *sta _decimal.Decimal.__format__ self as dec: self + cls: defining_class format_spec as fmtarg: unicode override: object = NULL / @@ -3696,9 +3737,9 @@ Formats the Decimal according to format_spec. [clinic start generated code]*/ static PyObject * -_decimal_Decimal___format___impl(PyObject *dec, PyObject *fmtarg, - PyObject *override) -/*[clinic end generated code: output=4b3640b7f0c8b6a5 input=e53488e49a0fff00]*/ +_decimal_Decimal___format___impl(PyObject *dec, PyTypeObject *cls, + PyObject *fmtarg, PyObject *override) +/*[clinic end generated code: output=6d95f91bbb28b3ed input=2dbfaa0cbe243e9e]*/ { PyObject *result = NULL; PyObject *dot = NULL; @@ -3711,7 +3752,7 @@ _decimal_Decimal___format___impl(PyObject *dec, PyObject *fmtarg, uint32_t status = 0; int replace_fillchar = 0; Py_ssize_t size; - decimal_state *state = get_module_state_by_def(Py_TYPE(dec)); + decimal_state *state = PyType_GetModuleState(cls); CURRENT_CONTEXT(state, context); fmt = (char *)PyUnicode_AsUTF8AndSize(fmtarg, &size); if (fmt == NULL) { @@ -3915,6 +3956,8 @@ dec_as_long(PyObject *dec, PyObject *context, int round) /*[clinic input] _decimal.Decimal.as_integer_ratio + cls: defining_class + Return a pair of integers whose ratio is exactly equal to the original. The ratio is in lowest terms and with a positive denominator. @@ -3922,8 +3965,8 @@ Raise OverflowError on infinities and a ValueError on NaNs. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_as_integer_ratio_impl(PyObject *self) -/*[clinic end generated code: output=c5d88e900080c264 input=7861cb643f01525a]*/ +_decimal_Decimal_as_integer_ratio_impl(PyObject *self, PyTypeObject *cls) +/*[clinic end generated code: output=eb49c512701f844b input=07e33d8852184761]*/ { PyObject *numerator = NULL; PyObject *denominator = NULL; @@ -3946,7 +3989,7 @@ _decimal_Decimal_as_integer_ratio_impl(PyObject *self) return NULL; } - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); CURRENT_CONTEXT(state, context); tmp = dec_alloc(state); @@ -4028,6 +4071,7 @@ _decimal_Decimal_as_integer_ratio_impl(PyObject *self) /*[clinic input] _decimal.Decimal.to_integral_value + cls: defining_class rounding: object = None context: object = None @@ -4039,15 +4083,16 @@ rounding mode of the current default context is used. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_to_integral_value_impl(PyObject *self, PyObject *rounding, +_decimal_Decimal_to_integral_value_impl(PyObject *self, PyTypeObject *cls, + PyObject *rounding, PyObject *context) -/*[clinic end generated code: output=7301465765f48b6b input=04e2312d5ed19f77]*/ +/*[clinic end generated code: output=23047d848ef84db1 input=85aa9499a21ea8d7]*/ { PyObject *result; uint32_t status = 0; mpd_context_t workctx; - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); CONTEXT_CHECK_VA(state, context); workctx = *CTX(context); @@ -4085,11 +4130,12 @@ versions. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_to_integral_impl(PyObject *self, PyObject *rounding, - PyObject *context) -/*[clinic end generated code: output=a0c7188686ee7f5c input=709b54618ecd0d8b]*/ +_decimal_Decimal_to_integral_impl(PyObject *self, PyTypeObject *cls, + PyObject *rounding, PyObject *context) +/*[clinic end generated code: output=5dac8f54c2a3ed26 input=709b54618ecd0d8b]*/ { - return _decimal_Decimal_to_integral_value_impl(self, rounding, context); + return _decimal_Decimal_to_integral_value_impl(self, cls, rounding, + context); } /*[clinic input] @@ -4104,15 +4150,16 @@ given, then the rounding mode of the current default context is used. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_to_integral_exact_impl(PyObject *self, PyObject *rounding, +_decimal_Decimal_to_integral_exact_impl(PyObject *self, PyTypeObject *cls, + PyObject *rounding, PyObject *context) -/*[clinic end generated code: output=8b004f9b45ac7746 input=fabce7a744b8087c]*/ +/*[clinic end generated code: output=543a39a02eea9917 input=fabce7a744b8087c]*/ { PyObject *result; uint32_t status = 0; mpd_context_t workctx; - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); CONTEXT_CHECK_VA(state, context); workctx = *CTX(context); @@ -4175,6 +4222,7 @@ PyDec_AsFloat(PyObject *dec) /*[clinic input] _decimal.Decimal.__round__ + cls: defining_class ndigits: object = NULL / @@ -4182,13 +4230,14 @@ Return the Integral closest to self, rounding half toward even. [clinic start generated code]*/ static PyObject * -_decimal_Decimal___round___impl(PyObject *self, PyObject *ndigits) -/*[clinic end generated code: output=ca6b3570a8df0c91 input=dc72084114f59380]*/ +_decimal_Decimal___round___impl(PyObject *self, PyTypeObject *cls, + PyObject *ndigits) +/*[clinic end generated code: output=790c2c6bd57890e6 input=d69e7178a58a66b1]*/ { PyObject *result; uint32_t status = 0; PyObject *context; - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); CURRENT_CONTEXT(state, context); if (ndigits) { mpd_uint_t dq[1] = {1}; @@ -4227,12 +4276,14 @@ _decimal_Decimal___round___impl(PyObject *self, PyObject *ndigits) /*[clinic input] _decimal.Decimal.as_tuple + cls: defining_class + Return a tuple representation of the number. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_as_tuple_impl(PyObject *self) -/*[clinic end generated code: output=c6e8e2420c515eca input=e26f2151d78ff59d]*/ +_decimal_Decimal_as_tuple_impl(PyObject *self, PyTypeObject *cls) +/*[clinic end generated code: output=d68b967becee8ab9 input=bfa86d640224d9f5]*/ { PyObject *result = NULL; PyObject *sign = NULL; @@ -4312,7 +4363,7 @@ _decimal_Decimal_as_tuple_impl(PyObject *self) } } - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); result = PyObject_CallFunctionObjArgs((PyObject *)state->DecimalTuple, sign, coeff, expt, NULL); @@ -4364,7 +4415,7 @@ nm_##MPDFUNC(PyObject *self, PyObject *other) \ PyObject *context; \ uint32_t status = 0; \ \ - decimal_state *state = find_state_left_or_right(self, other); \ + decimal_state *state = find_state_left_or_right(self, other); \ CURRENT_CONTEXT(state, context) ; \ CONVERT_BINOP(&a, &b, self, other, context); \ \ @@ -4394,25 +4445,26 @@ nm_##MPDFUNC(PyObject *self, PyObject *other) \ } /* Boolean function with an optional context arg. - Argument Clinic provides PyObject *self, PyObject *context + Argument Clinic provides PyObject *self, PyTypeObject *cls, + PyObject *context */ #define Dec_BoolFuncVA(MPDFUNC) \ { \ - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); \ + decimal_state *state = PyType_GetModuleState(cls); \ CONTEXT_CHECK_VA(state, context); \ \ return MPDFUNC(MPD(self), CTX(context)) ? incr_true() : incr_false(); \ } /* Unary function with an optional context arg. - Argument Clinic provides PyObject *self, PyObject *context + Argument Clinic provides PyObject *self, PyTypeObject *cls, + PyObject *context */ #define Dec_UnaryFuncVA(MPDFUNC) \ { \ PyObject *result; \ uint32_t status = 0; \ - decimal_state *state = \ - get_module_state_by_def(Py_TYPE(self)); \ + decimal_state *state = PyType_GetModuleState(cls); \ CONTEXT_CHECK_VA(state, context); \ \ if ((result = dec_alloc(state)) == NULL) { \ @@ -4429,15 +4481,15 @@ nm_##MPDFUNC(PyObject *self, PyObject *other) \ } /* Binary function with an optional context arg. - Argument Clinic provides PyObject *self, PyObject *other, PyObject *context + Argument Clinic provides PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context */ #define Dec_BinaryFuncVA(MPDFUNC) \ { \ PyObject *a, *b; \ PyObject *result; \ uint32_t status = 0; \ - decimal_state *state = \ - get_module_state_by_def(Py_TYPE(self)); \ + decimal_state *state = PyType_GetModuleState(cls); \ CONTEXT_CHECK_VA(state, context); \ CONVERT_BINOP_RAISE(&a, &b, self, other, context); \ \ @@ -4462,14 +4514,14 @@ nm_##MPDFUNC(PyObject *self, PyObject *other) \ NOT take a context. The context is used to record InvalidOperation if the second operand cannot be converted exactly. - Argument Clinic provides PyObject *self, PyObject *other, PyObject *context + Argument Clinic provides PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context */ #define Dec_BinaryFuncVA_NO_CTX(MPDFUNC) \ { \ PyObject *a, *b; \ PyObject *result; \ - decimal_state *state = \ - get_module_state_by_def(Py_TYPE(self)); \ + decimal_state *state = PyType_GetModuleState(cls); \ CONTEXT_CHECK_VA(state, context); \ CONVERT_BINOP_RAISE(&a, &b, self, other, context); \ \ @@ -4487,7 +4539,8 @@ nm_##MPDFUNC(PyObject *self, PyObject *other) \ } /* Ternary function with an optional context arg. - Argument Clinic provides PyObject *self, PyObject *other, PyObject *third, + Argument Clinic provides PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *third, PyObject *context */ #define Dec_TernaryFuncVA(MPDFUNC) \ @@ -4495,7 +4548,7 @@ nm_##MPDFUNC(PyObject *self, PyObject *other) \ PyObject *a, *b, *c; \ PyObject *result; \ uint32_t status = 0; \ - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); \ + decimal_state *state = PyType_GetModuleState(cls); \ CONTEXT_CHECK_VA(state, context); \ CONVERT_TERNOP_RAISE(&a, &b, &c, self, other, third, context); \ \ @@ -4648,6 +4701,7 @@ nm_mpd_qpow(PyObject *base, PyObject *exp, PyObject *mod) /*[clinic input] _decimal.Decimal.exp + cls: defining_class context: object = None Return the value of the (natural) exponential function e**x. @@ -4657,8 +4711,9 @@ correctly rounded. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_exp_impl(PyObject *self, PyObject *context) -/*[clinic end generated code: output=c0833b6e9b8c836f input=274784af925e60c9]*/ +_decimal_Decimal_exp_impl(PyObject *self, PyTypeObject *cls, + PyObject *context) +/*[clinic end generated code: output=40317012aedbaeac input=84919aad3dabda08]*/ Dec_UnaryFuncVA(mpd_qexp) /*[clinic input] @@ -4671,8 +4726,9 @@ correctly rounded. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_ln_impl(PyObject *self, PyObject *context) -/*[clinic end generated code: output=5191f4ef739b04b0 input=d353c51ec00d1cff]*/ +_decimal_Decimal_ln_impl(PyObject *self, PyTypeObject *cls, + PyObject *context) +/*[clinic end generated code: output=e8f9e81cac38e5dc input=d353c51ec00d1cff]*/ Dec_UnaryFuncVA(mpd_qln) /*[clinic input] @@ -4685,8 +4741,9 @@ correctly rounded. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_log10_impl(PyObject *self, PyObject *context) -/*[clinic end generated code: output=d5da63df75900275 input=48a6be60154c0b46]*/ +_decimal_Decimal_log10_impl(PyObject *self, PyTypeObject *cls, + PyObject *context) +/*[clinic end generated code: output=00b3255648135c95 input=48a6be60154c0b46]*/ Dec_UnaryFuncVA(mpd_qlog10) /*[clinic input] @@ -4696,8 +4753,9 @@ Returns the largest representable number smaller than itself. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_next_minus_impl(PyObject *self, PyObject *context) -/*[clinic end generated code: output=aacbd758399f883f input=666b348f71e6c090]*/ +_decimal_Decimal_next_minus_impl(PyObject *self, PyTypeObject *cls, + PyObject *context) +/*[clinic end generated code: output=a187a55e6976b572 input=666b348f71e6c090]*/ Dec_UnaryFuncVA(mpd_qnext_minus) /*[clinic input] @@ -4707,8 +4765,9 @@ Returns the smallest representable number larger than itself. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_next_plus_impl(PyObject *self, PyObject *context) -/*[clinic end generated code: output=f3a7029a213c553c input=04e105060ad1fa15]*/ +_decimal_Decimal_next_plus_impl(PyObject *self, PyTypeObject *cls, + PyObject *context) +/*[clinic end generated code: output=13737d41714e320e input=04e105060ad1fa15]*/ Dec_UnaryFuncVA(mpd_qnext_plus) /*[clinic input] @@ -4723,8 +4782,9 @@ the equivalent value Decimal('32.1'). [clinic start generated code]*/ static PyObject * -_decimal_Decimal_normalize_impl(PyObject *self, PyObject *context) -/*[clinic end generated code: output=db2c8b3c8eccff36 input=d5ee63acd904d4de]*/ +_decimal_Decimal_normalize_impl(PyObject *self, PyTypeObject *cls, + PyObject *context) +/*[clinic end generated code: output=32c4c0d13fe33fb9 input=d5ee63acd904d4de]*/ Dec_UnaryFuncVA(mpd_qreduce) /*[clinic input] @@ -4736,8 +4796,9 @@ The result is correctly rounded using the ROUND_HALF_EVEN rounding mode. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_sqrt_impl(PyObject *self, PyObject *context) -/*[clinic end generated code: output=420722a199dd9c2b input=3a76afbd39dc20b9]*/ +_decimal_Decimal_sqrt_impl(PyObject *self, PyTypeObject *cls, + PyObject *context) +/*[clinic end generated code: output=deb1280077b5e586 input=3a76afbd39dc20b9]*/ Dec_UnaryFuncVA(mpd_qsqrt) /* Binary arithmetic functions, optional context arg */ @@ -4745,6 +4806,7 @@ Dec_UnaryFuncVA(mpd_qsqrt) /*[clinic input] _decimal.Decimal.compare + cls: defining_class other: object context: object = None @@ -4759,9 +4821,9 @@ Return a decimal value: [clinic start generated code]*/ static PyObject * -_decimal_Decimal_compare_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=d6967aa3578b9d48 input=1b7b75a2a154e520]*/ +_decimal_Decimal_compare_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=a4a1d383ec192cfa input=d18a02bb8083e92a]*/ Dec_BinaryFuncVA(mpd_qcompare) /*[clinic input] @@ -4771,9 +4833,9 @@ Identical to compare, except that all NaNs signal. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_compare_signal_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=0b8d0ff43f6c8a95 input=a52a39d1c6fc369d]*/ +_decimal_Decimal_compare_signal_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=22f757371fd4167b input=a52a39d1c6fc369d]*/ Dec_BinaryFuncVA(mpd_qcompare_signal) /*[clinic input] @@ -4786,8 +4848,9 @@ operand is returned. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_max_impl(PyObject *self, PyObject *other, PyObject *context) -/*[clinic end generated code: output=f3a5c5d76761c9ff input=2ae2582f551296d8]*/ +_decimal_Decimal_max_impl(PyObject *self, PyTypeObject *cls, PyObject *other, + PyObject *context) +/*[clinic end generated code: output=d3d12db9815869e5 input=2ae2582f551296d8]*/ Dec_BinaryFuncVA(mpd_qmax) /*[clinic input] @@ -4797,9 +4860,9 @@ As the max() method, but compares the absolute values of the operands. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_max_mag_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=52b0451987bac65f input=88b105e66cf138c5]*/ +_decimal_Decimal_max_mag_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=f71f2c27d9bc7cac input=88b105e66cf138c5]*/ Dec_BinaryFuncVA(mpd_qmax_mag) /*[clinic input] @@ -4812,8 +4875,9 @@ operand is returned. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_min_impl(PyObject *self, PyObject *other, PyObject *context) -/*[clinic end generated code: output=d2f38ecb9d6f0493 input=2a70f2c087c418c9]*/ +_decimal_Decimal_min_impl(PyObject *self, PyTypeObject *cls, PyObject *other, + PyObject *context) +/*[clinic end generated code: output=c5620344ae5f3dd1 input=2a70f2c087c418c9]*/ Dec_BinaryFuncVA(mpd_qmin) /*[clinic input] @@ -4823,9 +4887,9 @@ As the min() method, but compares the absolute values of the operands. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_min_mag_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=aa3391935f6c8fc9 input=351fa3c0e592746a]*/ +_decimal_Decimal_min_mag_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=018562ad1c22aae3 input=351fa3c0e592746a]*/ Dec_BinaryFuncVA(mpd_qmin_mag) /*[clinic input] @@ -4840,9 +4904,9 @@ to be the same as the sign of the second operand. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_next_toward_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=edb933755644af69 input=fdf0091ea6e9e416]*/ +_decimal_Decimal_next_toward_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=71d879bca8bc1019 input=fdf0091ea6e9e416]*/ Dec_BinaryFuncVA(mpd_qnext_toward) /*[clinic input] @@ -4860,9 +4924,9 @@ If the result is zero then its sign will be the sign of self. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_remainder_near_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=6ce0fb3b0faff2f9 input=eb5a8dfe3470b794]*/ +_decimal_Decimal_remainder_near_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=d3fbb4985f2077fa input=eb5a8dfe3470b794]*/ Dec_BinaryFuncVA(mpd_qrem_near) /* Ternary arithmetic functions, optional context arg */ @@ -4870,6 +4934,7 @@ Dec_BinaryFuncVA(mpd_qrem_near) /*[clinic input] _decimal.Decimal.fma + cls: defining_class other: object third: object context: object = None @@ -4884,9 +4949,9 @@ self*other. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_fma_impl(PyObject *self, PyObject *other, PyObject *third, - PyObject *context) -/*[clinic end generated code: output=74a82b984e227b69 input=48f9aec6f389227a]*/ +_decimal_Decimal_fma_impl(PyObject *self, PyTypeObject *cls, PyObject *other, + PyObject *third, PyObject *context) +/*[clinic end generated code: output=db49a777e85b71e4 input=2104c001f6077c35]*/ Dec_TernaryFuncVA(mpd_qfma) /* Boolean functions, no context arg */ @@ -4995,8 +5060,9 @@ Normal number is a finite nonzero number, which is not subnormal. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_is_normal_impl(PyObject *self, PyObject *context) -/*[clinic end generated code: output=40cc429d388eb464 input=9afe43b9db9f4818]*/ +_decimal_Decimal_is_normal_impl(PyObject *self, PyTypeObject *cls, + PyObject *context) +/*[clinic end generated code: output=92a3878e293758d4 input=9afe43b9db9f4818]*/ Dec_BoolFuncVA(mpd_isnormal) /*[clinic input] @@ -5009,8 +5075,9 @@ exponent less than Emin. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_is_subnormal_impl(PyObject *self, PyObject *context) -/*[clinic end generated code: output=6f7d422b1f387d7f input=11839c122c185b8b]*/ +_decimal_Decimal_is_subnormal_impl(PyObject *self, PyTypeObject *cls, + PyObject *context) +/*[clinic end generated code: output=1404c04d980ebc07 input=11839c122c185b8b]*/ Dec_BoolFuncVA(mpd_issubnormal) /* Unary functions, no context arg */ @@ -5083,6 +5150,8 @@ _dec_mpd_radix(decimal_state *state) /*[clinic input] _decimal.Decimal.radix + cls: defining_class + Return Decimal(10). This is the radix (base) in which the Decimal class does @@ -5090,16 +5159,18 @@ all its arithmetic. Included for compatibility with the specification. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_radix_impl(PyObject *self) -/*[clinic end generated code: output=6b1db4c3fcdb5ee1 input=18b72393549ca8fd]*/ +_decimal_Decimal_radix_impl(PyObject *self, PyTypeObject *cls) +/*[clinic end generated code: output=40a3bc7ec3d99228 input=b0d4cb9f870bbac1]*/ { - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); return _dec_mpd_radix(state); } /*[clinic input] _decimal.Decimal.copy_abs + cls: defining_class + Return the absolute value of the argument. This operation is unaffected by context and is quiet: no flags are @@ -5107,13 +5178,13 @@ changed and no rounding is performed. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_copy_abs_impl(PyObject *self) -/*[clinic end generated code: output=fff53742cca94d70 input=a263c2e71d421f1b]*/ +_decimal_Decimal_copy_abs_impl(PyObject *self, PyTypeObject *cls) +/*[clinic end generated code: output=081cb7fb4230676e input=676d7c62b1795512]*/ { PyObject *result; uint32_t status = 0; + decimal_state *state = PyType_GetModuleState(cls); - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); if ((result = dec_alloc(state)) == NULL) { return NULL; } @@ -5129,7 +5200,7 @@ _decimal_Decimal_copy_abs_impl(PyObject *self) } /*[clinic input] -_decimal.Decimal.copy_negate +_decimal.Decimal.copy_negate = _decimal.Decimal.copy_abs Return the negation of the argument. @@ -5138,13 +5209,13 @@ changed and no rounding is performed. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_copy_negate_impl(PyObject *self) -/*[clinic end generated code: output=8551bc26dbc5d01d input=13d47ed3a5d228b1]*/ +_decimal_Decimal_copy_negate_impl(PyObject *self, PyTypeObject *cls) +/*[clinic end generated code: output=04fed82c17d4e28b input=23f41ee8899f3891]*/ { PyObject *result; uint32_t status = 0; + decimal_state *state = PyType_GetModuleState(cls); - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); if ((result = dec_alloc(state)) == NULL) { return NULL; } @@ -5168,8 +5239,9 @@ Return the digit-wise inversion of the (logical) operand. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_logical_invert_impl(PyObject *self, PyObject *context) -/*[clinic end generated code: output=59beb9b1b51b9f34 input=3531dac8b9548dad]*/ +_decimal_Decimal_logical_invert_impl(PyObject *self, PyTypeObject *cls, + PyObject *context) +/*[clinic end generated code: output=c626ed4b104a97b7 input=3531dac8b9548dad]*/ Dec_UnaryFuncVA(mpd_qinvert) /*[clinic input] @@ -5183,8 +5255,9 @@ Decimal('Infinity') is returned. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_logb_impl(PyObject *self, PyObject *context) -/*[clinic end generated code: output=f278db20b47f301c input=a8df027d1b8a2b17]*/ +_decimal_Decimal_logb_impl(PyObject *self, PyTypeObject *cls, + PyObject *context) +/*[clinic end generated code: output=36b0bda09e934245 input=a8df027d1b8a2b17]*/ Dec_UnaryFuncVA(mpd_qlogb) /*[clinic input] @@ -5211,12 +5284,13 @@ The returned value is one of the following ten strings: [clinic start generated code]*/ static PyObject * -_decimal_Decimal_number_class_impl(PyObject *self, PyObject *context) -/*[clinic end generated code: output=3044cd45966b4949 input=447095d2677fa0ca]*/ +_decimal_Decimal_number_class_impl(PyObject *self, PyTypeObject *cls, + PyObject *context) +/*[clinic end generated code: output=1ac82412e0849c52 input=447095d2677fa0ca]*/ { const char *cp; - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); CONTEXT_CHECK_VA(state, context); cp = mpd_class(MPD(self), CTX(context)); @@ -5238,14 +5312,15 @@ operation. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_to_eng_string_impl(PyObject *self, PyObject *context) -/*[clinic end generated code: output=d386194c25ffffa7 input=b2cb7e01e268e45d]*/ +_decimal_Decimal_to_eng_string_impl(PyObject *self, PyTypeObject *cls, + PyObject *context) +/*[clinic end generated code: output=901f128d437ae5c0 input=b2cb7e01e268e45d]*/ { PyObject *result; mpd_ssize_t size; char *s; - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); CONTEXT_CHECK_VA(state, context); size = mpd_to_eng_size(&s, MPD(self), CtxCaps(context)); @@ -5289,9 +5364,9 @@ exactly. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_compare_total_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=dca119b5e881a83e input=6f3111ec5fdbf3c1]*/ +_decimal_Decimal_compare_total_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=83649010bad7815f input=6f3111ec5fdbf3c1]*/ Dec_BinaryFuncVA_NO_CTX(mpd_compare_total) /*[clinic input] @@ -5309,9 +5384,9 @@ exactly. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_compare_total_mag_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=6bf1b3419112d0dd input=eba17c4c24eb2833]*/ +_decimal_Decimal_compare_total_mag_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=b99c924cafb5f0e3 input=eba17c4c24eb2833]*/ Dec_BinaryFuncVA_NO_CTX(mpd_compare_total_mag) /*[clinic input] @@ -5331,15 +5406,15 @@ exactly. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_copy_sign_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=72c62177763e012e input=51ed9e4691e2249e]*/ +_decimal_Decimal_copy_sign_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=e4c8f884f4d75801 input=51ed9e4691e2249e]*/ { PyObject *a, *b; PyObject *result; uint32_t status = 0; - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); CONTEXT_CHECK_VA(state, context); CONVERT_BINOP_RAISE(&a, &b, self, other, context); @@ -5373,14 +5448,14 @@ exactly. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_same_quantum_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=c0a3a046c662a7e2 input=8339415fa359e7df]*/ +_decimal_Decimal_same_quantum_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=7c757edb0c263721 input=8339415fa359e7df]*/ { PyObject *a, *b; PyObject *result; - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); CONTEXT_CHECK_VA(state, context); CONVERT_BINOP_RAISE(&a, &b, self, other, context); @@ -5400,9 +5475,9 @@ Return the digit-wise 'and' of the two (logical) operands. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_logical_and_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=1526a357f97eaf71 input=2b319baee8970929]*/ +_decimal_Decimal_logical_and_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=9a4cbb74c180b0bb input=2b319baee8970929]*/ Dec_BinaryFuncVA(mpd_qand) /*[clinic input] @@ -5412,9 +5487,9 @@ Return the digit-wise 'or' of the two (logical) operands. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_logical_or_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=e57a72acf0982f56 input=75e0e1d4dd373b90]*/ +_decimal_Decimal_logical_or_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=063c4de18dc41ecb input=75e0e1d4dd373b90]*/ Dec_BinaryFuncVA(mpd_qor) /*[clinic input] @@ -5424,9 +5499,9 @@ Return the digit-wise 'xor' of the two (logical) operands. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_logical_xor_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=ae3a7aeddde5a1a8 input=a1ed8d6ac38c1c9e]*/ +_decimal_Decimal_logical_xor_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=829b09cb49926ad7 input=a1ed8d6ac38c1c9e]*/ Dec_BinaryFuncVA(mpd_qxor) /*[clinic input] @@ -5443,9 +5518,9 @@ necessary. The sign and exponent of the first operand are unchanged. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_rotate_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=e59e757e70a8416a input=cde7b032eac43f0b]*/ +_decimal_Decimal_rotate_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=09f2737082882b83 input=cde7b032eac43f0b]*/ Dec_BinaryFuncVA(mpd_qrotate) /*[clinic input] @@ -5458,9 +5533,9 @@ second operand must be an integer. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_scaleb_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=f01e99600eda34d7 input=7f29f83278d05f83]*/ +_decimal_Decimal_scaleb_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=ae8730536c9f2d30 input=7f29f83278d05f83]*/ Dec_BinaryFuncVA(mpd_qscaleb) /*[clinic input] @@ -5477,14 +5552,15 @@ operand are unchanged. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_shift_impl(PyObject *self, PyObject *other, - PyObject *context) -/*[clinic end generated code: output=f79ff9ce6d5b05ed input=501759c2522cb78e]*/ +_decimal_Decimal_shift_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context) +/*[clinic end generated code: output=82e061a0d9ecc4f5 input=501759c2522cb78e]*/ Dec_BinaryFuncVA(mpd_qshift) /*[clinic input] _decimal.Decimal.quantize + cls: defining_class exp as w: object rounding: object = None context: object = None @@ -5514,16 +5590,17 @@ current thread's context is used. [clinic start generated code]*/ static PyObject * -_decimal_Decimal_quantize_impl(PyObject *self, PyObject *w, - PyObject *rounding, PyObject *context) -/*[clinic end generated code: output=5e84581f96dc685c input=4c7d28d36948e9aa]*/ +_decimal_Decimal_quantize_impl(PyObject *self, PyTypeObject *cls, + PyObject *w, PyObject *rounding, + PyObject *context) +/*[clinic end generated code: output=fc51edf458559913 input=1166e6311e047b74]*/ { PyObject *a, *b; PyObject *result; uint32_t status = 0; mpd_context_t workctx; - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); CONTEXT_CHECK_VA(state, context); workctx = *CTX(context); @@ -5620,16 +5697,18 @@ dec_richcompare(PyObject *v, PyObject *w, int op) /*[clinic input] _decimal.Decimal.__ceil__ + cls: defining_class + Return the ceiling as an Integral. [clinic start generated code]*/ static PyObject * -_decimal_Decimal___ceil___impl(PyObject *self) -/*[clinic end generated code: output=e755a6fb7bceac19 input=4a18ef307ac57da0]*/ +_decimal_Decimal___ceil___impl(PyObject *self, PyTypeObject *cls) +/*[clinic end generated code: output=d986ebf9aadbf9fe input=a8e0b87897706816]*/ { PyObject *context; - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); CURRENT_CONTEXT(state, context); return dec_as_long(self, context, MPD_ROUND_CEILING); } @@ -5689,18 +5768,18 @@ _decimal_Decimal___deepcopy__(PyObject *self, PyObject *memo) } /*[clinic input] -_decimal.Decimal.__floor__ +_decimal.Decimal.__floor__ = _decimal.Decimal.__ceil__ Return the floor as an Integral. [clinic start generated code]*/ static PyObject * -_decimal_Decimal___floor___impl(PyObject *self) -/*[clinic end generated code: output=56767050ac1a1d5a input=cabcc5618564548b]*/ +_decimal_Decimal___floor___impl(PyObject *self, PyTypeObject *cls) +/*[clinic end generated code: output=e239a2f7f6514c12 input=dcc37aeceb0efb8d]*/ { PyObject *context; - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); CURRENT_CONTEXT(state, context); return dec_as_long(self, context, MPD_ROUND_FLOOR); } @@ -5875,18 +5954,18 @@ _decimal_Decimal___sizeof___impl(PyObject *v) } /*[clinic input] -_decimal.Decimal.__trunc__ +_decimal.Decimal.__trunc__ = _decimal.Decimal.__ceil__ Return the Integral closest to x between 0 and x. [clinic start generated code]*/ static PyObject * -_decimal_Decimal___trunc___impl(PyObject *self) -/*[clinic end generated code: output=9ef59578960f80c0 input=a965a61096dcefeb]*/ +_decimal_Decimal___trunc___impl(PyObject *self, PyTypeObject *cls) +/*[clinic end generated code: output=7b3decc4b636ce32 input=9b3a3a85f63b0515]*/ { PyObject *context; - decimal_state *state = get_module_state_by_def(Py_TYPE(self)); + decimal_state *state = PyType_GetModuleState(cls); CURRENT_CONTEXT(state, context); return dec_as_long(self, context, MPD_ROUND_DOWN); } @@ -6096,7 +6175,8 @@ static PyType_Spec dec_spec = { } /* Unary context method. - Argument Clinic provides PyObject *context, PyObject *x + Argument Clinic provides PyObject *context, + PyTypeObject *cls, PyObject *x */ #define DecCtx_UnaryFunc(MPDFUNC) \ { \ @@ -6104,8 +6184,7 @@ static PyType_Spec dec_spec = { uint32_t status = 0; \ \ CONVERT_OP_RAISE(&a, x, context); \ - decimal_state *state = \ - get_module_state_from_ctx(context); \ + decimal_state *state = PyType_GetModuleState(cls); \ if ((result = dec_alloc(state)) == NULL) { \ Py_DECREF(a); \ return NULL; \ @@ -6122,7 +6201,8 @@ static PyType_Spec dec_spec = { } /* Binary context method. - Argument Clinic provides PyObject *context, PyObject *x, PyObject *y + Argument Clinic provides PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y */ #define DecCtx_BinaryFunc(MPDFUNC) \ { \ @@ -6131,8 +6211,7 @@ static PyType_Spec dec_spec = { uint32_t status = 0; \ \ CONVERT_BINOP_RAISE(&a, &b, x, y, context); \ - decimal_state *state = \ - get_module_state_from_ctx(context); \ + decimal_state *state = PyType_GetModuleState(cls); \ if ((result = dec_alloc(state)) == NULL) { \ Py_DECREF(a); \ Py_DECREF(b); \ @@ -6153,7 +6232,8 @@ static PyType_Spec dec_spec = { /* * Binary context method. The context is only used for conversion. * The actual MPDFUNC does NOT take a context arg. - * Argument Clinic provides PyObject *context, PyObject *x, PyObject *y + * Argument Clinic provides PyObject *context, PyTypeObject *cls, + * PyObject *x, PyObject *y */ #define DecCtx_BinaryFunc_NO_CTX(MPDFUNC) \ { \ @@ -6162,7 +6242,7 @@ static PyType_Spec dec_spec = { \ CONVERT_BINOP_RAISE(&a, &b, x, y, context); \ decimal_state *state = \ - get_module_state_from_ctx(context); \ + PyType_GetModuleState(cls); \ if ((result = dec_alloc(state)) == NULL) { \ Py_DECREF(a); \ Py_DECREF(b); \ @@ -6177,8 +6257,8 @@ static PyType_Spec dec_spec = { } /* Ternary context method. - Argument Clinic provides PyObject *context, PyObject *x, PyObject *y, - PyObject *z + Argument Clinic provides PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y, PyObject *z */ #define DecCtx_TernaryFunc(MPDFUNC) \ { \ @@ -6187,7 +6267,7 @@ static PyType_Spec dec_spec = { uint32_t status = 0; \ \ CONVERT_TERNOP_RAISE(&a, &b, &c, x, y, z, context); \ - decimal_state *state = get_module_state_from_ctx(context); \ + decimal_state *state = PyType_GetModuleState(cls); \ if ((result = dec_alloc(state)) == NULL) { \ Py_DECREF(a); \ Py_DECREF(b); \ @@ -6214,6 +6294,7 @@ static PyType_Spec dec_spec = { _decimal.Context.abs self as context: self + cls: defining_class x: object / @@ -6221,8 +6302,8 @@ Return the absolute value of x. [clinic start generated code]*/ static PyObject * -_decimal_Context_abs(PyObject *context, PyObject *x) -/*[clinic end generated code: output=5cafb5edf96df9e4 input=8384b327e52d6723]*/ +_decimal_Context_abs_impl(PyObject *context, PyTypeObject *cls, PyObject *x) +/*[clinic end generated code: output=fe080467d32e229c input=00a33f9c68463bb0]*/ DecCtx_UnaryFunc(mpd_qabs) /*[clinic input] @@ -6232,8 +6313,8 @@ Return e ** x. [clinic start generated code]*/ static PyObject * -_decimal_Context_exp(PyObject *context, PyObject *x) -/*[clinic end generated code: output=787085815e6a9aa4 input=5b443c4ab153dd2e]*/ +_decimal_Context_exp_impl(PyObject *context, PyTypeObject *cls, PyObject *x) +/*[clinic end generated code: output=c7477a67010ccc5f input=5b443c4ab153dd2e]*/ DecCtx_UnaryFunc(mpd_qexp) /*[clinic input] @@ -6243,8 +6324,8 @@ Return the natural (base e) logarithm of x. [clinic start generated code]*/ static PyObject * -_decimal_Context_ln(PyObject *context, PyObject *x) -/*[clinic end generated code: output=9ecce76097f16bbe input=cf43cd98a0fe7425]*/ +_decimal_Context_ln_impl(PyObject *context, PyTypeObject *cls, PyObject *x) +/*[clinic end generated code: output=63e691b0680bffc7 input=cf43cd98a0fe7425]*/ DecCtx_UnaryFunc(mpd_qln) /*[clinic input] @@ -6254,8 +6335,9 @@ Return the base 10 logarithm of x. [clinic start generated code]*/ static PyObject * -_decimal_Context_log10(PyObject *context, PyObject *x) -/*[clinic end generated code: output=08080765645630e4 input=309e57faf42c257d]*/ +_decimal_Context_log10_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=e0d9fc928570304d input=309e57faf42c257d]*/ DecCtx_UnaryFunc(mpd_qlog10) /*[clinic input] @@ -6267,8 +6349,9 @@ This operation applies the context to the result. [clinic start generated code]*/ static PyObject * -_decimal_Context_minus(PyObject *context, PyObject *x) -/*[clinic end generated code: output=49c1a0d59f4585b6 input=63be4c419d1d554b]*/ +_decimal_Context_minus_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=f06c409b6aef1aad input=63be4c419d1d554b]*/ DecCtx_UnaryFunc(mpd_qminus) /*[clinic input] @@ -6278,8 +6361,9 @@ Return the largest representable number smaller than x. [clinic start generated code]*/ static PyObject * -_decimal_Context_next_minus(PyObject *context, PyObject *x) -/*[clinic end generated code: output=0c11a0d5fa9103d2 input=969f4d24dfcd5e85]*/ +_decimal_Context_next_minus_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=8dd168f08bec9547 input=969f4d24dfcd5e85]*/ DecCtx_UnaryFunc(mpd_qnext_minus) /*[clinic input] @@ -6289,8 +6373,9 @@ Return the smallest representable number larger than x. [clinic start generated code]*/ static PyObject * -_decimal_Context_next_plus(PyObject *context, PyObject *x) -/*[clinic end generated code: output=fd834e8c58b76031 input=af1a85ee59b56a3c]*/ +_decimal_Context_next_plus_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=2a50586ad2f7c108 input=af1a85ee59b56a3c]*/ DecCtx_UnaryFunc(mpd_qnext_plus) /*[clinic input] @@ -6300,8 +6385,9 @@ Reduce x to its simplest form. Alias for reduce(x). [clinic start generated code]*/ static PyObject * -_decimal_Context_normalize(PyObject *context, PyObject *x) -/*[clinic end generated code: output=492c6ca375bcf020 input=a65bc39c81a654a9]*/ +_decimal_Context_normalize_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=9a9510f442ba2852 input=a65bc39c81a654a9]*/ DecCtx_UnaryFunc(mpd_qreduce) /*[clinic input] @@ -6313,8 +6399,8 @@ This operation applies the context to the result. [clinic start generated code]*/ static PyObject * -_decimal_Context_plus(PyObject *context, PyObject *x) -/*[clinic end generated code: output=ee089d734941936e input=5d8a75702d20e2f9]*/ +_decimal_Context_plus_impl(PyObject *context, PyTypeObject *cls, PyObject *x) +/*[clinic end generated code: output=c37d29f58a47f93a input=5d8a75702d20e2f9]*/ DecCtx_UnaryFunc(mpd_qplus) /*[clinic input] @@ -6324,8 +6410,9 @@ Round to an integer. [clinic start generated code]*/ static PyObject * -_decimal_Context_to_integral_value(PyObject *context, PyObject *x) -/*[clinic end generated code: output=ffc6470421c1439b input=3103e147cb9de9ed]*/ +_decimal_Context_to_integral_value_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=e3d9ad000bc06036 input=3103e147cb9de9ed]*/ DecCtx_UnaryFunc(mpd_qround_to_int) /*[clinic input] @@ -6335,8 +6422,9 @@ Round to an integer. Signal if the result is rounded or inexact. [clinic start generated code]*/ static PyObject * -_decimal_Context_to_integral_exact(PyObject *context, PyObject *x) -/*[clinic end generated code: output=7fac8eca35da9290 input=677dc4b915907b68]*/ +_decimal_Context_to_integral_exact_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=680b796dfae8e2ef input=677dc4b915907b68]*/ DecCtx_UnaryFunc(mpd_qround_to_intx) /*[clinic input] @@ -6346,8 +6434,9 @@ Identical to to_integral_value(x). [clinic start generated code]*/ static PyObject * -_decimal_Context_to_integral(PyObject *context, PyObject *x) -/*[clinic end generated code: output=2741701ed141df91 input=89d4a4b15495b8c9]*/ +_decimal_Context_to_integral_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=09f4823b90b2cf17 input=89d4a4b15495b8c9]*/ DecCtx_UnaryFunc(mpd_qround_to_int) /*[clinic input] @@ -6357,8 +6446,8 @@ Square root of a non-negative number to context precision. [clinic start generated code]*/ static PyObject * -_decimal_Context_sqrt(PyObject *context, PyObject *x) -/*[clinic end generated code: output=5595ae901120606c input=90bd954b0b8076fb]*/ +_decimal_Context_sqrt_impl(PyObject *context, PyTypeObject *cls, PyObject *x) +/*[clinic end generated code: output=2b9c16c6f5ceead0 input=90bd954b0b8076fb]*/ DecCtx_UnaryFunc(mpd_qsqrt) /* Binary arithmetic functions */ @@ -6367,6 +6456,7 @@ DecCtx_UnaryFunc(mpd_qsqrt) _decimal.Context.add self as context: self + cls: defining_class x: object y: object / @@ -6375,8 +6465,9 @@ Return the sum of x and y. [clinic start generated code]*/ static PyObject * -_decimal_Context_add_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=9957850af48fe295 input=8b8eac286bdf6cb4]*/ +_decimal_Context_add_impl(PyObject *context, PyTypeObject *cls, PyObject *x, + PyObject *y) +/*[clinic end generated code: output=ab4f0fb841e6a867 input=f2c74f6a845f62e9]*/ DecCtx_BinaryFunc(mpd_qadd) /*[clinic input] @@ -6386,8 +6477,9 @@ Compare x and y numerically. [clinic start generated code]*/ static PyObject * -_decimal_Context_compare_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=646ab96420b9aad7 input=f701cb179c966ec1]*/ +_decimal_Context_compare_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=56efd1faf653f1d7 input=f701cb179c966ec1]*/ DecCtx_BinaryFunc(mpd_qcompare) /*[clinic input] @@ -6397,9 +6489,9 @@ Compare x and y numerically. All NaNs signal. [clinic start generated code]*/ static PyObject * -_decimal_Context_compare_signal_impl(PyObject *context, PyObject *x, - PyObject *y) -/*[clinic end generated code: output=dd56e9e6c3d12216 input=32a1bcef7bbc5179]*/ +_decimal_Context_compare_signal_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=7c1a9a9f6ae4e5cd input=32a1bcef7bbc5179]*/ DecCtx_BinaryFunc(mpd_qcompare_signal) /*[clinic input] @@ -6409,8 +6501,9 @@ Return x divided by y. [clinic start generated code]*/ static PyObject * -_decimal_Context_divide_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=0a07a5e718fe4a2c input=00cd9bc2ba2a1786]*/ +_decimal_Context_divide_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=1a7924b20e24a528 input=00cd9bc2ba2a1786]*/ DecCtx_BinaryFunc(mpd_qdiv) /*[clinic input] @@ -6420,8 +6513,9 @@ Return x divided by y, truncated to an integer. [clinic start generated code]*/ static PyObject * -_decimal_Context_divide_int_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=8c2d505d4339f4ef input=e80ada2f50d9719d]*/ +_decimal_Context_divide_int_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=7a1d8948625105f0 input=e80ada2f50d9719d]*/ DecCtx_BinaryFunc(mpd_qdivint) /*[clinic input] @@ -6431,8 +6525,9 @@ Compare the values numerically and return the maximum. [clinic start generated code]*/ static PyObject * -_decimal_Context_max_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=c8545b7718414761 input=22008ab898c86a8b]*/ +_decimal_Context_max_impl(PyObject *context, PyTypeObject *cls, PyObject *x, + PyObject *y) +/*[clinic end generated code: output=cd54af10a51c11fc input=22008ab898c86a8b]*/ DecCtx_BinaryFunc(mpd_qmax) /*[clinic input] @@ -6442,8 +6537,9 @@ Compare the values numerically with their sign ignored. [clinic start generated code]*/ static PyObject * -_decimal_Context_max_mag_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=3cd67457cbc4d961 input=f7ce42ef82a7c52e]*/ +_decimal_Context_max_mag_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=1c812e73bcb7827f input=f7ce42ef82a7c52e]*/ DecCtx_BinaryFunc(mpd_qmax_mag) /*[clinic input] @@ -6453,8 +6549,9 @@ Compare the values numerically and return the minimum. [clinic start generated code]*/ static PyObject * -_decimal_Context_min_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=c1bc3852a7c09707 input=2aeec1167638c5ef]*/ +_decimal_Context_min_impl(PyObject *context, PyTypeObject *cls, PyObject *x, + PyObject *y) +/*[clinic end generated code: output=aa494e95b88107b3 input=2aeec1167638c5ef]*/ DecCtx_BinaryFunc(mpd_qmin) /*[clinic input] @@ -6464,8 +6561,9 @@ Compare the values numerically with their sign ignored. [clinic start generated code]*/ static PyObject * -_decimal_Context_min_mag_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=f662c9d1b49abfd2 input=19d158c29e4fc140]*/ +_decimal_Context_min_mag_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=ee0b69c1d9a14185 input=19d158c29e4fc140]*/ DecCtx_BinaryFunc(mpd_qmin_mag) /*[clinic input] @@ -6475,8 +6573,9 @@ Return the product of x and y. [clinic start generated code]*/ static PyObject * -_decimal_Context_multiply_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=970be645784d70ad input=2fdd01acdbeef8ba]*/ +_decimal_Context_multiply_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=45f33b805afa01a8 input=2fdd01acdbeef8ba]*/ DecCtx_BinaryFunc(mpd_qmul) /*[clinic input] @@ -6486,9 +6585,9 @@ Return the number closest to x, in the direction towards y. [clinic start generated code]*/ static PyObject * -_decimal_Context_next_toward_impl(PyObject *context, PyObject *x, - PyObject *y) -/*[clinic end generated code: output=938f2b4034e83618 input=aac775298e02b68c]*/ +_decimal_Context_next_toward_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=436afff6f43edec2 input=aac775298e02b68c]*/ DecCtx_BinaryFunc(mpd_qnext_toward) /*[clinic input] @@ -6498,8 +6597,9 @@ Return a value equal to x (rounded), having the exponent of y. [clinic start generated code]*/ static PyObject * -_decimal_Context_quantize_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=38ae7ac037d093d0 input=43d67a696ab6d895]*/ +_decimal_Context_quantize_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=fcf8cd32b7d628c9 input=43d67a696ab6d895]*/ DecCtx_BinaryFunc(mpd_qquantize) /*[clinic input] @@ -6512,8 +6612,9 @@ original dividend. [clinic start generated code]*/ static PyObject * -_decimal_Context_remainder_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=eb158964831b5ca4 input=36d0eb2b392c1215]*/ +_decimal_Context_remainder_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=e0f96c834abbfbd2 input=36d0eb2b392c1215]*/ DecCtx_BinaryFunc(mpd_qrem) /*[clinic input] @@ -6526,9 +6627,9 @@ is 0 then its sign will be the sign of x). [clinic start generated code]*/ static PyObject * -_decimal_Context_remainder_near_impl(PyObject *context, PyObject *x, - PyObject *y) -/*[clinic end generated code: output=2bcbd9bb031d0d13 input=bafb6327bb314c5c]*/ +_decimal_Context_remainder_near_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=7f18c535a12cf8ac input=bafb6327bb314c5c]*/ DecCtx_BinaryFunc(mpd_qrem_near) /*[clinic input] @@ -6538,8 +6639,9 @@ Return the difference between x and y. [clinic start generated code]*/ static PyObject * -_decimal_Context_subtract_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=fa8847e07b7c2bcc input=6767683ec68f7a1a]*/ +_decimal_Context_subtract_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=3d764a8a87e79401 input=6767683ec68f7a1a]*/ DecCtx_BinaryFunc(mpd_qsub) /*[clinic input] @@ -6599,6 +6701,7 @@ _decimal_Context_divmod_impl(PyObject *context, PyObject *x, PyObject *y) _decimal.Context.power self as context: self + cls: defining_class a as base: object b as exp: object modulo as mod: object = None @@ -6621,9 +6724,9 @@ restrictions hold: [clinic start generated code]*/ static PyObject * -_decimal_Context_power_impl(PyObject *context, PyObject *base, PyObject *exp, - PyObject *mod) -/*[clinic end generated code: output=d2e68694ec545245 input=e9aef844813de243]*/ +_decimal_Context_power_impl(PyObject *context, PyTypeObject *cls, + PyObject *base, PyObject *exp, PyObject *mod) +/*[clinic end generated code: output=d06d40c37cdd69dc input=2a70edd03317c666]*/ { PyObject *a, *b, *c = NULL; PyObject *result; @@ -6639,7 +6742,7 @@ _decimal_Context_power_impl(PyObject *context, PyObject *base, PyObject *exp, } } - decimal_state *state = get_module_state_from_ctx(context); + decimal_state *state = PyType_GetModuleState(cls); result = dec_alloc(state); if (result == NULL) { Py_DECREF(a); @@ -6673,6 +6776,7 @@ _decimal_Context_power_impl(PyObject *context, PyObject *base, PyObject *exp, _decimal.Context.fma self as context: self + cls: defining_class x: object y: object z: object @@ -6682,9 +6786,9 @@ Return x multiplied by y, plus z. [clinic start generated code]*/ static PyObject * -_decimal_Context_fma_impl(PyObject *context, PyObject *x, PyObject *y, - PyObject *z) -/*[clinic end generated code: output=2d6174716faaf4e1 input=80479612da3333d1]*/ +_decimal_Context_fma_impl(PyObject *context, PyTypeObject *cls, PyObject *x, + PyObject *y, PyObject *z) +/*[clinic end generated code: output=08ec3cefc59d71a9 input=da3963b1a1da83b9]*/ DecCtx_TernaryFunc(mpd_qfma) /* No argument */ @@ -6693,15 +6797,16 @@ DecCtx_TernaryFunc(mpd_qfma) _decimal.Context.radix self as context: self + cls: defining_class Return 10. [clinic start generated code]*/ static PyObject * -_decimal_Context_radix_impl(PyObject *context) -/*[clinic end generated code: output=9218fa309e0fcaa1 input=faeaa5b71f838c38]*/ +_decimal_Context_radix_impl(PyObject *context, PyTypeObject *cls) +/*[clinic end generated code: output=674b88b7cd0c264d input=e1e4f8c0abf86825]*/ { - decimal_state *state = get_module_state_from_ctx(context); + decimal_state *state = PyType_GetModuleState(cls); return _dec_mpd_radix(state); } @@ -6711,6 +6816,7 @@ _decimal_Context_radix_impl(PyObject *context) _decimal.Context.is_normal self as context: self + cls: defining_class x: object / @@ -6718,8 +6824,9 @@ Return True if x is a normal number, False otherwise. [clinic start generated code]*/ static PyObject * -_decimal_Context_is_normal(PyObject *context, PyObject *x) -/*[clinic end generated code: output=fed613aed8b286de input=1e7ff3f560842b8d]*/ +_decimal_Context_is_normal_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=089c5609db60bf57 input=7c90b825a517ef7e]*/ DecCtx_BoolFunc(mpd_isnormal) /*[clinic input] @@ -6729,8 +6836,9 @@ Return True if x is subnormal, False otherwise. [clinic start generated code]*/ static PyObject * -_decimal_Context_is_subnormal(PyObject *context, PyObject *x) -/*[clinic end generated code: output=834450c602d58759 input=73f1bd9367b913a4]*/ +_decimal_Context_is_subnormal_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=f58c45a288aadeda input=73f1bd9367b913a4]*/ DecCtx_BoolFunc(mpd_issubnormal) /*[clinic input] @@ -6740,8 +6848,9 @@ Return True if x is finite, False otherwise. [clinic start generated code]*/ static PyObject * -_decimal_Context_is_finite(PyObject *context, PyObject *x) -/*[clinic end generated code: output=45606d2f56874fef input=abff92a8a6bb85e6]*/ +_decimal_Context_is_finite_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=dfb00f1b5589b9f0 input=abff92a8a6bb85e6]*/ DecCtx_BoolFunc_NO_CTX(mpd_isfinite) /*[clinic input] @@ -6751,8 +6860,9 @@ Return True if x is infinite, False otherwise. [clinic start generated code]*/ static PyObject * -_decimal_Context_is_infinite(PyObject *context, PyObject *x) -/*[clinic end generated code: output=35c480cd0a2c3cf9 input=591242ae9a1e60e6]*/ +_decimal_Context_is_infinite_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=1c28517500811d01 input=591242ae9a1e60e6]*/ DecCtx_BoolFunc_NO_CTX(mpd_isinfinite) /*[clinic input] @@ -6762,8 +6872,9 @@ Return True if x is a qNaN or sNaN, False otherwise. [clinic start generated code]*/ static PyObject * -_decimal_Context_is_nan(PyObject *context, PyObject *x) -/*[clinic end generated code: output=cb529f55bf3106b3 input=520218376d5eec5e]*/ +_decimal_Context_is_nan_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=9dc15463ee19864a input=520218376d5eec5e]*/ DecCtx_BoolFunc_NO_CTX(mpd_isnan) /*[clinic input] @@ -6773,8 +6884,9 @@ Return True if x is a quiet NaN, False otherwise. [clinic start generated code]*/ static PyObject * -_decimal_Context_is_qnan(PyObject *context, PyObject *x) -/*[clinic end generated code: output=3e2e750eb643db1d input=97d06a14ab3360d1]*/ +_decimal_Context_is_qnan_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=4caa672e03703b6d input=97d06a14ab3360d1]*/ DecCtx_BoolFunc_NO_CTX(mpd_isqnan) /*[clinic input] @@ -6784,8 +6896,9 @@ Return True if x is a signaling NaN, False otherwise. [clinic start generated code]*/ static PyObject * -_decimal_Context_is_snan(PyObject *context, PyObject *x) -/*[clinic end generated code: output=a7ead03a2dfa15e4 input=0059fe4e9c3b25a8]*/ +_decimal_Context_is_snan_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=a8caa929d9f82ecd input=0059fe4e9c3b25a8]*/ DecCtx_BoolFunc_NO_CTX(mpd_issnan) /*[clinic input] @@ -6795,8 +6908,9 @@ Return True if x is negative, False otherwise. [clinic start generated code]*/ static PyObject * -_decimal_Context_is_signed(PyObject *context, PyObject *x) -/*[clinic end generated code: output=c85cc15479d5ed47 input=b950cd697721ab8b]*/ +_decimal_Context_is_signed_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=42c450c99d4fe7db input=b950cd697721ab8b]*/ DecCtx_BoolFunc_NO_CTX(mpd_issigned) /*[clinic input] @@ -6806,8 +6920,9 @@ Return True if x is a zero, False otherwise. [clinic start generated code]*/ static PyObject * -_decimal_Context_is_zero(PyObject *context, PyObject *x) -/*[clinic end generated code: output=24150f3c2422ebf8 input=bf08197d142a8027]*/ +_decimal_Context_is_zero_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=e6c55359b7241d9e input=bf08197d142a8027]*/ DecCtx_BoolFunc_NO_CTX(mpd_iszero) /*[clinic input] @@ -6817,10 +6932,11 @@ Return True if x is canonical, False otherwise. [clinic start generated code]*/ static PyObject * -_decimal_Context_is_canonical(PyObject *context, PyObject *x) -/*[clinic end generated code: output=b5b522b930a41186 input=1bf2129808e55eb9]*/ +_decimal_Context_is_canonical_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=18ee249d9aec957c input=1bf2129808e55eb9]*/ { - decimal_state *state = get_module_state_from_ctx(context); + decimal_state *state = PyType_GetModuleState(cls); if (!PyDec_Check(state, x)) { PyErr_SetString(PyExc_TypeError, "argument must be a Decimal"); @@ -6838,8 +6954,9 @@ Apply self to Decimal x. [clinic start generated code]*/ static PyObject * -_decimal_Context__apply(PyObject *context, PyObject *x) -/*[clinic end generated code: output=8db39d294602492e input=12b34468ca4a4c30]*/ +_decimal_Context__apply_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=c6b542f4e8114b97 input=12b34468ca4a4c30]*/ { PyObject *result, *a; @@ -6858,8 +6975,9 @@ Apply self to Decimal x. [clinic start generated code]*/ static PyObject * -_decimal_Context_apply(PyObject *context, PyObject *x) -/*[clinic end generated code: output=4d39653645a6df44 input=388e66ca82733516]*/ +_decimal_Context_apply_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=f8a7142d47ad4ff3 input=388e66ca82733516]*/ { return _decimal_Context__apply(context, v); } @@ -6872,10 +6990,11 @@ Return a new instance of x. [clinic start generated code]*/ static PyObject * -_decimal_Context_canonical(PyObject *context, PyObject *x) -/*[clinic end generated code: output=28fa845499e5d485 input=025ecb106ac15bff]*/ +_decimal_Context_canonical_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=f213e433e2032e5e input=025ecb106ac15bff]*/ { - decimal_state *state = get_module_state_from_ctx(context); + decimal_state *state = PyType_GetModuleState(cls); if (!PyDec_Check(state, x)) { PyErr_SetString(PyExc_TypeError, "argument must be a Decimal"); @@ -6892,14 +7011,15 @@ Return a copy of x with the sign set to 0. [clinic start generated code]*/ static PyObject * -_decimal_Context_copy_abs(PyObject *context, PyObject *x) -/*[clinic end generated code: output=a9035e6606261b30 input=4aa2f612625f0f73]*/ +_decimal_Context_copy_abs_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=a141ad4b9afe2deb input=4aa2f612625f0f73]*/ { PyObject *result, *a; uint32_t status = 0; CONVERT_OP_RAISE(&a, x, context); - decimal_state *state = get_module_state_from_ctx(context); + decimal_state *state = PyType_GetModuleState(cls); result = dec_alloc(state); if (result == NULL) { Py_DECREF(a); @@ -6923,8 +7043,9 @@ Return a copy of Decimal x. [clinic start generated code]*/ static PyObject * -_decimal_Context_copy_decimal(PyObject *context, PyObject *x) -/*[clinic end generated code: output=b9ec251a2a568a14 input=4db4f942f45fb7c9]*/ +_decimal_Context_copy_decimal_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=639a82e1193d31f6 input=4db4f942f45fb7c9]*/ { PyObject *result; @@ -6939,14 +7060,15 @@ Return a copy of x with the sign inverted. [clinic start generated code]*/ static PyObject * -_decimal_Context_copy_negate(PyObject *context, PyObject *x) -/*[clinic end generated code: output=5fe136d7bac13391 input=2e6e213e2ed0efda]*/ +_decimal_Context_copy_negate_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=e49d013489dc252b input=2e6e213e2ed0efda]*/ { PyObject *result, *a; uint32_t status = 0; CONVERT_OP_RAISE(&a, x, context); - decimal_state *state = get_module_state_from_ctx(context); + decimal_state *state = PyType_GetModuleState(cls); result = dec_alloc(state); if (result == NULL) { Py_DECREF(a); @@ -6970,8 +7092,8 @@ Return the exponent of the magnitude of the operand's MSD. [clinic start generated code]*/ static PyObject * -_decimal_Context_logb(PyObject *context, PyObject *x) -/*[clinic end generated code: output=d2d8469f828daa41 input=28d1cd1a8a906b9a]*/ +_decimal_Context_logb_impl(PyObject *context, PyTypeObject *cls, PyObject *x) +/*[clinic end generated code: output=9b9697e1eb68093f input=28d1cd1a8a906b9a]*/ DecCtx_UnaryFunc(mpd_qlogb) /*[clinic input] @@ -6981,8 +7103,9 @@ Invert all digits of x. [clinic start generated code]*/ static PyObject * -_decimal_Context_logical_invert(PyObject *context, PyObject *x) -/*[clinic end generated code: output=b863a5cdb986f684 input=1fa8dcc59c557fcc]*/ +_decimal_Context_logical_invert_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=97760277a958e2b0 input=1fa8dcc59c557fcc]*/ DecCtx_UnaryFunc(mpd_qinvert) /*[clinic input] @@ -6992,8 +7115,9 @@ Return an indication of the class of x. [clinic start generated code]*/ static PyObject * -_decimal_Context_number_class(PyObject *context, PyObject *x) -/*[clinic end generated code: output=2b39fa98dd723c6f input=1ead8462f1800e4e]*/ +_decimal_Context_number_class_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=c1592a23e25ba5ee input=1ead8462f1800e4e]*/ { PyObject *a; const char *cp; @@ -7013,8 +7137,9 @@ Convert a number to a string using scientific notation. [clinic start generated code]*/ static PyObject * -_decimal_Context_to_sci_string(PyObject *context, PyObject *x) -/*[clinic end generated code: output=7d461d24824c6f15 input=ed442677c66d342d]*/ +_decimal_Context_to_sci_string_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=092dcdef999d72da input=ed442677c66d342d]*/ { PyObject *result; PyObject *a; @@ -7043,8 +7168,9 @@ Convert a number to a string, using engineering notation. [clinic start generated code]*/ static PyObject * -_decimal_Context_to_eng_string(PyObject *context, PyObject *x) -/*[clinic end generated code: output=3a54b9de0b01708f input=a574385e2e3e3bc0]*/ +_decimal_Context_to_eng_string_impl(PyObject *context, PyTypeObject *cls, + PyObject *x) +/*[clinic end generated code: output=7fc53216c208f487 input=a574385e2e3e3bc0]*/ { PyObject *result; PyObject *a; @@ -7072,6 +7198,7 @@ _decimal_Context_to_eng_string(PyObject *context, PyObject *x) _decimal.Context.compare_total self as context: self + cls: defining_class x: object y: object / @@ -7080,9 +7207,9 @@ Compare x and y using their abstract representation. [clinic start generated code]*/ static PyObject * -_decimal_Context_compare_total_impl(PyObject *context, PyObject *x, - PyObject *y) -/*[clinic end generated code: output=a9299ef125fb2245 input=020b30c9bc2ea2c6]*/ +_decimal_Context_compare_total_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=f79177b27fe930e3 input=2bfc677a841e297a]*/ DecCtx_BinaryFunc_NO_CTX(mpd_compare_total) /*[clinic input] @@ -7092,9 +7219,9 @@ Compare x and y using their abstract representation, ignoring sign. [clinic start generated code]*/ static PyObject * -_decimal_Context_compare_total_mag_impl(PyObject *context, PyObject *x, - PyObject *y) -/*[clinic end generated code: output=7c376de9f94feeaf input=2b982e69f932dcb2]*/ +_decimal_Context_compare_total_mag_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=2528c669ccd6d6ff input=2b982e69f932dcb2]*/ DecCtx_BinaryFunc_NO_CTX(mpd_compare_total_mag) /*[clinic input] @@ -7104,15 +7231,16 @@ Copy the sign from y to x. [clinic start generated code]*/ static PyObject * -_decimal_Context_copy_sign_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=fff3c5c474acf78e input=c0682aeaffc7cfdf]*/ +_decimal_Context_copy_sign_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=77d23b6f4e42120c input=c0682aeaffc7cfdf]*/ { PyObject *a, *b; PyObject *result; uint32_t status = 0; CONVERT_BINOP_RAISE(&a, &b, x, y, context); - decimal_state *state = get_module_state_from_ctx(context); + decimal_state *state = PyType_GetModuleState(cls); result = dec_alloc(state); if (result == NULL) { Py_DECREF(a); @@ -7138,9 +7266,9 @@ Digit-wise and of x and y. [clinic start generated code]*/ static PyObject * -_decimal_Context_logical_and_impl(PyObject *context, PyObject *x, - PyObject *y) -/*[clinic end generated code: output=f1e9bf7844a395fc input=30ee33b5b365fd80]*/ +_decimal_Context_logical_and_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=009dfa08ecaa2ac8 input=30ee33b5b365fd80]*/ DecCtx_BinaryFunc(mpd_qand) /*[clinic input] @@ -7150,8 +7278,9 @@ Digit-wise or of x and y. [clinic start generated code]*/ static PyObject * -_decimal_Context_logical_or_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=28f7ecd1af3262f0 input=3b1a6725d0262fb9]*/ +_decimal_Context_logical_or_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=eb38617e8d31bf12 input=3b1a6725d0262fb9]*/ DecCtx_BinaryFunc(mpd_qor) /*[clinic input] @@ -7161,9 +7290,9 @@ Digit-wise xor of x and y. [clinic start generated code]*/ static PyObject * -_decimal_Context_logical_xor_impl(PyObject *context, PyObject *x, - PyObject *y) -/*[clinic end generated code: output=7d8461ace42d1871 input=5ebbbe8bb35da380]*/ +_decimal_Context_logical_xor_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=23cd81fdcd865d5a input=5ebbbe8bb35da380]*/ DecCtx_BinaryFunc(mpd_qxor) /*[clinic input] @@ -7173,8 +7302,9 @@ Return a copy of x, rotated by y places. [clinic start generated code]*/ static PyObject * -_decimal_Context_rotate_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=6d8b718f218712a2 input=7ad91845c909eb0a]*/ +_decimal_Context_rotate_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=3d5b3cfcb4659432 input=7ad91845c909eb0a]*/ DecCtx_BinaryFunc(mpd_qrotate) /*[clinic input] @@ -7184,8 +7314,9 @@ Return the first operand after adding the second value to its exp. [clinic start generated code]*/ static PyObject * -_decimal_Context_scaleb_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=3c9cb117027c7722 input=c5d2ee7a57f65f8c]*/ +_decimal_Context_scaleb_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=795ac61bcbe61c67 input=c5d2ee7a57f65f8c]*/ DecCtx_BinaryFunc(mpd_qscaleb) /*[clinic input] @@ -7195,8 +7326,9 @@ Return a copy of x, shifted by y places. [clinic start generated code]*/ static PyObject * -_decimal_Context_shift_impl(PyObject *context, PyObject *x, PyObject *y) -/*[clinic end generated code: output=78625878a264b3e5 input=1ab44ff0854420ce]*/ +_decimal_Context_shift_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=43d69615f0271c81 input=1ab44ff0854420ce]*/ DecCtx_BinaryFunc(mpd_qshift) /*[clinic input] @@ -7206,9 +7338,9 @@ Return True if the two operands have the same exponent. [clinic start generated code]*/ static PyObject * -_decimal_Context_same_quantum_impl(PyObject *context, PyObject *x, - PyObject *y) -/*[clinic end generated code: output=137acab27ece605c input=194cd156e398eaf9]*/ +_decimal_Context_same_quantum_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y) +/*[clinic end generated code: output=91a4d8325f98d9e9 input=194cd156e398eaf9]*/ { PyObject *a, *b; PyObject *result; @@ -7310,16 +7442,14 @@ static PyMethodDef context_methods [] = _DECIMAL_CONTEXT_CLEAR_FLAGS_METHODDEF _DECIMAL_CONTEXT_CLEAR_TRAPS_METHODDEF -#ifdef CONFIG_32 /* Unsafe set functions with relaxed range checks */ - { "_unsafe_setprec", context_unsafe_setprec, METH_O, NULL }, - { "_unsafe_setemin", context_unsafe_setemin, METH_O, NULL }, - { "_unsafe_setemax", context_unsafe_setemax, METH_O, NULL }, -#endif + _DECIMAL_CONTEXT__UNSAFE_SETPREC_METHODDEF + _DECIMAL_CONTEXT__UNSAFE_SETEMIN_METHODDEF + _DECIMAL_CONTEXT__UNSAFE_SETEMAX_METHODDEF /* Miscellaneous */ - { "__copy__", context_copy, METH_NOARGS, NULL }, - { "__reduce__", context_reduce, METH_NOARGS, NULL }, + _DECIMAL_CONTEXT___COPY___METHODDEF + _DECIMAL_CONTEXT___REDUCE___METHODDEF _DECIMAL_CONTEXT_COPY_METHODDEF _DECIMAL_CONTEXT_CREATE_DECIMAL_METHODDEF _DECIMAL_CONTEXT_CREATE_DECIMAL_FROM_FLOAT_METHODDEF diff --git a/Modules/_decimal/clinic/_decimal.c.h b/Modules/_decimal/clinic/_decimal.c.h index 0f7a7f78cd73e5..ccfbf63a7cead5 100644 --- a/Modules/_decimal/clinic/_decimal.c.h +++ b/Modules/_decimal/clinic/_decimal.c.h @@ -51,6 +51,123 @@ _decimal_Context_Etop(PyObject *self, PyObject *Py_UNUSED(ignored)) return _decimal_Context_Etop_impl(self); } +#if defined(CONFIG_32) + +PyDoc_STRVAR(_decimal_Context__unsafe_setprec__doc__, +"_unsafe_setprec($self, x, /)\n" +"--\n" +"\n"); + +#define _DECIMAL_CONTEXT__UNSAFE_SETPREC_METHODDEF \ + {"_unsafe_setprec", (PyCFunction)_decimal_Context__unsafe_setprec, METH_O, _decimal_Context__unsafe_setprec__doc__}, + +static PyObject * +_decimal_Context__unsafe_setprec_impl(PyObject *self, Py_ssize_t x); + +static PyObject * +_decimal_Context__unsafe_setprec(PyObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + Py_ssize_t x; + + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(arg); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + x = ival; + } + return_value = _decimal_Context__unsafe_setprec_impl(self, x); + +exit: + return return_value; +} + +#endif /* defined(CONFIG_32) */ + +#if defined(CONFIG_32) + +PyDoc_STRVAR(_decimal_Context__unsafe_setemin__doc__, +"_unsafe_setemin($self, x, /)\n" +"--\n" +"\n"); + +#define _DECIMAL_CONTEXT__UNSAFE_SETEMIN_METHODDEF \ + {"_unsafe_setemin", (PyCFunction)_decimal_Context__unsafe_setemin, METH_O, _decimal_Context__unsafe_setemin__doc__}, + +static PyObject * +_decimal_Context__unsafe_setemin_impl(PyObject *self, Py_ssize_t x); + +static PyObject * +_decimal_Context__unsafe_setemin(PyObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + Py_ssize_t x; + + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(arg); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + x = ival; + } + return_value = _decimal_Context__unsafe_setemin_impl(self, x); + +exit: + return return_value; +} + +#endif /* defined(CONFIG_32) */ + +#if defined(CONFIG_32) + +PyDoc_STRVAR(_decimal_Context__unsafe_setemax__doc__, +"_unsafe_setemax($self, x, /)\n" +"--\n" +"\n"); + +#define _DECIMAL_CONTEXT__UNSAFE_SETEMAX_METHODDEF \ + {"_unsafe_setemax", (PyCFunction)_decimal_Context__unsafe_setemax, METH_O, _decimal_Context__unsafe_setemax__doc__}, + +static PyObject * +_decimal_Context__unsafe_setemax_impl(PyObject *self, Py_ssize_t x); + +static PyObject * +_decimal_Context__unsafe_setemax(PyObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + Py_ssize_t x; + + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(arg); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + x = ival; + } + return_value = _decimal_Context__unsafe_setemax_impl(self, x); + +exit: + return return_value; +} + +#endif /* defined(CONFIG_32) */ + PyDoc_STRVAR(_decimal_Context_clear_traps__doc__, "clear_traps($self, /)\n" "--\n" @@ -257,15 +374,61 @@ PyDoc_STRVAR(_decimal_Context_copy__doc__, "Return a duplicate of the context with all flags cleared."); #define _DECIMAL_CONTEXT_COPY_METHODDEF \ - {"copy", (PyCFunction)_decimal_Context_copy, METH_NOARGS, _decimal_Context_copy__doc__}, + {"copy", _PyCFunction_CAST(_decimal_Context_copy), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_copy__doc__}, + +static PyObject * +_decimal_Context_copy_impl(PyObject *self, PyTypeObject *cls); + +static PyObject * +_decimal_Context_copy(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { + PyErr_SetString(PyExc_TypeError, "copy() takes no arguments"); + return NULL; + } + return _decimal_Context_copy_impl(self, cls); +} + +PyDoc_STRVAR(_decimal_Context___copy____doc__, +"__copy__($self, /)\n" +"--\n" +"\n"); + +#define _DECIMAL_CONTEXT___COPY___METHODDEF \ + {"__copy__", _PyCFunction_CAST(_decimal_Context___copy__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context___copy____doc__}, static PyObject * -_decimal_Context_copy_impl(PyObject *self); +_decimal_Context___copy___impl(PyObject *self, PyTypeObject *cls); static PyObject * -_decimal_Context_copy(PyObject *self, PyObject *Py_UNUSED(ignored)) +_decimal_Context___copy__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _decimal_Context_copy_impl(self); + if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { + PyErr_SetString(PyExc_TypeError, "__copy__() takes no arguments"); + return NULL; + } + return _decimal_Context___copy___impl(self, cls); +} + +PyDoc_STRVAR(_decimal_Context___reduce____doc__, +"__reduce__($self, /)\n" +"--\n" +"\n"); + +#define _DECIMAL_CONTEXT___REDUCE___METHODDEF \ + {"__reduce__", _PyCFunction_CAST(_decimal_Context___reduce__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context___reduce____doc__}, + +static PyObject * +_decimal_Context___reduce___impl(PyObject *self, PyTypeObject *cls); + +static PyObject * +_decimal_Context___reduce__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { + PyErr_SetString(PyExc_TypeError, "__reduce__() takes no arguments"); + return NULL; + } + return _decimal_Context___reduce___impl(self, cls); } PyDoc_STRVAR(_decimal_getcontext__doc__, @@ -445,18 +608,41 @@ PyDoc_STRVAR(_decimal_Decimal_from_float__doc__, " Decimal(\'-Infinity\')"); #define _DECIMAL_DECIMAL_FROM_FLOAT_METHODDEF \ - {"from_float", (PyCFunction)_decimal_Decimal_from_float, METH_O|METH_CLASS, _decimal_Decimal_from_float__doc__}, + {"from_float", _PyCFunction_CAST(_decimal_Decimal_from_float), METH_METHOD|METH_FASTCALL|METH_KEYWORDS|METH_CLASS, _decimal_Decimal_from_float__doc__}, static PyObject * -_decimal_Decimal_from_float_impl(PyTypeObject *type, PyObject *pyfloat); +_decimal_Decimal_from_float_impl(PyTypeObject *type, PyTypeObject *cls, + PyObject *pyfloat); static PyObject * -_decimal_Decimal_from_float(PyObject *type, PyObject *pyfloat) +_decimal_Decimal_from_float(PyObject *type, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "from_float", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *pyfloat; - return_value = _decimal_Decimal_from_float_impl((PyTypeObject *)type, pyfloat); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + pyfloat = args[0]; + return_value = _decimal_Decimal_from_float_impl((PyTypeObject *)type, cls, pyfloat); +exit: return return_value; } @@ -474,18 +660,41 @@ PyDoc_STRVAR(_decimal_Decimal_from_number__doc__, " Decimal(\'3.14\')"); #define _DECIMAL_DECIMAL_FROM_NUMBER_METHODDEF \ - {"from_number", (PyCFunction)_decimal_Decimal_from_number, METH_O|METH_CLASS, _decimal_Decimal_from_number__doc__}, + {"from_number", _PyCFunction_CAST(_decimal_Decimal_from_number), METH_METHOD|METH_FASTCALL|METH_KEYWORDS|METH_CLASS, _decimal_Decimal_from_number__doc__}, static PyObject * -_decimal_Decimal_from_number_impl(PyTypeObject *type, PyObject *number); +_decimal_Decimal_from_number_impl(PyTypeObject *type, PyTypeObject *cls, + PyObject *number); static PyObject * -_decimal_Decimal_from_number(PyObject *type, PyObject *number) +_decimal_Decimal_from_number(PyObject *type, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "from_number", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *number; - return_value = _decimal_Decimal_from_number_impl((PyTypeObject *)type, number); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + number = args[0]; + return_value = _decimal_Decimal_from_number_impl((PyTypeObject *)type, cls, number); +exit: return return_value; } @@ -499,7 +708,44 @@ PyDoc_STRVAR(_decimal_Context_create_decimal_from_float__doc__, "the context limits."); #define _DECIMAL_CONTEXT_CREATE_DECIMAL_FROM_FLOAT_METHODDEF \ - {"create_decimal_from_float", (PyCFunction)_decimal_Context_create_decimal_from_float, METH_O, _decimal_Context_create_decimal_from_float__doc__}, + {"create_decimal_from_float", _PyCFunction_CAST(_decimal_Context_create_decimal_from_float), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_create_decimal_from_float__doc__}, + +static PyObject * +_decimal_Context_create_decimal_from_float_impl(PyObject *context, + PyTypeObject *cls, + PyObject *f); + +static PyObject * +_decimal_Context_create_decimal_from_float(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "create_decimal_from_float", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *f; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + f = args[0]; + return_value = _decimal_Context_create_decimal_from_float_impl(context, cls, f); + +exit: + return return_value; +} PyDoc_STRVAR(dec_new__doc__, "Decimal(value=\'0\', context=None)\n" @@ -617,20 +863,36 @@ PyDoc_STRVAR(_decimal_Decimal___format____doc__, "Formats the Decimal according to format_spec."); #define _DECIMAL_DECIMAL___FORMAT___METHODDEF \ - {"__format__", _PyCFunction_CAST(_decimal_Decimal___format__), METH_FASTCALL, _decimal_Decimal___format____doc__}, + {"__format__", _PyCFunction_CAST(_decimal_Decimal___format__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal___format____doc__}, static PyObject * -_decimal_Decimal___format___impl(PyObject *dec, PyObject *fmtarg, - PyObject *override); +_decimal_Decimal___format___impl(PyObject *dec, PyTypeObject *cls, + PyObject *fmtarg, PyObject *override); static PyObject * -_decimal_Decimal___format__(PyObject *dec, PyObject *const *args, Py_ssize_t nargs) +_decimal_Decimal___format__(PyObject *dec, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "__format__", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *fmtarg; PyObject *override = NULL; - if (!_PyArg_CheckPositional("__format__", nargs, 1, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } if (!PyUnicode_Check(args[0])) { @@ -639,11 +901,11 @@ _decimal_Decimal___format__(PyObject *dec, PyObject *const *args, Py_ssize_t nar } fmtarg = args[0]; if (nargs < 2) { - goto skip_optional; + goto skip_optional_posonly; } override = args[1]; -skip_optional: - return_value = _decimal_Decimal___format___impl(dec, fmtarg, override); +skip_optional_posonly: + return_value = _decimal_Decimal___format___impl(dec, cls, fmtarg, override); exit: return return_value; @@ -659,15 +921,19 @@ PyDoc_STRVAR(_decimal_Decimal_as_integer_ratio__doc__, "Raise OverflowError on infinities and a ValueError on NaNs."); #define _DECIMAL_DECIMAL_AS_INTEGER_RATIO_METHODDEF \ - {"as_integer_ratio", (PyCFunction)_decimal_Decimal_as_integer_ratio, METH_NOARGS, _decimal_Decimal_as_integer_ratio__doc__}, + {"as_integer_ratio", _PyCFunction_CAST(_decimal_Decimal_as_integer_ratio), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_as_integer_ratio__doc__}, static PyObject * -_decimal_Decimal_as_integer_ratio_impl(PyObject *self); +_decimal_Decimal_as_integer_ratio_impl(PyObject *self, PyTypeObject *cls); static PyObject * -_decimal_Decimal_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored)) +_decimal_Decimal_as_integer_ratio(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _decimal_Decimal_as_integer_ratio_impl(self); + if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { + PyErr_SetString(PyExc_TypeError, "as_integer_ratio() takes no arguments"); + return NULL; + } + return _decimal_Decimal_as_integer_ratio_impl(self, cls); } PyDoc_STRVAR(_decimal_Decimal_to_integral_value__doc__, @@ -681,14 +947,15 @@ PyDoc_STRVAR(_decimal_Decimal_to_integral_value__doc__, "rounding mode of the current default context is used."); #define _DECIMAL_DECIMAL_TO_INTEGRAL_VALUE_METHODDEF \ - {"to_integral_value", _PyCFunction_CAST(_decimal_Decimal_to_integral_value), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_to_integral_value__doc__}, + {"to_integral_value", _PyCFunction_CAST(_decimal_Decimal_to_integral_value), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_to_integral_value__doc__}, static PyObject * -_decimal_Decimal_to_integral_value_impl(PyObject *self, PyObject *rounding, +_decimal_Decimal_to_integral_value_impl(PyObject *self, PyTypeObject *cls, + PyObject *rounding, PyObject *context); static PyObject * -_decimal_Decimal_to_integral_value(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_to_integral_value(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -739,7 +1006,7 @@ _decimal_Decimal_to_integral_value(PyObject *self, PyObject *const *args, Py_ssi } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_to_integral_value_impl(self, rounding, context); + return_value = _decimal_Decimal_to_integral_value_impl(self, cls, rounding, context); exit: return return_value; @@ -755,14 +1022,14 @@ PyDoc_STRVAR(_decimal_Decimal_to_integral__doc__, "versions."); #define _DECIMAL_DECIMAL_TO_INTEGRAL_METHODDEF \ - {"to_integral", _PyCFunction_CAST(_decimal_Decimal_to_integral), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_to_integral__doc__}, + {"to_integral", _PyCFunction_CAST(_decimal_Decimal_to_integral), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_to_integral__doc__}, static PyObject * -_decimal_Decimal_to_integral_impl(PyObject *self, PyObject *rounding, - PyObject *context); +_decimal_Decimal_to_integral_impl(PyObject *self, PyTypeObject *cls, + PyObject *rounding, PyObject *context); static PyObject * -_decimal_Decimal_to_integral(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_to_integral(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -813,7 +1080,7 @@ _decimal_Decimal_to_integral(PyObject *self, PyObject *const *args, Py_ssize_t n } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_to_integral_impl(self, rounding, context); + return_value = _decimal_Decimal_to_integral_impl(self, cls, rounding, context); exit: return return_value; @@ -831,14 +1098,15 @@ PyDoc_STRVAR(_decimal_Decimal_to_integral_exact__doc__, "given, then the rounding mode of the current default context is used."); #define _DECIMAL_DECIMAL_TO_INTEGRAL_EXACT_METHODDEF \ - {"to_integral_exact", _PyCFunction_CAST(_decimal_Decimal_to_integral_exact), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_to_integral_exact__doc__}, + {"to_integral_exact", _PyCFunction_CAST(_decimal_Decimal_to_integral_exact), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_to_integral_exact__doc__}, static PyObject * -_decimal_Decimal_to_integral_exact_impl(PyObject *self, PyObject *rounding, +_decimal_Decimal_to_integral_exact_impl(PyObject *self, PyTypeObject *cls, + PyObject *rounding, PyObject *context); static PyObject * -_decimal_Decimal_to_integral_exact(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_to_integral_exact(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -889,7 +1157,7 @@ _decimal_Decimal_to_integral_exact(PyObject *self, PyObject *const *args, Py_ssi } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_to_integral_exact_impl(self, rounding, context); + return_value = _decimal_Decimal_to_integral_exact_impl(self, cls, rounding, context); exit: return return_value; @@ -902,26 +1170,43 @@ PyDoc_STRVAR(_decimal_Decimal___round____doc__, "Return the Integral closest to self, rounding half toward even."); #define _DECIMAL_DECIMAL___ROUND___METHODDEF \ - {"__round__", _PyCFunction_CAST(_decimal_Decimal___round__), METH_FASTCALL, _decimal_Decimal___round____doc__}, + {"__round__", _PyCFunction_CAST(_decimal_Decimal___round__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal___round____doc__}, static PyObject * -_decimal_Decimal___round___impl(PyObject *self, PyObject *ndigits); +_decimal_Decimal___round___impl(PyObject *self, PyTypeObject *cls, + PyObject *ndigits); static PyObject * -_decimal_Decimal___round__(PyObject *self, PyObject *const *args, Py_ssize_t nargs) +_decimal_Decimal___round__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "__round__", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; PyObject *ndigits = NULL; - if (!_PyArg_CheckPositional("__round__", nargs, 0, 1)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } if (nargs < 1) { - goto skip_optional; + goto skip_optional_posonly; } ndigits = args[0]; -skip_optional: - return_value = _decimal_Decimal___round___impl(self, ndigits); +skip_optional_posonly: + return_value = _decimal_Decimal___round___impl(self, cls, ndigits); exit: return return_value; @@ -934,15 +1219,19 @@ PyDoc_STRVAR(_decimal_Decimal_as_tuple__doc__, "Return a tuple representation of the number."); #define _DECIMAL_DECIMAL_AS_TUPLE_METHODDEF \ - {"as_tuple", (PyCFunction)_decimal_Decimal_as_tuple, METH_NOARGS, _decimal_Decimal_as_tuple__doc__}, + {"as_tuple", _PyCFunction_CAST(_decimal_Decimal_as_tuple), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_as_tuple__doc__}, static PyObject * -_decimal_Decimal_as_tuple_impl(PyObject *self); +_decimal_Decimal_as_tuple_impl(PyObject *self, PyTypeObject *cls); static PyObject * -_decimal_Decimal_as_tuple(PyObject *self, PyObject *Py_UNUSED(ignored)) +_decimal_Decimal_as_tuple(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _decimal_Decimal_as_tuple_impl(self); + if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { + PyErr_SetString(PyExc_TypeError, "as_tuple() takes no arguments"); + return NULL; + } + return _decimal_Decimal_as_tuple_impl(self, cls); } PyDoc_STRVAR(_decimal_Decimal_exp__doc__, @@ -955,13 +1244,14 @@ PyDoc_STRVAR(_decimal_Decimal_exp__doc__, "correctly rounded."); #define _DECIMAL_DECIMAL_EXP_METHODDEF \ - {"exp", _PyCFunction_CAST(_decimal_Decimal_exp), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_exp__doc__}, + {"exp", _PyCFunction_CAST(_decimal_Decimal_exp), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_exp__doc__}, static PyObject * -_decimal_Decimal_exp_impl(PyObject *self, PyObject *context); +_decimal_Decimal_exp_impl(PyObject *self, PyTypeObject *cls, + PyObject *context); static PyObject * -_decimal_Decimal_exp(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_exp(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1005,7 +1295,7 @@ _decimal_Decimal_exp(PyObject *self, PyObject *const *args, Py_ssize_t nargs, Py } context = args[0]; skip_optional_pos: - return_value = _decimal_Decimal_exp_impl(self, context); + return_value = _decimal_Decimal_exp_impl(self, cls, context); exit: return return_value; @@ -1021,13 +1311,14 @@ PyDoc_STRVAR(_decimal_Decimal_ln__doc__, "correctly rounded."); #define _DECIMAL_DECIMAL_LN_METHODDEF \ - {"ln", _PyCFunction_CAST(_decimal_Decimal_ln), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_ln__doc__}, + {"ln", _PyCFunction_CAST(_decimal_Decimal_ln), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_ln__doc__}, static PyObject * -_decimal_Decimal_ln_impl(PyObject *self, PyObject *context); +_decimal_Decimal_ln_impl(PyObject *self, PyTypeObject *cls, + PyObject *context); static PyObject * -_decimal_Decimal_ln(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_ln(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1071,7 +1362,7 @@ _decimal_Decimal_ln(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyO } context = args[0]; skip_optional_pos: - return_value = _decimal_Decimal_ln_impl(self, context); + return_value = _decimal_Decimal_ln_impl(self, cls, context); exit: return return_value; @@ -1087,13 +1378,14 @@ PyDoc_STRVAR(_decimal_Decimal_log10__doc__, "correctly rounded."); #define _DECIMAL_DECIMAL_LOG10_METHODDEF \ - {"log10", _PyCFunction_CAST(_decimal_Decimal_log10), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_log10__doc__}, + {"log10", _PyCFunction_CAST(_decimal_Decimal_log10), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_log10__doc__}, static PyObject * -_decimal_Decimal_log10_impl(PyObject *self, PyObject *context); +_decimal_Decimal_log10_impl(PyObject *self, PyTypeObject *cls, + PyObject *context); static PyObject * -_decimal_Decimal_log10(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_log10(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1137,7 +1429,7 @@ _decimal_Decimal_log10(PyObject *self, PyObject *const *args, Py_ssize_t nargs, } context = args[0]; skip_optional_pos: - return_value = _decimal_Decimal_log10_impl(self, context); + return_value = _decimal_Decimal_log10_impl(self, cls, context); exit: return return_value; @@ -1150,13 +1442,14 @@ PyDoc_STRVAR(_decimal_Decimal_next_minus__doc__, "Returns the largest representable number smaller than itself."); #define _DECIMAL_DECIMAL_NEXT_MINUS_METHODDEF \ - {"next_minus", _PyCFunction_CAST(_decimal_Decimal_next_minus), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_next_minus__doc__}, + {"next_minus", _PyCFunction_CAST(_decimal_Decimal_next_minus), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_next_minus__doc__}, static PyObject * -_decimal_Decimal_next_minus_impl(PyObject *self, PyObject *context); +_decimal_Decimal_next_minus_impl(PyObject *self, PyTypeObject *cls, + PyObject *context); static PyObject * -_decimal_Decimal_next_minus(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_next_minus(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1200,7 +1493,7 @@ _decimal_Decimal_next_minus(PyObject *self, PyObject *const *args, Py_ssize_t na } context = args[0]; skip_optional_pos: - return_value = _decimal_Decimal_next_minus_impl(self, context); + return_value = _decimal_Decimal_next_minus_impl(self, cls, context); exit: return return_value; @@ -1213,13 +1506,14 @@ PyDoc_STRVAR(_decimal_Decimal_next_plus__doc__, "Returns the smallest representable number larger than itself."); #define _DECIMAL_DECIMAL_NEXT_PLUS_METHODDEF \ - {"next_plus", _PyCFunction_CAST(_decimal_Decimal_next_plus), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_next_plus__doc__}, + {"next_plus", _PyCFunction_CAST(_decimal_Decimal_next_plus), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_next_plus__doc__}, static PyObject * -_decimal_Decimal_next_plus_impl(PyObject *self, PyObject *context); +_decimal_Decimal_next_plus_impl(PyObject *self, PyTypeObject *cls, + PyObject *context); static PyObject * -_decimal_Decimal_next_plus(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_next_plus(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1263,7 +1557,7 @@ _decimal_Decimal_next_plus(PyObject *self, PyObject *const *args, Py_ssize_t nar } context = args[0]; skip_optional_pos: - return_value = _decimal_Decimal_next_plus_impl(self, context); + return_value = _decimal_Decimal_next_plus_impl(self, cls, context); exit: return return_value; @@ -1281,13 +1575,14 @@ PyDoc_STRVAR(_decimal_Decimal_normalize__doc__, "the equivalent value Decimal(\'32.1\')."); #define _DECIMAL_DECIMAL_NORMALIZE_METHODDEF \ - {"normalize", _PyCFunction_CAST(_decimal_Decimal_normalize), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_normalize__doc__}, + {"normalize", _PyCFunction_CAST(_decimal_Decimal_normalize), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_normalize__doc__}, static PyObject * -_decimal_Decimal_normalize_impl(PyObject *self, PyObject *context); +_decimal_Decimal_normalize_impl(PyObject *self, PyTypeObject *cls, + PyObject *context); static PyObject * -_decimal_Decimal_normalize(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_normalize(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1331,7 +1626,7 @@ _decimal_Decimal_normalize(PyObject *self, PyObject *const *args, Py_ssize_t nar } context = args[0]; skip_optional_pos: - return_value = _decimal_Decimal_normalize_impl(self, context); + return_value = _decimal_Decimal_normalize_impl(self, cls, context); exit: return return_value; @@ -1346,13 +1641,14 @@ PyDoc_STRVAR(_decimal_Decimal_sqrt__doc__, "The result is correctly rounded using the ROUND_HALF_EVEN rounding mode."); #define _DECIMAL_DECIMAL_SQRT_METHODDEF \ - {"sqrt", _PyCFunction_CAST(_decimal_Decimal_sqrt), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_sqrt__doc__}, + {"sqrt", _PyCFunction_CAST(_decimal_Decimal_sqrt), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_sqrt__doc__}, static PyObject * -_decimal_Decimal_sqrt_impl(PyObject *self, PyObject *context); +_decimal_Decimal_sqrt_impl(PyObject *self, PyTypeObject *cls, + PyObject *context); static PyObject * -_decimal_Decimal_sqrt(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_sqrt(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1396,7 +1692,7 @@ _decimal_Decimal_sqrt(PyObject *self, PyObject *const *args, Py_ssize_t nargs, P } context = args[0]; skip_optional_pos: - return_value = _decimal_Decimal_sqrt_impl(self, context); + return_value = _decimal_Decimal_sqrt_impl(self, cls, context); exit: return return_value; @@ -1416,14 +1712,14 @@ PyDoc_STRVAR(_decimal_Decimal_compare__doc__, " a > b ==> Decimal(\'1\')"); #define _DECIMAL_DECIMAL_COMPARE_METHODDEF \ - {"compare", _PyCFunction_CAST(_decimal_Decimal_compare), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_compare__doc__}, + {"compare", _PyCFunction_CAST(_decimal_Decimal_compare), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_compare__doc__}, static PyObject * -_decimal_Decimal_compare_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_compare_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_compare(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_compare(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1469,7 +1765,7 @@ _decimal_Decimal_compare(PyObject *self, PyObject *const *args, Py_ssize_t nargs } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_compare_impl(self, other, context); + return_value = _decimal_Decimal_compare_impl(self, cls, other, context); exit: return return_value; @@ -1482,14 +1778,14 @@ PyDoc_STRVAR(_decimal_Decimal_compare_signal__doc__, "Identical to compare, except that all NaNs signal."); #define _DECIMAL_DECIMAL_COMPARE_SIGNAL_METHODDEF \ - {"compare_signal", _PyCFunction_CAST(_decimal_Decimal_compare_signal), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_compare_signal__doc__}, + {"compare_signal", _PyCFunction_CAST(_decimal_Decimal_compare_signal), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_compare_signal__doc__}, static PyObject * -_decimal_Decimal_compare_signal_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_compare_signal_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_compare_signal(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_compare_signal(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1535,7 +1831,7 @@ _decimal_Decimal_compare_signal(PyObject *self, PyObject *const *args, Py_ssize_ } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_compare_signal_impl(self, other, context); + return_value = _decimal_Decimal_compare_signal_impl(self, cls, other, context); exit: return return_value; @@ -1551,13 +1847,14 @@ PyDoc_STRVAR(_decimal_Decimal_max__doc__, "operand is returned."); #define _DECIMAL_DECIMAL_MAX_METHODDEF \ - {"max", _PyCFunction_CAST(_decimal_Decimal_max), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_max__doc__}, + {"max", _PyCFunction_CAST(_decimal_Decimal_max), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_max__doc__}, static PyObject * -_decimal_Decimal_max_impl(PyObject *self, PyObject *other, PyObject *context); +_decimal_Decimal_max_impl(PyObject *self, PyTypeObject *cls, PyObject *other, + PyObject *context); static PyObject * -_decimal_Decimal_max(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_max(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1603,7 +1900,7 @@ _decimal_Decimal_max(PyObject *self, PyObject *const *args, Py_ssize_t nargs, Py } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_max_impl(self, other, context); + return_value = _decimal_Decimal_max_impl(self, cls, other, context); exit: return return_value; @@ -1616,14 +1913,14 @@ PyDoc_STRVAR(_decimal_Decimal_max_mag__doc__, "As the max() method, but compares the absolute values of the operands."); #define _DECIMAL_DECIMAL_MAX_MAG_METHODDEF \ - {"max_mag", _PyCFunction_CAST(_decimal_Decimal_max_mag), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_max_mag__doc__}, + {"max_mag", _PyCFunction_CAST(_decimal_Decimal_max_mag), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_max_mag__doc__}, static PyObject * -_decimal_Decimal_max_mag_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_max_mag_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_max_mag(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_max_mag(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1669,7 +1966,7 @@ _decimal_Decimal_max_mag(PyObject *self, PyObject *const *args, Py_ssize_t nargs } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_max_mag_impl(self, other, context); + return_value = _decimal_Decimal_max_mag_impl(self, cls, other, context); exit: return return_value; @@ -1685,13 +1982,14 @@ PyDoc_STRVAR(_decimal_Decimal_min__doc__, "operand is returned."); #define _DECIMAL_DECIMAL_MIN_METHODDEF \ - {"min", _PyCFunction_CAST(_decimal_Decimal_min), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_min__doc__}, + {"min", _PyCFunction_CAST(_decimal_Decimal_min), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_min__doc__}, static PyObject * -_decimal_Decimal_min_impl(PyObject *self, PyObject *other, PyObject *context); +_decimal_Decimal_min_impl(PyObject *self, PyTypeObject *cls, PyObject *other, + PyObject *context); static PyObject * -_decimal_Decimal_min(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_min(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1737,7 +2035,7 @@ _decimal_Decimal_min(PyObject *self, PyObject *const *args, Py_ssize_t nargs, Py } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_min_impl(self, other, context); + return_value = _decimal_Decimal_min_impl(self, cls, other, context); exit: return return_value; @@ -1750,14 +2048,14 @@ PyDoc_STRVAR(_decimal_Decimal_min_mag__doc__, "As the min() method, but compares the absolute values of the operands."); #define _DECIMAL_DECIMAL_MIN_MAG_METHODDEF \ - {"min_mag", _PyCFunction_CAST(_decimal_Decimal_min_mag), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_min_mag__doc__}, + {"min_mag", _PyCFunction_CAST(_decimal_Decimal_min_mag), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_min_mag__doc__}, static PyObject * -_decimal_Decimal_min_mag_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_min_mag_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_min_mag(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_min_mag(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1803,7 +2101,7 @@ _decimal_Decimal_min_mag(PyObject *self, PyObject *const *args, Py_ssize_t nargs } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_min_mag_impl(self, other, context); + return_value = _decimal_Decimal_min_mag_impl(self, cls, other, context); exit: return return_value; @@ -1821,14 +2119,14 @@ PyDoc_STRVAR(_decimal_Decimal_next_toward__doc__, "to be the same as the sign of the second operand."); #define _DECIMAL_DECIMAL_NEXT_TOWARD_METHODDEF \ - {"next_toward", _PyCFunction_CAST(_decimal_Decimal_next_toward), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_next_toward__doc__}, + {"next_toward", _PyCFunction_CAST(_decimal_Decimal_next_toward), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_next_toward__doc__}, static PyObject * -_decimal_Decimal_next_toward_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_next_toward_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_next_toward(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_next_toward(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1874,7 +2172,7 @@ _decimal_Decimal_next_toward(PyObject *self, PyObject *const *args, Py_ssize_t n } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_next_toward_impl(self, other, context); + return_value = _decimal_Decimal_next_toward_impl(self, cls, other, context); exit: return return_value; @@ -1895,14 +2193,14 @@ PyDoc_STRVAR(_decimal_Decimal_remainder_near__doc__, "If the result is zero then its sign will be the sign of self."); #define _DECIMAL_DECIMAL_REMAINDER_NEAR_METHODDEF \ - {"remainder_near", _PyCFunction_CAST(_decimal_Decimal_remainder_near), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_remainder_near__doc__}, + {"remainder_near", _PyCFunction_CAST(_decimal_Decimal_remainder_near), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_remainder_near__doc__}, static PyObject * -_decimal_Decimal_remainder_near_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_remainder_near_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_remainder_near(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_remainder_near(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -1948,7 +2246,7 @@ _decimal_Decimal_remainder_near(PyObject *self, PyObject *const *args, Py_ssize_ } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_remainder_near_impl(self, other, context); + return_value = _decimal_Decimal_remainder_near_impl(self, cls, other, context); exit: return return_value; @@ -1967,14 +2265,14 @@ PyDoc_STRVAR(_decimal_Decimal_fma__doc__, " Decimal(\'11\')"); #define _DECIMAL_DECIMAL_FMA_METHODDEF \ - {"fma", _PyCFunction_CAST(_decimal_Decimal_fma), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_fma__doc__}, + {"fma", _PyCFunction_CAST(_decimal_Decimal_fma), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_fma__doc__}, static PyObject * -_decimal_Decimal_fma_impl(PyObject *self, PyObject *other, PyObject *third, - PyObject *context); +_decimal_Decimal_fma_impl(PyObject *self, PyTypeObject *cls, PyObject *other, + PyObject *third, PyObject *context); static PyObject * -_decimal_Decimal_fma(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_fma(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -2022,7 +2320,7 @@ _decimal_Decimal_fma(PyObject *self, PyObject *const *args, Py_ssize_t nargs, Py } context = args[2]; skip_optional_pos: - return_value = _decimal_Decimal_fma_impl(self, other, third, context); + return_value = _decimal_Decimal_fma_impl(self, cls, other, third, context); exit: return return_value; @@ -2186,13 +2484,14 @@ PyDoc_STRVAR(_decimal_Decimal_is_normal__doc__, "Normal number is a finite nonzero number, which is not subnormal."); #define _DECIMAL_DECIMAL_IS_NORMAL_METHODDEF \ - {"is_normal", _PyCFunction_CAST(_decimal_Decimal_is_normal), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_is_normal__doc__}, + {"is_normal", _PyCFunction_CAST(_decimal_Decimal_is_normal), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_is_normal__doc__}, static PyObject * -_decimal_Decimal_is_normal_impl(PyObject *self, PyObject *context); +_decimal_Decimal_is_normal_impl(PyObject *self, PyTypeObject *cls, + PyObject *context); static PyObject * -_decimal_Decimal_is_normal(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_is_normal(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -2236,7 +2535,7 @@ _decimal_Decimal_is_normal(PyObject *self, PyObject *const *args, Py_ssize_t nar } context = args[0]; skip_optional_pos: - return_value = _decimal_Decimal_is_normal_impl(self, context); + return_value = _decimal_Decimal_is_normal_impl(self, cls, context); exit: return return_value; @@ -2252,13 +2551,14 @@ PyDoc_STRVAR(_decimal_Decimal_is_subnormal__doc__, "exponent less than Emin."); #define _DECIMAL_DECIMAL_IS_SUBNORMAL_METHODDEF \ - {"is_subnormal", _PyCFunction_CAST(_decimal_Decimal_is_subnormal), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_is_subnormal__doc__}, + {"is_subnormal", _PyCFunction_CAST(_decimal_Decimal_is_subnormal), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_is_subnormal__doc__}, static PyObject * -_decimal_Decimal_is_subnormal_impl(PyObject *self, PyObject *context); +_decimal_Decimal_is_subnormal_impl(PyObject *self, PyTypeObject *cls, + PyObject *context); static PyObject * -_decimal_Decimal_is_subnormal(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_is_subnormal(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -2302,7 +2602,7 @@ _decimal_Decimal_is_subnormal(PyObject *self, PyObject *const *args, Py_ssize_t } context = args[0]; skip_optional_pos: - return_value = _decimal_Decimal_is_subnormal_impl(self, context); + return_value = _decimal_Decimal_is_subnormal_impl(self, cls, context); exit: return return_value; @@ -2375,15 +2675,19 @@ PyDoc_STRVAR(_decimal_Decimal_radix__doc__, "all its arithmetic. Included for compatibility with the specification."); #define _DECIMAL_DECIMAL_RADIX_METHODDEF \ - {"radix", (PyCFunction)_decimal_Decimal_radix, METH_NOARGS, _decimal_Decimal_radix__doc__}, + {"radix", _PyCFunction_CAST(_decimal_Decimal_radix), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_radix__doc__}, static PyObject * -_decimal_Decimal_radix_impl(PyObject *self); +_decimal_Decimal_radix_impl(PyObject *self, PyTypeObject *cls); static PyObject * -_decimal_Decimal_radix(PyObject *self, PyObject *Py_UNUSED(ignored)) +_decimal_Decimal_radix(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _decimal_Decimal_radix_impl(self); + if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { + PyErr_SetString(PyExc_TypeError, "radix() takes no arguments"); + return NULL; + } + return _decimal_Decimal_radix_impl(self, cls); } PyDoc_STRVAR(_decimal_Decimal_copy_abs__doc__, @@ -2396,15 +2700,19 @@ PyDoc_STRVAR(_decimal_Decimal_copy_abs__doc__, "changed and no rounding is performed."); #define _DECIMAL_DECIMAL_COPY_ABS_METHODDEF \ - {"copy_abs", (PyCFunction)_decimal_Decimal_copy_abs, METH_NOARGS, _decimal_Decimal_copy_abs__doc__}, + {"copy_abs", _PyCFunction_CAST(_decimal_Decimal_copy_abs), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_copy_abs__doc__}, static PyObject * -_decimal_Decimal_copy_abs_impl(PyObject *self); +_decimal_Decimal_copy_abs_impl(PyObject *self, PyTypeObject *cls); static PyObject * -_decimal_Decimal_copy_abs(PyObject *self, PyObject *Py_UNUSED(ignored)) +_decimal_Decimal_copy_abs(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _decimal_Decimal_copy_abs_impl(self); + if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { + PyErr_SetString(PyExc_TypeError, "copy_abs() takes no arguments"); + return NULL; + } + return _decimal_Decimal_copy_abs_impl(self, cls); } PyDoc_STRVAR(_decimal_Decimal_copy_negate__doc__, @@ -2417,15 +2725,19 @@ PyDoc_STRVAR(_decimal_Decimal_copy_negate__doc__, "changed and no rounding is performed."); #define _DECIMAL_DECIMAL_COPY_NEGATE_METHODDEF \ - {"copy_negate", (PyCFunction)_decimal_Decimal_copy_negate, METH_NOARGS, _decimal_Decimal_copy_negate__doc__}, + {"copy_negate", _PyCFunction_CAST(_decimal_Decimal_copy_negate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_copy_negate__doc__}, static PyObject * -_decimal_Decimal_copy_negate_impl(PyObject *self); +_decimal_Decimal_copy_negate_impl(PyObject *self, PyTypeObject *cls); static PyObject * -_decimal_Decimal_copy_negate(PyObject *self, PyObject *Py_UNUSED(ignored)) +_decimal_Decimal_copy_negate(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _decimal_Decimal_copy_negate_impl(self); + if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { + PyErr_SetString(PyExc_TypeError, "copy_negate() takes no arguments"); + return NULL; + } + return _decimal_Decimal_copy_negate_impl(self, cls); } PyDoc_STRVAR(_decimal_Decimal_logical_invert__doc__, @@ -2435,13 +2747,14 @@ PyDoc_STRVAR(_decimal_Decimal_logical_invert__doc__, "Return the digit-wise inversion of the (logical) operand."); #define _DECIMAL_DECIMAL_LOGICAL_INVERT_METHODDEF \ - {"logical_invert", _PyCFunction_CAST(_decimal_Decimal_logical_invert), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_logical_invert__doc__}, + {"logical_invert", _PyCFunction_CAST(_decimal_Decimal_logical_invert), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_logical_invert__doc__}, static PyObject * -_decimal_Decimal_logical_invert_impl(PyObject *self, PyObject *context); +_decimal_Decimal_logical_invert_impl(PyObject *self, PyTypeObject *cls, + PyObject *context); static PyObject * -_decimal_Decimal_logical_invert(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_logical_invert(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -2485,7 +2798,7 @@ _decimal_Decimal_logical_invert(PyObject *self, PyObject *const *args, Py_ssize_ } context = args[0]; skip_optional_pos: - return_value = _decimal_Decimal_logical_invert_impl(self, context); + return_value = _decimal_Decimal_logical_invert_impl(self, cls, context); exit: return return_value; @@ -2502,13 +2815,14 @@ PyDoc_STRVAR(_decimal_Decimal_logb__doc__, "Decimal(\'Infinity\') is returned."); #define _DECIMAL_DECIMAL_LOGB_METHODDEF \ - {"logb", _PyCFunction_CAST(_decimal_Decimal_logb), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_logb__doc__}, + {"logb", _PyCFunction_CAST(_decimal_Decimal_logb), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_logb__doc__}, static PyObject * -_decimal_Decimal_logb_impl(PyObject *self, PyObject *context); +_decimal_Decimal_logb_impl(PyObject *self, PyTypeObject *cls, + PyObject *context); static PyObject * -_decimal_Decimal_logb(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_logb(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -2552,7 +2866,7 @@ _decimal_Decimal_logb(PyObject *self, PyObject *const *args, Py_ssize_t nargs, P } context = args[0]; skip_optional_pos: - return_value = _decimal_Decimal_logb_impl(self, context); + return_value = _decimal_Decimal_logb_impl(self, cls, context); exit: return return_value; @@ -2582,13 +2896,14 @@ PyDoc_STRVAR(_decimal_Decimal_number_class__doc__, " * \'sNaN\', indicating that the operand is a signaling NaN."); #define _DECIMAL_DECIMAL_NUMBER_CLASS_METHODDEF \ - {"number_class", _PyCFunction_CAST(_decimal_Decimal_number_class), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_number_class__doc__}, + {"number_class", _PyCFunction_CAST(_decimal_Decimal_number_class), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_number_class__doc__}, static PyObject * -_decimal_Decimal_number_class_impl(PyObject *self, PyObject *context); +_decimal_Decimal_number_class_impl(PyObject *self, PyTypeObject *cls, + PyObject *context); static PyObject * -_decimal_Decimal_number_class(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_number_class(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -2632,7 +2947,7 @@ _decimal_Decimal_number_class(PyObject *self, PyObject *const *args, Py_ssize_t } context = args[0]; skip_optional_pos: - return_value = _decimal_Decimal_number_class_impl(self, context); + return_value = _decimal_Decimal_number_class_impl(self, cls, context); exit: return return_value; @@ -2653,13 +2968,14 @@ PyDoc_STRVAR(_decimal_Decimal_to_eng_string__doc__, "operation."); #define _DECIMAL_DECIMAL_TO_ENG_STRING_METHODDEF \ - {"to_eng_string", _PyCFunction_CAST(_decimal_Decimal_to_eng_string), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_to_eng_string__doc__}, + {"to_eng_string", _PyCFunction_CAST(_decimal_Decimal_to_eng_string), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_to_eng_string__doc__}, static PyObject * -_decimal_Decimal_to_eng_string_impl(PyObject *self, PyObject *context); +_decimal_Decimal_to_eng_string_impl(PyObject *self, PyTypeObject *cls, + PyObject *context); static PyObject * -_decimal_Decimal_to_eng_string(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_to_eng_string(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -2703,7 +3019,7 @@ _decimal_Decimal_to_eng_string(PyObject *self, PyObject *const *args, Py_ssize_t } context = args[0]; skip_optional_pos: - return_value = _decimal_Decimal_to_eng_string_impl(self, context); + return_value = _decimal_Decimal_to_eng_string_impl(self, cls, context); exit: return return_value; @@ -2736,14 +3052,14 @@ PyDoc_STRVAR(_decimal_Decimal_compare_total__doc__, "exactly."); #define _DECIMAL_DECIMAL_COMPARE_TOTAL_METHODDEF \ - {"compare_total", _PyCFunction_CAST(_decimal_Decimal_compare_total), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_compare_total__doc__}, + {"compare_total", _PyCFunction_CAST(_decimal_Decimal_compare_total), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_compare_total__doc__}, static PyObject * -_decimal_Decimal_compare_total_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_compare_total_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_compare_total(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_compare_total(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -2789,7 +3105,7 @@ _decimal_Decimal_compare_total(PyObject *self, PyObject *const *args, Py_ssize_t } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_compare_total_impl(self, other, context); + return_value = _decimal_Decimal_compare_total_impl(self, cls, other, context); exit: return return_value; @@ -2810,14 +3126,14 @@ PyDoc_STRVAR(_decimal_Decimal_compare_total_mag__doc__, "exactly."); #define _DECIMAL_DECIMAL_COMPARE_TOTAL_MAG_METHODDEF \ - {"compare_total_mag", _PyCFunction_CAST(_decimal_Decimal_compare_total_mag), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_compare_total_mag__doc__}, + {"compare_total_mag", _PyCFunction_CAST(_decimal_Decimal_compare_total_mag), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_compare_total_mag__doc__}, static PyObject * -_decimal_Decimal_compare_total_mag_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_compare_total_mag_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_compare_total_mag(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_compare_total_mag(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -2863,7 +3179,7 @@ _decimal_Decimal_compare_total_mag(PyObject *self, PyObject *const *args, Py_ssi } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_compare_total_mag_impl(self, other, context); + return_value = _decimal_Decimal_compare_total_mag_impl(self, cls, other, context); exit: return return_value; @@ -2886,14 +3202,14 @@ PyDoc_STRVAR(_decimal_Decimal_copy_sign__doc__, "exactly."); #define _DECIMAL_DECIMAL_COPY_SIGN_METHODDEF \ - {"copy_sign", _PyCFunction_CAST(_decimal_Decimal_copy_sign), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_copy_sign__doc__}, + {"copy_sign", _PyCFunction_CAST(_decimal_Decimal_copy_sign), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_copy_sign__doc__}, static PyObject * -_decimal_Decimal_copy_sign_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_copy_sign_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_copy_sign(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_copy_sign(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -2939,7 +3255,7 @@ _decimal_Decimal_copy_sign(PyObject *self, PyObject *const *args, Py_ssize_t nar } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_copy_sign_impl(self, other, context); + return_value = _decimal_Decimal_copy_sign_impl(self, cls, other, context); exit: return return_value; @@ -2957,14 +3273,14 @@ PyDoc_STRVAR(_decimal_Decimal_same_quantum__doc__, "exactly."); #define _DECIMAL_DECIMAL_SAME_QUANTUM_METHODDEF \ - {"same_quantum", _PyCFunction_CAST(_decimal_Decimal_same_quantum), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_same_quantum__doc__}, + {"same_quantum", _PyCFunction_CAST(_decimal_Decimal_same_quantum), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_same_quantum__doc__}, static PyObject * -_decimal_Decimal_same_quantum_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_same_quantum_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_same_quantum(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_same_quantum(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -3010,7 +3326,7 @@ _decimal_Decimal_same_quantum(PyObject *self, PyObject *const *args, Py_ssize_t } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_same_quantum_impl(self, other, context); + return_value = _decimal_Decimal_same_quantum_impl(self, cls, other, context); exit: return return_value; @@ -3023,14 +3339,14 @@ PyDoc_STRVAR(_decimal_Decimal_logical_and__doc__, "Return the digit-wise \'and\' of the two (logical) operands."); #define _DECIMAL_DECIMAL_LOGICAL_AND_METHODDEF \ - {"logical_and", _PyCFunction_CAST(_decimal_Decimal_logical_and), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_logical_and__doc__}, + {"logical_and", _PyCFunction_CAST(_decimal_Decimal_logical_and), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_logical_and__doc__}, static PyObject * -_decimal_Decimal_logical_and_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_logical_and_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_logical_and(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_logical_and(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -3076,7 +3392,7 @@ _decimal_Decimal_logical_and(PyObject *self, PyObject *const *args, Py_ssize_t n } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_logical_and_impl(self, other, context); + return_value = _decimal_Decimal_logical_and_impl(self, cls, other, context); exit: return return_value; @@ -3089,14 +3405,14 @@ PyDoc_STRVAR(_decimal_Decimal_logical_or__doc__, "Return the digit-wise \'or\' of the two (logical) operands."); #define _DECIMAL_DECIMAL_LOGICAL_OR_METHODDEF \ - {"logical_or", _PyCFunction_CAST(_decimal_Decimal_logical_or), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_logical_or__doc__}, + {"logical_or", _PyCFunction_CAST(_decimal_Decimal_logical_or), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_logical_or__doc__}, static PyObject * -_decimal_Decimal_logical_or_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_logical_or_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_logical_or(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_logical_or(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -3142,7 +3458,7 @@ _decimal_Decimal_logical_or(PyObject *self, PyObject *const *args, Py_ssize_t na } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_logical_or_impl(self, other, context); + return_value = _decimal_Decimal_logical_or_impl(self, cls, other, context); exit: return return_value; @@ -3155,14 +3471,14 @@ PyDoc_STRVAR(_decimal_Decimal_logical_xor__doc__, "Return the digit-wise \'xor\' of the two (logical) operands."); #define _DECIMAL_DECIMAL_LOGICAL_XOR_METHODDEF \ - {"logical_xor", _PyCFunction_CAST(_decimal_Decimal_logical_xor), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_logical_xor__doc__}, + {"logical_xor", _PyCFunction_CAST(_decimal_Decimal_logical_xor), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_logical_xor__doc__}, static PyObject * -_decimal_Decimal_logical_xor_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_logical_xor_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_logical_xor(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_logical_xor(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -3208,7 +3524,7 @@ _decimal_Decimal_logical_xor(PyObject *self, PyObject *const *args, Py_ssize_t n } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_logical_xor_impl(self, other, context); + return_value = _decimal_Decimal_logical_xor_impl(self, cls, other, context); exit: return return_value; @@ -3228,14 +3544,14 @@ PyDoc_STRVAR(_decimal_Decimal_rotate__doc__, "necessary. The sign and exponent of the first operand are unchanged."); #define _DECIMAL_DECIMAL_ROTATE_METHODDEF \ - {"rotate", _PyCFunction_CAST(_decimal_Decimal_rotate), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_rotate__doc__}, + {"rotate", _PyCFunction_CAST(_decimal_Decimal_rotate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_rotate__doc__}, static PyObject * -_decimal_Decimal_rotate_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_rotate_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_rotate(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_rotate(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -3281,7 +3597,7 @@ _decimal_Decimal_rotate(PyObject *self, PyObject *const *args, Py_ssize_t nargs, } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_rotate_impl(self, other, context); + return_value = _decimal_Decimal_rotate_impl(self, cls, other, context); exit: return return_value; @@ -3297,14 +3613,14 @@ PyDoc_STRVAR(_decimal_Decimal_scaleb__doc__, "second operand must be an integer."); #define _DECIMAL_DECIMAL_SCALEB_METHODDEF \ - {"scaleb", _PyCFunction_CAST(_decimal_Decimal_scaleb), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_scaleb__doc__}, + {"scaleb", _PyCFunction_CAST(_decimal_Decimal_scaleb), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_scaleb__doc__}, static PyObject * -_decimal_Decimal_scaleb_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_scaleb_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_scaleb(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_scaleb(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -3350,7 +3666,7 @@ _decimal_Decimal_scaleb(PyObject *self, PyObject *const *args, Py_ssize_t nargs, } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_scaleb_impl(self, other, context); + return_value = _decimal_Decimal_scaleb_impl(self, cls, other, context); exit: return return_value; @@ -3370,14 +3686,14 @@ PyDoc_STRVAR(_decimal_Decimal_shift__doc__, "operand are unchanged."); #define _DECIMAL_DECIMAL_SHIFT_METHODDEF \ - {"shift", _PyCFunction_CAST(_decimal_Decimal_shift), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_shift__doc__}, + {"shift", _PyCFunction_CAST(_decimal_Decimal_shift), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_shift__doc__}, static PyObject * -_decimal_Decimal_shift_impl(PyObject *self, PyObject *other, - PyObject *context); +_decimal_Decimal_shift_impl(PyObject *self, PyTypeObject *cls, + PyObject *other, PyObject *context); static PyObject * -_decimal_Decimal_shift(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_shift(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -3423,7 +3739,7 @@ _decimal_Decimal_shift(PyObject *self, PyObject *const *args, Py_ssize_t nargs, } context = args[1]; skip_optional_pos: - return_value = _decimal_Decimal_shift_impl(self, other, context); + return_value = _decimal_Decimal_shift_impl(self, cls, other, context); exit: return return_value; @@ -3457,14 +3773,15 @@ PyDoc_STRVAR(_decimal_Decimal_quantize__doc__, "current thread\'s context is used."); #define _DECIMAL_DECIMAL_QUANTIZE_METHODDEF \ - {"quantize", _PyCFunction_CAST(_decimal_Decimal_quantize), METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_quantize__doc__}, + {"quantize", _PyCFunction_CAST(_decimal_Decimal_quantize), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal_quantize__doc__}, static PyObject * -_decimal_Decimal_quantize_impl(PyObject *self, PyObject *w, - PyObject *rounding, PyObject *context); +_decimal_Decimal_quantize_impl(PyObject *self, PyTypeObject *cls, + PyObject *w, PyObject *rounding, + PyObject *context); static PyObject * -_decimal_Decimal_quantize(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Decimal_quantize(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -3517,7 +3834,7 @@ _decimal_Decimal_quantize(PyObject *self, PyObject *const *args, Py_ssize_t narg } context = args[2]; skip_optional_pos: - return_value = _decimal_Decimal_quantize_impl(self, w, rounding, context); + return_value = _decimal_Decimal_quantize_impl(self, cls, w, rounding, context); exit: return return_value; @@ -3530,15 +3847,19 @@ PyDoc_STRVAR(_decimal_Decimal___ceil____doc__, "Return the ceiling as an Integral."); #define _DECIMAL_DECIMAL___CEIL___METHODDEF \ - {"__ceil__", (PyCFunction)_decimal_Decimal___ceil__, METH_NOARGS, _decimal_Decimal___ceil____doc__}, + {"__ceil__", _PyCFunction_CAST(_decimal_Decimal___ceil__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal___ceil____doc__}, static PyObject * -_decimal_Decimal___ceil___impl(PyObject *self); +_decimal_Decimal___ceil___impl(PyObject *self, PyTypeObject *cls); static PyObject * -_decimal_Decimal___ceil__(PyObject *self, PyObject *Py_UNUSED(ignored)) +_decimal_Decimal___ceil__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _decimal_Decimal___ceil___impl(self); + if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { + PyErr_SetString(PyExc_TypeError, "__ceil__() takes no arguments"); + return NULL; + } + return _decimal_Decimal___ceil___impl(self, cls); } PyDoc_STRVAR(_decimal_Decimal___complex____doc__, @@ -3591,15 +3912,19 @@ PyDoc_STRVAR(_decimal_Decimal___floor____doc__, "Return the floor as an Integral."); #define _DECIMAL_DECIMAL___FLOOR___METHODDEF \ - {"__floor__", (PyCFunction)_decimal_Decimal___floor__, METH_NOARGS, _decimal_Decimal___floor____doc__}, + {"__floor__", _PyCFunction_CAST(_decimal_Decimal___floor__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal___floor____doc__}, static PyObject * -_decimal_Decimal___floor___impl(PyObject *self); +_decimal_Decimal___floor___impl(PyObject *self, PyTypeObject *cls); static PyObject * -_decimal_Decimal___floor__(PyObject *self, PyObject *Py_UNUSED(ignored)) +_decimal_Decimal___floor__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _decimal_Decimal___floor___impl(self); + if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { + PyErr_SetString(PyExc_TypeError, "__floor__() takes no arguments"); + return NULL; + } + return _decimal_Decimal___floor___impl(self, cls); } PyDoc_STRVAR(_decimal_Decimal___reduce____doc__, @@ -3645,15 +3970,19 @@ PyDoc_STRVAR(_decimal_Decimal___trunc____doc__, "Return the Integral closest to x between 0 and x."); #define _DECIMAL_DECIMAL___TRUNC___METHODDEF \ - {"__trunc__", (PyCFunction)_decimal_Decimal___trunc__, METH_NOARGS, _decimal_Decimal___trunc____doc__}, + {"__trunc__", _PyCFunction_CAST(_decimal_Decimal___trunc__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Decimal___trunc____doc__}, static PyObject * -_decimal_Decimal___trunc___impl(PyObject *self); +_decimal_Decimal___trunc___impl(PyObject *self, PyTypeObject *cls); static PyObject * -_decimal_Decimal___trunc__(PyObject *self, PyObject *Py_UNUSED(ignored)) +_decimal_Decimal___trunc__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _decimal_Decimal___trunc___impl(self); + if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { + PyErr_SetString(PyExc_TypeError, "__trunc__() takes no arguments"); + return NULL; + } + return _decimal_Decimal___trunc___impl(self, cls); } PyDoc_STRVAR(_decimal_Context_abs__doc__, @@ -3663,7 +3992,42 @@ PyDoc_STRVAR(_decimal_Context_abs__doc__, "Return the absolute value of x."); #define _DECIMAL_CONTEXT_ABS_METHODDEF \ - {"abs", (PyCFunction)_decimal_Context_abs, METH_O, _decimal_Context_abs__doc__}, + {"abs", _PyCFunction_CAST(_decimal_Context_abs), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_abs__doc__}, + +static PyObject * +_decimal_Context_abs_impl(PyObject *context, PyTypeObject *cls, PyObject *x); + +static PyObject * +_decimal_Context_abs(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "abs", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_abs_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_exp__doc__, "exp($self, x, /)\n" @@ -3672,710 +4036,1406 @@ PyDoc_STRVAR(_decimal_Context_exp__doc__, "Return e ** x."); #define _DECIMAL_CONTEXT_EXP_METHODDEF \ - {"exp", (PyCFunction)_decimal_Context_exp, METH_O, _decimal_Context_exp__doc__}, + {"exp", _PyCFunction_CAST(_decimal_Context_exp), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_exp__doc__}, -PyDoc_STRVAR(_decimal_Context_ln__doc__, -"ln($self, x, /)\n" -"--\n" -"\n" -"Return the natural (base e) logarithm of x."); +static PyObject * +_decimal_Context_exp_impl(PyObject *context, PyTypeObject *cls, PyObject *x); -#define _DECIMAL_CONTEXT_LN_METHODDEF \ - {"ln", (PyCFunction)_decimal_Context_ln, METH_O, _decimal_Context_ln__doc__}, +static PyObject * +_decimal_Context_exp(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif -PyDoc_STRVAR(_decimal_Context_log10__doc__, -"log10($self, x, /)\n" -"--\n" -"\n" -"Return the base 10 logarithm of x."); - -#define _DECIMAL_CONTEXT_LOG10_METHODDEF \ - {"log10", (PyCFunction)_decimal_Context_log10, METH_O, _decimal_Context_log10__doc__}, - -PyDoc_STRVAR(_decimal_Context_minus__doc__, -"minus($self, x, /)\n" -"--\n" -"\n" -"Minus corresponds to unary prefix minus in Python.\n" -"\n" -"This operation applies the context to the result."); - -#define _DECIMAL_CONTEXT_MINUS_METHODDEF \ - {"minus", (PyCFunction)_decimal_Context_minus, METH_O, _decimal_Context_minus__doc__}, - -PyDoc_STRVAR(_decimal_Context_next_minus__doc__, -"next_minus($self, x, /)\n" -"--\n" -"\n" -"Return the largest representable number smaller than x."); - -#define _DECIMAL_CONTEXT_NEXT_MINUS_METHODDEF \ - {"next_minus", (PyCFunction)_decimal_Context_next_minus, METH_O, _decimal_Context_next_minus__doc__}, - -PyDoc_STRVAR(_decimal_Context_next_plus__doc__, -"next_plus($self, x, /)\n" -"--\n" -"\n" -"Return the smallest representable number larger than x."); - -#define _DECIMAL_CONTEXT_NEXT_PLUS_METHODDEF \ - {"next_plus", (PyCFunction)_decimal_Context_next_plus, METH_O, _decimal_Context_next_plus__doc__}, - -PyDoc_STRVAR(_decimal_Context_normalize__doc__, -"normalize($self, x, /)\n" -"--\n" -"\n" -"Reduce x to its simplest form. Alias for reduce(x)."); - -#define _DECIMAL_CONTEXT_NORMALIZE_METHODDEF \ - {"normalize", (PyCFunction)_decimal_Context_normalize, METH_O, _decimal_Context_normalize__doc__}, - -PyDoc_STRVAR(_decimal_Context_plus__doc__, -"plus($self, x, /)\n" -"--\n" -"\n" -"Plus corresponds to the unary prefix plus operator in Python.\n" -"\n" -"This operation applies the context to the result."); - -#define _DECIMAL_CONTEXT_PLUS_METHODDEF \ - {"plus", (PyCFunction)_decimal_Context_plus, METH_O, _decimal_Context_plus__doc__}, - -PyDoc_STRVAR(_decimal_Context_to_integral_value__doc__, -"to_integral_value($self, x, /)\n" -"--\n" -"\n" -"Round to an integer."); - -#define _DECIMAL_CONTEXT_TO_INTEGRAL_VALUE_METHODDEF \ - {"to_integral_value", (PyCFunction)_decimal_Context_to_integral_value, METH_O, _decimal_Context_to_integral_value__doc__}, - -PyDoc_STRVAR(_decimal_Context_to_integral_exact__doc__, -"to_integral_exact($self, x, /)\n" -"--\n" -"\n" -"Round to an integer. Signal if the result is rounded or inexact."); - -#define _DECIMAL_CONTEXT_TO_INTEGRAL_EXACT_METHODDEF \ - {"to_integral_exact", (PyCFunction)_decimal_Context_to_integral_exact, METH_O, _decimal_Context_to_integral_exact__doc__}, - -PyDoc_STRVAR(_decimal_Context_to_integral__doc__, -"to_integral($self, x, /)\n" -"--\n" -"\n" -"Identical to to_integral_value(x)."); - -#define _DECIMAL_CONTEXT_TO_INTEGRAL_METHODDEF \ - {"to_integral", (PyCFunction)_decimal_Context_to_integral, METH_O, _decimal_Context_to_integral__doc__}, + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "exp", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; -PyDoc_STRVAR(_decimal_Context_sqrt__doc__, -"sqrt($self, x, /)\n" -"--\n" -"\n" -"Square root of a non-negative number to context precision."); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_exp_impl(context, cls, x); -#define _DECIMAL_CONTEXT_SQRT_METHODDEF \ - {"sqrt", (PyCFunction)_decimal_Context_sqrt, METH_O, _decimal_Context_sqrt__doc__}, +exit: + return return_value; +} -PyDoc_STRVAR(_decimal_Context_add__doc__, -"add($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_ln__doc__, +"ln($self, x, /)\n" "--\n" "\n" -"Return the sum of x and y."); +"Return the natural (base e) logarithm of x."); -#define _DECIMAL_CONTEXT_ADD_METHODDEF \ - {"add", _PyCFunction_CAST(_decimal_Context_add), METH_FASTCALL, _decimal_Context_add__doc__}, +#define _DECIMAL_CONTEXT_LN_METHODDEF \ + {"ln", _PyCFunction_CAST(_decimal_Context_ln), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_ln__doc__}, static PyObject * -_decimal_Context_add_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_ln_impl(PyObject *context, PyTypeObject *cls, PyObject *x); static PyObject * -_decimal_Context_add(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_ln(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "ln", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; PyObject *x; - PyObject *y; - if (!_PyArg_CheckPositional("add", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; - y = args[1]; - return_value = _decimal_Context_add_impl(context, x, y); + return_value = _decimal_Context_ln_impl(context, cls, x); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_compare__doc__, -"compare($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_log10__doc__, +"log10($self, x, /)\n" "--\n" "\n" -"Compare x and y numerically."); +"Return the base 10 logarithm of x."); -#define _DECIMAL_CONTEXT_COMPARE_METHODDEF \ - {"compare", _PyCFunction_CAST(_decimal_Context_compare), METH_FASTCALL, _decimal_Context_compare__doc__}, +#define _DECIMAL_CONTEXT_LOG10_METHODDEF \ + {"log10", _PyCFunction_CAST(_decimal_Context_log10), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_log10__doc__}, static PyObject * -_decimal_Context_compare_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_log10_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); static PyObject * -_decimal_Context_compare(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_log10(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "log10", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; PyObject *x; - PyObject *y; - if (!_PyArg_CheckPositional("compare", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; - y = args[1]; - return_value = _decimal_Context_compare_impl(context, x, y); + return_value = _decimal_Context_log10_impl(context, cls, x); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_compare_signal__doc__, -"compare_signal($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_minus__doc__, +"minus($self, x, /)\n" "--\n" "\n" -"Compare x and y numerically. All NaNs signal."); +"Minus corresponds to unary prefix minus in Python.\n" +"\n" +"This operation applies the context to the result."); -#define _DECIMAL_CONTEXT_COMPARE_SIGNAL_METHODDEF \ - {"compare_signal", _PyCFunction_CAST(_decimal_Context_compare_signal), METH_FASTCALL, _decimal_Context_compare_signal__doc__}, +#define _DECIMAL_CONTEXT_MINUS_METHODDEF \ + {"minus", _PyCFunction_CAST(_decimal_Context_minus), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_minus__doc__}, static PyObject * -_decimal_Context_compare_signal_impl(PyObject *context, PyObject *x, - PyObject *y); +_decimal_Context_minus_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); static PyObject * -_decimal_Context_compare_signal(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_minus(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "minus", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; PyObject *x; - PyObject *y; - if (!_PyArg_CheckPositional("compare_signal", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; - y = args[1]; - return_value = _decimal_Context_compare_signal_impl(context, x, y); + return_value = _decimal_Context_minus_impl(context, cls, x); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_divide__doc__, -"divide($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_next_minus__doc__, +"next_minus($self, x, /)\n" "--\n" "\n" -"Return x divided by y."); +"Return the largest representable number smaller than x."); -#define _DECIMAL_CONTEXT_DIVIDE_METHODDEF \ - {"divide", _PyCFunction_CAST(_decimal_Context_divide), METH_FASTCALL, _decimal_Context_divide__doc__}, +#define _DECIMAL_CONTEXT_NEXT_MINUS_METHODDEF \ + {"next_minus", _PyCFunction_CAST(_decimal_Context_next_minus), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_next_minus__doc__}, static PyObject * -_decimal_Context_divide_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_next_minus_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); static PyObject * -_decimal_Context_divide(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_next_minus(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "next_minus", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; PyObject *x; - PyObject *y; - if (!_PyArg_CheckPositional("divide", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; - y = args[1]; - return_value = _decimal_Context_divide_impl(context, x, y); + return_value = _decimal_Context_next_minus_impl(context, cls, x); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_divide_int__doc__, -"divide_int($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_next_plus__doc__, +"next_plus($self, x, /)\n" "--\n" "\n" -"Return x divided by y, truncated to an integer."); +"Return the smallest representable number larger than x."); -#define _DECIMAL_CONTEXT_DIVIDE_INT_METHODDEF \ - {"divide_int", _PyCFunction_CAST(_decimal_Context_divide_int), METH_FASTCALL, _decimal_Context_divide_int__doc__}, +#define _DECIMAL_CONTEXT_NEXT_PLUS_METHODDEF \ + {"next_plus", _PyCFunction_CAST(_decimal_Context_next_plus), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_next_plus__doc__}, static PyObject * -_decimal_Context_divide_int_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_next_plus_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); static PyObject * -_decimal_Context_divide_int(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_next_plus(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "next_plus", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; PyObject *x; - PyObject *y; - if (!_PyArg_CheckPositional("divide_int", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; - y = args[1]; - return_value = _decimal_Context_divide_int_impl(context, x, y); + return_value = _decimal_Context_next_plus_impl(context, cls, x); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_max__doc__, -"max($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_normalize__doc__, +"normalize($self, x, /)\n" "--\n" "\n" -"Compare the values numerically and return the maximum."); +"Reduce x to its simplest form. Alias for reduce(x)."); -#define _DECIMAL_CONTEXT_MAX_METHODDEF \ - {"max", _PyCFunction_CAST(_decimal_Context_max), METH_FASTCALL, _decimal_Context_max__doc__}, +#define _DECIMAL_CONTEXT_NORMALIZE_METHODDEF \ + {"normalize", _PyCFunction_CAST(_decimal_Context_normalize), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_normalize__doc__}, static PyObject * -_decimal_Context_max_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_normalize_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); static PyObject * -_decimal_Context_max(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_normalize(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "normalize", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; PyObject *x; - PyObject *y; - if (!_PyArg_CheckPositional("max", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; - y = args[1]; - return_value = _decimal_Context_max_impl(context, x, y); + return_value = _decimal_Context_normalize_impl(context, cls, x); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_max_mag__doc__, -"max_mag($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_plus__doc__, +"plus($self, x, /)\n" "--\n" "\n" -"Compare the values numerically with their sign ignored."); +"Plus corresponds to the unary prefix plus operator in Python.\n" +"\n" +"This operation applies the context to the result."); -#define _DECIMAL_CONTEXT_MAX_MAG_METHODDEF \ - {"max_mag", _PyCFunction_CAST(_decimal_Context_max_mag), METH_FASTCALL, _decimal_Context_max_mag__doc__}, +#define _DECIMAL_CONTEXT_PLUS_METHODDEF \ + {"plus", _PyCFunction_CAST(_decimal_Context_plus), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_plus__doc__}, static PyObject * -_decimal_Context_max_mag_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_plus_impl(PyObject *context, PyTypeObject *cls, PyObject *x); static PyObject * -_decimal_Context_max_mag(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_plus(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "plus", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; PyObject *x; - PyObject *y; - if (!_PyArg_CheckPositional("max_mag", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; - y = args[1]; - return_value = _decimal_Context_max_mag_impl(context, x, y); + return_value = _decimal_Context_plus_impl(context, cls, x); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_min__doc__, -"min($self, x, y, /)\n" -"--\n" +PyDoc_STRVAR(_decimal_Context_to_integral_value__doc__, +"to_integral_value($self, x, /)\n" +"--\n" "\n" -"Compare the values numerically and return the minimum."); +"Round to an integer."); -#define _DECIMAL_CONTEXT_MIN_METHODDEF \ - {"min", _PyCFunction_CAST(_decimal_Context_min), METH_FASTCALL, _decimal_Context_min__doc__}, +#define _DECIMAL_CONTEXT_TO_INTEGRAL_VALUE_METHODDEF \ + {"to_integral_value", _PyCFunction_CAST(_decimal_Context_to_integral_value), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_to_integral_value__doc__}, static PyObject * -_decimal_Context_min_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_to_integral_value_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); static PyObject * -_decimal_Context_min(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_to_integral_value(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "to_integral_value", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; PyObject *x; - PyObject *y; - if (!_PyArg_CheckPositional("min", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; - y = args[1]; - return_value = _decimal_Context_min_impl(context, x, y); + return_value = _decimal_Context_to_integral_value_impl(context, cls, x); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_min_mag__doc__, -"min_mag($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_to_integral_exact__doc__, +"to_integral_exact($self, x, /)\n" "--\n" "\n" -"Compare the values numerically with their sign ignored."); +"Round to an integer. Signal if the result is rounded or inexact."); -#define _DECIMAL_CONTEXT_MIN_MAG_METHODDEF \ - {"min_mag", _PyCFunction_CAST(_decimal_Context_min_mag), METH_FASTCALL, _decimal_Context_min_mag__doc__}, +#define _DECIMAL_CONTEXT_TO_INTEGRAL_EXACT_METHODDEF \ + {"to_integral_exact", _PyCFunction_CAST(_decimal_Context_to_integral_exact), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_to_integral_exact__doc__}, static PyObject * -_decimal_Context_min_mag_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_to_integral_exact_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); static PyObject * -_decimal_Context_min_mag(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_to_integral_exact(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "to_integral_exact", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; PyObject *x; - PyObject *y; - if (!_PyArg_CheckPositional("min_mag", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; - y = args[1]; - return_value = _decimal_Context_min_mag_impl(context, x, y); + return_value = _decimal_Context_to_integral_exact_impl(context, cls, x); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_multiply__doc__, -"multiply($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_to_integral__doc__, +"to_integral($self, x, /)\n" "--\n" "\n" -"Return the product of x and y."); +"Identical to to_integral_value(x)."); -#define _DECIMAL_CONTEXT_MULTIPLY_METHODDEF \ - {"multiply", _PyCFunction_CAST(_decimal_Context_multiply), METH_FASTCALL, _decimal_Context_multiply__doc__}, +#define _DECIMAL_CONTEXT_TO_INTEGRAL_METHODDEF \ + {"to_integral", _PyCFunction_CAST(_decimal_Context_to_integral), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_to_integral__doc__}, static PyObject * -_decimal_Context_multiply_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_to_integral_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); static PyObject * -_decimal_Context_multiply(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_to_integral(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "to_integral", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; PyObject *x; - PyObject *y; - if (!_PyArg_CheckPositional("multiply", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; - y = args[1]; - return_value = _decimal_Context_multiply_impl(context, x, y); + return_value = _decimal_Context_to_integral_impl(context, cls, x); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_next_toward__doc__, -"next_toward($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_sqrt__doc__, +"sqrt($self, x, /)\n" "--\n" "\n" -"Return the number closest to x, in the direction towards y."); +"Square root of a non-negative number to context precision."); -#define _DECIMAL_CONTEXT_NEXT_TOWARD_METHODDEF \ - {"next_toward", _PyCFunction_CAST(_decimal_Context_next_toward), METH_FASTCALL, _decimal_Context_next_toward__doc__}, +#define _DECIMAL_CONTEXT_SQRT_METHODDEF \ + {"sqrt", _PyCFunction_CAST(_decimal_Context_sqrt), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_sqrt__doc__}, static PyObject * -_decimal_Context_next_toward_impl(PyObject *context, PyObject *x, - PyObject *y); +_decimal_Context_sqrt_impl(PyObject *context, PyTypeObject *cls, PyObject *x); static PyObject * -_decimal_Context_next_toward(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_sqrt(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "sqrt", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; PyObject *x; - PyObject *y; - if (!_PyArg_CheckPositional("next_toward", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; - y = args[1]; - return_value = _decimal_Context_next_toward_impl(context, x, y); + return_value = _decimal_Context_sqrt_impl(context, cls, x); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_quantize__doc__, -"quantize($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_add__doc__, +"add($self, x, y, /)\n" "--\n" "\n" -"Return a value equal to x (rounded), having the exponent of y."); +"Return the sum of x and y."); -#define _DECIMAL_CONTEXT_QUANTIZE_METHODDEF \ - {"quantize", _PyCFunction_CAST(_decimal_Context_quantize), METH_FASTCALL, _decimal_Context_quantize__doc__}, +#define _DECIMAL_CONTEXT_ADD_METHODDEF \ + {"add", _PyCFunction_CAST(_decimal_Context_add), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_add__doc__}, static PyObject * -_decimal_Context_quantize_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_add_impl(PyObject *context, PyTypeObject *cls, PyObject *x, + PyObject *y); static PyObject * -_decimal_Context_quantize(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_add(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "add", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("quantize", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_quantize_impl(context, x, y); + return_value = _decimal_Context_add_impl(context, cls, x, y); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_remainder__doc__, -"remainder($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_compare__doc__, +"compare($self, x, y, /)\n" "--\n" "\n" -"Return the remainder from integer division.\n" -"\n" -"The sign of the result, if non-zero, is the same as that of the\n" -"original dividend."); +"Compare x and y numerically."); -#define _DECIMAL_CONTEXT_REMAINDER_METHODDEF \ - {"remainder", _PyCFunction_CAST(_decimal_Context_remainder), METH_FASTCALL, _decimal_Context_remainder__doc__}, +#define _DECIMAL_CONTEXT_COMPARE_METHODDEF \ + {"compare", _PyCFunction_CAST(_decimal_Context_compare), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_compare__doc__}, static PyObject * -_decimal_Context_remainder_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_compare_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_remainder(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_compare(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "compare", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("remainder", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_remainder_impl(context, x, y); + return_value = _decimal_Context_compare_impl(context, cls, x, y); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_remainder_near__doc__, -"remainder_near($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_compare_signal__doc__, +"compare_signal($self, x, y, /)\n" "--\n" "\n" -"Return x - y * n.\n" -"\n" -"Here n is the integer nearest the exact value of x / y (if the result\n" -"is 0 then its sign will be the sign of x)."); +"Compare x and y numerically. All NaNs signal."); -#define _DECIMAL_CONTEXT_REMAINDER_NEAR_METHODDEF \ - {"remainder_near", _PyCFunction_CAST(_decimal_Context_remainder_near), METH_FASTCALL, _decimal_Context_remainder_near__doc__}, +#define _DECIMAL_CONTEXT_COMPARE_SIGNAL_METHODDEF \ + {"compare_signal", _PyCFunction_CAST(_decimal_Context_compare_signal), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_compare_signal__doc__}, static PyObject * -_decimal_Context_remainder_near_impl(PyObject *context, PyObject *x, - PyObject *y); +_decimal_Context_compare_signal_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_remainder_near(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_compare_signal(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "compare_signal", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("remainder_near", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_remainder_near_impl(context, x, y); + return_value = _decimal_Context_compare_signal_impl(context, cls, x, y); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_subtract__doc__, -"subtract($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_divide__doc__, +"divide($self, x, y, /)\n" "--\n" "\n" -"Return the difference between x and y."); +"Return x divided by y."); -#define _DECIMAL_CONTEXT_SUBTRACT_METHODDEF \ - {"subtract", _PyCFunction_CAST(_decimal_Context_subtract), METH_FASTCALL, _decimal_Context_subtract__doc__}, +#define _DECIMAL_CONTEXT_DIVIDE_METHODDEF \ + {"divide", _PyCFunction_CAST(_decimal_Context_divide), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_divide__doc__}, static PyObject * -_decimal_Context_subtract_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_divide_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_subtract(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_divide(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "divide", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("subtract", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_subtract_impl(context, x, y); + return_value = _decimal_Context_divide_impl(context, cls, x, y); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_divmod__doc__, -"divmod($self, x, y, /)\n" +PyDoc_STRVAR(_decimal_Context_divide_int__doc__, +"divide_int($self, x, y, /)\n" "--\n" "\n" -"Return quotient and remainder of the division x / y."); +"Return x divided by y, truncated to an integer."); -#define _DECIMAL_CONTEXT_DIVMOD_METHODDEF \ - {"divmod", _PyCFunction_CAST(_decimal_Context_divmod), METH_FASTCALL, _decimal_Context_divmod__doc__}, +#define _DECIMAL_CONTEXT_DIVIDE_INT_METHODDEF \ + {"divide_int", _PyCFunction_CAST(_decimal_Context_divide_int), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_divide_int__doc__}, static PyObject * -_decimal_Context_divmod_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_divide_int_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_divmod(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_divide_int(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "divide_int", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_divmod_impl(context, x, y); + return_value = _decimal_Context_divide_int_impl(context, cls, x, y); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_power__doc__, -"power($self, /, a, b, modulo=None)\n" +PyDoc_STRVAR(_decimal_Context_max__doc__, +"max($self, x, y, /)\n" "--\n" "\n" -"Compute a**b.\n" -"\n" -"If \'a\' is negative, then \'b\' must be integral. The result will be\n" -"inexact unless \'a\' is integral and the result is finite and can be\n" -"expressed exactly in \'precision\' digits. In the Python version the\n" -"result is always correctly rounded, in the C version the result is\n" -"almost always correctly rounded.\n" -"\n" -"If modulo is given, compute (a**b) % modulo. The following\n" -"restrictions hold:\n" -"\n" -" * all three arguments must be integral\n" -" * \'b\' must be nonnegative\n" -" * at least one of \'a\' or \'b\' must be nonzero\n" -" * modulo must be nonzero and less than 10**prec in absolute value"); +"Compare the values numerically and return the maximum."); -#define _DECIMAL_CONTEXT_POWER_METHODDEF \ - {"power", _PyCFunction_CAST(_decimal_Context_power), METH_FASTCALL|METH_KEYWORDS, _decimal_Context_power__doc__}, +#define _DECIMAL_CONTEXT_MAX_METHODDEF \ + {"max", _PyCFunction_CAST(_decimal_Context_max), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_max__doc__}, static PyObject * -_decimal_Context_power_impl(PyObject *context, PyObject *base, PyObject *exp, - PyObject *mod); +_decimal_Context_max_impl(PyObject *context, PyTypeObject *cls, PyObject *x, + PyObject *y); static PyObject * -_decimal_Context_power(PyObject *context, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +_decimal_Context_max(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 3 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - Py_hash_t ob_hash; - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_hash = -1, - .ob_item = { _Py_LATIN1_CHR('a'), _Py_LATIN1_CHR('b'), &_Py_ID(modulo), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else # define KWTUPLE NULL - #endif // !Py_BUILD_CORE + #endif - static const char * const _keywords[] = {"a", "b", "modulo", NULL}; + static const char * const _keywords[] = {"", "", NULL}; static _PyArg_Parser _parser = { .keywords = _keywords, - .fname = "power", + .fname = "max", .kwtuple = KWTUPLE, }; #undef KWTUPLE - PyObject *argsbuf[3]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; - PyObject *base; - PyObject *exp; - PyObject *mod = Py_None; + PyObject *argsbuf[2]; + PyObject *x; + PyObject *y; args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); if (!args) { goto exit; } - base = args[0]; - exp = args[1]; - if (!noptargs) { - goto skip_optional_pos; - } - mod = args[2]; -skip_optional_pos: - return_value = _decimal_Context_power_impl(context, base, exp, mod); + x = args[0]; + y = args[1]; + return_value = _decimal_Context_max_impl(context, cls, x, y); exit: return return_value; } -PyDoc_STRVAR(_decimal_Context_fma__doc__, +PyDoc_STRVAR(_decimal_Context_max_mag__doc__, +"max_mag($self, x, y, /)\n" +"--\n" +"\n" +"Compare the values numerically with their sign ignored."); + +#define _DECIMAL_CONTEXT_MAX_MAG_METHODDEF \ + {"max_mag", _PyCFunction_CAST(_decimal_Context_max_mag), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_max_mag__doc__}, + +static PyObject * +_decimal_Context_max_mag_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); + +static PyObject * +_decimal_Context_max_mag(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "max_mag", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; + PyObject *x; + PyObject *y; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + y = args[1]; + return_value = _decimal_Context_max_mag_impl(context, cls, x, y); + +exit: + return return_value; +} + +PyDoc_STRVAR(_decimal_Context_min__doc__, +"min($self, x, y, /)\n" +"--\n" +"\n" +"Compare the values numerically and return the minimum."); + +#define _DECIMAL_CONTEXT_MIN_METHODDEF \ + {"min", _PyCFunction_CAST(_decimal_Context_min), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_min__doc__}, + +static PyObject * +_decimal_Context_min_impl(PyObject *context, PyTypeObject *cls, PyObject *x, + PyObject *y); + +static PyObject * +_decimal_Context_min(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "min", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; + PyObject *x; + PyObject *y; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + y = args[1]; + return_value = _decimal_Context_min_impl(context, cls, x, y); + +exit: + return return_value; +} + +PyDoc_STRVAR(_decimal_Context_min_mag__doc__, +"min_mag($self, x, y, /)\n" +"--\n" +"\n" +"Compare the values numerically with their sign ignored."); + +#define _DECIMAL_CONTEXT_MIN_MAG_METHODDEF \ + {"min_mag", _PyCFunction_CAST(_decimal_Context_min_mag), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_min_mag__doc__}, + +static PyObject * +_decimal_Context_min_mag_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); + +static PyObject * +_decimal_Context_min_mag(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "min_mag", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; + PyObject *x; + PyObject *y; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + y = args[1]; + return_value = _decimal_Context_min_mag_impl(context, cls, x, y); + +exit: + return return_value; +} + +PyDoc_STRVAR(_decimal_Context_multiply__doc__, +"multiply($self, x, y, /)\n" +"--\n" +"\n" +"Return the product of x and y."); + +#define _DECIMAL_CONTEXT_MULTIPLY_METHODDEF \ + {"multiply", _PyCFunction_CAST(_decimal_Context_multiply), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_multiply__doc__}, + +static PyObject * +_decimal_Context_multiply_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); + +static PyObject * +_decimal_Context_multiply(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "multiply", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; + PyObject *x; + PyObject *y; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + y = args[1]; + return_value = _decimal_Context_multiply_impl(context, cls, x, y); + +exit: + return return_value; +} + +PyDoc_STRVAR(_decimal_Context_next_toward__doc__, +"next_toward($self, x, y, /)\n" +"--\n" +"\n" +"Return the number closest to x, in the direction towards y."); + +#define _DECIMAL_CONTEXT_NEXT_TOWARD_METHODDEF \ + {"next_toward", _PyCFunction_CAST(_decimal_Context_next_toward), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_next_toward__doc__}, + +static PyObject * +_decimal_Context_next_toward_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); + +static PyObject * +_decimal_Context_next_toward(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "next_toward", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; + PyObject *x; + PyObject *y; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + y = args[1]; + return_value = _decimal_Context_next_toward_impl(context, cls, x, y); + +exit: + return return_value; +} + +PyDoc_STRVAR(_decimal_Context_quantize__doc__, +"quantize($self, x, y, /)\n" +"--\n" +"\n" +"Return a value equal to x (rounded), having the exponent of y."); + +#define _DECIMAL_CONTEXT_QUANTIZE_METHODDEF \ + {"quantize", _PyCFunction_CAST(_decimal_Context_quantize), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_quantize__doc__}, + +static PyObject * +_decimal_Context_quantize_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); + +static PyObject * +_decimal_Context_quantize(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "quantize", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; + PyObject *x; + PyObject *y; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + y = args[1]; + return_value = _decimal_Context_quantize_impl(context, cls, x, y); + +exit: + return return_value; +} + +PyDoc_STRVAR(_decimal_Context_remainder__doc__, +"remainder($self, x, y, /)\n" +"--\n" +"\n" +"Return the remainder from integer division.\n" +"\n" +"The sign of the result, if non-zero, is the same as that of the\n" +"original dividend."); + +#define _DECIMAL_CONTEXT_REMAINDER_METHODDEF \ + {"remainder", _PyCFunction_CAST(_decimal_Context_remainder), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_remainder__doc__}, + +static PyObject * +_decimal_Context_remainder_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); + +static PyObject * +_decimal_Context_remainder(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "remainder", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; + PyObject *x; + PyObject *y; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + y = args[1]; + return_value = _decimal_Context_remainder_impl(context, cls, x, y); + +exit: + return return_value; +} + +PyDoc_STRVAR(_decimal_Context_remainder_near__doc__, +"remainder_near($self, x, y, /)\n" +"--\n" +"\n" +"Return x - y * n.\n" +"\n" +"Here n is the integer nearest the exact value of x / y (if the result\n" +"is 0 then its sign will be the sign of x)."); + +#define _DECIMAL_CONTEXT_REMAINDER_NEAR_METHODDEF \ + {"remainder_near", _PyCFunction_CAST(_decimal_Context_remainder_near), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_remainder_near__doc__}, + +static PyObject * +_decimal_Context_remainder_near_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); + +static PyObject * +_decimal_Context_remainder_near(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "remainder_near", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; + PyObject *x; + PyObject *y; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + y = args[1]; + return_value = _decimal_Context_remainder_near_impl(context, cls, x, y); + +exit: + return return_value; +} + +PyDoc_STRVAR(_decimal_Context_subtract__doc__, +"subtract($self, x, y, /)\n" +"--\n" +"\n" +"Return the difference between x and y."); + +#define _DECIMAL_CONTEXT_SUBTRACT_METHODDEF \ + {"subtract", _PyCFunction_CAST(_decimal_Context_subtract), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_subtract__doc__}, + +static PyObject * +_decimal_Context_subtract_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); + +static PyObject * +_decimal_Context_subtract(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "subtract", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; + PyObject *x; + PyObject *y; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + y = args[1]; + return_value = _decimal_Context_subtract_impl(context, cls, x, y); + +exit: + return return_value; +} + +PyDoc_STRVAR(_decimal_Context_divmod__doc__, +"divmod($self, x, y, /)\n" +"--\n" +"\n" +"Return quotient and remainder of the division x / y."); + +#define _DECIMAL_CONTEXT_DIVMOD_METHODDEF \ + {"divmod", _PyCFunction_CAST(_decimal_Context_divmod), METH_FASTCALL, _decimal_Context_divmod__doc__}, + +static PyObject * +_decimal_Context_divmod_impl(PyObject *context, PyObject *x, PyObject *y); + +static PyObject * +_decimal_Context_divmod(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *x; + PyObject *y; + + if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) { + goto exit; + } + x = args[0]; + y = args[1]; + return_value = _decimal_Context_divmod_impl(context, x, y); + +exit: + return return_value; +} + +PyDoc_STRVAR(_decimal_Context_power__doc__, +"power($self, /, a, b, modulo=None)\n" +"--\n" +"\n" +"Compute a**b.\n" +"\n" +"If \'a\' is negative, then \'b\' must be integral. The result will be\n" +"inexact unless \'a\' is integral and the result is finite and can be\n" +"expressed exactly in \'precision\' digits. In the Python version the\n" +"result is always correctly rounded, in the C version the result is\n" +"almost always correctly rounded.\n" +"\n" +"If modulo is given, compute (a**b) % modulo. The following\n" +"restrictions hold:\n" +"\n" +" * all three arguments must be integral\n" +" * \'b\' must be nonnegative\n" +" * at least one of \'a\' or \'b\' must be nonzero\n" +" * modulo must be nonzero and less than 10**prec in absolute value"); + +#define _DECIMAL_CONTEXT_POWER_METHODDEF \ + {"power", _PyCFunction_CAST(_decimal_Context_power), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_power__doc__}, + +static PyObject * +_decimal_Context_power_impl(PyObject *context, PyTypeObject *cls, + PyObject *base, PyObject *exp, PyObject *mod); + +static PyObject * +_decimal_Context_power(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 3 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .ob_item = { _Py_LATIN1_CHR('a'), _Py_LATIN1_CHR('b'), &_Py_ID(modulo), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"a", "b", "modulo", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "power", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[3]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; + PyObject *base; + PyObject *exp; + PyObject *mod = Py_None; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + base = args[0]; + exp = args[1]; + if (!noptargs) { + goto skip_optional_pos; + } + mod = args[2]; +skip_optional_pos: + return_value = _decimal_Context_power_impl(context, cls, base, exp, mod); + +exit: + return return_value; +} + +PyDoc_STRVAR(_decimal_Context_fma__doc__, "fma($self, x, y, z, /)\n" "--\n" "\n" "Return x multiplied by y, plus z."); #define _DECIMAL_CONTEXT_FMA_METHODDEF \ - {"fma", _PyCFunction_CAST(_decimal_Context_fma), METH_FASTCALL, _decimal_Context_fma__doc__}, + {"fma", _PyCFunction_CAST(_decimal_Context_fma), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_fma__doc__}, static PyObject * -_decimal_Context_fma_impl(PyObject *context, PyObject *x, PyObject *y, - PyObject *z); +_decimal_Context_fma_impl(PyObject *context, PyTypeObject *cls, PyObject *x, + PyObject *y, PyObject *z); static PyObject * -_decimal_Context_fma(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_fma(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "fma", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[3]; PyObject *x; PyObject *y; PyObject *z; - if (!_PyArg_CheckPositional("fma", nargs, 3, 3)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; z = args[2]; - return_value = _decimal_Context_fma_impl(context, x, y, z); + return_value = _decimal_Context_fma_impl(context, cls, x, y, z); exit: return return_value; @@ -4388,15 +5448,19 @@ PyDoc_STRVAR(_decimal_Context_radix__doc__, "Return 10."); #define _DECIMAL_CONTEXT_RADIX_METHODDEF \ - {"radix", (PyCFunction)_decimal_Context_radix, METH_NOARGS, _decimal_Context_radix__doc__}, + {"radix", _PyCFunction_CAST(_decimal_Context_radix), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_radix__doc__}, static PyObject * -_decimal_Context_radix_impl(PyObject *context); +_decimal_Context_radix_impl(PyObject *context, PyTypeObject *cls); static PyObject * -_decimal_Context_radix(PyObject *context, PyObject *Py_UNUSED(ignored)) +_decimal_Context_radix(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _decimal_Context_radix_impl(context); + if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { + PyErr_SetString(PyExc_TypeError, "radix() takes no arguments"); + return NULL; + } + return _decimal_Context_radix_impl(context, cls); } PyDoc_STRVAR(_decimal_Context_is_normal__doc__, @@ -4406,7 +5470,43 @@ PyDoc_STRVAR(_decimal_Context_is_normal__doc__, "Return True if x is a normal number, False otherwise."); #define _DECIMAL_CONTEXT_IS_NORMAL_METHODDEF \ - {"is_normal", (PyCFunction)_decimal_Context_is_normal, METH_O, _decimal_Context_is_normal__doc__}, + {"is_normal", _PyCFunction_CAST(_decimal_Context_is_normal), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_is_normal__doc__}, + +static PyObject * +_decimal_Context_is_normal_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_is_normal(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "is_normal", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_is_normal_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_is_subnormal__doc__, "is_subnormal($self, x, /)\n" @@ -4415,7 +5515,43 @@ PyDoc_STRVAR(_decimal_Context_is_subnormal__doc__, "Return True if x is subnormal, False otherwise."); #define _DECIMAL_CONTEXT_IS_SUBNORMAL_METHODDEF \ - {"is_subnormal", (PyCFunction)_decimal_Context_is_subnormal, METH_O, _decimal_Context_is_subnormal__doc__}, + {"is_subnormal", _PyCFunction_CAST(_decimal_Context_is_subnormal), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_is_subnormal__doc__}, + +static PyObject * +_decimal_Context_is_subnormal_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_is_subnormal(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "is_subnormal", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_is_subnormal_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_is_finite__doc__, "is_finite($self, x, /)\n" @@ -4424,7 +5560,43 @@ PyDoc_STRVAR(_decimal_Context_is_finite__doc__, "Return True if x is finite, False otherwise."); #define _DECIMAL_CONTEXT_IS_FINITE_METHODDEF \ - {"is_finite", (PyCFunction)_decimal_Context_is_finite, METH_O, _decimal_Context_is_finite__doc__}, + {"is_finite", _PyCFunction_CAST(_decimal_Context_is_finite), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_is_finite__doc__}, + +static PyObject * +_decimal_Context_is_finite_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_is_finite(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "is_finite", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_is_finite_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_is_infinite__doc__, "is_infinite($self, x, /)\n" @@ -4433,7 +5605,43 @@ PyDoc_STRVAR(_decimal_Context_is_infinite__doc__, "Return True if x is infinite, False otherwise."); #define _DECIMAL_CONTEXT_IS_INFINITE_METHODDEF \ - {"is_infinite", (PyCFunction)_decimal_Context_is_infinite, METH_O, _decimal_Context_is_infinite__doc__}, + {"is_infinite", _PyCFunction_CAST(_decimal_Context_is_infinite), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_is_infinite__doc__}, + +static PyObject * +_decimal_Context_is_infinite_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_is_infinite(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "is_infinite", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_is_infinite_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_is_nan__doc__, "is_nan($self, x, /)\n" @@ -4442,7 +5650,43 @@ PyDoc_STRVAR(_decimal_Context_is_nan__doc__, "Return True if x is a qNaN or sNaN, False otherwise."); #define _DECIMAL_CONTEXT_IS_NAN_METHODDEF \ - {"is_nan", (PyCFunction)_decimal_Context_is_nan, METH_O, _decimal_Context_is_nan__doc__}, + {"is_nan", _PyCFunction_CAST(_decimal_Context_is_nan), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_is_nan__doc__}, + +static PyObject * +_decimal_Context_is_nan_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_is_nan(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "is_nan", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_is_nan_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_is_qnan__doc__, "is_qnan($self, x, /)\n" @@ -4451,7 +5695,43 @@ PyDoc_STRVAR(_decimal_Context_is_qnan__doc__, "Return True if x is a quiet NaN, False otherwise."); #define _DECIMAL_CONTEXT_IS_QNAN_METHODDEF \ - {"is_qnan", (PyCFunction)_decimal_Context_is_qnan, METH_O, _decimal_Context_is_qnan__doc__}, + {"is_qnan", _PyCFunction_CAST(_decimal_Context_is_qnan), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_is_qnan__doc__}, + +static PyObject * +_decimal_Context_is_qnan_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_is_qnan(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "is_qnan", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_is_qnan_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_is_snan__doc__, "is_snan($self, x, /)\n" @@ -4459,8 +5739,44 @@ PyDoc_STRVAR(_decimal_Context_is_snan__doc__, "\n" "Return True if x is a signaling NaN, False otherwise."); -#define _DECIMAL_CONTEXT_IS_SNAN_METHODDEF \ - {"is_snan", (PyCFunction)_decimal_Context_is_snan, METH_O, _decimal_Context_is_snan__doc__}, +#define _DECIMAL_CONTEXT_IS_SNAN_METHODDEF \ + {"is_snan", _PyCFunction_CAST(_decimal_Context_is_snan), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_is_snan__doc__}, + +static PyObject * +_decimal_Context_is_snan_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_is_snan(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "is_snan", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_is_snan_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_is_signed__doc__, "is_signed($self, x, /)\n" @@ -4469,7 +5785,43 @@ PyDoc_STRVAR(_decimal_Context_is_signed__doc__, "Return True if x is negative, False otherwise."); #define _DECIMAL_CONTEXT_IS_SIGNED_METHODDEF \ - {"is_signed", (PyCFunction)_decimal_Context_is_signed, METH_O, _decimal_Context_is_signed__doc__}, + {"is_signed", _PyCFunction_CAST(_decimal_Context_is_signed), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_is_signed__doc__}, + +static PyObject * +_decimal_Context_is_signed_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_is_signed(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "is_signed", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_is_signed_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_is_zero__doc__, "is_zero($self, x, /)\n" @@ -4478,7 +5830,43 @@ PyDoc_STRVAR(_decimal_Context_is_zero__doc__, "Return True if x is a zero, False otherwise."); #define _DECIMAL_CONTEXT_IS_ZERO_METHODDEF \ - {"is_zero", (PyCFunction)_decimal_Context_is_zero, METH_O, _decimal_Context_is_zero__doc__}, + {"is_zero", _PyCFunction_CAST(_decimal_Context_is_zero), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_is_zero__doc__}, + +static PyObject * +_decimal_Context_is_zero_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_is_zero(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "is_zero", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_is_zero_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_is_canonical__doc__, "is_canonical($self, x, /)\n" @@ -4487,7 +5875,43 @@ PyDoc_STRVAR(_decimal_Context_is_canonical__doc__, "Return True if x is canonical, False otherwise."); #define _DECIMAL_CONTEXT_IS_CANONICAL_METHODDEF \ - {"is_canonical", (PyCFunction)_decimal_Context_is_canonical, METH_O, _decimal_Context_is_canonical__doc__}, + {"is_canonical", _PyCFunction_CAST(_decimal_Context_is_canonical), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_is_canonical__doc__}, + +static PyObject * +_decimal_Context_is_canonical_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_is_canonical(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "is_canonical", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_is_canonical_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context__apply__doc__, "_apply($self, x, /)\n" @@ -4496,7 +5920,43 @@ PyDoc_STRVAR(_decimal_Context__apply__doc__, "Apply self to Decimal x."); #define _DECIMAL_CONTEXT__APPLY_METHODDEF \ - {"_apply", (PyCFunction)_decimal_Context__apply, METH_O, _decimal_Context__apply__doc__}, + {"_apply", _PyCFunction_CAST(_decimal_Context__apply), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context__apply__doc__}, + +static PyObject * +_decimal_Context__apply_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context__apply(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "_apply", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context__apply_impl(context, cls, x); + +exit: + return return_value; +} #if defined(EXTRA_FUNCTIONALITY) @@ -4507,7 +5967,43 @@ PyDoc_STRVAR(_decimal_Context_apply__doc__, "Apply self to Decimal x."); #define _DECIMAL_CONTEXT_APPLY_METHODDEF \ - {"apply", (PyCFunction)_decimal_Context_apply, METH_O, _decimal_Context_apply__doc__}, + {"apply", _PyCFunction_CAST(_decimal_Context_apply), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_apply__doc__}, + +static PyObject * +_decimal_Context_apply_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_apply(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "apply", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_apply_impl(context, cls, x); + +exit: + return return_value; +} #endif /* defined(EXTRA_FUNCTIONALITY) */ @@ -4518,7 +6014,43 @@ PyDoc_STRVAR(_decimal_Context_canonical__doc__, "Return a new instance of x."); #define _DECIMAL_CONTEXT_CANONICAL_METHODDEF \ - {"canonical", (PyCFunction)_decimal_Context_canonical, METH_O, _decimal_Context_canonical__doc__}, + {"canonical", _PyCFunction_CAST(_decimal_Context_canonical), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_canonical__doc__}, + +static PyObject * +_decimal_Context_canonical_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_canonical(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "canonical", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_canonical_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_copy_abs__doc__, "copy_abs($self, x, /)\n" @@ -4527,7 +6059,43 @@ PyDoc_STRVAR(_decimal_Context_copy_abs__doc__, "Return a copy of x with the sign set to 0."); #define _DECIMAL_CONTEXT_COPY_ABS_METHODDEF \ - {"copy_abs", (PyCFunction)_decimal_Context_copy_abs, METH_O, _decimal_Context_copy_abs__doc__}, + {"copy_abs", _PyCFunction_CAST(_decimal_Context_copy_abs), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_copy_abs__doc__}, + +static PyObject * +_decimal_Context_copy_abs_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_copy_abs(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "copy_abs", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_copy_abs_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_copy_decimal__doc__, "copy_decimal($self, x, /)\n" @@ -4536,7 +6104,43 @@ PyDoc_STRVAR(_decimal_Context_copy_decimal__doc__, "Return a copy of Decimal x."); #define _DECIMAL_CONTEXT_COPY_DECIMAL_METHODDEF \ - {"copy_decimal", (PyCFunction)_decimal_Context_copy_decimal, METH_O, _decimal_Context_copy_decimal__doc__}, + {"copy_decimal", _PyCFunction_CAST(_decimal_Context_copy_decimal), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_copy_decimal__doc__}, + +static PyObject * +_decimal_Context_copy_decimal_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_copy_decimal(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "copy_decimal", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_copy_decimal_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_copy_negate__doc__, "copy_negate($self, x, /)\n" @@ -4544,17 +6148,88 @@ PyDoc_STRVAR(_decimal_Context_copy_negate__doc__, "\n" "Return a copy of x with the sign inverted."); -#define _DECIMAL_CONTEXT_COPY_NEGATE_METHODDEF \ - {"copy_negate", (PyCFunction)_decimal_Context_copy_negate, METH_O, _decimal_Context_copy_negate__doc__}, +#define _DECIMAL_CONTEXT_COPY_NEGATE_METHODDEF \ + {"copy_negate", _PyCFunction_CAST(_decimal_Context_copy_negate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_copy_negate__doc__}, + +static PyObject * +_decimal_Context_copy_negate_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_copy_negate(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "copy_negate", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_copy_negate_impl(context, cls, x); + +exit: + return return_value; +} + +PyDoc_STRVAR(_decimal_Context_logb__doc__, +"logb($self, x, /)\n" +"--\n" +"\n" +"Return the exponent of the magnitude of the operand\'s MSD."); + +#define _DECIMAL_CONTEXT_LOGB_METHODDEF \ + {"logb", _PyCFunction_CAST(_decimal_Context_logb), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_logb__doc__}, + +static PyObject * +_decimal_Context_logb_impl(PyObject *context, PyTypeObject *cls, PyObject *x); + +static PyObject * +_decimal_Context_logb(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "logb", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; -PyDoc_STRVAR(_decimal_Context_logb__doc__, -"logb($self, x, /)\n" -"--\n" -"\n" -"Return the exponent of the magnitude of the operand\'s MSD."); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_logb_impl(context, cls, x); -#define _DECIMAL_CONTEXT_LOGB_METHODDEF \ - {"logb", (PyCFunction)_decimal_Context_logb, METH_O, _decimal_Context_logb__doc__}, +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_logical_invert__doc__, "logical_invert($self, x, /)\n" @@ -4563,7 +6238,43 @@ PyDoc_STRVAR(_decimal_Context_logical_invert__doc__, "Invert all digits of x."); #define _DECIMAL_CONTEXT_LOGICAL_INVERT_METHODDEF \ - {"logical_invert", (PyCFunction)_decimal_Context_logical_invert, METH_O, _decimal_Context_logical_invert__doc__}, + {"logical_invert", _PyCFunction_CAST(_decimal_Context_logical_invert), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_logical_invert__doc__}, + +static PyObject * +_decimal_Context_logical_invert_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_logical_invert(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "logical_invert", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_logical_invert_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_number_class__doc__, "number_class($self, x, /)\n" @@ -4572,7 +6283,43 @@ PyDoc_STRVAR(_decimal_Context_number_class__doc__, "Return an indication of the class of x."); #define _DECIMAL_CONTEXT_NUMBER_CLASS_METHODDEF \ - {"number_class", (PyCFunction)_decimal_Context_number_class, METH_O, _decimal_Context_number_class__doc__}, + {"number_class", _PyCFunction_CAST(_decimal_Context_number_class), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_number_class__doc__}, + +static PyObject * +_decimal_Context_number_class_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_number_class(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "number_class", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_number_class_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_to_sci_string__doc__, "to_sci_string($self, x, /)\n" @@ -4581,7 +6328,43 @@ PyDoc_STRVAR(_decimal_Context_to_sci_string__doc__, "Convert a number to a string using scientific notation."); #define _DECIMAL_CONTEXT_TO_SCI_STRING_METHODDEF \ - {"to_sci_string", (PyCFunction)_decimal_Context_to_sci_string, METH_O, _decimal_Context_to_sci_string__doc__}, + {"to_sci_string", _PyCFunction_CAST(_decimal_Context_to_sci_string), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_to_sci_string__doc__}, + +static PyObject * +_decimal_Context_to_sci_string_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_to_sci_string(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "to_sci_string", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_to_sci_string_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_to_eng_string__doc__, "to_eng_string($self, x, /)\n" @@ -4590,7 +6373,43 @@ PyDoc_STRVAR(_decimal_Context_to_eng_string__doc__, "Convert a number to a string, using engineering notation."); #define _DECIMAL_CONTEXT_TO_ENG_STRING_METHODDEF \ - {"to_eng_string", (PyCFunction)_decimal_Context_to_eng_string, METH_O, _decimal_Context_to_eng_string__doc__}, + {"to_eng_string", _PyCFunction_CAST(_decimal_Context_to_eng_string), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_to_eng_string__doc__}, + +static PyObject * +_decimal_Context_to_eng_string_impl(PyObject *context, PyTypeObject *cls, + PyObject *x); + +static PyObject * +_decimal_Context_to_eng_string(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "to_eng_string", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *x; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + x = args[0]; + return_value = _decimal_Context_to_eng_string_impl(context, cls, x); + +exit: + return return_value; +} PyDoc_STRVAR(_decimal_Context_compare_total__doc__, "compare_total($self, x, y, /)\n" @@ -4599,25 +6418,41 @@ PyDoc_STRVAR(_decimal_Context_compare_total__doc__, "Compare x and y using their abstract representation."); #define _DECIMAL_CONTEXT_COMPARE_TOTAL_METHODDEF \ - {"compare_total", _PyCFunction_CAST(_decimal_Context_compare_total), METH_FASTCALL, _decimal_Context_compare_total__doc__}, + {"compare_total", _PyCFunction_CAST(_decimal_Context_compare_total), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_compare_total__doc__}, static PyObject * -_decimal_Context_compare_total_impl(PyObject *context, PyObject *x, - PyObject *y); +_decimal_Context_compare_total_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_compare_total(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_compare_total(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "compare_total", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("compare_total", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_compare_total_impl(context, x, y); + return_value = _decimal_Context_compare_total_impl(context, cls, x, y); exit: return return_value; @@ -4630,25 +6465,41 @@ PyDoc_STRVAR(_decimal_Context_compare_total_mag__doc__, "Compare x and y using their abstract representation, ignoring sign."); #define _DECIMAL_CONTEXT_COMPARE_TOTAL_MAG_METHODDEF \ - {"compare_total_mag", _PyCFunction_CAST(_decimal_Context_compare_total_mag), METH_FASTCALL, _decimal_Context_compare_total_mag__doc__}, + {"compare_total_mag", _PyCFunction_CAST(_decimal_Context_compare_total_mag), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_compare_total_mag__doc__}, static PyObject * -_decimal_Context_compare_total_mag_impl(PyObject *context, PyObject *x, - PyObject *y); +_decimal_Context_compare_total_mag_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_compare_total_mag(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_compare_total_mag(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "compare_total_mag", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("compare_total_mag", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_compare_total_mag_impl(context, x, y); + return_value = _decimal_Context_compare_total_mag_impl(context, cls, x, y); exit: return return_value; @@ -4661,24 +6512,41 @@ PyDoc_STRVAR(_decimal_Context_copy_sign__doc__, "Copy the sign from y to x."); #define _DECIMAL_CONTEXT_COPY_SIGN_METHODDEF \ - {"copy_sign", _PyCFunction_CAST(_decimal_Context_copy_sign), METH_FASTCALL, _decimal_Context_copy_sign__doc__}, + {"copy_sign", _PyCFunction_CAST(_decimal_Context_copy_sign), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_copy_sign__doc__}, static PyObject * -_decimal_Context_copy_sign_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_copy_sign_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_copy_sign(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_copy_sign(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "copy_sign", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("copy_sign", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_copy_sign_impl(context, x, y); + return_value = _decimal_Context_copy_sign_impl(context, cls, x, y); exit: return return_value; @@ -4691,25 +6559,41 @@ PyDoc_STRVAR(_decimal_Context_logical_and__doc__, "Digit-wise and of x and y."); #define _DECIMAL_CONTEXT_LOGICAL_AND_METHODDEF \ - {"logical_and", _PyCFunction_CAST(_decimal_Context_logical_and), METH_FASTCALL, _decimal_Context_logical_and__doc__}, + {"logical_and", _PyCFunction_CAST(_decimal_Context_logical_and), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_logical_and__doc__}, static PyObject * -_decimal_Context_logical_and_impl(PyObject *context, PyObject *x, - PyObject *y); +_decimal_Context_logical_and_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_logical_and(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_logical_and(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "logical_and", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("logical_and", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_logical_and_impl(context, x, y); + return_value = _decimal_Context_logical_and_impl(context, cls, x, y); exit: return return_value; @@ -4722,24 +6606,41 @@ PyDoc_STRVAR(_decimal_Context_logical_or__doc__, "Digit-wise or of x and y."); #define _DECIMAL_CONTEXT_LOGICAL_OR_METHODDEF \ - {"logical_or", _PyCFunction_CAST(_decimal_Context_logical_or), METH_FASTCALL, _decimal_Context_logical_or__doc__}, + {"logical_or", _PyCFunction_CAST(_decimal_Context_logical_or), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_logical_or__doc__}, static PyObject * -_decimal_Context_logical_or_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_logical_or_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_logical_or(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_logical_or(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "logical_or", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("logical_or", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_logical_or_impl(context, x, y); + return_value = _decimal_Context_logical_or_impl(context, cls, x, y); exit: return return_value; @@ -4752,25 +6653,41 @@ PyDoc_STRVAR(_decimal_Context_logical_xor__doc__, "Digit-wise xor of x and y."); #define _DECIMAL_CONTEXT_LOGICAL_XOR_METHODDEF \ - {"logical_xor", _PyCFunction_CAST(_decimal_Context_logical_xor), METH_FASTCALL, _decimal_Context_logical_xor__doc__}, + {"logical_xor", _PyCFunction_CAST(_decimal_Context_logical_xor), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_logical_xor__doc__}, static PyObject * -_decimal_Context_logical_xor_impl(PyObject *context, PyObject *x, - PyObject *y); +_decimal_Context_logical_xor_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_logical_xor(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_logical_xor(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "logical_xor", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("logical_xor", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_logical_xor_impl(context, x, y); + return_value = _decimal_Context_logical_xor_impl(context, cls, x, y); exit: return return_value; @@ -4783,24 +6700,41 @@ PyDoc_STRVAR(_decimal_Context_rotate__doc__, "Return a copy of x, rotated by y places."); #define _DECIMAL_CONTEXT_ROTATE_METHODDEF \ - {"rotate", _PyCFunction_CAST(_decimal_Context_rotate), METH_FASTCALL, _decimal_Context_rotate__doc__}, + {"rotate", _PyCFunction_CAST(_decimal_Context_rotate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_rotate__doc__}, static PyObject * -_decimal_Context_rotate_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_rotate_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_rotate(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_rotate(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "rotate", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("rotate", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_rotate_impl(context, x, y); + return_value = _decimal_Context_rotate_impl(context, cls, x, y); exit: return return_value; @@ -4813,24 +6747,41 @@ PyDoc_STRVAR(_decimal_Context_scaleb__doc__, "Return the first operand after adding the second value to its exp."); #define _DECIMAL_CONTEXT_SCALEB_METHODDEF \ - {"scaleb", _PyCFunction_CAST(_decimal_Context_scaleb), METH_FASTCALL, _decimal_Context_scaleb__doc__}, + {"scaleb", _PyCFunction_CAST(_decimal_Context_scaleb), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_scaleb__doc__}, static PyObject * -_decimal_Context_scaleb_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_scaleb_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_scaleb(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_scaleb(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "scaleb", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("scaleb", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_scaleb_impl(context, x, y); + return_value = _decimal_Context_scaleb_impl(context, cls, x, y); exit: return return_value; @@ -4843,24 +6794,41 @@ PyDoc_STRVAR(_decimal_Context_shift__doc__, "Return a copy of x, shifted by y places."); #define _DECIMAL_CONTEXT_SHIFT_METHODDEF \ - {"shift", _PyCFunction_CAST(_decimal_Context_shift), METH_FASTCALL, _decimal_Context_shift__doc__}, + {"shift", _PyCFunction_CAST(_decimal_Context_shift), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_shift__doc__}, static PyObject * -_decimal_Context_shift_impl(PyObject *context, PyObject *x, PyObject *y); +_decimal_Context_shift_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_shift(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_shift(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "shift", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("shift", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_shift_impl(context, x, y); + return_value = _decimal_Context_shift_impl(context, cls, x, y); exit: return return_value; @@ -4873,31 +6841,59 @@ PyDoc_STRVAR(_decimal_Context_same_quantum__doc__, "Return True if the two operands have the same exponent."); #define _DECIMAL_CONTEXT_SAME_QUANTUM_METHODDEF \ - {"same_quantum", _PyCFunction_CAST(_decimal_Context_same_quantum), METH_FASTCALL, _decimal_Context_same_quantum__doc__}, + {"same_quantum", _PyCFunction_CAST(_decimal_Context_same_quantum), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _decimal_Context_same_quantum__doc__}, static PyObject * -_decimal_Context_same_quantum_impl(PyObject *context, PyObject *x, - PyObject *y); +_decimal_Context_same_quantum_impl(PyObject *context, PyTypeObject *cls, + PyObject *x, PyObject *y); static PyObject * -_decimal_Context_same_quantum(PyObject *context, PyObject *const *args, Py_ssize_t nargs) +_decimal_Context_same_quantum(PyObject *context, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "same_quantum", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; PyObject *x; PyObject *y; - if (!_PyArg_CheckPositional("same_quantum", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } x = args[0]; y = args[1]; - return_value = _decimal_Context_same_quantum_impl(context, x, y); + return_value = _decimal_Context_same_quantum_impl(context, cls, x, y); exit: return return_value; } +#ifndef _DECIMAL_CONTEXT__UNSAFE_SETPREC_METHODDEF + #define _DECIMAL_CONTEXT__UNSAFE_SETPREC_METHODDEF +#endif /* !defined(_DECIMAL_CONTEXT__UNSAFE_SETPREC_METHODDEF) */ + +#ifndef _DECIMAL_CONTEXT__UNSAFE_SETEMIN_METHODDEF + #define _DECIMAL_CONTEXT__UNSAFE_SETEMIN_METHODDEF +#endif /* !defined(_DECIMAL_CONTEXT__UNSAFE_SETEMIN_METHODDEF) */ + +#ifndef _DECIMAL_CONTEXT__UNSAFE_SETEMAX_METHODDEF + #define _DECIMAL_CONTEXT__UNSAFE_SETEMAX_METHODDEF +#endif /* !defined(_DECIMAL_CONTEXT__UNSAFE_SETEMAX_METHODDEF) */ + #ifndef _DECIMAL_CONTEXT_APPLY_METHODDEF #define _DECIMAL_CONTEXT_APPLY_METHODDEF #endif /* !defined(_DECIMAL_CONTEXT_APPLY_METHODDEF) */ -/*[clinic end generated code: output=1e10ddd6610e17dc input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e938de3a355a353a input=a9049054013a1b77]*/ diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index d0fe7ad61547da..0a2b35025321cf 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -553,8 +553,8 @@ _io__Buffered_close_impl(buffered *self) if (!ENTER_BUFFERED(self)) { return NULL; } - - r = buffered_closed(self); + /* gh-138720: Use IS_CLOSED to match flush CHECK_CLOSED. */ + r = IS_CLOSED(self); if (r < 0) goto end; if (r > 0) { @@ -1789,18 +1789,18 @@ _bufferedreader_read_fast(buffered *self, Py_ssize_t n) static PyObject * _bufferedreader_read_generic(buffered *self, Py_ssize_t n) { - PyObject *res = NULL; Py_ssize_t current_size, remaining, written; - char *out; current_size = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t); if (n <= current_size) return _bufferedreader_read_fast(self, n); - res = PyBytes_FromStringAndSize(NULL, n); - if (res == NULL) + PyBytesWriter *writer = PyBytesWriter_Create(n); + if (writer == NULL) { goto error; - out = PyBytes_AS_STRING(res); + } + char *out = PyBytesWriter_GetData(writer); + remaining = n; written = 0; if (current_size > 0) { @@ -1829,11 +1829,9 @@ _bufferedreader_read_generic(buffered *self, Py_ssize_t n) if (r == 0 || r == -2) { /* EOF occurred or read() would block. */ if (r == 0 || written > 0) { - if (_PyBytes_Resize(&res, written)) - goto error; - return res; + return PyBytesWriter_FinishWithSize(writer, written); } - Py_DECREF(res); + PyBytesWriter_Discard(writer); Py_RETURN_NONE; } remaining -= r; @@ -1853,11 +1851,9 @@ _bufferedreader_read_generic(buffered *self, Py_ssize_t n) if (r == 0 || r == -2) { /* EOF occurred or read() would block. */ if (r == 0 || written > 0) { - if (_PyBytes_Resize(&res, written)) - goto error; - return res; + return PyBytesWriter_FinishWithSize(writer, written); } - Py_DECREF(res); + PyBytesWriter_Discard(writer); Py_RETURN_NONE; } if (remaining > r) { @@ -1876,10 +1872,10 @@ _bufferedreader_read_generic(buffered *self, Py_ssize_t n) break; } - return res; + return PyBytesWriter_Finish(writer); error: - Py_XDECREF(res); + PyBytesWriter_Discard(writer); return NULL; } diff --git a/Modules/_sqlite/blob.c b/Modules/_sqlite/blob.c index b619a13b562766..7f1fa26c3bac62 100644 --- a/Modules/_sqlite/blob.c +++ b/Modules/_sqlite/blob.c @@ -143,23 +143,23 @@ read_multiple(pysqlite_Blob *self, Py_ssize_t length, Py_ssize_t offset) assert(length <= sqlite3_blob_bytes(self->blob)); assert(offset < sqlite3_blob_bytes(self->blob)); - PyObject *buffer = PyBytes_FromStringAndSize(NULL, length); - if (buffer == NULL) { + PyBytesWriter *writer = PyBytesWriter_Create(length); + if (writer == NULL) { return NULL; } + char *raw_buffer = PyBytesWriter_GetData(writer); - char *raw_buffer = PyBytes_AS_STRING(buffer); int rc; Py_BEGIN_ALLOW_THREADS rc = sqlite3_blob_read(self->blob, raw_buffer, (int)length, (int)offset); Py_END_ALLOW_THREADS if (rc != SQLITE_OK) { - Py_DECREF(buffer); + PyBytesWriter_Discard(writer); blob_seterror(self, rc); return NULL; } - return buffer; + return PyBytesWriter_Finish(writer); } @@ -196,7 +196,7 @@ blob_read_impl(pysqlite_Blob *self, int length) assert(length >= 0); if (length == 0) { - return PyBytes_FromStringAndSize(NULL, 0); + return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); } PyObject *buffer = read_multiple(self, length, self->offset); @@ -440,20 +440,25 @@ subscript_slice(pysqlite_Blob *self, PyObject *item) if (step == 1) { return read_multiple(self, len, start); } + PyObject *blob = read_multiple(self, stop - start, start); if (blob == NULL) { return NULL; } - PyObject *result = PyBytes_FromStringAndSize(NULL, len); - if (result != NULL) { - char *blob_buf = PyBytes_AS_STRING(blob); - char *res_buf = PyBytes_AS_STRING(result); - for (Py_ssize_t i = 0, j = 0; i < len; i++, j += step) { - res_buf[i] = blob_buf[j]; - } + + PyBytesWriter *writer = PyBytesWriter_Create(len); + if (writer == NULL) { Py_DECREF(blob); + return NULL; + } + char *res_buf = PyBytesWriter_GetData(writer); + + char *blob_buf = PyBytes_AS_STRING(blob); + for (Py_ssize_t i = 0, j = 0; i < len; i++, j += step) { + res_buf[i] = blob_buf[j]; } - return result; + Py_DECREF(blob); + return PyBytesWriter_Finish(writer); } static PyObject * diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 0f1d007e47de2a..0731c48b460105 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -2891,7 +2891,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len, int group_right_1, Py_buffer *buffer) /*[clinic end generated code: output=49b16e6406023734 input=80ed30436df01a71]*/ { - PyObject *dest = NULL; + PyBytesWriter *writer = NULL; char *mem; size_t count = 0; int retval; @@ -2918,14 +2918,16 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len, } if (!group_right_1) { - dest = PyBytes_FromStringAndSize(NULL, len); - if (dest == NULL) - goto error; if (len == 0) { Py_XDECREF(sock); - return dest; + return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); + } + + writer = PyBytesWriter_Create(len); + if (writer == NULL) { + goto error; } - mem = PyBytes_AS_STRING(dest); + mem = PyBytesWriter_GetData(writer); } else { mem = buffer->buf; @@ -3003,8 +3005,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len, done: Py_XDECREF(sock); if (!group_right_1) { - _PyBytes_Resize(&dest, count); - return dest; + return PyBytesWriter_FinishWithSize(writer, count); } else { return PyLong_FromSize_t(count); @@ -3013,8 +3014,9 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len, error: PySSL_ChainExceptions(self); Py_XDECREF(sock); - if (!group_right_1) - Py_XDECREF(dest); + if (!group_right_1) { + PyBytesWriter_Discard(writer); + } return NULL; } @@ -5848,30 +5850,29 @@ _ssl_MemoryBIO_read_impl(PySSLMemoryBIO *self, int len) /*[clinic end generated code: output=a657aa1e79cd01b3 input=21046f2d7dac3a90]*/ { int avail, nbytes; - PyObject *result; avail = (int)Py_MIN(BIO_ctrl_pending(self->bio), INT_MAX); if ((len < 0) || (len > avail)) len = avail; - result = PyBytes_FromStringAndSize(NULL, len); - if ((result == NULL) || (len == 0)) - return result; + if (len == 0) { + return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); + } - nbytes = BIO_read(self->bio, PyBytes_AS_STRING(result), len); + PyBytesWriter *writer = PyBytesWriter_Create(len); + if (writer == NULL) { + return NULL; + } + + nbytes = BIO_read(self->bio, PyBytesWriter_GetData(writer), len); if (nbytes < 0) { _sslmodulestate *state = get_state_mbio(self); - Py_DECREF(result); + PyBytesWriter_Discard(writer); _setSSLError(state, NULL, 0, __FILE__, __LINE__); return NULL; } - /* There should never be any short reads but check anyway. */ - if (nbytes < len) { - _PyBytes_Resize(&result, nbytes); - } - - return result; + return PyBytesWriter_FinishWithSize(writer, nbytes); } /*[clinic input] diff --git a/Modules/_testcapi/heaptype.c b/Modules/_testcapi/heaptype.c index 257e0256655976..69dcf072da1815 100644 --- a/Modules/_testcapi/heaptype.c +++ b/Modules/_testcapi/heaptype.c @@ -782,10 +782,7 @@ heapctypesubclasswithfinalizer_finalize(PyObject *self) /* Save the current exception, if any. */ PyObject *exc = PyErr_GetRaisedException(); - if (_testcapimodule == NULL) { - goto cleanup_finalize; - } - PyObject *m = PyState_FindModule(_testcapimodule); + PyObject *m = PyType_GetModule(Py_TYPE(self)); if (m == NULL) { goto cleanup_finalize; } @@ -1402,8 +1399,8 @@ _PyTestCapi_Init_Heaptype(PyObject *m) { if (subclass_with_finalizer_bases == NULL) { return -1; } - PyObject *HeapCTypeSubclassWithFinalizer = PyType_FromSpecWithBases( - &HeapCTypeSubclassWithFinalizer_spec, subclass_with_finalizer_bases); + PyObject *HeapCTypeSubclassWithFinalizer = PyType_FromModuleAndSpec( + m, &HeapCTypeSubclassWithFinalizer_spec, subclass_with_finalizer_bases); Py_DECREF(subclass_with_finalizer_bases); ADD("HeapCTypeSubclassWithFinalizer", HeapCTypeSubclassWithFinalizer); diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index c80a780e22ca34..a5c4604056ab4e 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -3243,75 +3243,56 @@ create_managed_dict_type(void) return PyType_FromSpec(&ManagedDict_spec); } -static struct PyModuleDef _testcapimodule = { - PyModuleDef_HEAD_INIT, - .m_name = "_testcapi", - .m_size = sizeof(testcapistate_t), - .m_methods = TestMethods, -}; - -/* Per PEP 489, this module will not be converted to multi-phase initialization - */ - -PyMODINIT_FUNC -PyInit__testcapi(void) +static int +_testcapi_exec(PyObject *m) { - PyObject *m; - - m = PyModule_Create(&_testcapimodule); - if (m == NULL) - return NULL; -#ifdef Py_GIL_DISABLED - PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED); -#endif - Py_SET_TYPE(&_HashInheritanceTester_Type, &PyType_Type); if (PyType_Ready(&_HashInheritanceTester_Type) < 0) { - return NULL; + return -1; } if (PyType_Ready(&matmulType) < 0) - return NULL; + return -1; Py_INCREF(&matmulType); PyModule_AddObject(m, "matmulType", (PyObject *)&matmulType); if (PyType_Ready(&ipowType) < 0) { - return NULL; + return -1; } Py_INCREF(&ipowType); PyModule_AddObject(m, "ipowType", (PyObject *)&ipowType); if (PyType_Ready(&awaitType) < 0) - return NULL; + return -1; Py_INCREF(&awaitType); PyModule_AddObject(m, "awaitType", (PyObject *)&awaitType); MyList_Type.tp_base = &PyList_Type; if (PyType_Ready(&MyList_Type) < 0) - return NULL; + return -1; Py_INCREF(&MyList_Type); PyModule_AddObject(m, "MyList", (PyObject *)&MyList_Type); if (PyType_Ready(&GenericAlias_Type) < 0) - return NULL; + return -1; Py_INCREF(&GenericAlias_Type); PyModule_AddObject(m, "GenericAlias", (PyObject *)&GenericAlias_Type); if (PyType_Ready(&Generic_Type) < 0) - return NULL; + return -1; Py_INCREF(&Generic_Type); PyModule_AddObject(m, "Generic", (PyObject *)&Generic_Type); if (PyType_Ready(&MethInstance_Type) < 0) - return NULL; + return -1; Py_INCREF(&MethInstance_Type); PyModule_AddObject(m, "MethInstance", (PyObject *)&MethInstance_Type); if (PyType_Ready(&MethClass_Type) < 0) - return NULL; + return -1; Py_INCREF(&MethClass_Type); PyModule_AddObject(m, "MethClass", (PyObject *)&MethClass_Type); if (PyType_Ready(&MethStatic_Type) < 0) - return NULL; + return -1; Py_INCREF(&MethStatic_Type); PyModule_AddObject(m, "MethStatic", (PyObject *)&MethStatic_Type); @@ -3354,13 +3335,13 @@ PyInit__testcapi(void) PyModule_AddObject(m, "UINT64_MAX", PyLong_FromUInt64(UINT64_MAX)); if (PyModule_AddIntMacro(m, Py_single_input)) { - return NULL; + return -1; } if (PyModule_AddIntMacro(m, Py_file_input)) { - return NULL; + return -1; } if (PyModule_AddIntMacro(m, Py_eval_input)) { - return NULL; + return -1; } testcapistate_t *state = get_testcapi_state(m); @@ -3368,145 +3349,165 @@ PyInit__testcapi(void) PyModule_AddObject(m, "error", state->error); if (PyType_Ready(&ContainerNoGC_type) < 0) { - return NULL; + return -1; } Py_INCREF(&ContainerNoGC_type); if (PyModule_AddObject(m, "ContainerNoGC", (PyObject *) &ContainerNoGC_type) < 0) - return NULL; + return -1; PyObject *manual_heap_type = create_manual_heap_type(); if (manual_heap_type == NULL) { - return NULL; + return -1; } if (PyModule_Add(m, "ManualHeapType", manual_heap_type) < 0) { - return NULL; + return -1; } PyObject *managed_dict_type = create_managed_dict_type(); if (managed_dict_type == NULL) { - return NULL; + return -1; } if (PyModule_Add(m, "ManagedDictType", managed_dict_type) < 0) { - return NULL; + return -1; } /* Include tests from the _testcapi/ directory */ if (_PyTestCapi_Init_Vectorcall(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Heaptype(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Abstract(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Bytes(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Unicode(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_GetArgs(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_DateTime(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Docstring(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Mem(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Watchers(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Long(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Float(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Complex(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Numbers(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Dict(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Set(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_List(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Tuple(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Structmember(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Exceptions(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Code(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Buffer(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_File(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Codec(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Immortal(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_GC(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_PyAtomic(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Run(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Hash(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Time(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Modsupport(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Monitoring(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Object(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Config(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Import(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Frame(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Type(m) < 0) { - return NULL; + return -1; } if (_PyTestCapi_Init_Function(m) < 0) { - return NULL; + return -1; } - PyState_AddModule(m, &_testcapimodule); - return m; + return 0; +} + +static PyModuleDef_Slot _testcapi_slots[] = { + {Py_mod_exec, _testcapi_exec}, + {Py_mod_gil, Py_MOD_GIL_NOT_USED}, + {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, + {0, NULL}, +}; + +static struct PyModuleDef _testcapimodule = { + PyModuleDef_HEAD_INIT, + .m_name = "_testcapi", + .m_size = sizeof(testcapistate_t), + .m_methods = TestMethods, + .m_slots = _testcapi_slots +}; + +PyMODINIT_FUNC +PyInit__testcapi(void) +{ + return PyModuleDef_Init(&_testcapimodule); } diff --git a/Modules/_testclinic.c b/Modules/_testclinic.c index 69adf7d1a0a950..5c196c0dd0fb01 100644 --- a/Modules/_testclinic.c +++ b/Modules/_testclinic.c @@ -2308,6 +2308,88 @@ depr_multi_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c, #undef _SAVED_PY_VERSION +/*[clinic input] +output pop +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=e7c7c42daced52b0]*/ + + +/*[clinic input] +output push +destination kwarg new file '{dirname}/clinic/_testclinic_kwds.c.h' +output everything kwarg +output docstring_prototype suppress +output parser_prototype suppress +output impl_definition block +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=02965b54b3981cc4]*/ + +#include "clinic/_testclinic_kwds.c.h" + + +/*[clinic input] +lone_kwds + **kwds: dict +[clinic start generated code]*/ + +static PyObject * +lone_kwds_impl(PyObject *module, PyObject *kwds) +/*[clinic end generated code: output=572549c687a0432e input=6ef338b913ecae17]*/ +{ + return pack_arguments_newref(1, kwds); +} + + +/*[clinic input] +kwds_with_pos_only + a: object + b: object + / + **kwds: dict +[clinic start generated code]*/ + +static PyObject * +kwds_with_pos_only_impl(PyObject *module, PyObject *a, PyObject *b, + PyObject *kwds) +/*[clinic end generated code: output=573096d3a7efcce5 input=da081a5d9ae8878a]*/ +{ + return pack_arguments_newref(3, a, b, kwds); +} + + +/*[clinic input] +kwds_with_stararg + *args: tuple + **kwds: dict +[clinic start generated code]*/ + +static PyObject * +kwds_with_stararg_impl(PyObject *module, PyObject *args, PyObject *kwds) +/*[clinic end generated code: output=d4b0064626a25208 input=1be404572d685859]*/ +{ + return pack_arguments_newref(2, args, kwds); +} + + +/*[clinic input] +kwds_with_pos_only_and_stararg + a: object + b: object + / + *args: tuple + **kwds: dict +[clinic start generated code]*/ + +static PyObject * +kwds_with_pos_only_and_stararg_impl(PyObject *module, PyObject *a, + PyObject *b, PyObject *args, + PyObject *kwds) +/*[clinic end generated code: output=af7df7640c792246 input=2fe330c7981f0829]*/ +{ + return pack_arguments_newref(4, a, b, args, kwds); +} + + /*[clinic input] output pop [clinic start generated code]*/ @@ -2404,6 +2486,12 @@ static PyMethodDef tester_methods[] = { DEPR_KWD_NOINLINE_METHODDEF DEPR_KWD_MULTI_METHODDEF DEPR_MULTI_METHODDEF + + LONE_KWDS_METHODDEF + KWDS_WITH_POS_ONLY_METHODDEF + KWDS_WITH_STARARG_METHODDEF + KWDS_WITH_POS_ONLY_AND_STARARG_METHODDEF + {NULL, NULL} }; diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c index 243c7346576fc6..7aa63f913af335 100644 --- a/Modules/_testinternalcapi.c +++ b/Modules/_testinternalcapi.c @@ -2376,6 +2376,16 @@ emscripten_set_up_async_input_device(PyObject *self, PyObject *Py_UNUSED(ignored } #endif +static PyObject * +simple_pending_call(PyObject *self, PyObject *callable) +{ + if (_PyEval_AddPendingCall(_PyInterpreterState_GET(), _pending_callback, Py_NewRef(callable), 0) < 0) { + return NULL; + } + + Py_RETURN_NONE; +} + static PyMethodDef module_functions[] = { {"get_configs", get_configs, METH_NOARGS}, {"get_recursion_depth", get_recursion_depth, METH_NOARGS}, @@ -2481,6 +2491,7 @@ static PyMethodDef module_functions[] = { #ifdef __EMSCRIPTEN__ {"emscripten_set_up_async_input_device", emscripten_set_up_async_input_device, METH_NOARGS}, #endif + {"simple_pending_call", simple_pending_call, METH_O}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index c6d07b1360711c..070732aba860b2 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -429,7 +429,7 @@ force_done(void *arg) static int ThreadHandle_start(ThreadHandle *self, PyObject *func, PyObject *args, - PyObject *kwargs) + PyObject *kwargs, int daemon) { // Mark the handle as starting to prevent any other threads from doing so PyMutex_Lock(&self->mutex); @@ -453,7 +453,8 @@ ThreadHandle_start(ThreadHandle *self, PyObject *func, PyObject *args, goto start_failed; } PyInterpreterState *interp = _PyInterpreterState_GET(); - boot->tstate = _PyThreadState_New(interp, _PyThreadState_WHENCE_THREADING); + uint8_t whence = daemon ? _PyThreadState_WHENCE_THREADING_DAEMON : _PyThreadState_WHENCE_THREADING; + boot->tstate = _PyThreadState_New(interp, whence); if (boot->tstate == NULL) { PyMem_RawFree(boot); if (!PyErr_Occurred()) { @@ -1916,7 +1917,7 @@ do_start_new_thread(thread_module_state *state, PyObject *func, PyObject *args, add_to_shutdown_handles(state, handle); } - if (ThreadHandle_start(handle, func, args, kwargs) < 0) { + if (ThreadHandle_start(handle, func, args, kwargs, daemon) < 0) { if (!daemon) { remove_from_shutdown_handles(handle); } diff --git a/Modules/clinic/_testclinic_kwds.c.h b/Modules/clinic/_testclinic_kwds.c.h new file mode 100644 index 00000000000000..e2fd4d9f3b4591 --- /dev/null +++ b/Modules/clinic/_testclinic_kwds.c.h @@ -0,0 +1,184 @@ +/*[clinic input] +preserve +[clinic start generated code]*/ + +#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) +# include "pycore_gc.h" // PyGC_Head +#endif +#include "pycore_abstract.h" // _PyNumber_Index() +#include "pycore_long.h" // _PyLong_UnsignedShort_Converter() +#include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_runtime.h" // _Py_ID() +#include "pycore_tuple.h" // _PyTuple_FromArray() + +PyDoc_STRVAR(lone_kwds__doc__, +"lone_kwds($module, /, **kwds)\n" +"--\n" +"\n"); + +#define LONE_KWDS_METHODDEF \ + {"lone_kwds", _PyCFunction_CAST(lone_kwds), METH_VARARGS|METH_KEYWORDS, lone_kwds__doc__}, + +static PyObject * +lone_kwds_impl(PyObject *module, PyObject *kwds); + +static PyObject * +lone_kwds(PyObject *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + PyObject *__clinic_kwds = NULL; + + if (!_PyArg_NoPositional("lone_kwds", args)) { + goto exit; + } + if (kwargs == NULL) { + __clinic_kwds = PyDict_New(); + if (__clinic_kwds == NULL) { + goto exit; + } + } + else { + __clinic_kwds = Py_NewRef(kwargs); + } + return_value = lone_kwds_impl(module, __clinic_kwds); + +exit: + /* Cleanup for kwds */ + Py_XDECREF(__clinic_kwds); + + return return_value; +} + +PyDoc_STRVAR(kwds_with_pos_only__doc__, +"kwds_with_pos_only($module, a, b, /, **kwds)\n" +"--\n" +"\n"); + +#define KWDS_WITH_POS_ONLY_METHODDEF \ + {"kwds_with_pos_only", _PyCFunction_CAST(kwds_with_pos_only), METH_VARARGS|METH_KEYWORDS, kwds_with_pos_only__doc__}, + +static PyObject * +kwds_with_pos_only_impl(PyObject *module, PyObject *a, PyObject *b, + PyObject *kwds); + +static PyObject * +kwds_with_pos_only(PyObject *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + PyObject *a; + PyObject *b; + PyObject *__clinic_kwds = NULL; + + if (!_PyArg_CheckPositional("kwds_with_pos_only", PyTuple_GET_SIZE(args), 2, 2)) { + goto exit; + } + a = PyTuple_GET_ITEM(args, 0); + b = PyTuple_GET_ITEM(args, 1); + if (kwargs == NULL) { + __clinic_kwds = PyDict_New(); + if (__clinic_kwds == NULL) { + goto exit; + } + } + else { + __clinic_kwds = Py_NewRef(kwargs); + } + return_value = kwds_with_pos_only_impl(module, a, b, __clinic_kwds); + +exit: + /* Cleanup for kwds */ + Py_XDECREF(__clinic_kwds); + + return return_value; +} + +PyDoc_STRVAR(kwds_with_stararg__doc__, +"kwds_with_stararg($module, /, *args, **kwds)\n" +"--\n" +"\n"); + +#define KWDS_WITH_STARARG_METHODDEF \ + {"kwds_with_stararg", _PyCFunction_CAST(kwds_with_stararg), METH_VARARGS|METH_KEYWORDS, kwds_with_stararg__doc__}, + +static PyObject * +kwds_with_stararg_impl(PyObject *module, PyObject *args, PyObject *kwds); + +static PyObject * +kwds_with_stararg(PyObject *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + PyObject *__clinic_args = NULL; + PyObject *__clinic_kwds = NULL; + + __clinic_args = Py_NewRef(args); + if (kwargs == NULL) { + __clinic_kwds = PyDict_New(); + if (__clinic_kwds == NULL) { + goto exit; + } + } + else { + __clinic_kwds = Py_NewRef(kwargs); + } + return_value = kwds_with_stararg_impl(module, __clinic_args, __clinic_kwds); + +exit: + /* Cleanup for args */ + Py_XDECREF(__clinic_args); + /* Cleanup for kwds */ + Py_XDECREF(__clinic_kwds); + + return return_value; +} + +PyDoc_STRVAR(kwds_with_pos_only_and_stararg__doc__, +"kwds_with_pos_only_and_stararg($module, a, b, /, *args, **kwds)\n" +"--\n" +"\n"); + +#define KWDS_WITH_POS_ONLY_AND_STARARG_METHODDEF \ + {"kwds_with_pos_only_and_stararg", _PyCFunction_CAST(kwds_with_pos_only_and_stararg), METH_VARARGS|METH_KEYWORDS, kwds_with_pos_only_and_stararg__doc__}, + +static PyObject * +kwds_with_pos_only_and_stararg_impl(PyObject *module, PyObject *a, + PyObject *b, PyObject *args, + PyObject *kwds); + +static PyObject * +kwds_with_pos_only_and_stararg(PyObject *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + PyObject *a; + PyObject *b; + PyObject *__clinic_args = NULL; + PyObject *__clinic_kwds = NULL; + + if (!_PyArg_CheckPositional("kwds_with_pos_only_and_stararg", PyTuple_GET_SIZE(args), 2, PY_SSIZE_T_MAX)) { + goto exit; + } + a = PyTuple_GET_ITEM(args, 0); + b = PyTuple_GET_ITEM(args, 1); + __clinic_args = PyTuple_GetSlice(args, 2, PY_SSIZE_T_MAX); + if (!__clinic_args) { + goto exit; + } + if (kwargs == NULL) { + __clinic_kwds = PyDict_New(); + if (__clinic_kwds == NULL) { + goto exit; + } + } + else { + __clinic_kwds = Py_NewRef(kwargs); + } + return_value = kwds_with_pos_only_and_stararg_impl(module, a, b, __clinic_args, __clinic_kwds); + +exit: + /* Cleanup for args */ + Py_XDECREF(__clinic_args); + /* Cleanup for kwds */ + Py_XDECREF(__clinic_kwds); + + return return_value; +} +/*[clinic end generated code: output=e4dea1070e003f5d input=a9049054013a1b77]*/ diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 45e7c0d6451c15..dddf98d127c15f 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -7814,6 +7814,7 @@ PyDoc_STRVAR(os_preadv__doc__, "\n" "- RWF_HIPRI\n" "- RWF_NOWAIT\n" +"- RWF_DONTCACHE\n" "\n" "Using non-zero flags requires Linux 4.6 or newer."); @@ -8555,6 +8556,7 @@ PyDoc_STRVAR(os_pwritev__doc__, "- RWF_DSYNC\n" "- RWF_SYNC\n" "- RWF_APPEND\n" +"- RWF_DONTCACHE\n" "\n" "Using non-zero flags requires Linux 4.7 or newer."); @@ -13444,4 +13446,4 @@ os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py #ifndef OS__EMSCRIPTEN_LOG_METHODDEF #define OS__EMSCRIPTEN_LOG_METHODDEF #endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */ -/*[clinic end generated code: output=92662828d49f5d88 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b5b370c499174f85 input=a9049054013a1b77]*/ diff --git a/Modules/expat/refresh.sh b/Modules/expat/refresh.sh index cc7ae1686de052..0ea0e85d046988 100755 --- a/Modules/expat/refresh.sh +++ b/Modules/expat/refresh.sh @@ -54,6 +54,13 @@ rm libexpat.tar.gz # Step 3: Add the namespacing include to expat_external.h sed -i 's/# define Expat_External_INCLUDED 1/&\n\/* Namespace external symbols to allow multiple libexpat version to\n co-exist. \*\/\n#include "pyexpatns.h"/' expat_external.h +if ! grep -q '#include "pyexpatns\.h"' expat_external.h; then + echo " +Error: namespacing include not found in expat_external.h; +This may be due to source changes and will require updating this script" >&2 + exit 1 +fi + echo " Updated! next steps: - Verify all is okay: diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 62b0c35602323f..6da90dc95addce 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -11756,6 +11756,7 @@ The flags argument contains a bitwise OR of zero or more of the following flags: - RWF_HIPRI - RWF_NOWAIT +- RWF_DONTCACHE Using non-zero flags requires Linux 4.6 or newer. [clinic start generated code]*/ @@ -11763,7 +11764,7 @@ Using non-zero flags requires Linux 4.6 or newer. static Py_ssize_t os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, int flags) -/*[clinic end generated code: output=26fc9c6e58e7ada5 input=c1f876866fcd9d41]*/ +/*[clinic end generated code: output=26fc9c6e58e7ada5 input=34fb3b9ca06f7ba7]*/ { Py_ssize_t cnt, n; int async_err = 0; @@ -12413,6 +12414,7 @@ The flags argument contains a bitwise OR of zero or more of the following flags: - RWF_DSYNC - RWF_SYNC - RWF_APPEND +- RWF_DONTCACHE Using non-zero flags requires Linux 4.7 or newer. [clinic start generated code]*/ @@ -12420,7 +12422,7 @@ Using non-zero flags requires Linux 4.7 or newer. static Py_ssize_t os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, int flags) -/*[clinic end generated code: output=e3dd3e9d11a6a5c7 input=99d8a21493ff76ca]*/ +/*[clinic end generated code: output=e3dd3e9d11a6a5c7 input=664a67626d485665]*/ { Py_ssize_t cnt; Py_ssize_t result; @@ -17646,6 +17648,9 @@ all_ins(PyObject *m) #ifdef RWF_NOWAIT if (PyModule_AddIntConstant(m, "RWF_NOWAIT", RWF_NOWAIT)) return -1; #endif +#ifdef RWF_DONTCACHE + if (PyModule_AddIntConstant(m, "RWF_DONTCACHE", RWF_DONTCACHE)) return -1; +#endif #ifdef RWF_APPEND if (PyModule_AddIntConstant(m, "RWF_APPEND", RWF_APPEND)) return -1; #endif diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index cd314fdd5b1e14..07237ceaa647e6 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -3801,7 +3801,7 @@ byteswriter_allocated(PyBytesWriter *writer) static inline int -byteswriter_resize(PyBytesWriter *writer, Py_ssize_t size, int overallocate) +byteswriter_resize(PyBytesWriter *writer, Py_ssize_t size, int resize) { assert(size >= 0); @@ -3810,7 +3810,7 @@ byteswriter_resize(PyBytesWriter *writer, Py_ssize_t size, int overallocate) return 0; } - if (overallocate & writer->overallocate) { + if (resize & writer->overallocate) { if (size <= (PY_SSIZE_T_MAX - size / OVERALLOCATE_FACTOR)) { size += size / OVERALLOCATE_FACTOR; } @@ -3834,25 +3834,29 @@ byteswriter_resize(PyBytesWriter *writer, Py_ssize_t size, int overallocate) if (writer->obj == NULL) { return -1; } - assert((size_t)size > sizeof(writer->small_buffer)); - memcpy(PyByteArray_AS_STRING(writer->obj), - writer->small_buffer, - sizeof(writer->small_buffer)); + if (resize) { + assert((size_t)size > sizeof(writer->small_buffer)); + memcpy(PyByteArray_AS_STRING(writer->obj), + writer->small_buffer, + sizeof(writer->small_buffer)); + } } else { writer->obj = PyBytes_FromStringAndSize(NULL, size); if (writer->obj == NULL) { return -1; } - assert((size_t)size > sizeof(writer->small_buffer)); - memcpy(PyBytes_AS_STRING(writer->obj), - writer->small_buffer, - sizeof(writer->small_buffer)); + if (resize) { + assert((size_t)size > sizeof(writer->small_buffer)); + memcpy(PyBytes_AS_STRING(writer->obj), + writer->small_buffer, + sizeof(writer->small_buffer)); + } } #ifdef Py_DEBUG Py_ssize_t allocated = byteswriter_allocated(writer); - if (overallocate && allocated > old_allocated) { + if (resize && allocated > old_allocated) { memset(byteswriter_data(writer) + old_allocated, 0xff, allocated - old_allocated); } diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 517103acea8d8e..d7544d3a9fb122 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -107,7 +107,7 @@ _Py_HAVE_ZLIB;%(PreprocessorDefinitions) _Py_JIT;%(PreprocessorDefinitions) _Py_TIER2=$(UseTIER2);%(PreprocessorDefinitions) - Py_TAIL_CALL_INTERP=1;%(PreprocessorDefinitions) + _Py_TAIL_CALL_INTERP=1;%(PreprocessorDefinitions) HAVE_COMPUTED_GOTOS;%(PreprocessorDefinitions) Py_REMOTE_DEBUG;%(PreprocessorDefinitions) diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 74025ffe9cedc9..9b993188fb73c7 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -1219,7 +1219,7 @@ dummy_func( tstate->current_frame = frame->previous; assert(!_PyErr_Occurred(tstate)); PyObject *result = PyStackRef_AsPyObjectSteal(retval); -#if !Py_TAIL_CALL_INTERP +#if !_Py_TAIL_CALL_INTERP assert(frame == &entry.frame); #endif #ifdef _Py_TIER2 @@ -1509,7 +1509,7 @@ dummy_func( tier1 inst(CLEANUP_THROW, (sub_iter, last_sent_val, exc_value_st -- none, value)) { PyObject *exc_value = PyStackRef_AsPyObjectBorrow(exc_value_st); - #if !Py_TAIL_CALL_INTERP + #if !_Py_TAIL_CALL_INTERP assert(throwflag); #endif assert(exc_value && PyExceptionInstance_Check(exc_value)); @@ -5515,7 +5515,7 @@ dummy_func( } #endif RELOAD_STACK(); -#if Py_TAIL_CALL_INTERP +#if _Py_TAIL_CALL_INTERP int opcode; #endif DISPATCH(); @@ -5533,7 +5533,7 @@ dummy_func( if (frame->owner == FRAME_OWNED_BY_INTERPRETER) { /* Restore previous frame and exit */ tstate->current_frame = frame->previous; -#if !Py_TAIL_CALL_INTERP +#if !_Py_TAIL_CALL_INTERP assert(frame == &entry.frame); #endif #ifdef _Py_TIER2 @@ -5569,7 +5569,7 @@ dummy_func( assert(!_PyErr_Occurred(tstate)); #endif RELOAD_STACK(); -#if Py_TAIL_CALL_INTERP +#if _Py_TAIL_CALL_INTERP int opcode; #endif DISPATCH(); diff --git a/Python/ceval.c b/Python/ceval.c index 578c5d2a8b1420..7abbc9e9fd12b6 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -987,7 +987,7 @@ _PyObjectArray_Free(PyObject **array, PyObject **scratch) /* This setting is reversed below following _PyEval_EvalFrameDefault */ #endif -#if Py_TAIL_CALL_INTERP +#if _Py_TAIL_CALL_INTERP #include "opcode_targets.h" #include "generated_cases.c.h" #endif @@ -1019,15 +1019,16 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int check_invalid_reentrancy(); CALL_STAT_INC(pyeval_calls); -#if USE_COMPUTED_GOTOS && !Py_TAIL_CALL_INTERP +#if USE_COMPUTED_GOTOS && !_Py_TAIL_CALL_INTERP /* Import the static jump table */ #include "opcode_targets.h" + void **opcode_targets = opcode_targets_table; #endif #ifdef Py_STATS int lastopcode = 0; #endif -#if !Py_TAIL_CALL_INTERP +#if !_Py_TAIL_CALL_INTERP uint8_t opcode; /* Current opcode */ int oparg; /* Current opcode argument, if any */ assert(tstate->current_frame == NULL || tstate->current_frame->stackpointer != NULL); @@ -1099,22 +1100,22 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int next_instr = frame->instr_ptr; monitor_throw(tstate, frame, next_instr); stack_pointer = _PyFrame_GetStackPointer(frame); -#if Py_TAIL_CALL_INTERP +#if _Py_TAIL_CALL_INTERP # if Py_STATS - return _TAIL_CALL_error(frame, stack_pointer, tstate, next_instr, 0, lastopcode); + return _TAIL_CALL_error(frame, stack_pointer, tstate, next_instr, instruction_funcptr_table, 0, lastopcode); # else - return _TAIL_CALL_error(frame, stack_pointer, tstate, next_instr, 0); + return _TAIL_CALL_error(frame, stack_pointer, tstate, next_instr, instruction_funcptr_table, 0); # endif #else goto error; #endif } -#if Py_TAIL_CALL_INTERP +#if _Py_TAIL_CALL_INTERP # if Py_STATS - return _TAIL_CALL_start_frame(frame, NULL, tstate, NULL, 0, lastopcode); + return _TAIL_CALL_start_frame(frame, NULL, tstate, NULL, instruction_funcptr_table, 0, lastopcode); # else - return _TAIL_CALL_start_frame(frame, NULL, tstate, NULL, 0); + return _TAIL_CALL_start_frame(frame, NULL, tstate, NULL, instruction_funcptr_table, 0); # endif #else goto start_frame; diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h index 64ca7716fdbdee..4ed03b7fb01bdf 100644 --- a/Python/ceval_macros.h +++ b/Python/ceval_macros.h @@ -71,14 +71,14 @@ #endif #ifdef Py_STATS -# define TAIL_CALL_PARAMS _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate, _Py_CODEUNIT *next_instr, int oparg, int lastopcode -# define TAIL_CALL_ARGS frame, stack_pointer, tstate, next_instr, oparg, lastopcode +# define TAIL_CALL_PARAMS _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate, _Py_CODEUNIT *next_instr, const void *instruction_funcptr_table, int oparg, int lastopcode +# define TAIL_CALL_ARGS frame, stack_pointer, tstate, next_instr, instruction_funcptr_table, oparg, lastopcode #else -# define TAIL_CALL_PARAMS _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate, _Py_CODEUNIT *next_instr, int oparg -# define TAIL_CALL_ARGS frame, stack_pointer, tstate, next_instr, oparg +# define TAIL_CALL_PARAMS _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate, _Py_CODEUNIT *next_instr, const void *instruction_funcptr_table, int oparg +# define TAIL_CALL_ARGS frame, stack_pointer, tstate, next_instr, instruction_funcptr_table, oparg #endif -#if Py_TAIL_CALL_INTERP +#if _Py_TAIL_CALL_INTERP // Note: [[clang::musttail]] works for GCC 15, but not __attribute__((musttail)) at the moment. # define Py_MUSTTAIL [[clang::musttail]] # define Py_PRESERVE_NONE_CC __attribute__((preserve_none)) @@ -87,7 +87,7 @@ # define TARGET(op) Py_PRESERVE_NONE_CC PyObject *_TAIL_CALL_##op(TAIL_CALL_PARAMS) # define DISPATCH_GOTO() \ do { \ - Py_MUSTTAIL return (INSTRUCTION_TABLE[opcode])(TAIL_CALL_ARGS); \ + Py_MUSTTAIL return (((py_tail_call_funcptr *)instruction_funcptr_table)[opcode])(TAIL_CALL_ARGS); \ } while (0) # define JUMP_TO_LABEL(name) \ do { \ @@ -96,12 +96,12 @@ # ifdef Py_STATS # define JUMP_TO_PREDICTED(name) \ do { \ - Py_MUSTTAIL return (_TAIL_CALL_##name)(frame, stack_pointer, tstate, this_instr, oparg, lastopcode); \ + Py_MUSTTAIL return (_TAIL_CALL_##name)(frame, stack_pointer, tstate, this_instr, instruction_funcptr_table, oparg, lastopcode); \ } while (0) # else # define JUMP_TO_PREDICTED(name) \ do { \ - Py_MUSTTAIL return (_TAIL_CALL_##name)(frame, stack_pointer, tstate, this_instr, oparg); \ + Py_MUSTTAIL return (_TAIL_CALL_##name)(frame, stack_pointer, tstate, this_instr, instruction_funcptr_table, oparg); \ } while (0) # endif # define LABEL(name) TARGET(name) diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index c1f6f5c85cdd88..e33d15f2e51e16 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -8,18 +8,18 @@ #endif #define TIER_ONE 1 -#if !Py_TAIL_CALL_INTERP +#if !_Py_TAIL_CALL_INTERP #if !USE_COMPUTED_GOTOS dispatch_opcode: switch (opcode) #endif { -#endif /* Py_TAIL_CALL_INTERP */ +#endif /* _Py_TAIL_CALL_INTERP */ /* BEGIN INSTRUCTIONS */ TARGET(BINARY_OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP; (void)(opcode); #endif @@ -82,7 +82,7 @@ } TARGET(BINARY_OP_ADD_FLOAT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_ADD_FLOAT; (void)(opcode); #endif @@ -140,7 +140,7 @@ } TARGET(BINARY_OP_ADD_INT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_ADD_INT; (void)(opcode); #endif @@ -200,7 +200,7 @@ } TARGET(BINARY_OP_ADD_UNICODE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_ADD_UNICODE; (void)(opcode); #endif @@ -260,7 +260,7 @@ } TARGET(BINARY_OP_EXTEND) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_EXTEND; (void)(opcode); #endif @@ -324,7 +324,7 @@ } TARGET(BINARY_OP_INPLACE_ADD_UNICODE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_INPLACE_ADD_UNICODE; (void)(opcode); #endif @@ -407,7 +407,7 @@ } TARGET(BINARY_OP_MULTIPLY_FLOAT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_MULTIPLY_FLOAT; (void)(opcode); #endif @@ -465,7 +465,7 @@ } TARGET(BINARY_OP_MULTIPLY_INT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_MULTIPLY_INT; (void)(opcode); #endif @@ -525,7 +525,7 @@ } TARGET(BINARY_OP_SUBSCR_DICT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_SUBSCR_DICT; (void)(opcode); #endif @@ -591,7 +591,7 @@ } TARGET(BINARY_OP_SUBSCR_GETITEM) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_SUBSCR_GETITEM; (void)(opcode); #endif @@ -675,7 +675,7 @@ } TARGET(BINARY_OP_SUBSCR_LIST_INT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_SUBSCR_LIST_INT; (void)(opcode); #endif @@ -765,7 +765,7 @@ } TARGET(BINARY_OP_SUBSCR_LIST_SLICE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_SUBSCR_LIST_SLICE; (void)(opcode); #endif @@ -837,7 +837,7 @@ } TARGET(BINARY_OP_SUBSCR_STR_INT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_SUBSCR_STR_INT; (void)(opcode); #endif @@ -915,7 +915,7 @@ } TARGET(BINARY_OP_SUBSCR_TUPLE_INT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_SUBSCR_TUPLE_INT; (void)(opcode); #endif @@ -988,7 +988,7 @@ } TARGET(BINARY_OP_SUBTRACT_FLOAT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_SUBTRACT_FLOAT; (void)(opcode); #endif @@ -1046,7 +1046,7 @@ } TARGET(BINARY_OP_SUBTRACT_INT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_OP_SUBTRACT_INT; (void)(opcode); #endif @@ -1106,7 +1106,7 @@ } TARGET(BINARY_SLICE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BINARY_SLICE; (void)(opcode); #endif @@ -1162,7 +1162,7 @@ } TARGET(BUILD_INTERPOLATION) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BUILD_INTERPOLATION; (void)(opcode); #endif @@ -1220,7 +1220,7 @@ } TARGET(BUILD_LIST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BUILD_LIST; (void)(opcode); #endif @@ -1244,7 +1244,7 @@ } TARGET(BUILD_MAP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BUILD_MAP; (void)(opcode); #endif @@ -1296,7 +1296,7 @@ } TARGET(BUILD_SET) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BUILD_SET; (void)(opcode); #endif @@ -1353,7 +1353,7 @@ } TARGET(BUILD_SLICE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BUILD_SLICE; (void)(opcode); #endif @@ -1388,7 +1388,7 @@ } TARGET(BUILD_STRING) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BUILD_STRING; (void)(opcode); #endif @@ -1435,7 +1435,7 @@ } TARGET(BUILD_TEMPLATE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BUILD_TEMPLATE; (void)(opcode); #endif @@ -1473,7 +1473,7 @@ } TARGET(BUILD_TUPLE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = BUILD_TUPLE; (void)(opcode); #endif @@ -1495,7 +1495,7 @@ } TARGET(CACHE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CACHE; (void)(opcode); #endif @@ -1508,7 +1508,7 @@ } TARGET(CALL) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL; (void)(opcode); #endif @@ -1686,7 +1686,7 @@ } TARGET(CALL_ALLOC_AND_ENTER_INIT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_ALLOC_AND_ENTER_INIT; (void)(opcode); #endif @@ -1807,7 +1807,7 @@ } TARGET(CALL_BOUND_METHOD_EXACT_ARGS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_BOUND_METHOD_EXACT_ARGS; (void)(opcode); #endif @@ -1950,7 +1950,7 @@ } TARGET(CALL_BOUND_METHOD_GENERAL) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_BOUND_METHOD_GENERAL; (void)(opcode); #endif @@ -2078,7 +2078,7 @@ } TARGET(CALL_BUILTIN_CLASS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_BUILTIN_CLASS; (void)(opcode); #endif @@ -2183,7 +2183,7 @@ } TARGET(CALL_BUILTIN_FAST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_BUILTIN_FAST; (void)(opcode); #endif @@ -2292,7 +2292,7 @@ } TARGET(CALL_BUILTIN_FAST_WITH_KEYWORDS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_BUILTIN_FAST_WITH_KEYWORDS; (void)(opcode); #endif @@ -2401,7 +2401,7 @@ } TARGET(CALL_BUILTIN_O) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_BUILTIN_O; (void)(opcode); #endif @@ -2485,7 +2485,7 @@ } TARGET(CALL_FUNCTION_EX) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_FUNCTION_EX; (void)(opcode); #endif @@ -2652,7 +2652,7 @@ } TARGET(CALL_INTRINSIC_1) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_INTRINSIC_1; (void)(opcode); #endif @@ -2682,7 +2682,7 @@ } TARGET(CALL_INTRINSIC_2) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_INTRINSIC_2; (void)(opcode); #endif @@ -2721,7 +2721,7 @@ } TARGET(CALL_ISINSTANCE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_ISINSTANCE; (void)(opcode); #endif @@ -2797,7 +2797,7 @@ } TARGET(CALL_KW) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_KW; (void)(opcode); #endif @@ -2979,7 +2979,7 @@ } TARGET(CALL_KW_BOUND_METHOD) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_KW_BOUND_METHOD; (void)(opcode); #endif @@ -3109,7 +3109,7 @@ } TARGET(CALL_KW_NON_PY) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_KW_NON_PY; (void)(opcode); #endif @@ -3236,7 +3236,7 @@ } TARGET(CALL_KW_PY) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_KW_PY; (void)(opcode); #endif @@ -3346,7 +3346,7 @@ } TARGET(CALL_LEN) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_LEN; (void)(opcode); #endif @@ -3418,7 +3418,7 @@ } TARGET(CALL_LIST_APPEND) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_LIST_APPEND; (void)(opcode); #endif @@ -3506,7 +3506,7 @@ } TARGET(CALL_METHOD_DESCRIPTOR_FAST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_METHOD_DESCRIPTOR_FAST; (void)(opcode); #endif @@ -3627,7 +3627,7 @@ } TARGET(CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS; (void)(opcode); #endif @@ -3750,7 +3750,7 @@ } TARGET(CALL_METHOD_DESCRIPTOR_NOARGS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_METHOD_DESCRIPTOR_NOARGS; (void)(opcode); #endif @@ -3843,7 +3843,7 @@ } TARGET(CALL_METHOD_DESCRIPTOR_O) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_METHOD_DESCRIPTOR_O; (void)(opcode); #endif @@ -3949,7 +3949,7 @@ } TARGET(CALL_NON_PY_GENERAL) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_NON_PY_GENERAL; (void)(opcode); #endif @@ -4064,7 +4064,7 @@ } TARGET(CALL_PY_EXACT_ARGS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_PY_EXACT_ARGS; (void)(opcode); #endif @@ -4177,7 +4177,7 @@ } TARGET(CALL_PY_GENERAL) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_PY_GENERAL; (void)(opcode); #endif @@ -4277,7 +4277,7 @@ } TARGET(CALL_STR_1) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_STR_1; (void)(opcode); #endif @@ -4349,7 +4349,7 @@ } TARGET(CALL_TUPLE_1) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_TUPLE_1; (void)(opcode); #endif @@ -4421,7 +4421,7 @@ } TARGET(CALL_TYPE_1) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CALL_TYPE_1; (void)(opcode); #endif @@ -4476,7 +4476,7 @@ } TARGET(CHECK_EG_MATCH) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CHECK_EG_MATCH; (void)(opcode); #endif @@ -4547,7 +4547,7 @@ } TARGET(CHECK_EXC_MATCH) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CHECK_EXC_MATCH; (void)(opcode); #endif @@ -4584,7 +4584,7 @@ } TARGET(CLEANUP_THROW) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CLEANUP_THROW; (void)(opcode); #endif @@ -4602,7 +4602,7 @@ last_sent_val = stack_pointer[-2]; sub_iter = stack_pointer[-3]; PyObject *exc_value = PyStackRef_AsPyObjectBorrow(exc_value_st); - #if !Py_TAIL_CALL_INTERP + #if !_Py_TAIL_CALL_INTERP assert(throwflag); #endif assert(exc_value && PyExceptionInstance_Check(exc_value)); @@ -4643,7 +4643,7 @@ } TARGET(COMPARE_OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = COMPARE_OP; (void)(opcode); #endif @@ -4716,7 +4716,7 @@ } TARGET(COMPARE_OP_FLOAT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = COMPARE_OP_FLOAT; (void)(opcode); #endif @@ -4771,7 +4771,7 @@ } TARGET(COMPARE_OP_INT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = COMPARE_OP_INT; (void)(opcode); #endif @@ -4830,7 +4830,7 @@ } TARGET(COMPARE_OP_STR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = COMPARE_OP_STR; (void)(opcode); #endif @@ -4889,7 +4889,7 @@ } TARGET(CONTAINS_OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CONTAINS_OP; (void)(opcode); #endif @@ -4949,7 +4949,7 @@ } TARGET(CONTAINS_OP_DICT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CONTAINS_OP_DICT; (void)(opcode); #endif @@ -5007,7 +5007,7 @@ } TARGET(CONTAINS_OP_SET) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CONTAINS_OP_SET; (void)(opcode); #endif @@ -5065,7 +5065,7 @@ } TARGET(CONVERT_VALUE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = CONVERT_VALUE; (void)(opcode); #endif @@ -5097,7 +5097,7 @@ } TARGET(COPY) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = COPY; (void)(opcode); #endif @@ -5115,7 +5115,7 @@ } TARGET(COPY_FREE_VARS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = COPY_FREE_VARS; (void)(opcode); #endif @@ -5136,7 +5136,7 @@ } TARGET(DELETE_ATTR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = DELETE_ATTR; (void)(opcode); #endif @@ -5161,7 +5161,7 @@ } TARGET(DELETE_DEREF) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = DELETE_DEREF; (void)(opcode); #endif @@ -5183,7 +5183,7 @@ } TARGET(DELETE_FAST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = DELETE_FAST; (void)(opcode); #endif @@ -5209,7 +5209,7 @@ } TARGET(DELETE_GLOBAL) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = DELETE_GLOBAL; (void)(opcode); #endif @@ -5234,7 +5234,7 @@ } TARGET(DELETE_NAME) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = DELETE_NAME; (void)(opcode); #endif @@ -5266,7 +5266,7 @@ } TARGET(DELETE_SUBSCR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = DELETE_SUBSCR; (void)(opcode); #endif @@ -5298,7 +5298,7 @@ } TARGET(DICT_MERGE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = DICT_MERGE; (void)(opcode); #endif @@ -5337,7 +5337,7 @@ } TARGET(DICT_UPDATE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = DICT_UPDATE; (void)(opcode); #endif @@ -5380,7 +5380,7 @@ } TARGET(END_ASYNC_FOR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = END_ASYNC_FOR; (void)(opcode); #endif @@ -5425,7 +5425,7 @@ } TARGET(END_FOR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = END_FOR; (void)(opcode); #endif @@ -5442,7 +5442,7 @@ } TARGET(END_SEND) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = END_SEND; (void)(opcode); #endif @@ -5465,7 +5465,7 @@ } TARGET(ENTER_EXECUTOR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = ENTER_EXECUTOR; (void)(opcode); #endif @@ -5501,7 +5501,7 @@ } TARGET(EXIT_INIT_CHECK) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = EXIT_INIT_CHECK; (void)(opcode); #endif @@ -5524,7 +5524,7 @@ } TARGET(EXTENDED_ARG) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = EXTENDED_ARG; (void)(opcode); #endif @@ -5540,7 +5540,7 @@ } TARGET(FORMAT_SIMPLE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = FORMAT_SIMPLE; (void)(opcode); #endif @@ -5576,7 +5576,7 @@ } TARGET(FORMAT_WITH_SPEC) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = FORMAT_WITH_SPEC; (void)(opcode); #endif @@ -5612,7 +5612,7 @@ } TARGET(FOR_ITER) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = FOR_ITER; (void)(opcode); #endif @@ -5666,7 +5666,7 @@ } TARGET(FOR_ITER_GEN) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = FOR_ITER_GEN; (void)(opcode); #endif @@ -5737,7 +5737,7 @@ } TARGET(FOR_ITER_LIST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = FOR_ITER_LIST; (void)(opcode); #endif @@ -5821,7 +5821,7 @@ } TARGET(FOR_ITER_RANGE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = FOR_ITER_RANGE; (void)(opcode); #endif @@ -5888,7 +5888,7 @@ } TARGET(FOR_ITER_TUPLE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = FOR_ITER_TUPLE; (void)(opcode); #endif @@ -5944,7 +5944,7 @@ } TARGET(GET_AITER) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = GET_AITER; (void)(opcode); #endif @@ -6005,7 +6005,7 @@ } TARGET(GET_ANEXT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = GET_ANEXT; (void)(opcode); #endif @@ -6029,7 +6029,7 @@ } TARGET(GET_AWAITABLE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = GET_AWAITABLE; (void)(opcode); #endif @@ -6058,7 +6058,7 @@ } TARGET(GET_ITER) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = GET_ITER; (void)(opcode); #endif @@ -6104,7 +6104,7 @@ } TARGET(GET_LEN) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = GET_LEN; (void)(opcode); #endif @@ -6132,7 +6132,7 @@ } TARGET(GET_YIELD_FROM_ITER) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = GET_YIELD_FROM_ITER; (void)(opcode); #endif @@ -6177,7 +6177,7 @@ } TARGET(IMPORT_FROM) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = IMPORT_FROM; (void)(opcode); #endif @@ -6202,7 +6202,7 @@ } TARGET(IMPORT_NAME) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = IMPORT_NAME; (void)(opcode); #endif @@ -6241,7 +6241,7 @@ } TARGET(INSTRUMENTED_CALL) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_CALL; (void)(opcode); #endif @@ -6429,7 +6429,7 @@ } TARGET(INSTRUMENTED_CALL_FUNCTION_EX) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_CALL_FUNCTION_EX; (void)(opcode); #endif @@ -6596,7 +6596,7 @@ } TARGET(INSTRUMENTED_CALL_KW) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_CALL_KW; (void)(opcode); #endif @@ -6782,7 +6782,7 @@ } TARGET(INSTRUMENTED_END_ASYNC_FOR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_END_ASYNC_FOR; (void)(opcode); #endif @@ -6835,7 +6835,7 @@ } TARGET(INSTRUMENTED_END_FOR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_END_FOR; (void)(opcode); #endif @@ -6864,7 +6864,7 @@ } TARGET(INSTRUMENTED_END_SEND) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_END_SEND; (void)(opcode); #endif @@ -6898,7 +6898,7 @@ } TARGET(INSTRUMENTED_FOR_ITER) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_FOR_ITER; (void)(opcode); #endif @@ -6934,7 +6934,7 @@ } TARGET(INSTRUMENTED_INSTRUCTION) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_INSTRUCTION; (void)(opcode); #endif @@ -6961,7 +6961,7 @@ } TARGET(INSTRUMENTED_JUMP_BACKWARD) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_JUMP_BACKWARD; (void)(opcode); #endif @@ -6988,7 +6988,7 @@ } TARGET(INSTRUMENTED_JUMP_FORWARD) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_JUMP_FORWARD; (void)(opcode); #endif @@ -7002,7 +7002,7 @@ } TARGET(INSTRUMENTED_LINE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_LINE; (void)(opcode); #endif @@ -7042,7 +7042,7 @@ } TARGET(INSTRUMENTED_LOAD_SUPER_ATTR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_LOAD_SUPER_ATTR; (void)(opcode); #endif @@ -7162,7 +7162,7 @@ } TARGET(INSTRUMENTED_NOT_TAKEN) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_NOT_TAKEN; (void)(opcode); #endif @@ -7178,7 +7178,7 @@ } TARGET(INSTRUMENTED_POP_ITER) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_POP_ITER; (void)(opcode); #endif @@ -7203,7 +7203,7 @@ } TARGET(INSTRUMENTED_POP_JUMP_IF_FALSE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_POP_JUMP_IF_FALSE; (void)(opcode); #endif @@ -7227,7 +7227,7 @@ } TARGET(INSTRUMENTED_POP_JUMP_IF_NONE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_POP_JUMP_IF_NONE; (void)(opcode); #endif @@ -7258,7 +7258,7 @@ } TARGET(INSTRUMENTED_POP_JUMP_IF_NOT_NONE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_POP_JUMP_IF_NOT_NONE; (void)(opcode); #endif @@ -7287,7 +7287,7 @@ } TARGET(INSTRUMENTED_POP_JUMP_IF_TRUE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_POP_JUMP_IF_TRUE; (void)(opcode); #endif @@ -7311,7 +7311,7 @@ } TARGET(INSTRUMENTED_RESUME) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_RESUME; (void)(opcode); #endif @@ -7391,7 +7391,7 @@ } TARGET(INSTRUMENTED_RETURN_VALUE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_RETURN_VALUE; (void)(opcode); #endif @@ -7440,7 +7440,7 @@ } TARGET(INSTRUMENTED_YIELD_VALUE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INSTRUMENTED_YIELD_VALUE; (void)(opcode); #endif @@ -7508,7 +7508,7 @@ } TARGET(INTERPRETER_EXIT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = INTERPRETER_EXIT; (void)(opcode); #endif @@ -7522,7 +7522,7 @@ tstate->current_frame = frame->previous; assert(!_PyErr_Occurred(tstate)); PyObject *result = PyStackRef_AsPyObjectSteal(retval); - #if !Py_TAIL_CALL_INTERP + #if !_Py_TAIL_CALL_INTERP assert(frame == &entry.frame); #endif #ifdef _Py_TIER2 @@ -7543,7 +7543,7 @@ } TARGET(IS_OP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = IS_OP; (void)(opcode); #endif @@ -7576,7 +7576,7 @@ } TARGET(JUMP_BACKWARD) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = JUMP_BACKWARD; (void)(opcode); #endif @@ -7615,7 +7615,7 @@ } TARGET(JUMP_BACKWARD_JIT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = JUMP_BACKWARD_JIT; (void)(opcode); #endif @@ -7679,7 +7679,7 @@ } TARGET(JUMP_BACKWARD_NO_INTERRUPT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = JUMP_BACKWARD_NO_INTERRUPT; (void)(opcode); #endif @@ -7692,7 +7692,7 @@ } TARGET(JUMP_BACKWARD_NO_JIT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = JUMP_BACKWARD_NO_JIT; (void)(opcode); #endif @@ -7719,7 +7719,7 @@ } TARGET(JUMP_FORWARD) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = JUMP_FORWARD; (void)(opcode); #endif @@ -7731,7 +7731,7 @@ } TARGET(LIST_APPEND) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LIST_APPEND; (void)(opcode); #endif @@ -7753,7 +7753,7 @@ } TARGET(LIST_EXTEND) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LIST_EXTEND; (void)(opcode); #endif @@ -7800,7 +7800,7 @@ } TARGET(LOAD_ATTR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR; (void)(opcode); #endif @@ -7881,7 +7881,7 @@ } TARGET(LOAD_ATTR_CLASS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR_CLASS; (void)(opcode); #endif @@ -7939,7 +7939,7 @@ } TARGET(LOAD_ATTR_CLASS_WITH_METACLASS_CHECK) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR_CLASS_WITH_METACLASS_CHECK; (void)(opcode); #endif @@ -8007,7 +8007,7 @@ } TARGET(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN; (void)(opcode); #endif @@ -8065,7 +8065,7 @@ } TARGET(LOAD_ATTR_INSTANCE_VALUE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR_INSTANCE_VALUE; (void)(opcode); #endif @@ -8145,7 +8145,7 @@ } TARGET(LOAD_ATTR_METHOD_LAZY_DICT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR_METHOD_LAZY_DICT; (void)(opcode); #endif @@ -8201,7 +8201,7 @@ } TARGET(LOAD_ATTR_METHOD_NO_DICT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR_METHOD_NO_DICT; (void)(opcode); #endif @@ -8247,7 +8247,7 @@ } TARGET(LOAD_ATTR_METHOD_WITH_VALUES) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR_METHOD_WITH_VALUES; (void)(opcode); #endif @@ -8314,7 +8314,7 @@ } TARGET(LOAD_ATTR_MODULE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR_MODULE; (void)(opcode); #endif @@ -8388,7 +8388,7 @@ } TARGET(LOAD_ATTR_NONDESCRIPTOR_NO_DICT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR_NONDESCRIPTOR_NO_DICT; (void)(opcode); #endif @@ -8435,7 +8435,7 @@ } TARGET(LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES; (void)(opcode); #endif @@ -8503,7 +8503,7 @@ } TARGET(LOAD_ATTR_PROPERTY) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR_PROPERTY; (void)(opcode); #endif @@ -8597,7 +8597,7 @@ } TARGET(LOAD_ATTR_SLOT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR_SLOT; (void)(opcode); #endif @@ -8666,7 +8666,7 @@ } TARGET(LOAD_ATTR_WITH_HINT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_ATTR_WITH_HINT; (void)(opcode); #endif @@ -8776,7 +8776,7 @@ } TARGET(LOAD_BUILD_CLASS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_BUILD_CLASS; (void)(opcode); #endif @@ -8806,7 +8806,7 @@ } TARGET(LOAD_COMMON_CONSTANT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_COMMON_CONSTANT; (void)(opcode); #endif @@ -8823,7 +8823,7 @@ } TARGET(LOAD_CONST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_CONST; (void)(opcode); #endif @@ -8840,7 +8840,7 @@ } TARGET(LOAD_DEREF) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_DEREF; (void)(opcode); #endif @@ -8868,7 +8868,7 @@ } TARGET(LOAD_FAST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_FAST; (void)(opcode); #endif @@ -8885,7 +8885,7 @@ } TARGET(LOAD_FAST_AND_CLEAR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_FAST_AND_CLEAR; (void)(opcode); #endif @@ -8902,7 +8902,7 @@ } TARGET(LOAD_FAST_BORROW) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_FAST_BORROW; (void)(opcode); #endif @@ -8919,7 +8919,7 @@ } TARGET(LOAD_FAST_BORROW_LOAD_FAST_BORROW) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_FAST_BORROW_LOAD_FAST_BORROW; (void)(opcode); #endif @@ -8940,7 +8940,7 @@ } TARGET(LOAD_FAST_CHECK) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_FAST_CHECK; (void)(opcode); #endif @@ -8966,7 +8966,7 @@ } TARGET(LOAD_FAST_LOAD_FAST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_FAST_LOAD_FAST; (void)(opcode); #endif @@ -8987,7 +8987,7 @@ } TARGET(LOAD_FROM_DICT_OR_DEREF) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_FROM_DICT_OR_DEREF; (void)(opcode); #endif @@ -9032,7 +9032,7 @@ } TARGET(LOAD_FROM_DICT_OR_GLOBALS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_FROM_DICT_OR_GLOBALS; (void)(opcode); #endif @@ -9107,7 +9107,7 @@ } TARGET(LOAD_GLOBAL) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_GLOBAL; (void)(opcode); #endif @@ -9163,7 +9163,7 @@ } TARGET(LOAD_GLOBAL_BUILTIN) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_GLOBAL_BUILTIN; (void)(opcode); #endif @@ -9243,7 +9243,7 @@ } TARGET(LOAD_GLOBAL_MODULE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_GLOBAL_MODULE; (void)(opcode); #endif @@ -9310,7 +9310,7 @@ } TARGET(LOAD_LOCALS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_LOCALS; (void)(opcode); #endif @@ -9334,7 +9334,7 @@ } TARGET(LOAD_NAME) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_NAME; (void)(opcode); #endif @@ -9357,7 +9357,7 @@ } TARGET(LOAD_SMALL_INT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_SMALL_INT; (void)(opcode); #endif @@ -9375,7 +9375,7 @@ } TARGET(LOAD_SPECIAL) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_SPECIAL; (void)(opcode); #endif @@ -9421,7 +9421,7 @@ } TARGET(LOAD_SUPER_ATTR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_SUPER_ATTR; (void)(opcode); #endif @@ -9558,7 +9558,7 @@ } TARGET(LOAD_SUPER_ATTR_ATTR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_SUPER_ATTR_ATTR; (void)(opcode); #endif @@ -9620,7 +9620,7 @@ } TARGET(LOAD_SUPER_ATTR_METHOD) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = LOAD_SUPER_ATTR_METHOD; (void)(opcode); #endif @@ -9698,7 +9698,7 @@ } TARGET(MAKE_CELL) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = MAKE_CELL; (void)(opcode); #endif @@ -9719,7 +9719,7 @@ } TARGET(MAKE_FUNCTION) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = MAKE_FUNCTION; (void)(opcode); #endif @@ -9752,7 +9752,7 @@ } TARGET(MAP_ADD) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = MAP_ADD; (void)(opcode); #endif @@ -9783,7 +9783,7 @@ } TARGET(MATCH_CLASS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = MATCH_CLASS; (void)(opcode); #endif @@ -9835,7 +9835,7 @@ } TARGET(MATCH_KEYS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = MATCH_KEYS; (void)(opcode); #endif @@ -9862,7 +9862,7 @@ } TARGET(MATCH_MAPPING) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = MATCH_MAPPING; (void)(opcode); #endif @@ -9881,7 +9881,7 @@ } TARGET(MATCH_SEQUENCE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = MATCH_SEQUENCE; (void)(opcode); #endif @@ -9900,7 +9900,7 @@ } TARGET(NOP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = NOP; (void)(opcode); #endif @@ -9911,7 +9911,7 @@ } TARGET(NOT_TAKEN) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = NOT_TAKEN; (void)(opcode); #endif @@ -9922,7 +9922,7 @@ } TARGET(POP_EXCEPT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = POP_EXCEPT; (void)(opcode); #endif @@ -9943,7 +9943,7 @@ } TARGET(POP_ITER) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = POP_ITER; (void)(opcode); #endif @@ -9964,7 +9964,7 @@ } TARGET(POP_JUMP_IF_FALSE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = POP_JUMP_IF_FALSE; (void)(opcode); #endif @@ -9986,7 +9986,7 @@ } TARGET(POP_JUMP_IF_NONE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = POP_JUMP_IF_NONE; (void)(opcode); #endif @@ -10029,7 +10029,7 @@ } TARGET(POP_JUMP_IF_NOT_NONE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = POP_JUMP_IF_NOT_NONE; (void)(opcode); #endif @@ -10072,7 +10072,7 @@ } TARGET(POP_JUMP_IF_TRUE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = POP_JUMP_IF_TRUE; (void)(opcode); #endif @@ -10094,7 +10094,7 @@ } TARGET(POP_TOP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = POP_TOP; (void)(opcode); #endif @@ -10112,7 +10112,7 @@ } TARGET(PUSH_EXC_INFO) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = PUSH_EXC_INFO; (void)(opcode); #endif @@ -10141,7 +10141,7 @@ } TARGET(PUSH_NULL) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = PUSH_NULL; (void)(opcode); #endif @@ -10157,7 +10157,7 @@ } TARGET(RAISE_VARARGS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = RAISE_VARARGS; (void)(opcode); #endif @@ -10186,7 +10186,7 @@ } TARGET(RERAISE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = RERAISE; (void)(opcode); #endif @@ -10214,7 +10214,7 @@ } TARGET(RESERVED) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = RESERVED; (void)(opcode); #endif @@ -10227,7 +10227,7 @@ } TARGET(RESUME) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = RESUME; (void)(opcode); #endif @@ -10303,7 +10303,7 @@ } TARGET(RESUME_CHECK) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = RESUME_CHECK; (void)(opcode); #endif @@ -10341,7 +10341,7 @@ } TARGET(RETURN_GENERATOR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = RETURN_GENERATOR; (void)(opcode); #endif @@ -10380,7 +10380,7 @@ } TARGET(RETURN_VALUE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = RETURN_VALUE; (void)(opcode); #endif @@ -10411,7 +10411,7 @@ } TARGET(SEND) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = SEND; (void)(opcode); #endif @@ -10516,7 +10516,7 @@ } TARGET(SEND_GEN) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = SEND_GEN; (void)(opcode); #endif @@ -10585,7 +10585,7 @@ } TARGET(SETUP_ANNOTATIONS) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = SETUP_ANNOTATIONS; (void)(opcode); #endif @@ -10631,7 +10631,7 @@ } TARGET(SET_ADD) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = SET_ADD; (void)(opcode); #endif @@ -10655,7 +10655,7 @@ } TARGET(SET_FUNCTION_ATTRIBUTE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = SET_FUNCTION_ATTRIBUTE; (void)(opcode); #endif @@ -10683,7 +10683,7 @@ } TARGET(SET_UPDATE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = SET_UPDATE; (void)(opcode); #endif @@ -10710,7 +10710,7 @@ } TARGET(STORE_ATTR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_ATTR; (void)(opcode); #endif @@ -10767,7 +10767,7 @@ } TARGET(STORE_ATTR_INSTANCE_VALUE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_ATTR_INSTANCE_VALUE; (void)(opcode); #endif @@ -10843,7 +10843,7 @@ } TARGET(STORE_ATTR_SLOT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_ATTR_SLOT; (void)(opcode); #endif @@ -10894,7 +10894,7 @@ } TARGET(STORE_ATTR_WITH_HINT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_ATTR_WITH_HINT; (void)(opcode); #endif @@ -10982,7 +10982,7 @@ } TARGET(STORE_DEREF) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_DEREF; (void)(opcode); #endif @@ -11001,7 +11001,7 @@ } TARGET(STORE_FAST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_FAST; (void)(opcode); #endif @@ -11021,7 +11021,7 @@ } TARGET(STORE_FAST_LOAD_FAST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_FAST_LOAD_FAST; (void)(opcode); #endif @@ -11044,7 +11044,7 @@ } TARGET(STORE_FAST_STORE_FAST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_FAST_STORE_FAST; (void)(opcode); #endif @@ -11075,7 +11075,7 @@ } TARGET(STORE_GLOBAL) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_GLOBAL; (void)(opcode); #endif @@ -11100,7 +11100,7 @@ } TARGET(STORE_NAME) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_NAME; (void)(opcode); #endif @@ -11146,7 +11146,7 @@ } TARGET(STORE_SLICE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_SLICE; (void)(opcode); #endif @@ -11206,7 +11206,7 @@ } TARGET(STORE_SUBSCR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_SUBSCR; (void)(opcode); #endif @@ -11265,7 +11265,7 @@ } TARGET(STORE_SUBSCR_DICT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_SUBSCR_DICT; (void)(opcode); #endif @@ -11316,7 +11316,7 @@ } TARGET(STORE_SUBSCR_LIST_INT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = STORE_SUBSCR_LIST_INT; (void)(opcode); #endif @@ -11397,7 +11397,7 @@ } TARGET(SWAP) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = SWAP; (void)(opcode); #endif @@ -11417,7 +11417,7 @@ } TARGET(TO_BOOL) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = TO_BOOL; (void)(opcode); #endif @@ -11469,7 +11469,7 @@ } TARGET(TO_BOOL_ALWAYS_TRUE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = TO_BOOL_ALWAYS_TRUE; (void)(opcode); #endif @@ -11512,7 +11512,7 @@ } TARGET(TO_BOOL_BOOL) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = TO_BOOL_BOOL; (void)(opcode); #endif @@ -11536,7 +11536,7 @@ } TARGET(TO_BOOL_INT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = TO_BOOL_INT; (void)(opcode); #endif @@ -11576,7 +11576,7 @@ } TARGET(TO_BOOL_LIST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = TO_BOOL_LIST; (void)(opcode); #endif @@ -11619,7 +11619,7 @@ } TARGET(TO_BOOL_NONE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = TO_BOOL_NONE; (void)(opcode); #endif @@ -11646,7 +11646,7 @@ } TARGET(TO_BOOL_STR) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = TO_BOOL_STR; (void)(opcode); #endif @@ -11694,7 +11694,7 @@ } TARGET(UNARY_INVERT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = UNARY_INVERT; (void)(opcode); #endif @@ -11723,7 +11723,7 @@ } TARGET(UNARY_NEGATIVE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = UNARY_NEGATIVE; (void)(opcode); #endif @@ -11752,7 +11752,7 @@ } TARGET(UNARY_NOT) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = UNARY_NOT; (void)(opcode); #endif @@ -11770,7 +11770,7 @@ } TARGET(UNPACK_EX) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = UNPACK_EX; (void)(opcode); #endif @@ -11797,7 +11797,7 @@ } TARGET(UNPACK_SEQUENCE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = UNPACK_SEQUENCE; (void)(opcode); #endif @@ -11848,7 +11848,7 @@ } TARGET(UNPACK_SEQUENCE_LIST) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = UNPACK_SEQUENCE_LIST; (void)(opcode); #endif @@ -11907,7 +11907,7 @@ } TARGET(UNPACK_SEQUENCE_TUPLE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = UNPACK_SEQUENCE_TUPLE; (void)(opcode); #endif @@ -11957,7 +11957,7 @@ } TARGET(UNPACK_SEQUENCE_TWO_TUPLE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = UNPACK_SEQUENCE_TWO_TUPLE; (void)(opcode); #endif @@ -12008,7 +12008,7 @@ } TARGET(WITH_EXCEPT_START) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = WITH_EXCEPT_START; (void)(opcode); #endif @@ -12053,7 +12053,7 @@ } TARGET(YIELD_VALUE) { - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode = YIELD_VALUE; (void)(opcode); #endif @@ -12099,7 +12099,7 @@ } /* END INSTRUCTIONS */ -#if !Py_TAIL_CALL_INTERP +#if !_Py_TAIL_CALL_INTERP #if USE_COMPUTED_GOTOS _unknown_opcode: #else @@ -12121,7 +12121,7 @@ JUMP_TO_LABEL(error); /* This should never be reached. Every opcode should end with DISPATCH() or goto error. */ Py_UNREACHABLE(); -#endif /* Py_TAIL_CALL_INTERP */ +#endif /* _Py_TAIL_CALL_INTERP */ /* BEGIN LABELS */ LABEL(pop_2_error) @@ -12207,7 +12207,7 @@ JUMP_TO_LABEL(error); } #endif stack_pointer = _PyFrame_GetStackPointer(frame); - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode; #endif DISPATCH(); @@ -12224,7 +12224,7 @@ JUMP_TO_LABEL(error); frame->return_offset = 0; if (frame->owner == FRAME_OWNED_BY_INTERPRETER) { tstate->current_frame = frame->previous; - #if !Py_TAIL_CALL_INTERP + #if !_Py_TAIL_CALL_INTERP assert(frame == &entry.frame); #endif #ifdef _Py_TIER2 @@ -12258,7 +12258,7 @@ JUMP_TO_LABEL(error); assert(!_PyErr_Occurred(tstate)); #endif stack_pointer = _PyFrame_GetStackPointer(frame); - #if Py_TAIL_CALL_INTERP + #if _Py_TAIL_CALL_INTERP int opcode; #endif DISPATCH(); diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h index 1d6dcddab4b12d..6dd443e1655ed0 100644 --- a/Python/opcode_targets.h +++ b/Python/opcode_targets.h @@ -1,5 +1,5 @@ -#if !Py_TAIL_CALL_INTERP -static void *opcode_targets[256] = { +#if !_Py_TAIL_CALL_INTERP +static void *opcode_targets_table[256] = { &&TARGET_CACHE, &&TARGET_BINARY_SLICE, &&TARGET_BUILD_TEMPLATE, @@ -257,8 +257,8 @@ static void *opcode_targets[256] = { &&TARGET_INSTRUMENTED_LINE, &&TARGET_ENTER_EXECUTOR, }; -#else /* Py_TAIL_CALL_INTERP */ -static py_tail_call_funcptr INSTRUCTION_TABLE[256]; +#else /* _Py_TAIL_CALL_INTERP */ +static py_tail_call_funcptr instruction_funcptr_table[256]; Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_pop_2_error(TAIL_CALL_PARAMS); Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_pop_1_error(TAIL_CALL_PARAMS); @@ -503,7 +503,7 @@ Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_UNKNOWN_OPCODE(TAIL_CALL_PARAMS) JUMP_TO_LABEL(error); } -static py_tail_call_funcptr INSTRUCTION_TABLE[256] = { +static py_tail_call_funcptr instruction_funcptr_table[256] = { [BINARY_OP] = _TAIL_CALL_BINARY_OP, [BINARY_OP_ADD_FLOAT] = _TAIL_CALL_BINARY_OP_ADD_FLOAT, [BINARY_OP_ADD_INT] = _TAIL_CALL_BINARY_OP_ADD_INT, @@ -761,4 +761,4 @@ static py_tail_call_funcptr INSTRUCTION_TABLE[256] = { [232] = _TAIL_CALL_UNKNOWN_OPCODE, [233] = _TAIL_CALL_UNKNOWN_OPCODE, }; -#endif /* Py_TAIL_CALL_INTERP */ +#endif /* _Py_TAIL_CALL_INTERP */ diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 8920784a7b7eac..b930e2e2e43e33 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2013,6 +2013,133 @@ resolve_final_tstate(_PyRuntimeState *runtime) return main_tstate; } +#ifdef Py_GIL_DISABLED +#define ASSERT_WORLD_STOPPED(interp) assert(interp->runtime->stoptheworld.world_stopped) +#else +#define ASSERT_WORLD_STOPPED(interp) +#endif + +static int +interp_has_threads(PyInterpreterState *interp) +{ + /* This needs to check for non-daemon threads only, otherwise we get stuck + * in an infinite loop. */ + assert(interp != NULL); + ASSERT_WORLD_STOPPED(interp); + assert(interp->threads.head != NULL); + if (interp->threads.head->next == NULL) { + // No other threads active, easy way out. + return 0; + } + + // We don't have to worry about locking this because the + // world is stopped. + _Py_FOR_EACH_TSTATE_UNLOCKED(interp, tstate) { + if (tstate->_whence == _PyThreadState_WHENCE_THREADING) { + return 1; + } + } + + return 0; +} + +static int +interp_has_pending_calls(PyInterpreterState *interp) +{ + assert(interp != NULL); + ASSERT_WORLD_STOPPED(interp); + return interp->ceval.pending.npending != 0; +} + +static int +interp_has_atexit_callbacks(PyInterpreterState *interp) +{ + assert(interp != NULL); + assert(interp->atexit.callbacks != NULL); + ASSERT_WORLD_STOPPED(interp); + assert(PyList_CheckExact(interp->atexit.callbacks)); + return PyList_GET_SIZE(interp->atexit.callbacks) != 0; +} + +static int +runtime_has_subinterpreters(_PyRuntimeState *runtime) +{ + assert(runtime != NULL); + HEAD_LOCK(runtime); + PyInterpreterState *interp = runtime->interpreters.head; + HEAD_UNLOCK(runtime); + return interp->next != NULL; +} + +static void +make_pre_finalization_calls(PyThreadState *tstate, int subinterpreters) +{ + assert(tstate != NULL); + PyInterpreterState *interp = tstate->interp; + /* Each of these functions can start one another, e.g. a pending call + * could start a thread or vice versa. To ensure that we properly clean + * call everything, we run these in a loop until none of them run anything. */ + for (;;) { + assert(!interp->runtime->stoptheworld.world_stopped); + + // Wrap up existing "threading"-module-created, non-daemon threads. + wait_for_thread_shutdown(tstate); + + // Make any remaining pending calls. + _Py_FinishPendingCalls(tstate); + + /* The interpreter is still entirely intact at this point, and the + * exit funcs may be relying on that. In particular, if some thread + * or exit func is still waiting to do an import, the import machinery + * expects Py_IsInitialized() to return true. So don't say the + * runtime is uninitialized until after the exit funcs have run. + * Note that Threading.py uses an exit func to do a join on all the + * threads created thru it, so this also protects pending imports in + * the threads created via Threading. + */ + + _PyAtExit_Call(tstate->interp); + + if (subinterpreters) { + /* Clean up any lingering subinterpreters. + + Two preconditions need to be met here: + + - This has to happen before _PyRuntimeState_SetFinalizing is + called, or else threads might get prematurely blocked. + - The world must not be stopped, as finalizers can run. + */ + finalize_subinterpreters(); + } + + + /* Stop the world to prevent other threads from creating threads or + * atexit callbacks. On the default build, this is simply locked by + * the GIL. For pending calls, we acquire the dedicated mutex, because + * Py_AddPendingCall() can be called without an attached thread state. + */ + + PyMutex_Lock(&interp->ceval.pending.mutex); + // XXX Why does _PyThreadState_DeleteList() rely on all interpreters + // being stopped? + _PyEval_StopTheWorldAll(interp->runtime); + int has_subinterpreters = subinterpreters + ? runtime_has_subinterpreters(interp->runtime) + : 0; + int should_continue = (interp_has_threads(interp) + || interp_has_atexit_callbacks(interp) + || interp_has_pending_calls(interp) + || has_subinterpreters); + if (!should_continue) { + break; + } + _PyEval_StartTheWorldAll(interp->runtime); + PyMutex_Unlock(&interp->ceval.pending.mutex); + } + assert(PyMutex_IsLocked(&interp->ceval.pending.mutex)); + ASSERT_WORLD_STOPPED(interp); +} + static int _Py_Finalize(_PyRuntimeState *runtime) { @@ -2029,33 +2156,8 @@ _Py_Finalize(_PyRuntimeState *runtime) // Block some operations. tstate->interp->finalizing = 1; - // Wrap up existing "threading"-module-created, non-daemon threads. - wait_for_thread_shutdown(tstate); - - // Make any remaining pending calls. - _Py_FinishPendingCalls(tstate); - - /* The interpreter is still entirely intact at this point, and the - * exit funcs may be relying on that. In particular, if some thread - * or exit func is still waiting to do an import, the import machinery - * expects Py_IsInitialized() to return true. So don't say the - * runtime is uninitialized until after the exit funcs have run. - * Note that Threading.py uses an exit func to do a join on all the - * threads created thru it, so this also protects pending imports in - * the threads created via Threading. - */ - - _PyAtExit_Call(tstate->interp); - - /* Clean up any lingering subinterpreters. - - Two preconditions need to be met here: - - - This has to happen before _PyRuntimeState_SetFinalizing is - called, or else threads might get prematurely blocked. - - The world must not be stopped, as finalizers can run. - */ - finalize_subinterpreters(); + // This call stops the world and takes the pending calls lock. + make_pre_finalization_calls(tstate, /*subinterpreters=*/1); assert(_PyThreadState_GET() == tstate); @@ -2073,7 +2175,7 @@ _Py_Finalize(_PyRuntimeState *runtime) #endif /* Ensure that remaining threads are detached */ - _PyEval_StopTheWorldAll(runtime); + ASSERT_WORLD_STOPPED(tstate->interp); /* Remaining daemon threads will be trapped in PyThread_hang_thread when they attempt to take the GIL (ex: PyEval_RestoreThread()). */ @@ -2094,6 +2196,7 @@ _Py_Finalize(_PyRuntimeState *runtime) _PyThreadState_SetShuttingDown(p); } _PyEval_StartTheWorldAll(runtime); + PyMutex_Unlock(&tstate->interp->ceval.pending.mutex); /* Clear frames of other threads to call objects destructors. Destructors will be called in the current Python thread. Since @@ -2449,15 +2552,10 @@ Py_EndInterpreter(PyThreadState *tstate) } interp->finalizing = 1; - // Wrap up existing "threading"-module-created, non-daemon threads. - wait_for_thread_shutdown(tstate); - - // Make any remaining pending calls. - _Py_FinishPendingCalls(tstate); + // This call stops the world and takes the pending calls lock. + make_pre_finalization_calls(tstate, /*subinterpreters=*/0); - _PyAtExit_Call(tstate->interp); - _PyRuntimeState *runtime = interp->runtime; - _PyEval_StopTheWorldAll(runtime); + ASSERT_WORLD_STOPPED(interp); /* Remaining daemon threads will automatically exit when they attempt to take the GIL (ex: PyEval_RestoreThread()). */ _PyInterpreterState_SetFinalizing(interp, tstate); @@ -2467,7 +2565,8 @@ Py_EndInterpreter(PyThreadState *tstate) _PyThreadState_SetShuttingDown(p); } - _PyEval_StartTheWorldAll(runtime); + _PyEval_StartTheWorldAll(interp->runtime); + PyMutex_Unlock(&interp->ceval.pending.mutex); _PyThreadState_DeleteList(list, /*is_after_fork=*/0); // XXX Call something like _PyImport_Disable() here? diff --git a/Python/pystate.c b/Python/pystate.c index f43989b0181b1a..29c713dccc9fe8 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1461,7 +1461,7 @@ init_threadstate(_PyThreadStateImpl *_tstate, assert(tstate->prev == NULL); assert(tstate->_whence == _PyThreadState_WHENCE_NOTSET); - assert(whence >= 0 && whence <= _PyThreadState_WHENCE_EXEC); + assert(whence >= 0 && whence <= _PyThreadState_WHENCE_THREADING_DAEMON); tstate->_whence = whence; assert(id > 0); diff --git a/Tools/c-analyzer/cpython/_parser.py b/Tools/c-analyzer/cpython/_parser.py index bd30809b0fba43..17c56c9e8762c6 100644 --- a/Tools/c-analyzer/cpython/_parser.py +++ b/Tools/c-analyzer/cpython/_parser.py @@ -80,6 +80,7 @@ def format_tsv_lines(lines): 'Python/generated_cases.c.h', 'Python/executor_cases.c.h', 'Python/optimizer_cases.c.h', + 'Python/opcode_targets.h', # XXX: Throws errors if PY_VERSION_HEX is not mocked out 'Modules/clinic/_testclinic_depr.c.h', diff --git a/Tools/cases_generator/target_generator.py b/Tools/cases_generator/target_generator.py index ca151ff640a30c..324ef2773abe28 100644 --- a/Tools/cases_generator/target_generator.py +++ b/Tools/cases_generator/target_generator.py @@ -26,19 +26,19 @@ def write_opcode_targets(analysis: Analysis, out: CWriter) -> None: for name, op in analysis.opmap.items(): if op < 256: targets[op] = f"&&TARGET_{name},\n" - out.emit("#if !Py_TAIL_CALL_INTERP\n") - out.emit("static void *opcode_targets[256] = {\n") + out.emit("#if !_Py_TAIL_CALL_INTERP\n") + out.emit("static void *opcode_targets_table[256] = {\n") for target in targets: out.emit(target) out.emit("};\n") - out.emit("#else /* Py_TAIL_CALL_INTERP */\n") + out.emit("#else /* _Py_TAIL_CALL_INTERP */\n") def function_proto(name: str) -> str: return f"Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_{name}(TAIL_CALL_PARAMS)" def write_tailcall_dispatch_table(analysis: Analysis, out: CWriter) -> None: - out.emit("static py_tail_call_funcptr INSTRUCTION_TABLE[256];\n") + out.emit("static py_tail_call_funcptr instruction_funcptr_table[256];\n") out.emit("\n") # Emit function prototypes for labels. @@ -60,7 +60,7 @@ def write_tailcall_dispatch_table(analysis: Analysis, out: CWriter) -> None: out.emit("\n") # Emit the dispatch table. - out.emit("static py_tail_call_funcptr INSTRUCTION_TABLE[256] = {\n") + out.emit("static py_tail_call_funcptr instruction_funcptr_table[256] = {\n") for name in sorted(analysis.instructions.keys()): out.emit(f"[{name}] = _TAIL_CALL_{name},\n") named_values = analysis.opmap.values() @@ -68,7 +68,7 @@ def write_tailcall_dispatch_table(analysis: Analysis, out: CWriter) -> None: if rest not in named_values: out.emit(f"[{rest}] = _TAIL_CALL_UNKNOWN_OPCODE,\n") out.emit("};\n") - outfile.write("#endif /* Py_TAIL_CALL_INTERP */\n") + outfile.write("#endif /* _Py_TAIL_CALL_INTERP */\n") arg_parser = argparse.ArgumentParser( description="Generate the file with dispatch targets.", diff --git a/Tools/cases_generator/tier1_generator.py b/Tools/cases_generator/tier1_generator.py index 2fc6794f6a0887..94ffb0118f0786 100644 --- a/Tools/cases_generator/tier1_generator.py +++ b/Tools/cases_generator/tier1_generator.py @@ -157,20 +157,20 @@ def generate_tier1( #define TIER_ONE 1 """) outfile.write(f""" -#if !Py_TAIL_CALL_INTERP +#if !_Py_TAIL_CALL_INTERP #if !USE_COMPUTED_GOTOS dispatch_opcode: switch (opcode) #endif {{ -#endif /* Py_TAIL_CALL_INTERP */ +#endif /* _Py_TAIL_CALL_INTERP */ {INSTRUCTION_START_MARKER} """ ) generate_tier1_cases(analysis, outfile, lines) outfile.write(f""" {INSTRUCTION_END_MARKER} -#if !Py_TAIL_CALL_INTERP +#if !_Py_TAIL_CALL_INTERP #if USE_COMPUTED_GOTOS _unknown_opcode: #else @@ -186,7 +186,7 @@ def generate_tier1( /* This should never be reached. Every opcode should end with DISPATCH() or goto error. */ Py_UNREACHABLE(); -#endif /* Py_TAIL_CALL_INTERP */ +#endif /* _Py_TAIL_CALL_INTERP */ {LABEL_START_MARKER} """) out = CWriter(outfile, 2, lines) @@ -226,7 +226,7 @@ def generate_tier1_cases( popped = get_popped(inst, analysis) # We need to ifdef it because this breaks platforms # without computed gotos/tail calling. - out.emit(f"#if Py_TAIL_CALL_INTERP\n") + out.emit(f"#if _Py_TAIL_CALL_INTERP\n") out.emit(f"int opcode = {name};\n") out.emit(f"(void)(opcode);\n") out.emit(f"#endif\n") diff --git a/Tools/clinic/libclinic/__init__.py b/Tools/clinic/libclinic/__init__.py index 7c5cede2396677..9e9bdeadcc0fe1 100644 --- a/Tools/clinic/libclinic/__init__.py +++ b/Tools/clinic/libclinic/__init__.py @@ -84,6 +84,7 @@ "argsbuf", "fastargs", "kwargs", + "kwds", "kwnames", "nargs", "noptargs", diff --git a/Tools/clinic/libclinic/converter.py b/Tools/clinic/libclinic/converter.py index 2c93dda3541030..ac66e79f93b735 100644 --- a/Tools/clinic/libclinic/converter.py +++ b/Tools/clinic/libclinic/converter.py @@ -274,7 +274,7 @@ def _render_non_self( data.modifications.append('/* modifications for ' + name + ' */\n' + modifications.rstrip()) # keywords - if parameter.is_vararg(): + if parameter.is_variable_length(): pass elif parameter.is_positional_only(): data.keywords.append('') diff --git a/Tools/clinic/libclinic/converters.py b/Tools/clinic/libclinic/converters.py index d9f93b93d75875..3154299e31b4dc 100644 --- a/Tools/clinic/libclinic/converters.py +++ b/Tools/clinic/libclinic/converters.py @@ -1300,3 +1300,37 @@ def parse_vararg(self, *, pos_only: int, min_pos: int, max_pos: int, {paramname} = {start}; {self.length_name} = {size}; """ + + +# Converters for var-keyword parameters. + +class VarKeywordCConverter(CConverter): + format_unit = '' + + def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> str | None: + raise AssertionError('should never be called') + + def parse_var_keyword(self) -> str: + raise NotImplementedError + + +class var_keyword_dict_converter(VarKeywordCConverter): + type = 'PyObject *' + c_default = 'NULL' + + def cleanup(self) -> str: + return f'Py_XDECREF({self.parser_name});\n' + + def parse_var_keyword(self) -> str: + param_name = self.parser_name + return f""" + if (kwargs == NULL) {{{{ + {param_name} = PyDict_New(); + if ({param_name} == NULL) {{{{ + goto exit; + }}}} + }}}} + else {{{{ + {param_name} = Py_NewRef(kwargs); + }}}} + """ diff --git a/Tools/clinic/libclinic/dsl_parser.py b/Tools/clinic/libclinic/dsl_parser.py index f9587d20383c7a..0d83baeba9e508 100644 --- a/Tools/clinic/libclinic/dsl_parser.py +++ b/Tools/clinic/libclinic/dsl_parser.py @@ -246,6 +246,7 @@ def dedent(self, line: str) -> str: class DSLParser: function: Function | None state: StateKeeper + expecting_parameters: bool keyword_only: bool positional_only: bool deprecated_positional: VersionTuple | None @@ -285,6 +286,7 @@ def __init__(self, clinic: Clinic) -> None: def reset(self) -> None: self.function = None self.state = self.state_dsl_start + self.expecting_parameters = True self.keyword_only = False self.positional_only = False self.deprecated_positional = None @@ -876,6 +878,10 @@ def state_parameter(self, line: str) -> None: def parse_parameter(self, line: str) -> None: assert self.function is not None + if not self.expecting_parameters: + fail('Encountered parameter line when not expecting ' + f'parameters: {line}') + match self.parameter_state: case ParamState.START | ParamState.REQUIRED: self.to_required() @@ -909,27 +915,40 @@ def parse_parameter(self, line: str) -> None: if len(function_args.args) > 1: fail(f"Function {self.function.name!r} has an " f"invalid parameter declaration (comma?): {line!r}") - if function_args.kwarg: - fail(f"Function {self.function.name!r} has an " - f"invalid parameter declaration (**kwargs?): {line!r}") + is_vararg = is_var_keyword = False if function_args.vararg: self.check_previous_star() self.check_remaining_star() is_vararg = True parameter = function_args.vararg + elif function_args.kwarg: + # If the existing parameters are all positional only or ``*args`` + # (var-positional), then we allow ``**kwds`` (var-keyword). + # Currently, pos-or-keyword or keyword-only arguments are not + # allowed with the ``**kwds`` converter. + has_non_positional_param = any( + p.is_positional_or_keyword() or p.is_keyword_only() + for p in self.function.parameters.values() + ) + if has_non_positional_param: + fail(f"Function {self.function.name!r} has an " + f"invalid parameter declaration (**kwargs?): {line!r}") + is_var_keyword = True + parameter = function_args.kwarg else: - is_vararg = False parameter = function_args.args[0] parameter_name = parameter.arg name, legacy, kwargs = self.parse_converter(parameter.annotation) if is_vararg: - name = 'varpos_' + name + name = f'varpos_{name}' + elif is_var_keyword: + name = f'var_keyword_{name}' value: object if not function_args.defaults: - if is_vararg: + if is_vararg or is_var_keyword: value = NULL else: if self.parameter_state is ParamState.OPTIONAL: @@ -1065,6 +1084,8 @@ def bad_node(self, node: ast.AST) -> None: kind: inspect._ParameterKind if is_vararg: kind = inspect.Parameter.VAR_POSITIONAL + elif is_var_keyword: + kind = inspect.Parameter.VAR_KEYWORD elif self.keyword_only: kind = inspect.Parameter.KEYWORD_ONLY else: @@ -1118,6 +1139,8 @@ def bad_node(self, node: ast.AST) -> None: if is_vararg: self.keyword_only = True + if is_var_keyword: + self.expecting_parameters = False @staticmethod def parse_converter( @@ -1159,6 +1182,9 @@ def parse_star(self, function: Function, version: VersionTuple | None) -> None: The 'version' parameter signifies the future version from which the marker will take effect (None means it is already in effect). """ + if not self.expecting_parameters: + fail("Encountered '*' when not expecting parameters") + if version is None: self.check_previous_star() self.check_remaining_star() @@ -1214,6 +1240,9 @@ def parse_slash(self, function: Function, version: VersionTuple | None) -> None: The 'version' parameter signifies the future version from which the marker will take effect (None means it is already in effect). """ + if not self.expecting_parameters: + fail("Encountered '/' when not expecting parameters") + if version is None: if self.deprecated_keyword: fail(f"Function {function.name!r}: '/' must precede '/ [from ...]'") @@ -1450,11 +1479,13 @@ def add_parameter(text: str) -> None: if p.is_vararg(): p_lines.append("*") added_star = True + if p.is_var_keyword(): + p_lines.append("**") name = p.converter.signature_name or p.name p_lines.append(name) - if not p.is_vararg() and p.converter.is_optional(): + if not p.is_variable_length() and p.converter.is_optional(): p_lines.append('=') value = p.converter.py_default if not value: @@ -1583,8 +1614,11 @@ def check_remaining_star(self, lineno: int | None = None) -> None: for p in reversed(self.function.parameters.values()): if self.keyword_only: - if (p.kind == inspect.Parameter.KEYWORD_ONLY or - p.kind == inspect.Parameter.VAR_POSITIONAL): + if p.kind in { + inspect.Parameter.KEYWORD_ONLY, + inspect.Parameter.VAR_POSITIONAL, + inspect.Parameter.VAR_KEYWORD + }: return elif self.deprecated_positional: if p.deprecated_positional == self.deprecated_positional: diff --git a/Tools/clinic/libclinic/function.py b/Tools/clinic/libclinic/function.py index 4280af0c4c9b49..f981f0bcaf89f0 100644 --- a/Tools/clinic/libclinic/function.py +++ b/Tools/clinic/libclinic/function.py @@ -220,9 +220,18 @@ def is_keyword_only(self) -> bool: def is_positional_only(self) -> bool: return self.kind == inspect.Parameter.POSITIONAL_ONLY + def is_positional_or_keyword(self) -> bool: + return self.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD + def is_vararg(self) -> bool: return self.kind == inspect.Parameter.VAR_POSITIONAL + def is_var_keyword(self) -> bool: + return self.kind == inspect.Parameter.VAR_KEYWORD + + def is_variable_length(self) -> bool: + return self.is_vararg() or self.is_var_keyword() + def is_optional(self) -> bool: return not self.is_vararg() and (self.default is not unspecified) diff --git a/Tools/clinic/libclinic/parse_args.py b/Tools/clinic/libclinic/parse_args.py index 0e15d2f163b816..bca87ecd75100c 100644 --- a/Tools/clinic/libclinic/parse_args.py +++ b/Tools/clinic/libclinic/parse_args.py @@ -36,7 +36,7 @@ def declare_parser( num_keywords = len([ p for p in f.parameters.values() - if not p.is_positional_only() and not p.is_vararg() + if p.is_positional_or_keyword() or p.is_keyword_only() ]) condition = '#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)' @@ -220,6 +220,7 @@ class ParseArgsCodeGen: max_pos: int = 0 min_kw_only: int = 0 varpos: Parameter | None = None + var_keyword: Parameter | None = None docstring_prototype: str docstring_definition: str @@ -255,13 +256,24 @@ def __init__(self, func: Function, codegen: CodeGen) -> None: del self.parameters[i] break + for i, p in enumerate(self.parameters): + if p.is_var_keyword(): + self.var_keyword = p + del self.parameters[i] + break + self.converters = [p.converter for p in self.parameters] if self.func.critical_section: self.codegen.add_include('pycore_critical_section.h', 'Py_BEGIN_CRITICAL_SECTION()') + + # Use fastcall if not disabled, except if in a __new__ or + # __init__ method, or if there is a **kwargs parameter. if self.func.disable_fastcall: self.fastcall = False + elif self.var_keyword is not None: + self.fastcall = False else: self.fastcall = not self.is_new_or_init() @@ -469,6 +481,12 @@ def _parse_vararg(self) -> str: fastcall=self.fastcall, limited_capi=self.limited_capi) + def _parse_kwarg(self) -> str: + assert self.var_keyword is not None + c = self.var_keyword.converter + assert isinstance(c, libclinic.converters.VarKeywordCConverter) + return c.parse_var_keyword() + def parse_pos_only(self) -> None: if self.fastcall: # positional-only, but no option groups @@ -564,6 +582,8 @@ def parse_pos_only(self) -> None: parser_code.append("skip_optional:") if self.varpos: parser_code.append(libclinic.normalize_snippet(self._parse_vararg(), indent=4)) + elif self.var_keyword: + parser_code.append(libclinic.normalize_snippet(self._parse_kwarg(), indent=4)) else: for parameter in self.parameters: parameter.converter.use_converter() @@ -590,6 +610,45 @@ def parse_pos_only(self) -> None: """, indent=4)] self.parser_body(*parser_code) + def parse_var_keyword(self) -> None: + self.flags = "METH_VARARGS|METH_KEYWORDS" + self.parser_prototype = PARSER_PROTOTYPE_KEYWORD + nargs = 'PyTuple_GET_SIZE(args)' + + parser_code = [] + max_args = NO_VARARG if self.varpos else self.max_pos + if self.varpos is None and self.min_pos == self.max_pos == 0: + self.codegen.add_include('pycore_modsupport.h', + '_PyArg_NoPositional()') + parser_code.append(libclinic.normalize_snippet(""" + if (!_PyArg_NoPositional("{name}", args)) {{ + goto exit; + }} + """, indent=4)) + elif self.min_pos or max_args != NO_VARARG: + self.codegen.add_include('pycore_modsupport.h', + '_PyArg_CheckPositional()') + parser_code.append(libclinic.normalize_snippet(f""" + if (!_PyArg_CheckPositional("{{name}}", {nargs}, {self.min_pos}, {max_args})) {{{{ + goto exit; + }}}} + """, indent=4)) + + for i, p in enumerate(self.parameters): + parse_arg = p.converter.parse_arg( + f'PyTuple_GET_ITEM(args, {i})', + p.get_displayname(i+1), + limited_capi=self.limited_capi, + ) + assert parse_arg is not None + parser_code.append(libclinic.normalize_snippet(parse_arg, indent=4)) + + if self.varpos: + parser_code.append(libclinic.normalize_snippet(self._parse_vararg(), indent=4)) + if self.var_keyword: + parser_code.append(libclinic.normalize_snippet(self._parse_kwarg(), indent=4)) + self.parser_body(*parser_code) + def parse_general(self, clang: CLanguage) -> None: parsearg: str | None deprecated_positionals: dict[int, Parameter] = {} @@ -921,12 +980,14 @@ def parse_args(self, clang: CLanguage) -> dict[str, str]: # previous call to parser_body. this is used for an awful hack. self.parser_body_fields: tuple[str, ...] = () - if not self.parameters and not self.varpos: + if not self.parameters and not self.varpos and not self.var_keyword: self.parse_no_args() elif self.use_meth_o(): self.parse_one_arg() elif self.has_option_groups(): self.parse_option_groups() + elif self.var_keyword is not None: + self.parse_var_keyword() elif (not self.requires_defining_class and self.pos_only == len(self.parameters)): self.parse_pos_only() diff --git a/configure b/configure index 30562de4418516..ed6befdbced108 100755 --- a/configure +++ b/configure @@ -29814,7 +29814,7 @@ then : if test "$withval" = yes then -printf "%s\n" "#define Py_TAIL_CALL_INTERP 1" >>confdefs.h +printf "%s\n" "#define _Py_TAIL_CALL_INTERP 1" >>confdefs.h { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } @@ -29822,7 +29822,7 @@ fi if test "$withval" = no then -printf "%s\n" "#define Py_TAIL_CALL_INTERP 0" >>confdefs.h +printf "%s\n" "#define _Py_TAIL_CALL_INTERP 0" >>confdefs.h { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } diff --git a/configure.ac b/configure.ac index ac84ac65efb5c0..5d4c5c43187953 100644 --- a/configure.ac +++ b/configure.ac @@ -7107,13 +7107,13 @@ AC_ARG_WITH( [ if test "$withval" = yes then - AC_DEFINE([Py_TAIL_CALL_INTERP], [1], + AC_DEFINE([_Py_TAIL_CALL_INTERP], [1], [Define if you want to use tail-calling interpreters in CPython.]) AC_MSG_RESULT([yes]) fi if test "$withval" = no then - AC_DEFINE([Py_TAIL_CALL_INTERP], [0], + AC_DEFINE([_Py_TAIL_CALL_INTERP], [0], [Define if you want to use tail-calling interpreters in CPython.]) AC_MSG_RESULT([no]) fi diff --git a/pyconfig.h.in b/pyconfig.h.in index eec1875eab6ca2..60bff4a9f26356 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1752,9 +1752,6 @@ /* The version of SunOS/Solaris as reported by `uname -r' without the dot. */ #undef Py_SUNOS_VERSION -/* Define if you want to use tail-calling interpreters in CPython. */ -#undef Py_TAIL_CALL_INTERP - /* Define if you want to enable tracing references for debugging purpose */ #undef Py_TRACE_REFS @@ -2026,6 +2023,9 @@ /* HACL* library can compile SIMD256 implementations */ #undef _Py_HACL_CAN_COMPILE_VEC256 +/* Define if you want to use tail-calling interpreters in CPython. */ +#undef _Py_TAIL_CALL_INTERP + /* Define to force use of thread-safe errno, h_errno, and other functions */ #undef _REENTRANT