diff --git a/.azure-pipelines/ci.yml b/.azure-pipelines/ci.yml index 9b638ddd004..50dc50a6549 100644 --- a/.azure-pipelines/ci.yml +++ b/.azure-pipelines/ci.yml @@ -61,7 +61,7 @@ jobs: variables: testRunTitle: '$(build.sourceBranchName)-linux' testRunPlatform: linux - openssl_version: 1.1.1f + openssl_version: 1.1.1g steps: - template: ./posix-steps.yml @@ -118,7 +118,7 @@ jobs: variables: testRunTitle: '$(Build.SourceBranchName)-linux-coverage' testRunPlatform: linux-coverage - openssl_version: 1.1.1f + openssl_version: 1.1.1g steps: - template: ./posix-steps.yml diff --git a/.azure-pipelines/pr.yml b/.azure-pipelines/pr.yml index 65f23eb62ee..228f9db4f8e 100644 --- a/.azure-pipelines/pr.yml +++ b/.azure-pipelines/pr.yml @@ -61,7 +61,7 @@ jobs: variables: testRunTitle: '$(system.pullRequest.TargetBranch)-linux' testRunPlatform: linux - openssl_version: 1.1.1f + openssl_version: 1.1.1g steps: - template: ./posix-steps.yml @@ -118,7 +118,7 @@ jobs: variables: testRunTitle: '$(Build.SourceBranchName)-linux-coverage' testRunPlatform: linux-coverage - openssl_version: 1.1.1f + openssl_version: 1.1.1g steps: - template: ./posix-steps.yml diff --git a/.gitattributes b/.gitattributes index bec16a08152..598d8f0f159 100644 --- a/.gitattributes +++ b/.gitattributes @@ -41,8 +41,6 @@ PC/readme.txt text eol=crlf # Generated files # https://github.com/github/linguist#generated-code -Include/graminit.h linguist-generated=true -Python/graminit.h linguist-generated=true Modules/clinic/*.h linguist-generated=true Objects/clinic/*.h linguist-generated=true PC/clinic/*.h linguist-generated=true diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 4d80698eff3..31003a8ac24 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -72,10 +72,10 @@ Include/pytime.h @pganssle @abalkin /Modules/gcmodule.c @pablogsal /Doc/library/gc.rst @pablogsal -# Parser/Pgen -/Parser/pgen/ @pablogsal -/Parser/pegen/ @pablogsal -/Tools/peg_generator/ @pablogsal +# Parser +/Parser/ @pablogsal @lysnikolaou +/Tools/peg_generator/ @pablogsal @lysnikolaou +/Lib/test/test_peg_generator/ @pablogsal @lysnikolaou # SQLite 3 **/*sqlite* @berkerpeksag diff --git a/.github/problem-matchers/gcc.json b/.github/problem-matchers/gcc.json new file mode 100644 index 00000000000..bd5ab6c00a7 --- /dev/null +++ b/.github/problem-matchers/gcc.json @@ -0,0 +1,18 @@ +{ + "__comment": "Taken from vscode-cpptools's Extension/package.json gcc rule", + "problemMatcher": [ + { + "owner": "gcc-problem-matcher", + "pattern": [ + { + "regexp": "^(.*):(\\d+):(\\d+):\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + ] + } + ] +} \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6bb52cb6a5d..5649a6670e7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -87,6 +87,8 @@ jobs: OPENSSL_VER: 1.1.1f steps: - uses: actions/checkout@v2 + - name: Register gcc problem matcher + run: echo "::add-matcher::.github/problem-matchers/gcc.json" - name: Install Dependencies run: sudo ./.github/workflows/posix-deps-apt.sh - name: 'Restore OpenSSL build' diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 4f46cbf1100..035348e8a69 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -52,6 +52,7 @@ jobs: python -m pip install -U coverage python -m pip install -r Misc/requirements-test.txt python -m test.pythoninfo + export PYTHONPATH=`find .venv -name fullcoverage` - name: 'Tests with coverage' run: > source ./.venv/bin/activate && @@ -67,6 +68,7 @@ jobs: || true - name: 'Publish code coverage results' run: | + export PYTHONPATH= source ./.venv/bin/activate bash <(curl -s https://codecov.io/bash) -y .github/codecov.yml env: diff --git a/.travis.yml b/.travis.yml index 133385fbf5c..a915f7a46ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -82,6 +82,12 @@ matrix: packages: - xvfb before_script: + - | + if [[ "$TRAVIS_PULL_REQUEST" != "false" ]] + then + echo "Don't run Python coverage on pull requests." + exit + fi - ./configure - make -j4 # Need a venv that can parse covered code. @@ -89,11 +95,13 @@ matrix: - ./venv/bin/python -m pip install -U coverage - ./venv/bin/python -m pip install -r Misc/requirements-test.txt - ./venv/bin/python -m test.pythoninfo + - export PYTHONPATH=`find venv -name fullcoverage` script: # Skip tests that re-run the entire test suite. - xvfb-run ./venv/bin/python -m coverage run --branch --pylib -m test --fail-env-changed -uall,-cpu -x test_multiprocessing_fork -x test_multiprocessing_forkserver -x test_multiprocessing_spawn -x test_concurrent_futures || true after_script: # Probably should be after_success once test suite updated to run under coverage.py. # Make the `coverage` command available to Codecov w/ a version of Python that can parse all source files. + - export PYTHONPATH= - source ./venv/bin/activate - bash <(curl -s https://codecov.io/bash) -y .github/codecov.yml - name: "Test code coverage (C)" @@ -107,6 +115,12 @@ matrix: - lcov - xvfb before_script: + - | + if [[ "$TRAVIS_PULL_REQUEST" != "false" ]] + then + echo "Don't run C coverage on pull requests." + exit + fi - ./configure script: - xvfb-run make -j4 coverage-report diff --git a/Doc/Makefile b/Doc/Makefile index 05361f2ee2c..b8ca1edfbc6 100644 --- a/Doc/Makefile +++ b/Doc/Makefile @@ -143,7 +143,7 @@ clean: venv: $(PYTHON) -m venv $(VENVDIR) $(VENVDIR)/bin/python3 -m pip install -U pip setuptools - $(VENVDIR)/bin/python3 -m pip install -U Sphinx==2.2.0 blurb python-docs-theme + $(VENVDIR)/bin/python3 -m pip install -U Sphinx==2.3.1 blurb python-docs-theme @echo "The venv has been created in the $(VENVDIR) directory" dist: diff --git a/Doc/c-api/abstract.rst b/Doc/c-api/abstract.rst index 1823f9d70c7..f5df09fa7fd 100644 --- a/Doc/c-api/abstract.rst +++ b/Doc/c-api/abstract.rst @@ -24,4 +24,3 @@ but whose items have not been set to some non-\ ``NULL`` value yet. mapping.rst iter.rst buffer.rst - objbuffer.rst diff --git a/Doc/c-api/arg.rst b/Doc/c-api/arg.rst index b7baad589a7..26e872c5a34 100644 --- a/Doc/c-api/arg.rst +++ b/Doc/c-api/arg.rst @@ -55,13 +55,11 @@ which disallows mutable objects such as :class:`bytearray`. .. note:: - For all ``#`` variants of formats (``s#``, ``y#``, etc.), the type of - the length argument (int or :c:type:`Py_ssize_t`) is controlled by - defining the macro :c:macro:`PY_SSIZE_T_CLEAN` before including - :file:`Python.h`. If the macro was defined, length is a - :c:type:`Py_ssize_t` rather than an :c:type:`int`. This behavior will change - in a future Python version to only support :c:type:`Py_ssize_t` and - drop :c:type:`int` support. It is best to always define :c:macro:`PY_SSIZE_T_CLEAN`. + For all ``#`` variants of formats (``s#``, ``y#``, etc.), the macro + :c:macro:`PY_SSIZE_T_CLEAN` must be defined before including + :file:`Python.h`. On Python 3.9 and older, the type of the length argument + is :c:type:`Py_ssize_t` if the :c:macro:`PY_SSIZE_T_CLEAN` macro is defined, + or int otherwise. ``s`` (:class:`str`) [const char \*] @@ -90,7 +88,7 @@ which disallows mutable objects such as :class:`bytearray`. In this case the resulting C string may contain embedded NUL bytes. Unicode objects are converted to C strings using ``'utf-8'`` encoding. -``s#`` (:class:`str`, read-only :term:`bytes-like object`) [const char \*, int or :c:type:`Py_ssize_t`] +``s#`` (:class:`str`, read-only :term:`bytes-like object`) [const char \*, :c:type:`Py_ssize_t`] Like ``s*``, except that it doesn't accept mutable objects. The result is stored into two C variables, the first one a pointer to a C string, the second one its length. @@ -105,7 +103,7 @@ which disallows mutable objects such as :class:`bytearray`. Like ``s*``, but the Python object may also be ``None``, in which case the ``buf`` member of the :c:type:`Py_buffer` structure is set to ``NULL``. -``z#`` (:class:`str`, read-only :term:`bytes-like object` or ``None``) [const char \*, int or :c:type:`Py_ssize_t`] +``z#`` (:class:`str`, read-only :term:`bytes-like object` or ``None``) [const char \*, :c:type:`Py_ssize_t`] Like ``s#``, but the Python object may also be ``None``, in which case the C pointer is set to ``NULL``. @@ -124,7 +122,7 @@ which disallows mutable objects such as :class:`bytearray`. bytes-like objects. **This is the recommended way to accept binary data.** -``y#`` (read-only :term:`bytes-like object`) [const char \*, int or :c:type:`Py_ssize_t`] +``y#`` (read-only :term:`bytes-like object`) [const char \*, :c:type:`Py_ssize_t`] This variant on ``s#`` doesn't accept Unicode objects, only bytes-like objects. @@ -155,7 +153,7 @@ which disallows mutable objects such as :class:`bytearray`. Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using :c:func:`PyUnicode_AsWideCharString`. -``u#`` (:class:`str`) [const Py_UNICODE \*, int or :c:type:`Py_ssize_t`] +``u#`` (:class:`str`) [const Py_UNICODE \*, :c:type:`Py_ssize_t`] This variant on ``u`` stores into two C variables, the first one a pointer to a Unicode data buffer, the second one its length. This variant allows null code points. @@ -172,7 +170,7 @@ which disallows mutable objects such as :class:`bytearray`. Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using :c:func:`PyUnicode_AsWideCharString`. -``Z#`` (:class:`str` or ``None``) [const Py_UNICODE \*, int or :c:type:`Py_ssize_t`] +``Z#`` (:class:`str` or ``None``) [const Py_UNICODE \*, :c:type:`Py_ssize_t`] Like ``u#``, but the Python object may also be ``None``, in which case the :c:type:`Py_UNICODE` pointer is set to ``NULL``. @@ -213,7 +211,7 @@ which disallows mutable objects such as :class:`bytearray`. recoding them. Instead, the implementation assumes that the byte string object uses the encoding passed in as parameter. -``es#`` (:class:`str`) [const char \*encoding, char \*\*buffer, int or :c:type:`Py_ssize_t` \*buffer_length] +``es#`` (:class:`str`) [const char \*encoding, char \*\*buffer, :c:type:`Py_ssize_t` \*buffer_length] This variant on ``s#`` is used for encoding Unicode into a character buffer. Unlike the ``es`` format, this variant allows input data which contains NUL characters. @@ -244,7 +242,7 @@ which disallows mutable objects such as :class:`bytearray`. In both cases, *\*buffer_length* is set to the length of the encoded data without the trailing NUL byte. -``et#`` (:class:`str`, :class:`bytes` or :class:`bytearray`) [const char \*encoding, char \*\*buffer, int or :c:type:`Py_ssize_t` \*buffer_length] +``et#`` (:class:`str`, :class:`bytes` or :class:`bytearray`) [const char \*encoding, char \*\*buffer, :c:type:`Py_ssize_t` \*buffer_length] Same as ``es#`` except that byte string objects are passed through without recoding them. Instead, the implementation assumes that the byte string object uses the encoding passed in as parameter. @@ -549,7 +547,7 @@ Building values Convert a null-terminated C string to a Python :class:`str` object using ``'utf-8'`` encoding. If the C string pointer is ``NULL``, ``None`` is used. - ``s#`` (:class:`str` or ``None``) [const char \*, int or :c:type:`Py_ssize_t`] + ``s#`` (:class:`str` or ``None``) [const char \*, :c:type:`Py_ssize_t`] Convert a C string and its length to a Python :class:`str` object using ``'utf-8'`` encoding. If the C string pointer is ``NULL``, the length is ignored and ``None`` is returned. @@ -558,14 +556,14 @@ Building values This converts a C string to a Python :class:`bytes` object. If the C string pointer is ``NULL``, ``None`` is returned. - ``y#`` (:class:`bytes`) [const char \*, int or :c:type:`Py_ssize_t`] + ``y#`` (:class:`bytes`) [const char \*, :c:type:`Py_ssize_t`] This converts a C string and its lengths to a Python object. If the C string pointer is ``NULL``, ``None`` is returned. ``z`` (:class:`str` or ``None``) [const char \*] Same as ``s``. - ``z#`` (:class:`str` or ``None``) [const char \*, int or :c:type:`Py_ssize_t`] + ``z#`` (:class:`str` or ``None``) [const char \*, :c:type:`Py_ssize_t`] Same as ``s#``. ``u`` (:class:`str`) [const wchar_t \*] @@ -573,7 +571,7 @@ Building values data to a Python Unicode object. If the Unicode buffer pointer is ``NULL``, ``None`` is returned. - ``u#`` (:class:`str`) [const wchar_t \*, int or :c:type:`Py_ssize_t`] + ``u#`` (:class:`str`) [const wchar_t \*, :c:type:`Py_ssize_t`] Convert a Unicode (UTF-16 or UCS-4) data buffer and its length to a Python Unicode object. If the Unicode buffer pointer is ``NULL``, the length is ignored and ``None`` is returned. @@ -581,7 +579,7 @@ Building values ``U`` (:class:`str` or ``None``) [const char \*] Same as ``s``. - ``U#`` (:class:`str` or ``None``) [const char \*, int or :c:type:`Py_ssize_t`] + ``U#`` (:class:`str` or ``None``) [const char \*, :c:type:`Py_ssize_t`] Same as ``s#``. ``i`` (:class:`int`) [int] diff --git a/Doc/c-api/conversion.rst b/Doc/c-api/conversion.rst index b310fcb5e4f..efbaa52e2dc 100644 --- a/Doc/c-api/conversion.rst +++ b/Doc/c-api/conversion.rst @@ -27,12 +27,8 @@ not. The wrappers ensure that *str*[*size*-1] is always ``'\0'`` upon return. They never write more than *size* bytes (including the trailing ``'\0'``) into str. -Both functions require that ``str != NULL``, ``size > 0`` and ``format != -NULL``. - -If the platform doesn't have :c:func:`vsnprintf` and the buffer size needed to -avoid truncation exceeds *size* by more than 512 bytes, Python aborts with a -:c:func:`Py_FatalError`. +Both functions require that ``str != NULL``, ``size > 0``, ``format != NULL`` +and ``size < INT_MAX``. The return value (*rv*) for these functions should be interpreted as follows: @@ -48,8 +44,8 @@ The return value (*rv*) for these functions should be interpreted as follows: this case too, but the rest of *str* is undefined. The exact cause of the error depends on the underlying platform. -The following functions provide locale-independent string to number conversions. +The following functions provide locale-independent string to number conversions. .. c:function:: double PyOS_string_to_double(const char *s, char **endptr, PyObject *overflow_exception) diff --git a/Doc/c-api/dict.rst b/Doc/c-api/dict.rst index 2fb29cdd617..7493837ac62 100644 --- a/Doc/c-api/dict.rst +++ b/Doc/c-api/dict.rst @@ -100,6 +100,10 @@ Dictionary Objects :meth:`__eq__` methods will get suppressed. To get error reporting use :c:func:`PyDict_GetItemWithError()` instead. + .. versionchanged:: 3.10 + Calling this API without :term:`GIL` held had been allowed for historical + reason. It is no longer allowed. + .. c:function:: PyObject* PyDict_GetItemWithError(PyObject *p, PyObject *key) diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst index fc82c3eb590..37f5b9f880b 100644 --- a/Doc/c-api/init_config.rst +++ b/Doc/c-api/init_config.rst @@ -43,6 +43,7 @@ Functions: * :c:func:`Py_PreInitializeFromArgs` * :c:func:`Py_PreInitializeFromBytesArgs` * :c:func:`Py_RunMain` +* :c:func:`Py_GetArgcArgv` The preconfiguration (``PyPreConfig`` type) is stored in ``_PyRuntime.preconfig`` and the configuration (``PyConfig`` type) is stored in @@ -196,12 +197,12 @@ PyPreConfig Function to initialize a preconfiguration: - .. c:function:: void PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig) + .. c:function:: void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig) Initialize the preconfiguration with :ref:`Python Configuration `. - .. c:function:: void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig) + .. c:function:: void PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig) Initialize the preconfiguration with :ref:`Isolated Configuration `. @@ -423,6 +424,8 @@ PyConfig :c:member:`~PyConfig.argv` is empty, an empty string is added to ensure that :data:`sys.argv` always exists and is never empty. + See also the :c:member:`~PyConfig.orig_argv` member. + .. c:member:: wchar_t* base_exec_prefix :data:`sys.base_exec_prefix`. @@ -436,6 +439,14 @@ PyConfig :data:`sys.base_prefix`. + .. c:member:: wchar_t* platlibdir + + :data:`sys.platlibdir`: platform library directory name, set at configure time + by ``--with-platlibdir``, overrideable by the ``PYTHONPLATLIBDIR`` + environment variable. + + .. versionadded:: 3.9 + .. c:member:: int buffered_stdio If equals to 0, enable unbuffered mode, making the stdout and stderr @@ -577,6 +588,23 @@ PyConfig * 1: Remove assertions, set ``__debug__`` to ``False`` * 2: Strip docstrings + .. c:member:: PyWideStringList orig_argv + + The list of the original command line arguments passed to the Python + executable. + + If :c:member:`~PyConfig.orig_argv` list is empty and + :c:member:`~PyConfig.argv` is not a list only containing an empty + string, :c:func:`PyConfig_Read()` copies :c:member:`~PyConfig.argv` into + :c:member:`~PyConfig.orig_argv` before modifying + :c:member:`~PyConfig.argv` (if :c:member:`~PyConfig.parse_argv` is + non-zero). + + See also the :c:member:`~PyConfig.argv` member and the + :c:func:`Py_GetArgcArgv` function. + + .. versionadded:: 3.10 + .. c:member:: int parse_argv If non-zero, parse :c:member:`~PyConfig.argv` the same way the regular @@ -686,16 +714,6 @@ PyConfig :data:`sys._xoptions`. - .. c:member:: int _use_peg_parser - - Enable PEG parser? Default: 1. - - Set to 0 by :option:`-X oldparser <-X>` and :envvar:`PYTHONOLDPARSER`. - - See also :pep:`617`. - - .. deprecated-removed:: 3.9 3.10 - If ``parse_argv`` is non-zero, ``argv`` arguments are parsed the same way the regular Python parses command line arguments, and Python arguments are stripped from ``argv``: see :ref:`Command Line Arguments @@ -884,6 +902,7 @@ Path Configuration * Path configuration inputs: * :c:member:`PyConfig.home` + * :c:member:`PyConfig.platlibdir` * :c:member:`PyConfig.pathconfig_warnings` * :c:member:`PyConfig.program_name` * :c:member:`PyConfig.pythonpath_env` @@ -975,6 +994,16 @@ customized Python always running in isolated mode using :c:func:`Py_RunMain`. +Py_GetArgcArgv() +---------------- + +.. c:function:: void Py_GetArgcArgv(int *argc, wchar_t ***argv) + + Get the original command line arguments, before Python modified them. + + See also :c:member:`PyConfig.orig_argv` member. + + Multi-Phase Initialization Private Provisional API -------------------------------------------------- diff --git a/Doc/c-api/long.rst b/Doc/c-api/long.rst index c5c2aa60dcc..4d859fb641d 100644 --- a/Doc/c-api/long.rst +++ b/Doc/c-api/long.rst @@ -94,23 +94,10 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate. are no digits, :exc:`ValueError` will be raised. -.. c:function:: PyObject* PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base) - - Convert a sequence of Unicode digits to a Python integer value. The Unicode - string is first encoded to a byte string using :c:func:`PyUnicode_EncodeDecimal` - and then converted using :c:func:`PyLong_FromString`. - - .. deprecated-removed:: 3.3 4.0 - Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using - :c:func:`PyLong_FromUnicodeObject`. - - .. c:function:: PyObject* PyLong_FromUnicodeObject(PyObject *u, int base) Convert a sequence of Unicode digits in the string *u* to a Python integer - value. The Unicode string is first encoded to a byte string using - :c:func:`PyUnicode_EncodeDecimal` and then converted using - :c:func:`PyLong_FromString`. + value. .. versionadded:: 3.3 @@ -129,9 +116,8 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate. single: OverflowError (built-in exception) Return a C :c:type:`long` representation of *obj*. If *obj* is not an - instance of :c:type:`PyLongObject`, first call its :meth:`__index__` or - :meth:`__int__` method (if present) to convert it to a - :c:type:`PyLongObject`. + instance of :c:type:`PyLongObject`, first call its :meth:`__index__` method + (if present) to convert it to a :c:type:`PyLongObject`. Raise :exc:`OverflowError` if the value of *obj* is out of range for a :c:type:`long`. @@ -141,16 +127,15 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate. .. versionchanged:: 3.8 Use :meth:`__index__` if available. - .. deprecated:: 3.8 - Using :meth:`__int__` is deprecated. + .. versionchanged:: 3.10 + This function will no longer use :meth:`__int__`. .. c:function:: long PyLong_AsLongAndOverflow(PyObject *obj, int *overflow) Return a C :c:type:`long` representation of *obj*. If *obj* is not an - instance of :c:type:`PyLongObject`, first call its :meth:`__index__` or - :meth:`__int__` method (if present) to convert it to a - :c:type:`PyLongObject`. + instance of :c:type:`PyLongObject`, first call its :meth:`__index__` + method (if present) to convert it to a :c:type:`PyLongObject`. If the value of *obj* is greater than :const:`LONG_MAX` or less than :const:`LONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively, and @@ -162,8 +147,8 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate. .. versionchanged:: 3.8 Use :meth:`__index__` if available. - .. deprecated:: 3.8 - Using :meth:`__int__` is deprecated. + .. versionchanged:: 3.10 + This function will no longer use :meth:`__int__`. .. c:function:: long long PyLong_AsLongLong(PyObject *obj) @@ -172,9 +157,8 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate. single: OverflowError (built-in exception) Return a C :c:type:`long long` representation of *obj*. If *obj* is not an - instance of :c:type:`PyLongObject`, first call its :meth:`__index__` or - :meth:`__int__` method (if present) to convert it to a - :c:type:`PyLongObject`. + instance of :c:type:`PyLongObject`, first call its :meth:`__index__` method + (if present) to convert it to a :c:type:`PyLongObject`. Raise :exc:`OverflowError` if the value of *obj* is out of range for a :c:type:`long long`. @@ -184,16 +168,15 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate. .. versionchanged:: 3.8 Use :meth:`__index__` if available. - .. deprecated:: 3.8 - Using :meth:`__int__` is deprecated. + .. versionchanged:: 3.10 + This function will no longer use :meth:`__int__`. .. c:function:: long long PyLong_AsLongLongAndOverflow(PyObject *obj, int *overflow) Return a C :c:type:`long long` representation of *obj*. If *obj* is not an - instance of :c:type:`PyLongObject`, first call its :meth:`__index__` or - :meth:`__int__` method (if present) to convert it to a - :c:type:`PyLongObject`. + instance of :c:type:`PyLongObject`, first call its :meth:`__index__` method + (if present) to convert it to a :c:type:`PyLongObject`. If the value of *obj* is greater than :const:`LLONG_MAX` or less than :const:`LLONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively, @@ -207,8 +190,8 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate. .. versionchanged:: 3.8 Use :meth:`__index__` if available. - .. deprecated:: 3.8 - Using :meth:`__int__` is deprecated. + .. versionchanged:: 3.10 + This function will no longer use :meth:`__int__`. .. c:function:: Py_ssize_t PyLong_AsSsize_t(PyObject *pylong) @@ -278,10 +261,9 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate. .. c:function:: unsigned long PyLong_AsUnsignedLongMask(PyObject *obj) - Return a C :c:type:`unsigned long` representation of *obj*. If *obj* - is not an instance of :c:type:`PyLongObject`, first call its - :meth:`__index__` or :meth:`__int__` method (if present) to convert - it to a :c:type:`PyLongObject`. + Return a C :c:type:`unsigned long` representation of *obj*. If *obj* is not + an instance of :c:type:`PyLongObject`, first call its :meth:`__index__` + method (if present) to convert it to a :c:type:`PyLongObject`. If the value of *obj* is out of range for an :c:type:`unsigned long`, return the reduction of that value modulo ``ULONG_MAX + 1``. @@ -292,16 +274,16 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate. .. versionchanged:: 3.8 Use :meth:`__index__` if available. - .. deprecated:: 3.8 - Using :meth:`__int__` is deprecated. + .. versionchanged:: 3.10 + This function will no longer use :meth:`__int__`. .. c:function:: unsigned long long PyLong_AsUnsignedLongLongMask(PyObject *obj) Return a C :c:type:`unsigned long long` representation of *obj*. If *obj* is not an instance of :c:type:`PyLongObject`, first call its - :meth:`__index__` or :meth:`__int__` method (if present) to convert - it to a :c:type:`PyLongObject`. + :meth:`__index__` method (if present) to convert it to a + :c:type:`PyLongObject`. If the value of *obj* is out of range for an :c:type:`unsigned long long`, return the reduction of that value modulo ``ULLONG_MAX + 1``. @@ -312,8 +294,8 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate. .. versionchanged:: 3.8 Use :meth:`__index__` if available. - .. deprecated:: 3.8 - Using :meth:`__int__` is deprecated. + .. versionchanged:: 3.10 + This function will no longer use :meth:`__int__`. .. c:function:: double PyLong_AsDouble(PyObject *pylong) diff --git a/Doc/c-api/number.rst b/Doc/c-api/number.rst index 620204ca8e2..37979bb506b 100644 --- a/Doc/c-api/number.rst +++ b/Doc/c-api/number.rst @@ -256,6 +256,10 @@ Number Protocol Returns the *o* converted to a Python int on success or ``NULL`` with a :exc:`TypeError` exception raised on failure. + .. versionchanged:: 3.10 + The result always has exact type :class:`int`. Previously, the result + could have been an instance of a subclass of ``int``. + .. c:function:: PyObject* PyNumber_ToBase(PyObject *n, int base) diff --git a/Doc/c-api/objbuffer.rst b/Doc/c-api/objbuffer.rst deleted file mode 100644 index 6b82a642d7e..00000000000 --- a/Doc/c-api/objbuffer.rst +++ /dev/null @@ -1,55 +0,0 @@ -.. highlight:: c - -Old Buffer Protocol -------------------- - -.. deprecated:: 3.0 - -These functions were part of the "old buffer protocol" API in Python 2. -In Python 3, this protocol doesn't exist anymore but the functions are still -exposed to ease porting 2.x code. They act as a compatibility wrapper -around the :ref:`new buffer protocol `, but they don't give -you control over the lifetime of the resources acquired when a buffer is -exported. - -Therefore, it is recommended that you call :c:func:`PyObject_GetBuffer` -(or the ``y*`` or ``w*`` :ref:`format codes ` with the -:c:func:`PyArg_ParseTuple` family of functions) to get a buffer view over -an object, and :c:func:`PyBuffer_Release` when the buffer view can be released. - - -.. c:function:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len) - - Returns a pointer to a read-only memory location usable as character-based - input. The *obj* argument must support the single-segment character buffer - interface. On success, returns ``0``, sets *buffer* to the memory location - and *buffer_len* to the buffer length. Returns ``-1`` and sets a - :exc:`TypeError` on error. - - -.. c:function:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len) - - Returns a pointer to a read-only memory location containing arbitrary data. - The *obj* argument must support the single-segment readable buffer - interface. On success, returns ``0``, sets *buffer* to the memory location - and *buffer_len* to the buffer length. Returns ``-1`` and sets a - :exc:`TypeError` on error. - - -.. c:function:: int PyObject_CheckReadBuffer(PyObject *o) - - Returns ``1`` if *o* supports the single-segment readable buffer interface. - Otherwise returns ``0``. This function always succeeds. - - Note that this function tries to get and release a buffer, and exceptions - which occur while calling corresponding functions will get suppressed. - To get error reporting use :c:func:`PyObject_GetBuffer()` instead. - - -.. c:function:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len) - - Returns a pointer to a writable memory location. The *obj* argument must - support the single-segment, character buffer interface. On success, - returns ``0``, sets *buffer* to the memory location and *buffer_len* to the - buffer length. Returns ``-1`` and sets a :exc:`TypeError` on error. - diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst index 5535f42ac12..b2392fa5e19 100644 --- a/Doc/c-api/structures.rst +++ b/Doc/c-api/structures.rst @@ -88,13 +88,13 @@ the definition of all other Python objects. .. versionadded:: 3.9 -.. c:macro:: Py_REFCNT(o) +.. c:function:: Py_ssize_t Py_REFCNT(const PyObject *o) - This macro is used to access the :attr:`ob_refcnt` member of a Python - object. - It expands to:: + Get the reference count of the Python object *o*. - (((PyObject*)(o))->ob_refcnt) + .. versionchanged:: 3.10 + :c:func:`Py_REFCNT()` is changed to the inline static function. + Use :c:func:`Py_SET_REFCNT()` to set an object reference count. .. c:function:: void Py_SET_REFCNT(PyObject *o, Py_ssize_t refcnt) @@ -104,12 +104,13 @@ the definition of all other Python objects. .. versionadded:: 3.9 -.. c:macro:: Py_SIZE(o) +.. c:function:: Py_ssize_t Py_SIZE(const PyVarObject *o) - This macro is used to access the :attr:`ob_size` member of a Python object. - It expands to:: + Get the size of the Python object *o*. - (((PyVarObject*)(o))->ob_size) + .. versionchanged:: 3.10 + :c:func:`Py_SIZE()` is changed to the inline static function. + Use :c:func:`Py_SET_SIZE()` to set an object size. .. c:function:: void Py_SET_SIZE(PyVarObject *o, Py_ssize_t size) diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst index ce4e8c926b2..385c7f94c67 100644 --- a/Doc/c-api/typeobj.rst +++ b/Doc/c-api/typeobj.rst @@ -1223,11 +1223,25 @@ and :c:type:`PyType_Type` effectively act as defaults.) but the instance has no strong reference to the elements inside it, as they are allowed to be removed even if the instance is still alive). - Note that :c:func:`Py_VISIT` requires the *visit* and *arg* parameters to :c:func:`local_traverse` to have these specific names; don't name them just anything. + Heap-allocated types (:const:`Py_TPFLAGS_HEAPTYPE`, such as those created + with :c:func:`PyType_FromSpec` and similar APIs) hold a reference to their + type. Their traversal function must therefore either visit + :c:func:`Py_TYPE(self) `, or delegate this responsibility by + calling ``tp_traverse`` of another heap-allocated type (such as a + heap-allocated superclass). + If they do not, the type object may not be garbage-collected. + + .. versionchanged:: 3.9 + + Heap-allocated types are expected to visit ``Py_TYPE(self)`` in + ``tp_traverse``. In earlier versions of Python, due to + `bug 40217 `_, doing this + may lead to crashes in subclasses. + **Inheritance:** Group: :const:`Py_TPFLAGS_HAVE_GC`, :attr:`tp_traverse`, :attr:`tp_clear` diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index b1787ed1ce8..0748a1e3194 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -724,20 +724,6 @@ Extension modules can continue using them, as they will not be removed in Python .. versionadded:: 3.3 -.. c:function:: Py_UNICODE* PyUnicode_AsUnicodeCopy(PyObject *unicode) - - Create a copy of a Unicode string ending with a null code point. Return ``NULL`` - and raise a :exc:`MemoryError` exception on memory allocation failure, - otherwise return a new allocated buffer (use :c:func:`PyMem_Free` to free - the buffer). Note that the resulting :c:type:`Py_UNICODE*` string may - contain embedded null code points, which would cause the string to be - truncated when used in most C functions. - - .. versionadded:: 3.2 - - Please migrate to using :c:func:`PyUnicode_AsUCS4Copy` or similar new APIs. - - .. c:function:: Py_ssize_t PyUnicode_GetSize(PyObject *unicode) Return the size of the deprecated :c:type:`Py_UNICODE` representation, in diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index 4dacbe201d2..882d7d6d62f 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -1205,11 +1205,6 @@ PyLong_FromString:const char*:str:: PyLong_FromString:char**:pend:: PyLong_FromString:int:base:: -PyLong_FromUnicode:PyObject*::+1: -PyLong_FromUnicode:Py_UNICODE*:u:: -PyLong_FromUnicode:Py_ssize_t:length:: -PyLong_FromUnicode:int:base:: - PyLong_FromUnicodeObject:PyObject*::+1: PyLong_FromUnicodeObject:PyObject*:u:0: PyLong_FromUnicodeObject:int:base:: @@ -1568,21 +1563,6 @@ PyOS_FSPath:PyObject*:path:0: PyObject_ASCII:PyObject*::+1: PyObject_ASCII:PyObject*:o:0: -PyObject_AsCharBuffer:int::: -PyObject_AsCharBuffer:PyObject*:obj:0: -PyObject_AsCharBuffer:const char**:buffer:: -PyObject_AsCharBuffer:Py_ssize_t*:buffer_len:: - -PyObject_AsReadBuffer:int::: -PyObject_AsReadBuffer:PyObject*:obj:0: -PyObject_AsReadBuffer:const void**:buffer:: -PyObject_AsReadBuffer:Py_ssize_t*:buffer_len:: - -PyObject_AsWriteBuffer:int::: -PyObject_AsWriteBuffer:PyObject*:obj:0: -PyObject_AsWriteBuffer:void**:buffer:: -PyObject_AsWriteBuffer:Py_ssize_t*:buffer_len:: - PyObject_Bytes:PyObject*::+1: PyObject_Bytes:PyObject*:o:0: @@ -1618,9 +1598,6 @@ PyObject_CallObject:PyObject*:args:0: PyObject_CheckBuffer:int::: PyObject_CheckBuffer:PyObject*:obj:0: -PyObject_CheckReadBuffer:int::: -PyObject_CheckReadBuffer:PyObject*:o:0: - PyObject_DelAttr:int::: PyObject_DelAttr:PyObject*:o:0: PyObject_DelAttr:PyObject*:attr_name:0: @@ -2442,9 +2419,6 @@ PyUnicode_AsUnicodeAndSize:Py_UNICODE*::: PyUnicode_AsUnicodeAndSize:PyObject*:unicode:0: PyUnicode_AsUnicodeAndSize:Py_ssize_t*:size:: -PyUnicode_AsUnicodeCopy:Py_UNICODE*::: -PyUnicode_AsUnicodeCopy:PyObject*:unicode:0: - PyUnicode_GetSize:Py_ssize_t::: PyUnicode_GetSize:PyObject*:unicode:0: diff --git a/Doc/distributing/index.rst b/Doc/distributing/index.rst index 5f7b3bbc4f9..02379946244 100644 --- a/Doc/distributing/index.rst +++ b/Doc/distributing/index.rst @@ -128,6 +128,7 @@ involved in creating and publishing a project: * `Project structure`_ * `Building and packaging the project`_ * `Uploading the project to the Python Packaging Index`_ +* `The .pypirc file`_ .. _Project structure: \ https://packaging.python.org/tutorials/distributing-packages/ @@ -135,6 +136,8 @@ involved in creating and publishing a project: https://packaging.python.org/tutorials/distributing-packages/#packaging-your-project .. _Uploading the project to the Python Packaging Index: \ https://packaging.python.org/tutorials/distributing-packages/#uploading-your-project-to-pypi +.. _The .pypirc file: \ + https://packaging.python.org/specifications/pypirc/ How do I...? diff --git a/Doc/faq/general.rst b/Doc/faq/general.rst index 3ef553e8acb..eee3c3c203e 100644 --- a/Doc/faq/general.rst +++ b/Doc/faq/general.rst @@ -17,12 +17,13 @@ What is Python? Python is an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high level dynamic data -types, and classes. Python combines remarkable power with very clear syntax. -It has interfaces to many system calls and libraries, as well as to various -window systems, and is extensible in C or C++. It is also usable as an -extension language for applications that need a programmable interface. -Finally, Python is portable: it runs on many Unix variants, on the Mac, and on -Windows 2000 and later. +types, and classes. It supports multiple programming paradigms beyond +object-oriented programming, such as procedural and functional programming. +Python combines remarkable power with very clear syntax. It has interfaces to +many system calls and libraries, as well as to various window systems, and is +extensible in C or C++. It is also usable as an extension language for +applications that need a programmable interface. Finally, Python is portable: +it runs on many Unix variants including Linux and macOS, and on Windows. To find out more, start with :ref:`tutorial-index`. The `Beginner's Guide to Python `_ links to other @@ -295,8 +296,8 @@ How stable is Python? --------------------- Very stable. New, stable releases have been coming out roughly every 6 to 18 -months since 1991, and this seems likely to continue. Currently there are -usually around 18 months between major releases. +months since 1991, and this seems likely to continue. As of version 3.9, +Python will have a major new release every 12 months (:pep:`602`). The developers issue "bugfix" releases of older versions, so the stability of existing releases gradually improves. Bugfix releases, indicated by a third @@ -314,8 +315,8 @@ be maintained after January 1, 2020 ` How many people are using Python? --------------------------------- -There are probably tens of thousands of users, though it's difficult to obtain -an exact count. +There are probably millions of users, though it's difficult to obtain an exact +count. Python is available for free download, so there are no sales figures, and it's available from many different sites and packaged with many Linux distributions, diff --git a/Doc/glossary.rst b/Doc/glossary.rst index 6189cb04504..e997d366777 100644 --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -189,6 +189,10 @@ Glossary A list of bytecode instructions can be found in the documentation for :ref:`the dis module `. + callback + A subroutine function which is passed as an argument to be executed at + some point in the future. + class A template for creating user-defined objects. Class definitions normally contain method definitions which operate on instances of the diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst index 17f4ff6e474..de0f834551f 100644 --- a/Doc/howto/logging-cookbook.rst +++ b/Doc/howto/logging-cookbook.rst @@ -1368,7 +1368,7 @@ An example dictionary-based configuration ----------------------------------------- Below is an example of a logging configuration dictionary - it's taken from -the `documentation on the Django project `_. +the `documentation on the Django project `_. This dictionary is passed to :func:`~config.dictConfig` to put the configuration into effect:: LOGGING = { @@ -1424,7 +1424,7 @@ This dictionary is passed to :func:`~config.dictConfig` to put the configuration } For more information about this configuration, you can see the `relevant -section `_ +section `_ of the Django documentation. .. _cookbook-rotator-namer: diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 5e0096cae73..0b64dfe47f7 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1133,6 +1133,20 @@ container should match the type_ specified:: Any container can be passed as the *choices* value, so :class:`list` objects, :class:`set` objects, and custom containers are all supported. +This includes :class:`enum.Enum`, which could be used to restrain +argument's choices; if we reuse previous rock/paper/scissors game example, +this could be as follows:: + + >>> from enum import Enum + >>> class GameMove(Enum): + ... ROCK = 'rock' + ... PAPER = 'paper' + ... SCISSORS = 'scissors' + ... + >>> parser = argparse.ArgumentParser(prog='game.py') + >>> parser.add_argument('move', type=GameMove, choices=GameMove) + >>> parser.parse_args(['rock']) + Namespace(move=) required diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index 6c6ad01b842..25cb17811e7 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -1553,7 +1553,12 @@ and classes for traversing abstract syntax trees: .. warning:: The produced code string will not necessarily be equal to the original - code that generated the :class:`ast.AST` object. + code that generated the :class:`ast.AST` object (without any compiler + optimizations, such as constant tuples/frozensets). + + .. warning:: + Trying to unparse a highly complex expression would result with + :exc:`RecursionError`. .. versionadded:: 3.9 diff --git a/Doc/library/asyncio-dev.rst b/Doc/library/asyncio-dev.rst index ff51c4fa3b2..77f80671978 100644 --- a/Doc/library/asyncio-dev.rst +++ b/Doc/library/asyncio-dev.rst @@ -73,7 +73,7 @@ event loop, no other Tasks can run in the same thread. When a Task executes an ``await`` expression, the running Task gets suspended, and the event loop executes the next Task. -To schedule a callback from a different OS thread, the +To schedule a :term:`callback` from another OS thread, the :meth:`loop.call_soon_threadsafe` method should be used. Example:: loop.call_soon_threadsafe(callback, *args) diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index d60a6ce95cd..b1e73189a7a 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -191,8 +191,8 @@ Scheduling callbacks .. method:: loop.call_soon(callback, *args, context=None) - Schedule a *callback* to be called with *args* arguments at - the next iteration of the event loop. + Schedule the *callback* :term:`callback` to be called with + *args* arguments at the next iteration of the event loop. Callbacks are called in the order in which they are registered. Each callback will be called exactly once. diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst index 847363b134a..bac99b79504 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -614,8 +614,7 @@ Running in Threads allowing context variables from the event loop thread to be accessed in the separate thread. - Return an :class:`asyncio.Future` which represents the eventual result of - *func*. + Return a coroutine that can be awaited to get the eventual result of *func*. This coroutine function is primarily intended to be used for executing IO-bound functions/methods that would otherwise block the event loop if @@ -963,31 +962,6 @@ Task Object .. versionadded:: 3.8 - .. classmethod:: all_tasks(loop=None) - - Return a set of all tasks for an event loop. - - By default all tasks for the current event loop are returned. - If *loop* is ``None``, the :func:`get_event_loop` function - is used to get the current loop. - - .. deprecated-removed:: 3.7 3.9 - - Do not call this as a task method. Use the :func:`asyncio.all_tasks` - function instead. - - .. classmethod:: current_task(loop=None) - - Return the currently running task or ``None``. - - If *loop* is ``None``, the :func:`get_event_loop` function - is used to get the current loop. - - .. deprecated-removed:: 3.7 3.9 - - Do not call this as a task method. Use the - :func:`asyncio.current_task` function instead. - .. _asyncio_generator_based_coro: diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 549ac1bccad..f538da5e1c9 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -328,6 +328,19 @@ For example:: instead of replacing them. Also, the *iterable* is expected to be a sequence of elements, not a sequence of ``(key, value)`` pairs. +Counters support rich comparison operators for equality, subset, and +superset relationships: ``==``, ``!=``, ``<``, ``<=``, ``>``, ``>=``. +All of those tests treat missing elements as having zero counts so that +``Counter(a=1) == Counter(a=1, b=0)`` returns true. + +.. versionadded:: 3.10 + Rich comparison operations we were added + +.. versionchanged:: 3.10 + In equality tests, missing elements are treated as having zero counts. + Formerly, ``Counter(a=3)`` and ``Counter(a=3, b=0)`` were considered + distinct. + Common patterns for working with :class:`Counter` objects:: sum(c.values()) # total of all counts diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst index 61d39828e01..7a72c26d5ba 100644 --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -167,6 +167,9 @@ The :mod:`csv` module defines the following classes: All other optional or keyword arguments are passed to the underlying :class:`reader` instance. + .. versionchanged:: 3.6 + Returned rows are now of type :class:`OrderedDict`. + .. versionchanged:: 3.8 Returned rows are now of type :class:`dict`. diff --git a/Doc/library/datatypes.rst b/Doc/library/datatypes.rst index 675bbb6fafd..ff51b2779e5 100644 --- a/Doc/library/datatypes.rst +++ b/Doc/library/datatypes.rst @@ -33,3 +33,4 @@ The following modules are documented in this chapter: pprint.rst reprlib.rst enum.rst + graphlib.rst diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index 69a20fca178..38ad04177c5 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -2193,4 +2193,3 @@ are expected to be exact. .. [#] .. versionchanged:: 3.9 This approach now works for all exact results except for non-integer powers. - Also backported to 3.7 and 3.8. diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 90a2370c179..f4110c3585a 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -43,9 +43,8 @@ are always available. They are listed here in alphabetical order. .. function:: abs(x) Return the absolute value of a number. The argument may be an - integer or a floating point number. If the argument is a complex number, its - magnitude is returned. If *x* defines :meth:`__abs__`, - ``abs(x)`` returns ``x.__abs__()``. + integer, a floating point number, or an object implementing :meth:`__abs__`. + If the argument is a complex number, its magnitude is returned. .. function:: all(iterable) @@ -1721,50 +1720,90 @@ are always available. They are listed here in alphabetical order. dictionary are ignored. -.. function:: zip(*iterables) +.. function:: zip(*iterables, strict=False) - Make an iterator that aggregates elements from each of the iterables. + Iterate over several iterables in parallel, producing tuples with an item + from each one. - Returns an iterator of tuples, where the *i*-th tuple contains - the *i*-th element from each of the argument sequences or iterables. The - iterator stops when the shortest input iterable is exhausted. With a single - iterable argument, it returns an iterator of 1-tuples. With no arguments, - it returns an empty iterator. Equivalent to:: + Example:: - def zip(*iterables): - # zip('ABCD', 'xy') --> Ax By - sentinel = object() - iterators = [iter(it) for it in iterables] - while iterators: - result = [] - for it in iterators: - elem = next(it, sentinel) - if elem is sentinel: - return - result.append(elem) - yield tuple(result) + >>> for item in zip([1, 2, 3], ['sugar', 'spice', 'everything nice']): + ... print(item) + ... + (1, 'sugar') + (2, 'spice') + (3, 'everything nice') - The left-to-right evaluation order of the iterables is guaranteed. This - makes possible an idiom for clustering a data series into n-length groups - using ``zip(*[iter(s)]*n)``. This repeats the *same* iterator ``n`` times - so that each output tuple has the result of ``n`` calls to the iterator. - This has the effect of dividing the input into n-length chunks. + More formally: :func:`zip` returns an iterator of tuples, where the *i*-th + tuple contains the *i*-th element from each of the argument iterables. - :func:`zip` should only be used with unequal length inputs when you don't - care about trailing, unmatched values from the longer iterables. If those - values are important, use :func:`itertools.zip_longest` instead. + Another way to think of :func:`zip` is that it turns rows into columns, and + columns into rows. This is similar to `transposing a matrix + `_. - :func:`zip` in conjunction with the ``*`` operator can be used to unzip a - list:: + :func:`zip` is lazy: The elements won't be processed until the iterable is + iterated on, e.g. by a :keyword:`!for` loop or by wrapping in a + :class:`list`. - >>> x = [1, 2, 3] - >>> y = [4, 5, 6] - >>> zipped = zip(x, y) - >>> list(zipped) - [(1, 4), (2, 5), (3, 6)] - >>> x2, y2 = zip(*zip(x, y)) - >>> x == list(x2) and y == list(y2) - True + One thing to consider is that the iterables passed to :func:`zip` could have + different lengths; sometimes by design, and sometimes because of a bug in + the code that prepared these iterables. Python offers three different + approaches to dealing with this issue: + + * By default, :func:`zip` stops when the shortest iterable is exhausted. + It will ignore the remaining items in the longer iterables, cutting off + the result to the length of the shortest iterable:: + + >>> list(zip(range(3), ['fee', 'fi', 'fo', 'fum'])) + [(0, 'fee'), (1, 'fi'), (2, 'fo')] + + * :func:`zip` is often used in cases where the iterables are assumed to be + of equal length. In such cases, it's recommended to use the ``strict=True`` + option. Its output is the same as regular :func:`zip`:: + + >>> list(zip(('a', 'b', 'c'), (1, 2, 3), strict=True)) + [('a', 1), ('b', 2), ('c', 3)] + + Unlike the default behavior, it checks that the lengths of iterables are + identical, raising a :exc:`ValueError` if they aren't: + + >>> list(zip(range(3), ['fee', 'fi', 'fo', 'fum'], strict=True)) + Traceback (most recent call last): + ... + ValueError: zip() argument 2 is longer than argument 1 + + Without the ``strict=True`` argument, any bug that results in iterables of + different lengths will be silenced, possibly manifesting as a hard-to-find + bug in another part of the program. + + * Shorter iterables can be padded with a constant value to make all the + iterables have the same length. This is done by + :func:`itertools.zip_longest`. + + Edge cases: With a single iterable argument, :func:`zip` returns an + iterator of 1-tuples. With no arguments, it returns an empty iterator. + + Tips and tricks: + + * The left-to-right evaluation order of the iterables is guaranteed. This + makes possible an idiom for clustering a data series into n-length groups + using ``zip(*[iter(s)]*n, strict=True)``. This repeats the *same* iterator + ``n`` times so that each output tuple has the result of ``n`` calls to the + iterator. This has the effect of dividing the input into n-length chunks. + + * :func:`zip` in conjunction with the ``*`` operator can be used to unzip a + list:: + + >>> x = [1, 2, 3] + >>> y = [4, 5, 6] + >>> list(zip(x, y)) + [(1, 4), (2, 5), (3, 6)] + >>> x2, y2 = zip(*zip(x, y)) + >>> x == list(x2) and y == list(y2) + True + + .. versionchanged:: 3.10 + Added the ``strict`` argument. .. function:: __import__(name, globals=None, locals=None, fromlist=(), level=0) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index a44eb85b27d..14aa184e2cd 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -543,184 +543,6 @@ The :mod:`functools` module defines the following functions: .. versionadded:: 3.8 -.. class:: TopologicalSorter(graph=None) - - Provides functionality to topologically sort a graph of hashable nodes. - - A topological order is a linear ordering of the vertices in a graph such that - for every directed edge u -> v from vertex u to vertex v, vertex u comes - before vertex v in the ordering. For instance, the vertices of the graph may - represent tasks to be performed, and the edges may represent constraints that - one task must be performed before another; in this example, a topological - ordering is just a valid sequence for the tasks. A complete topological - ordering is possible if and only if the graph has no directed cycles, that - is, if it is a directed acyclic graph. - - If the optional *graph* argument is provided it must be a dictionary - representing a directed acyclic graph where the keys are nodes and the values - are iterables of all predecessors of that node in the graph (the nodes that - have edges that point to the value in the key). Additional nodes can be added - to the graph using the :meth:`~TopologicalSorter.add` method. - - In the general case, the steps required to perform the sorting of a given - graph are as follows: - - * Create an instance of the :class:`TopologicalSorter` with an optional - initial graph. - * Add additional nodes to the graph. - * Call :meth:`~TopologicalSorter.prepare` on the graph. - * While :meth:`~TopologicalSorter.is_active` is ``True``, iterate over - the nodes returned by :meth:`~TopologicalSorter.get_ready` and - process them. Call :meth:`~TopologicalSorter.done` on each node as it - finishes processing. - - In case just an immediate sorting of the nodes in the graph is required and - no parallelism is involved, the convenience method - :meth:`TopologicalSorter.static_order` can be used directly: - - .. doctest:: - - >>> graph = {"D": {"B", "C"}, "C": {"A"}, "B": {"A"}} - >>> ts = TopologicalSorter(graph) - >>> tuple(ts.static_order()) - ('A', 'C', 'B', 'D') - - The class is designed to easily support parallel processing of the nodes as - they become ready. For instance:: - - topological_sorter = TopologicalSorter() - - # Add nodes to 'topological_sorter'... - - topological_sorter.prepare() - while topological_sorter.is_active(): - for node in topological_sorter.get_ready(): - # Worker threads or processes take nodes to work on off the - # 'task_queue' queue. - task_queue.put(node) - - # When the work for a node is done, workers put the node in - # 'finalized_tasks_queue' so we can get more nodes to work on. - # The definition of 'is_active()' guarantees that, at this point, at - # least one node has been placed on 'task_queue' that hasn't yet - # been passed to 'done()', so this blocking 'get()' must (eventually) - # succeed. After calling 'done()', we loop back to call 'get_ready()' - # again, so put newly freed nodes on 'task_queue' as soon as - # logically possible. - node = finalized_tasks_queue.get() - topological_sorter.done(node) - - .. method:: add(node, *predecessors) - - Add a new node and its predecessors to the graph. Both the *node* and all - elements in *predecessors* must be hashable. - - If called multiple times with the same node argument, the set of - dependencies will be the union of all dependencies passed in. - - It is possible to add a node with no dependencies (*predecessors* is not - provided) or to provide a dependency twice. If a node that has not been - provided before is included among *predecessors* it will be automatically - added to the graph with no predecessors of its own. - - Raises :exc:`ValueError` if called after :meth:`~TopologicalSorter.prepare`. - - .. method:: prepare() - - Mark the graph as finished and check for cycles in the graph. If any cycle - is detected, :exc:`CycleError` will be raised, but - :meth:`~TopologicalSorter.get_ready` can still be used to obtain as many - nodes as possible until cycles block more progress. After a call to this - function, the graph cannot be modified, and therefore no more nodes can be - added using :meth:`~TopologicalSorter.add`. - - .. method:: is_active() - - Returns ``True`` if more progress can be made and ``False`` otherwise. - Progress can be made if cycles do not block the resolution and either - there are still nodes ready that haven't yet been returned by - :meth:`TopologicalSorter.get_ready` or the number of nodes marked - :meth:`TopologicalSorter.done` is less than the number that have been - returned by :meth:`TopologicalSorter.get_ready`. - - The :meth:`~TopologicalSorter.__bool__` method of this class defers to - this function, so instead of:: - - if ts.is_active(): - ... - - if possible to simply do:: - - if ts: - ... - - Raises :exc:`ValueError` if called without calling - :meth:`~TopologicalSorter.prepare` previously. - - .. method:: done(*nodes) - - Marks a set of nodes returned by :meth:`TopologicalSorter.get_ready` as - processed, unblocking any successor of each node in *nodes* for being - returned in the future by a call to :meth:`TopologicalSorter.get_ready`. - - Raises :exc:`ValueError` if any node in *nodes* has already been marked as - processed by a previous call to this method or if a node was not added to - the graph by using :meth:`TopologicalSorter.add`, if called without - calling :meth:`~TopologicalSorter.prepare` or if node has not yet been - returned by :meth:`~TopologicalSorter.get_ready`. - - .. method:: get_ready() - - Returns a ``tuple`` with all the nodes that are ready. Initially it - returns all nodes with no predecessors, and once those are marked as - processed by calling :meth:`TopologicalSorter.done`, further calls will - return all new nodes that have all their predecessors already processed. - Once no more progress can be made, empty tuples are returned. - - Raises :exc:`ValueError` if called without calling - :meth:`~TopologicalSorter.prepare` previously. - - .. method:: static_order() - - Returns an iterable of nodes in a topological order. Using this method - does not require to call :meth:`TopologicalSorter.prepare` or - :meth:`TopologicalSorter.done`. This method is equivalent to:: - - def static_order(self): - self.prepare() - while self.is_active(): - node_group = self.get_ready() - yield from node_group - self.done(*node_group) - - The particular order that is returned may depend on the specific order in - which the items were inserted in the graph. For example: - - .. doctest:: - - >>> ts = TopologicalSorter() - >>> ts.add(3, 2, 1) - >>> ts.add(1, 0) - >>> print([*ts.static_order()]) - [2, 0, 1, 3] - - >>> ts2 = TopologicalSorter() - >>> ts2.add(1, 0) - >>> ts2.add(3, 2, 1) - >>> print([*ts2.static_order()]) - [0, 2, 1, 3] - - This is due to the fact that "0" and "2" are in the same level in the - graph (they would have been returned in the same call to - :meth:`~TopologicalSorter.get_ready`) and the order between them is - determined by the order of insertion. - - - If any cycle is detected, :exc:`CycleError` will be raised. - - .. versionadded:: 3.9 - - .. function:: update_wrapper(wrapper, wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES) Update a *wrapper* function to look like the *wrapped* function. The optional @@ -829,20 +651,4 @@ callable, weak referencable, and can have attributes. There are some important differences. For instance, the :attr:`~definition.__name__` and :attr:`__doc__` attributes are not created automatically. Also, :class:`partial` objects defined in classes behave like static methods and do not transform into bound methods -during instance attribute look-up. - - -Exceptions ----------- -The :mod:`functools` module defines the following exception classes: - -.. exception:: CycleError - - Subclass of :exc:`ValueError` raised by :meth:`TopologicalSorter.prepare` if cycles exist - in the working graph. If multiple cycles exist, only one undefined choice among them will - be reported and included in the exception. - - The detected cycle can be accessed via the second element in the :attr:`~CycleError.args` - attribute of the exception instance and consists in a list of nodes, such that each node is, - in the graph, an immediate predecessor of the next node in the list. In the reported list, - the first and the last node will be the same, to make it clear that it is cyclic. +during instance attribute look-up. \ No newline at end of file diff --git a/Doc/library/glob.rst b/Doc/library/glob.rst index 92a8c4d1eb8..280e9f08266 100644 --- a/Doc/library/glob.rst +++ b/Doc/library/glob.rst @@ -36,7 +36,7 @@ For example, ``'[?]'`` matches the character ``'?'``. The :mod:`pathlib` module offers high-level path objects. -.. function:: glob(pathname, *, recursive=False) +.. function:: glob(pathname, *, root_dir=None, dir_fd=None, recursive=False) Return a possibly-empty list of path names that match *pathname*, which must be a string containing a path specification. *pathname* can be either absolute @@ -45,6 +45,15 @@ For example, ``'[?]'`` matches the character ``'?'``. symlinks are included in the results (as in the shell). Whether or not the results are sorted depends on the file system. + If *root_dir* is not ``None``, it should be a :term:`path-like object` + specifying the root directory for searching. It has the same effect on + :func:`glob` as changing the current directory before calling it. If + *pathname* is relative, the result will contain paths relative to + *root_dir*. + + This function can support :ref:`paths relative to directory descriptors + ` with the *dir_fd* parameter. + .. index:: single: **; in glob-style wildcards @@ -62,8 +71,11 @@ For example, ``'[?]'`` matches the character ``'?'``. .. versionchanged:: 3.5 Support for recursive globs using "``**``". + .. versionchanged:: 3.10 + Added the *root_dir* and *dir_fd* parameters. -.. function:: iglob(pathname, *, recursive=False) + +.. function:: iglob(pathname, *, root_dir=None, dir_fd=None, recursive=False) Return an :term:`iterator` which yields the same values as :func:`glob` without actually storing them all simultaneously. diff --git a/Doc/library/graphlib.rst b/Doc/library/graphlib.rst new file mode 100644 index 00000000000..820615e7230 --- /dev/null +++ b/Doc/library/graphlib.rst @@ -0,0 +1,209 @@ +:mod:`graphlib` --- Functionality to operate with graph-like structures +========================================================================= + +.. module:: graphlib + :synopsis: Functionality to operate with graph-like structures + + +**Source code:** :source:`Lib/graphlib.py` + +.. testsetup:: default + + import graphlib + from graphlib import * + +-------------- + + +.. class:: TopologicalSorter(graph=None) + + Provides functionality to topologically sort a graph of hashable nodes. + + A topological order is a linear ordering of the vertices in a graph such that + for every directed edge u -> v from vertex u to vertex v, vertex u comes + before vertex v in the ordering. For instance, the vertices of the graph may + represent tasks to be performed, and the edges may represent constraints that + one task must be performed before another; in this example, a topological + ordering is just a valid sequence for the tasks. A complete topological + ordering is possible if and only if the graph has no directed cycles, that + is, if it is a directed acyclic graph. + + If the optional *graph* argument is provided it must be a dictionary + representing a directed acyclic graph where the keys are nodes and the values + are iterables of all predecessors of that node in the graph (the nodes that + have edges that point to the value in the key). Additional nodes can be added + to the graph using the :meth:`~TopologicalSorter.add` method. + + In the general case, the steps required to perform the sorting of a given + graph are as follows: + + * Create an instance of the :class:`TopologicalSorter` with an optional + initial graph. + * Add additional nodes to the graph. + * Call :meth:`~TopologicalSorter.prepare` on the graph. + * While :meth:`~TopologicalSorter.is_active` is ``True``, iterate over + the nodes returned by :meth:`~TopologicalSorter.get_ready` and + process them. Call :meth:`~TopologicalSorter.done` on each node as it + finishes processing. + + In case just an immediate sorting of the nodes in the graph is required and + no parallelism is involved, the convenience method + :meth:`TopologicalSorter.static_order` can be used directly: + + .. doctest:: + + >>> graph = {"D": {"B", "C"}, "C": {"A"}, "B": {"A"}} + >>> ts = TopologicalSorter(graph) + >>> tuple(ts.static_order()) + ('A', 'C', 'B', 'D') + + The class is designed to easily support parallel processing of the nodes as + they become ready. For instance:: + + topological_sorter = TopologicalSorter() + + # Add nodes to 'topological_sorter'... + + topological_sorter.prepare() + while topological_sorter.is_active(): + for node in topological_sorter.get_ready(): + # Worker threads or processes take nodes to work on off the + # 'task_queue' queue. + task_queue.put(node) + + # When the work for a node is done, workers put the node in + # 'finalized_tasks_queue' so we can get more nodes to work on. + # The definition of 'is_active()' guarantees that, at this point, at + # least one node has been placed on 'task_queue' that hasn't yet + # been passed to 'done()', so this blocking 'get()' must (eventually) + # succeed. After calling 'done()', we loop back to call 'get_ready()' + # again, so put newly freed nodes on 'task_queue' as soon as + # logically possible. + node = finalized_tasks_queue.get() + topological_sorter.done(node) + + .. method:: add(node, *predecessors) + + Add a new node and its predecessors to the graph. Both the *node* and all + elements in *predecessors* must be hashable. + + If called multiple times with the same node argument, the set of + dependencies will be the union of all dependencies passed in. + + It is possible to add a node with no dependencies (*predecessors* is not + provided) or to provide a dependency twice. If a node that has not been + provided before is included among *predecessors* it will be automatically + added to the graph with no predecessors of its own. + + Raises :exc:`ValueError` if called after :meth:`~TopologicalSorter.prepare`. + + .. method:: prepare() + + Mark the graph as finished and check for cycles in the graph. If any cycle + is detected, :exc:`CycleError` will be raised, but + :meth:`~TopologicalSorter.get_ready` can still be used to obtain as many + nodes as possible until cycles block more progress. After a call to this + function, the graph cannot be modified, and therefore no more nodes can be + added using :meth:`~TopologicalSorter.add`. + + .. method:: is_active() + + Returns ``True`` if more progress can be made and ``False`` otherwise. + Progress can be made if cycles do not block the resolution and either + there are still nodes ready that haven't yet been returned by + :meth:`TopologicalSorter.get_ready` or the number of nodes marked + :meth:`TopologicalSorter.done` is less than the number that have been + returned by :meth:`TopologicalSorter.get_ready`. + + The :meth:`~TopologicalSorter.__bool__` method of this class defers to + this function, so instead of:: + + if ts.is_active(): + ... + + if possible to simply do:: + + if ts: + ... + + Raises :exc:`ValueError` if called without calling + :meth:`~TopologicalSorter.prepare` previously. + + .. method:: done(*nodes) + + Marks a set of nodes returned by :meth:`TopologicalSorter.get_ready` as + processed, unblocking any successor of each node in *nodes* for being + returned in the future by a call to :meth:`TopologicalSorter.get_ready`. + + Raises :exc:`ValueError` if any node in *nodes* has already been marked as + processed by a previous call to this method or if a node was not added to + the graph by using :meth:`TopologicalSorter.add`, if called without + calling :meth:`~TopologicalSorter.prepare` or if node has not yet been + returned by :meth:`~TopologicalSorter.get_ready`. + + .. method:: get_ready() + + Returns a ``tuple`` with all the nodes that are ready. Initially it + returns all nodes with no predecessors, and once those are marked as + processed by calling :meth:`TopologicalSorter.done`, further calls will + return all new nodes that have all their predecessors already processed. + Once no more progress can be made, empty tuples are returned. + + Raises :exc:`ValueError` if called without calling + :meth:`~TopologicalSorter.prepare` previously. + + .. method:: static_order() + + Returns an iterable of nodes in a topological order. Using this method + does not require to call :meth:`TopologicalSorter.prepare` or + :meth:`TopologicalSorter.done`. This method is equivalent to:: + + def static_order(self): + self.prepare() + while self.is_active(): + node_group = self.get_ready() + yield from node_group + self.done(*node_group) + + The particular order that is returned may depend on the specific order in + which the items were inserted in the graph. For example: + + .. doctest:: + + >>> ts = TopologicalSorter() + >>> ts.add(3, 2, 1) + >>> ts.add(1, 0) + >>> print([*ts.static_order()]) + [2, 0, 1, 3] + + >>> ts2 = TopologicalSorter() + >>> ts2.add(1, 0) + >>> ts2.add(3, 2, 1) + >>> print([*ts2.static_order()]) + [0, 2, 1, 3] + + This is due to the fact that "0" and "2" are in the same level in the + graph (they would have been returned in the same call to + :meth:`~TopologicalSorter.get_ready`) and the order between them is + determined by the order of insertion. + + + If any cycle is detected, :exc:`CycleError` will be raised. + + .. versionadded:: 3.9 + + +Exceptions +---------- +The :mod:`graphlib` module defines the following exception classes: + +.. exception:: CycleError + + Subclass of :exc:`ValueError` raised by :meth:`TopologicalSorter.prepare` if cycles exist + in the working graph. If multiple cycles exist, only one undefined choice among them will + be reported and included in the exception. + + The detected cycle can be accessed via the second element in the :attr:`~CycleError.args` + attribute of the exception instance and consists in a list of nodes, such that each node is, + in the graph, an immediate predecessor of the next node in the list. In the reported list, + the first and the last node will be the same, to make it clear that it is cyclic. \ No newline at end of file diff --git a/Doc/library/hmac.rst b/Doc/library/hmac.rst index 5ad348490ea..6f1b59b57ce 100644 --- a/Doc/library/hmac.rst +++ b/Doc/library/hmac.rst @@ -138,6 +138,11 @@ This module also provides the following helper function: .. versionadded:: 3.3 + .. versionchanged:: 3.10 + + The function uses OpenSSL's ``CRYPTO_memcmp()`` internally when + available. + .. seealso:: diff --git a/Doc/library/imp.rst b/Doc/library/imp.rst index f5ad8c72296..121a730e0c9 100644 --- a/Doc/library/imp.rst +++ b/Doc/library/imp.rst @@ -8,7 +8,7 @@ **Source code:** :source:`Lib/imp.py` .. deprecated:: 3.4 - The :mod:`imp` package is pending deprecation in favor of :mod:`importlib`. + The :mod:`imp` module is deprecated in favor of :mod:`importlib`. .. index:: statement: import diff --git a/Doc/library/importlib.metadata.rst b/Doc/library/importlib.metadata.rst index 15e58b860d9..21da143f3be 100644 --- a/Doc/library/importlib.metadata.rst +++ b/Doc/library/importlib.metadata.rst @@ -77,7 +77,9 @@ Entry points The ``entry_points()`` function returns a dictionary of all entry points, keyed by group. Entry points are represented by ``EntryPoint`` instances; each ``EntryPoint`` has a ``.name``, ``.group``, and ``.value`` attributes and -a ``.load()`` method to resolve the value. +a ``.load()`` method to resolve the value. There are also ``.module``, +``.attr``, and ``.extras`` attributes for getting the components of the +``.value`` attribute:: >>> eps = entry_points() # doctest: +SKIP >>> list(eps) # doctest: +SKIP @@ -86,6 +88,12 @@ a ``.load()`` method to resolve the value. >>> wheel = [ep for ep in scripts if ep.name == 'wheel'][0] # doctest: +SKIP >>> wheel # doctest: +SKIP EntryPoint(name='wheel', value='wheel.cli:main', group='console_scripts') + >>> wheel.module # doctest: +SKIP + 'wheel.cli' + >>> wheel.attr # doctest: +SKIP + 'main' + >>> wheel.extras # doctest: +SKIP + [] >>> main = wheel.load() # doctest: +SKIP >>> main # doctest: +SKIP @@ -94,7 +102,7 @@ The ``group`` and ``name`` are arbitrary values defined by the package author and usually a client will wish to resolve all entry points for a particular group. Read `the setuptools docs `_ -for more information on entrypoints, their definition, and usage. +for more information on entry points, their definition, and usage. .. _metadata: @@ -235,7 +243,7 @@ method:: """ The ``DistributionFinder.Context`` object provides ``.path`` and ``.name`` -properties indicating the path to search and names to match and may +properties indicating the path to search and name to match and may supply other relevant context. What this means in practice is that to support finding distribution package diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 3e5a6738981..107bc515a67 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -199,9 +199,9 @@ loops that truncate the stream. Return *r* length subsequences of elements from the input *iterable*. - Combinations are emitted in lexicographic sort order. So, if the - input *iterable* is sorted, the combination tuples will be produced - in sorted order. + The combination tuples are emitted in lexicographic ordering according to + the order of the input *iterable*. So, if the input *iterable* is sorted, + the combination tuples will be produced in sorted order. Elements are treated as unique based on their position, not on their value. So if the input elements are unique, there will be no repeat @@ -248,9 +248,9 @@ loops that truncate the stream. Return *r* length subsequences of elements from the input *iterable* allowing individual elements to be repeated more than once. - Combinations are emitted in lexicographic sort order. So, if the - input *iterable* is sorted, the combination tuples will be produced - in sorted order. + The combination tuples are emitted in lexicographic ordering according to + the order of the input *iterable*. So, if the input *iterable* is sorted, + the combination tuples will be produced in sorted order. Elements are treated as unique based on their position, not on their value. So if the input elements are unique, the generated combinations @@ -484,9 +484,9 @@ loops that truncate the stream. of the *iterable* and all possible full-length permutations are generated. - Permutations are emitted in lexicographic sort order. So, if the - input *iterable* is sorted, the permutation tuples will be produced - in sorted order. + The permutation tuples are emitted in lexicographic ordering according to + the order of the input *iterable*. So, if the input *iterable* is sorted, + the combination tuples will be produced in sorted order. Elements are treated as unique based on their position, not on their value. So if the input elements are unique, there will be no repeat @@ -563,6 +563,9 @@ loops that truncate the stream. for prod in result: yield tuple(prod) + Before :func:`product` runs, it completely consumes the input iterables, + keeping pools of values in memory to generate the products. Accordingly, + it only useful with finite inputs. .. function:: repeat(object[, times]) diff --git a/Doc/library/keyword.rst b/Doc/library/keyword.rst index acec45cdcd5..5cae79f5dc9 100644 --- a/Doc/library/keyword.rst +++ b/Doc/library/keyword.rst @@ -22,3 +22,19 @@ This module allows a Python program to determine if a string is a Sequence containing all the :ref:`keywords ` defined for the interpreter. If any keywords are defined to only be active when particular :mod:`__future__` statements are in effect, these will be included as well. + + +.. function:: issoftkeyword(s) + + Return ``True`` if *s* is a Python soft :ref:`keyword `. + + .. versionadded:: 3.9 + + +.. data:: softkwlist + + Sequence containing all the soft :ref:`keywords ` defined for the + interpreter. If any soft keywords are defined to only be active when particular + :mod:`__future__` statements are in effect, these will be included as well. + + .. versionadded:: 3.9 diff --git a/Doc/library/logging.rst b/Doc/library/logging.rst index 7267f812cc1..3ff67f76cc3 100644 --- a/Doc/library/logging.rst +++ b/Doc/library/logging.rst @@ -529,7 +529,8 @@ The useful mapping keys in a :class:`LogRecord` are given in the section on :ref:`logrecord-attributes`. -.. class:: Formatter(fmt=None, datefmt=None, style='%', validate=True) +.. class:: Formatter(fmt=None, datefmt=None, style='%', validate=True, *, + defaults=None) Returns a new instance of the :class:`Formatter` class. The instance is initialized with a format string for the message as a whole, as well as a @@ -545,6 +546,10 @@ The useful mapping keys in a :class:`LogRecord` are given in the section on :ref:`formatting-styles` for more information on using {- and $-formatting for log messages. + The *defaults* parameter can be a dictionary with default values to use in + custom fields. For example: + ``logging.Formatter('%(ip)s %(message)s', defaults={"ip": None})`` + .. versionchanged:: 3.2 The *style* parameter was added. @@ -553,6 +558,9 @@ The useful mapping keys in a :class:`LogRecord` are given in the section on will raise a ``ValueError``. For example: ``logging.Formatter('%(asctime)s - %(message)s', style='{')``. + .. versionchanged:: 3.10 + The *defaults* parameter was added. + .. method:: format(record) The record's attribute dictionary is used as the operand to a string diff --git a/Doc/library/mmap.rst b/Doc/library/mmap.rst index 1f3fbc340fc..698c1765378 100644 --- a/Doc/library/mmap.rst +++ b/Doc/library/mmap.rst @@ -81,7 +81,9 @@ To map anonymous memory, -1 should be passed as the fileno along with the length private copy-on-write mapping, so changes to the contents of the mmap object will be private to this process, and :const:`MAP_SHARED` creates a mapping that's shared with all other processes mapping the same areas of - the file. The default value is :const:`MAP_SHARED`. + the file. The default value is :const:`MAP_SHARED`. Some systems have + additional possible flags with the full list specified in + :ref:`MAP_* constants `. *prot*, if specified, gives the desired memory protection; the two most useful values are :const:`PROT_READ` and :const:`PROT_WRITE`, to specify @@ -342,3 +344,21 @@ MADV_* Constants Availability: Systems with the madvise() system call. .. versionadded:: 3.8 + +.. _map-constants: + +MAP_* Constants ++++++++++++++++ + +.. data:: MAP_SHARED + MAP_PRIVATE + MAP_DENYWRITE + MAP_EXECUTABLE + MAP_ANON + MAP_ANONYMOUS + MAP_POPULATE + + These are the various flags that can be passed to :meth:`mmap.mmap`. Note that some options might not be present on some systems. + + .. versionchanged:: 3.10 + Added MAP_POPULATE constant. diff --git a/Doc/library/operator.rst b/Doc/library/operator.rst index fa02bde8465..36c53556c26 100644 --- a/Doc/library/operator.rst +++ b/Doc/library/operator.rst @@ -112,6 +112,10 @@ The mathematical and bitwise operations are the most numerous: Return *a* converted to an integer. Equivalent to ``a.__index__()``. + .. versionchanged:: 3.10 + The result always has exact type :class:`int`. Previously, the result + could have been an instance of a subclass of ``int``. + .. function:: inv(obj) invert(obj) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 6d5fb314a8e..275b2d390e7 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1211,6 +1211,7 @@ or `the MSDN `_ on Windo - :data:`RWF_DSYNC` - :data:`RWF_SYNC` + - :data:`RWF_APPEND` Return the total number of bytes actually written. @@ -1228,8 +1229,8 @@ or `the MSDN `_ on Windo .. data:: RWF_DSYNC - Provide a per-write equivalent of the :data:`O_DSYNC` ``open(2)`` flag. This - flag effect applies only to the data range written by the system call. + Provide a per-write equivalent of the :data:`O_DSYNC` :func:`os.open` flag. + This flag effect applies only to the data range written by the system call. .. availability:: Linux 4.7 and newer. @@ -1238,14 +1239,28 @@ or `the MSDN `_ on Windo .. data:: RWF_SYNC - Provide a per-write equivalent of the :data:`O_SYNC` ``open(2)`` flag. This - flag effect applies only to the data range written by the system call. + Provide a per-write equivalent of the :data:`O_SYNC` :func:`os.open` flag. + This flag effect applies only to the data range written by the system call. .. availability:: Linux 4.7 and newer. .. versionadded:: 3.7 +.. data:: RWF_APPEND + + Provide a per-write equivalent of the :data:`O_APPEND` :func:`os.open` + flag. This flag is meaningful only for :func:`os.pwritev`, and its + effect applies only to the data range written by the system call. The + *offset* argument does not affect the write operation; the data is always + appended to the end of the file. However, if the *offset* argument is + ``-1``, the current file *offset* is updated. + + .. availability:: Linux 4.16 and newer. + + .. versionadded:: 3.10 + + .. function:: read(fd, n) Read at most *n* bytes from file descriptor *fd*. diff --git a/Doc/library/othergui.rst b/Doc/library/othergui.rst index 4548459f8e2..48c1f275411 100644 --- a/Doc/library/othergui.rst +++ b/Doc/library/othergui.rst @@ -30,10 +30,11 @@ available for Python: for generating bindings for C++ libraries as Python classes, and is specifically designed for Python. - `PySide `_ - PySide is a newer binding to the Qt toolkit, provided by Nokia. - Compared to PyQt, its licensing scheme is friendlier to non-open source - applications. + `PySide2 `_ + Also known as the Qt for Python project, PySide2 is a newer binding to the + Qt toolkit. It is provided by The Qt Company and aims to provide a + complete port of PySide to Qt 5. Compared to PyQt, its licensing scheme is + friendlier to non-open source applications. `wxPython `_ wxPython is a cross-platform GUI toolkit for Python that is built around @@ -47,7 +48,7 @@ available for Python: an XML-based resource format and more, including an ever growing library of user-contributed modules. -PyGTK, PyQt, and wxPython, all have a modern look and feel and more +PyGTK, PyQt, PySide2, and wxPython, all have a modern look and feel and more widgets than Tkinter. In addition, there are many other GUI toolkits for Python, both cross-platform, and platform-specific. See the `GUI Programming `_ page in the Python Wiki for a diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst index 606e8e53457..ed1e9712c0e 100644 --- a/Doc/library/pdb.rst +++ b/Doc/library/pdb.rst @@ -538,6 +538,7 @@ by the local file. executed in the current environment). .. pdbcommand:: retval + Print the return value for the last return of a function. .. rubric:: Footnotes diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst index c7c63e6f808..1b094aeb9ca 100644 --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -570,12 +570,14 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules. available), or "xztar" (if the :mod:`lzma` module is available). *root_dir* is a directory that will be the root directory of the - archive; for example, we typically chdir into *root_dir* before creating the - archive. + archive, all paths in the archive will be relative to it; for example, + we typically chdir into *root_dir* before creating the archive. *base_dir* is the directory where we start archiving from; i.e. *base_dir* will be the common prefix of all files and - directories in the archive. + directories in the archive. *base_dir* must be given relative + to *root_dir*. See :ref:`shutil-archiving-example-with-basedir` for how to + use *base_dir* and *root_dir* together. *root_dir* and *base_dir* both default to the current directory. @@ -727,6 +729,48 @@ The resulting archive contains: -rw-r--r-- tarek/staff 37192 2010-02-06 18:23:10 ./known_hosts +.. _shutil-archiving-example-with-basedir: + +Archiving example with *base_dir* +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In this example, similar to the `one above `_, +we show how to use :func:`make_archive`, but this time with the usage of +*base_dir*. We now have the following directory structure: + +.. code-block:: shell-session + + $ tree tmp + tmp + └── root + └── structure + ├── content + └── please_add.txt + └── do_not_add.txt + +In the final archive, :file:`please_add.txt` should be included, but +:file:`do_not_add.txt` should not. Therefore we use the following:: + + >>> from shutil import make_archive + >>> import os + >>> archive_name = os.path.expanduser(os.path.join('~', 'myarchive')) + >>> make_archive( + ... archive_name, + ... 'tar', + ... root_dir='tmp/root', + ... base_dir='structure/content', + ... ) + '/Users/tarek/my_archive.tar' + +Listing the files in the resulting archive gives us: + +.. code-block:: shell-session + + $ python -m tarfile -l /Users/tarek/myarchive.tar + structure/content/ + structure/content/please_add.txt + + Querying the size of the output terminal ---------------------------------------- diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 6a9fdcb38d2..7028d240c59 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -478,6 +478,27 @@ class`. In addition, it provides a few more methods: .. versionadded:: 3.1 +.. method:: int.bit_count() + + Return the number of ones in the binary representation of the absolute + value of the integer. This is also known as the population count. + Example:: + + >>> n = 19 + >>> bin(n) + '0b10011' + >>> n.bit_count() + 3 + >>> (-n).bit_count() + 3 + + Equivalent to:: + + def bit_count(self): + return bin(self).count("1") + + .. versionadded:: 3.10 + .. method:: int.to_bytes(length, byteorder, \*, signed=False) Return an array of bytes representing an integer. @@ -4601,6 +4622,12 @@ support membership tests: .. versionchanged:: 3.8 Dictionary views are now reversible. +.. describe:: dictview.mapping + + Return a :class:`types.MappingProxyType` that wraps the original + dictionary to which the view refers. + + .. versionadded:: 3.10 Keys views are set-like since their entries are unique and hashable. If all values are hashable, so that ``(key, value)`` pairs are unique and hashable, @@ -4640,6 +4667,12 @@ An example of dictionary view usage:: >>> keys ^ {'sausage', 'juice'} {'juice', 'sausage', 'bacon', 'spam'} + >>> # get back a read-only proxy for the original dictionary + >>> values.mapping + mappingproxy({'eggs': 2, 'sausage': 1, 'bacon': 1, 'spam': 500}) + >>> values.mapping['spam'] + 500 + .. _typecontextmanager: diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst index 5988bd35e72..e37cc980e97 100644 --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -738,10 +738,11 @@ Instances of the :class:`Popen` class have the following methods: .. method:: Popen.communicate(input=None, timeout=None) Interact with process: Send data to stdin. Read data from stdout and stderr, - until end-of-file is reached. Wait for process to terminate. The optional - *input* argument should be data to be sent to the child process, or - ``None``, if no data should be sent to the child. If streams were opened in - text mode, *input* must be a string. Otherwise, it must be bytes. + until end-of-file is reached. Wait for process to terminate and set the + :attr:`~Popen.returncode` attribute. The optional *input* argument should be + data to be sent to the child process, or ``None``, if no data should be sent + to the child. If streams were opened in text mode, *input* must be a string. + Otherwise, it must be bytes. :meth:`communicate` returns a tuple ``(stdout_data, stderr_data)``. The data will be strings if streams were opened in text mode; otherwise, diff --git a/Doc/library/symbol.rst b/Doc/library/symbol.rst index 44996936e2d..d56600af29d 100644 --- a/Doc/library/symbol.rst +++ b/Doc/library/symbol.rst @@ -17,6 +17,11 @@ the definitions of the names in the context of the language grammar. The specific numeric values which the names map to may change between Python versions. +.. warning:: + + The symbol module is deprecated and will be removed in future versions of + Python. + This module also provides one additional data object: diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 98f63fb83f8..d201d7061f9 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -66,6 +66,8 @@ always available. To loop over the standard input, or the list of files given on the command line, see the :mod:`fileinput` module. + See also :data:`sys.orig_argv`. + .. note:: On Unix, command line arguments are passed by bytes from OS. Python decodes them with filesystem encoding and "surrogateescape" error handler. @@ -1037,6 +1039,16 @@ always available. deleting essential items from the dictionary may cause Python to fail. +.. data:: orig_argv + + The list of the original command line arguments passed to the Python + executable. + + See also :data:`sys.argv`. + + .. versionadded:: 3.10 + + .. data:: path .. index:: triple: module; search; path @@ -1141,8 +1153,7 @@ always available. .. data:: platlibdir Name of the platform-specific library directory. It is used to build the - path of platform-specific dynamic libraries and the path of the standard - library. + path of standard library and the paths of installed extension modules. It is equal to ``"lib"`` on most platforms. On Fedora and SuSE, it is equal to ``"lib64"`` on 64-bit platforms which gives the following ``sys.path`` @@ -1153,8 +1164,10 @@ always available. * ``/usr/lib64/pythonX.Y/lib-dynload/``: C extension modules of the standard library (like the :mod:`errno` module, the exact filename is platform specific) - * ``/usr/lib/pythonX.Y/site-packages`` (always use ``lib``, not + * ``/usr/lib/pythonX.Y/site-packages/`` (always use ``lib``, not :data:`sys.platlibdir`): Third-party modules + * ``/usr/lib64/pythonX.Y/site-packages/``: + C extension modules of third-party packages .. versionadded:: 3.9 diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst index 459e4ad991d..c204263d3a0 100644 --- a/Doc/library/tarfile.rst +++ b/Doc/library/tarfile.rst @@ -787,7 +787,7 @@ How to read a gzip compressed tar archive and display some member information:: import tarfile tar = tarfile.open("sample.tar.gz", "r:gz") for tarinfo in tar: - print(tarinfo.name, "is", tarinfo.size, "bytes in size and is", end="") + print(tarinfo.name, "is", tarinfo.size, "bytes in size and is ", end="") if tarinfo.isreg(): print("a regular file.") elif tarinfo.isdir(): diff --git a/Doc/library/test.rst b/Doc/library/test.rst index f7e6eba0181..cd05ef07b4a 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -247,46 +247,6 @@ The :mod:`test.support` module defines the following constants: Path for shell if not on Windows; otherwise ``None``. -.. data:: FS_NONASCII - - A non-ASCII character encodable by :func:`os.fsencode`. - - -.. data:: TESTFN - - Set to a name that is safe to use as the name of a temporary file. Any - temporary file that is created should be closed and unlinked (removed). - - -.. data:: TESTFN_UNICODE - - Set to a non-ASCII name for a temporary file. - - -.. data:: TESTFN_ENCODING - - Set to :func:`sys.getfilesystemencoding`. - - -.. data:: TESTFN_UNENCODABLE - - Set to a filename (str type) that should not be able to be encoded by file - system encoding in strict mode. It may be ``None`` if it's not possible to - generate such a filename. - - -.. data:: TESTFN_UNDECODABLE - - Set to a filename (bytes type) that should not be able to be decoded by - file system encoding in strict mode. It may be ``None`` if it's not - possible to generate such a filename. - - -.. data:: TESTFN_NONASCII - - Set to a filename containing the :data:`FS_NONASCII` character. - - .. data:: LOOPBACK_TIMEOUT Timeout in seconds for tests using a network server listening on the network @@ -348,11 +308,6 @@ The :mod:`test.support` module defines the following constants: :data:`SHORT_TIMEOUT`. -.. data:: SAVEDCWD - - Set to :func:`os.getcwd`. - - .. data:: PGO Set when tests can be skipped when they are not useful for PGO. @@ -443,44 +398,6 @@ The :mod:`test.support` module defines the following constants: The :mod:`test.support` module defines the following functions: -.. function:: forget(module_name) - - Remove the module named *module_name* from ``sys.modules`` and delete any - byte-compiled files of the module. - - -.. function:: unload(name) - - Delete *name* from ``sys.modules``. - - -.. function:: unlink(filename) - - Call :func:`os.unlink` on *filename*. On Windows platforms, this is - wrapped with a wait loop that checks for the existence fo the file. - - -.. function:: rmdir(filename) - - Call :func:`os.rmdir` on *filename*. On Windows platforms, this is - wrapped with a wait loop that checks for the existence of the file. - - -.. function:: rmtree(path) - - Call :func:`shutil.rmtree` on *path* or call :func:`os.lstat` and - :func:`os.rmdir` to remove a path and its contents. On Windows platforms, - this is wrapped with a wait loop that checks for the existence of the files. - - -.. function:: make_legacy_pyc(source) - - Move a :pep:`3147`/:pep:`488` pyc file to its legacy pyc location and return the file - system path to the legacy pyc file. The *source* value is the file system - path to the source file. It does not need to exist, however the PEP - 3147/488 pyc file must exist. - - .. function:: is_resource_enabled(resource) Return ``True`` if *resource* is enabled and available. The list of @@ -526,16 +443,6 @@ The :mod:`test.support` module defines the following functions: rather than looking directly in the path directories. -.. function:: create_empty_file(filename) - - Create an empty file with *filename*. If it already exists, truncate it. - - -.. function:: fd_count() - - Count the number of open file descriptors. - - .. function:: match_test(test) Match *test* to patterns set in :func:`set_match_tests`. @@ -590,79 +497,6 @@ The :mod:`test.support` module defines the following functions: check_impl_detail(cpython=False) # Everywhere except CPython. -.. function:: check_warnings(\*filters, quiet=True) - - A convenience wrapper for :func:`warnings.catch_warnings()` that makes it - easier to test that a warning was correctly raised. It is approximately - equivalent to calling ``warnings.catch_warnings(record=True)`` with - :meth:`warnings.simplefilter` set to ``always`` and with the option to - automatically validate the results that are recorded. - - ``check_warnings`` accepts 2-tuples of the form ``("message regexp", - WarningCategory)`` as positional arguments. If one or more *filters* are - provided, or if the optional keyword argument *quiet* is ``False``, - it checks to make sure the warnings are as expected: each specified filter - must match at least one of the warnings raised by the enclosed code or the - test fails, and if any warnings are raised that do not match any of the - specified filters the test fails. To disable the first of these checks, - set *quiet* to ``True``. - - If no arguments are specified, it defaults to:: - - check_warnings(("", Warning), quiet=True) - - In this case all warnings are caught and no errors are raised. - - On entry to the context manager, a :class:`WarningRecorder` instance is - returned. The underlying warnings list from - :func:`~warnings.catch_warnings` is available via the recorder object's - :attr:`warnings` attribute. As a convenience, the attributes of the object - representing the most recent warning can also be accessed directly through - the recorder object (see example below). If no warning has been raised, - then any of the attributes that would otherwise be expected on an object - representing a warning will return ``None``. - - The recorder object also has a :meth:`reset` method, which clears the - warnings list. - - The context manager is designed to be used like this:: - - with check_warnings(("assertion is always true", SyntaxWarning), - ("", UserWarning)): - exec('assert(False, "Hey!")') - warnings.warn(UserWarning("Hide me!")) - - In this case if either warning was not raised, or some other warning was - raised, :func:`check_warnings` would raise an error. - - When a test needs to look more deeply into the warnings, rather than - just checking whether or not they occurred, code like this can be used:: - - with check_warnings(quiet=True) as w: - warnings.warn("foo") - assert str(w.args[0]) == "foo" - warnings.warn("bar") - assert str(w.args[0]) == "bar" - assert str(w.warnings[0].args[0]) == "foo" - assert str(w.warnings[1].args[0]) == "bar" - w.reset() - assert len(w.warnings) == 0 - - - Here all warnings will be caught, and the test code tests the captured - warnings directly. - - .. versionchanged:: 3.2 - New optional arguments *filters* and *quiet*. - - -.. function:: check_no_resource_warning(testcase) - - Context manager to check that no :exc:`ResourceWarning` was raised. You - must remove the object which may emit :exc:`ResourceWarning` before the - end of the context manager. - - .. function:: set_memlimit(limit) Set the values for :data:`max_memuse` and :data:`real_max_memuse` for big @@ -718,47 +552,6 @@ The :mod:`test.support` module defines the following functions: self.assertEqual(captured, "hello") -.. function:: temp_dir(path=None, quiet=False) - - A context manager that creates a temporary directory at *path* and - yields the directory. - - If *path* is ``None``, the temporary directory is created using - :func:`tempfile.mkdtemp`. If *quiet* is ``False``, the context manager - raises an exception on error. Otherwise, if *path* is specified and - cannot be created, only a warning is issued. - - -.. function:: change_cwd(path, quiet=False) - - A context manager that temporarily changes the current working - directory to *path* and yields the directory. - - If *quiet* is ``False``, the context manager raises an exception - on error. Otherwise, it issues only a warning and keeps the current - working directory the same. - - -.. function:: temp_cwd(name='tempcwd', quiet=False) - - A context manager that temporarily creates a new directory and - changes the current working directory (CWD). - - The context manager creates a temporary directory in the current - directory with name *name* before temporarily changing the current - working directory. If *name* is ``None``, the temporary directory is - created using :func:`tempfile.mkdtemp`. - - If *quiet* is ``False`` and it is not possible to create or change - the CWD, an error is raised. Otherwise, only a warning is raised - and the original CWD is used. - - -.. function:: temp_umask(umask) - - A context manager that temporarily sets the process umask. - - .. function:: disable_faulthandler() A context manager that replaces ``sys.stderr`` with ``sys.__stderr__``. @@ -838,18 +631,6 @@ The :mod:`test.support` module defines the following functions: .. versionadded:: 3.9 -.. function:: wait_threads_exit(timeout=60.0) - - Context manager to wait until all threads created in the ``with`` statement - exit. - - -.. function:: start_threads(threads, unlock=None) - - Context manager to start *threads*. It attempts to join the threads upon - exit. - - .. function:: calcobjsize(fmt) Return :func:`struct.calcsize` for ``nP{fmt}0n`` or, if ``gettotalrefcount`` @@ -868,28 +649,6 @@ The :mod:`test.support` module defines the following functions: header size equals *size*. -.. function:: can_symlink() - - Return ``True`` if the OS supports symbolic links, ``False`` - otherwise. - - -.. function:: can_xattr() - - Return ``True`` if the OS supports xattr, ``False`` - otherwise. - - -.. decorator:: skip_unless_symlink - - A decorator for running tests that require support for symbolic links. - - -.. decorator:: skip_unless_xattr - - A decorator for running tests that require support for xattr. - - .. decorator:: anticipate_failure(condition) A decorator to conditionally mark tests with @@ -988,11 +747,6 @@ The :mod:`test.support` module defines the following functions: the trace function. -.. decorator:: reap_threads(func) - - Decorator to ensure the threads are cleaned up even if the test fails. - - .. decorator:: bigmemtest(size, memuse, dry_run=True) Decorator for bigmem tests. @@ -1014,12 +768,6 @@ The :mod:`test.support` module defines the following functions: wrap. -.. function:: make_bad_fd() - - Create an invalid file descriptor by opening and closing a temporary file, - and returning its descriptor. - - .. function:: check_syntax_error(testcase, statement, errtext='', *, lineno=None, offset=None) Test for syntax errors in *statement* by attempting to compile *statement*. @@ -1030,103 +778,11 @@ The :mod:`test.support` module defines the following functions: the offset of the exception. -.. function:: check_syntax_warning(testcase, statement, errtext='', *, lineno=1, offset=None) - - Test for syntax warning in *statement* by attempting to compile *statement*. - Test also that the :exc:`SyntaxWarning` is emitted only once, and that it - will be converted to a :exc:`SyntaxError` when turned into error. - *testcase* is the :mod:`unittest` instance for the test. *errtext* is the - regular expression which should match the string representation of the - emitted :exc:`SyntaxWarning` and raised :exc:`SyntaxError`. If *lineno* - is not ``None``, compares to the line of the warning and exception. - If *offset* is not ``None``, compares to the offset of the exception. - - .. versionadded:: 3.8 - - .. function:: open_urlresource(url, *args, **kw) Open *url*. If open fails, raises :exc:`TestFailed`. -.. function:: import_module(name, deprecated=False, *, required_on()) - - This function imports and returns the named module. Unlike a normal - import, this function raises :exc:`unittest.SkipTest` if the module - cannot be imported. - - Module and package deprecation messages are suppressed during this import - if *deprecated* is ``True``. If a module is required on a platform but - optional for others, set *required_on* to an iterable of platform prefixes - which will be compared against :data:`sys.platform`. - - .. versionadded:: 3.1 - - -.. function:: import_fresh_module(name, fresh=(), blocked=(), deprecated=False) - - This function imports and returns a fresh copy of the named Python module - by removing the named module from ``sys.modules`` before doing the import. - Note that unlike :func:`reload`, the original module is not affected by - this operation. - - *fresh* is an iterable of additional module names that are also removed - from the ``sys.modules`` cache before doing the import. - - *blocked* is an iterable of module names that are replaced with ``None`` - in the module cache during the import to ensure that attempts to import - them raise :exc:`ImportError`. - - The named module and any modules named in the *fresh* and *blocked* - parameters are saved before starting the import and then reinserted into - ``sys.modules`` when the fresh import is complete. - - Module and package deprecation messages are suppressed during this import - if *deprecated* is ``True``. - - This function will raise :exc:`ImportError` if the named module cannot be - imported. - - Example use:: - - # Get copies of the warnings module for testing without affecting the - # version being used by the rest of the test suite. One copy uses the - # C implementation, the other is forced to use the pure Python fallback - # implementation - py_warnings = import_fresh_module('warnings', blocked=['_warnings']) - c_warnings = import_fresh_module('warnings', fresh=['_warnings']) - - .. versionadded:: 3.1 - - -.. function:: modules_setup() - - Return a copy of :data:`sys.modules`. - - -.. function:: modules_cleanup(oldmodules) - - Remove modules except for *oldmodules* and ``encodings`` in order to - preserve internal cache. - - -.. function:: threading_setup() - - Return current thread count and copy of dangling threads. - - -.. function:: threading_cleanup(*original_values) - - Cleanup up threads not specified in *original_values*. Designed to emit - a warning if a test leaves running threads in the background. - - -.. function:: join_thread(thread, timeout=30.0) - - Join a *thread* within *timeout*. Raise an :exc:`AssertionError` if thread - is still alive after *timeout* seconds. - - .. function:: reap_children() Use this at the end of ``test_main`` whenever sub-processes are started. @@ -1140,39 +796,6 @@ The :mod:`test.support` module defines the following functions: is raised. -.. function:: catch_threading_exception() - - Context manager catching :class:`threading.Thread` exception using - :func:`threading.excepthook`. - - Attributes set when an exception is catched: - - * ``exc_type`` - * ``exc_value`` - * ``exc_traceback`` - * ``thread`` - - See :func:`threading.excepthook` documentation. - - These attributes are deleted at the context manager exit. - - Usage:: - - with support.catch_threading_exception() as cm: - # code spawning a thread which raises an exception - ... - - # check the thread exception, use cm attributes: - # exc_type, exc_value, exc_traceback, thread - ... - - # exc_type, exc_value, exc_traceback, thread attributes of cm no longer - # exists at this point - # (to avoid reference cycles) - - .. versionadded:: 3.8 - - .. function:: catch_unraisable_exception() Context manager catching unraisable exception using @@ -1216,11 +839,6 @@ The :mod:`test.support` module defines the following functions: return load_package_tests(os.path.dirname(__file__), *args) -.. function:: fs_is_case_insensitive(directory) - - Return ``True`` if the file system for *directory* is case-insensitive. - - .. function:: detect_api_mismatch(ref_api, other_api, *, ignore=()) Returns the set of attributes, functions or methods of *ref_api* not @@ -1301,40 +919,17 @@ The :mod:`test.support` module defines the following functions: .. versionadded:: 3.6 +.. function:: skip_if_broken_multiprocessing_synchronize() + + Skip tests if the :mod:`multiprocessing.synchronize` module is missing, if + there is no available semaphore implementation, or if creating a lock raises + an :exc:`OSError`. + + .. versionadded:: 3.10 + The :mod:`test.support` module defines the following classes: -.. class:: TransientResource(exc, **kwargs) - - Instances are a context manager that raises :exc:`ResourceDenied` if the - specified exception type is raised. Any keyword arguments are treated as - attribute/value pairs to be compared against any exception raised within the - :keyword:`with` statement. Only if all pairs match properly against - attributes on the exception is :exc:`ResourceDenied` raised. - - -.. class:: EnvironmentVarGuard() - - Class used to temporarily set or unset environment variables. Instances can - be used as a context manager and have a complete dictionary interface for - querying/modifying the underlying ``os.environ``. After exit from the - context manager all changes to environment variables done through this - instance will be rolled back. - - .. versionchanged:: 3.1 - Added dictionary interface. - -.. method:: EnvironmentVarGuard.set(envvar, value) - - Temporarily set the environment variable ``envvar`` to the value of - ``value``. - - -.. method:: EnvironmentVarGuard.unset(envvar) - - Temporarily unset the environment variable ``envvar``. - - .. class:: SuppressCrashReport() A context manager used to try to prevent crash dialog popups on tests that @@ -1350,29 +945,6 @@ The :mod:`test.support` module defines the following classes: On both platforms, the old value is restored by :meth:`__exit__`. -.. class:: CleanImport(*module_names) - - A context manager to force import to return a new module reference. This - is useful for testing module-level behaviors, such as the emission of a - DeprecationWarning on import. Example usage:: - - with CleanImport('foo'): - importlib.import_module('foo') # New reference. - - -.. class:: DirsOnSysPath(*paths) - - A context manager to temporarily add directories to sys.path. - - This makes a copy of :data:`sys.path`, appends any directories given - as positional arguments, then reverts :data:`sys.path` to the copied - settings when the context ends. - - Note that *all* :data:`sys.path` modifications in the body of the - context manager, including replacement of the object, - will be reverted at the end of the block. - - .. class:: SaveSignals() Class to save and restore signal handlers registered by the Python signal @@ -1391,12 +963,6 @@ The :mod:`test.support` module defines the following classes: Try to match a single stored value (*dv*) with a supplied value (*v*). -.. class:: WarningsRecorder() - - Class used to record warnings for unit tests. See documentation of - :func:`check_warnings` above for more details. - - .. class:: BasicTestRunner() .. method:: run(test) @@ -1404,13 +970,6 @@ The :mod:`test.support` module defines the following classes: Run *test* and return the result. -.. class:: FakePath(path) - - Simple :term:`path-like object`. It implements the :meth:`__fspath__` - method which just returns the *path* argument. If *path* is an exception, - it will be raised in :meth:`!__fspath__`. - - :mod:`test.support.socket_helper` --- Utilities for socket tests ================================================================ @@ -1628,3 +1187,483 @@ The module defines the following class: .. method:: BytecodeTestCase.assertNotInBytecode(x, opname, argval=_UNSPECIFIED) Throws :exc:`AssertionError` if *opname* is found. + + +:mod:`test.support.threading_helper` --- Utilities for threading tests +====================================================================== + +.. module:: test.support.threading_helper + :synopsis: Support for threading tests. + +The :mod:`test.support.threading_helper` module provides support for threading tests. + +.. versionadded:: 3.10 + + +.. function:: join_thread(thread, timeout=None) + + Join a *thread* within *timeout*. Raise an :exc:`AssertionError` if thread + is still alive after *timeout* seconds. + + +.. decorator:: reap_threads(func) + + Decorator to ensure the threads are cleaned up even if the test fails. + + +.. function:: start_threads(threads, unlock=None) + + Context manager to start *threads*. It attempts to join the threads upon + exit. + + +.. function:: threading_cleanup(*original_values) + + Cleanup up threads not specified in *original_values*. Designed to emit + a warning if a test leaves running threads in the background. + + +.. function:: threading_setup() + + Return current thread count and copy of dangling threads. + + +.. function:: wait_threads_exit(timeout=None) + + Context manager to wait until all threads created in the ``with`` statement + exit. + + +.. function:: catch_threading_exception() + + Context manager catching :class:`threading.Thread` exception using + :func:`threading.excepthook`. + + Attributes set when an exception is catched: + + * ``exc_type`` + * ``exc_value`` + * ``exc_traceback`` + * ``thread`` + + See :func:`threading.excepthook` documentation. + + These attributes are deleted at the context manager exit. + + Usage:: + + with threading_helper.catch_threading_exception() as cm: + # code spawning a thread which raises an exception + ... + + # check the thread exception, use cm attributes: + # exc_type, exc_value, exc_traceback, thread + ... + + # exc_type, exc_value, exc_traceback, thread attributes of cm no longer + # exists at this point + # (to avoid reference cycles) + + .. versionadded:: 3.8 + + +:mod:`test.support.os_helper` --- Utilities for os tests +======================================================================== + +.. module:: test.support.os_helper + :synopsis: Support for os tests. + +The :mod:`test.support.os_helper` module provides support for os tests. + +.. versionadded:: 3.10 + + +.. data:: FS_NONASCII + + A non-ASCII character encodable by :func:`os.fsencode`. + + +.. data:: SAVEDCWD + + Set to :func:`os.getcwd`. + + +.. data:: TESTFN + + Set to a name that is safe to use as the name of a temporary file. Any + temporary file that is created should be closed and unlinked (removed). + + +.. data:: TESTFN_NONASCII + + Set to a filename containing the :data:`FS_NONASCII` character. + + +.. data:: TESTFN_UNENCODABLE + + Set to a filename (str type) that should not be able to be encoded by file + system encoding in strict mode. It may be ``None`` if it's not possible to + generate such a filename. + + +.. data:: TESTFN_UNDECODABLE + + Set to a filename (bytes type) that should not be able to be decoded by + file system encoding in strict mode. It may be ``None`` if it's not + possible to generate such a filename. + + +.. data:: TESTFN_UNICODE + + Set to a non-ASCII name for a temporary file. + + +.. class:: EnvironmentVarGuard() + + Class used to temporarily set or unset environment variables. Instances can + be used as a context manager and have a complete dictionary interface for + querying/modifying the underlying ``os.environ``. After exit from the + context manager all changes to environment variables done through this + instance will be rolled back. + + .. versionchanged:: 3.1 + Added dictionary interface. + + +.. class:: FakePath(path) + + Simple :term:`path-like object`. It implements the :meth:`__fspath__` + method which just returns the *path* argument. If *path* is an exception, + it will be raised in :meth:`!__fspath__`. + + +.. method:: EnvironmentVarGuard.set(envvar, value) + + Temporarily set the environment variable ``envvar`` to the value of + ``value``. + + +.. method:: EnvironmentVarGuard.unset(envvar) + + Temporarily unset the environment variable ``envvar``. + + +.. function:: can_symlink() + + Return ``True`` if the OS supports symbolic links, ``False`` + otherwise. + + +.. function:: can_xattr() + + Return ``True`` if the OS supports xattr, ``False`` + otherwise. + + +.. function:: change_cwd(path, quiet=False) + + A context manager that temporarily changes the current working + directory to *path* and yields the directory. + + If *quiet* is ``False``, the context manager raises an exception + on error. Otherwise, it issues only a warning and keeps the current + working directory the same. + + +.. function:: create_empty_file(filename) + + Create an empty file with *filename*. If it already exists, truncate it. + + +.. function:: fd_count() + + Count the number of open file descriptors. + + +.. function:: fs_is_case_insensitive(directory) + + Return ``True`` if the file system for *directory* is case-insensitive. + + +.. function:: make_bad_fd() + + Create an invalid file descriptor by opening and closing a temporary file, + and returning its descriptor. + + +.. function:: rmdir(filename) + + Call :func:`os.rmdir` on *filename*. On Windows platforms, this is + wrapped with a wait loop that checks for the existence of the file. + + +.. function:: rmtree(path) + + Call :func:`shutil.rmtree` on *path* or call :func:`os.lstat` and + :func:`os.rmdir` to remove a path and its contents. On Windows platforms, + this is wrapped with a wait loop that checks for the existence of the files. + + +.. decorator:: skip_unless_symlink + + A decorator for running tests that require support for symbolic links. + + +.. decorator:: skip_unless_xattr + + A decorator for running tests that require support for xattr. + + +.. function:: temp_cwd(name='tempcwd', quiet=False) + + A context manager that temporarily creates a new directory and + changes the current working directory (CWD). + + The context manager creates a temporary directory in the current + directory with name *name* before temporarily changing the current + working directory. If *name* is ``None``, the temporary directory is + created using :func:`tempfile.mkdtemp`. + + If *quiet* is ``False`` and it is not possible to create or change + the CWD, an error is raised. Otherwise, only a warning is raised + and the original CWD is used. + + +.. function:: temp_dir(path=None, quiet=False) + + A context manager that creates a temporary directory at *path* and + yields the directory. + + If *path* is ``None``, the temporary directory is created using + :func:`tempfile.mkdtemp`. If *quiet* is ``False``, the context manager + raises an exception on error. Otherwise, if *path* is specified and + cannot be created, only a warning is issued. + + +.. function:: temp_umask(umask) + + A context manager that temporarily sets the process umask. + + +.. function:: unlink(filename) + + Call :func:`os.unlink` on *filename*. On Windows platforms, this is + wrapped with a wait loop that checks for the existence fo the file. + + +:mod:`test.support.import_helper` --- Utilities for import tests +================================================================ + +.. module:: test.support.import_helper + :synopsis: Support for import tests. + +The :mod:`test.support.import_helper` module provides support for import tests. + +.. versionadded:: 3.10 + + +.. function:: forget(module_name) + + Remove the module named *module_name* from ``sys.modules`` and delete any + byte-compiled files of the module. + + +.. function:: import_fresh_module(name, fresh=(), blocked=(), deprecated=False) + + This function imports and returns a fresh copy of the named Python module + by removing the named module from ``sys.modules`` before doing the import. + Note that unlike :func:`reload`, the original module is not affected by + this operation. + + *fresh* is an iterable of additional module names that are also removed + from the ``sys.modules`` cache before doing the import. + + *blocked* is an iterable of module names that are replaced with ``None`` + in the module cache during the import to ensure that attempts to import + them raise :exc:`ImportError`. + + The named module and any modules named in the *fresh* and *blocked* + parameters are saved before starting the import and then reinserted into + ``sys.modules`` when the fresh import is complete. + + Module and package deprecation messages are suppressed during this import + if *deprecated* is ``True``. + + This function will raise :exc:`ImportError` if the named module cannot be + imported. + + Example use:: + + # Get copies of the warnings module for testing without affecting the + # version being used by the rest of the test suite. One copy uses the + # C implementation, the other is forced to use the pure Python fallback + # implementation + py_warnings = import_fresh_module('warnings', blocked=['_warnings']) + c_warnings = import_fresh_module('warnings', fresh=['_warnings']) + + .. versionadded:: 3.1 + + +.. function:: import_module(name, deprecated=False, *, required_on()) + + This function imports and returns the named module. Unlike a normal + import, this function raises :exc:`unittest.SkipTest` if the module + cannot be imported. + + Module and package deprecation messages are suppressed during this import + if *deprecated* is ``True``. If a module is required on a platform but + optional for others, set *required_on* to an iterable of platform prefixes + which will be compared against :data:`sys.platform`. + + .. versionadded:: 3.1 + + +.. function:: modules_setup() + + Return a copy of :data:`sys.modules`. + + +.. function:: modules_cleanup(oldmodules) + + Remove modules except for *oldmodules* and ``encodings`` in order to + preserve internal cache. + + +.. function:: unload(name) + + Delete *name* from ``sys.modules``. + + +.. function:: make_legacy_pyc(source) + + Move a :pep:`3147`/:pep:`488` pyc file to its legacy pyc location and return the file + system path to the legacy pyc file. The *source* value is the file system + path to the source file. It does not need to exist, however the PEP + 3147/488 pyc file must exist. + + +.. class:: CleanImport(*module_names) + + A context manager to force import to return a new module reference. This + is useful for testing module-level behaviors, such as the emission of a + DeprecationWarning on import. Example usage:: + + with CleanImport('foo'): + importlib.import_module('foo') # New reference. + + +.. class:: DirsOnSysPath(*paths) + + A context manager to temporarily add directories to sys.path. + + This makes a copy of :data:`sys.path`, appends any directories given + as positional arguments, then reverts :data:`sys.path` to the copied + settings when the context ends. + + Note that *all* :data:`sys.path` modifications in the body of the + context manager, including replacement of the object, + will be reverted at the end of the block. + + +:mod:`test.support.warnings_helper` --- Utilities for warnings tests +==================================================================== + +.. module:: test.support.warnings_helper + :synopsis: Support for warnings tests. + +The :mod:`test.support.warnings_helper` module provides support for warnings tests. + +.. versionadded:: 3.10 + + +.. function:: check_no_resource_warning(testcase) + + Context manager to check that no :exc:`ResourceWarning` was raised. You + must remove the object which may emit :exc:`ResourceWarning` before the + end of the context manager. + + +.. function:: check_syntax_warning(testcase, statement, errtext='', *, lineno=1, offset=None) + + Test for syntax warning in *statement* by attempting to compile *statement*. + Test also that the :exc:`SyntaxWarning` is emitted only once, and that it + will be converted to a :exc:`SyntaxError` when turned into error. + *testcase* is the :mod:`unittest` instance for the test. *errtext* is the + regular expression which should match the string representation of the + emitted :exc:`SyntaxWarning` and raised :exc:`SyntaxError`. If *lineno* + is not ``None``, compares to the line of the warning and exception. + If *offset* is not ``None``, compares to the offset of the exception. + + .. versionadded:: 3.8 + + +.. function:: check_warnings(\*filters, quiet=True) + + A convenience wrapper for :func:`warnings.catch_warnings()` that makes it + easier to test that a warning was correctly raised. It is approximately + equivalent to calling ``warnings.catch_warnings(record=True)`` with + :meth:`warnings.simplefilter` set to ``always`` and with the option to + automatically validate the results that are recorded. + + ``check_warnings`` accepts 2-tuples of the form ``("message regexp", + WarningCategory)`` as positional arguments. If one or more *filters* are + provided, or if the optional keyword argument *quiet* is ``False``, + it checks to make sure the warnings are as expected: each specified filter + must match at least one of the warnings raised by the enclosed code or the + test fails, and if any warnings are raised that do not match any of the + specified filters the test fails. To disable the first of these checks, + set *quiet* to ``True``. + + If no arguments are specified, it defaults to:: + + check_warnings(("", Warning), quiet=True) + + In this case all warnings are caught and no errors are raised. + + On entry to the context manager, a :class:`WarningRecorder` instance is + returned. The underlying warnings list from + :func:`~warnings.catch_warnings` is available via the recorder object's + :attr:`warnings` attribute. As a convenience, the attributes of the object + representing the most recent warning can also be accessed directly through + the recorder object (see example below). If no warning has been raised, + then any of the attributes that would otherwise be expected on an object + representing a warning will return ``None``. + + The recorder object also has a :meth:`reset` method, which clears the + warnings list. + + The context manager is designed to be used like this:: + + with check_warnings(("assertion is always true", SyntaxWarning), + ("", UserWarning)): + exec('assert(False, "Hey!")') + warnings.warn(UserWarning("Hide me!")) + + In this case if either warning was not raised, or some other warning was + raised, :func:`check_warnings` would raise an error. + + When a test needs to look more deeply into the warnings, rather than + just checking whether or not they occurred, code like this can be used:: + + with check_warnings(quiet=True) as w: + warnings.warn("foo") + assert str(w.args[0]) == "foo" + warnings.warn("bar") + assert str(w.args[0]) == "bar" + assert str(w.warnings[0].args[0]) == "foo" + assert str(w.warnings[1].args[0]) == "bar" + w.reset() + assert len(w.warnings) == 0 + + + Here all warnings will be caught, and the test code tests the captured + warnings directly. + + .. versionchanged:: 3.2 + New optional arguments *filters* and *quiet*. + + +.. class:: WarningsRecorder() + + Class used to record warnings for unit tests. See documentation of + :func:`check_warnings` above for more details. diff --git a/Doc/library/threading.rst b/Doc/library/threading.rst index 3a446adfac8..458e39bf721 100644 --- a/Doc/library/threading.rst +++ b/Doc/library/threading.rst @@ -349,13 +349,12 @@ since it is impossible to detect the termination of alien threads. .. attribute:: native_id - The native integral thread ID of this thread. + The Thread ID (``TID``) of this thread, as assigned by the OS (kernel). This is a non-negative integer, or ``None`` if the thread has not been started. See the :func:`get_native_id` function. - This represents the Thread ID (``TID``) as assigned to the - thread by the OS (kernel). Its value may be used to uniquely identify - this particular thread system-wide (until the thread terminates, - after which the value may be recycled by the OS). + This value may be used to uniquely identify this particular thread + system-wide (until the thread terminates, after which the value + may be recycled by the OS). .. note:: diff --git a/Doc/library/tracemalloc.rst b/Doc/library/tracemalloc.rst index fba1caab455..20f668c7282 100644 --- a/Doc/library/tracemalloc.rst +++ b/Doc/library/tracemalloc.rst @@ -345,7 +345,7 @@ Functions See also :func:`get_traced_memory`. - .. versionadded:: 3.10 + .. versionadded:: 3.9 .. function:: get_tracemalloc_memory() diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index e85b6d697f7..e5143c5f8d9 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -672,7 +672,7 @@ The module defines the following classes, functions and decorators: A generic version of :class:`collections.abc.ByteString`. This type represents the types :class:`bytes`, :class:`bytearray`, - and :class:`memoryview`. + and :class:`memoryview` of byte sequences. As a shorthand for this type, :class:`bytes` can be used to annotate arguments of any of the types mentioned above. diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst index b2e16cf331e..0dddbd25d99 100644 --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -950,6 +950,9 @@ Test cases | :meth:`assertLogs(logger, level) | The ``with`` block logs on *logger* | 3.4 | | ` | with minimum *level* | | +---------------------------------------------------------+--------------------------------------+------------+ + | :meth:`assertNoLogs(logger, level) | The ``with`` block does not log on | 3.10 | + | ` | *logger* with minimum *level* | | + +---------------------------------------------------------+--------------------------------------+------------+ .. method:: assertRaises(exception, callable, *args, **kwds) assertRaises(exception, *, msg=None) @@ -1121,6 +1124,24 @@ Test cases .. versionadded:: 3.4 + .. method:: assertNoLogs(logger=None, level=None) + + A context manager to test that no messages are logged on + the *logger* or one of its children, with at least the given + *level*. + + If given, *logger* should be a :class:`logging.Logger` object or a + :class:`str` giving the name of a logger. The default is the root + logger, which will catch all messages. + + If given, *level* should be either a numeric logging level or + its string equivalent (for example either ``"ERROR"`` or + :attr:`logging.ERROR`). The default is :attr:`logging.INFO`. + + Unlike :meth:`assertLogs`, nothing will be returned by the context + manager. + + .. versionadded:: 3.10 There are also other methods used to perform more specific checks, such as: diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst index 12eb985c344..d3c3a070f38 100644 --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -163,14 +163,6 @@ Extension types can easily be made to support weak references; see application without adding attributes to those objects. This can be especially useful with objects that override attribute accesses. - .. note:: - - Caution: Because a :class:`WeakKeyDictionary` is built on top of a Python - dictionary, it must not change size when iterating over it. This can be - difficult to ensure for a :class:`WeakKeyDictionary` because actions - performed by the program during iteration may cause items in the - dictionary to vanish "by magic" (as a side effect of garbage collection). - .. versionchanged:: 3.9 Added support for ``|`` and ``|=`` operators, specified in :pep:`584`. @@ -192,14 +184,6 @@ than needed. Mapping class that references values weakly. Entries in the dictionary will be discarded when no strong reference to the value exists any more. - .. note:: - - Caution: Because a :class:`WeakValueDictionary` is built on top of a Python - dictionary, it must not change size when iterating over it. This can be - difficult to ensure for a :class:`WeakValueDictionary` because actions performed - by the program during iteration may cause items in the dictionary to vanish "by - magic" (as a side effect of garbage collection). - .. versionchanged:: 3.9 Added support for ``|`` and ``|=`` operators, as specified in :pep:`584`. diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst index 658bc3a54f8..7725e4d158d 100644 --- a/Doc/library/xml.etree.elementtree.rst +++ b/Doc/library/xml.etree.elementtree.rst @@ -15,6 +15,8 @@ for parsing and creating XML data. .. versionchanged:: 3.3 This module will use a fast implementation whenever available. + +.. deprecated:: 3.3 The :mod:`xml.etree.cElementTree` module is deprecated. @@ -816,16 +818,25 @@ Functions loader fails, it can return None or raise an exception. -.. function:: xml.etree.ElementInclude.include( elem, loader=None) +.. function:: xml.etree.ElementInclude.include( elem, loader=None, base_url=None, \ + max_depth=6) This function expands XInclude directives. *elem* is the root element. *loader* is an optional resource loader. If omitted, it defaults to :func:`default_loader`. If given, it should be a callable that implements the same interface as - :func:`default_loader`. Returns the expanded resource. If the parse mode is + :func:`default_loader`. *base_url* is base URL of the original file, to resolve + relative include file references. *max_depth* is the maximum number of recursive + inclusions. Limited to reduce the risk of malicious content explosion. Pass a + negative value to disable the limitation. + + Returns the expanded resource. If the parse mode is ``"xml"``, this is an ElementTree instance. If the parse mode is "text", this is a Unicode string. If the loader fails, it can return None or raise an exception. + .. versionadded:: 3.9 + The *base_url* and *max_depth* parameters. + .. _elementtree-element-objects: diff --git a/Doc/license.rst b/Doc/license.rst index 472a5cf3d88..fa6d71a7804 100644 --- a/Doc/license.rst +++ b/Doc/license.rst @@ -889,7 +889,7 @@ libmpdec The :mod:`_decimal` module is built using an included copy of the libmpdec library unless the build is configured ``--with-system-libmpdec``:: - Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + Copyright (c) 2008-2020 Stefan Krah. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions diff --git a/Doc/make.bat b/Doc/make.bat index 6f8f172e95e..7fde0636427 100644 --- a/Doc/make.bat +++ b/Doc/make.bat @@ -13,7 +13,7 @@ if not defined SPHINXBUILD ( %PYTHON% -c "import sphinx" > nul 2> nul if errorlevel 1 ( echo Installing sphinx with %PYTHON% - %PYTHON% -m pip install sphinx + %PYTHON% -m pip install sphinx==2.2.0 if errorlevel 1 exit /B ) set SPHINXBUILD=%PYTHON% -c "import sphinx.cmd.build, sys; sys.exit(sphinx.cmd.build.main())" diff --git a/Doc/myfile.bz2 b/Doc/myfile.bz2 deleted file mode 100644 index 7ada20f6092..00000000000 Binary files a/Doc/myfile.bz2 and /dev/null differ diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index e3a3a88757e..7d70cbcaa37 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -704,7 +704,7 @@ Top-level format specifiers may include nested replacement fields. These nested fields may include their own conversion fields and :ref:`format specifiers `, but may not include more deeply-nested replacement fields. The :ref:`format specifier mini-language ` is the same as that used by -the string .format() method. +the :meth:`str.format` method. Formatted string literals may be concatenated, but replacement fields cannot be split across literals. diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py index bc51555fa05..46064fa3b6b 100644 --- a/Doc/tools/extensions/pyspecific.py +++ b/Doc/tools/extensions/pyspecific.py @@ -311,7 +311,8 @@ class DeprecatedRemoved(Directive): final_argument_whitespace = True option_spec = {} - _label = 'Deprecated since version {deprecated}, will be removed in version {removed}' + _deprecated_label = 'Deprecated since version {deprecated}, will be removed in version {removed}' + _removed_label = 'Deprecated since version {deprecated}, removed in version {removed}' def run(self): node = addnodes.versionmodified() @@ -319,7 +320,15 @@ class DeprecatedRemoved(Directive): node['type'] = 'deprecated-removed' version = (self.arguments[0], self.arguments[1]) node['version'] = version - label = translators['sphinx'].gettext(self._label) + env = self.state.document.settings.env + current_version = tuple(int(e) for e in env.config.version.split('.')) + removed_version = tuple(int(e) for e in self.arguments[1].split('.')) + if current_version < removed_version: + label = self._deprecated_label + else: + label = self._removed_label + + label = translators['sphinx'].gettext(label) text = label.format(deprecated=self.arguments[0], removed=self.arguments[1]) if len(self.arguments) == 3: inodes, messages = self.state.inline_text(self.arguments[2], diff --git a/Doc/tools/templates/dummy.html b/Doc/tools/templates/dummy.html index 8d94137b01b..68ae3ad148e 100644 --- a/Doc/tools/templates/dummy.html +++ b/Doc/tools/templates/dummy.html @@ -5,3 +5,4 @@ In extensions/pyspecific.py: {% trans %}CPython implementation detail:{% endtrans %} {% trans %}Deprecated since version {deprecated}, will be removed in version {removed}{% endtrans %} +{% trans %}Deprecated since version {deprecated}, removed in version {removed}{% endtrans %} diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst index 06bdd0d9351..250d2a9ddb4 100644 --- a/Doc/tutorial/classes.rst +++ b/Doc/tutorial/classes.rst @@ -114,8 +114,8 @@ accessible. "Directly accessible" here means that an unqualified reference to a name attempts to find the name in the namespace. Although scopes are determined statically, they are used dynamically. At any -time during execution, there are at least three nested scopes whose namespaces -are directly accessible: +time during execution, At any time during execution, there are 3 or 4 nested +scopes whose namespaces are directly accessible: * the innermost scope, which is searched first, contains the local names * the scopes of any enclosing functions, which are searched starting with the diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 26de866aab9..5d5b01d8132 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -300,11 +300,10 @@ passed using *call by value* (where the *value* is always an object *reference*, not the value of the object). [#]_ When a function calls another function, a new local symbol table is created for that call. -A function definition introduces the function name in the current symbol table. -The value of the function name has a type that is recognized by the interpreter -as a user-defined function. This value can be assigned to another name which -can then also be used as a function. This serves as a general renaming -mechanism:: +A function definition associates the function name with the function object in +the current symbol table. The interpreter recognizes the object pointed to by +that name as a user-defined function. Other names can also point to that same +function object and can also be used to access the function:: >>> fib diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst index a404f4be19f..366a532e817 100644 --- a/Doc/tutorial/inputoutput.rst +++ b/Doc/tutorial/inputoutput.rst @@ -172,7 +172,7 @@ Positional and keyword arguments can be arbitrarily combined:: If you have a really long format string that you don't want to split up, it would be nice if you could reference the variables to be formatted by name instead of by position. This can be done by simply passing the dict and using -square brackets ``'[]'`` to access the keys :: +square brackets ``'[]'`` to access the keys. :: >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678} >>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; ' @@ -257,10 +257,10 @@ left with zeros. It understands about plus and minus signs:: Old string formatting --------------------- -The ``%`` operator can also be used for string formatting. It interprets the -left argument much like a :c:func:`sprintf`\ -style format string to be applied -to the right argument, and returns the string resulting from this formatting -operation. For example:: +The % operator (modulo) can also be used for string formatting. Given ``'string' +% values``, instances of ``%`` in ``string`` are replaced with zero or more +elements of ``values``. This operation is commonly known as string +interpolation. For example:: >>> import math >>> print('The value of pi is approximately %5.3f.' % math.pi) diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index b0911956a9e..8c65d99ef31 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -369,6 +369,11 @@ Miscellaneous options (filename or built-in module) from which it is loaded. When given twice (:option:`!-vv`), print a message for each file that is checked for when searching for a module. Also provides information on module cleanup at exit. + + .. versionchanged:: 3.10 + The :mod:`site` module reports the site-specific paths + and :file:`.pth` files being processed. + See also :envvar:`PYTHONVERBOSE`. @@ -426,8 +431,6 @@ Miscellaneous options defines the following possible values: * ``-X faulthandler`` to enable :mod:`faulthandler`; - * ``-X oldparser``: enable the traditional LL(1) parser. See also - :envvar:`PYTHONOLDPARSER` and :pep:`617`. * ``-X showrefcount`` to output the total reference count and number of used memory blocks when the program finishes or after each statement in the interactive interpreter. This only works on debug builds. @@ -538,6 +541,14 @@ conflict. within a Python program as the variable :data:`sys.path`. +.. envvar:: PYTHONPLATLIBDIR + + If this is set to a non-empty string, it overrides the :data:`sys.platlibdir` + value. + + .. versionadded:: 3.9 + + .. envvar:: PYTHONSTARTUP If this is the name of a readable file, the Python commands in that file are @@ -579,15 +590,6 @@ conflict. :option:`-d` multiple times. -.. envvar:: PYTHONOLDPARSER - - If this is set to a non-empty string, enable the traditional LL(1) parser. - - See also the :option:`-X` ``oldparser`` option and :pep:`617`. - - .. deprecated-removed:: 3.9 3.10 - - .. envvar:: PYTHONINSPECT If this is set to a non-empty string it is equivalent to specifying the diff --git a/Doc/using/windows.rst b/Doc/using/windows.rst index 97e9cdfeb09..b95a43c853c 100644 --- a/Doc/using/windows.rst +++ b/Doc/using/windows.rst @@ -108,9 +108,7 @@ approximately 32,000 characters. Your administrator will need to activate the to ``1``. This allows the :func:`open` function, the :mod:`os` module and most other -path functionality to accept and return paths longer than 260 characters when -using strings. (Use of bytes as paths is deprecated on Windows, and this feature -is not available when using bytes.) +path functionality to accept and return paths longer than 260 characters. After changing the above option, no further configuration is required. diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index fabd9a2463e..a3b53ba48e9 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -70,6 +70,17 @@ Summary -- Release highlights New Features ============ +* The :class:`int` type has a new method :meth:`int.bit_count`, returning the + number of ones in the binary expansion of a given integer, also known + as the population count. (Contributed by Niklas Fiekas in :issue:`29882`.) + +* The views returned by :meth:`dict.keys`, :meth:`dict.values` and + :meth:`dict.items` now all have a ``mapping`` attribute that gives a + :class:`types.MappingProxyType` object wrapping the original + dictionary. (Contributed by Dennis Sweeney in :issue:`40890`.) + +* :pep:`618`: The :func:`zip` function now has an optional ``strict`` flag, used + to require that all the iterables have an equal length. Other Language Changes @@ -92,16 +103,29 @@ New Modules Improved Modules ================ -tracemalloc ------------ +glob +---- + +Added the *root_dir* and *dir_fd* parameters in :func:`~glob.glob` and +:func:`~glob.iglob` which allow to specify the root directory for searching. +(Contributed by Serhiy Storchaka in :issue:`38144`.) + +sys +--- + +Add :data:`sys.orig_argv` attribute: the list of the original command line +arguments passed to the Python executable. +(Contributed by Victor Stinner in :issue:`23427`.) -Added :func:`tracemalloc.reset_peak` to set the peak size of traced memory -blocks to the current size, to measure the peak of specific pieces of code. -(Contributed by Huon Wilson in :issue:`40630`.) Optimizations ============= +* The :mod:`runpy` module now imports fewer modules. + The ``python3 -m module-name`` command startup time is 1.3x faster in + average. + (Contributed by Victor Stinner in :issue:`41006`.) + Deprecated ========== @@ -122,6 +146,10 @@ that may require changes to your code. Build Changes ============= +* The C99 functions :c:func:`snprintf` and :c:func:`vsnprintf` are now required + to build Python. + (Contributed by Victor Stinner in :issue:`36020`.) + C API Changes ============= @@ -129,15 +157,95 @@ C API Changes New Features ------------ +* The result of :c:func:`PyNumber_Index` now always has exact type :class:`int`. + Previously, the result could have been an instance of a subclass of ``int``. + (Contributed by Serhiy Storchaka in :issue:`40792`.) + +* Add a new :c:member:`~PyConfig.orig_argv` member to the :c:type:`PyConfig` + structure: the list of the original command line arguments passed to the + Python executable. + (Contributed by Victor Stinner in :issue:`23427`.) Porting to Python 3.10 ---------------------- +* The ``PY_SSIZE_T_CLEAN`` macro must now be defined to use + :c:func:`PyArg_ParseTuple` and :c:func:`Py_BuildValue` formats which use + ``#``: ``es#``, ``et#``, ``s#``, ``u#``, ``y#``, ``z#``, ``U#`` and ``Z#``. + See :ref:`Parsing arguments and building values + ` and the :pep:`353`. + (Contributed by Victor Stinner in :issue:`40943`.) + * Since :c:func:`Py_TYPE()` is changed to the inline static function, ``Py_TYPE(obj) = new_type`` must be replaced with ``Py_SET_TYPE(obj, new_type)``: - see :c:func:`Py_SET_TYPE()` (available since Python 3.9). + see :c:func:`Py_SET_TYPE()` (available since Python 3.9). For backward + compatibility, this macro can be used:: + + #if PY_VERSION_HEX < 0x030900A4 + # define Py_SET_TYPE(obj, type) ((Py_TYPE(obj) = (type)), (void)0) + #endif + (Contributed by Dong-hee Na in :issue:`39573`.) +* Since :c:func:`Py_REFCNT()` is changed to the inline static function, + ``Py_REFCNT(obj) = new_refcnt`` must be replaced with ``Py_SET_REFCNT(obj, new_refcnt)``: + see :c:func:`Py_SET_REFCNT()` (available since Python 3.9). For backward + compatibility, this macro can be used:: + + #if PY_VERSION_HEX < 0x030900A4 + # define Py_SET_REFCNT(obj, refcnt) ((Py_REFCNT(obj) = (refcnt)), (void)0) + #endif + + (Contributed by Victor Stinner in :issue:`39573`.) + +* Since :c:func:`Py_SIZE()` is changed to the inline static function, + ``Py_SIZE(obj) = new_size`` must be replaced with ``Py_SET_SIZE(obj, new_size)``: + see :c:func:`Py_SET_SIZE()` (available since Python 3.9). For backward + compatibility, this macro can be used:: + + #if PY_VERSION_HEX < 0x030900A4 + # define Py_SET_SIZE(obj, size) ((Py_SIZE(obj) = (size)), (void)0) + #endif + + (Contributed by Victor Stinner in :issue:`39573`.) + +* Calling :c:func:`PyDict_GetItem` without :term:`GIL` held had been allowed + for historical reason. It is no longer allowed. + (Contributed by Victor Stinner in :issue:`40839`.) + +* ``PyUnicode_FromUnicode(NULL, size)`` and ``PyUnicode_FromStringAndSize(NULL, size)`` + raise ``DeprecationWarning`` now. Use :c:func:`PyUnicode_New` to allocate + Unicode object without initial data. + (Contributed by Inada Naoki in :issue:`36346`.) Removed ------- + +* ``PyObject_AsCharBuffer()``, ``PyObject_AsReadBuffer()``, ``PyObject_CheckReadBuffer()``, + and ``PyObject_AsWriteBuffer()`` are removed. Please migrate to new buffer protocol; + :c:func:`PyObject_GetBuffer` and :c:func:`PyBuffer_Release`. + (Contributed by Inada Naoki in :issue:`41103`.) + +* Removed ``Py_UNICODE_str*`` functions manipulating ``Py_UNICODE*`` strings. + (Contributed by Inada Naoki in :issue:`41123`.) + + * ``Py_UNICODE_strlen``: use :c:func:`PyUnicode_GetLength` or + :c:macro:`PyUnicode_GET_LENGTH` + * ``Py_UNICODE_strcat``: use :c:func:`PyUnicode_CopyCharacters` or + :c:func:`PyUnicode_FromFormat` + * ``Py_UNICODE_strcpy``, ``Py_UNICODE_strncpy``: use + :c:func:`PyUnicode_CopyCharacters` or :c:func:`PyUnicode_Substring` + * ``Py_UNICODE_strcmp``: use :c:func:`PyUnicode_Compare` + * ``Py_UNICODE_strncmp``: use :c:func:`PyUnicode_Tailmatch` + * ``Py_UNICODE_strchr``, ``Py_UNICODE_strrchr``: use + :c:func:`PyUnicode_FindChar` + +* Removed ``PyUnicode_GetMax()``. Please migrate to new (:pep:`393`) APIs. + (Contributed by Inada Naoki in :issue:`41103`.) + +* Removed ``PyLong_FromUnicode()``. Please migrate to :c:func:`PyLong_FromUnicodeObject`. + (Contributed by Inada Naoki in :issue:`41103`.) + +* Removed ``PyUnicode_AsUnicodeCopy()``. Please use :c:func:`PyUnicode_AsUCS4Copy` or + :c:func:`PyUnicode_AsWideCharString` + (Contributed by Inada Naoki in :issue:`41103`.) diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index d72fea2c679..c2db9bc74cc 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -113,7 +113,7 @@ PEP 616: New removeprefix() and removesuffix() string methods to easily remove an unneeded prefix or a suffix from a string. Corresponding ``bytes``, ``bytearray``, and ``collections.UserString`` methods have also been added. See :pep:`616` for a full description. (Contributed by Dennis Sweeney in -:issue:`18939`.) +:issue:`39939`.) PEP 585: Builtin Generic Types ------------------------------ @@ -156,7 +156,7 @@ back to the LL(1) parser using a command line switch (``-X oldparser``) or an environment variable (``PYTHONOLDPARSER=1``). See :pep:`617` for more details. (Contributed by Guido van Rossum, -Pablo Galindo and Lysandros Nikolau in :issue:`40334`.) +Pablo Galindo and Lysandros Nikolaou in :issue:`40334`.) Other Language Changes @@ -245,6 +245,14 @@ PyPI and maintained by the CPython core team. PEP written and implemented by Paul Ganssle +graphlib +--------- + +Add the :mod:`graphlib` that contains the :class:`graphlib.TopologicalSorter` class +to offer functionality to perform topological sorting of graphs. (Contributed by Pablo +Galindo, Tim Peters and Larry Hastings in :issue:`17005`.) + + Improved Modules ================ @@ -352,13 +360,6 @@ ftplib if the given timeout for their constructor is zero to prevent the creation of a non-blocking socket. (Contributed by Dong-hee Na in :issue:`39259`.) -functools ---------- - -Add the :class:`functools.TopologicalSorter` class to offer functionality to perform -topological sorting of graphs. (Contributed by Pablo Galindo, Tim Peters and Larry -Hastings in :issue:`17005`.) - gc -- @@ -552,16 +553,21 @@ sys --- Add a new :attr:`sys.platlibdir` attribute: name of the platform-specific -library directory. It is used to build the path of platform-specific dynamic -libraries and the path of the standard library. It is equal to ``"lib"`` on -most platforms. On Fedora and SuSE, it is equal to ``"lib64"`` on 64-bit -platforms. +library directory. It is used to build the path of standard library and the +paths of installed extension modules. It is equal to ``"lib"`` on most +platforms. On Fedora and SuSE, it is equal to ``"lib64"`` on 64-bit platforms. (Contributed by Jan MatÄ›jek, MatÄ›j Cepl, Charalampos Stratakis and Victor Stinner in :issue:`1294959`.) Previously, :attr:`sys.stderr` was block-buffered when non-interactive. Now ``stderr`` defaults to always being line-buffered. (Contributed by Jendrik Seipp in :issue:`13601`.) +tracemalloc +----------- + +Added :func:`tracemalloc.reset_peak` to set the peak size of traced memory +blocks to the current size, to measure the peak of specific pieces of code. +(Contributed by Huon Wilson in :issue:`40630`.) typing ------ @@ -679,6 +685,10 @@ in nanoseconds. The benchmarks were measured on an running the macOS 64-bit builds found at `python.org `_. +* A number of Python builtins (:class:`range`, :class:`tuple`, :class:`set`, :class:`frozenset`, :class:`list`, :class:`dict`) + are now sped up by using :pep:`590` vectorcall protocol. + (Contributed by Dong-hee Na, Mark Shannon, Jeroen Demeyer and Petr Viktorin in :issue:`37207`.) + Deprecated ========== @@ -693,9 +703,10 @@ Deprecated Python versions it will raise a :exc:`TypeError` for all floats. (Contributed by Serhiy Storchaka in :issue:`37315`.) -* The :mod:`parser` module is deprecated and will be removed in future versions - of Python. For the majority of use cases, users can leverage the Abstract Syntax - Tree (AST) generation and compilation stage, using the :mod:`ast` module. +* The :mod:`parser` and :mod:`symbol` modules are deprecated and will be + removed in future versions of Python. For the majority of use cases, + users can leverage the Abstract Syntax Tree (AST) generation and compilation + stage, using the :mod:`ast` module. * Using :data:`NotImplemented` in a boolean context has been deprecated, as it is almost exclusively the result of incorrect rich comparator @@ -762,6 +773,9 @@ Deprecated `parso`_. (Contributed by Carl Meyer in :issue:`40360`.) +* The *random* parameter of :func:`random.shuffle` has been deprecated. + (Contributed by Raymond Hettinger in :issue:`40465`) + .. _LibCST: https://libcst.readthedocs.io/ .. _parso: https://parso.readthedocs.io/ @@ -816,11 +830,6 @@ Removed module have been removed. They were deprecated in Python 3.2. Use ``iter(x)`` or ``list(x)`` instead of ``x.getchildren()`` and ``x.iter()`` or ``list(x.iter())`` instead of ``x.getiterator()``. - The ``xml.etree.cElementTree`` module has been removed, - use the :mod:`xml.etree.ElementTree` module instead. - Since Python 3.3 the ``xml.etree.cElementTree`` module has been deprecated, - the ``xml.etree.ElementTree`` module uses a fast implementation whenever - available. (Contributed by Serhiy Storchaka in :issue:`36543`.) * The old :mod:`plistlib` API has been removed, it was deprecated since Python @@ -829,9 +838,6 @@ Removed removed, standard :class:`bytes` objects are always used instead. (Contributed by Jon Janzen in :issue:`36409`.) -* The C function ``PyThreadState_DeleteCurrent()`` has been removed. It was not documented. - (Contributed by Joannah Nanjekye in :issue:`37878`.) - * The C function ``PyGen_NeedsFinalizing`` has been removed. It was not documented, tested, or used anywhere within CPython after the implementation of :pep:`442`. Patch by Joannah Nanjekye. @@ -876,6 +882,11 @@ Removed deprecated since 2006, and only returning ``False`` when it's called. (Contributed by Batuhan Taskaya in :issue:`40208`) +* The :meth:`asyncio.Task.current_task` and :meth:`asyncio.Task.all_tasks` have + have been removed. They were deprecated since Python 3.7 and you can use + :func:`asyncio.current_task` and :func:`asyncio.all_tasks` instead. + (Contributed by Rémi Lapeyre in :issue:`40967`) + Porting to Python 3.9 ===================== @@ -933,6 +944,55 @@ Changes in the Python API (Contributed by Inada Naoki in :issue:`34538`.) +Changes in the C API +-------------------- + +* Instances of heap-allocated types (such as those created with + :c:func:`PyType_FromSpec` and similar APIs) hold a reference to their type + object since Python 3.8. As indicated in the "Changes in the C API" of Python + 3.8, for the vast majority of cases, there should be no side effect but for + types that have a custom :c:member:`~PyTypeObject.tp_traverse` function, + ensure that all custom ``tp_traverse`` functions of heap-allocated types + visit the object's type. + + Example: + + .. code-block:: c + + int + foo_traverse(foo_struct *self, visitproc visit, void *arg) { + // Rest of the traverse function + #if PY_VERSION_HEX >= 0x03090000 + // This was not needed before Python 3.9 (Python issue 35810 and 40217) + Py_VISIT(Py_TYPE(self)); + #endif + } + + If your traverse function delegates to ``tp_traverse`` of its base class + (or another type), ensure that ``Py_TYPE(self)`` is visited only once. + Note that only heap types are expected to visit the type in ``tp_traverse``. + + For example, if your ``tp_traverse`` function includes: + + .. code-block:: c + + base->tp_traverse(self, visit, arg) + + then add: + + .. code-block:: c + + #if PY_VERSION_HEX >= 0x03090000 + // This was not needed before Python 3.9 (Python issue 35810 and 40217) + if (base->tp_flags & Py_TPFLAGS_HEAPTYPE) { + // a heap type's tp_traverse already visited Py_TYPE(self) + } else { + Py_VISIT(Py_TYPE(self)); + } + #else + + (See :issue:`35810` and :issue:`40217` for more information.) + CPython bytecode changes ------------------------ @@ -1042,6 +1102,16 @@ Porting to Python 3.9 and refers to a constant string. (Contributed by Serhiy Storchaka in :issue:`38650`.) +* The :c:type:`PyGC_Head` structure is now opaque. It is only defined in the + internal C API (``pycore_gc.h``). + (Contributed by Victor Stinner in :issue:`40241`.) + +* The ``Py_UNICODE_COPY``, ``Py_UNICODE_FILL``, ``PyUnicode_WSTR_LENGTH``, + :c:func:`PyUnicode_FromUnicode`, :c:func:`PyUnicode_AsUnicode`, + ``_PyUnicode_AsUnicode``, and :c:func:`PyUnicode_AsUnicodeAndSize` are + marked as deprecated in C. They have been deprecated by :pep:`393` since + Python 3.3. + (Contributed by Inada Naoki in :issue:`36346`.) Removed ------- @@ -1059,6 +1129,8 @@ Removed * Exclude the following functions from the limited C API: + * ``PyThreadState_DeleteCurrent()`` + (Contributed by Joannah Nanjekye in :issue:`37878`.) * ``_Py_CheckRecursionLimit`` * ``_Py_NewReference()`` * ``_Py_ForgetReference()`` @@ -1108,3 +1180,8 @@ Removed * Remove ``_PyUnicode_ClearStaticStrings()`` function. (Contributed by Victor Stinner in :issue:`39465`.) + +* Remove ``Py_UNICODE_MATCH``. It has been deprecated by :pep:`393`, and + broken since Python 3.3. The :c:func:`PyUnicode_Tailmatch` function can be + used instead. + (Contributed by Inada Naoki in :issue:`36346`.) diff --git a/Grammar/python.gram b/Grammar/python.gram index 19d9bb36fed..1cba1140746 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -1,6 +1,5 @@ -# Simplified grammar for Python +# PEG grammar for Python -@bytecode True @trailer ''' void * _PyPegen_parse(Parser *p) @@ -92,9 +91,9 @@ assignment[stmt_ty]: | a=('(' b=single_target ')' { b } | single_subscript_attribute_target) ':' b=expression c=['=' d=annotated_rhs { d }] { CHECK_VERSION(6, "Variable annotations syntax is", _Py_AnnAssign(a, b, c, 0, EXTRA)) } - | a=(z=star_targets '=' { z })+ b=(yield_expr | star_expressions) tc=[TYPE_COMMENT] { + | a=(z=star_targets '=' { z })+ b=(yield_expr | star_expressions) !'=' tc=[TYPE_COMMENT] { _Py_Assign(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) } - | a=single_target b=augassign c=(yield_expr | star_expressions) { + | a=single_target b=augassign ~ c=(yield_expr | star_expressions) { _Py_AugAssign(a, b->kind, c, EXTRA) } | invalid_assignment @@ -122,7 +121,9 @@ yield_stmt[stmt_ty]: y=yield_expr { _Py_Expr(y, EXTRA) } assert_stmt[stmt_ty]: 'assert' a=expression b=[',' z=expression { z }] { _Py_Assert(a, b, EXTRA) } -del_stmt[stmt_ty]: 'del' a=del_targets { _Py_Delete(a, EXTRA) } +del_stmt[stmt_ty]: + | 'del' a=del_targets &(';' | NEWLINE) { _Py_Delete(a, EXTRA) } + | invalid_del_stmt import_stmt[stmt_ty]: import_name | import_from import_name[stmt_ty]: 'import' a=dotted_as_names { _Py_Import(a, EXTRA) } @@ -165,10 +166,11 @@ while_stmt[stmt_ty]: | 'while' a=named_expression ':' b=block c=[else_block] { _Py_While(a, b, c, EXTRA) } for_stmt[stmt_ty]: - | 'for' t=star_targets 'in' ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { + | 'for' t=star_targets 'in' ~ ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { _Py_For(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA) } - | ASYNC 'for' t=star_targets 'in' ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { + | ASYNC 'for' t=star_targets 'in' ~ ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { CHECK_VERSION(5, "Async for loops are", _Py_AsyncFor(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA)) } + | invalid_for_target with_stmt[stmt_ty]: | 'with' '(' a=','.with_item+ ','? ')' ':' b=block { @@ -180,7 +182,9 @@ with_stmt[stmt_ty]: | ASYNC 'with' a=','.with_item+ ':' tc=[TYPE_COMMENT] b=block { CHECK_VERSION(5, "Async with statements are", _Py_AsyncWith(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA)) } with_item[withitem_ty]: - | e=expression o=['as' t=target { t }] { _Py_withitem(e, o, p->arena) } + | e=expression 'as' t=target &(',' | ')' | ':') { _Py_withitem(e, t, p->arena) } + | invalid_with_item + | e=expression { _Py_withitem(e, NULL, p->arena) } try_stmt[stmt_ty]: | 'try' ':' b=block f=finally_block { _Py_Try(b, NULL, NULL, f, EXTRA) } @@ -312,7 +316,7 @@ star_named_expression[expr_ty]: | '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) } | named_expression named_expression[expr_ty]: - | a=NAME ':=' b=expression { _Py_NamedExpr(CHECK(_PyPegen_set_expr_context(p, a, Store)), b, EXTRA) } + | a=NAME ':=' ~ b=expression { _Py_NamedExpr(CHECK(_PyPegen_set_expr_context(p, a, Store)), b, EXTRA) } | expression !':=' | invalid_named_expression @@ -329,7 +333,11 @@ expression[expr_ty] (memo): | lambdef lambdef[expr_ty]: - | 'lambda' a=[lambda_parameters] ':' b=expression { _Py_Lambda((a) ? a : CHECK(_PyPegen_empty_arguments(p)), b, EXTRA) } + | 'lambda' a=[lambda_params] ':' b=expression { _Py_Lambda((a) ? a : CHECK(_PyPegen_empty_arguments(p)), b, EXTRA) } + +lambda_params[arguments_ty]: + | invalid_lambda_parameters + | lambda_parameters # lambda_parameters etc. duplicates parameters but without annotations # or type comments, and if there's no comma after a parameter, we expect @@ -473,7 +481,6 @@ atom[expr_ty]: | 'True' { _Py_Constant(Py_True, NULL, EXTRA) } | 'False' { _Py_Constant(Py_False, NULL, EXTRA) } | 'None' { _Py_Constant(Py_None, NULL, EXTRA) } - | '__new_parser__' { RAISE_SYNTAX_ERROR("You found it!") } | &STRING strings | NUMBER | &'(' (tuple | group | genexp) @@ -485,18 +492,20 @@ strings[expr_ty] (memo): a=STRING+ { _PyPegen_concatenate_strings(p, a) } list[expr_ty]: | '[' a=[star_named_expressions] ']' { _Py_List(a, Load, EXTRA) } listcomp[expr_ty]: - | '[' a=named_expression b=for_if_clauses ']' { _Py_ListComp(a, b, EXTRA) } + | '[' a=named_expression ~ b=for_if_clauses ']' { _Py_ListComp(a, b, EXTRA) } | invalid_comprehension tuple[expr_ty]: | '(' a=[y=star_named_expression ',' z=[star_named_expressions] { _PyPegen_seq_insert_in_front(p, y, z) } ] ')' { _Py_Tuple(a, Load, EXTRA) } -group[expr_ty]: '(' a=(yield_expr | named_expression) ')' { a } +group[expr_ty]: + | '(' a=(yield_expr | named_expression) ')' { a } + | invalid_group genexp[expr_ty]: - | '(' a=expression b=for_if_clauses ')' { _Py_GeneratorExp(a, b, EXTRA) } + | '(' a=expression ~ b=for_if_clauses ')' { _Py_GeneratorExp(a, b, EXTRA) } | invalid_comprehension set[expr_ty]: '{' a=expressions_list '}' { _Py_Set(a, EXTRA) } setcomp[expr_ty]: - | '{' a=expression b=for_if_clauses '}' { _Py_SetComp(a, b, EXTRA) } + | '{' a=expression ~ b=for_if_clauses '}' { _Py_SetComp(a, b, EXTRA) } | invalid_comprehension dict[expr_ty]: | '{' a=[double_starred_kvpairs] '}' { @@ -512,10 +521,11 @@ kvpair[KeyValuePair*]: a=expression ':' b=expression { _PyPegen_key_value_pair(p for_if_clauses[asdl_seq*]: | for_if_clause+ for_if_clause[comprehension_ty]: - | ASYNC 'for' a=star_targets 'in' b=disjunction c=('if' z=disjunction { z })* { + | ASYNC 'for' a=star_targets 'in' ~ b=disjunction c=('if' z=disjunction { z })* { CHECK_VERSION(6, "Async comprehensions are", _Py_comprehension(a, b, c, 1, p->arena)) } - | 'for' a=star_targets 'in' b=disjunction c=('if' z=disjunction { z })* { + | 'for' a=star_targets 'in' ~ b=disjunction c=('if' z=disjunction { z })* { _Py_comprehension(a, b, c, 0, p->arena) } + | invalid_for_target yield_expr[expr_ty]: | 'yield' 'from' a=expression { _Py_YieldFrom(a, EXTRA) } @@ -585,19 +595,15 @@ single_subscript_attribute_target[expr_ty]: | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) } del_targets[asdl_seq*]: a=','.del_target+ [','] { a } -# The lookaheads to del_target_end ensure that we don't match expressions where a prefix of the -# expression matches our rule, thereby letting these cases fall through to invalid_del_target. del_target[expr_ty] (memo): - | a=t_primary '.' b=NAME &del_target_end { _Py_Attribute(a, b->v.Name.id, Del, EXTRA) } - | a=t_primary '[' b=slices ']' &del_target_end { _Py_Subscript(a, b, Del, EXTRA) } + | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Del, EXTRA) } + | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Del, EXTRA) } | del_t_atom del_t_atom[expr_ty]: - | a=NAME &del_target_end { _PyPegen_set_expr_context(p, a, Del) } + | a=NAME { _PyPegen_set_expr_context(p, a, Del) } | '(' a=del_target ')' { _PyPegen_set_expr_context(p, a, Del) } | '(' a=[del_targets] ')' { _Py_Tuple(a, Del, EXTRA) } | '[' a=[del_targets] ']' { _Py_List(a, Del, EXTRA) } - | invalid_del_target -del_target_end: ')' | ']' | ',' | ';' | NEWLINE targets[asdl_seq*]: a=','.target+ [','] { a } target[expr_ty] (memo): @@ -640,23 +646,32 @@ invalid_named_expression: RAISE_SYNTAX_ERROR_KNOWN_LOCATION( a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) } invalid_assignment: - | a=list ':' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not list) can be annotated") } - | a=tuple ':' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") } - | a=star_named_expression ',' star_named_expressions* ':' { - RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") } - | a=expression ':' expression ['=' annotated_rhs] { - RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "illegal target for annotation") } - | a=star_expressions '=' (yield_expr | star_expressions) { + | a=invalid_ann_assign_target ':' expression { RAISE_SYNTAX_ERROR_KNOWN_LOCATION( - _PyPegen_get_invalid_target(a), - "cannot assign to %s", _PyPegen_get_expr_name(_PyPegen_get_invalid_target(a))) } + a, + "only single target (not %s) can be annotated", + _PyPegen_get_expr_name(a) + )} + | a=star_named_expression ',' star_named_expressions* ':' expression { + RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") } + | a=expression ':' expression { + RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "illegal target for annotation") } + | (star_targets '=')* a=star_expressions '=' { + RAISE_SYNTAX_ERROR_INVALID_TARGET(STAR_TARGETS, a) } + | (star_targets '=')* a=yield_expr '=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "assignment to yield expression not possible") } | a=star_expressions augassign (yield_expr | star_expressions) { RAISE_SYNTAX_ERROR_KNOWN_LOCATION( - a, + a, "'%s' is an illegal expression for augmented assignment", _PyPegen_get_expr_name(a) )} - +invalid_ann_assign_target[expr_ty]: + | list + | tuple + | '(' a=invalid_ann_assign_target ')' { a } +invalid_del_stmt: + | 'del' a=star_expressions { + RAISE_SYNTAX_ERROR_INVALID_TARGET(DEL_TARGETS, a) } invalid_block: | NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") } invalid_comprehension: @@ -668,6 +683,9 @@ invalid_dict_comprehension: invalid_parameters: | param_no_default* (slash_with_default | param_with_default+) param_no_default { RAISE_SYNTAX_ERROR("non-default argument follows default argument") } +invalid_lambda_parameters: + | lambda_param_no_default* (lambda_slash_with_default | lambda_param_with_default+) lambda_param_no_default { + RAISE_SYNTAX_ERROR("non-default argument follows default argument") } invalid_star_etc: | '*' (')' | ',' (')' | '**')) { RAISE_SYNTAX_ERROR("named arguments must follow bare *") } | '*' ',' TYPE_COMMENT { RAISE_SYNTAX_ERROR("bare * has associated type comment") } @@ -676,9 +694,17 @@ invalid_lambda_star_etc: invalid_double_type_comments: | TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT { RAISE_SYNTAX_ERROR("Cannot have two type comments on def") } -invalid_del_target: - | a=star_expression &del_target_end { - RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot delete %s", _PyPegen_get_expr_name(a)) } +invalid_with_item: + | expression 'as' a=expression { + RAISE_SYNTAX_ERROR_INVALID_TARGET(STAR_TARGETS, a) } + +invalid_for_target: + | ASYNC? 'for' a=star_expressions { + RAISE_SYNTAX_ERROR_INVALID_TARGET(FOR_TARGETS, a) } + +invalid_group: + | '(' a=starred_expression ')' { + RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "can't use starred expression here") } invalid_import_from_targets: | import_from_as_names ',' { RAISE_SYNTAX_ERROR("trailing comma not allowed without surrounding parentheses") } diff --git a/Include/Python.h b/Include/Python.h index dcd0a57ac1f..57f71d41d8d 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -141,6 +141,7 @@ #include "modsupport.h" #include "compile.h" #include "pythonrun.h" +#include "parser_interface.h" #include "pylifecycle.h" #include "ceval.h" #include "sysmodule.h" diff --git a/Include/abstract.h b/Include/abstract.h index bb51c668ac6..a23b7dc78f4 100644 --- a/Include/abstract.h +++ b/Include/abstract.h @@ -309,53 +309,6 @@ PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key); PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key); -/* === Old Buffer API ============================================ */ - -/* FIXME: usage of these should all be replaced in Python itself - but for backwards compatibility we will implement them. - Their usage without a corresponding "unlock" mechanism - may create issues (but they would already be there). */ - -/* Takes an arbitrary object which must support the (character, single segment) - buffer interface and returns a pointer to a read-only memory location - useable as character based input for subsequent processing. - - Return 0 on success. buffer and buffer_len are only set in case no error - occurs. Otherwise, -1 is returned and an exception set. */ -Py_DEPRECATED(3.0) -PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj, - const char **buffer, - Py_ssize_t *buffer_len); - -/* Checks whether an arbitrary object supports the (character, single segment) - buffer interface. - - Returns 1 on success, 0 on failure. */ -Py_DEPRECATED(3.0) PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj); - -/* Same as PyObject_AsCharBuffer() except that this API expects (readable, - single segment) buffer interface and returns a pointer to a read-only memory - location which can contain arbitrary data. - - 0 is returned on success. buffer and buffer_len are only set in case no - error occurs. Otherwise, -1 is returned and an exception set. */ -Py_DEPRECATED(3.0) -PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj, - const void **buffer, - Py_ssize_t *buffer_len); - -/* Takes an arbitrary object which must support the (writable, single segment) - buffer interface and returns a pointer to a writable memory location in - buffer of size 'buffer_len'. - - Return 0 on success. buffer and buffer_len are only set in case no error - occurs. Otherwise, -1 is returned and an exception set. */ -Py_DEPRECATED(3.0) -PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj, - void **buffer, - Py_ssize_t *buffer_len); - - /* === New Buffer API ============================================ */ /* Takes an arbitrary object and returns the result of calling diff --git a/Include/ast.h b/Include/ast.h index a8c52af786b..de42a3b5e6f 100644 --- a/Include/ast.h +++ b/Include/ast.h @@ -6,19 +6,8 @@ extern "C" { #endif #include "Python-ast.h" /* mod_ty */ -#include "node.h" /* node */ PyAPI_FUNC(int) PyAST_Validate(mod_ty); -PyAPI_FUNC(mod_ty) PyAST_FromNode( - const node *n, - PyCompilerFlags *flags, - const char *filename, /* decoded from the filesystem encoding */ - PyArena *arena); -PyAPI_FUNC(mod_ty) PyAST_FromNodeObject( - const node *n, - PyCompilerFlags *flags, - PyObject *filename, - PyArena *arena); /* _PyAST_ExprAsUnicode is defined in ast_unparse.c */ PyAPI_FUNC(PyObject *) _PyAST_ExprAsUnicode(expr_ty); diff --git a/Include/bitset.h b/Include/bitset.h deleted file mode 100644 index 6a2ac9787ea..00000000000 --- a/Include/bitset.h +++ /dev/null @@ -1,23 +0,0 @@ - -#ifndef Py_BITSET_H -#define Py_BITSET_H -#ifdef __cplusplus -extern "C" { -#endif - -/* Bitset interface */ - -#define BYTE char -typedef BYTE *bitset; - -#define testbit(ss, ibit) (((ss)[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0) - -#define BITSPERBYTE (8*sizeof(BYTE)) -#define BIT2BYTE(ibit) ((ibit) / BITSPERBYTE) -#define BIT2SHIFT(ibit) ((ibit) % BITSPERBYTE) -#define BIT2MASK(ibit) (1 << BIT2SHIFT(ibit)) - -#ifdef __cplusplus -} -#endif -#endif /* !Py_BITSET_H */ diff --git a/Include/ceval.h b/Include/ceval.h index df5253900ee..0f372e2044a 100644 --- a/Include/ceval.h +++ b/Include/ceval.h @@ -128,8 +128,12 @@ PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *); Py_DEPRECATED(3.9) PyAPI_FUNC(int) PyEval_ThreadsInitialized(void); Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void); +/* PyEval_AcquireLock() and PyEval_ReleaseLock() are part of stable ABI. + * They will be removed from this header file in the future version. + * But they will be remained in ABI until Python 4.0. + */ Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_AcquireLock(void); -/* Py_DEPRECATED(3.2) */ PyAPI_FUNC(void) PyEval_ReleaseLock(void); +Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_ReleaseLock(void); PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate); PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate); diff --git a/Include/compile.h b/Include/compile.h index 12417ce8054..4dd5435ce71 100644 --- a/Include/compile.h +++ b/Include/compile.h @@ -8,10 +8,6 @@ extern "C" { #endif /* Public interface */ -struct _node; /* Declare the existence of this type */ -PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *); -/* XXX (ncoghlan): Unprefixed type name in a public API! */ - #define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \ CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \ CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \ diff --git a/Include/cpython/abstract.h b/Include/cpython/abstract.h index 7bc80833a74..b5b6e481978 100644 --- a/Include/cpython/abstract.h +++ b/Include/cpython/abstract.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - /* === Object Protocol ================================================== */ #ifdef PY_SSIZE_T_CLEAN @@ -379,6 +375,5 @@ PyAPI_FUNC(void) _Py_add_one_to_index_C(int nd, Py_ssize_t *index, /* Convert Python int to Py_ssize_t. Do nothing if the argument is None. */ PyAPI_FUNC(int) _Py_convert_optional_to_ssize_t(PyObject *, void *); -#ifdef __cplusplus -} -#endif +/* Same as PyNumber_Index but can return an instance of a subclass of int. */ +PyAPI_FUNC(PyObject *) _PyNumber_Index(PyObject *o); \ No newline at end of file diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index e1922a677bd..06338928f67 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *); PyAPI_DATA(int) _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg); PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *); @@ -32,7 +28,3 @@ PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc); PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *); PyAPI_FUNC(int) _PyEval_SliceIndexNotNone(PyObject *, Py_ssize_t *); - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/dictobject.h b/Include/cpython/dictobject.h index e33a0d156fe..ffe0e97fb35 100644 --- a/Include/cpython/dictobject.h +++ b/Include/cpython/dictobject.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - typedef struct _dictkeysobject PyDictKeysObject; /* The ma_values pointer is NULL for a combined table @@ -86,7 +82,3 @@ typedef struct { PyAPI_FUNC(PyObject *) _PyDictView_New(PyObject *, PyTypeObject *); PyAPI_FUNC(PyObject *) _PyDictView_Intersect(PyObject* self, PyObject *other); - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/fileobject.h b/Include/cpython/fileobject.h index 57eac13c064..4f2408c7e87 100644 --- a/Include/cpython/fileobject.h +++ b/Include/cpython/fileobject.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - PyAPI_FUNC(char *) Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000 @@ -26,7 +22,3 @@ typedef PyObject * (*Py_OpenCodeHookFunction)(PyObject *, void *); PyAPI_FUNC(PyObject *) PyFile_OpenCode(const char *utf8path); PyAPI_FUNC(PyObject *) PyFile_OpenCodeObject(PyObject *path); PyAPI_FUNC(int) PyFile_SetOpenCodeHook(Py_OpenCodeHookFunction hook, void *userData); - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/frameobject.h b/Include/cpython/frameobject.h index 36a51baae87..c76fbe0616c 100644 --- a/Include/cpython/frameobject.h +++ b/Include/cpython/frameobject.h @@ -4,10 +4,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { int b_type; /* what kind of block this is */ int b_handler; /* where to jump to find handler */ @@ -78,7 +74,3 @@ PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *); PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out); PyAPI_FUNC(PyFrameObject *) PyFrame_GetBack(PyFrameObject *frame); - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/import.h b/Include/cpython/import.h index c1b47121f12..3b20a74c855 100644 --- a/Include/cpython/import.h +++ b/Include/cpython/import.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - PyMODINIT_FUNC PyInit__imp(void); PyAPI_FUNC(int) _PyImport_IsInitialized(PyInterpreterState *); @@ -44,7 +40,3 @@ struct _frozen { collection of frozen modules: */ PyAPI_DATA(const struct _frozen *) PyImport_FrozenModules; - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/initconfig.h b/Include/cpython/initconfig.h index df93a5539d4..bbe83876777 100644 --- a/Include/cpython/initconfig.h +++ b/Include/cpython/initconfig.h @@ -1,9 +1,6 @@ #ifndef Py_PYCORECONFIG_H #define Py_PYCORECONFIG_H #ifndef Py_LIMITED_API -#ifdef __cplusplus -extern "C" { -#endif /* --- PyStatus ----------------------------------------------- */ @@ -147,10 +144,6 @@ typedef struct { Set to 1 by -X faulthandler and PYTHONFAULTHANDLER. -1 means unset. */ int faulthandler; - /* Enable PEG parser? - 1 by default, set to 0 by -X oldparser and PYTHONOLDPARSER */ - int _use_peg_parser; - /* Enable tracemalloc? Set by -X tracemalloc=N and PYTHONTRACEMALLOC. -1 means unset */ int tracemalloc; @@ -388,6 +381,7 @@ typedef struct { wchar_t *base_prefix; /* sys.base_prefix */ wchar_t *exec_prefix; /* sys.exec_prefix */ wchar_t *base_exec_prefix; /* sys.base_exec_prefix */ + wchar_t *platlibdir; /* sys.platlibdir */ /* --- Parameter only used by Py_Main() ---------- */ @@ -413,6 +407,16 @@ typedef struct { /* If non-zero, disallow threads, subprocesses, and fork. Default: 0. */ int _isolated_interpreter; + + /* The list of the original command line arguments passed to the Python + executable. + + If 'orig_argv' list is empty and 'argv' is not a list only containing an + empty string, PyConfig_Read() copies 'argv' into 'orig_argv' before + modifying 'argv' (if 'parse_argv is non-zero). + + _PyConfig_Write() initializes Py_GetArgcArgv() to this list. */ + PyWideStringList orig_argv; } PyConfig; PyAPI_FUNC(void) PyConfig_InitPythonConfig(PyConfig *config); @@ -438,8 +442,13 @@ PyAPI_FUNC(PyStatus) PyConfig_SetWideStringList(PyConfig *config, PyWideStringList *list, Py_ssize_t length, wchar_t **items); -#ifdef __cplusplus -} -#endif + +/* --- Helper functions --------------------------------------- */ + +/* Get the original command line arguments, before Python modified them. + + See also PyConfig.orig_argv. */ +PyAPI_FUNC(void) Py_GetArgcArgv(int *argc, wchar_t ***argv); + #endif /* !Py_LIMITED_API */ #endif /* !Py_PYCORECONFIG_H */ diff --git a/Include/cpython/interpreteridobject.h b/Include/cpython/interpreteridobject.h index 67ec5873542..5076584209b 100644 --- a/Include/cpython/interpreteridobject.h +++ b/Include/cpython/interpreteridobject.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - /* Interpreter ID Object */ PyAPI_DATA(PyTypeObject) _PyInterpreterID_Type; @@ -13,7 +9,3 @@ PyAPI_DATA(PyTypeObject) _PyInterpreterID_Type; PyAPI_FUNC(PyObject *) _PyInterpreterID_New(int64_t); PyAPI_FUNC(PyObject *) _PyInterpreterState_GetIDObject(PyInterpreterState *); PyAPI_FUNC(PyInterpreterState *) _PyInterpreterID_LookUp(PyObject *); - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/listobject.h b/Include/cpython/listobject.h index 74fe3301a7a..70b9d83d8a2 100644 --- a/Include/cpython/listobject.h +++ b/Include/cpython/listobject.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { PyObject_VAR_HEAD /* Vector of pointers to list elements. list[0] is ob_item[0], etc. */ @@ -36,8 +32,3 @@ PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out); #define PyList_GET_ITEM(op, i) (_PyList_CAST(op)->ob_item[i]) #define PyList_SET_ITEM(op, i, v) (_PyList_CAST(op)->ob_item[i] = (v)) #define PyList_GET_SIZE(op) Py_SIZE(_PyList_CAST(op)) -#define _PyList_ITEMS(op) (_PyList_CAST(op)->ob_item) - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 444f832f5bd..ae3920d4508 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - PyAPI_FUNC(void) _Py_NewReference(PyObject *op); #ifdef Py_TRACE_REFS @@ -13,10 +9,6 @@ PyAPI_FUNC(void) _Py_NewReference(PyObject *op); PyAPI_FUNC(void) _Py_ForgetReference(PyObject *); #endif -/* Update the Python traceback of an object. This function must be called - when a memory block is reused from a free list. */ -PyAPI_FUNC(int) _PyTraceMalloc_NewReference(PyObject *op); - #ifdef Py_REF_DEBUG PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void); #endif @@ -548,7 +540,3 @@ PyAPI_FUNC(void) _PyTrash_end(struct _ts *tstate); * unconditionally */ #define Py_TRASHCAN_SAFE_BEGIN(op) Py_TRASHCAN_BEGIN_CONDITION(op, 1) #define Py_TRASHCAN_SAFE_END(op) Py_TRASHCAN_END - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/objimpl.h b/Include/cpython/objimpl.h index b835936db70..15999a239f7 100644 --- a/Include/cpython/objimpl.h +++ b/Include/cpython/objimpl.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - #define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize ) /* _PyObject_VAR_SIZE returns the number of bytes (as size_t) allocated for a @@ -41,8 +37,9 @@ extern "C" { PyObject *op; op = (PyObject *) Your_Allocator(_PyObject_SIZE(YourTypeStruct)); - if (op == NULL) - return PyErr_NoMemory(); + if (op == NULL) { + return PyErr_NoMemory(); + } PyObject_Init(op, &YourTypeStruct); @@ -55,40 +52,6 @@ extern "C" { the 1st step is performed automatically for you, so in a C++ class constructor you would start directly with PyObject_Init/InitVar. */ - -/* Inline functions trading binary compatibility for speed: - PyObject_INIT() is the fast version of PyObject_Init(), and - PyObject_INIT_VAR() is the fast version of PyObject_InitVar(). - - These inline functions must not be called with op=NULL. */ -static inline PyObject* -_PyObject_INIT(PyObject *op, PyTypeObject *typeobj) -{ - assert(op != NULL); - Py_SET_TYPE(op, typeobj); - if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) { - Py_INCREF(typeobj); - } - _Py_NewReference(op); - return op; -} - -#define PyObject_INIT(op, typeobj) \ - _PyObject_INIT(_PyObject_CAST(op), (typeobj)) - -static inline PyVarObject* -_PyObject_INIT_VAR(PyVarObject *op, PyTypeObject *typeobj, Py_ssize_t size) -{ - assert(op != NULL); - Py_SET_SIZE(op, size); - PyObject_INIT((PyObject *)op, typeobj); - return op; -} - -#define PyObject_INIT_VAR(op, typeobj, size) \ - _PyObject_INIT_VAR(_PyVarObject_CAST(op), (typeobj), (size)) - - /* This function returns the number of allocated memory blocks, regardless of size */ PyAPI_FUNC(Py_ssize_t) _Py_GetAllocatedBlocks(void); @@ -139,7 +102,3 @@ PyAPI_FUNC(PyObject *) _PyObject_GC_Calloc(size_t size); #define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0) PyAPI_FUNC(PyObject **) PyObject_GET_WEAKREFS_LISTPTR(PyObject *op); - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/pyerrors.h b/Include/cpython/pyerrors.h index dd3c2caa0cc..3f347dc2e2d 100644 --- a/Include/cpython/pyerrors.h +++ b/Include/cpython/pyerrors.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - /* Error objects */ /* PyException_HEAD defines the initial segment of every exception class. */ @@ -188,7 +184,3 @@ PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFormat( ...); #define Py_FatalError(message) _Py_FatalErrorFunc(__func__, message) - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/pylifecycle.h b/Include/cpython/pylifecycle.h index eb523b82e18..f38ec5a4ae3 100644 --- a/Include/cpython/pylifecycle.h +++ b/Include/cpython/pylifecycle.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - /* Only used by applications that embed the interpreter and need to * override the standard encoding determination mechanism */ @@ -66,7 +62,3 @@ PyAPI_FUNC(int) _Py_LegacyLocaleDetected(int warn); PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category); PyAPI_FUNC(PyThreadState *) _Py_NewInterpreter(int isolated_subinterpreter); - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/pymem.h b/Include/cpython/pymem.h index 79f063b1217..61d71958458 100644 --- a/Include/cpython/pymem.h +++ b/Include/cpython/pymem.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - PyAPI_FUNC(void *) PyMem_RawMalloc(size_t size); PyAPI_FUNC(void *) PyMem_RawCalloc(size_t nelem, size_t elsize); PyAPI_FUNC(void *) PyMem_RawRealloc(void *ptr, size_t new_size); @@ -102,7 +98,3 @@ PyAPI_FUNC(void) PyMem_SetAllocator(PyMemAllocatorDomain domain, The function does nothing if Python is not compiled is debug mode. */ PyAPI_FUNC(void) PyMem_SetupDebugHooks(void); - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index f292da1d3c6..42a7fc16306 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - #include "cpython/initconfig.h" PyAPI_FUNC(int) _PyInterpreterState_RequiresIDRef(PyInterpreterState *); @@ -257,7 +253,3 @@ typedef int (*crossinterpdatafunc)(PyObject *, struct _xid *); PyAPI_FUNC(int) _PyCrossInterpreterData_RegisterClass(PyTypeObject *, crossinterpdatafunc); PyAPI_FUNC(crossinterpdatafunc) _PyCrossInterpreterData_Lookup(PyObject *); - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/sysmodule.h b/Include/cpython/sysmodule.h index 1802b5b3000..fc4c899b3fe 100644 --- a/Include/cpython/sysmodule.h +++ b/Include/cpython/sysmodule.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - PyAPI_FUNC(PyObject *) _PySys_GetObjectId(_Py_Identifier *key); PyAPI_FUNC(int) _PySys_SetObjectId(_Py_Identifier *key, PyObject *); @@ -18,7 +14,3 @@ PyAPI_FUNC(int) PySys_Audit( const char *argFormat, ...); PyAPI_FUNC(int) PySys_AddAuditHook(Py_AuditHookFunction, void*); - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/traceback.h b/Include/cpython/traceback.h index 837470c3ba2..aac5b42c344 100644 --- a/Include/cpython/traceback.h +++ b/Include/cpython/traceback.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - typedef struct _traceback { PyObject_HEAD struct _traceback *tb_next; @@ -16,7 +12,3 @@ typedef struct _traceback { PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, PyObject *, int, int); PyAPI_FUNC(void) _PyTraceback_Add(const char *, const char *, int); - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/tupleobject.h b/Include/cpython/tupleobject.h index 1565f2a5c3d..51dcd4237be 100644 --- a/Include/cpython/tupleobject.h +++ b/Include/cpython/tupleobject.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { PyObject_VAR_HEAD /* ob_item contains space for 'ob_size' elements. @@ -30,7 +26,3 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *); #define PyTuple_SET_ITEM(op, i, v) (_PyTuple_CAST(op)->ob_item[i] = v) PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out); - -#ifdef __cplusplus -} -#endif diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 4fd674ffea3..49ad32d5d19 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -2,10 +2,6 @@ # error "this header file must not be included directly" #endif -#ifdef __cplusplus -extern "C" { -#endif - /* Py_UNICODE was the native Unicode storage format (code unit) used by Python and represents a single Unicode element in the Unicode type. With PEP 393, Py_UNICODE is deprecated and replaced with a @@ -15,6 +11,8 @@ extern "C" { /* --- Internal Unicode Operations ---------------------------------------- */ +#define USE_UNICODE_WCHAR_CACHE 1 + /* Since splitting on whitespace is an important use case, and whitespace in most situations is solely ASCII whitespace, we optimize for the common case by using a quick look-up table @@ -50,13 +48,18 @@ extern "C" { Py_UNICODE_ISDIGIT(ch) || \ Py_UNICODE_ISNUMERIC(ch)) -#define Py_UNICODE_COPY(target, source, length) \ - memcpy((target), (source), (length)*sizeof(Py_UNICODE)) +Py_DEPRECATED(3.3) static inline void +Py_UNICODE_COPY(Py_UNICODE *target, const Py_UNICODE *source, Py_ssize_t length) { + memcpy(target, source, length * sizeof(Py_UNICODE)); +} -#define Py_UNICODE_FILL(target, value, length) \ - do {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\ - for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\ - } while (0) +Py_DEPRECATED(3.3) static inline void +Py_UNICODE_FILL(Py_UNICODE *target, Py_UNICODE value, Py_ssize_t length) { + Py_ssize_t i; + for (i = 0; i < length; i++) { + target[i] = value; + } +} /* macros to work with surrogates */ #define Py_UNICODE_IS_SURROGATE(ch) (0xD800 <= (ch) && (ch) <= 0xDFFF) @@ -71,14 +74,6 @@ extern "C" { /* low surrogate = bottom 10 bits added to DC00 */ #define Py_UNICODE_LOW_SURROGATE(ch) (0xDC00 + ((ch) & 0x3FF)) -/* Check if substring matches at given offset. The offset must be - valid, and the substring must not be empty. */ - -#define Py_UNICODE_MATCH(string, offset, substring) \ - ((*((string)->wstr + (offset)) == *((substring)->wstr)) && \ - ((*((string)->wstr + (offset) + (substring)->wstr_length-1) == *((substring)->wstr + (substring)->wstr_length-1))) && \ - !memcmp((string)->wstr + (offset), (substring)->wstr, (substring)->wstr_length*sizeof(Py_UNICODE))) - /* --- Unicode Type ------------------------------------------------------- */ /* ASCII-only strings created through PyUnicode_New use the PyASCIIObject @@ -251,10 +246,6 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency( int check_content); /* Fast access macros */ -#define PyUnicode_WSTR_LENGTH(op) \ - (PyUnicode_IS_COMPACT_ASCII(op) ? \ - ((PyASCIIObject*)op)->length : \ - ((PyCompactUnicodeObject*)op)->wstr_length) /* Returns the deprecated Py_UNICODE representation's size in code units (this includes surrogate pairs as 2 units). @@ -449,6 +440,14 @@ enum PyUnicode_Kind { (0xffffU) : \ (0x10ffffU))))) +Py_DEPRECATED(3.3) +static inline Py_ssize_t _PyUnicode_get_wstr_length(PyObject *op) { + return PyUnicode_IS_COMPACT_ASCII(op) ? + ((PyASCIIObject*)op)->length : + ((PyCompactUnicodeObject*)op)->wstr_length; +} +#define PyUnicode_WSTR_LENGTH(op) _PyUnicode_get_wstr_length((PyObject*)op) + /* === Public API ========================================================= */ /* --- Plain Py_UNICODE --------------------------------------------------- */ @@ -547,7 +546,7 @@ PyAPI_FUNC(void) _PyUnicode_FastFill( only allowed if u was set to NULL. The buffer is copied into the new object. */ -/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode( const Py_UNICODE *u, /* Unicode buffer */ Py_ssize_t size /* size of buffer */ ); @@ -576,7 +575,7 @@ PyAPI_FUNC(Py_UCS4) _PyUnicode_FindMaxChar ( Py_UNICODE buffer. If the wchar_t/Py_UNICODE representation is not yet available, this function will calculate it. */ -/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode( PyObject *unicode /* Unicode object */ ); @@ -591,14 +590,11 @@ PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode( If the wchar_t/Py_UNICODE representation is not yet available, this function will calculate it. */ -/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize( PyObject *unicode, /* Unicode object */ Py_ssize_t *size /* location where to save the length */ ); -/* Get the maximum ordinal for a Unicode character. */ -Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void); - /* --- _PyUnicodeWriter API ----------------------------------------------- */ @@ -978,7 +974,7 @@ Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS( */ -/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(int) PyUnicode_EncodeDecimal( +Py_DEPRECATED(3.3) PyAPI_FUNC(int) PyUnicode_EncodeDecimal( Py_UNICODE *s, /* Unicode buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ char *output, /* Output buffer; must have size >= length */ @@ -991,7 +987,7 @@ Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS( Returns a new Unicode string on success, NULL on failure. */ -/* Py_DEPRECATED(3.3) */ +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_TransformDecimalToASCII( Py_UNICODE *s, /* Unicode buffer */ Py_ssize_t length /* Number of Py_UNICODE chars to transform */ @@ -1166,53 +1162,8 @@ PyAPI_FUNC(int) _PyUnicode_IsAlpha( Py_UCS4 ch /* Unicode character */ ); -Py_DEPRECATED(3.3) PyAPI_FUNC(size_t) Py_UNICODE_strlen( - const Py_UNICODE *u - ); - -Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcpy( - Py_UNICODE *s1, - const Py_UNICODE *s2); - -Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcat( - Py_UNICODE *s1, const Py_UNICODE *s2); - -Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strncpy( - Py_UNICODE *s1, - const Py_UNICODE *s2, - size_t n); - -Py_DEPRECATED(3.3) PyAPI_FUNC(int) Py_UNICODE_strcmp( - const Py_UNICODE *s1, - const Py_UNICODE *s2 - ); - -Py_DEPRECATED(3.3) PyAPI_FUNC(int) Py_UNICODE_strncmp( - const Py_UNICODE *s1, - const Py_UNICODE *s2, - size_t n - ); - -Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr( - const Py_UNICODE *s, - Py_UNICODE c - ); - -Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr( - const Py_UNICODE *s, - Py_UNICODE c - ); - PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int); -/* Create a copy of a unicode string ending with a nul character. Return NULL - and raise a MemoryError exception on memory allocation failure, otherwise - return a new allocated buffer (use PyMem_Free() to free the buffer). */ - -Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy( - PyObject *unicode - ); - /* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/ PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*); @@ -1220,8 +1171,7 @@ PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*); and where the hash values are equal (i.e. a very probable match) */ PyAPI_FUNC(int) _PyUnicode_EQ(PyObject *, PyObject *); -PyAPI_FUNC(Py_ssize_t) _PyUnicode_ScanIdentifier(PyObject *); +PyAPI_FUNC(int) _PyUnicode_WideCharString_Converter(PyObject *, void *); +PyAPI_FUNC(int) _PyUnicode_WideCharString_Opt_Converter(PyObject *, void *); -#ifdef __cplusplus -} -#endif +PyAPI_FUNC(Py_ssize_t) _PyUnicode_ScanIdentifier(PyObject *); diff --git a/Include/graminit.h b/Include/graminit.h deleted file mode 100644 index d1027b7a743..00000000000 --- a/Include/graminit.h +++ /dev/null @@ -1,94 +0,0 @@ -/* Generated by Parser/pgen */ - -#define single_input 256 -#define file_input 257 -#define eval_input 258 -#define decorator 259 -#define decorators 260 -#define decorated 261 -#define async_funcdef 262 -#define funcdef 263 -#define parameters 264 -#define typedargslist 265 -#define tfpdef 266 -#define varargslist 267 -#define vfpdef 268 -#define stmt 269 -#define simple_stmt 270 -#define small_stmt 271 -#define expr_stmt 272 -#define annassign 273 -#define testlist_star_expr 274 -#define augassign 275 -#define del_stmt 276 -#define pass_stmt 277 -#define flow_stmt 278 -#define break_stmt 279 -#define continue_stmt 280 -#define return_stmt 281 -#define yield_stmt 282 -#define raise_stmt 283 -#define import_stmt 284 -#define import_name 285 -#define import_from 286 -#define import_as_name 287 -#define dotted_as_name 288 -#define import_as_names 289 -#define dotted_as_names 290 -#define dotted_name 291 -#define global_stmt 292 -#define nonlocal_stmt 293 -#define assert_stmt 294 -#define compound_stmt 295 -#define async_stmt 296 -#define if_stmt 297 -#define while_stmt 298 -#define for_stmt 299 -#define try_stmt 300 -#define with_stmt 301 -#define with_item 302 -#define except_clause 303 -#define suite 304 -#define namedexpr_test 305 -#define test 306 -#define test_nocond 307 -#define lambdef 308 -#define lambdef_nocond 309 -#define or_test 310 -#define and_test 311 -#define not_test 312 -#define comparison 313 -#define comp_op 314 -#define star_expr 315 -#define expr 316 -#define xor_expr 317 -#define and_expr 318 -#define shift_expr 319 -#define arith_expr 320 -#define term 321 -#define factor 322 -#define power 323 -#define atom_expr 324 -#define atom 325 -#define testlist_comp 326 -#define trailer 327 -#define subscriptlist 328 -#define subscript 329 -#define sliceop 330 -#define exprlist 331 -#define testlist 332 -#define dictorsetmaker 333 -#define classdef 334 -#define arglist 335 -#define argument 336 -#define comp_iter 337 -#define sync_comp_for 338 -#define comp_for 339 -#define comp_if 340 -#define encoding_decl 341 -#define yield_expr 342 -#define yield_arg 343 -#define func_body_suite 344 -#define func_type_input 345 -#define func_type 346 -#define typelist 347 diff --git a/Include/grammar.h b/Include/grammar.h deleted file mode 100644 index 4b66b1e9b97..00000000000 --- a/Include/grammar.h +++ /dev/null @@ -1,77 +0,0 @@ - -/* Grammar interface */ - -#ifndef Py_GRAMMAR_H -#define Py_GRAMMAR_H -#ifdef __cplusplus -extern "C" { -#endif - -#include "bitset.h" /* Sigh... */ - -/* A label of an arc */ - -typedef struct { - int lb_type; - const char *lb_str; -} label; - -#define EMPTY 0 /* Label number 0 is by definition the empty label */ - -/* A list of labels */ - -typedef struct { - int ll_nlabels; - const label *ll_label; -} labellist; - -/* An arc from one state to another */ - -typedef struct { - short a_lbl; /* Label of this arc */ - short a_arrow; /* State where this arc goes to */ -} arc; - -/* A state in a DFA */ - -typedef struct { - int s_narcs; - const arc *s_arc; /* Array of arcs */ - - /* Optional accelerators */ - int s_lower; /* Lowest label index */ - int s_upper; /* Highest label index */ - int *s_accel; /* Accelerator */ - int s_accept; /* Nonzero for accepting state */ -} state; - -/* A DFA */ - -typedef struct { - int d_type; /* Non-terminal this represents */ - char *d_name; /* For printing */ - int d_nstates; - state *d_state; /* Array of states */ - bitset d_first; -} dfa; - -/* A grammar */ - -typedef struct { - int g_ndfas; - const dfa *g_dfa; /* Array of DFAs */ - const labellist g_ll; - int g_start; /* Start symbol of the grammar */ - int g_accel; /* Set if accelerators present */ -} grammar; - -/* FUNCTIONS */ -const dfa *PyGrammar_FindDFA(grammar *g, int type); -const char *PyGrammar_LabelRepr(label *lb); -void PyGrammar_AddAccelerators(grammar *g); -void PyGrammar_RemoveAccelerators(grammar *); - -#ifdef __cplusplus -} -#endif -#endif /* !Py_GRAMMAR_H */ diff --git a/Include/internal/pycore_bitutils.h b/Include/internal/pycore_bitutils.h new file mode 100644 index 00000000000..0bd3270fe82 --- /dev/null +++ b/Include/internal/pycore_bitutils.h @@ -0,0 +1,177 @@ +/* Bit and bytes utilities. + + Bytes swap functions, reverse order of bytes: + + - _Py_bswap16(uint16_t) + - _Py_bswap32(uint32_t) + - _Py_bswap64(uint64_t) +*/ + +#ifndef Py_INTERNAL_BITUTILS_H +#define Py_INTERNAL_BITUTILS_H +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef Py_BUILD_CORE +# error "this header requires Py_BUILD_CORE define" +#endif + +#if defined(__clang__) || \ + (defined(__GNUC__) && \ + ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))) + /* __builtin_bswap16() is available since GCC 4.8, + __builtin_bswap32() is available since GCC 4.3, + __builtin_bswap64() is available since GCC 4.3. */ +# define _PY_HAVE_BUILTIN_BSWAP +#endif + +#ifdef _MSC_VER + /* Get _byteswap_ushort(), _byteswap_ulong(), _byteswap_uint64() */ +# include +#endif + +static inline uint16_t +_Py_bswap16(uint16_t word) +{ +#ifdef _PY_HAVE_BUILTIN_BSWAP + return __builtin_bswap16(word); +#elif defined(_MSC_VER) + Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned short)); + return _byteswap_ushort(word); +#else + // Portable implementation which doesn't rely on circular bit shift + return ( ((word & UINT16_C(0x00FF)) << 8) + | ((word & UINT16_C(0xFF00)) >> 8)); +#endif +} + +static inline uint32_t +_Py_bswap32(uint32_t word) +{ +#ifdef _PY_HAVE_BUILTIN_BSWAP + return __builtin_bswap32(word); +#elif defined(_MSC_VER) + Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned long)); + return _byteswap_ulong(word); +#else + // Portable implementation which doesn't rely on circular bit shift + return ( ((word & UINT32_C(0x000000FF)) << 24) + | ((word & UINT32_C(0x0000FF00)) << 8) + | ((word & UINT32_C(0x00FF0000)) >> 8) + | ((word & UINT32_C(0xFF000000)) >> 24)); +#endif +} + +static inline uint64_t +_Py_bswap64(uint64_t word) +{ +#ifdef _PY_HAVE_BUILTIN_BSWAP + return __builtin_bswap64(word); +#elif defined(_MSC_VER) + return _byteswap_uint64(word); +#else + // Portable implementation which doesn't rely on circular bit shift + return ( ((word & UINT64_C(0x00000000000000FF)) << 56) + | ((word & UINT64_C(0x000000000000FF00)) << 40) + | ((word & UINT64_C(0x0000000000FF0000)) << 24) + | ((word & UINT64_C(0x00000000FF000000)) << 8) + | ((word & UINT64_C(0x000000FF00000000)) >> 8) + | ((word & UINT64_C(0x0000FF0000000000)) >> 24) + | ((word & UINT64_C(0x00FF000000000000)) >> 40) + | ((word & UINT64_C(0xFF00000000000000)) >> 56)); +#endif +} + + +// Population count: count the number of 1's in 'x' +// (number of bits set to 1), also known as the hamming weight. +// +// Implementation note. CPUID is not used, to test if x86 POPCNT instruction +// can be used, to keep the implementation simple. For example, Visual Studio +// __popcnt() is not used this reason. The clang and GCC builtin function can +// use the x86 POPCNT instruction if the target architecture has SSE4a or +// newer. +static inline int +_Py_popcount32(uint32_t x) +{ +#if (defined(__clang__) || defined(__GNUC__)) + +#if SIZEOF_INT >= 4 + Py_BUILD_ASSERT(sizeof(x) <= sizeof(unsigned int)); + return __builtin_popcount(x); +#else + // The C standard guarantees that unsigned long will always be big enough + // to hold a uint32_t value without losing information. + Py_BUILD_ASSERT(sizeof(x) <= sizeof(unsigned long)); + return __builtin_popcountl(x); +#endif + +#else + // 32-bit SWAR (SIMD Within A Register) popcount + + // Binary: 0 1 0 1 ... + const uint32_t M1 = 0x55555555; + // Binary: 00 11 00 11. .. + const uint32_t M2 = 0x33333333; + // Binary: 0000 1111 0000 1111 ... + const uint32_t M4 = 0x0F0F0F0F; + // 256**4 + 256**3 + 256**2 + 256**1 + const uint32_t SUM = 0x01010101; + + // Put count of each 2 bits into those 2 bits + x = x - ((x >> 1) & M1); + // Put count of each 4 bits into those 4 bits + x = (x & M2) + ((x >> 2) & M2); + // Put count of each 8 bits into those 8 bits + x = (x + (x >> 4)) & M4; + // Sum of the 4 byte counts + return (uint32_t)((uint64_t)x * (uint64_t)SUM) >> 24; +#endif +} + + +// Return the index of the most significant 1 bit in 'x'. This is the smallest +// integer k such that x < 2**k. Equivalent to floor(log2(x)) + 1 for x != 0. +static inline int +_Py_bit_length(unsigned long x) +{ +#if (defined(__clang__) || defined(__GNUC__)) + if (x != 0) { + // __builtin_clzl() is available since GCC 3.4. + // Undefined behavior for x == 0. + return (int)sizeof(unsigned long) * 8 - __builtin_clzl(x); + } + else { + return 0; + } +#elif defined(_MSC_VER) + // _BitScanReverse() is documented to search 32 bits. + Py_BUILD_ASSERT(sizeof(unsigned long) <= 4); + unsigned long msb; + if (_BitScanReverse(&msb, x)) { + return (int)msb + 1; + } + else { + return 0; + } +#else + const int BIT_LENGTH_TABLE[32] = { + 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 + }; + int msb = 0; + while (x >= 32) { + msb += 6; + x >>= 6; + } + msb += BIT_LENGTH_TABLE[x]; + return msb; +#endif +} + + +#ifdef __cplusplus +} +#endif +#endif /* !Py_INTERNAL_BITUTILS_H */ diff --git a/Include/internal/pycore_byteswap.h b/Include/internal/pycore_byteswap.h deleted file mode 100644 index 5e64704a004..00000000000 --- a/Include/internal/pycore_byteswap.h +++ /dev/null @@ -1,89 +0,0 @@ -/* Bytes swap functions, reverse order of bytes: - - - _Py_bswap16(uint16_t) - - _Py_bswap32(uint32_t) - - _Py_bswap64(uint64_t) -*/ - -#ifndef Py_INTERNAL_BSWAP_H -#define Py_INTERNAL_BSWAP_H -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef Py_BUILD_CORE -# error "this header requires Py_BUILD_CORE define" -#endif - -#if defined(__clang__) || \ - (defined(__GNUC__) && \ - ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))) - /* __builtin_bswap16() is available since GCC 4.8, - __builtin_bswap32() is available since GCC 4.3, - __builtin_bswap64() is available since GCC 4.3. */ -# define _PY_HAVE_BUILTIN_BSWAP -#endif - -#ifdef _MSC_VER - /* Get _byteswap_ushort(), _byteswap_ulong(), _byteswap_uint64() */ -# include -#endif - -static inline uint16_t -_Py_bswap16(uint16_t word) -{ -#ifdef _PY_HAVE_BUILTIN_BSWAP - return __builtin_bswap16(word); -#elif defined(_MSC_VER) - Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned short)); - return _byteswap_ushort(word); -#else - // Portable implementation which doesn't rely on circular bit shift - return ( ((word & UINT16_C(0x00FF)) << 8) - | ((word & UINT16_C(0xFF00)) >> 8)); -#endif -} - -static inline uint32_t -_Py_bswap32(uint32_t word) -{ -#ifdef _PY_HAVE_BUILTIN_BSWAP - return __builtin_bswap32(word); -#elif defined(_MSC_VER) - Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned long)); - return _byteswap_ulong(word); -#else - // Portable implementation which doesn't rely on circular bit shift - return ( ((word & UINT32_C(0x000000FF)) << 24) - | ((word & UINT32_C(0x0000FF00)) << 8) - | ((word & UINT32_C(0x00FF0000)) >> 8) - | ((word & UINT32_C(0xFF000000)) >> 24)); -#endif -} - -static inline uint64_t -_Py_bswap64(uint64_t word) -{ -#ifdef _PY_HAVE_BUILTIN_BSWAP - return __builtin_bswap64(word); -#elif defined(_MSC_VER) - return _byteswap_uint64(word); -#else - // Portable implementation which doesn't rely on circular bit shift - return ( ((word & UINT64_C(0x00000000000000FF)) << 56) - | ((word & UINT64_C(0x000000000000FF00)) << 40) - | ((word & UINT64_C(0x0000000000FF0000)) << 24) - | ((word & UINT64_C(0x00000000FF000000)) << 8) - | ((word & UINT64_C(0x000000FF00000000)) >> 8) - | ((word & UINT64_C(0x0000FF0000000000)) >> 24) - | ((word & UINT64_C(0x00FF000000000000)) >> 40) - | ((word & UINT64_C(0xFF00000000000000)) >> 56)); -#endif -} - - -#ifdef __cplusplus -} -#endif -#endif /* !Py_INTERNAL_BSWAP_H */ - diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index 36899009908..aafb533b57d 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -25,7 +25,7 @@ PyAPI_FUNC(int) _PyEval_AddPendingCall( void *arg); PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyThreadState *tstate); #ifdef HAVE_FORK -extern void _PyEval_ReInitThreads(struct pyruntimestate *runtime); +extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate); #endif PyAPI_FUNC(void) _PyEval_SetCoroutineOriginTrackingDepth( PyThreadState *tstate, diff --git a/Include/internal/pycore_context.h b/Include/internal/pycore_context.h index f665ad5c115..ea4b3c8ea73 100644 --- a/Include/internal/pycore_context.h +++ b/Include/internal/pycore_context.h @@ -37,6 +37,6 @@ struct _pycontexttokenobject { int _PyContext_Init(void); -void _PyContext_Fini(void); +void _PyContext_Fini(PyThreadState *tstate); #endif /* !Py_INTERNAL_CONTEXT_H */ diff --git a/Include/internal/pycore_gc.h b/Include/internal/pycore_gc.h index 0511eea779a..da202a1df53 100644 --- a/Include/internal/pycore_gc.h +++ b/Include/internal/pycore_gc.h @@ -165,13 +165,13 @@ PyAPI_FUNC(void) _PyGC_InitState(struct _gc_runtime_state *); // Functions to clear types free lists -extern void _PyFrame_ClearFreeList(void); -extern void _PyTuple_ClearFreeList(void); -extern void _PyFloat_ClearFreeList(void); -extern void _PyList_ClearFreeList(void); -extern void _PyDict_ClearFreeList(void); -extern void _PyAsyncGen_ClearFreeLists(void); -extern void _PyContext_ClearFreeList(void); +extern void _PyFrame_ClearFreeList(PyThreadState *tstate); +extern void _PyTuple_ClearFreeList(PyThreadState *tstate); +extern void _PyFloat_ClearFreeList(PyThreadState *tstate); +extern void _PyList_ClearFreeList(PyThreadState *tstate); +extern void _PyDict_ClearFreeList(PyThreadState *tstate); +extern void _PyAsyncGen_ClearFreeLists(PyThreadState *tstate); +extern void _PyContext_ClearFreeList(PyThreadState *tstate); #ifdef __cplusplus } diff --git a/Include/internal/pycore_import.h b/Include/internal/pycore_import.h index b011ea44251..35a67abebac 100644 --- a/Include/internal/pycore_import.h +++ b/Include/internal/pycore_import.h @@ -11,7 +11,7 @@ PyAPI_FUNC(PyObject *) _PyImport_FindBuiltin( ); #ifdef HAVE_FORK -extern void _PyImport_ReInitLock(void); +extern PyStatus _PyImport_ReInitLock(void); #endif extern void _PyImport_Cleanup(PyThreadState *tstate); diff --git a/Include/internal/pycore_initconfig.h b/Include/internal/pycore_initconfig.h index 8c6706c95cb..457a005860b 100644 --- a/Include/internal/pycore_initconfig.h +++ b/Include/internal/pycore_initconfig.h @@ -150,7 +150,7 @@ extern PyStatus _PyConfig_Copy( PyConfig *config, const PyConfig *config2); extern PyStatus _PyConfig_InitPathConfig(PyConfig *config); -extern void _PyConfig_Write(const PyConfig *config, +extern PyStatus _PyConfig_Write(const PyConfig *config, struct pyruntimestate *runtime); extern PyStatus _PyConfig_SetPyArgv( PyConfig *config, diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h index f04ea330d04..cfc27470c80 100644 --- a/Include/internal/pycore_interp.h +++ b/Include/internal/pycore_interp.h @@ -13,7 +13,12 @@ extern "C" { #include "pycore_gc.h" /* struct _gc_runtime_state */ #include "pycore_warnings.h" /* struct _warnings_runtime_state */ -/* ceval state */ +struct _Py_parser_state { + struct { + int level; + int atbol; + } listnode; +}; struct _pending_calls { PyThread_type_lock lock; @@ -60,10 +65,105 @@ struct _Py_unicode_fs_codec { _Py_error_handler error_handler; }; +struct _Py_bytes_state { + PyObject *empty_string; + PyBytesObject *characters[256]; +}; + struct _Py_unicode_state { + // The empty Unicode object is a singleton to improve performance. + PyObject *empty_string; + /* Single character Unicode strings in the Latin-1 range are being + shared as well. */ + PyObject *latin1[256]; struct _Py_unicode_fs_codec fs_codec; }; +struct _Py_float_state { + /* Special free list + free_list is a singly-linked list of available PyFloatObjects, + linked via abuse of their ob_type members. */ + int numfree; + PyFloatObject *free_list; +}; + +/* Speed optimization to avoid frequent malloc/free of small tuples */ +#ifndef PyTuple_MAXSAVESIZE + // Largest tuple to save on free list +# define PyTuple_MAXSAVESIZE 20 +#endif +#ifndef PyTuple_MAXFREELIST + // Maximum number of tuples of each size to save +# define PyTuple_MAXFREELIST 2000 +#endif + +struct _Py_tuple_state { +#if PyTuple_MAXSAVESIZE > 0 + /* Entries 1 up to PyTuple_MAXSAVESIZE are free lists, + entry 0 is the empty tuple () of which at most one instance + will be allocated. */ + PyTupleObject *free_list[PyTuple_MAXSAVESIZE]; + int numfree[PyTuple_MAXSAVESIZE]; +#endif +}; + +/* Empty list reuse scheme to save calls to malloc and free */ +#ifndef PyList_MAXFREELIST +# define PyList_MAXFREELIST 80 +#endif + +struct _Py_list_state { + PyListObject *free_list[PyList_MAXFREELIST]; + int numfree; +}; + +#ifndef PyDict_MAXFREELIST +# define PyDict_MAXFREELIST 80 +#endif + +struct _Py_dict_state { + /* Dictionary reuse scheme to save calls to malloc and free */ + PyDictObject *free_list[PyDict_MAXFREELIST]; + int numfree; + PyDictKeysObject *keys_free_list[PyDict_MAXFREELIST]; + int keys_numfree; +}; + +struct _Py_frame_state { + PyFrameObject *free_list; + /* number of frames currently in free_list */ + int numfree; +}; + +#ifndef _PyAsyncGen_MAXFREELIST +# define _PyAsyncGen_MAXFREELIST 80 +#endif + +struct _Py_async_gen_state { + /* Freelists boost performance 6-10%; they also reduce memory + fragmentation, as _PyAsyncGenWrappedValue and PyAsyncGenASend + are short-living objects that are instantiated for every + __anext__() call. */ + struct _PyAsyncGenWrappedValue* value_freelist[_PyAsyncGen_MAXFREELIST]; + int value_numfree; + + struct PyAsyncGenASend* asend_freelist[_PyAsyncGen_MAXFREELIST]; + int asend_numfree; +}; + +struct _Py_context_state { + // List of free PyContext objects + PyContext *freelist; + int numfree; +}; + +struct _Py_exc_state { + // The dict mapping from errno codes to OSError subclasses + PyObject *errnomap; + PyBaseExceptionObject *memerrors_freelist; + int memerrors_numfree; +}; + /* interpreter state */ @@ -110,8 +210,6 @@ struct _is { PyObject *codec_error_registry; int codecs_initialized; - struct _Py_unicode_state unicode; - PyConfig config; #ifdef HAVE_DLOPEN int dlopenflags; @@ -142,12 +240,7 @@ struct _is { PyObject *audit_hooks; - struct { - struct { - int level; - int atbol; - } listnode; - } parser; + struct _Py_parser_state parser; #if _PY_NSMALLNEGINTS + _PY_NSMALLPOSINTS > 0 /* Small integers are preallocated in this array so that they @@ -157,6 +250,20 @@ struct _is { */ PyLongObject* small_ints[_PY_NSMALLNEGINTS + _PY_NSMALLPOSINTS]; #endif + struct _Py_bytes_state bytes; + struct _Py_unicode_state unicode; + struct _Py_float_state float_state; + /* Using a cache is very effective since typically only a single slice is + created and then deleted again. */ + PySliceObject *slice_cache; + + struct _Py_tuple_state tuple; + struct _Py_list_state list; + struct _Py_dict_state dict_state; + struct _Py_frame_state frame; + struct _Py_async_gen_state async_gen; + struct _Py_context_state context; + struct _Py_exc_state exc_state; }; /* Used by _PyImport_Cleanup() */ diff --git a/Include/internal/pycore_list.h b/Include/internal/pycore_list.h new file mode 100644 index 00000000000..f18fb052c49 --- /dev/null +++ b/Include/internal/pycore_list.h @@ -0,0 +1,20 @@ +#ifndef Py_INTERNAL_LIST_H +#define Py_INTERNAL_LIST_H +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef Py_BUILD_CORE +# error "this header requires Py_BUILD_CORE define" +#endif + +#include "listobject.h" // _PyList_CAST() + + +#define _PyList_ITEMS(op) (_PyList_CAST(op)->ob_item) + + +#ifdef __cplusplus +} +#endif +#endif /* !Py_INTERNAL_LIST_H */ diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index 32e86d06db5..edd0031c3ef 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -15,7 +15,46 @@ extern "C" { PyAPI_FUNC(int) _PyType_CheckConsistency(PyTypeObject *type); PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content); +/* Update the Python traceback of an object. This function must be called + when a memory block is reused from a free list. + + Internal function called by _Py_NewReference(). */ +extern int _PyTraceMalloc_NewReference(PyObject *op); + +// Fast inlined version of PyType_HasFeature() +static inline int +_PyType_HasFeature(PyTypeObject *type, unsigned long feature) { + return ((type->tp_flags & feature) != 0); +} + +/* Inline functions trading binary compatibility for speed: + _PyObject_Init() is the fast version of PyObject_Init(), and + _PyObject_InitVar() is the fast version of PyObject_InitVar(). + + These inline functions must not be called with op=NULL. */ +static inline void +_PyObject_Init(PyObject *op, PyTypeObject *typeobj) +{ + assert(op != NULL); + Py_SET_TYPE(op, typeobj); + if (_PyType_HasFeature(typeobj, Py_TPFLAGS_HEAPTYPE)) { + Py_INCREF(typeobj); + } + _Py_NewReference(op); +} + +static inline void +_PyObject_InitVar(PyVarObject *op, PyTypeObject *typeobj, Py_ssize_t size) +{ + assert(op != NULL); + Py_SET_SIZE(op, size); + _PyObject_Init((PyObject *)op, typeobj); +} + + /* Tell the GC to track this object. + * + * The object must not be tracked by the GC. * * NB: While the object is tracked by the collector, it must be safe to call the * ob_traverse method. @@ -24,20 +63,24 @@ PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content); * because it's not object header. So we don't use _PyGCHead_PREV() and * _PyGCHead_SET_PREV() for it to avoid unnecessary bitwise operations. * - * The PyObject_GC_Track() function is the public version of this macro. + * See also the public PyObject_GC_Track() function. */ -static inline void _PyObject_GC_TRACK_impl(const char *filename, int lineno, - PyObject *op) +static inline void _PyObject_GC_TRACK( +// The preprocessor removes _PyObject_ASSERT_FROM() calls if NDEBUG is defined +#ifndef NDEBUG + const char *filename, int lineno, +#endif + PyObject *op) { _PyObject_ASSERT_FROM(op, !_PyObject_GC_IS_TRACKED(op), "object already tracked by the garbage collector", - filename, lineno, "_PyObject_GC_TRACK"); + filename, lineno, __func__); PyGC_Head *gc = _Py_AS_GC(op); _PyObject_ASSERT_FROM(op, (gc->_gc_prev & _PyGC_PREV_MASK_COLLECTING) == 0, "object is in generation which is garbage collected", - filename, lineno, "_PyObject_GC_TRACK"); + filename, lineno, __func__); PyThreadState *tstate = _PyThreadState_GET(); PyGC_Head *generation0 = tstate->interp->gc.generation0; @@ -48,9 +91,6 @@ static inline void _PyObject_GC_TRACK_impl(const char *filename, int lineno, generation0->_gc_prev = (uintptr_t)gc; } -#define _PyObject_GC_TRACK(op) \ - _PyObject_GC_TRACK_impl(__FILE__, __LINE__, _PyObject_CAST(op)) - /* Tell the GC to stop tracking this object. * * Internal note: This may be called while GC. So _PyGC_PREV_MASK_COLLECTING @@ -58,14 +98,19 @@ static inline void _PyObject_GC_TRACK_impl(const char *filename, int lineno, * * The object must be tracked by the GC. * - * The PyObject_GC_UnTrack() function is the public version of this macro. + * See also the public PyObject_GC_UnTrack() which accept an object which is + * not tracked. */ -static inline void _PyObject_GC_UNTRACK_impl(const char *filename, int lineno, - PyObject *op) +static inline void _PyObject_GC_UNTRACK( +// The preprocessor removes _PyObject_ASSERT_FROM() calls if NDEBUG is defined +#ifndef NDEBUG + const char *filename, int lineno, +#endif + PyObject *op) { _PyObject_ASSERT_FROM(op, _PyObject_GC_IS_TRACKED(op), "object not tracked by the garbage collector", - filename, lineno, "_PyObject_GC_UNTRACK"); + filename, lineno, __func__); PyGC_Head *gc = _Py_AS_GC(op); PyGC_Head *prev = _PyGCHead_PREV(gc); @@ -76,8 +121,20 @@ static inline void _PyObject_GC_UNTRACK_impl(const char *filename, int lineno, gc->_gc_prev &= _PyGC_PREV_MASK_FINALIZED; } -#define _PyObject_GC_UNTRACK(op) \ - _PyObject_GC_UNTRACK_impl(__FILE__, __LINE__, _PyObject_CAST(op)) +// Macros to accept any type for the parameter, and to automatically pass +// the filename and the filename (if NDEBUG is not defined) where the macro +// is called. +#ifdef NDEBUG +# define _PyObject_GC_TRACK(op) \ + _PyObject_GC_TRACK(_PyObject_CAST(op)) +# define _PyObject_GC_UNTRACK(op) \ + _PyObject_GC_UNTRACK(_PyObject_CAST(op)) +#else +# define _PyObject_GC_TRACK(op) \ + _PyObject_GC_TRACK(__FILE__, __LINE__, _PyObject_CAST(op)) +# define _PyObject_GC_UNTRACK(op) \ + _PyObject_GC_UNTRACK(__FILE__, __LINE__, _PyObject_CAST(op)) +#endif #ifdef Py_REF_DEBUG extern void _PyDebug_PrintTotalRefs(void); @@ -96,12 +153,6 @@ _PyObject_GET_WEAKREFS_LISTPTR(PyObject *op) return (PyObject **)((char *)op + offset); } -// Fast inlined version of PyType_HasFeature() -static inline int -_PyType_HasFeature(PyTypeObject *type, unsigned long feature) { - return ((type->tp_flags & feature) != 0); -} - // Fast inlined version of PyObject_IS_GC() static inline int _PyObject_IS_GC(PyObject *obj) diff --git a/Include/internal/pycore_pylifecycle.h b/Include/internal/pycore_pylifecycle.h index 77ea3f27454..22def3dbc8b 100644 --- a/Include/internal/pycore_pylifecycle.h +++ b/Include/internal/pycore_pylifecycle.h @@ -31,9 +31,11 @@ PyAPI_FUNC(int) _Py_IsLocaleCoercionTarget(const char *ctype_loc); /* Various one-time initializers */ -extern PyStatus _PyUnicode_Init(void); +extern PyStatus _PyUnicode_Init(PyThreadState *tstate); +extern PyStatus _PyBytes_Init(PyThreadState *tstate); extern int _PyStructSequence_Init(void); extern int _PyLong_Init(PyThreadState *tstate); +extern PyStatus _PyTuple_Init(PyThreadState *tstate); extern PyStatus _PyFaulthandler_Init(int enable); extern int _PyTraceMalloc_Init(int enable); extern PyObject * _PyBuiltin_Init(PyThreadState *tstate); @@ -43,7 +45,7 @@ extern PyStatus _PySys_Create( extern PyStatus _PySys_ReadPreinitWarnOptions(PyWideStringList *options); extern PyStatus _PySys_ReadPreinitXOptions(PyConfig *config); extern int _PySys_InitMain(PyThreadState *tstate); -extern PyStatus _PyExc_Init(void); +extern PyStatus _PyExc_Init(PyThreadState *tstate); extern PyStatus _PyErr_Init(void); extern PyStatus _PyBuiltins_AddExceptions(PyObject * bltinmod); extern PyStatus _PyImportHooks_Init(PyThreadState *tstate); @@ -58,25 +60,25 @@ extern PyStatus _PyGC_Init(PyThreadState *tstate); /* Various internal finalizers */ -extern void _PyFrame_Fini(void); -extern void _PyDict_Fini(void); -extern void _PyTuple_Fini(void); -extern void _PyList_Fini(void); -extern void _PySet_Fini(void); -extern void _PyBytes_Fini(void); -extern void _PyFloat_Fini(void); -extern void _PySlice_Fini(void); -extern void _PyAsyncGen_Fini(void); +extern void _PyFrame_Fini(PyThreadState *tstate); +extern void _PyDict_Fini(PyThreadState *tstate); +extern void _PyTuple_Fini(PyThreadState *tstate); +extern void _PyList_Fini(PyThreadState *tstate); +extern void _PyBytes_Fini(PyThreadState *tstate); +extern void _PyFloat_Fini(PyThreadState *tstate); +extern void _PySlice_Fini(PyThreadState *tstate); +extern void _PyAsyncGen_Fini(PyThreadState *tstate); extern void PyOS_FiniInterrupts(void); -extern void _PyExc_Fini(void); +extern void _PyExc_Fini(PyThreadState *tstate); extern void _PyImport_Fini(void); extern void _PyImport_Fini2(void); extern void _PyGC_Fini(PyThreadState *tstate); extern void _PyType_Fini(void); extern void _Py_HashRandomization_Fini(void); extern void _PyUnicode_Fini(PyThreadState *tstate); +extern void _PyUnicode_ClearInterned(PyThreadState *tstate); extern void _PyLong_Fini(PyThreadState *tstate); extern void _PyFaulthandler_Fini(void); extern void _PyHash_Fini(void); diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h index 3d925e2250d..e4e35c16ce8 100644 --- a/Include/internal/pycore_pymem.h +++ b/Include/internal/pycore_pymem.h @@ -69,9 +69,6 @@ PyAPI_FUNC(int) _PyMem_GetAllocatorName( PYMEM_ALLOCATOR_NOT_SET does nothing. */ PyAPI_FUNC(int) _PyMem_SetupAllocators(PyMemAllocatorName allocator); -/* bpo-35053: Expose _Py_tracemalloc_config for _Py_NewReference() - which access directly _Py_tracemalloc_config.tracing for best - performances. */ struct _PyTraceMalloc_Config { /* Module initialized? Variable protected by the GIL */ diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h index d96ba312070..0cd5550cfda 100644 --- a/Include/internal/pycore_pystate.h +++ b/Include/internal/pycore_pystate.h @@ -86,6 +86,21 @@ _PyThreadState_GET(void) #undef PyThreadState_GET #define PyThreadState_GET() _PyThreadState_GET() +PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalError_TstateNULL(const char *func); + +static inline void +_Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate) +{ + if (tstate == NULL) { + _Py_FatalError_TstateNULL(func); + } +} + +// Call Py_FatalError() if tstate is NULL +#define _Py_EnsureTstateNotNULL(tstate) \ + _Py_EnsureFuncTstateNotNULL(__func__, tstate) + + /* Get the current interpreter state. The macro is unsafe: it does not check for error and it can return NULL. @@ -96,7 +111,9 @@ _PyThreadState_GET(void) and _PyGILState_GetInterpreterStateUnsafe(). */ static inline PyInterpreterState* _PyInterpreterState_GET(void) { PyThreadState *tstate = _PyThreadState_GET(); - assert(tstate != NULL); +#ifdef Py_DEBUG + _Py_EnsureTstateNotNULL(tstate); +#endif return tstate->interp; } @@ -114,9 +131,12 @@ PyAPI_FUNC(PyThreadState *) _PyThreadState_Swap( PyThreadState *newts); PyAPI_FUNC(PyStatus) _PyInterpreterState_Enable(_PyRuntimeState *runtime); -PyAPI_FUNC(void) _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime); -PyAPI_FUNC(void) _PyGILState_Reinit(_PyRuntimeState *runtime); +#ifdef HAVE_FORK +extern PyStatus _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime); +extern PyStatus _PyGILState_Reinit(_PyRuntimeState *runtime); +extern void _PySignal_AfterFork(void); +#endif PyAPI_FUNC(int) _PyState_AddModule( @@ -124,6 +144,9 @@ PyAPI_FUNC(int) _PyState_AddModule( PyObject* module, struct PyModuleDef* def); + +PyAPI_FUNC(int) _PyOS_InterruptOccurred(PyThreadState *tstate); + #ifdef __cplusplus } #endif diff --git a/Include/internal/pycore_runtime.h b/Include/internal/pycore_runtime.h index ebdc12b23a9..3a01d64e63d 100644 --- a/Include/internal/pycore_runtime.h +++ b/Include/internal/pycore_runtime.h @@ -120,7 +120,7 @@ PyAPI_FUNC(PyStatus) _PyRuntimeState_Init(_PyRuntimeState *runtime); PyAPI_FUNC(void) _PyRuntimeState_Fini(_PyRuntimeState *runtime); #ifdef HAVE_FORK -PyAPI_FUNC(void) _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime); +extern PyStatus _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime); #endif /* Initialize _PyRuntimeState. diff --git a/Include/internal/pycore_tupleobject.h b/Include/internal/pycore_tuple.h similarity index 75% rename from Include/internal/pycore_tupleobject.h rename to Include/internal/pycore_tuple.h index f95f16c0ed0..5353e18d083 100644 --- a/Include/internal/pycore_tupleobject.h +++ b/Include/internal/pycore_tuple.h @@ -1,5 +1,5 @@ -#ifndef Py_INTERNAL_TUPLEOBJECT_H -#define Py_INTERNAL_TUPLEOBJECT_H +#ifndef Py_INTERNAL_TUPLE_H +#define Py_INTERNAL_TUPLE_H #ifdef __cplusplus extern "C" { #endif @@ -11,9 +11,10 @@ extern "C" { #include "tupleobject.h" /* _PyTuple_CAST() */ #define _PyTuple_ITEMS(op) (_PyTuple_CAST(op)->ob_item) + PyAPI_FUNC(PyObject *) _PyTuple_FromArray(PyObject *const *, Py_ssize_t); #ifdef __cplusplus } #endif -#endif /* !Py_INTERNAL_TUPLEOBJECT_H */ +#endif /* !Py_INTERNAL_TUPLE_H */ diff --git a/Include/intrcheck.h b/Include/intrcheck.h index e5bf5a834e4..88f2a7076ce 100644 --- a/Include/intrcheck.h +++ b/Include/intrcheck.h @@ -1,4 +1,3 @@ - #ifndef Py_INTRCHECK_H #define Py_INTRCHECK_H #ifdef __cplusplus @@ -19,7 +18,6 @@ Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyOS_AfterFork(void); #ifndef Py_LIMITED_API PyAPI_FUNC(int) _PyOS_IsMainThread(void); -PyAPI_FUNC(void) _PySignal_AfterFork(void); #ifdef MS_WINDOWS /* windows.h is not included by Python.h so use void* instead of HANDLE */ diff --git a/Include/longobject.h b/Include/longobject.h index dad08c23f82..06e3e249040 100644 --- a/Include/longobject.h +++ b/Include/longobject.h @@ -102,8 +102,6 @@ PyAPI_FUNC(long long) PyLong_AsLongLongAndOverflow(PyObject *, int *); PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int); #ifndef Py_LIMITED_API -Py_DEPRECATED(3.3) -PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int); PyAPI_FUNC(PyObject *) PyLong_FromUnicodeObject(PyObject *u, int base); PyAPI_FUNC(PyObject *) _PyLong_FromBytes(const char *, Py_ssize_t, int); #endif diff --git a/Include/node.h b/Include/node.h deleted file mode 100644 index ca24f289085..00000000000 --- a/Include/node.h +++ /dev/null @@ -1,47 +0,0 @@ - -/* Parse tree node interface */ - -#ifndef Py_NODE_H -#define Py_NODE_H -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _node { - short n_type; - char *n_str; - int n_lineno; - int n_col_offset; - int n_nchildren; - struct _node *n_child; - int n_end_lineno; - int n_end_col_offset; -} node; - -PyAPI_FUNC(node *) PyNode_New(int type); -PyAPI_FUNC(int) PyNode_AddChild(node *n, int type, - char *str, int lineno, int col_offset, - int end_lineno, int end_col_offset); -PyAPI_FUNC(void) PyNode_Free(node *n); -#ifndef Py_LIMITED_API -PyAPI_FUNC(Py_ssize_t) _PyNode_SizeOf(node *n); -#endif - -/* Node access functions */ -#define NCH(n) ((n)->n_nchildren) - -#define CHILD(n, i) (&(n)->n_child[i]) -#define TYPE(n) ((n)->n_type) -#define STR(n) ((n)->n_str) -#define LINENO(n) ((n)->n_lineno) - -/* Assert that the type of a node is what we expect */ -#define REQ(n, type) assert(TYPE(n) == (type)) - -PyAPI_FUNC(void) PyNode_ListTree(node *); -void _PyNode_FinalizeEndPos(node *n); // helper also used in parsetok.c - -#ifdef __cplusplus -} -#endif -#endif /* !Py_NODE_H */ diff --git a/Include/object.h b/Include/object.h index 5ad05699bb4..537567040f9 100644 --- a/Include/object.h +++ b/Include/object.h @@ -119,30 +119,45 @@ typedef struct { /* Cast argument to PyVarObject* type. */ #define _PyVarObject_CAST(op) ((PyVarObject*)(op)) +#define _PyVarObject_CAST_CONST(op) ((const PyVarObject*)(op)) + + +static inline Py_ssize_t _Py_REFCNT(const PyObject *ob) { + return ob->ob_refcnt; +} +#define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob)) + + +static inline Py_ssize_t _Py_SIZE(const PyVarObject *ob) { + return ob->ob_size; +} +#define Py_SIZE(ob) _Py_SIZE(_PyVarObject_CAST_CONST(ob)) -#define Py_REFCNT(ob) (_PyObject_CAST(ob)->ob_refcnt) -#define Py_SIZE(ob) (_PyVarObject_CAST(ob)->ob_size) static inline PyTypeObject* _Py_TYPE(const PyObject *ob) { return ob->ob_type; } #define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST_CONST(ob)) + static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) { return ob->ob_type == type; } #define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST_CONST(ob), type) + static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) { ob->ob_refcnt = refcnt; } #define Py_SET_REFCNT(ob, refcnt) _Py_SET_REFCNT(_PyObject_CAST(ob), refcnt) + static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type) { ob->ob_type = type; } #define Py_SET_TYPE(ob, type) _Py_SET_TYPE(_PyObject_CAST(ob), type) + static inline void _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) { ob->ob_size = size; } diff --git a/Include/objimpl.h b/Include/objimpl.h index 030d7eee297..af537175bfe 100644 --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -118,7 +118,14 @@ PyAPI_FUNC(void) PyObject_Free(void *ptr); /* Functions */ PyAPI_FUNC(PyObject *) PyObject_Init(PyObject *, PyTypeObject *); PyAPI_FUNC(PyVarObject *) PyObject_InitVar(PyVarObject *, - PyTypeObject *, Py_ssize_t); + PyTypeObject *, Py_ssize_t); + +#define PyObject_INIT(op, typeobj) \ + PyObject_Init(_PyObject_CAST(op), (typeobj)) +#define PyObject_INIT_VAR(op, typeobj, size) \ + PyObject_InitVar(_PyVarObject_CAST(op), (typeobj), (size)) + + PyAPI_FUNC(PyObject *) _PyObject_New(PyTypeObject *); PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t); @@ -136,19 +143,6 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t); #define PyObject_NEW_VAR(type, typeobj, n) PyObject_NewVar(type, typeobj, n) -#ifdef Py_LIMITED_API -/* Define PyObject_INIT() and PyObject_INIT_VAR() as aliases to PyObject_Init() - and PyObject_InitVar() in the limited C API for compatibility with the - CPython C API. */ -# define PyObject_INIT(op, typeobj) \ - PyObject_Init(_PyObject_CAST(op), (typeobj)) -# define PyObject_INIT_VAR(op, typeobj, size) \ - PyObject_InitVar(_PyVarObject_CAST(op), (typeobj), (size)) -#else -/* PyObject_INIT() and PyObject_INIT_VAR() are defined in cpython/objimpl.h */ -#endif - - /* * Garbage Collection Support * ========================== diff --git a/Include/internal/pegen_interface.h b/Include/parser_interface.h similarity index 54% rename from Include/internal/pegen_interface.h rename to Include/parser_interface.h index ee4c77ec006..1c6576d926d 100644 --- a/Include/internal/pegen_interface.h +++ b/Include/parser_interface.h @@ -4,43 +4,49 @@ extern "C" { #endif -#ifndef Py_BUILD_CORE -# error "this header requires Py_BUILD_CORE define" -#endif - #include "Python.h" -#include "Python-ast.h" -PyAPI_FUNC(mod_ty) PyPegen_ASTFromString( +#ifndef Py_LIMITED_API +PyAPI_FUNC(struct _mod *) PyParser_ASTFromString( const char *str, const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena); -PyAPI_FUNC(mod_ty) PyPegen_ASTFromStringObject( +PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject( const char *str, PyObject* filename, int mode, PyCompilerFlags *flags, PyArena *arena); -PyAPI_FUNC(mod_ty) PyPegen_ASTFromFileObject( +PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile( FILE *fp, - PyObject *filename_ob, + const char *filename, + const char* enc, int mode, - const char *enc, const char *ps1, const char *ps2, PyCompilerFlags *flags, int *errcode, PyArena *arena); -PyAPI_FUNC(mod_ty) PyPegen_ASTFromFilename( +PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject( + FILE *fp, + PyObject *filename_ob, + const char *enc, + int mode, + const char *ps1, + const char *ps2, + PyCompilerFlags *flags, + int *errcode, + PyArena *arena); +PyAPI_FUNC(struct _mod *) PyParser_ASTFromFilename( const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena); - +#endif /* !Py_LIMITED_API */ #ifdef __cplusplus } #endif -#endif /* !Py_PEGENINTERFACE*/ +#endif /* !Py_PEGENINTERFACE */ diff --git a/Include/parsetok.h b/Include/parsetok.h deleted file mode 100644 index 935d733e90a..00000000000 --- a/Include/parsetok.h +++ /dev/null @@ -1,110 +0,0 @@ -/* Parser-tokenizer link interface */ - -#ifndef Py_LIMITED_API -#ifndef Py_PARSETOK_H -#define Py_PARSETOK_H -#ifdef __cplusplus -extern "C" { -#endif - -#include "grammar.h" /* grammar */ -#include "node.h" /* node */ - -typedef struct { - int error; - PyObject *filename; - int lineno; - int offset; - char *text; /* UTF-8-encoded string */ - int token; - int expected; -} perrdetail; - -#if 0 -#define PyPARSE_YIELD_IS_KEYWORD 0x0001 -#endif - -#define PyPARSE_DONT_IMPLY_DEDENT 0x0002 - -#if 0 -#define PyPARSE_WITH_IS_KEYWORD 0x0003 -#define PyPARSE_PRINT_IS_FUNCTION 0x0004 -#define PyPARSE_UNICODE_LITERALS 0x0008 -#endif - -#define PyPARSE_IGNORE_COOKIE 0x0010 -#define PyPARSE_BARRY_AS_BDFL 0x0020 -#define PyPARSE_TYPE_COMMENTS 0x0040 -#define PyPARSE_ASYNC_HACKS 0x0080 - -PyAPI_FUNC(node *) PyParser_ParseString(const char *, grammar *, int, - perrdetail *); -PyAPI_FUNC(node *) PyParser_ParseFile (FILE *, const char *, grammar *, int, - const char *, const char *, - perrdetail *); - -PyAPI_FUNC(node *) PyParser_ParseStringFlags(const char *, grammar *, int, - perrdetail *, int); -PyAPI_FUNC(node *) PyParser_ParseFileFlags( - FILE *fp, - const char *filename, /* decoded from the filesystem encoding */ - const char *enc, - grammar *g, - int start, - const char *ps1, - const char *ps2, - perrdetail *err_ret, - int flags); -PyAPI_FUNC(node *) PyParser_ParseFileFlagsEx( - FILE *fp, - const char *filename, /* decoded from the filesystem encoding */ - const char *enc, - grammar *g, - int start, - const char *ps1, - const char *ps2, - perrdetail *err_ret, - int *flags); -PyAPI_FUNC(node *) PyParser_ParseFileObject( - FILE *fp, - PyObject *filename, - const char *enc, - grammar *g, - int start, - const char *ps1, - const char *ps2, - perrdetail *err_ret, - int *flags); - -PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilename( - const char *s, - const char *filename, /* decoded from the filesystem encoding */ - grammar *g, - int start, - perrdetail *err_ret, - int flags); -PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilenameEx( - const char *s, - const char *filename, /* decoded from the filesystem encoding */ - grammar *g, - int start, - perrdetail *err_ret, - int *flags); -PyAPI_FUNC(node *) PyParser_ParseStringObject( - const char *s, - PyObject *filename, - grammar *g, - int start, - perrdetail *err_ret, - int *flags); - -/* Note that the following functions are defined in pythonrun.c, - not in parsetok.c */ -PyAPI_FUNC(void) PyParser_SetError(perrdetail *); -PyAPI_FUNC(void) PyParser_ClearError(perrdetail *); - -#ifdef __cplusplus -} -#endif -#endif /* !Py_PARSETOK_H */ -#endif /* !Py_LIMITED_API */ diff --git a/Include/pyerrors.h b/Include/pyerrors.h index 399bb7c3a6f..979a26ba68a 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -4,6 +4,8 @@ extern "C" { #endif +#include // va_list + /* Error handling definitions */ PyAPI_FUNC(void) PyErr_SetNone(PyObject *); @@ -307,21 +309,6 @@ PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason( const char *reason /* UTF-8 encoded string */ ); -/* These APIs aren't really part of the error implementation, but - often needed to format error messages; the native C lib APIs are - not available on all platforms, which is why we provide emulations - for those platforms in Python/mysnprintf.c, - WARNING: The return value of snprintf varies across platforms; do - not rely on any particular behavior; eventually the C99 defn may - be reliable. -*/ -#if defined(MS_WIN32) && !defined(HAVE_SNPRINTF) -# define HAVE_SNPRINTF -# define snprintf _snprintf -# define vsnprintf _vsnprintf -#endif - -#include PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...) Py_GCC_ATTRIBUTE((format(printf, 3, 4))); PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va) diff --git a/Include/pymath.h b/Include/pymath.h index 63ca972784e..f869724334a 100644 --- a/Include/pymath.h +++ b/Include/pymath.h @@ -227,12 +227,4 @@ PyAPI_FUNC(void) _Py_set_387controlword(unsigned short); * behavior. */ #define _Py_InIntegralTypeRange(type, v) (_Py_IntegralTypeMin(type) <= v && v <= _Py_IntegralTypeMax(type)) -/* Return the smallest integer k such that n < 2**k, or 0 if n == 0. - * Equivalent to floor(log2(x))+1. Also equivalent to: bitwidth_of_type - - * count_leading_zero_bits(x) - */ -#ifndef Py_LIMITED_API -PyAPI_FUNC(unsigned int) _Py_bit_length(unsigned long d); -#endif - #endif /* Py_PYMATH_H */ diff --git a/Include/pyport.h b/Include/pyport.h index 63d3b81de5d..7137006870b 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -131,7 +131,9 @@ typedef int Py_ssize_clean_t; /* Smallest negative value of type Py_ssize_t. */ #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1) -/* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf +/* Macro kept for backward compatibility: use "z" in new code. + * + * PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf * format to convert an argument with the width of a size_t or Py_ssize_t. * C99 introduced "z" for this purpose, but old MSVCs had not supported it. * Since MSVC supports "z" since (at least) 2015, we can just use "z" @@ -513,6 +515,26 @@ extern "C" { #define Py_DEPRECATED(VERSION_UNUSED) #endif +#if defined(__clang__) +#define _Py_COMP_DIAG_PUSH _Pragma("clang diagnostic push") +#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \ + _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") +#define _Py_COMP_DIAG_POP _Pragma("clang diagnostic pop") +#elif defined(__GNUC__) \ + && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) +#define _Py_COMP_DIAG_PUSH _Pragma("GCC diagnostic push") +#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \ + _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#define _Py_COMP_DIAG_POP _Pragma("GCC diagnostic pop") +#elif defined(_MSC_VER) +#define _Py_COMP_DIAG_PUSH __pragma(warning(push)) +#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS __pragma(warning(disable: 4996)) +#define _Py_COMP_DIAG_POP __pragma(warning(pop)) +#else +#define _Py_COMP_DIAG_PUSH +#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS +#define _Py_COMP_DIAG_POP +#endif /* _Py_HOT_FUNCTION * The hot attribute on a function is used to inform the compiler that the @@ -829,10 +851,10 @@ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler; #endif /* Mark a function which cannot return. Example: + PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void); - PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void); */ + XLC support is intentionally omitted due to bpo-40244 */ #if defined(__clang__) || \ - defined(__xlc__) || \ (defined(__GNUC__) && \ ((__GNUC__ >= 3) || \ (__GNUC__ == 2) && (__GNUC_MINOR__ >= 5))) diff --git a/Include/pythonrun.h b/Include/pythonrun.h index 46091e09216..d43734b5a12 100644 --- a/Include/pythonrun.h +++ b/Include/pythonrun.h @@ -32,57 +32,7 @@ PyAPI_FUNC(int) PyRun_InteractiveLoopFlags( const char *filename, /* decoded from the filesystem encoding */ PyCompilerFlags *flags); -PyAPI_FUNC(struct _mod *) PyParser_ASTFromString( - const char *s, - const char *filename, /* decoded from the filesystem encoding */ - int start, - PyCompilerFlags *flags, - PyArena *arena); -PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject( - const char *s, - PyObject *filename, - int start, - PyCompilerFlags *flags, - PyArena *arena); -PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile( - FILE *fp, - const char *filename, /* decoded from the filesystem encoding */ - const char* enc, - int start, - const char *ps1, - const char *ps2, - PyCompilerFlags *flags, - int *errcode, - PyArena *arena); -PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject( - FILE *fp, - PyObject *filename, - const char* enc, - int start, - const char *ps1, - const char *ps2, - PyCompilerFlags *flags, - int *errcode, - PyArena *arena); -#endif -#ifndef PyParser_SimpleParseString -#define PyParser_SimpleParseString(S, B) \ - PyParser_SimpleParseStringFlags(S, B, 0) -#define PyParser_SimpleParseFile(FP, S, B) \ - PyParser_SimpleParseFileFlags(FP, S, B, 0) -#endif -PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int, - int); -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *, - const char *, - int, int); -#endif -PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *, - int, int); - -#ifndef Py_LIMITED_API PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *, PyObject *, PyCompilerFlags *); diff --git a/Include/typeslots.h b/Include/typeslots.h index 0ce6a377dcf..64f6fff5144 100644 --- a/Include/typeslots.h +++ b/Include/typeslots.h @@ -1,7 +1,12 @@ /* Do not renumber the file; these numbers are part of the stable ABI. */ +#if defined(Py_LIMITED_API) /* Disabled, see #10181 */ #undef Py_bf_getbuffer #undef Py_bf_releasebuffer +#else +#define Py_bf_getbuffer 1 +#define Py_bf_releasebuffer 2 +#endif #define Py_mp_ass_subscript 3 #define Py_mp_length 4 #define Py_mp_subscript 5 diff --git a/Lib/argparse.py b/Lib/argparse.py index 2677ef63e9e..2fb1da59f94 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -857,7 +857,6 @@ class BooleanOptionalAction(Action): def __init__(self, option_strings, dest, - const=None, default=None, type=None, choices=None, diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index a05cbb6bdd6..884a58f2ed6 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -266,6 +266,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): (handle, writer)) if reader is not None: reader.cancel() + return handle def _remove_reader(self, fd): if self.is_closed(): @@ -302,6 +303,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): (reader, handle)) if writer is not None: writer.cancel() + return handle def _remove_writer(self, fd): """Remove a writer callback.""" @@ -329,7 +331,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): def add_reader(self, fd, callback, *args): """Add a reader callback.""" self._ensure_fd_no_transport(fd) - return self._add_reader(fd, callback, *args) + self._add_reader(fd, callback, *args) def remove_reader(self, fd): """Remove a reader callback.""" @@ -339,7 +341,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): def add_writer(self, fd, callback, *args): """Add a writer callback..""" self._ensure_fd_no_transport(fd) - return self._add_writer(fd, callback, *args) + self._add_writer(fd, callback, *args) def remove_writer(self, fd): """Remove a writer callback.""" @@ -362,13 +364,15 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): pass fut = self.create_future() fd = sock.fileno() - self.add_reader(fd, self._sock_recv, fut, sock, n) + self._ensure_fd_no_transport(fd) + handle = self._add_reader(fd, self._sock_recv, fut, sock, n) fut.add_done_callback( - functools.partial(self._sock_read_done, fd)) + functools.partial(self._sock_read_done, fd, handle=handle)) return await fut - def _sock_read_done(self, fd, fut): - self.remove_reader(fd) + def _sock_read_done(self, fd, fut, handle=None): + if handle is None or not handle.cancelled(): + self.remove_reader(fd) def _sock_recv(self, fut, sock, n): # _sock_recv() can add itself as an I/O callback if the operation can't @@ -401,9 +405,10 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): pass fut = self.create_future() fd = sock.fileno() - self.add_reader(fd, self._sock_recv_into, fut, sock, buf) + self._ensure_fd_no_transport(fd) + handle = self._add_reader(fd, self._sock_recv_into, fut, sock, buf) fut.add_done_callback( - functools.partial(self._sock_read_done, fd)) + functools.partial(self._sock_read_done, fd, handle=handle)) return await fut def _sock_recv_into(self, fut, sock, buf): @@ -446,11 +451,12 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): fut = self.create_future() fd = sock.fileno() - fut.add_done_callback( - functools.partial(self._sock_write_done, fd)) + self._ensure_fd_no_transport(fd) # use a trick with a list in closure to store a mutable state - self.add_writer(fd, self._sock_sendall, fut, sock, - memoryview(data), [n]) + handle = self._add_writer(fd, self._sock_sendall, fut, sock, + memoryview(data), [n]) + fut.add_done_callback( + functools.partial(self._sock_write_done, fd, handle=handle)) return await fut def _sock_sendall(self, fut, sock, view, pos): @@ -502,9 +508,11 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): # connection runs in background. We have to wait until the socket # becomes writable to be notified when the connection succeed or # fails. + self._ensure_fd_no_transport(fd) + handle = self._add_writer( + fd, self._sock_connect_cb, fut, sock, address) fut.add_done_callback( - functools.partial(self._sock_write_done, fd)) - self.add_writer(fd, self._sock_connect_cb, fut, sock, address) + functools.partial(self._sock_write_done, fd, handle=handle)) except (SystemExit, KeyboardInterrupt): raise except BaseException as exc: @@ -512,8 +520,9 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): else: fut.set_result(None) - def _sock_write_done(self, fd, fut): - self.remove_writer(fd) + def _sock_write_done(self, fd, fut, handle=None): + if handle is None or not handle.cancelled(): + self.remove_writer(fd) def _sock_connect_cb(self, fut, sock, address): if fut.done(): diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 21b98b6647b..5e0692ef777 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -113,34 +113,6 @@ class Task(futures._PyFuture): # Inherit Python Task implementation # status is still pending _log_destroy_pending = True - @classmethod - def current_task(cls, loop=None): - """Return the currently running task in an event loop or None. - - By default the current task for the current event loop is returned. - - None is returned when called not in the context of a Task. - """ - warnings.warn("Task.current_task() is deprecated since Python 3.7, " - "use asyncio.current_task() instead", - DeprecationWarning, - stacklevel=2) - if loop is None: - loop = events.get_event_loop() - return current_task(loop) - - @classmethod - def all_tasks(cls, loop=None): - """Return a set of all tasks for an event loop. - - By default all tasks for the current event loop are returned. - """ - warnings.warn("Task.all_tasks() is deprecated since Python 3.7, " - "use asyncio.all_tasks() instead", - DeprecationWarning, - stacklevel=2) - return _all_tasks_compat(loop) - def __init__(self, coro, *, loop=None, name=None): super().__init__(loop=loop) if self._source_traceback: diff --git a/Lib/asyncio/threads.py b/Lib/asyncio/threads.py index 51e0ba95d82..34b7513a420 100644 --- a/Lib/asyncio/threads.py +++ b/Lib/asyncio/threads.py @@ -17,7 +17,7 @@ async def to_thread(func, /, *args, **kwargs): allowing context variables from the main thread to be accessed in the separate thread. - Return an asyncio.Future which represents the eventual result of *func*. + Return a coroutine that can be awaited to get the eventual result of *func*. """ loop = events.get_running_loop() ctx = contextvars.copy_context() diff --git a/Lib/calendar.py b/Lib/calendar.py index 7550d52c0a9..7311a017372 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -571,19 +571,11 @@ class LocaleTextCalendar(TextCalendar): def formatweekday(self, day, width): with different_locale(self.locale): - if width >= 9: - names = day_name - else: - names = day_abbr - name = names[day] - return name[:width].center(width) + return super().formatweekday(day, width) def formatmonthname(self, theyear, themonth, width, withyear=True): with different_locale(self.locale): - s = month_name[themonth] - if withyear: - s = "%s %r" % (s, theyear) - return s.center(width) + return super().formatmonthname(theyear, themonth, width, withyear) class LocaleHTMLCalendar(HTMLCalendar): @@ -601,16 +593,11 @@ class LocaleHTMLCalendar(HTMLCalendar): def formatweekday(self, day): with different_locale(self.locale): - s = day_abbr[day] - return '%s' % (self.cssclasses[day], s) + return super().formatweekday(day) def formatmonthname(self, theyear, themonth, withyear=True): with different_locale(self.locale): - s = month_name[themonth] - if withyear: - s = '%s %s' % (s, theyear) - return '%s' % s - + return super().formatmonthname(theyear, themonth, withyear) # Support for old module level interface c = TextCalendar() diff --git a/Lib/cgi.py b/Lib/cgi.py index c22c71b3878..77ab703cc03 100755 --- a/Lib/cgi.py +++ b/Lib/cgi.py @@ -200,7 +200,10 @@ def parse_multipart(fp, pdict, encoding="utf-8", errors="replace"): ctype = "multipart/form-data; boundary={}".format(boundary) headers = Message() headers.set_type(ctype) - headers['Content-Length'] = pdict['CONTENT-LENGTH'] + try: + headers['Content-Length'] = pdict['CONTENT-LENGTH'] + except KeyError: + pass fs = FieldStorage(fp, headers=headers, encoding=encoding, errors=errors, environ={'REQUEST_METHOD': 'POST'}) return {k: fs.getlist(k) for k in fs} @@ -736,7 +739,8 @@ class FieldStorage: last_line_lfend = True _read = 0 while 1: - if self.limit is not None and _read >= self.limit: + + if self.limit is not None and 0 <= self.limit <= _read: break line = self.fp.readline(1<<16) # bytes self.bytes_read += len(line) diff --git a/Lib/codeop.py b/Lib/codeop.py index 835e68c09ba..7e192ea6a10 100644 --- a/Lib/codeop.py +++ b/Lib/codeop.py @@ -57,6 +57,7 @@ Compile(): """ import __future__ +import warnings _features = [getattr(__future__, fname) for fname in __future__.all_feature_names] @@ -83,15 +84,18 @@ def _maybe_compile(compiler, source, filename, symbol): except SyntaxError: pass - try: - code1 = compiler(source + "\n", filename, symbol) - except SyntaxError as e: - err1 = e + # Suppress warnings after the first compile to avoid duplication. + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + try: + code1 = compiler(source + "\n", filename, symbol) + except SyntaxError as e: + err1 = e - try: - code2 = compiler(source + "\n\n", filename, symbol) - except SyntaxError as e: - err2 = e + try: + code2 = compiler(source + "\n\n", filename, symbol) + except SyntaxError as e: + err2 = e try: if code: diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 011a0c1e7c1..5d75501645f 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -14,17 +14,29 @@ list, set, and tuple. ''' -__all__ = ['deque', 'defaultdict', 'namedtuple', 'UserDict', 'UserList', - 'UserString', 'Counter', 'OrderedDict', 'ChainMap'] +__all__ = [ + 'ChainMap', + 'Counter', + 'OrderedDict', + 'UserDict', + 'UserList', + 'UserString', + 'defaultdict', + 'deque', + 'namedtuple', +] import _collections_abc -from operator import itemgetter as _itemgetter, eq as _eq -from keyword import iskeyword as _iskeyword import sys as _sys -import heapq as _heapq -from _weakref import proxy as _proxy -from itertools import repeat as _repeat, chain as _chain, starmap as _starmap + +from itertools import chain as _chain +from itertools import repeat as _repeat +from itertools import starmap as _starmap +from keyword import iskeyword as _iskeyword +from operator import eq as _eq +from operator import itemgetter as _itemgetter from reprlib import recursive_repr as _recursive_repr +from _weakref import proxy as _proxy try: from _collections import deque @@ -54,6 +66,7 @@ def __getattr__(name): return obj raise AttributeError(f'module {__name__!r} has no attribute {name!r}') + ################################################################################ ### OrderedDict ################################################################################ @@ -399,16 +412,23 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non # Variables used in the methods and docstrings field_names = tuple(map(_sys.intern, field_names)) num_fields = len(field_names) - arg_list = repr(field_names).replace("'", "")[1:-1] + arg_list = ', '.join(field_names) + if num_fields == 1: + arg_list += ',' repr_fmt = '(' + ', '.join(f'{name}=%r' for name in field_names) + ')' tuple_new = tuple.__new__ _dict, _tuple, _len, _map, _zip = dict, tuple, len, map, zip # Create all the named tuple methods to be added to the class namespace - s = f'lambda _cls, {arg_list}: _tuple_new(_cls, ({arg_list}))' - namespace = {'_tuple_new': tuple_new, '__name__': f'namedtuple_{typename}'} - __new__ = eval(s, namespace) + namespace = { + '_tuple_new': tuple_new, + '__builtins__': None, + '__name__': f'namedtuple_{typename}', + } + code = f'lambda _cls, {arg_list}: _tuple_new(_cls, ({arg_list}))' + __new__ = eval(code, namespace) + __new__.__name__ = '__new__' __new__.__doc__ = f'Create new instance of {typename}({arg_list})' if defaults is not None: __new__.__defaults__ = defaults @@ -445,8 +465,14 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non return _tuple(self) # Modify function metadata to help with introspection and debugging - for method in (__new__, _make.__func__, _replace, - __repr__, _asdict, __getnewargs__): + for method in ( + __new__, + _make.__func__, + _replace, + __repr__, + _asdict, + __getnewargs__, + ): method.__qualname__ = f'{typename}.{method.__name__}' # Build-up the class namespace dictionary @@ -562,7 +588,7 @@ class Counter(dict): >>> c = Counter(a=4, b=2) # a new counter from keyword args ''' - super(Counter, self).__init__() + super().__init__() self.update(iterable, **kwds) def __missing__(self, key): @@ -581,7 +607,10 @@ class Counter(dict): # Emulate Bag.sortedByCount from Smalltalk if n is None: return sorted(self.items(), key=_itemgetter(1), reverse=True) - return _heapq.nlargest(n, self.items(), key=_itemgetter(1)) + + # Lazy import to speedup Python startup time + import heapq + return heapq.nlargest(n, self.items(), key=_itemgetter(1)) def elements(self): '''Iterator over elements repeating each as many times as its count. @@ -646,7 +675,8 @@ class Counter(dict): for elem, count in iterable.items(): self[elem] = count + self_get(elem, 0) else: - super(Counter, self).update(iterable) # fast path when counter is empty + # fast path when counter is empty + super().update(iterable) else: _count_elements(self, iterable) if kwds: @@ -691,15 +721,52 @@ class Counter(dict): if elem in self: super().__delitem__(elem) + def __eq__(self, other): + 'True if all counts agree. Missing counts are treated as zero.' + if not isinstance(other, Counter): + return NotImplemented + return all(self[e] == other[e] for c in (self, other) for e in c) + + def __ne__(self, other): + 'True if any counts disagree. Missing counts are treated as zero.' + if not isinstance(other, Counter): + return NotImplemented + return not self == other + + def __le__(self, other): + 'True if all counts in self are a subset of those in other.' + if not isinstance(other, Counter): + return NotImplemented + return all(self[e] <= other[e] for c in (self, other) for e in c) + + def __lt__(self, other): + 'True if all counts in self are a proper subset of those in other.' + if not isinstance(other, Counter): + return NotImplemented + return self <= other and self != other + + def __ge__(self, other): + 'True if all counts in self are a superset of those in other.' + if not isinstance(other, Counter): + return NotImplemented + return all(self[e] >= other[e] for c in (self, other) for e in c) + + def __gt__(self, other): + 'True if all counts in self are a proper superset of those in other.' + if not isinstance(other, Counter): + return NotImplemented + return self >= other and self != other + def __repr__(self): if not self: - return '%s()' % self.__class__.__name__ + return f'{self.__class__.__name__}()' try: - items = ', '.join(map('%r: %r'.__mod__, self.most_common())) - return '%s({%s})' % (self.__class__.__name__, items) + # dict() preserves the ordering returned by most_common() + d = dict(self.most_common()) except TypeError: # handle case where values are not orderable - return '{0}({1!r})'.format(self.__class__.__name__, dict(self)) + d = dict(self) + return f'{self.__class__.__name__}({d!r})' # Multiset-style mathematical operations discussed in: # Knuth TAOCP Volume II section 4.6.3 exercise 19 @@ -710,12 +777,26 @@ class Counter(dict): # To strip negative and zero counts, add-in an empty counter: # c += Counter() # - # Rich comparison operators for multiset subset and superset tests - # are deliberately omitted due to semantic conflicts with the - # existing inherited dict equality method. Subset and superset - # semantics ignore zero counts and require that p≤q ∧ p≥q → p=q; - # however, that would not be the case for p=Counter(a=1, b=0) - # and q=Counter(a=1) where the dictionaries are not equal. + # When the multiplicities are all zero or one, multiset operations + # are guaranteed to be equivalent to the corresponding operations + # for regular sets. + # Given counter multisets such as: + # cp = Counter(a=1, b=0, c=1) + # cq = Counter(c=1, d=0, e=1) + # The corresponding regular sets would be: + # sp = {'a', 'c'} + # sq = {'c', 'e'} + # All of the following relations would hold: + # set(cp + cq) == sp | sq + # set(cp - cq) == sp - sq + # set(cp | cq) == sp | sq + # set(cp & cq) == sp & sq + # (cp == cq) == (sp == sq) + # (cp != cq) == (sp != sq) + # (cp <= cq) == (sp <= sq) + # (cp < cq) == (sp < sq) + # (cp >= cq) == (sp >= sq) + # (cp > cq) == (sp > sq) def __add__(self, other): '''Add counts from two counters. @@ -964,7 +1045,7 @@ class ChainMap(_collections_abc.MutableMapping): try: del self.maps[0][key] except KeyError: - raise KeyError('Key not found in the first mapping: {!r}'.format(key)) + raise KeyError(f'Key not found in the first mapping: {key!r}') def popitem(self): 'Remove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.' @@ -978,30 +1059,30 @@ class ChainMap(_collections_abc.MutableMapping): try: return self.maps[0].pop(key, *args) except KeyError: - raise KeyError('Key not found in the first mapping: {!r}'.format(key)) + raise KeyError(f'Key not found in the first mapping: {key!r}') def clear(self): 'Clear maps[0], leaving maps[1:] intact.' self.maps[0].clear() def __ior__(self, other): - self.maps[0] |= other + self.maps[0].update(other) return self def __or__(self, other): - if isinstance(other, _collections_abc.Mapping): - m = self.maps[0].copy() - m.update(other) - return self.__class__(m, *self.maps[1:]) - return NotImplemented + if not isinstance(other, _collections_abc.Mapping): + return NotImplemented + m = self.copy() + m.maps[0].update(other) + return m def __ror__(self, other): - if isinstance(other, _collections_abc.Mapping): - m = dict(other) - for child in reversed(self.maps): - m.update(child) - return self.__class__(m) - return NotImplemented + if not isinstance(other, _collections_abc.Mapping): + return NotImplemented + m = dict(other) + for child in reversed(self.maps): + m.update(child) + return self.__class__(m) ################################################################################ @@ -1018,15 +1099,22 @@ class UserDict(_collections_abc.MutableMapping): if kwargs: self.update(kwargs) - def __len__(self): return len(self.data) + def __len__(self): + return len(self.data) + def __getitem__(self, key): if key in self.data: return self.data[key] if hasattr(self.__class__, "__missing__"): return self.__class__.__missing__(self, key) raise KeyError(key) - def __setitem__(self, key, item): self.data[key] = item - def __delitem__(self, key): del self.data[key] + + def __setitem__(self, key, item): + self.data[key] = item + + def __delitem__(self, key): + del self.data[key] + def __iter__(self): return iter(self.data) @@ -1035,7 +1123,8 @@ class UserDict(_collections_abc.MutableMapping): return key in self.data # Now, add the methods in dicts but not in MutableMapping - def __repr__(self): return repr(self.data) + def __repr__(self): + return repr(self.data) def __or__(self, other): if isinstance(other, UserDict): @@ -1043,12 +1132,14 @@ class UserDict(_collections_abc.MutableMapping): if isinstance(other, dict): return self.__class__(self.data | other) return NotImplemented + def __ror__(self, other): if isinstance(other, UserDict): return self.__class__(other.data | self.data) if isinstance(other, dict): return self.__class__(other | self.data) return NotImplemented + def __ior__(self, other): if isinstance(other, UserDict): self.data |= other.data @@ -1084,13 +1175,13 @@ class UserDict(_collections_abc.MutableMapping): return d - ################################################################################ ### UserList ################################################################################ class UserList(_collections_abc.MutableSequence): """A more or less complete user-defined wrapper around list objects.""" + def __init__(self, initlist=None): self.data = [] if initlist is not None: @@ -1101,35 +1192,60 @@ class UserList(_collections_abc.MutableSequence): self.data[:] = initlist.data[:] else: self.data = list(initlist) - def __repr__(self): return repr(self.data) - def __lt__(self, other): return self.data < self.__cast(other) - def __le__(self, other): return self.data <= self.__cast(other) - def __eq__(self, other): return self.data == self.__cast(other) - def __gt__(self, other): return self.data > self.__cast(other) - def __ge__(self, other): return self.data >= self.__cast(other) + + def __repr__(self): + return repr(self.data) + + def __lt__(self, other): + return self.data < self.__cast(other) + + def __le__(self, other): + return self.data <= self.__cast(other) + + def __eq__(self, other): + return self.data == self.__cast(other) + + def __gt__(self, other): + return self.data > self.__cast(other) + + def __ge__(self, other): + return self.data >= self.__cast(other) + def __cast(self, other): return other.data if isinstance(other, UserList) else other - def __contains__(self, item): return item in self.data - def __len__(self): return len(self.data) + + def __contains__(self, item): + return item in self.data + + def __len__(self): + return len(self.data) + def __getitem__(self, i): if isinstance(i, slice): return self.__class__(self.data[i]) else: return self.data[i] - def __setitem__(self, i, item): self.data[i] = item - def __delitem__(self, i): del self.data[i] + + def __setitem__(self, i, item): + self.data[i] = item + + def __delitem__(self, i): + del self.data[i] + def __add__(self, other): if isinstance(other, UserList): return self.__class__(self.data + other.data) elif isinstance(other, type(self.data)): return self.__class__(self.data + other) return self.__class__(self.data + list(other)) + def __radd__(self, other): if isinstance(other, UserList): return self.__class__(other.data + self.data) elif isinstance(other, type(self.data)): return self.__class__(other + self.data) return self.__class__(list(other) + self.data) + def __iadd__(self, other): if isinstance(other, UserList): self.data += other.data @@ -1138,28 +1254,53 @@ class UserList(_collections_abc.MutableSequence): else: self.data += list(other) return self + def __mul__(self, n): - return self.__class__(self.data*n) + return self.__class__(self.data * n) + __rmul__ = __mul__ + def __imul__(self, n): self.data *= n return self + def __copy__(self): inst = self.__class__.__new__(self.__class__) inst.__dict__.update(self.__dict__) # Create a copy and avoid triggering descriptors inst.__dict__["data"] = self.__dict__["data"][:] return inst - def append(self, item): self.data.append(item) - def insert(self, i, item): self.data.insert(i, item) - def pop(self, i=-1): return self.data.pop(i) - def remove(self, item): self.data.remove(item) - def clear(self): self.data.clear() - def copy(self): return self.__class__(self) - def count(self, item): return self.data.count(item) - def index(self, item, *args): return self.data.index(item, *args) - def reverse(self): self.data.reverse() - def sort(self, /, *args, **kwds): self.data.sort(*args, **kwds) + + def append(self, item): + self.data.append(item) + + def insert(self, i, item): + self.data.insert(i, item) + + def pop(self, i=-1): + return self.data.pop(i) + + def remove(self, item): + self.data.remove(item) + + def clear(self): + self.data.clear() + + def copy(self): + return self.__class__(self) + + def count(self, item): + return self.data.count(item) + + def index(self, item, *args): + return self.data.index(item, *args) + + def reverse(self): + self.data.reverse() + + def sort(self, /, *args, **kwds): + self.data.sort(*args, **kwds) + def extend(self, other): if isinstance(other, UserList): self.data.extend(other.data) @@ -1167,12 +1308,12 @@ class UserList(_collections_abc.MutableSequence): self.data.extend(other) - ################################################################################ ### UserString ################################################################################ class UserString(_collections_abc.Sequence): + def __init__(self, seq): if isinstance(seq, str): self.data = seq @@ -1180,12 +1321,25 @@ class UserString(_collections_abc.Sequence): self.data = seq.data[:] else: self.data = str(seq) - def __str__(self): return str(self.data) - def __repr__(self): return repr(self.data) - def __int__(self): return int(self.data) - def __float__(self): return float(self.data) - def __complex__(self): return complex(self.data) - def __hash__(self): return hash(self.data) + + def __str__(self): + return str(self.data) + + def __repr__(self): + return repr(self.data) + + def __int__(self): + return int(self.data) + + def __float__(self): + return float(self.data) + + def __complex__(self): + return complex(self.data) + + def __hash__(self): + return hash(self.data) + def __getnewargs__(self): return (self.data[:],) @@ -1193,18 +1347,22 @@ class UserString(_collections_abc.Sequence): if isinstance(string, UserString): return self.data == string.data return self.data == string + def __lt__(self, string): if isinstance(string, UserString): return self.data < string.data return self.data < string + def __le__(self, string): if isinstance(string, UserString): return self.data <= string.data return self.data <= string + def __gt__(self, string): if isinstance(string, UserString): return self.data > string.data return self.data > string + def __ge__(self, string): if isinstance(string, UserString): return self.data >= string.data @@ -1215,110 +1373,188 @@ class UserString(_collections_abc.Sequence): char = char.data return char in self.data - def __len__(self): return len(self.data) - def __getitem__(self, index): return self.__class__(self.data[index]) + def __len__(self): + return len(self.data) + + def __getitem__(self, index): + return self.__class__(self.data[index]) + def __add__(self, other): if isinstance(other, UserString): return self.__class__(self.data + other.data) elif isinstance(other, str): return self.__class__(self.data + other) return self.__class__(self.data + str(other)) + def __radd__(self, other): if isinstance(other, str): return self.__class__(other + self.data) return self.__class__(str(other) + self.data) + def __mul__(self, n): - return self.__class__(self.data*n) + return self.__class__(self.data * n) + __rmul__ = __mul__ + def __mod__(self, args): return self.__class__(self.data % args) + def __rmod__(self, template): return self.__class__(str(template) % self) + # the following methods are defined in alphabetical order: - def capitalize(self): return self.__class__(self.data.capitalize()) + def capitalize(self): + return self.__class__(self.data.capitalize()) + def casefold(self): return self.__class__(self.data.casefold()) + def center(self, width, *args): return self.__class__(self.data.center(width, *args)) + def count(self, sub, start=0, end=_sys.maxsize): if isinstance(sub, UserString): sub = sub.data return self.data.count(sub, start, end) + def removeprefix(self, prefix, /): if isinstance(prefix, UserString): prefix = prefix.data return self.__class__(self.data.removeprefix(prefix)) + def removesuffix(self, suffix, /): if isinstance(suffix, UserString): suffix = suffix.data return self.__class__(self.data.removesuffix(suffix)) + def encode(self, encoding='utf-8', errors='strict'): encoding = 'utf-8' if encoding is None else encoding errors = 'strict' if errors is None else errors return self.data.encode(encoding, errors) + def endswith(self, suffix, start=0, end=_sys.maxsize): return self.data.endswith(suffix, start, end) + def expandtabs(self, tabsize=8): return self.__class__(self.data.expandtabs(tabsize)) + def find(self, sub, start=0, end=_sys.maxsize): if isinstance(sub, UserString): sub = sub.data return self.data.find(sub, start, end) + def format(self, /, *args, **kwds): return self.data.format(*args, **kwds) + def format_map(self, mapping): return self.data.format_map(mapping) + def index(self, sub, start=0, end=_sys.maxsize): return self.data.index(sub, start, end) - def isalpha(self): return self.data.isalpha() - def isalnum(self): return self.data.isalnum() - def isascii(self): return self.data.isascii() - def isdecimal(self): return self.data.isdecimal() - def isdigit(self): return self.data.isdigit() - def isidentifier(self): return self.data.isidentifier() - def islower(self): return self.data.islower() - def isnumeric(self): return self.data.isnumeric() - def isprintable(self): return self.data.isprintable() - def isspace(self): return self.data.isspace() - def istitle(self): return self.data.istitle() - def isupper(self): return self.data.isupper() - def join(self, seq): return self.data.join(seq) + + def isalpha(self): + return self.data.isalpha() + + def isalnum(self): + return self.data.isalnum() + + def isascii(self): + return self.data.isascii() + + def isdecimal(self): + return self.data.isdecimal() + + def isdigit(self): + return self.data.isdigit() + + def isidentifier(self): + return self.data.isidentifier() + + def islower(self): + return self.data.islower() + + def isnumeric(self): + return self.data.isnumeric() + + def isprintable(self): + return self.data.isprintable() + + def isspace(self): + return self.data.isspace() + + def istitle(self): + return self.data.istitle() + + def isupper(self): + return self.data.isupper() + + def join(self, seq): + return self.data.join(seq) + def ljust(self, width, *args): return self.__class__(self.data.ljust(width, *args)) - def lower(self): return self.__class__(self.data.lower()) - def lstrip(self, chars=None): return self.__class__(self.data.lstrip(chars)) + + def lower(self): + return self.__class__(self.data.lower()) + + def lstrip(self, chars=None): + return self.__class__(self.data.lstrip(chars)) + maketrans = str.maketrans + def partition(self, sep): return self.data.partition(sep) + def replace(self, old, new, maxsplit=-1): if isinstance(old, UserString): old = old.data if isinstance(new, UserString): new = new.data return self.__class__(self.data.replace(old, new, maxsplit)) + def rfind(self, sub, start=0, end=_sys.maxsize): if isinstance(sub, UserString): sub = sub.data return self.data.rfind(sub, start, end) + def rindex(self, sub, start=0, end=_sys.maxsize): return self.data.rindex(sub, start, end) + def rjust(self, width, *args): return self.__class__(self.data.rjust(width, *args)) + def rpartition(self, sep): return self.data.rpartition(sep) + def rstrip(self, chars=None): return self.__class__(self.data.rstrip(chars)) + def split(self, sep=None, maxsplit=-1): return self.data.split(sep, maxsplit) + def rsplit(self, sep=None, maxsplit=-1): return self.data.rsplit(sep, maxsplit) - def splitlines(self, keepends=False): return self.data.splitlines(keepends) + + def splitlines(self, keepends=False): + return self.data.splitlines(keepends) + def startswith(self, prefix, start=0, end=_sys.maxsize): return self.data.startswith(prefix, start, end) - def strip(self, chars=None): return self.__class__(self.data.strip(chars)) - def swapcase(self): return self.__class__(self.data.swapcase()) - def title(self): return self.__class__(self.data.title()) + + def strip(self, chars=None): + return self.__class__(self.data.strip(chars)) + + def swapcase(self): + return self.__class__(self.data.swapcase()) + + def title(self): + return self.__class__(self.data.title()) + def translate(self, *args): return self.__class__(self.data.translate(*args)) - def upper(self): return self.__class__(self.data.upper()) - def zfill(self, width): return self.__class__(self.data.zfill(width)) + + def upper(self): + return self.__class__(self.data.upper()) + + def zfill(self, width): + return self.__class__(self.data.zfill(width)) diff --git a/Lib/copy.py b/Lib/copy.py index 41873f2c046..dd41c54dffe 100644 --- a/Lib/copy.py +++ b/Lib/copy.py @@ -192,6 +192,7 @@ d[bytes] = _deepcopy_atomic d[str] = _deepcopy_atomic d[types.CodeType] = _deepcopy_atomic d[type] = _deepcopy_atomic +d[range] = _deepcopy_atomic d[types.BuiltinFunctionType] = _deepcopy_atomic d[types.FunctionType] = _deepcopy_atomic d[weakref.ref] = _deepcopy_atomic diff --git a/Lib/ctypes/test/__init__.py b/Lib/ctypes/test/__init__.py index 26a70b76963..6e496fa5a52 100644 --- a/Lib/ctypes/test/__init__.py +++ b/Lib/ctypes/test/__init__.py @@ -1,9 +1,11 @@ import os import unittest from test import support +from test.support import import_helper + # skip tests if _ctypes was not built -ctypes = support.import_module('ctypes') +ctypes = import_helper.import_module('ctypes') ctypes_symbols = dir(ctypes) def need_symbol(name): diff --git a/Lib/ctypes/test/test_callbacks.py b/Lib/ctypes/test/test_callbacks.py index f622093df61..d8e9c5a760e 100644 --- a/Lib/ctypes/test/test_callbacks.py +++ b/Lib/ctypes/test/test_callbacks.py @@ -1,5 +1,7 @@ import functools import unittest +from test import support + from ctypes import * from ctypes.test import need_symbol import _ctypes_test @@ -287,7 +289,36 @@ class SampleCallbacksTestCase(unittest.TestCase): self.assertEqual(s.second, check.second) self.assertEqual(s.third, check.third) -################################################################ + def test_callback_too_many_args(self): + def func(*args): + return len(args) + + CTYPES_MAX_ARGCOUNT = 1024 + proto = CFUNCTYPE(c_int, *(c_int,) * CTYPES_MAX_ARGCOUNT) + cb = proto(func) + args1 = (1,) * CTYPES_MAX_ARGCOUNT + self.assertEqual(cb(*args1), CTYPES_MAX_ARGCOUNT) + + args2 = (1,) * (CTYPES_MAX_ARGCOUNT + 1) + with self.assertRaises(ArgumentError): + cb(*args2) + + def test_convert_result_error(self): + def func(): + return ("tuple",) + + proto = CFUNCTYPE(c_int) + ctypes_func = proto(func) + with support.catch_unraisable_exception() as cm: + # don't test the result since it is an uninitialized value + result = ctypes_func() + + self.assertIsInstance(cm.unraisable.exc_value, TypeError) + self.assertEqual(cm.unraisable.err_msg, + "Exception ignored on converting result " + "of ctypes callback function") + self.assertIs(cm.unraisable.object, func) + if __name__ == '__main__': unittest.main() diff --git a/Lib/ctypes/test/test_find.py b/Lib/ctypes/test/test_find.py index b99fdcba7b2..bfb6b42cbb2 100644 --- a/Lib/ctypes/test/test_find.py +++ b/Lib/ctypes/test/test_find.py @@ -2,6 +2,7 @@ import unittest import os.path import sys import test.support +from test.support import os_helper from ctypes import * from ctypes.util import find_library @@ -65,8 +66,8 @@ class Test_OpenGL_libs(unittest.TestCase): self.gle.gleGetJoinStyle def test_shell_injection(self): - result = find_library('; echo Hello shell > ' + test.support.TESTFN) - self.assertFalse(os.path.lexists(test.support.TESTFN)) + result = find_library('; echo Hello shell > ' + os_helper.TESTFN) + self.assertFalse(os.path.lexists(os_helper.TESTFN)) self.assertIsNone(result) @@ -100,7 +101,7 @@ class LibPathFindTest(unittest.TestCase): # LD_LIBRARY_PATH) self.assertIsNone(find_library(libname)) # now add the location to LD_LIBRARY_PATH - with test.support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: KEY = 'LD_LIBRARY_PATH' if KEY not in env: v = d diff --git a/Lib/ctypes/test/test_random_things.py b/Lib/ctypes/test/test_random_things.py index ee5b2128ea0..2988e275cf4 100644 --- a/Lib/ctypes/test/test_random_things.py +++ b/Lib/ctypes/test/test_random_things.py @@ -1,5 +1,9 @@ from ctypes import * -import unittest, sys +import contextlib +from test import support +import unittest +import sys + def callback_func(arg): 42 / arg @@ -34,41 +38,40 @@ class CallbackTracbackTestCase(unittest.TestCase): # created, then a full traceback printed. When SystemExit is # raised in a callback function, the interpreter exits. - def capture_stderr(self, func, *args, **kw): - # helper - call function 'func', and return the captured stderr - import io - old_stderr = sys.stderr - logger = sys.stderr = io.StringIO() - try: - func(*args, **kw) - finally: - sys.stderr = old_stderr - return logger.getvalue() + @contextlib.contextmanager + def expect_unraisable(self, exc_type, exc_msg=None): + with support.catch_unraisable_exception() as cm: + yield + + self.assertIsInstance(cm.unraisable.exc_value, exc_type) + if exc_msg is not None: + self.assertEqual(str(cm.unraisable.exc_value), exc_msg) + self.assertEqual(cm.unraisable.err_msg, + "Exception ignored on calling ctypes " + "callback function") + self.assertIs(cm.unraisable.object, callback_func) def test_ValueError(self): cb = CFUNCTYPE(c_int, c_int)(callback_func) - out = self.capture_stderr(cb, 42) - self.assertEqual(out.splitlines()[-1], - "ValueError: 42") + with self.expect_unraisable(ValueError, '42'): + cb(42) def test_IntegerDivisionError(self): cb = CFUNCTYPE(c_int, c_int)(callback_func) - out = self.capture_stderr(cb, 0) - self.assertEqual(out.splitlines()[-1][:19], - "ZeroDivisionError: ") + with self.expect_unraisable(ZeroDivisionError): + cb(0) def test_FloatDivisionError(self): cb = CFUNCTYPE(c_int, c_double)(callback_func) - out = self.capture_stderr(cb, 0.0) - self.assertEqual(out.splitlines()[-1][:19], - "ZeroDivisionError: ") + with self.expect_unraisable(ZeroDivisionError): + cb(0.0) def test_TypeErrorDivisionError(self): cb = CFUNCTYPE(c_int, c_char_p)(callback_func) - out = self.capture_stderr(cb, b"spam") - self.assertEqual(out.splitlines()[-1], - "TypeError: " - "unsupported operand type(s) for /: 'int' and 'bytes'") + err_msg = "unsupported operand type(s) for /: 'int' and 'bytes'" + with self.expect_unraisable(TypeError, err_msg): + cb(b"spam") + if __name__ == '__main__': unittest.main() diff --git a/Lib/ctypes/test/test_struct_fields.py b/Lib/ctypes/test/test_struct_fields.py index 8045cc82679..ee8415f3e63 100644 --- a/Lib/ctypes/test/test_struct_fields.py +++ b/Lib/ctypes/test/test_struct_fields.py @@ -46,6 +46,14 @@ class StructFieldsTestCase(unittest.TestCase): Y._fields_ = [] self.assertRaises(AttributeError, setattr, X, "_fields_", []) + def test_5(self): + class X(Structure): + _fields_ = (("char", c_char * 5),) + + x = X(b'#' * 5) + x.char = b'a\0b\0' + self.assertEqual(bytes(x), b'a\x00###') + # __set__ and __get__ should raise a TypeError in case their self # argument is not a ctype instance. def test___set__(self): diff --git a/Lib/ctypes/test/test_unaligned_structures.py b/Lib/ctypes/test/test_unaligned_structures.py index bcacfc8184b..ee7fb45809b 100644 --- a/Lib/ctypes/test/test_unaligned_structures.py +++ b/Lib/ctypes/test/test_unaligned_structures.py @@ -27,7 +27,6 @@ for typ in [c_short, c_int, c_long, c_longlong, class TestStructures(unittest.TestCase): def test_native(self): for typ in structures: -## print typ.value self.assertEqual(typ.value.offset, 1) o = typ() o.value = 4 @@ -35,7 +34,6 @@ class TestStructures(unittest.TestCase): def test_swapped(self): for typ in byteswapped_structures: -## print >> sys.stderr, typ.value self.assertEqual(typ.value.offset, 1) o = typ() o.value = 4 diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py index fc69508354b..530d3e99574 100644 --- a/Lib/dataclasses.py +++ b/Lib/dataclasses.py @@ -1094,7 +1094,7 @@ def _asdict_inner(obj, dict_factory): # method, because: # - it does not recurse in to the namedtuple fields and # convert them to dicts (using dict_factory). - # - I don't actually want to return a dict here. The the main + # - I don't actually want to return a dict here. The main # use case here is json.dumps, and it handles converting # namedtuples to lists. Admittedly we're losing some # information here when we produce a json list instead of a diff --git a/Lib/distutils/command/build_py.py b/Lib/distutils/command/build_py.py index cf0ca57c320..edc2171cd12 100644 --- a/Lib/distutils/command/build_py.py +++ b/Lib/distutils/command/build_py.py @@ -5,7 +5,7 @@ Implements the Distutils 'build_py' command.""" import os import importlib.util import sys -from glob import glob +import glob from distutils.core import Command from distutils.errors import * @@ -125,7 +125,7 @@ class build_py (Command): files = [] for pattern in globs: # Each pattern has to be converted to a platform-specific path - filelist = glob(os.path.join(src_dir, convert_path(pattern))) + filelist = glob.glob(os.path.join(glob.escape(src_dir), convert_path(pattern))) # Files that match more than one pattern are only added once files.extend([fn for fn in filelist if fn not in files and os.path.isfile(fn)]) @@ -216,7 +216,7 @@ class build_py (Command): def find_package_modules(self, package, package_dir): self.check_package(package, package_dir) - module_files = glob(os.path.join(package_dir, "*.py")) + module_files = glob.glob(os.path.join(glob.escape(package_dir), "*.py")) modules = [] setup_script = os.path.abspath(self.distribution.script_name) diff --git a/Lib/distutils/tests/__init__.py b/Lib/distutils/tests/__init__.py index 5d2e69e3e6a..16d011fd9ee 100644 --- a/Lib/distutils/tests/__init__.py +++ b/Lib/distutils/tests/__init__.py @@ -15,26 +15,25 @@ by import rather than matching pre-defined names. import os import sys import unittest -import warnings from test.support import run_unittest +from test.support.warnings_helper import save_restore_warnings_filters here = os.path.dirname(__file__) or os.curdir def test_suite(): - old_filters = warnings.filters[:] suite = unittest.TestSuite() for fn in os.listdir(here): if fn.startswith("test") and fn.endswith(".py"): modname = "distutils.tests." + fn[:-3] - __import__(modname) + # bpo-40055: Save/restore warnings filters to leave them unchanged. + # Importing tests imports docutils which imports pkg_resources + # which adds a warnings filter. + with save_restore_warnings_filters(): + __import__(modname) module = sys.modules[modname] suite.addTest(module.test_suite()) - # bpo-40055: Save/restore warnings filters to leave them unchanged. - # Importing tests imports docutils which imports pkg_resources which adds a - # warnings filter. - warnings.filters[:] = old_filters return suite diff --git a/Lib/distutils/tests/support.py b/Lib/distutils/tests/support.py index 259af882ec0..23b907b607e 100644 --- a/Lib/distutils/tests/support.py +++ b/Lib/distutils/tests/support.py @@ -6,7 +6,7 @@ import tempfile import unittest import sysconfig from copy import deepcopy -import test.support +from test.support import os_helper from distutils import log from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL @@ -64,7 +64,7 @@ class TempdirManager(object): super().tearDown() while self.tempdirs: tmpdir = self.tempdirs.pop() - test.support.rmtree(tmpdir) + os_helper.rmtree(tmpdir) def mkdtemp(self): """Create a temporary directory that will be cleaned up. diff --git a/Lib/distutils/tests/test_archive_util.py b/Lib/distutils/tests/test_archive_util.py index e9aad0e40fd..edcec2513e0 100644 --- a/Lib/distutils/tests/test_archive_util.py +++ b/Lib/distutils/tests/test_archive_util.py @@ -13,7 +13,9 @@ from distutils.archive_util import (check_archive_formats, make_tarball, ARCHIVE_FORMATS) from distutils.spawn import find_executable, spawn from distutils.tests import support -from test.support import check_warnings, run_unittest, patch, change_cwd +from test.support import run_unittest, patch +from test.support.os_helper import change_cwd +from test.support.warnings_helper import check_warnings try: import grp diff --git a/Lib/distutils/tests/test_bdist_msi.py b/Lib/distutils/tests/test_bdist_msi.py index 418e60ec729..a61266a14f9 100644 --- a/Lib/distutils/tests/test_bdist_msi.py +++ b/Lib/distutils/tests/test_bdist_msi.py @@ -1,7 +1,8 @@ """Tests for distutils.command.bdist_msi.""" import sys import unittest -from test.support import run_unittest, check_warnings +from test.support import run_unittest +from test.support.warnings_helper import check_warnings from distutils.tests import support diff --git a/Lib/distutils/tests/test_bdist_wininst.py b/Lib/distutils/tests/test_bdist_wininst.py index 5c3d025d332..c338069a1dc 100644 --- a/Lib/distutils/tests/test_bdist_wininst.py +++ b/Lib/distutils/tests/test_bdist_wininst.py @@ -2,7 +2,8 @@ import sys import platform import unittest -from test.support import run_unittest, check_warnings +from test.support import run_unittest +from test.support.warnings_helper import check_warnings from distutils.command.bdist_wininst import bdist_wininst from distutils.tests import support diff --git a/Lib/distutils/tests/test_build_ext.py b/Lib/distutils/tests/test_build_ext.py index 5e47e0773a9..f9e0d766d87 100644 --- a/Lib/distutils/tests/test_build_ext.py +++ b/Lib/distutils/tests/test_build_ext.py @@ -15,6 +15,7 @@ from distutils.errors import ( import unittest from test import support +from test.support import os_helper from test.support.script_helper import assert_python_ok # http://bugs.python.org/issue4373 @@ -38,7 +39,7 @@ class BuildExtTestCase(TempdirManager, # bpo-30132: On Windows, a .pdb file may be created in the current # working directory. Create a temporary working directory to cleanup # everything at the end of the test. - change_cwd = support.change_cwd(self.tmp_dir) + change_cwd = os_helper.change_cwd(self.tmp_dir) change_cwd.__enter__() self.addCleanup(change_cwd.__exit__, None, None, None) diff --git a/Lib/distutils/tests/test_core.py b/Lib/distutils/tests/test_core.py index 27ce7324afc..4e6694a3d1c 100644 --- a/Lib/distutils/tests/test_core.py +++ b/Lib/distutils/tests/test_core.py @@ -5,8 +5,8 @@ import distutils.core import os import shutil import sys -import test.support from test.support import captured_stdout, run_unittest +from test.support import os_helper import unittest from distutils.tests import support from distutils import log @@ -62,13 +62,13 @@ class CoreTestCase(support.EnvironGuard, unittest.TestCase): super(CoreTestCase, self).tearDown() def cleanup_testfn(self): - path = test.support.TESTFN + path = os_helper.TESTFN if os.path.isfile(path): os.remove(path) elif os.path.isdir(path): shutil.rmtree(path) - def write_setup(self, text, path=test.support.TESTFN): + def write_setup(self, text, path=os_helper.TESTFN): f = open(path, "w") try: f.write(text) @@ -105,8 +105,8 @@ class CoreTestCase(support.EnvironGuard, unittest.TestCase): cwd = os.getcwd() # Create a directory and write the setup.py file there: - os.mkdir(test.support.TESTFN) - setup_py = os.path.join(test.support.TESTFN, "setup.py") + os.mkdir(os_helper.TESTFN) + setup_py = os.path.join(os_helper.TESTFN, "setup.py") distutils.core.run_setup( self.write_setup(setup_prints_cwd, path=setup_py)) diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py index 60956dadef2..f8a9e86b16f 100644 --- a/Lib/distutils/tests/test_dist.py +++ b/Lib/distutils/tests/test_dist.py @@ -12,8 +12,9 @@ from distutils.dist import Distribution, fix_help_options from distutils.cmd import Command from test.support import ( - TESTFN, captured_stdout, captured_stderr, run_unittest + captured_stdout, captured_stderr, run_unittest ) +from test.support.os_helper import TESTFN from distutils.tests import support from distutils import log diff --git a/Lib/distutils/tests/test_extension.py b/Lib/distutils/tests/test_extension.py index e35f2738b6a..81fad02dbec 100644 --- a/Lib/distutils/tests/test_extension.py +++ b/Lib/distutils/tests/test_extension.py @@ -3,7 +3,8 @@ import unittest import os import warnings -from test.support import check_warnings, run_unittest +from test.support import run_unittest +from test.support.warnings_helper import check_warnings from distutils.extension import read_setup_file, Extension class ExtensionTestCase(unittest.TestCase): diff --git a/Lib/distutils/tests/test_file_util.py b/Lib/distutils/tests/test_file_util.py index a4e2d025f96..c7783b858d5 100644 --- a/Lib/distutils/tests/test_file_util.py +++ b/Lib/distutils/tests/test_file_util.py @@ -8,7 +8,9 @@ from distutils.file_util import move_file, copy_file from distutils import log from distutils.tests import support from distutils.errors import DistutilsFileError -from test.support import run_unittest, unlink +from test.support import run_unittest +from test.support.os_helper import unlink + class FileUtilTestCase(support.TempdirManager, unittest.TestCase): diff --git a/Lib/distutils/tests/test_filelist.py b/Lib/distutils/tests/test_filelist.py index c71342d0dc4..cee97d439e6 100644 --- a/Lib/distutils/tests/test_filelist.py +++ b/Lib/distutils/tests/test_filelist.py @@ -8,7 +8,7 @@ from distutils.errors import DistutilsTemplateError from distutils.filelist import glob_to_re, translate_pattern, FileList from distutils import filelist -import test.support +from test.support import os_helper from test.support import captured_stdout, run_unittest from distutils.tests import support @@ -295,9 +295,9 @@ class FileListTestCase(support.LoggingSilencer, class FindAllTestCase(unittest.TestCase): - @test.support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_missing_symlink(self): - with test.support.temp_cwd(): + with os_helper.temp_cwd(): os.symlink('foo', 'bar') self.assertEqual(filelist.findall(), []) @@ -307,13 +307,13 @@ class FindAllTestCase(unittest.TestCase): '.' as the parameter, the dot should be omitted from the results. """ - with test.support.temp_cwd(): + with os_helper.temp_cwd(): os.mkdir('foo') file1 = os.path.join('foo', 'file1.txt') - test.support.create_empty_file(file1) + os_helper.create_empty_file(file1) os.mkdir('bar') file2 = os.path.join('bar', 'file2.txt') - test.support.create_empty_file(file2) + os_helper.create_empty_file(file2) expected = [file2, file1] self.assertEqual(sorted(filelist.findall()), expected) @@ -322,9 +322,9 @@ class FindAllTestCase(unittest.TestCase): When findall is called with another path, the full path name should be returned. """ - with test.support.temp_dir() as temp_dir: + with os_helper.temp_dir() as temp_dir: file1 = os.path.join(temp_dir, 'file1.txt') - test.support.create_empty_file(file1) + os_helper.create_empty_file(file1) expected = [file1] self.assertEqual(filelist.findall(temp_dir), expected) diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py index e68b0af3ce0..bba48633c9c 100644 --- a/Lib/distutils/tests/test_register.py +++ b/Lib/distutils/tests/test_register.py @@ -5,7 +5,8 @@ import getpass import urllib import warnings -from test.support import check_warnings, run_unittest +from test.support import run_unittest +from test.support.warnings_helper import check_warnings from distutils.command import register as register_module from distutils.command.register import register diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py index 23db1269591..752e9db5ba5 100644 --- a/Lib/distutils/tests/test_sdist.py +++ b/Lib/distutils/tests/test_sdist.py @@ -6,7 +6,8 @@ import warnings import zipfile from os.path import join from textwrap import dedent -from test.support import captured_stdout, check_warnings, run_unittest +from test.support import captured_stdout, run_unittest +from test.support.warnings_helper import check_warnings try: import zlib diff --git a/Lib/distutils/tests/test_spawn.py b/Lib/distutils/tests/test_spawn.py index cf1faad5f4d..3647bab7b1c 100644 --- a/Lib/distutils/tests/test_spawn.py +++ b/Lib/distutils/tests/test_spawn.py @@ -4,7 +4,7 @@ import stat import sys import unittest.mock from test.support import run_unittest, unix_shell -from test import support as test_support +from test.support import os_helper from distutils.spawn import find_executable from distutils.spawn import spawn @@ -44,9 +44,9 @@ class SpawnTestCase(support.TempdirManager, spawn([exe]) # should work without any error def test_find_executable(self): - with test_support.temp_dir() as tmp_dir: + with os_helper.temp_dir() as tmp_dir: # use TESTFN to get a pseudo-unique filename - program_noeext = test_support.TESTFN + program_noeext = os_helper.TESTFN # Give the temporary program an ".exe" suffix for all. # It's needed on Windows and not harmful on other platforms. program = program_noeext + ".exe" @@ -66,7 +66,7 @@ class SpawnTestCase(support.TempdirManager, self.assertEqual(rv, filename) # test find in the current directory - with test_support.change_cwd(tmp_dir): + with os_helper.change_cwd(tmp_dir): rv = find_executable(program) self.assertEqual(rv, program) @@ -76,7 +76,7 @@ class SpawnTestCase(support.TempdirManager, self.assertIsNone(rv) # PATH='': no match, except in the current directory - with test_support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['PATH'] = '' with unittest.mock.patch('distutils.spawn.os.confstr', return_value=tmp_dir, create=True), \ @@ -86,12 +86,12 @@ class SpawnTestCase(support.TempdirManager, self.assertIsNone(rv) # look in current directory - with test_support.change_cwd(tmp_dir): + with os_helper.change_cwd(tmp_dir): rv = find_executable(program) self.assertEqual(rv, program) # PATH=':': explicitly looks in the current directory - with test_support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['PATH'] = os.pathsep with unittest.mock.patch('distutils.spawn.os.confstr', return_value='', create=True), \ @@ -100,12 +100,12 @@ class SpawnTestCase(support.TempdirManager, self.assertIsNone(rv) # look in current directory - with test_support.change_cwd(tmp_dir): + with os_helper.change_cwd(tmp_dir): rv = find_executable(program) self.assertEqual(rv, program) # missing PATH: test os.confstr("CS_PATH") and os.defpath - with test_support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env.pop('PATH', None) # without confstr diff --git a/Lib/distutils/tests/test_sysconfig.py b/Lib/distutils/tests/test_sysconfig.py index 236755d0952..59676b0e0b0 100644 --- a/Lib/distutils/tests/test_sysconfig.py +++ b/Lib/distutils/tests/test_sysconfig.py @@ -10,7 +10,10 @@ import unittest from distutils import sysconfig from distutils.ccompiler import get_default_compiler from distutils.tests import support -from test.support import TESTFN, run_unittest, check_warnings, swap_item +from test.support import run_unittest, swap_item +from test.support.os_helper import TESTFN +from test.support.warnings_helper import check_warnings + class SysconfigTestCase(support.EnvironGuard, unittest.TestCase): def setUp(self): diff --git a/Lib/distutils/tests/test_unixccompiler.py b/Lib/distutils/tests/test_unixccompiler.py index eef702cf018..eefe4ba4029 100644 --- a/Lib/distutils/tests/test_unixccompiler.py +++ b/Lib/distutils/tests/test_unixccompiler.py @@ -1,7 +1,8 @@ """Tests for distutils.unixccompiler.""" import sys import unittest -from test.support import EnvironmentVarGuard, run_unittest +from test.support import run_unittest +from test.support.os_helper import EnvironmentVarGuard from distutils import sysconfig from distutils.unixccompiler import UnixCCompiler diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py index 9c55ef7fb45..51d355fbb0a 100644 --- a/Lib/email/_header_value_parser.py +++ b/Lib/email/_header_value_parser.py @@ -1218,12 +1218,21 @@ def get_bare_quoted_string(value): if value[0] in WSP: token, value = get_fws(value) elif value[:2] == '=?': + valid_ew = False try: token, value = get_encoded_word(value) bare_quoted_string.defects.append(errors.InvalidHeaderDefect( "encoded word inside quoted string")) + valid_ew = True except errors.HeaderParseError: token, value = get_qcontent(value) + # Collapse the whitespace between two encoded words that occur in a + # bare-quoted-string. + if valid_ew and len(bare_quoted_string) > 1: + if (bare_quoted_string[-1].token_type == 'fws' and + bare_quoted_string[-2].token_type == 'encoded-word'): + bare_quoted_string[-1] = EWWhiteSpaceTerminal( + bare_quoted_string[-1], 'fws') else: token, value = get_qcontent(value) bare_quoted_string.append(token) diff --git a/Lib/email/utils.py b/Lib/email/utils.py index b137ce3973a..1a7719dbc48 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -81,7 +81,7 @@ def formataddr(pair, charset='utf-8'): If the first element of pair is false, then the second element is returned unmodified. - Optional charset if given is the character set that is used to encode + The optional charset is the character set that is used to encode realname in case realname is not ASCII safe. Can be an instance of str or a Charset-like object which has a header_encode method. Default is 'utf-8'. diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py index 545fce656fd..21320a83198 100644 --- a/Lib/ensurepip/__init__.py +++ b/Lib/ensurepip/__init__.py @@ -12,13 +12,13 @@ from . import _bundled __all__ = ["version", "bootstrap"] -_SETUPTOOLS_VERSION = "41.2.0" +_SETUPTOOLS_VERSION = "47.1.0" -_PIP_VERSION = "19.2.3" +_PIP_VERSION = "20.1.1" _PROJECTS = [ - ("setuptools", _SETUPTOOLS_VERSION), - ("pip", _PIP_VERSION), + ("setuptools", _SETUPTOOLS_VERSION, "py3"), + ("pip", _PIP_VERSION, "py2.py3"), ] @@ -107,8 +107,8 @@ def _bootstrap(*, root=None, upgrade=False, user=False, # Put our bundled wheels into a temporary directory and construct the # additional paths that need added to sys.path additional_paths = [] - for project, version in _PROJECTS: - wheel_name = "{}-{}-py2.py3-none-any.whl".format(project, version) + for project, version, py_tag in _PROJECTS: + wheel_name = "{}-{}-{}-none-any.whl".format(project, version, py_tag) whl = resources.read_binary( _bundled, wheel_name, @@ -119,7 +119,7 @@ def _bootstrap(*, root=None, upgrade=False, user=False, additional_paths.append(os.path.join(tmpdir, wheel_name)) # Construct the arguments to be passed to the pip command - args = ["install", "--no-index", "--find-links", tmpdir] + args = ["install", "--no-cache-dir", "--no-index", "--find-links", tmpdir] if root: args += ["--root", root] if upgrade: diff --git a/Lib/ensurepip/_bundled/pip-19.2.3-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/pip-19.2.3-py2.py3-none-any.whl deleted file mode 100644 index 8118df8ac19..00000000000 Binary files a/Lib/ensurepip/_bundled/pip-19.2.3-py2.py3-none-any.whl and /dev/null differ diff --git a/Lib/ensurepip/_bundled/pip-20.1.1-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/pip-20.1.1-py2.py3-none-any.whl new file mode 100644 index 00000000000..ea1d0f7c860 Binary files /dev/null and b/Lib/ensurepip/_bundled/pip-20.1.1-py2.py3-none-any.whl differ diff --git a/Lib/ensurepip/_bundled/setuptools-41.2.0-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/setuptools-47.1.0-py3-none-any.whl similarity index 65% rename from Lib/ensurepip/_bundled/setuptools-41.2.0-py2.py3-none-any.whl rename to Lib/ensurepip/_bundled/setuptools-47.1.0-py3-none-any.whl index 82df6f63f4e..f87867ff982 100644 Binary files a/Lib/ensurepip/_bundled/setuptools-41.2.0-py2.py3-none-any.whl and b/Lib/ensurepip/_bundled/setuptools-47.1.0-py3-none-any.whl differ diff --git a/Lib/functools.py b/Lib/functools.py index 87c7d874389..b1f1fe8d9a6 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -11,7 +11,6 @@ __all__ = ['update_wrapper', 'wraps', 'WRAPPER_ASSIGNMENTS', 'WRAPPER_UPDATES', 'total_ordering', 'cache', 'cmp_to_key', 'lru_cache', 'reduce', - 'TopologicalSorter', 'CycleError', 'partial', 'partialmethod', 'singledispatch', 'singledispatchmethod', 'cached_property'] @@ -199,250 +198,6 @@ def total_ordering(cls): setattr(cls, opname, opfunc) return cls -################################################################################ -### topological sort -################################################################################ - -_NODE_OUT = -1 -_NODE_DONE = -2 - - -class _NodeInfo: - __slots__ = 'node', 'npredecessors', 'successors' - - def __init__(self, node): - # The node this class is augmenting. - self.node = node - - # Number of predecessors, generally >= 0. When this value falls to 0, - # and is returned by get_ready(), this is set to _NODE_OUT and when the - # node is marked done by a call to done(), set to _NODE_DONE. - self.npredecessors = 0 - - # List of successor nodes. The list can contain duplicated elements as - # long as they're all reflected in the successor's npredecessors attribute). - self.successors = [] - - -class CycleError(ValueError): - """Subclass of ValueError raised by TopologicalSorterif cycles exist in the graph - - If multiple cycles exist, only one undefined choice among them will be reported - and included in the exception. The detected cycle can be accessed via the second - element in the *args* attribute of the exception instance and consists in a list - of nodes, such that each node is, in the graph, an immediate predecessor of the - next node in the list. In the reported list, the first and the last node will be - the same, to make it clear that it is cyclic. - """ - pass - - -class TopologicalSorter: - """Provides functionality to topologically sort a graph of hashable nodes""" - - def __init__(self, graph=None): - self._node2info = {} - self._ready_nodes = None - self._npassedout = 0 - self._nfinished = 0 - - if graph is not None: - for node, predecessors in graph.items(): - self.add(node, *predecessors) - - def _get_nodeinfo(self, node): - if (result := self._node2info.get(node)) is None: - self._node2info[node] = result = _NodeInfo(node) - return result - - def add(self, node, *predecessors): - """Add a new node and its predecessors to the graph. - - Both the *node* and all elements in *predecessors* must be hashable. - - If called multiple times with the same node argument, the set of dependencies - will be the union of all dependencies passed in. - - It is possible to add a node with no dependencies (*predecessors* is not provided) - as well as provide a dependency twice. If a node that has not been provided before - is included among *predecessors* it will be automatically added to the graph with - no predecessors of its own. - - Raises ValueError if called after "prepare". - """ - if self._ready_nodes is not None: - raise ValueError("Nodes cannot be added after a call to prepare()") - - # Create the node -> predecessor edges - nodeinfo = self._get_nodeinfo(node) - nodeinfo.npredecessors += len(predecessors) - - # Create the predecessor -> node edges - for pred in predecessors: - pred_info = self._get_nodeinfo(pred) - pred_info.successors.append(node) - - def prepare(self): - """Mark the graph as finished and check for cycles in the graph. - - If any cycle is detected, "CycleError" will be raised, but "get_ready" can - still be used to obtain as many nodes as possible until cycles block more - progress. After a call to this function, the graph cannot be modified and - therefore no more nodes can be added using "add". - """ - if self._ready_nodes is not None: - raise ValueError("cannot prepare() more than once") - - self._ready_nodes = [i.node for i in self._node2info.values() - if i.npredecessors == 0] - # ready_nodes is set before we look for cycles on purpose: - # if the user wants to catch the CycleError, that's fine, - # they can continue using the instance to grab as many - # nodes as possible before cycles block more progress - cycle = self._find_cycle() - if cycle: - raise CycleError(f"nodes are in a cycle", cycle) - - def get_ready(self): - """Return a tuple of all the nodes that are ready. - - Initially it returns all nodes with no predecessors; once those are marked - as processed by calling "done", further calls will return all new nodes that - have all their predecessors already processed. Once no more progress can be made, - empty tuples are returned. - - Raises ValueError if called without calling "prepare" previously. - """ - if self._ready_nodes is None: - raise ValueError("prepare() must be called first") - - # Get the nodes that are ready and mark them - result = tuple(self._ready_nodes) - n2i = self._node2info - for node in result: - n2i[node].npredecessors = _NODE_OUT - - # Clean the list of nodes that are ready and update - # the counter of nodes that we have returned. - self._ready_nodes.clear() - self._npassedout += len(result) - - return result - - def is_active(self): - """Return True if more progress can be made and ``False`` otherwise. - - Progress can be made if cycles do not block the resolution and either there - are still nodes ready that haven't yet been returned by "get_ready" or the - number of nodes marked "done" is less than the number that have been returned - by "get_ready". - - Raises ValueError if called without calling "prepare" previously. - """ - if self._ready_nodes is None: - raise ValueError("prepare() must be called first") - return self._nfinished < self._npassedout or bool(self._ready_nodes) - - def __bool__(self): - return self.is_active() - - def done(self, *nodes): - """Marks a set of nodes returned by "get_ready" as processed. - - This method unblocks any successor of each node in *nodes* for being returned - in the future by a a call to "get_ready" - - Raises :exec:`ValueError` if any node in *nodes* has already been marked as - processed by a previous call to this method, if a node was not added to the - graph by using "add" or if called without calling "prepare" previously or if - node has not yet been returned by "get_ready". - """ - - if self._ready_nodes is None: - raise ValueError("prepare() must be called first") - - n2i = self._node2info - - for node in nodes: - - # Check if we know about this node (it was added previously using add() - if (nodeinfo := n2i.get(node)) is None: - raise ValueError(f"node {node!r} was not added using add()") - - # If the node has not being returned (marked as ready) previously, inform the user. - stat = nodeinfo.npredecessors - if stat != _NODE_OUT: - if stat >= 0: - raise ValueError(f"node {node!r} was not passed out (still not ready)") - elif stat == _NODE_DONE: - raise ValueError(f"node {node!r} was already marked done") - else: - assert False, f"node {node!r}: unknown status {stat}" - - # Mark the node as processed - nodeinfo.npredecessors = _NODE_DONE - - # Go to all the successors and reduce the number of predecessors, collecting all the ones - # that are ready to be returned in the next get_ready() call. - for successor in nodeinfo.successors: - successor_info = n2i[successor] - successor_info.npredecessors -= 1 - if successor_info.npredecessors == 0: - self._ready_nodes.append(successor) - self._nfinished += 1 - - def _find_cycle(self): - n2i = self._node2info - stack = [] - itstack = [] - seen = set() - node2stacki = {} - - for node in n2i: - if node in seen: - continue - - while True: - if node in seen: - # If we have seen already the node and is in the - # current stack we have found a cycle. - if node in node2stacki: - return stack[node2stacki[node]:] + [node] - # else go on to get next successor - else: - seen.add(node) - itstack.append(iter(n2i[node].successors).__next__) - node2stacki[node] = len(stack) - stack.append(node) - - # Backtrack to the topmost stack entry with - # at least another successor. - while stack: - try: - node = itstack[-1]() - break - except StopIteration: - del node2stacki[stack.pop()] - itstack.pop() - else: - break - return None - - def static_order(self): - """Returns an iterable of nodes in a topological order. - - The particular order that is returned may depend on the specific - order in which the items were inserted in the graph. - - Using this method does not require to call "prepare" or "done". If any - cycle is detected, :exc:`CycleError` will be raised. - """ - self.prepare() - while self.is_active(): - node_group = self.get_ready() - yield from node_group - self.done(*node_group) - ################################################################################ ### cmp_to_key() function converter @@ -481,14 +236,14 @@ _initial_missing = object() def reduce(function, sequence, initial=_initial_missing): """ - reduce(function, sequence[, initial]) -> value + reduce(function, iterable[, initial]) -> value - Apply a function of two arguments cumulatively to the items of a sequence, - from left to right, so as to reduce the sequence to a single value. - For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates + Apply a function of two arguments cumulatively to the items of a sequence + or iterable, from left to right, so as to reduce the iterable to a single + value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5). If initial is present, it is placed before the items - of the sequence in the calculation, and serves as a default when the - sequence is empty. + of the iterable in the calculation, and serves as a default when the + iterable is empty. """ it = iter(sequence) @@ -497,7 +252,8 @@ def reduce(function, sequence, initial=_initial_missing): try: value = next(it) except StopIteration: - raise TypeError("reduce() of empty sequence with no initial value") from None + raise TypeError( + "reduce() of empty iterable with no initial value") from None else: value = initial diff --git a/Lib/glob.py b/Lib/glob.py index 0dd2f8be661..3c449a90dff 100644 --- a/Lib/glob.py +++ b/Lib/glob.py @@ -3,11 +3,13 @@ import os import re import fnmatch +import itertools +import stat import sys __all__ = ["glob", "iglob", "escape"] -def glob(pathname, *, recursive=False): +def glob(pathname, *, root_dir=None, dir_fd=None, recursive=False): """Return a list of paths matching a pathname pattern. The pattern may contain simple shell-style wildcards a la @@ -18,9 +20,9 @@ def glob(pathname, *, recursive=False): If recursive is true, the pattern '**' will match any files and zero or more directories and subdirectories. """ - return list(iglob(pathname, recursive=recursive)) + return list(iglob(pathname, root_dir=root_dir, dir_fd=dir_fd, recursive=recursive)) -def iglob(pathname, *, recursive=False): +def iglob(pathname, *, root_dir=None, dir_fd=None, recursive=False): """Return an iterator which yields the paths matching a pathname pattern. The pattern may contain simple shell-style wildcards a la @@ -31,36 +33,43 @@ def iglob(pathname, *, recursive=False): If recursive is true, the pattern '**' will match any files and zero or more directories and subdirectories. """ - sys.audit("glob.glob", pathname, recursive) - it = _iglob(pathname, recursive, False) - if recursive and _isrecursive(pathname): - s = next(it) # skip empty string - assert not s + if root_dir is not None: + root_dir = os.fspath(root_dir) + else: + root_dir = pathname[:0] + it = _iglob(pathname, root_dir, dir_fd, recursive, False) + if not pathname or recursive and _isrecursive(pathname[:2]): + try: + s = next(it) # skip empty string + if s: + it = itertools.chain((s,), it) + except StopIteration: + pass return it -def _iglob(pathname, recursive, dironly): +def _iglob(pathname, root_dir, dir_fd, recursive, dironly): dirname, basename = os.path.split(pathname) if not has_magic(pathname): assert not dironly if basename: - if os.path.lexists(pathname): + if _lexists(_join(root_dir, pathname), dir_fd): yield pathname else: # Patterns ending with a slash should match only directories - if os.path.isdir(dirname): + if _isdir(_join(root_dir, dirname), dir_fd): yield pathname return if not dirname: if recursive and _isrecursive(basename): - yield from _glob2(dirname, basename, dironly) + yield from _glob2(root_dir, basename, dir_fd, dironly) else: - yield from _glob1(dirname, basename, dironly) + yield from _glob1(root_dir, basename, dir_fd, dironly) return # `os.path.split()` returns the argument itself as a dirname if it is a # drive or UNC path. Prevent an infinite recursion if a drive or UNC path # contains magic characters (i.e. r'\\?\C:'). if dirname != pathname and has_magic(dirname): - dirs = _iglob(dirname, recursive, True) + dirs = _iglob(dirname, root_dir, dir_fd, recursive, True) else: dirs = [dirname] if has_magic(basename): @@ -71,76 +80,121 @@ def _iglob(pathname, recursive, dironly): else: glob_in_dir = _glob0 for dirname in dirs: - for name in glob_in_dir(dirname, basename, dironly): + for name in glob_in_dir(_join(root_dir, dirname), basename, dir_fd, dironly): yield os.path.join(dirname, name) # These 2 helper functions non-recursively glob inside a literal directory. # They return a list of basenames. _glob1 accepts a pattern while _glob0 # takes a literal basename (so it only has to check for its existence). -def _glob1(dirname, pattern, dironly): - names = list(_iterdir(dirname, dironly)) +def _glob1(dirname, pattern, dir_fd, dironly): + names = list(_iterdir(dirname, dir_fd, dironly)) if not _ishidden(pattern): names = (x for x in names if not _ishidden(x)) return fnmatch.filter(names, pattern) -def _glob0(dirname, basename, dironly): - if not basename: - # `os.path.split()` returns an empty basename for paths ending with a - # directory separator. 'q*x/' should match only directories. - if os.path.isdir(dirname): +def _glob0(dirname, basename, dir_fd, dironly): + if basename: + if _lexists(_join(dirname, basename), dir_fd): return [basename] else: - if os.path.lexists(os.path.join(dirname, basename)): + # `os.path.split()` returns an empty basename for paths ending with a + # directory separator. 'q*x/' should match only directories. + if _isdir(dirname, dir_fd): return [basename] return [] # Following functions are not public but can be used by third-party code. def glob0(dirname, pattern): - return _glob0(dirname, pattern, False) + return _glob0(dirname, pattern, None, False) def glob1(dirname, pattern): - return _glob1(dirname, pattern, False) + return _glob1(dirname, pattern, None, False) # This helper function recursively yields relative pathnames inside a literal # directory. -def _glob2(dirname, pattern, dironly): +def _glob2(dirname, pattern, dir_fd, dironly): assert _isrecursive(pattern) yield pattern[:0] - yield from _rlistdir(dirname, dironly) + yield from _rlistdir(dirname, dir_fd, dironly) # If dironly is false, yields all file names inside a directory. # If dironly is true, yields only directory names. -def _iterdir(dirname, dironly): - if not dirname: - if isinstance(dirname, bytes): - dirname = bytes(os.curdir, 'ASCII') - else: - dirname = os.curdir +def _iterdir(dirname, dir_fd, dironly): try: - with os.scandir(dirname) as it: - for entry in it: - try: - if not dironly or entry.is_dir(): - yield entry.name - except OSError: - pass + fd = None + fsencode = None + if dir_fd is not None: + if dirname: + fd = arg = os.open(dirname, _dir_open_flags, dir_fd=dir_fd) + else: + arg = dir_fd + if isinstance(dirname, bytes): + fsencode = os.fsencode + elif dirname: + arg = dirname + elif isinstance(dirname, bytes): + arg = bytes(os.curdir, 'ASCII') + else: + arg = os.curdir + try: + with os.scandir(arg) as it: + for entry in it: + try: + if not dironly or entry.is_dir(): + if fsencode is not None: + yield fsencode(entry.name) + else: + yield entry.name + except OSError: + pass + finally: + if fd is not None: + os.close(fd) except OSError: return # Recursively yields relative pathnames inside a literal directory. -def _rlistdir(dirname, dironly): - names = list(_iterdir(dirname, dironly)) +def _rlistdir(dirname, dir_fd, dironly): + names = list(_iterdir(dirname, dir_fd, dironly)) for x in names: if not _ishidden(x): yield x - path = os.path.join(dirname, x) if dirname else x - for y in _rlistdir(path, dironly): - yield os.path.join(x, y) + path = _join(dirname, x) if dirname else x + for y in _rlistdir(path, dir_fd, dironly): + yield _join(x, y) +def _lexists(pathname, dir_fd): + # Same as os.path.lexists(), but with dir_fd + if dir_fd is None: + return os.path.lexists(pathname) + try: + os.lstat(pathname, dir_fd=dir_fd) + except (OSError, ValueError): + return False + else: + return True + +def _isdir(pathname, dir_fd): + # Same as os.path.isdir(), but with dir_fd + if dir_fd is None: + return os.path.isdir(pathname) + try: + st = os.stat(pathname, dir_fd=dir_fd) + except (OSError, ValueError): + return False + else: + return stat.S_ISDIR(st.st_mode) + +def _join(dirname, basename): + # It is common if dirname or basename is empty + if not dirname or not basename: + return dirname or basename + return os.path.join(dirname, basename) + magic_check = re.compile('([*?[])') magic_check_bytes = re.compile(b'([*?[])') @@ -171,3 +225,6 @@ def escape(pathname): else: pathname = magic_check.sub(r'[\1]', pathname) return drive + pathname + + +_dir_open_flags = os.O_RDONLY | getattr(os, 'O_DIRECTORY', 0) diff --git a/Lib/graphlib.py b/Lib/graphlib.py new file mode 100644 index 00000000000..948f62f1dc3 --- /dev/null +++ b/Lib/graphlib.py @@ -0,0 +1,245 @@ +__all__ = ["TopologicalSorter", "CycleError"] + +_NODE_OUT = -1 +_NODE_DONE = -2 + + +class _NodeInfo: + __slots__ = "node", "npredecessors", "successors" + + def __init__(self, node): + # The node this class is augmenting. + self.node = node + + # Number of predecessors, generally >= 0. When this value falls to 0, + # and is returned by get_ready(), this is set to _NODE_OUT and when the + # node is marked done by a call to done(), set to _NODE_DONE. + self.npredecessors = 0 + + # List of successor nodes. The list can contain duplicated elements as + # long as they're all reflected in the successor's npredecessors attribute). + self.successors = [] + + +class CycleError(ValueError): + """Subclass of ValueError raised by TopologicalSorterif cycles exist in the graph + + If multiple cycles exist, only one undefined choice among them will be reported + and included in the exception. The detected cycle can be accessed via the second + element in the *args* attribute of the exception instance and consists in a list + of nodes, such that each node is, in the graph, an immediate predecessor of the + next node in the list. In the reported list, the first and the last node will be + the same, to make it clear that it is cyclic. + """ + + pass + + +class TopologicalSorter: + """Provides functionality to topologically sort a graph of hashable nodes""" + + def __init__(self, graph=None): + self._node2info = {} + self._ready_nodes = None + self._npassedout = 0 + self._nfinished = 0 + + if graph is not None: + for node, predecessors in graph.items(): + self.add(node, *predecessors) + + def _get_nodeinfo(self, node): + if (result := self._node2info.get(node)) is None: + self._node2info[node] = result = _NodeInfo(node) + return result + + def add(self, node, *predecessors): + """Add a new node and its predecessors to the graph. + + Both the *node* and all elements in *predecessors* must be hashable. + + If called multiple times with the same node argument, the set of dependencies + will be the union of all dependencies passed in. + + It is possible to add a node with no dependencies (*predecessors* is not provided) + as well as provide a dependency twice. If a node that has not been provided before + is included among *predecessors* it will be automatically added to the graph with + no predecessors of its own. + + Raises ValueError if called after "prepare". + """ + if self._ready_nodes is not None: + raise ValueError("Nodes cannot be added after a call to prepare()") + + # Create the node -> predecessor edges + nodeinfo = self._get_nodeinfo(node) + nodeinfo.npredecessors += len(predecessors) + + # Create the predecessor -> node edges + for pred in predecessors: + pred_info = self._get_nodeinfo(pred) + pred_info.successors.append(node) + + def prepare(self): + """Mark the graph as finished and check for cycles in the graph. + + If any cycle is detected, "CycleError" will be raised, but "get_ready" can + still be used to obtain as many nodes as possible until cycles block more + progress. After a call to this function, the graph cannot be modified and + therefore no more nodes can be added using "add". + """ + if self._ready_nodes is not None: + raise ValueError("cannot prepare() more than once") + + self._ready_nodes = [ + i.node for i in self._node2info.values() if i.npredecessors == 0 + ] + # ready_nodes is set before we look for cycles on purpose: + # if the user wants to catch the CycleError, that's fine, + # they can continue using the instance to grab as many + # nodes as possible before cycles block more progress + cycle = self._find_cycle() + if cycle: + raise CycleError(f"nodes are in a cycle", cycle) + + def get_ready(self): + """Return a tuple of all the nodes that are ready. + + Initially it returns all nodes with no predecessors; once those are marked + as processed by calling "done", further calls will return all new nodes that + have all their predecessors already processed. Once no more progress can be made, + empty tuples are returned. + + Raises ValueError if called without calling "prepare" previously. + """ + if self._ready_nodes is None: + raise ValueError("prepare() must be called first") + + # Get the nodes that are ready and mark them + result = tuple(self._ready_nodes) + n2i = self._node2info + for node in result: + n2i[node].npredecessors = _NODE_OUT + + # Clean the list of nodes that are ready and update + # the counter of nodes that we have returned. + self._ready_nodes.clear() + self._npassedout += len(result) + + return result + + def is_active(self): + """Return True if more progress can be made and ``False`` otherwise. + + Progress can be made if cycles do not block the resolution and either there + are still nodes ready that haven't yet been returned by "get_ready" or the + number of nodes marked "done" is less than the number that have been returned + by "get_ready". + + Raises ValueError if called without calling "prepare" previously. + """ + if self._ready_nodes is None: + raise ValueError("prepare() must be called first") + return self._nfinished < self._npassedout or bool(self._ready_nodes) + + def __bool__(self): + return self.is_active() + + def done(self, *nodes): + """Marks a set of nodes returned by "get_ready" as processed. + + This method unblocks any successor of each node in *nodes* for being returned + in the future by a a call to "get_ready" + + Raises :exec:`ValueError` if any node in *nodes* has already been marked as + processed by a previous call to this method, if a node was not added to the + graph by using "add" or if called without calling "prepare" previously or if + node has not yet been returned by "get_ready". + """ + + if self._ready_nodes is None: + raise ValueError("prepare() must be called first") + + n2i = self._node2info + + for node in nodes: + + # Check if we know about this node (it was added previously using add() + if (nodeinfo := n2i.get(node)) is None: + raise ValueError(f"node {node!r} was not added using add()") + + # If the node has not being returned (marked as ready) previously, inform the user. + stat = nodeinfo.npredecessors + if stat != _NODE_OUT: + if stat >= 0: + raise ValueError( + f"node {node!r} was not passed out (still not ready)" + ) + elif stat == _NODE_DONE: + raise ValueError(f"node {node!r} was already marked done") + else: + assert False, f"node {node!r}: unknown status {stat}" + + # Mark the node as processed + nodeinfo.npredecessors = _NODE_DONE + + # Go to all the successors and reduce the number of predecessors, collecting all the ones + # that are ready to be returned in the next get_ready() call. + for successor in nodeinfo.successors: + successor_info = n2i[successor] + successor_info.npredecessors -= 1 + if successor_info.npredecessors == 0: + self._ready_nodes.append(successor) + self._nfinished += 1 + + def _find_cycle(self): + n2i = self._node2info + stack = [] + itstack = [] + seen = set() + node2stacki = {} + + for node in n2i: + if node in seen: + continue + + while True: + if node in seen: + # If we have seen already the node and is in the + # current stack we have found a cycle. + if node in node2stacki: + return stack[node2stacki[node] :] + [node] + # else go on to get next successor + else: + seen.add(node) + itstack.append(iter(n2i[node].successors).__next__) + node2stacki[node] = len(stack) + stack.append(node) + + # Backtrack to the topmost stack entry with + # at least another successor. + while stack: + try: + node = itstack[-1]() + break + except StopIteration: + del node2stacki[stack.pop()] + itstack.pop() + else: + break + return None + + def static_order(self): + """Returns an iterable of nodes in a topological order. + + The particular order that is returned may depend on the specific + order in which the items were inserted in the graph. + + Using this method does not require to call "prepare" or "done". If any + cycle is detected, :exc:`CycleError` will be raised. + """ + self.prepare() + while self.is_active(): + node_group = self.get_ready() + yield from node_group + self.done(*node_group) diff --git a/Lib/hashlib.py b/Lib/hashlib.py index 1b6e50247c1..58c340d56e3 100644 --- a/Lib/hashlib.py +++ b/Lib/hashlib.py @@ -70,6 +70,11 @@ __all__ = __always_supported + ('new', 'algorithms_guaranteed', __builtin_constructor_cache = {} +# Prefer our blake2 implementation +# OpenSSL 1.1.0 comes with a limited implementation of blake2b/s. The OpenSSL +# implementations neither support keyed blake2 (blake2 MAC) nor advanced +# features like salt, personalization, or tree hashing. OpenSSL hash-only +# variants are available as 'blake2b512' and 'blake2s256', though. __block_openssl_constructor = { 'blake2b', 'blake2s', } @@ -120,7 +125,7 @@ def __get_builtin_constructor(name): def __get_openssl_constructor(name): if name in __block_openssl_constructor: - # Prefer our blake2 and sha3 implementation. + # Prefer our builtin blake2 implementation. return __get_builtin_constructor(name) try: # MD5, SHA1, and SHA2 are in all supported OpenSSL versions @@ -149,10 +154,7 @@ def __hash_new(name, data=b'', **kwargs): optionally initialized with data (which must be a bytes-like object). """ if name in __block_openssl_constructor: - # Prefer our blake2 and sha3 implementation - # OpenSSL 1.1.0 comes with a limited implementation of blake2b/s. - # It does neither support keyed blake2 nor advanced features like - # salt, personal, tree hashing or SSE. + # Prefer our builtin blake2 implementation. return __get_builtin_constructor(name)(data, **kwargs) try: return _hashlib.new(name, data, **kwargs) diff --git a/Lib/hmac.py b/Lib/hmac.py index 54a1ef9bdbd..180bc378b52 100644 --- a/Lib/hmac.py +++ b/Lib/hmac.py @@ -4,14 +4,15 @@ Implements the HMAC algorithm as described by RFC 2104. """ import warnings as _warnings -from _operator import _compare_digest as compare_digest try: import _hashlib as _hashopenssl except ImportError: _hashopenssl = None _openssl_md_meths = None + from _operator import _compare_digest as compare_digest else: _openssl_md_meths = frozenset(_hashopenssl.openssl_md_meth_names) + compare_digest = _hashopenssl.compare_digest import hashlib as _hashlib trans_5C = bytes((x ^ 0x5C) for x in range(256)) diff --git a/Lib/http/client.py b/Lib/http/client.py index 019380a7203..500230d5d51 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -448,18 +448,25 @@ class HTTPResponse(io.BufferedIOBase): self._close_conn() return b"" + if self.chunked: + return self._read_chunked(amt) + if amt is not None: - # Amount is given, implement using readinto - b = bytearray(amt) - n = self.readinto(b) - return memoryview(b)[:n].tobytes() + if self.length is not None and amt > self.length: + # clip the read to the "end of response" + amt = self.length + s = self.fp.read(amt) + if not s and amt: + # Ideally, we would raise IncompleteRead if the content-length + # wasn't satisfied, but it might break compatibility. + self._close_conn() + elif self.length is not None: + self.length -= len(s) + if not self.length: + self._close_conn() + return s else: # Amount is not given (unbounded read) so we must check self.length - # and self.chunked - - if self.chunked: - return self._readall_chunked() - if self.length is None: s = self.fp.read() else: @@ -560,7 +567,7 @@ class HTTPResponse(io.BufferedIOBase): self.chunk_left = chunk_left return chunk_left - def _readall_chunked(self): + def _read_chunked(self, amt=None): assert self.chunked != _UNKNOWN value = [] try: @@ -568,7 +575,15 @@ class HTTPResponse(io.BufferedIOBase): chunk_left = self._get_chunk_left() if chunk_left is None: break + + if amt is not None and amt <= chunk_left: + value.append(self._safe_read(amt)) + self.chunk_left = chunk_left - amt + break + value.append(self._safe_read(chunk_left)) + if amt is not None: + amt -= chunk_left self.chunk_left = 0 return b''.join(value) except IncompleteRead: diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index 709008f78a5..7ae29af0b30 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -3,6 +3,11 @@ Released on 2020-10-05? ====================================== +bpo-41152: The encoding of ``stdin``, ``stdout`` and ``stderr`` in IDLE +is now always UTF-8. + +bpo-41144: Make Open Module open a special module such as os.path. + bpo-40723: Make test_idle pass when run after import. Patch by Florian Dahlitz. @@ -12,8 +17,9 @@ when fetching a calltip. bpo-27115: For 'Go to Line', use a Query entry box subclass with IDLE standard behavior and improved error checking. -bpo-39885: Since clicking to get an IDLE context menu moves the -cursor, any text selection should be and now is cleared. +bpo-39885: When a context menu is invoked by right-clicking outside +of a selection, clear the selection and move the cursor. Cut and +Copy require that the click be within the selection. bpo-39852: Edit "Go to line" now clears any selection, preventing accidental deletion. It also updates Ln and Col on the status bar. diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py index b0f88b5463d..a178eaf93c0 100644 --- a/Lib/idlelib/editor.py +++ b/Lib/idlelib/editor.py @@ -499,15 +499,23 @@ class EditorWindow(object): rmenu = None def right_menu_event(self, event): - self.text.tag_remove("sel", "1.0", "end") - self.text.mark_set("insert", "@%d,%d" % (event.x, event.y)) + text = self.text + newdex = text.index(f'@{event.x},{event.y}') + try: + in_selection = (text.compare('sel.first', '<=', newdex) and + text.compare(newdex, '<=', 'sel.last')) + except TclError: + in_selection = False + if not in_selection: + text.tag_remove("sel", "1.0", "end") + text.mark_set("insert", newdex) if not self.rmenu: self.make_rmenu() rmenu = self.rmenu self.event = event iswin = sys.platform[:3] == 'win' if iswin: - self.text.config(cursor="arrow") + text.config(cursor="arrow") for item in self.rmenu_specs: try: @@ -520,7 +528,6 @@ class EditorWindow(object): state = getattr(self, verify_state)() rmenu.entryconfigure(label, state=state) - rmenu.tk_popup(event.x_root, event.y_root) if iswin: self.text.config(cursor="ibeam") diff --git a/Lib/idlelib/idle_test/test_editor.py b/Lib/idlelib/idle_test/test_editor.py index 91e8ef89d1d..443dcf02167 100644 --- a/Lib/idlelib/idle_test/test_editor.py +++ b/Lib/idlelib/idle_test/test_editor.py @@ -5,6 +5,7 @@ import unittest from collections import namedtuple from test.support import requires from tkinter import Tk +from idlelib.idle_test.mock_idle import Func Editor = editor.EditorWindow @@ -92,6 +93,12 @@ class TestGetLineIndent(unittest.TestCase): ) +def insert(text, string): + text.delete('1.0', 'end') + text.insert('end', string) + text.update() # Force update for colorizer to finish. + + class IndentAndNewlineTest(unittest.TestCase): @classmethod @@ -113,13 +120,6 @@ class IndentAndNewlineTest(unittest.TestCase): cls.root.destroy() del cls.root - def insert(self, text): - t = self.window.text - t.delete('1.0', 'end') - t.insert('end', text) - # Force update for colorizer to finish. - t.update() - def test_indent_and_newline_event(self): eq = self.assertEqual w = self.window @@ -170,13 +170,13 @@ class IndentAndNewlineTest(unittest.TestCase): w.prompt_last_line = '' for test in tests: with self.subTest(label=test.label): - self.insert(test.text) + insert(text, test.text) text.mark_set('insert', test.mark) nl(event=None) eq(get('1.0', 'end'), test.expected) # Selected text. - self.insert(' def f1(self, a, b):\n return a + b') + insert(text, ' def f1(self, a, b):\n return a + b') text.tag_add('sel', '1.17', '1.end') nl(None) # Deletes selected text before adding new line. @@ -184,11 +184,37 @@ class IndentAndNewlineTest(unittest.TestCase): # Preserves the whitespace in shell prompt. w.prompt_last_line = '>>> ' - self.insert('>>> \t\ta =') + insert(text, '>>> \t\ta =') text.mark_set('insert', '1.5') nl(None) eq(get('1.0', 'end'), '>>> \na =\n') +class RMenuTest(unittest.TestCase): + + @classmethod + def setUpClass(cls): + requires('gui') + cls.root = Tk() + cls.root.withdraw() + cls.window = Editor(root=cls.root) + + @classmethod + def tearDownClass(cls): + cls.window._close() + del cls.window + cls.root.update_idletasks() + for id in cls.root.tk.call('after', 'info'): + cls.root.after_cancel(id) + cls.root.destroy() + del cls.root + + class DummyRMenu: + def tk_popup(x, y): pass + + def test_rclick(self): + pass + + if __name__ == '__main__': unittest.main(verbosity=2) diff --git a/Lib/idlelib/idle_test/test_outwin.py b/Lib/idlelib/idle_test/test_outwin.py index cd099ecd841..e347bfca7f1 100644 --- a/Lib/idlelib/idle_test/test_outwin.py +++ b/Lib/idlelib/idle_test/test_outwin.py @@ -58,11 +58,6 @@ class OutputWindowTest(unittest.TestCase): get = self.text.get write = self.window.write - # Test bytes. - b = b'Test bytes.' - eq(write(b), len(b)) - eq(get('1.0', '1.end'), b.decode()) - # No new line - insert stays on same line. delete('1.0', 'end') test_text = 'test text' diff --git a/Lib/idlelib/idle_test/test_query.py b/Lib/idlelib/idle_test/test_query.py index 6d026cb5320..e968862688b 100644 --- a/Lib/idlelib/idle_test/test_query.py +++ b/Lib/idlelib/idle_test/test_query.py @@ -136,6 +136,9 @@ class ModuleNameTest(unittest.TestCase): dialog = self.Dummy_ModuleName('idlelib') self.assertTrue(dialog.entry_ok().endswith('__init__.py')) self.assertEqual(dialog.entry_error['text'], '') + dialog = self.Dummy_ModuleName('os.path') + self.assertTrue(dialog.entry_ok().endswith('path.py')) + self.assertEqual(dialog.entry_error['text'], '') class GotoTest(unittest.TestCase): diff --git a/Lib/idlelib/iomenu.py b/Lib/idlelib/iomenu.py index 4b2833b8ca5..7641d866858 100644 --- a/Lib/idlelib/iomenu.py +++ b/Lib/idlelib/iomenu.py @@ -1,10 +1,8 @@ -import codecs -from codecs import BOM_UTF8 import os -import re import shlex import sys import tempfile +import tokenize import tkinter.filedialog as tkFileDialog import tkinter.messagebox as tkMessageBox @@ -13,95 +11,12 @@ from tkinter.simpledialog import askstring import idlelib from idlelib.config import idleConf -if idlelib.testing: # Set True by test.test_idle to avoid setlocale. - encoding = 'utf-8' - errors = 'surrogateescape' +encoding = 'utf-8' +if sys.platform == 'win32': + errors = 'surrogatepass' else: - # Try setting the locale, so that we can find out - # what encoding to use - try: - import locale - locale.setlocale(locale.LC_CTYPE, "") - except (ImportError, locale.Error): - pass + errors = 'surrogateescape' - if sys.platform == 'win32': - encoding = 'utf-8' - errors = 'surrogateescape' - else: - try: - # Different things can fail here: the locale module may not be - # loaded, it may not offer nl_langinfo, or CODESET, or the - # resulting codeset may be unknown to Python. We ignore all - # these problems, falling back to ASCII - locale_encoding = locale.nl_langinfo(locale.CODESET) - if locale_encoding: - codecs.lookup(locale_encoding) - except (NameError, AttributeError, LookupError): - # Try getdefaultlocale: it parses environment variables, - # which may give a clue. Unfortunately, getdefaultlocale has - # bugs that can cause ValueError. - try: - locale_encoding = locale.getdefaultlocale()[1] - if locale_encoding: - codecs.lookup(locale_encoding) - except (ValueError, LookupError): - pass - - if locale_encoding: - encoding = locale_encoding.lower() - errors = 'strict' - else: - # POSIX locale or macOS - encoding = 'ascii' - errors = 'surrogateescape' - # Encoding is used in multiple files; locale_encoding nowhere. - # The only use of 'encoding' below is in _decode as initial value - # of deprecated block asking user for encoding. - # Perhaps use elsewhere should be reviewed. - -coding_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)', re.ASCII) -blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)', re.ASCII) - -def coding_spec(data): - """Return the encoding declaration according to PEP 263. - - When checking encoded data, only the first two lines should be passed - in to avoid a UnicodeDecodeError if the rest of the data is not unicode. - The first two lines would contain the encoding specification. - - Raise a LookupError if the encoding is declared but unknown. - """ - if isinstance(data, bytes): - # This encoding might be wrong. However, the coding - # spec must be ASCII-only, so any non-ASCII characters - # around here will be ignored. Decoding to Latin-1 should - # never fail (except for memory outage) - lines = data.decode('iso-8859-1') - else: - lines = data - # consider only the first two lines - if '\n' in lines: - lst = lines.split('\n', 2)[:2] - elif '\r' in lines: - lst = lines.split('\r', 2)[:2] - else: - lst = [lines] - for line in lst: - match = coding_re.match(line) - if match is not None: - break - if not blank_re.match(line): - return None - else: - return None - name = match.group(1) - try: - codecs.lookup(name) - except LookupError: - # The standard encoding error does not indicate the encoding - raise LookupError("Unknown encoding: "+name) - return name class IOBinding: @@ -118,7 +33,7 @@ class IOBinding: self.save_as) self.__id_savecopy = self.text.bind("<>", self.save_a_copy) - self.fileencoding = None + self.fileencoding = 'utf-8' self.__id_print = self.text.bind("<>", self.print_window) def close(self): @@ -205,34 +120,44 @@ class IOBinding: self.text.focus_set() return "break" - eol = r"(\r\n)|\n|\r" # \r\n (Windows), \n (UNIX), or \r (Mac) - eol_re = re.compile(eol) eol_convention = os.linesep # default def loadfile(self, filename): try: - # open the file in binary mode so that we can handle - # end-of-line convention ourselves. - with open(filename, 'rb') as f: - two_lines = f.readline() + f.readline() - f.seek(0) - bytes = f.read() - except OSError as msg: - tkMessageBox.showerror("I/O Error", str(msg), parent=self.text) + try: + with tokenize.open(filename) as f: + chars = f.read() + fileencoding = f.encoding + eol_convention = f.newlines + converted = False + except (UnicodeDecodeError, SyntaxError): + # Wait for the editor window to appear + self.editwin.text.update() + enc = askstring( + "Specify file encoding", + "The file's encoding is invalid for Python 3.x.\n" + "IDLE will convert it to UTF-8.\n" + "What is the current encoding of the file?", + initialvalue='utf-8', + parent=self.editwin.text) + with open(filename, encoding=enc) as f: + chars = f.read() + fileencoding = f.encoding + eol_convention = f.newlines + converted = True + except OSError as err: + tkMessageBox.showerror("I/O Error", str(err), parent=self.text) return False - chars, converted = self._decode(two_lines, bytes) - if chars is None: + except UnicodeDecodeError: tkMessageBox.showerror("Decoding Error", "File %s\nFailed to Decode" % filename, parent=self.text) return False - # We now convert all end-of-lines to '\n's - firsteol = self.eol_re.search(chars) - if firsteol: - self.eol_convention = firsteol.group(0) - chars = self.eol_re.sub(r"\n", chars) + self.text.delete("1.0", "end") self.set_filename(None) + self.fileencoding = fileencoding + self.eol_convention = eol_convention self.text.insert("1.0", chars) self.reset_undo() self.set_filename(filename) @@ -245,74 +170,6 @@ class IOBinding: self.updaterecentfileslist(filename) return True - def _decode(self, two_lines, bytes): - "Create a Unicode string." - chars = None - # Check presence of a UTF-8 signature first - if bytes.startswith(BOM_UTF8): - try: - chars = bytes[3:].decode("utf-8") - except UnicodeDecodeError: - # has UTF-8 signature, but fails to decode... - return None, False - else: - # Indicates that this file originally had a BOM - self.fileencoding = 'BOM' - return chars, False - # Next look for coding specification - try: - enc = coding_spec(two_lines) - except LookupError as name: - tkMessageBox.showerror( - title="Error loading the file", - message="The encoding '%s' is not known to this Python "\ - "installation. The file may not display correctly" % name, - parent = self.text) - enc = None - except UnicodeDecodeError: - return None, False - if enc: - try: - chars = str(bytes, enc) - self.fileencoding = enc - return chars, False - except UnicodeDecodeError: - pass - # Try ascii: - try: - chars = str(bytes, 'ascii') - self.fileencoding = None - return chars, False - except UnicodeDecodeError: - pass - # Try utf-8: - try: - chars = str(bytes, 'utf-8') - self.fileencoding = 'utf-8' - return chars, False - except UnicodeDecodeError: - pass - # Finally, try the locale's encoding. This is deprecated; - # the user should declare a non-ASCII encoding - try: - # Wait for the editor window to appear - self.editwin.text.update() - enc = askstring( - "Specify file encoding", - "The file's encoding is invalid for Python 3.x.\n" - "IDLE will convert it to UTF-8.\n" - "What is the current encoding of the file?", - initialvalue = encoding, - parent = self.editwin.text) - - if enc: - chars = str(bytes, enc) - self.fileencoding = None - return chars, True - except (UnicodeDecodeError, LookupError): - pass - return None, False # None on failure - def maybesave(self): if self.get_saved(): return "yes" @@ -400,38 +257,30 @@ class IOBinding: # text to us. Don't try to guess further. return chars # Preserve a BOM that might have been present on opening - if self.fileencoding == 'BOM': - return BOM_UTF8 + chars.encode("utf-8") + if self.fileencoding == 'utf-8-sig': + return chars.encode('utf-8-sig') # See whether there is anything non-ASCII in it. # If not, no need to figure out the encoding. try: return chars.encode('ascii') - except UnicodeError: + except UnicodeEncodeError: pass # Check if there is an encoding declared try: - # a string, let coding_spec slice it to the first two lines - enc = coding_spec(chars) - failed = None - except LookupError as msg: - failed = msg - enc = None - else: - if not enc: - # PEP 3120: default source encoding is UTF-8 - enc = 'utf-8' - if enc: - try: - return chars.encode(enc) - except UnicodeError: - failed = "Invalid encoding '%s'" % enc + encoded = chars.encode('ascii', 'replace') + enc, _ = tokenize.detect_encoding(io.BytesIO(encoded).readline) + return chars.encode(enc) + except SyntaxError as err: + failed = str(err) + except UnicodeEncodeError: + failed = "Invalid encoding '%s'" % enc tkMessageBox.showerror( "I/O Error", "%s.\nSaving as UTF-8" % failed, - parent = self.text) + parent=self.text) # Fallback: save as UTF-8, with BOM - ignoring the incorrect # declared encoding - return BOM_UTF8 + chars.encode("utf-8") + return chars.encode('utf-8-sig') def print_window(self, event): confirm = tkMessageBox.askokcancel( diff --git a/Lib/idlelib/outwin.py b/Lib/idlelib/outwin.py index 90272b6feb4..5ab08bbaf4b 100644 --- a/Lib/idlelib/outwin.py +++ b/Lib/idlelib/outwin.py @@ -6,7 +6,6 @@ import re from tkinter import messagebox from idlelib.editor import EditorWindow -from idlelib import iomenu file_line_pats = [ @@ -110,8 +109,7 @@ class OutputWindow(EditorWindow): Return: Length of text inserted. """ - if isinstance(s, bytes): - s = s.decode(iomenu.encoding, "replace") + assert isinstance(s, str) self.text.insert(mark, s, tags) self.text.see(mark) self.text.update() diff --git a/Lib/idlelib/query.py b/Lib/idlelib/query.py index 2a88530b4d0..015fc7ade45 100644 --- a/Lib/idlelib/query.py +++ b/Lib/idlelib/query.py @@ -19,7 +19,7 @@ Subclass HelpSource gets menu item and path for additions to Help menu. # HelpSource was extracted from configHelpSourceEdit.py (temporarily # config_help.py), with darwin code moved from ok to path_ok. -import importlib +import importlib.util, importlib.abc import os import shlex from sys import executable, platform # Platform is set for one test. @@ -57,7 +57,8 @@ class Query(Toplevel): self.withdraw() # Hide while configuring, especially geometry. self.title(title) self.transient(parent) - self.grab_set() + if not _utest: # Otherwise fail when directly run unittest. + self.grab_set() windowingsystem = self.tk.call('tk', 'windowingsystem') if windowingsystem == 'aqua': @@ -209,17 +210,23 @@ class ModuleName(Query): self.showerror(str(msg)) return None if spec is None: - self.showerror("module not found") + self.showerror("module not found.") return None if not isinstance(spec.loader, importlib.abc.SourceLoader): - self.showerror("not a source-based module") + self.showerror("not a source-based module.") return None try: file_path = spec.loader.get_filename(name) except AttributeError: - self.showerror("loader does not support get_filename", - parent=self) + self.showerror("loader does not support get_filename.") return None + except ImportError: + # Some special modules require this (e.g. os.path) + try: + file_path = spec.loader.get_filename() + except TypeError: + self.showerror("loader failed to get filename.") + return None return file_path @@ -375,7 +382,7 @@ class CustomRun(Query): return cli_args def entry_ok(self): - "Return apparently valid (cli_args, restart) or None" + "Return apparently valid (cli_args, restart) or None." cli_args = self.cli_args_ok() restart = self.restartvar.get() return None if cli_args is None else (cli_args, restart) diff --git a/Lib/idlelib/tree.py b/Lib/idlelib/tree.py index 6229be4e5a8..5947268f5c3 100644 --- a/Lib/idlelib/tree.py +++ b/Lib/idlelib/tree.py @@ -38,7 +38,7 @@ def listicons(icondir=ICONDIR): """Utility to display the available icons.""" root = Tk() import glob - list = glob.glob(os.path.join(icondir, "*.gif")) + list = glob.glob(os.path.join(glob.escape(icondir), "*.gif")) list.sort() images = [] row = column = 0 diff --git a/Lib/imaplib.py b/Lib/imaplib.py index d9720f20c39..73184396d89 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -1251,13 +1251,12 @@ class IMAP4: sys.stderr.write(' %s.%02d %s\n' % (tm, (secs*100)%100, s)) sys.stderr.flush() - def _dump_ur(self, dict): - # Dump untagged responses (in `dict'). - l = dict.items() - if not l: return - t = '\n\t\t' - l = map(lambda x:'%s: "%s"' % (x[0], x[1][0] and '" "'.join(x[1]) or ''), l) - self._mesg('untagged responses dump:%s%s' % (t, t.join(l))) + def _dump_ur(self, untagged_resp_dict): + if not untagged_resp_dict: + return + items = (f'{key}: {value!r}' + for key, value in untagged_resp_dict.items()) + self._mesg('untagged responses dump:' + '\n\t\t'.join(items)) def _log(self, line): # Keep log of last `_cmd_log_len' interactions for debugging. diff --git a/Lib/imghdr.py b/Lib/imghdr.py index 76e8abb2d58..6e01fd85746 100644 --- a/Lib/imghdr.py +++ b/Lib/imghdr.py @@ -152,7 +152,7 @@ def testall(list, recursive, toplevel): if recursive or toplevel: print('recursing down:') import glob - names = glob.glob(os.path.join(filename, '*')) + names = glob.glob(os.path.join(glob.escape(filename), '*')) testall(names, recursive, 0) else: print('*** directory (use -r) ***') diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index 0c73c505f98..bea37d76626 100644 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -54,7 +54,6 @@ _unpack_uint32 = _bootstrap_external._unpack_uint32 # Fully bootstrapped at this point, import whatever you like, circular # dependencies and startup overhead minimisation permitting :) -import types import warnings @@ -136,12 +135,13 @@ def reload(module): The module must have been successfully imported before. """ - if not module or not isinstance(module, types.ModuleType): - raise TypeError("reload() argument must be a module") try: name = module.__spec__.name except AttributeError: - name = module.__name__ + try: + name = module.__name__ + except AttributeError: + raise TypeError("reload() argument must be a module") if sys.modules.get(name) is not module: msg = "module {} not in sys.modules" diff --git a/Lib/importlib/_abc.py b/Lib/importlib/_abc.py new file mode 100644 index 00000000000..fb5ec727cea --- /dev/null +++ b/Lib/importlib/_abc.py @@ -0,0 +1,50 @@ +"""Subset of importlib.abc used to reduce importlib.util imports.""" +from . import _bootstrap +import abc + + +class Loader(metaclass=abc.ABCMeta): + + """Abstract base class for import loaders.""" + + def create_module(self, spec): + """Return a module to initialize and into which to load. + + This method should raise ImportError if anything prevents it + from creating a new module. It may return None to indicate + that the spec should create the new module. + """ + # By default, defer to default semantics for the new module. + return None + + # We don't define exec_module() here since that would break + # hasattr checks we do to support backward compatibility. + + def load_module(self, fullname): + """Return the loaded module. + + The module must be added to sys.modules and have import-related + attributes set properly. The fullname is a str. + + ImportError is raised on failure. + + This method is deprecated in favor of loader.exec_module(). If + exec_module() exists then it is used to provide a backwards-compatible + functionality for this method. + + """ + if not hasattr(self, 'exec_module'): + raise ImportError + return _bootstrap._load_module_shim(self, fullname) + + def module_repr(self, module): + """Return a module's repr. + + Used by the module type when the method does not raise + NotImplementedError. + + This method is deprecated. + + """ + # The exception will cause ModuleType.__repr__ to ignore this method. + raise NotImplementedError diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 25a3f8c0e09..4f06039f3d2 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -982,32 +982,10 @@ class FileLoader: with _io.FileIO(path, 'r') as file: return file.read() - # ResourceReader ABC API. - @_check_name def get_resource_reader(self, module): - if self.is_package(module): - return self - return None - - def open_resource(self, resource): - path = _path_join(_path_split(self.path)[0], resource) - return _io.FileIO(path, 'r') - - def resource_path(self, resource): - if not self.is_resource(resource): - raise FileNotFoundError - path = _path_join(_path_split(self.path)[0], resource) - return path - - def is_resource(self, name): - if path_sep in name: - return False - path = _path_join(_path_split(self.path)[0], name) - return _path_isfile(path) - - def contents(self): - return iter(_os.listdir(_path_split(self.path)[0])) + from importlib.readers import FileReader + return FileReader(self) class SourceFileLoader(FileLoader, SourceLoader): diff --git a/Lib/importlib/_common.py b/Lib/importlib/_common.py index ba7cbac3c9b..b15c59eb9c9 100644 --- a/Lib/importlib/_common.py +++ b/Lib/importlib/_common.py @@ -1,9 +1,72 @@ import os import pathlib -import zipfile import tempfile import functools import contextlib +import types +import importlib + +from typing import Union, Any, Optional +from .abc import ResourceReader + +Package = Union[types.ModuleType, str] + + +def files(package): + """ + Get a Traversable resource from a package + """ + return from_package(get_package(package)) + + +def normalize_path(path): + # type: (Any) -> str + """Normalize a path by ensuring it is a string. + + If the resulting string contains path separators, an exception is raised. + """ + str_path = str(path) + parent, file_name = os.path.split(str_path) + if parent: + raise ValueError('{!r} must be only a file name'.format(path)) + return file_name + + +def get_resource_reader(package): + # type: (types.ModuleType) -> Optional[ResourceReader] + """ + Return the package's loader if it's a ResourceReader. + """ + # We can't use + # a issubclass() check here because apparently abc.'s __subclasscheck__() + # hook wants to create a weak reference to the object, but + # zipimport.zipimporter does not support weak references, resulting in a + # TypeError. That seems terrible. + spec = package.__spec__ + reader = getattr(spec.loader, 'get_resource_reader', None) + if reader is None: + return None + return reader(spec.name) + + +def resolve(cand): + # type: (Package) -> types.ModuleType + return ( + cand if isinstance(cand, types.ModuleType) + else importlib.import_module(cand) + ) + + +def get_package(package): + # type: (Package) -> types.ModuleType + """Take a package name or module object and return the module. + + Raise an exception if the resolved module is not a package. + """ + resolved = resolve(package) + if resolved.__spec__.submodule_search_locations is None: + raise TypeError('{!r} is not a package'.format(package)) + return resolved def from_package(package): @@ -12,27 +75,8 @@ def from_package(package): """ spec = package.__spec__ - return from_traversable_resources(spec) or fallback_resources(spec) - - -def from_traversable_resources(spec): - """ - If the spec.loader implements TraversableResources, - directly or implicitly, it will have a ``files()`` method. - """ - with contextlib.suppress(AttributeError): - return spec.loader.files() - - -def fallback_resources(spec): - package_directory = pathlib.Path(spec.origin).parent - try: - archive_path = spec.loader.archive - rel_path = package_directory.relative_to(archive_path) - return zipfile.Path(archive_path, str(rel_path) + '/') - except Exception: - pass - return package_directory + reader = spec.loader.get_resource_reader(spec.name) + return reader.files() @contextlib.contextmanager diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py index b8a9bb1a21e..97d5afa3001 100644 --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -12,6 +12,7 @@ try: import _frozen_importlib_external except ImportError: _frozen_importlib_external = _bootstrap_external +from ._abc import Loader import abc import warnings from typing import Protocol, runtime_checkable @@ -134,53 +135,6 @@ class PathEntryFinder(Finder): _register(PathEntryFinder, machinery.FileFinder) -class Loader(metaclass=abc.ABCMeta): - - """Abstract base class for import loaders.""" - - def create_module(self, spec): - """Return a module to initialize and into which to load. - - This method should raise ImportError if anything prevents it - from creating a new module. It may return None to indicate - that the spec should create the new module. - """ - # By default, defer to default semantics for the new module. - return None - - # We don't define exec_module() here since that would break - # hasattr checks we do to support backward compatibility. - - def load_module(self, fullname): - """Return the loaded module. - - The module must be added to sys.modules and have import-related - attributes set properly. The fullname is a str. - - ImportError is raised on failure. - - This method is deprecated in favor of loader.exec_module(). If - exec_module() exists then it is used to provide a backwards-compatible - functionality for this method. - - """ - if not hasattr(self, 'exec_module'): - raise ImportError - return _bootstrap._load_module_shim(self, fullname) - - def module_repr(self, module): - """Return a module's repr. - - Used by the module type when the method does not raise - NotImplementedError. - - This method is deprecated. - - """ - # The exception will cause ModuleType.__repr__ to ignore this method. - raise NotImplementedError - - class ResourceLoader(Loader): """Abstract base class for loaders which can return data from their @@ -468,7 +422,7 @@ class TraversableResources(ResourceReader): raise FileNotFoundError(resource) def is_resource(self, path): - return self.files().joinpath(path).isfile() + return self.files().joinpath(path).is_file() def contents(self): return (item.name for item in self.files().iterdir()) diff --git a/Lib/importlib/metadata.py b/Lib/importlib/metadata.py index 831f593277c..ffa0cba4570 100644 --- a/Lib/importlib/metadata.py +++ b/Lib/importlib/metadata.py @@ -78,6 +78,16 @@ class EntryPoint( attrs = filter(None, (match.group('attr') or '').split('.')) return functools.reduce(getattr, attrs, module) + @property + def module(self): + match = self.pattern.match(self.value) + return match.group('module') + + @property + def attr(self): + match = self.pattern.match(self.value) + return match.group('attr') + @property def extras(self): match = self.pattern.match(self.value) @@ -170,7 +180,7 @@ class Distribution: """ for resolver in cls._discover_resolvers(): dists = resolver(DistributionFinder.Context(name=name)) - dist = next(dists, None) + dist = next(iter(dists), None) if dist is not None: return dist else: @@ -213,6 +223,17 @@ class Distribution: ) return filter(None, declared) + @classmethod + def _local(cls, root='.'): + from pep517 import build, meta + system = build.compat_system(root) + builder = functools.partial( + meta.build, + source_dir=root, + system=system, + ) + return PathDistribution(zipfile.Path(meta.build_as_zip(builder))) + @property def metadata(self): """Return the parsed metadata for this Distribution. @@ -391,7 +412,7 @@ class FastPath: def __init__(self, root): self.root = root - self.base = os.path.basename(root).lower() + self.base = os.path.basename(self.root).lower() def joinpath(self, child): return pathlib.Path(self.root, child) @@ -408,8 +429,8 @@ class FastPath: names = zip_path.root.namelist() self.joinpath = zip_path.joinpath - return ( - posixpath.split(child)[0] + return dict.fromkeys( + child.split(posixpath.sep, 1)[0] for child in names ) @@ -475,7 +496,6 @@ class MetadataPathFinder(DistributionFinder): ) - class PathDistribution(Distribution): def __init__(self, path): """Construct a distribution from a path to the metadata directory. diff --git a/Lib/importlib/readers.py b/Lib/importlib/readers.py new file mode 100644 index 00000000000..6331e4daf43 --- /dev/null +++ b/Lib/importlib/readers.py @@ -0,0 +1,41 @@ +import zipfile +import pathlib +from . import abc + + +class FileReader(abc.TraversableResources): + def __init__(self, loader): + self.path = pathlib.Path(loader.path).parent + + def resource_path(self, resource): + """ + Return the file system path to prevent + `resources.path()` from creating a temporary + copy. + """ + return str(self.path.joinpath(resource)) + + def files(self): + return self.path + + +class ZipReader(abc.TraversableResources): + def __init__(self, loader, module): + _, _, name = module.rpartition('.') + prefix = loader.prefix.replace('\\', '/') + name + '/' + self.path = zipfile.Path(loader.archive, prefix) + + def open_resource(self, resource): + try: + return super().open_resource(resource) + except KeyError as exc: + raise FileNotFoundError(exc.args[0]) + + def is_resource(self, path): + # workaround for `zipfile.Path.is_file` returning true + # for non-existent paths. + target = self.files().joinpath(path) + return target.is_file() and target.exists() + + def files(self): + return self.path diff --git a/Lib/importlib/resources.py b/Lib/importlib/resources.py index b803a01c91d..4535619f4f0 100644 --- a/Lib/importlib/resources.py +++ b/Lib/importlib/resources.py @@ -1,15 +1,13 @@ import os -from . import abc as resources_abc from . import _common -from ._common import as_file +from ._common import as_file, files from contextlib import contextmanager, suppress -from importlib import import_module from importlib.abc import ResourceLoader from io import BytesIO, TextIOWrapper from pathlib import Path from types import ModuleType -from typing import ContextManager, Iterable, Optional, Union +from typing import ContextManager, Iterable, Union from typing import cast from typing.io import BinaryIO, TextIO @@ -33,60 +31,11 @@ Package = Union[str, ModuleType] Resource = Union[str, os.PathLike] -def _resolve(name) -> ModuleType: - """If name is a string, resolve to a module.""" - if hasattr(name, '__spec__'): - return name - return import_module(name) - - -def _get_package(package) -> ModuleType: - """Take a package name or module object and return the module. - - If a name, the module is imported. If the resolved module - object is not a package, raise an exception. - """ - module = _resolve(package) - if module.__spec__.submodule_search_locations is None: - raise TypeError('{!r} is not a package'.format(package)) - return module - - -def _normalize_path(path) -> str: - """Normalize a path by ensuring it is a string. - - If the resulting string contains path separators, an exception is raised. - """ - parent, file_name = os.path.split(path) - if parent: - raise ValueError('{!r} must be only a file name'.format(path)) - return file_name - - -def _get_resource_reader( - package: ModuleType) -> Optional[resources_abc.ResourceReader]: - # Return the package's loader if it's a ResourceReader. We can't use - # a issubclass() check here because apparently abc.'s __subclasscheck__() - # hook wants to create a weak reference to the object, but - # zipimport.zipimporter does not support weak references, resulting in a - # TypeError. That seems terrible. - spec = package.__spec__ - if hasattr(spec.loader, 'get_resource_reader'): - return cast(resources_abc.ResourceReader, - spec.loader.get_resource_reader(spec.name)) - return None - - -def _check_location(package): - if package.__spec__.origin is None or not package.__spec__.has_location: - raise FileNotFoundError(f'Package has no location {package!r}') - - def open_binary(package: Package, resource: Resource) -> BinaryIO: """Return a file-like object opened for binary reading of the resource.""" - resource = _normalize_path(resource) - package = _get_package(package) - reader = _get_resource_reader(package) + resource = _common.normalize_path(resource) + package = _common.get_package(package) + reader = _common.get_resource_reader(package) if reader is not None: return reader.open_resource(resource) absolute_package_path = os.path.abspath( @@ -140,13 +89,6 @@ def read_text(package: Package, return fp.read() -def files(package: Package) -> resources_abc.Traversable: - """ - Get a Traversable resource from a package - """ - return _common.from_package(_get_package(package)) - - def path( package: Package, resource: Resource, ) -> 'ContextManager[Path]': @@ -158,17 +100,18 @@ def path( raised if the file was deleted prior to the context manager exiting). """ - reader = _get_resource_reader(_get_package(package)) + reader = _common.get_resource_reader(_common.get_package(package)) return ( _path_from_reader(reader, resource) if reader else - _common.as_file(files(package).joinpath(_normalize_path(resource))) + _common.as_file( + _common.files(package).joinpath(_common.normalize_path(resource))) ) @contextmanager def _path_from_reader(reader, resource): - norm_resource = _normalize_path(resource) + norm_resource = _common.normalize_path(resource) with suppress(FileNotFoundError): yield Path(reader.resource_path(norm_resource)) return @@ -182,9 +125,9 @@ def is_resource(package: Package, name: str) -> bool: Directories are *not* resources. """ - package = _get_package(package) - _normalize_path(name) - reader = _get_resource_reader(package) + package = _common.get_package(package) + _common.normalize_path(name) + reader = _common.get_resource_reader(package) if reader is not None: return reader.is_resource(name) package_contents = set(contents(package)) @@ -200,8 +143,8 @@ def contents(package: Package) -> Iterable[str]: not considered resources. Use `is_resource()` on each entry returned here to check if it is a resource or not. """ - package = _get_package(package) - reader = _get_resource_reader(package) + package = _common.get_package(package) + reader = _common.get_resource_reader(package) if reader is not None: return reader.contents() # Is the package a namespace package? By definition, namespace packages diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py index 269a6fa930a..1e44843a687 100644 --- a/Lib/importlib/util.py +++ b/Lib/importlib/util.py @@ -1,5 +1,5 @@ """Utility code for constructing importers, etc.""" -from . import abc +from ._abc import Loader from ._bootstrap import module_from_spec from ._bootstrap import _resolve_name from ._bootstrap import spec_from_loader @@ -263,7 +263,7 @@ class _LazyModule(types.ModuleType): delattr(self, attr) -class LazyLoader(abc.Loader): +class LazyLoader(Loader): """A loader that creates a module which defers loading until attribute access.""" diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index 6e5a754c2ac..75b4c352c1d 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1420,7 +1420,7 @@ class IPv4Interface(IPv4Address): return False def __hash__(self): - return self._ip ^ self._prefixlen ^ int(self.network.network_address) + return hash((self._ip, self._prefixlen, int(self.network.network_address))) __reduce__ = _IPAddressBase.__reduce__ @@ -2120,7 +2120,7 @@ class IPv6Interface(IPv6Address): return False def __hash__(self): - return self._ip ^ self._prefixlen ^ int(self.network.network_address) + return hash((self._ip, self._prefixlen, int(self.network.network_address))) __reduce__ = _IPAddressBase.__reduce__ diff --git a/Lib/keyword.py b/Lib/keyword.py index ddcbb25d3d3..ccc951500f6 100644 --- a/Lib/keyword.py +++ b/Lib/keyword.py @@ -1,18 +1,19 @@ -"""Keywords (from "Grammar/Grammar") +"""Keywords (from "Grammar/python.gram") This file is automatically generated; please don't muck it up! To update the symbols in this file, 'cd' to the top directory of the python source tree and run: - python3 -m Parser.pgen.keywordgen Grammar/Grammar \ - Grammar/Tokens \ - Lib/keyword.py + PYTHONPATH=Tools/peg_generator python3 -m pegen.keywordgen \ + Grammar/Grammar \ + Grammar/Tokens \ + Lib/keyword.py Alternatively, you can run 'make regen-keyword'. """ -__all__ = ["iskeyword", "kwlist"] +__all__ = ["iskeyword", "issoftkeyword", "kwlist", "softkwlist"] kwlist = [ 'False', @@ -52,4 +53,9 @@ kwlist = [ 'yield' ] +softkwlist = [ + +] + iskeyword = frozenset(kwlist).__contains__ +issoftkeyword = frozenset(softkwlist).__contains__ diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 6d27301a705..94361ca75f4 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -411,8 +411,9 @@ class PercentStyle(object): asctime_search = '%(asctime)' validation_pattern = re.compile(r'%\(\w+\)[#0+ -]*(\*|\d+)?(\.(\*|\d+))?[diouxefgcrsa%]', re.I) - def __init__(self, fmt): + def __init__(self, fmt, *, defaults=None): self._fmt = fmt or self.default_format + self._defaults = defaults def usesTime(self): return self._fmt.find(self.asctime_search) >= 0 @@ -423,7 +424,11 @@ class PercentStyle(object): raise ValueError("Invalid format '%s' for '%s' style" % (self._fmt, self.default_format[0])) def _format(self, record): - return self._fmt % record.__dict__ + if defaults := self._defaults: + values = defaults | record.__dict__ + else: + values = record.__dict__ + return self._fmt % values def format(self, record): try: @@ -441,7 +446,11 @@ class StrFormatStyle(PercentStyle): field_spec = re.compile(r'^(\d+|\w+)(\.\w+|\[[^]]+\])*$') def _format(self, record): - return self._fmt.format(**record.__dict__) + if defaults := self._defaults: + values = defaults | record.__dict__ + else: + values = record.__dict__ + return self._fmt.format(**values) def validate(self): """Validate the input format, ensure it is the correct string formatting style""" @@ -467,8 +476,8 @@ class StringTemplateStyle(PercentStyle): asctime_format = '${asctime}' asctime_search = '${asctime}' - def __init__(self, fmt): - self._fmt = fmt or self.default_format + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) self._tpl = Template(self._fmt) def usesTime(self): @@ -490,7 +499,11 @@ class StringTemplateStyle(PercentStyle): raise ValueError('invalid format: no fields') def _format(self, record): - return self._tpl.substitute(**record.__dict__) + if defaults := self._defaults: + values = defaults | record.__dict__ + else: + values = record.__dict__ + return self._tpl.substitute(**values) BASIC_FORMAT = "%(levelname)s:%(name)s:%(message)s" @@ -546,7 +559,8 @@ class Formatter(object): converter = time.localtime - def __init__(self, fmt=None, datefmt=None, style='%', validate=True): + def __init__(self, fmt=None, datefmt=None, style='%', validate=True, *, + defaults=None): """ Initialize the formatter with specified format strings. @@ -565,7 +579,7 @@ class Formatter(object): if style not in _STYLES: raise ValueError('Style must be one of: %s' % ','.join( _STYLES.keys())) - self._style = _STYLES[style][0](fmt) + self._style = _STYLES[style][0](fmt, defaults=defaults) if validate: self._style.validate() @@ -1480,7 +1494,11 @@ class Logger(Filterer): if self.isEnabledFor(CRITICAL): self._log(CRITICAL, msg, args, **kwargs) - fatal = critical + def fatal(self, msg, *args, **kwargs): + """ + Don't use this method, use critical() instead. + """ + self.critical(msg, *args, **kwargs) def log(self, level, msg, *args, **kwargs): """ @@ -2039,7 +2057,11 @@ def critical(msg, *args, **kwargs): basicConfig() root.critical(msg, *args, **kwargs) -fatal = critical +def fatal(msg, *args, **kwargs): + """ + Don't use this function, use critical() instead. + """ + critical(msg, *args, **kwargs) def error(msg, *args, **kwargs): """ diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py index e972ca2e291..f3343c80545 100644 --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -372,7 +372,7 @@ def init(files=None): def read_mime_types(file): try: - f = open(file) + f = open(file, encoding='utf-8') except OSError: return None with f: @@ -448,6 +448,7 @@ def _default_mime_types(): '.dvi' : 'application/x-dvi', '.gtar' : 'application/x-gtar', '.hdf' : 'application/x-hdf', + '.h5' : 'application/x-hdf5', '.latex' : 'application/x-latex', '.mif' : 'application/x-mif', '.cdf' : 'application/x-netcdf', diff --git a/Lib/pdb.py b/Lib/pdb.py index bf503f1e73e..081023526c0 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -79,6 +79,7 @@ import glob import pprint import signal import inspect +import tokenize import traceback import linecache @@ -93,7 +94,7 @@ __all__ = ["run", "pm", "Pdb", "runeval", "runctx", "runcall", "set_trace", def find_function(funcname, filename): cre = re.compile(r'def\s+%s\s*[(]' % re.escape(funcname)) try: - fp = open(filename) + fp = tokenize.open(filename) except OSError: return None # consumer of this info expects the first line to be 1 @@ -473,7 +474,7 @@ class Pdb(bdb.Bdb, cmd.Cmd): except Exception: ret = [] # Then, try to complete file names as well. - globs = glob.glob(text + '*') + globs = glob.glob(glob.escape(text) + '*') for fn in globs: if os.path.isdir(fn): ret.append(fn + '/') diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py index 4c184678a29..3d7f19f3998 100644 --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -7,7 +7,6 @@ import importlib.util import importlib.machinery import os import os.path -import re import sys from types import ModuleType import warnings @@ -638,9 +637,7 @@ def get_data(package, resource): return loader.get_data(resource_name) -_DOTTED_WORDS = r'(?!\d)(\w+)(\.(?!\d)(\w+))*' -_NAME_PATTERN = re.compile(f'^(?P{_DOTTED_WORDS})(?P:(?P{_DOTTED_WORDS})?)?$', re.U) -del _DOTTED_WORDS +_NAME_PATTERN = None def resolve_name(name): """ @@ -674,6 +671,15 @@ def resolve_name(name): AttributeError - if a failure occurred when traversing the object hierarchy within the imported package to get to the desired object) """ + global _NAME_PATTERN + if _NAME_PATTERN is None: + # Lazy import to speedup Python startup time + import re + dotted_words = r'(?!\d)(\w+)(\.(?!\d)(\w+))*' + _NAME_PATTERN = re.compile(f'^(?P{dotted_words})' + f'(?P:(?P{dotted_words})?)?$', + re.UNICODE) + m = _NAME_PATTERN.match(name) if not m: raise ValueError(f'invalid format: {name!r}') diff --git a/Lib/random.py b/Lib/random.py index 75f70d5d699..a6454f520df 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -1,5 +1,9 @@ """Random variable generators. + bytes + ----- + uniform bytes (values between 0 and 255) + integers -------- uniform within range @@ -37,14 +41,20 @@ General notes on the underlying Mersenne Twister core generator: """ +# Translated by Guido van Rossum from C source provided by +# Adrian Baddeley. Adapted by Raymond Hettinger for use with +# the Mersenne Twister and os.urandom() core generators. + from warnings import warn as _warn from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin +from math import tau as TWOPI, floor as _floor from os import urandom as _urandom from _collections_abc import Set as _Set, Sequence as _Sequence from itertools import accumulate as _accumulate, repeat as _repeat from bisect import bisect as _bisect import os as _os +import _random try: # hashlib is pretty heavy to load, try lean internal module first @@ -53,28 +63,40 @@ except ImportError: # fallback to official implementation from hashlib import sha512 as _sha512 +__all__ = [ + "Random", + "SystemRandom", + "betavariate", + "choice", + "choices", + "expovariate", + "gammavariate", + "gauss", + "getrandbits", + "getstate", + "lognormvariate", + "normalvariate", + "paretovariate", + "randint", + "random", + "randrange", + "sample", + "seed", + "setstate", + "shuffle", + "triangular", + "uniform", + "vonmisesvariate", + "weibullvariate", +] -__all__ = ["Random","seed","random","uniform","randint","choice","sample", - "randrange","shuffle","normalvariate","lognormvariate", - "expovariate","vonmisesvariate","gammavariate","triangular", - "gauss","betavariate","paretovariate","weibullvariate", - "getstate","setstate", "getrandbits", "choices", - "SystemRandom"] - -NV_MAGICCONST = 4 * _exp(-0.5)/_sqrt(2.0) -TWOPI = 2.0*_pi +NV_MAGICCONST = 4 * _exp(-0.5) / _sqrt(2.0) LOG4 = _log(4.0) SG_MAGICCONST = 1.0 + _log(4.5) BPF = 53 # Number of bits in a float -RECIP_BPF = 2**-BPF +RECIP_BPF = 2 ** -BPF -# Translated by Guido van Rossum from C source provided by -# Adrian Baddeley. Adapted by Raymond Hettinger for use with -# the Mersenne Twister and os.urandom() core generators. - -import _random - class Random(_random.Random): """Random number generator base class used by bound module functions. @@ -100,26 +122,6 @@ class Random(_random.Random): self.seed(x) self.gauss_next = None - def __init_subclass__(cls, /, **kwargs): - """Control how subclasses generate random integers. - - The algorithm a subclass can use depends on the random() and/or - getrandbits() implementation available to it and determines - whether it can generate random integers from arbitrarily large - ranges. - """ - - for c in cls.__mro__: - if '_randbelow' in c.__dict__: - # just inherit it - break - if 'getrandbits' in c.__dict__: - cls._randbelow = cls._randbelow_with_getrandbits - break - if 'random' in c.__dict__: - cls._randbelow = cls._randbelow_without_getrandbits - break - def seed(self, a=None, version=2): """Initialize internal state from a seed. @@ -180,7 +182,7 @@ class Random(_random.Random): # really unsigned 32-bit ints, so we convert negative ints from # version 2 to positive longs for version 3. try: - internalstate = tuple(x % (2**32) for x in internalstate) + internalstate = tuple(x % (2 ** 32) for x in internalstate) except ValueError as e: raise TypeError from e super().setstate(internalstate) @@ -189,21 +191,18 @@ class Random(_random.Random): "Random.setstate() of version %s" % (version, self.VERSION)) -## ---- Methods below this point do not need to be overridden when -## ---- subclassing for the purpose of using a different core generator. -## -------------------- bytes methods --------------------- + ## ------------------------------------------------------- + ## ---- Methods below this point do not need to be overridden or extended + ## ---- when subclassing for the purpose of using a different core generator. - def randbytes(self, n): - """Generate n random bytes.""" - return self.getrandbits(n * 8).to_bytes(n, 'little') -## -------------------- pickle support ------------------- + ## -------------------- pickle support ------------------- # Issue 17489: Since __reduce__ was defined to fix #759889 this is no # longer called; we leave it here because it has been here since random was # rewritten back in 2001 and why risk breaking something. - def __getstate__(self): # for pickle + def __getstate__(self): # for pickle return self.getstate() def __setstate__(self, state): # for pickle @@ -212,9 +211,83 @@ class Random(_random.Random): def __reduce__(self): return self.__class__, (), self.getstate() -## -------------------- integer methods ------------------- - def randrange(self, start, stop=None, step=1, _int=int): + ## ---- internal support method for evenly distributed integers ---- + + def __init_subclass__(cls, /, **kwargs): + """Control how subclasses generate random integers. + + The algorithm a subclass can use depends on the random() and/or + getrandbits() implementation available to it and determines + whether it can generate random integers from arbitrarily large + ranges. + """ + + for c in cls.__mro__: + if '_randbelow' in c.__dict__: + # just inherit it + break + if 'getrandbits' in c.__dict__: + cls._randbelow = cls._randbelow_with_getrandbits + break + if 'random' in c.__dict__: + cls._randbelow = cls._randbelow_without_getrandbits + break + + def _randbelow_with_getrandbits(self, n): + "Return a random int in the range [0,n). Returns 0 if n==0." + + if not n: + return 0 + getrandbits = self.getrandbits + k = n.bit_length() # don't use (n-1) here because n can be 1 + r = getrandbits(k) # 0 <= r < 2**k + while r >= n: + r = getrandbits(k) + return r + + def _randbelow_without_getrandbits(self, n, maxsize=1<= maxsize: + _warn("Underlying random() generator does not supply \n" + "enough bits to choose from a population range this large.\n" + "To remove the range limitation, add a getrandbits() method.") + return _floor(random() * n) + if n == 0: + return 0 + rem = maxsize % n + limit = (maxsize - rem) / maxsize # int(limit * maxsize) % n == 0 + r = random() + while r >= limit: + r = random() + return _floor(r * maxsize) % n + + _randbelow = _randbelow_with_getrandbits + + + ## -------------------------------------------------------- + ## ---- Methods below this point generate custom distributions + ## ---- based on the methods defined above. They do not + ## ---- directly touch the underlying generator and only + ## ---- access randomness through the methods: random(), + ## ---- getrandbits(), or _randbelow(). + + + ## -------------------- bytes methods --------------------- + + def randbytes(self, n): + """Generate n random bytes.""" + return self.getrandbits(n * 8).to_bytes(n, 'little') + + + ## -------------------- integer methods ------------------- + + def randrange(self, start, stop=None, step=1): """Choose a random item from range(start, stop[, step]). This fixes the problem with randint() which includes the @@ -224,7 +297,7 @@ class Random(_random.Random): # This code is a bit messy to make it fast for the # common case while still doing adequate error checking. - istart = _int(start) + istart = int(start) if istart != start: raise ValueError("non-integer arg 1 for randrange()") if stop is None: @@ -233,7 +306,7 @@ class Random(_random.Random): raise ValueError("empty range for randrange()") # stop argument supplied. - istop = _int(stop) + istop = int(stop) if istop != stop: raise ValueError("non-integer stop for randrange()") width = istop - istart @@ -243,7 +316,7 @@ class Random(_random.Random): raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width)) # Non-unit step argument supplied. - istep = _int(step) + istep = int(step) if istep != step: raise ValueError("non-integer step for randrange()") if istep > 0: @@ -256,7 +329,7 @@ class Random(_random.Random): if n <= 0: raise ValueError("empty range for randrange()") - return istart + istep*self._randbelow(n) + return istart + istep * self._randbelow(n) def randint(self, a, b): """Return random integer in range [a, b], including both end points. @@ -264,46 +337,13 @@ class Random(_random.Random): return self.randrange(a, b+1) - def _randbelow_with_getrandbits(self, n): - "Return a random int in the range [0,n). Returns 0 if n==0." - if not n: - return 0 - getrandbits = self.getrandbits - k = n.bit_length() # don't use (n-1) here because n can be 1 - r = getrandbits(k) # 0 <= r < 2**k - while r >= n: - r = getrandbits(k) - return r - - def _randbelow_without_getrandbits(self, n, int=int, maxsize=1<= maxsize: - _warn("Underlying random() generator does not supply \n" - "enough bits to choose from a population range this large.\n" - "To remove the range limitation, add a getrandbits() method.") - return int(random() * n) - if n == 0: - return 0 - rem = maxsize % n - limit = (maxsize - rem) / maxsize # int(limit * maxsize) % n == 0 - r = random() - while r >= limit: - r = random() - return int(r*maxsize) % n - - _randbelow = _randbelow_with_getrandbits - -## -------------------- sequence methods ------------------- + ## -------------------- sequence methods ------------------- def choice(self, seq): """Choose a random element from a non-empty sequence.""" - return seq[self._randbelow(len(seq))] # raises IndexError if seq is empty + # raises IndexError if seq is empty + return seq[self._randbelow(len(seq))] def shuffle(self, x, random=None): """Shuffle list x in place, and return None. @@ -318,17 +358,17 @@ class Random(_random.Random): randbelow = self._randbelow for i in reversed(range(1, len(x))): # pick an element in x[:i+1] with which to exchange x[i] - j = randbelow(i+1) + j = randbelow(i + 1) x[i], x[j] = x[j], x[i] else: _warn('The *random* parameter to shuffle() has been deprecated\n' 'since Python 3.9 and will be removed in a subsequent ' 'version.', DeprecationWarning, 2) - _int = int + floor = _floor for i in reversed(range(1, len(x))): # pick an element in x[:i+1] with which to exchange x[i] - j = _int(random() * (i+1)) + j = floor(random() * (i + 1)) x[i], x[j] = x[j], x[i] def sample(self, population, k, *, counts=None): @@ -410,14 +450,15 @@ class Random(_random.Random): result = [None] * k setsize = 21 # size of a small set minus size of an empty list if k > 5: - setsize += 4 ** _ceil(_log(k * 3, 4)) # table size for big sets + setsize += 4 ** _ceil(_log(k * 3, 4)) # table size for big sets if n <= setsize: - # An n-length list is smaller than a k-length set + # An n-length list is smaller than a k-length set. + # Invariant: non-selected at pool[0 : n-i] pool = list(population) - for i in range(k): # invariant: non-selected at [0,n-i) - j = randbelow(n-i) + for i in range(k): + j = randbelow(n - i) result[i] = pool[j] - pool[j] = pool[n-i-1] # move non-selected item into vacancy + pool[j] = pool[n - i - 1] # move non-selected item into vacancy else: selected = set() selected_add = selected.add @@ -440,9 +481,9 @@ class Random(_random.Random): n = len(population) if cum_weights is None: if weights is None: - _int = int + floor = _floor n += 0.0 # convert to float for a small speed improvement - return [population[_int(random() * n)] for i in _repeat(None, k)] + return [population[floor(random() * n)] for i in _repeat(None, k)] cum_weights = list(_accumulate(weights)) elif weights is not None: raise TypeError('Cannot specify both weights and cumulative weights') @@ -456,15 +497,12 @@ class Random(_random.Random): return [population[bisect(cum_weights, random() * total, 0, hi)] for i in _repeat(None, k)] -## -------------------- real-valued distributions ------------------- -## -------------------- uniform distribution ------------------- + ## -------------------- real-valued distributions ------------------- def uniform(self, a, b): "Get a random number in the range [a, b) or [a, b] depending on rounding." - return a + (b-a) * self.random() - -## -------------------- triangular -------------------- + return a + (b - a) * self.random() def triangular(self, low=0.0, high=1.0, mode=None): """Triangular distribution. @@ -486,180 +524,26 @@ class Random(_random.Random): low, high = high, low return low + (high - low) * _sqrt(u * c) -## -------------------- normal distribution -------------------- - def normalvariate(self, mu, sigma): """Normal distribution. mu is the mean, and sigma is the standard deviation. """ - # mu = mean, sigma = standard deviation - # Uses Kinderman and Monahan method. Reference: Kinderman, # A.J. and Monahan, J.F., "Computer generation of random # variables using the ratio of uniform deviates", ACM Trans # Math Software, 3, (1977), pp257-260. random = self.random - while 1: + while True: u1 = random() u2 = 1.0 - random() - z = NV_MAGICCONST*(u1-0.5)/u2 - zz = z*z/4.0 + z = NV_MAGICCONST * (u1 - 0.5) / u2 + zz = z * z / 4.0 if zz <= -_log(u2): break - return mu + z*sigma - -## -------------------- lognormal distribution -------------------- - - def lognormvariate(self, mu, sigma): - """Log normal distribution. - - If you take the natural logarithm of this distribution, you'll get a - normal distribution with mean mu and standard deviation sigma. - mu can have any value, and sigma must be greater than zero. - - """ - return _exp(self.normalvariate(mu, sigma)) - -## -------------------- exponential distribution -------------------- - - def expovariate(self, lambd): - """Exponential distribution. - - lambd is 1.0 divided by the desired mean. It should be - nonzero. (The parameter would be called "lambda", but that is - a reserved word in Python.) Returned values range from 0 to - positive infinity if lambd is positive, and from negative - infinity to 0 if lambd is negative. - - """ - # lambd: rate lambd = 1/mean - # ('lambda' is a Python reserved word) - - # we use 1-random() instead of random() to preclude the - # possibility of taking the log of zero. - return -_log(1.0 - self.random())/lambd - -## -------------------- von Mises distribution -------------------- - - def vonmisesvariate(self, mu, kappa): - """Circular data distribution. - - mu is the mean angle, expressed in radians between 0 and 2*pi, and - kappa is the concentration parameter, which must be greater than or - equal to zero. If kappa is equal to zero, this distribution reduces - to a uniform random angle over the range 0 to 2*pi. - - """ - # mu: mean angle (in radians between 0 and 2*pi) - # kappa: concentration parameter kappa (>= 0) - # if kappa = 0 generate uniform random angle - - # Based upon an algorithm published in: Fisher, N.I., - # "Statistical Analysis of Circular Data", Cambridge - # University Press, 1993. - - # Thanks to Magnus Kessler for a correction to the - # implementation of step 4. - - random = self.random - if kappa <= 1e-6: - return TWOPI * random() - - s = 0.5 / kappa - r = s + _sqrt(1.0 + s * s) - - while 1: - u1 = random() - z = _cos(_pi * u1) - - d = z / (r + z) - u2 = random() - if u2 < 1.0 - d * d or u2 <= (1.0 - d) * _exp(d): - break - - q = 1.0 / r - f = (q + z) / (1.0 + q * z) - u3 = random() - if u3 > 0.5: - theta = (mu + _acos(f)) % TWOPI - else: - theta = (mu - _acos(f)) % TWOPI - - return theta - -## -------------------- gamma distribution -------------------- - - def gammavariate(self, alpha, beta): - """Gamma distribution. Not the gamma function! - - Conditions on the parameters are alpha > 0 and beta > 0. - - The probability distribution function is: - - x ** (alpha - 1) * math.exp(-x / beta) - pdf(x) = -------------------------------------- - math.gamma(alpha) * beta ** alpha - - """ - - # alpha > 0, beta > 0, mean is alpha*beta, variance is alpha*beta**2 - - # Warning: a few older sources define the gamma distribution in terms - # of alpha > -1.0 - if alpha <= 0.0 or beta <= 0.0: - raise ValueError('gammavariate: alpha and beta must be > 0.0') - - random = self.random - if alpha > 1.0: - - # Uses R.C.H. Cheng, "The generation of Gamma - # variables with non-integral shape parameters", - # Applied Statistics, (1977), 26, No. 1, p71-74 - - ainv = _sqrt(2.0 * alpha - 1.0) - bbb = alpha - LOG4 - ccc = alpha + ainv - - while 1: - u1 = random() - if not 1e-7 < u1 < .9999999: - continue - u2 = 1.0 - random() - v = _log(u1/(1.0-u1))/ainv - x = alpha*_exp(v) - z = u1*u1*u2 - r = bbb+ccc*v-x - if r + SG_MAGICCONST - 4.5*z >= 0.0 or r >= _log(z): - return x * beta - - elif alpha == 1.0: - # expovariate(1/beta) - return -_log(1.0 - random()) * beta - - else: # alpha is between 0 and 1 (exclusive) - - # Uses ALGORITHM GS of Statistical Computing - Kennedy & Gentle - - while 1: - u = random() - b = (_e + alpha)/_e - p = b*u - if p <= 1.0: - x = p ** (1.0/alpha) - else: - x = -_log((b-p)/alpha) - u1 = random() - if p > 1.0: - if u1 <= x ** (alpha - 1.0): - break - elif u1 <= _exp(-x): - break - return x * beta - -## -------------------- Gauss (faster alternative) -------------------- + return mu + z * sigma def gauss(self, mu, sigma): """Gaussian distribution. @@ -670,7 +554,6 @@ class Random(_random.Random): Not thread-safe without a lock around calls. """ - # When x and y are two variables from [0, 1), uniformly # distributed, then # @@ -698,21 +581,141 @@ class Random(_random.Random): z = _cos(x2pi) * g2rad self.gauss_next = _sin(x2pi) * g2rad - return mu + z*sigma + return mu + z * sigma -## -------------------- beta -------------------- -## See -## http://mail.python.org/pipermail/python-bugs-list/2001-January/003752.html -## for Ivan Frohne's insightful analysis of why the original implementation: -## -## def betavariate(self, alpha, beta): -## # Discrete Event Simulation in C, pp 87-88. -## -## y = self.expovariate(alpha) -## z = self.expovariate(1.0/beta) -## return z/(y+z) -## -## was dead wrong, and how it probably got that way. + def lognormvariate(self, mu, sigma): + """Log normal distribution. + + If you take the natural logarithm of this distribution, you'll get a + normal distribution with mean mu and standard deviation sigma. + mu can have any value, and sigma must be greater than zero. + + """ + return _exp(self.normalvariate(mu, sigma)) + + def expovariate(self, lambd): + """Exponential distribution. + + lambd is 1.0 divided by the desired mean. It should be + nonzero. (The parameter would be called "lambda", but that is + a reserved word in Python.) Returned values range from 0 to + positive infinity if lambd is positive, and from negative + infinity to 0 if lambd is negative. + + """ + # lambd: rate lambd = 1/mean + # ('lambda' is a Python reserved word) + + # we use 1-random() instead of random() to preclude the + # possibility of taking the log of zero. + return -_log(1.0 - self.random()) / lambd + + def vonmisesvariate(self, mu, kappa): + """Circular data distribution. + + mu is the mean angle, expressed in radians between 0 and 2*pi, and + kappa is the concentration parameter, which must be greater than or + equal to zero. If kappa is equal to zero, this distribution reduces + to a uniform random angle over the range 0 to 2*pi. + + """ + # Based upon an algorithm published in: Fisher, N.I., + # "Statistical Analysis of Circular Data", Cambridge + # University Press, 1993. + + # Thanks to Magnus Kessler for a correction to the + # implementation of step 4. + + random = self.random + if kappa <= 1e-6: + return TWOPI * random() + + s = 0.5 / kappa + r = s + _sqrt(1.0 + s * s) + + while True: + u1 = random() + z = _cos(_pi * u1) + + d = z / (r + z) + u2 = random() + if u2 < 1.0 - d * d or u2 <= (1.0 - d) * _exp(d): + break + + q = 1.0 / r + f = (q + z) / (1.0 + q * z) + u3 = random() + if u3 > 0.5: + theta = (mu + _acos(f)) % TWOPI + else: + theta = (mu - _acos(f)) % TWOPI + + return theta + + def gammavariate(self, alpha, beta): + """Gamma distribution. Not the gamma function! + + Conditions on the parameters are alpha > 0 and beta > 0. + + The probability distribution function is: + + x ** (alpha - 1) * math.exp(-x / beta) + pdf(x) = -------------------------------------- + math.gamma(alpha) * beta ** alpha + + """ + # alpha > 0, beta > 0, mean is alpha*beta, variance is alpha*beta**2 + + # Warning: a few older sources define the gamma distribution in terms + # of alpha > -1.0 + if alpha <= 0.0 or beta <= 0.0: + raise ValueError('gammavariate: alpha and beta must be > 0.0') + + random = self.random + if alpha > 1.0: + + # Uses R.C.H. Cheng, "The generation of Gamma + # variables with non-integral shape parameters", + # Applied Statistics, (1977), 26, No. 1, p71-74 + + ainv = _sqrt(2.0 * alpha - 1.0) + bbb = alpha - LOG4 + ccc = alpha + ainv + + while 1: + u1 = random() + if not 1e-7 < u1 < 0.9999999: + continue + u2 = 1.0 - random() + v = _log(u1 / (1.0 - u1)) / ainv + x = alpha * _exp(v) + z = u1 * u1 * u2 + r = bbb + ccc * v - x + if r + SG_MAGICCONST - 4.5 * z >= 0.0 or r >= _log(z): + return x * beta + + elif alpha == 1.0: + # expovariate(1/beta) + return -_log(1.0 - random()) * beta + + else: + # alpha is between 0 and 1 (exclusive) + # Uses ALGORITHM GS of Statistical Computing - Kennedy & Gentle + while True: + u = random() + b = (_e + alpha) / _e + p = b * u + if p <= 1.0: + x = p ** (1.0 / alpha) + else: + x = -_log((b - p) / alpha) + u1 = random() + if p > 1.0: + if u1 <= x ** (alpha - 1.0): + break + elif u1 <= _exp(-x): + break + return x * beta def betavariate(self, alpha, beta): """Beta distribution. @@ -721,25 +724,32 @@ class Random(_random.Random): Returned values range between 0 and 1. """ + ## See + ## http://mail.python.org/pipermail/python-bugs-list/2001-January/003752.html + ## for Ivan Frohne's insightful analysis of why the original implementation: + ## + ## def betavariate(self, alpha, beta): + ## # Discrete Event Simulation in C, pp 87-88. + ## + ## y = self.expovariate(alpha) + ## z = self.expovariate(1.0/beta) + ## return z/(y+z) + ## + ## was dead wrong, and how it probably got that way. # This version due to Janne Sinkkonen, and matches all the std # texts (e.g., Knuth Vol 2 Ed 3 pg 134 "the beta distribution"). y = self.gammavariate(alpha, 1.0) - if y == 0: - return 0.0 - else: + if y: return y / (y + self.gammavariate(beta, 1.0)) - -## -------------------- Pareto -------------------- + return 0.0 def paretovariate(self, alpha): """Pareto distribution. alpha is the shape parameter.""" # Jain, pg. 495 u = 1.0 - self.random() - return 1.0 / u ** (1.0/alpha) - -## -------------------- Weibull -------------------- + return 1.0 / u ** (1.0 / alpha) def weibullvariate(self, alpha, beta): """Weibull distribution. @@ -750,16 +760,20 @@ class Random(_random.Random): # Jain, pg. 499; bug fix courtesy Bill Arms u = 1.0 - self.random() - return alpha * (-_log(u)) ** (1.0/beta) + return alpha * (-_log(u)) ** (1.0 / beta) + +## ------------------------------------------------------------------ ## --------------- Operating System Random Source ------------------ + class SystemRandom(Random): """Alternate random number generator using sources provided by the operating system (such as /dev/urandom on Unix or CryptGenRandom on Windows). Not available on all systems (see os.urandom() for details). + """ def random(self): @@ -789,51 +803,11 @@ class SystemRandom(Random): raise NotImplementedError('System entropy source does not have state.') getstate = setstate = _notimplemented -## -------------------- test program -------------------- - -def _test_generator(n, func, args): - import time - print(n, 'times', func.__name__) - total = 0.0 - sqsum = 0.0 - smallest = 1e10 - largest = -1e10 - t0 = time.perf_counter() - for i in range(n): - x = func(*args) - total += x - sqsum = sqsum + x*x - smallest = min(x, smallest) - largest = max(x, largest) - t1 = time.perf_counter() - print(round(t1-t0, 3), 'sec,', end=' ') - avg = total/n - stddev = _sqrt(sqsum/n - avg*avg) - print('avg %g, stddev %g, min %g, max %g\n' % \ - (avg, stddev, smallest, largest)) - - -def _test(N=2000): - _test_generator(N, random, ()) - _test_generator(N, normalvariate, (0.0, 1.0)) - _test_generator(N, lognormvariate, (0.0, 1.0)) - _test_generator(N, vonmisesvariate, (0.0, 1.0)) - _test_generator(N, gammavariate, (0.01, 1.0)) - _test_generator(N, gammavariate, (0.1, 1.0)) - _test_generator(N, gammavariate, (0.1, 2.0)) - _test_generator(N, gammavariate, (0.5, 1.0)) - _test_generator(N, gammavariate, (0.9, 1.0)) - _test_generator(N, gammavariate, (1.0, 1.0)) - _test_generator(N, gammavariate, (2.0, 1.0)) - _test_generator(N, gammavariate, (20.0, 1.0)) - _test_generator(N, gammavariate, (200.0, 1.0)) - _test_generator(N, gauss, (0.0, 1.0)) - _test_generator(N, betavariate, (3.0, 3.0)) - _test_generator(N, triangular, (0.0, 1.0, 1.0/3.0)) +# ---------------------------------------------------------------------- # Create one instance, seeded from current time, and export its methods # as module-level functions. The functions share state across all uses -#(both in the user's code and in the Python libraries), but that's fine +# (both in the user's code and in the Python libraries), but that's fine # for most programs and is easier for the casual user than making them # instantiate their own Random() instance. @@ -862,6 +836,49 @@ setstate = _inst.setstate getrandbits = _inst.getrandbits randbytes = _inst.randbytes + +## ------------------------------------------------------ +## ----------------- test program ----------------------- + +def _test_generator(n, func, args): + from statistics import stdev, fmean as mean + from time import perf_counter + + t0 = perf_counter() + data = [func(*args) for i in range(n)] + t1 = perf_counter() + + xbar = mean(data) + sigma = stdev(data, xbar) + low = min(data) + high = max(data) + + print(f'{t1 - t0:.3f} sec, {n} times {func.__name__}') + print('avg %g, stddev %g, min %g, max %g\n' % (xbar, sigma, low, high)) + + +def _test(N=2000): + _test_generator(N, random, ()) + _test_generator(N, normalvariate, (0.0, 1.0)) + _test_generator(N, lognormvariate, (0.0, 1.0)) + _test_generator(N, vonmisesvariate, (0.0, 1.0)) + _test_generator(N, gammavariate, (0.01, 1.0)) + _test_generator(N, gammavariate, (0.1, 1.0)) + _test_generator(N, gammavariate, (0.1, 2.0)) + _test_generator(N, gammavariate, (0.5, 1.0)) + _test_generator(N, gammavariate, (0.9, 1.0)) + _test_generator(N, gammavariate, (1.0, 1.0)) + _test_generator(N, gammavariate, (2.0, 1.0)) + _test_generator(N, gammavariate, (20.0, 1.0)) + _test_generator(N, gammavariate, (200.0, 1.0)) + _test_generator(N, gauss, (0.0, 1.0)) + _test_generator(N, betavariate, (3.0, 3.0)) + _test_generator(N, triangular, (0.0, 1.0, 1.0 / 3.0)) + + +## ------------------------------------------------------ +## ------------------ fork support --------------------- + if hasattr(_os, "fork"): _os.register_at_fork(after_in_child=_inst.seed) diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py index bca4a7bc521..c06388e8d9c 100644 --- a/Lib/rlcompleter.py +++ b/Lib/rlcompleter.py @@ -31,6 +31,7 @@ Notes: import atexit import builtins +import inspect import __main__ __all__ = ["Completer"] @@ -96,7 +97,13 @@ class Completer: def _callable_postfix(self, val, word): if callable(val): - word = word + "(" + word += "(" + try: + if not inspect.signature(val).parameters: + word += ")" + except ValueError: + pass + return word def global_matches(self, text): diff --git a/Lib/site.py b/Lib/site.py index e981a142088..8979365cafc 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -88,6 +88,11 @@ USER_SITE = None USER_BASE = None +def _trace(message): + if sys.flags.verbose: + print(message, file=sys.stderr) + + def makepath(*paths): dir = os.path.join(*paths) try: @@ -156,6 +161,7 @@ def addpackage(sitedir, name, known_paths): else: reset = False fullname = os.path.join(sitedir, name) + _trace(f"Processing .pth file: {fullname!r}") try: f = io.TextIOWrapper(io.open_code(fullname)) except OSError: @@ -190,6 +196,7 @@ def addpackage(sitedir, name, known_paths): def addsitedir(sitedir, known_paths=None): """Add 'sitedir' argument to sys.path if missing and handle .pth files in 'sitedir'""" + _trace(f"Adding directory: {sitedir!r}") if known_paths is None: known_paths = _init_pathinfo() reset = True @@ -310,6 +317,7 @@ def addusersitepackages(known_paths): """ # get the per user site-package path # this call will also make sure USER_BASE and USER_SITE are set + _trace("Processing user site-packages") user_site = getusersitepackages() if ENABLE_USER_SITE and os.path.isdir(user_site): @@ -354,6 +362,7 @@ def getsitepackages(prefixes=None): def addsitepackages(known_paths, prefixes=None): """Add site-packages to sys.path""" + _trace("Processing global site-packages") for sitedir in getsitepackages(prefixes): if os.path.isdir(sitedir): addsitedir(sitedir, known_paths) @@ -453,9 +462,9 @@ def enablerlcompleter(): def write_history(): try: readline.write_history_file(history) - except (FileNotFoundError, PermissionError): - # home directory does not exist or is not writable - # https://bugs.python.org/issue19891 + except OSError: + # bpo-19891, bpo-41193: Home directory does not exist + # or is not writable, or the filesystem is read-only. pass atexit.register(write_history) diff --git a/Lib/sndhdr.py b/Lib/sndhdr.py index 594353136f5..96595c69744 100644 --- a/Lib/sndhdr.py +++ b/Lib/sndhdr.py @@ -241,7 +241,7 @@ def testall(list, recursive, toplevel): if recursive or toplevel: print('recursing down:') import glob - names = glob.glob(os.path.join(filename, '*')) + names = glob.glob(os.path.join(glob.escape(filename), '*')) testall(names, recursive, 0) else: print('*** directory (use -r) ***') diff --git a/Lib/sqlite3/test/userfunctions.py b/Lib/sqlite3/test/userfunctions.py index 9501f535c49..c11c82e1275 100644 --- a/Lib/sqlite3/test/userfunctions.py +++ b/Lib/sqlite3/test/userfunctions.py @@ -1,8 +1,7 @@ -#-*- coding: iso-8859-1 -*- # pysqlite2/test/userfunctions.py: tests for user-defined functions and # aggregates. # -# Copyright (C) 2005-2007 Gerhard Häring +# Copyright (C) 2005-2007 Gerhard Häring # # This file is part of pysqlite. # @@ -158,6 +157,7 @@ class FunctionTests(unittest.TestCase): self.con.create_function("isblob", 1, func_isblob) self.con.create_function("islonglong", 1, func_islonglong) self.con.create_function("spam", -1, func) + self.con.execute("create table test(t text)") def tearDown(self): self.con.close() @@ -276,18 +276,36 @@ class FunctionTests(unittest.TestCase): val = cur.fetchone()[0] self.assertEqual(val, 2) + # Regarding deterministic functions: + # + # Between 3.8.3 and 3.15.0, deterministic functions were only used to + # optimize inner loops, so for those versions we can only test if the + # sqlite machinery has factored out a call or not. From 3.15.0 and onward, + # deterministic functions were permitted in WHERE clauses of partial + # indices, which allows testing based on syntax, iso. the query optimizer. + @unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher") def CheckFuncNonDeterministic(self): mock = unittest.mock.Mock(return_value=None) - self.con.create_function("deterministic", 0, mock, deterministic=False) - self.con.execute("select deterministic() = deterministic()") - self.assertEqual(mock.call_count, 2) + self.con.create_function("nondeterministic", 0, mock, deterministic=False) + if sqlite.sqlite_version_info < (3, 15, 0): + self.con.execute("select nondeterministic() = nondeterministic()") + self.assertEqual(mock.call_count, 2) + else: + with self.assertRaises(sqlite.OperationalError): + self.con.execute("create index t on test(t) where nondeterministic() is not null") - @unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "deterministic parameter not supported") + @unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher") def CheckFuncDeterministic(self): mock = unittest.mock.Mock(return_value=None) self.con.create_function("deterministic", 0, mock, deterministic=True) - self.con.execute("select deterministic() = deterministic()") - self.assertEqual(mock.call_count, 1) + if sqlite.sqlite_version_info < (3, 15, 0): + self.con.execute("select deterministic() = deterministic()") + self.assertEqual(mock.call_count, 1) + else: + try: + self.con.execute("create index t on test(t) where deterministic() is not null") + except sqlite.OperationalError: + self.fail("Unexpected failure while creating partial index") @unittest.skipIf(sqlite.sqlite_version_info >= (3, 8, 3), "SQLite < 3.8.3 needed") def CheckFuncDeterministicNotSupported(self): diff --git a/Lib/statistics.py b/Lib/statistics.py index c76a6ca519e..f9d3802ec5f 100644 --- a/Lib/statistics.py +++ b/Lib/statistics.py @@ -163,7 +163,7 @@ def _sum(data, start=0): T = _coerce(int, type(start)) for typ, values in groupby(data, type): T = _coerce(T, typ) # or raise TypeError - for n,d in map(_exact_ratio, values): + for n, d in map(_exact_ratio, values): count += 1 partials[d] = partials_get(d, 0) + n if None in partials: @@ -261,7 +261,7 @@ def _convert(value, T): return T(value) except TypeError: if issubclass(T, Decimal): - return T(value.numerator)/T(value.denominator) + return T(value.numerator) / T(value.denominator) else: raise @@ -277,8 +277,8 @@ def _find_lteq(a, x): def _find_rteq(a, l, x): 'Locate the rightmost value exactly equal to x' i = bisect_right(a, x, lo=l) - if i != (len(a)+1) and a[i-1] == x: - return i-1 + if i != (len(a) + 1) and a[i - 1] == x: + return i - 1 raise ValueError @@ -315,7 +315,7 @@ def mean(data): raise StatisticsError('mean requires at least one data point') T, total, count = _sum(data) assert count == n - return _convert(total/n, T) + return _convert(total / n, T) def fmean(data): @@ -403,11 +403,11 @@ def harmonic_mean(data): else: raise TypeError('unsupported type') try: - T, total, count = _sum(1/x for x in _fail_neg(data, errmsg)) + T, total, count = _sum(1 / x for x in _fail_neg(data, errmsg)) except ZeroDivisionError: return 0 assert count == n - return _convert(n/total, T) + return _convert(n / total, T) # FIXME: investigate ways to calculate medians without sorting? Quickselect? @@ -428,11 +428,11 @@ def median(data): n = len(data) if n == 0: raise StatisticsError("no median for empty data") - if n%2 == 1: - return data[n//2] + if n % 2 == 1: + return data[n // 2] else: - i = n//2 - return (data[i - 1] + data[i])/2 + i = n // 2 + return (data[i - 1] + data[i]) / 2 def median_low(data): @@ -451,10 +451,10 @@ def median_low(data): n = len(data) if n == 0: raise StatisticsError("no median for empty data") - if n%2 == 1: - return data[n//2] + if n % 2 == 1: + return data[n // 2] else: - return data[n//2 - 1] + return data[n // 2 - 1] def median_high(data): @@ -473,7 +473,7 @@ def median_high(data): n = len(data) if n == 0: raise StatisticsError("no median for empty data") - return data[n//2] + return data[n // 2] def median_grouped(data, interval=1): @@ -510,15 +510,15 @@ def median_grouped(data, interval=1): return data[0] # Find the value at the midpoint. Remember this corresponds to the # centre of the class interval. - x = data[n//2] + x = data[n // 2] for obj in (x, interval): if isinstance(obj, (str, bytes)): raise TypeError('expected number but got %r' % obj) try: - L = x - interval/2 # The lower limit of the median interval. + L = x - interval / 2 # The lower limit of the median interval. except TypeError: # Mixed type. For now we just coerce to float. - L = float(x) - float(interval)/2 + L = float(x) - float(interval) / 2 # Uses bisection search to search for x in data with log(n) time complexity # Find the position of leftmost occurrence of x in data @@ -528,7 +528,7 @@ def median_grouped(data, interval=1): l2 = _find_rteq(data, l1, x) cf = l1 f = l2 - l1 + 1 - return L + interval*(n/2 - cf)/f + return L + interval * (n / 2 - cf) / f def mode(data): @@ -554,8 +554,7 @@ def mode(data): If *data* is empty, ``mode``, raises StatisticsError. """ - data = iter(data) - pairs = Counter(data).most_common(1) + pairs = Counter(iter(data)).most_common(1) try: return pairs[0][0] except IndexError: @@ -597,7 +596,7 @@ def multimode(data): # For sample data where there is a positive probability for values # beyond the range of the data, the R6 exclusive method is a # reasonable choice. Consider a random sample of nine values from a -# population with a uniform distribution from 0.0 to 100.0. The +# population with a uniform distribution from 0.0 to 1.0. The # distribution of the third ranked sample point is described by # betavariate(alpha=3, beta=7) which has mode=0.250, median=0.286, and # mean=0.300. Only the latter (which corresponds with R6) gives the @@ -643,9 +642,8 @@ def quantiles(data, *, n=4, method='exclusive'): m = ld - 1 result = [] for i in range(1, n): - j = i * m // n - delta = i*m - j*n - interpolated = (data[j] * (n - delta) + data[j+1] * delta) / n + j, delta = divmod(i * m, n) + interpolated = (data[j] * (n - delta) + data[j + 1] * delta) / n result.append(interpolated) return result if method == 'exclusive': @@ -655,7 +653,7 @@ def quantiles(data, *, n=4, method='exclusive'): j = i * m // n # rescale i to m/n j = 1 if j < 1 else ld-1 if j > ld-1 else j # clamp to 1 .. ld-1 delta = i*m - j*n # exact integer math - interpolated = (data[j-1] * (n - delta) + data[j] * delta) / n + interpolated = (data[j - 1] * (n - delta) + data[j] * delta) / n result.append(interpolated) return result raise ValueError(f'Unknown method: {method!r}') @@ -682,14 +680,16 @@ def _ss(data, c=None): calculated from ``c`` as given. Use the second case with care, as it can lead to garbage results. """ - if c is None: - c = mean(data) + if c is not None: + T, total, count = _sum((x-c)**2 for x in data) + return (T, total) + c = mean(data) T, total, count = _sum((x-c)**2 for x in data) # The following sum should mathematically equal zero, but due to rounding # error may not. - U, total2, count2 = _sum((x-c) for x in data) + U, total2, count2 = _sum((x - c) for x in data) assert T == U and count == count2 - total -= total2**2/len(data) + total -= total2 ** 2 / len(data) assert not total < 0, 'negative sum of square deviations: %f' % total return (T, total) @@ -738,7 +738,7 @@ def variance(data, xbar=None): if n < 2: raise StatisticsError('variance requires at least two data points') T, ss = _ss(data, xbar) - return _convert(ss/(n-1), T) + return _convert(ss / (n - 1), T) def pvariance(data, mu=None): @@ -782,7 +782,7 @@ def pvariance(data, mu=None): if n < 1: raise StatisticsError('pvariance requires at least one data point') T, ss = _ss(data, mu) - return _convert(ss/n, T) + return _convert(ss / n, T) def stdev(data, xbar=None): @@ -991,7 +991,7 @@ class NormalDist: if not isinstance(other, NormalDist): raise TypeError('Expected another NormalDist instance') X, Y = self, other - if (Y._sigma, Y._mu) < (X._sigma, X._mu): # sort to assure commutativity + if (Y._sigma, Y._mu) < (X._sigma, X._mu): # sort to assure commutativity X, Y = Y, X X_var, Y_var = X.variance, Y.variance if not X_var or not Y_var: diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 13600c28cf7..86fdf27f9b0 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -326,7 +326,7 @@ def _args_from_interpreter_flags(): if dev_mode: args.extend(('-X', 'dev')) for opt in ('faulthandler', 'tracemalloc', 'importtime', - 'showrefcount', 'utf8', 'oldparser'): + 'showrefcount', 'utf8'): if opt in xoptions: value = xoptions[opt] if value is True: diff --git a/Lib/symbol.py b/Lib/symbol.py deleted file mode 100644 index 36e0eec7ac1..00000000000 --- a/Lib/symbol.py +++ /dev/null @@ -1,113 +0,0 @@ -"""Non-terminal symbols of Python grammar (from "graminit.h").""" - -# This file is automatically generated; please don't muck it up! -# -# To update the symbols in this file, 'cd' to the top directory of -# the python source tree after building the interpreter and run: -# -# python3 Tools/scripts/generate_symbol_py.py Include/graminit.h Lib/symbol.py -# -# or just -# -# make regen-symbol - -#--start constants-- -single_input = 256 -file_input = 257 -eval_input = 258 -decorator = 259 -decorators = 260 -decorated = 261 -async_funcdef = 262 -funcdef = 263 -parameters = 264 -typedargslist = 265 -tfpdef = 266 -varargslist = 267 -vfpdef = 268 -stmt = 269 -simple_stmt = 270 -small_stmt = 271 -expr_stmt = 272 -annassign = 273 -testlist_star_expr = 274 -augassign = 275 -del_stmt = 276 -pass_stmt = 277 -flow_stmt = 278 -break_stmt = 279 -continue_stmt = 280 -return_stmt = 281 -yield_stmt = 282 -raise_stmt = 283 -import_stmt = 284 -import_name = 285 -import_from = 286 -import_as_name = 287 -dotted_as_name = 288 -import_as_names = 289 -dotted_as_names = 290 -dotted_name = 291 -global_stmt = 292 -nonlocal_stmt = 293 -assert_stmt = 294 -compound_stmt = 295 -async_stmt = 296 -if_stmt = 297 -while_stmt = 298 -for_stmt = 299 -try_stmt = 300 -with_stmt = 301 -with_item = 302 -except_clause = 303 -suite = 304 -namedexpr_test = 305 -test = 306 -test_nocond = 307 -lambdef = 308 -lambdef_nocond = 309 -or_test = 310 -and_test = 311 -not_test = 312 -comparison = 313 -comp_op = 314 -star_expr = 315 -expr = 316 -xor_expr = 317 -and_expr = 318 -shift_expr = 319 -arith_expr = 320 -term = 321 -factor = 322 -power = 323 -atom_expr = 324 -atom = 325 -testlist_comp = 326 -trailer = 327 -subscriptlist = 328 -subscript = 329 -sliceop = 330 -exprlist = 331 -testlist = 332 -dictorsetmaker = 333 -classdef = 334 -arglist = 335 -argument = 336 -comp_iter = 337 -sync_comp_for = 338 -comp_for = 339 -comp_if = 340 -encoding_decl = 341 -yield_expr = 342 -yield_arg = 343 -func_body_suite = 344 -func_type_input = 345 -func_type = 346 -typelist = 347 -#--end constants-- - -sym_name = {} -for _name, _value in list(globals().items()): - if type(_value) is type(0): - sym_name[_value] = _name -del _name, _value diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 155a8276e75..6b4679f82da 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -26,13 +26,16 @@ import warnings import test.support import test.support.script_helper from test import support +from test.support import hashlib_helper +from test.support import import_helper from test.support import socket_helper +from test.support import threading_helper # Skip tests if _multiprocessing wasn't built. -_multiprocessing = test.support.import_module('_multiprocessing') +_multiprocessing = import_helper.import_module('_multiprocessing') # Skip tests if sem_open implementation is broken. -test.support.import_module('multiprocessing.synchronize') +support.skip_if_broken_multiprocessing_synchronize() import threading import multiprocessing.connection @@ -81,7 +84,7 @@ def close_queue(queue): def join_process(process): # Since multiprocessing.Process has the same API than threading.Thread # (join() and is_alive(), the support function can be reused - support.join_thread(process) + threading_helper.join_thread(process) if os.name == "posix": @@ -2953,6 +2956,8 @@ class _TestRemoteManager(BaseTestCase): # Make queue finalizer run before the server is stopped del queue + +@hashlib_helper.requires_hashdigest('md5') class _TestManagerRestart(BaseTestCase): @classmethod @@ -3437,6 +3442,7 @@ class _TestPoll(BaseTestCase): # @unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction") +@hashlib_helper.requires_hashdigest('md5') class _TestPicklingConnections(BaseTestCase): ALLOWED_TYPES = ('processes',) @@ -3739,6 +3745,7 @@ class _TestSharedCTypes(BaseTestCase): @unittest.skipUnless(HAS_SHMEM, "requires multiprocessing.shared_memory") +@hashlib_helper.requires_hashdigest('md5') class _TestSharedMemory(BaseTestCase): ALLOWED_TYPES = ('processes',) @@ -4234,7 +4241,7 @@ class _TestFinalize(BaseTestCase): gc.set_threshold(5, 5, 5) threads = [threading.Thread(target=run_finalizers), threading.Thread(target=make_finalizers)] - with test.support.start_threads(threads): + with threading_helper.start_threads(threads): time.sleep(4.0) # Wait a bit to trigger race condition finish = True if exc is not None: @@ -4254,7 +4261,7 @@ class _TestImportStar(unittest.TestCase): def get_module_names(self): import glob folder = os.path.dirname(multiprocessing.__file__) - pattern = os.path.join(folder, '*.py') + pattern = os.path.join(glob.escape(folder), '*.py') files = glob.glob(pattern) modules = [os.path.splitext(os.path.split(f)[1])[0] for f in files] modules = ['multiprocessing.' + m for m in modules] @@ -4414,6 +4421,7 @@ class TestInvalidHandle(unittest.TestCase): +@hashlib_helper.requires_hashdigest('md5') class OtherTest(unittest.TestCase): # TODO: add more tests for deliver/answer challenge. def test_deliver_challenge_auth_failure(self): @@ -4450,6 +4458,7 @@ class OtherTest(unittest.TestCase): def initializer(ns): ns.test += 1 +@hashlib_helper.requires_hashdigest('md5') class TestInitializers(unittest.TestCase): def setUp(self): self.mgr = multiprocessing.Manager() @@ -5304,6 +5313,7 @@ class TestPoolNotLeakOnFailure(unittest.TestCase): any(process.is_alive() for process in forked_processes)) +@hashlib_helper.requires_hashdigest('md5') class TestSyncManagerTypes(unittest.TestCase): """Test all the types which can be shared between a parent and a child process by using a manager which acts as an intermediary @@ -5698,6 +5708,8 @@ def install_tests_in_module_dict(remote_globs, start_method): Mixin = local_globs[type_.capitalize() + 'Mixin'] class Temp(base, Mixin, unittest.TestCase): pass + if type_ == 'manager': + Temp = hashlib_helper.requires_hashdigest('md5')(Temp) Temp.__name__ = Temp.__qualname__ = newname Temp.__module__ = __module__ remote_globs[newname] = Temp diff --git a/Lib/test/audiotests.py b/Lib/test/audiotests.py index d3e8e9ee44a..9d6c4cc2b4b 100644 --- a/Lib/test/audiotests.py +++ b/Lib/test/audiotests.py @@ -1,4 +1,5 @@ -from test.support import findfile, TESTFN, unlink +from test.support import findfile +from test.support.os_helper import TESTFN, unlink import array import io import pickle diff --git a/Lib/test/audit-tests.py b/Lib/test/audit-tests.py index b90c4b8f757..ee6fc93351b 100644 --- a/Lib/test/audit-tests.py +++ b/Lib/test/audit-tests.py @@ -44,28 +44,6 @@ class TestHook: raise self.exc_type("saw event " + event) -class TestFinalizeHook: - """Used in the test_finalize_hooks function to ensure that hooks - are correctly cleaned up, that they are notified about the cleanup, - and are unable to prevent it. - """ - - def __init__(self): - print("Created", id(self), file=sys.stdout, flush=True) - - def __call__(self, event, args): - # Avoid recursion when we call id() below - if event == "builtins.id": - return - - print(event, id(self), file=sys.stdout, flush=True) - - if event == "cpython._PySys_ClearAuditHooks": - raise RuntimeError("Should be ignored") - elif event == "cpython.PyInterpreterState_Clear": - raise RuntimeError("Should be ignored") - - # Simple helpers, since we are not in unittest here def assertEqual(x, y): if x != y: @@ -128,10 +106,6 @@ def test_block_add_hook_baseexception(): pass -def test_finalize_hooks(): - sys.addaudithook(TestFinalizeHook()) - - def test_pickle(): import pickle @@ -350,9 +324,9 @@ def test_socket(): if __name__ == "__main__": - from test.libregrtest.setup import suppress_msvcrt_asserts + from test.support import suppress_msvcrt_asserts - suppress_msvcrt_asserts(False) + suppress_msvcrt_asserts() test = sys.argv[1] globals()[test]() diff --git a/Lib/test/clinic.test b/Lib/test/clinic.test index 5e6f129f092..07e13829d5d 100644 --- a/Lib/test/clinic.test +++ b/Lib/test/clinic.test @@ -1332,7 +1332,7 @@ test_Py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t na } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -1347,7 +1347,7 @@ test_Py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t na } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -1373,7 +1373,7 @@ exit: static PyObject * test_Py_ssize_t_converter_impl(PyObject *module, Py_ssize_t a, Py_ssize_t b, Py_ssize_t c) -/*[clinic end generated code: output=ea781bb7169b3436 input=3855f184bb3f299d]*/ +/*[clinic end generated code: output=3bf73f9fdfeab468 input=3855f184bb3f299d]*/ /*[clinic input] @@ -1813,13 +1813,26 @@ test_Py_UNICODE_converter(PyObject *module, PyObject *const *args, Py_ssize_t na const Py_UNICODE *e; Py_ssize_clean_t e_length; - if (!_PyArg_ParseStack(args, nargs, "uuZu#Z#:test_Py_UNICODE_converter", - &a, &b, &c, &d, &d_length, &e, &e_length)) { + if (!_PyArg_ParseStack(args, nargs, "O&O&O&u#Z#:test_Py_UNICODE_converter", + _PyUnicode_WideCharString_Converter, &a, _PyUnicode_WideCharString_Converter, &b, _PyUnicode_WideCharString_Opt_Converter, &c, &d, &d_length, &e, &e_length)) { goto exit; } return_value = test_Py_UNICODE_converter_impl(module, a, b, c, d, d_length, e, e_length); exit: + /* Cleanup for a */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)a); + #endif /* USE_UNICODE_WCHAR_CACHE */ + /* Cleanup for b */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)b); + #endif /* USE_UNICODE_WCHAR_CACHE */ + /* Cleanup for c */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)c); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -1830,7 +1843,7 @@ test_Py_UNICODE_converter_impl(PyObject *module, const Py_UNICODE *a, Py_ssize_clean_t d_length, const Py_UNICODE *e, Py_ssize_clean_t e_length) -/*[clinic end generated code: output=dd0a09a1b772e57b input=064a3b68ad7f04b0]*/ +/*[clinic end generated code: output=ef45e982fedf0b3d input=064a3b68ad7f04b0]*/ /*[clinic input] diff --git a/Lib/test/fork_wait.py b/Lib/test/fork_wait.py index 249b5e96073..4d3dbd8e83f 100644 --- a/Lib/test/fork_wait.py +++ b/Lib/test/fork_wait.py @@ -12,6 +12,7 @@ active threads survive in the child after a fork(); this is an error. import os, sys, time, unittest import threading from test import support +from test.support import threading_helper LONGSLEEP = 2 @@ -21,7 +22,7 @@ NUM_THREADS = 4 class ForkWait(unittest.TestCase): def setUp(self): - self._threading_key = support.threading_setup() + self._threading_key = threading_helper.threading_setup() self.alive = {} self.stop = 0 self.threads = [] @@ -33,7 +34,7 @@ class ForkWait(unittest.TestCase): thread.join() thread = None self.threads.clear() - support.threading_cleanup(*self._threading_key) + threading_helper.threading_cleanup(*self._threading_key) def f(self, id): while not self.stop: diff --git a/Lib/test/libregrtest/cmdline.py b/Lib/test/libregrtest/cmdline.py index c0bb051bd07..a4bac79c8af 100644 --- a/Lib/test/libregrtest/cmdline.py +++ b/Lib/test/libregrtest/cmdline.py @@ -2,6 +2,7 @@ import argparse import os import sys from test import support +from test.support import os_helper USAGE = """\ @@ -291,7 +292,7 @@ def _create_parser(): def relative_filename(string): # CWD is replaced with a temporary dir before calling main(), so we # join it with the saved CWD so it ends up where the user expects. - return os.path.join(support.SAVEDCWD, string) + return os.path.join(os_helper.SAVEDCWD, string) def huntrleaks(string): diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 95b4856c8be..793c99a8f4c 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -20,6 +20,7 @@ from test.libregrtest.setup import setup_tests from test.libregrtest.pgo import setup_pgo_tests from test.libregrtest.utils import removepy, count, format_duration, printlist from test import support +from test.support import os_helper # bpo-38203: Maximum delay in seconds to exit Python (call Py_Finalize()). @@ -215,7 +216,7 @@ class Regrtest: # regex to match 'test_builtin' in line: # '0:00:00 [ 4/400] test_builtin -- test_dict took 1 sec' regex = re.compile(r'\btest_[a-zA-Z0-9_]+\b') - with open(os.path.join(support.SAVEDCWD, self.ns.fromfile)) as fp: + with open(os.path.join(os_helper.SAVEDCWD, self.ns.fromfile)) as fp: for line in fp: line = line.split('#', 1)[0] line = line.strip() @@ -558,7 +559,7 @@ class Regrtest: for k, v in totals.items(): root.set(k, str(v)) - xmlpath = os.path.join(support.SAVEDCWD, self.ns.xmlpath) + xmlpath = os.path.join(os_helper.SAVEDCWD, self.ns.xmlpath) with open(xmlpath, 'wb') as f: for s in ET.tostringlist(root): f.write(s) @@ -596,21 +597,22 @@ class Regrtest: test_cwd = 'test_python_worker_{}'.format(pid) else: test_cwd = 'test_python_{}'.format(pid) + test_cwd += os_helper.FS_NONASCII test_cwd = os.path.join(self.tmp_dir, test_cwd) return test_cwd def cleanup(self): import glob - path = os.path.join(self.tmp_dir, 'test_python_*') + path = os.path.join(glob.escape(self.tmp_dir), 'test_python_*') print("Cleanup %s directory" % self.tmp_dir) for name in glob.glob(path): if os.path.isdir(name): print("Remove directory: %s" % name) - support.rmtree(name) + os_helper.rmtree(name) else: print("Remove file: %s" % name) - support.unlink(name) + os_helper.unlink(name) def main(self, tests=None, **kwargs): self.parse_args(kwargs) @@ -627,8 +629,8 @@ class Regrtest: # Run the tests in a context manager that temporarily changes the CWD # to a temporary and writable directory. If it's not possible to # create or change the CWD, the original CWD will be used. - # The original CWD is available from support.SAVEDCWD. - with support.temp_cwd(test_cwd, quiet=True): + # The original CWD is available from os_helper.SAVEDCWD. + with os_helper.temp_cwd(test_cwd, quiet=True): # When using multiprocessing, worker processes will use test_cwd # as their parent temporary directory. So when the main process # exit, it removes also subdirectories of worker processes. diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py index 9338b280479..e46cc31caea 100644 --- a/Lib/test/libregrtest/runtest.py +++ b/Lib/test/libregrtest/runtest.py @@ -11,6 +11,8 @@ import traceback import unittest from test import support +from test.support import import_helper +from test.support import os_helper from test.libregrtest.refleak import dash_R, clear_caches from test.libregrtest.save_env import saved_test_environment from test.libregrtest.utils import format_duration, print_warning @@ -216,7 +218,7 @@ def _runtest_inner2(ns, test_name): abstest = get_abs_module(ns, test_name) # remove the module from sys.module to reload it if it was already imported - support.unload(abstest) + import_helper.unload(abstest) the_module = importlib.import_module(abstest) @@ -313,7 +315,7 @@ def cleanup_test_droppings(test_name, verbose): # since if a test leaves a file open, it cannot be deleted by name (while # there's nothing we can do about that here either, we can display the # name of the offending test, which is a real help). - for name in (support.TESTFN,): + for name in (os_helper.TESTFN,): if not os.path.exists(name): continue diff --git a/Lib/test/libregrtest/runtest_mp.py b/Lib/test/libregrtest/runtest_mp.py index 7a18e45434b..3d503af23b6 100644 --- a/Lib/test/libregrtest/runtest_mp.py +++ b/Lib/test/libregrtest/runtest_mp.py @@ -11,6 +11,7 @@ import time import traceback import types from test import support +from test.support import os_helper from test.libregrtest.runtest import ( runtest, INTERRUPTED, CHILD_ERROR, PROGRESS_MIN_TIME, @@ -70,7 +71,7 @@ def run_test_in_subprocess(testname, ns): stderr=subprocess.PIPE, universal_newlines=True, close_fds=(os.name != 'nt'), - cwd=support.SAVEDCWD, + cwd=os_helper.SAVEDCWD, **kw) diff --git a/Lib/test/libregrtest/save_env.py b/Lib/test/libregrtest/save_env.py index e7c27a698b0..50ed3536496 100644 --- a/Lib/test/libregrtest/save_env.py +++ b/Lib/test/libregrtest/save_env.py @@ -10,6 +10,7 @@ import threading import urllib.request import warnings from test import support +from test.support import os_helper from test.libregrtest.utils import print_warning try: import _multiprocessing, multiprocessing.process @@ -241,7 +242,7 @@ class saved_test_environment: return sorted(fn + ('/' if os.path.isdir(fn) else '') for fn in os.listdir()) def restore_files(self, saved_value): - fn = support.TESTFN + fn = os_helper.TESTFN if fn not in saved_value and (fn + '/') not in saved_value: if os.path.isfile(fn): support.unlink(fn) diff --git a/Lib/test/libregrtest/setup.py b/Lib/test/libregrtest/setup.py index ce8149677e0..1f264c1be49 100644 --- a/Lib/test/libregrtest/setup.py +++ b/Lib/test/libregrtest/setup.py @@ -69,7 +69,7 @@ def setup_tests(ns): if ns.threshold is not None: gc.set_threshold(ns.threshold) - suppress_msvcrt_asserts(ns.verbose and ns.verbose >= 2) + support.suppress_msvcrt_asserts(ns.verbose and ns.verbose >= 2) support.use_resources = ns.use_resources @@ -93,31 +93,6 @@ def setup_tests(ns): support.LONG_TIMEOUT = min(support.LONG_TIMEOUT, ns.timeout) -def suppress_msvcrt_asserts(verbose): - try: - import msvcrt - except ImportError: - return - - msvcrt.SetErrorMode(msvcrt.SEM_FAILCRITICALERRORS| - msvcrt.SEM_NOALIGNMENTFAULTEXCEPT| - msvcrt.SEM_NOGPFAULTERRORBOX| - msvcrt.SEM_NOOPENFILEERRORBOX) - try: - msvcrt.CrtSetReportMode - except AttributeError: - # release build - return - - for m in [msvcrt.CRT_WARN, msvcrt.CRT_ERROR, msvcrt.CRT_ASSERT]: - if verbose: - msvcrt.CrtSetReportMode(m, msvcrt.CRTDBG_MODE_FILE) - msvcrt.CrtSetReportFile(m, msvcrt.CRTDBG_FILE_STDERR) - else: - msvcrt.CrtSetReportMode(m, 0) - - - def replace_stdout(): """Set stdout encoder error handler to backslashreplace (as stderr error handler) to avoid UnicodeEncodeError when printing a traceback""" diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py index 44bc2ae6573..f7eea88c54a 100644 --- a/Lib/test/list_tests.py +++ b/Lib/test/list_tests.py @@ -66,20 +66,6 @@ class CommonTest(seq_tests.CommonTest): a = self.type2test([a]) self.assertRaises(RecursionError, repr, a) - def test_print(self): - d = self.type2test(range(200)) - d.append(d) - d.extend(range(200,400)) - d.append(d) - d.append(400) - try: - with open(support.TESTFN, "w") as fo: - fo.write(str(d)) - with open(support.TESTFN, "r") as fo: - self.assertEqual(fo.read(), repr(d)) - finally: - os.remove(support.TESTFN) - def test_set_subscript(self): a = self.type2test(range(20)) self.assertRaises(ValueError, a.__setitem__, slice(0, 10, 0), [1,2,3]) diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py index b3975254c79..d69bcc94968 100644 --- a/Lib/test/lock_tests.py +++ b/Lib/test/lock_tests.py @@ -11,6 +11,7 @@ import unittest import weakref from test import support +from test.support import threading_helper requires_fork = unittest.skipUnless(hasattr(os, 'fork'), @@ -37,7 +38,7 @@ class Bunch(object): self.started = [] self.finished = [] self._can_exit = not wait_before_exit - self.wait_thread = support.wait_threads_exit() + self.wait_thread = threading_helper.wait_threads_exit() self.wait_thread.__enter__() def task(): @@ -73,10 +74,10 @@ class Bunch(object): class BaseTestCase(unittest.TestCase): def setUp(self): - self._threads = support.threading_setup() + self._threads = threading_helper.threading_setup() def tearDown(self): - support.threading_cleanup(*self._threads) + threading_helper.threading_cleanup(*self._threads) support.reap_children() def assertTimeout(self, actual, expected): @@ -239,7 +240,7 @@ class LockTests(BaseLockTests): lock.acquire() phase.append(None) - with support.wait_threads_exit(): + with threading_helper.wait_threads_exit(): start_new_thread(f, ()) while len(phase) == 0: _wait() diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 6ef4c8989f5..afbc2b3bf0a 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -21,18 +21,28 @@ try: except ImportError: _testbuffer = None +from test import support +from test.support import os_helper +from test.support import ( + TestFailed, run_with_locale, no_tracing, + _2G, _4G, bigmemtest + ) +from test.support.import_helper import forget +from test.support.os_helper import TESTFN +from test.support import threading_helper +from test.support.warnings_helper import save_restore_warnings_filters + +from pickle import bytes_types + + +# bpo-41003: Save/restore warnings filters to leave them unchanged. +# Ignore filters installed by numpy. try: - import numpy as np + with save_restore_warnings_filters(): + import numpy as np except ImportError: np = None -from test import support -from test.support import ( - TestFailed, TESTFN, run_with_locale, no_tracing, - _2G, _4G, bigmemtest, reap_threads, forget, - ) - -from pickle import bytes_types requires_32b = unittest.skipUnless(sys.maxsize < 2**32, "test is only meaningful on 32-bit builds") @@ -1350,7 +1360,7 @@ class AbstractUnpickleTests(unittest.TestCase): for p in badpickles: self.check_unpickling_error(self.truncated_errors, p) - @reap_threads + @threading_helper.reap_threads def test_unpickle_module_race(self): # https://bugs.python.org/issue34572 locker_module = dedent(""" @@ -3093,7 +3103,7 @@ class AbstractPickleModuleTests(unittest.TestCase): f.close() self.assertRaises(ValueError, self.dump, 123, f) finally: - support.unlink(TESTFN) + os_helper.unlink(TESTFN) def test_load_closed_file(self): f = open(TESTFN, "wb") @@ -3101,7 +3111,7 @@ class AbstractPickleModuleTests(unittest.TestCase): f.close() self.assertRaises(ValueError, self.dump, 123, f) finally: - support.unlink(TESTFN) + os_helper.unlink(TESTFN) def test_load_from_and_dump_to_file(self): stream = io.BytesIO() @@ -3132,7 +3142,7 @@ class AbstractPickleModuleTests(unittest.TestCase): self.assertRaises(TypeError, self.dump, 123, f, proto) finally: f.close() - support.unlink(TESTFN) + os_helper.unlink(TESTFN) def test_incomplete_input(self): s = io.BytesIO(b"X''.") diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 8dee5b9dcc7..f8f60fb6c27 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -3,73 +3,68 @@ if __name__ != 'test.support': raise ImportError('support must be imported from the test package') -import collections.abc import contextlib -import errno -import fnmatch import functools -import glob -import importlib -import importlib.util import os -import platform import re import stat -import struct -import subprocess import sys import sysconfig -import _thread -import threading import time import types import unittest -import warnings + +from .import_helper import ( + CleanImport, DirsOnSysPath, _ignore_deprecated_imports, + _save_and_block_module, _save_and_remove_module, + forget, import_fresh_module, import_module, make_legacy_pyc, + modules_cleanup, modules_setup, unload) +from .os_helper import ( + FS_NONASCII, SAVEDCWD, TESTFN, TESTFN_ASCII, TESTFN_NONASCII, + TESTFN_UNENCODABLE, TESTFN_UNDECODABLE, + TESTFN_UNICODE, can_symlink, can_xattr, + change_cwd, create_empty_file, fd_count, + fs_is_case_insensitive, make_bad_fd, rmdir, + rmtree, skip_unless_symlink, skip_unless_xattr, + temp_cwd, temp_dir, temp_umask, unlink, + EnvironmentVarGuard, FakePath, _longpath) +from .warnings_helper import ( + WarningsRecorder, _filterwarnings, + check_no_resource_warning, check_no_warnings, + check_syntax_warning, check_warnings, ignore_warnings) from .testresult import get_test_runner + __all__ = [ # globals "PIPE_MAX_SIZE", "verbose", "max_memuse", "use_resources", "failfast", # exceptions "Error", "TestFailed", "TestDidNotRun", "ResourceDenied", - # imports - "import_module", "import_fresh_module", "CleanImport", - # modules - "unload", "forget", # io "record_original_stdout", "get_original_stdout", "captured_stdout", "captured_stdin", "captured_stderr", - # filesystem - "TESTFN", "SAVEDCWD", "unlink", "rmtree", "temp_cwd", "findfile", - "create_empty_file", "can_symlink", "fs_is_case_insensitive", # unittest "is_resource_enabled", "requires", "requires_freebsd_version", "requires_linux_version", "requires_mac_ver", - "check_syntax_error", "check_syntax_warning", - "TransientResource", "time_out", "socket_peer_reset", "ioerror_peer_reset", + "check_syntax_error", "BasicTestRunner", "run_unittest", "run_doctest", - "skip_unless_symlink", "requires_gzip", "requires_bz2", "requires_lzma", + "requires_gzip", "requires_bz2", "requires_lzma", "bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute", - "requires_IEEE_754", "skip_unless_xattr", "requires_zlib", + "requires_IEEE_754", "requires_zlib", "anticipate_failure", "load_package_tests", "detect_api_mismatch", "check__all__", "skip_if_buggy_ucrt_strfptime", - "ignore_warnings", # sys "is_jython", "is_android", "check_impl_detail", "unix_shell", "setswitchinterval", # network "open_urlresource", # processes - 'temp_umask', "reap_children", - # threads - "threading_setup", "threading_cleanup", "reap_threads", "start_threads", + "reap_children", # miscellaneous - "check_warnings", "check_no_resource_warning", "check_no_warnings", - "EnvironmentVarGuard", - "run_with_locale", "swap_item", + "run_with_locale", "swap_item", "findfile", "swap_attr", "Matcher", "set_memlimit", "SuppressCrashReport", "sortdict", - "run_with_tz", "PGO", "missing_compiler_executable", "fd_count", + "run_with_tz", "PGO", "missing_compiler_executable", "ALWAYS_EQ", "NEVER_EQ", "LARGEST", "SMALLEST", "LOOPBACK_TIMEOUT", "INTERNET_TIMEOUT", "SHORT_TIMEOUT", "LONG_TIMEOUT", ] @@ -85,7 +80,7 @@ __all__ = [ # The timeout should be long enough for connect(), recv() and send() methods # of socket.socket. LOOPBACK_TIMEOUT = 5.0 -if sys.platform == 'win32' and platform.machine() == 'ARM': +if sys.platform == 'win32' and ' 32 bit (ARM)' in sys.version: # bpo-37553: test_socket.SendfileUsingSendTest is taking longer than 2 # seconds on Windows ARM32 buildbot LOOPBACK_TIMEOUT = 10 @@ -132,84 +127,6 @@ class ResourceDenied(unittest.SkipTest): and unexpected skips. """ -@contextlib.contextmanager -def _ignore_deprecated_imports(ignore=True): - """Context manager to suppress package and module deprecation - warnings when importing them. - - If ignore is False, this context manager has no effect. - """ - if ignore: - with warnings.catch_warnings(): - warnings.filterwarnings("ignore", ".+ (module|package)", - DeprecationWarning) - yield - else: - yield - - -def ignore_warnings(*, category): - """Decorator to suppress deprecation warnings. - - Use of context managers to hide warnings make diffs - more noisy and tools like 'git blame' less useful. - """ - def decorator(test): - @functools.wraps(test) - def wrapper(self, *args, **kwargs): - with warnings.catch_warnings(): - warnings.simplefilter('ignore', category=category) - return test(self, *args, **kwargs) - return wrapper - return decorator - - -def import_module(name, deprecated=False, *, required_on=()): - """Import and return the module to be tested, raising SkipTest if - it is not available. - - If deprecated is True, any module or package deprecation messages - will be suppressed. If a module is required on a platform but optional for - others, set required_on to an iterable of platform prefixes which will be - compared against sys.platform. - """ - with _ignore_deprecated_imports(deprecated): - try: - return importlib.import_module(name) - except ImportError as msg: - if sys.platform.startswith(tuple(required_on)): - raise - raise unittest.SkipTest(str(msg)) - - -def _save_and_remove_module(name, orig_modules): - """Helper function to save and remove a module from sys.modules - - Raise ImportError if the module can't be imported. - """ - # try to import the module and raise an error if it can't be imported - if name not in sys.modules: - __import__(name) - del sys.modules[name] - for modname in list(sys.modules): - if modname == name or modname.startswith(name + '.'): - orig_modules[modname] = sys.modules[modname] - del sys.modules[modname] - -def _save_and_block_module(name, orig_modules): - """Helper function to save and block a module in sys.modules - - Return True if the module was in sys.modules, False otherwise. - """ - saved = True - try: - orig_modules[name] = sys.modules[name] - except KeyError: - saved = False - sys.modules[name] = None - return saved - - def anticipate_failure(condition): """Decorator to mark a test that is known to be broken in some cases @@ -240,56 +157,6 @@ def load_package_tests(pkg_dir, loader, standard_tests, pattern): return standard_tests -def import_fresh_module(name, fresh=(), blocked=(), deprecated=False): - """Import and return a module, deliberately bypassing sys.modules. - - This function imports and returns a fresh copy of the named Python module - by removing the named module from sys.modules before doing the import. - Note that unlike reload, the original module is not affected by - this operation. - - *fresh* is an iterable of additional module names that are also removed - from the sys.modules cache before doing the import. - - *blocked* is an iterable of module names that are replaced with None - in the module cache during the import to ensure that attempts to import - them raise ImportError. - - The named module and any modules named in the *fresh* and *blocked* - parameters are saved before starting the import and then reinserted into - sys.modules when the fresh import is complete. - - Module and package deprecation messages are suppressed during this import - if *deprecated* is True. - - This function will raise ImportError if the named module cannot be - imported. - """ - # NOTE: test_heapq, test_json and test_warnings include extra sanity checks - # to make sure that this utility function is working as expected - with _ignore_deprecated_imports(deprecated): - # Keep track of modules saved for later restoration as well - # as those which just need a blocking entry removed - orig_modules = {} - names_to_remove = [] - _save_and_remove_module(name, orig_modules) - try: - for fresh_name in fresh: - _save_and_remove_module(fresh_name, orig_modules) - for blocked_name in blocked: - if not _save_and_block_module(blocked_name, orig_modules): - names_to_remove.append(blocked_name) - fresh_module = importlib.import_module(name) - except ImportError: - fresh_module = None - finally: - for orig_name, module in orig_modules.items(): - sys.modules[orig_name] = module - for name_to_remove in names_to_remove: - del sys.modules[name_to_remove] - return fresh_module - - def get_attribute(obj, name): """Get an attribute, raising SkipTest if AttributeError is raised.""" try: @@ -318,11 +185,6 @@ def record_original_stdout(stdout): def get_original_stdout(): return _original_stdout or sys.stdout -def unload(name): - try: - del sys.modules[name] - except KeyError: - pass def _force_run(path, func, *args): try: @@ -334,157 +196,12 @@ def _force_run(path, func, *args): os.chmod(path, stat.S_IRWXU) return func(*args) -if sys.platform.startswith("win"): - def _waitfor(func, pathname, waitall=False): - # Perform the operation - func(pathname) - # Now setup the wait loop - if waitall: - dirname = pathname - else: - dirname, name = os.path.split(pathname) - dirname = dirname or '.' - # Check for `pathname` to be removed from the filesystem. - # The exponential backoff of the timeout amounts to a total - # of ~1 second after which the deletion is probably an error - # anyway. - # Testing on an i7@4.3GHz shows that usually only 1 iteration is - # required when contention occurs. - timeout = 0.001 - while timeout < 1.0: - # Note we are only testing for the existence of the file(s) in - # the contents of the directory regardless of any security or - # access rights. If we have made it this far, we have sufficient - # permissions to do that much using Python's equivalent of the - # Windows API FindFirstFile. - # Other Windows APIs can fail or give incorrect results when - # dealing with files that are pending deletion. - L = os.listdir(dirname) - if not (L if waitall else name in L): - return - # Increase the timeout and try again - time.sleep(timeout) - timeout *= 2 - warnings.warn('tests may fail, delete still pending for ' + pathname, - RuntimeWarning, stacklevel=4) - - def _unlink(filename): - _waitfor(os.unlink, filename) - - def _rmdir(dirname): - _waitfor(os.rmdir, dirname) - - def _rmtree(path): - def _rmtree_inner(path): - for name in _force_run(path, os.listdir, path): - fullname = os.path.join(path, name) - try: - mode = os.lstat(fullname).st_mode - except OSError as exc: - print("support.rmtree(): os.lstat(%r) failed with %s" % (fullname, exc), - file=sys.__stderr__) - mode = 0 - if stat.S_ISDIR(mode): - _waitfor(_rmtree_inner, fullname, waitall=True) - _force_run(fullname, os.rmdir, fullname) - else: - _force_run(fullname, os.unlink, fullname) - _waitfor(_rmtree_inner, path, waitall=True) - _waitfor(lambda p: _force_run(p, os.rmdir, p), path) - - def _longpath(path): - try: - import ctypes - except ImportError: - # No ctypes means we can't expands paths. - pass - else: - buffer = ctypes.create_unicode_buffer(len(path) * 2) - length = ctypes.windll.kernel32.GetLongPathNameW(path, buffer, - len(buffer)) - if length: - return buffer[:length] - return path -else: - _unlink = os.unlink - _rmdir = os.rmdir - - def _rmtree(path): - import shutil - try: - shutil.rmtree(path) - return - except OSError: - pass - - def _rmtree_inner(path): - for name in _force_run(path, os.listdir, path): - fullname = os.path.join(path, name) - try: - mode = os.lstat(fullname).st_mode - except OSError: - mode = 0 - if stat.S_ISDIR(mode): - _rmtree_inner(fullname) - _force_run(path, os.rmdir, fullname) - else: - _force_run(path, os.unlink, fullname) - _rmtree_inner(path) - os.rmdir(path) - - def _longpath(path): - return path - -def unlink(filename): - try: - _unlink(filename) - except (FileNotFoundError, NotADirectoryError): - pass - -def rmdir(dirname): - try: - _rmdir(dirname) - except FileNotFoundError: - pass - -def rmtree(path): - try: - _rmtree(path) - except FileNotFoundError: - pass - -def make_legacy_pyc(source): - """Move a PEP 3147/488 pyc file to its legacy pyc location. - - :param source: The file system path to the source file. The source file - does not need to exist, however the PEP 3147/488 pyc file must exist. - :return: The file system path to the legacy pyc file. - """ - pyc_file = importlib.util.cache_from_source(source) - up_one = os.path.dirname(os.path.abspath(source)) - legacy_pyc = os.path.join(up_one, source + 'c') - os.rename(pyc_file, legacy_pyc) - return legacy_pyc - -def forget(modname): - """'Forget' a module was ever imported. - - This removes the module from sys.modules and deletes any PEP 3147/488 or - legacy .pyc files. - """ - unload(modname) - for dirname in sys.path: - source = os.path.join(dirname, modname + '.py') - # It doesn't matter if they exist or not, unlink all possible - # combinations of PEP 3147/488 and legacy pyc files. - unlink(source + 'c') - for opt in ('', 1, 2): - unlink(importlib.util.cache_from_source(source, optimization=opt)) # Check whether a gui is actually available def _is_gui_available(): if hasattr(_is_gui_available, 'result'): return _is_gui_available.result + import platform reason = None if sys.platform.startswith('win') and platform.win32_is_iot(): reason = "gui is not available on Windows IoT Core" @@ -582,25 +299,25 @@ def _requires_unix_version(sysname, min_version): For example, @_requires_unix_version('FreeBSD', (7, 2)) raises SkipTest if the FreeBSD version is less than 7.2. """ - def decorator(func): - @functools.wraps(func) - def wrapper(*args, **kw): - if platform.system() == sysname: - version_txt = platform.release().split('-', 1)[0] - try: - version = tuple(map(int, version_txt.split('.'))) - except ValueError: - pass - else: - if version < min_version: - min_version_txt = '.'.join(map(str, min_version)) - raise unittest.SkipTest( - "%s version %s or higher required, not %s" - % (sysname, min_version_txt, version_txt)) - return func(*args, **kw) - wrapper.min_version = min_version - return wrapper - return decorator + import platform + min_version_txt = '.'.join(map(str, min_version)) + version_txt = platform.release().split('-', 1)[0] + if platform.system() == sysname: + try: + version = tuple(map(int, version_txt.split('.'))) + except ValueError: + skip = False + else: + skip = version < min_version + else: + skip = False + + return unittest.skipIf( + skip, + f"{sysname} version {min_version_txt} or higher required, not " + f"{version_txt}" + ) + def requires_freebsd_version(*min_version): """Decorator raising SkipTest if the OS is FreeBSD and the FreeBSD version is @@ -631,6 +348,7 @@ def requires_mac_ver(*min_version): @functools.wraps(func) def wrapper(*args, **kw): if sys.platform == 'darwin': + import platform version_txt = platform.mac_ver()[0] try: version = tuple(map(int, version_txt.split('.'))) @@ -717,150 +435,10 @@ if sys.platform != 'win32': else: unix_shell = None -# Filename used for testing -if os.name == 'java': - # Jython disallows @ in module names - TESTFN = '$test' -else: - TESTFN = '@test' - -# Disambiguate TESTFN for parallel testing, while letting it remain a valid -# module name. -TESTFN = "{}_{}_tmp".format(TESTFN, os.getpid()) - # Define the URL of a dedicated HTTP server for the network tests. # The URL must use clear-text HTTP: no redirection to encrypted HTTPS. TEST_HTTP_URL = "http://www.pythontest.net" -# FS_NONASCII: non-ASCII character encodable by os.fsencode(), -# or None if there is no such character. -FS_NONASCII = None -for character in ( - # First try printable and common characters to have a readable filename. - # For each character, the encoding list are just example of encodings able - # to encode the character (the list is not exhaustive). - - # U+00E6 (Latin Small Letter Ae): cp1252, iso-8859-1 - '\u00E6', - # U+0130 (Latin Capital Letter I With Dot Above): cp1254, iso8859_3 - '\u0130', - # U+0141 (Latin Capital Letter L With Stroke): cp1250, cp1257 - '\u0141', - # U+03C6 (Greek Small Letter Phi): cp1253 - '\u03C6', - # U+041A (Cyrillic Capital Letter Ka): cp1251 - '\u041A', - # U+05D0 (Hebrew Letter Alef): Encodable to cp424 - '\u05D0', - # U+060C (Arabic Comma): cp864, cp1006, iso8859_6, mac_arabic - '\u060C', - # U+062A (Arabic Letter Teh): cp720 - '\u062A', - # U+0E01 (Thai Character Ko Kai): cp874 - '\u0E01', - - # Then try more "special" characters. "special" because they may be - # interpreted or displayed differently depending on the exact locale - # encoding and the font. - - # U+00A0 (No-Break Space) - '\u00A0', - # U+20AC (Euro Sign) - '\u20AC', -): - try: - # If Python is set up to use the legacy 'mbcs' in Windows, - # 'replace' error mode is used, and encode() returns b'?' - # for characters missing in the ANSI codepage - if os.fsdecode(os.fsencode(character)) != character: - raise UnicodeError - except UnicodeError: - pass - else: - FS_NONASCII = character - break - -# TESTFN_UNICODE is a non-ascii filename -TESTFN_UNICODE = TESTFN + "-\xe0\xf2\u0258\u0141\u011f" -if sys.platform == 'darwin': - # In Mac OS X's VFS API file names are, by definition, canonically - # decomposed Unicode, encoded using UTF-8. See QA1173: - # http://developer.apple.com/mac/library/qa/qa2001/qa1173.html - import unicodedata - TESTFN_UNICODE = unicodedata.normalize('NFD', TESTFN_UNICODE) -TESTFN_ENCODING = sys.getfilesystemencoding() - -# TESTFN_UNENCODABLE is a filename (str type) that should *not* be able to be -# encoded by the filesystem encoding (in strict mode). It can be None if we -# cannot generate such filename. -TESTFN_UNENCODABLE = None -if os.name == 'nt': - # skip win32s (0) or Windows 9x/ME (1) - if sys.getwindowsversion().platform >= 2: - # Different kinds of characters from various languages to minimize the - # probability that the whole name is encodable to MBCS (issue #9819) - TESTFN_UNENCODABLE = TESTFN + "-\u5171\u0141\u2661\u0363\uDC80" - try: - TESTFN_UNENCODABLE.encode(TESTFN_ENCODING) - except UnicodeEncodeError: - pass - else: - print('WARNING: The filename %r CAN be encoded by the filesystem encoding (%s). ' - 'Unicode filename tests may not be effective' - % (TESTFN_UNENCODABLE, TESTFN_ENCODING)) - TESTFN_UNENCODABLE = None -# Mac OS X denies unencodable filenames (invalid utf-8) -elif sys.platform != 'darwin': - try: - # ascii and utf-8 cannot encode the byte 0xff - b'\xff'.decode(TESTFN_ENCODING) - except UnicodeDecodeError: - # 0xff will be encoded using the surrogate character u+DCFF - TESTFN_UNENCODABLE = TESTFN \ - + b'-\xff'.decode(TESTFN_ENCODING, 'surrogateescape') - else: - # File system encoding (eg. ISO-8859-* encodings) can encode - # the byte 0xff. Skip some unicode filename tests. - pass - -# TESTFN_UNDECODABLE is a filename (bytes type) that should *not* be able to be -# decoded from the filesystem encoding (in strict mode). It can be None if we -# cannot generate such filename (ex: the latin1 encoding can decode any byte -# sequence). On UNIX, TESTFN_UNDECODABLE can be decoded by os.fsdecode() thanks -# to the surrogateescape error handler (PEP 383), but not from the filesystem -# encoding in strict mode. -TESTFN_UNDECODABLE = None -for name in ( - # b'\xff' is not decodable by os.fsdecode() with code page 932. Windows - # accepts it to create a file or a directory, or don't accept to enter to - # such directory (when the bytes name is used). So test b'\xe7' first: it is - # not decodable from cp932. - b'\xe7w\xf0', - # undecodable from ASCII, UTF-8 - b'\xff', - # undecodable from iso8859-3, iso8859-6, iso8859-7, cp424, iso8859-8, cp856 - # and cp857 - b'\xae\xd5' - # undecodable from UTF-8 (UNIX and Mac OS X) - b'\xed\xb2\x80', b'\xed\xb4\x80', - # undecodable from shift_jis, cp869, cp874, cp932, cp1250, cp1251, cp1252, - # cp1253, cp1254, cp1255, cp1257, cp1258 - b'\x81\x98', -): - try: - name.decode(TESTFN_ENCODING) - except UnicodeDecodeError: - TESTFN_UNDECODABLE = os.fsencode(TESTFN) + name - break - -if FS_NONASCII: - TESTFN_NONASCII = TESTFN + '-' + FS_NONASCII -else: - TESTFN_NONASCII = None - -# Save the initial cwd -SAVEDCWD = os.getcwd() - # Set by libregrtest/main.py so we can skip tests that are not # useful for PGO PGO = False @@ -869,103 +447,6 @@ PGO = False # PGO task. If this is True, PGO is also True. PGO_EXTENDED = False -@contextlib.contextmanager -def temp_dir(path=None, quiet=False): - """Return a context manager that creates a temporary directory. - - Arguments: - - path: the directory to create temporarily. If omitted or None, - defaults to creating a temporary directory using tempfile.mkdtemp. - - quiet: if False (the default), the context manager raises an exception - on error. Otherwise, if the path is specified and cannot be - created, only a warning is issued. - - """ - import tempfile - dir_created = False - if path is None: - path = tempfile.mkdtemp() - dir_created = True - path = os.path.realpath(path) - else: - try: - os.mkdir(path) - dir_created = True - except OSError as exc: - if not quiet: - raise - warnings.warn(f'tests may fail, unable to create ' - f'temporary directory {path!r}: {exc}', - RuntimeWarning, stacklevel=3) - if dir_created: - pid = os.getpid() - try: - yield path - finally: - # In case the process forks, let only the parent remove the - # directory. The child has a different process id. (bpo-30028) - if dir_created and pid == os.getpid(): - rmtree(path) - -@contextlib.contextmanager -def change_cwd(path, quiet=False): - """Return a context manager that changes the current working directory. - - Arguments: - - path: the directory to use as the temporary current working directory. - - quiet: if False (the default), the context manager raises an exception - on error. Otherwise, it issues only a warning and keeps the current - working directory the same. - - """ - saved_dir = os.getcwd() - try: - os.chdir(os.path.realpath(path)) - except OSError as exc: - if not quiet: - raise - warnings.warn(f'tests may fail, unable to change the current working ' - f'directory to {path!r}: {exc}', - RuntimeWarning, stacklevel=3) - try: - yield os.getcwd() - finally: - os.chdir(saved_dir) - - -@contextlib.contextmanager -def temp_cwd(name='tempcwd', quiet=False): - """ - Context manager that temporarily creates and changes the CWD. - - The function temporarily changes the current working directory - after creating a temporary directory in the current directory with - name *name*. If *name* is None, the temporary directory is - created using tempfile.mkdtemp. - - If *quiet* is False (default) and it is not possible to - create or change the CWD, an error is raised. If *quiet* is True, - only a warning is raised and the original CWD is used. - - """ - with temp_dir(path=name, quiet=quiet) as temp_path: - with change_cwd(temp_path, quiet=quiet) as cwd_dir: - yield cwd_dir - -if hasattr(os, "umask"): - @contextlib.contextmanager - def temp_umask(umask): - """Context manager that temporarily sets the process umask.""" - oldmask = os.umask(umask) - try: - yield - finally: - os.umask(oldmask) - # TEST_HOME_DIR refers to the top level directory of the "test" package # that contains Python's regression test suite TEST_SUPPORT_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -974,6 +455,7 @@ TEST_HOME_DIR = os.path.dirname(TEST_SUPPORT_DIR) # TEST_DATA_DIR is used as a target download location for remote resources TEST_DATA_DIR = os.path.join(TEST_HOME_DIR, "data") + def findfile(filename, subdir=None): """Try to find a file on sys.path or in the test directory. If it is not found the argument passed to the function is returned (this does not @@ -992,10 +474,6 @@ def findfile(filename, subdir=None): if os.path.exists(fn): return fn return filename -def create_empty_file(filename): - """Create an empty file. If the file already exists, truncate it.""" - fd = os.open(filename, os.O_WRONLY | os.O_CREAT | os.O_TRUNC) - os.close(fd) def sortdict(dict): "Like repr(dict), but in sorted order." @@ -1004,19 +482,6 @@ def sortdict(dict): withcommas = ", ".join(reprpairs) return "{%s}" % withcommas -def make_bad_fd(): - """ - Create an invalid file descriptor by opening and closing a file and return - its fd. - """ - file = open(TESTFN, "wb") - try: - return file.fileno() - finally: - file.close() - unlink(TESTFN) - - def check_syntax_error(testcase, statement, errtext='', *, lineno=None, offset=None): with testcase.assertRaisesRegex(SyntaxError, errtext) as cm: compile(statement, '', 'exec') @@ -1028,32 +493,6 @@ def check_syntax_error(testcase, statement, errtext='', *, lineno=None, offset=N if offset is not None: testcase.assertEqual(err.offset, offset) -def check_syntax_warning(testcase, statement, errtext='', *, lineno=1, offset=None): - # Test also that a warning is emitted only once. - with warnings.catch_warnings(record=True) as warns: - warnings.simplefilter('always', SyntaxWarning) - compile(statement, '', 'exec') - testcase.assertEqual(len(warns), 1, warns) - - warn, = warns - testcase.assertTrue(issubclass(warn.category, SyntaxWarning), warn.category) - if errtext: - testcase.assertRegex(str(warn.message), errtext) - testcase.assertEqual(warn.filename, '') - testcase.assertIsNotNone(warn.lineno) - if lineno is not None: - testcase.assertEqual(warn.lineno, lineno) - - # SyntaxWarning should be converted to SyntaxError when raised, - # since the latter contains more information and provides better - # error report. - with warnings.catch_warnings(record=True) as warns: - warnings.simplefilter('error', SyntaxWarning) - check_syntax_error(testcase, statement, errtext, - lineno=lineno, offset=offset) - # No warnings are leaked when a SyntaxError is raised. - testcase.assertEqual(warns, []) - def open_urlresource(url, *args, **kw): import urllib.request, urllib.parse @@ -1109,277 +548,6 @@ def open_urlresource(url, *args, **kw): raise TestFailed('invalid resource %r' % fn) -class WarningsRecorder(object): - """Convenience wrapper for the warnings list returned on - entry to the warnings.catch_warnings() context manager. - """ - def __init__(self, warnings_list): - self._warnings = warnings_list - self._last = 0 - - def __getattr__(self, attr): - if len(self._warnings) > self._last: - return getattr(self._warnings[-1], attr) - elif attr in warnings.WarningMessage._WARNING_DETAILS: - return None - raise AttributeError("%r has no attribute %r" % (self, attr)) - - @property - def warnings(self): - return self._warnings[self._last:] - - def reset(self): - self._last = len(self._warnings) - - -def _filterwarnings(filters, quiet=False): - """Catch the warnings, then check if all the expected - warnings have been raised and re-raise unexpected warnings. - If 'quiet' is True, only re-raise the unexpected warnings. - """ - # Clear the warning registry of the calling module - # in order to re-raise the warnings. - frame = sys._getframe(2) - registry = frame.f_globals.get('__warningregistry__') - if registry: - registry.clear() - with warnings.catch_warnings(record=True) as w: - # Set filter "always" to record all warnings. Because - # test_warnings swap the module, we need to look up in - # the sys.modules dictionary. - sys.modules['warnings'].simplefilter("always") - yield WarningsRecorder(w) - # Filter the recorded warnings - reraise = list(w) - missing = [] - for msg, cat in filters: - seen = False - for w in reraise[:]: - warning = w.message - # Filter out the matching messages - if (re.match(msg, str(warning), re.I) and - issubclass(warning.__class__, cat)): - seen = True - reraise.remove(w) - if not seen and not quiet: - # This filter caught nothing - missing.append((msg, cat.__name__)) - if reraise: - raise AssertionError("unhandled warning %s" % reraise[0]) - if missing: - raise AssertionError("filter (%r, %s) did not catch any warning" % - missing[0]) - - -@contextlib.contextmanager -def check_warnings(*filters, **kwargs): - """Context manager to silence warnings. - - Accept 2-tuples as positional arguments: - ("message regexp", WarningCategory) - - Optional argument: - - if 'quiet' is True, it does not fail if a filter catches nothing - (default True without argument, - default False if some filters are defined) - - Without argument, it defaults to: - check_warnings(("", Warning), quiet=True) - """ - quiet = kwargs.get('quiet') - if not filters: - filters = (("", Warning),) - # Preserve backward compatibility - if quiet is None: - quiet = True - return _filterwarnings(filters, quiet) - - -@contextlib.contextmanager -def check_no_warnings(testcase, message='', category=Warning, force_gc=False): - """Context manager to check that no warnings are emitted. - - This context manager enables a given warning within its scope - and checks that no warnings are emitted even with that warning - enabled. - - If force_gc is True, a garbage collection is attempted before checking - for warnings. This may help to catch warnings emitted when objects - are deleted, such as ResourceWarning. - - Other keyword arguments are passed to warnings.filterwarnings(). - """ - with warnings.catch_warnings(record=True) as warns: - warnings.filterwarnings('always', - message=message, - category=category) - yield - if force_gc: - gc_collect() - testcase.assertEqual(warns, []) - - -@contextlib.contextmanager -def check_no_resource_warning(testcase): - """Context manager to check that no ResourceWarning is emitted. - - Usage: - - with check_no_resource_warning(self): - f = open(...) - ... - del f - - You must remove the object which may emit ResourceWarning before - the end of the context manager. - """ - with check_no_warnings(testcase, category=ResourceWarning, force_gc=True): - yield - - -class CleanImport(object): - """Context manager to force import to return a new module reference. - - This is useful for testing module-level behaviours, such as - the emission of a DeprecationWarning on import. - - Use like this: - - with CleanImport("foo"): - importlib.import_module("foo") # new reference - """ - - def __init__(self, *module_names): - self.original_modules = sys.modules.copy() - for module_name in module_names: - if module_name in sys.modules: - module = sys.modules[module_name] - # It is possible that module_name is just an alias for - # another module (e.g. stub for modules renamed in 3.x). - # In that case, we also need delete the real module to clear - # the import cache. - if module.__name__ != module_name: - del sys.modules[module.__name__] - del sys.modules[module_name] - - def __enter__(self): - return self - - def __exit__(self, *ignore_exc): - sys.modules.update(self.original_modules) - - -class EnvironmentVarGuard(collections.abc.MutableMapping): - - """Class to help protect the environment variable properly. Can be used as - a context manager.""" - - def __init__(self): - self._environ = os.environ - self._changed = {} - - def __getitem__(self, envvar): - return self._environ[envvar] - - def __setitem__(self, envvar, value): - # Remember the initial value on the first access - if envvar not in self._changed: - self._changed[envvar] = self._environ.get(envvar) - self._environ[envvar] = value - - def __delitem__(self, envvar): - # Remember the initial value on the first access - if envvar not in self._changed: - self._changed[envvar] = self._environ.get(envvar) - if envvar in self._environ: - del self._environ[envvar] - - def keys(self): - return self._environ.keys() - - def __iter__(self): - return iter(self._environ) - - def __len__(self): - return len(self._environ) - - def set(self, envvar, value): - self[envvar] = value - - def unset(self, envvar): - del self[envvar] - - def __enter__(self): - return self - - def __exit__(self, *ignore_exc): - for (k, v) in self._changed.items(): - if v is None: - if k in self._environ: - del self._environ[k] - else: - self._environ[k] = v - os.environ = self._environ - - -class DirsOnSysPath(object): - """Context manager to temporarily add directories to sys.path. - - This makes a copy of sys.path, appends any directories given - as positional arguments, then reverts sys.path to the copied - settings when the context ends. - - Note that *all* sys.path modifications in the body of the - context manager, including replacement of the object, - will be reverted at the end of the block. - """ - - def __init__(self, *paths): - self.original_value = sys.path[:] - self.original_object = sys.path - sys.path.extend(paths) - - def __enter__(self): - return self - - def __exit__(self, *ignore_exc): - sys.path = self.original_object - sys.path[:] = self.original_value - - -class TransientResource(object): - - """Raise ResourceDenied if an exception is raised while the context manager - is in effect that matches the specified exception and attributes.""" - - def __init__(self, exc, **kwargs): - self.exc = exc - self.attrs = kwargs - - def __enter__(self): - return self - - def __exit__(self, type_=None, value=None, traceback=None): - """If type_ is a subclass of self.exc and value has attributes matching - self.attrs, raise ResourceDenied. Otherwise let the exception - propagate (if any).""" - if type_ is not None and issubclass(self.exc, type_): - for attr, attr_value in self.attrs.items(): - if not hasattr(value, attr): - break - if getattr(value, attr) != attr_value: - break - else: - raise ResourceDenied("an optional resource is not available") - -# Context managers that raise ResourceDenied when various issues -# with the Internet connection manifest themselves as exceptions. -# XXX deprecate these and use transient_internet() instead -time_out = TransientResource(OSError, errno=errno.ETIMEDOUT) -socket_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET) -ioerror_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET) - - @contextlib.contextmanager def captured_output(stream_name): """Return a context manager used by captured_stdout/stdin/stderr @@ -1470,9 +638,11 @@ if hasattr(sys, "getobjects"): _vheader = _header + 'n' def calcobjsize(fmt): + import struct return struct.calcsize(_header + fmt + _align) def calcvobjsize(fmt): + import struct return struct.calcsize(_vheader + fmt + _align) @@ -1603,6 +773,7 @@ class _MemoryWatchdog: self.started = False def start(self): + import warnings try: f = open(self.procfile, 'r') except OSError as e: @@ -1611,6 +782,7 @@ class _MemoryWatchdog: sys.stderr.flush() return + import subprocess with f: watchdog_script = findfile("memory_watchdog.py") self.mem_watchdog = subprocess.Popen([sys.executable, watchdog_script], @@ -1744,7 +916,7 @@ def check_impl_detail(**guards): if check_impl_detail(cpython=False): # everywhere except on CPython """ guards, default = _parse_guards(guards) - return guards.get(platform.python_implementation().lower(), default) + return guards.get(sys.implementation.name, default) def no_tracing(func): @@ -1878,6 +1050,7 @@ def _compile_match_function(patterns): # The test.bisect_cmd utility only uses such full test identifiers. func = set(patterns).__contains__ else: + import fnmatch regex = '|'.join(map(fnmatch.translate, patterns)) # The search *is* case sensitive on purpose: # don't use flags=re.IGNORECASE @@ -1972,139 +1145,15 @@ def print_warning(msg): for line in msg.splitlines(): print(f"Warning -- {line}", file=sys.__stderr__, flush=True) -def modules_setup(): - return sys.modules.copy(), - -def modules_cleanup(oldmodules): - # Encoders/decoders are registered permanently within the internal - # codec cache. If we destroy the corresponding modules their - # globals will be set to None which will trip up the cached functions. - encodings = [(k, v) for k, v in sys.modules.items() - if k.startswith('encodings.')] - sys.modules.clear() - sys.modules.update(encodings) - # XXX: This kind of problem can affect more than just encodings. In particular - # extension modules (such as _ssl) don't cope with reloading properly. - # Really, test modules should be cleaning out the test specific modules they - # know they added (ala test_runpy) rather than relying on this function (as - # test_importhooks and test_pkg do currently). - # Implicitly imported *real* modules should be left alone (see issue 10556). - sys.modules.update(oldmodules) - -#======================================================================= -# Threading support to prevent reporting refleaks when running regrtest.py -R # Flag used by saved_test_environment of test.libregrtest.save_env, # to check if a test modified the environment. The flag should be set to False # before running a new test. # -# For example, threading_cleanup() sets the flag is the function fails +# For example, threading_helper.threading_cleanup() sets the flag is the function fails # to cleanup threads. environment_altered = False -# NOTE: we use thread._count() rather than threading.enumerate() (or the -# moral equivalent thereof) because a threading.Thread object is still alive -# until its __bootstrap() method has returned, even after it has been -# unregistered from the threading module. -# thread._count(), on the other hand, only gets decremented *after* the -# __bootstrap() method has returned, which gives us reliable reference counts -# at the end of a test run. - -def threading_setup(): - return _thread._count(), threading._dangling.copy() - -def threading_cleanup(*original_values): - global environment_altered - - _MAX_COUNT = 100 - - for count in range(_MAX_COUNT): - values = _thread._count(), threading._dangling - if values == original_values: - break - - if not count: - # Display a warning at the first iteration - environment_altered = True - dangling_threads = values[1] - print_warning(f"threading_cleanup() failed to cleanup " - f"{values[0] - original_values[0]} threads " - f"(count: {values[0]}, " - f"dangling: {len(dangling_threads)})") - for thread in dangling_threads: - print_warning(f"Dangling thread: {thread!r}") - - # Don't hold references to threads - dangling_threads = None - values = None - - time.sleep(0.01) - gc_collect() - - -def reap_threads(func): - """Use this function when threads are being used. This will - ensure that the threads are cleaned up even when the test fails. - """ - @functools.wraps(func) - def decorator(*args): - key = threading_setup() - try: - return func(*args) - finally: - threading_cleanup(*key) - return decorator - - -@contextlib.contextmanager -def wait_threads_exit(timeout=None): - """ - bpo-31234: Context manager to wait until all threads created in the with - statement exit. - - Use _thread.count() to check if threads exited. Indirectly, wait until - threads exit the internal t_bootstrap() C function of the _thread module. - - threading_setup() and threading_cleanup() are designed to emit a warning - if a test leaves running threads in the background. This context manager - is designed to cleanup threads started by the _thread.start_new_thread() - which doesn't allow to wait for thread exit, whereas thread.Thread has a - join() method. - """ - if timeout is None: - timeout = SHORT_TIMEOUT - old_count = _thread._count() - try: - yield - finally: - start_time = time.monotonic() - deadline = start_time + timeout - while True: - count = _thread._count() - if count <= old_count: - break - if time.monotonic() > deadline: - dt = time.monotonic() - start_time - msg = (f"wait_threads() failed to cleanup {count - old_count} " - f"threads after {dt:.1f} seconds " - f"(count: {count}, old count: {old_count})") - raise AssertionError(msg) - time.sleep(0.010) - gc_collect() - - -def join_thread(thread, timeout=None): - """Join a thread. Raise an AssertionError if the thread is still alive - after timeout seconds. - """ - if timeout is None: - timeout = SHORT_TIMEOUT - thread.join(timeout) - if thread.is_alive(): - msg = f"failed to join the thread in {timeout:.1f} seconds" - raise AssertionError(msg) - - def reap_children(): """Use this function at the end of test_main() whenever sub-processes are started. This will help ensure that no extra children (zombies) @@ -2133,43 +1182,6 @@ def reap_children(): environment_altered = True -@contextlib.contextmanager -def start_threads(threads, unlock=None): - import faulthandler - threads = list(threads) - started = [] - try: - try: - for t in threads: - t.start() - started.append(t) - except: - if verbose: - print("Can't start %d threads, only %d threads started" % - (len(threads), len(started))) - raise - yield - finally: - try: - if unlock: - unlock() - endtime = starttime = time.monotonic() - for timeout in range(1, 16): - endtime += 60 - for t in started: - t.join(max(endtime - time.monotonic(), 0.01)) - started = [t for t in started if t.is_alive()] - if not started: - break - if verbose: - print('Unable to join %d threads during a period of ' - '%d minutes' % (len(started), timeout)) - finally: - started = [t for t in started if t.is_alive()] - if started: - faulthandler.dump_traceback(sys.stdout) - raise AssertionError('Unable to join %d threads' % len(started)) - @contextlib.contextmanager def swap_attr(obj, attr, new_val): """Temporary swap out an attribute with a new object. @@ -2235,11 +1247,13 @@ def swap_item(obj, item, new_val): def args_from_interpreter_flags(): """Return a list of command-line arguments reproducing the current settings in sys.flags and sys.warnoptions.""" + import subprocess return subprocess._args_from_interpreter_flags() def optim_args_from_interpreter_flags(): """Return a list of command-line arguments reproducing the current optimization settings in sys.flags.""" + import subprocess return subprocess._optim_args_from_interpreter_flags() @@ -2277,28 +1291,6 @@ class Matcher(object): return result -_can_symlink = None -def can_symlink(): - global _can_symlink - if _can_symlink is not None: - return _can_symlink - symlink_path = TESTFN + "can_symlink" - try: - os.symlink(TESTFN, symlink_path) - can = True - except (OSError, NotImplementedError, AttributeError): - can = False - else: - os.remove(symlink_path) - _can_symlink = can - return can - -def skip_unless_symlink(test): - """Skip decorator for tests that require functional symlink""" - ok = can_symlink() - msg = "Requires functional symlink implementation" - return test if ok else unittest.skip(msg)(test) - _buggy_ucrt = None def skip_if_buggy_ucrt_strfptime(test): """ @@ -2338,6 +1330,7 @@ class PythonSymlink: if sys.platform == "win32": def _platform_specific(self): + import glob import _winapi if os.path.lexists(self.real) and not os.path.exists(self.real): @@ -2352,7 +1345,7 @@ class PythonSymlink: dll, os.path.join(dest_dir, os.path.basename(dll)) )) - for runtime in glob.glob(os.path.join(src_dir, "vcruntime*.dll")): + for runtime in glob.glob(os.path.join(glob.escape(src_dir), "vcruntime*.dll")): self._also_link.append(( runtime, os.path.join(dest_dir, os.path.basename(runtime)) @@ -2380,6 +1373,7 @@ class PythonSymlink: print("failed to clean up {}: {}".format(link, ex)) def _call(self, python, args, env, returncode): + import subprocess cmd = [python, *args] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) @@ -2399,44 +1393,6 @@ class PythonSymlink: return self._call(self.link, args, self._env, returncode) -_can_xattr = None -def can_xattr(): - import tempfile - global _can_xattr - if _can_xattr is not None: - return _can_xattr - if not hasattr(os, "setxattr"): - can = False - else: - tmp_dir = tempfile.mkdtemp() - tmp_fp, tmp_name = tempfile.mkstemp(dir=tmp_dir) - try: - with open(TESTFN, "wb") as fp: - try: - # TESTFN & tempfile may use different file systems with - # different capabilities - os.setxattr(tmp_fp, b"user.test", b"") - os.setxattr(tmp_name, b"trusted.foo", b"42") - os.setxattr(fp.fileno(), b"user.test", b"") - # Kernels < 2.6.39 don't respect setxattr flags. - kernel_version = platform.release() - m = re.match(r"2.6.(\d{1,2})", kernel_version) - can = m is None or int(m.group(1)) >= 39 - except OSError: - can = False - finally: - unlink(TESTFN) - unlink(tmp_name) - rmdir(tmp_dir) - _can_xattr = can - return can - -def skip_unless_xattr(test): - """Skip decorator for tests that require functional extended attributes""" - ok = can_xattr() - msg = "no non-broken extended attribute support" - return test if ok else unittest.skip(msg)(test) - def skip_if_pgo_task(test): """Skip decorator for tests not run in (non-extended) PGO task""" ok = not PGO or PGO_EXTENDED @@ -2444,20 +1400,6 @@ def skip_if_pgo_task(test): return test if ok else unittest.skip(msg)(test) -def fs_is_case_insensitive(directory): - """Detects if the file system for the specified directory is case-insensitive.""" - import tempfile - with tempfile.NamedTemporaryFile(dir=directory) as base: - base_path = base.name - case_path = base_path.upper() - if case_path == base_path: - case_path = base_path.lower() - try: - return os.path.samefile(base_path, case_path) - except FileNotFoundError: - return False - - def detect_api_mismatch(ref_api, other_api, *, ignore=()): """Returns the set of items in ref_api not in other_api, except for a defined list of items to be ignored in this check. @@ -2532,6 +1474,27 @@ def check__all__(test_case, module, name_of_module=None, extra=(), test_case.assertCountEqual(module.__all__, expected) +def suppress_msvcrt_asserts(verbose=False): + try: + import msvcrt + except ImportError: + return + + msvcrt.SetErrorMode(msvcrt.SEM_FAILCRITICALERRORS + | msvcrt.SEM_NOALIGNMENTFAULTEXCEPT + | msvcrt.SEM_NOGPFAULTERRORBOX + | msvcrt.SEM_NOOPENFILEERRORBOX) + + # CrtSetReportMode() is only available in debug build + if hasattr(msvcrt, 'CrtSetReportMode'): + for m in [msvcrt.CRT_WARN, msvcrt.CRT_ERROR, msvcrt.CRT_ASSERT]: + if verbose: + msvcrt.CrtSetReportMode(m, msvcrt.CRTDBG_MODE_FILE) + msvcrt.CrtSetReportFile(m, msvcrt.CRTDBG_FILE_STDERR) + else: + msvcrt.CrtSetReportMode(m, 0) + + class SuppressCrashReport: """Try to prevent a crash report from popping up. @@ -2543,30 +1506,25 @@ class SuppressCrashReport: def __enter__(self): """On Windows, disable Windows Error Reporting dialogs using - SetErrorMode. + SetErrorMode() and CrtSetReportMode(). On UNIX, try to save the previous core file size limit, then set soft limit to 0. """ if sys.platform.startswith('win'): # see http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx - # GetErrorMode is not available on Windows XP and Windows Server 2003, - # but SetErrorMode returns the previous value, so we can use that - import ctypes - self._k32 = ctypes.windll.kernel32 - SEM_NOGPFAULTERRORBOX = 0x02 - self.old_value = self._k32.SetErrorMode(SEM_NOGPFAULTERRORBOX) - self._k32.SetErrorMode(self.old_value | SEM_NOGPFAULTERRORBOX) - - # Suppress assert dialogs in debug builds - # (see http://bugs.python.org/issue23314) try: import msvcrt - msvcrt.CrtSetReportMode - except (AttributeError, ImportError): - # no msvcrt or a release build - pass - else: + except ImportError: + return + + self.old_value = msvcrt.GetErrorMode() + + msvcrt.SetErrorMode(self.old_value | msvcrt.SEM_NOGPFAULTERRORBOX) + + # bpo-23314: Suppress assert dialogs in debug builds. + # CrtSetReportMode() is only available in debug build. + if hasattr(msvcrt, 'CrtSetReportMode'): self.old_modes = {} for report_type in [msvcrt.CRT_WARN, msvcrt.CRT_ERROR, @@ -2592,6 +1550,7 @@ class SuppressCrashReport: pass if sys.platform == 'darwin': + import subprocess # Check if the 'Crash Reporter' on OSX was configured # in 'Developer' mode and warn that it will get triggered # when it is. @@ -2617,10 +1576,10 @@ class SuppressCrashReport: return if sys.platform.startswith('win'): - self._k32.SetErrorMode(self.old_value) + import msvcrt + msvcrt.SetErrorMode(self.old_value) if self.old_modes: - import msvcrt for report_type, (old_mode, old_file) in self.old_modes.items(): msvcrt.CrtSetReportMode(report_type, old_mode) msvcrt.CrtSetReportFile(report_type, old_file) @@ -2738,6 +1697,7 @@ def setswitchinterval(interval): if is_android and interval < minimum_interval: global _is_android_emulator if _is_android_emulator is None: + import subprocess _is_android_emulator = (subprocess.check_output( ['getprop', 'ro.kernel.qemu']).strip() == b'1') if _is_android_emulator: @@ -2763,65 +1723,6 @@ def disable_faulthandler(): faulthandler.enable(file=fd, all_threads=True) -def fd_count(): - """Count the number of open file descriptors. - """ - if sys.platform.startswith(('linux', 'freebsd')): - try: - names = os.listdir("/proc/self/fd") - # Subtract one because listdir() internally opens a file - # descriptor to list the content of the /proc/self/fd/ directory. - return len(names) - 1 - except FileNotFoundError: - pass - - MAXFD = 256 - if hasattr(os, 'sysconf'): - try: - MAXFD = os.sysconf("SC_OPEN_MAX") - except OSError: - pass - - old_modes = None - if sys.platform == 'win32': - # bpo-25306, bpo-31009: Call CrtSetReportMode() to not kill the process - # on invalid file descriptor if Python is compiled in debug mode - try: - import msvcrt - msvcrt.CrtSetReportMode - except (AttributeError, ImportError): - # no msvcrt or a release build - pass - else: - old_modes = {} - for report_type in (msvcrt.CRT_WARN, - msvcrt.CRT_ERROR, - msvcrt.CRT_ASSERT): - old_modes[report_type] = msvcrt.CrtSetReportMode(report_type, 0) - - try: - count = 0 - for fd in range(MAXFD): - try: - # Prefer dup() over fstat(). fstat() can require input/output - # whereas dup() doesn't. - fd2 = os.dup(fd) - except OSError as e: - if e.errno != errno.EBADF: - raise - else: - os.close(fd2) - count += 1 - finally: - if old_modes is not None: - for report_type in (msvcrt.CRT_WARN, - msvcrt.CRT_ERROR, - msvcrt.CRT_ASSERT): - msvcrt.CrtSetReportMode(report_type, old_modes[report_type]) - - return count - - class SaveSignals: """ Save and restore signal handlers. @@ -2866,24 +1767,6 @@ def with_pymalloc(): return _testcapi.WITH_PYMALLOC -class FakePath: - """Simple implementing of the path protocol. - """ - def __init__(self, path): - self.path = path - - def __repr__(self): - return f'' - - def __fspath__(self): - if (isinstance(self.path, BaseException) or - isinstance(self.path, type) and - issubclass(self.path, BaseException)): - raise self.path - else: - return self.path - - class _ALWAYS_EQ: """ Object that is equal to anything. @@ -3023,63 +1906,6 @@ class catch_unraisable_exception: del self.unraisable -class catch_threading_exception: - """ - Context manager catching threading.Thread exception using - threading.excepthook. - - Attributes set when an exception is catched: - - * exc_type - * exc_value - * exc_traceback - * thread - - See threading.excepthook() documentation for these attributes. - - These attributes are deleted at the context manager exit. - - Usage: - - with support.catch_threading_exception() as cm: - # code spawning a thread which raises an exception - ... - - # check the thread exception, use cm attributes: - # exc_type, exc_value, exc_traceback, thread - ... - - # exc_type, exc_value, exc_traceback, thread attributes of cm no longer - # exists at this point - # (to avoid reference cycles) - """ - - def __init__(self): - self.exc_type = None - self.exc_value = None - self.exc_traceback = None - self.thread = None - self._old_hook = None - - def _hook(self, args): - self.exc_type = args.exc_type - self.exc_value = args.exc_value - self.exc_traceback = args.exc_traceback - self.thread = args.thread - - def __enter__(self): - self._old_hook = threading.excepthook - threading.excepthook = self._hook - return self - - def __exit__(self, *exc_info): - threading.excepthook = self._old_hook - del self.exc_type - del self.exc_value - del self.exc_traceback - del self.thread - - def wait_process(pid, *, exitcode, timeout=None): """ Wait until process pid completes and check that the process exit code is @@ -3097,7 +1923,6 @@ def wait_process(pid, *, exitcode, timeout=None): if timeout is None: timeout = SHORT_TIMEOUT t0 = time.monotonic() - deadline = t0 + timeout sleep = 0.001 max_sleep = 0.1 while True: @@ -3133,12 +1958,25 @@ def wait_process(pid, *, exitcode, timeout=None): if pid2 != pid: raise AssertionError(f"pid {pid2} != pid {pid}") +def skip_if_broken_multiprocessing_synchronize(): + """ + Skip tests if the multiprocessing.synchronize module is missing, if there + is no available semaphore implementation, or if creating a lock raises an + OSError (on Linux only). + """ -def use_old_parser(): - import _testinternalcapi - config = _testinternalcapi.get_configs() - return (config['config']['_use_peg_parser'] == 0) + # Skip tests if the _multiprocessing extension is missing. + import_module('_multiprocessing') + # Skip tests if there is no available semaphore implementation: + # multiprocessing.synchronize requires _multiprocessing.SemLock. + synchronize = import_module('multiprocessing.synchronize') -def skip_if_new_parser(msg): - return unittest.skipIf(not use_old_parser(), msg) + if sys.platform == "linux": + try: + # bpo-38377: On Linux, creating a semaphore fails with OSError + # if the current user does not have the permission to create + # a file in /dev/shm/ directory. + synchronize.Lock(ctx=None) + except OSError as exc: + raise unittest.SkipTest(f"broken multiprocessing SemLock: {exc!r}") diff --git a/Lib/test/support/import_helper.py b/Lib/test/support/import_helper.py new file mode 100644 index 00000000000..5d1e9406879 --- /dev/null +++ b/Lib/test/support/import_helper.py @@ -0,0 +1,238 @@ +import contextlib +import importlib +import importlib.util +import os +import sys +import unittest +import warnings + +from .os_helper import unlink + + +@contextlib.contextmanager +def _ignore_deprecated_imports(ignore=True): + """Context manager to suppress package and module deprecation + warnings when importing them. + + If ignore is False, this context manager has no effect. + """ + if ignore: + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", ".+ (module|package)", + DeprecationWarning) + yield + else: + yield + + +def unload(name): + try: + del sys.modules[name] + except KeyError: + pass + + +def forget(modname): + """'Forget' a module was ever imported. + + This removes the module from sys.modules and deletes any PEP 3147/488 or + legacy .pyc files. + """ + unload(modname) + for dirname in sys.path: + source = os.path.join(dirname, modname + '.py') + # It doesn't matter if they exist or not, unlink all possible + # combinations of PEP 3147/488 and legacy pyc files. + unlink(source + 'c') + for opt in ('', 1, 2): + unlink(importlib.util.cache_from_source(source, optimization=opt)) + + +def make_legacy_pyc(source): + """Move a PEP 3147/488 pyc file to its legacy pyc location. + + :param source: The file system path to the source file. The source file + does not need to exist, however the PEP 3147/488 pyc file must exist. + :return: The file system path to the legacy pyc file. + """ + pyc_file = importlib.util.cache_from_source(source) + up_one = os.path.dirname(os.path.abspath(source)) + legacy_pyc = os.path.join(up_one, source + 'c') + os.rename(pyc_file, legacy_pyc) + return legacy_pyc + + +def import_module(name, deprecated=False, *, required_on=()): + """Import and return the module to be tested, raising SkipTest if + it is not available. + + If deprecated is True, any module or package deprecation messages + will be suppressed. If a module is required on a platform but optional for + others, set required_on to an iterable of platform prefixes which will be + compared against sys.platform. + """ + with _ignore_deprecated_imports(deprecated): + try: + return importlib.import_module(name) + except ImportError as msg: + if sys.platform.startswith(tuple(required_on)): + raise + raise unittest.SkipTest(str(msg)) + + +def _save_and_remove_module(name, orig_modules): + """Helper function to save and remove a module from sys.modules + + Raise ImportError if the module can't be imported. + """ + # try to import the module and raise an error if it can't be imported + if name not in sys.modules: + __import__(name) + del sys.modules[name] + for modname in list(sys.modules): + if modname == name or modname.startswith(name + '.'): + orig_modules[modname] = sys.modules[modname] + del sys.modules[modname] + + +def _save_and_block_module(name, orig_modules): + """Helper function to save and block a module in sys.modules + + Return True if the module was in sys.modules, False otherwise. + """ + saved = True + try: + orig_modules[name] = sys.modules[name] + except KeyError: + saved = False + sys.modules[name] = None + return saved + + +def import_fresh_module(name, fresh=(), blocked=(), deprecated=False): + """Import and return a module, deliberately bypassing sys.modules. + + This function imports and returns a fresh copy of the named Python module + by removing the named module from sys.modules before doing the import. + Note that unlike reload, the original module is not affected by + this operation. + + *fresh* is an iterable of additional module names that are also removed + from the sys.modules cache before doing the import. + + *blocked* is an iterable of module names that are replaced with None + in the module cache during the import to ensure that attempts to import + them raise ImportError. + + The named module and any modules named in the *fresh* and *blocked* + parameters are saved before starting the import and then reinserted into + sys.modules when the fresh import is complete. + + Module and package deprecation messages are suppressed during this import + if *deprecated* is True. + + This function will raise ImportError if the named module cannot be + imported. + """ + # NOTE: test_heapq, test_json and test_warnings include extra sanity checks + # to make sure that this utility function is working as expected + with _ignore_deprecated_imports(deprecated): + # Keep track of modules saved for later restoration as well + # as those which just need a blocking entry removed + orig_modules = {} + names_to_remove = [] + _save_and_remove_module(name, orig_modules) + try: + for fresh_name in fresh: + _save_and_remove_module(fresh_name, orig_modules) + for blocked_name in blocked: + if not _save_and_block_module(blocked_name, orig_modules): + names_to_remove.append(blocked_name) + fresh_module = importlib.import_module(name) + except ImportError: + fresh_module = None + finally: + for orig_name, module in orig_modules.items(): + sys.modules[orig_name] = module + for name_to_remove in names_to_remove: + del sys.modules[name_to_remove] + return fresh_module + + +class CleanImport(object): + """Context manager to force import to return a new module reference. + + This is useful for testing module-level behaviours, such as + the emission of a DeprecationWarning on import. + + Use like this: + + with CleanImport("foo"): + importlib.import_module("foo") # new reference + """ + + def __init__(self, *module_names): + self.original_modules = sys.modules.copy() + for module_name in module_names: + if module_name in sys.modules: + module = sys.modules[module_name] + # It is possible that module_name is just an alias for + # another module (e.g. stub for modules renamed in 3.x). + # In that case, we also need delete the real module to clear + # the import cache. + if module.__name__ != module_name: + del sys.modules[module.__name__] + del sys.modules[module_name] + + def __enter__(self): + return self + + def __exit__(self, *ignore_exc): + sys.modules.update(self.original_modules) + + +class DirsOnSysPath(object): + """Context manager to temporarily add directories to sys.path. + + This makes a copy of sys.path, appends any directories given + as positional arguments, then reverts sys.path to the copied + settings when the context ends. + + Note that *all* sys.path modifications in the body of the + context manager, including replacement of the object, + will be reverted at the end of the block. + """ + + def __init__(self, *paths): + self.original_value = sys.path[:] + self.original_object = sys.path + sys.path.extend(paths) + + def __enter__(self): + return self + + def __exit__(self, *ignore_exc): + sys.path = self.original_object + sys.path[:] = self.original_value + + +def modules_setup(): + return sys.modules.copy(), + + +def modules_cleanup(oldmodules): + # Encoders/decoders are registered permanently within the internal + # codec cache. If we destroy the corresponding modules their + # globals will be set to None which will trip up the cached functions. + encodings = [(k, v) for k, v in sys.modules.items() + if k.startswith('encodings.')] + sys.modules.clear() + sys.modules.update(encodings) + # XXX: This kind of problem can affect more than just encodings. + # In particular extension modules (such as _ssl) don't cope + # with reloading properly. Really, test modules should be cleaning + # out the test specific modules they know they added (ala test_runpy) + # rather than relying on this function (as test_importhooks and test_pkg + # do currently). Implicitly imported *real* modules should be left alone + # (see issue 10556). + sys.modules.update(oldmodules) diff --git a/Lib/test/support/interpreters.py b/Lib/test/support/interpreters.py index ef9dcafb2a3..2935708f9df 100644 --- a/Lib/test/support/interpreters.py +++ b/Lib/test/support/interpreters.py @@ -1,5 +1,6 @@ """Subinterpreters High Level Module.""" +import time import _xxsubinterpreters as _interpreters # aliases: @@ -19,47 +20,51 @@ __all__ = [ def create(*, isolated=True): - """ - Initialize a new (idle) Python interpreter. - """ + """Return a new (idle) Python interpreter.""" id = _interpreters.create(isolated=isolated) return Interpreter(id, isolated=isolated) def list_all(): - """ - Get all existing interpreters. - """ - return [Interpreter(id) for id in - _interpreters.list_all()] + """Return all existing interpreters.""" + return [Interpreter(id) for id in _interpreters.list_all()] def get_current(): - """ - Get the currently running interpreter. - """ + """Return the currently running interpreter.""" id = _interpreters.get_current() return Interpreter(id) def get_main(): - """ - Get the main interpreter. - """ + """Return the main interpreter.""" id = _interpreters.get_main() return Interpreter(id) class Interpreter: - """ - The Interpreter object represents - a single interpreter. - """ + """A single Python interpreter.""" def __init__(self, id, *, isolated=None): + if not isinstance(id, (int, _interpreters.InterpreterID)): + raise TypeError(f'id must be an int, got {id!r}') self._id = id self._isolated = isolated + def __repr__(self): + data = dict(id=int(self._id), isolated=self._isolated) + kwargs = (f'{k}={v!r}' for k, v in data.items()) + return f'{type(self).__name__}({", ".join(kwargs)})' + + def __hash__(self): + return hash(self._id) + + def __eq__(self, other): + if not isinstance(other, Interpreter): + return NotImplemented + else: + return other._id == self._id + @property def id(self): return self._id @@ -67,84 +72,98 @@ class Interpreter: @property def isolated(self): if self._isolated is None: + # XXX The low-level function has not been added yet. + # See bpo-.... self._isolated = _interpreters.is_isolated(self._id) return self._isolated def is_running(self): - """ - Return whether or not the identified - interpreter is running. - """ + """Return whether or not the identified interpreter is running.""" return _interpreters.is_running(self._id) def close(self): - """ - Finalize and destroy the interpreter. + """Finalize and destroy the interpreter. - Attempting to destroy the current - interpreter results in a RuntimeError. + Attempting to destroy the current interpreter results + in a RuntimeError. """ return _interpreters.destroy(self._id) def run(self, src_str, /, *, channels=None): - """ - Run the given source code in the interpreter. + """Run the given source code in the interpreter. + This blocks the current Python thread until done. """ - _interpreters.run_string(self._id, src_str) + _interpreters.run_string(self._id, src_str, channels) def create_channel(): - """ - Create a new channel for passing data between - interpreters. - """ + """Return (recv, send) for a new cross-interpreter channel. + The channel may be used to pass data safely between interpreters. + """ cid = _interpreters.channel_create() - return (RecvChannel(cid), SendChannel(cid)) + recv, send = RecvChannel(cid), SendChannel(cid) + return recv, send def list_all_channels(): - """ - Get all open channels. - """ + """Return a list of (recv, send) for all open channels.""" return [(RecvChannel(cid), SendChannel(cid)) for cid in _interpreters.channel_list_all()] +class _ChannelEnd: + """The base class for RecvChannel and SendChannel.""" + + def __init__(self, id): + if not isinstance(id, (int, _interpreters.ChannelID)): + raise TypeError(f'id must be an int, got {id!r}') + self._id = id + + def __repr__(self): + return f'{type(self).__name__}(id={int(self._id)})' + + def __hash__(self): + return hash(self._id) + + def __eq__(self, other): + if isinstance(self, RecvChannel): + if not isinstance(other, RecvChannel): + return NotImplemented + elif not isinstance(other, SendChannel): + return NotImplemented + return other._id == self._id + + @property + def id(self): + return self._id + + _NOT_SET = object() -class RecvChannel: - """ - The RecvChannel object represents - a recieving channel. - """ +class RecvChannel(_ChannelEnd): + """The receiving end of a cross-interpreter channel.""" - def __init__(self, id): - self._id = id + def recv(self, *, _sentinel=object(), _delay=10 / 1000): # 10 milliseconds + """Return the next object from the channel. - def recv(self, *, _delay=10 / 1000): # 10 milliseconds + This blocks until an object has been sent, if none have been + sent already. """ - Get the next object from the channel, - and wait if none have been sent. - Associate the interpreter with the channel. - """ - import time - sentinel = object() - obj = _interpreters.channel_recv(self._id, sentinel) - while obj is sentinel: + obj = _interpreters.channel_recv(self._id, _sentinel) + while obj is _sentinel: time.sleep(_delay) - obj = _interpreters.channel_recv(self._id, sentinel) + obj = _interpreters.channel_recv(self._id, _sentinel) return obj def recv_nowait(self, default=_NOT_SET): - """ - Like recv(), but return the default - instead of waiting. + """Return the next object from the channel. - This function is blocked by a missing low-level - implementation of channel_recv_wait(). + If none have been sent then return the default if one + is provided or fail with ChannelEmptyError. Otherwise this + is the same as recv(). """ if default is _NOT_SET: return _interpreters.channel_recv(self._id) @@ -152,32 +171,27 @@ class RecvChannel: return _interpreters.channel_recv(self._id, default) -class SendChannel: - """ - The SendChannel object represents - a sending channel. - """ - - def __init__(self, id): - self._id = id +class SendChannel(_ChannelEnd): + """The sending end of a cross-interpreter channel.""" def send(self, obj): + """Send the object (i.e. its data) to the channel's receiving end. + + This blocks until the object is received. """ - Send the object (i.e. its data) to the receiving - end of the channel and wait. Associate the interpreter - with the channel. - """ - import time _interpreters.channel_send(self._id, obj) + # XXX We are missing a low-level channel_send_wait(). + # See bpo-32604 and gh-19829. + # Until that shows up we fake it: time.sleep(2) def send_nowait(self, obj): - """ - Like send(), but return False if not received. + """Send the object to the channel's receiving end. - This function is blocked by a missing low-level - implementation of channel_send_wait(). + If the object is immediately received then return True + (else False). Otherwise this is the same as send(). """ - - _interpreters.channel_send(self._id, obj) - return False + # XXX Note that at the moment channel_send() only ever returns + # None. This should be fixed when channel_send_wait() is added. + # See bpo-32604 and gh-19829. + return _interpreters.channel_send(self._id, obj) diff --git a/Lib/test/support/interpreters.rst b/Lib/test/support/interpreters.rst deleted file mode 100644 index 37a60b1072a..00000000000 --- a/Lib/test/support/interpreters.rst +++ /dev/null @@ -1,145 +0,0 @@ -High-level implementation of Subinterpreters -============================================ - -**Source code:** :source:`Lib/test/support/_interpreters.py` - --------------- - -This module provides high-level tools for working with sub-interpreters, -such as creating them, running code in them, or sending data between them. -It is a wrapper around the low-level ``__xxsubinterpreters`` module. - -.. versionchanged:: added in 3.9 - -Interpreter Objects -------------------- - -The ``Interpreter`` object represents a single interpreter. - -.. class:: Interpreter(id) - - The class implementing a subinterpreter object. - - .. method:: is_running() - - Return ``True`` if the identified interpreter is running. - - .. method:: close() - - Destroy the interpreter. Attempting to destroy the current - interpreter results in a `RuntimeError`. - - .. method:: run(self, src_str, /, *, channels=None): - - Run the given source code in the interpreter. This blocks - the current thread until done. ``channels`` should be in - the form : `(RecvChannel, SendChannel)`. - -RecvChannel Objects -------------------- - -The ``RecvChannel`` object represents a recieving channel. - -.. class:: RecvChannel(id) - - This class represents the receiving end of a channel. - - .. method:: recv() - - Get the next object from the channel, and wait if - none have been sent. Associate the interpreter - with the channel. - - .. method:: recv_nowait(default=None) - - Like ``recv()``, but return the default result - instead of waiting. - - -SendChannel Objects --------------------- - -The ``SendChannel`` object represents a sending channel. - -.. class:: SendChannel(id) - - This class represents the sending end of a channel. - - .. method:: send(obj) - - Send the object ``obj`` to the receiving end of the channel - and wait. Associate the interpreter with the channel. - - .. method:: send_nowait(obj) - - Similar to ``send()``, but returns ``False`` if - *obj* is not immediately received instead of blocking. - - -This module defines the following global functions: - - -.. function:: is_shareable(obj) - - Return ``True`` if the object's data can be shared between - interpreters. - -.. function:: create_channel() - - Create a new channel for passing data between interpreters. - -.. function:: list_all_channels() - - Return all open channels. - -.. function:: create(*, isolated=True) - - Initialize a new (idle) Python interpreter. Get the currently - running interpreter. This method returns an ``Interpreter`` object. - -.. function:: get_current() - - Get the currently running interpreter. This method returns - an ``Interpreter`` object. - -.. function:: get_main() - - Get the main interpreter. This method returns - an ``Interpreter`` object. - -.. function:: list_all() - - Get all existing interpreters. Returns a list - of ``Interpreter`` objects. - -This module also defines the following exceptions. - -.. exception:: RunFailedError - - This exception, a subclass of :exc:`RuntimeError`, is raised when the - ``Interpreter.run()`` results in an uncaught exception. - -.. exception:: ChannelError - - This exception is a subclass of :exc:`Exception`, and is the base - class for all channel-related exceptions. - -.. exception:: ChannelNotFoundError - - This exception is a subclass of :exc:`ChannelError`, and is raised - when the identified channel is not found. - -.. exception:: ChannelEmptyError - - This exception is a subclass of :exc:`ChannelError`, and is raised when - the channel is unexpectedly empty. - -.. exception:: ChannelNotEmptyError - - This exception is a subclass of :exc:`ChannelError`, and is raised when - the channel is unexpectedly not empty. - -.. exception:: NotReceivedError - - This exception is a subclass of :exc:`ChannelError`, and is raised when - nothing was waiting to receive a sent object. diff --git a/Lib/test/support/os_helper.py b/Lib/test/support/os_helper.py new file mode 100644 index 00000000000..d9807a1e114 --- /dev/null +++ b/Lib/test/support/os_helper.py @@ -0,0 +1,612 @@ +import collections.abc +import contextlib +import errno +import os +import re +import stat +import sys +import time +import unittest +import warnings + + +# Filename used for testing +if os.name == 'java': + # Jython disallows @ in module names + TESTFN_ASCII = '$test' +else: + TESTFN_ASCII = '@test' + +# Disambiguate TESTFN for parallel testing, while letting it remain a valid +# module name. +TESTFN_ASCII = "{}_{}_tmp".format(TESTFN_ASCII, os.getpid()) + +# TESTFN_UNICODE is a non-ascii filename +TESTFN_UNICODE = TESTFN_ASCII + "-\xe0\xf2\u0258\u0141\u011f" +if sys.platform == 'darwin': + # In Mac OS X's VFS API file names are, by definition, canonically + # decomposed Unicode, encoded using UTF-8. See QA1173: + # http://developer.apple.com/mac/library/qa/qa2001/qa1173.html + import unicodedata + TESTFN_UNICODE = unicodedata.normalize('NFD', TESTFN_UNICODE) + +# TESTFN_UNENCODABLE is a filename (str type) that should *not* be able to be +# encoded by the filesystem encoding (in strict mode). It can be None if we +# cannot generate such filename. +TESTFN_UNENCODABLE = None +if os.name == 'nt': + # skip win32s (0) or Windows 9x/ME (1) + if sys.getwindowsversion().platform >= 2: + # Different kinds of characters from various languages to minimize the + # probability that the whole name is encodable to MBCS (issue #9819) + TESTFN_UNENCODABLE = TESTFN_ASCII + "-\u5171\u0141\u2661\u0363\uDC80" + try: + TESTFN_UNENCODABLE.encode(sys.getfilesystemencoding()) + except UnicodeEncodeError: + pass + else: + print('WARNING: The filename %r CAN be encoded by the filesystem ' + 'encoding (%s). Unicode filename tests may not be effective' + % (TESTFN_UNENCODABLE, sys.getfilesystemencoding())) + TESTFN_UNENCODABLE = None +# Mac OS X denies unencodable filenames (invalid utf-8) +elif sys.platform != 'darwin': + try: + # ascii and utf-8 cannot encode the byte 0xff + b'\xff'.decode(sys.getfilesystemencoding()) + except UnicodeDecodeError: + # 0xff will be encoded using the surrogate character u+DCFF + TESTFN_UNENCODABLE = TESTFN_ASCII \ + + b'-\xff'.decode(sys.getfilesystemencoding(), 'surrogateescape') + else: + # File system encoding (eg. ISO-8859-* encodings) can encode + # the byte 0xff. Skip some unicode filename tests. + pass + +# FS_NONASCII: non-ASCII character encodable by os.fsencode(), +# or an empty string if there is no such character. +FS_NONASCII = '' +for character in ( + # First try printable and common characters to have a readable filename. + # For each character, the encoding list are just example of encodings able + # to encode the character (the list is not exhaustive). + + # U+00E6 (Latin Small Letter Ae): cp1252, iso-8859-1 + '\u00E6', + # U+0130 (Latin Capital Letter I With Dot Above): cp1254, iso8859_3 + '\u0130', + # U+0141 (Latin Capital Letter L With Stroke): cp1250, cp1257 + '\u0141', + # U+03C6 (Greek Small Letter Phi): cp1253 + '\u03C6', + # U+041A (Cyrillic Capital Letter Ka): cp1251 + '\u041A', + # U+05D0 (Hebrew Letter Alef): Encodable to cp424 + '\u05D0', + # U+060C (Arabic Comma): cp864, cp1006, iso8859_6, mac_arabic + '\u060C', + # U+062A (Arabic Letter Teh): cp720 + '\u062A', + # U+0E01 (Thai Character Ko Kai): cp874 + '\u0E01', + + # Then try more "special" characters. "special" because they may be + # interpreted or displayed differently depending on the exact locale + # encoding and the font. + + # U+00A0 (No-Break Space) + '\u00A0', + # U+20AC (Euro Sign) + '\u20AC', +): + try: + # If Python is set up to use the legacy 'mbcs' in Windows, + # 'replace' error mode is used, and encode() returns b'?' + # for characters missing in the ANSI codepage + if os.fsdecode(os.fsencode(character)) != character: + raise UnicodeError + except UnicodeError: + pass + else: + FS_NONASCII = character + break + +# Save the initial cwd +SAVEDCWD = os.getcwd() + +# TESTFN_UNDECODABLE is a filename (bytes type) that should *not* be able to be +# decoded from the filesystem encoding (in strict mode). It can be None if we +# cannot generate such filename (ex: the latin1 encoding can decode any byte +# sequence). On UNIX, TESTFN_UNDECODABLE can be decoded by os.fsdecode() thanks +# to the surrogateescape error handler (PEP 383), but not from the filesystem +# encoding in strict mode. +TESTFN_UNDECODABLE = None +for name in ( + # b'\xff' is not decodable by os.fsdecode() with code page 932. Windows + # accepts it to create a file or a directory, or don't accept to enter to + # such directory (when the bytes name is used). So test b'\xe7' first: + # it is not decodable from cp932. + b'\xe7w\xf0', + # undecodable from ASCII, UTF-8 + b'\xff', + # undecodable from iso8859-3, iso8859-6, iso8859-7, cp424, iso8859-8, cp856 + # and cp857 + b'\xae\xd5' + # undecodable from UTF-8 (UNIX and Mac OS X) + b'\xed\xb2\x80', b'\xed\xb4\x80', + # undecodable from shift_jis, cp869, cp874, cp932, cp1250, cp1251, cp1252, + # cp1253, cp1254, cp1255, cp1257, cp1258 + b'\x81\x98', +): + try: + name.decode(sys.getfilesystemencoding()) + except UnicodeDecodeError: + TESTFN_UNDECODABLE = os.fsencode(TESTFN_ASCII) + name + break + +if FS_NONASCII: + TESTFN_NONASCII = TESTFN_ASCII + FS_NONASCII +else: + TESTFN_NONASCII = None +TESTFN = TESTFN_NONASCII or TESTFN_ASCII + + +def make_bad_fd(): + """ + Create an invalid file descriptor by opening and closing a file and return + its fd. + """ + file = open(TESTFN, "wb") + try: + return file.fileno() + finally: + file.close() + unlink(TESTFN) + + +_can_symlink = None + + +def can_symlink(): + global _can_symlink + if _can_symlink is not None: + return _can_symlink + symlink_path = TESTFN + "can_symlink" + try: + os.symlink(TESTFN, symlink_path) + can = True + except (OSError, NotImplementedError, AttributeError): + can = False + else: + os.remove(symlink_path) + _can_symlink = can + return can + + +def skip_unless_symlink(test): + """Skip decorator for tests that require functional symlink""" + ok = can_symlink() + msg = "Requires functional symlink implementation" + return test if ok else unittest.skip(msg)(test) + + +_can_xattr = None + + +def can_xattr(): + import tempfile + global _can_xattr + if _can_xattr is not None: + return _can_xattr + if not hasattr(os, "setxattr"): + can = False + else: + import platform + tmp_dir = tempfile.mkdtemp() + tmp_fp, tmp_name = tempfile.mkstemp(dir=tmp_dir) + try: + with open(TESTFN, "wb") as fp: + try: + # TESTFN & tempfile may use different file systems with + # different capabilities + os.setxattr(tmp_fp, b"user.test", b"") + os.setxattr(tmp_name, b"trusted.foo", b"42") + os.setxattr(fp.fileno(), b"user.test", b"") + # Kernels < 2.6.39 don't respect setxattr flags. + kernel_version = platform.release() + m = re.match(r"2.6.(\d{1,2})", kernel_version) + can = m is None or int(m.group(1)) >= 39 + except OSError: + can = False + finally: + unlink(TESTFN) + unlink(tmp_name) + rmdir(tmp_dir) + _can_xattr = can + return can + + +def skip_unless_xattr(test): + """Skip decorator for tests that require functional extended attributes""" + ok = can_xattr() + msg = "no non-broken extended attribute support" + return test if ok else unittest.skip(msg)(test) + + +def unlink(filename): + try: + _unlink(filename) + except (FileNotFoundError, NotADirectoryError): + pass + + +if sys.platform.startswith("win"): + def _waitfor(func, pathname, waitall=False): + # Perform the operation + func(pathname) + # Now setup the wait loop + if waitall: + dirname = pathname + else: + dirname, name = os.path.split(pathname) + dirname = dirname or '.' + # Check for `pathname` to be removed from the filesystem. + # The exponential backoff of the timeout amounts to a total + # of ~1 second after which the deletion is probably an error + # anyway. + # Testing on an i7@4.3GHz shows that usually only 1 iteration is + # required when contention occurs. + timeout = 0.001 + while timeout < 1.0: + # Note we are only testing for the existence of the file(s) in + # the contents of the directory regardless of any security or + # access rights. If we have made it this far, we have sufficient + # permissions to do that much using Python's equivalent of the + # Windows API FindFirstFile. + # Other Windows APIs can fail or give incorrect results when + # dealing with files that are pending deletion. + L = os.listdir(dirname) + if not (L if waitall else name in L): + return + # Increase the timeout and try again + time.sleep(timeout) + timeout *= 2 + warnings.warn('tests may fail, delete still pending for ' + pathname, + RuntimeWarning, stacklevel=4) + + def _unlink(filename): + _waitfor(os.unlink, filename) + + def _rmdir(dirname): + _waitfor(os.rmdir, dirname) + + def _rmtree(path): + from test.support import _force_run + + def _rmtree_inner(path): + for name in _force_run(path, os.listdir, path): + fullname = os.path.join(path, name) + try: + mode = os.lstat(fullname).st_mode + except OSError as exc: + print("support.rmtree(): os.lstat(%r) failed with %s" + % (fullname, exc), + file=sys.__stderr__) + mode = 0 + if stat.S_ISDIR(mode): + _waitfor(_rmtree_inner, fullname, waitall=True) + _force_run(fullname, os.rmdir, fullname) + else: + _force_run(fullname, os.unlink, fullname) + _waitfor(_rmtree_inner, path, waitall=True) + _waitfor(lambda p: _force_run(p, os.rmdir, p), path) + + def _longpath(path): + try: + import ctypes + except ImportError: + # No ctypes means we can't expands paths. + pass + else: + buffer = ctypes.create_unicode_buffer(len(path) * 2) + length = ctypes.windll.kernel32.GetLongPathNameW(path, buffer, + len(buffer)) + if length: + return buffer[:length] + return path +else: + _unlink = os.unlink + _rmdir = os.rmdir + + def _rmtree(path): + import shutil + try: + shutil.rmtree(path) + return + except OSError: + pass + + def _rmtree_inner(path): + from test.support import _force_run + for name in _force_run(path, os.listdir, path): + fullname = os.path.join(path, name) + try: + mode = os.lstat(fullname).st_mode + except OSError: + mode = 0 + if stat.S_ISDIR(mode): + _rmtree_inner(fullname) + _force_run(path, os.rmdir, fullname) + else: + _force_run(path, os.unlink, fullname) + _rmtree_inner(path) + os.rmdir(path) + + def _longpath(path): + return path + + +def rmdir(dirname): + try: + _rmdir(dirname) + except FileNotFoundError: + pass + + +def rmtree(path): + try: + _rmtree(path) + except FileNotFoundError: + pass + + +@contextlib.contextmanager +def temp_dir(path=None, quiet=False): + """Return a context manager that creates a temporary directory. + + Arguments: + + path: the directory to create temporarily. If omitted or None, + defaults to creating a temporary directory using tempfile.mkdtemp. + + quiet: if False (the default), the context manager raises an exception + on error. Otherwise, if the path is specified and cannot be + created, only a warning is issued. + + """ + import tempfile + dir_created = False + if path is None: + path = tempfile.mkdtemp() + dir_created = True + path = os.path.realpath(path) + else: + try: + os.mkdir(path) + dir_created = True + except OSError as exc: + if not quiet: + raise + warnings.warn(f'tests may fail, unable to create ' + f'temporary directory {path!r}: {exc}', + RuntimeWarning, stacklevel=3) + if dir_created: + pid = os.getpid() + try: + yield path + finally: + # In case the process forks, let only the parent remove the + # directory. The child has a different process id. (bpo-30028) + if dir_created and pid == os.getpid(): + rmtree(path) + + +@contextlib.contextmanager +def change_cwd(path, quiet=False): + """Return a context manager that changes the current working directory. + + Arguments: + + path: the directory to use as the temporary current working directory. + + quiet: if False (the default), the context manager raises an exception + on error. Otherwise, it issues only a warning and keeps the current + working directory the same. + + """ + saved_dir = os.getcwd() + try: + os.chdir(os.path.realpath(path)) + except OSError as exc: + if not quiet: + raise + warnings.warn(f'tests may fail, unable to change the current working ' + f'directory to {path!r}: {exc}', + RuntimeWarning, stacklevel=3) + try: + yield os.getcwd() + finally: + os.chdir(saved_dir) + + +@contextlib.contextmanager +def temp_cwd(name='tempcwd', quiet=False): + """ + Context manager that temporarily creates and changes the CWD. + + The function temporarily changes the current working directory + after creating a temporary directory in the current directory with + name *name*. If *name* is None, the temporary directory is + created using tempfile.mkdtemp. + + If *quiet* is False (default) and it is not possible to + create or change the CWD, an error is raised. If *quiet* is True, + only a warning is raised and the original CWD is used. + + """ + with temp_dir(path=name, quiet=quiet) as temp_path: + with change_cwd(temp_path, quiet=quiet) as cwd_dir: + yield cwd_dir + + +def create_empty_file(filename): + """Create an empty file. If the file already exists, truncate it.""" + fd = os.open(filename, os.O_WRONLY | os.O_CREAT | os.O_TRUNC) + os.close(fd) + + +def fs_is_case_insensitive(directory): + """Detects if the file system for the specified directory + is case-insensitive.""" + import tempfile + with tempfile.NamedTemporaryFile(dir=directory) as base: + base_path = base.name + case_path = base_path.upper() + if case_path == base_path: + case_path = base_path.lower() + try: + return os.path.samefile(base_path, case_path) + except FileNotFoundError: + return False + + +class FakePath: + """Simple implementing of the path protocol. + """ + def __init__(self, path): + self.path = path + + def __repr__(self): + return f'' + + def __fspath__(self): + if (isinstance(self.path, BaseException) or + isinstance(self.path, type) and + issubclass(self.path, BaseException)): + raise self.path + else: + return self.path + + +def fd_count(): + """Count the number of open file descriptors. + """ + if sys.platform.startswith(('linux', 'freebsd')): + try: + names = os.listdir("/proc/self/fd") + # Subtract one because listdir() internally opens a file + # descriptor to list the content of the /proc/self/fd/ directory. + return len(names) - 1 + except FileNotFoundError: + pass + + MAXFD = 256 + if hasattr(os, 'sysconf'): + try: + MAXFD = os.sysconf("SC_OPEN_MAX") + except OSError: + pass + + old_modes = None + if sys.platform == 'win32': + # bpo-25306, bpo-31009: Call CrtSetReportMode() to not kill the process + # on invalid file descriptor if Python is compiled in debug mode + try: + import msvcrt + msvcrt.CrtSetReportMode + except (AttributeError, ImportError): + # no msvcrt or a release build + pass + else: + old_modes = {} + for report_type in (msvcrt.CRT_WARN, + msvcrt.CRT_ERROR, + msvcrt.CRT_ASSERT): + old_modes[report_type] = msvcrt.CrtSetReportMode(report_type, + 0) + + try: + count = 0 + for fd in range(MAXFD): + try: + # Prefer dup() over fstat(). fstat() can require input/output + # whereas dup() doesn't. + fd2 = os.dup(fd) + except OSError as e: + if e.errno != errno.EBADF: + raise + else: + os.close(fd2) + count += 1 + finally: + if old_modes is not None: + for report_type in (msvcrt.CRT_WARN, + msvcrt.CRT_ERROR, + msvcrt.CRT_ASSERT): + msvcrt.CrtSetReportMode(report_type, old_modes[report_type]) + + return count + + +if hasattr(os, "umask"): + @contextlib.contextmanager + def temp_umask(umask): + """Context manager that temporarily sets the process umask.""" + oldmask = os.umask(umask) + try: + yield + finally: + os.umask(oldmask) + + +class EnvironmentVarGuard(collections.abc.MutableMapping): + + """Class to help protect the environment variable properly. Can be used as + a context manager.""" + + def __init__(self): + self._environ = os.environ + self._changed = {} + + def __getitem__(self, envvar): + return self._environ[envvar] + + def __setitem__(self, envvar, value): + # Remember the initial value on the first access + if envvar not in self._changed: + self._changed[envvar] = self._environ.get(envvar) + self._environ[envvar] = value + + def __delitem__(self, envvar): + # Remember the initial value on the first access + if envvar not in self._changed: + self._changed[envvar] = self._environ.get(envvar) + if envvar in self._environ: + del self._environ[envvar] + + def keys(self): + return self._environ.keys() + + def __iter__(self): + return iter(self._environ) + + def __len__(self): + return len(self._environ) + + def set(self, envvar, value): + self[envvar] = value + + def unset(self, envvar): + del self[envvar] + + def __enter__(self): + return self + + def __exit__(self, *ignore_exc): + for (k, v) in self._changed.items(): + if v is None: + if k in self._environ: + del self._environ[k] + else: + self._environ[k] = v + os.environ = self._environ diff --git a/Lib/test/support/script_helper.py b/Lib/test/support/script_helper.py index 37e576d4a77..09bb586dcf7 100644 --- a/Lib/test/support/script_helper.py +++ b/Lib/test/support/script_helper.py @@ -11,7 +11,7 @@ import py_compile import zipfile from importlib.util import source_from_cache -from test.support import make_legacy_pyc +from test.support.import_helper import make_legacy_pyc # Cached result of the expensive test performed in the function below. diff --git a/Lib/test/support/socket_helper.py b/Lib/test/support/socket_helper.py index f709ffd40dd..7070c12c253 100644 --- a/Lib/test/support/socket_helper.py +++ b/Lib/test/support/socket_helper.py @@ -146,7 +146,7 @@ def skip_unless_bind_unix_socket(test): return unittest.skip('No UNIX Sockets')(test) global _bind_nix_socket_error if _bind_nix_socket_error is None: - from test.support import TESTFN, unlink + from .os_helper import TESTFN, unlink path = TESTFN + "can_bind_unix_socket" with socket.socket(socket.AF_UNIX) as sock: try: diff --git a/Lib/test/support/threading_helper.py b/Lib/test/support/threading_helper.py new file mode 100644 index 00000000000..0632577cdb3 --- /dev/null +++ b/Lib/test/support/threading_helper.py @@ -0,0 +1,209 @@ +import _thread +import contextlib +import functools +import sys +import threading +import time + +from test import support + + +#======================================================================= +# Threading support to prevent reporting refleaks when running regrtest.py -R + +# NOTE: we use thread._count() rather than threading.enumerate() (or the +# moral equivalent thereof) because a threading.Thread object is still alive +# until its __bootstrap() method has returned, even after it has been +# unregistered from the threading module. +# thread._count(), on the other hand, only gets decremented *after* the +# __bootstrap() method has returned, which gives us reliable reference counts +# at the end of a test run. + + +def threading_setup(): + return _thread._count(), threading._dangling.copy() + + +def threading_cleanup(*original_values): + _MAX_COUNT = 100 + + for count in range(_MAX_COUNT): + values = _thread._count(), threading._dangling + if values == original_values: + break + + if not count: + # Display a warning at the first iteration + support.environment_altered = True + dangling_threads = values[1] + support.print_warning(f"threading_cleanup() failed to cleanup " + f"{values[0] - original_values[0]} threads " + f"(count: {values[0]}, " + f"dangling: {len(dangling_threads)})") + for thread in dangling_threads: + support.print_warning(f"Dangling thread: {thread!r}") + + # Don't hold references to threads + dangling_threads = None + values = None + + time.sleep(0.01) + support.gc_collect() + + +def reap_threads(func): + """Use this function when threads are being used. This will + ensure that the threads are cleaned up even when the test fails. + """ + @functools.wraps(func) + def decorator(*args): + key = threading_setup() + try: + return func(*args) + finally: + threading_cleanup(*key) + return decorator + + +@contextlib.contextmanager +def wait_threads_exit(timeout=None): + """ + bpo-31234: Context manager to wait until all threads created in the with + statement exit. + + Use _thread.count() to check if threads exited. Indirectly, wait until + threads exit the internal t_bootstrap() C function of the _thread module. + + threading_setup() and threading_cleanup() are designed to emit a warning + if a test leaves running threads in the background. This context manager + is designed to cleanup threads started by the _thread.start_new_thread() + which doesn't allow to wait for thread exit, whereas thread.Thread has a + join() method. + """ + if timeout is None: + timeout = support.SHORT_TIMEOUT + old_count = _thread._count() + try: + yield + finally: + start_time = time.monotonic() + deadline = start_time + timeout + while True: + count = _thread._count() + if count <= old_count: + break + if time.monotonic() > deadline: + dt = time.monotonic() - start_time + msg = (f"wait_threads() failed to cleanup {count - old_count} " + f"threads after {dt:.1f} seconds " + f"(count: {count}, old count: {old_count})") + raise AssertionError(msg) + time.sleep(0.010) + support.gc_collect() + + +def join_thread(thread, timeout=None): + """Join a thread. Raise an AssertionError if the thread is still alive + after timeout seconds. + """ + if timeout is None: + timeout = support.SHORT_TIMEOUT + thread.join(timeout) + if thread.is_alive(): + msg = f"failed to join the thread in {timeout:.1f} seconds" + raise AssertionError(msg) + + +@contextlib.contextmanager +def start_threads(threads, unlock=None): + import faulthandler + threads = list(threads) + started = [] + try: + try: + for t in threads: + t.start() + started.append(t) + except: + if support.verbose: + print("Can't start %d threads, only %d threads started" % + (len(threads), len(started))) + raise + yield + finally: + try: + if unlock: + unlock() + endtime = time.monotonic() + for timeout in range(1, 16): + endtime += 60 + for t in started: + t.join(max(endtime - time.monotonic(), 0.01)) + started = [t for t in started if t.is_alive()] + if not started: + break + if support.verbose: + print('Unable to join %d threads during a period of ' + '%d minutes' % (len(started), timeout)) + finally: + started = [t for t in started if t.is_alive()] + if started: + faulthandler.dump_traceback(sys.stdout) + raise AssertionError('Unable to join %d threads' % len(started)) + + +class catch_threading_exception: + """ + Context manager catching threading.Thread exception using + threading.excepthook. + + Attributes set when an exception is catched: + + * exc_type + * exc_value + * exc_traceback + * thread + + See threading.excepthook() documentation for these attributes. + + These attributes are deleted at the context manager exit. + + Usage: + + with threading_helper.catch_threading_exception() as cm: + # code spawning a thread which raises an exception + ... + + # check the thread exception, use cm attributes: + # exc_type, exc_value, exc_traceback, thread + ... + + # exc_type, exc_value, exc_traceback, thread attributes of cm no longer + # exists at this point + # (to avoid reference cycles) + """ + + def __init__(self): + self.exc_type = None + self.exc_value = None + self.exc_traceback = None + self.thread = None + self._old_hook = None + + def _hook(self, args): + self.exc_type = args.exc_type + self.exc_value = args.exc_value + self.exc_traceback = args.exc_traceback + self.thread = args.thread + + def __enter__(self): + self._old_hook = threading.excepthook + threading.excepthook = self._hook + return self + + def __exit__(self, *exc_info): + threading.excepthook = self._old_hook + del self.exc_type + del self.exc_value + del self.exc_traceback + del self.thread diff --git a/Lib/test/support/warnings_helper.py b/Lib/test/support/warnings_helper.py new file mode 100644 index 00000000000..de23e6b452b --- /dev/null +++ b/Lib/test/support/warnings_helper.py @@ -0,0 +1,189 @@ +import contextlib +import functools +import re +import sys +import warnings + + +def check_syntax_warning(testcase, statement, errtext='', + *, lineno=1, offset=None): + # Test also that a warning is emitted only once. + from test.support import check_syntax_error + with warnings.catch_warnings(record=True) as warns: + warnings.simplefilter('always', SyntaxWarning) + compile(statement, '', 'exec') + testcase.assertEqual(len(warns), 1, warns) + + warn, = warns + testcase.assertTrue(issubclass(warn.category, SyntaxWarning), + warn.category) + if errtext: + testcase.assertRegex(str(warn.message), errtext) + testcase.assertEqual(warn.filename, '') + testcase.assertIsNotNone(warn.lineno) + if lineno is not None: + testcase.assertEqual(warn.lineno, lineno) + + # SyntaxWarning should be converted to SyntaxError when raised, + # since the latter contains more information and provides better + # error report. + with warnings.catch_warnings(record=True) as warns: + warnings.simplefilter('error', SyntaxWarning) + check_syntax_error(testcase, statement, errtext, + lineno=lineno, offset=offset) + # No warnings are leaked when a SyntaxError is raised. + testcase.assertEqual(warns, []) + + +def ignore_warnings(*, category): + """Decorator to suppress deprecation warnings. + + Use of context managers to hide warnings make diffs + more noisy and tools like 'git blame' less useful. + """ + def decorator(test): + @functools.wraps(test) + def wrapper(self, *args, **kwargs): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', category=category) + return test(self, *args, **kwargs) + return wrapper + return decorator + + +class WarningsRecorder(object): + """Convenience wrapper for the warnings list returned on + entry to the warnings.catch_warnings() context manager. + """ + def __init__(self, warnings_list): + self._warnings = warnings_list + self._last = 0 + + def __getattr__(self, attr): + if len(self._warnings) > self._last: + return getattr(self._warnings[-1], attr) + elif attr in warnings.WarningMessage._WARNING_DETAILS: + return None + raise AttributeError("%r has no attribute %r" % (self, attr)) + + @property + def warnings(self): + return self._warnings[self._last:] + + def reset(self): + self._last = len(self._warnings) + + +@contextlib.contextmanager +def check_warnings(*filters, **kwargs): + """Context manager to silence warnings. + + Accept 2-tuples as positional arguments: + ("message regexp", WarningCategory) + + Optional argument: + - if 'quiet' is True, it does not fail if a filter catches nothing + (default True without argument, + default False if some filters are defined) + + Without argument, it defaults to: + check_warnings(("", Warning), quiet=True) + """ + quiet = kwargs.get('quiet') + if not filters: + filters = (("", Warning),) + # Preserve backward compatibility + if quiet is None: + quiet = True + return _filterwarnings(filters, quiet) + + +@contextlib.contextmanager +def check_no_warnings(testcase, message='', category=Warning, force_gc=False): + """Context manager to check that no warnings are emitted. + + This context manager enables a given warning within its scope + and checks that no warnings are emitted even with that warning + enabled. + + If force_gc is True, a garbage collection is attempted before checking + for warnings. This may help to catch warnings emitted when objects + are deleted, such as ResourceWarning. + + Other keyword arguments are passed to warnings.filterwarnings(). + """ + from test.support import gc_collect + with warnings.catch_warnings(record=True) as warns: + warnings.filterwarnings('always', + message=message, + category=category) + yield + if force_gc: + gc_collect() + testcase.assertEqual(warns, []) + + +@contextlib.contextmanager +def check_no_resource_warning(testcase): + """Context manager to check that no ResourceWarning is emitted. + + Usage: + + with check_no_resource_warning(self): + f = open(...) + ... + del f + + You must remove the object which may emit ResourceWarning before + the end of the context manager. + """ + with check_no_warnings(testcase, category=ResourceWarning, force_gc=True): + yield + + +def _filterwarnings(filters, quiet=False): + """Catch the warnings, then check if all the expected + warnings have been raised and re-raise unexpected warnings. + If 'quiet' is True, only re-raise the unexpected warnings. + """ + # Clear the warning registry of the calling module + # in order to re-raise the warnings. + frame = sys._getframe(2) + registry = frame.f_globals.get('__warningregistry__') + if registry: + registry.clear() + with warnings.catch_warnings(record=True) as w: + # Set filter "always" to record all warnings. Because + # test_warnings swap the module, we need to look up in + # the sys.modules dictionary. + sys.modules['warnings'].simplefilter("always") + yield WarningsRecorder(w) + # Filter the recorded warnings + reraise = list(w) + missing = [] + for msg, cat in filters: + seen = False + for w in reraise[:]: + warning = w.message + # Filter out the matching messages + if (re.match(msg, str(warning), re.I) and + issubclass(warning.__class__, cat)): + seen = True + reraise.remove(w) + if not seen and not quiet: + # This filter caught nothing + missing.append((msg, cat.__name__)) + if reraise: + raise AssertionError("unhandled warning %s" % reraise[0]) + if missing: + raise AssertionError("filter (%r, %s) did not catch any warning" % + missing[0]) + + +@contextlib.contextmanager +def save_restore_warnings_filters(): + old_filters = warnings.filters[:] + try: + yield + finally: + warnings.filters[:] = old_filters diff --git a/Lib/test/test__xxsubinterpreters.py b/Lib/test/test__xxsubinterpreters.py index e17bfde2c2f..cf34fc3d0e7 100644 --- a/Lib/test/test__xxsubinterpreters.py +++ b/Lib/test/test__xxsubinterpreters.py @@ -10,10 +10,11 @@ import time import unittest from test import support +from test.support import import_helper from test.support import script_helper -interpreters = support.import_module('_xxsubinterpreters') +interpreters = import_helper.import_module('_xxsubinterpreters') ################################## @@ -378,6 +379,9 @@ class ShareableTypeTests(unittest.TestCase): self._assert_values(i.to_bytes(2, 'little', signed=True) for i in range(-1, 258)) + def test_strs(self): + self._assert_values(['hello world', '你好世界', '']) + def test_int(self): self._assert_values(itertools.chain(range(-1, 258), [sys.maxsize, -sys.maxsize - 1])) @@ -470,6 +474,7 @@ class IsRunningTests(TestBase): main = interpreters.get_main() self.assertTrue(interpreters.is_running(main)) + @unittest.skip('Fails on FreeBSD') def test_subinterpreter(self): interp = interpreters.create() self.assertFalse(interpreters.is_running(interp)) @@ -756,21 +761,9 @@ class DestroyTests(TestBase): class RunStringTests(TestBase): - SCRIPT = dedent(""" - with open('{}', 'w') as out: - out.write('{}') - """) - FILENAME = 'spam' - def setUp(self): super().setUp() self.id = interpreters.create() - self._fs = None - - def tearDown(self): - if self._fs is not None: - self._fs.close() - super().tearDown() def test_success(self): script, file = _captured_script('print("it worked!", end="")') diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py index 5a95099cc5c..fb6da4136f4 100644 --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -1,4 +1,6 @@ -from test.support import check_no_resource_warning, findfile, TESTFN, unlink +from test.support import findfile +from test.support.os_helper import TESTFN, unlink +from test.support.warnings_helper import check_no_resource_warning import unittest from unittest import mock from test import audiotests diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index e82a0c39c21..22cae626ccc 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -700,6 +700,14 @@ class TestBooleanOptionalAction(ParserTestCase): ('--no-foo --foo', NS(foo=True)), ] + def test_const(self): + # See bpo-40862 + parser = argparse.ArgumentParser() + with self.assertRaises(TypeError) as cm: + parser.add_argument('--foo', const=True, action=argparse.BooleanOptionalAction) + + self.assertIn("got an unexpected keyword argument 'const'", str(cm.exception)) + class TestBooleanOptionalActionRequired(ParserTestCase): """Tests BooleanOptionalAction required""" diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index f731b70415e..c423f545488 100644 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -2,8 +2,10 @@ Roger E. Masse """ +import collections.abc import unittest from test import support +from test.support import os_helper from test.support import _2G import weakref import pickle @@ -28,6 +30,10 @@ typecodes = 'ubBhHiIlLfdqQ' class MiscTest(unittest.TestCase): + def test_array_is_sequence(self): + self.assertIsInstance(array.array("B"), collections.abc.MutableSequence) + self.assertIsInstance(array.array("B"), collections.abc.Reversible) + def test_bad_constructor(self): self.assertRaises(TypeError, array.array) self.assertRaises(TypeError, array.array, spam=42) @@ -330,6 +336,67 @@ class BaseTest: self.assertEqual(list(empit), [self.outside]) self.assertEqual(list(a), list(self.example) + [self.outside]) + def test_reverse_iterator(self): + a = array.array(self.typecode, self.example) + self.assertEqual(list(a), list(self.example)) + self.assertEqual(list(reversed(a)), list(iter(a))[::-1]) + + def test_reverse_iterator_picking(self): + orig = array.array(self.typecode, self.example) + data = list(orig) + data2 = [self.outside] + data + rev_data = data[len(data)-2::-1] + [self.outside] + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + # initial iterator + itorig = reversed(orig) + d = pickle.dumps((itorig, orig), proto) + it, a = pickle.loads(d) + a.insert(0, self.outside) + self.assertEqual(type(it), type(itorig)) + self.assertEqual(list(it), rev_data) + self.assertEqual(list(a), data2) + + # running iterator + next(itorig) + d = pickle.dumps((itorig, orig), proto) + it, a = pickle.loads(d) + a.insert(0, self.outside) + self.assertEqual(type(it), type(itorig)) + self.assertEqual(list(it), rev_data[1:]) + self.assertEqual(list(a), data2) + + # empty iterator + for i in range(1, len(data)): + next(itorig) + d = pickle.dumps((itorig, orig), proto) + it, a = pickle.loads(d) + a.insert(0, self.outside) + self.assertEqual(type(it), type(itorig)) + self.assertEqual(list(it), []) + self.assertEqual(list(a), data2) + + # exhausted iterator + self.assertRaises(StopIteration, next, itorig) + d = pickle.dumps((itorig, orig), proto) + it, a = pickle.loads(d) + a.insert(0, self.outside) + self.assertEqual(list(it), []) + self.assertEqual(list(a), data2) + + def test_exhausted_reverse_iterator(self): + a = array.array(self.typecode, self.example) + self.assertEqual(list(a), list(self.example)) + exhit = reversed(a) + empit = reversed(a) + for x in exhit: # exhaust the iterator + next(empit) # Pointing past the 0th position. + a.insert(0, self.outside) + self.assertEqual(list(exhit), []) + # The iterator index points past the 0th position so inserting + # an element in the beggining does not make it appear. + self.assertEqual(list(empit), []) + self.assertEqual(list(a), [self.outside] + list(self.example)) + def test_insert(self): a = array.array(self.typecode, self.example) a.insert(0, self.example[0]) @@ -366,13 +433,13 @@ class BaseTest: def test_tofromfile(self): a = array.array(self.typecode, 2*self.example) self.assertRaises(TypeError, a.tofile) - support.unlink(support.TESTFN) - f = open(support.TESTFN, 'wb') + os_helper.unlink(os_helper.TESTFN) + f = open(os_helper.TESTFN, 'wb') try: a.tofile(f) f.close() b = array.array(self.typecode) - f = open(support.TESTFN, 'rb') + f = open(os_helper.TESTFN, 'rb') self.assertRaises(TypeError, b.fromfile) b.fromfile(f, len(self.example)) self.assertEqual(b, array.array(self.typecode, self.example)) @@ -383,27 +450,27 @@ class BaseTest: finally: if not f.closed: f.close() - support.unlink(support.TESTFN) + os_helper.unlink(os_helper.TESTFN) def test_fromfile_ioerror(self): # Issue #5395: Check if fromfile raises a proper OSError # instead of EOFError. a = array.array(self.typecode) - f = open(support.TESTFN, 'wb') + f = open(os_helper.TESTFN, 'wb') try: self.assertRaises(OSError, a.fromfile, f, len(self.example)) finally: f.close() - support.unlink(support.TESTFN) + os_helper.unlink(os_helper.TESTFN) def test_filewrite(self): a = array.array(self.typecode, 2*self.example) - f = open(support.TESTFN, 'wb') + f = open(os_helper.TESTFN, 'wb') try: f.write(a) f.close() b = array.array(self.typecode) - f = open(support.TESTFN, 'rb') + f = open(os_helper.TESTFN, 'rb') b.fromfile(f, len(self.example)) self.assertEqual(b, array.array(self.typecode, self.example)) self.assertNotEqual(a, b) @@ -413,7 +480,7 @@ class BaseTest: finally: if not f.closed: f.close() - support.unlink(support.TESTFN) + os_helper.unlink(os_helper.TESTFN) def test_tofromlist(self): a = array.array(self.typecode, 2*self.example) diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 3e9c8b55cdf..78e4a5653d4 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -663,6 +663,18 @@ class AST_Tests(unittest.TestCase): expressions[0] = f"expr = {ast.expr.__subclasses__()[0].__doc__}" self.assertCountEqual(ast.expr.__doc__.split("\n"), expressions) + def test_issue40614_feature_version(self): + ast.parse('f"{x=}"', feature_version=(3, 8)) + with self.assertRaises(SyntaxError): + ast.parse('f"{x=}"', feature_version=(3, 7)) + + def test_constant_as_name(self): + for constant in "True", "False", "None": + expr = ast.Expression(ast.Name(constant, ast.Load())) + ast.fix_missing_locations(expr) + with self.assertRaisesRegex(ValueError, f"Name node can't be used with '{constant}' constant"): + compile(expr, "", "eval") + class ASTHelpers_Test(unittest.TestCase): maxDiff = None diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py index 004d368d763..b32edddc7d5 100644 --- a/Lib/test/test_asynchat.py +++ b/Lib/test/test_asynchat.py @@ -2,6 +2,7 @@ from test import support from test.support import socket_helper +from test.support import threading_helper import asynchat import asyncore @@ -103,10 +104,10 @@ class TestAsynchat(unittest.TestCase): usepoll = False def setUp(self): - self._threads = support.threading_setup() + self._threads = threading_helper.threading_setup() def tearDown(self): - support.threading_cleanup(*self._threads) + threading_helper.threading_cleanup(*self._threads) def line_terminator_check(self, term, server_chunk): event = threading.Event() @@ -122,7 +123,7 @@ class TestAsynchat(unittest.TestCase): c.push(b"I'm not dead yet!" + term) c.push(SERVER_QUIT) asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) - support.join_thread(s) + threading_helper.join_thread(s) self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"]) @@ -153,7 +154,7 @@ class TestAsynchat(unittest.TestCase): c.push(data) c.push(SERVER_QUIT) asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) - support.join_thread(s) + threading_helper.join_thread(s) self.assertEqual(c.contents, [data[:termlen]]) @@ -173,7 +174,7 @@ class TestAsynchat(unittest.TestCase): c.push(data) c.push(SERVER_QUIT) asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) - support.join_thread(s) + threading_helper.join_thread(s) self.assertEqual(c.contents, []) self.assertEqual(c.buffer, data) @@ -185,7 +186,7 @@ class TestAsynchat(unittest.TestCase): p = asynchat.simple_producer(data+SERVER_QUIT, buffer_size=8) c.push_with_producer(p) asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) - support.join_thread(s) + threading_helper.join_thread(s) self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"]) @@ -195,7 +196,7 @@ class TestAsynchat(unittest.TestCase): data = b"hello world\nI'm not dead yet!\n" c.push_with_producer(data+SERVER_QUIT) asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) - support.join_thread(s) + threading_helper.join_thread(s) self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"]) @@ -206,7 +207,7 @@ class TestAsynchat(unittest.TestCase): c.push(b"hello world\n\nI'm not dead yet!\n") c.push(SERVER_QUIT) asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) - support.join_thread(s) + threading_helper.join_thread(s) self.assertEqual(c.contents, [b"hello world", b"", b"I'm not dead yet!"]) @@ -225,7 +226,7 @@ class TestAsynchat(unittest.TestCase): # where the server echoes all of its data before we can check that it # got any down below. s.start_resend_event.set() - support.join_thread(s) + threading_helper.join_thread(s) self.assertEqual(c.contents, []) # the server might have been able to send a byte or two back, but this @@ -246,7 +247,7 @@ class TestAsynchat(unittest.TestCase): self.assertRaises(TypeError, c.push, 'unicode') c.push(SERVER_QUIT) asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) - support.join_thread(s) + threading_helper.join_thread(s) self.assertEqual(c.contents, [b'bytes', b'bytes', b'bytes']) diff --git a/Lib/test/test_asyncio/__init__.py b/Lib/test/test_asyncio/__init__.py index c77c7a81278..5d415044d7d 100644 --- a/Lib/test/test_asyncio/__init__.py +++ b/Lib/test/test_asyncio/__init__.py @@ -1,8 +1,10 @@ import os -from test.support import load_package_tests, import_module +from test.support import load_package_tests +from test.support import import_helper + # Skip tests if we don't have concurrent.futures. -import_module('concurrent.futures') +import_helper.import_module('concurrent.futures') def load_tests(*args): return load_package_tests(os.path.dirname(__file__), *args) diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py index 533d5cc7f50..f74dabc2db9 100644 --- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -16,6 +16,7 @@ from asyncio import constants from test.test_asyncio import utils as test_utils from test import support from test.support.script_helper import assert_python_ok +from test.support import os_helper from test.support import socket_helper @@ -1983,14 +1984,14 @@ class BaseLoopSockSendfileTests(test_utils.TestCase): def setUpClass(cls): cls.__old_bufsize = constants.SENDFILE_FALLBACK_READBUFFER_SIZE constants.SENDFILE_FALLBACK_READBUFFER_SIZE = 1024 * 16 - with open(support.TESTFN, 'wb') as fp: + with open(os_helper.TESTFN, 'wb') as fp: fp.write(cls.DATA) super().setUpClass() @classmethod def tearDownClass(cls): constants.SENDFILE_FALLBACK_READBUFFER_SIZE = cls.__old_bufsize - support.unlink(support.TESTFN) + os_helper.unlink(os_helper.TESTFN) super().tearDownClass() def setUp(self): @@ -1998,7 +1999,7 @@ class BaseLoopSockSendfileTests(test_utils.TestCase): # BaseSelectorEventLoop() has no native implementation self.loop = BaseSelectorEventLoop() self.set_event_loop(self.loop) - self.file = open(support.TESTFN, 'rb') + self.file = open(os_helper.TESTFN, 'rb') self.addCleanup(self.file.close) super().setUp() @@ -2095,7 +2096,7 @@ class BaseLoopSockSendfileTests(test_utils.TestCase): def test_nonbinary_file(self): sock = self.make_socket() - with open(support.TESTFN, 'r') as f: + with open(os_helper.TESTFN, 'r') as f: with self.assertRaisesRegex(ValueError, "binary mode"): self.run_loop(self.loop.sock_sendfile(sock, f)) diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index 0fb36188418..ef9d6fc48e9 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -33,6 +33,7 @@ from asyncio import selector_events from test.test_asyncio import utils as test_utils from test import support from test.support import socket_helper +from test.support import threading_helper from test.support import ALWAYS_EQ, LARGEST, SMALLEST @@ -706,7 +707,7 @@ class EventLoopTestsMixin: proto.transport.close() lsock.close() - support.join_thread(thread) + threading_helper.join_thread(thread) self.assertFalse(thread.is_alive()) self.assertEqual(proto.state, 'CLOSED') self.assertEqual(proto.nbytes, len(message)) @@ -2672,10 +2673,10 @@ class GetEventLoopTestsMixin: if sys.platform != 'win32': def test_get_event_loop_new_process(self): - # Issue bpo-32126: The multiprocessing module used by + # bpo-32126: The multiprocessing module used by # ProcessPoolExecutor is not functional when the # multiprocessing.synchronize module cannot be imported. - support.import_module('multiprocessing.synchronize') + support.skip_if_broken_multiprocessing_synchronize() async def main(): pool = concurrent.futures.ProcessPoolExecutor() diff --git a/Lib/test/test_asyncio/test_sendfile.py b/Lib/test/test_asyncio/test_sendfile.py index dbce199a9b8..a30d9b9b4d9 100644 --- a/Lib/test/test_asyncio/test_sendfile.py +++ b/Lib/test/test_asyncio/test_sendfile.py @@ -10,6 +10,7 @@ from asyncio import base_events from asyncio import constants from unittest import mock from test import support +from test.support import os_helper from test.support import socket_helper from test.test_asyncio import utils as test_utils @@ -98,17 +99,17 @@ class SendfileBase: @classmethod def setUpClass(cls): - with open(support.TESTFN, 'wb') as fp: + with open(os_helper.TESTFN, 'wb') as fp: fp.write(cls.DATA) super().setUpClass() @classmethod def tearDownClass(cls): - support.unlink(support.TESTFN) + os_helper.unlink(os_helper.TESTFN) super().tearDownClass() def setUp(self): - self.file = open(support.TESTFN, 'rb') + self.file = open(os_helper.TESTFN, 'rb') self.addCleanup(self.file.close) self.loop = self.create_event_loop() self.set_event_loop(self.loop) diff --git a/Lib/test/test_asyncio/test_sock_lowlevel.py b/Lib/test/test_asyncio/test_sock_lowlevel.py index 2f2d5a45497..e339ee9a4fc 100644 --- a/Lib/test/test_asyncio/test_sock_lowlevel.py +++ b/Lib/test/test_asyncio/test_sock_lowlevel.py @@ -1,6 +1,9 @@ import socket +import time import asyncio import sys +import unittest + from asyncio import proactor_events from itertools import cycle, islice from test.test_asyncio import utils as test_utils @@ -122,6 +125,150 @@ class BaseSockTestsMixin: sock = socket.socket() self._basetest_sock_recv_into(httpd, sock) + async def _basetest_sock_recv_racing(self, httpd, sock): + sock.setblocking(False) + await self.loop.sock_connect(sock, httpd.address) + + task = asyncio.create_task(self.loop.sock_recv(sock, 1024)) + await asyncio.sleep(0) + task.cancel() + + asyncio.create_task( + self.loop.sock_sendall(sock, b'GET / HTTP/1.0\r\n\r\n')) + data = await self.loop.sock_recv(sock, 1024) + # consume data + await self.loop.sock_recv(sock, 1024) + + self.assertTrue(data.startswith(b'HTTP/1.0 200 OK')) + + async def _basetest_sock_recv_into_racing(self, httpd, sock): + sock.setblocking(False) + await self.loop.sock_connect(sock, httpd.address) + + data = bytearray(1024) + with memoryview(data) as buf: + task = asyncio.create_task( + self.loop.sock_recv_into(sock, buf[:1024])) + await asyncio.sleep(0) + task.cancel() + + task = asyncio.create_task( + self.loop.sock_sendall(sock, b'GET / HTTP/1.0\r\n\r\n')) + nbytes = await self.loop.sock_recv_into(sock, buf[:1024]) + # consume data + await self.loop.sock_recv_into(sock, buf[nbytes:]) + self.assertTrue(data.startswith(b'HTTP/1.0 200 OK')) + + await task + + async def _basetest_sock_send_racing(self, listener, sock): + listener.bind(('127.0.0.1', 0)) + listener.listen(1) + + # make connection + sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024) + sock.setblocking(False) + task = asyncio.create_task( + self.loop.sock_connect(sock, listener.getsockname())) + await asyncio.sleep(0) + server = listener.accept()[0] + server.setblocking(False) + + with server: + await task + + # fill the buffer until sending 5 chars would block + size = 8192 + while size >= 4: + with self.assertRaises(BlockingIOError): + while True: + sock.send(b' ' * size) + size = int(size / 2) + + # cancel a blocked sock_sendall + task = asyncio.create_task( + self.loop.sock_sendall(sock, b'hello')) + await asyncio.sleep(0) + task.cancel() + + # receive everything that is not a space + async def recv_all(): + rv = b'' + while True: + buf = await self.loop.sock_recv(server, 8192) + if not buf: + return rv + rv += buf.strip() + task = asyncio.create_task(recv_all()) + + # immediately make another sock_sendall call + await self.loop.sock_sendall(sock, b'world') + sock.shutdown(socket.SHUT_WR) + data = await task + # ProactorEventLoop could deliver hello, so endswith is necessary + self.assertTrue(data.endswith(b'world')) + + # After the first connect attempt before the listener is ready, + # the socket needs time to "recover" to make the next connect call. + # On Linux, a second retry will do. On Windows, the waiting time is + # unpredictable; and on FreeBSD the socket may never come back + # because it's a loopback address. Here we'll just retry for a few + # times, and have to skip the test if it's not working. See also: + # https://stackoverflow.com/a/54437602/3316267 + # https://lists.freebsd.org/pipermail/freebsd-current/2005-May/049876.html + async def _basetest_sock_connect_racing(self, listener, sock): + listener.bind(('127.0.0.1', 0)) + addr = listener.getsockname() + sock.setblocking(False) + + task = asyncio.create_task(self.loop.sock_connect(sock, addr)) + await asyncio.sleep(0) + task.cancel() + + listener.listen(1) + + skip_reason = "Max retries reached" + for i in range(128): + try: + await self.loop.sock_connect(sock, addr) + except ConnectionRefusedError as e: + skip_reason = e + except OSError as e: + skip_reason = e + + # Retry only for this error: + # [WinError 10022] An invalid argument was supplied + if getattr(e, 'winerror', 0) != 10022: + break + else: + # success + return + + self.skipTest(skip_reason) + + def test_sock_client_racing(self): + with test_utils.run_test_server() as httpd: + sock = socket.socket() + with sock: + self.loop.run_until_complete(asyncio.wait_for( + self._basetest_sock_recv_racing(httpd, sock), 10)) + sock = socket.socket() + with sock: + self.loop.run_until_complete(asyncio.wait_for( + self._basetest_sock_recv_into_racing(httpd, sock), 10)) + listener = socket.socket() + sock = socket.socket() + with listener, sock: + self.loop.run_until_complete(asyncio.wait_for( + self._basetest_sock_send_racing(listener, sock), 10)) + + def test_sock_client_connect_racing(self): + listener = socket.socket() + sock = socket.socket() + with listener, sock: + self.loop.run_until_complete(asyncio.wait_for( + self._basetest_sock_connect_racing(listener, sock), 10)) + async def _basetest_huge_content(self, address): sock = socket.socket() sock.setblocking(False) diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py index 6657a88e657..177a02cdcc1 100644 --- a/Lib/test/test_asyncio/test_subprocess.py +++ b/Lib/test/test_asyncio/test_subprocess.py @@ -10,6 +10,7 @@ from asyncio import base_subprocess from asyncio import subprocess from test.test_asyncio import utils as test_utils from test import support +from test.support import os_helper if sys.platform != 'win32': from asyncio import unix_events @@ -626,10 +627,10 @@ class SubprocessMixin: def test_create_subprocess_exec_with_path(self): async def execute(): p = await subprocess.create_subprocess_exec( - support.FakePath(sys.executable), '-c', 'pass') + os_helper.FakePath(sys.executable), '-c', 'pass') await p.wait() p = await subprocess.create_subprocess_exec( - sys.executable, '-c', 'pass', support.FakePath('.')) + sys.executable, '-c', 'pass', os_helper.FakePath('.')) await p.wait() self.assertIsNone(self.loop.run_until_complete(execute())) @@ -737,7 +738,7 @@ class GenericWatcherTests: with self.assertRaises(RuntimeError): await subprocess.create_subprocess_exec( - support.FakePath(sys.executable), '-c', 'pass') + os_helper.FakePath(sys.executable), '-c', 'pass') watcher.add_child_handler.assert_not_called() diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 3734013fad9..f9db066ce89 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -1943,32 +1943,6 @@ class BaseTaskTests: self.assertEqual(res, 'test') self.assertIsNone(t2.result()) - - def test_current_task_deprecated(self): - Task = self.__class__.Task - - with self.assertWarns(DeprecationWarning): - self.assertIsNone(Task.current_task(loop=self.loop)) - - async def coro(loop): - with self.assertWarns(DeprecationWarning): - self.assertIs(Task.current_task(loop=loop), task) - - # See http://bugs.python.org/issue29271 for details: - asyncio.set_event_loop(loop) - try: - with self.assertWarns(DeprecationWarning): - self.assertIs(Task.current_task(None), task) - with self.assertWarns(DeprecationWarning): - self.assertIs(Task.current_task(), task) - finally: - asyncio.set_event_loop(None) - - task = self.new_task(self.loop, coro(self.loop)) - self.loop.run_until_complete(task) - with self.assertWarns(DeprecationWarning): - self.assertIsNone(Task.current_task(loop=self.loop)) - def test_current_task(self): self.assertIsNone(asyncio.current_task(loop=self.loop)) @@ -2305,16 +2279,6 @@ class BaseTaskTests: self.assertIsInstance(exception, Exception) self.assertEqual(exception.args, ("foo", )) - def test_all_tasks_deprecated(self): - Task = self.__class__.Task - - async def coro(): - with self.assertWarns(DeprecationWarning): - assert Task.all_tasks(self.loop) == {t} - - t = self.new_task(self.loop, coro()) - self.loop.run_until_complete(t) - def test_log_destroyed_pending_task(self): Task = self.__class__.Task @@ -2337,15 +2301,7 @@ class BaseTaskTests: self.assertEqual(asyncio.all_tasks(loop=self.loop), {task}) - # See http://bugs.python.org/issue29271 for details: - asyncio.set_event_loop(self.loop) - try: - with self.assertWarns(DeprecationWarning): - self.assertEqual(Task.all_tasks(), {task}) - with self.assertWarns(DeprecationWarning): - self.assertEqual(Task.all_tasks(None), {task}) - finally: - asyncio.set_event_loop(None) + asyncio.set_event_loop(None) # execute the task so it waits for future self.loop._run_once() @@ -3043,8 +2999,6 @@ class BaseTaskIntrospectionTests: self.assertEqual(asyncio.all_tasks(loop), set()) self._register_task(task) self.assertEqual(asyncio.all_tasks(loop), set()) - with self.assertWarns(DeprecationWarning): - self.assertEqual(asyncio.Task.all_tasks(loop), {task}) self._unregister_task(task) def test__enter_task(self): diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py index 10bd46dea19..2c7d52a15bb 100644 --- a/Lib/test/test_asyncio/test_unix_events.py +++ b/Lib/test/test_asyncio/test_unix_events.py @@ -14,7 +14,7 @@ import tempfile import threading import unittest from unittest import mock -from test import support +from test.support import os_helper from test.support import socket_helper if sys.platform == 'win32': @@ -467,19 +467,19 @@ class SelectorEventLoopUnixSockSendfileTests(test_utils.TestCase): @classmethod def setUpClass(cls): - with open(support.TESTFN, 'wb') as fp: + with open(os_helper.TESTFN, 'wb') as fp: fp.write(cls.DATA) super().setUpClass() @classmethod def tearDownClass(cls): - support.unlink(support.TESTFN) + os_helper.unlink(os_helper.TESTFN) super().tearDownClass() def setUp(self): self.loop = asyncio.new_event_loop() self.set_event_loop(self.loop) - self.file = open(support.TESTFN, 'rb') + self.file = open(os_helper.TESTFN, 'rb') self.addCleanup(self.file.close) super().setUp() diff --git a/Lib/test/test_asyncio/utils.py b/Lib/test/test_asyncio/utils.py index 804db9166fe..34da7390e1b 100644 --- a/Lib/test/test_asyncio/utils.py +++ b/Lib/test/test_asyncio/utils.py @@ -34,6 +34,7 @@ from asyncio import futures from asyncio import tasks from asyncio.log import logger from test import support +from test.support import threading_helper def data_file(filename): @@ -546,7 +547,7 @@ class TestCase(unittest.TestCase): def setUp(self): self._get_running_loop = events._get_running_loop events._get_running_loop = lambda: None - self._thread_cleanup = support.threading_setup() + self._thread_cleanup = threading_helper.threading_setup() def tearDown(self): self.unpatch_get_running_loop() @@ -558,7 +559,7 @@ class TestCase(unittest.TestCase): self.assertEqual(sys.exc_info(), (None, None, None)) self.doCleanups() - support.threading_cleanup(*self._thread_cleanup) + threading_helper.threading_cleanup(*self._thread_cleanup) support.reap_children() diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py index 3c3abe41917..2cee6fb2e99 100644 --- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -11,6 +11,7 @@ import threading from test import support from test.support import socket_helper +from test.support import threading_helper from io import BytesIO if support.PGO: @@ -323,7 +324,7 @@ class DispatcherWithSendTests(unittest.TestCase): def tearDown(self): asyncore.close_all() - @support.reap_threads + @threading_helper.reap_threads def test_send(self): evt = threading.Event() sock = socket.socket() @@ -360,7 +361,7 @@ class DispatcherWithSendTests(unittest.TestCase): self.assertEqual(cap.getvalue(), data*2) finally: - support.join_thread(t) + threading_helper.join_thread(t) @unittest.skipUnless(hasattr(asyncore, 'file_wrapper'), @@ -766,7 +767,7 @@ class BaseTestAPI: self.assertTrue(s.socket.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)) - @support.reap_threads + @threading_helper.reap_threads def test_quick_connect(self): # see: http://bugs.python.org/issue10340 if self.family not in (socket.AF_INET, getattr(socket, "AF_INET6", object())): @@ -788,7 +789,7 @@ class BaseTestAPI: except OSError: pass finally: - support.join_thread(t) + threading_helper.join_thread(t) class TestAPI_UseIPv4Sockets(BaseTestAPI): family = socket.AF_INET diff --git a/Lib/test/test_audit.py b/Lib/test/test_audit.py index f405c692397..f79edbc4bd0 100644 --- a/Lib/test/test_audit.py +++ b/Lib/test/test_audit.py @@ -51,22 +51,6 @@ class AuditTest(unittest.TestCase): def test_block_add_hook_baseexception(self): self.do_test("test_block_add_hook_baseexception") - def test_finalize_hooks(self): - returncode, events, stderr = self.run_python("test_finalize_hooks") - if stderr: - print(stderr, file=sys.stderr) - if returncode: - self.fail(stderr) - - firstId = events[0][2] - self.assertSequenceEqual( - [ - ("Created", " ", firstId), - ("cpython._PySys_ClearAuditHooks", " ", firstId), - ], - events, - ) - def test_pickle(self): support.import_module("pickle") diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py index 1dbeac41dc0..1f67e46cd22 100644 --- a/Lib/test/test_base64.py +++ b/Lib/test/test_base64.py @@ -1,9 +1,9 @@ import unittest -from test import support import base64 import binascii import os from array import array +from test.support import os_helper from test.support import script_helper @@ -647,8 +647,8 @@ class BaseXYTestCase(unittest.TestCase): class TestMain(unittest.TestCase): def tearDown(self): - if os.path.exists(support.TESTFN): - os.unlink(support.TESTFN) + if os.path.exists(os_helper.TESTFN): + os.unlink(os_helper.TESTFN) def get_output(self, *args): return script_helper.assert_python_ok('-m', 'base64', *args).out @@ -662,9 +662,9 @@ class TestMain(unittest.TestCase): )) def test_encode_file(self): - with open(support.TESTFN, 'wb') as fp: + with open(os_helper.TESTFN, 'wb') as fp: fp.write(b'a\xffb\n') - output = self.get_output('-e', support.TESTFN) + output = self.get_output('-e', os_helper.TESTFN) self.assertEqual(output.rstrip(), b'Yf9iCg==') def test_encode_from_stdin(self): @@ -674,9 +674,9 @@ class TestMain(unittest.TestCase): self.assertIsNone(err) def test_decode(self): - with open(support.TESTFN, 'wb') as fp: + with open(os_helper.TESTFN, 'wb') as fp: fp.write(b'Yf9iCg==') - output = self.get_output('-d', support.TESTFN) + output = self.get_output('-d', os_helper.TESTFN) self.assertEqual(output.rstrip(), b'a\xffb') if __name__ == '__main__': diff --git a/Lib/test/test_bdb.py b/Lib/test/test_bdb.py index 6e82cce1f41..ae168805678 100644 --- a/Lib/test/test_bdb.py +++ b/Lib/test/test_bdb.py @@ -726,7 +726,7 @@ class StateTestCase(BaseTestCase): ('line', 2, 'tfunc_import'), ('step', ), ('line', 3, 'tfunc_import'), ('quit', ), ] - skip = ('importlib*', 'zipimport', TEST_MODULE) + skip = ('importlib*', 'zipimport', 'encodings.*', TEST_MODULE) with TracerRun(self, skip=skip) as tracer: tracer.runcall(tfunc_import) diff --git a/Lib/test/test_binhex.py b/Lib/test/test_binhex.py index 86ca37ce1b9..5e59f576151 100644 --- a/Lib/test/test_binhex.py +++ b/Lib/test/test_binhex.py @@ -5,22 +5,27 @@ """ import unittest from test import support +from test.support import import_helper +from test.support import os_helper +from test.support import warnings_helper -with support.check_warnings(('', DeprecationWarning)): - import binhex + +with warnings_helper.check_warnings(('', DeprecationWarning)): + binhex = import_helper.import_fresh_module('binhex') class BinHexTestCase(unittest.TestCase): def setUp(self): - self.fname1 = support.TESTFN + "1" - self.fname2 = support.TESTFN + "2" - self.fname3 = support.TESTFN + "very_long_filename__very_long_filename__very_long_filename__very_long_filename__" + # binhex supports only file names encodable to Latin1 + self.fname1 = os_helper.TESTFN_ASCII + "1" + self.fname2 = os_helper.TESTFN_ASCII + "2" + self.fname3 = os_helper.TESTFN_ASCII + "very_long_filename__very_long_filename__very_long_filename__very_long_filename__" def tearDown(self): - support.unlink(self.fname1) - support.unlink(self.fname2) - support.unlink(self.fname3) + os_helper.unlink(self.fname1) + os_helper.unlink(self.fname2) + os_helper.unlink(self.fname3) DATA = b'Jack is my hero' diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py index 909a59a9d2a..7b3a3859e08 100644 --- a/Lib/test/test_bool.py +++ b/Lib/test/test_bool.py @@ -2,6 +2,7 @@ import unittest from test import support +from test.support import os_helper import os @@ -18,20 +19,11 @@ class BoolTest(unittest.TestCase): self.assertRaises(TypeError, int.__new__, bool, 0) - def test_print(self): - try: - with open(support.TESTFN, "w") as fo: - print(False, True, file=fo) - with open(support.TESTFN, "r") as fi: - self.assertEqual(fi.read(), 'False True\n') - finally: - os.remove(support.TESTFN) - def test_repr(self): self.assertEqual(repr(False), 'False') self.assertEqual(repr(True), 'True') - self.assertEqual(eval(repr(False)), False) - self.assertEqual(eval(repr(True)), True) + self.assertIs(eval(repr(False)), False) + self.assertIs(eval(repr(True)), True) def test_str(self): self.assertEqual(str(False), 'False') @@ -243,11 +235,11 @@ class BoolTest(unittest.TestCase): def test_fileclosed(self): try: - with open(support.TESTFN, "w") as f: + with open(os_helper.TESTFN, "w") as f: self.assertIs(f.closed, False) self.assertIs(f.closed, True) finally: - os.remove(support.TESTFN) + os.remove(os_helper.TESTFN) def test_types(self): # types are always true. diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py index d440bcf7e0f..468c6ea9def 100644 --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -16,6 +16,7 @@ import contextlib import unittest from test import support +from test.support import os_helper from itertools import permutations, product from random import randrange, sample, choice import warnings @@ -39,7 +40,7 @@ except ImportError: ctypes = None try: - with support.EnvironmentVarGuard() as os.environ, \ + with os_helper.EnvironmentVarGuard() as os.environ, \ warnings.catch_warnings(): from numpy import ndarray as numpy_array except ImportError: diff --git a/Lib/test/test_bufio.py b/Lib/test/test_bufio.py index fea6da491e4..17151b13615 100644 --- a/Lib/test/test_bufio.py +++ b/Lib/test/test_bufio.py @@ -1,5 +1,6 @@ import unittest from test import support +from test.support import os_helper import io # C implementation. import _pyio as pyio # Python implementation. @@ -17,18 +18,18 @@ class BufferSizeTest: # .readline()s deliver what we wrote. # Ensure we can open TESTFN for writing. - support.unlink(support.TESTFN) + os_helper.unlink(os_helper.TESTFN) # Since C doesn't guarantee we can write/read arbitrary bytes in text # files, use binary mode. - f = self.open(support.TESTFN, "wb") + f = self.open(os_helper.TESTFN, "wb") try: # write once with \n and once without f.write(s) f.write(b"\n") f.write(s) f.close() - f = open(support.TESTFN, "rb") + f = open(os_helper.TESTFN, "rb") line = f.readline() self.assertEqual(line, s + b"\n") line = f.readline() @@ -37,7 +38,7 @@ class BufferSizeTest: self.assertFalse(line) # Must be at EOF f.close() finally: - support.unlink(support.TESTFN) + os_helper.unlink(os_helper.TESTFN) def drive_one(self, pattern): for length in lengths: diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 290ba2cad8e..40df7b606ae 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1521,6 +1521,14 @@ class BuiltinTest(unittest.TestCase): self.assertRaises(TypeError, vars, 42) self.assertEqual(vars(self.C_get_vars()), {'a':2}) + def iter_error(self, iterable, error): + """Collect `iterable` into a list, catching an expected `error`.""" + items = [] + with self.assertRaises(error): + for item in iterable: + items.append(item) + return items + def test_zip(self): a = (1, 2, 3) b = (4, 5, 6) @@ -1573,6 +1581,66 @@ class BuiltinTest(unittest.TestCase): z1 = zip(a, b) self.check_iter_pickle(z1, t, proto) + def test_zip_pickle_strict(self): + a = (1, 2, 3) + b = (4, 5, 6) + t = [(1, 4), (2, 5), (3, 6)] + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + z1 = zip(a, b, strict=True) + self.check_iter_pickle(z1, t, proto) + + def test_zip_pickle_strict_fail(self): + a = (1, 2, 3) + b = (4, 5, 6, 7) + t = [(1, 4), (2, 5), (3, 6)] + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + z1 = zip(a, b, strict=True) + z2 = pickle.loads(pickle.dumps(z1, proto)) + self.assertEqual(self.iter_error(z1, ValueError), t) + self.assertEqual(self.iter_error(z2, ValueError), t) + + def test_zip_pickle_stability(self): + # Pickles of zip((1, 2, 3), (4, 5, 6)) dumped from 3.9: + pickles = [ + b'citertools\nizip\np0\n(c__builtin__\niter\np1\n((I1\nI2\nI3\ntp2\ntp3\nRp4\nI0\nbg1\n((I4\nI5\nI6\ntp5\ntp6\nRp7\nI0\nbtp8\nRp9\n.', + b'citertools\nizip\nq\x00(c__builtin__\niter\nq\x01((K\x01K\x02K\x03tq\x02tq\x03Rq\x04K\x00bh\x01((K\x04K\x05K\x06tq\x05tq\x06Rq\x07K\x00btq\x08Rq\t.', + b'\x80\x02citertools\nizip\nq\x00c__builtin__\niter\nq\x01K\x01K\x02K\x03\x87q\x02\x85q\x03Rq\x04K\x00bh\x01K\x04K\x05K\x06\x87q\x05\x85q\x06Rq\x07K\x00b\x86q\x08Rq\t.', + b'\x80\x03cbuiltins\nzip\nq\x00cbuiltins\niter\nq\x01K\x01K\x02K\x03\x87q\x02\x85q\x03Rq\x04K\x00bh\x01K\x04K\x05K\x06\x87q\x05\x85q\x06Rq\x07K\x00b\x86q\x08Rq\t.', + b'\x80\x04\x95L\x00\x00\x00\x00\x00\x00\x00\x8c\x08builtins\x94\x8c\x03zip\x94\x93\x94\x8c\x08builtins\x94\x8c\x04iter\x94\x93\x94K\x01K\x02K\x03\x87\x94\x85\x94R\x94K\x00bh\x05K\x04K\x05K\x06\x87\x94\x85\x94R\x94K\x00b\x86\x94R\x94.', + b'\x80\x05\x95L\x00\x00\x00\x00\x00\x00\x00\x8c\x08builtins\x94\x8c\x03zip\x94\x93\x94\x8c\x08builtins\x94\x8c\x04iter\x94\x93\x94K\x01K\x02K\x03\x87\x94\x85\x94R\x94K\x00bh\x05K\x04K\x05K\x06\x87\x94\x85\x94R\x94K\x00b\x86\x94R\x94.', + ] + for protocol, dump in enumerate(pickles): + z1 = zip((1, 2, 3), (4, 5, 6)) + z2 = zip((1, 2, 3), (4, 5, 6), strict=False) + z3 = pickle.loads(dump) + l3 = list(z3) + self.assertEqual(type(z3), zip) + self.assertEqual(pickle.dumps(z1, protocol), dump) + self.assertEqual(pickle.dumps(z2, protocol), dump) + self.assertEqual(list(z1), l3) + self.assertEqual(list(z2), l3) + + def test_zip_pickle_strict_stability(self): + # Pickles of zip((1, 2, 3), (4, 5), strict=True) dumped from 3.10: + pickles = [ + b'citertools\nizip\np0\n(c__builtin__\niter\np1\n((I1\nI2\nI3\ntp2\ntp3\nRp4\nI0\nbg1\n((I4\nI5\ntp5\ntp6\nRp7\nI0\nbtp8\nRp9\nI01\nb.', + b'citertools\nizip\nq\x00(c__builtin__\niter\nq\x01((K\x01K\x02K\x03tq\x02tq\x03Rq\x04K\x00bh\x01((K\x04K\x05tq\x05tq\x06Rq\x07K\x00btq\x08Rq\tI01\nb.', + b'\x80\x02citertools\nizip\nq\x00c__builtin__\niter\nq\x01K\x01K\x02K\x03\x87q\x02\x85q\x03Rq\x04K\x00bh\x01K\x04K\x05\x86q\x05\x85q\x06Rq\x07K\x00b\x86q\x08Rq\t\x88b.', + b'\x80\x03cbuiltins\nzip\nq\x00cbuiltins\niter\nq\x01K\x01K\x02K\x03\x87q\x02\x85q\x03Rq\x04K\x00bh\x01K\x04K\x05\x86q\x05\x85q\x06Rq\x07K\x00b\x86q\x08Rq\t\x88b.', + b'\x80\x04\x95L\x00\x00\x00\x00\x00\x00\x00\x8c\x08builtins\x94\x8c\x03zip\x94\x93\x94\x8c\x08builtins\x94\x8c\x04iter\x94\x93\x94K\x01K\x02K\x03\x87\x94\x85\x94R\x94K\x00bh\x05K\x04K\x05\x86\x94\x85\x94R\x94K\x00b\x86\x94R\x94\x88b.', + b'\x80\x05\x95L\x00\x00\x00\x00\x00\x00\x00\x8c\x08builtins\x94\x8c\x03zip\x94\x93\x94\x8c\x08builtins\x94\x8c\x04iter\x94\x93\x94K\x01K\x02K\x03\x87\x94\x85\x94R\x94K\x00bh\x05K\x04K\x05\x86\x94\x85\x94R\x94K\x00b\x86\x94R\x94\x88b.', + ] + a = (1, 2, 3) + b = (4, 5) + t = [(1, 4), (2, 5)] + for protocol, dump in enumerate(pickles): + z1 = zip(a, b, strict=True) + z2 = pickle.loads(dump) + self.assertEqual(pickle.dumps(z1, protocol), dump) + self.assertEqual(type(z2), zip) + self.assertEqual(self.iter_error(z1, ValueError), t) + self.assertEqual(self.iter_error(z2, ValueError), t) + def test_zip_bad_iterable(self): exception = TypeError() @@ -1585,6 +1653,88 @@ class BuiltinTest(unittest.TestCase): self.assertIs(cm.exception, exception) + def test_zip_strict(self): + self.assertEqual(tuple(zip((1, 2, 3), 'abc', strict=True)), + ((1, 'a'), (2, 'b'), (3, 'c'))) + self.assertRaises(ValueError, tuple, + zip((1, 2, 3, 4), 'abc', strict=True)) + self.assertRaises(ValueError, tuple, + zip((1, 2), 'abc', strict=True)) + self.assertRaises(ValueError, tuple, + zip((1, 2), (1, 2), 'abc', strict=True)) + + def test_zip_strict_iterators(self): + x = iter(range(5)) + y = [0] + z = iter(range(5)) + self.assertRaises(ValueError, list, + (zip(x, y, z, strict=True))) + self.assertEqual(next(x), 2) + self.assertEqual(next(z), 1) + + def test_zip_strict_error_handling(self): + + class Error(Exception): + pass + + class Iter: + def __init__(self, size): + self.size = size + def __iter__(self): + return self + def __next__(self): + self.size -= 1 + if self.size < 0: + raise Error + return self.size + + l1 = self.iter_error(zip("AB", Iter(1), strict=True), Error) + self.assertEqual(l1, [("A", 0)]) + l2 = self.iter_error(zip("AB", Iter(2), "A", strict=True), ValueError) + self.assertEqual(l2, [("A", 1, "A")]) + l3 = self.iter_error(zip("AB", Iter(2), "ABC", strict=True), Error) + self.assertEqual(l3, [("A", 1, "A"), ("B", 0, "B")]) + l4 = self.iter_error(zip("AB", Iter(3), strict=True), ValueError) + self.assertEqual(l4, [("A", 2), ("B", 1)]) + l5 = self.iter_error(zip(Iter(1), "AB", strict=True), Error) + self.assertEqual(l5, [(0, "A")]) + l6 = self.iter_error(zip(Iter(2), "A", strict=True), ValueError) + self.assertEqual(l6, [(1, "A")]) + l7 = self.iter_error(zip(Iter(2), "ABC", strict=True), Error) + self.assertEqual(l7, [(1, "A"), (0, "B")]) + l8 = self.iter_error(zip(Iter(3), "AB", strict=True), ValueError) + self.assertEqual(l8, [(2, "A"), (1, "B")]) + + def test_zip_strict_error_handling_stopiteration(self): + + class Iter: + def __init__(self, size): + self.size = size + def __iter__(self): + return self + def __next__(self): + self.size -= 1 + if self.size < 0: + raise StopIteration + return self.size + + l1 = self.iter_error(zip("AB", Iter(1), strict=True), ValueError) + self.assertEqual(l1, [("A", 0)]) + l2 = self.iter_error(zip("AB", Iter(2), "A", strict=True), ValueError) + self.assertEqual(l2, [("A", 1, "A")]) + l3 = self.iter_error(zip("AB", Iter(2), "ABC", strict=True), ValueError) + self.assertEqual(l3, [("A", 1, "A"), ("B", 0, "B")]) + l4 = self.iter_error(zip("AB", Iter(3), strict=True), ValueError) + self.assertEqual(l4, [("A", 2), ("B", 1)]) + l5 = self.iter_error(zip(Iter(1), "AB", strict=True), ValueError) + self.assertEqual(l5, [(0, "A")]) + l6 = self.iter_error(zip(Iter(2), "A", strict=True), ValueError) + self.assertEqual(l6, [(1, "A")]) + l7 = self.iter_error(zip(Iter(2), "ABC", strict=True), ValueError) + self.assertEqual(l7, [(1, "A"), (0, "B")]) + l8 = self.iter_error(zip(Iter(3), "AB", strict=True), ValueError) + self.assertEqual(l8, [(2, "A"), (1, "B")]) + def test_format(self): # Test the basic machinery of the format() builtin. Don't test # the specifics of the various formatters diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index 770e2c5592c..61b4b9162cc 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -16,6 +16,7 @@ import textwrap import unittest import test.support +from test.support import import_helper import test.string_tests import test.list_tests from test.support import bigaddrspacetest, MAX_Py_ssize_t @@ -967,7 +968,7 @@ class BaseBytesTest: self.assertEqual(c, b'hllo') def test_sq_item(self): - _testcapi = test.support.import_module('_testcapi') + _testcapi = import_helper.import_module('_testcapi') obj = self.type2test((42,)) with self.assertRaises(IndexError): _testcapi.sequence_getitem(obj, -2) @@ -1024,8 +1025,8 @@ class BytesTest(BaseBytesTest, unittest.TestCase): # Test PyBytes_FromFormat() def test_from_format(self): - ctypes = test.support.import_module('ctypes') - _testcapi = test.support.import_module('_testcapi') + ctypes = import_helper.import_module('ctypes') + _testcapi = import_helper.import_module('_testcapi') from ctypes import pythonapi, py_object from ctypes import ( c_int, c_uint, diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py index 78b95d88faa..ccc5e4df83a 100644 --- a/Lib/test/test_bz2.py +++ b/Lib/test/test_bz2.py @@ -12,13 +12,15 @@ import random import shutil import subprocess import threading -from test.support import unlink +from test.support import import_helper +from test.support import threading_helper +from test.support.os_helper import unlink import _compression import sys # Skip tests if the bz2 module doesn't exist. -bz2 = support.import_module('bz2') +bz2 = import_helper.import_module('bz2') from bz2 import BZ2File, BZ2Compressor, BZ2Decompressor has_cmdline_bunzip2 = None @@ -69,7 +71,7 @@ class BaseTest(unittest.TestCase): # simply use the bigger test data for all tests. test_size = 0 BIG_TEXT = bytearray(128*1024) - for fname in glob.glob(os.path.join(os.path.dirname(__file__), '*.py')): + for fname in glob.glob(os.path.join(glob.escape(os.path.dirname(__file__)), '*.py')): with open(fname, 'rb') as fh: test_size += fh.readinto(memoryview(BIG_TEXT)[test_size:]) if test_size > 128*1024: @@ -502,7 +504,7 @@ class BZ2FileTest(BaseTest): for i in range(5): f.write(data) threads = [threading.Thread(target=comp) for i in range(nthreads)] - with support.start_threads(threads): + with threading_helper.start_threads(threads): pass def testMixedIterationAndReads(self): diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index 6241d114d33..7c7ec1c931a 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -564,6 +564,30 @@ class CalendarTestCase(unittest.TestCase): new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) self.assertEqual(old_october, new_october) + def test_locale_html_calendar_custom_css_class_month_name(self): + try: + cal = calendar.LocaleHTMLCalendar(locale='') + local_month = cal.formatmonthname(2010, 10, 10) + except locale.Error: + # cannot set the system default locale -- skip rest of test + raise unittest.SkipTest('cannot set the system default locale') + self.assertIn('class="month"', local_month) + cal.cssclass_month_head = "text-center month" + local_month = cal.formatmonthname(2010, 10, 10) + self.assertIn('class="text-center month"', local_month) + + def test_locale_html_calendar_custom_css_class_weekday(self): + try: + cal = calendar.LocaleHTMLCalendar(locale='') + local_weekday = cal.formatweekday(6) + except locale.Error: + # cannot set the system default locale -- skip rest of test + raise unittest.SkipTest('cannot set the system default locale') + self.assertIn('class="sun"', local_weekday) + cal.cssclasses_weekday_head = ["mon2", "tue2", "wed2", "thu2", "fri2", "sat2", "sun2"] + local_weekday = cal.formatweekday(6) + self.assertIn('class="sun2"', local_weekday) + def test_itermonthdays3(self): # ensure itermonthdays3 doesn't overflow after datetime.MAXYEAR list(calendar.Calendar().itermonthdays3(datetime.MAXYEAR, 12)) diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 5c7526aa7ec..55027c9cbcd 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -17,6 +17,8 @@ import importlib.machinery import importlib.util from test import support from test.support import MISSING_C_DOCSTRINGS +from test.support import import_helper +from test.support import threading_helper from test.support.script_helper import assert_python_failure, assert_python_ok try: import _posixsubprocess @@ -24,7 +26,7 @@ except ImportError: _posixsubprocess = None # Skip this test if the _testcapi module isn't available. -_testcapi = support.import_module('_testcapi') +_testcapi = import_helper.import_module('_testcapi') import _testinternalcapi @@ -67,7 +69,10 @@ class CAPITest(unittest.TestCase): self.assertTrue(err.rstrip().startswith( b'Fatal Python error: ' b'PyThreadState_Get: ' - b'current thread state is NULL (released GIL?)')) + b'the function must be called with the GIL held, ' + b'but the GIL is released ' + b'(the current Python thread state is NULL)'), + err) def test_memoryview_from_NULL_pointer(self): self.assertRaises(ValueError, _testcapi.make_memoryview_from_NULL_pointer) @@ -473,6 +478,11 @@ class CAPITest(unittest.TestCase): self.assertEqual(ref(), inst) self.assertEqual(inst.weakreflist, ref) + def test_heaptype_with_buffer(self): + inst = _testcapi.HeapCTypeWithBuffer() + b = bytes(inst) + self.assertEqual(b, b"1234") + def test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_once(self): subclass_instance = _testcapi.HeapCTypeSubclass() type_refcnt = sys.getrefcount(_testcapi.HeapCTypeSubclass) @@ -507,6 +517,14 @@ class CAPITest(unittest.TestCase): # Test that subtype_dealloc decref the newly assigned __class__ only once self.assertEqual(new_type_refcnt, sys.getrefcount(_testcapi.HeapCTypeSubclass)) + def test_heaptype_with_setattro(self): + obj = _testcapi.HeapCTypeSetattr() + self.assertEqual(obj.pvalue, 10) + obj.value = 12 + self.assertEqual(obj.pvalue, 12) + del obj.value + self.assertEqual(obj.pvalue, 0) + def test_pynumber_tobase(self): from _testcapi import pynumber_tobase self.assertEqual(pynumber_tobase(123, 2), '0b1111011') @@ -575,7 +593,7 @@ class TestPendingCalls(unittest.TestCase): threads = [threading.Thread(target=self.pendingcalls_thread, args=(context,)) for i in range(context.nThreads)] - with support.start_threads(threads): + with threading_helper.start_threads(threads): self.pendingcalls_wait(context.l, n, context) def pendingcalls_thread(self, context): @@ -618,6 +636,27 @@ class SubinterpreterTest(unittest.TestCase): self.assertNotEqual(pickle.load(f), id(sys.modules)) self.assertNotEqual(pickle.load(f), id(builtins)) + def test_subinterps_recent_language_features(self): + r, w = os.pipe() + code = """if 1: + import pickle + with open({:d}, "wb") as f: + + @(lambda x:x) # Py 3.9 + def noop(x): return x + + a = (b := f'1{{2}}3') + noop('x') # Py 3.8 (:=) / 3.6 (f'') + + async def foo(arg): return await arg # Py 3.5 + + pickle.dump(dict(a=a, b=b), f) + """.format(w) + + with open(r, "rb") as f: + ret = support.run_in_subinterp(code) + self.assertEqual(ret, 0) + self.assertEqual(pickle.load(f), {'a': '123x', 'b': '123'}) + def test_mutate_exception(self): """ Exceptions saved in global module state get shared between @@ -634,7 +673,7 @@ class SubinterpreterTest(unittest.TestCase): class TestThreadState(unittest.TestCase): - @support.reap_threads + @threading_helper.reap_threads def test_thread_state(self): # some extra thread-state tests driven via _testcapi def target(): diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py index ab8677199f3..101942de947 100644 --- a/Lib/test/test_cgi.py +++ b/Lib/test/test_cgi.py @@ -128,6 +128,20 @@ class CgiTests(unittest.TestCase): 'file': [b'Testing 123.\n'], 'title': ['']} self.assertEqual(result, expected) + def test_parse_multipart_without_content_length(self): + POSTDATA = '''--JfISa01 +Content-Disposition: form-data; name="submit-name" + +just a string + +--JfISa01-- +''' + fp = BytesIO(POSTDATA.encode('latin1')) + env = {'boundary': 'JfISa01'.encode('latin1')} + result = cgi.parse_multipart(fp, env) + expected = {'submit-name': ['just a string\n']} + self.assertEqual(result, expected) + def test_parse_multipart_invalid_encoding(self): BOUNDARY = "JfISa01" POSTDATA = """--JfISa01 diff --git a/Lib/test/test_cgitb.py b/Lib/test/test_cgitb.py index 8991bc1ff34..590ffdea112 100644 --- a/Lib/test/test_cgitb.py +++ b/Lib/test/test_cgitb.py @@ -1,4 +1,4 @@ -from test.support import temp_dir +from test.support.os_helper import temp_dir from test.support.script_helper import assert_python_failure import unittest import sys @@ -41,8 +41,9 @@ class TestCgitb(unittest.TestCase): rc, out, err = assert_python_failure( '-c', ('import cgitb; cgitb.enable(logdir=%s); ' - 'raise ValueError("Hello World")') % repr(tracedir)) - out = out.decode(sys.getfilesystemencoding()) + 'raise ValueError("Hello World")') % repr(tracedir), + PYTHONIOENCODING='utf-8') + out = out.decode() self.assertIn("ValueError", out) self.assertIn("Hello World", out) self.assertIn("<module>", out) @@ -56,8 +57,9 @@ class TestCgitb(unittest.TestCase): rc, out, err = assert_python_failure( '-c', ('import cgitb; cgitb.enable(format="text", logdir=%s); ' - 'raise ValueError("Hello World")') % repr(tracedir)) - out = out.decode(sys.getfilesystemencoding()) + 'raise ValueError("Hello World")') % repr(tracedir), + PYTHONIOENCODING='utf-8') + out = out.decode() self.assertIn("ValueError", out) self.assertIn("Hello World", out) self.assertNotIn('

', out) diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index 72440253303..4794d446f08 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -9,6 +9,7 @@ import tempfile import textwrap import unittest from test import support +from test.support import os_helper from test.support.script_helper import ( spawn_python, kill_python, assert_python_ok, assert_python_failure, interpreter_requires_environment @@ -141,11 +142,11 @@ class CmdLineTest(unittest.TestCase): # All good if execution is successful assert_python_ok('-c', 'pass') - @unittest.skipUnless(support.FS_NONASCII, 'need support.FS_NONASCII') + @unittest.skipUnless(os_helper.FS_NONASCII, 'need os_helper.FS_NONASCII') def test_non_ascii(self): # Test handling of non-ascii data command = ("assert(ord(%r) == %s)" - % (support.FS_NONASCII, ord(support.FS_NONASCII))) + % (os_helper.FS_NONASCII, ord(os_helper.FS_NONASCII))) assert_python_ok('-c', command) # On Windows, pass bytes to subprocess doesn't test how Python decodes the @@ -463,8 +464,8 @@ class CmdLineTest(unittest.TestCase): # Issue #15001: PyRun_SimpleFileExFlags() did crash because it kept a # borrowed reference to the dict of __main__ module and later modify # the dict whereas the module was destroyed - filename = support.TESTFN - self.addCleanup(support.unlink, filename) + filename = os_helper.TESTFN + self.addCleanup(os_helper.unlink, filename) with open(filename, "w") as script: print("import sys", file=script) print("del sys.modules['__main__']", file=script) @@ -499,7 +500,7 @@ class CmdLineTest(unittest.TestCase): # dummyvar to prevent extraneous -E dummyvar="") self.assertEqual(out.strip(), b'1 1 1') - with support.temp_cwd() as tmpdir: + with os_helper.temp_cwd() as tmpdir: fake = os.path.join(tmpdir, "uuid.py") main = os.path.join(tmpdir, "main.py") with open(fake, "w") as f: @@ -561,7 +562,7 @@ class CmdLineTest(unittest.TestCase): elif opt is not None: args[:0] = ['-X', f'pycache_prefix={opt}'] with self.subTest(envval=envval, opt=opt): - with support.temp_cwd(): + with os_helper.temp_cwd(): assert_python_ok(*args, **env) def run_xdev(self, *args, check_exitcode=True, xdev=True): @@ -644,7 +645,8 @@ class CmdLineTest(unittest.TestCase): def check_warnings_filters(self, cmdline_option, envvar, use_pywarning=False): if use_pywarning: - code = ("import sys; from test.support import import_fresh_module; " + code = ("import sys; from test.support.import_helper import " + "import_fresh_module; " "warnings = import_fresh_module('warnings', blocked=['_warnings']); ") else: code = "import sys, warnings; " diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py index 0c5e362feea..45cb1a7b74e 100644 --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -303,6 +303,11 @@ class CodeopTests(unittest.TestCase): self.assertNotEqual(compile_command("a = 1\n", "abc").co_filename, compile("a = 1\n", "def", 'single').co_filename) + def test_warning(self): + # Test that the warning is only returned once. + with support.check_warnings((".*literal", SyntaxWarning)) as w: + compile_command("0 is 0") + self.assertEqual(len(w.warnings), 1) if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index a8d3337ef52..7c7f8655b0f 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -7,6 +7,7 @@ import inspect import operator import pickle from random import choice, randrange +from itertools import product, chain, combinations import string import sys from test import support @@ -2122,29 +2123,6 @@ class TestCounter(unittest.TestCase): set_result = setop(set(p.elements()), set(q.elements())) self.assertEqual(counter_result, dict.fromkeys(set_result, 1)) - def test_subset_superset_not_implemented(self): - # Verify that multiset comparison operations are not implemented. - - # These operations were intentionally omitted because multiset - # comparison semantics conflict with existing dict equality semantics. - - # For multisets, we would expect that if p<=q and p>=q are both true, - # then p==q. However, dict equality semantics require that p!=q when - # one of sets contains an element with a zero count and the other - # doesn't. - - p = Counter(a=1, b=0) - q = Counter(a=1, c=0) - self.assertNotEqual(p, q) - with self.assertRaises(TypeError): - p < q - with self.assertRaises(TypeError): - p <= q - with self.assertRaises(TypeError): - p > q - with self.assertRaises(TypeError): - p >= q - def test_inplace_operations(self): elements = 'abcd' for i in range(1000): @@ -2219,6 +2197,47 @@ class TestCounter(unittest.TestCase): self.assertTrue(c.called) self.assertEqual(dict(c), {'a': 5, 'b': 2, 'c': 1, 'd': 1, 'r':2 }) + def test_multiset_operations_equivalent_to_set_operations(self): + # When the multiplicities are all zero or one, multiset operations + # are guaranteed to be equivalent to the corresponding operations + # for regular sets. + s = list(product(('a', 'b', 'c'), range(2))) + powerset = chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) + counters = [Counter(dict(groups)) for groups in powerset] + for cp, cq in product(counters, repeat=2): + sp = set(cp.elements()) + sq = set(cq.elements()) + self.assertEqual(set(cp + cq), sp | sq) + self.assertEqual(set(cp - cq), sp - sq) + self.assertEqual(set(cp | cq), sp | sq) + self.assertEqual(set(cp & cq), sp & sq) + self.assertEqual(cp == cq, sp == sq) + self.assertEqual(cp != cq, sp != sq) + self.assertEqual(cp <= cq, sp <= sq) + self.assertEqual(cp >= cq, sp >= sq) + self.assertEqual(cp < cq, sp < sq) + self.assertEqual(cp > cq, sp > sq) + + def test_eq(self): + self.assertEqual(Counter(a=3, b=2, c=0), Counter('ababa')) + self.assertNotEqual(Counter(a=3, b=2), Counter('babab')) + + def test_le(self): + self.assertTrue(Counter(a=3, b=2, c=0) <= Counter('ababa')) + self.assertFalse(Counter(a=3, b=2) <= Counter('babab')) + + def test_lt(self): + self.assertTrue(Counter(a=3, b=1, c=0) < Counter('ababa')) + self.assertFalse(Counter(a=3, b=2, c=0) < Counter('ababa')) + + def test_ge(self): + self.assertTrue(Counter(a=2, b=1, c=0) >= Counter('aab')) + self.assertFalse(Counter(a=3, b=2, c=0) >= Counter('aabd')) + + def test_gt(self): + self.assertTrue(Counter(a=3, b=2, c=0) > Counter('aab')) + self.assertFalse(Counter(a=2, b=1, c=0) > Counter('aab')) + ################################################################################ ### Run tests diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 566ca27fca8..3dd8c8d1db8 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -7,7 +7,9 @@ import _ast import tempfile import types from test import support -from test.support import script_helper, FakePath +from test.support import script_helper +from test.support.os_helper import FakePath + class TestSpecifics(unittest.TestCase): diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py index b4061b79357..be1149a87fa 100644 --- a/Lib/test/test_compileall.py +++ b/Lib/test/test_compileall.py @@ -23,6 +23,7 @@ except ImportError: _have_multiprocessing = False from test import support +from test.support import os_helper from test.support import script_helper from .test_py_compile import without_source_date_epoch @@ -356,7 +357,7 @@ class CompileallTestsBase: except Exception: pass - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_ignore_symlink_destination(self): # Create folders for allowed files, symlinks and prohibited area allowed_path = os.path.join(self.directory, "test", "dir", "allowed") @@ -438,7 +439,7 @@ class CommandLineTestsBase: sys_path_writable = False break finally: - support.unlink(str(path)) + os_helper.unlink(str(path)) if directory_created: directory.rmdir() else: @@ -456,13 +457,15 @@ class CommandLineTestsBase: def assertRunOK(self, *args, **env_vars): rc, out, err = script_helper.assert_python_ok( - *self._get_run_args(args), **env_vars) + *self._get_run_args(args), **env_vars, + PYTHONIOENCODING='utf-8') self.assertEqual(b'', err) return out def assertRunNotOK(self, *args, **env_vars): rc, out, err = script_helper.assert_python_failure( - *self._get_run_args(args), **env_vars) + *self._get_run_args(args), **env_vars, + PYTHONIOENCODING='utf-8') return rc, out, err def assertCompiled(self, fn): @@ -475,7 +478,7 @@ class CommandLineTestsBase: def setUp(self): self.directory = tempfile.mkdtemp() - self.addCleanup(support.rmtree, self.directory) + self.addCleanup(os_helper.rmtree, self.directory) self.pkgdir = os.path.join(self.directory, 'foo') os.mkdir(self.pkgdir) self.pkgdir_cachedir = os.path.join(self.pkgdir, '__pycache__') @@ -623,7 +626,7 @@ class CommandLineTestsBase: self.assertCompiled(spamfn) self.assertCompiled(eggfn) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_symlink_loop(self): # Currently, compileall ignores symlinks to directories. # If that limitation is ever lifted, it should protect against @@ -821,7 +824,7 @@ class CommandLineTestsBase: except Exception: pass - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_ignore_symlink_destination(self): # Create folders for allowed files, symlinks and prohibited area allowed_path = os.path.join(self.directory, "test", "dir", "allowed") diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index dee5c7fa308..d1f241f7a60 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -500,22 +500,6 @@ class ComplexTest(unittest.TestCase): def test_neg(self): self.assertEqual(-(1+6j), -1-6j) - def test_file(self): - a = 3.33+4.43j - b = 5.1+2.3j - - fo = None - try: - fo = open(support.TESTFN, "w") - print(a, b, file=fo) - fo.close() - fo = open(support.TESTFN, "r") - self.assertEqual(fo.read(), ("%s %s\n" % (a, b))) - finally: - if (fo is not None) and (not fo.closed): - fo.close() - support.unlink(support.TESTFN) - def test_getnewargs(self): self.assertEqual((1+2j).__getnewargs__(), (1.0, 2.0)) self.assertEqual((1-2j).__getnewargs__(), (1.0, -2.0)) diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py index 40597ffee73..7da967ea6ce 100644 --- a/Lib/test/test_concurrent_futures.py +++ b/Lib/test/test_concurrent_futures.py @@ -1,10 +1,12 @@ from test import support +from test.support import threading_helper # Skip tests if _multiprocessing wasn't built. support.import_module('_multiprocessing') # Skip tests if sem_open implementation is broken. -support.import_module('multiprocessing.synchronize') +support.skip_if_broken_multiprocessing_synchronize() +from test.support import hashlib_helper from test.support.script_helper import assert_python_ok import contextlib @@ -100,11 +102,11 @@ def make_dummy_object(_): class BaseTestCase(unittest.TestCase): def setUp(self): - self._thread_key = support.threading_setup() + self._thread_key = threading_helper.threading_setup() def tearDown(self): support.reap_children() - support.threading_cleanup(*self._thread_key) + threading_helper.threading_cleanup(*self._thread_key) class ExecutorMixin: @@ -952,6 +954,7 @@ class ProcessPoolExecutorTest(ExecutorTest): self.assertIn('raise RuntimeError(123) # some comment', f1.getvalue()) + @hashlib_helper.requires_hashdigest('md5') def test_ressources_gced_in_workers(self): # Ensure that argument for a job are correctly gc-ed after the job # is finished @@ -1496,11 +1499,11 @@ _threads_key = None def setUpModule(): global _threads_key - _threads_key = support.threading_setup() + _threads_key = threading_helper.threading_setup() def tearDownModule(): - support.threading_cleanup(*_threads_key) + threading_helper.threading_cleanup(*_threads_key) multiprocessing.util._cleanup_tests() diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index 35f72fb216b..ba3d233f63d 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -357,7 +357,7 @@ class TestCopy(unittest.TestCase): pass tests = [None, 42, 2**100, 3.14, True, False, 1j, "hello", "hello\u1234", f.__code__, - NewStyle, Classic, max, property()] + NewStyle, range(10), Classic, max, property()] for x in tests: self.assertIs(copy.deepcopy(x), x) @@ -579,17 +579,6 @@ class TestCopy(unittest.TestCase): self.assertIsNot(y, x) self.assertIs(y.foo, y) - def test_deepcopy_range(self): - class I(int): - pass - x = range(I(10)) - y = copy.deepcopy(x) - self.assertIsNot(y, x) - self.assertEqual(y, x) - self.assertIsNot(y.stop, x.stop) - self.assertEqual(y.stop, x.stop) - self.assertIsInstance(y.stop, I) - # _reconstruct() def test_reconstruct_string(self): diff --git a/Lib/test/test_crashers.py b/Lib/test/test_crashers.py index 58dfd001da3..31b712028f8 100644 --- a/Lib/test/test_crashers.py +++ b/Lib/test/test_crashers.py @@ -11,7 +11,7 @@ import test.support from test.support.script_helper import assert_python_failure CRASHER_DIR = os.path.join(os.path.dirname(__file__), "crashers") -CRASHER_FILES = os.path.join(CRASHER_DIR, "*.py") +CRASHER_FILES = os.path.join(glob.escape(CRASHER_DIR), "*.py") infinite_loops = ["infinite_loop_re.py", "nasty_eq_vs_dict.py"] diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index a16d14019f3..d421be075ca 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -14,6 +14,12 @@ from itertools import permutations from textwrap import dedent from collections import OrderedDict + +class BadIterable: + def __iter__(self): + raise OSError + + class Test_Csv(unittest.TestCase): """ Test the underlying C csv parser in ways that are not appropriate @@ -40,9 +46,15 @@ class Test_Csv(unittest.TestCase): def test_reader_arg_valid(self): self._test_arg_valid(csv.reader, []) + self.assertRaises(OSError, csv.reader, BadIterable()) def test_writer_arg_valid(self): self._test_arg_valid(csv.writer, StringIO()) + class BadWriter: + @property + def write(self): + raise OSError + self.assertRaises(OSError, csv.writer, BadWriter()) def _test_default_attrs(self, ctor, *args): obj = ctor(*args) @@ -141,6 +153,7 @@ class Test_Csv(unittest.TestCase): self._write_test([None], '""') self._write_error_test(csv.Error, [None], quoting = csv.QUOTE_NONE) # Check that exceptions are passed up the chain + self._write_error_test(OSError, BadIterable()) class BadList: def __len__(self): return 10; @@ -230,6 +243,12 @@ class Test_Csv(unittest.TestCase): fileobj.seek(0) self.assertEqual(fileobj.read(), 'a\r\n""\r\n') + def test_writerows_errors(self): + with TemporaryFile("w+", newline='') as fileobj: + writer = csv.writer(fileobj) + self.assertRaises(TypeError, writer.writerows, None) + self.assertRaises(OSError, writer.writerows, BadIterable()) + @support.cpython_only def test_writerows_legacy_strings(self): import _testcapi @@ -334,7 +353,6 @@ class Test_Csv(unittest.TestCase): def test_roundtrip_quoteed_newlines(self): with TemporaryFile("w+", newline='') as fileobj: writer = csv.writer(fileobj) - self.assertRaises(TypeError, writer.writerows, None) rows = [['a\nb','b'],['c','x\r\nd']] writer.writerows(rows) fileobj.seek(0) diff --git a/Lib/test/test_ctypes.py b/Lib/test/test_ctypes.py index 68268992e9f..b0a12c97347 100644 --- a/Lib/test/test_ctypes.py +++ b/Lib/test/test_ctypes.py @@ -1,5 +1,6 @@ import unittest -from test.support import import_module +from test.support.import_helper import import_module + ctypes_test = import_module('ctypes.test') diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py index 1db3bef6f41..e02d1e16ae3 100644 --- a/Lib/test/test_dbm.py +++ b/Lib/test/test_dbm.py @@ -2,17 +2,18 @@ import unittest import glob -import test.support +from test.support import import_helper +from test.support import os_helper # Skip tests if dbm module doesn't exist. -dbm = test.support.import_module('dbm') +dbm = import_helper.import_module('dbm') try: from dbm import ndbm except ImportError: ndbm = None -_fname = test.support.TESTFN +_fname = os_helper.TESTFN # # Iterates over every database module supported by dbm currently available, @@ -33,8 +34,8 @@ def dbm_iterator(): def delete_files(): # we don't know the precise name the underlying database uses # so we use glob to locate all names - for f in glob.glob(_fname + "*"): - test.support.unlink(f) + for f in glob.glob(glob.escape(_fname) + "*"): + os_helper.unlink(f) class AnyDBMTestCase: @@ -74,7 +75,7 @@ class AnyDBMTestCase: def test_anydbm_creation_n_file_exists_with_invalid_contents(self): # create an empty file - test.support.create_empty_file(_fname) + os_helper.create_empty_file(_fname) with dbm.open(_fname, 'n') as f: self.assertEqual(len(f), 0) @@ -169,7 +170,7 @@ class WhichDBTestCase(unittest.TestCase): # Issue 17198: check that ndbm which is referenced in whichdb is defined db_file = '{}_ndbm.db'.format(_fname) with open(db_file, 'w'): - self.addCleanup(test.support.unlink, db_file) + self.addCleanup(os_helper.unlink, db_file) self.assertIsNone(self.dbm.whichdb(db_file[:-3])) def tearDown(self): @@ -177,10 +178,10 @@ class WhichDBTestCase(unittest.TestCase): def setUp(self): delete_files() - self.filename = test.support.TESTFN + self.filename = os_helper.TESTFN self.d = dbm.open(self.filename, 'c') self.d.close() - self.dbm = test.support.import_fresh_module('dbm') + self.dbm = import_helper.import_fresh_module('dbm') def test_keys(self): self.d = dbm.open(self.filename, 'c') diff --git a/Lib/test/test_dbm_dumb.py b/Lib/test/test_dbm_dumb.py index 0a60778207d..071cb845013 100644 --- a/Lib/test/test_dbm_dumb.py +++ b/Lib/test/test_dbm_dumb.py @@ -10,9 +10,11 @@ import stat import unittest import dbm.dumb as dumbdbm from test import support +from test.support import os_helper from functools import partial -_fname = support.TESTFN +_fname = os_helper.TESTFN + def _delete_files(): for ext in [".dir", ".dat", ".bak"]: @@ -264,7 +266,7 @@ class DumbDBMTestCase(unittest.TestCase): dumbdbm.open(_fname, flag) def test_readonly_files(self): - with support.temp_dir() as dir: + with os_helper.temp_dir() as dir: fname = os.path.join(dir, 'db') with dumbdbm.open(fname, 'n') as f: self.assertEqual(list(f.keys()), []) @@ -277,12 +279,12 @@ class DumbDBMTestCase(unittest.TestCase): self.assertEqual(sorted(f.keys()), sorted(self._dict)) f.close() # don't write - @unittest.skipUnless(support.TESTFN_NONASCII, + @unittest.skipUnless(os_helper.TESTFN_NONASCII, 'requires OS support of non-ASCII encodings') def test_nonascii_filename(self): - filename = support.TESTFN_NONASCII + filename = os_helper.TESTFN_NONASCII for suffix in ['.dir', '.dat', '.bak']: - self.addCleanup(support.unlink, filename + suffix) + self.addCleanup(os_helper.unlink, filename + suffix) with dumbdbm.open(filename, 'c') as db: db[b'key'] = b'value' self.assertTrue(os.path.exists(filename + '.dat')) diff --git a/Lib/test/test_dbm_gnu.py b/Lib/test/test_dbm_gnu.py index f1c7d34085c..078bf0e9b92 100644 --- a/Lib/test/test_dbm_gnu.py +++ b/Lib/test/test_dbm_gnu.py @@ -1,5 +1,6 @@ from test import support -gdbm = support.import_module("dbm.gnu") #skip if not supported +from test.support import import_helper +gdbm = import_helper.import_module("dbm.gnu") #skip if not supported import unittest import os from test.support import TESTFN, TESTFN_NONASCII, unlink diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index f1abd2aecb1..716e6eb7fb1 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -34,8 +34,9 @@ import numbers import locale from test.support import (run_unittest, run_doctest, is_resource_enabled, requires_IEEE_754, requires_docstrings) -from test.support import (import_fresh_module, TestFailed, +from test.support import (TestFailed, run_with_locale, cpython_only) +from test.support.import_helper import import_fresh_module import random import inspect import threading @@ -5201,6 +5202,7 @@ class CWhitebox(unittest.TestCase): DefaultContext = C.DefaultContext InvalidOperation = C.InvalidOperation + FloatOperation = C.FloatOperation DivisionByZero = C.DivisionByZero Overflow = C.Overflow Subnormal = C.Subnormal @@ -5274,6 +5276,7 @@ class CWhitebox(unittest.TestCase): Underflow: C.DecUnderflow, Overflow: C.DecOverflow, DivisionByZero: C.DecDivisionByZero, + FloatOperation: C.DecFloatOperation, InvalidOperation: C.DecIEEEInvalidOperation } IntCond = [ diff --git a/Lib/test/test_defaultdict.py b/Lib/test/test_defaultdict.py index b48c649fce6..68fc449780a 100644 --- a/Lib/test/test_defaultdict.py +++ b/Lib/test/test_defaultdict.py @@ -72,27 +72,6 @@ class TestDefaultDict(unittest.TestCase): d3[13] self.assertEqual(repr(d3), "defaultdict(%s, {13: 43})" % repr(foo)) - def test_print(self): - d1 = defaultdict() - def foo(): return 42 - d2 = defaultdict(foo, {1: 2}) - # NOTE: We can't use tempfile.[Named]TemporaryFile since this - # code must exercise the tp_print C code, which only gets - # invoked for *real* files. - tfn = tempfile.mktemp() - try: - f = open(tfn, "w+") - try: - print(d1, file=f) - print(d2, file=f) - f.seek(0) - self.assertEqual(f.readline(), repr(d1) + "\n") - self.assertEqual(f.readline(), repr(d2) + "\n") - finally: - f.close() - finally: - os.remove(tfn) - def test_copy(self): d1 = defaultdict() d2 = d1.copy() @@ -160,18 +139,6 @@ class TestDefaultDict(unittest.TestCase): r"sub\(, \{\}\)") - # NOTE: printing a subclass of a builtin type does not call its - # tp_print slot. So this part is essentially the same test as above. - tfn = tempfile.mktemp() - try: - f = open(tfn, "w+") - try: - print(d, file=f) - finally: - f.close() - finally: - os.remove(tfn) - def test_callable_arg(self): self.assertRaises(TypeError, defaultdict, {}) diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index c0f7138254f..93cc6ca4f44 100644 --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -66,28 +66,9 @@ class TestBasic(unittest.TestCase): self.assertEqual(list(d), [7, 8, 9]) d = deque(range(200), maxlen=10) d.append(d) - support.unlink(support.TESTFN) - fo = open(support.TESTFN, "w") - try: - fo.write(str(d)) - fo.close() - fo = open(support.TESTFN, "r") - self.assertEqual(fo.read(), repr(d)) - finally: - fo.close() - support.unlink(support.TESTFN) - + self.assertEqual(repr(d)[-30:], ', 198, 199, [...]], maxlen=10)') d = deque(range(10), maxlen=None) self.assertEqual(repr(d), 'deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])') - fo = open(support.TESTFN, "w") - try: - fo.write(str(d)) - fo.close() - fo = open(support.TESTFN, "r") - self.assertEqual(fo.read(), repr(d)) - finally: - fo.close() - support.unlink(support.TESTFN) def test_maxlen_zero(self): it = iter(range(100)) @@ -545,21 +526,7 @@ class TestBasic(unittest.TestCase): e = eval(repr(d)) self.assertEqual(list(d), list(e)) d.append(d) - self.assertIn('...', repr(d)) - - def test_print(self): - d = deque(range(200)) - d.append(d) - try: - support.unlink(support.TESTFN) - fo = open(support.TESTFN, "w") - print(d, file=fo, end='') - fo.close() - fo = open(support.TESTFN, "r") - self.assertEqual(fo.read(), repr(d)) - finally: - fo.close() - support.unlink(support.TESTFN) + self.assertEqual(repr(d)[-20:], '7, 198, 199, [...]])') def test_init(self): self.assertRaises(TypeError, deque, 'abc', 2, 3); diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 96cc8de2d98..7bb6f2bb4b3 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -3552,13 +3552,6 @@ order (MRO) for bases """ self.assertEqual(o.__str__(), '41') self.assertEqual(o.__repr__(), 'A repr') - capture = io.StringIO() - # Calling str() or not exercises different internal paths. - print(o, file=capture) - print(str(o), file=capture) - self.assertEqual(capture.getvalue(), '41\n41\n') - capture.close() - def test_keyword_arguments(self): # Testing keyword arguments to __init__, __call__... def f(a): return a diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index 6b8596fff6a..9ff8b7d501a 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -105,6 +105,26 @@ class DictTest(unittest.TestCase): self.assertRaises(TypeError, d.items, None) self.assertEqual(repr(dict(a=1).items()), "dict_items([('a', 1)])") + def test_views_mapping(self): + mappingproxy = type(type.__dict__) + class Dict(dict): + pass + for cls in [dict, Dict]: + d = cls() + m1 = d.keys().mapping + m2 = d.values().mapping + m3 = d.items().mapping + + for m in [m1, m2, m3]: + self.assertIsInstance(m, mappingproxy) + self.assertEqual(m, d) + + d["foo"] = "bar" + + for m in [m1, m2, m3]: + self.assertIsInstance(m, mappingproxy) + self.assertEqual(m, d) + def test_contains(self): d = {} self.assertNotIn('a', d) @@ -697,6 +717,16 @@ class DictTest(unittest.TestCase): self.assertEqual(k1 ^ k2, {(3,3)}) self.assertEqual(k1 ^ k3, {(1,1), (2,2), (4,4)}) + def test_items_symmetric_difference(self): + rr = random.randrange + for _ in range(100): + left = {x:rr(3) for x in range(20) if rr(2)} + right = {x:rr(3) for x in range(20) if rr(2)} + with self.subTest(left=left, right=right): + expected = set(left.items()) ^ set(right.items()) + actual = left.items() ^ right.items() + self.assertEqual(actual, expected) + def test_dictview_mixed_set_operations(self): # Just a few for .keys() self.assertTrue({1:1}.keys() == {1}) diff --git a/Lib/test/test_dict_version.py b/Lib/test/test_dict_version.py index b23786514f8..8cdccad0d79 100644 --- a/Lib/test/test_dict_version.py +++ b/Lib/test/test_dict_version.py @@ -2,11 +2,11 @@ Test implementation of the PEP 509: dictionary versionning. """ import unittest -from test import support +from test.support import import_helper # PEP 509 is implemented in CPython but other Python implementations # don't require to implement it -_testcapi = support.import_module('_testcapi') +_testcapi = import_helper.import_module('_testcapi') class DictVersionTests(unittest.TestCase): diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 3efe5dafc20..8d9f8729687 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -669,7 +669,7 @@ plain ol' Python and is guaranteed to be available. True >>> real_tests = [t for t in tests if len(t.examples) > 0] >>> len(real_tests) # objects that actually have doctests - 13 + 14 >>> for t in real_tests: ... print('{} {}'.format(len(t.examples), t.name)) ... @@ -682,6 +682,7 @@ plain ol' Python and is guaranteed to be available. 1 builtins.hex 1 builtins.int 3 builtins.int.as_integer_ratio + 2 builtins.int.bit_count 2 builtins.int.bit_length 5 builtins.memoryview.hex 1 builtins.oct diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index 59eabb00921..1d28e26dec6 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -37,7 +37,8 @@ from email import iterators from email import base64mime from email import quoprimime -from test.support import unlink, start_threads +from test.support import threading_helper +from test.support import unlink from test.test_email import openfile, TestEmailBase # These imports are documented to work, but we are testing them using a @@ -3241,7 +3242,7 @@ Foo append(make_msgid(domain='testdomain-string')) threads = [MsgidsThread() for i in range(5)] - with start_threads(threads): + with threading_helper.start_threads(threads): pass all_ids = sum([t.msgids for t in threads], []) self.assertEqual(len(set(all_ids)), len(all_ids)) diff --git a/Lib/test/test_email/test_headerregistry.py b/Lib/test/test_email/test_headerregistry.py index 82e121350ff..68bbc9561c4 100644 --- a/Lib/test/test_email/test_headerregistry.py +++ b/Lib/test/test_email/test_headerregistry.py @@ -873,6 +873,25 @@ class TestContentDisposition(TestHeaderBase): {'filename': 'foo'}, [errors.InvalidHeaderDefect]), + 'invalid_parameter_value_with_fws_between_ew': ( + 'attachment; filename="=?UTF-8?Q?Schulbesuchsbest=C3=A4ttigung=2E?=' + ' =?UTF-8?Q?pdf?="', + 'attachment', + {'filename': 'Schulbesuchsbestättigung.pdf'}, + [errors.InvalidHeaderDefect]*3, + ('attachment; filename="Schulbesuchsbestättigung.pdf"'), + ('Content-Disposition: attachment;\n' + ' filename*=utf-8\'\'Schulbesuchsbest%C3%A4ttigung.pdf\n'), + ), + + 'parameter_value_with_fws_between_tokens': ( + 'attachment; filename="File =?utf-8?q?Name?= With Spaces.pdf"', + 'attachment', + {'filename': 'File Name With Spaces.pdf'}, + [errors.InvalidHeaderDefect], + 'attachment; filename="File Name With Spaces.pdf"', + ('Content-Disposition: attachment; filename="File Name With Spaces.pdf"\n'), + ) } diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 3d60b2f330c..44d2596d9eb 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -32,7 +32,7 @@ API_ISOLATED = 3 def debug_build(program): program = os.path.basename(program) name = os.path.splitext(program)[0] - return name.endswith("_d") + return name.casefold().endswith("_d".casefold()) def remove_python_envvars(): @@ -347,7 +347,6 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'isolated': 0, 'use_environment': 1, 'dev_mode': 0, - '_use_peg_parser': 1, 'install_signal_handlers': 1, 'use_hash_seed': 0, @@ -366,6 +365,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'program_name': GET_DEFAULT_CONFIG, 'parse_argv': 0, 'argv': [""], + 'orig_argv': [], 'xoptions': [], 'warnoptions': [], @@ -380,6 +380,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'exec_prefix': GET_DEFAULT_CONFIG, 'base_exec_prefix': GET_DEFAULT_CONFIG, 'module_search_paths': GET_DEFAULT_CONFIG, + 'platlibdir': sys.platlibdir, 'site_import': 1, 'bytes_warning': 0, @@ -567,7 +568,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): if expected['stdio_errors'] is self.GET_DEFAULT_CONFIG: expected['stdio_errors'] = 'surrogateescape' - if sys.platform == 'win32': + if MS_WINDOWS: default_executable = self.test_exe elif expected['program_name'] is not self.GET_DEFAULT_CONFIG: default_executable = os.path.abspath(expected['program_name']) @@ -585,13 +586,14 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): if value is self.GET_DEFAULT_CONFIG: expected[key] = config[key] - pythonpath_env = expected['pythonpath_env'] - if pythonpath_env is not None: - paths = pythonpath_env.split(os.path.pathsep) - expected['module_search_paths'] = [*paths, *expected['module_search_paths']] - if modify_path_cb is not None: - expected['module_search_paths'] = expected['module_search_paths'].copy() - modify_path_cb(expected['module_search_paths']) + if expected['module_search_paths'] is not self.IGNORE_CONFIG: + pythonpath_env = expected['pythonpath_env'] + if pythonpath_env is not None: + paths = pythonpath_env.split(os.path.pathsep) + expected['module_search_paths'] = [*paths, *expected['module_search_paths']] + if modify_path_cb is not None: + expected['module_search_paths'] = expected['module_search_paths'].copy() + modify_path_cb(expected['module_search_paths']) for key in self.COPY_PRE_CONFIG: if key not in expected_preconfig: @@ -601,7 +603,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): pre_config = dict(configs['pre_config']) for key, value in list(expected.items()): if value is self.IGNORE_CONFIG: - del pre_config[key] + pre_config.pop(key, None) del expected[key] self.assertEqual(pre_config, expected) @@ -609,7 +611,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): config = dict(configs['config']) for key, value in list(expected.items()): if value is self.IGNORE_CONFIG: - del config[key] + config.pop(key, None) del expected[key] self.assertEqual(config, expected) @@ -684,6 +686,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): self.check_pre_config(configs, expected_preconfig) self.check_config(configs, expected_config) self.check_global_config(configs) + return configs def test_init_default_config(self): self.check_all_configs("test_init_initialize_config", api=API_COMPAT) @@ -730,14 +733,18 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'import_time': 1, 'show_ref_count': 1, 'malloc_stats': 1, - '_use_peg_parser': 0, 'stdio_encoding': 'iso8859-1', 'stdio_errors': 'replace', 'pycache_prefix': 'conf_pycache_prefix', 'program_name': './conf_program_name', - 'argv': ['-c', 'arg2', ], + 'argv': ['-c', 'arg2'], + 'orig_argv': ['python3', + '-W', 'cmdline_warnoption', + '-X', 'cmdline_xoption', + '-c', 'pass', + 'arg2'], 'parse_argv': 1, 'xoptions': [ 'config_xoption1=3', @@ -764,6 +771,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'buffered_stdio': 0, 'user_site_directory': 0, 'faulthandler': 1, + 'platlibdir': 'my_platlibdir', + 'module_search_paths': self.IGNORE_CONFIG, 'check_hash_pycs_mode': 'always', 'pathconfig_warnings': 0, @@ -795,7 +804,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'user_site_directory': 0, 'faulthandler': 1, 'warnoptions': ['EnvVar'], - '_use_peg_parser': 0, + 'platlibdir': 'env_platlibdir', + 'module_search_paths': self.IGNORE_CONFIG, } self.check_all_configs("test_init_compat_env", config, preconfig, api=API_COMPAT) @@ -823,7 +833,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'user_site_directory': 0, 'faulthandler': 1, 'warnoptions': ['EnvVar'], - '_use_peg_parser': 0, + 'platlibdir': 'env_platlibdir', + 'module_search_paths': self.IGNORE_CONFIG, } self.check_all_configs("test_init_python_env", config, preconfig, api=API_PYTHON) @@ -864,6 +875,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): } config = { 'argv': ['script.py'], + 'orig_argv': ['python3', '-X', 'dev', 'script.py'], 'run_filename': os.path.abspath('script.py'), 'dev_mode': 1, 'faulthandler': 1, @@ -878,9 +890,14 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): preconfig = { 'isolated': 0, } + argv = ["python3", + "-E", "-I", + "-X", "dev", + "-X", "utf8", + "script.py"] config = { - 'argv': ["python3", "-E", "-I", - "-X", "dev", "-X", "utf8", "script.py"], + 'argv': argv, + 'orig_argv': argv, 'isolated': 0, } self.check_all_configs("test_preinit_dont_parse_argv", config, preconfig, @@ -959,6 +976,9 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'ignore:::sysadd_warnoption', 'ignore:::config_warnoption', ], + 'orig_argv': ['python3', + '-W', 'ignore:::cmdline_warnoption', + '-X', 'cmdline_xoption'], } self.check_all_configs("test_init_sys_add", config, api=API_PYTHON) @@ -967,6 +987,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'print(json.dumps(_testinternalcapi.get_configs()))') config = { 'argv': ['-c', 'arg2'], + 'orig_argv': ['python3', '-c', code, 'arg2'], 'program_name': './python3', 'run_command': code + '\n', 'parse_argv': 1, @@ -978,6 +999,9 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'print(json.dumps(_testinternalcapi.get_configs()))') config = { 'argv': ['-c', 'arg2'], + 'orig_argv': ['python3', + '-c', code, + 'arg2'], 'program_name': './python3', 'run_command': code + '\n', 'parse_argv': 1, @@ -991,6 +1015,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): config = { 'parse_argv': 1, 'argv': ['-c', 'arg1', '-v', 'arg3'], + 'orig_argv': ['./argv0', '-E', '-c', 'pass', 'arg1', '-v', 'arg3'], 'program_name': './argv0', 'run_command': 'pass\n', 'use_environment': 0, @@ -1004,6 +1029,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): config = { 'parse_argv': 0, 'argv': ['./argv0', '-E', '-c', 'pass', 'arg1', '-v', 'arg3'], + 'orig_argv': ['./argv0', '-E', '-c', 'pass', 'arg1', '-v', 'arg3'], 'program_name': './argv0', } self.check_all_configs("test_init_dont_parse_argv", config, pre_config, @@ -1039,6 +1065,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): } self.default_program_name(config) env = {'TESTPATH': os.path.pathsep.join(paths)} + self.check_all_configs("test_init_setpath", config, api=API_COMPAT, env=env, ignore_stderr=True) @@ -1096,12 +1123,18 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): # Copy pythonXY.dll (or pythonXY_d.dll) ver = sys.version_info dll = f'python{ver.major}{ver.minor}' + dll3 = f'python{ver.major}' if debug_build(sys.executable): dll += '_d' + dll3 += '_d' dll += '.dll' + dll3 += '.dll' dll = os.path.join(os.path.dirname(self.test_exe), dll) + dll3 = os.path.join(os.path.dirname(self.test_exe), dll3) dll_copy = os.path.join(tmpdir, os.path.basename(dll)) + dll3_copy = os.path.join(tmpdir, os.path.basename(dll3)) shutil.copyfile(dll, dll_copy) + shutil.copyfile(dll3, dll3_copy) # Copy Python program exec_copy = os.path.join(tmpdir, os.path.basename(self.test_exe)) @@ -1229,9 +1262,18 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): config['base_prefix'] = pyvenv_home config['prefix'] = pyvenv_home env = self.copy_paths_by_env(config) - self.check_all_configs("test_init_compat_config", config, - api=API_COMPAT, env=env, - ignore_stderr=True, cwd=tmpdir) + actual = self.check_all_configs("test_init_compat_config", config, + api=API_COMPAT, env=env, + ignore_stderr=True, cwd=tmpdir) + if MS_WINDOWS: + self.assertEqual( + actual['windows']['python3_dll'], + os.path.join( + tmpdir, + os.path.basename(self.EXPECTED_CONFIG['windows']['python3_dll']) + ) + ) + def test_global_pathconfig(self): # Test C API functions getting the path configuration: @@ -1291,10 +1333,17 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'faulthandler': 1, 'bytes_warning': 1, 'warnoptions': warnoptions, + 'orig_argv': ['python3', + '-Wignore:::cmdline1', + '-Wignore:::cmdline2'], } self.check_all_configs("test_init_warnoptions", config, preconfig, api=API_PYTHON) + def test_get_argc_argv(self): + self.run_embedded_interpreter("test_get_argc_argv") + # ignore output + class AuditingTests(EmbeddingTestsMixin, unittest.TestCase): def test_open_code_hook(self): diff --git a/Lib/test/test_ensurepip.py b/Lib/test/test_ensurepip.py index 89966893092..4786d28f39a 100644 --- a/Lib/test/test_ensurepip.py +++ b/Lib/test/test_ensurepip.py @@ -40,7 +40,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "setuptools", "pip", ], unittest.mock.ANY, @@ -54,7 +54,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "--root", "/foo/bar/", "setuptools", "pip", ], @@ -66,7 +66,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "--user", "setuptools", "pip", ], unittest.mock.ANY, @@ -77,7 +77,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "--upgrade", "setuptools", "pip", ], unittest.mock.ANY, @@ -88,7 +88,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "-v", "setuptools", "pip", ], unittest.mock.ANY, @@ -99,7 +99,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "-vv", "setuptools", "pip", ], unittest.mock.ANY, @@ -110,7 +110,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "-vvv", "setuptools", "pip", ], unittest.mock.ANY, @@ -260,7 +260,7 @@ class TestBootstrappingMainFunction(EnsurepipMixin, unittest.TestCase): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "setuptools", "pip", ], unittest.mock.ANY, diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 1df0313da0a..e7bad624067 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -10,6 +10,7 @@ from io import StringIO from pickle import dumps, loads, PicklingError, HIGHEST_PROTOCOL from test import support from test.support import ALWAYS_EQ +from test.support import threading_helper from datetime import timedelta @@ -2333,7 +2334,7 @@ class TestFlag(unittest.TestCase): self.assertEqual(Color.ALL.value, 7) self.assertEqual(str(Color.BLUE), 'blue') - @support.reap_threads + @threading_helper.reap_threads def test_unique_composite(self): # override __eq__ to be identity only class TestFlag(Flag): @@ -2363,7 +2364,7 @@ class TestFlag(unittest.TestCase): threading.Thread(target=cycle_enum) for _ in range(8) ] - with support.start_threads(threads): + with threading_helper.start_threads(threads): pass # check that only 248 members were created self.assertFalse( @@ -2751,7 +2752,7 @@ class TestIntFlag(unittest.TestCase): self.assertEqual(Color.ALL.value, 7) self.assertEqual(str(Color.BLUE), 'blue') - @support.reap_threads + @threading_helper.reap_threads def test_unique_composite(self): # override __eq__ to be identity only class TestFlag(IntFlag): @@ -2781,7 +2782,7 @@ class TestIntFlag(unittest.TestCase): threading.Thread(target=cycle_enum) for _ in range(8) ] - with support.start_threads(threads): + with threading_helper.start_threads(threads): pass # check that only 248 members were created self.assertFalse( diff --git a/Lib/test/test_eof.py b/Lib/test/test_eof.py index bebad310611..2cf263d2746 100644 --- a/Lib/test/test_eof.py +++ b/Lib/test/test_eof.py @@ -2,6 +2,7 @@ import sys from test import support +from test.support import os_helper from test.support import script_helper import unittest @@ -48,14 +49,18 @@ class EOFTestCase(unittest.TestCase): @unittest.skipIf(not sys.executable, "sys.executable required") def test_line_continuation_EOF_from_file_bpo2180(self): """Ensure tok_nextc() does not add too many ending newlines.""" - with support.temp_dir() as temp_dir: + with os_helper.temp_dir() as temp_dir: file_name = script_helper.make_script(temp_dir, 'foo', '\\') rc, out, err = script_helper.assert_python_failure(file_name) self.assertIn(b'unexpected EOF while parsing', err) + self.assertIn(b'line 2', err) + self.assertIn(b'\\', err) file_name = script_helper.make_script(temp_dir, 'foo', 'y = 6\\') rc, out, err = script_helper.assert_python_failure(file_name) self.assertIn(b'unexpected EOF while parsing', err) + self.assertIn(b'line 2', err) + self.assertIn(b'y = 6\\', err) if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 196f31e76cc..a67e69bfff7 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -251,9 +251,9 @@ class ExceptionTests(unittest.TestCase): check('def f():\n x, y: int', 2, 3) check('[*x for x in xs]', 1, 2) check('foo(x for x in range(10), 100)', 1, 5) - check('(yield i) = 2', 1, 1 if support.use_old_parser() else 2) - check('def f(*):\n pass', 1, 7 if support.use_old_parser() else 8) - check('for 1 in []: pass', 1, 5 if support.use_old_parser() else 7) + check('for 1 in []: pass', 1, 5) + check('(yield i) = 2', 1, 2) + check('def f(*):\n pass', 1, 8) @cpython_only def testSettingException(self): diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py index 1faf29e01d3..4205ca82222 100644 --- a/Lib/test/test_extcall.py +++ b/Lib/test/test_extcall.py @@ -79,6 +79,24 @@ Here we add keyword arguments >>> f(1, 2, 3, *(4, 5), x=6, y=7, **UserDict(a=8, b=9)) (1, 2, 3, 4, 5) {'a': 8, 'b': 9, 'x': 6, 'y': 7} +Mix keyword arguments and dict unpacking + + >>> d1 = {'a':1} + + >>> d2 = {'c':3} + + >>> f(b=2, **d1, **d2) + () {'a': 1, 'b': 2, 'c': 3} + + >>> f(**d1, b=2, **d2) + () {'a': 1, 'b': 2, 'c': 3} + + >>> f(**d1, **d2, b=2) + () {'a': 1, 'b': 2, 'c': 3} + + >>> f(**d1, b=2, **d2, d=4) + () {'a': 1, 'b': 2, 'c': 3, 'd': 4} + Examples with invalid arguments (TypeErrors). We're also testing the function names in the exception messages. diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py index 9ab68c67241..7e109208326 100644 --- a/Lib/test/test_fcntl.py +++ b/Lib/test/test_fcntl.py @@ -6,8 +6,10 @@ import struct import sys import unittest from multiprocessing import Process -from test.support import (verbose, TESTFN, unlink, run_unittest, import_module, - cpython_only) +from test.support import (verbose, run_unittest, cpython_only) +from test.support.import_helper import import_module +from test.support.os_helper import TESTFN, unlink + # Skip test if no fcntl module. fcntl = import_module('fcntl') diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py index cd642e7aaf8..149767591d9 100644 --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -7,8 +7,9 @@ from weakref import proxy import io import _pyio as pyio -from test.support import TESTFN -from test import support +from test.support.os_helper import TESTFN +from test.support import os_helper +from test.support import warnings_helper from collections import UserList class AutoFileTests: @@ -20,7 +21,7 @@ class AutoFileTests: def tearDown(self): if self.f: self.f.close() - support.unlink(TESTFN) + os_helper.unlink(TESTFN) def testWeakRefs(self): # verify weak references @@ -139,7 +140,7 @@ class PyAutoFileTests(AutoFileTests, unittest.TestCase): class OtherFileTests: def tearDown(self): - support.unlink(TESTFN) + os_helper.unlink(TESTFN) def testModeStrings(self): # check invalid mode strings @@ -187,7 +188,7 @@ class OtherFileTests: # make sure that explicitly setting the buffer size doesn't cause # misbehaviour especially with repeated close() calls for s in (-1, 0, 512): - with support.check_no_warnings(self, + with warnings_helper.check_no_warnings(self, message='line buffering', category=RuntimeWarning): self._checkBufferSize(s) diff --git a/Lib/test/test_filecmp.py b/Lib/test/test_filecmp.py index b5b24a24c8d..ca9b4f354a5 100644 --- a/Lib/test/test_filecmp.py +++ b/Lib/test/test_filecmp.py @@ -5,13 +5,14 @@ import tempfile import unittest from test import support +from test.support import os_helper class FileCompareTestCase(unittest.TestCase): def setUp(self): - self.name = support.TESTFN - self.name_same = support.TESTFN + '-same' - self.name_diff = support.TESTFN + '-diff' + self.name = os_helper.TESTFN + self.name_same = os_helper.TESTFN + '-same' + self.name_diff = os_helper.TESTFN + '-diff' data = 'Contents of file go here.\n' for name in [self.name, self.name_same, self.name_diff]: with open(name, 'w') as output: diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py index 014f19e6cbd..d5edf749385 100644 --- a/Lib/test/test_fileinput.py +++ b/Lib/test/test_fileinput.py @@ -24,8 +24,11 @@ from io import BytesIO, StringIO from fileinput import FileInput, hook_encoded from pathlib import Path -from test.support import verbose, TESTFN, check_warnings -from test.support import unlink as safe_unlink +from test.support import verbose +from test.support.os_helper import TESTFN +from test.support.os_helper import unlink as safe_unlink +from test.support import os_helper +from test.support import warnings_helper from test import support from unittest import mock @@ -39,7 +42,7 @@ class BaseTests: # temp file's name. def writeTmp(self, content, *, mode='w'): # opening in text mode is the default fd, name = tempfile.mkstemp() - self.addCleanup(support.unlink, name) + self.addCleanup(os_helper.unlink, name) with open(fd, mode) as f: f.write(content) return name @@ -234,9 +237,9 @@ class FileInputTests(BaseTests, unittest.TestCase): pass # try opening in universal newline mode t1 = self.writeTmp(b"A\nB\r\nC\rD", mode="wb") - with check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): fi = FileInput(files=t1, mode="U") - with check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): lines = list(fi) self.assertEqual(lines, ["A\n", "B\n", "C\n", "D"]) @@ -353,7 +356,7 @@ class FileInputTests(BaseTests, unittest.TestCase): with FileInput(files=[]) as fi: self.assertEqual(fi._files, ('-',)) - @support.ignore_warnings(category=DeprecationWarning) + @warnings_helper.ignore_warnings(category=DeprecationWarning) def test__getitem__(self): """Tests invoking FileInput.__getitem__() with the current line number""" @@ -371,7 +374,7 @@ class FileInputTests(BaseTests, unittest.TestCase): with FileInput(files=[t]) as fi: self.assertEqual(fi[0], "line1\n") - @support.ignore_warnings(category=DeprecationWarning) + @warnings_helper.ignore_warnings(category=DeprecationWarning) def test__getitem__invalid_key(self): """Tests invoking FileInput.__getitem__() with an index unequal to the line number""" @@ -381,7 +384,7 @@ class FileInputTests(BaseTests, unittest.TestCase): fi[1] self.assertEqual(cm.exception.args, ("accessing lines out of order",)) - @support.ignore_warnings(category=DeprecationWarning) + @warnings_helper.ignore_warnings(category=DeprecationWarning) def test__getitem__eof(self): """Tests invoking FileInput.__getitem__() with the line number but at end-of-input""" @@ -400,7 +403,7 @@ class FileInputTests(BaseTests, unittest.TestCase): os_unlink_replacement = UnconditionallyRaise(OSError) try: t = self.writeTmp("\n") - self.addCleanup(support.unlink, t + '.bak') + self.addCleanup(safe_unlink, t + '.bak') with FileInput(files=[t], inplace=True) as fi: next(fi) # make sure the file is opened os.unlink = os_unlink_replacement diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py index 26e4500ae8c..ff611a90eed 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -9,8 +9,9 @@ from array import array from weakref import proxy from functools import wraps -from test.support import (TESTFN, TESTFN_UNICODE, check_warnings, run_unittest, - make_bad_fd, cpython_only, swap_attr) +from test.support import (run_unittest, cpython_only, swap_attr) +from test.support.os_helper import (TESTFN, TESTFN_UNICODE, make_bad_fd) +from test.support.warnings_helper import check_warnings from collections import UserList import _io # C implementation of io diff --git a/Lib/test/test_flufl.py b/Lib/test/test_flufl.py index 22285859a92..0ff54aa227e 100644 --- a/Lib/test/test_flufl.py +++ b/Lib/test/test_flufl.py @@ -20,7 +20,7 @@ class FLUFLTests(unittest.TestCase): self.assertTrue(cm.exception.lineno, 2) # The old parser reports the end of the token and the new # parser reports the start of the token - self.assertEqual(cm.exception.offset, 4 if support.use_old_parser() else 3) + self.assertEqual(cm.exception.offset, 3) def test_guido_as_bdfl(self): code = '2 {0} 3' @@ -33,7 +33,7 @@ class FLUFLTests(unittest.TestCase): self.assertEqual(cm.exception.lineno, 1) # The old parser reports the end of the token and the new # parser reports the start of the token - self.assertEqual(cm.exception.offset, 4 if support.use_old_parser() else 3) + self.assertEqual(cm.exception.offset, 3) if __name__ == '__main__': diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py index 4559cd5623e..e9e5bb9cf00 100644 --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -484,6 +484,17 @@ class FormatTest(unittest.TestCase): with self.assertRaises(ValueError) as cm: format(c, ".%sf" % (INT_MAX + 1)) + def test_g_format_has_no_trailing_zeros(self): + # regression test for bugs.python.org/issue40780 + self.assertEqual("%.3g" % 1505.0, "1.5e+03") + self.assertEqual("%#.3g" % 1505.0, "1.50e+03") + + self.assertEqual(format(1505.0, ".3g"), "1.5e+03") + self.assertEqual(format(1505.0, "#.3g"), "1.50e+03") + + self.assertEqual(format(12300050.0, ".6g"), "1.23e+07") + self.assertEqual(format(12300050.0, "#.6g"), "1.23000e+07") + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index ea4e589929e..35a62a0632e 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -12,7 +12,7 @@ import os import types import decimal import unittest -from test.support import temp_cwd, use_old_parser +from test.support.os_helper import temp_cwd from test.support.script_helper import assert_python_failure a_global = 'global variable' @@ -524,7 +524,7 @@ non-important content # This looks like a nested format spec. ]) - self.assertAllRaise(SyntaxError, "invalid syntax", + self.assertAllRaise(SyntaxError, "f-string: invalid syntax", [# Invalid syntax inside a nested spec. "f'{4:{/5}}'", ]) @@ -598,7 +598,7 @@ non-important content # are added around it. But we shouldn't go from an invalid # expression to a valid one. The added parens are just # supposed to allow whitespace (including newlines). - self.assertAllRaise(SyntaxError, 'invalid syntax', + self.assertAllRaise(SyntaxError, 'f-string: invalid syntax', ["f'{,}'", "f'{,}'", # this is (,), which is an error ]) @@ -716,7 +716,7 @@ non-important content # lambda doesn't work without parens, because the colon # makes the parser think it's a format_spec - self.assertAllRaise(SyntaxError, 'invalid syntax', + self.assertAllRaise(SyntaxError, 'f-string: invalid syntax', ["f'{lambda x:x}'", ]) @@ -725,9 +725,11 @@ non-important content # a function into a generator def fn(y): f'y:{yield y*2}' + f'{yield}' g = fn(4) self.assertEqual(next(g), 8) + self.assertEqual(next(g), None) def test_yield_send(self): def fn(x): @@ -1047,15 +1049,15 @@ non-important content r"f'{1000:j}'", ]) - @unittest.skipIf(use_old_parser(), "The old parser only supports as the filename") def test_filename_in_syntaxerror(self): # see issue 38964 with temp_cwd() as cwd: file_path = os.path.join(cwd, 't.py') with open(file_path, 'w') as f: f.write('f"{a b}"') # This generates a SyntaxError - _, _, stderr = assert_python_failure(file_path) - self.assertIn(file_path, stderr.decode('utf-8')) + _, _, stderr = assert_python_failure(file_path, + PYTHONIOENCODING='ascii') + self.assertIn(file_path.encode('ascii', 'backslashreplace'), stderr) def test_loop(self): for i in range(1000): @@ -1192,6 +1194,10 @@ non-important content self.assertEqual(f'{(x:=10)}', '10') self.assertEqual(x, 10) + def test_invalid_syntax_error_message(self): + with self.assertRaisesRegex(SyntaxError, "f-string: invalid syntax"): + compile("f'{a $ b}'", "?", "exec") + if __name__ == '__main__': unittest.main() diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py index e424076d7d3..cb43573318b 100644 --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -19,6 +19,7 @@ except ImportError: from unittest import TestCase, skipUnless from test import support +from test.support import threading_helper from test.support import socket_helper from test.support.socket_helper import HOST, HOSTv6 @@ -1117,11 +1118,11 @@ def test_main(): TestTLS_FTPClassMixin, TestTLS_FTPClass, MiscTestCase] - thread_info = support.threading_setup() + thread_info = threading_helper.threading_setup() try: support.run_unittest(*tests) finally: - support.threading_cleanup(*thread_info) + threading_helper.threading_cleanup(*thread_info) if __name__ == '__main__': diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index e122fe0b333..edd5773e13d 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -3,7 +3,7 @@ import builtins import collections import collections.abc import copy -from itertools import permutations, chain +from itertools import permutations import pickle from random import choice import sys @@ -19,14 +19,18 @@ import gc from weakref import proxy import contextlib +from test.support import import_helper +from test.support import threading_helper from test.support.script_helper import assert_python_ok import functools -py_functools = support.import_fresh_module('functools', blocked=['_functools']) -c_functools = support.import_fresh_module('functools', fresh=['_functools']) +py_functools = import_helper.import_fresh_module('functools', + blocked=['_functools']) +c_functools = import_helper.import_fresh_module('functools', + fresh=['_functools']) -decimal = support.import_fresh_module('decimal', fresh=['_decimal']) +decimal = import_helper.import_fresh_module('decimal', fresh=['_decimal']) @contextlib.contextmanager def replaced_module(name, replacement): @@ -1163,275 +1167,6 @@ class Orderable_LT: return self.value == other.value -class TestTopologicalSort(unittest.TestCase): - - def _test_graph(self, graph, expected): - - def static_order_with_groups(ts): - ts.prepare() - while ts.is_active(): - nodes = ts.get_ready() - for node in nodes: - ts.done(node) - yield nodes - - ts = functools.TopologicalSorter(graph) - self.assertEqual(list(static_order_with_groups(ts)), list(expected)) - - ts = functools.TopologicalSorter(graph) - self.assertEqual(list(ts.static_order()), list(chain(*expected))) - - def _assert_cycle(self, graph, cycle): - ts = functools.TopologicalSorter() - for node, dependson in graph.items(): - ts.add(node, *dependson) - try: - ts.prepare() - except functools.CycleError as e: - msg, seq = e.args - self.assertIn(' '.join(map(str, cycle)), - ' '.join(map(str, seq * 2))) - else: - raise - - def test_simple_cases(self): - self._test_graph( - {2: {11}, - 9: {11, 8}, - 10: {11, 3}, - 11: {7, 5}, - 8: {7, 3}}, - [(3, 5, 7), (11, 8), (2, 10, 9)] - ) - - self._test_graph({1: {}}, [(1,)]) - - self._test_graph({x: {x+1} for x in range(10)}, - [(x,) for x in range(10, -1, -1)]) - - self._test_graph({2: {3}, 3: {4}, 4: {5}, 5: {1}, - 11: {12}, 12: {13}, 13: {14}, 14: {15}}, - [(1, 15), (5, 14), (4, 13), (3, 12), (2, 11)]) - - self._test_graph({ - 0: [1, 2], - 1: [3], - 2: [5, 6], - 3: [4], - 4: [9], - 5: [3], - 6: [7], - 7: [8], - 8: [4], - 9: [] - }, - [(9,), (4,), (3, 8), (1, 5, 7), (6,), (2,), (0,)] - ) - - self._test_graph({ - 0: [1, 2], - 1: [], - 2: [3], - 3: [] - }, - [(1, 3), (2,), (0,)] - ) - - self._test_graph({ - 0: [1, 2], - 1: [], - 2: [3], - 3: [], - 4: [5], - 5: [6], - 6: [] - }, - [(1, 3, 6), (2, 5), (0, 4)] - ) - - def test_no_dependencies(self): - self._test_graph( - {1: {2}, - 3: {4}, - 5: {6}}, - [(2, 4, 6), (1, 3, 5)] - ) - - self._test_graph( - {1: set(), - 3: set(), - 5: set()}, - [(1, 3, 5)] - ) - - def test_the_node_multiple_times(self): - # Test same node multiple times in dependencies - self._test_graph({1: {2}, 3: {4}, 0: [2, 4, 4, 4, 4, 4]}, - [(2, 4), (1, 3, 0)]) - - # Test adding the same dependency multiple times - ts = functools.TopologicalSorter() - ts.add(1, 2) - ts.add(1, 2) - ts.add(1, 2) - self.assertEqual([*ts.static_order()], [2, 1]) - - def test_graph_with_iterables(self): - dependson = (2*x + 1 for x in range(5)) - ts = functools.TopologicalSorter({0: dependson}) - self.assertEqual(list(ts.static_order()), [1, 3, 5, 7, 9, 0]) - - def test_add_dependencies_for_same_node_incrementally(self): - # Test same node multiple times - ts = functools.TopologicalSorter() - ts.add(1, 2) - ts.add(1, 3) - ts.add(1, 4) - ts.add(1, 5) - - ts2 = functools.TopologicalSorter({1: {2, 3, 4, 5}}) - self.assertEqual([*ts.static_order()], [*ts2.static_order()]) - - def test_empty(self): - self._test_graph({}, []) - - def test_cycle(self): - # Self cycle - self._assert_cycle({1: {1}}, [1, 1]) - # Simple cycle - self._assert_cycle({1: {2}, 2: {1}}, [1, 2, 1]) - # Indirect cycle - self._assert_cycle({1: {2}, 2: {3}, 3: {1}}, [1, 3, 2, 1]) - # not all elements involved in a cycle - self._assert_cycle({1: {2}, 2: {3}, 3: {1}, 5: {4}, 4: {6}}, [1, 3, 2, 1]) - # Multiple cycles - self._assert_cycle({1: {2}, 2: {1}, 3: {4}, 4: {5}, 6: {7}, 7: {6}}, - [1, 2, 1]) - # Cycle in the middle of the graph - self._assert_cycle({1: {2}, 2: {3}, 3: {2, 4}, 4: {5}}, [3, 2]) - - def test_calls_before_prepare(self): - ts = functools.TopologicalSorter() - - with self.assertRaisesRegex(ValueError, r"prepare\(\) must be called first"): - ts.get_ready() - with self.assertRaisesRegex(ValueError, r"prepare\(\) must be called first"): - ts.done(3) - with self.assertRaisesRegex(ValueError, r"prepare\(\) must be called first"): - ts.is_active() - - def test_prepare_multiple_times(self): - ts = functools.TopologicalSorter() - ts.prepare() - with self.assertRaisesRegex(ValueError, r"cannot prepare\(\) more than once"): - ts.prepare() - - def test_invalid_nodes_in_done(self): - ts = functools.TopologicalSorter() - ts.add(1, 2, 3, 4) - ts.add(2, 3, 4) - ts.prepare() - ts.get_ready() - - with self.assertRaisesRegex(ValueError, "node 2 was not passed out"): - ts.done(2) - with self.assertRaisesRegex(ValueError, r"node 24 was not added using add\(\)"): - ts.done(24) - - def test_done(self): - ts = functools.TopologicalSorter() - ts.add(1, 2, 3, 4) - ts.add(2, 3) - ts.prepare() - - self.assertEqual(ts.get_ready(), (3, 4)) - # If we don't mark anything as done, get_ready() returns nothing - self.assertEqual(ts.get_ready(), ()) - ts.done(3) - # Now 2 becomes available as 3 is done - self.assertEqual(ts.get_ready(), (2,)) - self.assertEqual(ts.get_ready(), ()) - ts.done(4) - ts.done(2) - # Only 1 is missing - self.assertEqual(ts.get_ready(), (1,)) - self.assertEqual(ts.get_ready(), ()) - ts.done(1) - self.assertEqual(ts.get_ready(), ()) - self.assertFalse(ts.is_active()) - - def test_is_active(self): - ts = functools.TopologicalSorter() - ts.add(1, 2) - ts.prepare() - - self.assertTrue(ts.is_active()) - self.assertEqual(ts.get_ready(), (2,)) - self.assertTrue(ts.is_active()) - ts.done(2) - self.assertTrue(ts.is_active()) - self.assertEqual(ts.get_ready(), (1,)) - self.assertTrue(ts.is_active()) - ts.done(1) - self.assertFalse(ts.is_active()) - - def test_not_hashable_nodes(self): - ts = functools.TopologicalSorter() - self.assertRaises(TypeError, ts.add, dict(), 1) - self.assertRaises(TypeError, ts.add, 1, dict()) - self.assertRaises(TypeError, ts.add, dict(), dict()) - - def test_order_of_insertion_does_not_matter_between_groups(self): - def get_groups(ts): - ts.prepare() - while ts.is_active(): - nodes = ts.get_ready() - ts.done(*nodes) - yield set(nodes) - - ts = functools.TopologicalSorter() - ts.add(3, 2, 1) - ts.add(1, 0) - ts.add(4, 5) - ts.add(6, 7) - ts.add(4, 7) - - ts2 = functools.TopologicalSorter() - ts2.add(1, 0) - ts2.add(3, 2, 1) - ts2.add(4, 7) - ts2.add(6, 7) - ts2.add(4, 5) - - self.assertEqual(list(get_groups(ts)), list(get_groups(ts2))) - - def test_static_order_does_not_change_with_the_hash_seed(self): - def check_order_with_hash_seed(seed): - code = """if 1: - import functools - ts = functools.TopologicalSorter() - ts.add('blech', 'bluch', 'hola') - ts.add('abcd', 'blech', 'bluch', 'a', 'b') - ts.add('a', 'a string', 'something', 'b') - ts.add('bluch', 'hola', 'abcde', 'a', 'b') - print(list(ts.static_order())) - """ - env = os.environ.copy() - # signal to assert_python not to do a copy - # of os.environ on its own - env['__cleanenv'] = True - env['PYTHONHASHSEED'] = str(seed) - out = assert_python_ok('-c', code, **env) - return out - - run1 = check_order_with_hash_seed(1234) - run2 = check_order_with_hash_seed(31415) - - self.assertNotEqual(run1, "") - self.assertNotEqual(run2, "") - self.assertEqual(run1, run2) - - class TestCache: # This tests that the pass-through is working as designed. # The underlying functionality is tested in TestLRU. @@ -1798,7 +1533,7 @@ class TestLRU: # create n threads in order to fill cache threads = [threading.Thread(target=full, args=[k]) for k in range(n)] - with support.start_threads(threads): + with threading_helper.start_threads(threads): start.set() hits, misses, maxsize, currsize = f.cache_info() @@ -1816,7 +1551,7 @@ class TestLRU: threads += [threading.Thread(target=full, args=[k]) for k in range(n)] start.clear() - with support.start_threads(threads): + with threading_helper.start_threads(threads): start.set() finally: sys.setswitchinterval(orig_si) @@ -1838,7 +1573,7 @@ class TestLRU: self.assertEqual(f(i), 3 * i) stop.wait(10) threads = [threading.Thread(target=test) for k in range(n)] - with support.start_threads(threads): + with threading_helper.start_threads(threads): for i in range(m): start.wait(10) stop.reset() @@ -1858,7 +1593,7 @@ class TestLRU: self.assertEqual(f(x), 3 * x, i) threads = [threading.Thread(target=test, args=(i, v)) for i, v in enumerate([1, 2, 2, 3, 2])] - with support.start_threads(threads): + with threading_helper.start_threads(threads): pass def test_need_for_rlock(self): @@ -2792,7 +2527,7 @@ class TestCachedProperty(unittest.TestCase): threading.Thread(target=lambda: item.cost) for k in range(num_threads) ] - with support.start_threads(threads): + with threading_helper.start_threads(threads): go.set() finally: sys.setswitchinterval(orig_si) diff --git a/Lib/test/test_future.py b/Lib/test/test_future.py index 0f40357b3a7..e4715587d21 100644 --- a/Lib/test/test_future.py +++ b/Lib/test/test_future.py @@ -4,6 +4,7 @@ import __future__ import ast import unittest from test import support +from test.support import import_helper from textwrap import dedent import os import re @@ -24,17 +25,17 @@ class FutureTest(unittest.TestCase): self.assertEqual(err.offset, offset) def test_future1(self): - with support.CleanImport('future_test1'): + with import_helper.CleanImport('future_test1'): from test import future_test1 self.assertEqual(future_test1.result, 6) def test_future2(self): - with support.CleanImport('future_test2'): + with import_helper.CleanImport('future_test2'): from test import future_test2 self.assertEqual(future_test2.result, 6) def test_future3(self): - with support.CleanImport('test_future3'): + with import_helper.CleanImport('test_future3'): from test import test_future3 def test_badfuture3(self): @@ -113,7 +114,7 @@ class FutureTest(unittest.TestCase): self.fail("syntax error didn't occur") def test_multiple_features(self): - with support.CleanImport("test.test_future5"): + with import_helper.CleanImport("test.test_future5"): from test import test_future5 def test_unicode_literals_exec(self): diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index acb6391944b..c82970827c6 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -1,10 +1,10 @@ import unittest import unittest.mock from test.support import (verbose, refcount_test, run_unittest, - cpython_only, start_threads, - temp_dir, TESTFN, unlink, + cpython_only, temp_dir, TESTFN, unlink, import_module) from test.support.script_helper import assert_python_ok, make_script +from test.support import threading_helper import gc import sys @@ -415,7 +415,7 @@ class GCTests(unittest.TestCase): for i in range(N_THREADS): t = threading.Thread(target=run_thread) threads.append(t) - with start_threads(threads, lambda: exit.append(1)): + with threading_helper.start_threads(threads, lambda: exit.append(1)): time.sleep(1.0) finally: sys.setswitchinterval(old_switchinterval) diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py index 210cd0d3787..22c75bae987 100644 --- a/Lib/test/test_gdb.py +++ b/Lib/test/test_gdb.py @@ -39,7 +39,8 @@ def get_gdb_version(): # 'GNU gdb (GDB) Fedora 7.9.1-17.fc22\n' -> 7.9 # 'GNU gdb 6.1.1 [FreeBSD]\n' -> 6.1 # 'GNU gdb (GDB) Fedora (7.5.1-37.fc18)\n' -> 7.5 - match = re.search(r"^GNU gdb.*?\b(\d+)\.(\d+)", version) + # 'HP gdb 6.7 for HP Itanium (32 or 64 bit) and target HP-UX 11iv2 and 11iv3.\n' -> 6.7 + match = re.search(r"^(?:GNU|HP) gdb.*?\b(\d+)\.(\d+)", version) if match is None: raise Exception("unable to parse GDB version: %r" % version) return (version, int(match.group(1)), int(match.group(2))) diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py index 9d5ac44b6d0..e7acbcd2908 100644 --- a/Lib/test/test_genericpath.py +++ b/Lib/test/test_genericpath.py @@ -534,7 +534,7 @@ class CommonTest(GenericTest): class PathLikeTests(unittest.TestCase): def setUp(self): - self.file_name = support.TESTFN.lower() + self.file_name = support.TESTFN self.file_path = FakePath(support.TESTFN) self.addCleanup(support.unlink, self.file_name) create_file(self.file_name, b"test_genericpath.PathLikeTests") diff --git a/Lib/test/test_getopt.py b/Lib/test/test_getopt.py index 9275dc4c5ba..9261276ebb9 100644 --- a/Lib/test/test_getopt.py +++ b/Lib/test/test_getopt.py @@ -1,7 +1,8 @@ # test_getopt.py # David Goodger 2000-08-19 -from test.support import verbose, run_doctest, EnvironmentVarGuard +from test.support import verbose, run_doctest +from test.support.os_helper import EnvironmentVarGuard import unittest import getopt diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py index cba8c7c60e2..f8158523a04 100644 --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -9,6 +9,7 @@ from test.support import (TESTFN, skip_unless_symlink, class GlobTests(unittest.TestCase): + dir_fd = None def norm(self, *parts): return os.path.normpath(os.path.join(self.tempdir, *parts)) @@ -38,8 +39,14 @@ class GlobTests(unittest.TestCase): os.symlink(self.norm('broken'), self.norm('sym1')) os.symlink('broken', self.norm('sym2')) os.symlink(os.path.join('a', 'bcd'), self.norm('sym3')) + if {os.open, os.stat} <= os.supports_dir_fd and os.scandir in os.supports_fd: + self.dir_fd = os.open(self.tempdir, os.O_RDONLY | os.O_DIRECTORY) + else: + self.dir_fd = None def tearDown(self): + if self.dir_fd is not None: + os.close(self.dir_fd) shutil.rmtree(self.tempdir) def glob(self, *parts, **kwargs): @@ -53,6 +60,41 @@ class GlobTests(unittest.TestCase): bres = [os.fsencode(x) for x in res] self.assertCountEqual(glob.glob(os.fsencode(p), **kwargs), bres) self.assertCountEqual(glob.iglob(os.fsencode(p), **kwargs), bres) + + with change_cwd(self.tempdir): + res2 = glob.glob(pattern, **kwargs) + for x in res2: + self.assertFalse(os.path.isabs(x), x) + if pattern == '**' or pattern == '**' + os.sep: + expected = res[1:] + else: + expected = res + self.assertCountEqual([os.path.join(self.tempdir, x) for x in res2], + expected) + self.assertCountEqual(glob.iglob(pattern, **kwargs), res2) + bpattern = os.fsencode(pattern) + bres2 = [os.fsencode(x) for x in res2] + self.assertCountEqual(glob.glob(bpattern, **kwargs), bres2) + self.assertCountEqual(glob.iglob(bpattern, **kwargs), bres2) + + self.assertCountEqual(glob.glob(pattern, root_dir=self.tempdir, **kwargs), res2) + self.assertCountEqual(glob.iglob(pattern, root_dir=self.tempdir, **kwargs), res2) + btempdir = os.fsencode(self.tempdir) + self.assertCountEqual( + glob.glob(bpattern, root_dir=btempdir, **kwargs), bres2) + self.assertCountEqual( + glob.iglob(bpattern, root_dir=btempdir, **kwargs), bres2) + + if self.dir_fd is not None: + self.assertCountEqual( + glob.glob(pattern, dir_fd=self.dir_fd, **kwargs), res2) + self.assertCountEqual( + glob.iglob(pattern, dir_fd=self.dir_fd, **kwargs), res2) + self.assertCountEqual( + glob.glob(bpattern, dir_fd=self.dir_fd, **kwargs), bres2) + self.assertCountEqual( + glob.iglob(bpattern, dir_fd=self.dir_fd, **kwargs), bres2) + return res def assertSequencesEqual_noorder(self, l1, l2): @@ -78,6 +120,14 @@ class GlobTests(unittest.TestCase): res = glob.glob(os.path.join(os.fsencode(os.curdir), b'*')) self.assertEqual({type(r) for r in res}, {bytes}) + def test_glob_empty_pattern(self): + self.assertEqual(glob.glob(''), []) + self.assertEqual(glob.glob(b''), []) + self.assertEqual(glob.glob('', root_dir=self.tempdir), []) + self.assertEqual(glob.glob(b'', root_dir=os.fsencode(self.tempdir)), []) + self.assertEqual(glob.glob('', dir_fd=self.dir_fd), []) + self.assertEqual(glob.glob(b'', dir_fd=self.dir_fd), []) + def test_glob_one_directory(self): eq = self.assertSequencesEqual_noorder eq(self.glob('a*'), map(self.norm, ['a', 'aab', 'aaa'])) diff --git a/Lib/test/test_global.py b/Lib/test/test_global.py index 8159602be98..c71d055297e 100644 --- a/Lib/test/test_global.py +++ b/Lib/test/test_global.py @@ -1,6 +1,7 @@ """Verify that warnings are issued for global statements following use.""" -from test.support import run_unittest, check_syntax_error, check_warnings +from test.support import run_unittest, check_syntax_error +from test.support.warnings_helper import check_warnings import unittest import warnings diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index e1a402e2b46..a51452e739f 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -1,7 +1,8 @@ # Python test set -- part 1, grammar. # This just tests whether the parser accepts them all. -from test.support import check_syntax_error, check_syntax_warning, use_old_parser +from test.support import check_syntax_error +from test.support.warnings_helper import check_syntax_warning import inspect import unittest import sys @@ -276,7 +277,8 @@ class CNS: class GrammarTests(unittest.TestCase): - from test.support import check_syntax_error, check_syntax_warning + from test.support import check_syntax_error + from test.support.warnings_helper import check_syntax_warning # single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE # XXX can't test in a script -- this rule is only used when interactive @@ -1714,69 +1716,53 @@ class GrammarTests(unittest.TestCase): with manager() as x, manager(): pass - if not use_old_parser(): - test_cases = [ - """if 1: - with ( - manager() - ): - pass - """, - """if 1: - with ( - manager() as x - ): - pass - """, - """if 1: - with ( - manager() as (x, y), - manager() as z, - ): - pass - """, - """if 1: - with ( - manager(), - manager() - ): - pass - """, - """if 1: - with ( - manager() as x, - manager() as y - ): - pass - """, - """if 1: - with ( - manager() as x, - manager() - ): - pass - """, - """if 1: - with ( - manager() as x, - manager() as y, - manager() as z, - ): - pass - """, - """if 1: - with ( - manager() as x, - manager() as y, - manager(), - ): - pass - """, - ] - for case in test_cases: - with self.subTest(case=case): - compile(case, "", "exec") + with ( + manager() + ): + pass + with ( + manager() as x + ): + pass + + with ( + manager() as (x, y), + manager() as z, + ): + pass + + with ( + manager(), + manager() + ): + pass + + with ( + manager() as x, + manager() as y + ): + pass + + with ( + manager() as x, + manager() + ): + pass + + with ( + manager() as x, + manager() as y, + manager() as z, + ): + pass + + with ( + manager() as x, + manager() as y, + manager(), + ): + pass def test_if_else_expr(self): # Test ifelse expressions in various cases diff --git a/Lib/test/test_graphlib.py b/Lib/test/test_graphlib.py new file mode 100644 index 00000000000..00432537f22 --- /dev/null +++ b/Lib/test/test_graphlib.py @@ -0,0 +1,244 @@ +from itertools import chain +import graphlib +import os +import unittest + +from test.support.script_helper import assert_python_ok + +class TestTopologicalSort(unittest.TestCase): + def _test_graph(self, graph, expected): + def static_order_with_groups(ts): + ts.prepare() + while ts.is_active(): + nodes = ts.get_ready() + for node in nodes: + ts.done(node) + yield nodes + + ts = graphlib.TopologicalSorter(graph) + self.assertEqual(list(static_order_with_groups(ts)), list(expected)) + + ts = graphlib.TopologicalSorter(graph) + self.assertEqual(list(ts.static_order()), list(chain(*expected))) + + def _assert_cycle(self, graph, cycle): + ts = graphlib.TopologicalSorter() + for node, dependson in graph.items(): + ts.add(node, *dependson) + try: + ts.prepare() + except graphlib.CycleError as e: + msg, seq = e.args + self.assertIn(" ".join(map(str, cycle)), " ".join(map(str, seq * 2))) + else: + raise + + def test_simple_cases(self): + self._test_graph( + {2: {11}, 9: {11, 8}, 10: {11, 3}, 11: {7, 5}, 8: {7, 3}}, + [(3, 5, 7), (11, 8), (2, 10, 9)], + ) + + self._test_graph({1: {}}, [(1,)]) + + self._test_graph( + {x: {x + 1} for x in range(10)}, [(x,) for x in range(10, -1, -1)] + ) + + self._test_graph( + {2: {3}, 3: {4}, 4: {5}, 5: {1}, 11: {12}, 12: {13}, 13: {14}, 14: {15}}, + [(1, 15), (5, 14), (4, 13), (3, 12), (2, 11)], + ) + + self._test_graph( + { + 0: [1, 2], + 1: [3], + 2: [5, 6], + 3: [4], + 4: [9], + 5: [3], + 6: [7], + 7: [8], + 8: [4], + 9: [], + }, + [(9,), (4,), (3, 8), (1, 5, 7), (6,), (2,), (0,)], + ) + + self._test_graph({0: [1, 2], 1: [], 2: [3], 3: []}, [(1, 3), (2,), (0,)]) + + self._test_graph( + {0: [1, 2], 1: [], 2: [3], 3: [], 4: [5], 5: [6], 6: []}, + [(1, 3, 6), (2, 5), (0, 4)], + ) + + def test_no_dependencies(self): + self._test_graph({1: {2}, 3: {4}, 5: {6}}, [(2, 4, 6), (1, 3, 5)]) + + self._test_graph({1: set(), 3: set(), 5: set()}, [(1, 3, 5)]) + + def test_the_node_multiple_times(self): + # Test same node multiple times in dependencies + self._test_graph({1: {2}, 3: {4}, 0: [2, 4, 4, 4, 4, 4]}, [(2, 4), (1, 3, 0)]) + + # Test adding the same dependency multiple times + ts = graphlib.TopologicalSorter() + ts.add(1, 2) + ts.add(1, 2) + ts.add(1, 2) + self.assertEqual([*ts.static_order()], [2, 1]) + + def test_graph_with_iterables(self): + dependson = (2 * x + 1 for x in range(5)) + ts = graphlib.TopologicalSorter({0: dependson}) + self.assertEqual(list(ts.static_order()), [1, 3, 5, 7, 9, 0]) + + def test_add_dependencies_for_same_node_incrementally(self): + # Test same node multiple times + ts = graphlib.TopologicalSorter() + ts.add(1, 2) + ts.add(1, 3) + ts.add(1, 4) + ts.add(1, 5) + + ts2 = graphlib.TopologicalSorter({1: {2, 3, 4, 5}}) + self.assertEqual([*ts.static_order()], [*ts2.static_order()]) + + def test_empty(self): + self._test_graph({}, []) + + def test_cycle(self): + # Self cycle + self._assert_cycle({1: {1}}, [1, 1]) + # Simple cycle + self._assert_cycle({1: {2}, 2: {1}}, [1, 2, 1]) + # Indirect cycle + self._assert_cycle({1: {2}, 2: {3}, 3: {1}}, [1, 3, 2, 1]) + # not all elements involved in a cycle + self._assert_cycle({1: {2}, 2: {3}, 3: {1}, 5: {4}, 4: {6}}, [1, 3, 2, 1]) + # Multiple cycles + self._assert_cycle({1: {2}, 2: {1}, 3: {4}, 4: {5}, 6: {7}, 7: {6}}, [1, 2, 1]) + # Cycle in the middle of the graph + self._assert_cycle({1: {2}, 2: {3}, 3: {2, 4}, 4: {5}}, [3, 2]) + + def test_calls_before_prepare(self): + ts = graphlib.TopologicalSorter() + + with self.assertRaisesRegex(ValueError, r"prepare\(\) must be called first"): + ts.get_ready() + with self.assertRaisesRegex(ValueError, r"prepare\(\) must be called first"): + ts.done(3) + with self.assertRaisesRegex(ValueError, r"prepare\(\) must be called first"): + ts.is_active() + + def test_prepare_multiple_times(self): + ts = graphlib.TopologicalSorter() + ts.prepare() + with self.assertRaisesRegex(ValueError, r"cannot prepare\(\) more than once"): + ts.prepare() + + def test_invalid_nodes_in_done(self): + ts = graphlib.TopologicalSorter() + ts.add(1, 2, 3, 4) + ts.add(2, 3, 4) + ts.prepare() + ts.get_ready() + + with self.assertRaisesRegex(ValueError, "node 2 was not passed out"): + ts.done(2) + with self.assertRaisesRegex(ValueError, r"node 24 was not added using add\(\)"): + ts.done(24) + + def test_done(self): + ts = graphlib.TopologicalSorter() + ts.add(1, 2, 3, 4) + ts.add(2, 3) + ts.prepare() + + self.assertEqual(ts.get_ready(), (3, 4)) + # If we don't mark anything as done, get_ready() returns nothing + self.assertEqual(ts.get_ready(), ()) + ts.done(3) + # Now 2 becomes available as 3 is done + self.assertEqual(ts.get_ready(), (2,)) + self.assertEqual(ts.get_ready(), ()) + ts.done(4) + ts.done(2) + # Only 1 is missing + self.assertEqual(ts.get_ready(), (1,)) + self.assertEqual(ts.get_ready(), ()) + ts.done(1) + self.assertEqual(ts.get_ready(), ()) + self.assertFalse(ts.is_active()) + + def test_is_active(self): + ts = graphlib.TopologicalSorter() + ts.add(1, 2) + ts.prepare() + + self.assertTrue(ts.is_active()) + self.assertEqual(ts.get_ready(), (2,)) + self.assertTrue(ts.is_active()) + ts.done(2) + self.assertTrue(ts.is_active()) + self.assertEqual(ts.get_ready(), (1,)) + self.assertTrue(ts.is_active()) + ts.done(1) + self.assertFalse(ts.is_active()) + + def test_not_hashable_nodes(self): + ts = graphlib.TopologicalSorter() + self.assertRaises(TypeError, ts.add, dict(), 1) + self.assertRaises(TypeError, ts.add, 1, dict()) + self.assertRaises(TypeError, ts.add, dict(), dict()) + + def test_order_of_insertion_does_not_matter_between_groups(self): + def get_groups(ts): + ts.prepare() + while ts.is_active(): + nodes = ts.get_ready() + ts.done(*nodes) + yield set(nodes) + + ts = graphlib.TopologicalSorter() + ts.add(3, 2, 1) + ts.add(1, 0) + ts.add(4, 5) + ts.add(6, 7) + ts.add(4, 7) + + ts2 = graphlib.TopologicalSorter() + ts2.add(1, 0) + ts2.add(3, 2, 1) + ts2.add(4, 7) + ts2.add(6, 7) + ts2.add(4, 5) + + self.assertEqual(list(get_groups(ts)), list(get_groups(ts2))) + + def test_static_order_does_not_change_with_the_hash_seed(self): + def check_order_with_hash_seed(seed): + code = """if 1: + import graphlib + ts = graphlib.TopologicalSorter() + ts.add('blech', 'bluch', 'hola') + ts.add('abcd', 'blech', 'bluch', 'a', 'b') + ts.add('a', 'a string', 'something', 'b') + ts.add('bluch', 'hola', 'abcde', 'a', 'b') + print(list(ts.static_order())) + """ + env = os.environ.copy() + # signal to assert_python not to do a copy + # of os.environ on its own + env["__cleanenv"] = True + env["PYTHONHASHSEED"] = str(seed) + out = assert_python_ok("-c", code, **env) + return out + + run1 = check_order_with_hash_seed(1234) + run2 = check_order_with_hash_seed(31415) + + self.assertNotEqual(run1, "") + self.assertNotEqual(run2, "") + self.assertEqual(run1, run2) diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py index 78334213f24..0f235d1805e 100644 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@ -328,8 +328,15 @@ class TestGzip(BaseTest): cmByte = fRead.read(1) self.assertEqual(cmByte, b'\x08') # deflate + try: + expectedname = self.filename.encode('Latin-1') + b'\x00' + expectedflags = b'\x08' # only the FNAME flag is set + except UnicodeEncodeError: + expectedname = b'' + expectedflags = b'\x00' + flagsByte = fRead.read(1) - self.assertEqual(flagsByte, b'\x08') # only the FNAME flag is set + self.assertEqual(flagsByte, expectedflags) mtimeBytes = fRead.read(4) self.assertEqual(mtimeBytes, struct.pack(' 1, "test needs root privilege and more than one user") def test_chown_with_root(self): uid_1, uid_2 = all_users[:2] - gid = os.stat(support.TESTFN).st_gid - os.chown(support.TESTFN, uid_1, gid) - uid = os.stat(support.TESTFN).st_uid + gid = os.stat(os_helper.TESTFN).st_gid + os.chown(os_helper.TESTFN, uid_1, gid) + uid = os.stat(os_helper.TESTFN).st_uid self.assertEqual(uid, uid_1) - os.chown(support.TESTFN, uid_2, gid) - uid = os.stat(support.TESTFN).st_uid + os.chown(os_helper.TESTFN, uid_2, gid) + uid = os.stat(os_helper.TESTFN).st_uid self.assertEqual(uid, uid_2) @unittest.skipUnless(not root_in_posix and len(all_users) > 1, "test needs non-root account and more than one user") def test_chown_without_permission(self): uid_1, uid_2 = all_users[:2] - gid = os.stat(support.TESTFN).st_gid + gid = os.stat(os_helper.TESTFN).st_gid with self.assertRaises(PermissionError): - os.chown(support.TESTFN, uid_1, gid) - os.chown(support.TESTFN, uid_2, gid) + os.chown(os_helper.TESTFN, uid_1, gid) + os.chown(os_helper.TESTFN, uid_2, gid) @classmethod def tearDownClass(cls): - os.rmdir(support.TESTFN) + os.rmdir(os_helper.TESTFN) class RemoveDirsTests(unittest.TestCase): def setUp(self): - os.makedirs(support.TESTFN) + os.makedirs(os_helper.TESTFN) def tearDown(self): - support.rmtree(support.TESTFN) + os_helper.rmtree(os_helper.TESTFN) def test_remove_all(self): - dira = os.path.join(support.TESTFN, 'dira') + dira = os.path.join(os_helper.TESTFN, 'dira') os.mkdir(dira) dirb = os.path.join(dira, 'dirb') os.mkdir(dirb) os.removedirs(dirb) self.assertFalse(os.path.exists(dirb)) self.assertFalse(os.path.exists(dira)) - self.assertFalse(os.path.exists(support.TESTFN)) + self.assertFalse(os.path.exists(os_helper.TESTFN)) def test_remove_partial(self): - dira = os.path.join(support.TESTFN, 'dira') + dira = os.path.join(os_helper.TESTFN, 'dira') os.mkdir(dira) dirb = os.path.join(dira, 'dirb') os.mkdir(dirb) @@ -1593,10 +1597,10 @@ class RemoveDirsTests(unittest.TestCase): os.removedirs(dirb) self.assertFalse(os.path.exists(dirb)) self.assertTrue(os.path.exists(dira)) - self.assertTrue(os.path.exists(support.TESTFN)) + self.assertTrue(os.path.exists(os_helper.TESTFN)) def test_remove_nothing(self): - dira = os.path.join(support.TESTFN, 'dira') + dira = os.path.join(os_helper.TESTFN, 'dira') os.mkdir(dira) dirb = os.path.join(dira, 'dirb') os.mkdir(dirb) @@ -1605,7 +1609,7 @@ class RemoveDirsTests(unittest.TestCase): os.removedirs(dirb) self.assertTrue(os.path.exists(dirb)) self.assertTrue(os.path.exists(dira)) - self.assertTrue(os.path.exists(support.TESTFN)) + self.assertTrue(os.path.exists(os_helper.TESTFN)) class DevNullTests(unittest.TestCase): @@ -1743,8 +1747,8 @@ class URandomFDTests(unittest.TestCase): def test_urandom_fd_reopened(self): # Issue #21207: urandom() should detect its fd to /dev/urandom # changed to something else, and reopen it. - self.addCleanup(support.unlink, support.TESTFN) - create_file(support.TESTFN, b"x" * 256) + self.addCleanup(os_helper.unlink, os_helper.TESTFN) + create_file(os_helper.TESTFN, b"x" * 256) code = """if 1: import os @@ -1770,7 +1774,7 @@ class URandomFDTests(unittest.TestCase): os.dup2(new_fd, fd) sys.stdout.buffer.write(os.urandom(4)) sys.stdout.buffer.write(os.urandom(4)) - """.format(TESTFN=support.TESTFN) + """.format(TESTFN=os_helper.TESTFN) rc, out, err = assert_python_ok('-Sc', code) self.assertEqual(len(out), 8) self.assertNotEqual(out[0:4], out[4:8]) @@ -1922,36 +1926,36 @@ class ExecTests(unittest.TestCase): class Win32ErrorTests(unittest.TestCase): def setUp(self): try: - os.stat(support.TESTFN) + os.stat(os_helper.TESTFN) except FileNotFoundError: exists = False except OSError as exc: exists = True self.fail("file %s must not exist; os.stat failed with %s" - % (support.TESTFN, exc)) + % (os_helper.TESTFN, exc)) else: - self.fail("file %s must not exist" % support.TESTFN) + self.fail("file %s must not exist" % os_helper.TESTFN) def test_rename(self): - self.assertRaises(OSError, os.rename, support.TESTFN, support.TESTFN+".bak") + self.assertRaises(OSError, os.rename, os_helper.TESTFN, os_helper.TESTFN+".bak") def test_remove(self): - self.assertRaises(OSError, os.remove, support.TESTFN) + self.assertRaises(OSError, os.remove, os_helper.TESTFN) def test_chdir(self): - self.assertRaises(OSError, os.chdir, support.TESTFN) + self.assertRaises(OSError, os.chdir, os_helper.TESTFN) def test_mkdir(self): - self.addCleanup(support.unlink, support.TESTFN) + self.addCleanup(os_helper.unlink, os_helper.TESTFN) - with open(support.TESTFN, "x") as f: - self.assertRaises(OSError, os.mkdir, support.TESTFN) + with open(os_helper.TESTFN, "x") as f: + self.assertRaises(OSError, os.mkdir, os_helper.TESTFN) def test_utime(self): - self.assertRaises(OSError, os.utime, support.TESTFN, None) + self.assertRaises(OSError, os.utime, os_helper.TESTFN, None) def test_chmod(self): - self.assertRaises(OSError, os.chmod, support.TESTFN, 0) + self.assertRaises(OSError, os.chmod, os_helper.TESTFN, 0) class TestInvalidFD(unittest.TestCase): @@ -1969,7 +1973,7 @@ class TestInvalidFD(unittest.TestCase): def check(self, f, *args): try: - f(support.make_bad_fd(), *args) + f(os_helper.make_bad_fd(), *args) except OSError as e: self.assertEqual(e.errno, errno.EBADF) else: @@ -1978,11 +1982,11 @@ class TestInvalidFD(unittest.TestCase): @unittest.skipUnless(hasattr(os, 'isatty'), 'test needs os.isatty()') def test_isatty(self): - self.assertEqual(os.isatty(support.make_bad_fd()), False) + self.assertEqual(os.isatty(os_helper.make_bad_fd()), False) @unittest.skipUnless(hasattr(os, 'closerange'), 'test needs os.closerange()') def test_closerange(self): - fd = support.make_bad_fd() + fd = os_helper.make_bad_fd() # Make sure none of the descriptors we are about to close are # currently valid (issue 6542). for i in range(10): @@ -2056,8 +2060,8 @@ class TestInvalidFD(unittest.TestCase): class LinkTests(unittest.TestCase): def setUp(self): - self.file1 = support.TESTFN - self.file2 = os.path.join(support.TESTFN + "2") + self.file1 = os_helper.TESTFN + self.file2 = os.path.join(os_helper.TESTFN + "2") def tearDown(self): for file in (self.file1, self.file2): @@ -2162,12 +2166,12 @@ class PosixUidGidTests(unittest.TestCase): @unittest.skipIf(sys.platform == "win32", "Posix specific tests") class Pep383Tests(unittest.TestCase): def setUp(self): - if support.TESTFN_UNENCODABLE: - self.dir = support.TESTFN_UNENCODABLE - elif support.TESTFN_NONASCII: - self.dir = support.TESTFN_NONASCII + if os_helper.TESTFN_UNENCODABLE: + self.dir = os_helper.TESTFN_UNENCODABLE + elif os_helper.TESTFN_NONASCII: + self.dir = os_helper.TESTFN_NONASCII else: - self.dir = support.TESTFN + self.dir = os_helper.TESTFN self.bdir = os.fsencode(self.dir) bytesfn = [] @@ -2177,11 +2181,11 @@ class Pep383Tests(unittest.TestCase): except UnicodeEncodeError: return bytesfn.append(fn) - add_filename(support.TESTFN_UNICODE) - if support.TESTFN_UNENCODABLE: - add_filename(support.TESTFN_UNENCODABLE) - if support.TESTFN_NONASCII: - add_filename(support.TESTFN_NONASCII) + add_filename(os_helper.TESTFN_UNICODE) + if os_helper.TESTFN_UNENCODABLE: + add_filename(os_helper.TESTFN_UNENCODABLE) + if os_helper.TESTFN_NONASCII: + add_filename(os_helper.TESTFN_NONASCII) if not bytesfn: self.skipTest("couldn't create any non-ascii filename") @@ -2189,7 +2193,7 @@ class Pep383Tests(unittest.TestCase): os.mkdir(self.dir) try: for fn in bytesfn: - support.create_empty_file(os.path.join(self.bdir, fn)) + os_helper.create_empty_file(os.path.join(self.bdir, fn)) fn = os.fsdecode(fn) if fn in self.unicodefn: raise ValueError("duplicate filename") @@ -2355,41 +2359,41 @@ class Win32ListdirTests(unittest.TestCase): self.created_paths = [] for i in range(2): dir_name = 'SUB%d' % i - dir_path = os.path.join(support.TESTFN, dir_name) + dir_path = os.path.join(os_helper.TESTFN, dir_name) file_name = 'FILE%d' % i - file_path = os.path.join(support.TESTFN, file_name) + file_path = os.path.join(os_helper.TESTFN, file_name) os.makedirs(dir_path) - with open(file_path, 'w') as f: + with open(file_path, 'w', encoding='utf-8') as f: f.write("I'm %s and proud of it. Blame test_os.\n" % file_path) self.created_paths.extend([dir_name, file_name]) self.created_paths.sort() def tearDown(self): - shutil.rmtree(support.TESTFN) + shutil.rmtree(os_helper.TESTFN) def test_listdir_no_extended_path(self): """Test when the path is not an "extended" path.""" # unicode self.assertEqual( - sorted(os.listdir(support.TESTFN)), + sorted(os.listdir(os_helper.TESTFN)), self.created_paths) # bytes self.assertEqual( - sorted(os.listdir(os.fsencode(support.TESTFN))), + sorted(os.listdir(os.fsencode(os_helper.TESTFN))), [os.fsencode(path) for path in self.created_paths]) def test_listdir_extended_path(self): """Test when the path starts with '\\\\?\\'.""" # See: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath # unicode - path = '\\\\?\\' + os.path.abspath(support.TESTFN) + path = '\\\\?\\' + os.path.abspath(os_helper.TESTFN) self.assertEqual( sorted(os.listdir(path)), self.created_paths) # bytes - path = b'\\\\?\\' + os.fsencode(os.path.abspath(support.TESTFN)) + path = b'\\\\?\\' + os.fsencode(os.path.abspath(os_helper.TESTFN)) self.assertEqual( sorted(os.listdir(path)), [os.fsencode(path) for path in self.created_paths]) @@ -2432,32 +2436,32 @@ class ReadlinkTests(unittest.TestCase): self.assertRaises(FileNotFoundError, os.readlink, FakePath('missing-link')) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_pathlike(self): os.symlink(self.filelink_target, self.filelink) - self.addCleanup(support.unlink, self.filelink) + self.addCleanup(os_helper.unlink, self.filelink) filelink = FakePath(self.filelink) self.assertPathEqual(os.readlink(filelink), self.filelink_target) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_pathlike_bytes(self): os.symlink(self.filelinkb_target, self.filelinkb) - self.addCleanup(support.unlink, self.filelinkb) + self.addCleanup(os_helper.unlink, self.filelinkb) path = os.readlink(FakePath(self.filelinkb)) self.assertPathEqual(path, self.filelinkb_target) self.assertIsInstance(path, bytes) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_bytes(self): os.symlink(self.filelinkb_target, self.filelinkb) - self.addCleanup(support.unlink, self.filelinkb) + self.addCleanup(os_helper.unlink, self.filelinkb) path = os.readlink(self.filelinkb) self.assertPathEqual(path, self.filelinkb_target) self.assertIsInstance(path, bytes) @unittest.skipUnless(sys.platform == "win32", "Win32 specific tests") -@support.skip_unless_symlink +@os_helper.skip_unless_symlink class Win32SymlinkTests(unittest.TestCase): filelink = 'filelinktest' filelink_target = os.path.abspath(__file__) @@ -2528,10 +2532,10 @@ class Win32SymlinkTests(unittest.TestCase): self.assertNotEqual(os.lstat(bytes_link), os.stat(bytes_link)) def test_12084(self): - level1 = os.path.abspath(support.TESTFN) + level1 = os.path.abspath(os_helper.TESTFN) level2 = os.path.join(level1, "level2") level3 = os.path.join(level2, "level3") - self.addCleanup(support.rmtree, level1) + self.addCleanup(os_helper.rmtree, level1) os.mkdir(level1) os.mkdir(level2) @@ -2717,7 +2721,7 @@ class Win32NtTests(unittest.TestCase): self.assertEqual(0, handle_delta) -@support.skip_unless_symlink +@os_helper.skip_unless_symlink class NonLocalSymlinkTests(unittest.TestCase): def setUp(self): @@ -2856,8 +2860,8 @@ class SpawnTests(unittest.TestCase): def create_args(self, *, with_env=False, use_bytes=False): self.exitcode = 17 - filename = support.TESTFN - self.addCleanup(support.unlink, filename) + filename = os_helper.TESTFN + self.addCleanup(os_helper.unlink, filename) if not with_env: code = 'import sys; sys.exit(%s)' % self.exitcode @@ -3008,8 +3012,8 @@ class SpawnTests(unittest.TestCase): self.assertEqual(exitcode, 127) # equal character in the environment variable value - filename = support.TESTFN - self.addCleanup(support.unlink, filename) + filename = os_helper.TESTFN + self.addCleanup(os_helper.unlink, filename) with open(filename, "w") as fp: fp.write('import sys, os\n' 'if os.getenv("FRUIT") != "orange=lemon":\n' @@ -3163,13 +3167,13 @@ class TestSendfile(unittest.TestCase): @classmethod def setUpClass(cls): - cls.key = support.threading_setup() - create_file(support.TESTFN, cls.DATA) + cls.key = threading_helper.threading_setup() + create_file(os_helper.TESTFN, cls.DATA) @classmethod def tearDownClass(cls): - support.threading_cleanup(*cls.key) - support.unlink(support.TESTFN) + threading_helper.threading_cleanup(*cls.key) + os_helper.unlink(os_helper.TESTFN) def setUp(self): self.server = SendfileTestServer((socket_helper.HOST, 0)) @@ -3180,7 +3184,7 @@ class TestSendfile(unittest.TestCase): # synchronize by waiting for "220 ready" response self.client.recv(1024) self.sockno = self.client.fileno() - self.file = open(support.TESTFN, 'rb') + self.file = open(os_helper.TESTFN, 'rb') self.fileno = self.file.fileno() def tearDown(self): @@ -3312,10 +3316,10 @@ class TestSendfile(unittest.TestCase): @requires_headers_trailers def test_trailers(self): - TESTFN2 = support.TESTFN + "2" + TESTFN2 = os_helper.TESTFN + "2" file_data = b"abcdef" - self.addCleanup(support.unlink, TESTFN2) + self.addCleanup(os_helper.unlink, TESTFN2) create_file(TESTFN2, file_data) with open(TESTFN2, 'rb') as f: @@ -3361,13 +3365,13 @@ def supports_extended_attributes(): return False try: - with open(support.TESTFN, "xb", 0) as fp: + with open(os_helper.TESTFN, "xb", 0) as fp: try: os.setxattr(fp.fileno(), b"user.test", b"") except OSError: return False finally: - support.unlink(support.TESTFN) + os_helper.unlink(os_helper.TESTFN) return True @@ -3379,8 +3383,8 @@ def supports_extended_attributes(): class ExtendedAttributeTests(unittest.TestCase): def _check_xattrs_str(self, s, getxattr, setxattr, removexattr, listxattr, **kwargs): - fn = support.TESTFN - self.addCleanup(support.unlink, fn) + fn = os_helper.TESTFN + self.addCleanup(os_helper.unlink, fn) create_file(fn) with self.assertRaises(OSError) as cm: @@ -3428,10 +3432,10 @@ class ExtendedAttributeTests(unittest.TestCase): def _check_xattrs(self, *args, **kwargs): self._check_xattrs_str(str, *args, **kwargs) - support.unlink(support.TESTFN) + os_helper.unlink(os_helper.TESTFN) self._check_xattrs_str(os.fsencode, *args, **kwargs) - support.unlink(support.TESTFN) + os_helper.unlink(os_helper.TESTFN) def test_simple(self): self._check_xattrs(os.getxattr, os.setxattr, os.removexattr, @@ -3530,16 +3534,16 @@ class OSErrorTests(unittest.TestCase): self.bytes_filenames = [] self.unicode_filenames = [] - if support.TESTFN_UNENCODABLE is not None: - decoded = support.TESTFN_UNENCODABLE + if os_helper.TESTFN_UNENCODABLE is not None: + decoded = os_helper.TESTFN_UNENCODABLE else: - decoded = support.TESTFN + decoded = os_helper.TESTFN self.unicode_filenames.append(decoded) self.unicode_filenames.append(Str(decoded)) - if support.TESTFN_UNDECODABLE is not None: - encoded = support.TESTFN_UNDECODABLE + if os_helper.TESTFN_UNDECODABLE is not None: + encoded = os_helper.TESTFN_UNDECODABLE else: - encoded = os.fsencode(support.TESTFN) + encoded = os.fsencode(os_helper.TESTFN) self.bytes_filenames.append(encoded) self.bytes_filenames.append(bytearray(encoded)) self.bytes_filenames.append(memoryview(encoded)) @@ -3733,14 +3737,14 @@ class PathTConverterTests(unittest.TestCase): ] def test_path_t_converter(self): - str_filename = support.TESTFN + str_filename = os_helper.TESTFN if os.name == 'nt': bytes_fspath = bytes_filename = None else: - bytes_filename = support.TESTFN.encode('ascii') + bytes_filename = os.fsencode(os_helper.TESTFN) bytes_fspath = FakePath(bytes_filename) fd = os.open(FakePath(str_filename), os.O_WRONLY|os.O_CREAT) - self.addCleanup(support.unlink, support.TESTFN) + self.addCleanup(os_helper.unlink, os_helper.TESTFN) self.addCleanup(os.close, fd) int_fspath = FakePath(fd) @@ -3810,8 +3814,8 @@ class ExportsTests(unittest.TestCase): class TestDirEntry(unittest.TestCase): def setUp(self): - self.path = os.path.realpath(support.TESTFN) - self.addCleanup(support.rmtree, self.path) + self.path = os.path.realpath(os_helper.TESTFN) + self.addCleanup(os_helper.rmtree, self.path) os.mkdir(self.path) def test_uninstantiable(self): @@ -3827,12 +3831,12 @@ class TestDirEntry(unittest.TestCase): class TestScandir(unittest.TestCase): - check_no_resource_warning = support.check_no_resource_warning + check_no_resource_warning = warnings_helper.check_no_resource_warning def setUp(self): - self.path = os.path.realpath(support.TESTFN) + self.path = os.path.realpath(os_helper.TESTFN) self.bytes_path = os.fsencode(self.path) - self.addCleanup(support.rmtree, self.path) + self.addCleanup(os_helper.rmtree, self.path) os.mkdir(self.path) def create_file(self, name="file.txt"): @@ -3902,7 +3906,7 @@ class TestScandir(unittest.TestCase): def test_attributes(self): link = hasattr(os, 'link') - symlink = support.can_symlink() + symlink = os_helper.can_symlink() dirname = os.path.join(self.path, "dir") os.mkdir(dirname) @@ -4026,7 +4030,7 @@ class TestScandir(unittest.TestCase): self.assertRaises(FileNotFoundError, entry.stat, follow_symlinks=False) def test_broken_symlink(self): - if not support.can_symlink(): + if not os_helper.can_symlink(): return self.skipTest('cannot create symbolic link') filename = self.create_file("file.txt") @@ -4080,7 +4084,7 @@ class TestScandir(unittest.TestCase): self.assertIn(os.scandir, os.supports_fd) self.create_file('file.txt') expected_names = ['file.txt'] - if support.can_symlink(): + if os_helper.can_symlink(): os.symlink('file.txt', os.path.join(self.path, 'link')) expected_names.append('link') diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py deleted file mode 100644 index a4d2cdc090a..00000000000 --- a/Lib/test/test_parser.py +++ /dev/null @@ -1,1046 +0,0 @@ -import copy -import warnings -with warnings.catch_warnings(): - warnings.filterwarnings('ignore', 'The parser module is deprecated', - DeprecationWarning) - import parser -import pickle -import unittest -import operator -import struct -from test import support -from test.support.script_helper import assert_python_failure -from test.support.script_helper import assert_python_ok - -# -# First, we test that we can generate trees from valid source fragments, -# and that these valid trees are indeed allowed by the tree-loading side -# of the parser module. -# - -class RoundtripLegalSyntaxTestCase(unittest.TestCase): - - def roundtrip(self, f, s): - st1 = f(s) - t = st1.totuple() - try: - st2 = parser.sequence2st(t) - except parser.ParserError as why: - self.fail("could not roundtrip %r: %s" % (s, why)) - - self.assertEqual(t, st2.totuple(), - "could not re-generate syntax tree") - - def check_expr(self, s): - self.roundtrip(parser.expr, s) - - def test_flags_passed(self): - # The unicode literals flags has to be passed from the parser to AST - # generation. - suite = parser.suite("from __future__ import unicode_literals; x = ''") - code = suite.compile() - scope = {} - exec(code, {}, scope) - self.assertIsInstance(scope["x"], str) - - def check_suite(self, s): - self.roundtrip(parser.suite, s) - - def test_yield_statement(self): - self.check_suite("def f(): yield 1") - self.check_suite("def f(): yield") - self.check_suite("def f(): x += yield") - self.check_suite("def f(): x = yield 1") - self.check_suite("def f(): x = y = yield 1") - self.check_suite("def f(): x = yield") - self.check_suite("def f(): x = y = yield") - self.check_suite("def f(): 1 + (yield)*2") - self.check_suite("def f(): (yield 1)*2") - self.check_suite("def f(): return; yield 1") - self.check_suite("def f(): yield 1; return") - self.check_suite("def f(): yield from 1") - self.check_suite("def f(): x = yield from 1") - self.check_suite("def f(): f((yield from 1))") - self.check_suite("def f(): yield 1; return 1") - self.check_suite("def f():\n" - " for x in range(30):\n" - " yield x\n") - self.check_suite("def f():\n" - " if (yield):\n" - " yield x\n") - - def test_await_statement(self): - self.check_suite("async def f():\n await smth()") - self.check_suite("async def f():\n foo = await smth()") - self.check_suite("async def f():\n foo, bar = await smth()") - self.check_suite("async def f():\n (await smth())") - self.check_suite("async def f():\n foo((await smth()))") - self.check_suite("async def f():\n await foo(); return 42") - - def test_async_with_statement(self): - self.check_suite("async def f():\n async with 1: pass") - self.check_suite("async def f():\n async with a as b, c as d: pass") - - def test_async_for_statement(self): - self.check_suite("async def f():\n async for i in (): pass") - self.check_suite("async def f():\n async for i, b in (): pass") - - def test_nonlocal_statement(self): - self.check_suite("def f():\n" - " x = 0\n" - " def g():\n" - " nonlocal x\n") - self.check_suite("def f():\n" - " x = y = 0\n" - " def g():\n" - " nonlocal x, y\n") - - def test_expressions(self): - self.check_expr("foo(1)") - self.check_expr("[1, 2, 3]") - self.check_expr("[x**3 for x in range(20)]") - self.check_expr("[x**3 for x in range(20) if x % 3]") - self.check_expr("[x**3 for x in range(20) if x % 2 if x % 3]") - self.check_expr("list(x**3 for x in range(20))") - self.check_expr("list(x**3 for x in range(20) if x % 3)") - self.check_expr("list(x**3 for x in range(20) if x % 2 if x % 3)") - self.check_expr("foo(*args)") - self.check_expr("foo(*args, **kw)") - self.check_expr("foo(**kw)") - self.check_expr("foo(key=value)") - self.check_expr("foo(key=value, *args)") - self.check_expr("foo(key=value, *args, **kw)") - self.check_expr("foo(key=value, **kw)") - self.check_expr("foo(a, b, c, *args)") - self.check_expr("foo(a, b, c, *args, **kw)") - self.check_expr("foo(a, b, c, **kw)") - self.check_expr("foo(a, *args, keyword=23)") - self.check_expr("foo + bar") - self.check_expr("foo - bar") - self.check_expr("foo * bar") - self.check_expr("foo / bar") - self.check_expr("foo // bar") - self.check_expr("(foo := 1)") - self.check_expr("lambda: 0") - self.check_expr("lambda x: 0") - self.check_expr("lambda *y: 0") - self.check_expr("lambda *y, **z: 0") - self.check_expr("lambda **z: 0") - self.check_expr("lambda x, y: 0") - self.check_expr("lambda foo=bar: 0") - self.check_expr("lambda foo=bar, spaz=nifty+spit: 0") - self.check_expr("lambda foo=bar, **z: 0") - self.check_expr("lambda foo=bar, blaz=blat+2, **z: 0") - self.check_expr("lambda foo=bar, blaz=blat+2, *y, **z: 0") - self.check_expr("lambda x, *y, **z: 0") - self.check_expr("(x for x in range(10))") - self.check_expr("foo(x for x in range(10))") - self.check_expr("...") - self.check_expr("a[...]") - - def test_simple_expression(self): - # expr_stmt - self.check_suite("a") - - def test_simple_assignments(self): - self.check_suite("a = b") - self.check_suite("a = b = c = d = e") - - def test_var_annot(self): - self.check_suite("x: int = 5") - self.check_suite("y: List[T] = []; z: [list] = fun()") - self.check_suite("x: tuple = (1, 2)") - self.check_suite("d[f()]: int = 42") - self.check_suite("f(d[x]): str = 'abc'") - self.check_suite("x.y.z.w: complex = 42j") - self.check_suite("x: int") - self.check_suite("def f():\n" - " x: str\n" - " y: int = 5\n") - self.check_suite("class C:\n" - " x: str\n" - " y: int = 5\n") - self.check_suite("class C:\n" - " def __init__(self, x: int) -> None:\n" - " self.x: int = x\n") - # double check for nonsense - with self.assertRaises(SyntaxError): - exec("2+2: int", {}, {}) - with self.assertRaises(SyntaxError): - exec("[]: int = 5", {}, {}) - with self.assertRaises(SyntaxError): - exec("x, *y, z: int = range(5)", {}, {}) - with self.assertRaises(SyntaxError): - exec("x: int = 1, y = 2", {}, {}) - with self.assertRaises(SyntaxError): - exec("u = v: int", {}, {}) - with self.assertRaises(SyntaxError): - exec("False: int", {}, {}) - with self.assertRaises(SyntaxError): - exec("x.False: int", {}, {}) - with self.assertRaises(SyntaxError): - exec("x.y,: int", {}, {}) - with self.assertRaises(SyntaxError): - exec("[0]: int", {}, {}) - with self.assertRaises(SyntaxError): - exec("f(): int", {}, {}) - - def test_simple_augmented_assignments(self): - self.check_suite("a += b") - self.check_suite("a -= b") - self.check_suite("a *= b") - self.check_suite("a /= b") - self.check_suite("a //= b") - self.check_suite("a %= b") - self.check_suite("a &= b") - self.check_suite("a |= b") - self.check_suite("a ^= b") - self.check_suite("a <<= b") - self.check_suite("a >>= b") - self.check_suite("a **= b") - - def test_function_defs(self): - self.check_suite("def f(): pass") - self.check_suite("def f(*args): pass") - self.check_suite("def f(*args, **kw): pass") - self.check_suite("def f(**kw): pass") - self.check_suite("def f(foo=bar): pass") - self.check_suite("def f(foo=bar, *args): pass") - self.check_suite("def f(foo=bar, *args, **kw): pass") - self.check_suite("def f(foo=bar, **kw): pass") - - self.check_suite("def f(a, b): pass") - self.check_suite("def f(a, b, *args): pass") - self.check_suite("def f(a, b, *args, **kw): pass") - self.check_suite("def f(a, b, **kw): pass") - self.check_suite("def f(a, b, foo=bar): pass") - self.check_suite("def f(a, b, foo=bar, *args): pass") - self.check_suite("def f(a, b, foo=bar, *args, **kw): pass") - self.check_suite("def f(a, b, foo=bar, **kw): pass") - - self.check_suite("@staticmethod\n" - "def f(): pass") - self.check_suite("@staticmethod\n" - "@funcattrs(x, y)\n" - "def f(): pass") - self.check_suite("@funcattrs()\n" - "def f(): pass") - - self.check_suite("@False or x\n" - "def f(): pass") - self.check_suite("@d := x\n" - "def f(): pass") - self.check_suite("@lambda f: x(f)\n" - "def f(): pass") - self.check_suite("@[..., x, ...][1]\n" - "def f(): pass") - self.check_suite("@x(x)(x)\n" - "def f(): pass") - self.check_suite("@(x, x)\n" - "def f(): pass") - self.check_suite("@...\n" - "def f(): pass") - self.check_suite("@None\n" - "def f(): pass") - self.check_suite("@w @(x @y) @(z)\n" - "def f(): pass") - self.check_suite("@w[x].y.z\n" - "def f(): pass") - - # keyword-only arguments - self.check_suite("def f(*, a): pass") - self.check_suite("def f(*, a = 5): pass") - self.check_suite("def f(*, a = 5, b): pass") - self.check_suite("def f(*, a, b = 5): pass") - self.check_suite("def f(*, a, b = 5, **kwds): pass") - self.check_suite("def f(*args, a): pass") - self.check_suite("def f(*args, a = 5): pass") - self.check_suite("def f(*args, a = 5, b): pass") - self.check_suite("def f(*args, a, b = 5): pass") - self.check_suite("def f(*args, a, b = 5, **kwds): pass") - - # positional-only arguments - self.check_suite("def f(a, /): pass") - self.check_suite("def f(a, /,): pass") - self.check_suite("def f(a, b, /): pass") - self.check_suite("def f(a, b, /, c): pass") - self.check_suite("def f(a, b, /, c = 6): pass") - self.check_suite("def f(a, b, /, c, *, d): pass") - self.check_suite("def f(a, b, /, c = 1, *, d): pass") - self.check_suite("def f(a, b, /, c, *, d = 1): pass") - self.check_suite("def f(a, b=1, /, c=2, *, d = 3): pass") - self.check_suite("def f(a=0, b=1, /, c=2, *, d = 3): pass") - - # function annotations - self.check_suite("def f(a: int): pass") - self.check_suite("def f(a: int = 5): pass") - self.check_suite("def f(*args: list): pass") - self.check_suite("def f(**kwds: dict): pass") - self.check_suite("def f(*, a: int): pass") - self.check_suite("def f(*, a: int = 5): pass") - self.check_suite("def f() -> int: pass") - - def test_class_defs(self): - self.check_suite("class foo():pass") - self.check_suite("class foo(object):pass") - self.check_suite("@class_decorator\n" - "class foo():pass") - self.check_suite("@class_decorator(arg)\n" - "class foo():pass") - self.check_suite("@decorator1\n" - "@decorator2\n" - "class foo():pass") - - self.check_suite("@False or x\n" - "class C: pass") - self.check_suite("@d := x\n" - "class C: pass") - self.check_suite("@lambda f: x(f)\n" - "class C: pass") - self.check_suite("@[..., x, ...][1]\n" - "class C: pass") - self.check_suite("@x(x)(x)\n" - "class C: pass") - self.check_suite("@(x, x)\n" - "class C: pass") - self.check_suite("@...\n" - "class C: pass") - self.check_suite("@None\n" - "class C: pass") - self.check_suite("@w @(x @y) @(z)\n" - "class C: pass") - self.check_suite("@w[x].y.z\n" - "class C: pass") - - def test_import_from_statement(self): - self.check_suite("from sys.path import *") - self.check_suite("from sys.path import dirname") - self.check_suite("from sys.path import (dirname)") - self.check_suite("from sys.path import (dirname,)") - self.check_suite("from sys.path import dirname as my_dirname") - self.check_suite("from sys.path import (dirname as my_dirname)") - self.check_suite("from sys.path import (dirname as my_dirname,)") - self.check_suite("from sys.path import dirname, basename") - self.check_suite("from sys.path import (dirname, basename)") - self.check_suite("from sys.path import (dirname, basename,)") - self.check_suite( - "from sys.path import dirname as my_dirname, basename") - self.check_suite( - "from sys.path import (dirname as my_dirname, basename)") - self.check_suite( - "from sys.path import (dirname as my_dirname, basename,)") - self.check_suite( - "from sys.path import dirname, basename as my_basename") - self.check_suite( - "from sys.path import (dirname, basename as my_basename)") - self.check_suite( - "from sys.path import (dirname, basename as my_basename,)") - self.check_suite("from .bogus import x") - - def test_basic_import_statement(self): - self.check_suite("import sys") - self.check_suite("import sys as system") - self.check_suite("import sys, math") - self.check_suite("import sys as system, math") - self.check_suite("import sys, math as my_math") - - def test_relative_imports(self): - self.check_suite("from . import name") - self.check_suite("from .. import name") - # check all the way up to '....', since '...' is tokenized - # differently from '.' (it's an ellipsis token). - self.check_suite("from ... import name") - self.check_suite("from .... import name") - self.check_suite("from .pkg import name") - self.check_suite("from ..pkg import name") - self.check_suite("from ...pkg import name") - self.check_suite("from ....pkg import name") - - def test_pep263(self): - self.check_suite("# -*- coding: iso-8859-1 -*-\n" - "pass\n") - - def test_assert(self): - self.check_suite("assert alo < ahi and blo < bhi\n") - - def test_with(self): - self.check_suite("with open('x'): pass\n") - self.check_suite("with open('x') as f: pass\n") - self.check_suite("with open('x') as f, open('y') as g: pass\n") - - def test_try_stmt(self): - self.check_suite("try: pass\nexcept: pass\n") - self.check_suite("try: pass\nfinally: pass\n") - self.check_suite("try: pass\nexcept A: pass\nfinally: pass\n") - self.check_suite("try: pass\nexcept A: pass\nexcept: pass\n" - "finally: pass\n") - self.check_suite("try: pass\nexcept: pass\nelse: pass\n") - self.check_suite("try: pass\nexcept: pass\nelse: pass\n" - "finally: pass\n") - - def test_if_stmt(self): - self.check_suite("if True:\n pass\nelse:\n pass\n") - self.check_suite("if True:\n pass\nelif True:\n pass\nelse:\n pass\n") - - def test_position(self): - # An absolutely minimal test of position information. Better - # tests would be a big project. - code = "def f(x):\n return x + 1" - st = parser.suite(code) - - def walk(tree): - node_type = tree[0] - next = tree[1] - if isinstance(next, (tuple, list)): - for elt in tree[1:]: - for x in walk(elt): - yield x - else: - yield tree - - expected = [ - (1, 'def', 1, 0), - (1, 'f', 1, 4), - (7, '(', 1, 5), - (1, 'x', 1, 6), - (8, ')', 1, 7), - (11, ':', 1, 8), - (4, '', 1, 9), - (5, '', 2, -1), - (1, 'return', 2, 4), - (1, 'x', 2, 11), - (14, '+', 2, 13), - (2, '1', 2, 15), - (4, '', 2, 16), - (6, '', 2, -1), - (4, '', 2, -1), - (0, '', 2, -1), - ] - - self.assertEqual(list(walk(st.totuple(line_info=True, col_info=True))), - expected) - self.assertEqual(list(walk(st.totuple())), - [(t, n) for t, n, l, c in expected]) - self.assertEqual(list(walk(st.totuple(line_info=True))), - [(t, n, l) for t, n, l, c in expected]) - self.assertEqual(list(walk(st.totuple(col_info=True))), - [(t, n, c) for t, n, l, c in expected]) - self.assertEqual(list(walk(st.tolist(line_info=True, col_info=True))), - [list(x) for x in expected]) - self.assertEqual(list(walk(parser.st2tuple(st, line_info=True, - col_info=True))), - expected) - self.assertEqual(list(walk(parser.st2list(st, line_info=True, - col_info=True))), - [list(x) for x in expected]) - - def test_extended_unpacking(self): - self.check_suite("*a = y") - self.check_suite("x, *b, = m") - self.check_suite("[*a, *b] = y") - self.check_suite("for [*x, b] in x: pass") - - def test_raise_statement(self): - self.check_suite("raise\n") - self.check_suite("raise e\n") - self.check_suite("try:\n" - " suite\n" - "except Exception as e:\n" - " raise ValueError from e\n") - - def test_list_displays(self): - self.check_expr('[]') - self.check_expr('[*{2}, 3, *[4]]') - - def test_set_displays(self): - self.check_expr('{*{2}, 3, *[4]}') - self.check_expr('{2}') - self.check_expr('{2,}') - self.check_expr('{2, 3}') - self.check_expr('{2, 3,}') - - def test_dict_displays(self): - self.check_expr('{}') - self.check_expr('{a:b}') - self.check_expr('{a:b,}') - self.check_expr('{a:b, c:d}') - self.check_expr('{a:b, c:d,}') - self.check_expr('{**{}}') - self.check_expr('{**{}, 3:4, **{5:6, 7:8}}') - - def test_argument_unpacking(self): - self.check_expr("f(*a, **b)") - self.check_expr('f(a, *b, *c, *d)') - self.check_expr('f(**a, **b)') - self.check_expr('f(2, *a, *b, **b, **c, **d)') - self.check_expr("f(*b, *() or () and (), **{} and {}, **() or {})") - - def test_set_comprehensions(self): - self.check_expr('{x for x in seq}') - self.check_expr('{f(x) for x in seq}') - self.check_expr('{f(x) for x in seq if condition(x)}') - - def test_dict_comprehensions(self): - self.check_expr('{x:x for x in seq}') - self.check_expr('{x**2:x[3] for x in seq if condition(x)}') - self.check_expr('{x:x for x in seq1 for y in seq2 if condition(x, y)}') - - def test_named_expressions(self): - self.check_suite("(a := 1)") - self.check_suite("(a := a)") - self.check_suite("if (match := pattern.search(data)) is None: pass") - self.check_suite("while match := pattern.search(f.read()): pass") - self.check_suite("[y := f(x), y**2, y**3]") - self.check_suite("filtered_data = [y for x in data if (y := f(x)) is None]") - self.check_suite("(y := f(x))") - self.check_suite("y0 = (y1 := f(x))") - self.check_suite("foo(x=(y := f(x)))") - self.check_suite("def foo(answer=(p := 42)): pass") - self.check_suite("def foo(answer: (p := 42) = 5): pass") - self.check_suite("lambda: (x := 1)") - self.check_suite("(x := lambda: 1)") - self.check_suite("(x := lambda: (y := 1))") # not in PEP - self.check_suite("lambda line: (m := re.match(pattern, line)) and m.group(1)") - self.check_suite("x = (y := 0)") - self.check_suite("(z:=(y:=(x:=0)))") - self.check_suite("(info := (name, phone, *rest))") - self.check_suite("(x:=1,2)") - self.check_suite("(total := total + tax)") - self.check_suite("len(lines := f.readlines())") - self.check_suite("foo(x := 3, cat='vector')") - self.check_suite("foo(cat=(category := 'vector'))") - self.check_suite("if any(len(longline := l) >= 100 for l in lines): print(longline)") - self.check_suite( - "if env_base := os.environ.get('PYTHONUSERBASE', None): return env_base" - ) - self.check_suite( - "if self._is_special and (ans := self._check_nans(context=context)): return ans" - ) - self.check_suite("foo(b := 2, a=1)") - self.check_suite("foo(b := 2, a=1)") - self.check_suite("foo((b := 2), a=1)") - self.check_suite("foo(c=(b := 2), a=1)") - self.check_suite("{(x := C(i)).q: x for i in y}") - - -# -# Second, we take *invalid* trees and make sure we get ParserError -# rejections for them. -# - -class IllegalSyntaxTestCase(unittest.TestCase): - - def check_bad_tree(self, tree, label): - try: - parser.sequence2st(tree) - except parser.ParserError: - pass - else: - self.fail("did not detect invalid tree for %r" % label) - - def test_junk(self): - # not even remotely valid: - self.check_bad_tree((1, 2, 3), "") - - def test_illegal_terminal(self): - tree = \ - (257, - (269, - (270, - (271, - (277, - (1,))), - (4, ''))), - (4, ''), - (0, '')) - self.check_bad_tree(tree, "too small items in terminal node") - tree = \ - (257, - (269, - (270, - (271, - (277, - (1, b'pass'))), - (4, ''))), - (4, ''), - (0, '')) - self.check_bad_tree(tree, "non-string second item in terminal node") - tree = \ - (257, - (269, - (270, - (271, - (277, - (1, 'pass', '0', 0))), - (4, ''))), - (4, ''), - (0, '')) - self.check_bad_tree(tree, "non-integer third item in terminal node") - tree = \ - (257, - (269, - (270, - (271, - (277, - (1, 'pass', 0, 0))), - (4, ''))), - (4, ''), - (0, '')) - self.check_bad_tree(tree, "too many items in terminal node") - - def test_illegal_yield_1(self): - # Illegal yield statement: def f(): return 1; yield 1 - tree = \ - (257, - (264, - (285, - (259, - (1, 'def'), - (1, 'f'), - (260, (7, '('), (8, ')')), - (11, ':'), - (291, - (4, ''), - (5, ''), - (264, - (265, - (266, - (272, - (275, - (1, 'return'), - (313, - (292, - (293, - (294, - (295, - (297, - (298, - (299, - (300, - (301, - (302, (303, (304, (305, (2, '1')))))))))))))))))), - (264, - (265, - (266, - (272, - (276, - (1, 'yield'), - (313, - (292, - (293, - (294, - (295, - (297, - (298, - (299, - (300, - (301, - (302, - (303, (304, (305, (2, '1')))))))))))))))))), - (4, ''))), - (6, ''))))), - (4, ''), - (0, '')))) - self.check_bad_tree(tree, "def f():\n return 1\n yield 1") - - def test_illegal_yield_2(self): - # Illegal return in generator: def f(): return 1; yield 1 - tree = \ - (257, - (264, - (265, - (266, - (278, - (1, 'from'), - (281, (1, '__future__')), - (1, 'import'), - (279, (1, 'generators')))), - (4, ''))), - (264, - (285, - (259, - (1, 'def'), - (1, 'f'), - (260, (7, '('), (8, ')')), - (11, ':'), - (291, - (4, ''), - (5, ''), - (264, - (265, - (266, - (272, - (275, - (1, 'return'), - (313, - (292, - (293, - (294, - (295, - (297, - (298, - (299, - (300, - (301, - (302, (303, (304, (305, (2, '1')))))))))))))))))), - (264, - (265, - (266, - (272, - (276, - (1, 'yield'), - (313, - (292, - (293, - (294, - (295, - (297, - (298, - (299, - (300, - (301, - (302, - (303, (304, (305, (2, '1')))))))))))))))))), - (4, ''))), - (6, ''))))), - (4, ''), - (0, '')))) - self.check_bad_tree(tree, "def f():\n return 1\n yield 1") - - def test_a_comma_comma_c(self): - # Illegal input: a,,c - tree = \ - (258, - (311, - (290, - (291, - (292, - (293, - (295, - (296, - (297, - (298, (299, (300, (301, (302, (303, (1, 'a')))))))))))))), - (12, ','), - (12, ','), - (290, - (291, - (292, - (293, - (295, - (296, - (297, - (298, (299, (300, (301, (302, (303, (1, 'c'))))))))))))))), - (4, ''), - (0, '')) - self.check_bad_tree(tree, "a,,c") - - def test_illegal_operator(self): - # Illegal input: a $= b - tree = \ - (257, - (264, - (265, - (266, - (267, - (312, - (291, - (292, - (293, - (294, - (296, - (297, - (298, - (299, - (300, (301, (302, (303, (304, (1, 'a'))))))))))))))), - (268, (37, '$=')), - (312, - (291, - (292, - (293, - (294, - (296, - (297, - (298, - (299, - (300, (301, (302, (303, (304, (1, 'b'))))))))))))))))), - (4, ''))), - (0, '')) - self.check_bad_tree(tree, "a $= b") - - def test_malformed_global(self): - #doesn't have global keyword in ast - tree = (257, - (264, - (265, - (266, - (282, (1, 'foo'))), (4, ''))), - (4, ''), - (0, '')) - self.check_bad_tree(tree, "malformed global ast") - - def test_missing_import_source(self): - # from import fred - tree = \ - (257, - (268, - (269, - (270, - (282, - (284, (1, 'from'), (1, 'import'), - (287, (285, (1, 'fred')))))), - (4, ''))), - (4, ''), (0, '')) - self.check_bad_tree(tree, "from import fred") - - def test_illegal_encoding(self): - # Illegal encoding declaration - tree = \ - (341, - (257, (0, ''))) - self.check_bad_tree(tree, "missed encoding") - tree = \ - (341, - (257, (0, '')), - b'iso-8859-1') - self.check_bad_tree(tree, "non-string encoding") - tree = \ - (341, - (257, (0, '')), - '\udcff') - with self.assertRaises(UnicodeEncodeError): - parser.sequence2st(tree) - - def test_invalid_node_id(self): - tree = (257, (269, (-7, ''))) - self.check_bad_tree(tree, "negative node id") - tree = (257, (269, (99, ''))) - self.check_bad_tree(tree, "invalid token id") - tree = (257, (269, (9999, (0, '')))) - self.check_bad_tree(tree, "invalid symbol id") - - def test_ParserError_message(self): - try: - parser.sequence2st((257,(269,(257,(0,''))))) - except parser.ParserError as why: - self.assertIn("compound_stmt", str(why)) # Expected - self.assertIn("file_input", str(why)) # Got - - - -class CompileTestCase(unittest.TestCase): - - # These tests are very minimal. :-( - - def test_compile_expr(self): - st = parser.expr('2 + 3') - code = parser.compilest(st) - self.assertEqual(eval(code), 5) - - def test_compile_suite(self): - st = parser.suite('x = 2; y = x + 3') - code = parser.compilest(st) - globs = {} - exec(code, globs) - self.assertEqual(globs['y'], 5) - - def test_compile_error(self): - st = parser.suite('1 = 3 + 4') - self.assertRaises(SyntaxError, parser.compilest, st) - - def test_compile_badunicode(self): - st = parser.suite('a = "\\U12345678"') - self.assertRaises(SyntaxError, parser.compilest, st) - st = parser.suite('a = "\\u1"') - self.assertRaises(SyntaxError, parser.compilest, st) - - def test_issue_9011(self): - # Issue 9011: compilation of an unary minus expression changed - # the meaning of the ST, so that a second compilation produced - # incorrect results. - st = parser.expr('-3') - code1 = parser.compilest(st) - self.assertEqual(eval(code1), -3) - code2 = parser.compilest(st) - self.assertEqual(eval(code2), -3) - - def test_compile_filename(self): - st = parser.expr('a + 5') - code = parser.compilest(st) - self.assertEqual(code.co_filename, '') - code = st.compile() - self.assertEqual(code.co_filename, '') - for filename in 'file.py', b'file.py': - code = parser.compilest(st, filename) - self.assertEqual(code.co_filename, 'file.py') - code = st.compile(filename) - self.assertEqual(code.co_filename, 'file.py') - for filename in bytearray(b'file.py'), memoryview(b'file.py'): - with self.assertWarns(DeprecationWarning): - code = parser.compilest(st, filename) - self.assertEqual(code.co_filename, 'file.py') - with self.assertWarns(DeprecationWarning): - code = st.compile(filename) - self.assertEqual(code.co_filename, 'file.py') - self.assertRaises(TypeError, parser.compilest, st, list(b'file.py')) - self.assertRaises(TypeError, st.compile, list(b'file.py')) - - -class ParserStackLimitTestCase(unittest.TestCase): - """try to push the parser to/over its limits. - see http://bugs.python.org/issue1881 for a discussion - """ - def _nested_expression(self, level): - return "["*level+"]"*level - - def test_deeply_nested_list(self): - # This has fluctuated between 99 levels in 2.x, down to 93 levels in - # 3.7.X and back up to 99 in 3.8.X. Related to MAXSTACK size in Parser.h - e = self._nested_expression(99) - st = parser.expr(e) - st.compile() - - def test_trigger_memory_error(self): - e = self._nested_expression(100) - rc, out, err = assert_python_failure('-Xoldparser', '-c', e) - # parsing the expression will result in an error message - # followed by a MemoryError (see #11963) - self.assertIn(b's_push: parser stack overflow', err) - self.assertIn(b'MemoryError', err) - -class STObjectTestCase(unittest.TestCase): - """Test operations on ST objects themselves""" - - def test_comparisons(self): - # ST objects should support order and equality comparisons - st1 = parser.expr('2 + 3') - st2 = parser.suite('x = 2; y = x + 3') - st3 = parser.expr('list(x**3 for x in range(20))') - st1_copy = parser.expr('2 + 3') - st2_copy = parser.suite('x = 2; y = x + 3') - st3_copy = parser.expr('list(x**3 for x in range(20))') - - # exercise fast path for object identity - self.assertEqual(st1 == st1, True) - self.assertEqual(st2 == st2, True) - self.assertEqual(st3 == st3, True) - # slow path equality - self.assertEqual(st1, st1_copy) - self.assertEqual(st2, st2_copy) - self.assertEqual(st3, st3_copy) - self.assertEqual(st1 == st2, False) - self.assertEqual(st1 == st3, False) - self.assertEqual(st2 == st3, False) - self.assertEqual(st1 != st1, False) - self.assertEqual(st2 != st2, False) - self.assertEqual(st3 != st3, False) - self.assertEqual(st1 != st1_copy, False) - self.assertEqual(st2 != st2_copy, False) - self.assertEqual(st3 != st3_copy, False) - self.assertEqual(st2 != st1, True) - self.assertEqual(st1 != st3, True) - self.assertEqual(st3 != st2, True) - # we don't particularly care what the ordering is; just that - # it's usable and self-consistent - self.assertEqual(st1 < st2, not (st2 <= st1)) - self.assertEqual(st1 < st3, not (st3 <= st1)) - self.assertEqual(st2 < st3, not (st3 <= st2)) - self.assertEqual(st1 < st2, st2 > st1) - self.assertEqual(st1 < st3, st3 > st1) - self.assertEqual(st2 < st3, st3 > st2) - self.assertEqual(st1 <= st2, st2 >= st1) - self.assertEqual(st3 <= st1, st1 >= st3) - self.assertEqual(st2 <= st3, st3 >= st2) - # transitivity - bottom = min(st1, st2, st3) - top = max(st1, st2, st3) - mid = sorted([st1, st2, st3])[1] - self.assertTrue(bottom < mid) - self.assertTrue(bottom < top) - self.assertTrue(mid < top) - self.assertTrue(bottom <= mid) - self.assertTrue(bottom <= top) - self.assertTrue(mid <= top) - self.assertTrue(bottom <= bottom) - self.assertTrue(mid <= mid) - self.assertTrue(top <= top) - # interaction with other types - self.assertEqual(st1 == 1588.602459, False) - self.assertEqual('spanish armada' != st2, True) - self.assertRaises(TypeError, operator.ge, st3, None) - self.assertRaises(TypeError, operator.le, False, st1) - self.assertRaises(TypeError, operator.lt, st1, 1815) - self.assertRaises(TypeError, operator.gt, b'waterloo', st2) - - def test_copy_pickle(self): - sts = [ - parser.expr('2 + 3'), - parser.suite('x = 2; y = x + 3'), - parser.expr('list(x**3 for x in range(20))') - ] - for st in sts: - st_copy = copy.copy(st) - self.assertEqual(st_copy.totuple(), st.totuple()) - st_copy = copy.deepcopy(st) - self.assertEqual(st_copy.totuple(), st.totuple()) - for proto in range(pickle.HIGHEST_PROTOCOL+1): - st_copy = pickle.loads(pickle.dumps(st, proto)) - self.assertEqual(st_copy.totuple(), st.totuple()) - - check_sizeof = support.check_sizeof - - @support.cpython_only - def test_sizeof(self): - def XXXROUNDUP(n): - if n <= 1: - return n - if n <= 128: - return (n + 3) & ~3 - return 1 << (n - 1).bit_length() - - basesize = support.calcobjsize('Piii') - nodesize = struct.calcsize('hP3iP0h2i') - def sizeofchildren(node): - if node is None: - return 0 - res = 0 - hasstr = len(node) > 1 and isinstance(node[-1], str) - if hasstr: - res += len(node[-1]) + 1 - children = node[1:-1] if hasstr else node[1:] - if children: - res += XXXROUNDUP(len(children)) * nodesize - for child in children: - res += sizeofchildren(child) - return res - - def check_st_sizeof(st): - self.check_sizeof(st, basesize + nodesize + - sizeofchildren(st.totuple())) - - check_st_sizeof(parser.expr('2 + 3')) - check_st_sizeof(parser.expr('2 + 3 + 4')) - check_st_sizeof(parser.suite('x = 2 + 3')) - check_st_sizeof(parser.suite('')) - check_st_sizeof(parser.suite('# -*- coding: utf-8 -*-')) - check_st_sizeof(parser.expr('[' + '2,' * 1000 + ']')) - - - # XXX tests for pickling and unpickling of ST objects should go here - -class OtherParserCase(unittest.TestCase): - - def test_two_args_to_expr(self): - # See bug #12264 - with self.assertRaises(TypeError): - parser.expr("a", "b") - - -class TestDeprecation(unittest.TestCase): - def test_deprecation_message(self): - code = "def f():\n import parser\n\nf()" - rc, out, err = assert_python_ok('-c', code) - self.assertIn(b':2: DeprecationWarning', err) - - -if __name__ == "__main__": - unittest.main() diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index fcb7e4e6072..65bca291d96 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -5,6 +5,7 @@ import os import pdb import sys import types +import codecs import unittest import subprocess import textwrap @@ -1197,6 +1198,7 @@ class PdbTestCase(unittest.TestCase): stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, + env = {**os.environ, 'PYTHONIOENCODING': 'utf-8'} ) as proc: stdout, stderr = proc.communicate(str.encode(commands)) stdout = stdout and bytes.decode(stdout) @@ -1226,9 +1228,7 @@ class PdbTestCase(unittest.TestCase): return self._run_pdb(['-m', self.module_name], commands) def _assert_find_function(self, file_content, func_name, expected): - file_content = textwrap.dedent(file_content) - - with open(support.TESTFN, 'w') as f: + with open(support.TESTFN, 'wb') as f: f.write(file_content) expected = None if not expected else ( @@ -1237,22 +1237,49 @@ class PdbTestCase(unittest.TestCase): expected, pdb.find_function(func_name, support.TESTFN)) def test_find_function_empty_file(self): - self._assert_find_function('', 'foo', None) + self._assert_find_function(b'', 'foo', None) def test_find_function_found(self): self._assert_find_function( """\ - def foo(): - pass +def foo(): + pass - def bar(): - pass +def bÅ“r(): + pass - def quux(): - pass - """, - 'bar', - ('bar', 4), +def quux(): + pass +""".encode(), + 'bÅ“r', + ('bÅ“r', 4), + ) + + def test_find_function_found_with_encoding_cookie(self): + self._assert_find_function( + """\ +# coding: iso-8859-15 +def foo(): + pass + +def bÅ“r(): + pass + +def quux(): + pass +""".encode('iso-8859-15'), + 'bÅ“r', + ('bÅ“r', 5), + ) + + def test_find_function_found_with_bom(self): + self._assert_find_function( + codecs.BOM_UTF8 + """\ +def bÅ“r(): + pass +""".encode(), + 'bÅ“r', + ('bÅ“r', 1), ) def test_issue7964(self): @@ -1327,10 +1354,11 @@ class PdbTestCase(unittest.TestCase): stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, + env={**os.environ, 'PYTHONIOENCODING': 'utf-8'} ) self.addCleanup(proc.stdout.close) stdout, stderr = proc.communicate(b'cont\n') - self.assertNotIn('Error', stdout.decode(), + self.assertNotIn(b'Error', stdout, "Got an error running test script under PDB") def test_issue36250(self): @@ -1356,10 +1384,11 @@ class PdbTestCase(unittest.TestCase): stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, + env = {**os.environ, 'PYTHONIOENCODING': 'utf-8'} ) self.addCleanup(proc.stdout.close) stdout, stderr = proc.communicate(b'cont\ncont\n') - self.assertNotIn('Error', stdout.decode(), + self.assertNotIn(b'Error', stdout, "Got an error running test script under PDB") def test_issue16180(self): @@ -1399,8 +1428,8 @@ class PdbTestCase(unittest.TestCase): ) with proc: stdout, stderr = proc.communicate(b'q\n') - self.assertNotIn("NameError: name 'invalid' is not defined", - stdout.decode()) + self.assertNotIn(b"NameError: name 'invalid' is not defined", + stdout) finally: if save_home is not None: diff --git a/Lib/test/test_peg_generator/test_c_parser.py b/Lib/test/test_peg_generator/test_c_parser.py index 72383d5b5a6..f9935258c86 100644 --- a/Lib/test/test_peg_generator/test_c_parser.py +++ b/Lib/test/test_peg_generator/test_c_parser.py @@ -365,8 +365,8 @@ class TestCParser(TempdirManager, unittest.TestCase): start: expr+ NEWLINE? ENDMARKER expr: NAME """ - test_source = """ - for text in ("a b 42 b a", "å å 42 å å"): + test_source = r""" + for text in ("a b 42 b a", "\u540d \u540d 42 \u540d \u540d"): try: parse.parse_string(text, mode=0) except SyntaxError as e: @@ -432,3 +432,15 @@ class TestCParser(TempdirManager, unittest.TestCase): self.check_input_strings_for_grammar(valid_cases, invalid_cases) """ self.run_test(grammar_source, test_source) + + def test_soft_keywords_lookahead(self) -> None: + grammar_source = """ + start: &"if" "if" expr '+' expr NEWLINE + expr: NAME + """ + test_source = """ + valid_cases = ["if if + if"] + invalid_cases = ["if if"] + self.check_input_strings_for_grammar(valid_cases, invalid_cases) + """ + self.run_test(grammar_source, test_source) diff --git a/Lib/test/test_peg_generator/test_pegen.py b/Lib/test/test_peg_generator/test_pegen.py index 30e1b675643..5b4e964d698 100644 --- a/Lib/test/test_peg_generator/test_pegen.py +++ b/Lib/test/test_peg_generator/test_pegen.py @@ -493,6 +493,14 @@ class TestPegen(unittest.TestCase): # Would assert False without a special case in compute_left_recursives(). make_parser(grammar) + def test_opt_sequence(self) -> None: + grammar = """ + start: [NAME*] + """ + # This case was failing because of a double trailing comma at the end + # of a line in the generated source. See bpo-41044 + make_parser(grammar) + def test_left_recursion_too_complex(self) -> None: grammar = """ start: foo diff --git a/Lib/test/test_peg_parser.py b/Lib/test/test_peg_parser.py deleted file mode 100644 index 6ccb2573176..00000000000 --- a/Lib/test/test_peg_parser.py +++ /dev/null @@ -1,796 +0,0 @@ -import ast -import _peg_parser as peg_parser -import unittest -from typing import Any, Union, Iterable, Tuple -from textwrap import dedent -from test import support - - -TEST_CASES = [ - ('annotated_assignment', 'x: int = 42'), - ('annotated_assignment_with_tuple', 'x: tuple = 1, 2'), - ('annotated_assignment_with_parens', '(paren): int = 3+2'), - ('annotated_assignment_with_yield', 'x: int = yield 42'), - ('annotated_no_assignment', 'x: int'), - ('annotation_with_multiple_parens', '((parens)): int'), - ('annotation_with_parens', '(parens): int'), - ('annotated_assignment_with_attr', 'a.b: int'), - ('annotated_assignment_with_subscript', 'a[b]: int'), - ('annotated_assignment_with_attr_and_parens', '(a.b): int'), - ('annotated_assignment_with_subscript_and_parens', '(a[b]): int'), - ('assert', 'assert a'), - ('assert_message', 'assert a, b'), - ('assignment_false', 'a = False'), - ('assignment_none', 'a = None'), - ('assignment_true', 'a = True'), - ('assignment_paren', '(a) = 42'), - ('assignment_paren_multiple', '(a, b) = (0, 1)'), - ('asyncfor', - ''' - async for i in a: - pass - '''), - ('attribute_call', 'a.b()'), - ('attribute_multiple_names', 'abcd.efg.hij'), - ('attribute_simple', 'a.b'), - ('attributes_subscript', 'a.b[0]'), - ('augmented_assignment', 'x += 42'), - ('augmented_assignment_attribute', 'a.b.c += 42'), - ('augmented_assignment_paren', '(x) += 42'), - ('augmented_assignment_paren_subscript', '(x[0]) -= 42'), - ('binop_add', '1 + 1'), - ('binop_add_multiple', '1 + 1 + 1 + 1'), - ('binop_all', '1 + 2 * 5 + 3 ** 2 - -3'), - ('binop_boolop_comp', '1 + 1 == 2 or 1 + 1 == 3 and not b'), - ('boolop_or', 'a or b'), - ('boolop_or_multiple', 'a or b or c'), - ('class_def_bases', - ''' - class C(A, B): - pass - '''), - ('class_def_decorators', - ''' - @a - class C: - pass - '''), - ('class_def_decorator_with_expression', - ''' - @lambda x: 42 - class C: - pass - '''), - ('class_def_decorator_with_expression_and_walrus', - ''' - @x:=lambda x: 42 - class C: - pass - '''), - - ('class_def_keywords', - ''' - class C(keyword=a+b, **c): - pass - '''), - ('class_def_mixed', - ''' - class C(A, B, keyword=0, **a): - pass - '''), - ('class_def_simple', - ''' - class C: - pass - '''), - ('class_def_starred_and_kwarg', - ''' - class C(A, B, *x, **y): - pass - '''), - ('class_def_starred_in_kwargs', - ''' - class C(A, x=2, *[B, C], y=3): - pass - '''), - ('call_attribute', 'f().b'), - ('call_genexp', 'f(i for i in a)'), - ('call_mixed_args', 'f(a, b, *c, **d)'), - ('call_mixed_args_named', 'f(a, b, *c, d=4, **v)'), - ('call_one_arg', 'f(a)'), - ('call_posarg_genexp', 'f(a, (i for i in a))'), - ('call_simple', 'f()'), - ('call_subscript', 'f()[0]'), - ('comp', 'a == b'), - ('comp_multiple', 'a == b == c'), - ('comp_paren_end', 'a == (b-1)'), - ('comp_paren_start', '(a-1) == b'), - ('decorator', - ''' - @a - def f(): - pass - '''), - ('decorator_async', - ''' - @a - async def d(): - pass - '''), - ('decorator_with_expression', - ''' - @lambda x: 42 - def f(): - pass - '''), - ('decorator_with_expression_and_walrus', - ''' - @x:=lambda x: 42 - def f(): - pass - '''), - ('del_attribute', 'del a.b'), - ('del_call_attribute', 'del a().c'), - ('del_call_genexp_attribute', 'del a(i for i in b).c'), - ('del_empty', 'del()'), - ('del_list', 'del a, [b, c]'), - ('del_mixed', 'del a[0].b().c'), - ('del_multiple', 'del a, b'), - ('del_multiple_calls_attribute', 'del a()().b'), - ('del_paren', 'del(a,b)'), - ('del_paren_single_target', 'del(a)'), - ('del_subscript_attribute', 'del a[0].b'), - ('del_tuple', 'del a, (b, c)'), - ('delete', 'del a'), - ('dict', - ''' - { - a: 1, - b: 2, - c: 3 - } - '''), - ('dict_comp', '{x:1 for x in a}'), - ('dict_comp_if', '{x:1+2 for x in a if b}'), - ('dict_empty', '{}'), - ('for', - ''' - for i in a: - pass - '''), - ('for_else', - ''' - for i in a: - pass - else: - pass - '''), - ('for_star_target_in_paren', 'for (a) in b: pass'), - ('for_star_targets_attribute', 'for a.b in c: pass'), - ('for_star_targets_call_attribute', 'for a().c in b: pass'), - ('for_star_targets_empty', 'for () in a: pass'), - ('for_star_targets_mixed', 'for a[0].b().c in d: pass'), - ('for_star_targets_mixed_starred', - ''' - for a, *b, (c, d) in e: - pass - '''), - ('for_star_targets_multiple', 'for a, b in c: pass'), - ('for_star_targets_nested_starred', 'for *[*a] in b: pass'), - ('for_star_targets_starred', 'for *a in b: pass'), - ('for_star_targets_subscript_attribute', 'for a[0].b in c: pass'), - ('for_star_targets_trailing_comma', - ''' - for a, (b, c), in d: - pass - '''), - ('for_star_targets_tuple', 'for a, (b, c) in d: pass'), - ('for_underscore', - ''' - for _ in a: - pass - '''), - ('function_return_type', - ''' - def f() -> Any: - pass - '''), - ('f-string_slice', "f'{x[2]}'"), - ('f-string_slice_upper', "f'{x[2:3]}'"), - ('f-string_slice_step', "f'{x[2:3:-2]}'"), - ('f-string_constant', "f'{42}'"), - ('f-string_boolop', "f'{x and y}'"), - ('f-string_named_expr', "f'{(x:=42)}'"), - ('f-string_binop', "f'{x+y}'"), - ('f-string_unaryop', "f'{not x}'"), - ('f-string_lambda', "f'{(lambda x, /, y, y2=42 , *z, k1, k2=34, **k3: 42)}'"), - ('f-string_lambda_call', "f'{(lambda: 2)(2)}'"), - ('f-string_ifexpr', "f'{x if y else z}'"), - ('f-string_dict', "f'{ {2:34, 3:34} }'"), - ('f-string_set', "f'{ {2,-45} }'"), - ('f-string_list', "f'{ [2,-45] }'"), - ('f-string_tuple', "f'{ (2,-45) }'"), - ('f-string_listcomp', "f'{[x for x in y if z]}'"), - ('f-string_setcomp', "f'{ {x for x in y if z} }'"), - ('f-string_dictcomp', "f'{ {x:x for x in y if z} }'"), - ('f-string_genexpr', "f'{ (x for x in y if z) }'"), - ('f-string_yield', "f'{ (yield x) }'"), - ('f-string_yieldfrom', "f'{ (yield from x) }'"), - ('f-string_await', "f'{ await x }'"), - ('f-string_compare', "f'{ x == y }'"), - ('f-string_call', "f'{ f(x,y,z) }'"), - ('f-string_attribute', "f'{ f.x.y.z }'"), - ('f-string_starred', "f'{ *x, }'"), - ('f-string_doublestarred', "f'{ {**x} }'"), - ('f-string_escape_brace', "f'{{Escape'"), - ('f-string_escape_closing_brace', "f'Escape}}'"), - ('f-string_repr', "f'{a!r}'"), - ('f-string_str', "f'{a!s}'"), - ('f-string_ascii', "f'{a!a}'"), - ('f-string_debug', "f'{a=}'"), - ('f-string_padding', "f'{a:03d}'"), - ('f-string_multiline', - """ - f''' - {hello} - ''' - """), - ('f-string_multiline_in_expr', - """ - f''' - { - hello - } - ''' - """), - ('f-string_multiline_in_call', - """ - f''' - {f( - a, b, c - )} - ''' - """), - ('global', 'global a, b'), - ('group', '(yield a)'), - ('if_elif', - ''' - if a: - pass - elif b: - pass - '''), - ('if_elif_elif', - ''' - if a: - pass - elif b: - pass - elif c: - pass - '''), - ('if_elif_else', - ''' - if a: - pass - elif b: - pass - else: - pass - '''), - ('if_else', - ''' - if a: - pass - else: - pass - '''), - ('if_simple', 'if a: pass'), - ('import', 'import a'), - ('import_alias', 'import a as b'), - ('import_dotted', 'import a.b'), - ('import_dotted_alias', 'import a.b as c'), - ('import_dotted_multichar', 'import ab.cd'), - ('import_from', 'from a import b'), - ('import_from_alias', 'from a import b as c'), - ('import_from_dotted', 'from a.b import c'), - ('import_from_dotted_alias', 'from a.b import c as d'), - ('import_from_multiple_aliases', 'from a import b as c, d as e'), - ('import_from_one_dot', 'from .a import b'), - ('import_from_one_dot_alias', 'from .a import b as c'), - ('import_from_star', 'from a import *'), - ('import_from_three_dots', 'from ...a import b'), - ('import_from_trailing_comma', 'from a import (b,)'), - ('kwarg', - ''' - def f(**a): - pass - '''), - ('kwonly_args', - ''' - def f(*, a, b): - pass - '''), - ('kwonly_args_with_default', - ''' - def f(*, a=2, b): - pass - '''), - ('lambda_kwarg', 'lambda **a: 42'), - ('lambda_kwonly_args', 'lambda *, a, b: 42'), - ('lambda_kwonly_args_with_default', 'lambda *, a=2, b: 42'), - ('lambda_mixed_args', 'lambda a, /, b, *, c: 42'), - ('lambda_mixed_args_with_default', 'lambda a, b=2, /, c=3, *e, f, **g: 42'), - ('lambda_no_args', 'lambda: 42'), - ('lambda_pos_args', 'lambda a,b: 42'), - ('lambda_pos_args_with_default', 'lambda a, b=2: 42'), - ('lambda_pos_only_args', 'lambda a, /: 42'), - ('lambda_pos_only_args_with_default', 'lambda a=0, /: 42'), - ('lambda_pos_posonly_args', 'lambda a, b, /, c, d: 42'), - ('lambda_pos_posonly_args_with_default', 'lambda a, b=0, /, c=2: 42'), - ('lambda_vararg', 'lambda *a: 42'), - ('lambda_vararg_kwonly_args', 'lambda *a, b: 42'), - ('list', '[1, 2, a]'), - ('list_comp', '[i for i in a]'), - ('list_comp_if', '[i for i in a if b]'), - ('list_trailing_comma', '[1+2, a, 3+4,]'), - ('mixed_args', - ''' - def f(a, /, b, *, c): - pass - '''), - ('mixed_args_with_default', - ''' - def f(a, b=2, /, c=3, *e, f, **g): - pass - '''), - ('multipart_string_bytes', 'b"Hola" b"Hello" b"Bye"'), - ('multipart_string_triple', '"""Something here""" "and now"'), - ('multipart_string_different_prefixes', 'u"Something" "Other thing" r"last thing"'), - ('multiple_assignments', 'x = y = z = 42'), - ('multiple_assignments_with_yield', 'x = y = z = yield 42'), - ('multiple_pass', - ''' - pass; pass - pass - '''), - ('namedexpr', '(x := [1, 2, 3])'), - ('namedexpr_false', '(x := False)'), - ('namedexpr_none', '(x := None)'), - ('namedexpr_true', '(x := True)'), - ('nonlocal', 'nonlocal a, b'), - ('number_complex', '-2.234+1j'), - ('number_float', '-34.2333'), - ('number_imaginary_literal', '1.1234j'), - ('number_integer', '-234'), - ('number_underscores', '1_234_567'), - ('pass', 'pass'), - ('pos_args', - ''' - def f(a, b): - pass - '''), - ('pos_args_with_default', - ''' - def f(a, b=2): - pass - '''), - ('pos_only_args', - ''' - def f(a, /): - pass - '''), - ('pos_only_args_with_default', - ''' - def f(a=0, /): - pass - '''), - ('pos_posonly_args', - ''' - def f(a, b, /, c, d): - pass - '''), - ('pos_posonly_args_with_default', - ''' - def f(a, b=0, /, c=2): - pass - '''), - ('primary_mixed', 'a.b.c().d[0]'), - ('raise', 'raise'), - ('raise_ellipsis', 'raise ...'), - ('raise_expr', 'raise a'), - ('raise_from', 'raise a from b'), - ('return', 'return'), - ('return_expr', 'return a'), - ('set', '{1, 2+4, 3+5}'), - ('set_comp', '{i for i in a}'), - ('set_trailing_comma', '{1, 2, 3,}'), - ('simple_assignment', 'x = 42'), - ('simple_assignment_with_yield', 'x = yield 42'), - ('string_bytes', 'b"hello"'), - ('string_concatenation_bytes', 'b"hello" b"world"'), - ('string_concatenation_simple', '"abcd" "efgh"'), - ('string_format_simple', 'f"hello"'), - ('string_format_with_formatted_value', 'f"hello {world}"'), - ('string_simple', '"hello"'), - ('string_unicode', 'u"hello"'), - ('subscript_attribute', 'a[0].b'), - ('subscript_call', 'a[b]()'), - ('subscript_multiple_slices', 'a[0:a:2, 1]'), - ('subscript_simple', 'a[0]'), - ('subscript_single_element_tuple', 'a[0,]'), - ('subscript_trailing_comma', 'a[0, 1, 2,]'), - ('subscript_tuple', 'a[0, 1, 2]'), - ('subscript_whole_slice', 'a[0+1:b:c]'), - ('try_except', - ''' - try: - pass - except: - pass - '''), - ('try_except_else', - ''' - try: - pass - except: - pass - else: - pass - '''), - ('try_except_else_finally', - ''' - try: - pass - except: - pass - else: - pass - finally: - pass - '''), - ('try_except_expr', - ''' - try: - pass - except a: - pass - '''), - ('try_except_expr_target', - ''' - try: - pass - except a as b: - pass - '''), - ('try_except_finally', - ''' - try: - pass - except: - pass - finally: - pass - '''), - ('try_finally', - ''' - try: - pass - finally: - pass - '''), - ('unpacking_binop', '[*([1, 2, 3] + [3, 4, 5])]'), - ('unpacking_call', '[*b()]'), - ('unpacking_compare', '[*(x < y)]'), - ('unpacking_constant', '[*3]'), - ('unpacking_dict', '[*{1: 2, 3: 4}]'), - ('unpacking_dict_comprehension', '[*{x:y for x,y in z}]'), - ('unpacking_ifexpr', '[*([1, 2, 3] if x else y)]'), - ('unpacking_list', '[*[1,2,3]]'), - ('unpacking_list_comprehension', '[*[x for x in y]]'), - ('unpacking_namedexpr', '[*(x:=[1, 2, 3])]'), - ('unpacking_set', '[*{1,2,3}]'), - ('unpacking_set_comprehension', '[*{x for x in y}]'), - ('unpacking_string', '[*"myvalue"]'), - ('unpacking_tuple', '[*(1,2,3)]'), - ('unpacking_unaryop', '[*(not [1, 2, 3])]'), - ('unpacking_yield', '[*(yield 42)]'), - ('unpacking_yieldfrom', '[*(yield from x)]'), - ('tuple', '(1, 2, 3)'), - ('vararg', - ''' - def f(*a): - pass - '''), - ('vararg_kwonly_args', - ''' - def f(*a, b): - pass - '''), - ('while', - ''' - while a: - pass - '''), - ('while_else', - ''' - while a: - pass - else: - pass - '''), - ('with', - ''' - with a: - pass - '''), - ('with_as', - ''' - with a as b: - pass - '''), - ('with_as_paren', - ''' - with a as (b): - pass - '''), - ('with_as_empty', 'with a as (): pass'), - ('with_list_recursive', - ''' - with a as [x, [y, z]]: - pass - '''), - ('with_tuple_recursive', - ''' - with a as ((x, y), z): - pass - '''), - ('with_tuple_target', - ''' - with a as (x, y): - pass - '''), - ('with_list_target', - ''' - with a as [x, y]: - pass - '''), - ('yield', 'yield'), - ('yield_expr', 'yield a'), - ('yield_from', 'yield from a'), -] - -FAIL_TEST_CASES = [ - ("annotation_multiple_targets", "(a, b): int = 42"), - ("annotation_nested_tuple", "((a, b)): int"), - ("annotation_list", "[a]: int"), - ("annotation_lambda", "lambda: int = 42"), - ("annotation_tuple", "(a,): int"), - ("annotation_tuple_without_paren", "a,: int"), - ("assignment_keyword", "a = if"), - ("augmented_assignment_list", "[a, b] += 1"), - ("augmented_assignment_tuple", "a, b += 1"), - ("augmented_assignment_tuple_paren", "(a, b) += (1, 2)"), - ("comprehension_lambda", "(a for a in lambda: b)"), - ("comprehension_else", "(a for a in b if c else d"), - ("del_call", "del a()"), - ("del_call_genexp", "del a(i for i in b)"), - ("del_subscript_call", "del a[b]()"), - ("del_attribute_call", "del a.b()"), - ("del_mixed_call", "del a[0].b().c.d()"), - ("for_star_targets_call", "for a() in b: pass"), - ("for_star_targets_subscript_call", "for a[b]() in c: pass"), - ("for_star_targets_attribute_call", "for a.b() in c: pass"), - ("for_star_targets_mixed_call", "for a[0].b().c.d() in e: pass"), - ("for_star_targets_in", "for a, in in b: pass"), - ("f-string_assignment", "f'{x = 42}'"), - ("f-string_empty", "f'{}'"), - ("f-string_function_def", "f'{def f(): pass}'"), - ("f-string_lambda", "f'{lambda x: 42}'"), - ("f-string_singe_brace", "f'{'"), - ("f-string_single_closing_brace", "f'}'"), - ("from_import_invalid", "from import import a"), - ("from_import_trailing_comma", "from a import b,"), - ("import_non_ascii_syntax_error", "import ä £"), - # This test case checks error paths involving tokens with uninitialized - # values of col_offset and end_col_offset. - ("invalid indentation", - """ - def f(): - a - a - """), - ("not_terminated_string", "a = 'example"), - ("try_except_attribute_target", - """ - try: - pass - except Exception as a.b: - pass - """), - ("try_except_subscript_target", - """ - try: - pass - except Exception as a[0]: - pass - """), -] - -FAIL_SPECIALIZED_MESSAGE_CASES = [ - ("f(x, y, z=1, **b, *a", "iterable argument unpacking follows keyword argument unpacking"), - ("f(x, y=1, *z, **a, b", "positional argument follows keyword argument unpacking"), - ("f(x, y, z=1, a=2, b", "positional argument follows keyword argument"), - ("True = 1", "cannot assign to True"), - ("a() = 1", "cannot assign to function call"), - ("(a, b): int", "only single target (not tuple) can be annotated"), - ("[a, b]: int", "only single target (not list) can be annotated"), - ("a(): int", "illegal target for annotation"), - ("1 += 1", "'literal' is an illegal expression for augmented assignment"), - ("pass\n pass", "unexpected indent"), - ("def f():\npass", "expected an indented block"), - ("def f(*): pass", "named arguments must follow bare *"), - ("def f(*,): pass", "named arguments must follow bare *"), - ("def f(*, **a): pass", "named arguments must follow bare *"), - ("lambda *: pass", "named arguments must follow bare *"), - ("lambda *,: pass", "named arguments must follow bare *"), - ("lambda *, **a: pass", "named arguments must follow bare *"), - ("f(g()=2", "expression cannot contain assignment, perhaps you meant \"==\"?"), - ("f(a, b, *c, d.e=2", "expression cannot contain assignment, perhaps you meant \"==\"?"), - ("f(*a, **b, c=0, d[1]=3)", "expression cannot contain assignment, perhaps you meant \"==\"?"), -] - -GOOD_BUT_FAIL_TEST_CASES = [ - ('string_concatenation_format', 'f"{hello} world" f"again {and_again}"'), - ('string_concatenation_multiple', - ''' - f"hello" f"{world} again" f"and_again" - '''), - ('f-string_multiline_comp', - """ - f''' - {(i for i in a - if b)} - ''' - """), -] - -FSTRINGS_TRACEBACKS = { - 'multiline_fstrings_same_line_with_brace': ( - """ - f''' - {a$b} - ''' - """, - '(a$b)', - ), - 'multiline_fstring_brace_on_next_line': ( - """ - f''' - {a$b - }''' - """, - '(a$b', - ), - 'multiline_fstring_brace_on_previous_line': ( - """ - f''' - { - a$b}''' - """, - 'a$b)', - ), -} - -EXPRESSIONS_TEST_CASES = [ - ("expression_add", "1+1"), - ("expression_add_2", "a+b"), - ("expression_call", "f(a, b=2, **kw)"), - ("expression_tuple", "1, 2, 3"), - ("expression_tuple_one_value", "1,") -] - - -def cleanup_source(source: Any) -> str: - if isinstance(source, str): - result = dedent(source) - elif not isinstance(source, (list, tuple)): - result = "\n".join(source) - else: - raise TypeError(f"Invalid type for test source: {source}") - return result - - -def prepare_test_cases( - test_cases: Iterable[Tuple[str, Union[str, Iterable[str]]]] -) -> Tuple[Iterable[str], Iterable[str]]: - - test_ids, _test_sources = zip(*test_cases) - test_sources = list(_test_sources) - for index, source in enumerate(test_sources): - result = cleanup_source(source) - test_sources[index] = result - return test_ids, test_sources - - -TEST_IDS, TEST_SOURCES = prepare_test_cases(TEST_CASES) - -GOOD_BUT_FAIL_TEST_IDS, GOOD_BUT_FAIL_SOURCES = prepare_test_cases( - GOOD_BUT_FAIL_TEST_CASES -) - -FAIL_TEST_IDS, FAIL_SOURCES = prepare_test_cases(FAIL_TEST_CASES) - -EXPRESSIONS_TEST_IDS, EXPRESSIONS_TEST_SOURCES = prepare_test_cases( - EXPRESSIONS_TEST_CASES -) - - -class ASTGenerationTest(unittest.TestCase): - def test_correct_ast_generation_on_source_files(self) -> None: - self.maxDiff = None - for source in TEST_SOURCES: - actual_ast = peg_parser.parse_string(source) - expected_ast = peg_parser.parse_string(source, oldparser=True) - self.assertEqual( - ast.dump(actual_ast, include_attributes=True), - ast.dump(expected_ast, include_attributes=True), - f"Wrong AST generation for source: {source}", - ) - - def test_incorrect_ast_generation_on_source_files(self) -> None: - for source in FAIL_SOURCES: - with self.assertRaises(SyntaxError, msg=f"Parsing {source} did not raise an exception"): - peg_parser.parse_string(source) - - def test_incorrect_ast_generation_with_specialized_errors(self) -> None: - for source, error_text in FAIL_SPECIALIZED_MESSAGE_CASES: - exc = IndentationError if "indent" in error_text else SyntaxError - with self.assertRaises(exc) as se: - peg_parser.parse_string(source) - self.assertTrue( - error_text in se.exception.msg, - f"Actual error message does not match expexted for {source}" - ) - - @unittest.expectedFailure - def test_correct_but_known_to_fail_ast_generation_on_source_files(self) -> None: - for source in GOOD_BUT_FAIL_SOURCES: - actual_ast = peg_parser.parse_string(source) - expected_ast = peg_parser.parse_string(source, oldparser=True) - self.assertEqual( - ast.dump(actual_ast, include_attributes=True), - ast.dump(expected_ast, include_attributes=True), - f"Wrong AST generation for source: {source}", - ) - - def test_correct_ast_generation_without_pos_info(self) -> None: - for source in GOOD_BUT_FAIL_SOURCES: - actual_ast = peg_parser.parse_string(source) - expected_ast = peg_parser.parse_string(source, oldparser=True) - self.assertEqual( - ast.dump(actual_ast), - ast.dump(expected_ast), - f"Wrong AST generation for source: {source}", - ) - - def test_fstring_parse_error_tracebacks(self) -> None: - for source, error_text in FSTRINGS_TRACEBACKS.values(): - with self.assertRaises(SyntaxError) as se: - peg_parser.parse_string(dedent(source)) - self.assertEqual(error_text, se.exception.text) - - def test_correct_ast_generatrion_eval(self) -> None: - for source in EXPRESSIONS_TEST_SOURCES: - actual_ast = peg_parser.parse_string(source, mode='eval') - expected_ast = peg_parser.parse_string(source, mode='eval', oldparser=True) - self.assertEqual( - ast.dump(actual_ast, include_attributes=True), - ast.dump(expected_ast, include_attributes=True), - f"Wrong AST generation for source: {source}", - ) - - def test_tokenizer_errors_are_propagated(self) -> None: - n=201 - with self.assertRaisesRegex(SyntaxError, "too many nested parentheses"): - peg_parser.parse_string(n*'(' + ')'*n) diff --git a/Lib/test/test_pickle.py b/Lib/test/test_pickle.py index 2307b133dbd..1f5cb103933 100644 --- a/Lib/test/test_pickle.py +++ b/Lib/test/test_pickle.py @@ -10,6 +10,7 @@ import weakref import unittest from test import support +from test.support import import_helper from test.pickletester import AbstractHookTests from test.pickletester import AbstractUnpickleTests @@ -499,7 +500,7 @@ class CompatPickleTests(unittest.TestCase): ('builtins', name)) def test_multiprocessing_exceptions(self): - module = support.import_module('multiprocessing.context') + module = import_helper.import_module('multiprocessing.context') for name, exc in get_exceptions(module): with self.subTest(name): self.assertEqual(reverse_mapping('multiprocessing.context', name), diff --git a/Lib/test/test_picklebuffer.py b/Lib/test/test_picklebuffer.py index 97981c882e8..435b3e038aa 100644 --- a/Lib/test/test_picklebuffer.py +++ b/Lib/test/test_picklebuffer.py @@ -8,7 +8,7 @@ from pickle import PickleBuffer import weakref import unittest -from test import support +from test.support import import_helper class B(bytes): @@ -75,7 +75,7 @@ class PickleBufferTest(unittest.TestCase): def test_ndarray_2d(self): # C-contiguous - ndarray = support.import_module("_testbuffer").ndarray + ndarray = import_helper.import_module("_testbuffer").ndarray arr = ndarray(list(range(12)), shape=(4, 3), format='", "single") def test_invalid_syntax_errors(self): - if use_old_parser(): - check_syntax_error(self, "def f(a, b = 5, /, c): pass", "non-default argument follows default argument") - check_syntax_error(self, "def f(a = 5, b, /, c): pass", "non-default argument follows default argument") - check_syntax_error(self, "def f(a = 5, b=1, /, c, *, d=2): pass", "non-default argument follows default argument") - check_syntax_error(self, "def f(a = 5, b, /): pass", "non-default argument follows default argument") - + check_syntax_error(self, "def f(a, b = 5, /, c): pass", "non-default argument follows default argument") + check_syntax_error(self, "def f(a = 5, b, /, c): pass", "non-default argument follows default argument") + check_syntax_error(self, "def f(a = 5, b=1, /, c, *, d=2): pass", "non-default argument follows default argument") + check_syntax_error(self, "def f(a = 5, b, /): pass", "non-default argument follows default argument") check_syntax_error(self, "def f(*args, /): pass") check_syntax_error(self, "def f(*args, a, /): pass") check_syntax_error(self, "def f(**kwargs, /): pass") @@ -46,12 +44,10 @@ class PositionalOnlyTestCase(unittest.TestCase): check_syntax_error(self, "def f(a, *, c, /, d, e): pass") def test_invalid_syntax_errors_async(self): - if use_old_parser(): - check_syntax_error(self, "async def f(a, b = 5, /, c): pass", "non-default argument follows default argument") - check_syntax_error(self, "async def f(a = 5, b, /, c): pass", "non-default argument follows default argument") - check_syntax_error(self, "async def f(a = 5, b=1, /, c, d=2): pass", "non-default argument follows default argument") - check_syntax_error(self, "async def f(a = 5, b, /): pass", "non-default argument follows default argument") - + check_syntax_error(self, "async def f(a, b = 5, /, c): pass", "non-default argument follows default argument") + check_syntax_error(self, "async def f(a = 5, b, /, c): pass", "non-default argument follows default argument") + check_syntax_error(self, "async def f(a = 5, b=1, /, c, d=2): pass", "non-default argument follows default argument") + check_syntax_error(self, "async def f(a = 5, b, /): pass", "non-default argument follows default argument") check_syntax_error(self, "async def f(*args, /): pass") check_syntax_error(self, "async def f(*args, a, /): pass") check_syntax_error(self, "async def f(**kwargs, /): pass") @@ -235,11 +231,9 @@ class PositionalOnlyTestCase(unittest.TestCase): self.assertEqual(x(1, 2), 3) def test_invalid_syntax_lambda(self): - if use_old_parser(): - check_syntax_error(self, "lambda a, b = 5, /, c: None", "non-default argument follows default argument") - check_syntax_error(self, "lambda a = 5, b, /, c: None", "non-default argument follows default argument") - check_syntax_error(self, "lambda a = 5, b, /: None", "non-default argument follows default argument") - + check_syntax_error(self, "lambda a, b = 5, /, c: None", "non-default argument follows default argument") + check_syntax_error(self, "lambda a = 5, b, /, c: None", "non-default argument follows default argument") + check_syntax_error(self, "lambda a = 5, b, /: None", "non-default argument follows default argument") check_syntax_error(self, "lambda *args, /: None") check_syntax_error(self, "lambda *args, a, /: None") check_syntax_error(self, "lambda **kwargs, /: None") diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 4d3d8976d60..18819a5dc1c 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -627,7 +627,7 @@ class PathLikeTests(unittest.TestCase): path = posixpath def setUp(self): - self.file_name = support.TESTFN.lower() + self.file_name = support.TESTFN self.file_path = FakePath(support.TESTFN) self.addCleanup(support.unlink, self.file_name) with open(self.file_name, 'xb', 0) as file: diff --git a/Lib/test/test_profile.py b/Lib/test/test_profile.py index 01a8a6eaf5a..738be85bedf 100644 --- a/Lib/test/test_profile.py +++ b/Lib/test/test_profile.py @@ -6,7 +6,8 @@ import unittest import os from difflib import unified_diff from io import StringIO -from test.support import TESTFN, run_unittest, unlink +from test.support import run_unittest +from test.support.os_helper import TESTFN, unlink from contextlib import contextmanager import profile diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py index 9c32467cbbd..7ca0557800b 100644 --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -1,4 +1,5 @@ -from test.support import verbose, import_module, reap_children +from test.support import verbose, reap_children +from test.support.import_helper import import_module # Skip these tests if termios is not available import_module('termios') diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py index 85740cecd82..f8f12571ca9 100644 --- a/Lib/test/test_pwd.py +++ b/Lib/test/test_pwd.py @@ -1,8 +1,8 @@ import sys import unittest -from test import support +from test.support import import_helper -pwd = support.import_module('pwd') +pwd = import_helper.import_module('pwd') @unittest.skipUnless(hasattr(pwd, 'getpwall'), 'Does not have getpwall()') class PwdTest(unittest.TestCase): diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py index d4a68c9320d..d8ba009ea84 100644 --- a/Lib/test/test_py_compile.py +++ b/Lib/test/test_py_compile.py @@ -9,13 +9,14 @@ import tempfile import unittest from test import support +from test.support import os_helper def without_source_date_epoch(fxn): """Runs function with SOURCE_DATE_EPOCH unset.""" @functools.wraps(fxn) def wrapper(*args, **kwargs): - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env.unset('SOURCE_DATE_EPOCH') return fxn(*args, **kwargs) return wrapper @@ -25,7 +26,7 @@ def with_source_date_epoch(fxn): """Runs function with SOURCE_DATE_EPOCH set.""" @functools.wraps(fxn) def wrapper(*args, **kwargs): - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['SOURCE_DATE_EPOCH'] = '123456789' return fxn(*args, **kwargs) return wrapper @@ -101,7 +102,7 @@ class PyCompileTestsBase: self.assertTrue(os.path.exists(self.cache_path)) def test_cwd(self): - with support.change_cwd(self.directory): + with os_helper.change_cwd(self.directory): py_compile.compile(os.path.basename(self.source_path), os.path.basename(self.pyc_path)) self.assertTrue(os.path.exists(self.pyc_path)) diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index ffabb7f1b94..f0d7ffd562c 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -24,9 +24,10 @@ import textwrap from io import StringIO from collections import namedtuple from test.support.script_helper import assert_python_ok +from test.support import threading_helper from test.support import ( TESTFN, rmtree, - reap_children, reap_threads, captured_output, captured_stdout, + reap_children, captured_output, captured_stdout, captured_stderr, unlink, requires_docstrings ) from test import pydoc_mod @@ -1575,7 +1576,7 @@ class TestInternalUtilities(unittest.TestCase): self.assertIsNone(self._get_revised_path(trailing_argv0dir)) -@reap_threads +@threading_helper.reap_threads def test_main(): try: test.support.run_unittest(PydocDocTest, diff --git a/Lib/test/test_queue.py b/Lib/test/test_queue.py index d88e28a9146..7b23699a00f 100644 --- a/Lib/test/test_queue.py +++ b/Lib/test/test_queue.py @@ -7,6 +7,7 @@ import time import unittest import weakref from test import support +from test.support import threading_helper py_queue = support.import_fresh_module('queue', blocked=['_queue']) c_queue = support.import_fresh_module('queue', fresh=['_queue']) @@ -63,7 +64,7 @@ class BlockingTestMixin: block_func) return self.result finally: - support.join_thread(thread) # make sure the thread terminates + threading_helper.join_thread(thread) # make sure the thread terminates # Call this instead if block_func is supposed to raise an exception. def do_exceptional_blocking_test(self,block_func, block_args, trigger_func, @@ -79,7 +80,7 @@ class BlockingTestMixin: self.fail("expected exception of kind %r" % expected_exception_class) finally: - support.join_thread(thread) # make sure the thread terminates + threading_helper.join_thread(thread) # make sure the thread terminates if not thread.startedEvent.is_set(): self.fail("trigger thread ended but event never set") @@ -484,7 +485,7 @@ class BaseSimpleQueueTest: args=(q, results, sentinel)) for i in range(n_consumers)] - with support.start_threads(feeders + consumers): + with threading_helper.start_threads(feeders + consumers): pass self.assertFalse(exceptions) diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index a3710f4aa48..a80e71e67e4 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -5,6 +5,8 @@ import os import time import pickle import warnings +import test.support + from functools import partial from math import log, exp, pi, fsum, sin, factorial from test import support @@ -372,6 +374,14 @@ class TestBasicOps: restoredseq = [newgen.random() for i in range(10)] self.assertEqual(origseq, restoredseq) + @test.support.cpython_only + def test_bug_41052(self): + # _random.Random should not be allowed to serialization + import _random + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + r = _random.Random() + self.assertRaises(TypeError, pickle.dumps, r, proto) + def test_bug_1727780(self): # verify that version-2-pickles can be loaded # fine, whether they are created on 32-bit or 64-bit diff --git a/Lib/test/test_range.py b/Lib/test/test_range.py index 30fa129b50e..107c0e2e11c 100644 --- a/Lib/test/test_range.py +++ b/Lib/test/test_range.py @@ -648,11 +648,17 @@ class RangeTest(unittest.TestCase): self.assert_attrs(range(0, 10, 3), 0, 10, 3) self.assert_attrs(range(10, 0, -1), 10, 0, -1) self.assert_attrs(range(10, 0, -3), 10, 0, -3) + self.assert_attrs(range(True), 0, 1, 1) + self.assert_attrs(range(False, True), 0, 1, 1) + self.assert_attrs(range(False, True, True), 0, 1, 1) def assert_attrs(self, rangeobj, start, stop, step): self.assertEqual(rangeobj.start, start) self.assertEqual(rangeobj.stop, stop) self.assertEqual(rangeobj.step, step) + self.assertIs(type(rangeobj.start), int) + self.assertIs(type(rangeobj.stop), int) + self.assertIs(type(rangeobj.step), int) with self.assertRaises(AttributeError): rangeobj.start = 0 diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py index 67ee9b7f7cf..de573bef9f9 100644 --- a/Lib/test/test_readline.py +++ b/Lib/test/test_readline.py @@ -10,7 +10,9 @@ import subprocess import sys import tempfile import unittest -from test.support import import_module, unlink, temp_dir, TESTFN, verbose +from test.support import verbose +from test.support.import_helper import import_module +from test.support.os_helper import unlink, temp_dir, TESTFN from test.support.script_helper import assert_python_ok # Skip tests if there is no readline module diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py index de209da41a3..39af0d96d1e 100644 --- a/Lib/test/test_regrtest.py +++ b/Lib/test/test_regrtest.py @@ -18,6 +18,7 @@ import textwrap import unittest from test import libregrtest from test import support +from test.support import os_helper from test.libregrtest import utils @@ -161,12 +162,12 @@ class ParseArgsTestCase(unittest.TestCase): self.assertEqual(ns.ignore_tests, ['pattern']) self.checkError([opt], 'expected one argument') - self.addCleanup(support.unlink, support.TESTFN) - with open(support.TESTFN, "w") as fp: + self.addCleanup(os_helper.unlink, os_helper.TESTFN) + with open(os_helper.TESTFN, "w") as fp: print('matchfile1', file=fp) print('matchfile2', file=fp) - filename = os.path.abspath(support.TESTFN) + filename = os.path.abspath(os_helper.TESTFN) ns = libregrtest._parse_args(['-m', 'match', '--ignorefile', filename]) self.assertEqual(ns.ignore_tests, @@ -183,12 +184,12 @@ class ParseArgsTestCase(unittest.TestCase): '-m', 'pattern2']) self.assertEqual(ns.match_tests, ['pattern1', 'pattern2']) - self.addCleanup(support.unlink, support.TESTFN) - with open(support.TESTFN, "w") as fp: + self.addCleanup(os_helper.unlink, os_helper.TESTFN) + with open(os_helper.TESTFN, "w") as fp: print('matchfile1', file=fp) print('matchfile2', file=fp) - filename = os.path.abspath(support.TESTFN) + filename = os.path.abspath(os_helper.TESTFN) ns = libregrtest._parse_args(['-m', 'match', '--matchfile', filename]) self.assertEqual(ns.match_tests, @@ -237,7 +238,7 @@ class ParseArgsTestCase(unittest.TestCase): def test_testdir(self): ns = libregrtest._parse_args(['--testdir', 'foo']) - self.assertEqual(ns.testdir, os.path.join(support.SAVEDCWD, 'foo')) + self.assertEqual(ns.testdir, os.path.join(os_helper.SAVEDCWD, 'foo')) self.checkError(['--testdir'], 'expected one argument') def test_runleaks(self): @@ -284,7 +285,7 @@ class ParseArgsTestCase(unittest.TestCase): with self.subTest(opt=opt): ns = libregrtest._parse_args([opt, 'foo']) self.assertEqual(ns.coverdir, - os.path.join(support.SAVEDCWD, 'foo')) + os.path.join(os_helper.SAVEDCWD, 'foo')) self.checkError([opt], 'expected one argument') def test_nocoverdir(self): @@ -363,7 +364,7 @@ class BaseTestCase(unittest.TestCase): self.testdir = os.path.realpath(os.path.dirname(__file__)) self.tmptestdir = tempfile.mkdtemp() - self.addCleanup(support.rmtree, self.tmptestdir) + self.addCleanup(os_helper.rmtree, self.tmptestdir) def create_test(self, name=None, code=None): if not name: @@ -384,7 +385,7 @@ class BaseTestCase(unittest.TestCase): name = self.TESTNAME_PREFIX + name path = os.path.join(self.tmptestdir, name + '.py') - self.addCleanup(support.unlink, path) + self.addCleanup(os_helper.unlink, path) # Use 'x' mode to ensure that we do not override existing tests try: with open(path, 'x', encoding='utf-8') as fp: @@ -556,7 +557,7 @@ class CheckActualTests(BaseTestCase): args = ['-Wd', '-E', '-bb', '-m', 'test.regrtest', '--list-tests'] output = self.run_python(args) rough_number_of_tests_found = len(output.splitlines()) - actual_testsuite_glob = os.path.join(os.path.dirname(__file__), + actual_testsuite_glob = os.path.join(glob.escape(os.path.dirname(__file__)), 'test*.py') rough_counted_test_py_files = len(glob.glob(actual_testsuite_glob)) # We're not trying to duplicate test finding logic in here, @@ -770,8 +771,8 @@ class ArgsTestCase(BaseTestCase): # Write the list of files using a format similar to regrtest output: # [1/2] test_1 # [2/2] test_2 - filename = support.TESTFN - self.addCleanup(support.unlink, filename) + filename = os_helper.TESTFN + self.addCleanup(os_helper.unlink, filename) # test format '0:00:00 [2/7] test_opcodes -- test_grammar took 0 sec' with open(filename, "w") as fp: @@ -886,7 +887,7 @@ class ArgsTestCase(BaseTestCase): test = self.create_test('huntrleaks', code=code) filename = 'reflog.txt' - self.addCleanup(support.unlink, filename) + self.addCleanup(os_helper.unlink, filename) output = self.run_tests('--huntrleaks', '3:3:', test, exitcode=2, stderr=subprocess.STDOUT) @@ -997,8 +998,8 @@ class ArgsTestCase(BaseTestCase): testname = self.create_test(code=code) # only run a subset - filename = support.TESTFN - self.addCleanup(support.unlink, filename) + filename = os_helper.TESTFN + self.addCleanup(os_helper.unlink, filename) subset = [ # only ignore the method name @@ -1038,8 +1039,8 @@ class ArgsTestCase(BaseTestCase): self.assertEqual(methods, all_methods) # only run a subset - filename = support.TESTFN - self.addCleanup(support.unlink, filename) + filename = os_helper.TESTFN + self.addCleanup(os_helper.unlink, filename) subset = [ # only match the method name diff --git a/Lib/test/test_repl.py b/Lib/test/test_repl.py index 71f192f90d9..03bf8d8b548 100644 --- a/Lib/test/test_repl.py +++ b/Lib/test/test_repl.py @@ -29,7 +29,9 @@ def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw): # test.support.script_helper. env = kw.setdefault('env', dict(os.environ)) env['TERM'] = 'vt100' - return subprocess.Popen(cmd_line, executable=sys.executable, + return subprocess.Popen(cmd_line, + executable=sys.executable, + text=True, stdin=subprocess.PIPE, stdout=stdout, stderr=stderr, **kw) @@ -49,12 +51,11 @@ class TestInteractiveInterpreter(unittest.TestCase): sys.exit(0) """ user_input = dedent(user_input) - user_input = user_input.encode() p = spawn_repl() with SuppressCrashReport(): p.stdin.write(user_input) output = kill_python(p) - self.assertIn(b'After the exception.', output) + self.assertIn('After the exception.', output) # Exit code 120: Py_FinalizeEx() failed to flush stdout and stderr. self.assertIn(p.returncode, (1, 120)) @@ -86,13 +87,26 @@ class TestInteractiveInterpreter(unittest.TestCase): """ ''' user_input = dedent(user_input) - user_input = user_input.encode() p = spawn_repl() - with SuppressCrashReport(): - p.stdin.write(user_input) + p.stdin.write(user_input) output = kill_python(p) self.assertEqual(p.returncode, 0) + def test_close_stdin(self): + user_input = dedent(''' + import os + print("before close") + os.close(0) + ''') + prepare_repl = dedent(''' + from test.support import suppress_msvcrt_asserts + suppress_msvcrt_asserts() + ''') + process = spawn_repl('-c', prepare_repl) + output = process.communicate(user_input)[0] + self.assertEqual(process.returncode, 0) + self.assertIn('before close', output) + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_reprlib.py b/Lib/test/test_reprlib.py index 4bf91945ea4..a328810c21e 100644 --- a/Lib/test/test_reprlib.py +++ b/Lib/test/test_reprlib.py @@ -10,7 +10,8 @@ import importlib import importlib.util import unittest -from test.support import create_empty_file, verbose +from test.support import verbose +from test.support.os_helper import create_empty_file from reprlib import repr as r # Don't shadow builtin repr from reprlib import Repr from reprlib import recursive_repr diff --git a/Lib/test/test_rlcompleter.py b/Lib/test/test_rlcompleter.py index 0dc1080ca32..ee3019d8782 100644 --- a/Lib/test/test_rlcompleter.py +++ b/Lib/test/test_rlcompleter.py @@ -40,12 +40,12 @@ class TestRlcompleter(unittest.TestCase): # test with a customized namespace self.assertEqual(self.completer.global_matches('CompleteM'), - ['CompleteMe(']) + ['CompleteMe()']) self.assertEqual(self.completer.global_matches('eg'), ['egg(']) # XXX: see issue5256 self.assertEqual(self.completer.global_matches('CompleteM'), - ['CompleteMe(']) + ['CompleteMe()']) def test_attr_matches(self): # test with builtins namespace @@ -64,7 +64,7 @@ class TestRlcompleter(unittest.TestCase): ['CompleteMe.spam']) self.assertEqual(self.completer.attr_matches('Completeme.egg'), []) self.assertEqual(self.completer.attr_matches('CompleteMe.'), - ['CompleteMe.mro(', 'CompleteMe.spam']) + ['CompleteMe.mro()', 'CompleteMe.spam']) self.assertEqual(self.completer.attr_matches('CompleteMe._'), ['CompleteMe._ham']) matches = self.completer.attr_matches('CompleteMe.__') @@ -134,7 +134,7 @@ class TestRlcompleter(unittest.TestCase): # No opening bracket "(" because we overrode the built-in class self.assertEqual(completer.complete('memoryview', 0), 'memoryview') self.assertIsNone(completer.complete('memoryview', 1)) - self.assertEqual(completer.complete('Ellipsis', 0), 'Ellipsis(') + self.assertEqual(completer.complete('Ellipsis', 0), 'Ellipsis()') self.assertIsNone(completer.complete('Ellipsis', 1)) if __name__ == '__main__': diff --git a/Lib/test/test_robotparser.py b/Lib/test/test_robotparser.py index a3112b8fdf4..b0bed431d4b 100644 --- a/Lib/test/test_robotparser.py +++ b/Lib/test/test_robotparser.py @@ -5,6 +5,7 @@ import unittest import urllib.robotparser from test import support from test.support import socket_helper +from test.support import threading_helper from http.server import BaseHTTPRequestHandler, HTTPServer @@ -330,7 +331,7 @@ class PasswordProtectedSiteTestCase(unittest.TestCase): self.t.join() self.server.server_close() - @support.reap_threads + @threading_helper.reap_threads def testPasswordProtectedSite(self): addr = self.server.server_address url = 'http://' + socket_helper.HOST + ':' + str(addr[1]) diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index ce3a422b502..bc77103641b 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -19,6 +19,7 @@ from io import BytesIO, StringIO import codecs import os.path import shutil +import sys from urllib.error import URLError import urllib.request from test import support @@ -35,7 +36,7 @@ except UnicodeEncodeError: supports_nonascii_filenames = True if not os.path.supports_unicode_filenames: try: - support.TESTFN_UNICODE.encode(support.TESTFN_ENCODING) + support.TESTFN_UNICODE.encode(sys.getfilesystemencoding()) except (UnicodeError, TypeError): # Either the file system encoding is None, or the file name # cannot be encoded in the file system encoding. diff --git a/Lib/test/test_sched.py b/Lib/test/test_sched.py index 26cb4be81e5..491d7b3a745 100644 --- a/Lib/test/test_sched.py +++ b/Lib/test/test_sched.py @@ -4,6 +4,7 @@ import threading import time import unittest from test import support +from test.support import threading_helper TIMEOUT = support.SHORT_TIMEOUT @@ -82,7 +83,7 @@ class TestCase(unittest.TestCase): self.assertEqual(q.get(timeout=TIMEOUT), 5) self.assertTrue(q.empty()) timer.advance(1000) - support.join_thread(t) + threading_helper.join_thread(t) self.assertTrue(q.empty()) self.assertEqual(timer.time(), 5) @@ -137,7 +138,7 @@ class TestCase(unittest.TestCase): self.assertEqual(q.get(timeout=TIMEOUT), 4) self.assertTrue(q.empty()) timer.advance(1000) - support.join_thread(t) + threading_helper.join_thread(t) self.assertTrue(q.empty()) self.assertEqual(timer.time(), 4) diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index e4766ab190b..e45f018d2da 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -1,5 +1,6 @@ import unittest from test import support +from test.support import warnings_helper import gc import weakref import operator @@ -317,20 +318,6 @@ class TestJointOps: name = repr(s).partition('(')[0] # strip class name self.assertEqual(repr(s), '%s({%s(...)})' % (name, name)) - def test_cyclical_print(self): - w = ReprWrapper() - s = self.thetype([w]) - w.value = s - fo = open(support.TESTFN, "w") - try: - fo.write(str(s)) - fo.close() - fo = open(support.TESTFN, "r") - self.assertEqual(fo.read(), repr(s)) - finally: - fo.close() - support.unlink(support.TESTFN) - def test_do_not_rehash_dict_keys(self): n = 10 d = dict.fromkeys(map(HashCountingInt, range(n))) @@ -675,15 +662,6 @@ class TestFrozenSet(TestJointOps, unittest.TestCase): s.__init__(self.otherword) self.assertEqual(s, set(self.word)) - def test_singleton_empty_frozenset(self): - f = frozenset() - efs = [frozenset(), frozenset([]), frozenset(()), frozenset(''), - frozenset(), frozenset([]), frozenset(()), frozenset(''), - frozenset(range(0)), frozenset(frozenset()), - frozenset(f), f] - # All of the empty frozensets should have just one id() - self.assertEqual(len(set(map(id, efs))), 1) - def test_constructor_identity(self): s = self.thetype(range(3)) t = self.thetype(s) @@ -803,17 +781,6 @@ class TestBasicOps: sorted_repr_values.sort() self.assertEqual(result, sorted_repr_values) - def test_print(self): - try: - fo = open(support.TESTFN, "w") - fo.write(str(self.set)) - fo.close() - fo = open(support.TESTFN, "r") - self.assertEqual(fo.read(), repr(self.set)) - finally: - fo.close() - support.unlink(support.TESTFN) - def test_length(self): self.assertEqual(len(self.set), self.length) @@ -987,7 +954,7 @@ class TestBasicOpsBytes(TestBasicOps, unittest.TestCase): class TestBasicOpsMixedStringBytes(TestBasicOps, unittest.TestCase): def setUp(self): - self._warning_filters = support.check_warnings() + self._warning_filters = warnings_helper.check_warnings() self._warning_filters.__enter__() warnings.simplefilter('ignore', BytesWarning) self.case = "string and bytes set" diff --git a/Lib/test/test_shelve.py b/Lib/test/test_shelve.py index 9ffe2cbeae4..ac25eee2e52 100644 --- a/Lib/test/test_shelve.py +++ b/Lib/test/test_shelve.py @@ -2,6 +2,7 @@ import unittest import shelve import glob from test import support +from test.support import os_helper from collections.abc import MutableMapping from test.test_dbm import dbm_iterator @@ -45,7 +46,7 @@ class TestCase(unittest.TestCase): def tearDown(self): for f in glob.glob(self.fn+"*"): - support.unlink(f) + os_helper.unlink(f) def test_close(self): d1 = {} @@ -186,7 +187,7 @@ class TestShelveBase(mapping_tests.BasicTestMappingProtocol): self._db = [] if not self._in_mem: for f in glob.glob(self.fn+"*"): - support.unlink(f) + os_helper.unlink(f) class TestAsciiFileShelve(TestShelveBase): _args={'protocol':0} diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index e56b337083c..06ca50af143 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -30,7 +30,8 @@ except ImportError: posix = None from test import support -from test.support import TESTFN, FakePath +from test.support import os_helper +from test.support.os_helper import TESTFN, FakePath TESTFN2 = TESTFN + "2" MACOS = sys.platform.startswith("darwin") @@ -140,9 +141,9 @@ def supports_file2file_sendfile(): return True finally: if srcname is not None: - support.unlink(srcname) + os_helper.unlink(srcname) if dstname is not None: - support.unlink(dstname) + os_helper.unlink(dstname) SUPPORTS_SENDFILE = supports_file2file_sendfile() @@ -168,7 +169,7 @@ class BaseTest: Returns the path of the directory. """ d = tempfile.mkdtemp(prefix=prefix, dir=os.getcwd()) - self.addCleanup(support.rmtree, d) + self.addCleanup(os_helper.rmtree, d) return d @@ -183,7 +184,7 @@ class TestRmTree(BaseTest, unittest.TestCase): self.assertIsInstance(victim, bytes) shutil.rmtree(victim) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_rmtree_fails_on_symlink(self): tmp = self.mkdtemp() dir_ = os.path.join(tmp, 'dir') @@ -202,7 +203,7 @@ class TestRmTree(BaseTest, unittest.TestCase): self.assertEqual(errors[0][1], link) self.assertIsInstance(errors[0][2][1], OSError) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_rmtree_works_on_symlinks(self): tmp = self.mkdtemp() dir1 = os.path.join(tmp, 'dir1') @@ -231,7 +232,7 @@ class TestRmTree(BaseTest, unittest.TestCase): os.mkdir(dir_) link = os.path.join(tmp, 'link') _winapi.CreateJunction(dir_, link) - self.addCleanup(support.unlink, link) + self.addCleanup(os_helper.unlink, link) self.assertRaises(OSError, shutil.rmtree, link) self.assertTrue(os.path.exists(dir_)) self.assertTrue(os.path.lexists(link)) @@ -313,7 +314,7 @@ class TestRmTree(BaseTest, unittest.TestCase): self.child_file_path = os.path.join(TESTFN, 'a') self.child_dir_path = os.path.join(TESTFN, 'b') - support.create_empty_file(self.child_file_path) + os_helper.create_empty_file(self.child_file_path) os.mkdir(self.child_dir_path) old_dir_mode = os.stat(TESTFN).st_mode old_child_file_mode = os.stat(self.child_file_path).st_mode @@ -407,7 +408,7 @@ class TestRmTree(BaseTest, unittest.TestCase): self.assertRaises(NotADirectoryError, shutil.rmtree, path) os.remove(path) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_rmtree_on_symlink(self): # bug 1669. os.mkdir(TESTFN) @@ -482,7 +483,7 @@ class TestCopyTree(BaseTest, unittest.TestCase): with self.assertRaises(FileExistsError): shutil.copytree(src_dir, dst_dir, dirs_exist_ok=False) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_copytree_symlinks(self): tmp_dir = self.mkdtemp() src_dir = os.path.join(tmp_dir, 'src') @@ -634,7 +635,7 @@ class TestCopyTree(BaseTest, unittest.TestCase): write_file((src_dir, 'restrictive.txt'), '456') os.chmod(os.path.join(src_dir, 'restrictive.txt'), 0o600) restrictive_subdir = tempfile.mkdtemp(dir=src_dir) - self.addCleanup(support.rmtree, restrictive_subdir) + self.addCleanup(os_helper.rmtree, restrictive_subdir) os.chmod(restrictive_subdir, 0o600) shutil.copytree(src_dir, dst_dir) @@ -681,7 +682,7 @@ class TestCopyTree(BaseTest, unittest.TestCase): # Issue #3002: copyfile and copytree block indefinitely on named pipes @unittest.skipUnless(hasattr(os, "mkfifo"), 'requires os.mkfifo()') - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_copytree_named_pipe(self): os.mkdir(TESTFN) try: @@ -719,7 +720,7 @@ class TestCopyTree(BaseTest, unittest.TestCase): shutil.copytree(src_dir, dst_dir, copy_function=_copy) self.assertEqual(len(copied), 2) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_copytree_dangling_symlinks(self): # a dangling symlink raises an error at the end src_dir = self.mkdtemp() @@ -739,7 +740,7 @@ class TestCopyTree(BaseTest, unittest.TestCase): shutil.copytree(src_dir, dst_dir, symlinks=True) self.assertIn('test.txt', os.listdir(dst_dir)) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_copytree_symlink_dir(self): src_dir = self.mkdtemp() dst_dir = os.path.join(self.mkdtemp(), 'destination') @@ -785,7 +786,7 @@ class TestCopy(BaseTest, unittest.TestCase): ### shutil.copymode - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_copymode_follow_symlinks(self): tmp_dir = self.mkdtemp() src = os.path.join(tmp_dir, 'foo') @@ -818,7 +819,7 @@ class TestCopy(BaseTest, unittest.TestCase): self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) @unittest.skipUnless(hasattr(os, 'lchmod'), 'requires os.lchmod') - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_copymode_symlink_to_symlink(self): tmp_dir = self.mkdtemp() src = os.path.join(tmp_dir, 'foo') @@ -848,7 +849,7 @@ class TestCopy(BaseTest, unittest.TestCase): self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) @unittest.skipIf(hasattr(os, 'lchmod'), 'requires os.lchmod to be missing') - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_copymode_symlink_to_symlink_wo_lchmod(self): tmp_dir = self.mkdtemp() src = os.path.join(tmp_dir, 'foo') @@ -863,7 +864,7 @@ class TestCopy(BaseTest, unittest.TestCase): ### shutil.copystat - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_copystat_symlinks(self): tmp_dir = self.mkdtemp() src = os.path.join(tmp_dir, 'foo') @@ -935,7 +936,7 @@ class TestCopy(BaseTest, unittest.TestCase): ### shutil.copyxattr - @support.skip_unless_xattr + @os_helper.skip_unless_xattr def test_copyxattr(self): tmp_dir = self.mkdtemp() src = os.path.join(tmp_dir, 'foo') @@ -999,8 +1000,8 @@ class TestCopy(BaseTest, unittest.TestCase): self.assertEqual(os.getxattr(dst, 'user.the_value'), b'fiddly') self.assertEqual(os.getxattr(dstro, 'user.the_value'), b'fiddly') - @support.skip_unless_symlink - @support.skip_unless_xattr + @os_helper.skip_unless_symlink + @os_helper.skip_unless_xattr @unittest.skipUnless(hasattr(os, 'geteuid') and os.geteuid() == 0, 'root privileges required') def test_copyxattr_symlinks(self): @@ -1042,7 +1043,7 @@ class TestCopy(BaseTest, unittest.TestCase): self.assertTrue(os.path.exists(file2)) self.assertEqual(os.stat(file1).st_mode, os.stat(file2).st_mode) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_copy_symlinks(self): tmp_dir = self.mkdtemp() src = os.path.join(tmp_dir, 'foo') @@ -1084,7 +1085,7 @@ class TestCopy(BaseTest, unittest.TestCase): self.assertEqual(getattr(file1_stat, 'st_flags'), getattr(file2_stat, 'st_flags')) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_copy2_symlinks(self): tmp_dir = self.mkdtemp() src = os.path.join(tmp_dir, 'foo') @@ -1119,7 +1120,7 @@ class TestCopy(BaseTest, unittest.TestCase): if hasattr(os, 'lchflags') and hasattr(src_link_stat, 'st_flags'): self.assertEqual(src_link_stat.st_flags, dst_stat.st_flags) - @support.skip_unless_xattr + @os_helper.skip_unless_xattr def test_copy2_xattr(self): tmp_dir = self.mkdtemp() src = os.path.join(tmp_dir, 'foo') @@ -1146,7 +1147,7 @@ class TestCopy(BaseTest, unittest.TestCase): ### shutil.copyfile - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_copyfile_symlinks(self): tmp_dir = self.mkdtemp() src = os.path.join(tmp_dir, 'src') @@ -1183,7 +1184,7 @@ class TestCopy(BaseTest, unittest.TestCase): finally: shutil.rmtree(TESTFN, ignore_errors=True) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_dont_copy_file_onto_symlink_to_itself(self): # bug 851123. os.mkdir(TESTFN) @@ -1258,7 +1259,7 @@ class TestArchives(BaseTest, unittest.TestCase): work_dir = os.path.dirname(tmpdir2) rel_base_name = os.path.join(os.path.basename(tmpdir2), 'archive') - with support.change_cwd(work_dir): + with os_helper.change_cwd(work_dir): base_name = os.path.abspath(rel_base_name) tarball = make_archive(rel_base_name, 'gztar', root_dir, '.') @@ -1272,7 +1273,7 @@ class TestArchives(BaseTest, unittest.TestCase): './file1', './file2', './sub/file3']) # trying an uncompressed one - with support.change_cwd(work_dir): + with os_helper.change_cwd(work_dir): tarball = make_archive(rel_base_name, 'tar', root_dir, '.') self.assertEqual(tarball, base_name + '.tar') self.assertTrue(os.path.isfile(tarball)) @@ -1347,7 +1348,7 @@ class TestArchives(BaseTest, unittest.TestCase): work_dir = os.path.dirname(tmpdir2) rel_base_name = os.path.join(os.path.basename(tmpdir2), 'archive') - with support.change_cwd(work_dir): + with os_helper.change_cwd(work_dir): base_name = os.path.abspath(rel_base_name) res = make_archive(rel_base_name, 'zip', root_dir) @@ -1360,7 +1361,7 @@ class TestArchives(BaseTest, unittest.TestCase): 'dist/file1', 'dist/file2', 'dist/sub/file3', 'outer']) - with support.change_cwd(work_dir): + with os_helper.change_cwd(work_dir): base_name = os.path.abspath(rel_base_name) res = make_archive(rel_base_name, 'zip', root_dir, base_dir) @@ -1412,7 +1413,7 @@ class TestArchives(BaseTest, unittest.TestCase): # now check the ZIP file using `unzip -t` zip_cmd = ['unzip', '-t', archive] - with support.change_cwd(root_dir): + with os_helper.change_cwd(root_dir): try: subprocess.check_output(zip_cmd, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as exc: @@ -1462,7 +1463,7 @@ class TestArchives(BaseTest, unittest.TestCase): base_name = os.path.join(self.mkdtemp(), 'archive') group = grp.getgrgid(0)[0] owner = pwd.getpwuid(0)[0] - with support.change_cwd(root_dir): + with os_helper.change_cwd(root_dir): archive_name = make_archive(base_name, 'gztar', root_dir, 'dist', owner=owner, group=group) @@ -1496,7 +1497,7 @@ class TestArchives(BaseTest, unittest.TestCase): def test_make_tarfile_in_curdir(self): # Issue #21280 root_dir = self.mkdtemp() - with support.change_cwd(root_dir): + with os_helper.change_cwd(root_dir): self.assertEqual(make_archive('test', 'tar'), 'test.tar') self.assertTrue(os.path.isfile('test.tar')) @@ -1504,7 +1505,7 @@ class TestArchives(BaseTest, unittest.TestCase): def test_make_zipfile_in_curdir(self): # Issue #21280 root_dir = self.mkdtemp() - with support.change_cwd(root_dir): + with os_helper.change_cwd(root_dir): self.assertEqual(make_archive('test', 'zip'), 'test.zip') self.assertTrue(os.path.isfile('test.zip')) @@ -1711,18 +1712,18 @@ class TestWhich(BaseTest, unittest.TestCase): # that exists, it should be returned. base_dir, tail_dir = os.path.split(self.dir) relpath = os.path.join(tail_dir, self.file) - with support.change_cwd(path=base_dir): + with os_helper.change_cwd(path=base_dir): rv = shutil.which(relpath, path=self.temp_dir) self.assertEqual(rv, relpath) # But it shouldn't be searched in PATH directories (issue #16957). - with support.change_cwd(path=self.dir): + with os_helper.change_cwd(path=self.dir): rv = shutil.which(relpath, path=base_dir) self.assertIsNone(rv) def test_cwd(self): # Issue #16957 base_dir = os.path.dirname(self.dir) - with support.change_cwd(path=self.dir): + with os_helper.change_cwd(path=self.dir): rv = shutil.which(self.file, path=base_dir) if sys.platform == "win32": # Windows: current directory implicitly on PATH @@ -1743,7 +1744,7 @@ class TestWhich(BaseTest, unittest.TestCase): def test_relative_path(self): base_dir, tail_dir = os.path.split(self.dir) - with support.change_cwd(path=base_dir): + with os_helper.change_cwd(path=base_dir): rv = shutil.which(self.file, path=tail_dir) self.assertEqual(rv, os.path.join(tail_dir, self.file)) @@ -1761,19 +1762,19 @@ class TestWhich(BaseTest, unittest.TestCase): self.assertEqual(rv, self.temp_file.name[:-4] + self.ext) def test_environ_path(self): - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['PATH'] = self.env_path rv = shutil.which(self.file) self.assertEqual(rv, self.temp_file.name) def test_environ_path_empty(self): # PATH='': no match - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['PATH'] = '' with unittest.mock.patch('os.confstr', return_value=self.dir, \ create=True), \ support.swap_attr(os, 'defpath', self.dir), \ - support.change_cwd(self.dir): + os_helper.change_cwd(self.dir): rv = shutil.which(self.file) self.assertIsNone(rv) @@ -1786,7 +1787,7 @@ class TestWhich(BaseTest, unittest.TestCase): expected_cwd = os.path.join(curdir, expected_cwd) # PATH=':': explicitly looks in the current directory - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['PATH'] = os.pathsep with unittest.mock.patch('os.confstr', return_value=self.dir, \ create=True), \ @@ -1795,12 +1796,12 @@ class TestWhich(BaseTest, unittest.TestCase): self.assertIsNone(rv) # look in current directory - with support.change_cwd(self.dir): + with os_helper.change_cwd(self.dir): rv = shutil.which(self.file) self.assertEqual(rv, expected_cwd) def test_environ_path_missing(self): - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env.pop('PATH', None) # without confstr @@ -1819,14 +1820,14 @@ class TestWhich(BaseTest, unittest.TestCase): def test_empty_path(self): base_dir = os.path.dirname(self.dir) - with support.change_cwd(path=self.dir), \ - support.EnvironmentVarGuard() as env: + with os_helper.change_cwd(path=self.dir), \ + os_helper.EnvironmentVarGuard() as env: env['PATH'] = self.env_path rv = shutil.which(self.file, path='') self.assertIsNone(rv) def test_empty_path_no_PATH(self): - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env.pop('PATH', None) rv = shutil.which(self.file) self.assertIsNone(rv) @@ -1843,7 +1844,7 @@ class TestWhich(BaseTest, unittest.TestCase): program = os.path.basename(temp_filexyz.name) program = os.path.splitext(program)[0] - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['PATHEXT'] = ext rv = shutil.which(program, path=self.temp_dir) self.assertEqual(rv, temp_filexyz.name) @@ -1918,7 +1919,7 @@ class TestMove(BaseTest, unittest.TestCase): try: self._check_move_dir(self.src_dir, dst_dir, dst_dir) finally: - support.rmtree(dst_dir) + os_helper.rmtree(dst_dir) @mock_rename def test_move_dir_other_fs(self): @@ -1965,7 +1966,7 @@ class TestMove(BaseTest, unittest.TestCase): msg='_destinsrc() wrongly concluded that ' 'dst (%s) is not in src (%s)' % (dst, src)) finally: - support.rmtree(TESTFN) + os_helper.rmtree(TESTFN) def test_destinsrc_false_positive(self): os.mkdir(TESTFN) @@ -1977,9 +1978,9 @@ class TestMove(BaseTest, unittest.TestCase): msg='_destinsrc() wrongly concluded that ' 'dst (%s) is in src (%s)' % (dst, src)) finally: - support.rmtree(TESTFN) + os_helper.rmtree(TESTFN) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink @mock_rename def test_move_file_symlink(self): dst = os.path.join(self.src_dir, 'bar') @@ -1988,7 +1989,7 @@ class TestMove(BaseTest, unittest.TestCase): self.assertTrue(os.path.islink(self.dst_file)) self.assertTrue(os.path.samefile(self.src_file, self.dst_file)) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink @mock_rename def test_move_file_symlink_to_dir(self): filename = "bar" @@ -1999,7 +2000,7 @@ class TestMove(BaseTest, unittest.TestCase): self.assertTrue(os.path.islink(final_link)) self.assertTrue(os.path.samefile(self.src_file, final_link)) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink @mock_rename def test_move_dangling_symlink(self): src = os.path.join(self.src_dir, 'baz') @@ -2010,7 +2011,7 @@ class TestMove(BaseTest, unittest.TestCase): self.assertTrue(os.path.islink(dst_link)) self.assertEqual(os.path.realpath(src), os.path.realpath(dst_link)) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink @mock_rename def test_move_dir_symlink(self): src = os.path.join(self.src_dir, 'baz') @@ -2044,8 +2045,8 @@ class TestMove(BaseTest, unittest.TestCase): moved = [] def _copy(src, dst): moved.append((src, dst)) - support.create_empty_file(os.path.join(self.src_dir, 'child')) - support.create_empty_file(os.path.join(self.src_dir, 'child1')) + os_helper.create_empty_file(os.path.join(self.src_dir, 'child')) + os_helper.create_empty_file(os.path.join(self.src_dir, 'child1')) shutil.move(self.src_dir, self.dst_dir, copy_function=_copy) self.assertEqual(len(moved), 3) @@ -2167,11 +2168,11 @@ class TestCopyFileObj(unittest.TestCase): @classmethod def tearDownClass(cls): - support.unlink(TESTFN) - support.unlink(TESTFN2) + os_helper.unlink(TESTFN) + os_helper.unlink(TESTFN2) def tearDown(self): - support.unlink(TESTFN2) + os_helper.unlink(TESTFN2) @contextlib.contextmanager def get_files(self): @@ -2216,7 +2217,7 @@ class TestCopyFileObj(unittest.TestCase): with tempfile.NamedTemporaryFile(dir=os.getcwd(), delete=False) as f: f.write(b'foo') fname = f.name - self.addCleanup(support.unlink, fname) + self.addCleanup(os_helper.unlink, fname) with unittest.mock.patch("shutil._copyfileobj_readinto") as m: shutil.copyfile(fname, TESTFN2) self.assertEqual(m.call_args[0][2], 3) @@ -2225,7 +2226,7 @@ class TestCopyFileObj(unittest.TestCase): with tempfile.NamedTemporaryFile(dir=os.getcwd(), delete=False) as f: pass fname = f.name - self.addCleanup(support.unlink, fname) + self.addCleanup(os_helper.unlink, fname) with unittest.mock.patch("shutil._copyfileobj_readinto") as m: shutil.copyfile(fname, TESTFN2) assert not m.called @@ -2247,10 +2248,10 @@ class _ZeroCopyFileTest(object): @classmethod def tearDownClass(cls): - support.unlink(TESTFN) + os_helper.unlink(TESTFN) def tearDown(self): - support.unlink(TESTFN2) + os_helper.unlink(TESTFN2) @contextlib.contextmanager def get_files(self): @@ -2296,8 +2297,8 @@ class _ZeroCopyFileTest(object): def test_empty_file(self): srcname = TESTFN + 'src' dstname = TESTFN + 'dst' - self.addCleanup(lambda: support.unlink(srcname)) - self.addCleanup(lambda: support.unlink(dstname)) + self.addCleanup(lambda: os_helper.unlink(srcname)) + self.addCleanup(lambda: os_helper.unlink(dstname)) with open(srcname, "wb"): pass @@ -2421,9 +2422,9 @@ class TestZeroCopySendfile(_ZeroCopyFileTest, unittest.TestCase): # sendfile() are the same. self.assertEqual(blocksize, os.path.getsize(TESTFN)) # ...unless we're dealing with a small file. - support.unlink(TESTFN2) + os_helper.unlink(TESTFN2) write_file(TESTFN2, b"hello", binary=True) - self.addCleanup(support.unlink, TESTFN2 + '3') + self.addCleanup(os_helper.unlink, TESTFN2 + '3') self.assertRaises(ZeroDivisionError, shutil.copyfile, TESTFN2, TESTFN2 + '3') blocksize = m.call_args[0][3] @@ -2473,20 +2474,20 @@ class TestGetTerminalSize(unittest.TestCase): def test_os_environ_first(self): "Check if environment variables have precedence" - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['COLUMNS'] = '777' del env['LINES'] size = shutil.get_terminal_size() self.assertEqual(size.columns, 777) - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: del env['COLUMNS'] env['LINES'] = '888' size = shutil.get_terminal_size() self.assertEqual(size.lines, 888) def test_bad_environ(self): - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['COLUMNS'] = 'xxx' env['LINES'] = 'yyy' size = shutil.get_terminal_size() @@ -2510,7 +2511,7 @@ class TestGetTerminalSize(unittest.TestCase): self.skipTest("stty invocation failed") expected = (int(size[1]), int(size[0])) # reversed order - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: del env['LINES'] del env['COLUMNS'] actual = shutil.get_terminal_size() @@ -2518,7 +2519,7 @@ class TestGetTerminalSize(unittest.TestCase): self.assertEqual(expected, actual) def test_fallback(self): - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: del env['LINES'] del env['COLUMNS'] diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py index 957e7a41d54..9751c64c99e 100644 --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -13,6 +13,7 @@ from test.support import (captured_stderr, TESTFN, EnvironmentVarGuard, import builtins import encodings import glob +import io import os import re import shutil @@ -320,6 +321,14 @@ class HelperFunctionsTests(unittest.TestCase): mock_addsitedir.assert_not_called() self.assertFalse(known_paths) + def test_trace(self): + message = "bla-bla-bla" + for verbose, out in (True, message + "\n"), (False, ""): + with mock.patch('sys.flags', mock.Mock(verbose=verbose)), \ + mock.patch('sys.stderr', io.StringIO()): + site._trace(message) + self.assertEqual(sys.stderr.getvalue(), out) + class PthFile(object): """Helper class for handling testing of .pth files""" @@ -534,7 +543,7 @@ class StartupImportTests(unittest.TestCase): # found in sys.path (see site.addpackage()). Skip the test if at least # one .pth file is found. for path in isolated_paths: - pth_files = glob.glob(os.path.join(path, "*.pth")) + pth_files = glob.glob(os.path.join(glob.escape(path), "*.pth")) if pth_files: self.skipTest(f"found {len(pth_files)} .pth files in: {path}") diff --git a/Lib/test/test_smtpd.py b/Lib/test/test_smtpd.py index 3be77397439..d5d5abfcf37 100644 --- a/Lib/test/test_smtpd.py +++ b/Lib/test/test_smtpd.py @@ -2,6 +2,7 @@ import unittest import textwrap from test import support, mock_socket from test.support import socket_helper +from test.support import warnings_helper import socket import io import smtpd @@ -714,49 +715,49 @@ class SMTPDChannelTest(unittest.TestCase): b'recognized\r\n') def test_attribute_deprecations(self): - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): spam = self.channel._SMTPChannel__server - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): self.channel._SMTPChannel__server = 'spam' - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): spam = self.channel._SMTPChannel__line - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): self.channel._SMTPChannel__line = 'spam' - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): spam = self.channel._SMTPChannel__state - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): self.channel._SMTPChannel__state = 'spam' - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): spam = self.channel._SMTPChannel__greeting - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): self.channel._SMTPChannel__greeting = 'spam' - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): spam = self.channel._SMTPChannel__mailfrom - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): self.channel._SMTPChannel__mailfrom = 'spam' - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): spam = self.channel._SMTPChannel__rcpttos - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): self.channel._SMTPChannel__rcpttos = 'spam' - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): spam = self.channel._SMTPChannel__data - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): self.channel._SMTPChannel__data = 'spam' - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): spam = self.channel._SMTPChannel__fqdn - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): self.channel._SMTPChannel__fqdn = 'spam' - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): spam = self.channel._SMTPChannel__peer - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): self.channel._SMTPChannel__peer = 'spam' - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): spam = self.channel._SMTPChannel__conn - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): self.channel._SMTPChannel__conn = 'spam' - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): spam = self.channel._SMTPChannel__addr - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): self.channel._SMTPChannel__addr = 'spam' @unittest.skipUnless(socket_helper.IPV6_ENABLED, "IPv6 not enabled") diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py index 57629990031..7816ed34886 100644 --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -22,7 +22,7 @@ import unittest from test import support, mock_socket from test.support import hashlib_helper from test.support import socket_helper -from test.support import threading_setup, threading_cleanup, join_thread +from test.support import threading_helper from unittest.mock import Mock HOST = socket_helper.HOST @@ -217,7 +217,7 @@ class DebuggingServerTests(unittest.TestCase): maxDiff = None def setUp(self): - self.thread_key = threading_setup() + self.thread_key = threading_helper.threading_setup() self.real_getfqdn = socket.getfqdn socket.getfqdn = mock_socket.getfqdn # temporarily replace sys.stdout to capture DebuggingServer output @@ -249,7 +249,7 @@ class DebuggingServerTests(unittest.TestCase): self.client_evt.set() # wait for the server thread to terminate self.serv_evt.wait() - join_thread(self.thread) + threading_helper.join_thread(self.thread) # restore sys.stdout sys.stdout = self.old_stdout # restore DEBUGSTREAM @@ -257,7 +257,7 @@ class DebuggingServerTests(unittest.TestCase): smtpd.DEBUGSTREAM = self.old_DEBUGSTREAM del self.thread self.doCleanups() - threading_cleanup(*self.thread_key) + threading_helper.threading_cleanup(*self.thread_key) def get_output_without_xpeer(self): test_output = self.output.getvalue() @@ -704,7 +704,7 @@ class TooLongLineTests(unittest.TestCase): respdata = b'250 OK' + (b'.' * smtplib._MAXLINE * 2) + b'\n' def setUp(self): - self.thread_key = threading_setup() + self.thread_key = threading_helper.threading_setup() self.old_stdout = sys.stdout self.output = io.StringIO() sys.stdout = self.output @@ -722,10 +722,10 @@ class TooLongLineTests(unittest.TestCase): def tearDown(self): self.evt.wait() sys.stdout = self.old_stdout - join_thread(self.thread) + threading_helper.join_thread(self.thread) del self.thread self.doCleanups() - threading_cleanup(*self.thread_key) + threading_helper.threading_cleanup(*self.thread_key) def testLineTooLong(self): self.assertRaises(smtplib.SMTPResponseException, smtplib.SMTP, @@ -955,7 +955,7 @@ class SimSMTPServer(smtpd.SMTPServer): class SMTPSimTests(unittest.TestCase): def setUp(self): - self.thread_key = threading_setup() + self.thread_key = threading_helper.threading_setup() self.real_getfqdn = socket.getfqdn socket.getfqdn = mock_socket.getfqdn self.serv_evt = threading.Event() @@ -978,10 +978,10 @@ class SMTPSimTests(unittest.TestCase): self.client_evt.set() # wait for the server thread to terminate self.serv_evt.wait() - join_thread(self.thread) + threading_helper.join_thread(self.thread) del self.thread self.doCleanups() - threading_cleanup(*self.thread_key) + threading_helper.threading_cleanup(*self.thread_key) def testBasic(self): # smoke test @@ -1268,7 +1268,7 @@ class SMTPUTF8SimTests(unittest.TestCase): maxDiff = None def setUp(self): - self.thread_key = threading_setup() + self.thread_key = threading_helper.threading_setup() self.real_getfqdn = socket.getfqdn socket.getfqdn = mock_socket.getfqdn self.serv_evt = threading.Event() @@ -1293,10 +1293,10 @@ class SMTPUTF8SimTests(unittest.TestCase): self.client_evt.set() # wait for the server thread to terminate self.serv_evt.wait() - join_thread(self.thread) + threading_helper.join_thread(self.thread) del self.thread self.doCleanups() - threading_cleanup(*self.thread_key) + threading_helper.threading_cleanup(*self.thread_key) def test_test_server_supports_extensions(self): smtp = smtplib.SMTP( @@ -1397,7 +1397,7 @@ class SimSMTPAUTHInitialResponseServer(SimSMTPServer): class SMTPAUTHInitialResponseSimTests(unittest.TestCase): def setUp(self): - self.thread_key = threading_setup() + self.thread_key = threading_helper.threading_setup() self.real_getfqdn = socket.getfqdn socket.getfqdn = mock_socket.getfqdn self.serv_evt = threading.Event() @@ -1421,10 +1421,10 @@ class SMTPAUTHInitialResponseSimTests(unittest.TestCase): self.client_evt.set() # wait for the server thread to terminate self.serv_evt.wait() - join_thread(self.thread) + threading_helper.join_thread(self.thread) del self.thread self.doCleanups() - threading_cleanup(*self.thread_key) + threading_helper.threading_cleanup(*self.thread_key) def testAUTH_PLAIN_initial_response_login(self): self.serv.add_feature('AUTH PLAIN') diff --git a/Lib/test/test_smtpnet.py b/Lib/test/test_smtpnet.py index 74a00a9d7cc..72f51cd8d81 100644 --- a/Lib/test/test_smtpnet.py +++ b/Lib/test/test_smtpnet.py @@ -1,10 +1,11 @@ import unittest from test import support +from test.support import import_helper from test.support import socket_helper import smtplib import socket -ssl = support.import_module("ssl") +ssl = import_helper.import_module("ssl") support.requires("network") diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index dc1330735df..67ac045330f 100755 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1,6 +1,8 @@ import unittest from test import support +from test.support import os_helper from test.support import socket_helper +from test.support import threading_helper import errno import io @@ -336,7 +338,7 @@ class ThreadableTest: self.server_ready.set() def _setUp(self): - self.wait_threads = support.wait_threads_exit() + self.wait_threads = threading_helper.wait_threads_exit() self.wait_threads.__enter__() self.server_ready = threading.Event() @@ -696,7 +698,7 @@ class UnixSocketTestBase(SocketTestBase): def bindSock(self, sock): path = tempfile.mktemp(dir=self.dir_path) socket_helper.bind_unix_socket(sock, path) - self.addCleanup(support.unlink, path) + self.addCleanup(os_helper.unlink, path) class UnixStreamBase(UnixSocketTestBase): """Base class for Unix-domain SOCK_STREAM tests.""" @@ -1916,14 +1918,14 @@ class GeneralModuleTests(unittest.TestCase): def test_socket_fileno_requires_valid_fd(self): WSAENOTSOCK = 10038 with self.assertRaises(OSError) as cm: - socket.socket(fileno=support.make_bad_fd()) + socket.socket(fileno=os_helper.make_bad_fd()) self.assertIn(cm.exception.errno, (errno.EBADF, WSAENOTSOCK)) with self.assertRaises(OSError) as cm: socket.socket( socket.AF_INET, socket.SOCK_STREAM, - fileno=support.make_bad_fd()) + fileno=os_helper.make_bad_fd()) self.assertIn(cm.exception.errno, (errno.EBADF, WSAENOTSOCK)) def test_socket_fileno_requires_socket_fd(self): @@ -5457,35 +5459,35 @@ class TestUnixDomain(unittest.TestCase): def testStrAddr(self): # Test binding to and retrieving a normal string pathname. - path = os.path.abspath(support.TESTFN) + path = os.path.abspath(os_helper.TESTFN) self.bind(self.sock, path) - self.addCleanup(support.unlink, path) + self.addCleanup(os_helper.unlink, path) self.assertEqual(self.sock.getsockname(), path) def testBytesAddr(self): # Test binding to a bytes pathname. - path = os.path.abspath(support.TESTFN) + path = os.path.abspath(os_helper.TESTFN) self.bind(self.sock, self.encoded(path)) - self.addCleanup(support.unlink, path) + self.addCleanup(os_helper.unlink, path) self.assertEqual(self.sock.getsockname(), path) def testSurrogateescapeBind(self): # Test binding to a valid non-ASCII pathname, with the # non-ASCII bytes supplied using surrogateescape encoding. - path = os.path.abspath(support.TESTFN_UNICODE) + path = os.path.abspath(os_helper.TESTFN_UNICODE) b = self.encoded(path) self.bind(self.sock, b.decode("ascii", "surrogateescape")) - self.addCleanup(support.unlink, path) + self.addCleanup(os_helper.unlink, path) self.assertEqual(self.sock.getsockname(), path) def testUnencodableAddr(self): # Test binding to a pathname that cannot be encoded in the # file system encoding. - if support.TESTFN_UNENCODABLE is None: + if os_helper.TESTFN_UNENCODABLE is None: self.skipTest("No unencodable filename available") - path = os.path.abspath(support.TESTFN_UNENCODABLE) + path = os.path.abspath(os_helper.TESTFN_UNENCODABLE) self.bind(self.sock, path) - self.addCleanup(support.unlink, path) + self.addCleanup(os_helper.unlink, path) self.assertEqual(self.sock.getsockname(), path) @@ -5959,16 +5961,16 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest): chunk = b"".join([random.choice(string.ascii_letters).encode() for i in range(cls.BUFSIZE)]) - with open(support.TESTFN, 'wb') as f: + with open(os_helper.TESTFN, 'wb') as f: for csize in chunks(cls.FILESIZE, cls.BUFSIZE): f.write(chunk) - with open(support.TESTFN, 'rb') as f: + with open(os_helper.TESTFN, 'rb') as f: cls.FILEDATA = f.read() assert len(cls.FILEDATA) == cls.FILESIZE @classmethod def tearDownClass(cls): - support.unlink(support.TESTFN) + os_helper.unlink(os_helper.TESTFN) def accept_conn(self): self.serv.settimeout(support.LONG_TIMEOUT) @@ -5995,7 +5997,7 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest): def _testRegularFile(self): address = self.serv.getsockname() - file = open(support.TESTFN, 'rb') + file = open(os_helper.TESTFN, 'rb') with socket.create_connection(address) as sock, file as file: meth = self.meth_from_sock(sock) sent = meth(file) @@ -6030,9 +6032,9 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest): def _testEmptyFileSend(self): address = self.serv.getsockname() - filename = support.TESTFN + "2" + filename = os_helper.TESTFN + "2" with open(filename, 'wb'): - self.addCleanup(support.unlink, filename) + self.addCleanup(os_helper.unlink, filename) file = open(filename, 'rb') with socket.create_connection(address) as sock, file as file: meth = self.meth_from_sock(sock) @@ -6049,7 +6051,7 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest): def _testOffset(self): address = self.serv.getsockname() - file = open(support.TESTFN, 'rb') + file = open(os_helper.TESTFN, 'rb') with socket.create_connection(address) as sock, file as file: meth = self.meth_from_sock(sock) sent = meth(file, offset=5000) @@ -6066,7 +6068,7 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest): def _testCount(self): address = self.serv.getsockname() - file = open(support.TESTFN, 'rb') + file = open(os_helper.TESTFN, 'rb') sock = socket.create_connection(address, timeout=support.LOOPBACK_TIMEOUT) with sock, file: @@ -6087,7 +6089,7 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest): def _testCountSmall(self): address = self.serv.getsockname() - file = open(support.TESTFN, 'rb') + file = open(os_helper.TESTFN, 'rb') sock = socket.create_connection(address, timeout=support.LOOPBACK_TIMEOUT) with sock, file: @@ -6108,7 +6110,7 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest): def _testCountWithOffset(self): address = self.serv.getsockname() - file = open(support.TESTFN, 'rb') + file = open(os_helper.TESTFN, 'rb') with socket.create_connection(address, timeout=2) as sock, file as file: count = 100007 meth = self.meth_from_sock(sock) @@ -6127,7 +6129,7 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest): def _testNonBlocking(self): address = self.serv.getsockname() - file = open(support.TESTFN, 'rb') + file = open(os_helper.TESTFN, 'rb') with socket.create_connection(address) as sock, file as file: sock.setblocking(False) meth = self.meth_from_sock(sock) @@ -6143,7 +6145,7 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest): def _testWithTimeout(self): address = self.serv.getsockname() - file = open(support.TESTFN, 'rb') + file = open(os_helper.TESTFN, 'rb') sock = socket.create_connection(address, timeout=support.LOOPBACK_TIMEOUT) with sock, file: @@ -6161,7 +6163,7 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest): def _testWithTimeoutTriggeredSend(self): address = self.serv.getsockname() - with open(support.TESTFN, 'rb') as file: + with open(os_helper.TESTFN, 'rb') as file: with socket.create_connection(address) as sock: sock.settimeout(0.01) meth = self.meth_from_sock(sock) @@ -6177,17 +6179,17 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest): pass def test_errors(self): - with open(support.TESTFN, 'rb') as file: + with open(os_helper.TESTFN, 'rb') as file: with socket.socket(type=socket.SOCK_DGRAM) as s: meth = self.meth_from_sock(s) self.assertRaisesRegex( ValueError, "SOCK_STREAM", meth, file) - with open(support.TESTFN, 'rt') as file: + with open(os_helper.TESTFN, 'rt') as file: with socket.socket() as s: meth = self.meth_from_sock(s) self.assertRaisesRegex( ValueError, "binary mode", meth, file) - with open(support.TESTFN, 'rb') as file: + with open(os_helper.TESTFN, 'rb') as file: with socket.socket() as s: meth = self.meth_from_sock(s) self.assertRaisesRegex(TypeError, "positive integer", @@ -6665,9 +6667,9 @@ def test_main(): ]) tests.append(TestMSWindowsTCPFlags) - thread_info = support.threading_setup() + thread_info = threading_helper.threading_setup() support.run_unittest(*tests) - support.threading_cleanup(*thread_info) + threading_helper.threading_cleanup(*thread_info) if __name__ == "__main__": diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py index c663cc95889..5db8cec567a 100644 --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -14,8 +14,9 @@ import unittest import socketserver import test.support -from test.support import reap_children, reap_threads, verbose +from test.support import reap_children, verbose from test.support import socket_helper +from test.support import threading_helper test.support.requires("network") @@ -120,7 +121,7 @@ class SocketServerTest(unittest.TestCase): self.assertEqual(server.server_address, server.socket.getsockname()) return server - @reap_threads + @threading_helper.reap_threads def run_server(self, svrcls, hdlrbase, testfunc): server = self.make_server(self.pickaddr(svrcls.address_family), svrcls, hdlrbase) @@ -249,7 +250,7 @@ class SocketServerTest(unittest.TestCase): socketserver.DatagramRequestHandler, self.dgram_examine) - @reap_threads + @threading_helper.reap_threads def test_shutdown(self): # Issue #2302: shutdown() should always succeed in making an # other thread leave serve_forever(). diff --git a/Lib/test/test_sqlite.py b/Lib/test/test_sqlite.py index 9564da35193..73002f228fa 100644 --- a/Lib/test/test_sqlite.py +++ b/Lib/test/test_sqlite.py @@ -1,7 +1,8 @@ import test.support +from test.support import import_helper # Skip test if _sqlite3 module not installed -test.support.import_module('_sqlite3') +import_helper.import_module('_sqlite3') import unittest import sqlite3 diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index 5d496c66876..ecb6049a675 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -5,6 +5,7 @@ import unittest import unittest.mock from test import support from test.support import socket_helper +from test.support import threading_helper import socket import select import time @@ -4429,7 +4430,7 @@ class TestPostHandshakeAuth(unittest.TestCase): # Ignore expected SSLError in ConnectionHandler of ThreadedEchoServer # (it is only raised sometimes on Windows) - with support.catch_threading_exception() as cm: + with threading_helper.catch_threading_exception() as cm: server = ThreadedEchoServer(context=server_context, chatty=False) with server: with client_context.wrap_socket(socket.socket(), @@ -4750,11 +4751,11 @@ def test_main(verbose=False): if support.is_resource_enabled('network'): tests.append(NetworkedTests) - thread_info = support.threading_setup() + thread_info = threading_helper.threading_setup() try: support.run_unittest(*tests) finally: - support.threading_cleanup(*thread_info) + threading_helper.threading_cleanup(*thread_info) if __name__ == "__main__": test_main() diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py index 5c3b1fdd8b1..bf415dda557 100644 --- a/Lib/test/test_statistics.py +++ b/Lib/test/test_statistics.py @@ -2089,6 +2089,10 @@ class TestVariance(VarianceStdevMixin, NumericTestCase, UnivariateTypeMixin): self.assertEqual(result, exact) self.assertIsInstance(result, Decimal) + def test_center_not_at_mean(self): + data = (1.0, 2.0) + self.assertEqual(self.func(data), 0.5) + self.assertEqual(self.func(data, xbar=2.0), 1.0) class TestPStdev(VarianceStdevMixin, NumericTestCase): # Tests for population standard deviation. @@ -2101,6 +2105,11 @@ class TestPStdev(VarianceStdevMixin, NumericTestCase): expected = math.sqrt(statistics.pvariance(data)) self.assertEqual(self.func(data), expected) + def test_center_not_at_mean(self): + # See issue: 40855 + data = (3, 6, 7, 10) + self.assertEqual(self.func(data), 2.5) + self.assertEqual(self.func(data, mu=0.5), 6.5) class TestStdev(VarianceStdevMixin, NumericTestCase): # Tests for sample standard deviation. @@ -2118,6 +2127,9 @@ class TestStdev(VarianceStdevMixin, NumericTestCase): expected = math.sqrt(statistics.variance(data)) self.assertEqual(self.func(data), expected) + def test_center_not_at_mean(self): + data = (1.0, 2.0) + self.assertEqual(self.func(data, xbar=2.0), 1.0) class TestGeometricMean(unittest.TestCase): diff --git a/Lib/test/test_string_literals.py b/Lib/test/test_string_literals.py index 9565ee2485a..7231970acf1 100644 --- a/Lib/test/test_string_literals.py +++ b/Lib/test/test_string_literals.py @@ -33,7 +33,6 @@ import shutil import tempfile import unittest import warnings -from test.support import use_old_parser TEMPLATE = r"""# coding: %s @@ -168,8 +167,7 @@ class TestLiterals(unittest.TestCase): eval("b'''\n\\z'''") self.assertEqual(len(w), 1) self.assertEqual(w[0].filename, '') - if use_old_parser(): - self.assertEqual(w[0].lineno, 1) + self.assertEqual(w[0].lineno, 1) with warnings.catch_warnings(record=True) as w: warnings.simplefilter('error', category=DeprecationWarning) @@ -178,8 +176,7 @@ class TestLiterals(unittest.TestCase): exc = cm.exception self.assertEqual(w, []) self.assertEqual(exc.filename, '') - if use_old_parser(): - self.assertEqual(exc.lineno, 1) + self.assertEqual(exc.lineno, 1) def test_eval_bytes_raw(self): self.assertEqual(eval(""" br'x' """), b'x') diff --git a/Lib/test/test_structmembers.py b/Lib/test/test_structmembers.py index 57ec45f3f92..07d2f623f71 100644 --- a/Lib/test/test_structmembers.py +++ b/Lib/test/test_structmembers.py @@ -1,8 +1,9 @@ import unittest -from test import support +from test.support import import_helper +from test.support import warnings_helper # Skip this test if the _testcapi module isn't available. -support.import_module('_testcapi') +import_helper.import_module('_testcapi') from _testcapi import _test_structmembersType, \ CHAR_MAX, CHAR_MIN, UCHAR_MAX, \ SHRT_MAX, SHRT_MIN, USHRT_MAX, \ @@ -116,27 +117,27 @@ class ReadWriteTests(unittest.TestCase): class TestWarnings(unittest.TestCase): def test_byte_max(self): - with support.check_warnings(('', RuntimeWarning)): + with warnings_helper.check_warnings(('', RuntimeWarning)): ts.T_BYTE = CHAR_MAX+1 def test_byte_min(self): - with support.check_warnings(('', RuntimeWarning)): + with warnings_helper.check_warnings(('', RuntimeWarning)): ts.T_BYTE = CHAR_MIN-1 def test_ubyte_max(self): - with support.check_warnings(('', RuntimeWarning)): + with warnings_helper.check_warnings(('', RuntimeWarning)): ts.T_UBYTE = UCHAR_MAX+1 def test_short_max(self): - with support.check_warnings(('', RuntimeWarning)): + with warnings_helper.check_warnings(('', RuntimeWarning)): ts.T_SHORT = SHRT_MAX+1 def test_short_min(self): - with support.check_warnings(('', RuntimeWarning)): + with warnings_helper.check_warnings(('', RuntimeWarning)): ts.T_SHORT = SHRT_MIN-1 def test_ushort_max(self): - with support.check_warnings(('', RuntimeWarning)): + with warnings_helper.check_warnings(('', RuntimeWarning)): ts.T_USHORT = USHRT_MAX+1 diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index aced87694cf..0162424e2fd 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1,6 +1,9 @@ import unittest from unittest import mock from test import support +from test.support import import_helper +from test.support import os_helper +from test.support import warnings_helper import subprocess import sys import signal @@ -20,7 +23,7 @@ import threading import gc import textwrap import json -from test.support import FakePath +from test.support.os_helper import FakePath try: import _testcapi @@ -357,7 +360,7 @@ class ProcessTestCase(BaseTestCase): # Normalize an expected cwd (for Tru64 support). # We can't use os.path.realpath since it doesn't expand Tru64 {memb} # strings. See bug #1063571. - with support.change_cwd(cwd): + with os_helper.change_cwd(cwd): return os.getcwd() # For use in the test_cwd* tests below. @@ -406,7 +409,7 @@ class ProcessTestCase(BaseTestCase): # is relative. python_dir, python_base = self._split_python_path() rel_python = os.path.join(os.curdir, python_base) - with support.temp_cwd() as wrong_dir: + with os_helper.temp_cwd() as wrong_dir: # Before calling with the correct cwd, confirm that the call fails # without cwd and with the wrong cwd. self.assertRaises(FileNotFoundError, subprocess.Popen, @@ -423,7 +426,7 @@ class ProcessTestCase(BaseTestCase): python_dir, python_base = self._split_python_path() rel_python = os.path.join(os.curdir, python_base) doesntexist = "somethingyoudonthave" - with support.temp_cwd() as wrong_dir: + with os_helper.temp_cwd() as wrong_dir: # Before calling with the correct cwd, confirm that the call fails # without cwd and with the wrong cwd. self.assertRaises(FileNotFoundError, subprocess.Popen, @@ -441,7 +444,7 @@ class ProcessTestCase(BaseTestCase): python_dir, python_base = self._split_python_path() abs_python = os.path.join(python_dir, python_base) rel_python = os.path.join(os.curdir, python_base) - with support.temp_dir() as wrong_dir: + with os_helper.temp_dir() as wrong_dir: # Before calling with an absolute path, confirm that using a # relative path fails. self.assertRaises(FileNotFoundError, subprocess.Popen, @@ -1052,7 +1055,7 @@ class ProcessTestCase(BaseTestCase): try: for i in range(max_handles): try: - tmpfile = os.path.join(tmpdir, support.TESTFN) + tmpfile = os.path.join(tmpdir, os_helper.TESTFN) handles.append(os.open(tmpfile, os.O_WRONLY|os.O_CREAT)) except OSError as e: if e.errno != errno.EMFILE: @@ -2881,7 +2884,7 @@ class POSIXProcessTestCase(BaseTestCase): def test_select_unbuffered(self): # Issue #11459: bufsize=0 should really set the pipes as # unbuffered (and therefore let select() work properly). - select = support.import_module("select") + select = import_helper.import_module("select") p = subprocess.Popen([sys.executable, "-c", 'import sys;' 'sys.stdout.write("apple")'], @@ -2909,7 +2912,7 @@ class POSIXProcessTestCase(BaseTestCase): self.addCleanup(p.stderr.close) ident = id(p) pid = p.pid - with support.check_warnings(('', ResourceWarning)): + with warnings_helper.check_warnings(('', ResourceWarning)): p = None if mswindows: @@ -2934,7 +2937,7 @@ class POSIXProcessTestCase(BaseTestCase): self.addCleanup(p.stderr.close) ident = id(p) pid = p.pid - with support.check_warnings(('', ResourceWarning)): + with warnings_helper.check_warnings(('', ResourceWarning)): p = None os.kill(pid, signal.SIGKILL) @@ -3288,7 +3291,8 @@ class Win32ProcessTestCase(BaseTestCase): self.assertIn(b"OSError", stderr) # Check for a warning due to using handle_list and close_fds=False - with support.check_warnings((".*overriding close_fds", RuntimeWarning)): + with warnings_helper.check_warnings((".*overriding close_fds", + RuntimeWarning)): startupinfo = subprocess.STARTUPINFO() startupinfo.lpAttributeList = {"handle_list": handles[:]} p = subprocess.Popen([sys.executable, "-c", diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index b5a16f9cb60..b268511844b 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -12,20 +12,24 @@ import textwrap import time import unittest from test import support +from test.support import import_helper +from test.support import os_helper from test.support import script_helper from test.support import socket_helper +from test.support import warnings_helper -TESTFN = support.TESTFN +TESTFN = os_helper.TESTFN class TestSupport(unittest.TestCase): def test_import_module(self): - support.import_module("ftplib") - self.assertRaises(unittest.SkipTest, support.import_module, "foo") + import_helper.import_module("ftplib") + self.assertRaises(unittest.SkipTest, + import_helper.import_module, "foo") def test_import_fresh_module(self): - support.import_fresh_module("ftplib") + import_helper.import_fresh_module("ftplib") def test_get_attribute(self): self.assertEqual(support.get_attribute(self, "test_get_attribute"), @@ -39,38 +43,38 @@ class TestSupport(unittest.TestCase): def test_unload(self): import sched self.assertIn("sched", sys.modules) - support.unload("sched") + import_helper.unload("sched") self.assertNotIn("sched", sys.modules) def test_unlink(self): with open(TESTFN, "w") as f: pass - support.unlink(TESTFN) + os_helper.unlink(TESTFN) self.assertFalse(os.path.exists(TESTFN)) - support.unlink(TESTFN) + os_helper.unlink(TESTFN) def test_rmtree(self): - dirpath = support.TESTFN + 'd' + dirpath = os_helper.TESTFN + 'd' subdirpath = os.path.join(dirpath, 'subdir') os.mkdir(dirpath) os.mkdir(subdirpath) - support.rmtree(dirpath) + os_helper.rmtree(dirpath) self.assertFalse(os.path.exists(dirpath)) with support.swap_attr(support, 'verbose', 0): - support.rmtree(dirpath) + os_helper.rmtree(dirpath) os.mkdir(dirpath) os.mkdir(subdirpath) os.chmod(dirpath, stat.S_IRUSR|stat.S_IXUSR) with support.swap_attr(support, 'verbose', 0): - support.rmtree(dirpath) + os_helper.rmtree(dirpath) self.assertFalse(os.path.exists(dirpath)) os.mkdir(dirpath) os.mkdir(subdirpath) os.chmod(dirpath, 0) with support.swap_attr(support, 'verbose', 0): - support.rmtree(dirpath) + os_helper.rmtree(dirpath) self.assertFalse(os.path.exists(dirpath)) def test_forget(self): @@ -83,12 +87,12 @@ class TestSupport(unittest.TestCase): mod = __import__(TESTFN) self.assertIn(TESTFN, sys.modules) - support.forget(TESTFN) + import_helper.forget(TESTFN) self.assertNotIn(TESTFN, sys.modules) finally: del sys.path[0] - support.unlink(mod_filename) - support.rmtree('__pycache__') + os_helper.unlink(mod_filename) + os_helper.rmtree('__pycache__') def test_HOST(self): s = socket.create_server((socket_helper.HOST, 0)) @@ -115,23 +119,23 @@ class TestSupport(unittest.TestCase): try: path = os.path.join(parent_dir, 'temp') self.assertFalse(os.path.isdir(path)) - with support.temp_dir(path) as temp_path: + with os_helper.temp_dir(path) as temp_path: self.assertEqual(temp_path, path) self.assertTrue(os.path.isdir(path)) self.assertFalse(os.path.isdir(path)) finally: - support.rmtree(parent_dir) + os_helper.rmtree(parent_dir) def test_temp_dir__path_none(self): """Test passing no path.""" - with support.temp_dir() as temp_path: + with os_helper.temp_dir() as temp_path: self.assertTrue(os.path.isdir(temp_path)) self.assertFalse(os.path.isdir(temp_path)) def test_temp_dir__existing_dir__quiet_default(self): """Test passing a directory that already exists.""" def call_temp_dir(path): - with support.temp_dir(path) as temp_path: + with os_helper.temp_dir(path) as temp_path: raise Exception("should not get here") path = tempfile.mkdtemp() @@ -150,8 +154,8 @@ class TestSupport(unittest.TestCase): path = os.path.realpath(path) try: - with support.check_warnings() as recorder: - with support.temp_dir(path, quiet=True) as temp_path: + with warnings_helper.check_warnings() as recorder: + with os_helper.temp_dir(path, quiet=True) as temp_path: self.assertEqual(path, temp_path) warnings = [str(w.message) for w in recorder.warnings] # Make sure temp_dir did not delete the original directory. @@ -173,7 +177,8 @@ class TestSupport(unittest.TestCase): script_helper.assert_python_ok("-c", textwrap.dedent(""" import os from test import support - with support.temp_cwd() as temp_path: + from test.support import os_helper + with os_helper.temp_cwd() as temp_path: pid = os.fork() if pid != 0: # parent process @@ -194,8 +199,8 @@ class TestSupport(unittest.TestCase): def test_change_cwd(self): original_cwd = os.getcwd() - with support.temp_dir() as temp_path: - with support.change_cwd(temp_path) as new_cwd: + with os_helper.temp_dir() as temp_path: + with os_helper.change_cwd(temp_path) as new_cwd: self.assertEqual(new_cwd, temp_path) self.assertEqual(os.getcwd(), new_cwd) @@ -206,10 +211,10 @@ class TestSupport(unittest.TestCase): original_cwd = os.getcwd() def call_change_cwd(path): - with support.change_cwd(path) as new_cwd: + with os_helper.change_cwd(path) as new_cwd: raise Exception("should not get here") - with support.temp_dir() as parent_dir: + with os_helper.temp_dir() as parent_dir: non_existent_dir = os.path.join(parent_dir, 'does_not_exist') self.assertRaises(FileNotFoundError, call_change_cwd, non_existent_dir) @@ -220,10 +225,10 @@ class TestSupport(unittest.TestCase): """Test passing a non-existent directory with quiet=True.""" original_cwd = os.getcwd() - with support.temp_dir() as parent_dir: + with os_helper.temp_dir() as parent_dir: bad_dir = os.path.join(parent_dir, 'does_not_exist') - with support.check_warnings() as recorder: - with support.change_cwd(bad_dir, quiet=True) as new_cwd: + with warnings_helper.check_warnings() as recorder: + with os_helper.change_cwd(bad_dir, quiet=True) as new_cwd: self.assertEqual(new_cwd, original_cwd) self.assertEqual(os.getcwd(), new_cwd) warnings = [str(w.message) for w in recorder.warnings] @@ -240,8 +245,8 @@ class TestSupport(unittest.TestCase): def test_change_cwd__chdir_warning(self): """Check the warning message when os.chdir() fails.""" path = TESTFN + '_does_not_exist' - with support.check_warnings() as recorder: - with support.change_cwd(path=path, quiet=True): + with warnings_helper.check_warnings() as recorder: + with os_helper.change_cwd(path=path, quiet=True): pass messages = [str(w.message) for w in recorder.warnings] @@ -256,7 +261,7 @@ class TestSupport(unittest.TestCase): def test_temp_cwd(self): here = os.getcwd() - with support.temp_cwd(name=TESTFN): + with os_helper.temp_cwd(name=TESTFN): self.assertEqual(os.path.basename(os.getcwd()), TESTFN) self.assertFalse(os.path.exists(TESTFN)) self.assertEqual(os.getcwd(), here) @@ -265,7 +270,7 @@ class TestSupport(unittest.TestCase): def test_temp_cwd__name_none(self): """Test passing None to temp_cwd().""" original_cwd = os.getcwd() - with support.temp_cwd(name=None) as new_cwd: + with os_helper.temp_cwd(name=None) as new_cwd: self.assertNotEqual(new_cwd, original_cwd) self.assertTrue(os.path.isdir(new_cwd)) self.assertEqual(os.getcwd(), new_cwd) @@ -275,7 +280,7 @@ class TestSupport(unittest.TestCase): self.assertEqual(support.sortdict({3:3, 2:2, 1:1}), "{1: 1, 2: 2, 3: 3}") def test_make_bad_fd(self): - fd = support.make_bad_fd() + fd = os_helper.make_bad_fd() with self.assertRaises(OSError) as cm: os.write(fd, b"foo") self.assertEqual(cm.exception.errno, errno.EBADF) @@ -287,11 +292,11 @@ class TestSupport(unittest.TestCase): def test_CleanImport(self): import importlib - with support.CleanImport("asyncore"): + with import_helper.CleanImport("asyncore"): importlib.import_module("asyncore") def test_DirsOnSysPath(self): - with support.DirsOnSysPath('foo', 'bar'): + with import_helper.DirsOnSysPath('foo', 'bar'): self.assertIn("foo", sys.path) self.assertIn("bar", sys.path) self.assertNotIn("foo", sys.path) @@ -625,10 +630,10 @@ class TestSupport(unittest.TestCase): # We cannot test the absolute value of fd_count(): on old Linux # kernel or glibc versions, os.urandom() keeps a FD open on # /dev/urandom device and Python has 4 FD opens instead of 3. - start = support.fd_count() + start = os_helper.fd_count() fd = os.open(__file__, os.O_RDONLY) try: - more = support.fd_count() + more = os_helper.fd_count() finally: os.close(fd) self.assertEqual(more - start, 1) @@ -660,7 +665,6 @@ class TestSupport(unittest.TestCase): # findfile # check_warnings # EnvironmentVarGuard - # TransientResource # transient_internet # run_with_locale # set_memlimit diff --git a/Lib/test/test_symbol.py b/Lib/test/test_symbol.py deleted file mode 100644 index 645d8f43b6c..00000000000 --- a/Lib/test/test_symbol.py +++ /dev/null @@ -1,58 +0,0 @@ -import unittest -from test import support -import os -import sys -import sysconfig -import subprocess - - -SYMBOL_FILE = support.findfile('symbol.py') -GEN_SYMBOL_FILE = os.path.join(os.path.dirname(__file__), - '..', '..', 'Tools', 'scripts', - 'generate_symbol_py.py') -GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), - '..', '..', 'Include', 'graminit.h') -TEST_PY_FILE = 'symbol_test.py' - - -class TestSymbolGeneration(unittest.TestCase): - - def _copy_file_without_generated_symbols(self, source_file, dest_file): - with open(source_file) as fp: - lines = fp.readlines() - with open(dest_file, 'w') as fp: - fp.writelines(lines[:lines.index("#--start constants--\n") + 1]) - fp.writelines(lines[lines.index("#--end constants--\n"):]) - - def _generate_symbols(self, grammar_file, target_symbol_py_file): - proc = subprocess.Popen([sys.executable, - GEN_SYMBOL_FILE, - grammar_file, - target_symbol_py_file], stderr=subprocess.PIPE) - stderr = proc.communicate()[1] - return proc.returncode, stderr - - def compare_files(self, file1, file2): - with open(file1) as fp: - lines1 = fp.readlines() - with open(file2) as fp: - lines2 = fp.readlines() - self.assertEqual(lines1, lines2) - - @unittest.skipUnless(sysconfig.is_python_build(), - 'test only works from source build directory') - def test_real_grammar_and_symbol_file(self): - output = support.TESTFN - self.addCleanup(support.unlink, output) - - self._copy_file_without_generated_symbols(SYMBOL_FILE, output) - - exitcode, stderr = self._generate_symbols(GRAMMAR_FILE, output) - self.assertEqual(b'', stderr) - self.assertEqual(0, exitcode) - - self.compare_files(SYMBOL_FILE, output) - - -if __name__ == "__main__": - unittest.main() diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index 4df5535b005..4657fd1c0d8 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -63,6 +63,10 @@ SyntaxError: cannot assign to __debug__ Traceback (most recent call last): SyntaxError: cannot assign to function call +>>> yield = 1 +Traceback (most recent call last): +SyntaxError: assignment to yield expression not possible + >>> del f() Traceback (most recent call last): SyntaxError: cannot delete function call @@ -136,6 +140,18 @@ SyntaxError: cannot assign to operator Traceback (most recent call last): SyntaxError: cannot assign to conditional expression +>>> True = True = 3 +Traceback (most recent call last): +SyntaxError: cannot assign to True + +>>> x = y = True = z = 3 +Traceback (most recent call last): +SyntaxError: cannot assign to True + +>>> x = y = yield = 1 +Traceback (most recent call last): +SyntaxError: assignment to yield expression not possible + >>> a, b += 1, 2 Traceback (most recent call last): SyntaxError: 'tuple' is an illegal expression for augmented assignment @@ -148,6 +164,77 @@ SyntaxError: 'tuple' is an illegal expression for augmented assignment Traceback (most recent call last): SyntaxError: 'list' is an illegal expression for augmented assignment +Invalid targets in `for` loops and `with` statements should also +produce a specialized error message + +>>> for a() in b: pass +Traceback (most recent call last): +SyntaxError: cannot assign to function call + +>>> for (a, b()) in b: pass +Traceback (most recent call last): +SyntaxError: cannot assign to function call + +>>> for [a, b()] in b: pass +Traceback (most recent call last): +SyntaxError: cannot assign to function call + +>>> for (*a, b, c+1) in b: pass +Traceback (most recent call last): +SyntaxError: cannot assign to operator + +>>> for (x, *(y, z.d())) in b: pass +Traceback (most recent call last): +SyntaxError: cannot assign to function call + +>>> for a, b() in c: pass +Traceback (most recent call last): +SyntaxError: cannot assign to function call + +>>> for a, b, (c + 1, d()): pass +Traceback (most recent call last): +SyntaxError: cannot assign to operator + +>>> for i < (): pass +Traceback (most recent call last): +SyntaxError: invalid syntax + +>>> for a, b +Traceback (most recent call last): +SyntaxError: invalid syntax + +>>> with a as b(): pass +Traceback (most recent call last): +SyntaxError: cannot assign to function call + +>>> with a as (b, c()): pass +Traceback (most recent call last): +SyntaxError: cannot assign to function call + +>>> with a as [b, c()]: pass +Traceback (most recent call last): +SyntaxError: cannot assign to function call + +>>> with a as (*b, c, d+1): pass +Traceback (most recent call last): +SyntaxError: cannot assign to operator + +>>> with a as (x, *(y, z.d())): pass +Traceback (most recent call last): +SyntaxError: cannot assign to function call + +>>> with a as b, c as d(): pass +Traceback (most recent call last): +SyntaxError: cannot assign to function call + +>>> with a as b +Traceback (most recent call last): +SyntaxError: invalid syntax + +>>> p = p = +Traceback (most recent call last): +SyntaxError: invalid syntax + From compiler_complex_args(): >>> def f(None=1): @@ -155,7 +242,6 @@ From compiler_complex_args(): Traceback (most recent call last): SyntaxError: invalid syntax - From ast_for_arguments(): >>> def f(x, y=1, z): @@ -647,6 +733,19 @@ SyntaxError: trailing comma not allowed without surrounding parentheses Traceback (most recent call last): SyntaxError: trailing comma not allowed without surrounding parentheses +>>> (): int +Traceback (most recent call last): +SyntaxError: only single target (not tuple) can be annotated +>>> []: int +Traceback (most recent call last): +SyntaxError: only single target (not list) can be annotated +>>> (()): int +Traceback (most recent call last): +SyntaxError: only single target (not tuple) can be annotated +>>> ([]): int +Traceback (most recent call last): +SyntaxError: only single target (not list) can be annotated + Corner-cases that used to fail to raise the correct error: >>> def f(*, x=lambda __debug__:0): pass @@ -714,14 +813,13 @@ class SyntaxTestCase(unittest.TestCase): def test_assign_call(self): self._check_error("f() = 1", "assign") - @unittest.skipIf(support.use_old_parser(), "The old parser cannot generate these error messages") def test_assign_del(self): self._check_error("del (,)", "invalid syntax") self._check_error("del 1", "delete literal") self._check_error("del (1, 2)", "delete literal") self._check_error("del None", "delete None") self._check_error("del *x", "delete starred") - self._check_error("del (*x)", "delete starred") + self._check_error("del (*x)", "use starred expression") self._check_error("del (*x,)", "delete starred") self._check_error("del [*x,]", "delete starred") self._check_error("del f()", "delete function call") @@ -839,6 +937,20 @@ class SyntaxTestCase(unittest.TestCase): "iterable argument unpacking follows " "keyword argument unpacking") + def test_empty_line_after_linecont(self): + # See issue-40847 + s = r"""\ +pass + \ + +pass +""" + try: + compile(s, '', 'exec') + except SyntaxError: + self.fail("Empty line after a line continuation character is valid.") + + def test_main(): support.run_unittest(SyntaxTestCase) from test import test_syntax diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 33b34593a0a..aaba6630ff4 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1,5 +1,3 @@ -from test import support -from test.support.script_helper import assert_python_ok, assert_python_failure import builtins import codecs import gc @@ -11,6 +9,9 @@ import subprocess import sys import sysconfig import test.support +from test import support +from test.support.script_helper import assert_python_ok, assert_python_failure +from test.support import threading_helper import textwrap import unittest import warnings @@ -365,7 +366,7 @@ class SysModuleTest(unittest.TestCase): ) # sys._current_frames() is a CPython-only gimmick. - @test.support.reap_threads + @threading_helper.reap_threads def test_current_frames(self): import threading import traceback @@ -433,6 +434,11 @@ class SysModuleTest(unittest.TestCase): def test_attributes(self): self.assertIsInstance(sys.api_version, int) self.assertIsInstance(sys.argv, list) + for arg in sys.argv: + self.assertIsInstance(arg, str) + self.assertIsInstance(sys.orig_argv, list) + for arg in sys.orig_argv: + self.assertIsInstance(arg, str) self.assertIn(sys.byteorder, ("little", "big")) self.assertIsInstance(sys.builtin_module_names, tuple) self.assertIsInstance(sys.copyright, str) @@ -486,6 +492,7 @@ class SysModuleTest(unittest.TestCase): self.assertIsInstance(sys.platform, str) self.assertIsInstance(sys.prefix, str) self.assertIsInstance(sys.base_prefix, str) + self.assertIsInstance(sys.platlibdir, str) self.assertIsInstance(sys.version, str) vi = sys.version_info self.assertIsInstance(vi[:], tuple) @@ -928,6 +935,21 @@ class SysModuleTest(unittest.TestCase): out = out.decode('ascii', 'replace').rstrip() self.assertEqual(out, 'mbcs replace') + def test_orig_argv(self): + code = textwrap.dedent(''' + import sys + print(sys.argv) + print(sys.orig_argv) + ''') + args = [sys.executable, '-I', '-X', 'utf8', '-c', code, 'arg'] + proc = subprocess.run(args, check=True, capture_output=True, text=True) + expected = [ + repr(['-c', 'arg']), # sys.argv + repr(args), # sys.orig_argv + ] + self.assertEqual(proc.stdout.rstrip().splitlines(), expected, + proc) + @test.support.cpython_only class UnraisableHookTest(unittest.TestCase): diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py index 08b1fe24149..05fa441e20c 100644 --- a/Lib/test/test_sysconfig.py +++ b/Lib/test/test_sysconfig.py @@ -5,9 +5,11 @@ import subprocess import shutil from copy import copy -from test.support import (import_module, TESTFN, unlink, check_warnings, - captured_stdout, skip_unless_symlink, change_cwd, - PythonSymlink) +from test.support import (captured_stdout, PythonSymlink) +from test.support.import_helper import import_module +from test.support.os_helper import (TESTFN, unlink, skip_unless_symlink, + change_cwd) +from test.support.warnings_helper import check_warnings import sysconfig from sysconfig import (get_paths, get_platform, get_config_vars, diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index be66f1f89e6..d60d35b5be0 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -2305,7 +2305,8 @@ class CommandLineTest(unittest.TestCase): def test_test_command_verbose(self): for tar_name in testtarnames: for opt in '-v', '--verbose': - out = self.tarfilecmd(opt, '-t', tar_name) + out = self.tarfilecmd(opt, '-t', tar_name, + PYTHONIOENCODING='utf-8') self.assertIn(b'is a tar archive.\n', out) def test_test_command_invalid_file(self): @@ -2376,7 +2377,8 @@ class CommandLineTest(unittest.TestCase): 'and-utf8-bom-sig-only.txt')] for opt in '-v', '--verbose': try: - out = self.tarfilecmd(opt, '-c', tmpname, *files) + out = self.tarfilecmd(opt, '-c', tmpname, *files, + PYTHONIOENCODING='utf-8') self.assertIn(b' file created.', out) with tarfile.open(tmpname) as tar: tar.getmembers() @@ -2434,7 +2436,8 @@ class CommandLineTest(unittest.TestCase): for opt in '-v', '--verbose': try: with support.temp_cwd(tarextdir): - out = self.tarfilecmd(opt, '-e', tmpname) + out = self.tarfilecmd(opt, '-e', tmpname, + PYTHONIOENCODING='utf-8') self.assertIn(b' file is extracted.', out) finally: support.rmtree(tarextdir) diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py index 1c5b9cf2bd2..db982dac8d6 100644 --- a/Lib/test/test_tcl.py +++ b/Lib/test/test_tcl.py @@ -5,9 +5,10 @@ import sys import os import warnings from test import support +from test.support import import_helper # Skip this test if the _tkinter module wasn't built. -_tkinter = support.import_module('_tkinter') +_tkinter = import_helper.import_module('_tkinter') import tkinter from tkinter import Tcl diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index fcc706ede5a..8ace883d74b 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -15,7 +15,9 @@ from unittest import mock import unittest from test import support +from test.support import os_helper from test.support import script_helper +from test.support import warnings_helper has_textmode = (tempfile._text_openflags != tempfile._bin_openflags) @@ -69,7 +71,7 @@ class BaseTestCase(unittest.TestCase): b_check = re.compile(br"^[a-z0-9_-]{8}$") def setUp(self): - self._warnings_manager = support.check_warnings() + self._warnings_manager = warnings_helper.check_warnings() self._warnings_manager.__enter__() warnings.filterwarnings("ignore", category=RuntimeWarning, message="mktemp", module=__name__) @@ -224,7 +226,7 @@ class TestCandidateTempdirList(BaseTestCase): # _candidate_tempdir_list contains the expected directories # Make sure the interesting environment variables are all set. - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: for envname in 'TMPDIR', 'TEMP', 'TMP': dirname = os.getenv(envname) if not dirname: @@ -310,7 +312,7 @@ def _inside_empty_temp_dir(): with support.swap_attr(tempfile, 'tempdir', dir): yield finally: - support.rmtree(dir) + os_helper.rmtree(dir) def _mock_candidate_names(*names): @@ -594,13 +596,13 @@ class TestGetTempDir(BaseTestCase): case_sensitive_tempdir = tempfile.mkdtemp("-Temp") _tempdir, tempfile.tempdir = tempfile.tempdir, None try: - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: # Fake the first env var which is checked as a candidate env["TMPDIR"] = case_sensitive_tempdir self.assertEqual(tempfile.gettempdir(), case_sensitive_tempdir) finally: tempfile.tempdir = _tempdir - support.rmdir(case_sensitive_tempdir) + os_helper.rmdir(case_sensitive_tempdir) class TestMkstemp(BaseTestCase): @@ -950,7 +952,7 @@ class TestNamedTemporaryFile(BaseTestCase): def test_bad_mode(self): dir = tempfile.mkdtemp() - self.addCleanup(support.rmtree, dir) + self.addCleanup(os_helper.rmtree, dir) with self.assertRaises(ValueError): tempfile.NamedTemporaryFile(mode='wr', dir=dir) with self.assertRaises(TypeError): @@ -1351,7 +1353,7 @@ class TestTemporaryDirectory(BaseTestCase): finally: os.rmdir(dir) - @support.skip_unless_symlink + @os_helper.skip_unless_symlink def test_cleanup_with_symlink_to_a_directory(self): # cleanup() should not follow symlinks to directories (issue #12464) d1 = self.do_create() @@ -1448,7 +1450,9 @@ class TestTemporaryDirectory(BaseTestCase): name = d.name # Check for the resource warning - with support.check_warnings(('Implicitly', ResourceWarning), quiet=False): + with warnings_helper.check_warnings(('Implicitly', + ResourceWarning), + quiet=False): warnings.filterwarnings("always", category=ResourceWarning) del d support.gc_collect() diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py index 77e46f2c2f1..62b57fa3388 100644 --- a/Lib/test/test_thread.py +++ b/Lib/test/test_thread.py @@ -2,6 +2,7 @@ import os import unittest import random from test import support +from test.support import threading_helper import _thread as thread import time import weakref @@ -32,8 +33,8 @@ class BasicThreadTest(unittest.TestCase): self.running = 0 self.next_ident = 0 - key = support.threading_setup() - self.addCleanup(support.threading_cleanup, *key) + key = threading_helper.threading_setup() + self.addCleanup(threading_helper.threading_cleanup, *key) class ThreadRunningTests(BasicThreadTest): @@ -58,7 +59,7 @@ class ThreadRunningTests(BasicThreadTest): self.done_mutex.release() def test_starting_threads(self): - with support.wait_threads_exit(): + with threading_helper.wait_threads_exit(): # Basic test for thread creation. for i in range(NUMTASKS): self.newtask() @@ -94,7 +95,7 @@ class ThreadRunningTests(BasicThreadTest): verbose_print("trying stack_size = (%d)" % tss) self.next_ident = 0 self.created = 0 - with support.wait_threads_exit(): + with threading_helper.wait_threads_exit(): for i in range(NUMTASKS): self.newtask() @@ -116,7 +117,7 @@ class ThreadRunningTests(BasicThreadTest): mut.acquire() mut.release() - with support.wait_threads_exit(): + with threading_helper.wait_threads_exit(): thread.start_new_thread(task, ()) while not started: time.sleep(POLL_SLEEP) @@ -140,7 +141,7 @@ class ThreadRunningTests(BasicThreadTest): started = thread.allocate_lock() with support.catch_unraisable_exception() as cm: - with support.wait_threads_exit(): + with threading_helper.wait_threads_exit(): started.acquire() thread.start_new_thread(task, ()) started.acquire() @@ -180,7 +181,7 @@ class Barrier: class BarrierTest(BasicThreadTest): def test_barrier(self): - with support.wait_threads_exit(): + with threading_helper.wait_threads_exit(): self.bar = Barrier(NUMTASKS) self.running = NUMTASKS for i in range(NUMTASKS): @@ -223,7 +224,7 @@ class TestForkInThread(unittest.TestCase): self.read_fd, self.write_fd = os.pipe() @unittest.skipUnless(hasattr(os, 'fork'), 'need os.fork') - @support.reap_threads + @threading_helper.reap_threads def test_forkinthread(self): pid = None @@ -243,7 +244,7 @@ class TestForkInThread(unittest.TestCase): finally: os._exit(0) - with support.wait_threads_exit(): + with threading_helper.wait_threads_exit(): thread.start_new_thread(fork_thread, (self.read_fd, self.write_fd)) self.assertEqual(os.read(self.read_fd, 2), b"OK") os.close(self.write_fd) diff --git a/Lib/test/test_threadedtempfile.py b/Lib/test/test_threadedtempfile.py index e1d7a10179c..fe63c9e9143 100644 --- a/Lib/test/test_threadedtempfile.py +++ b/Lib/test/test_threadedtempfile.py @@ -15,7 +15,7 @@ provoking a 2.0 failure under Linux. import tempfile -from test.support import start_threads +from test.support import threading_helper import unittest import io import threading @@ -50,7 +50,7 @@ class TempFileGreedy(threading.Thread): class ThreadedTempFileTest(unittest.TestCase): def test_main(self): threads = [TempFileGreedy() for i in range(NUM_THREADS)] - with start_threads(threads, startEvent.set): + with threading_helper.start_threads(threads, startEvent.set): pass ok = sum(t.ok_count for t in threads) errors = [str(t.name) + str(t.errors.getvalue()) diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 81e5f70d6d6..ad82e304e32 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -3,6 +3,7 @@ Tests for the threading module. """ import test.support +from test.support import threading_helper from test.support import verbose, import_module, cpython_only from test.support.script_helper import assert_python_ok, assert_python_failure @@ -75,10 +76,10 @@ class TestThread(threading.Thread): class BaseTestCase(unittest.TestCase): def setUp(self): - self._threads = test.support.threading_setup() + self._threads = threading_helper.threading_setup() def tearDown(self): - test.support.threading_cleanup(*self._threads) + threading_helper.threading_cleanup(*self._threads) test.support.reap_children() @@ -130,7 +131,7 @@ class ThreadTests(BaseTestCase): done.set() done = threading.Event() ident = [] - with support.wait_threads_exit(): + with threading_helper.wait_threads_exit(): tid = _thread.start_new_thread(f, ()) done.wait() self.assertEqual(ident[0], tid) @@ -171,7 +172,7 @@ class ThreadTests(BaseTestCase): mutex = threading.Lock() mutex.acquire() - with support.wait_threads_exit(): + with threading_helper.wait_threads_exit(): tid = _thread.start_new_thread(f, (mutex,)) # Wait for the thread to finish. mutex.acquire() diff --git a/Lib/test/test_threading_local.py b/Lib/test/test_threading_local.py index 2fd14ae2e16..9862094eacc 100644 --- a/Lib/test/test_threading_local.py +++ b/Lib/test/test_threading_local.py @@ -2,6 +2,7 @@ import sys import unittest from doctest import DocTestSuite from test import support +from test.support import threading_helper import weakref import gc @@ -65,8 +66,8 @@ class BaseLocalTest: # Simply check that the variable is correctly set self.assertEqual(local.x, i) - with support.start_threads(threading.Thread(target=f, args=(i,)) - for i in range(10)): + with threading_helper.start_threads(threading.Thread(target=f, args=(i,)) + for i in range(10)): pass def test_derived_cycle_dealloc(self): diff --git a/Lib/test/test_threadsignals.py b/Lib/test/test_threadsignals.py index eeacd3698cb..15e8078e936 100644 --- a/Lib/test/test_threadsignals.py +++ b/Lib/test/test_threadsignals.py @@ -5,6 +5,7 @@ import signal import os import sys from test import support +from test.support import threading_helper import _thread as thread import time @@ -39,7 +40,7 @@ def send_signals(): class ThreadSignals(unittest.TestCase): def test_signals(self): - with support.wait_threads_exit(): + with threading_helper.wait_threads_exit(): # Test signal handling semantics of threads. # We spawn a thread, have the thread send two signals, and # wait for it to finish. Check that we got both signals @@ -129,7 +130,7 @@ class ThreadSignals(unittest.TestCase): def other_thread(): rlock.acquire() - with support.wait_threads_exit(): + with threading_helper.wait_threads_exit(): thread.start_new_thread(other_thread, ()) # Wait until we can't acquire it without blocking... while rlock.acquire(blocking=False): @@ -165,7 +166,7 @@ class ThreadSignals(unittest.TestCase): time.sleep(0.5) lock.release() - with support.wait_threads_exit(): + with threading_helper.wait_threads_exit(): thread.start_new_thread(other_thread, ()) # Wait until we can't acquire it without blocking... while lock.acquire(blocking=False): @@ -212,7 +213,7 @@ class ThreadSignals(unittest.TestCase): os.kill(process_pid, signal.SIGUSR1) done.release() - with support.wait_threads_exit(): + with threading_helper.wait_threads_exit(): # Send the signals from the non-main thread, since the main thread # is the only one that can process signals. thread.start_new_thread(send_signals, ()) diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index 80e43fafad8..6ced0470d07 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -1,4 +1,5 @@ from test import support +from test.support import warnings_helper import decimal import enum import locale @@ -247,7 +248,7 @@ class TimeTestCase(unittest.TestCase): # not change output based on its value and no test for year # because systems vary in their support for year 0. expected = "2000 01 01 00 00 00 1 001" - with support.check_warnings(): + with warnings_helper.check_warnings(): result = time.strftime("%Y %m %d %H %M %S %w %j", (2000,)+(0,)*8) self.assertEqual(expected, result) diff --git a/Lib/test/test_tix.py b/Lib/test/test_tix.py index e6ea3d07444..e6d759e7bd3 100644 --- a/Lib/test/test_tix.py +++ b/Lib/test/test_tix.py @@ -1,9 +1,10 @@ import unittest from test import support +from test.support import import_helper import sys # Skip this test if the _tkinter module wasn't built. -_tkinter = support.import_module('_tkinter') +_tkinter = import_helper.import_module('_tkinter') # Skip test if tk cannot be initialized. support.requires('gui') diff --git a/Lib/test/test_tk.py b/Lib/test/test_tk.py index 48cefd92e12..59842a5e25e 100644 --- a/Lib/test/test_tk.py +++ b/Lib/test/test_tk.py @@ -1,6 +1,7 @@ from test import support +from test.support import import_helper # Skip test if _tkinter wasn't built. -support.import_module('_tkinter') +import_helper.import_module('_tkinter') # Skip test if tk cannot be initialized. support.requires('gui') diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py index 4c90092893a..6de7aa87bb2 100644 --- a/Lib/test/test_tokenize.py +++ b/Lib/test/test_tokenize.py @@ -1605,7 +1605,7 @@ class TestRoundtrip(TestCase): import glob, random fn = support.findfile("tokenize_tests.txt") tempdir = os.path.dirname(fn) or os.curdir - testfiles = glob.glob(os.path.join(tempdir, "test*.py")) + testfiles = glob.glob(os.path.join(glob.escape(tempdir), "test*.py")) # Tokenize is broken on test_pep3131.py because regular expressions are # broken on the obscure unicode identifiers in it. *sigh* diff --git a/Lib/test/test_tools/__init__.py b/Lib/test/test_tools/__init__.py index eb9acad677d..61af6578e09 100644 --- a/Lib/test/test_tools/__init__.py +++ b/Lib/test/test_tools/__init__.py @@ -4,6 +4,7 @@ import importlib import os.path import unittest from test import support +from test.support import import_helper basepath = os.path.normpath( os.path.dirname( # @@ -26,11 +27,11 @@ def skip_if_missing(tool=None): @contextlib.contextmanager def imports_under_tool(name, *subdirs): tooldir = os.path.join(toolsdir, name, *subdirs) - with support.DirsOnSysPath(tooldir) as cm: + with import_helper.DirsOnSysPath(tooldir) as cm: yield cm def import_tool(toolname): - with support.DirsOnSysPath(scriptsdir): + with import_helper.DirsOnSysPath(scriptsdir): return importlib.import_module(toolname) def load_tests(*args): diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py index 8b419307340..03ed29d3f97 100644 --- a/Lib/test/test_tools/test_pathfix.py +++ b/Lib/test/test_tools/test_pathfix.py @@ -30,16 +30,18 @@ class TestPathfixFunctional(unittest.TestCase): with open(filename, 'w', encoding='utf8') as f: f.write(f'{shebang}\n' + 'print("Hello world")\n') + encoding = sys.getfilesystemencoding() proc = subprocess.run( [sys.executable, self.script, *pathfix_flags, '-n', pathfix_arg], - capture_output=True, text=1) + env={**os.environ, 'PYTHONIOENCODING': encoding}, + capture_output=True) if stdout == '' and proc.returncode == 0: stdout = f'{filename}: updating\n' self.assertEqual(proc.returncode, exitcode, proc) - self.assertEqual(proc.stdout, stdout, proc) - self.assertEqual(proc.stderr, stderr, proc) + self.assertEqual(proc.stdout.decode(encoding), stdout.replace('\n', os.linesep), proc) + self.assertEqual(proc.stderr.decode(encoding), stderr.replace('\n', os.linesep), proc) with open(filename, 'r', encoding='utf8') as f: output = f.read() diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py index 7cda546b8b9..c03982ba72b 100644 --- a/Lib/test/test_trace.py +++ b/Lib/test/test_trace.py @@ -1,6 +1,6 @@ import os import sys -from test.support import TESTFN, rmtree, unlink, captured_stdout +from test.support import TESTFN, TESTFN_UNICODE, FS_NONASCII, rmtree, unlink, captured_stdout from test.support.script_helper import assert_python_ok, assert_python_failure import textwrap import unittest @@ -428,9 +428,10 @@ class TestCoverageCommandLineOutput(unittest.TestCase): coverfile = 'tmp.cover' def setUp(self): - with open(self.codefile, 'w') as f: + with open(self.codefile, 'w', encoding='iso-8859-15') as f: f.write(textwrap.dedent('''\ - x = 42 + # coding: iso-8859-15 + x = 'spÅ“m' if []: print('unreachable') ''')) @@ -451,9 +452,10 @@ class TestCoverageCommandLineOutput(unittest.TestCase): self.assertEqual(stderr, b'') self.assertFalse(os.path.exists(tracecoverpath)) self.assertTrue(os.path.exists(self.coverfile)) - with open(self.coverfile) as f: + with open(self.coverfile, encoding='iso-8859-15') as f: self.assertEqual(f.read(), - " 1: x = 42\n" + " # coding: iso-8859-15\n" + " 1: x = 'spÅ“m'\n" " 1: if []:\n" " print('unreachable')\n" ) @@ -462,9 +464,10 @@ class TestCoverageCommandLineOutput(unittest.TestCase): argv = '-m trace --count --missing'.split() + [self.codefile] status, stdout, stderr = assert_python_ok(*argv) self.assertTrue(os.path.exists(self.coverfile)) - with open(self.coverfile) as f: + with open(self.coverfile, encoding='iso-8859-15') as f: self.assertEqual(f.read(), textwrap.dedent('''\ - 1: x = 42 + # coding: iso-8859-15 + 1: x = 'spÅ“m' 1: if []: >>>>>> print('unreachable') ''')) @@ -485,26 +488,33 @@ class TestCommandLine(unittest.TestCase): self.assertIn(message, stderr) def test_listfuncs_flag_success(self): - with open(TESTFN, 'w') as fd: - self.addCleanup(unlink, TESTFN) + filename = TESTFN + '.py' + modulename = os.path.basename(TESTFN) + with open(filename, 'w', encoding='utf-8') as fd: + self.addCleanup(unlink, filename) fd.write("a = 1\n") - status, stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN) + status, stdout, stderr = assert_python_ok('-m', 'trace', '-l', filename, + PYTHONIOENCODING='utf-8') self.assertIn(b'functions called:', stdout) + expected = f'filename: {filename}, modulename: {modulename}, funcname: ' + self.assertIn(expected.encode(), stdout) def test_sys_argv_list(self): - with open(TESTFN, 'w') as fd: + with open(TESTFN, 'w', encoding='utf-8') as fd: self.addCleanup(unlink, TESTFN) fd.write("import sys\n") fd.write("print(type(sys.argv))\n") status, direct_stdout, stderr = assert_python_ok(TESTFN) - status, trace_stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN) + status, trace_stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN, + PYTHONIOENCODING='utf-8') self.assertIn(direct_stdout.strip(), trace_stdout) def test_count_and_summary(self): filename = f'{TESTFN}.py' coverfilename = f'{TESTFN}.cover' - with open(filename, 'w') as fd: + modulename = os.path.basename(TESTFN) + with open(filename, 'w', encoding='utf-8') as fd: self.addCleanup(unlink, filename) self.addCleanup(unlink, coverfilename) fd.write(textwrap.dedent("""\ @@ -517,11 +527,12 @@ class TestCommandLine(unittest.TestCase): for i in range(10): f() """)) - status, stdout, _ = assert_python_ok('-m', 'trace', '-cs', filename) + status, stdout, _ = assert_python_ok('-m', 'trace', '-cs', filename, + PYTHONIOENCODING='utf-8') stdout = stdout.decode() self.assertEqual(status, 0) self.assertIn('lines cov% module (path)', stdout) - self.assertIn(f'6 100% {TESTFN} ({filename})', stdout) + self.assertIn(f'6 100% {modulename} ({filename})', stdout) def test_run_as_module(self): assert_python_ok('-m', 'trace', '-l', '--module', 'timeit', '-n', '1') diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index f9a5f2fc53e..c5fbd8700ae 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -7,7 +7,8 @@ import sys import unittest import re from test import support -from test.support import TESTFN, Error, captured_output, unlink, cpython_only, ALWAYS_EQ +from test.support import Error, captured_output, cpython_only, ALWAYS_EQ +from test.support.os_helper import TESTFN, unlink from test.support.script_helper import assert_python_ok import textwrap @@ -655,7 +656,6 @@ class BaseExceptionReportingTests: self.assertIn('inner_raise() # Marker', blocks[2]) self.check_zero_div(blocks[2]) - @unittest.skipIf(support.use_old_parser(), "Pegen is arguably better here, so no need to fix this") def test_syntax_error_offset_at_eol(self): # See #10186. def e(): diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index f429e883b59..398add05a12 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1417,8 +1417,6 @@ class GenericTests(BaseTestCase): def test_generic_errors(self): T = TypeVar('T') S = TypeVar('S') - with self.assertRaises(TypeError): - Generic[T]() with self.assertRaises(TypeError): Generic[T][T] with self.assertRaises(TypeError): diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 2ee4e64d635..afc95555db0 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -15,6 +15,8 @@ import textwrap import unicodedata import unittest import warnings +from test.support import import_helper +from test.support import warnings_helper from test import support, string_tests from test.support.script_helper import assert_python_failure @@ -504,7 +506,7 @@ class UnicodeTest(string_tests.CommonTest, self.assertIs(text.replace(pattern, pattern), text) def test_bytes_comparison(self): - with support.check_warnings(): + with warnings_helper.check_warnings(): warnings.simplefilter('ignore', BytesWarning) self.assertEqual('abc' == b'abc', False) self.assertEqual('abc' != b'abc', True) @@ -725,7 +727,9 @@ class UnicodeTest(string_tests.CommonTest, import _testcapi u = 'ð–€ð–“ð–Žð–ˆð–”ð–‰ð–Š' self.assertTrue(u.isidentifier()) - self.assertTrue(_testcapi.unicode_legacy_string(u).isidentifier()) + with warnings_helper.check_warnings(): + warnings.simplefilter('ignore', DeprecationWarning) + self.assertTrue(_testcapi.unicode_legacy_string(u).isidentifier()) def test_isprintable(self): self.assertTrue("".isprintable()) @@ -2215,22 +2219,6 @@ class UnicodeTest(string_tests.CommonTest, self.assertEqual(("abc" "def" "ghi"), "abcdefghi") self.assertEqual(("abc" "def" "ghi"), "abcdefghi") - def test_printing(self): - class BitBucket: - def write(self, text): - pass - - out = BitBucket() - print('abc', file=out) - print('abc', 'def', file=out) - print('abc', 'def', file=out) - print('abc', 'def', file=out) - print('abc\n', file=out) - print('abc\n', end=' ', file=out) - print('abc\n', end=' ', file=out) - print('def\n', file=out) - print('def\n', file=out) - def test_ucs4(self): x = '\U00100000' y = x.encode("raw-unicode-escape").decode("raw-unicode-escape") @@ -2521,7 +2509,7 @@ class CAPITest(unittest.TestCase): # Test PyUnicode_FromFormat() def test_from_format(self): - support.import_module('ctypes') + import_helper.import_module('ctypes') from ctypes import ( pythonapi, py_object, sizeof, c_int, c_long, c_longlong, c_ssize_t, @@ -2762,7 +2750,7 @@ class CAPITest(unittest.TestCase): @support.cpython_only def test_aswidechar(self): from _testcapi import unicode_aswidechar - support.import_module('ctypes') + import_helper.import_module('ctypes') from ctypes import c_wchar, sizeof wchar, size = unicode_aswidechar('abcdef', 2) @@ -2800,7 +2788,7 @@ class CAPITest(unittest.TestCase): @support.cpython_only def test_aswidecharstring(self): from _testcapi import unicode_aswidecharstring - support.import_module('ctypes') + import_helper.import_module('ctypes') from ctypes import c_wchar, sizeof wchar, size = unicode_aswidecharstring('abc') diff --git a/Lib/test/test_unicode_file.py b/Lib/test/test_unicode_file.py index b16e4c5b3bd..e3979491879 100644 --- a/Lib/test/test_unicode_file.py +++ b/Lib/test/test_unicode_file.py @@ -2,15 +2,18 @@ # We don't test many operations on files other than # that their names can be used with Unicode characters. import os, glob, time, shutil +import sys import unicodedata import unittest -from test.support import (run_unittest, rmtree, change_cwd, - TESTFN_ENCODING, TESTFN_UNICODE, TESTFN_UNENCODABLE, create_empty_file) +from test.support import run_unittest +from test.support.os_helper import (rmtree, change_cwd, TESTFN_UNICODE, + TESTFN_UNENCODABLE, create_empty_file) + if not os.path.supports_unicode_filenames: try: - TESTFN_UNICODE.encode(TESTFN_ENCODING) + TESTFN_UNICODE.encode(sys.getfilesystemencoding()) except (UnicodeError, TypeError): # Either the file system encoding is None, or the file name # cannot be encoded in the file system encoding. @@ -40,7 +43,7 @@ class TestUnicodeFiles(unittest.TestCase): self._do_copyish(filename, filename) # Filename should appear in glob output self.assertTrue( - os.path.abspath(filename)==os.path.abspath(glob.glob(filename)[0])) + os.path.abspath(filename)==os.path.abspath(glob.glob(glob.escape(filename))[0])) # basename should appear in listdir. path, base = os.path.split(os.path.abspath(filename)) file_list = os.listdir(path) diff --git a/Lib/test/test_univnewlines.py b/Lib/test/test_univnewlines.py index fd07539fb60..b9054918780 100644 --- a/Lib/test/test_univnewlines.py +++ b/Lib/test/test_univnewlines.py @@ -5,6 +5,8 @@ import unittest import os import sys from test import support +from test.support import os_helper + if not hasattr(sys.stdin, 'newlines'): raise unittest.SkipTest( @@ -46,29 +48,29 @@ class TestGenericUnivNewlines: data = self.DATA if "b" in self.WRITEMODE: data = data.encode("ascii") - with self.open(support.TESTFN, self.WRITEMODE) as fp: + with self.open(os_helper.TESTFN, self.WRITEMODE) as fp: fp.write(data) def tearDown(self): try: - os.unlink(support.TESTFN) + os.unlink(os_helper.TESTFN) except: pass def test_read(self): - with self.open(support.TESTFN, self.READMODE) as fp: + with self.open(os_helper.TESTFN, self.READMODE) as fp: data = fp.read() self.assertEqual(data, DATA_LF) self.assertEqual(repr(fp.newlines), repr(self.NEWLINE)) def test_readlines(self): - with self.open(support.TESTFN, self.READMODE) as fp: + with self.open(os_helper.TESTFN, self.READMODE) as fp: data = fp.readlines() self.assertEqual(data, DATA_SPLIT) self.assertEqual(repr(fp.newlines), repr(self.NEWLINE)) def test_readline(self): - with self.open(support.TESTFN, self.READMODE) as fp: + with self.open(os_helper.TESTFN, self.READMODE) as fp: data = [] d = fp.readline() while d: @@ -78,7 +80,7 @@ class TestGenericUnivNewlines: self.assertEqual(repr(fp.newlines), repr(self.NEWLINE)) def test_seek(self): - with self.open(support.TESTFN, self.READMODE) as fp: + with self.open(os_helper.TESTFN, self.READMODE) as fp: fp.readline() pos = fp.tell() data = fp.readlines() @@ -105,7 +107,7 @@ class TestCRLFNewlines(TestGenericUnivNewlines): DATA = DATA_CRLF def test_tell(self): - with self.open(support.TESTFN, self.READMODE) as fp: + with self.open(os_helper.TESTFN, self.READMODE) as fp: self.assertEqual(repr(fp.newlines), repr(None)) data = fp.readline() pos = fp.tell() diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index ebeb9a00145..f41fa2a9506 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -9,6 +9,8 @@ import io import unittest from unittest.mock import patch from test import support +from test.support import os_helper +from test.support import warnings_helper import os try: import ssl @@ -50,7 +52,7 @@ def urlopen(url, data=None, proxies=None): def FancyURLopener(): - with support.check_warnings( + with warnings_helper.check_warnings( ('FancyURLopener style of invoking requests is deprecated.', DeprecationWarning)): return urllib.request.FancyURLopener() @@ -145,18 +147,19 @@ class urlopen_FileTests(unittest.TestCase): # Create a temp file to use for testing self.text = bytes("test_urllib: %s\n" % self.__class__.__name__, "ascii") - f = open(support.TESTFN, 'wb') + f = open(os_helper.TESTFN, 'wb') try: f.write(self.text) finally: f.close() - self.pathname = support.TESTFN - self.returned_obj = urlopen("file:%s" % self.pathname) + self.pathname = os_helper.TESTFN + self.quoted_pathname = urllib.parse.quote(self.pathname) + self.returned_obj = urlopen("file:%s" % self.quoted_pathname) def tearDown(self): """Shut down the open object""" self.returned_obj.close() - os.remove(support.TESTFN) + os.remove(os_helper.TESTFN) def test_interface(self): # Make sure object returned by urlopen() has the specified methods @@ -198,7 +201,7 @@ class urlopen_FileTests(unittest.TestCase): self.assertIsInstance(self.returned_obj.headers, email.message.Message) def test_url(self): - self.assertEqual(self.returned_obj.url, self.pathname) + self.assertEqual(self.returned_obj.url, self.quoted_pathname) def test_status(self): self.assertIsNone(self.returned_obj.status) @@ -207,7 +210,7 @@ class urlopen_FileTests(unittest.TestCase): self.assertIsInstance(self.returned_obj.info(), email.message.Message) def test_geturl(self): - self.assertEqual(self.returned_obj.geturl(), self.pathname) + self.assertEqual(self.returned_obj.geturl(), self.quoted_pathname) def test_getcode(self): self.assertIsNone(self.returned_obj.getcode()) @@ -229,7 +232,7 @@ class ProxyTests(unittest.TestCase): def setUp(self): # Records changes to env vars - self.env = support.EnvironmentVarGuard() + self.env = os_helper.EnvironmentVarGuard() # Delete all proxy related env vars for k in list(os.environ): if 'proxy' in k.lower(): @@ -591,13 +594,13 @@ Connection: close self.unfakehttp() def test_URLopener_deprecation(self): - with support.check_warnings(('',DeprecationWarning)): + with warnings_helper.check_warnings(('',DeprecationWarning)): urllib.request.URLopener() @unittest.skipUnless(ssl, "ssl module required") def test_cafile_and_context(self): context = ssl.create_default_context() - with support.check_warnings(('', DeprecationWarning)): + with warnings_helper.check_warnings(('', DeprecationWarning)): with self.assertRaises(ValueError): urllib.request.urlopen( "https://localhost", cafile="/nonexistent/path", context=context @@ -698,10 +701,10 @@ class urlretrieve_FileTests(unittest.TestCase): self.tempFiles = [] # Create a temporary file. - self.registerFileForCleanUp(support.TESTFN) + self.registerFileForCleanUp(os_helper.TESTFN) self.text = b'testing urllib.urlretrieve' try: - FILE = open(support.TESTFN, 'wb') + FILE = open(os_helper.TESTFN, 'wb') FILE.write(self.text) FILE.close() finally: @@ -744,18 +747,18 @@ class urlretrieve_FileTests(unittest.TestCase): def test_basic(self): # Make sure that a local file just gets its own location returned and # a headers value is returned. - result = urllib.request.urlretrieve("file:%s" % support.TESTFN) - self.assertEqual(result[0], support.TESTFN) + result = urllib.request.urlretrieve("file:%s" % os_helper.TESTFN) + self.assertEqual(result[0], os_helper.TESTFN) self.assertIsInstance(result[1], email.message.Message, "did not get an email.message.Message instance " "as second returned value") def test_copy(self): # Test that setting the filename argument works. - second_temp = "%s.2" % support.TESTFN + second_temp = "%s.2" % os_helper.TESTFN self.registerFileForCleanUp(second_temp) result = urllib.request.urlretrieve(self.constructLocalFileUrl( - support.TESTFN), second_temp) + os_helper.TESTFN), second_temp) self.assertEqual(second_temp, result[0]) self.assertTrue(os.path.exists(second_temp), "copy of the file was not " "made") @@ -776,10 +779,10 @@ class urlretrieve_FileTests(unittest.TestCase): self.assertIsInstance(file_size, int) self.assertEqual(block_count, count_holder[0]) count_holder[0] = count_holder[0] + 1 - second_temp = "%s.2" % support.TESTFN + second_temp = "%s.2" % os_helper.TESTFN self.registerFileForCleanUp(second_temp) urllib.request.urlretrieve( - self.constructLocalFileUrl(support.TESTFN), + self.constructLocalFileUrl(os_helper.TESTFN), second_temp, hooktester) def test_reporthook_0_bytes(self): @@ -789,7 +792,7 @@ class urlretrieve_FileTests(unittest.TestCase): _report.append((block_count, block_read_size, file_size)) srcFileName = self.createNewTempFile() urllib.request.urlretrieve(self.constructLocalFileUrl(srcFileName), - support.TESTFN, hooktester) + os_helper.TESTFN, hooktester) self.assertEqual(len(report), 1) self.assertEqual(report[0][2], 0) @@ -802,7 +805,7 @@ class urlretrieve_FileTests(unittest.TestCase): _report.append((block_count, block_read_size, file_size)) srcFileName = self.createNewTempFile(b"x" * 5) urllib.request.urlretrieve(self.constructLocalFileUrl(srcFileName), - support.TESTFN, hooktester) + os_helper.TESTFN, hooktester) self.assertEqual(len(report), 2) self.assertEqual(report[0][2], 5) self.assertEqual(report[1][2], 5) @@ -816,7 +819,7 @@ class urlretrieve_FileTests(unittest.TestCase): _report.append((block_count, block_read_size, file_size)) srcFileName = self.createNewTempFile(b"x" * 8193) urllib.request.urlretrieve(self.constructLocalFileUrl(srcFileName), - support.TESTFN, hooktester) + os_helper.TESTFN, hooktester) self.assertEqual(len(report), 3) self.assertEqual(report[0][2], 8193) self.assertEqual(report[0][1], 8192) @@ -1555,7 +1558,7 @@ class URLopener_Tests(FakeHTTPMixin, unittest.TestCase): class DummyURLopener(urllib.request.URLopener): def open_spam(self, url): return url - with support.check_warnings( + with warnings_helper.check_warnings( ('DummyURLopener style of invoking requests is deprecated.', DeprecationWarning)): self.assertEqual(DummyURLopener().open( @@ -1566,9 +1569,9 @@ class URLopener_Tests(FakeHTTPMixin, unittest.TestCase): "spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/"), "//c:|windows%/:=&?~#+!$,;'@()*[]|/path/") - @support.ignore_warnings(category=DeprecationWarning) + @warnings_helper.ignore_warnings(category=DeprecationWarning) def test_urlopener_retrieve_file(self): - with support.temp_dir() as tmpdir: + with os_helper.temp_dir() as tmpdir: fd, tmpfile = tempfile.mkstemp(dir=tmpdir) os.close(fd) fileurl = "file:" + urllib.request.pathname2url(tmpfile) @@ -1576,7 +1579,7 @@ class URLopener_Tests(FakeHTTPMixin, unittest.TestCase): # Some buildbots have TEMP folder that uses a lowercase drive letter. self.assertEqual(os.path.normcase(filename), os.path.normcase(tmpfile)) - @support.ignore_warnings(category=DeprecationWarning) + @warnings_helper.ignore_warnings(category=DeprecationWarning) def test_urlopener_retrieve_remote(self): url = "http://www.python.org/file.txt" self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello!") @@ -1584,7 +1587,7 @@ class URLopener_Tests(FakeHTTPMixin, unittest.TestCase): filename, _ = urllib.request.URLopener().retrieve(url) self.assertEqual(os.path.splitext(filename)[1], ".txt") - @support.ignore_warnings(category=DeprecationWarning) + @warnings_helper.ignore_warnings(category=DeprecationWarning) def test_local_file_open(self): # bpo-35907, CVE-2019-9948: urllib must reject local_file:// scheme class DummyURLopener(urllib.request.URLopener): diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py index ed426b05a71..e568cc45755 100644 --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -10,6 +10,7 @@ import hashlib from test import support from test.support import hashlib_helper +from test.support import threading_helper try: import ssl @@ -666,11 +667,11 @@ def setUpModule(): # Store the threading_setup in a key and ensure that it is cleaned up # in the tearDown global threads_key - threads_key = support.threading_setup() + threads_key = threading_helper.threading_setup() def tearDownModule(): if threads_key: - support.threading_cleanup(*threads_key) + threading_helper.threading_cleanup(*threads_key) if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py index ba4c500e8ec..cb74685715d 100644 --- a/Lib/test/test_urllib2net.py +++ b/Lib/test/test_urllib2net.py @@ -1,3 +1,4 @@ +import errno import unittest from test import support from test.support import socket_helper @@ -39,6 +40,39 @@ _urlopen_with_retry = _wrap_with_retry_thrice(urllib.request.urlopen, urllib.error.URLError) +class TransientResource(object): + + """Raise ResourceDenied if an exception is raised while the context manager + is in effect that matches the specified exception and attributes.""" + + def __init__(self, exc, **kwargs): + self.exc = exc + self.attrs = kwargs + + def __enter__(self): + return self + + def __exit__(self, type_=None, value=None, traceback=None): + """If type_ is a subclass of self.exc and value has attributes matching + self.attrs, raise ResourceDenied. Otherwise let the exception + propagate (if any).""" + if type_ is not None and issubclass(self.exc, type_): + for attr, attr_value in self.attrs.items(): + if not hasattr(value, attr): + break + if getattr(value, attr) != attr_value: + break + else: + raise ResourceDenied("an optional resource is not available") + +# Context managers that raise ResourceDenied when various issues +# with the Internet connection manifest themselves as exceptions. +# XXX deprecate these and use transient_internet() instead +time_out = TransientResource(OSError, errno=errno.ETIMEDOUT) +socket_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET) +ioerror_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET) + + class AuthTests(unittest.TestCase): """Tests urllib2 authentication features.""" @@ -237,9 +271,9 @@ class OtherNetworkTests(unittest.TestCase): raise else: try: - with support.time_out, \ - support.socket_peer_reset, \ - support.ioerror_peer_reset: + with time_out, \ + socket_peer_reset, \ + ioerror_peer_reset: buf = f.read() debug("read %d bytes" % len(buf)) except socket.timeout: diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py index c8709f7a0d6..753b31eef0d 100644 --- a/Lib/test/test_uu.py +++ b/Lib/test/test_uu.py @@ -4,7 +4,7 @@ Nick Mathewson """ import unittest -from test import support +from test.support import os_helper import os import stat @@ -174,10 +174,11 @@ class UUStdIOTest(unittest.TestCase): class UUFileTest(unittest.TestCase): def setUp(self): - self.tmpin = support.TESTFN + "i" - self.tmpout = support.TESTFN + "o" - self.addCleanup(support.unlink, self.tmpin) - self.addCleanup(support.unlink, self.tmpout) + # uu.encode() supports only ASCII file names + self.tmpin = os_helper.TESTFN_ASCII + "i" + self.tmpout = os_helper.TESTFN_ASCII + "o" + self.addCleanup(os_helper.unlink, self.tmpin) + self.addCleanup(os_helper.unlink, self.tmpout) def test_encode(self): with open(self.tmpin, 'wb') as fin: diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index b1c92427dd2..718113d6e1b 100644 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -1,5 +1,6 @@ import unittest from test import support +from test.support import import_helper import builtins import contextlib import copy @@ -10,8 +11,8 @@ import sys import weakref from unittest import mock -py_uuid = support.import_fresh_module('uuid', blocked=['_uuid']) -c_uuid = support.import_fresh_module('uuid', fresh=['_uuid']) +py_uuid = import_helper.import_fresh_module('uuid', blocked=['_uuid']) +c_uuid = import_helper.import_fresh_module('uuid', fresh=['_uuid']) def importable(name): try: diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 44c62193bf7..ca003d55d7c 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -16,7 +16,8 @@ import sys import tempfile from test.support import (captured_stdout, captured_stderr, requires_zlib, can_symlink, EnvironmentVarGuard, rmtree, - import_module) + import_module, + skip_if_broken_multiprocessing_synchronize) import unittest import venv from unittest.mock import patch @@ -79,8 +80,8 @@ class BaseTest(unittest.TestCase): def get_env_file(self, *args): return os.path.join(self.env_dir, *args) - def get_text_file_contents(self, *args): - with open(self.get_env_file(*args), 'r') as f: + def get_text_file_contents(self, *args, encoding='utf-8'): + with open(self.get_env_file(*args), 'r', encoding=encoding) as f: result = f.read() return result @@ -357,10 +358,11 @@ class BasicTest(BaseTest): """ Test that the multiprocessing is able to spawn. """ - # Issue bpo-36342: Instantiation of a Pool object imports the + # bpo-36342: Instantiation of a Pool object imports the # multiprocessing.synchronize module. Skip the test if this module # cannot be imported. - import_module('multiprocessing.synchronize') + skip_if_broken_multiprocessing_synchronize() + rmtree(self.env_dir) self.run_with_capture(venv.create, self.env_dir) envpy = os.path.join(os.path.realpath(self.env_dir), @@ -513,7 +515,7 @@ class EnsurePipTest(BaseTest): # executing pip with sudo, you may want sudo's -H flag." # where $HOME is replaced by the HOME environment variable. err = re.sub("^(WARNING: )?The directory .* or its parent directory " - "is not owned by the current user .*$", "", + "is not owned or is not writable by the current user.*$", "", err, flags=re.MULTILINE) self.assertEqual(err.rstrip(), "") # Being fairly specific regarding the expected behaviour for the diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 268ecb03f4d..dcc0ea89b5a 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -940,8 +940,8 @@ class PyWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase): """)) def run(*args): - res = assert_python_ok(*args) - stderr = res.err.decode('ascii', 'replace') + res = assert_python_ok(*args, PYTHONIOENCODING='utf-8') + stderr = res.err.decode('utf-8', 'replace') stderr = '\n'.join(stderr.splitlines()) # normalize newlines @@ -1198,13 +1198,13 @@ class EnvironmentVariableTests(BaseTest): @unittest.skipUnless(sys.getfilesystemencoding() != 'ascii', 'requires non-ascii filesystemencoding') def test_nonascii(self): + PYTHONWARNINGS="ignore:DeprecationWarning" + support.FS_NONASCII rc, stdout, stderr = assert_python_ok("-c", "import sys; sys.stdout.write(str(sys.warnoptions))", PYTHONIOENCODING="utf-8", - PYTHONWARNINGS="ignore:DeprecaciónWarning", + PYTHONWARNINGS=PYTHONWARNINGS, PYTHONDEVMODE="") - self.assertEqual(stdout, - "['ignore:DeprecaciónWarning']".encode('utf-8')) + self.assertEqual(stdout, str([PYTHONWARNINGS]).encode()) class CEnvironmentVariableTests(EnvironmentVariableTests, unittest.TestCase): module = c_warnings diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py index 5c25ec8f7ec..487abcd8d95 100644 --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -4,11 +4,12 @@ import os, sys, errno import unittest from test import support +from test.support import import_helper import threading from platform import machine, win32_edition # Do this first so test will be skipped if module doesn't exist -support.import_module('winreg', required_on=['win']) +import_helper.import_module('winreg', required_on=['win']) # Now import everything from winreg import * diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py index 4bf5d39e619..93ca6b99a92 100644 --- a/Lib/test/test_wsgiref.py +++ b/Lib/test/test_wsgiref.py @@ -1,6 +1,7 @@ from unittest import mock from test import support from test.support import socket_helper +from test.support import warnings_helper from test.test_httpservers import NoLogRequestHandler from unittest import TestCase from wsgiref.util import setup_testing_defaults @@ -339,7 +340,7 @@ class UtilityTests(TestCase): util.setup_testing_defaults(kw) self.assertEqual(util.request_uri(kw,query),uri) - @support.ignore_warnings(category=DeprecationWarning) + @warnings_helper.ignore_warnings(category=DeprecationWarning) def checkFW(self,text,size,match): def make_it(text=text,size=size): diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index d01649d1c31..63f9b92a83d 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -24,7 +24,12 @@ import weakref from functools import partial from itertools import product, islice from test import support -from test.support import TESTFN, findfile, import_fresh_module, gc_collect, swap_attr +from test.support import os_helper +from test.support import warnings_helper +from test.support import findfile, gc_collect, swap_attr +from test.support.import_helper import import_fresh_module +from test.support.os_helper import TESTFN + # pyET is the pure-Python implementation. # @@ -601,7 +606,7 @@ class ElementTreeTest(unittest.TestCase): self.assertFalse(f.closed) self.assertEqual(str(cm.exception), "unknown event 'bogus'") - with support.check_no_resource_warning(self): + with warnings_helper.check_no_resource_warning(self): with self.assertRaises(ValueError) as cm: iterparse(SIMPLE_XMLFILE, events) self.assertEqual(str(cm.exception), "unknown event 'bogus'") @@ -627,13 +632,13 @@ class ElementTreeTest(unittest.TestCase): self.assertEqual(str(cm.exception), 'junk after document element: line 1, column 12') - self.addCleanup(support.unlink, TESTFN) + self.addCleanup(os_helper.unlink, TESTFN) with open(TESTFN, "wb") as f: f.write(b"junk") it = iterparse(TESTFN) action, elem = next(it) self.assertEqual((action, elem.tag), ('end', 'document')) - with support.check_no_resource_warning(self): + with warnings_helper.check_no_resource_warning(self): with self.assertRaises(ET.ParseError) as cm: next(it) self.assertEqual(str(cm.exception), @@ -3641,14 +3646,14 @@ class IOTest(unittest.TestCase): "" % enc).encode(enc)) def test_write_to_filename(self): - self.addCleanup(support.unlink, TESTFN) + self.addCleanup(os_helper.unlink, TESTFN) tree = ET.ElementTree(ET.XML('''''')) tree.write(TESTFN) with open(TESTFN, 'rb') as f: self.assertEqual(f.read(), b'''''') def test_write_to_text_file(self): - self.addCleanup(support.unlink, TESTFN) + self.addCleanup(os_helper.unlink, TESTFN) tree = ET.ElementTree(ET.XML('''''')) with open(TESTFN, 'w', encoding='utf-8') as f: tree.write(f, encoding='unicode') @@ -3657,7 +3662,7 @@ class IOTest(unittest.TestCase): self.assertEqual(f.read(), b'''''') def test_write_to_binary_file(self): - self.addCleanup(support.unlink, TESTFN) + self.addCleanup(os_helper.unlink, TESTFN) tree = ET.ElementTree(ET.XML('''''')) with open(TESTFN, 'wb') as f: tree.write(f) @@ -3666,7 +3671,7 @@ class IOTest(unittest.TestCase): self.assertEqual(f.read(), b'''''') def test_write_to_binary_file_with_bom(self): - self.addCleanup(support.unlink, TESTFN) + self.addCleanup(os_helper.unlink, TESTFN) tree = ET.ElementTree(ET.XML('''''')) # test BOM writing to buffered file with open(TESTFN, 'wb') as f: diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index 7437e13d061..e26e1714a54 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -8,6 +8,9 @@ import unittest cET = import_fresh_module('xml.etree.ElementTree', fresh=['_elementtree']) +cET_alias = import_fresh_module('xml.etree.cElementTree', + fresh=['_elementtree', 'xml.etree'], + deprecated=True) @unittest.skipUnless(cET, 'requires _elementtree') @@ -167,6 +170,14 @@ class MiscTests(unittest.TestCase): support.gc_collect() +@unittest.skipUnless(cET, 'requires _elementtree') +class TestAliasWorking(unittest.TestCase): + # Test that the cET alias module is alive + def test_alias_working(self): + e = cET_alias.Element('foo') + self.assertEqual(e.tag, 'foo') + + @unittest.skipUnless(cET, 'requires _elementtree') @support.cpython_only class TestAcceleratorImported(unittest.TestCase): @@ -175,6 +186,9 @@ class TestAcceleratorImported(unittest.TestCase): # SubElement is a function so it retains _elementtree as its module. self.assertEqual(cET.SubElement.__module__, '_elementtree') + def test_correct_import_cET_alias(self): + self.assertEqual(cET_alias.SubElement.__module__, '_elementtree') + def test_parser_comes_from_C(self): # The type of methods defined in Python code is types.FunctionType, # while the type of methods defined inside _elementtree is @@ -214,6 +228,7 @@ def test_main(): # Run the tests specific to the C implementation support.run_unittest( MiscTests, + TestAliasWorking, TestAcceleratorImported, SizeofTest, ) diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index f68af527eae..3dfa84bf77d 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -15,7 +15,9 @@ import re import io import contextlib from test import support +from test.support import os_helper from test.support import socket_helper +from test.support import threading_helper from test.support import ALWAYS_EQ, LARGEST, SMALLEST try: @@ -1371,7 +1373,7 @@ class CGIHandlerTestCase(unittest.TestCase): self.cgi = None def test_cgi_get(self): - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['REQUEST_METHOD'] = 'GET' # if the method is GET and no request_text is given, it runs handle_get # get sysout output @@ -1403,7 +1405,7 @@ class CGIHandlerTestCase(unittest.TestCase): """ - with support.EnvironmentVarGuard() as env, \ + with os_helper.EnvironmentVarGuard() as env, \ captured_stdout(encoding=self.cgi.encoding) as data_out, \ support.captured_stdin() as data_in: data_in.write(data) @@ -1464,7 +1466,7 @@ class UseBuiltinTypesTestCase(unittest.TestCase): self.assertTrue(server.use_builtin_types) -@support.reap_threads +@threading_helper.reap_threads def test_main(): support.run_unittest(XMLRPCTestCase, HelperTestCase, DateTimeTestCase, BinaryTestCase, FaultTestCase, UseBuiltinTypesTestCase, diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index c9ca1ddaafe..2851051425b 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -19,9 +19,10 @@ from tempfile import TemporaryFile from random import randint, random, randbytes from test.support import script_helper -from test.support import (TESTFN, findfile, unlink, rmtree, temp_dir, temp_cwd, - requires_zlib, requires_bz2, requires_lzma, - captured_stdout) +from test.support import (findfile, requires_zlib, requires_bz2, + requires_lzma, captured_stdout) +from test.support.os_helper import TESTFN, unlink, rmtree, temp_dir, temp_cwd + TESTFN2 = TESTFN + "2" TESTFNDIR = TESTFN + "d" @@ -1600,6 +1601,11 @@ class OtherTests(unittest.TestCase): self.assertEqual(zf.filelist[0].filename, "foo.txt") self.assertEqual(zf.filelist[1].filename, "\xf6.txt") + def test_read_after_write_unicode_filenames(self): + with zipfile.ZipFile(TESTFN2, 'w') as zipfp: + zipfp.writestr('приклад', b'sample') + self.assertEqual(zipfp.read('приклад'), b'sample') + def test_exclusive_create_zip_file(self): """Test exclusive creating a new zipfile.""" unlink(TESTFN2) diff --git a/Lib/test/test_zipimport_support.py b/Lib/test/test_zipimport_support.py index 88561017503..7bf50a33728 100644 --- a/Lib/test/test_zipimport_support.py +++ b/Lib/test/test_zipimport_support.py @@ -13,6 +13,7 @@ import doctest import inspect import linecache import unittest +from test.support import os_helper from test.support.script_helper import (spawn_python, kill_python, assert_python_ok, make_script, make_zip_script) @@ -77,7 +78,7 @@ class ZipSupportTests(unittest.TestCase): def test_inspect_getsource_issue4223(self): test_src = "def foo(): pass\n" - with test.support.temp_dir() as d: + with os_helper.temp_dir() as d: init_name = make_script(d, '__init__', test_src) name_in_zip = os.path.join('zip_pkg', os.path.basename(init_name)) @@ -117,7 +118,7 @@ class ZipSupportTests(unittest.TestCase): mod_name = mod_name.replace("sample_", "sample_zipped_") sample_sources[mod_name] = src - with test.support.temp_dir() as d: + with os_helper.temp_dir() as d: script_name = make_script(d, 'test_zipped_doctest', test_src) zip_name, run_name = make_zip_script(d, 'test_zip', @@ -192,7 +193,7 @@ class ZipSupportTests(unittest.TestCase): doctest.testmod() """) pattern = 'File "%s", line 2, in %s' - with test.support.temp_dir() as d: + with os_helper.temp_dir() as d: script_name = make_script(d, 'script', test_src) rc, out, err = assert_python_ok(script_name) expected = pattern % (script_name, "__main__.Test") @@ -219,7 +220,7 @@ class ZipSupportTests(unittest.TestCase): import pdb pdb.Pdb(nosigint=True).runcall(f) """) - with test.support.temp_dir() as d: + with os_helper.temp_dir() as d: script_name = make_script(d, 'script', test_src) p = spawn_python(script_name) p.stdin.write(b'l\n') diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index 02509cdf553..7f30cac64f7 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -1,5 +1,6 @@ import unittest from test import support +from test.support import import_helper import binascii import copy import pickle @@ -7,7 +8,8 @@ import random import sys from test.support import bigmemtest, _1G, _4G -zlib = support.import_module('zlib') + +zlib = import_helper.import_module('zlib') requires_Compress_copy = unittest.skipUnless( hasattr(zlib.compressobj(), "copy"), diff --git a/Lib/test/test_zoneinfo/test_zoneinfo.py b/Lib/test/test_zoneinfo/test_zoneinfo.py index fe2c380c514..1f1fa60f1ff 100644 --- a/Lib/test/test_zoneinfo/test_zoneinfo.py +++ b/Lib/test/test_zoneinfo/test_zoneinfo.py @@ -19,12 +19,7 @@ from datetime import date, datetime, time, timedelta, timezone from functools import cached_property from . import _support as test_support -from ._support import ( - OS_ENV_LOCK, - TZPATH_LOCK, - TZPATH_TEST_LOCK, - ZoneInfoTestBase, -) +from ._support import OS_ENV_LOCK, TZPATH_TEST_LOCK, ZoneInfoTestBase py_zoneinfo, c_zoneinfo = test_support.get_modules() @@ -365,7 +360,6 @@ class ZoneInfoTest(TzPathUserMixin, ZoneInfoTestBase): self.assertEqual(dt.dst(), offset.dst, dt) def test_folds_from_utc(self): - tests = [] for key in self.zones(): zi = self.zone_from_key(key) with self.subTest(key=key): @@ -927,7 +921,7 @@ class TZStrTest(ZoneInfoTestBase): # the Version 2+ file. In this case, we have no transitions, just # the tzstr in the footer, so up to the footer, the files are # identical and we can just write the same file twice in a row. - for i in range(2): + for _ in range(2): out += b"TZif" # Magic value out += b"3" # Version out += b" " * 15 # Reserved @@ -952,7 +946,6 @@ class TZStrTest(ZoneInfoTestBase): return self.klass.from_file(zonefile, key=tzstr) def test_tzstr_localized(self): - i = 0 for tzstr, cases in self.test_cases.items(): with self.subTest(tzstr=tzstr): zi = self.zone_from_tzstr(tzstr) diff --git a/Lib/trace.py b/Lib/trace.py index 52047c3fbf4..c505d8bc72a 100755 --- a/Lib/trace.py +++ b/Lib/trace.py @@ -287,8 +287,9 @@ class CoverageResults: if self.outfile: # try and store counts and module info into self.outfile try: - pickle.dump((self.counts, self.calledfuncs, self.callers), - open(self.outfile, 'wb'), 1) + with open(self.outfile, 'wb') as f: + pickle.dump((self.counts, self.calledfuncs, self.callers), + f, 1) except OSError as err: print("Can't save counts files because %s" % err, file=sys.stderr) @@ -715,7 +716,7 @@ def main(): sys.argv = [opts.progname, *opts.arguments] sys.path[0] = os.path.dirname(opts.progname) - with open(opts.progname) as fp: + with open(opts.progname, 'rb') as fp: code = compile(fp.read(), opts.progname, 'exec') # try to emulate __main__ namespace as much as possible globs = { diff --git a/Lib/typing.py b/Lib/typing.py index f94996daebd..fd657caafee 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -894,16 +894,6 @@ class Generic: __slots__ = () _is_protocol = False - def __new__(cls, *args, **kwds): - if cls in (Generic, Protocol): - raise TypeError(f"Type {cls.__name__} cannot be instantiated; " - "it can be used only as a base class") - if super().__new__ is object.__new__ and cls.__init__ is not object.__init__: - obj = super().__new__(cls) - else: - obj = super().__new__(cls, *args, **kwds) - return obj - @_tp_cache def __class_getitem__(cls, params): if not isinstance(params, tuple): diff --git a/Lib/unittest/_log.py b/Lib/unittest/_log.py index 94e7e758bd9..961c448a7fb 100644 --- a/Lib/unittest/_log.py +++ b/Lib/unittest/_log.py @@ -26,11 +26,11 @@ class _CapturingHandler(logging.Handler): class _AssertLogsContext(_BaseTestCaseContext): - """A context manager used to implement TestCase.assertLogs().""" + """A context manager for assertLogs() and assertNoLogs() """ LOGGING_FORMAT = "%(levelname)s:%(name)s:%(message)s" - def __init__(self, test_case, logger_name, level): + def __init__(self, test_case, logger_name, level, no_logs): _BaseTestCaseContext.__init__(self, test_case) self.logger_name = logger_name if level: @@ -38,6 +38,7 @@ class _AssertLogsContext(_BaseTestCaseContext): else: self.level = logging.INFO self.msg = None + self.no_logs = no_logs def __enter__(self): if isinstance(self.logger_name, logging.Logger): @@ -54,16 +55,31 @@ class _AssertLogsContext(_BaseTestCaseContext): logger.handlers = [handler] logger.setLevel(self.level) logger.propagate = False + if self.no_logs: + return return handler.watcher def __exit__(self, exc_type, exc_value, tb): self.logger.handlers = self.old_handlers self.logger.propagate = self.old_propagate self.logger.setLevel(self.old_level) + if exc_type is not None: # let unexpected exceptions pass through return False - if len(self.watcher.records) == 0: - self._raiseFailure( - "no logs of level {} or higher triggered on {}" - .format(logging.getLevelName(self.level), self.logger.name)) + + if self.no_logs: + # assertNoLogs + if len(self.watcher.records) > 0: + self._raiseFailure( + "Unexpected logs found: {!r}".format( + self.watcher.output + ) + ) + + else: + # assertLogs + if len(self.watcher.records) == 0: + self._raiseFailure( + "no logs of level {} or higher triggered on {}" + .format(logging.getLevelName(self.level), self.logger.name)) diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index f8bc865ee82..872f1211275 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -252,7 +252,7 @@ class _AssertWarnsContext(_AssertRaisesBaseContext): def __enter__(self): # The __warningregistry__'s need to be in a pristine state for tests # to work properly. - for v in sys.modules.values(): + for v in list(sys.modules.values()): if getattr(v, '__warningregistry__', None): v.__warningregistry__ = {} self.warnings_manager = warnings.catch_warnings(record=True) @@ -295,7 +295,6 @@ class _AssertWarnsContext(_AssertRaisesBaseContext): self._raiseFailure("{} not triggered".format(exc_name)) - class _OrderedChainMap(collections.ChainMap): def __iter__(self): seen = set() @@ -788,7 +787,16 @@ class TestCase(object): """ # Lazy import to avoid importing logging if it is not needed. from ._log import _AssertLogsContext - return _AssertLogsContext(self, logger, level) + return _AssertLogsContext(self, logger, level, no_logs=False) + + def assertNoLogs(self, logger=None, level=None): + """ Fail unless no log messages of level *level* or higher are emitted + on *logger_name* or its children. + + This method must be used as a context manager. + """ + from ._log import _AssertLogsContext + return _AssertLogsContext(self, logger, level, no_logs=True) def _getAssertEqualityFunc(self, first, second): """Get a detailed comparison function for the types of the two args. diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index f855c4dc00b..0e416967a30 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -8,6 +8,7 @@ import logging import warnings import weakref import inspect +import types from copy import deepcopy from test import support @@ -1350,6 +1351,20 @@ test case pass self.assertRaises(TypeError, self.assertWarnsRegex, MyWarn, lambda: True) + def testAssertWarnsModifySysModules(self): + # bpo-29620: handle modified sys.modules during iteration + class Foo(types.ModuleType): + @property + def __warningregistry__(self): + sys.modules['@bar@'] = 'bar' + + sys.modules['@foo@'] = Foo('foo') + try: + self.assertWarns(UserWarning, warnings.warn, 'expected') + finally: + del sys.modules['@foo@'] + del sys.modules['@bar@'] + def testAssertRaisesRegexMismatch(self): def Stub(): raise Exception('Unexpected') @@ -1666,6 +1681,81 @@ test case with self.assertLogs('foo'): log_quux.error("1") + def testAssertLogsUnexpectedException(self): + # Check unexpected exception will go through. + with self.assertRaises(ZeroDivisionError): + with self.assertLogs(): + raise ZeroDivisionError("Unexpected") + + def testAssertNoLogsDefault(self): + with self.assertRaises(self.failureException) as cm: + with self.assertNoLogs(): + log_foo.info("1") + log_foobar.debug("2") + self.assertEqual( + str(cm.exception), + "Unexpected logs found: ['INFO:foo:1']", + ) + + def testAssertNoLogsFailureFoundLogs(self): + with self.assertRaises(self.failureException) as cm: + with self.assertNoLogs(): + log_quux.error("1") + log_foo.error("foo") + + self.assertEqual( + str(cm.exception), + "Unexpected logs found: ['ERROR:quux:1', 'ERROR:foo:foo']", + ) + + def testAssertNoLogsPerLogger(self): + with self.assertNoStderr(): + with self.assertLogs(log_quux): + with self.assertNoLogs(logger=log_foo): + log_quux.error("1") + + def testAssertNoLogsFailurePerLogger(self): + # Failure due to unexpected logs for the given logger or its + # children. + with self.assertRaises(self.failureException) as cm: + with self.assertLogs(log_quux): + with self.assertNoLogs(logger=log_foo): + log_quux.error("1") + log_foobar.info("2") + self.assertEqual( + str(cm.exception), + "Unexpected logs found: ['INFO:foo.bar:2']", + ) + + def testAssertNoLogsPerLevel(self): + # Check per-level filtering + with self.assertNoStderr(): + with self.assertNoLogs(level="ERROR"): + log_foo.info("foo") + log_quux.debug("1") + + def testAssertNoLogsFailurePerLevel(self): + # Failure due to unexpected logs at the specified level. + with self.assertRaises(self.failureException) as cm: + with self.assertNoLogs(level="DEBUG"): + log_foo.debug("foo") + log_quux.debug("1") + self.assertEqual( + str(cm.exception), + "Unexpected logs found: ['DEBUG:foo:foo', 'DEBUG:quux:1']", + ) + + def testAssertNoLogsUnexpectedException(self): + # Check unexpected exception will go through. + with self.assertRaises(ZeroDivisionError): + with self.assertNoLogs(): + raise ZeroDivisionError("Unexpected") + + def testAssertNoLogsYieldsNone(self): + with self.assertNoLogs() as value: + pass + self.assertIsNone(value) + def testDeprecatedMethodNames(self): """ Test that the deprecated methods raise a DeprecationWarning. See #9424. diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py index 9c73bcfb44a..cea91308ce1 100755 --- a/Lib/webbrowser.py +++ b/Lib/webbrowser.py @@ -413,7 +413,7 @@ class Grail(BaseBrowser): tempdir = os.path.join(tempfile.gettempdir(), ".grail-unix") user = pwd.getpwuid(os.getuid())[0] - filename = os.path.join(tempdir, user + "-*") + filename = os.path.join(glob.escape(tempdir), glob.escape(user) + "-*") maybes = glob.glob(filename) if not maybes: return None @@ -545,12 +545,12 @@ def register_standard_browsers(): register(browser, None, BackgroundBrowser(browser)) else: # Prefer X browsers if present - if os.environ.get("DISPLAY"): + if os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY"): try: cmd = "xdg-settings get default-web-browser".split() raw_result = subprocess.check_output(cmd, stderr=subprocess.DEVNULL) result = raw_result.decode().strip() - except (FileNotFoundError, subprocess.CalledProcessError): + except (FileNotFoundError, subprocess.CalledProcessError, PermissionError) : pass else: global _os_preferred_browser diff --git a/Lib/xml/etree/cElementTree.py b/Lib/xml/etree/cElementTree.py new file mode 100644 index 00000000000..368e6791895 --- /dev/null +++ b/Lib/xml/etree/cElementTree.py @@ -0,0 +1,3 @@ +# Deprecated alias for xml.etree.ElementTree + +from xml.etree.ElementTree import * diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 8903d6a42ee..915698f9e05 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -1534,7 +1534,7 @@ class ZipFile: # strong encryption raise NotImplementedError("strong encryption (flag bit 6)") - if zinfo.flag_bits & 0x800: + if fheader[_FH_GENERAL_PURPOSE_FLAG_BITS] & 0x800: # UTF-8 filename fname_str = fname.decode("utf-8") else: diff --git a/Lib/zipimport.py b/Lib/zipimport.py index 5ef0a17c2a5..080e0c4d986 100644 --- a/Lib/zipimport.py +++ b/Lib/zipimport.py @@ -280,11 +280,8 @@ class zipimporter: return None except ZipImportError: return None - if not _ZipImportResourceReader._registered: - from importlib.abc import ResourceReader - ResourceReader.register(_ZipImportResourceReader) - _ZipImportResourceReader._registered = True - return _ZipImportResourceReader(self, fullname) + from importlib.readers import ZipReader + return ZipReader(self, fullname) def __repr__(self): @@ -719,74 +716,3 @@ def _get_module_code(self, fullname): return code, ispackage, modpath else: raise ZipImportError(f"can't find module {fullname!r}", name=fullname) - - -class _ZipImportResourceReader: - """Private class used to support ZipImport.get_resource_reader(). - - This class is allowed to reference all the innards and private parts of - the zipimporter. - """ - _registered = False - - def __init__(self, zipimporter, fullname): - self.zipimporter = zipimporter - self.fullname = fullname - - def open_resource(self, resource): - fullname_as_path = self.fullname.replace('.', '/') - path = f'{fullname_as_path}/{resource}' - from io import BytesIO - try: - return BytesIO(self.zipimporter.get_data(path)) - except OSError: - raise FileNotFoundError(path) - - def resource_path(self, resource): - # All resources are in the zip file, so there is no path to the file. - # Raising FileNotFoundError tells the higher level API to extract the - # binary data and create a temporary file. - raise FileNotFoundError - - def is_resource(self, name): - # Maybe we could do better, but if we can get the data, it's a - # resource. Otherwise it isn't. - fullname_as_path = self.fullname.replace('.', '/') - path = f'{fullname_as_path}/{name}' - try: - self.zipimporter.get_data(path) - except OSError: - return False - return True - - def contents(self): - # This is a bit convoluted, because fullname will be a module path, - # but _files is a list of file names relative to the top of the - # archive's namespace. We want to compare file paths to find all the - # names of things inside the module represented by fullname. So we - # turn the module path of fullname into a file path relative to the - # top of the archive, and then we iterate through _files looking for - # names inside that "directory". - from pathlib import Path - fullname_path = Path(self.zipimporter.get_filename(self.fullname)) - relative_path = fullname_path.relative_to(self.zipimporter.archive) - # Don't forget that fullname names a package, so its path will include - # __init__.py, which we want to ignore. - assert relative_path.name == '__init__.py' - package_path = relative_path.parent - subdirs_seen = set() - for filename in self.zipimporter._files: - try: - relative = Path(filename).relative_to(package_path) - except ValueError: - continue - # If the path of the file (which is relative to the top of the zip - # namespace), relative to the package given when the resource - # reader was created, has a parent, then it's a name in a - # subdirectory and thus we skip it. - parent_name = relative.parent.name - if len(parent_name) == 0: - yield relative.name - elif parent_name not in subdirs_seen: - subdirs_seen.add(parent_name) - yield parent_name diff --git a/Lib/zoneinfo/_common.py b/Lib/zoneinfo/_common.py index 3d35d4f4b46..4c24f01bd7b 100644 --- a/Lib/zoneinfo/_common.py +++ b/Lib/zoneinfo/_common.py @@ -80,7 +80,6 @@ def load_data(fobj): # not by position in the array but by position in the unsplit # abbreviation string. I suppose this makes more sense in C, which uses # null to terminate the strings, but it's inconvenient here... - char_total = 0 abbr_vals = {} abbr_chars = fobj.read(charcnt) @@ -137,8 +136,7 @@ class _TZifHeader: ] def __init__(self, *args): - assert len(self.__slots__) == len(args) - for attr, val in zip(self.__slots__, args): + for attr, val in zip(self.__slots__, args, strict=True): setattr(self, attr, val) @classmethod diff --git a/Lib/zoneinfo/_tzpath.py b/Lib/zoneinfo/_tzpath.py index 9e381b6e443..9513611c177 100644 --- a/Lib/zoneinfo/_tzpath.py +++ b/Lib/zoneinfo/_tzpath.py @@ -12,7 +12,8 @@ def reset_tzpath(to=None): f"tzpaths must be a list or tuple, " + f"not {type(tzpaths)}: {tzpaths!r}" ) - elif not all(map(os.path.isabs, tzpaths)): + + if not all(map(os.path.isabs, tzpaths)): raise ValueError(_get_invalid_paths_message(tzpaths)) base_tzpath = tzpaths else: diff --git a/Lib/zoneinfo/_zoneinfo.py b/Lib/zoneinfo/_zoneinfo.py index b207dd346fe..9810637d3ef 100644 --- a/Lib/zoneinfo/_zoneinfo.py +++ b/Lib/zoneinfo/_zoneinfo.py @@ -4,7 +4,7 @@ import collections import functools import re import weakref -from datetime import datetime, timedelta, timezone, tzinfo +from datetime import datetime, timedelta, tzinfo from . import _common, _tzpath @@ -742,7 +742,7 @@ def _parse_tz_delta(tz_delta): if not -86400 < total < 86400: raise ValueError( - "Offset must be strictly between -24h and +24h:" + tz_delta + f"Offset must be strictly between -24h and +24h: {tz_delta}" ) # Yes, +5 maps to an offset of -5h diff --git a/Mac/BuildScript/README.rst b/Mac/BuildScript/README.rst index f8b25fa5af1..94a6bb28cad 100644 --- a/Mac/BuildScript/README.rst +++ b/Mac/BuildScript/README.rst @@ -7,216 +7,84 @@ framework-based Python out-of-tree, installs it in a funny place with $DESTROOT, massages that installation to remove .pyc files and such, creates an Installer package from the installation plus other files in ``resources`` and ``scripts`` and placed that on a ``.dmg`` disk image. +The installer package built on the dmg is a macOS bundle format installer +package. This format is deprecated and is no longer supported by modern +macOS systems; it is usable on macOS 10.6 and earlier systems. +To be usable on newer versions of macOS, the bits in the bundle package +must be assembled in a macOS flat installer package, using current +versions of the pkgbuild and productbuild utilities. To pass macoS +Gatekeeper download quarantine, the final package must be signed +with a valid Apple Developer ID certificate using productsign. +Starting with macOS 10.15 Catalina, Gatekeeper now also requires +that installer packages are submitted to and pass Apple's automated +notarization service using the altool command. To pass notarization, +the binaries included in the package must be built with at least +the macOS 10.9 SDK, mout now be signed with the codesign utility +and executables must opt in to the hardened run time option with +any necessary entitlements. Details of these processes are +available in the on-line Apple Developer Documentation and man pages. -For Python 3.4.0, PSF practice is to build two installer variants -for each release. +As of 3.8.0 and 3.7.7, PSF practice is to build one installer variants +for each release. Note that as of this writing, no Pythons support +building on a newer version of macOS that will run on older versions +by setting MACOSX_DEPLOYMENT_TARGET. This is because the various +Python C modules do not yet support runtime testing of macOS +feature availability (for example, by using macOS AvailabilityMacros.h +and weak-linking). To build a Python that is to be used on a +range of macOS releases, always build on the oldest release to be +supported; the necessary shared libraries for that release will +normally also be available on later systems, with the occasional +exception such as the removal of 32-bit libraries in macOS 10.15. -1. 32-bit-only, i386 and PPC universal, capable on running on all machines - supported by Mac OS X 10.5 through (at least) 10.9:: +build-installer requires Apple Developer tools, either from the +Command Line Tools package or from a full Xcode installation. +You should use the most recent version of either for the operating +system version in use. (One notable exception: on macOS 10.6, +Snow Leopard, use Xcode 3, not Xcode 4 which was released later +in the 10.6 support cycle.) + +1. 64-bit, x86_64, for OS X 10.9 (and later):: /path/to/bootstrap/python2.7 build-installer.py \ - --sdk-path=/Developer/SDKs/MacOSX10.5.sdk \ - --universal-archs=32-bit \ - --dep-target=10.5 + --universal-archs=intel-64 \ + --dep-target=10.9 - builds the following third-party libraries - * NCurses 5.9 (http://bugs.python.org/issue15037) - * SQLite 3.8.11 - * XZ 5.0.5 - - - uses system-supplied versions of third-party libraries - - * readline module links with Apple BSD editline (libedit) - - - requires ActiveState ``Tcl/Tk 8.4`` (currently 8.4.20) to be installed for building - - - recommended build environment: - - * Mac OS X 10.5.8 Intel or PPC - * Xcode 3.1.4 - * ``MacOSX10.5`` SDK - * ``MACOSX_DEPLOYMENT_TARGET=10.5`` - * Apple ``gcc-4.2`` - * bootstrap non-framework Python 2.7 for documentation build with - Sphinx (as of 3.4.1) - - - alternate build environments: - - * Mac OS X 10.6.8 with Xcode 3.2.6 - - need to change ``/System/Library/Frameworks/{Tcl,Tk}.framework/Version/Current`` to ``8.4`` - * Note Xcode 4.* does not support building for PPC so cannot be used for this build - -2. 64-bit / 32-bit, x86_64 and i386 universal, for OS X 10.6 (and later):: - - /path/to/bootstrap/python2.7 build-installer.py \ - --sdk-path=/Developer/SDKs/MacOSX10.6.sdk \ - --universal-archs=intel \ - --dep-target=10.6 - - - builds the following third-party libraries - - * NCurses 5.9 (http://bugs.python.org/issue15037) - * SQLite 3.8.11 - * XZ 5.0.5 - - - uses system-supplied versions of third-party libraries - - * readline module links with Apple BSD editline (libedit) - - - requires ActiveState Tcl/Tk 8.5.15.1 (or later) to be installed for building - - - recommended build environment: - - * Mac OS X 10.6.8 (or later) - * Xcode 3.2.6 - * ``MacOSX10.6`` SDK - * ``MACOSX_DEPLOYMENT_TARGET=10.6`` - * Apple ``gcc-4.2`` - * bootstrap non-framework Python 2.7 for documentation build with - Sphinx (as of 3.4.1) - - - alternate build environments: - - * none. Xcode 4.x currently supplies two C compilers. - ``llvm-gcc-4.2.1`` has been found to miscompile Python 3.3.x and - produce a non-functional Python executable. As it appears to be - considered a migration aid by Apple and is not likely to be fixed, - its use should be avoided. The other compiler, ``clang``, has been - undergoing rapid development. While it appears to have become - production-ready in the most recent Xcode 5 releases, the versions - available on the deprecated Xcode 4.x for 10.6 were early releases - and did not receive the level of exposure in production environments - that the Xcode 3 gcc-4.2 compiler has had. - - -* For Python 2.7.x and 3.2.x, the 32-bit-only installer was configured to - support Mac OS X 10.3.9 through (at least) 10.6. Because it is - believed that there are few systems still running OS X 10.3 or 10.4 - and because it has become increasingly difficult to test and - support the differences in these earlier systems, as of Python 3.3.0 the PSF - 32-bit installer no longer supports them. For reference in building such - an installer yourself, the details are:: - - /usr/bin/python build-installer.py \ - --sdk-path=/Developer/SDKs/MacOSX10.4u.sdk \ - --universal-archs=32-bit \ - --dep-target=10.3 - - - builds the following third-party libraries - - * Bzip2 + * OpenSSL 1.1.1 + * Tcl/Tk 8.6 * NCurses - * GNU Readline (GPL) - * SQLite 3 + * SQLite * XZ - * Zlib 1.2.3 - * Oracle Sleepycat DB 4.8 (Python 2.x only) + * libffi - - requires ActiveState ``Tcl/Tk 8.4`` (currently 8.4.20) to be installed for building + - uses system-supplied versions of third-party libraries + + * readline module links with Apple BSD editline (libedit) + * zlib + * bz2 - recommended build environment: - * Mac OS X 10.5.8 PPC or Intel - * Xcode 3.1.4 (or later) - * ``MacOSX10.4u`` SDK (later SDKs do not support PPC G3 processors) - * ``MACOSX_DEPLOYMENT_TARGET=10.3`` - * Apple ``gcc-4.0`` - * system Python 2.5 for documentation build with Sphinx - - - alternate build environments: - - * Mac OS X 10.6.8 with Xcode 3.2.6 - - need to change ``/System/Library/Frameworks/{Tcl,Tk}.framework/Version/Current`` to ``8.4`` - + * Mac OS X 10.9.5 + * Xcode Command Line Tools 6.2 + * ``MacOSX10.9`` SDK + * ``MACOSX_DEPLOYMENT_TARGET=10.9`` + * Apple ``clang`` General Prerequisites --------------------- -* No Fink (in ``/sw``) or MacPorts (in ``/opt/local``) or other local - libraries or utilities (in ``/usr/local``) as they could +* No Fink (in ``/sw``) or MacPorts (in ``/opt/local``) or Homebrew or + other local libraries or utilities (in ``/usr/local``) as they could interfere with the build. -* The documentation for the release is built using Sphinx - because it is included in the installer. For 2.7.x and 3.x.x up to and - including 3.4.0, the ``Doc/Makefile`` uses ``svn`` to download repos of - ``Sphinx`` and its dependencies. Beginning with 3.4.1, the ``Doc/Makefile`` - assumes there is an externally-provided ``sphinx-build`` and requires at - least Python 2.6 to run. Because of this, it is no longer possible to - build a 3.4.1 or later installer on OS X 10.5 using the Apple-supplied - Python 2.5. - * It is safest to start each variant build with an empty source directory - populated with a fresh copy of the untarred source. + populated with a fresh copy of the untarred source or a source repo. * It is recommended that you remove any existing installed version of the Python being built:: sudo rm -rf /Library/Frameworks/Python.framework/Versions/n.n - -The Recipe ----------- - -Here are the steps you need to follow to build a Python installer: - -* Run ``build-installer.py``. Optionally you can pass a number of arguments - to specify locations of various files. Please see the top of - ``build-installer.py`` for its usage. - - Running this script takes some time, it will not only build Python itself - but also some 3th-party libraries that are needed for extensions. - -* When done the script will tell you where the DMG image is (by default - somewhere in ``/tmp/_py``). - -Building other universal installers -................................... - -It is also possible to build a 4-way universal installer that runs on -OS X 10.5 Leopard or later:: - - /usr/bin/python /build-installer.py \ - --dep-target=10.5 - --universal-archs=all - --sdk-path=/Developer/SDKs/MacOSX10.5.sdk - -This requires that the deployment target is 10.5, and hence -also that you are building on at least OS X 10.5. 4-way includes -``i386``, ``x86_64``, ``ppc``, and ``ppc64`` (G5). ``ppc64`` executable -variants can only be run on G5 machines running 10.5. Note that, -while OS X 10.6 is only supported on Intel-based machines, it is possible -to run ``ppc`` (32-bit) executables unmodified thanks to the Rosetta ppc -emulation in OS X 10.5 and 10.6. The 4-way installer variant must be -built with Xcode 3. It is not regularly built or tested. - -Other ``--universal-archs`` options are ``64-bit`` (``x86_64``, ``ppc64``), -and ``3-way`` (``ppc``, ``i386``, ``x86_64``). None of these options -are regularly exercised; use at your own risk. - - -Testing -------- - -Ideally, the resulting binaries should be installed and the test suite run -on all supported OS X releases and architectures. As a practical matter, -that is generally not possible. At a minimum, variant 1 should be run on -a PPC G4 system with OS X 10.5 and at least one Intel system running OS X -10.9, 10.8, 10.7, 10.6, or 10.5. Variant 2 should be run on 10.9, 10.8, -10.7, and 10.6 systems in both 32-bit and 64-bit modes.:: - - /usr/local/bin/pythonn.n -m test -w -u all,-largefile - /usr/local/bin/pythonn.n-32 -m test -w -u all - -Certain tests will be skipped and some cause the interpreter to fail -which will likely generate ``Python quit unexpectedly`` alert messages -to be generated at several points during a test run. These are normal -during testing and can be ignored. - -It is also recommend to launch IDLE and verify that it is at least -functional. Double-click on the IDLE app icon in ``/Applications/Python n.n``. -It should also be tested from the command line:: - - /usr/local/bin/idlen.n - diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py index a10601bed9f..4fab4882efa 100755 --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -2,6 +2,20 @@ """ This script is used to build "official" universal installers on macOS. +NEW for 3.9.0 and backports: +- 2.7 end-of-life issues: + - Python 3 installs now update the Current version link + in /Library/Frameworks/Python.framework/Versions +- fully support running under Python 3 as well as 2.7 +- support building on newer macOS systems with SIP +- fully support building on macOS 10.9+ +- support 10.6+ on best effort +- support bypassing docs build by supplying a prebuilt + docs html tarball in the third-party source library, + in the format and filename conventional of those + downloadable from python.org: + python-3.x.y-docs-html.tar.bz2 + NEW for 3.7.0: - support Intel 64-bit-only () and 32-bit-only installer builds - build and use internal Tcl/Tk 8.6 for 10.6+ builds @@ -14,28 +28,7 @@ NEW for 3.7.0: - use generic "gcc" as compiler (CC env var) rather than "gcc-4.2" TODO: -- support SDKROOT and DEVELOPER_DIR xcrun env variables -- test with 10.5 and 10.4 and determine support status - -Please ensure that this script keeps working with Python 2.5, to avoid -bootstrap issues (/usr/bin/python is Python 2.5 on OSX 10.5). Doc builds -use current versions of Sphinx and require a reasonably current python3. -Sphinx and dependencies are installed into a venv using the python3's pip -so will fetch them from PyPI if necessary. Since python3 is now used for -Sphinx, build-installer.py should also be converted to use python3! - -For 3.7.0, when building for a 10.6 or higher deployment target, -build-installer builds and links with its own copy of Tcl/Tk 8.6. -Otherwise, it requires an installed third-party version of -Tcl/Tk 8.4 (for OS X 10.4 and 10.5 deployment targets), Tcl/TK 8.5 -(for 10.6 or later), or Tcl/TK 8.6 (for 10.9 or later) -installed in /Library/Frameworks. When installed, -the Python built by this script will attempt to dynamically link first to -Tcl and Tk frameworks in /Library/Frameworks if available otherwise fall -back to the ones in /System/Library/Framework. For the build, we recommend -installing the most recent ActiveTcl 8.6. 8.5, or 8.4 version, depending -on the deployment target. The actual version linked to depends on the -path of /Library/Frameworks/{Tcl,Tk}.framework/Versions/Current. +- test building with SDKROOT and DEVELOPER_DIR xcrun env variables Usage: see USAGE variable in the script. """ @@ -56,14 +49,15 @@ STAT_0o775 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR INCLUDE_TIMESTAMP = 1 VERBOSE = 1 -from plistlib import Plist +RUNNING_ON_PYTHON2 = sys.version_info.major == 2 -try: +if RUNNING_ON_PYTHON2: from plistlib import writePlist -except ImportError: - # We're run using python2.3 - def writePlist(plist, path): - plist.write(path) +else: + from plistlib import dump + def writePlist(path, plist): + with open(plist, 'wb') as fp: + dump(path, fp) def shellQuote(value): """ @@ -302,7 +296,7 @@ def library_recipes(): "--libdir=/Library/Frameworks/Python.framework/Versions/%s/lib"%(getVersion(),), ], patchscripts=[ - ("ftp://invisible-island.net/ncurses//5.9/ncurses-5.9-20120616-patch.sh.bz2", + ("ftp://ftp.invisible-island.net/ncurses//5.9/ncurses-5.9-20120616-patch.sh.bz2", "f54bf02a349f96a7c4f0d00922f3a0d4"), ], useLDFlags=False, @@ -313,9 +307,9 @@ def library_recipes(): ), ), dict( - name="SQLite 3.31.1", - url="https://sqlite.org/2020/sqlite-autoconf-3310100.tar.gz", - checksum='2d0a553534c521504e3ac3ad3b90f125', + name="SQLite 3.32.2", + url="https://sqlite.org/2020/sqlite-autoconf-3320200.tar.gz", + checksum='eb498918a33159cdf8104997aad29e83', extra_cflags=('-Os ' '-DSQLITE_ENABLE_FTS5 ' '-DSQLITE_ENABLE_FTS4 ' @@ -1066,14 +1060,40 @@ def buildPythonDocs(): curDir = os.getcwd() os.chdir(buildDir) runCommand('make clean') - # Create virtual environment for docs builds with blurb and sphinx - runCommand('make venv') - runCommand('venv/bin/python3 -m pip install -U Sphinx==2.2.0') - runCommand('make html PYTHON=venv/bin/python') + + # Search third-party source directory for a pre-built version of the docs. + # Use the naming convention of the docs.python.org html downloads: + # python-3.9.0b1-docs-html.tar.bz2 + doctarfiles = [ f for f in os.listdir(DEPSRC) + if f.startswith('python-'+getFullVersion()) + if f.endswith('-docs-html.tar.bz2') ] + if doctarfiles: + doctarfile = doctarfiles[0] + if not os.path.exists('build'): + os.mkdir('build') + # if build directory existed, it was emptied by make clean, above + os.chdir('build') + # Extract the first archive found for this version into build + runCommand('tar xjf %s'%shellQuote(os.path.join(DEPSRC, doctarfile))) + # see if tar extracted a directory ending in -docs-html + archivefiles = [ f for f in os.listdir('.') + if f.endswith('-docs-html') + if os.path.isdir(f) ] + if archivefiles: + archivefile = archivefiles[0] + # make it our 'Docs/build/html' directory + print(' -- using pre-built python documentation from %s'%archivefile) + os.rename(archivefile, 'html') + os.chdir(buildDir) + + htmlDir = os.path.join('build', 'html') + if not os.path.exists(htmlDir): + # Create virtual environment for docs builds with blurb and sphinx + runCommand('make venv') + runCommand('venv/bin/python3 -m pip install -U Sphinx==2.3.1') + runCommand('make html PYTHON=venv/bin/python') + os.rename(htmlDir, docdir) os.chdir(curDir) - if not os.path.exists(docdir): - os.mkdir(docdir) - os.rename(os.path.join(buildDir, 'build', 'html'), docdir) def buildPython(): @@ -1099,8 +1119,7 @@ def buildPython(): # Since the extra libs are not in their installed framework location # during the build, augment the library path so that the interpreter # will find them during its extension import sanity checks. - os.environ['DYLD_LIBRARY_PATH'] = os.path.join(WORKDIR, - 'libraries', 'usr', 'local', 'lib') + print("Running configure...") runCommand("%s -C --enable-framework --enable-universalsdk=/ " "--with-universal-archs=%s " @@ -1108,12 +1127,15 @@ def buildPython(): "%s " "%s " "%s " + "%s " "LDFLAGS='-g -L%s/libraries/usr/local/lib' " "CFLAGS='-g -I%s/libraries/usr/local/include' 2>&1"%( shellQuote(os.path.join(SRCDIR, 'configure')), UNIVERSALARCHS, (' ', '--with-computed-gotos ')[PYTHON_3], (' ', '--without-ensurepip ')[PYTHON_3], + (' ', "--with-openssl='%s/libraries/usr/local'"%( + shellQuote(WORKDIR)[1:-1],))[PYTHON_3], (' ', "--with-tcltk-includes='-I%s/libraries/usr/local/include'"%( shellQuote(WORKDIR)[1:-1],))[internalTk()], (' ', "--with-tcltk-libs='-L%s/libraries/usr/local/lib -ltcl8.6 -ltk8.6'"%( @@ -1121,6 +1143,24 @@ def buildPython(): shellQuote(WORKDIR)[1:-1], shellQuote(WORKDIR)[1:-1])) + # As of macOS 10.11 with SYSTEM INTEGRITY PROTECTION, DYLD_* + # environment variables are no longer automatically inherited + # by child processes from their parents. We used to just set + # DYLD_LIBRARY_PATH, pointing to the third-party libs, + # in build-installer.py's process environment and it was + # passed through the make utility into the environment of + # setup.py. Instead, we now append DYLD_LIBRARY_PATH to + # the existing RUNSHARED configuration value when we call + # make for extension module builds. + + runshared_for_make = "".join([ + " RUNSHARED=", + "'", + grepValue("Makefile", "RUNSHARED"), + ' DYLD_LIBRARY_PATH=', + os.path.join(WORKDIR, 'libraries', 'usr', 'local', 'lib'), + "'" ]) + # Look for environment value BUILDINSTALLER_BUILDPYTHON_MAKE_EXTRAS # and, if defined, append its value to the make command. This allows # us to pass in version control tags, like GITTAG, to a build from a @@ -1135,21 +1175,24 @@ def buildPython(): make_extras = os.getenv("BUILDINSTALLER_BUILDPYTHON_MAKE_EXTRAS") if make_extras: - make_cmd = "make " + make_extras + make_cmd = "make " + make_extras + runshared_for_make else: - make_cmd = "make" + make_cmd = "make" + runshared_for_make print("Running " + make_cmd) runCommand(make_cmd) - print("Running make install") - runCommand("make install DESTDIR=%s"%( - shellQuote(rootDir))) + make_cmd = "make install DESTDIR=%s %s"%( + shellQuote(rootDir), + runshared_for_make) + print("Running " + make_cmd) + runCommand(make_cmd) - print("Running make frameworkinstallextras") - runCommand("make frameworkinstallextras DESTDIR=%s"%( - shellQuote(rootDir))) + make_cmd = "make frameworkinstallextras DESTDIR=%s %s"%( + shellQuote(rootDir), + runshared_for_make) + print("Running " + make_cmd) + runCommand(make_cmd) - del os.environ['DYLD_LIBRARY_PATH'] print("Copying required shared libraries") if os.path.exists(os.path.join(WORKDIR, 'libraries', 'Library')): build_lib_dir = os.path.join( @@ -1278,7 +1321,13 @@ def buildPython(): data = fp.read() fp.close() # create build_time_vars dict - exec(data) + if RUNNING_ON_PYTHON2: + exec(data) + else: + g_dict = {} + l_dict = {} + exec(data, g_dict, l_dict) + build_time_vars = l_dict['build_time_vars'] vars = {} for k, v in build_time_vars.items(): if type(v) == type(''): @@ -1395,7 +1444,7 @@ def packageFromRecipe(targetDir, recipe): vers = getFullVersion() major, minor = getVersionMajorMinor() - pl = Plist( + pl = dict( CFBundleGetInfoString="Python.%s %s"%(pkgname, vers,), CFBundleIdentifier='org.python.Python.%s'%(pkgname,), CFBundleName='Python.%s'%(pkgname,), @@ -1417,7 +1466,7 @@ def packageFromRecipe(targetDir, recipe): ) writePlist(pl, os.path.join(packageContents, 'Info.plist')) - pl = Plist( + pl = dict( IFPkgDescriptionDescription=readme, IFPkgDescriptionTitle=recipe.get('long_name', "Python.%s"%(pkgname,)), IFPkgDescriptionVersion=vers, @@ -1433,7 +1482,7 @@ def makeMpkgPlist(path): vers = getFullVersion() major, minor = getVersionMajorMinor() - pl = Plist( + pl = dict( CFBundleGetInfoString="Python %s"%(vers,), CFBundleIdentifier='org.python.Python', CFBundleName='Python', @@ -1486,7 +1535,7 @@ def buildInstaller(): os.mkdir(rsrcDir) makeMpkgPlist(os.path.join(pkgroot, 'Info.plist')) - pl = Plist( + pl = dict( IFPkgDescriptionTitle="Python", IFPkgDescriptionVersion=getVersion(), ) diff --git a/Mac/BuildScript/resources/ReadMe.rtf b/Mac/BuildScript/resources/ReadMe.rtf index 086ab42b389..a4dd8b5ee41 100644 --- a/Mac/BuildScript/resources/ReadMe.rtf +++ b/Mac/BuildScript/resources/ReadMe.rtf @@ -1,4 +1,4 @@ -{\rtf1\ansi\ansicpg1252\cocoartf2511 +{\rtf1\ansi\ansicpg1252\cocoartf2513 \cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fswiss\fcharset0 Helvetica-Bold;\f2\fswiss\fcharset0 Helvetica-Oblique; \f3\fmodern\fcharset0 CourierNewPSMT;} {\colortbl;\red255\green255\blue255;} @@ -11,7 +11,7 @@ \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\partightenfactor0 \f1\b \cf0 NOTE: -\f0\b0 This is an alpha test preview of Python 3.9.0, the next feature release of Python 3. It is not intended for production use.\ +\f0\b0 This is an alpha test preview of Python 3.10.0, the next feature release of Python 3. It is not intended for production use.\ \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0 \cf0 \ \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0 @@ -56,12 +56,6 @@ Due to new security checks on macOS 10.15 Catalina, when launching IDLE macOS ma \f0\b0 button to proceed.\ \ -\f1\b \ul macOS 10.15 (Catalina) Gatekeeper Requirements [changed in 3.9.0a4]\ - -\f0\b0 \ulnone \ -As of 2020-02-03, Apple has changed how third-party installer packages, like those provided by python.org, are notarized for verification by Gatekeeper and begun enforcing additional requirements such as code signing and use of the hardened runtime. As of 3.9.0a4, python.org installer packages now meet those additional notarization requirements. The necessary changes in packaging should be transparent to your use of Python but, in the unlikely event that you encounter changes in behavior between 3.9.0a4 and earlier 3.9.0 alphas in areas like ctypes, importlib, or mmap, please check bugs.python.org for existing reports and, if necessary, open a new issue.\ -\ - \f1\b \ul Other changes\ \f0\b0 \ulnone \ diff --git a/Mac/BuildScript/resources/Welcome.rtf b/Mac/BuildScript/resources/Welcome.rtf index bf6aebe9248..cadfbf6a54c 100644 --- a/Mac/BuildScript/resources/Welcome.rtf +++ b/Mac/BuildScript/resources/Welcome.rtf @@ -1,5 +1,5 @@ -{\rtf1\ansi\ansicpg1252\cocoartf1671\cocoasubrtf600 -\cocoascreenfonts1{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fswiss\fcharset0 Helvetica-Bold;\f2\fmodern\fcharset0 CourierNewPSMT; +{\rtf1\ansi\ansicpg1252\cocoartf2513 +\cocoascreenfonts1\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fswiss\fcharset0 Helvetica-Bold;\f2\fmodern\fcharset0 CourierNewPSMT; } {\colortbl;\red255\green255\blue255;} {\*\expandedcolortbl;;} @@ -26,5 +26,5 @@ At the end of this install, click on \ \f1\b NOTE: -\f0\b0 This is an alpha test preview of Python 3.9.0, the next feature release of Python 3. It is not intended for production use.\ +\f0\b0 This is an alpha test preview of Python 3.10.0, the next feature release of Python 3. It is not intended for production use.\ } \ No newline at end of file diff --git a/Mac/BuildScript/scripts/postflight.documentation b/Mac/BuildScript/scripts/postflight.documentation index 3cbbc1bf10c..ec48599cba7 100755 --- a/Mac/BuildScript/scripts/postflight.documentation +++ b/Mac/BuildScript/scripts/postflight.documentation @@ -12,7 +12,9 @@ SHARE_DOCDIR_TO_FWK="../../.." # make link in /Applications/Python m.n/ for Finder users if [ -d "${APPDIR}" ]; then ln -fhs "${FWK_DOCDIR}/index.html" "${APPDIR}/Python Documentation.html" - open "${APPDIR}" || true # open the applications folder + if [ "${COMMAND_LINE_INSTALL}" != 1 ]; then + open "${APPDIR}" || true # open the applications folder + fi fi # make share/doc link in framework for command line users diff --git a/Mac/PythonLauncher/factorySettings.plist b/Mac/PythonLauncher/factorySettings.plist index 120242135ce..6f650ae7616 100644 --- a/Mac/PythonLauncher/factorySettings.plist +++ b/Mac/PythonLauncher/factorySettings.plist @@ -10,9 +10,9 @@ interpreter_list - /usr/local/bin/pythonw - /usr/bin/pythonw - /sw/bin/pythonw + /usr/local/bin/python3 + /opt/local/bin/python3 + /sw/bin/python3 honourhashbang @@ -35,12 +35,9 @@ interpreter_list - /usr/local/bin/pythonw - /usr/local/bin/python - /usr/bin/pythonw - /usr/bin/python - /sw/bin/pythonw - /sw/bin/python + /usr/local/bin/python3 + /opt/local/bin/python3 + /sw/bin/python3 honourhashbang @@ -63,12 +60,9 @@ interpreter_list - /usr/local/bin/pythonw - /usr/local/bin/python - /usr/bin/pythonw - /usr/bin/python - /sw/bin/pythonw - /sw/bin/python + /usr/local/bin/python3 + /opt/local/bin/python3 + /sw/bin/python3 honourhashbang diff --git a/Mac/Resources/app/Info.plist.in b/Mac/Resources/app/Info.plist.in index 66b5e764c54..1d624984a85 100644 --- a/Mac/Resources/app/Info.plist.in +++ b/Mac/Resources/app/Info.plist.in @@ -20,7 +20,7 @@ CFBundleExecutable Python CFBundleGetInfoString - %version%, (c) 2001-2016 Python Software Foundation. + %version%, (c) 2001-2020 Python Software Foundation. CFBundleHelpBookFolder Documentation @@ -55,7 +55,7 @@ NSAppleScriptEnabled NSHumanReadableCopyright - (c) 2001-2016 Python Software Foundation. + (c) 2001-2020 Python Software Foundation. NSHighResolutionCapable diff --git a/Makefile.pre.in b/Makefile.pre.in index 5a18704e441..3428b9842a5 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -148,7 +148,7 @@ SCRIPTDIR= $(prefix)/$(PLATLIBDIR) ABIFLAGS= @ABIFLAGS@ # Detailed destination directories -BINLIBDEST= $(LIBDIR)/python$(VERSION) +BINLIBDEST= @BINLIBDEST@ LIBDEST= $(SCRIPTDIR)/python$(VERSION) INCLUDEPY= $(INCLUDEDIR)/python$(LDVERSION) CONFINCLUDEPY= $(CONFINCLUDEDIR)/python$(LDVERSION) @@ -300,32 +300,24 @@ LIBFFI_INCLUDEDIR= @LIBFFI_INCLUDEDIR@ # Parser PEGEN_OBJS= \ - Parser/pegen/pegen.o \ - Parser/pegen/parse.o \ - Parser/pegen/parse_string.o \ - Parser/pegen/peg_api.o + Parser/pegen.o \ + Parser/parser.o \ + Parser/string_parser.o \ + Parser/peg_api.o PEGEN_HEADERS= \ - $(srcdir)/Include/internal/pegen_interface.h \ - $(srcdir)/Parser/pegen/pegen.h \ - $(srcdir)/Parser/pegen/parse_string.h + $(srcdir)/Include/parser_interface.h \ + $(srcdir)/Parser/pegen.h \ + $(srcdir)/Parser/string_parser.h POBJS= \ - Parser/acceler.o \ - Parser/grammar1.o \ - Parser/listnode.o \ - Parser/node.o \ - Parser/parser.o \ Parser/token.o \ -PARSER_OBJS= $(POBJS) $(PEGEN_OBJS) Parser/myreadline.o Parser/parsetok.o Parser/tokenizer.o +PARSER_OBJS= $(POBJS) $(PEGEN_OBJS) Parser/myreadline.o Parser/tokenizer.o PARSER_HEADERS= \ $(PEGEN_HEADERS) \ - $(srcdir)/Include/grammar.h \ - $(srcdir)/Include/parsetok.h \ - $(srcdir)/Parser/parser.h \ $(srcdir)/Parser/tokenizer.h ########################################################################## @@ -352,7 +344,6 @@ PYTHON_OBJS= \ Python/getcopyright.o \ Python/getplatform.o \ Python/getversion.o \ - Python/graminit.o \ Python/hamt.o \ Python/hashtable.o \ Python/import.o \ @@ -568,7 +559,7 @@ coverage-lcov: @echo # Force regeneration of parser and importlib -coverage-report: regen-grammar regen-token regen-importlib +coverage-report: regen-token regen-importlib @ # build with coverage info $(MAKE) coverage @ # run tests, ignore failures @@ -749,8 +740,8 @@ regen-importlib: Programs/_freeze_importlib ############################################################################ # Regenerate all generated files -regen-all: regen-opcode regen-opcode-targets regen-typeslots regen-grammar \ - regen-token regen-keyword regen-symbol regen-ast regen-importlib clinic \ +regen-all: regen-opcode regen-opcode-targets regen-typeslots \ + regen-token regen-ast regen-importlib clinic \ regen-pegen-metaparser regen-pegen ############################################################################ @@ -775,7 +766,6 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile -DEXEC_PREFIX='"$(exec_prefix)"' \ -DVERSION='"$(VERSION)"' \ -DVPATH='"$(VPATH)"' \ - -DPLATLIBDIR='"$(PLATLIBDIR)"' \ -o $@ $(srcdir)/Modules/getpath.c Programs/python.o: $(srcdir)/Programs/python.c @@ -807,23 +797,15 @@ Python/dynload_hpux.o: $(srcdir)/Python/dynload_hpux.c Makefile Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile $(srcdir)/Include/pydtrace.h $(CC) -c $(PY_CORE_CFLAGS) \ -DABIFLAGS='"$(ABIFLAGS)"' \ - -DPLATLIBDIR='"$(PLATLIBDIR)"' \ $(MULTIARCH_CPPFLAGS) \ -o $@ $(srcdir)/Python/sysmodule.c -$(IO_OBJS): $(IO_H) +Python/initconfig.o: $(srcdir)/Python/initconfig.c + $(CC) -c $(PY_CORE_CFLAGS) \ + -DPLATLIBDIR='"$(PLATLIBDIR)"' \ + -o $@ $(srcdir)/Python/initconfig.c -.PHONY: regen-grammar -regen-grammar: regen-token - # Regenerate Include/graminit.h and Python/graminit.c - # from Grammar/Grammar using pgen - @$(MKDIR_P) Include - PYTHONPATH=$(srcdir) $(PYTHON_FOR_REGEN) -m Parser.pgen $(srcdir)/Grammar/Grammar \ - $(srcdir)/Grammar/Tokens \ - $(srcdir)/Include/graminit.h.new \ - $(srcdir)/Python/graminit.c.new - $(UPDATE_FILE) $(srcdir)/Include/graminit.h $(srcdir)/Include/graminit.h.new - $(UPDATE_FILE) $(srcdir)/Python/graminit.c $(srcdir)/Python/graminit.c.new +$(IO_OBJS): $(IO_H) .PHONY: regen-pegen-metaparser regen-pegen-metaparser: @@ -836,12 +818,12 @@ regen-pegen-metaparser: .PHONY: regen-pegen regen-pegen: - @$(MKDIR_P) $(srcdir)/Parser/pegen + @$(MKDIR_P) $(srcdir)/Parser PYTHONPATH=$(srcdir)/Tools/peg_generator $(PYTHON_FOR_REGEN) -m pegen -q c \ $(srcdir)/Grammar/python.gram \ $(srcdir)/Grammar/Tokens \ - -o $(srcdir)/Parser/pegen/parse.new.c - $(UPDATE_FILE) $(srcdir)/Parser/pegen/parse.c $(srcdir)/Parser/pegen/parse.new.c + -o $(srcdir)/Parser/parser.new.c + $(UPDATE_FILE) $(srcdir)/Parser/parser.c $(srcdir)/Parser/parser.new.c .PHONY=regen-ast regen-ast: @@ -890,22 +872,15 @@ regen-token: .PHONY: regen-keyword regen-keyword: - # Regenerate Lib/keyword.py from Grammar/Grammar and Grammar/Tokens - # using Parser/pgen - PYTHONPATH=$(srcdir) $(PYTHON_FOR_REGEN) -m Parser.pgen.keywordgen $(srcdir)/Grammar/Grammar \ + # Regenerate Lib/keyword.py from Grammar/python.gram and Grammar/Tokens + # using Tools/peg_generator/pegen + PYTHONPATH=$(srcdir)/Tools/peg_generator $(PYTHON_FOR_REGEN) -m pegen.keywordgen \ + $(srcdir)/Grammar/python.gram \ $(srcdir)/Grammar/Tokens \ $(srcdir)/Lib/keyword.py.new $(UPDATE_FILE) $(srcdir)/Lib/keyword.py $(srcdir)/Lib/keyword.py.new -.PHONY: regen-symbol -regen-symbol: $(srcdir)/Include/graminit.h - # Regenerate Lib/symbol.py from Include/graminit.h - # using Tools/scripts/generate_symbol_py.py - $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/generate_symbol_py.py \ - $(srcdir)/Include/graminit.h \ - $(srcdir)/Lib/symbol.py - -Python/compile.o Python/symtable.o Python/ast_unparse.o Python/ast.o Python/future.o Parser/parsetok.o: $(srcdir)/Include/graminit.h $(srcdir)/Include/Python-ast.h +Python/compile.o Python/symtable.o Python/ast_unparse.o Python/ast.o Python/future.o: $(srcdir)/Include/Python-ast.h Python/getplatform.o: $(srcdir)/Python/getplatform.c $(CC) -c $(PY_CORE_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c @@ -1005,7 +980,6 @@ PYTHON_HEADERS= \ $(srcdir)/Include/abstract.h \ $(srcdir)/Include/asdl.h \ $(srcdir)/Include/ast.h \ - $(srcdir)/Include/bitset.h \ $(srcdir)/Include/bltinmodule.h \ $(srcdir)/Include/boolobject.h \ $(srcdir)/Include/bytearrayobject.h \ @@ -1043,7 +1017,6 @@ PYTHON_HEADERS= \ $(srcdir)/Include/modsupport.h \ $(srcdir)/Include/moduleobject.h \ $(srcdir)/Include/namespaceobject.h \ - $(srcdir)/Include/node.h \ $(srcdir)/Include/object.h \ $(srcdir)/Include/objimpl.h \ $(srcdir)/Include/odictobject.h \ @@ -1121,7 +1094,7 @@ PYTHON_HEADERS= \ $(srcdir)/Include/internal/pycore_abstract.h \ $(srcdir)/Include/internal/pycore_accu.h \ $(srcdir)/Include/internal/pycore_atomic.h \ - $(srcdir)/Include/internal/pycore_byteswap.h \ + $(srcdir)/Include/internal/pycore_bitutils.h \ $(srcdir)/Include/internal/pycore_bytes_methods.h \ $(srcdir)/Include/internal/pycore_call.h \ $(srcdir)/Include/internal/pycore_ceval.h \ @@ -1137,6 +1110,7 @@ PYTHON_HEADERS= \ $(srcdir)/Include/internal/pycore_import.h \ $(srcdir)/Include/internal/pycore_initconfig.h \ $(srcdir)/Include/internal/pycore_interp.h \ + $(srcdir)/Include/internal/pycore_list.h \ $(srcdir)/Include/internal/pycore_object.h \ $(srcdir)/Include/internal/pycore_pathconfig.h \ $(srcdir)/Include/internal/pycore_pyerrors.h \ @@ -1147,7 +1121,7 @@ PYTHON_HEADERS= \ $(srcdir)/Include/internal/pycore_runtime.h \ $(srcdir)/Include/internal/pycore_sysmodule.h \ $(srcdir)/Include/internal/pycore_traceback.h \ - $(srcdir)/Include/internal/pycore_tupleobject.h \ + $(srcdir)/Include/internal/pycore_tuple.h \ $(srcdir)/Include/internal/pycore_warnings.h \ $(DTRACE_HEADERS) diff --git a/Misc/ACKS b/Misc/ACKS index a505a3d7840..641ef0cace0 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -910,6 +910,7 @@ Vajrasky Kok Guido Kollerie Jacek KoÅ‚odziej Jacek Konieczny +Krzysztof Konopko Arkady Koplyarov Peter A. Koren Марк Коренберг @@ -1677,6 +1678,7 @@ Péter Szabó John Szakmeister Piotr Szczepaniak Amir Szekely +David Szotten Maciej Szulik Joel Taddei Arfrever Frehtes Taifersar Arahesis @@ -1704,6 +1706,7 @@ Mikhail Terekhov Victor Terrón Pablo Galindo Richard M. Tew +Srinivas Reddy Thatiparthy Tobias Thelen Christian Theune Févry Thibault diff --git a/Misc/NEWS.d/3.9.0a5.rst b/Misc/NEWS.d/3.9.0a5.rst index 7e2eaa3a100..39e017768c3 100644 --- a/Misc/NEWS.d/3.9.0a5.rst +++ b/Misc/NEWS.d/3.9.0a5.rst @@ -176,7 +176,7 @@ convention. Patch by Dong-hee Na. .. section: Core and Builtins Chaged list overallocation strategy. It no longer overallocates if the new -size is closer to overalocated size than to the old size and adds padding. +size is closer to overallocated size than to the old size and adds padding. .. @@ -990,7 +990,7 @@ modules are built. Add ``--with-platlibdir`` option to the configure script: name of the platform-specific library directory, stored in the new :attr:`sys.platlibdir` attribute. It is used to build the path of -platform-specific dynamic libraries and the path of the standard library. It +platform-specific extension modules and the path of the standard library. It is equal to ``"lib"`` on most platforms. On Fedora and SuSE, it is equal to ``"lib64"`` on 64-bit platforms. Patch by Jan MatÄ›jek, MatÄ›j Cepl, Charalampos Stratakis and Victor Stinner. diff --git a/Misc/NEWS.d/next/Build/2020-06-08-19-57-05.bpo-40684.WIY2-i.rst b/Misc/NEWS.d/next/Build/2020-06-08-19-57-05.bpo-40684.WIY2-i.rst new file mode 100644 index 00000000000..0495e5e4136 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2020-06-08-19-57-05.bpo-40684.WIY2-i.rst @@ -0,0 +1,2 @@ +``make install`` now uses the ``PLATLIBDIR`` variable for the destination +``lib-dynload/`` directory when ``./configure --with-platlibdir`` is used. diff --git a/Misc/NEWS.d/next/Build/2020-06-15-22-14-25.bpo-36020.wbiv0P.rst b/Misc/NEWS.d/next/Build/2020-06-15-22-14-25.bpo-36020.wbiv0P.rst new file mode 100644 index 00000000000..de50dff3b1d --- /dev/null +++ b/Misc/NEWS.d/next/Build/2020-06-15-22-14-25.bpo-36020.wbiv0P.rst @@ -0,0 +1,2 @@ +The C99 functions :c:func:`snprintf` and :c:func:`vsnprintf` are now required +to build Python. diff --git a/Misc/NEWS.d/next/Build/2020-06-25-06-59-13.bpo-40204.GpD04D.rst b/Misc/NEWS.d/next/Build/2020-06-25-06-59-13.bpo-40204.GpD04D.rst new file mode 100644 index 00000000000..25a6d751e5f --- /dev/null +++ b/Misc/NEWS.d/next/Build/2020-06-25-06-59-13.bpo-40204.GpD04D.rst @@ -0,0 +1 @@ +Pin Sphinx version to 2.3.1 in ``Doc/Makefile``. diff --git a/Misc/NEWS.d/next/C API/2020-02-08-08-01-35.bpo-39583.qURKSl.rst b/Misc/NEWS.d/next/C API/2020-02-08-08-01-35.bpo-39583.qURKSl.rst new file mode 100644 index 00000000000..1c9f44f7443 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-02-08-08-01-35.bpo-39583.qURKSl.rst @@ -0,0 +1 @@ +Remove superfluous "extern C" declarations from ``Include/cpython/*.h``. diff --git a/Misc/NEWS.d/next/C API/2020-05-20-19-11-12.bpo-40703.qQXfW8.rst b/Misc/NEWS.d/next/C API/2020-05-20-19-11-12.bpo-40703.qQXfW8.rst new file mode 100644 index 00000000000..5385a2d8dce --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-05-20-19-11-12.bpo-40703.qQXfW8.rst @@ -0,0 +1,2 @@ +The PyType_FromSpec*() functions no longer overwrite the type's "__module__" attribute +if it is set via "Py_tp_members" or "Py_tp_getset". diff --git a/Misc/NEWS.d/next/C API/2020-05-26-16-21-47.bpo-39573.depAgq.rst b/Misc/NEWS.d/next/C API/2020-05-26-16-21-47.bpo-39573.depAgq.rst new file mode 100644 index 00000000000..f8f675cebca --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-05-26-16-21-47.bpo-39573.depAgq.rst @@ -0,0 +1,5 @@ +Convert :c:func:`Py_REFCNT` and :c:func:`Py_SIZE` macros to static inline +functions. They cannot be used as l-value anymore: use +:c:func:`Py_SET_REFCNT` and :c:func:`Py_SET_SIZE` to set an object reference +count and size. This change is backward incompatible on purpose, to prepare +the C API for an opaque :c:type:`PyObject` structure. diff --git a/Misc/NEWS.d/next/C API/2020-05-27-11-02-15.bpo-40792.pBw2Bb.rst b/Misc/NEWS.d/next/C API/2020-05-27-11-02-15.bpo-40792.pBw2Bb.rst new file mode 100644 index 00000000000..4cfe09bc774 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-05-27-11-02-15.bpo-40792.pBw2Bb.rst @@ -0,0 +1,2 @@ +The result of :c:func:`PyNumber_Index` now always has exact type :class:`int`. +Previously, the result could have been an instance of a subclass of ``int``. diff --git a/Misc/NEWS.d/next/C API/2020-06-01-16-12-37.bpo-40826.zQzFoK.rst b/Misc/NEWS.d/next/C API/2020-06-01-16-12-37.bpo-40826.zQzFoK.rst new file mode 100644 index 00000000000..0d7a36c3eb4 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-01-16-12-37.bpo-40826.zQzFoK.rst @@ -0,0 +1,2 @@ +:c:func:`PyOS_InterruptOccurred` now fails with a fatal error if it is +called with the GIL released. diff --git a/Misc/NEWS.d/next/C API/2020-06-01-20-47-49.bpo-40839.bAi52Z.rst b/Misc/NEWS.d/next/C API/2020-06-01-20-47-49.bpo-40839.bAi52Z.rst new file mode 100644 index 00000000000..5de2f40c14e --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-01-20-47-49.bpo-40839.bAi52Z.rst @@ -0,0 +1,2 @@ +Calling :c:func:`PyDict_GetItem` without :term:`GIL` held had been allowed for +historical reason. It is no longer allowed. diff --git a/Misc/NEWS.d/next/C API/2020-06-03-17-48-13.bpo-40679.3sgWma.rst b/Misc/NEWS.d/next/C API/2020-06-03-17-48-13.bpo-40679.3sgWma.rst new file mode 100644 index 00000000000..ccf908cef19 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-03-17-48-13.bpo-40679.3sgWma.rst @@ -0,0 +1 @@ +Fix a ``_PyEval_EvalCode()`` crash if *qualname* argument is NULL. diff --git a/Misc/NEWS.d/next/C API/2020-06-04-08-01-23.bpo-40724.qIIdSi.rst b/Misc/NEWS.d/next/C API/2020-06-04-08-01-23.bpo-40724.qIIdSi.rst new file mode 100644 index 00000000000..82793dbf7ad --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-04-08-01-23.bpo-40724.qIIdSi.rst @@ -0,0 +1 @@ +Allow defining buffer slots in type specs. diff --git a/Misc/NEWS.d/next/C API/2020-06-08-15-59-06.bpo-40910.L56oI0.rst b/Misc/NEWS.d/next/C API/2020-06-08-15-59-06.bpo-40910.L56oI0.rst new file mode 100644 index 00000000000..1d0cb0b0235 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-08-15-59-06.bpo-40910.L56oI0.rst @@ -0,0 +1,3 @@ +Export explicitly the :c:func:`Py_GetArgcArgv` function to the C API and +document the function. Previously, it was exported implicitly which no +longer works since Python is built with ``-fvisibility=hidden``. diff --git a/Misc/NEWS.d/next/C API/2020-06-10-18-37-26.bpo-40943.i4q7rK.rst b/Misc/NEWS.d/next/C API/2020-06-10-18-37-26.bpo-40943.i4q7rK.rst new file mode 100644 index 00000000000..360ddae34cb --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-10-18-37-26.bpo-40943.i4q7rK.rst @@ -0,0 +1,5 @@ +The ``PY_SSIZE_T_CLEAN`` macro must now be defined to use +:c:func:`PyArg_ParseTuple` and :c:func:`Py_BuildValue` formats which use ``#``: +``es#``, ``et#``, ``s#``, ``u#``, ``y#``, ``z#``, ``U#`` and ``Z#``. +See :ref:`Parsing arguments and building values ` and the +:pep:`353`. diff --git a/Misc/NEWS.d/next/C API/2020-06-15-16-46-01.bpo-36020.djI6jw.rst b/Misc/NEWS.d/next/C API/2020-06-15-16-46-01.bpo-36020.djI6jw.rst new file mode 100644 index 00000000000..1f91dce4608 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-15-16-46-01.bpo-36020.djI6jw.rst @@ -0,0 +1,2 @@ +On Windows, ``#include "pyerrors.h"`` no longer defines ``snprintf`` and +``vsnprintf`` macros. diff --git a/Misc/NEWS.d/next/C API/2020-06-15-23-17-51.bpo-40989.tlzG3r.rst b/Misc/NEWS.d/next/C API/2020-06-15-23-17-51.bpo-40989.tlzG3r.rst new file mode 100644 index 00000000000..1be473d1427 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-15-23-17-51.bpo-40989.tlzG3r.rst @@ -0,0 +1,3 @@ +The :c:func:`PyObject_INIT` and :c:func:`PyObject_INIT_VAR` macros become +aliases to, respectively, :c:func:`PyObject_Init` and +:c:func:`PyObject_InitVar` functions. diff --git a/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst b/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst new file mode 100644 index 00000000000..1e448303a85 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst @@ -0,0 +1,4 @@ +Mark ``Py_UNICODE_COPY``, ``Py_UNICODE_FILL``, ``PyUnicode_WSTR_LENGTH``, +``PyUnicode_FromUnicode``, ``PyUnicode_AsUnicode``, +and ``PyUnicode_AsUnicodeAndSize`` as deprecated in C. Remove ``Py_UNICODE_MATCH`` +which was deprecated and broken since Python 3.3. diff --git a/Misc/NEWS.d/next/C API/2020-06-17-20-31-12.bpo-36346.mwIyxi.rst b/Misc/NEWS.d/next/C API/2020-06-17-20-31-12.bpo-36346.mwIyxi.rst new file mode 100644 index 00000000000..9b0400399be --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-17-20-31-12.bpo-36346.mwIyxi.rst @@ -0,0 +1,2 @@ +Raises DeprecationWarning for ``PyUnicode_FromUnicode(NULL, size)`` and +``PyUnicode_FromStringAndSize(NULL, size)`` with ``size > 0``. diff --git a/Misc/NEWS.d/next/C API/2020-06-24-22-57-07.bpo-41103.doojgE.rst b/Misc/NEWS.d/next/C API/2020-06-24-22-57-07.bpo-41103.doojgE.rst new file mode 100644 index 00000000000..082b77b9035 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-24-22-57-07.bpo-41103.doojgE.rst @@ -0,0 +1,4 @@ +``PyObject_AsCharBuffer()``, ``PyObject_AsReadBuffer()``, +``PyObject_CheckReadBuffer()``, and ``PyObject_AsWriteBuffer()`` are +removed. Please migrate to new buffer protocol; :c:func:`PyObject_GetBuffer` +and :c:func:`PyBuffer_Release`. diff --git a/Misc/NEWS.d/next/C API/2020-06-26-13-29-25.bpo-41123.bRa1oy.rst b/Misc/NEWS.d/next/C API/2020-06-26-13-29-25.bpo-41123.bRa1oy.rst new file mode 100644 index 00000000000..1261a8708d6 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-26-13-29-25.bpo-41123.bRa1oy.rst @@ -0,0 +1 @@ +Removed ``Py_UNICODE_str*`` functions manipulating ``Py_UNICODE*`` strings. diff --git a/Misc/NEWS.d/next/C API/2020-06-28-11-39-22.bpo-41123.sjJWjQ.rst b/Misc/NEWS.d/next/C API/2020-06-28-11-39-22.bpo-41123.sjJWjQ.rst new file mode 100644 index 00000000000..97331458c6a --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-28-11-39-22.bpo-41123.sjJWjQ.rst @@ -0,0 +1 @@ +Removed ``PyUnicode_GetMax()``. diff --git a/Misc/NEWS.d/next/C API/2020-06-29-11-33-49.bpo-41123.qFevek.rst b/Misc/NEWS.d/next/C API/2020-06-29-11-33-49.bpo-41123.qFevek.rst new file mode 100644 index 00000000000..1f5813594b0 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-29-11-33-49.bpo-41123.qFevek.rst @@ -0,0 +1 @@ +Removed ``PyLong_FromUnicode()``. diff --git a/Misc/NEWS.d/next/C API/2020-06-29-15-49-36.bpo-41123.wYY4E1.rst b/Misc/NEWS.d/next/C API/2020-06-29-15-49-36.bpo-41123.wYY4E1.rst new file mode 100644 index 00000000000..74ac4546277 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-29-15-49-36.bpo-41123.wYY4E1.rst @@ -0,0 +1 @@ +Remove ``PyUnicode_AsUnicodeCopy``. diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-08-29-15-57-07.bpo-19569.RGu2Kb.rst b/Misc/NEWS.d/next/Core and Builtins/2018-08-29-15-57-07.bpo-19569.RGu2Kb.rst new file mode 100644 index 00000000000..1b76bd8e247 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2018-08-29-15-57-07.bpo-19569.RGu2Kb.rst @@ -0,0 +1,2 @@ +Add the private macros ``_Py_COMP_DIAG_PUSH``, +``_Py_COMP_DIAG_IGNORE_DEPR_DECLS``, and ``_Py_COMP_DIAG_POP``. diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-06-02-11-29-15.bpo-29882.AkRzjb.rst b/Misc/NEWS.d/next/Core and Builtins/2019-06-02-11-29-15.bpo-29882.AkRzjb.rst new file mode 100644 index 00000000000..240b5680b36 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2019-06-02-11-29-15.bpo-29882.AkRzjb.rst @@ -0,0 +1,2 @@ +Add :meth:`int.bit_count()`, counting the number of ones in the binary +representation of an integer. Patch by Niklas Fiekas. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-04-05-02-35-08.bpo-1635741.Kfe9fT.rst b/Misc/NEWS.d/next/Core and Builtins/2020-04-05-02-35-08.bpo-1635741.Kfe9fT.rst new file mode 100644 index 00000000000..956d0b68a8d --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-04-05-02-35-08.bpo-1635741.Kfe9fT.rst @@ -0,0 +1 @@ +Port :mod:`_lzma` to multiphase initialization. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-04-10-23-54-57.bpo-1635741.ZURqoN.rst b/Misc/NEWS.d/next/Core and Builtins/2020-04-10-23-54-57.bpo-1635741.ZURqoN.rst new file mode 100644 index 00000000000..cb849fb9b44 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-04-10-23-54-57.bpo-1635741.ZURqoN.rst @@ -0,0 +1 @@ +Port :mod:`mmap` to multiphase initialization. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-04-11-13-07-49.bpo-4022.Ctpn_F.rst b/Misc/NEWS.d/next/Core and Builtins/2020-04-11-13-07-49.bpo-4022.Ctpn_F.rst new file mode 100644 index 00000000000..a13a8e88226 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-04-11-13-07-49.bpo-4022.Ctpn_F.rst @@ -0,0 +1 @@ +Improve performance of generators by not raising internal StopIteration. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-05-20-01-17-34.bpo-40521.wvAehI.rst b/Misc/NEWS.d/next/Core and Builtins/2020-05-20-01-17-34.bpo-40521.wvAehI.rst new file mode 100644 index 00000000000..43226931ccc --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-05-20-01-17-34.bpo-40521.wvAehI.rst @@ -0,0 +1,9 @@ +Each interpreter now its has own free lists, singletons and caches: + +* Free lists: float, tuple, list, dict, frame, context, + asynchronous generator, MemoryError. +* Singletons: empty tuple, empty bytes string, empty Unicode string, + single byte character, single Unicode (latin1) character. +* Slice cache. + +They are no longer shared by all interpreters. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-05-23-01-15-51.bpo-40217.jZsHTc.rst b/Misc/NEWS.d/next/Core and Builtins/2020-05-23-01-15-51.bpo-40217.jZsHTc.rst new file mode 100644 index 00000000000..b13e8eeb063 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-05-23-01-15-51.bpo-40217.jZsHTc.rst @@ -0,0 +1,4 @@ +Instances of types created with :c:func:`PyType_FromSpecWithBases` will no +longer automatically visit their class object when traversing references in +the garbage collector. The user is expected to manually visit the object's +class. Patch by Pablo Galindo. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-05-26-17-43-58.bpo-40780.3Ckdgm.rst b/Misc/NEWS.d/next/Core and Builtins/2020-05-26-17-43-58.bpo-40780.3Ckdgm.rst new file mode 100644 index 00000000000..ed6020c2e23 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-05-26-17-43-58.bpo-40780.3Ckdgm.rst @@ -0,0 +1,2 @@ +Fix a corner case where g-style string formatting of a float failed to +remove trailing zeros. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-05-27-22-37-58.bpo-40792.WEDqqU.rst b/Misc/NEWS.d/next/Core and Builtins/2020-05-27-22-37-58.bpo-40792.WEDqqU.rst new file mode 100644 index 00000000000..5986a221f5b --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-05-27-22-37-58.bpo-40792.WEDqqU.rst @@ -0,0 +1,3 @@ +Attributes ``start``, ``stop`` and ``step`` of the :class:`range` object now +always has exact type :class:`int`. Previously, they could have been an +instance of a subclass of ``int``. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-05-30-14-37-18.bpo-40824.XR3V5s.rst b/Misc/NEWS.d/next/Core and Builtins/2020-05-30-14-37-18.bpo-40824.XR3V5s.rst new file mode 100644 index 00000000000..73c593c04a0 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-05-30-14-37-18.bpo-40824.XR3V5s.rst @@ -0,0 +1,4 @@ +Unexpected errors in calling the ``__iter__`` method are no longer masked by +``TypeError`` in the :keyword:`in` operator and functions +:func:`~operator.contains`, :func:`~operator.indexOf` and +:func:`~operator.countOf` of the :mod:`operator` module. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-05-30-23-18-35.bpo-19468.S-TA7p.rst b/Misc/NEWS.d/next/Core and Builtins/2020-05-30-23-18-35.bpo-19468.S-TA7p.rst new file mode 100644 index 00000000000..e35750e37f4 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-05-30-23-18-35.bpo-19468.S-TA7p.rst @@ -0,0 +1,2 @@ +Delete unnecessary instance check in importlib.reload(). +Patch by Furkan Önder. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-05-30-23-23-35.bpo-1635741.0D-laM.rst b/Misc/NEWS.d/next/Core and Builtins/2020-05-30-23-23-35.bpo-1635741.0D-laM.rst new file mode 100644 index 00000000000..cd2bcb6e608 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-05-30-23-23-35.bpo-1635741.0D-laM.rst @@ -0,0 +1 @@ +Port :mod:`fcntl` to multiphase initialization. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-01-20-31-07.bpo-40826.XCI4M2.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-01-20-31-07.bpo-40826.XCI4M2.rst new file mode 100644 index 00000000000..a03ed180eb9 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-01-20-31-07.bpo-40826.XCI4M2.rst @@ -0,0 +1,2 @@ +Fix GIL usage in :c:func:`PyOS_Readline`: lock the GIL to set an exception +and pass the Python thread state when checking if there is a pending signal. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-03-13-53-24.bpo-40854.O6vfQU.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-03-13-53-24.bpo-40854.O6vfQU.rst new file mode 100644 index 00000000000..6ef4ed5af73 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-03-13-53-24.bpo-40854.O6vfQU.rst @@ -0,0 +1 @@ +Allow overriding :data:`sys.platlibdir` via a new :envvar:`PYTHONPLATLIBDIR` environment variable. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-05-12-48-28.bpo-40870.9cd2sk.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-05-12-48-28.bpo-40870.9cd2sk.rst new file mode 100644 index 00000000000..8e943a29f33 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-05-12-48-28.bpo-40870.9cd2sk.rst @@ -0,0 +1,2 @@ +Raise :exc:`ValueError` when validating custom AST's where the constants +``True``, ``False`` and ``None`` are used within a :class:`ast.Name` node. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-05-23-25-00.bpo-40883.M6sQ-Q.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-05-23-25-00.bpo-40883.M6sQ-Q.rst new file mode 100644 index 00000000000..ebeb0cc60d1 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-05-23-25-00.bpo-40883.M6sQ-Q.rst @@ -0,0 +1 @@ +Fix memory leak in when parsing f-strings in the new parser. Patch by Pablo Galindo \ No newline at end of file diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-06-00-23-19.bpo-40880.fjdzSh.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-06-00-23-19.bpo-40880.fjdzSh.rst new file mode 100644 index 00000000000..ab42f5c205f --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-06-00-23-19.bpo-40880.fjdzSh.rst @@ -0,0 +1,2 @@ +Fix invalid memory read in the new parser when checking newlines in string +literals. Patch by Pablo Galindo. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-07-22-50-10.bpo-40903.7dWejS.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-07-22-50-10.bpo-40903.7dWejS.rst new file mode 100644 index 00000000000..5ee72c14ad3 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-07-22-50-10.bpo-40903.7dWejS.rst @@ -0,0 +1 @@ +Fixed a possible segfault in the new PEG parser when producing error messages for invalid assignments of the form :code:`p=p=`. Patch by Pablo Galindo \ No newline at end of file diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-08-01-08-57.bpo-40904.76qQzo.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-08-01-08-57.bpo-40904.76qQzo.rst new file mode 100644 index 00000000000..09009b18c63 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-08-01-08-57.bpo-40904.76qQzo.rst @@ -0,0 +1,2 @@ +Fix possible segfault in the new PEG parser when parsing f-string containing +yield statements with no value (:code:`f"{yield}"`). Patch by Pablo Galindo diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-08-22-46-33.bpo-40889.vIBl-W.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-08-22-46-33.bpo-40889.vIBl-W.rst new file mode 100644 index 00000000000..0ab1a261e3e --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-08-22-46-33.bpo-40889.vIBl-W.rst @@ -0,0 +1 @@ +Improved the performance of symmetric difference operations on dictionary item views. Patch by Dennis Sweeney. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-09-00-20-13.bpo-40890.LoRV-g.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-09-00-20-13.bpo-40890.LoRV-g.rst new file mode 100644 index 00000000000..eaefc894a13 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-09-00-20-13.bpo-40890.LoRV-g.rst @@ -0,0 +1 @@ +Each dictionary view now has a ``mapping`` attribute that provides a :class:`types.MappingProxyType` wrapping the original dictionary. Patch contributed by Dennis Sweeney. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-09-23-52-32.bpo-40847.4XAACw.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-09-23-52-32.bpo-40847.4XAACw.rst new file mode 100644 index 00000000000..0b489f24832 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-09-23-52-32.bpo-40847.4XAACw.rst @@ -0,0 +1,4 @@ +Fix a bug where a line with only a line continuation character is not considered a blank line at tokenizer level. +In such cases, more than a single `NEWLINE` token was emitted. The old parser was working around the issue, +but the new parser threw a :exc:`SyntaxError` for valid input due to this. For example, an empty line following +a line continuation character was interpreted as a :exc:`SyntaxError`. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-10-11-27-15.bpo-40939.DO-wAI.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-10-11-27-15.bpo-40939.DO-wAI.rst new file mode 100644 index 00000000000..b12985d0816 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-10-11-27-15.bpo-40939.DO-wAI.rst @@ -0,0 +1 @@ +Remove the old parser, the :mod:`parser` module and all associated support code, command-line options and environment variables. Patch by Pablo Galindo. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-11-16-06-49.bpo-40947.72cZcR.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-11-16-06-49.bpo-40947.72cZcR.rst new file mode 100644 index 00000000000..e7dfe06531a --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-11-16-06-49.bpo-40947.72cZcR.rst @@ -0,0 +1,2 @@ +The Python :ref:`Path Configuration ` now takes +:c:member:`PyConfig.platlibdir` in account. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-12-00-12-28.bpo-40950.tzMy7m.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-12-00-12-28.bpo-40950.tzMy7m.rst new file mode 100644 index 00000000000..925b5790f73 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-12-00-12-28.bpo-40950.tzMy7m.rst @@ -0,0 +1,2 @@ +Add a state to the :mod:`nis` module (:pep:`3121`) and apply +the multiphase initialization. Patch by Dong-hee Na. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-12-12-21-54.bpo-40957.Z8n6I6.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-12-12-21-54.bpo-40957.Z8n6I6.rst new file mode 100644 index 00000000000..f99c374f94a --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-12-12-21-54.bpo-40957.Z8n6I6.rst @@ -0,0 +1 @@ +Fix refleak in _Py_fopen_obj() when PySys_Audit() fails diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-12-22-56-17.bpo-1635741.mmlp3Q.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-12-22-56-17.bpo-1635741.mmlp3Q.rst new file mode 100644 index 00000000000..ae12d25baa3 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-12-22-56-17.bpo-1635741.mmlp3Q.rst @@ -0,0 +1 @@ +Port :mod:`_dbm` to multiphase initialization. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-15-01-20-44.bpo-40958.7O2Wh1.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-15-01-20-44.bpo-40958.7O2Wh1.rst new file mode 100644 index 00000000000..8e36897948f --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-15-01-20-44.bpo-40958.7O2Wh1.rst @@ -0,0 +1,2 @@ +Fix a possible buffer overflow in the PEG parser when gathering information +for emitting syntax errors. Patch by Pablo Galindo. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-15-16-29-55.bpo-40985.IIN_xX.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-15-16-29-55.bpo-40985.IIN_xX.rst new file mode 100644 index 00000000000..e07134c7166 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-15-16-29-55.bpo-40985.IIN_xX.rst @@ -0,0 +1 @@ +Fix a bug that caused the :exc:`SyntaxError` text to be empty when a file ends with a line ending in a line continuation character (i.e. backslash). The error text should contain the text of the last line. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-17-00-52-21.bpo-1635741.61iyYh.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-17-00-52-21.bpo-1635741.61iyYh.rst new file mode 100644 index 00000000000..cffe70dd71e --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-17-00-52-21.bpo-1635741.61iyYh.rst @@ -0,0 +1 @@ +Port :mod:`_gdbm` to multiphase initialization. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-17-10-27-17.bpo-40636.MYaCIe.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-17-10-27-17.bpo-40636.MYaCIe.rst new file mode 100644 index 00000000000..ba26ad9373c --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-17-10-27-17.bpo-40636.MYaCIe.rst @@ -0,0 +1,3 @@ +:func:`zip` now supports :pep:`618`'s ``strict`` parameter, which raises a +:exc:`ValueError` if the arguments are exhausted at different lengths. +Patch by Brandt Bucher. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-18-00-07-09.bpo-41006.H-wN-d.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-18-00-07-09.bpo-41006.H-wN-d.rst new file mode 100644 index 00000000000..4593e6bb89a --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-18-00-07-09.bpo-41006.H-wN-d.rst @@ -0,0 +1,2 @@ +The ``encodings.latin_1`` module is no longer imported at startup. Now it is +only imported when it is the filesystem encoding or the stdio encoding. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-18-19-04-30.bpo-40077._yI-ax.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-18-19-04-30.bpo-40077._yI-ax.rst new file mode 100644 index 00000000000..2e0258a7b36 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-18-19-04-30.bpo-40077._yI-ax.rst @@ -0,0 +1 @@ +Convert :mod:`_bz2` to use :c:func:`PyType_FromSpec`. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-20-16-59-02.bpo-40939.6810Ak.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-20-16-59-02.bpo-40939.6810Ak.rst new file mode 100644 index 00000000000..8a626d479a9 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-20-16-59-02.bpo-40939.6810Ak.rst @@ -0,0 +1 @@ +Remove the remaining files from the old parser and the :mod:`symbol` module. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-20-17-00-44.bpo-35975.UDHCHp.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-20-17-00-44.bpo-35975.UDHCHp.rst new file mode 100644 index 00000000000..73f4a6da2e5 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-20-17-00-44.bpo-35975.UDHCHp.rst @@ -0,0 +1,3 @@ +Stefan Behnel reported that cf_feature_version is used even when +PyCF_ONLY_AST is not set. This is against the intention and against the +documented behavior, so it's been fixed. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-20-19-27-47.bpo-40939.jxJ4yn.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-20-19-27-47.bpo-40939.jxJ4yn.rst new file mode 100644 index 00000000000..7024dfe47ae --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-20-19-27-47.bpo-40939.jxJ4yn.rst @@ -0,0 +1 @@ +Rename `PyPegen*` functions to `PyParser*`, so that we can remove the old set of `PyParser*` functions that were using the old parser, but keep everything backwards-compatible. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-20-22-46-18.bpo-41052.46MPeF.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-20-22-46-18.bpo-41052.46MPeF.rst new file mode 100644 index 00000000000..82969bf4a78 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-20-22-46-18.bpo-41052.46MPeF.rst @@ -0,0 +1 @@ +Opt out serialization/deserialization for _random.Random diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-21-10-54-02.bpo-41061.AHf9MU.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-21-10-54-02.bpo-41061.AHf9MU.rst new file mode 100644 index 00000000000..b5bb81621b7 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-21-10-54-02.bpo-41061.AHf9MU.rst @@ -0,0 +1 @@ +Fix incorrect expressions and asserts in hashtable code and tests. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-21-19-53-33.bpo-41056.IDu_EK.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-21-19-53-33.bpo-41056.IDu_EK.rst new file mode 100644 index 00000000000..25f93c9da31 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-21-19-53-33.bpo-41056.IDu_EK.rst @@ -0,0 +1 @@ +Fixes a reference to deallocated stack space during startup when constructing sys.path involving a relative symlink when code was supplied via -c. (discovered via Coverity) \ No newline at end of file diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-22-13-22-30.bpo-41076.eWYw2N.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-22-13-22-30.bpo-41076.eWYw2N.rst new file mode 100644 index 00000000000..f13560ad9d2 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-22-13-22-30.bpo-41076.eWYw2N.rst @@ -0,0 +1 @@ +Pre-feed the parser with the location of the f-string expression, not the f-string itself, which allows us to skip the shifting of the AST node locations after the parsing is completed. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-23-07-35-11.bpo-40521.dMNA6k.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-23-07-35-11.bpo-40521.dMNA6k.rst new file mode 100644 index 00000000000..25f146e35ef --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-23-07-35-11.bpo-40521.dMNA6k.rst @@ -0,0 +1 @@ +Empty frozensets are no longer singletons. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-23-15-10-19.bpo-41084.pt3y7F.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-23-15-10-19.bpo-41084.pt3y7F.rst new file mode 100644 index 00000000000..cd349af770b --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-23-15-10-19.bpo-41084.pt3y7F.rst @@ -0,0 +1 @@ +Prefix the error message with 'f-string: ', when parsing an f-string expression which throws a :exc:`SyntaxError`. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-23-18-32-41.bpo-39960.Kez3fP.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-23-18-32-41.bpo-39960.Kez3fP.rst new file mode 100644 index 00000000000..f69fccfa4db --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-23-18-32-41.bpo-39960.Kez3fP.rst @@ -0,0 +1,2 @@ +The "hackcheck" that prevents sneaking around a type's __setattr__() by calling the +superclass method was rewritten to allow C implemented heap types. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-23-23-26-42.bpo-41094.zEIJse.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-23-23-26-42.bpo-41094.zEIJse.rst new file mode 100644 index 00000000000..6dd45e21d17 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-23-23-26-42.bpo-41094.zEIJse.rst @@ -0,0 +1,2 @@ +Fix decoding errors with audit when open files with non-ASCII names on non-UTF-8 +locale. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-30-04-44-29.bpo-41100.PJwA6F.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-30-04-44-29.bpo-41100.PJwA6F.rst new file mode 100644 index 00000000000..d6176d69f0e --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-30-04-44-29.bpo-41100.PJwA6F.rst @@ -0,0 +1 @@ +add arm64 to the allowable Mac OS arches in mpdecimal.h \ No newline at end of file diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-07-01-20-17-38.bpo-1635741.-AtPYu.rst b/Misc/NEWS.d/next/Core and Builtins/2020-07-01-20-17-38.bpo-1635741.-AtPYu.rst new file mode 100644 index 00000000000..c529923779f --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-07-01-20-17-38.bpo-1635741.-AtPYu.rst @@ -0,0 +1 @@ +Port :mod:`sha256` to multiphase initialization diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-07-03-23-10-02.bpo-1635741.F5coWe.rst b/Misc/NEWS.d/next/Core and Builtins/2020-07-03-23-10-02.bpo-1635741.F5coWe.rst new file mode 100644 index 00000000000..927c8e5b708 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-07-03-23-10-02.bpo-1635741.F5coWe.rst @@ -0,0 +1 @@ +Port :mod:`faulthandler` to multiphase initialization. diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-07-06-18-36-33.bpo-41215.vFGFIz.rst b/Misc/NEWS.d/next/Core and Builtins/2020-07-06-18-36-33.bpo-41215.vFGFIz.rst new file mode 100644 index 00000000000..7343da31e94 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-07-06-18-36-33.bpo-41215.vFGFIz.rst @@ -0,0 +1,2 @@ +Use non-NULL default values in the PEG parser keyword list to overcome a bug that was preventing +Python from being properly compiled when using the XLC compiler. Patch by Pablo Galindo. diff --git a/Misc/NEWS.d/next/IDLE/2020-05-29-18-21-58.bpo-39885.zB_-bN.rst b/Misc/NEWS.d/next/IDLE/2020-05-29-18-21-58.bpo-39885.zB_-bN.rst new file mode 100644 index 00000000000..a847b759971 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2020-05-29-18-21-58.bpo-39885.zB_-bN.rst @@ -0,0 +1,2 @@ +Make context menu Cut and Copy work again when right-clicking within a +selection. diff --git a/Misc/NEWS.d/next/IDLE/2020-06-27-17-02-00.bpo-41144.JoFGIX.rst b/Misc/NEWS.d/next/IDLE/2020-06-27-17-02-00.bpo-41144.JoFGIX.rst new file mode 100644 index 00000000000..ed558d3e7de --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2020-06-27-17-02-00.bpo-41144.JoFGIX.rst @@ -0,0 +1 @@ +Make Open Module open a special module such as os.path. diff --git a/Misc/NEWS.d/next/IDLE/2020-06-29-14-51-15.bpo-41152.d6mV0C.rst b/Misc/NEWS.d/next/IDLE/2020-06-29-14-51-15.bpo-41152.d6mV0C.rst new file mode 100644 index 00000000000..434be10b530 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2020-06-29-14-51-15.bpo-41152.d6mV0C.rst @@ -0,0 +1,2 @@ +The encoding of ``stdin``, ``stdout`` and ``stderr`` in IDLE is now always +UTF-8. diff --git a/Misc/NEWS.d/next/Library/2018-06-07-22-04-01.bpo-28557.ViNJnK.rst b/Misc/NEWS.d/next/Library/2018-06-07-22-04-01.bpo-28557.ViNJnK.rst new file mode 100644 index 00000000000..4137e2ff89b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-06-07-22-04-01.bpo-28557.ViNJnK.rst @@ -0,0 +1 @@ +Improve the error message for a misbehaving ``rawio.readinto`` diff --git a/Misc/NEWS.d/next/Library/2018-07-29-12-14-54.bpo-34226.BE7zbu.rst b/Misc/NEWS.d/next/Library/2018-07-29-12-14-54.bpo-34226.BE7zbu.rst new file mode 100644 index 00000000000..2656b4bf22a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-07-29-12-14-54.bpo-34226.BE7zbu.rst @@ -0,0 +1 @@ +Fix `cgi.parse_multipart` without content_length. Patch by Roger Duran diff --git a/Misc/NEWS.d/next/Library/2018-08-21-16-20-33.bpo-29620.xxx666.rst b/Misc/NEWS.d/next/Library/2018-08-21-16-20-33.bpo-29620.xxx666.rst new file mode 100644 index 00000000000..d781919504e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-08-21-16-20-33.bpo-29620.xxx666.rst @@ -0,0 +1,3 @@ +:func:`~unittest.TestCase.assertWarns` no longer raises a ``RuntimeException`` +when accessing a module's ``__warningregistry__`` causes importation of a new +module, or when a new module is imported in another thread. Patch by Kernc. diff --git a/Misc/NEWS.d/next/Library/2018-10-27-09-37-03.bpo-35078.kweA3R.rst b/Misc/NEWS.d/next/Library/2018-10-27-09-37-03.bpo-35078.kweA3R.rst new file mode 100644 index 00000000000..123f9dabde9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-10-27-09-37-03.bpo-35078.kweA3R.rst @@ -0,0 +1,3 @@ +Refactor formatweekday, formatmonthname methods in LocaleHTMLCalendar and LocaleTextCalendar classes in calendar module to call the base class methods.This enables customizable CSS classes for LocaleHTMLCalendar. +Patch by Srinivas Reddy Thatiparthy + diff --git a/Misc/NEWS.d/next/Library/2019-03-01-01-56-23.bpo-33944.-82Pkt.rst b/Misc/NEWS.d/next/Library/2019-03-01-01-56-23.bpo-33944.-82Pkt.rst new file mode 100644 index 00000000000..b0c953dd675 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-03-01-01-56-23.bpo-33944.-82Pkt.rst @@ -0,0 +1 @@ +Added site.py site-packages tracing in verbose mode. diff --git a/Misc/NEWS.d/next/Library/2019-08-11-16-28-03.bpo-26543.X-TJZO.rst b/Misc/NEWS.d/next/Library/2019-08-11-16-28-03.bpo-26543.X-TJZO.rst new file mode 100644 index 00000000000..8715b8d79ca --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-08-11-16-28-03.bpo-26543.X-TJZO.rst @@ -0,0 +1 @@ +Fix :meth:`IMAP4.noop()` when debug mode is enabled (ex: ``imaplib.Debug = 3``). diff --git a/Misc/NEWS.d/next/Library/2019-09-12-21-34-03.bpo-38144.8uQCdd.rst b/Misc/NEWS.d/next/Library/2019-09-12-21-34-03.bpo-38144.8uQCdd.rst new file mode 100644 index 00000000000..2c335bf29cf --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-09-12-21-34-03.bpo-38144.8uQCdd.rst @@ -0,0 +1 @@ +Added the *root_dir* and *dir_fd* parameters in :func:`glob.glob`. diff --git a/Misc/NEWS.d/next/Library/2019-12-15-18-47-20.bpo-39040.tKa0Qs.rst b/Misc/NEWS.d/next/Library/2019-12-15-18-47-20.bpo-39040.tKa0Qs.rst new file mode 100644 index 00000000000..078bce22be3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-12-15-18-47-20.bpo-39040.tKa0Qs.rst @@ -0,0 +1,2 @@ +Fix parsing of invalid mime headers parameters by collapsing whitespace between +encoded words in a bare-quote-string. diff --git a/Misc/NEWS.d/next/Library/2020-04-23-18-21-19.bpo-39385.MIAyS7.rst b/Misc/NEWS.d/next/Library/2020-04-23-18-21-19.bpo-39385.MIAyS7.rst new file mode 100644 index 00000000000..e6c5c0dd438 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-04-23-18-21-19.bpo-39385.MIAyS7.rst @@ -0,0 +1,3 @@ +A new test assertion context-manager, :func:`unittest.assertNoLogs` will +ensure a given block of code emits no log messages using the logging module. +Contributed by Kit Yan Choi. diff --git a/Misc/NEWS.d/next/Library/2020-05-06-02-01-25.bpo-13097.Wh5xSK.rst b/Misc/NEWS.d/next/Library/2020-05-06-02-01-25.bpo-13097.Wh5xSK.rst new file mode 100644 index 00000000000..a7f5f588289 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-06-02-01-25.bpo-13097.Wh5xSK.rst @@ -0,0 +1 @@ +``ctypes`` now raises an ``ArgumentError`` when a callback is invoked with more than 1024 arguments. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Library/2020-05-13-16-28-33.bpo-40611.ZCk0_c.rst b/Misc/NEWS.d/next/Library/2020-05-13-16-28-33.bpo-40611.ZCk0_c.rst new file mode 100644 index 00000000000..50ef3ad200a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-13-16-28-33.bpo-40611.ZCk0_c.rst @@ -0,0 +1 @@ +:data:`~mmap.MAP_POPULATE` constant has now been added to the list of exported :mod:`mmap` module flags. diff --git a/Misc/NEWS.d/next/Library/2020-05-15-13-40-15.bpo-40630.YXEX_M.rst b/Misc/NEWS.d/next/Library/2020-05-15-13-40-15.bpo-40630.YXEX_M.rst deleted file mode 100644 index bb2e7452d3c..00000000000 --- a/Misc/NEWS.d/next/Library/2020-05-15-13-40-15.bpo-40630.YXEX_M.rst +++ /dev/null @@ -1,2 +0,0 @@ -Added :func:`tracemalloc.reset_peak` to set the peak size of traced memory -blocks to the current size, to measure the peak of specific pieces of code. diff --git a/Misc/NEWS.d/next/Library/2020-05-15-21-14-45.bpo-36543.Jt-eSX.rst b/Misc/NEWS.d/next/Library/2020-05-15-21-14-45.bpo-36543.Jt-eSX.rst new file mode 100644 index 00000000000..468c1ac9eee --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-15-21-14-45.bpo-36543.Jt-eSX.rst @@ -0,0 +1 @@ +Restored the deprecated :mod:`xml.etree.cElementTree` module. diff --git a/Misc/NEWS.d/next/Library/2020-05-18-15-38-25.bpo-25920.PxrLY8.rst b/Misc/NEWS.d/next/Library/2020-05-18-15-38-25.bpo-25920.PxrLY8.rst new file mode 100644 index 00000000000..cc60e976286 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-18-15-38-25.bpo-25920.PxrLY8.rst @@ -0,0 +1,7 @@ +On macOS, when building Python for macOS 10.4 and older, which wasn't the case +for python.org macOS installer, :func:`socket.getaddrinfo` no longer uses an +internal lock to prevent race conditions when calling ``getaddrinfo()`` which +is thread-safe since macOS 10.5. Python 3.9 requires macOS 10.6 or newer. The +internal lock caused random hang on fork when another thread was calling +:func:`socket.getaddrinfo`. The lock was also used on FreeBSD older than 5.3, +OpenBSD older than 201311 and NetBSD older than 4. diff --git a/Misc/NEWS.d/next/Library/2020-05-18-17-29-30.bpo-40626.NeZufF.rst b/Misc/NEWS.d/next/Library/2020-05-18-17-29-30.bpo-40626.NeZufF.rst new file mode 100644 index 00000000000..fe652cd7ee3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-18-17-29-30.bpo-40626.NeZufF.rst @@ -0,0 +1 @@ +Add h5 file extension as MIME Type application/x-hdf5, as per HDF Group recommendation for HDF5 formatted data files. Patch contributed by Mark Schwab. diff --git a/Misc/NEWS.d/next/Library/2020-05-18-22-41-02.bpo-40614.8j3kmq.rst b/Misc/NEWS.d/next/Library/2020-05-18-22-41-02.bpo-40614.8j3kmq.rst new file mode 100644 index 00000000000..238b98c14a3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-18-22-41-02.bpo-40614.8j3kmq.rst @@ -0,0 +1 @@ +:func:`ast.parse` will not parse self documenting expressions in f-strings when passed ``feature_version`` is less than ``(3, 8)``. diff --git a/Misc/NEWS.d/next/Library/2020-05-23-04-18-00.bpo-37129.YoYoYo.rst b/Misc/NEWS.d/next/Library/2020-05-23-04-18-00.bpo-37129.YoYoYo.rst new file mode 100644 index 00000000000..e025e96f4f1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-23-04-18-00.bpo-37129.YoYoYo.rst @@ -0,0 +1 @@ +Add a new :data:`os.RWF_APPEND` flag for :func:`os.pwritev`. diff --git a/Misc/NEWS.d/next/Library/2020-05-24-23-52-35.bpo-40759.DdZdaw.rst b/Misc/NEWS.d/next/Library/2020-05-24-23-52-35.bpo-40759.DdZdaw.rst new file mode 100644 index 00000000000..e77da3ac3df --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-24-23-52-35.bpo-40759.DdZdaw.rst @@ -0,0 +1 @@ +Deprecate the :mod:`symbol` module. diff --git a/Misc/NEWS.d/next/Library/2020-05-25-11-52-23.bpo-30064.6CICsH.rst b/Misc/NEWS.d/next/Library/2020-05-25-11-52-23.bpo-30064.6CICsH.rst new file mode 100644 index 00000000000..904991dca16 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-25-11-52-23.bpo-30064.6CICsH.rst @@ -0,0 +1 @@ +Fix asyncio ``loop.sock_*`` race condition issue diff --git a/Misc/NEWS.d/next/Library/2020-05-25-22-18-38.bpo-30008.CKC3td.rst b/Misc/NEWS.d/next/Library/2020-05-25-22-18-38.bpo-30008.CKC3td.rst new file mode 100644 index 00000000000..c4cfa56ce02 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-25-22-18-38.bpo-30008.CKC3td.rst @@ -0,0 +1,2 @@ +Fix :mod:`ssl` code to be compatible with OpenSSL 1.1.x builds that use +``no-deprecated`` and ``--api=1.1.0``. diff --git a/Misc/NEWS.d/next/Library/2020-05-27-17-00-18.bpo-40795.eZSnHA.rst b/Misc/NEWS.d/next/Library/2020-05-27-17-00-18.bpo-40795.eZSnHA.rst new file mode 100644 index 00000000000..dd02fb05cab --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-27-17-00-18.bpo-40795.eZSnHA.rst @@ -0,0 +1,4 @@ +:mod:`ctypes` module: If ctypes fails to convert the result of a callback or +if a ctypes callback function raises an exception, sys.unraisablehook is now +called with an exception set. Previously, the error was logged into stderr +by :c:func:`PyErr_Print`. diff --git a/Misc/NEWS.d/next/Library/2020-05-27-18-04-52.bpo-40791.IzpNor.rst b/Misc/NEWS.d/next/Library/2020-05-27-18-04-52.bpo-40791.IzpNor.rst new file mode 100644 index 00000000000..b88f308ec3b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-27-18-04-52.bpo-40791.IzpNor.rst @@ -0,0 +1,2 @@ +:func:`hashlib.compare_digest` uses OpenSSL's ``CRYPTO_memcmp()`` function +when OpenSSL is available. diff --git a/Misc/NEWS.d/next/Library/2020-05-27-21-27-01.bpo-40767.L5MnVV.rst b/Misc/NEWS.d/next/Library/2020-05-27-21-27-01.bpo-40767.L5MnVV.rst new file mode 100644 index 00000000000..4bebb311b4d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-27-21-27-01.bpo-40767.L5MnVV.rst @@ -0,0 +1,3 @@ +:mod:`webbrowser` now properly finds the default browser in pure Wayland +systems by checking the WAYLAND_DISPLAY environment variable. Patch +contributed by Jérémy Attali. diff --git a/Misc/NEWS.d/next/Library/2020-05-27-22-19-42.bpo-40792.87Yx01.rst b/Misc/NEWS.d/next/Library/2020-05-27-22-19-42.bpo-40792.87Yx01.rst new file mode 100644 index 00000000000..032a96c6a5c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-27-22-19-42.bpo-40792.87Yx01.rst @@ -0,0 +1,2 @@ +The result of :func:`operator.index` now always has exact type :class:`int`. +Previously, the result could have been an instance of a subclass of ``int``. diff --git a/Misc/NEWS.d/next/Library/2020-05-28-16-51-00.bpo-38488.hFQNgA.rst b/Misc/NEWS.d/next/Library/2020-05-28-16-51-00.bpo-38488.hFQNgA.rst new file mode 100644 index 00000000000..c44da9fecb6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-28-16-51-00.bpo-38488.hFQNgA.rst @@ -0,0 +1 @@ +Update ensurepip to install pip 20.1.1 and setuptools 47.1.0. diff --git a/Misc/NEWS.d/next/Library/2020-05-28-17-32-29.bpo-40777.1kJU6N.rst b/Misc/NEWS.d/next/Library/2020-05-28-17-32-29.bpo-40777.1kJU6N.rst new file mode 100644 index 00000000000..761bc83562c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-28-17-32-29.bpo-40777.1kJU6N.rst @@ -0,0 +1,2 @@ +Initialize PyDateTime_IsoCalendarDateType.tp_base at run-time to avoid +errors on some compilers. diff --git a/Misc/NEWS.d/next/Library/2020-05-30-14-19-47.bpo-26407.MjWLO1.rst b/Misc/NEWS.d/next/Library/2020-05-30-14-19-47.bpo-26407.MjWLO1.rst new file mode 100644 index 00000000000..d0e45cf1b1f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-30-14-19-47.bpo-26407.MjWLO1.rst @@ -0,0 +1,3 @@ +Unexpected errors in calling the ``__iter__`` method are no longer masked +by ``TypeError`` in :func:`csv.reader`, :func:`csv.writer.writerow` and +:meth:`csv.writer.writerows`. diff --git a/Misc/NEWS.d/next/Library/2020-05-30-18-48-58.bpo-40755.IyOe2J.rst b/Misc/NEWS.d/next/Library/2020-05-30-18-48-58.bpo-40755.IyOe2J.rst new file mode 100644 index 00000000000..be5653ea58f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-30-18-48-58.bpo-40755.IyOe2J.rst @@ -0,0 +1 @@ +Add rich comparisons to collections.Counter(). diff --git a/Misc/NEWS.d/next/Library/2020-05-31-15-52-18.bpo-40834.MO9_hb.rst b/Misc/NEWS.d/next/Library/2020-05-31-15-52-18.bpo-40834.MO9_hb.rst new file mode 100644 index 00000000000..272783773ff --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-31-15-52-18.bpo-40834.MO9_hb.rst @@ -0,0 +1 @@ +Fix truncate when sending str object with_xxsubinterpreters.channel_send. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Library/2020-05-31-23-32-36.bpo-17005.JlRUGB.rst b/Misc/NEWS.d/next/Library/2020-05-31-23-32-36.bpo-17005.JlRUGB.rst new file mode 100644 index 00000000000..0fd01fb6230 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-31-23-32-36.bpo-17005.JlRUGB.rst @@ -0,0 +1,4 @@ +The topological sort functionality that was introduced initially in the +:mod:`functools` module has been moved to a new :mod:`graphlib` module to +better accommodate the new tools and keep the original scope of the +:mod:`functools` module. Patch by Pablo Galindo diff --git a/Misc/NEWS.d/next/Library/2020-06-01-02-16-29.bpo-39314.0T9hlA.rst b/Misc/NEWS.d/next/Library/2020-06-01-02-16-29.bpo-39314.0T9hlA.rst new file mode 100644 index 00000000000..e805332efb6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-01-02-16-29.bpo-39314.0T9hlA.rst @@ -0,0 +1,3 @@ +:class:`rlcompleter.Completer` and the standard Python shell now close the +parenthesis for functions that take no arguments. Patch contributed by Rémi +Lapeyre. diff --git a/Misc/NEWS.d/next/Library/2020-06-02-02-16-02.bpo-39791.StCJlA.rst b/Misc/NEWS.d/next/Library/2020-06-02-02-16-02.bpo-39791.StCJlA.rst new file mode 100644 index 00000000000..61753a57ca8 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-02-02-16-02.bpo-39791.StCJlA.rst @@ -0,0 +1 @@ +Built-in loaders (SourceFileLoader and ZipImporter) now supply ``TraversableResources`` implementations for ``ResourceReader``, and the fallback function has been removed. diff --git a/Misc/NEWS.d/next/Library/2020-06-02-23-49-07.bpo-32604.ZN4V4l.rst b/Misc/NEWS.d/next/Library/2020-06-02-23-49-07.bpo-32604.ZN4V4l.rst new file mode 100644 index 00000000000..6375276602e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-02-23-49-07.bpo-32604.ZN4V4l.rst @@ -0,0 +1,2 @@ +Fix reference leak in the :mod:`select` module when the the module is +imported in a subinterpreter. diff --git a/Misc/NEWS.d/next/Library/2020-06-04-16-25-15.bpo-40807.yYyLWx.rst b/Misc/NEWS.d/next/Library/2020-06-04-16-25-15.bpo-40807.yYyLWx.rst new file mode 100644 index 00000000000..532b809b77e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-04-16-25-15.bpo-40807.yYyLWx.rst @@ -0,0 +1,2 @@ +Stop codeop._maybe_compile, used by code.InteractiveInterpreter (and IDLE). +from from emitting each warning three times. diff --git a/Misc/NEWS.d/next/Library/2020-06-05-19-29-10.bpo-39791._CcO3d.rst b/Misc/NEWS.d/next/Library/2020-06-05-19-29-10.bpo-39791._CcO3d.rst new file mode 100644 index 00000000000..73e0cbb013f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-05-19-29-10.bpo-39791._CcO3d.rst @@ -0,0 +1 @@ +Refresh importlib.metadata from importlib_metadata 1.6.1. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Library/2020-06-05-20-00-18.bpo-40876.zDhiZj.rst b/Misc/NEWS.d/next/Library/2020-06-05-20-00-18.bpo-40876.zDhiZj.rst new file mode 100644 index 00000000000..75f62addbab --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-05-20-00-18.bpo-40876.zDhiZj.rst @@ -0,0 +1 @@ +Clarify error message in the :mod:`csv` module. diff --git a/Misc/NEWS.d/next/Library/2020-06-06-02-42-26.bpo-40884.n7fOwS.rst b/Misc/NEWS.d/next/Library/2020-06-06-02-42-26.bpo-40884.n7fOwS.rst new file mode 100644 index 00000000000..64990e8023f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-06-02-42-26.bpo-40884.n7fOwS.rst @@ -0,0 +1,3 @@ +Added a `defaults` parameter to :class:`logging.Formatter`, to allow +specifying default values for custom fields. Patch by Asaf Alon and Bar +Harel. diff --git a/Misc/NEWS.d/next/Library/2020-06-08-18-59-16.bpo-23427.ilg1Cz.rst b/Misc/NEWS.d/next/Library/2020-06-08-18-59-16.bpo-23427.ilg1Cz.rst new file mode 100644 index 00000000000..37382975bb4 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-08-18-59-16.bpo-23427.ilg1Cz.rst @@ -0,0 +1,2 @@ +Add :data:`sys.orig_argv` attribute: the list of the original command line +arguments passed to the Python executable. diff --git a/Misc/NEWS.d/next/Library/2020-06-11-11-07-10.bpo-40939.-D5Asl.rst b/Misc/NEWS.d/next/Library/2020-06-11-11-07-10.bpo-40939.-D5Asl.rst new file mode 100644 index 00000000000..0e831129dd8 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-11-11-07-10.bpo-40939.-D5Asl.rst @@ -0,0 +1 @@ +Use the new PEG parser when generating the stdlib :mod:`keyword` module. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Library/2020-06-12-10-44-15.bpo-40855.jSot83.rst b/Misc/NEWS.d/next/Library/2020-06-12-10-44-15.bpo-40855.jSot83.rst new file mode 100644 index 00000000000..201d510327a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-12-10-44-15.bpo-40855.jSot83.rst @@ -0,0 +1,2 @@ +The standard deviation and variance functions in the statistics module were +ignoring their mu and xbar arguments. diff --git a/Misc/NEWS.d/next/Library/2020-06-12-11-55-30.bpo-40955.huixCg.rst b/Misc/NEWS.d/next/Library/2020-06-12-11-55-30.bpo-40955.huixCg.rst new file mode 100644 index 00000000000..9a9803044ec --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-12-11-55-30.bpo-40955.huixCg.rst @@ -0,0 +1 @@ +Fix a minor memory leak in :mod:`subprocess` module when extra_groups was specified. diff --git a/Misc/NEWS.d/next/Library/2020-06-13-12-04-50.bpo-40924.SM_luS.rst b/Misc/NEWS.d/next/Library/2020-06-13-12-04-50.bpo-40924.SM_luS.rst new file mode 100644 index 00000000000..4e4c6e88ac5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-13-12-04-50.bpo-40924.SM_luS.rst @@ -0,0 +1,3 @@ +Ensure ``importlib.resources.path`` returns an extant path for the +SourceFileLoader's resource reader. Avoids the regression identified in +master while a long-term solution is devised. diff --git a/Misc/NEWS.d/next/Library/2020-06-15-00-13-57.bpo-40967._dx3OO.rst b/Misc/NEWS.d/next/Library/2020-06-15-00-13-57.bpo-40967._dx3OO.rst new file mode 100644 index 00000000000..4694d991bab --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-15-00-13-57.bpo-40967._dx3OO.rst @@ -0,0 +1,2 @@ +Removed :meth:`asyncio.Task.current_task` and +:meth:`asyncio.Task.all_tasks`. Patch contributed by Rémi Lapeyre. diff --git a/Misc/NEWS.d/next/Library/2020-06-15-12-22-53.bpo-40448.1dk8Bu.rst b/Misc/NEWS.d/next/Library/2020-06-15-12-22-53.bpo-40448.1dk8Bu.rst new file mode 100644 index 00000000000..a755c5faa67 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-15-12-22-53.bpo-40448.1dk8Bu.rst @@ -0,0 +1,2 @@ +:mod:`ensurepip` now disables the use of `pip` cache when installing the +bundled versions of `pip` and `setuptools`. Patch by Krzysztof Konopko. diff --git a/Misc/NEWS.d/next/Library/2020-06-17-17-26-24.bpo-41002.NPBItE.rst b/Misc/NEWS.d/next/Library/2020-06-17-17-26-24.bpo-41002.NPBItE.rst new file mode 100644 index 00000000000..c3eebb7b9ae --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-17-17-26-24.bpo-41002.NPBItE.rst @@ -0,0 +1 @@ +Improve performance of HTTPResponse.read with a given amount. Patch by Bruce Merry. diff --git a/Misc/NEWS.d/next/Library/2020-06-20-00-19-30.bpo-41043.p-Pk-H.rst b/Misc/NEWS.d/next/Library/2020-06-20-00-19-30.bpo-41043.p-Pk-H.rst new file mode 100644 index 00000000000..9c6020eb8d7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-20-00-19-30.bpo-41043.p-Pk-H.rst @@ -0,0 +1,2 @@ +Fixed the use of :func:`~glob.glob` in the stdlib: literal part of the path +is now always correctly escaped. diff --git a/Misc/NEWS.d/next/Library/2020-06-20-10-16-57.bpo-41048.hEXB-B.rst b/Misc/NEWS.d/next/Library/2020-06-20-10-16-57.bpo-41048.hEXB-B.rst new file mode 100644 index 00000000000..2595900137d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-20-10-16-57.bpo-41048.hEXB-B.rst @@ -0,0 +1,2 @@ +:func:`mimetypes.read_mime_types` function reads the rule file using UTF-8 encoding, not the locale encoding. +Patch by Srinivas Reddy Thatiparthy. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Library/2020-06-20-18-33-03.bpo-41056.gTH4Bq.rst b/Misc/NEWS.d/next/Library/2020-06-20-18-33-03.bpo-41056.gTH4Bq.rst new file mode 100644 index 00000000000..0439d82a50a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-20-18-33-03.bpo-41056.gTH4Bq.rst @@ -0,0 +1 @@ +Fixed an instance where a MemoryError within the zoneinfo module might not be reported or not reported at its source. (found by Coverity) \ No newline at end of file diff --git a/Misc/NEWS.d/next/Library/2020-06-20-18-35-43.bpo-41056.Garcle.rst b/Misc/NEWS.d/next/Library/2020-06-20-18-35-43.bpo-41056.Garcle.rst new file mode 100644 index 00000000000..1776f0d1cf8 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-20-18-35-43.bpo-41056.Garcle.rst @@ -0,0 +1 @@ +Fix a NULL pointer dereference within the ssl module during a MemoryError in the keylog callback. (discovered by Coverity) \ No newline at end of file diff --git a/Misc/NEWS.d/next/Library/2020-06-20-18-37-29.bpo-41056.d9v_uL.rst b/Misc/NEWS.d/next/Library/2020-06-20-18-37-29.bpo-41056.d9v_uL.rst new file mode 100644 index 00000000000..ddcc1102d5e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-20-18-37-29.bpo-41056.d9v_uL.rst @@ -0,0 +1 @@ +Invalid file descriptor values are now prevented from being passed to os.fpathconf. (discovered by Coverity) \ No newline at end of file diff --git a/Misc/NEWS.d/next/Library/2020-06-20-21-03-55.bpo-41058.gztdZy.rst b/Misc/NEWS.d/next/Library/2020-06-20-21-03-55.bpo-41058.gztdZy.rst new file mode 100644 index 00000000000..6ac90098aa5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-20-21-03-55.bpo-41058.gztdZy.rst @@ -0,0 +1 @@ +:func:`pdb.find_function` now correctly determines the source file encoding. diff --git a/Misc/NEWS.d/next/Library/2020-06-22-10-25-39.bpo-41068._bX2BW.rst b/Misc/NEWS.d/next/Library/2020-06-22-10-25-39.bpo-41068._bX2BW.rst new file mode 100644 index 00000000000..20580c7886f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-22-10-25-39.bpo-41068._bX2BW.rst @@ -0,0 +1,2 @@ +Fixed reading files with non-ASCII names from ZIP archive directly after +writing them. diff --git a/Misc/NEWS.d/next/Library/2020-06-22-20-08-40.bpo-31938.EVuko9.rst b/Misc/NEWS.d/next/Library/2020-06-22-20-08-40.bpo-31938.EVuko9.rst new file mode 100644 index 00000000000..0488e94d42e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-22-20-08-40.bpo-31938.EVuko9.rst @@ -0,0 +1 @@ +Fix default-value signatures of several functions in the :mod:`select` module - by Anthony Sottile. diff --git a/Misc/NEWS.d/next/Library/2020-06-23-06-09-59.bpo-40521.HUfxP7.rst b/Misc/NEWS.d/next/Library/2020-06-23-06-09-59.bpo-40521.HUfxP7.rst new file mode 100644 index 00000000000..7689a1470b0 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-23-06-09-59.bpo-40521.HUfxP7.rst @@ -0,0 +1 @@ +Remove freelist from collections.deque(). diff --git a/Misc/NEWS.d/next/Library/2020-06-25-10-11-47.bpo-31082.HsgDkx.rst b/Misc/NEWS.d/next/Library/2020-06-25-10-11-47.bpo-31082.HsgDkx.rst new file mode 100644 index 00000000000..9746d33a496 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-25-10-11-47.bpo-31082.HsgDkx.rst @@ -0,0 +1 @@ +Use the term "iterable" in the docstring for :func:`functools.reduce`. diff --git a/Misc/NEWS.d/next/Library/2020-06-27-13-51-36.bpo-41138.bIpf7g.rst b/Misc/NEWS.d/next/Library/2020-06-27-13-51-36.bpo-41138.bIpf7g.rst new file mode 100644 index 00000000000..839d430e89b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-27-13-51-36.bpo-41138.bIpf7g.rst @@ -0,0 +1,2 @@ +Fixed the :mod:`trace` module CLI for Python source files with non-UTF-8 +encoding. diff --git a/Misc/NEWS.d/next/Library/2020-06-28-21-16-51.bpo-40874.YImvzA.rst b/Misc/NEWS.d/next/Library/2020-06-28-21-16-51.bpo-40874.YImvzA.rst new file mode 100644 index 00000000000..a43eab8f4dc --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-28-21-16-51.bpo-40874.YImvzA.rst @@ -0,0 +1 @@ +The decimal module now requires libmpdec-2.5.0. diff --git a/Misc/NEWS.d/next/Library/2020-06-30-20-50-51.bpo-41161.QTdJjz.rst b/Misc/NEWS.d/next/Library/2020-06-30-20-50-51.bpo-41161.QTdJjz.rst new file mode 100644 index 00000000000..0d8fb521bad --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-30-20-50-51.bpo-41161.QTdJjz.rst @@ -0,0 +1,2 @@ +The decimal module now requires libmpdec-2.5.0. Users of +--with-system-libmpdec should update their system library. diff --git a/Misc/NEWS.d/next/Library/2020-07-02-11-53-45.bpo-41193.8-Tnql.rst b/Misc/NEWS.d/next/Library/2020-07-02-11-53-45.bpo-41193.8-Tnql.rst new file mode 100644 index 00000000000..8807d9c21fe --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-07-02-11-53-45.bpo-41193.8-Tnql.rst @@ -0,0 +1,4 @@ +The ``write_history()`` atexit function of the readline completer now +ignores any :exc:`OSError` to ignore error if the filesystem is read-only, +instead of only ignoring :exc:`FileNotFoundError` and +:exc:`PermissionError`. diff --git a/Misc/NEWS.d/next/Library/2020-07-03-13-15-08.bpo-41194.djrKjs.rst b/Misc/NEWS.d/next/Library/2020-07-03-13-15-08.bpo-41194.djrKjs.rst new file mode 100644 index 00000000000..d63a0e5222b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-07-03-13-15-08.bpo-41194.djrKjs.rst @@ -0,0 +1,2 @@ +Fix a crash in the ``_ast`` module: it can no longer be loaded more than once. +It now uses a global state rather than a module state. diff --git a/Misc/NEWS.d/next/Library/2020-07-04-21-56-46.bpo-39168.DQWsXj.rst b/Misc/NEWS.d/next/Library/2020-07-04-21-56-46.bpo-39168.DQWsXj.rst new file mode 100644 index 00000000000..667885eccd9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-07-04-21-56-46.bpo-39168.DQWsXj.rst @@ -0,0 +1 @@ +Remove the ``__new__`` method of :class:`typing.Generic`. diff --git a/Misc/NEWS.d/next/Library/2020-07-05-19-16-02.bpo-29727.Q6Z2rg.rst b/Misc/NEWS.d/next/Library/2020-07-05-19-16-02.bpo-29727.Q6Z2rg.rst new file mode 100644 index 00000000000..85cfa4f8938 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-07-05-19-16-02.bpo-29727.Q6Z2rg.rst @@ -0,0 +1,2 @@ +Register :class:`array.array` as a +:class:`~collections.abc.MutableSequence`. Patch by Pablo Galindo. diff --git a/Misc/NEWS.d/next/Security/2020-06-29-16-02-29.bpo-41004.ovF0KZ.rst b/Misc/NEWS.d/next/Security/2020-06-29-16-02-29.bpo-41004.ovF0KZ.rst new file mode 100644 index 00000000000..1380b31fbe9 --- /dev/null +++ b/Misc/NEWS.d/next/Security/2020-06-29-16-02-29.bpo-41004.ovF0KZ.rst @@ -0,0 +1 @@ +The __hash__() methods of ipaddress.IPv4Interface and ipaddress.IPv6Interface incorrectly generated constant hash values of 32 and 128 respectively. This resulted in always causing hash collisions. The fix uses hash() to generate hash values for the tuple of (address, mask length, network address). diff --git a/Misc/NEWS.d/next/Security/2020-07-03-17-21-37.bpo-29778.cR_fGS.rst b/Misc/NEWS.d/next/Security/2020-07-03-17-21-37.bpo-29778.cR_fGS.rst new file mode 100644 index 00000000000..998ffb1ee66 --- /dev/null +++ b/Misc/NEWS.d/next/Security/2020-07-03-17-21-37.bpo-29778.cR_fGS.rst @@ -0,0 +1,2 @@ +Ensure :file:`python3.dll` is loaded from correct locations when Python is +embedded (CVE-2020-15523). diff --git a/Misc/NEWS.d/next/Security/2020-07-03-20-41-29.bpo-41162.tb8pVj.rst b/Misc/NEWS.d/next/Security/2020-07-03-20-41-29.bpo-41162.tb8pVj.rst new file mode 100644 index 00000000000..f0333ac4a7b --- /dev/null +++ b/Misc/NEWS.d/next/Security/2020-07-03-20-41-29.bpo-41162.tb8pVj.rst @@ -0,0 +1 @@ +Audit hooks are now cleared later during finalization to avoid missing events. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Tests/2018-08-20-09-38-52.bpo-34401.eGxMPm.rst b/Misc/NEWS.d/next/Tests/2018-08-20-09-38-52.bpo-34401.eGxMPm.rst new file mode 100644 index 00000000000..1b28d94c056 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2018-08-20-09-38-52.bpo-34401.eGxMPm.rst @@ -0,0 +1 @@ +Make test_gdb properly run on HP-UX. Patch by Michael Osipov. diff --git a/Misc/NEWS.d/next/Tests/2020-05-26-07-53-31.bpo-17258.X_IKTQ.rst b/Misc/NEWS.d/next/Tests/2020-05-26-07-53-31.bpo-17258.X_IKTQ.rst new file mode 100644 index 00000000000..0a4b329b802 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2020-05-26-07-53-31.bpo-17258.X_IKTQ.rst @@ -0,0 +1 @@ +Skip some :mod:`multiprocessing` tests when MD5 hash digest is blocked. diff --git a/Misc/NEWS.d/next/Tests/2020-06-09-18-48-18.bpo-40927.67ylLg.rst b/Misc/NEWS.d/next/Tests/2020-06-09-18-48-18.bpo-40927.67ylLg.rst new file mode 100644 index 00000000000..66209b84c94 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2020-06-09-18-48-18.bpo-40927.67ylLg.rst @@ -0,0 +1,2 @@ +Fix test_binhex when run twice: it now uses import_fresh_module() to ensure +that it raises DeprecationWarning each time. diff --git a/Misc/NEWS.d/next/Tests/2020-06-12-20-46-23.bpo-40964.OBzf2c.rst b/Misc/NEWS.d/next/Tests/2020-06-12-20-46-23.bpo-40964.OBzf2c.rst new file mode 100644 index 00000000000..abfe4f0da43 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2020-06-12-20-46-23.bpo-40964.OBzf2c.rst @@ -0,0 +1,2 @@ +Disable remote :mod:`imaplib` tests, host cyrus.andrew.cmu.edu is blocking +incoming connections. diff --git a/Misc/NEWS.d/next/Tests/2020-06-17-15-07-14.bpo-41003.tiH_Fy.rst b/Misc/NEWS.d/next/Tests/2020-06-17-15-07-14.bpo-41003.tiH_Fy.rst new file mode 100644 index 00000000000..6f908d99fea --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2020-06-17-15-07-14.bpo-41003.tiH_Fy.rst @@ -0,0 +1,3 @@ +Fix ``test_copyreg`` when ``numpy`` is installed: ``test.pickletester`` now +saves/restores warnings filters when importing ``numpy``, to ignore filters +installed by ``numpy``. diff --git a/Misc/NEWS.d/next/Tests/2020-06-17-17-27-07.bpo-41009.Rvn6OQ.rst b/Misc/NEWS.d/next/Tests/2020-06-17-17-27-07.bpo-41009.Rvn6OQ.rst new file mode 100644 index 00000000000..1208c119a35 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2020-06-17-17-27-07.bpo-41009.Rvn6OQ.rst @@ -0,0 +1,2 @@ +Fix use of ``support.require_{linux|mac|freebsd}_version()`` decorators as +class decorator. diff --git a/Misc/NEWS.d/next/Tests/2020-06-17-18-00-21.bpo-38377.jfg4TH.rst b/Misc/NEWS.d/next/Tests/2020-06-17-18-00-21.bpo-38377.jfg4TH.rst new file mode 100644 index 00000000000..11a30761d36 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2020-06-17-18-00-21.bpo-38377.jfg4TH.rst @@ -0,0 +1,4 @@ +On Linux, skip tests using multiprocessing if the current user cannot create +a file in ``/dev/shm/`` directory. Add the +:func:`~test.support.skip_if_broken_multiprocessing_synchronize` function to +the :mod:`test.support` module. diff --git a/Misc/NEWS.d/next/Tests/2020-06-22-00-21-12.bpo-41069.bLZkX-.rst b/Misc/NEWS.d/next/Tests/2020-06-22-00-21-12.bpo-41069.bLZkX-.rst new file mode 100644 index 00000000000..14bbd1a39a4 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2020-06-22-00-21-12.bpo-41069.bLZkX-.rst @@ -0,0 +1,2 @@ +:data:`test.support.TESTFN` and the current directory for tests when run via +``test.regrtest`` contain now non-ascii characters if possible. diff --git a/Misc/NEWS.d/next/Tests/2020-06-23-12-02-45.bpo-41085.JZKsyz.rst b/Misc/NEWS.d/next/Tests/2020-06-23-12-02-45.bpo-41085.JZKsyz.rst new file mode 100644 index 00000000000..463dffdd653 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2020-06-23-12-02-45.bpo-41085.JZKsyz.rst @@ -0,0 +1,2 @@ +Fix integer overflow in the :meth:`array.array.index` method on 64-bit Windows +for index larger than ``2**31``. diff --git a/Misc/NEWS.d/next/Windows/2019-07-11-06-11-09.bpo-37556.sygMUU.rst b/Misc/NEWS.d/next/Windows/2019-07-11-06-11-09.bpo-37556.sygMUU.rst new file mode 100644 index 00000000000..e8af96421b8 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2019-07-11-06-11-09.bpo-37556.sygMUU.rst @@ -0,0 +1 @@ +Extend py.exe help to mention overrides via venv, shebang, environmental variables & ini files. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Windows/2020-06-12-13-13-44.bpo-40164.SPrSn5.rst b/Misc/NEWS.d/next/Windows/2020-06-12-13-13-44.bpo-40164.SPrSn5.rst new file mode 100644 index 00000000000..6390de717d7 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2020-06-12-13-13-44.bpo-40164.SPrSn5.rst @@ -0,0 +1 @@ +Updates Windows OpenSSL to 1.1.1g \ No newline at end of file diff --git a/Misc/NEWS.d/next/Windows/2020-06-23-03-12-57.bpo-41039.0hgd0s.rst b/Misc/NEWS.d/next/Windows/2020-06-23-03-12-57.bpo-41039.0hgd0s.rst new file mode 100644 index 00000000000..acc3f7441f1 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2020-06-23-03-12-57.bpo-41039.0hgd0s.rst @@ -0,0 +1,2 @@ +Stable ABI redirection DLL (python3.dll) now uses ``#pragma +comment(linker)`` for re-exporting. diff --git a/Misc/NEWS.d/next/Windows/2020-06-24-21-30-42.bpo-41074.gaQc3C.rst b/Misc/NEWS.d/next/Windows/2020-06-24-21-30-42.bpo-41074.gaQc3C.rst new file mode 100644 index 00000000000..ec91fd361c3 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2020-06-24-21-30-42.bpo-41074.gaQc3C.rst @@ -0,0 +1,3 @@ +Fixed support of non-ASCII names in functions :func:`msilib.OpenDatabase` +and :func:`msilib.init_database` and non-ASCII SQL in method +:meth:`msilib.Database.OpenView`. diff --git a/Misc/NEWS.d/next/Windows/2020-06-28-12-40-41.bpo-41142.jpZzzh.rst b/Misc/NEWS.d/next/Windows/2020-06-28-12-40-41.bpo-41142.jpZzzh.rst new file mode 100644 index 00000000000..91406da7a25 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2020-06-28-12-40-41.bpo-41142.jpZzzh.rst @@ -0,0 +1,2 @@ +:mod:`msilib` now supports creating CAB files with non-ASCII file path and +adding files with non-ASCII file path to them. diff --git a/Misc/NEWS.d/next/macOS/2020-06-07-20-10-56.bpo-40741.80A2BW.rst b/Misc/NEWS.d/next/macOS/2020-06-07-20-10-56.bpo-40741.80A2BW.rst new file mode 100644 index 00000000000..6ff7b9a805b --- /dev/null +++ b/Misc/NEWS.d/next/macOS/2020-06-07-20-10-56.bpo-40741.80A2BW.rst @@ -0,0 +1 @@ +Update macOS installer to use SQLite 3.32.2. diff --git a/Misc/NEWS.d/next/macOS/2020-06-17-13-45-15.bpo-41005.zZegdV.rst b/Misc/NEWS.d/next/macOS/2020-06-17-13-45-15.bpo-41005.zZegdV.rst new file mode 100644 index 00000000000..3b5f3f23a12 --- /dev/null +++ b/Misc/NEWS.d/next/macOS/2020-06-17-13-45-15.bpo-41005.zZegdV.rst @@ -0,0 +1 @@ +fixed an XDG settings issue not allowing macos to open browser in webbrowser.py \ No newline at end of file diff --git a/Misc/NEWS.d/next/macOS/2020-06-24-13-51-57.bpo-41100.mcHdc5.rst b/Misc/NEWS.d/next/macOS/2020-06-24-13-51-57.bpo-41100.mcHdc5.rst new file mode 100644 index 00000000000..d6bb6161366 --- /dev/null +++ b/Misc/NEWS.d/next/macOS/2020-06-24-13-51-57.bpo-41100.mcHdc5.rst @@ -0,0 +1,7 @@ +Fix configure error when building on macOS 11. +Note that the current Python release was released +shortly after the first developer preview of macOS +11 (Big Sur); there are other known issues with +building and running on the developer preview. +Big Sur is expected to be fully supported in a +future bugfix release of Python 3.8.x and with 3.9.0. \ No newline at end of file diff --git a/Misc/NEWS.d/next/macOS/2020-06-25-06-09-00.bpo-39580.N_vJ9h.rst b/Misc/NEWS.d/next/macOS/2020-06-25-06-09-00.bpo-39580.N_vJ9h.rst new file mode 100644 index 00000000000..95d65359804 --- /dev/null +++ b/Misc/NEWS.d/next/macOS/2020-06-25-06-09-00.bpo-39580.N_vJ9h.rst @@ -0,0 +1,2 @@ +Avoid opening Finder window if running installer from the command line. +Patch contributed by Rick Heil. diff --git a/Misc/python.man b/Misc/python.man index 89a15a5e7b2..74b2d72939e 100644 --- a/Misc/python.man +++ b/Misc/python.man @@ -413,6 +413,8 @@ inserted in the path in front of $PYTHONPATH. The search path can be manipulated from within a Python program as the variable .IR sys.path . +.IP PYTHONPLATLIBDIR +Override sys.platlibdir. .IP PYTHONSTARTUP If this is the name of a readable file, the Python commands in that file are executed before the first prompt is displayed in interactive diff --git a/Modules/Setup b/Modules/Setup index 02cfb67518d..470bf6bc2ef 100644 --- a/Modules/Setup +++ b/Modules/Setup @@ -134,9 +134,6 @@ faulthandler faulthandler.c # can call _PyTraceMalloc_NewReference(). _tracemalloc _tracemalloc.c -# PEG-based parser module -- slated to be *the* parser -_peg_parser _peg_parser.c - # The rest of the modules listed in this file are all commented out by # default. Usually they can be detected and built as dynamically # loaded modules by the new setup.py script added in Python 2.1. If @@ -183,7 +180,7 @@ _symtable symtablemodule.c #_datetime _datetimemodule.c # datetime accelerator #_zoneinfo _zoneinfo.c # zoneinfo accelerator #_bisect _bisectmodule.c # Bisection algorithms -#_heapq _heapqmodule.c # Heap queue algorithm +#_heapq _heapqmodule.c -DPy_BUILD_CORE_MODULE # Heap queue algorithm #_asyncio _asynciomodule.c # Fast asyncio Future #_json -I$(srcdir)/Include/internal -DPy_BUILD_CORE_BUILTIN _json.c # _json speedups #_statistics _statisticsmodule.c # statistics accelerator @@ -331,10 +328,6 @@ _symtable symtablemodule.c # Helper module for various ascii-encoders #binascii binascii.c -# Fred Drake's interface to the Python parser -#parser parsermodule.c - - # Andrew Kuchling's zlib module. # This require zlib 1.1.3 (or later). # See http://www.gzip.org/zlib/ diff --git a/Modules/_abc.c b/Modules/_abc.c index 434bc454175..709b52ff96b 100644 --- a/Modules/_abc.c +++ b/Modules/_abc.c @@ -46,6 +46,7 @@ typedef struct { static int abc_data_traverse(_abc_data *self, visitproc visit, void *arg) { + Py_VISIT(Py_TYPE(self)); Py_VISIT(self->_abc_registry); Py_VISIT(self->_abc_cache); Py_VISIT(self->_abc_negative_cache); diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 0608c40f6c3..b378742648b 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -13,10 +13,8 @@ module _asyncio _Py_IDENTIFIER(__asyncio_running_event_loop__); _Py_IDENTIFIER(_asyncio_future_blocking); _Py_IDENTIFIER(add_done_callback); -_Py_IDENTIFIER(_all_tasks_compat); _Py_IDENTIFIER(call_soon); _Py_IDENTIFIER(cancel); -_Py_IDENTIFIER(current_task); _Py_IDENTIFIER(get_event_loop); _Py_IDENTIFIER(send); _Py_IDENTIFIER(throw); @@ -710,6 +708,7 @@ future_add_done_callback(FutureObj *fut, PyObject *arg, PyObject *ctx) else { fut->fut_callbacks = PyList_New(1); if (fut->fut_callbacks == NULL) { + Py_DECREF(tup); return NULL; } @@ -2181,91 +2180,6 @@ TaskObj_get_fut_waiter(TaskObj *task, void *Py_UNUSED(ignored)) Py_RETURN_NONE; } -/*[clinic input] -@classmethod -_asyncio.Task.current_task - - loop: object = None - -Return the currently running task in an event loop or None. - -By default the current task for the current event loop is returned. - -None is returned when called not in the context of a Task. -[clinic start generated code]*/ - -static PyObject * -_asyncio_Task_current_task_impl(PyTypeObject *type, PyObject *loop) -/*[clinic end generated code: output=99fbe7332c516e03 input=cd14770c5b79c7eb]*/ -{ - PyObject *ret; - PyObject *current_task_func; - - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Task.current_task() is deprecated, " \ - "use asyncio.current_task() instead", - 1) < 0) { - return NULL; - } - - current_task_func = _PyObject_GetAttrId(asyncio_mod, &PyId_current_task); - if (current_task_func == NULL) { - return NULL; - } - - if (loop == Py_None) { - loop = get_event_loop(); - if (loop == NULL) { - Py_DECREF(current_task_func); - return NULL; - } - ret = PyObject_CallOneArg(current_task_func, loop); - Py_DECREF(current_task_func); - Py_DECREF(loop); - return ret; - } - else { - ret = PyObject_CallOneArg(current_task_func, loop); - Py_DECREF(current_task_func); - return ret; - } -} - -/*[clinic input] -@classmethod -_asyncio.Task.all_tasks - - loop: object = None - -Return a set of all tasks for an event loop. - -By default all tasks for the current event loop are returned. -[clinic start generated code]*/ - -static PyObject * -_asyncio_Task_all_tasks_impl(PyTypeObject *type, PyObject *loop) -/*[clinic end generated code: output=11f9b20749ccca5d input=497f80bc9ce726b5]*/ -{ - PyObject *res; - PyObject *all_tasks_func; - - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Task.all_tasks() is deprecated, " \ - "use asyncio.all_tasks() instead", - 1) < 0) { - return NULL; - } - - all_tasks_func = _PyObject_GetAttrId(asyncio_mod, &PyId__all_tasks_compat); - if (all_tasks_func == NULL) { - return NULL; - } - - res = PyObject_CallOneArg(all_tasks_func, loop); - Py_DECREF(all_tasks_func); - return res; -} - /*[clinic input] _asyncio.Task._make_cancelled_error @@ -2586,8 +2500,6 @@ static PyMethodDef TaskType_methods[] = { _ASYNCIO_FUTURE_DONE_METHODDEF _ASYNCIO_TASK_SET_RESULT_METHODDEF _ASYNCIO_TASK_SET_EXCEPTION_METHODDEF - _ASYNCIO_TASK_CURRENT_TASK_METHODDEF - _ASYNCIO_TASK_ALL_TASKS_METHODDEF _ASYNCIO_TASK_CANCEL_METHODDEF _ASYNCIO_TASK_GET_STACK_METHODDEF _ASYNCIO_TASK_PRINT_STACK_METHODDEF diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c index 880632c6234..effb0de2e65 100644 --- a/Modules/_bz2module.c +++ b/Modules/_bz2module.c @@ -28,6 +28,19 @@ #define RELEASE_LOCK(obj) PyThread_release_lock((obj)->lock) +typedef struct { + PyTypeObject *bz2_compressor_type; + PyTypeObject *bz2_decompressor_type; +} _bz2_state; + +static inline _bz2_state* +get_bz2_state(PyObject *module) +{ + void *state = PyModule_GetState(module); + assert(state != NULL); + return (_bz2_state *)state; +} + typedef struct { PyObject_HEAD bz_stream bzs; @@ -51,9 +64,6 @@ typedef struct { PyThread_type_lock lock; } BZ2Decompressor; -static PyTypeObject BZ2Compressor_Type; -static PyTypeObject BZ2Decompressor_Type; - /* Helper functions. */ static int @@ -262,6 +272,21 @@ _bz2_BZ2Compressor_flush_impl(BZ2Compressor *self) return result; } +/*[clinic input] +_bz2.BZ2Compressor.__reduce__ + +[clinic start generated code]*/ + +static PyObject * +_bz2_BZ2Compressor___reduce___impl(BZ2Compressor *self) +/*[clinic end generated code: output=d13db66ae043e141 input=e09bccef0e6731b2]*/ +{ + PyErr_Format(PyExc_TypeError, + "cannot pickle %s object", + Py_TYPE(self)->tp_name); + return NULL; +} + static void* BZ2_Malloc(void* ctx, int items, int size) { @@ -280,21 +305,11 @@ BZ2_Free(void* ctx, void *ptr) PyMem_RawFree(ptr); } -/*[clinic input] -_bz2.BZ2Compressor.__init__ - - compresslevel: int = 9 - Compression level, as a number between 1 and 9. - / - -Create a compressor object for compressing data incrementally. - -For one-shot compression, use the compress() function instead. -[clinic start generated code]*/ +/* Argument Clinic is not used since the Argument Clinic always want to + check the type which would be wrong here */ static int _bz2_BZ2Compressor___init___impl(BZ2Compressor *self, int compresslevel) -/*[clinic end generated code: output=c4e6adfd02963827 input=4e1ff7b8394b6e9a]*/ { int bzerror; @@ -325,63 +340,89 @@ error: return -1; } +PyDoc_STRVAR(_bz2_BZ2Compressor___init____doc__, +"BZ2Compressor(compresslevel=9, /)\n" +"--\n" +"\n" +"Create a compressor object for compressing data incrementally.\n" +"\n" +" compresslevel\n" +" Compression level, as a number between 1 and 9.\n" +"\n" +"For one-shot compression, use the compress() function instead."); + +static int +_bz2_BZ2Compressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) +{ + int return_value = -1; + int compresslevel = 9; + + if (!_PyArg_NoKeywords("BZ2Compressor", kwargs)) { + goto exit; + } + if (!_PyArg_CheckPositional("BZ2Compressor", PyTuple_GET_SIZE(args), 0, 1)) { + goto exit; + } + if (PyTuple_GET_SIZE(args) < 1) { + goto skip_optional; + } + compresslevel = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0)); + if (compresslevel == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: + return_value = _bz2_BZ2Compressor___init___impl((BZ2Compressor *)self, compresslevel); + +exit: + return return_value; +} + static void BZ2Compressor_dealloc(BZ2Compressor *self) { BZ2_bzCompressEnd(&self->bzs); - if (self->lock != NULL) + if (self->lock != NULL) { PyThread_free_lock(self->lock); - Py_TYPE(self)->tp_free((PyObject *)self); + } + PyTypeObject *tp = Py_TYPE(self); + tp->tp_free((PyObject *)self); + Py_DECREF(tp); +} + +static int +BZ2Compressor_traverse(BZ2Compressor *self, visitproc visit, void *arg) +{ + Py_VISIT(Py_TYPE(self)); + return 0; } static PyMethodDef BZ2Compressor_methods[] = { _BZ2_BZ2COMPRESSOR_COMPRESS_METHODDEF _BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF + _BZ2_BZ2COMPRESSOR___REDUCE___METHODDEF {NULL} }; - -static PyTypeObject BZ2Compressor_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_bz2.BZ2Compressor", /* tp_name */ - sizeof(BZ2Compressor), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)BZ2Compressor_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_as_async */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - _bz2_BZ2Compressor___init____doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BZ2Compressor_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - _bz2_BZ2Compressor___init__, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ +static PyType_Slot bz2_compressor_type_slots[] = { + {Py_tp_dealloc, BZ2Compressor_dealloc}, + {Py_tp_methods, BZ2Compressor_methods}, + {Py_tp_init, _bz2_BZ2Compressor___init__}, + {Py_tp_new, PyType_GenericNew}, + {Py_tp_doc, (char *)_bz2_BZ2Compressor___init____doc__}, + {Py_tp_traverse, BZ2Compressor_traverse}, + {0, 0} }; +static PyType_Spec bz2_compressor_type_spec = { + .name = "_bz2.BZ2Compressor", + .basicsize = sizeof(BZ2Compressor), + // Calling PyType_GetModuleState() on a subclass is not safe. + // bz2_compressor_type_spec does not have Py_TPFLAGS_BASETYPE flag + // which prevents to create a subclass. + // So calling PyType_GetModuleState() in this file is always safe. + .flags = Py_TPFLAGS_DEFAULT, + .slots = bz2_compressor_type_slots, +}; /* BZ2Decompressor class. */ @@ -602,16 +643,24 @@ _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data, } /*[clinic input] -_bz2.BZ2Decompressor.__init__ +_bz2.BZ2Decompressor.__reduce__ -Create a decompressor object for decompressing data incrementally. - -For one-shot decompression, use the decompress() function instead. [clinic start generated code]*/ +static PyObject * +_bz2_BZ2Decompressor___reduce___impl(BZ2Decompressor *self) +/*[clinic end generated code: output=f6a40650813f482e input=8db9175a609fdd43]*/ +{ + PyErr_Format(PyExc_TypeError, + "cannot pickle %s object", + Py_TYPE(self)->tp_name); + return NULL; +} + +/* Argument Clinic is not used since the Argument Clinic always want to + check the type which would be wrong here */ static int _bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self) -/*[clinic end generated code: output=e4d2b9bb866ab8f1 input=95f6500dcda60088]*/ { int bzerror; @@ -646,20 +695,58 @@ error: return -1; } +static int +_bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) +{ + int return_value = -1; + + if (!_PyArg_NoPositional("BZ2Decompressor", args)) { + goto exit; + } + if (!_PyArg_NoKeywords("BZ2Decompressor", kwargs)) { + goto exit; + } + return_value = _bz2_BZ2Decompressor___init___impl((BZ2Decompressor *)self); + +exit: + return return_value; +} + +PyDoc_STRVAR(_bz2_BZ2Decompressor___init____doc__, +"BZ2Decompressor()\n" +"--\n" +"\n" +"Create a decompressor object for decompressing data incrementally.\n" +"\n" +"For one-shot decompression, use the decompress() function instead."); + static void BZ2Decompressor_dealloc(BZ2Decompressor *self) { - if(self->input_buffer != NULL) + if(self->input_buffer != NULL) { PyMem_Free(self->input_buffer); + } BZ2_bzDecompressEnd(&self->bzs); Py_CLEAR(self->unused_data); - if (self->lock != NULL) + if (self->lock != NULL) { PyThread_free_lock(self->lock); - Py_TYPE(self)->tp_free((PyObject *)self); + } + + PyTypeObject *tp = Py_TYPE(self); + tp->tp_free((PyObject *)self); + Py_DECREF(tp); +} + +static int +BZ2Decompressor_traverse(BZ2Decompressor *self, visitproc visit, void *arg) +{ + Py_VISIT(Py_TYPE(self)); + return 0; } static PyMethodDef BZ2Decompressor_methods[] = { _BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF + _BZ2_BZ2DECOMPRESSOR___REDUCE___METHODDEF {NULL} }; @@ -682,64 +769,81 @@ static PyMemberDef BZ2Decompressor_members[] = { {NULL} }; -static PyTypeObject BZ2Decompressor_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_bz2.BZ2Decompressor", /* tp_name */ - sizeof(BZ2Decompressor), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)BZ2Decompressor_dealloc,/* tp_dealloc */ - 0, /* tp_vectorcall_offset */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_as_async */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - _bz2_BZ2Decompressor___init____doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BZ2Decompressor_methods, /* tp_methods */ - BZ2Decompressor_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - _bz2_BZ2Decompressor___init__, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ +static PyType_Slot bz2_decompressor_type_slots[] = { + {Py_tp_dealloc, BZ2Decompressor_dealloc}, + {Py_tp_methods, BZ2Decompressor_methods}, + {Py_tp_init, _bz2_BZ2Decompressor___init__}, + {Py_tp_doc, (char *)_bz2_BZ2Decompressor___init____doc__}, + {Py_tp_members, BZ2Decompressor_members}, + {Py_tp_new, PyType_GenericNew}, + {Py_tp_traverse, BZ2Decompressor_traverse}, + {0, 0} }; +static PyType_Spec bz2_decompressor_type_spec = { + .name = "_bz2.BZ2Decompressor", + .basicsize = sizeof(BZ2Decompressor), + // Calling PyType_GetModuleState() on a subclass is not safe. + // bz2_decompressor_type_spec does not have Py_TPFLAGS_BASETYPE flag + // which prevents to create a subclass. + // So calling PyType_GetModuleState() in this file is always safe. + .flags = Py_TPFLAGS_DEFAULT, + .slots = bz2_decompressor_type_slots, +}; /* Module initialization. */ static int _bz2_exec(PyObject *module) { - if (PyModule_AddType(module, &BZ2Compressor_Type) < 0) { + _bz2_state *state = get_bz2_state(module); + state->bz2_compressor_type = (PyTypeObject *)PyType_FromModuleAndSpec(module, + &bz2_compressor_type_spec, NULL); + if (state->bz2_compressor_type == NULL) { return -1; } - if (PyModule_AddType(module, &BZ2Decompressor_Type) < 0) { + if (PyModule_AddType(module, state->bz2_compressor_type) < 0) { + return -1; + } + + state->bz2_decompressor_type = (PyTypeObject *)PyType_FromModuleAndSpec(module, + &bz2_decompressor_type_spec, NULL); + if (state->bz2_decompressor_type == NULL) { + return -1; + } + + if (PyModule_AddType(module, state->bz2_decompressor_type) < 0) { return -1; } return 0; } +static int +_bz2_traverse(PyObject *module, visitproc visit, void *arg) +{ + _bz2_state *state = get_bz2_state(module); + Py_VISIT(state->bz2_compressor_type); + Py_VISIT(state->bz2_decompressor_type); + return 0; +} + +static int +_bz2_clear(PyObject *module) +{ + _bz2_state *state = get_bz2_state(module); + Py_CLEAR(state->bz2_compressor_type); + Py_CLEAR(state->bz2_decompressor_type); + return 0; +} + +static void +_bz2_free(void *module) +{ + _bz2_clear((PyObject *)module); +} + static struct PyModuleDef_Slot _bz2_slots[] = { {Py_mod_exec, _bz2_exec}, {0, NULL} @@ -747,14 +851,12 @@ static struct PyModuleDef_Slot _bz2_slots[] = { static struct PyModuleDef _bz2module = { PyModuleDef_HEAD_INIT, - "_bz2", - NULL, - 0, - NULL, - _bz2_slots, - NULL, - NULL, - NULL + .m_name = "_bz2", + .m_size = sizeof(_bz2_state), + .m_slots = _bz2_slots, + .m_traverse = _bz2_traverse, + .m_clear = _bz2_clear, + .m_free = _bz2_free, }; PyMODINIT_FUNC diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 7120e4dda0e..00198ff3eb7 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -117,23 +117,9 @@ static PyTypeObject deque_type; #define CHECK_NOT_END(link) #endif -/* A simple freelisting scheme is used to minimize calls to the memory - allocator. It accommodates common use cases where new blocks are being - added at about the same rate as old blocks are being freed. - */ - -#define MAXFREEBLOCKS 16 -static Py_ssize_t numfreeblocks = 0; -static block *freeblocks[MAXFREEBLOCKS]; - static block * newblock(void) { - block *b; - if (numfreeblocks) { - numfreeblocks--; - return freeblocks[numfreeblocks]; - } - b = PyMem_Malloc(sizeof(block)); + block *b = PyMem_Malloc(sizeof(block)); if (b != NULL) { return b; } @@ -144,12 +130,7 @@ newblock(void) { static void freeblock(block *b) { - if (numfreeblocks < MAXFREEBLOCKS) { - freeblocks[numfreeblocks] = b; - numfreeblocks++; - } else { - PyMem_Free(b); - } + PyMem_Free(b); } static PyObject * diff --git a/Modules/_csv.c b/Modules/_csv.c index 3a52632ccfd..da61db9377f 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -112,8 +112,6 @@ typedef struct { static PyTypeObject Reader_Type; -#define ReaderObject_Check(v) Py_IS_TYPE(v, &Reader_Type) - typedef struct { PyObject_HEAD @@ -148,13 +146,6 @@ get_dialect_from_registry(PyObject * name_obj) return dialect_obj; } -static PyObject * -get_string(PyObject *str) -{ - Py_XINCREF(str); - return str; -} - static PyObject * get_nullchar_as_None(Py_UCS4 c) { @@ -168,7 +159,8 @@ get_nullchar_as_None(Py_UCS4 c) static PyObject * Dialect_get_lineterminator(DialectObj *self, void *Py_UNUSED(ignored)) { - return get_string(self->lineterminator); + Py_XINCREF(self->lineterminator); + return self->lineterminator; } static PyObject * @@ -812,7 +804,7 @@ Reader_iternext(ReaderObj *self) PyErr_Format(_csvstate_global->error_obj, "iterator should return strings, " "not %.200s " - "(did you open the file in text mode?)", + "(the file should be opened in text mode)", Py_TYPE(lineobj)->tp_name ); Py_DECREF(lineobj); @@ -964,8 +956,6 @@ csv_reader(PyObject *module, PyObject *args, PyObject *keyword_args) } self->input_iter = PyObject_GetIter(iterator); if (self->input_iter == NULL) { - PyErr_SetString(PyExc_TypeError, - "argument 1 must be an iterator"); Py_DECREF(self); return NULL; } @@ -1171,10 +1161,14 @@ csv_writerow(WriterObj *self, PyObject *seq) PyObject *iter, *field, *line, *result; iter = PyObject_GetIter(seq); - if (iter == NULL) - return PyErr_Format(_csvstate_global->error_obj, - "iterable expected, not %.200s", - Py_TYPE(seq)->tp_name); + if (iter == NULL) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) { + PyErr_Format(_csvstate_global->error_obj, + "iterable expected, not %.200s", + Py_TYPE(seq)->tp_name); + } + return NULL; + } /* Join all fields in internal buffer. */ @@ -1264,8 +1258,6 @@ csv_writerows(WriterObj *self, PyObject *seqseq) row_iter = PyObject_GetIter(seqseq); if (row_iter == NULL) { - PyErr_SetString(PyExc_TypeError, - "writerows() argument must be iterable"); return NULL; } while ((row_obj = PyIter_Next(row_iter))) { diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index 2b903c98e8e..2abfa67cdc0 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -84,7 +84,7 @@ PrintError(const char *msg, ...) va_list marker; va_start(marker, msg); - vsnprintf(buf, sizeof(buf), msg, marker); + PyOS_vsnprintf(buf, sizeof(buf), msg, marker); va_end(marker); if (f != NULL && f != Py_None) PyFile_WriteString(buf, f); @@ -213,9 +213,6 @@ static void _CallPythonObject(void *mem, pArgs++; } -#define CHECK(what, x) \ -if (x == NULL) _PyTraceback_Add(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_Print() - if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) { error_object = _ctypes_get_errobj(&space); if (error_object == NULL) @@ -235,7 +232,10 @@ if (x == NULL) _PyTraceback_Add(what, "_ctypes/callbacks.c", __LINE__ - 1), PyEr } result = PyObject_CallObject(callable, arglist); - CHECK("'calling callback function'", result); + if (result == NULL) { + _PyErr_WriteUnraisableMsg("on calling ctypes callback function", + callable); + } #ifdef MS_WIN32 if (flags & FUNCFLAG_USE_LASTERROR) { @@ -251,16 +251,17 @@ if (x == NULL) _PyTraceback_Add(what, "_ctypes/callbacks.c", __LINE__ - 1), PyEr } Py_XDECREF(error_object); - if ((restype != &ffi_type_void) && result) { - PyObject *keep; + if (restype != &ffi_type_void && result) { assert(setfunc); + #ifdef WORDS_BIGENDIAN - /* See the corresponding code in callproc.c, around line 961 */ - if (restype->type != FFI_TYPE_FLOAT && restype->size < sizeof(ffi_arg)) + /* See the corresponding code in _ctypes_callproc(): + in callproc.c, around line 1219. */ + if (restype->type != FFI_TYPE_FLOAT && restype->size < sizeof(ffi_arg)) { mem = (char *)mem + sizeof(ffi_arg) - restype->size; + } #endif - keep = setfunc(mem, result, 0); - CHECK("'converting callback result'", keep); + /* keep is an object we have to keep alive so that the result stays valid. If there is no such object, the setfunc will have returned Py_None. @@ -270,18 +271,32 @@ if (x == NULL) _PyTraceback_Add(what, "_ctypes/callbacks.c", __LINE__ - 1), PyEr be the result. EXCEPT when restype is py_object - Python itself knows how to manage the refcount of these objects. */ - if (keep == NULL) /* Could not convert callback result. */ - PyErr_WriteUnraisable(callable); - else if (keep == Py_None) /* Nothing to keep */ + PyObject *keep = setfunc(mem, result, 0); + + if (keep == NULL) { + /* Could not convert callback result. */ + _PyErr_WriteUnraisableMsg("on converting result " + "of ctypes callback function", + callable); + } + else if (keep == Py_None) { + /* Nothing to keep */ Py_DECREF(keep); + } else if (setfunc != _ctypes_get_fielddesc("O")->setfunc) { if (-1 == PyErr_WarnEx(PyExc_RuntimeWarning, "memory leak in callback function.", 1)) - PyErr_WriteUnraisable(callable); + { + _PyErr_WriteUnraisableMsg("on converting result " + "of ctypes callback function", + callable); + } } } + Py_XDECREF(result); + Done: Py_XDECREF(arglist); PyGILState_Release(state); diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 5c1ecabd816..6030cc3d436 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -1072,6 +1072,14 @@ GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk) #define IS_PASS_BY_REF(x) (x > 8 || !POW2(x)) #endif +/* + * bpo-13097: Max number of arguments _ctypes_callproc will accept. + * + * This limit is enforced for the `alloca()` call in `_ctypes_callproc`, + * to avoid allocating a massive buffer on the stack. + */ +#define CTYPES_MAX_ARGCOUNT 1024 + /* * Requirements, must be ensured by the caller: * - argtuple is tuple of arguments @@ -1107,6 +1115,13 @@ PyObject *_ctypes_callproc(PPROC pProc, ++argcount; #endif + if (argcount > CTYPES_MAX_ARGCOUNT) + { + PyErr_Format(PyExc_ArgError, "too many arguments (%zi), maximum is %i", + argcount, CTYPES_MAX_ARGCOUNT); + return NULL; + } + args = (struct argument *)alloca(sizeof(struct argument) * argcount); if (!args) { PyErr_NoMemory(); @@ -1216,7 +1231,9 @@ PyObject *_ctypes_callproc(PPROC pProc, if (rtype->type != FFI_TYPE_FLOAT && rtype->type != FFI_TYPE_STRUCT && rtype->size < sizeof(ffi_arg)) + { resbuf = (char *)resbuf + sizeof(ffi_arg) - rtype->size; + } #endif #ifdef MS_WIN32 @@ -1398,15 +1415,12 @@ static PyObject *py_dl_open(PyObject *self, PyObject *args) if (name != Py_None) { if (PyUnicode_FSConverter(name, &name2) == 0) return NULL; - if (PyBytes_Check(name2)) - name_str = PyBytes_AS_STRING(name2); - else - name_str = PyByteArray_AS_STRING(name2); + name_str = PyBytes_AS_STRING(name2); } else { name_str = NULL; name2 = NULL; } - if (PySys_Audit("ctypes.dlopen", "s", name_str) < 0) { + if (PySys_Audit("ctypes.dlopen", "O", name) < 0) { return NULL; } handle = ctypes_dlopen(name_str, mode); diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 7f853190a78..3a9b7119201 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -1,5 +1,5 @@ #include "Python.h" -#include "pycore_byteswap.h" // _Py_bswap32() +#include "pycore_bitutils.h" // _Py_bswap32() #include #ifdef MS_WIN32 @@ -1263,7 +1263,9 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length) } data = PyBytes_AS_STRING(value); - size = strlen(data); /* XXX Why not Py_SIZE(value)? */ + // bpo-39593: Use strlen() to truncate the string at the first null character. + size = strlen(data); + if (size < length) { /* This will copy the terminating NUL character * if there is space for it. diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c index 7ca91f64161..f124803493d 100644 --- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -39,6 +39,7 @@ _curses_panel_clear(PyObject *m) static int _curses_panel_traverse(PyObject *m, visitproc visit, void *arg) { + Py_VISIT(Py_TYPE(m)); Py_VISIT(get_curses_panelstate(m)->PyCursesError); return 0; } diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 7a5efd23b9e..74a54e74ae0 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -8,6 +8,7 @@ #define _PY_DATETIME_IMPL #include "Python.h" +#include "pycore_object.h" // _PyObject_Init() #include "datetime.h" #include "structmember.h" // PyMemberDef @@ -638,30 +639,24 @@ normalize_datetime(int *year, int *month, int *day, static PyObject * time_alloc(PyTypeObject *type, Py_ssize_t aware) { - PyObject *self; - - self = (PyObject *) - PyObject_MALLOC(aware ? - sizeof(PyDateTime_Time) : - sizeof(_PyDateTime_BaseTime)); - if (self == NULL) - return (PyObject *)PyErr_NoMemory(); - (void)PyObject_INIT(self, type); + size_t size = aware ? sizeof(PyDateTime_Time) : sizeof(_PyDateTime_BaseTime); + PyObject *self = (PyObject *)PyObject_Malloc(size); + if (self == NULL) { + return PyErr_NoMemory(); + } + _PyObject_Init(self, type); return self; } static PyObject * datetime_alloc(PyTypeObject *type, Py_ssize_t aware) { - PyObject *self; - - self = (PyObject *) - PyObject_MALLOC(aware ? - sizeof(PyDateTime_DateTime) : - sizeof(_PyDateTime_BaseDateTime)); - if (self == NULL) - return (PyObject *)PyErr_NoMemory(); - (void)PyObject_INIT(self, type); + size_t size = aware ? sizeof(PyDateTime_DateTime) : sizeof(_PyDateTime_BaseDateTime); + PyObject *self = (PyObject *)PyObject_Malloc(size); + if (self == NULL) { + return PyErr_NoMemory(); + } + _PyObject_Init(self, type); return self; } @@ -3325,7 +3320,7 @@ static PyTypeObject PyDateTime_IsoCalendarDateType = { .tp_doc = iso_calendar_date__doc__, .tp_methods = iso_calendar_date_methods, .tp_getset = iso_calendar_date_getset, - .tp_base = &PyTuple_Type, + // .tp_base = &PyTuple_Type, // filled in PyInit__datetime .tp_new = iso_calendar_date_new, }; @@ -4079,7 +4074,7 @@ static PyTypeObject PyDateTime_TimeZoneType = { timezone_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - &PyDateTime_TZInfoType, /* tp_base */ + 0, /* tp_base; filled in PyInit__datetime */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -6458,7 +6453,8 @@ static PyTypeObject PyDateTime_DateTimeType = { datetime_methods, /* tp_methods */ 0, /* tp_members */ datetime_getset, /* tp_getset */ - &PyDateTime_DateType, /* tp_base */ + 0, /* tp_base; filled in + PyInit__datetime */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -6524,6 +6520,12 @@ PyInit__datetime(void) if (m == NULL) return NULL; + // `&...` is not a constant expression according to a strict reading + // of C standards. Fill tp_base at run-time rather than statically. + // See https://bugs.python.org/issue40777 + PyDateTime_IsoCalendarDateType.tp_base = &PyTuple_Type; + PyDateTime_TimeZoneType.tp_base = &PyDateTime_TZInfoType; + PyDateTime_DateTimeType.tp_base = &PyDateTime_DateType; PyTypeObject *types[] = { &PyDateTime_DateType, diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c index 80a0503622c..97772a04d08 100644 --- a/Modules/_dbmmodule.c +++ b/Modules/_dbmmodule.c @@ -28,6 +28,19 @@ static const char which_dbm[] = "Berkeley DB"; #error "No ndbm.h available!" #endif +typedef struct { + PyTypeObject *dbm_type; + PyObject *dbm_error; +} _dbm_state; + +static inline _dbm_state* +get_dbm_state(PyObject *module) +{ + void *state = PyModule_GetState(module); + assert(state != NULL); + return (_dbm_state *)state; +} + /*[clinic input] module _dbm class _dbm.dbm "dbmobject *" "&Dbmtype" @@ -43,28 +56,25 @@ typedef struct { #include "clinic/_dbmmodule.c.h" -static PyTypeObject Dbmtype; - -#define is_dbmobject(v) Py_IS_TYPE(v, &Dbmtype) -#define check_dbmobject_open(v) if ((v)->di_dbm == NULL) \ - { PyErr_SetString(DbmError, "DBM object has already been closed"); \ - return NULL; } - -static PyObject *DbmError; +#define check_dbmobject_open(v, err) \ + if ((v)->di_dbm == NULL) { \ + PyErr_SetString(err, "DBM object has already been closed"); \ + return NULL; \ + } static PyObject * -newdbmobject(const char *file, int flags, int mode) +newdbmobject(_dbm_state *state, const char *file, int flags, int mode) { dbmobject *dp; - dp = PyObject_New(dbmobject, &Dbmtype); + dp = PyObject_New(dbmobject, state->dbm_type); if (dp == NULL) return NULL; dp->di_size = -1; dp->flags = flags; /* See issue #19296 */ if ( (dp->di_dbm = dbm_open((char *)file, flags, mode)) == 0 ) { - PyErr_SetFromErrnoWithFilename(DbmError, file); + PyErr_SetFromErrnoWithFilename(state->dbm_error, file); Py_DECREF(dp); return NULL; } @@ -76,16 +86,21 @@ newdbmobject(const char *file, int flags, int mode) static void dbm_dealloc(dbmobject *dp) { - if ( dp->di_dbm ) + if (dp->di_dbm) { dbm_close(dp->di_dbm); - PyObject_Del(dp); + } + PyTypeObject *tp = Py_TYPE(dp); + tp->tp_free(dp); + Py_DECREF(tp); } static Py_ssize_t dbm_length(dbmobject *dp) { + _dbm_state *state = PyType_GetModuleState(Py_TYPE(dp)); + assert(state != NULL); if (dp->di_dbm == NULL) { - PyErr_SetString(DbmError, "DBM object has already been closed"); + PyErr_SetString(state->dbm_error, "DBM object has already been closed"); return -1; } if ( dp->di_size < 0 ) { @@ -106,12 +121,14 @@ dbm_subscript(dbmobject *dp, PyObject *key) { datum drec, krec; Py_ssize_t tmp_size; - - if (!PyArg_Parse(key, "s#", &krec.dptr, &tmp_size) ) + _dbm_state *state = PyType_GetModuleState(Py_TYPE(dp)); + assert(state != NULL); + if (!PyArg_Parse(key, "s#", &krec.dptr, &tmp_size)) { return NULL; + } krec.dsize = tmp_size; - check_dbmobject_open(dp); + check_dbmobject_open(dp, state->dbm_error); drec = dbm_fetch(dp->di_dbm, krec); if ( drec.dptr == 0 ) { PyErr_SetObject(PyExc_KeyError, key); @@ -119,7 +136,7 @@ dbm_subscript(dbmobject *dp, PyObject *key) } if ( dbm_error(dp->di_dbm) ) { dbm_clearerr(dp->di_dbm); - PyErr_SetString(DbmError, ""); + PyErr_SetString(state->dbm_error, ""); return NULL; } return PyBytes_FromStringAndSize(drec.dptr, drec.dsize); @@ -136,9 +153,11 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w) "dbm mappings have bytes or string keys only"); return -1; } + _dbm_state *state = PyType_GetModuleState(Py_TYPE(dp)); + assert(state != NULL); krec.dsize = tmp_size; if (dp->di_dbm == NULL) { - PyErr_SetString(DbmError, "DBM object has already been closed"); + PyErr_SetString(state->dbm_error, "DBM object has already been closed"); return -1; } dp->di_size = -1; @@ -151,7 +170,7 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w) PyErr_SetObject(PyExc_KeyError, v); } else { - PyErr_SetString(DbmError, "cannot delete item from database"); + PyErr_SetString(state->dbm_error, "cannot delete item from database"); } return -1; } @@ -164,25 +183,19 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w) drec.dsize = tmp_size; if ( dbm_store(dp->di_dbm, krec, drec, DBM_REPLACE) < 0 ) { dbm_clearerr(dp->di_dbm); - PyErr_SetString(DbmError, + PyErr_SetString(state->dbm_error, "cannot add item to database"); return -1; } } if ( dbm_error(dp->di_dbm) ) { dbm_clearerr(dp->di_dbm); - PyErr_SetString(DbmError, ""); + PyErr_SetString(state->dbm_error, ""); return -1; } return 0; } -static PyMappingMethods dbm_as_mapping = { - (lenfunc)dbm_length, /*mp_length*/ - (binaryfunc)dbm_subscript, /*mp_subscript*/ - (objobjargproc)dbm_ass_sub, /*mp_ass_subscript*/ -}; - /*[clinic input] _dbm.dbm.close @@ -193,8 +206,9 @@ static PyObject * _dbm_dbm_close_impl(dbmobject *self) /*[clinic end generated code: output=c8dc5b6709600b86 input=046db72377d51be8]*/ { - if (self->di_dbm) + if (self->di_dbm) { dbm_close(self->di_dbm); + } self->di_dbm = NULL; Py_RETURN_NONE; } @@ -202,21 +216,26 @@ _dbm_dbm_close_impl(dbmobject *self) /*[clinic input] _dbm.dbm.keys + cls: defining_class + Return a list of all keys in the database. [clinic start generated code]*/ static PyObject * -_dbm_dbm_keys_impl(dbmobject *self) -/*[clinic end generated code: output=434549f7c121b33c input=d210ba778cd9c68a]*/ +_dbm_dbm_keys_impl(dbmobject *self, PyTypeObject *cls) +/*[clinic end generated code: output=f2a593b3038e5996 input=d3706a28fc051097]*/ { PyObject *v, *item; datum key; int err; - check_dbmobject_open(self); + _dbm_state *state = PyType_GetModuleState(cls); + assert(state != NULL); + check_dbmobject_open(self, state->dbm_error); v = PyList_New(0); - if (v == NULL) + if (v == NULL) { return NULL; + } for (key = dbm_firstkey(self->di_dbm); key.dptr; key = dbm_nextkey(self->di_dbm)) { item = PyBytes_FromStringAndSize(key.dptr, key.dsize); @@ -241,8 +260,10 @@ dbm_contains(PyObject *self, PyObject *arg) datum key, val; Py_ssize_t size; + _dbm_state *state = PyType_GetModuleState(Py_TYPE(dp)); + assert(state != NULL); if ((dp)->di_dbm == NULL) { - PyErr_SetString(DbmError, + PyErr_SetString(state->dbm_error, "DBM object has already been closed"); return -1; } @@ -266,22 +287,9 @@ dbm_contains(PyObject *self, PyObject *arg) return val.dptr != NULL; } -static PySequenceMethods dbm_as_sequence = { - 0, /* sq_length */ - 0, /* sq_concat */ - 0, /* sq_repeat */ - 0, /* sq_item */ - 0, /* sq_slice */ - 0, /* sq_ass_item */ - 0, /* sq_ass_slice */ - dbm_contains, /* sq_contains */ - 0, /* sq_inplace_concat */ - 0, /* sq_inplace_repeat */ -}; - /*[clinic input] _dbm.dbm.get - + cls: defining_class key: str(accept={str, robuffer}, zeroes=True) default: object = None / @@ -290,19 +298,20 @@ Return the value for key if present, otherwise default. [clinic start generated code]*/ static PyObject * -_dbm_dbm_get_impl(dbmobject *self, const char *key, +_dbm_dbm_get_impl(dbmobject *self, PyTypeObject *cls, const char *key, Py_ssize_clean_t key_length, PyObject *default_value) -/*[clinic end generated code: output=b44f95eba8203d93 input=b788eba0ffad2e91]*/ -/*[clinic end generated code: output=4f5c0e523eaf1251 input=9402c0af8582dc69]*/ +/*[clinic end generated code: output=34851b5dc1c664dc input=66b993b8349fa8c1]*/ { datum dbm_key, val; - + _dbm_state *state = PyType_GetModuleState(cls); + assert(state != NULL); dbm_key.dptr = (char *)key; dbm_key.dsize = key_length; - check_dbmobject_open(self); + check_dbmobject_open(self, state->dbm_error); val = dbm_fetch(self->di_dbm, dbm_key); - if (val.dptr != NULL) + if (val.dptr != NULL) { return PyBytes_FromStringAndSize(val.dptr, val.dsize); + } Py_INCREF(default_value); return default_value; @@ -310,6 +319,7 @@ _dbm_dbm_get_impl(dbmobject *self, const char *key, /*[clinic input] _dbm.dbm.setdefault + cls: defining_class key: str(accept={str, robuffer}, zeroes=True) default: object(c_default="NULL") = b'' / @@ -320,24 +330,27 @@ If key is not in the database, it is inserted with default as the value. [clinic start generated code]*/ static PyObject * -_dbm_dbm_setdefault_impl(dbmobject *self, const char *key, +_dbm_dbm_setdefault_impl(dbmobject *self, PyTypeObject *cls, const char *key, Py_ssize_clean_t key_length, PyObject *default_value) -/*[clinic end generated code: output=52545886cf272161 input=bf40c48edaca01d6]*/ +/*[clinic end generated code: output=d5c68fe673886767 input=126a3ff15c5f8232]*/ { datum dbm_key, val; Py_ssize_t tmp_size; - + _dbm_state *state = PyType_GetModuleState(cls); + assert(state != NULL); dbm_key.dptr = (char *)key; dbm_key.dsize = key_length; - check_dbmobject_open(self); + check_dbmobject_open(self, state->dbm_error); val = dbm_fetch(self->di_dbm, dbm_key); - if (val.dptr != NULL) + if (val.dptr != NULL) { return PyBytes_FromStringAndSize(val.dptr, val.dsize); + } if (default_value == NULL) { default_value = PyBytes_FromStringAndSize(NULL, 0); - if (default_value == NULL) + if (default_value == NULL) { return NULL; + } val.dptr = NULL; val.dsize = 0; } @@ -352,7 +365,7 @@ _dbm_dbm_setdefault_impl(dbmobject *self, const char *key, } if (dbm_store(self->di_dbm, dbm_key, val, DBM_INSERT) < 0) { dbm_clearerr(self->di_dbm); - PyErr_SetString(DbmError, "cannot add item to database"); + PyErr_SetString(state->dbm_error, "cannot add item to database"); Py_DECREF(default_value); return NULL; } @@ -373,7 +386,6 @@ dbm__exit__(PyObject *self, PyObject *args) return _PyObject_CallMethodIdNoArgs(self, &PyId_close); } - static PyMethodDef dbm_methods[] = { _DBM_DBM_CLOSE_METHODDEF _DBM_DBM_KEYS_METHODDEF @@ -381,38 +393,29 @@ static PyMethodDef dbm_methods[] = { _DBM_DBM_SETDEFAULT_METHODDEF {"__enter__", dbm__enter__, METH_NOARGS, NULL}, {"__exit__", dbm__exit__, METH_VARARGS, NULL}, - {NULL, NULL} /* sentinel */ + {NULL, NULL} /* sentinel */ }; -static PyTypeObject Dbmtype = { - PyVarObject_HEAD_INIT(NULL, 0) - "_dbm.dbm", - sizeof(dbmobject), - 0, - (destructor)dbm_dealloc, /*tp_dealloc*/ - 0, /*tp_vectorcall_offset*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_as_async*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - &dbm_as_sequence, /*tp_as_sequence*/ - &dbm_as_mapping, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /*tp_flags*/ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - dbm_methods, /*tp_methods*/ +static PyType_Slot dbmtype_spec_slots[] = { + {Py_tp_dealloc, dbm_dealloc}, + {Py_tp_methods, dbm_methods}, + {Py_sq_contains, dbm_contains}, + {Py_mp_length, dbm_length}, + {Py_mp_subscript, dbm_subscript}, + {Py_mp_ass_subscript, dbm_ass_sub}, + {0, 0} +}; + + +static PyType_Spec dbmtype_spec = { + .name = "_dbm.dbm", + .basicsize = sizeof(dbmobject), + // Calling PyType_GetModuleState() on a subclass is not safe. + // dbmtype_spec does not have Py_TPFLAGS_BASETYPE flag + // which prevents to create a subclass. + // So calling PyType_GetModuleState() in this file is always safe. + .flags = Py_TPFLAGS_DEFAULT, + .slots = dbmtype_spec_slots, }; /* ----------------------------------------------------------------- */ @@ -443,19 +446,26 @@ dbmopen_impl(PyObject *module, PyObject *filename, const char *flags, /*[clinic end generated code: output=9527750f5df90764 input=376a9d903a50df59]*/ { int iflags; - - if ( strcmp(flags, "r") == 0 ) + _dbm_state *state = get_dbm_state(module); + assert(state != NULL); + if (strcmp(flags, "r") == 0) { iflags = O_RDONLY; - else if ( strcmp(flags, "w") == 0 ) + } + else if (strcmp(flags, "w") == 0) { iflags = O_RDWR; - else if ( strcmp(flags, "rw") == 0 ) /* B/W compat */ + } + else if (strcmp(flags, "rw") == 0) { + /* Backward compatibility */ iflags = O_RDWR|O_CREAT; - else if ( strcmp(flags, "c") == 0 ) + } + else if (strcmp(flags, "c") == 0) { iflags = O_RDWR|O_CREAT; - else if ( strcmp(flags, "n") == 0 ) + } + else if (strcmp(flags, "n") == 0) { iflags = O_RDWR|O_CREAT|O_TRUNC; + } else { - PyErr_SetString(DbmError, + PyErr_SetString(state->dbm_error, "arg 2 to open should be 'r', 'w', 'c', or 'n'"); return NULL; } @@ -470,7 +480,7 @@ dbmopen_impl(PyObject *module, PyObject *filename, const char *flags, PyErr_SetString(PyExc_ValueError, "embedded null character"); return NULL; } - PyObject *self = newdbmobject(name, iflags, mode); + PyObject *self = newdbmobject(state, name, iflags, mode); Py_DECREF(filenamebytes); return self; } @@ -480,42 +490,70 @@ static PyMethodDef dbmmodule_methods[] = { { 0, 0 }, }; +static int +_dbm_exec(PyObject *module) +{ + _dbm_state *state = get_dbm_state(module); + state->dbm_type = (PyTypeObject *)PyType_FromModuleAndSpec(module, + &dbmtype_spec, NULL); + if (state->dbm_type == NULL) { + return -1; + } + state->dbm_error = PyErr_NewException("_dbm.error", PyExc_OSError, NULL); + if (state->dbm_error == NULL) { + return -1; + } + if (PyModule_AddStringConstant(module, "library", which_dbm) < 0) { + return -1; + } + if (PyModule_AddType(module, (PyTypeObject *)state->dbm_error) < 0) { + return -1; + } + return 0; +} + +static int +_dbm_module_traverse(PyObject *module, visitproc visit, void *arg) +{ + _dbm_state *state = get_dbm_state(module); + Py_VISIT(state->dbm_error); + Py_VISIT(state->dbm_type); + return 0; +} + +static int +_dbm_module_clear(PyObject *module) +{ + _dbm_state *state = get_dbm_state(module); + Py_CLEAR(state->dbm_error); + Py_CLEAR(state->dbm_type); + return 0; +} + +static void +_dbm_module_free(void *module) +{ + _dbm_module_clear((PyObject *)module); +} + +static PyModuleDef_Slot _dbmmodule_slots[] = { + {Py_mod_exec, _dbm_exec}, + {0, NULL} +}; static struct PyModuleDef _dbmmodule = { PyModuleDef_HEAD_INIT, - "_dbm", - NULL, - -1, - dbmmodule_methods, - NULL, - NULL, - NULL, - NULL + .m_name = "_dbm", + .m_size = sizeof(_dbm_state), + .m_methods = dbmmodule_methods, + .m_slots = _dbmmodule_slots, + .m_traverse = _dbm_module_traverse, + .m_clear = _dbm_module_clear, + .m_free = _dbm_module_free, }; PyMODINIT_FUNC -PyInit__dbm(void) { - PyObject *m, *d, *s; - - if (PyType_Ready(&Dbmtype) < 0) - return NULL; - m = PyModule_Create(&_dbmmodule); - if (m == NULL) - return NULL; - d = PyModule_GetDict(m); - if (DbmError == NULL) - DbmError = PyErr_NewException("_dbm.error", - PyExc_OSError, NULL); - s = PyUnicode_FromString(which_dbm); - if (s != NULL) { - PyDict_SetItemString(d, "library", s); - Py_DECREF(s); - } - if (DbmError != NULL) - PyDict_SetItemString(d, "error", DbmError); - if (PyErr_Occurred()) { - Py_DECREF(m); - m = NULL; - } - return m; +PyInit__dbm(void) +{ + return PyModuleDef_Init(&_dbmmodule); } diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index 20ba8fb77ad..ff7c647c222 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -36,8 +36,8 @@ #include "docstrings.h" -#if !defined(MPD_VERSION_HEX) || MPD_VERSION_HEX < 0x02040100 - #error "libmpdec version >= 2.4.1 required" +#if !defined(MPD_VERSION_HEX) || MPD_VERSION_HEX < 0x02050000 + #error "libmpdec version >= 2.5.0 required" #endif diff --git a/Modules/_decimal/libmpdec/basearith.c b/Modules/_decimal/libmpdec/basearith.c index dfe1523927a..85c608fadf5 100644 --- a/Modules/_decimal/libmpdec/basearith.c +++ b/Modules/_decimal/libmpdec/basearith.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,13 +27,13 @@ #include "mpdecimal.h" -#include -#include -#include + #include +#include + +#include "basearith.h" #include "constants.h" #include "typearith.h" -#include "basearith.h" /*********************************************************************/ @@ -337,6 +337,7 @@ _mpd_basedivmod(mpd_uint_t *q, mpd_uint_t *r, /* D2: loop */ for (j=m; j != MPD_SIZE_MAX; j--) { + assert(2 <= j+n && j+n <= nplusm); /* annotation for scan-build */ /* D3: calculate qhat and rhat */ rhat = _mpd_shortdiv(w2, u+j+n-1, 2, v[n-1]); @@ -652,6 +653,3 @@ _mpd_shortdiv_b(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n, return rem; } - - - diff --git a/Modules/_decimal/libmpdec/basearith.h b/Modules/_decimal/libmpdec/basearith.h index 976358a110e..d35925aaddb 100644 --- a/Modules/_decimal/libmpdec/basearith.h +++ b/Modules/_decimal/libmpdec/basearith.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,11 @@ */ -#ifndef BASEARITH_H -#define BASEARITH_H +#ifndef LIBMPDEC_BASEARITH_H_ +#define LIBMPDEC_BASEARITH_H_ #include "mpdecimal.h" -#include #include "typearith.h" @@ -216,7 +215,4 @@ _mpd_isallnine(const mpd_uint_t *data, mpd_ssize_t len) MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif /* BASEARITH_H */ - - - +#endif /* LIBMPDEC_BASEARITH_H_ */ diff --git a/Modules/_decimal/libmpdec/bits.h b/Modules/_decimal/libmpdec/bits.h index b5eaa24976a..aa9c3e77980 100644 --- a/Modules/_decimal/libmpdec/bits.h +++ b/Modules/_decimal/libmpdec/bits.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,11 @@ */ -#ifndef BITS_H -#define BITS_H +#ifndef LIBMPDEC_BITS_H_ +#define LIBMPDEC_BITS_H_ #include "mpdecimal.h" -#include /* Check if n is a power of 2. */ @@ -186,7 +185,4 @@ mpd_bsf(mpd_size_t a) #endif /* BSR/BSF */ -#endif /* BITS_H */ - - - +#endif /* LIBMPDEC_BITS_H_ */ diff --git a/Modules/_decimal/libmpdec/constants.c b/Modules/_decimal/libmpdec/constants.c index 2c2d5ea4810..4c4de622bc6 100644 --- a/Modules/_decimal/libmpdec/constants.c +++ b/Modules/_decimal/libmpdec/constants.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,7 +27,6 @@ #include "mpdecimal.h" -#include #include "constants.h" @@ -128,5 +127,3 @@ const char *mpd_clamp_string[MPD_CLAMP_GUARD] = { "CLAMP_DEFAULT", "CLAMP_IEEE_754" }; - - diff --git a/Modules/_decimal/libmpdec/constants.h b/Modules/_decimal/libmpdec/constants.h index c0febfc8772..7c1db839c20 100644 --- a/Modules/_decimal/libmpdec/constants.h +++ b/Modules/_decimal/libmpdec/constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,14 @@ */ -#ifndef CONSTANTS_H -#define CONSTANTS_H +#ifndef LIBMPDEC_CONSTANTS_H_ +#define LIBMPDEC_CONSTANTS_H_ #include "mpdecimal.h" +#include + /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) @@ -84,7 +86,4 @@ extern const mpd_uint_t UH_P1P2; MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif /* CONSTANTS_H */ - - - +#endif /* LIBMPDEC_CONSTANTS_H_ */ diff --git a/Modules/_decimal/libmpdec/context.c b/Modules/_decimal/libmpdec/context.c index 24c7b890c1d..9cbc2050959 100644 --- a/Modules/_decimal/libmpdec/context.c +++ b/Modules/_decimal/libmpdec/context.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,14 +27,16 @@ #include "mpdecimal.h" + +#include #include #include -#include void -mpd_dflt_traphandler(mpd_context_t *ctx UNUSED) +mpd_dflt_traphandler(mpd_context_t *ctx) { + (void)ctx; raise(SIGFPE); } @@ -282,5 +284,3 @@ mpd_addstatus_raise(mpd_context_t *ctx, uint32_t flags) mpd_traphandler(ctx); } } - - diff --git a/Modules/_decimal/libmpdec/convolute.c b/Modules/_decimal/libmpdec/convolute.c index 4c62e8bd3ab..4bc8e8b5fd3 100644 --- a/Modules/_decimal/libmpdec/convolute.c +++ b/Modules/_decimal/libmpdec/convolute.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,15 +27,14 @@ #include "mpdecimal.h" -#include #include "bits.h" #include "constants.h" +#include "convolute.h" #include "fnt.h" #include "fourstep.h" #include "numbertheory.h" #include "sixstep.h" #include "umodarith.h" -#include "convolute.h" /* Bignum: Fast convolution using the Number Theoretic Transform. Used for @@ -170,5 +169,3 @@ fnt_autoconvolute(mpd_uint_t *c1, mpd_size_t n, int modnum) return 1; } - - diff --git a/Modules/_decimal/libmpdec/convolute.h b/Modules/_decimal/libmpdec/convolute.h index f30a177a684..62edb3e4573 100644 --- a/Modules/_decimal/libmpdec/convolute.h +++ b/Modules/_decimal/libmpdec/convolute.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,11 @@ */ -#ifndef CONVOLUTE_H -#define CONVOLUTE_H +#ifndef LIBMPDEC_CONVOLUTE_H_ +#define LIBMPDEC_CONVOLUTE_H_ #include "mpdecimal.h" -#include /* Internal header file: all symbols have local scope in the DSO */ @@ -47,4 +46,4 @@ int fnt_autoconvolute(mpd_uint_t *c1, mpd_size_t n, int modnum); MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif +#endif /* LIBMPDEC_CONVOLUTE_H_ */ diff --git a/Modules/_decimal/libmpdec/crt.c b/Modules/_decimal/libmpdec/crt.c index 4a1e80a2322..613274ee0c5 100644 --- a/Modules/_decimal/libmpdec/crt.c +++ b/Modules/_decimal/libmpdec/crt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,11 +27,14 @@ #include "mpdecimal.h" -#include + #include + +#include "constants.h" +#include "crt.h" #include "numbertheory.h" #include "umodarith.h" -#include "crt.h" +#include "typearith.h" /* Bignum: Chinese Remainder Theorem, extends the maximum transform length. */ @@ -175,5 +178,3 @@ crt3(mpd_uint_t *x1, mpd_uint_t *x2, mpd_uint_t *x3, mpd_size_t rsize) assert(carry[0] == 0 && carry[1] == 0 && carry[2] == 0); } - - diff --git a/Modules/_decimal/libmpdec/crt.h b/Modules/_decimal/libmpdec/crt.h index f61e7729363..15a347d4cb3 100644 --- a/Modules/_decimal/libmpdec/crt.h +++ b/Modules/_decimal/libmpdec/crt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,11 @@ */ -#ifndef CRT_H -#define CRT_H +#ifndef LIBMPDEC_CRT_H_ +#define LIBMPDEC_CRT_H_ #include "mpdecimal.h" -#include /* Internal header file: all symbols have local scope in the DSO */ @@ -44,4 +43,4 @@ void crt3(mpd_uint_t *x1, mpd_uint_t *x2, mpd_uint_t *x3, mpd_size_t nmemb); MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif +#endif /* LIBMPDEC_CRT_H_ */ diff --git a/Modules/_decimal/libmpdec/difradix2.c b/Modules/_decimal/libmpdec/difradix2.c index 06e5ab5e222..049ecff65b6 100644 --- a/Modules/_decimal/libmpdec/difradix2.c +++ b/Modules/_decimal/libmpdec/difradix2.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,12 +27,14 @@ #include "mpdecimal.h" -#include + #include + #include "bits.h" +#include "constants.h" +#include "difradix2.h" #include "numbertheory.h" #include "umodarith.h" -#include "difradix2.h" /* Bignum: The actual transform routine (decimation in frequency). */ @@ -169,5 +171,3 @@ fnt_dif2(mpd_uint_t a[], mpd_size_t n, struct fnt_params *tparams) bitreverse_permute(a, n); } - - diff --git a/Modules/_decimal/libmpdec/difradix2.h b/Modules/_decimal/libmpdec/difradix2.h index 5e22bcf324f..cdcbcf9a710 100644 --- a/Modules/_decimal/libmpdec/difradix2.h +++ b/Modules/_decimal/libmpdec/difradix2.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,11 @@ */ -#ifndef DIF_RADIX2_H -#define DIF_RADIX2_H +#ifndef LIBMPDEC_DIFRADIX2_H_ +#define LIBMPDEC_DIFRADIX2_H_ #include "mpdecimal.h" -#include #include "numbertheory.h" @@ -45,4 +44,4 @@ void fnt_dif2(mpd_uint_t a[], mpd_size_t n, struct fnt_params *tparams); MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif +#endif /* LIBMPDEC_DIFRADIX2_H_ */ diff --git a/Modules/_decimal/libmpdec/fnt.c b/Modules/_decimal/libmpdec/fnt.c index 7e924c85242..0dbe98fc71c 100644 --- a/Modules/_decimal/libmpdec/fnt.c +++ b/Modules/_decimal/libmpdec/fnt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,13 +27,14 @@ #include "mpdecimal.h" -#include -#include + #include +#include + #include "bits.h" #include "difradix2.h" -#include "numbertheory.h" #include "fnt.h" +#include "numbertheory.h" /* Bignum: Fast transform for medium-sized coefficients. */ @@ -76,6 +77,3 @@ std_inv_fnt(mpd_uint_t *a, mpd_size_t n, int modnum) mpd_free(tparams); return 1; } - - - diff --git a/Modules/_decimal/libmpdec/fnt.h b/Modules/_decimal/libmpdec/fnt.h index fa2154a798d..5222c476a3a 100644 --- a/Modules/_decimal/libmpdec/fnt.h +++ b/Modules/_decimal/libmpdec/fnt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,11 @@ */ -#ifndef FNT_H -#define FNT_H +#ifndef LIBMPDEC_FNT_H_ +#define LIBMPDEC_FNT_H_ #include "mpdecimal.h" -#include /* Internal header file: all symbols have local scope in the DSO */ @@ -45,5 +44,4 @@ int std_inv_fnt(mpd_uint_t a[], mpd_size_t n, int modnum); MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif - +#endif /* LIBMPDEC_FNT_H_ */ diff --git a/Modules/_decimal/libmpdec/fourstep.c b/Modules/_decimal/libmpdec/fourstep.c index 21d3e7485df..fb173ed5a52 100644 --- a/Modules/_decimal/libmpdec/fourstep.c +++ b/Modules/_decimal/libmpdec/fourstep.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,12 +27,14 @@ #include "mpdecimal.h" + #include + +#include "constants.h" +#include "fourstep.h" #include "numbertheory.h" #include "sixstep.h" -#include "transpose.h" #include "umodarith.h" -#include "fourstep.h" /* Bignum: Cache efficient Matrix Fourier Transform for arrays of the @@ -187,6 +189,7 @@ four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum) #if 0 /* An unordered transform is sufficient for convolution. */ /* Transpose the matrix. */ + #include "transpose.h" transpose_3xpow2(a, R, C); #endif @@ -217,6 +220,7 @@ inv_four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum) #if 0 /* An unordered transform is sufficient for convolution. */ /* Transpose the matrix, producing an R*C matrix. */ + #include "transpose.h" transpose_3xpow2(a, C, R); #endif @@ -253,5 +257,3 @@ inv_four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum) return 1; } - - diff --git a/Modules/_decimal/libmpdec/fourstep.h b/Modules/_decimal/libmpdec/fourstep.h index 80dcd4be3d5..5ffb6fcc8ec 100644 --- a/Modules/_decimal/libmpdec/fourstep.h +++ b/Modules/_decimal/libmpdec/fourstep.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,11 @@ */ -#ifndef FOUR_STEP_H -#define FOUR_STEP_H +#ifndef LIBMPDEC_FOURSTEP_H_ +#define LIBMPDEC_FOURSTEP_H_ #include "mpdecimal.h" -#include /* Internal header file: all symbols have local scope in the DSO */ @@ -45,4 +44,4 @@ int inv_four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif +#endif /* LIBMPDEC_FOURSTEP_H_ */ diff --git a/Modules/_decimal/libmpdec/io.c b/Modules/_decimal/libmpdec/io.c index f45e558f1a9..9513a68e378 100644 --- a/Modules/_decimal/libmpdec/io.c +++ b/Modules/_decimal/libmpdec/io.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,16 +27,16 @@ #include "mpdecimal.h" + +#include +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include -#include "bits.h" -#include "constants.h" + #include "typearith.h" #include "io.h" @@ -277,7 +277,7 @@ mpd_qset_string(mpd_t *dec, const char *s, const mpd_context_t *ctx, } } - digits = end - coeff; + digits = end - coeff; if (dpoint) { size_t fracdigits = end-dpoint-1; if (dpoint > coeff) digits--; @@ -326,6 +326,22 @@ conversion_error: mpd_seterror(dec, MPD_Conversion_syntax, status); } +/* convert a character string to a decimal, use a maxcontext for conversion */ +void +mpd_qset_string_exact(mpd_t *dec, const char *s, uint32_t *status) +{ + mpd_context_t maxcontext; + + mpd_maxcontext(&maxcontext); + mpd_qset_string(dec, s, &maxcontext, status); + + if (*status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) { + /* we want exact results */ + mpd_seterror(dec, MPD_Invalid_operation, status); + } + *status &= MPD_Errors; +} + /* Print word x with n decimal digits to string s. dot is either NULL or the location of a decimal point. */ #define EXTRACT_DIGIT(s, x, d, dot) \ @@ -539,8 +555,8 @@ _mpd_to_string(char **result, const mpd_t *dec, int flags, mpd_ssize_t dplace) dplace = -1 + mod_mpd_ssize_t(dec->exp+2, 3); } else { /* ldigits-1 is the adjusted exponent, which - * should be divisible by three. If not, move - * dplace one or two places to the right. */ + * should be divisible by three. If not, move + * dplace one or two places to the right. */ dplace += mod_mpd_ssize_t(ldigits-1, 3); } } @@ -1247,7 +1263,7 @@ mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec, } if (isupper((uchar)type)) { - type = tolower((uchar)type); + type = (char)tolower((uchar)type); flags |= MPD_FMT_UPPER; } if (spec->sign == ' ') { @@ -1265,6 +1281,7 @@ mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec, stackspec.align = '>'; spec = &stackspec; } + assert(strlen(spec->fill) == 1); /* annotation for scan-build */ if (type == '%') { flags |= MPD_FMT_PERCENT; } @@ -1579,5 +1596,3 @@ mpd_print(const mpd_t *dec) fputs("mpd_fprint: output error\n", stderr); /* GCOV_NOT_REACHED */ } } - - diff --git a/Modules/_decimal/libmpdec/io.h b/Modules/_decimal/libmpdec/io.h index de5486a00ca..79d7c05ce36 100644 --- a/Modules/_decimal/libmpdec/io.h +++ b/Modules/_decimal/libmpdec/io.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,17 +26,20 @@ */ -#ifndef IO_H -#define IO_H +#ifndef LIBMPDEC_IO_H_ +#define LIBMPDEC_IO_H_ -#include #include "mpdecimal.h" +#include + #if SIZE_MAX == MPD_SIZE_MAX #define mpd_strtossize _mpd_strtossize #else +#include + static inline mpd_ssize_t mpd_strtossize(const char *s, char **end, int base) { @@ -56,4 +59,4 @@ mpd_strtossize(const char *s, char **end, int base) #endif -#endif +#endif /* LIBMPDEC_IO_H_ */ diff --git a/Modules/_decimal/libmpdec/literature/fnt.py b/Modules/_decimal/libmpdec/literature/fnt.py index 6363536da64..c1285a565db 100644 --- a/Modules/_decimal/libmpdec/literature/fnt.py +++ b/Modules/_decimal/libmpdec/literature/fnt.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2008-2016 Stefan Krah. All rights reserved. +# Copyright (c) 2008-2020 Stefan Krah. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/Modules/_decimal/libmpdec/literature/matrix-transform.txt b/Modules/_decimal/libmpdec/literature/matrix-transform.txt index 701d85d6b43..6e7ad742090 100644 --- a/Modules/_decimal/libmpdec/literature/matrix-transform.txt +++ b/Modules/_decimal/libmpdec/literature/matrix-transform.txt @@ -1,6 +1,6 @@ -(* Copyright (c) 2011 Stefan Krah. All rights reserved. *) +(* Copyright (c) 2011-2020 Stefan Krah. All rights reserved. *) The Matrix Fourier Transform: diff --git a/Modules/_decimal/libmpdec/literature/mulmod-64.txt b/Modules/_decimal/libmpdec/literature/mulmod-64.txt index 029b8de3d7c..fa967bf95e3 100644 --- a/Modules/_decimal/libmpdec/literature/mulmod-64.txt +++ b/Modules/_decimal/libmpdec/literature/mulmod-64.txt @@ -1,6 +1,6 @@ -(* Copyright (c) 2011 Stefan Krah. All rights reserved. *) +(* Copyright (c) 2011-2020 Stefan Krah. All rights reserved. *) ========================================================================== diff --git a/Modules/_decimal/libmpdec/literature/mulmod-ppro.txt b/Modules/_decimal/libmpdec/literature/mulmod-ppro.txt index 4d17a928e6e..ba804e4b4e7 100644 --- a/Modules/_decimal/libmpdec/literature/mulmod-ppro.txt +++ b/Modules/_decimal/libmpdec/literature/mulmod-ppro.txt @@ -1,6 +1,6 @@ -(* Copyright (c) 2011 Stefan Krah. All rights reserved. *) +(* Copyright (c) 2011-2020 Stefan Krah. All rights reserved. *) ======================================================================== diff --git a/Modules/_decimal/libmpdec/literature/six-step.txt b/Modules/_decimal/libmpdec/literature/six-step.txt index 8e45f487584..852d5b0df8b 100644 --- a/Modules/_decimal/libmpdec/literature/six-step.txt +++ b/Modules/_decimal/libmpdec/literature/six-step.txt @@ -1,6 +1,6 @@ -(* Copyright (c) 2011 Stefan Krah. All rights reserved. *) +(* Copyright (c) 2011-2020 Stefan Krah. All rights reserved. *) The Six Step Transform: diff --git a/Modules/_decimal/libmpdec/literature/umodarith.lisp b/Modules/_decimal/libmpdec/literature/umodarith.lisp index 99d71c373d1..d71f074a26d 100644 --- a/Modules/_decimal/libmpdec/literature/umodarith.lisp +++ b/Modules/_decimal/libmpdec/literature/umodarith.lisp @@ -1,5 +1,5 @@ ; -; Copyright (c) 2008-2016 Stefan Krah. All rights reserved. +; Copyright (c) 2008-2020 Stefan Krah. All rights reserved. ; ; Redistribution and use in source and binary forms, with or without ; modification, are permitted provided that the following conditions @@ -149,7 +149,7 @@ (defthmd addmod-correct (implies (and (< 0 m) (< m base) - (< a m) (<= b m) + (< a m) (<= b m) (natp m) (natp base) (natp a) (natp b)) (equal (addmod a b m base) @@ -179,7 +179,7 @@ (defthmd submod-correct (implies (and (< 0 m) (< m base) - (< a m) (<= b m) + (< a m) (<= b m) (natp m) (natp base) (natp a) (natp b)) (equal (submod a b m base) @@ -200,7 +200,7 @@ (defthm submod-2-correct (implies (and (< 0 m) (< m base) - (< a m) (<= b m) + (< a m) (<= b m) (natp m) (natp base) (natp a) (natp b)) (equal (submod-2 a b m base) @@ -231,7 +231,7 @@ (defthmd ext-submod-ext-submod-2-equal (implies (and (< 0 m) (< m base) - (< a (* 2 m)) (< b (* 2 m)) + (< a (* 2 m)) (< b (* 2 m)) (natp m) (natp base) (natp a) (natp b)) (equal (ext-submod a b m base) @@ -239,7 +239,7 @@ (defthmd ext-submod-2-correct (implies (and (< 0 m) (< m base) - (< a (* 2 m)) (< b (* 2 m)) + (< a (* 2 m)) (< b (* 2 m)) (natp m) (natp base) (natp a) (natp b)) (equal (ext-submod-2 a b m base) @@ -257,7 +257,7 @@ (defthmd dw-reduce-correct (implies (and (< 0 m) (< m base) - (< hi base) (< lo base) + (< hi base) (< lo base) (natp m) (natp base) (natp hi) (natp lo)) (equal (dw-reduce hi lo m base) @@ -322,7 +322,7 @@ (defthmd dw-submod-correct (implies (and (< 0 m) (< m base) (natp a) (< a m) - (< hi base) (< lo base) + (< hi base) (< lo base) (natp m) (natp base) (natp hi) (natp lo)) (equal (dw-submod a hi lo m base) diff --git a/Modules/_decimal/libmpdec/mpalloc.c b/Modules/_decimal/libmpdec/mpalloc.c index a854e09911b..eb5ee7a807b 100644 --- a/Modules/_decimal/libmpdec/mpalloc.c +++ b/Modules/_decimal/libmpdec/mpalloc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,10 +27,14 @@ #include "mpdecimal.h" + +#include #include #include -#include "typearith.h" +#include + #include "mpalloc.h" +#include "typearith.h" #if defined(_MSC_VER) @@ -294,4 +298,59 @@ mpd_realloc_dyn(mpd_t *result, mpd_ssize_t nwords, uint32_t *status) return 1; } +/* + * Input: 'result' is a static mpd_t with a static coefficient. + * Assumption: 'nwords' >= result->alloc. + * + * Resize the static coefficient to a larger dynamic one and copy the + * existing data. + * + * On failure the value of 'result' is unchanged. + */ +int +mpd_switch_to_dyn_cxx(mpd_t *result, mpd_ssize_t nwords) +{ + assert(nwords >= result->alloc); + mpd_uint_t *data = mpd_alloc(nwords, sizeof *result->data); + if (data == NULL) { + return 0; + } + + memcpy(data, result->data, result->alloc * (sizeof *result->data)); + result->data = data; + result->alloc = nwords; + mpd_set_dynamic_data(result); + return 1; +} + +/* + * Input: 'result' is a static or a dynamic mpd_t with a dynamic coefficient. + * Resize the coefficient to length 'nwords': + * Case nwords > result->alloc: + * If realloc is successful: + * 'result' has a larger coefficient but the same value. Return 1. + * Otherwise: + * 'result' has a the same coefficient. Return 0. + * Case nwords < result->alloc: + * If realloc is successful: + * 'result' has a smaller coefficient. result->len is undefined. Return 1. + * Otherwise (unlikely): + * 'result' is unchanged. Reuse the now oversized coefficient. Return 1. + */ +int +mpd_realloc_dyn_cxx(mpd_t *result, mpd_ssize_t nwords) +{ + uint8_t err = 0; + + mpd_uint_t *p = mpd_realloc(result->data, nwords, sizeof *result->data, &err); + if (!err) { + result->data = p; + result->alloc = nwords; + } + else if (nwords > result->alloc) { + return 0; + } + + return 1; +} diff --git a/Modules/_decimal/libmpdec/mpalloc.h b/Modules/_decimal/libmpdec/mpalloc.h index efd711953a3..186808457b2 100644 --- a/Modules/_decimal/libmpdec/mpalloc.h +++ b/Modules/_decimal/libmpdec/mpalloc.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,14 @@ */ -#ifndef MPALLOC_H -#define MPALLOC_H +#ifndef LIBMPDEC_MPALLOC_H_ +#define LIBMPDEC_MPALLOC_H_ #include "mpdecimal.h" +#include + /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) @@ -41,11 +43,11 @@ int mpd_switch_to_dyn(mpd_t *result, mpd_ssize_t size, uint32_t *status); int mpd_switch_to_dyn_zero(mpd_t *result, mpd_ssize_t size, uint32_t *status); int mpd_realloc_dyn(mpd_t *result, mpd_ssize_t size, uint32_t *status); +int mpd_switch_to_dyn_cxx(mpd_t *result, mpd_ssize_t size); +int mpd_realloc_dyn_cxx(mpd_t *result, mpd_ssize_t size); + MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif - - - +#endif /* LIBMPDEC_MPALLOC_H_ */ diff --git a/Modules/_decimal/libmpdec/mpdecimal.c b/Modules/_decimal/libmpdec/mpdecimal.c index 0986edb576a..ad8db508b36 100644 --- a/Modules/_decimal/libmpdec/mpdecimal.c +++ b/Modules/_decimal/libmpdec/mpdecimal.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,18 +27,21 @@ #include "mpdecimal.h" + +#include +#include +#include #include #include #include -#include -#include + #include "basearith.h" #include "bits.h" +#include "constants.h" #include "convolute.h" #include "crt.h" #include "mpalloc.h" #include "typearith.h" -#include "umodarith.h" #ifdef PPRO #if defined(_MSC_VER) @@ -241,7 +244,7 @@ mpd_lsd(mpd_uint_t word) } /* Coefficient size needed to store 'digits' */ -ALWAYS_INLINE mpd_ssize_t +mpd_ssize_t mpd_digits_to_size(mpd_ssize_t digits) { mpd_ssize_t q, r; @@ -260,8 +263,9 @@ mpd_exp_digits(mpd_ssize_t exp) /* Canonical */ ALWAYS_INLINE int -mpd_iscanonical(const mpd_t *dec UNUSED) +mpd_iscanonical(const mpd_t *dec) { + (void)dec; return 1; } @@ -512,6 +516,28 @@ mpd_qresize(mpd_t *result, mpd_ssize_t nwords, uint32_t *status) return mpd_realloc_dyn(result, nwords, status); } +/* Same as mpd_qresize, but do not set the result no NaN on failure. */ +static ALWAYS_INLINE int +mpd_qresize_cxx(mpd_t *result, mpd_ssize_t nwords) +{ + assert(!mpd_isconst_data(result)); /* illegal operation for a const */ + assert(!mpd_isshared_data(result)); /* illegal operation for a shared */ + assert(MPD_MINALLOC <= result->alloc); + + nwords = (nwords <= MPD_MINALLOC) ? MPD_MINALLOC : nwords; + if (nwords == result->alloc) { + return 1; + } + if (mpd_isstatic_data(result)) { + if (nwords > result->alloc) { + return mpd_switch_to_dyn_cxx(result, nwords); + } + return 1; + } + + return mpd_realloc_dyn_cxx(result, nwords); +} + /* Same as mpd_qresize, but the complete coefficient (including the old * memory area!) is initialized to zero. */ ALWAYS_INLINE int @@ -1192,7 +1218,7 @@ _c32setu64(mpd_t *result, uint64_t u, uint8_t sign, uint32_t *status) result->data[i] = w[i]; } - mpd_set_sign(result, sign); + mpd_set_flags(result, sign); result->exp = 0; result->len = len; mpd_setdigits(result); @@ -1244,6 +1270,26 @@ mpd_qset_i64(mpd_t *result, int64_t a, const mpd_context_t *ctx, #endif } +/* quietly set a decimal from an int64_t, use a maxcontext for conversion */ +void +mpd_qset_i64_exact(mpd_t *result, int64_t a, uint32_t *status) +{ + mpd_context_t maxcontext; + + mpd_maxcontext(&maxcontext); +#ifdef CONFIG_64 + mpd_qset_ssize(result, a, &maxcontext, status); +#else + _c32_qset_i64(result, a, &maxcontext, status); +#endif + + if (*status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) { + /* we want exact results */ + mpd_seterror(result, MPD_Invalid_operation, status); + } + *status &= MPD_Errors; +} + /* quietly set a decimal from a uint64_t */ void mpd_qset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx, @@ -1255,8 +1301,27 @@ mpd_qset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx, _c32_qset_u64(result, a, ctx, status); #endif } -#endif /* !LEGACY_COMPILER */ +/* quietly set a decimal from a uint64_t, use a maxcontext for conversion */ +void +mpd_qset_u64_exact(mpd_t *result, uint64_t a, uint32_t *status) +{ + mpd_context_t maxcontext; + + mpd_maxcontext(&maxcontext); +#ifdef CONFIG_64 + mpd_qset_uint(result, a, &maxcontext, status); +#else + _c32_qset_u64(result, a, &maxcontext, status); +#endif + + if (*status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) { + /* we want exact results */ + mpd_seterror(result, MPD_Invalid_operation, status); + } + *status &= MPD_Errors; +} +#endif /* !LEGACY_COMPILER */ /* * Quietly get an mpd_uint_t from a decimal. Assumes @@ -1345,11 +1410,13 @@ mpd_qabs_uint(const mpd_t *a, uint32_t *status) mpd_ssize_t mpd_qget_ssize(const mpd_t *a, uint32_t *status) { + uint32_t workstatus = 0; mpd_uint_t u; int isneg; - u = mpd_qabs_uint(a, status); - if (*status&MPD_Invalid_operation) { + u = mpd_qabs_uint(a, &workstatus); + if (workstatus&MPD_Invalid_operation) { + *status |= workstatus; return MPD_SSIZE_MAX; } @@ -1469,9 +1536,11 @@ mpd_qget_i64(const mpd_t *a, uint32_t *status) uint32_t mpd_qget_u32(const mpd_t *a, uint32_t *status) { - uint64_t x = mpd_qget_uint(a, status); + uint32_t workstatus = 0; + uint64_t x = mpd_qget_uint(a, &workstatus); - if (*status&MPD_Invalid_operation) { + if (workstatus&MPD_Invalid_operation) { + *status |= workstatus; return UINT32_MAX; } if (x > UINT32_MAX) { @@ -1486,9 +1555,11 @@ mpd_qget_u32(const mpd_t *a, uint32_t *status) int32_t mpd_qget_i32(const mpd_t *a, uint32_t *status) { - int64_t x = mpd_qget_ssize(a, status); + uint32_t workstatus = 0; + int64_t x = mpd_qget_ssize(a, &workstatus); - if (*status&MPD_Invalid_operation) { + if (workstatus&MPD_Invalid_operation) { + *status |= workstatus; return INT32_MAX; } if (x < INT32_MIN || x > INT32_MAX) { @@ -1504,14 +1575,20 @@ mpd_qget_i32(const mpd_t *a, uint32_t *status) uint64_t mpd_qget_u64(const mpd_t *a, uint32_t *status) { - return _c32_qget_u64(1, a, status); + uint32_t workstatus = 0; + uint64_t x = _c32_qget_u64(1, a, &workstatus); + *status |= workstatus; + return x; } /* quietly get an int64_t from a decimal */ int64_t mpd_qget_i64(const mpd_t *a, uint32_t *status) { - return _c32_qget_i64(a, status); + uint32_t workstatus = 0; + int64_t x = _c32_qget_i64(a, &workstatus); + *status |= workstatus; + return x; } #endif @@ -1937,6 +2014,25 @@ mpd_qcopy(mpd_t *result, const mpd_t *a, uint32_t *status) return 1; } +/* Same as mpd_qcopy, but do not set the result to NaN on failure. */ +int +mpd_qcopy_cxx(mpd_t *result, const mpd_t *a) +{ + if (result == a) return 1; + + if (!mpd_qresize_cxx(result, a->len)) { + return 0; + } + + mpd_copy_flags(result, a); + result->exp = a->exp; + result->digits = a->digits; + result->len = a->len; + memcpy(result->data, a->data, a->len * (sizeof *result->data)); + + return 1; +} + /* * Copy to a decimal with a static buffer. The caller has to make sure that * the buffer is big enough. Cannot fail. @@ -3780,11 +3876,31 @@ void mpd_qdiv(mpd_t *q, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status) { - _mpd_qdiv(SET_IDEAL_EXP, q, a, b, ctx, status); + MPD_NEW_STATIC(aa,0,0,0,0); + MPD_NEW_STATIC(bb,0,0,0,0); + uint32_t xstatus = 0; - if (*status & MPD_Malloc_error) { + if (q == a) { + if (!mpd_qcopy(&aa, a, status)) { + mpd_seterror(q, MPD_Malloc_error, status); + goto out; + } + a = &aa; + } + + if (q == b) { + if (!mpd_qcopy(&bb, b, status)) { + mpd_seterror(q, MPD_Malloc_error, status); + goto out; + } + b = &bb; + } + + _mpd_qdiv(SET_IDEAL_EXP, q, a, b, ctx, &xstatus); + + if (xstatus & (MPD_Malloc_error|MPD_Division_impossible)) { /* Inexact quotients (the usual case) fill the entire context precision, - * which can lead to malloc() failures for very high precisions. Retry + * which can lead to the above errors for very high precisions. Retry * the operation with a lower precision in case the result is exact. * * We need an upper bound for the number of digits of a_coeff / b_coeff @@ -3799,25 +3915,33 @@ mpd_qdiv(mpd_t *q, const mpd_t *a, const mpd_t *b, * We arrive at a total upper bound: * * maxdigits(a_coeff') + maxdigits(1 / b_coeff') <= - * a->digits + log2(b_coeff) = - * a->digits + log10(b_coeff) / log10(2) <= + * log10(a_coeff) + log2(b_coeff) = + * log10(a_coeff) + log10(b_coeff) / log10(2) <= * a->digits + b->digits * 4; */ - uint32_t workstatus = 0; mpd_context_t workctx = *ctx; + uint32_t ystatus = 0; + workctx.prec = a->digits + b->digits * 4; if (workctx.prec >= ctx->prec) { - return; /* No point in retrying, keep the original error. */ + *status |= (xstatus&MPD_Errors); + goto out; /* No point in retrying, keep the original error. */ } - _mpd_qdiv(SET_IDEAL_EXP, q, a, b, &workctx, &workstatus); - if (workstatus == 0) { /* The result is exact, unrounded, normal etc. */ - *status = 0; - return; + _mpd_qdiv(SET_IDEAL_EXP, q, a, b, &workctx, &ystatus); + if (ystatus != 0) { + ystatus = *status | ((ystatus|xstatus)&MPD_Errors); + mpd_seterror(q, ystatus, status); } - - mpd_seterror(q, *status, status); } + else { + *status |= xstatus; + } + + +out: + mpd_del(&aa); + mpd_del(&bb); } /* Internal function. */ @@ -3907,6 +4031,7 @@ _mpd_qdivmod(mpd_t *q, mpd_t *r, const mpd_t *a, const mpd_t *b, } if (b->len == 1) { + assert(b->data[0] != 0); /* annotation for scan-build */ if (a->len == 1) { _mpd_div_word(&q->data[0], &r->data[0], a->data[0], b->data[0]); } @@ -6251,9 +6376,11 @@ _mpd_qpow_int(mpd_t *result, const mpd_t *base, const mpd_t *exp, workctx.round = MPD_ROUND_HALF_EVEN; workctx.clamp = 0; if (mpd_isnegative(exp)) { + uint32_t workstatus = 0; workctx.prec += 1; - mpd_qdiv(&tbase, &one, base, &workctx, status); - if (*status&MPD_Errors) { + mpd_qdiv(&tbase, &one, base, &workctx, &workstatus); + *status |= workstatus; + if (workstatus&MPD_Errors) { mpd_setspecial(result, MPD_POS, MPD_NAN); goto finish; } @@ -6988,6 +7115,8 @@ mpd_qrem_near(mpd_t *r, const mpd_t *a, const mpd_t *b, mpd_ssize_t expdiff, qdigits; int cmp, isodd, allnine; + assert(r != NULL); /* annotation for scan-build */ + if (mpd_isspecial(a) || mpd_isspecial(b)) { if (mpd_qcheck_nans(r, a, b, ctx, status)) { return; @@ -7218,6 +7347,11 @@ void mpd_qtrunc(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status) { + if (mpd_isspecial(a)) { + mpd_seterror(result, MPD_Invalid_operation, status); + return; + } + (void)_mpd_qround_to_integral(TO_INT_TRUNC, result, a, ctx, status); } @@ -7226,6 +7360,12 @@ mpd_qfloor(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status) { mpd_context_t workctx = *ctx; + + if (mpd_isspecial(a)) { + mpd_seterror(result, MPD_Invalid_operation, status); + return; + } + workctx.round = MPD_ROUND_FLOOR; (void)_mpd_qround_to_integral(TO_INT_SILENT, result, a, &workctx, status); @@ -7236,6 +7376,12 @@ mpd_qceil(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status) { mpd_context_t workctx = *ctx; + + if (mpd_isspecial(a)) { + mpd_seterror(result, MPD_Invalid_operation, status); + return; + } + workctx.round = MPD_ROUND_CEILING; (void)_mpd_qround_to_integral(TO_INT_SILENT, result, a, &workctx, status); @@ -7877,9 +8023,20 @@ void mpd_qsqrt(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status) { - _mpd_qsqrt(result, a, ctx, status); + MPD_NEW_STATIC(aa,0,0,0,0); + uint32_t xstatus = 0; - if (*status & (MPD_Malloc_error|MPD_Division_impossible)) { + if (result == a) { + if (!mpd_qcopy(&aa, a, status)) { + mpd_seterror(result, MPD_Malloc_error, status); + goto out; + } + a = &aa; + } + + _mpd_qsqrt(result, a, ctx, &xstatus); + + if (xstatus & (MPD_Malloc_error|MPD_Division_impossible)) { /* The above conditions can occur at very high context precisions * if intermediate values get too large. Retry the operation with * a lower context precision in case the result is exact. @@ -7889,22 +8046,27 @@ mpd_qsqrt(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, * * NOTE: sqrt(40e9) = 2.0e+5 /\ digits(40e9) = digits(2.0e+5) = 2 */ - uint32_t workstatus = 0; + uint32_t ystatus = 0; mpd_context_t workctx = *ctx; + workctx.prec = a->digits; - if (workctx.prec >= ctx->prec) { - return; /* No point in repeating this, keep the original error. */ + *status |= (xstatus|MPD_Errors); + goto out; /* No point in repeating this, keep the original error. */ } - _mpd_qsqrt(result, a, &workctx, &workstatus); - if (workstatus == 0) { - *status = 0; - return; + _mpd_qsqrt(result, a, &workctx, &ystatus); + if (ystatus != 0) { + ystatus = *status | ((xstatus|ystatus)&MPD_Errors); + mpd_seterror(result, ystatus, status); } - - mpd_seterror(result, *status, status); } + else { + *status |= xstatus; + } + +out: + mpd_del(&aa); } @@ -7918,6 +8080,7 @@ mpd_sizeinbase(const mpd_t *a, uint32_t base) { double x; size_t digits; + double upper_bound; assert(mpd_isinteger(a)); assert(base >= 2); @@ -7934,10 +8097,14 @@ mpd_sizeinbase(const mpd_t *a, uint32_t base) if (digits > 2711437152599294ULL) { return SIZE_MAX; } + + upper_bound = (double)((1ULL<<53)-1); +#else + upper_bound = (double)(SIZE_MAX-1); #endif x = (double)digits / log10(base); - return (x > SIZE_MAX-1) ? SIZE_MAX : (size_t)x + 1; + return (x > upper_bound) ? SIZE_MAX : (size_t)x + 1; } /* Space needed to import a base 'base' integer of length 'srclen'. */ @@ -7945,6 +8112,7 @@ static mpd_ssize_t _mpd_importsize(size_t srclen, uint32_t base) { double x; + double upper_bound; assert(srclen > 0); assert(base >= 2); @@ -7953,10 +8121,15 @@ _mpd_importsize(size_t srclen, uint32_t base) if (srclen > (1ULL<<53)) { return MPD_SSIZE_MAX; } + + assert((1ULL<<53) <= MPD_MAXIMPORT); + upper_bound = (double)((1ULL<<53)-1); +#else + upper_bound = MPD_MAXIMPORT-1; #endif x = (double)srclen * (log10(base)/MPD_RDIGITS); - return (x >= MPD_MAXIMPORT) ? MPD_SSIZE_MAX : (mpd_ssize_t)x + 1; + return (x > upper_bound) ? MPD_SSIZE_MAX : (mpd_ssize_t)x + 1; } static uint8_t @@ -8483,6 +8656,3 @@ mpd_qimport_u32(mpd_t *result, mpd_qresize(result, result->len, status); mpd_qfinalize(result, ctx, status); } - - - diff --git a/Modules/_decimal/libmpdec/mpdecimal.h b/Modules/_decimal/libmpdec/mpdecimal.h index a67dd9bc126..35ce429f601 100644 --- a/Modules/_decimal/libmpdec/mpdecimal.h +++ b/Modules/_decimal/libmpdec/mpdecimal.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,59 +26,51 @@ */ -#ifndef MPDECIMAL_H -#define MPDECIMAL_H - - -#ifdef __cplusplus -extern "C" { - #ifndef __STDC_LIMIT_MACROS - #define __STDC_LIMIT_MACROS - #define MPD_CLEAR_STDC_LIMIT_MACROS - #endif -#endif +#ifndef LIBMPDEC_MPDECIMAL_H_ +#define LIBMPDEC_MPDECIMAL_H_ #ifndef _MSC_VER #include "pyconfig.h" #endif -#include -#include -#include -#include -#include -#include -#include +#ifdef __cplusplus + #include + #include + #include + #include + #include +extern "C" { +#else + #include + #include + #include + #include + #include +#endif -#ifdef _MSC_VER - #include "vccompat.h" - #ifndef UNUSED - #define UNUSED - #endif + +#if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) && \ + defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER) + #define MPD_PRAGMA(x) _Pragma(x) + #define MPD_HIDE_SYMBOLS_START "GCC visibility push(hidden)" + #define MPD_HIDE_SYMBOLS_END "GCC visibility pop" +#else #define MPD_PRAGMA(x) #define MPD_HIDE_SYMBOLS_START #define MPD_HIDE_SYMBOLS_END +#endif + +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) + #define UNUSED __attribute__((unused)) +#else + #define UNUSED +#endif + +#if defined(_MSC_VER) + #include "vccompat.h" #define EXTINLINE extern inline #else - #ifndef __GNUC_STDC_INLINE__ - #define __GNUC_STDC_INLINE__ 1 - #endif - #if defined(__GNUC__) && !defined(__INTEL_COMPILER) - #define UNUSED __attribute__((unused)) - #else - #define UNUSED - #endif - #if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) && \ - defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER) - #define MPD_PRAGMA(x) _Pragma(x) - #define MPD_HIDE_SYMBOLS_START "GCC visibility push(hidden)" - #define MPD_HIDE_SYMBOLS_END "GCC visibility pop" - #else - #define MPD_PRAGMA(x) - #define MPD_HIDE_SYMBOLS_START - #define MPD_HIDE_SYMBOLS_END - #endif #define EXTINLINE #endif @@ -103,10 +95,10 @@ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) /******************************************************************************/ #define MPD_MAJOR_VERSION 2 -#define MPD_MINOR_VERSION 4 -#define MPD_MICRO_VERSION 2 +#define MPD_MINOR_VERSION 5 +#define MPD_MICRO_VERSION 0 -#define MPD_VERSION "2.4.2" +#define MPD_VERSION "2.5.0" #define MPD_VERSION_HEX ((MPD_MAJOR_VERSION << 24) | \ (MPD_MINOR_VERSION << 16) | \ @@ -135,6 +127,9 @@ const char *mpd_version(void); #elif defined(__x86_64__) #define CONFIG_64 #define ASM + #elif defined(__arm64__) + #define CONFIG_64 + #define ANSI #else #error "unknown architecture for universal build." #endif @@ -423,6 +418,7 @@ void mpd_print(const mpd_t *dec); /* assignment from a string */ void mpd_qset_string(mpd_t *dec, const char *s, const mpd_context_t *ctx, uint32_t *status); +void mpd_qset_string_exact(mpd_t *dec, const char *s, uint32_t *status); /* set to NaN with error flags */ void mpd_seterror(mpd_t *result, uint32_t flags, uint32_t *status); @@ -440,6 +436,8 @@ void mpd_qset_u32(mpd_t *result, uint32_t a, const mpd_context_t *ctx, uint32_t #ifndef LEGACY_COMPILER void mpd_qset_i64(mpd_t *result, int64_t a, const mpd_context_t *ctx, uint32_t *status); void mpd_qset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx, uint32_t *status); +void mpd_qset_i64_exact(mpd_t *result, int64_t a, uint32_t *status); +void mpd_qset_u64_exact(mpd_t *result, uint64_t a, uint32_t *status); #endif /* quietly assign a C integer type to an mpd_t with a static coefficient */ @@ -467,7 +465,8 @@ void mpd_qfinalize(mpd_t *result, const mpd_context_t *ctx, uint32_t *status); const char *mpd_class(const mpd_t *a, const mpd_context_t *ctx); -int mpd_qcopy(mpd_t *result, const mpd_t *a, uint32_t *status); +int mpd_qcopy(mpd_t *result, const mpd_t *a, uint32_t *status); +int mpd_qcopy_cxx(mpd_t *result, const mpd_t *a); mpd_t *mpd_qncopy(const mpd_t *a); int mpd_qcopy_abs(mpd_t *result, const mpd_t *a, uint32_t *status); int mpd_qcopy_negate(mpd_t *result, const mpd_t *a, uint32_t *status); @@ -721,7 +720,7 @@ EXTINLINE mpd_uint_t mpd_lsd(mpd_uint_t word); EXTINLINE mpd_ssize_t mpd_digits_to_size(mpd_ssize_t digits); /* number of digits in the exponent, undefined for MPD_SSIZE_MIN */ EXTINLINE int mpd_exp_digits(mpd_ssize_t exp); -EXTINLINE int mpd_iscanonical(const mpd_t *dec UNUSED); +EXTINLINE int mpd_iscanonical(const mpd_t *dec); EXTINLINE int mpd_isfinite(const mpd_t *dec); EXTINLINE int mpd_isinfinite(const mpd_t *dec); EXTINLINE int mpd_isinteger(const mpd_t *dec); @@ -833,15 +832,8 @@ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ #ifdef __cplusplus - #ifdef MPD_CLEAR_STDC_LIMIT_MACROS - #undef MPD_CLEAR_STDC_LIMIT_MACROS - #undef __STDC_LIMIT_MACROS - #endif } /* END extern "C" */ #endif -#endif /* MPDECIMAL_H */ - - - +#endif /* LIBMPDEC_MPDECIMAL_H_ */ diff --git a/Modules/_decimal/libmpdec/numbertheory.c b/Modules/_decimal/libmpdec/numbertheory.c index 4e035477e28..210e0deb371 100644 --- a/Modules/_decimal/libmpdec/numbertheory.c +++ b/Modules/_decimal/libmpdec/numbertheory.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,11 +27,13 @@ #include "mpdecimal.h" -#include + #include +#include + #include "bits.h" -#include "umodarith.h" #include "numbertheory.h" +#include "umodarith.h" /* Bignum: Initialize the Number Theoretic Transform. */ @@ -128,5 +130,3 @@ _mpd_init_w3table(mpd_uint_t w3table[3], int sign, int modnum) w3table[1] = kernel; w3table[2] = POWMOD(kernel, 2); } - - diff --git a/Modules/_decimal/libmpdec/numbertheory.h b/Modules/_decimal/libmpdec/numbertheory.h index e94c157910c..47b7753b831 100644 --- a/Modules/_decimal/libmpdec/numbertheory.h +++ b/Modules/_decimal/libmpdec/numbertheory.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,12 @@ */ -#ifndef NUMBER_THEORY_H -#define NUMBER_THEORY_H +#ifndef LIBMPDEC_NUMBERTHEORY_H_ +#define LIBMPDEC_NUMBERTHEORY_H_ -#include "constants.h" #include "mpdecimal.h" +#include "constants.h" /* Internal header file: all symbols have local scope in the DSO */ @@ -73,6 +73,4 @@ std_setmodulus(int modnum, mpd_uint_t *umod) MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif - - +#endif /* LIBMPDEC_NUMBERTHEORY_H_ */ diff --git a/Modules/_decimal/libmpdec/sixstep.c b/Modules/_decimal/libmpdec/sixstep.c index 92d513ebe18..a4d1dbed781 100644 --- a/Modules/_decimal/libmpdec/sixstep.c +++ b/Modules/_decimal/libmpdec/sixstep.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,15 +27,17 @@ #include "mpdecimal.h" -#include -#include + #include +#include + #include "bits.h" +#include "constants.h" #include "difradix2.h" #include "numbertheory.h" +#include "sixstep.h" #include "transpose.h" #include "umodarith.h" -#include "sixstep.h" /* Bignum: Cache efficient Matrix Fourier Transform for arrays of the @@ -210,5 +212,3 @@ inv_six_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum) return 1; } - - diff --git a/Modules/_decimal/libmpdec/sixstep.h b/Modules/_decimal/libmpdec/sixstep.h index 4a8b015e3a9..89b4a33afc7 100644 --- a/Modules/_decimal/libmpdec/sixstep.h +++ b/Modules/_decimal/libmpdec/sixstep.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,11 @@ */ -#ifndef SIX_STEP_H -#define SIX_STEP_H +#ifndef LIBMPDEC_SIXSTEP_H_ +#define LIBMPDEC_SIXSTEP_H_ #include "mpdecimal.h" -#include /* Internal header file: all symbols have local scope in the DSO */ @@ -45,4 +44,4 @@ int inv_six_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif +#endif /* LIBMPDEC_SIXSTEP_H_ */ diff --git a/Modules/_decimal/libmpdec/transpose.c b/Modules/_decimal/libmpdec/transpose.c index 55d6d899227..56321b5f39a 100644 --- a/Modules/_decimal/libmpdec/transpose.c +++ b/Modules/_decimal/libmpdec/transpose.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,15 +27,17 @@ #include "mpdecimal.h" + +#include +#include #include #include #include -#include -#include + #include "bits.h" #include "constants.h" -#include "typearith.h" #include "transpose.h" +#include "typearith.h" #define BUFSIZE 4096 @@ -272,5 +274,3 @@ transpose_pow2(mpd_uint_t *matrix, mpd_size_t rows, mpd_size_t cols) return 1; } - - diff --git a/Modules/_decimal/libmpdec/transpose.h b/Modules/_decimal/libmpdec/transpose.h index e1cd1fa17dd..e91c18d7435 100644 --- a/Modules/_decimal/libmpdec/transpose.h +++ b/Modules/_decimal/libmpdec/transpose.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,11 @@ */ -#ifndef TRANSPOSE_H -#define TRANSPOSE_H +#ifndef LIBMPDEC_TRANSPOSE_H_ +#define LIBMPDEC_TRANSPOSE_H_ #include "mpdecimal.h" -#include /* Internal header file: all symbols have local scope in the DSO */ @@ -59,4 +58,4 @@ static inline void pointerswap(mpd_uint_t **a, mpd_uint_t **b) MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif +#endif /* LIBMPDEC_TRANSPOSE_H_ */ diff --git a/Modules/_decimal/libmpdec/typearith.h b/Modules/_decimal/libmpdec/typearith.h index 405237dac51..47961788d76 100644 --- a/Modules/_decimal/libmpdec/typearith.h +++ b/Modules/_decimal/libmpdec/typearith.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,14 @@ */ -#ifndef TYPEARITH_H -#define TYPEARITH_H +#ifndef LIBMPDEC_TYPEARITH_H_ +#define LIBMPDEC_TYPEARITH_H_ #include "mpdecimal.h" +#include + /*****************************************************************************/ /* Low level native arithmetic on basic types */ @@ -663,7 +665,4 @@ mulmod_size_t(mpd_size_t a, mpd_size_t b, mpd_size_t m) } -#endif /* TYPEARITH_H */ - - - +#endif /* LIBMPDEC_TYPEARITH_H_ */ diff --git a/Modules/_decimal/libmpdec/umodarith.h b/Modules/_decimal/libmpdec/umodarith.h index 68d15188cb3..d7dbbbe6a73 100644 --- a/Modules/_decimal/libmpdec/umodarith.h +++ b/Modules/_decimal/libmpdec/umodarith.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,13 @@ */ -#ifndef UMODARITH_H -#define UMODARITH_H +#ifndef LIBMPDEC_UMODARITH_H_ +#define LIBMPDEC_UMODARITH_H_ +#include "mpdecimal.h" + #include "constants.h" -#include "mpdecimal.h" #include "typearith.h" @@ -644,7 +645,4 @@ ppro_powmod(mpd_uint_t base, mpd_uint_t exp, double *dmod, uint32_t *dinvmod) #endif /* CONFIG_32 */ -#endif /* UMODARITH_H */ - - - +#endif /* LIBMPDEC_UMODARITH_H_ */ diff --git a/Modules/_decimal/libmpdec/vccompat.h b/Modules/_decimal/libmpdec/vccompat.h index 2ba805dcc56..e2e1c42cc02 100644 --- a/Modules/_decimal/libmpdec/vccompat.h +++ b/Modules/_decimal/libmpdec/vccompat.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,14 +26,16 @@ */ -#ifndef VCCOMPAT_H -#define VCCOMPAT_H +#ifndef LIBMPDEC_VCCOMPAT_H_ +#define LIBMPDEC_VCCOMPAT_H_ /* Visual C fixes: no snprintf ... */ #ifdef _MSC_VER - #undef inline - #define inline __inline + #ifndef __cplusplus + #undef inline + #define inline __inline + #endif #undef random #define random rand #undef srandom @@ -51,7 +53,4 @@ #endif -#endif /* VCCOMPAT_H */ - - - +#endif /* LIBMPDEC_VCCOMPAT_H_ */ diff --git a/Modules/_decimal/libmpdec/vcdiv64.asm b/Modules/_decimal/libmpdec/vcdiv64.asm index 6b6645673ab..597e9ba9352 100644 --- a/Modules/_decimal/libmpdec/vcdiv64.asm +++ b/Modules/_decimal/libmpdec/vcdiv64.asm @@ -1,5 +1,5 @@ ; -; Copyright (c) 2008-2016 Stefan Krah. All rights reserved. +; Copyright (c) 2008-2020 Stefan Krah. All rights reserved. ; ; Redistribution and use in source and binary forms, with or without ; modification, are permitted provided that the following conditions @@ -44,5 +44,3 @@ _mpd_div_words PROC _mpd_div_words ENDP _TEXT ENDS END - - diff --git a/Modules/_decimal/tests/deccheck.py b/Modules/_decimal/tests/deccheck.py index 5cd5db57114..5d9179e6168 100644 --- a/Modules/_decimal/tests/deccheck.py +++ b/Modules/_decimal/tests/deccheck.py @@ -29,9 +29,20 @@ # Usage: python deccheck.py [--short|--medium|--long|--all] # -import sys, random + +import sys +import os +import time +import random from copy import copy from collections import defaultdict + +import argparse +import subprocess +from subprocess import PIPE, STDOUT +from queue import Queue, Empty +from threading import Thread, Event, Lock + from test.support import import_fresh_module from randdec import randfloat, all_unary, all_binary, all_ternary from randdec import unary_optarg, binary_optarg, ternary_optarg @@ -1124,18 +1135,35 @@ def check_untested(funcdict, c_cls, p_cls): funcdict['untested'] = tuple(sorted(intersect-tested)) - #for key in ('untested', 'c_only', 'p_only'): - # s = 'Context' if c_cls == C.Context else 'Decimal' - # print("\n%s %s:\n%s" % (s, key, funcdict[key])) + # for key in ('untested', 'c_only', 'p_only'): + # s = 'Context' if c_cls == C.Context else 'Decimal' + # print("\n%s %s:\n%s" % (s, key, funcdict[key])) if __name__ == '__main__': - import time + parser = argparse.ArgumentParser(prog="deccheck.py") + + group = parser.add_mutually_exclusive_group() + group.add_argument('--short', dest='time', action="store_const", const='short', default='short', help="short test (default)") + group.add_argument('--medium', dest='time', action="store_const", const='medium', default='short', help="medium test (reasonable run time)") + group.add_argument('--long', dest='time', action="store_const", const='long', default='short', help="long test (long run time)") + group.add_argument('--all', dest='time', action="store_const", const='all', default='short', help="all tests (excessive run time)") + + group = parser.add_mutually_exclusive_group() + group.add_argument('--single', dest='single', nargs=1, default=False, metavar="TEST", help="run a single test") + group.add_argument('--multicore', dest='multicore', action="store_true", default=False, help="use all available cores") + + args = parser.parse_args() + assert args.single is False or args.multicore is False + if args.single: + args.single = args.single[0] + randseed = int(time.time()) random.seed(randseed) + # Set up the testspecs list. A testspec is simply a dictionary # that determines the amount of different contexts that 'test_method' # will generate. @@ -1168,17 +1196,17 @@ if __name__ == '__main__': {'prec': [34], 'expts': [(-6143, 6144)], 'clamp': 1, 'iter': None} ] - if '--medium' in sys.argv: + if args.time == 'medium': base['expts'].append(('rand', 'rand')) # 5 random precisions base['samples'] = 5 testspecs = [small] + ieee + [base] - if '--long' in sys.argv: + elif args.time == 'long': base['expts'].append(('rand', 'rand')) # 10 random precisions base['samples'] = 10 testspecs = [small] + ieee + [base] - elif '--all' in sys.argv: + elif args.time == 'all': base['expts'].append(('rand', 'rand')) # All precisions in [1, 100] base['samples'] = 100 @@ -1195,39 +1223,100 @@ if __name__ == '__main__': small['expts'] = [(-prec, prec)] testspecs = [small, rand_ieee, base] + check_untested(Functions, C.Decimal, P.Decimal) check_untested(ContextFunctions, C.Context, P.Context) - log("\n\nRandom seed: %d\n\n", randseed) + if args.multicore: + q = Queue() + elif args.single: + log("Random seed: %d", randseed) + else: + log("\n\nRandom seed: %d\n\n", randseed) + + + FOUND_METHOD = False + def do_single(method, f): + global FOUND_METHOD + if args.multicore: + q.put(method) + elif not args.single or args.single == method: + FOUND_METHOD = True + f() # Decimal methods: for method in Functions['unary'] + Functions['unary_ctx'] + \ Functions['unary_rnd_ctx']: - test_method(method, testspecs, test_unary) + do_single(method, lambda: test_method(method, testspecs, test_unary)) for method in Functions['binary'] + Functions['binary_ctx']: - test_method(method, testspecs, test_binary) + do_single(method, lambda: test_method(method, testspecs, test_binary)) for method in Functions['ternary'] + Functions['ternary_ctx']: - test_method(method, testspecs, test_ternary) + name = '__powmod__' if method == '__pow__' else method + do_single(name, lambda: test_method(method, testspecs, test_ternary)) - test_method('__format__', testspecs, test_format) - test_method('__round__', testspecs, test_round) - test_method('from_float', testspecs, test_from_float) - test_method('quantize', testspecs, test_quantize_api) + do_single('__format__', lambda: test_method('__format__', testspecs, test_format)) + do_single('__round__', lambda: test_method('__round__', testspecs, test_round)) + do_single('from_float', lambda: test_method('from_float', testspecs, test_from_float)) + do_single('quantize_api', lambda: test_method('quantize', testspecs, test_quantize_api)) # Context methods: for method in ContextFunctions['unary']: - test_method(method, testspecs, test_unary) + do_single(method, lambda: test_method(method, testspecs, test_unary)) for method in ContextFunctions['binary']: - test_method(method, testspecs, test_binary) + do_single(method, lambda: test_method(method, testspecs, test_binary)) for method in ContextFunctions['ternary']: - test_method(method, testspecs, test_ternary) + name = 'context.powmod' if method == 'context.power' else method + do_single(name, lambda: test_method(method, testspecs, test_ternary)) - test_method('context.create_decimal_from_float', testspecs, test_from_float) + do_single('context.create_decimal_from_float', + lambda: test_method('context.create_decimal_from_float', + testspecs, test_from_float)) + if args.multicore: + error = Event() + write_lock = Lock() - sys.exit(EXIT_STATUS) + def write_output(out, returncode): + if returncode != 0: + error.set() + + with write_lock: + sys.stdout.buffer.write(out + b"\n") + sys.stdout.buffer.flush() + + def tfunc(): + while not error.is_set(): + try: + test = q.get(block=False, timeout=-1) + except Empty: + return + + cmd = [sys.executable, "deccheck.py", "--%s" % args.time, "--single", test] + p = subprocess.Popen(cmd, stdout=PIPE, stderr=STDOUT) + out, _ = p.communicate() + write_output(out, p.returncode) + + N = os.cpu_count() + t = N * [None] + + for i in range(N): + t[i] = Thread(target=tfunc) + t[i].start() + + for i in range(N): + t[i].join() + + sys.exit(1 if error.is_set() else 0) + + elif args.single: + if not FOUND_METHOD: + log("\nerror: cannot find method \"%s\"" % args.single) + EXIT_STATUS = 1 + sys.exit(EXIT_STATUS) + else: + sys.exit(EXIT_STATUS) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index d158d3bae15..bb86fe862da 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -1,6 +1,6 @@ #include "Python.h" #include "pycore_pystate.h" // _PyThreadState_GET() -#include "pycore_tupleobject.h" +#include "pycore_tuple.h" // _PyTuple_ITEMS() #include "structmember.h" // PyMemberDef /* _functools module written and maintained @@ -484,8 +484,7 @@ static int keyobject_traverse(keyobject *ko, visitproc visit, void *arg) { Py_VISIT(ko->cmp); - if (ko->object) - Py_VISIT(ko->object); + Py_VISIT(ko->object); return 0; } @@ -680,7 +679,7 @@ functools_reduce(PyObject *self, PyObject *args) if (result == NULL) PyErr_SetString(PyExc_TypeError, - "reduce() of empty sequence with no initial value"); + "reduce() of empty iterable with no initial value"); Py_DECREF(it); return result; @@ -693,14 +692,14 @@ Fail: } PyDoc_STRVAR(functools_reduce_doc, -"reduce(function, sequence[, initial]) -> value\n\ +"reduce(function, iterable[, initial]) -> value\n\ \n\ -Apply a function of two arguments cumulatively to the items of a sequence,\n\ -from left to right, so as to reduce the sequence to a single value.\n\ -For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\ +Apply a function of two arguments cumulatively to the items of a sequence\n\ +or iterable, from left to right, so as to reduce the iterable to a single\n\ +value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\ ((((1+2)+3)+4)+5). If initial is present, it is placed before the items\n\ -of the sequence in the calculation, and serves as a default when the\n\ -sequence is empty."); +of the iterable in the calculation, and serves as a default when the\n\ +iterable is empty."); /* lru_cache object **********************************************************/ diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c index dd4c6b16f74..9e843acbaa6 100644 --- a/Modules/_gdbmmodule.c +++ b/Modules/_gdbmmodule.c @@ -1,5 +1,5 @@ -/* DBM module using dictionary interface */ +/* GDBM module using dictionary interface */ /* Author: Anthony Baxter, after dbmmodule.c */ /* Doc strings: Mitch Chapman */ @@ -16,11 +16,24 @@ extern const char * gdbm_strerror(gdbm_error); #endif +typedef struct { + PyTypeObject *gdbm_type; + PyObject *gdbm_error; +} _gdbm_state; + +static inline _gdbm_state* +get_gdbm_state(PyObject *module) +{ + void *state = PyModule_GetState(module); + assert(state != NULL); + return (_gdbm_state *)state; +} + /*[clinic input] module _gdbm -class _gdbm.gdbm "dbmobject *" "&Dbmtype" +class _gdbm.gdbm "gdbmobject *" "&Gdbmtype" [clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=113927c6170729b2]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=38ae71cedfc7172b]*/ PyDoc_STRVAR(gdbmmodule__doc__, "This module provides an interface to the GNU DBM (GDBM) library.\n\ @@ -38,20 +51,15 @@ typedef struct { PyObject_HEAD Py_ssize_t di_size; /* -1 means recompute */ GDBM_FILE di_dbm; -} dbmobject; - -static PyTypeObject Dbmtype; +} gdbmobject; #include "clinic/_gdbmmodule.c.h" -#define is_dbmobject(v) Py_IS_TYPE(v, &Dbmtype) -#define check_dbmobject_open(v) if ((v)->di_dbm == NULL) \ - { PyErr_SetString(DbmError, "GDBM object has already been closed"); \ - return NULL; } - - - -static PyObject *DbmError; +#define check_gdbmobject_open(v, err) \ + if ((v)->di_dbm == NULL) { \ + PyErr_SetString(err, "GDBM object has already been closed"); \ + return NULL; \ + } PyDoc_STRVAR(gdbm_object__doc__, "This object represents a GDBM database.\n\ @@ -64,20 +72,21 @@ GDBM objects also support additional operations such as firstkey,\n\ nextkey, reorganize, and sync."); static PyObject * -newdbmobject(const char *file, int flags, int mode) +newgdbmobject(_gdbm_state *state, const char *file, int flags, int mode) { - dbmobject *dp; - - dp = PyObject_New(dbmobject, &Dbmtype); - if (dp == NULL) + gdbmobject *dp = PyObject_New(gdbmobject, state->gdbm_type); + if (dp == NULL) { return NULL; + } dp->di_size = -1; errno = 0; if ((dp->di_dbm = gdbm_open((char *)file, 0, flags, mode, NULL)) == 0) { - if (errno != 0) - PyErr_SetFromErrnoWithFilename(DbmError, file); - else - PyErr_SetString(DbmError, gdbm_strerror(gdbm_errno)); + if (errno != 0) { + PyErr_SetFromErrnoWithFilename(state->gdbm_error, file); + } + else { + PyErr_SetString(state->gdbm_error, gdbm_strerror(gdbm_errno)); + } Py_DECREF(dp); return NULL; } @@ -87,18 +96,22 @@ newdbmobject(const char *file, int flags, int mode) /* Methods */ static void -dbm_dealloc(dbmobject *dp) +gdbm_dealloc(gdbmobject *dp) { - if (dp->di_dbm) + if (dp->di_dbm) { gdbm_close(dp->di_dbm); - PyObject_Del(dp); + } + PyTypeObject *tp = Py_TYPE(dp); + tp->tp_free(dp); + Py_DECREF(tp); } static Py_ssize_t -dbm_length(dbmobject *dp) +gdbm_length(gdbmobject *dp) { + _gdbm_state *state = PyType_GetModuleState(Py_TYPE(dp)); if (dp->di_dbm == NULL) { - PyErr_SetString(DbmError, "GDBM object has already been closed"); + PyErr_SetString(state->gdbm_error, "GDBM object has already been closed"); return -1; } if (dp->di_size < 0) { @@ -107,10 +120,10 @@ dbm_length(dbmobject *dp) gdbm_count_t count; if (gdbm_count(dp->di_dbm, &count) == -1) { if (errno != 0) { - PyErr_SetFromErrno(DbmError); + PyErr_SetFromErrno(state->gdbm_error); } else { - PyErr_SetString(DbmError, gdbm_strerror(gdbm_errno)); + PyErr_SetString(state->gdbm_error, gdbm_strerror(gdbm_errno)); } return -1; } @@ -161,16 +174,17 @@ parse_datum(PyObject *o, datum *d, const char *failmsg) } static PyObject * -dbm_subscript(dbmobject *dp, PyObject *key) +gdbm_subscript(gdbmobject *dp, PyObject *key) { PyObject *v; datum drec, krec; + _gdbm_state *state = PyType_GetModuleState(Py_TYPE(dp)); if (!parse_datum(key, &krec, NULL)) { return NULL; } if (dp->di_dbm == NULL) { - PyErr_SetString(DbmError, + PyErr_SetString(state->gdbm_error, "GDBM object has already been closed"); return NULL; } @@ -195,12 +209,12 @@ Get the value for key, or default if not present. [clinic start generated code]*/ static PyObject * -_gdbm_gdbm_get_impl(dbmobject *self, PyObject *key, PyObject *default_value) -/*[clinic end generated code: output=19b7c585ad4f554a input=a9c20423f34c17b6]*/ +_gdbm_gdbm_get_impl(gdbmobject *self, PyObject *key, PyObject *default_value) +/*[clinic end generated code: output=92421838f3a852f4 input=a9c20423f34c17b6]*/ { PyObject *res; - res = dbm_subscript(self, key); + res = gdbm_subscript(self, key); if (res == NULL && PyErr_ExceptionMatches(PyExc_KeyError)) { PyErr_Clear(); Py_INCREF(default_value); @@ -210,16 +224,17 @@ _gdbm_gdbm_get_impl(dbmobject *self, PyObject *key, PyObject *default_value) } static int -dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w) +gdbm_ass_sub(gdbmobject *dp, PyObject *v, PyObject *w) { datum krec, drec; const char *failmsg = "gdbm mappings have bytes or string indices only"; + _gdbm_state *state = PyType_GetModuleState(Py_TYPE(dp)); if (!parse_datum(v, &krec, failmsg)) { return -1; } if (dp->di_dbm == NULL) { - PyErr_SetString(DbmError, + PyErr_SetString(state->gdbm_error, "GDBM object has already been closed"); return -1; } @@ -230,7 +245,7 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w) PyErr_SetObject(PyExc_KeyError, v); } else { - PyErr_SetString(DbmError, gdbm_strerror(gdbm_errno)); + PyErr_SetString(state->gdbm_error, gdbm_strerror(gdbm_errno)); } return -1; } @@ -242,9 +257,9 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w) errno = 0; if (gdbm_store(dp->di_dbm, krec, drec, GDBM_REPLACE) < 0) { if (errno != 0) - PyErr_SetFromErrno(DbmError); + PyErr_SetFromErrno(state->gdbm_error); else - PyErr_SetString(DbmError, + PyErr_SetString(state->gdbm_error, gdbm_strerror(gdbm_errno)); return -1; } @@ -263,28 +278,22 @@ Get value for key, or set it to default and return default if not present. [clinic start generated code]*/ static PyObject * -_gdbm_gdbm_setdefault_impl(dbmobject *self, PyObject *key, +_gdbm_gdbm_setdefault_impl(gdbmobject *self, PyObject *key, PyObject *default_value) -/*[clinic end generated code: output=88760ee520329012 input=0db46b69e9680171]*/ +/*[clinic end generated code: output=f3246e880509f142 input=0db46b69e9680171]*/ { PyObject *res; - res = dbm_subscript(self, key); + res = gdbm_subscript(self, key); if (res == NULL && PyErr_ExceptionMatches(PyExc_KeyError)) { PyErr_Clear(); - if (dbm_ass_sub(self, key, default_value) < 0) + if (gdbm_ass_sub(self, key, default_value) < 0) return NULL; - return dbm_subscript(self, key); + return gdbm_subscript(self, key); } return res; } -static PyMappingMethods dbm_as_mapping = { - (lenfunc)dbm_length, /*mp_length*/ - (binaryfunc)dbm_subscript, /*mp_subscript*/ - (objobjargproc)dbm_ass_sub, /*mp_ass_subscript*/ -}; - /*[clinic input] _gdbm.gdbm.close @@ -292,11 +301,12 @@ Close the database. [clinic start generated code]*/ static PyObject * -_gdbm_gdbm_close_impl(dbmobject *self) -/*[clinic end generated code: output=23512a594598b563 input=0a203447379b45fd]*/ +_gdbm_gdbm_close_impl(gdbmobject *self) +/*[clinic end generated code: output=f5abb4d6bb9e52d5 input=0a203447379b45fd]*/ { - if (self->di_dbm) + if (self->di_dbm) { gdbm_close(self->di_dbm); + } self->di_dbm = NULL; Py_RETURN_NONE; } @@ -305,22 +315,27 @@ _gdbm_gdbm_close_impl(dbmobject *self) /*[clinic input] _gdbm.gdbm.keys + cls: defining_class + Get a list of all keys in the database. [clinic start generated code]*/ static PyObject * -_gdbm_gdbm_keys_impl(dbmobject *self) -/*[clinic end generated code: output=cb4b1776c3645dcc input=1832ee0a3132cfaf]*/ +_gdbm_gdbm_keys_impl(gdbmobject *self, PyTypeObject *cls) +/*[clinic end generated code: output=c24b824e81404755 input=1428b7c79703d7d5]*/ { PyObject *v, *item; datum key, nextkey; int err; - if (self == NULL || !is_dbmobject(self)) { + _gdbm_state *state = PyType_GetModuleState(cls); + assert(state != NULL); + + if (self == NULL || !Py_IS_TYPE(self, state->gdbm_type)) { PyErr_BadInternalCall(); return NULL; } - check_dbmobject_open(self); + check_gdbmobject_open(self, state->gdbm_error); v = PyList_New(0); if (v == NULL) @@ -349,14 +364,15 @@ _gdbm_gdbm_keys_impl(dbmobject *self) } static int -dbm_contains(PyObject *self, PyObject *arg) +gdbm_contains(PyObject *self, PyObject *arg) { - dbmobject *dp = (dbmobject *)self; + gdbmobject *dp = (gdbmobject *)self; datum key; Py_ssize_t size; + _gdbm_state *state = PyType_GetModuleState(Py_TYPE(dp)); if ((dp)->di_dbm == NULL) { - PyErr_SetString(DbmError, + PyErr_SetString(state->gdbm_error, "GDBM object has already been closed"); return -1; } @@ -379,22 +395,11 @@ dbm_contains(PyObject *self, PyObject *arg) return gdbm_exists(dp->di_dbm, key); } -static PySequenceMethods dbm_as_sequence = { - 0, /* sq_length */ - 0, /* sq_concat */ - 0, /* sq_repeat */ - 0, /* sq_item */ - 0, /* sq_slice */ - 0, /* sq_ass_item */ - 0, /* sq_ass_slice */ - dbm_contains, /* sq_contains */ - 0, /* sq_inplace_concat */ - 0, /* sq_inplace_repeat */ -}; - /*[clinic input] _gdbm.gdbm.firstkey + cls: defining_class + Return the starting key for the traversal. It's possible to loop over every key in the database using this method @@ -403,13 +408,15 @@ hash values, and won't be sorted by the key values. [clinic start generated code]*/ static PyObject * -_gdbm_gdbm_firstkey_impl(dbmobject *self) -/*[clinic end generated code: output=9ff85628d84b65d2 input=0dbd6a335d69bba0]*/ +_gdbm_gdbm_firstkey_impl(gdbmobject *self, PyTypeObject *cls) +/*[clinic end generated code: output=139275e9c8b60827 input=ed8782a029a5d299]*/ { PyObject *v; datum key; + _gdbm_state *state = PyType_GetModuleState(cls); + assert(state != NULL); - check_dbmobject_open(self); + check_gdbmobject_open(self, state->gdbm_error); key = gdbm_firstkey(self->di_dbm); if (key.dptr) { v = PyBytes_FromStringAndSize(key.dptr, key.dsize); @@ -424,6 +431,7 @@ _gdbm_gdbm_firstkey_impl(dbmobject *self) /*[clinic input] _gdbm.gdbm.nextkey + cls: defining_class key: str(accept={str, robuffer}, zeroes=True) / @@ -439,16 +447,18 @@ to create a list in memory that contains them all: [clinic start generated code]*/ static PyObject * -_gdbm_gdbm_nextkey_impl(dbmobject *self, const char *key, +_gdbm_gdbm_nextkey_impl(gdbmobject *self, PyTypeObject *cls, const char *key, Py_ssize_clean_t key_length) -/*[clinic end generated code: output=192ab892de6eb2f6 input=1f1606943614e36f]*/ +/*[clinic end generated code: output=204964441fdbaf02 input=fcf6a51a96ce0172]*/ { PyObject *v; datum dbm_key, nextkey; + _gdbm_state *state = PyType_GetModuleState(cls); + assert(state != NULL); dbm_key.dptr = (char *)key; dbm_key.dsize = key_length; - check_dbmobject_open(self); + check_gdbmobject_open(self, state->gdbm_error); nextkey = gdbm_nextkey(self->di_dbm, dbm_key); if (nextkey.dptr) { v = PyBytes_FromStringAndSize(nextkey.dptr, nextkey.dsize); @@ -463,6 +473,8 @@ _gdbm_gdbm_nextkey_impl(dbmobject *self, const char *key, /*[clinic input] _gdbm.gdbm.reorganize + cls: defining_class + Reorganize the database. If you have carried out a lot of deletions and would like to shrink @@ -473,16 +485,18 @@ kept and reused as new (key,value) pairs are added. [clinic start generated code]*/ static PyObject * -_gdbm_gdbm_reorganize_impl(dbmobject *self) -/*[clinic end generated code: output=38d9624df92e961d input=f6bea85bcfd40dd2]*/ +_gdbm_gdbm_reorganize_impl(gdbmobject *self, PyTypeObject *cls) +/*[clinic end generated code: output=d77c69e8e3dd644a input=e1359faeef844e46]*/ { - check_dbmobject_open(self); + _gdbm_state *state = PyType_GetModuleState(cls); + assert(state != NULL); + check_gdbmobject_open(self, state->gdbm_error); errno = 0; if (gdbm_reorganize(self->di_dbm) < 0) { if (errno != 0) - PyErr_SetFromErrno(DbmError); + PyErr_SetFromErrno(state->gdbm_error); else - PyErr_SetString(DbmError, gdbm_strerror(gdbm_errno)); + PyErr_SetString(state->gdbm_error, gdbm_strerror(gdbm_errno)); return NULL; } Py_RETURN_NONE; @@ -491,6 +505,8 @@ _gdbm_gdbm_reorganize_impl(dbmobject *self) /*[clinic input] _gdbm.gdbm.sync + cls: defining_class + Flush the database to the disk file. When the database has been opened in fast mode, this method forces @@ -498,29 +514,31 @@ any unwritten data to be written to the disk. [clinic start generated code]*/ static PyObject * -_gdbm_gdbm_sync_impl(dbmobject *self) -/*[clinic end generated code: output=488b15f47028f125 input=2a47d2c9e153ab8a]*/ +_gdbm_gdbm_sync_impl(gdbmobject *self, PyTypeObject *cls) +/*[clinic end generated code: output=bb680a2035c3f592 input=3d749235f79b6f2a]*/ { - check_dbmobject_open(self); + _gdbm_state *state = PyType_GetModuleState(cls); + assert(state != NULL); + check_gdbmobject_open(self, state->gdbm_error); gdbm_sync(self->di_dbm); Py_RETURN_NONE; } static PyObject * -dbm__enter__(PyObject *self, PyObject *args) +gdbm__enter__(PyObject *self, PyObject *args) { Py_INCREF(self); return self; } static PyObject * -dbm__exit__(PyObject *self, PyObject *args) +gdbm__exit__(PyObject *self, PyObject *args) { _Py_IDENTIFIER(close); return _PyObject_CallMethodIdNoArgs(self, &PyId_close); } -static PyMethodDef dbm_methods[] = { +static PyMethodDef gdbm_methods[] = { _GDBM_GDBM_CLOSE_METHODDEF _GDBM_GDBM_KEYS_METHODDEF _GDBM_GDBM_FIRSTKEY_METHODDEF @@ -529,46 +547,38 @@ static PyMethodDef dbm_methods[] = { _GDBM_GDBM_SYNC_METHODDEF _GDBM_GDBM_GET_METHODDEF _GDBM_GDBM_SETDEFAULT_METHODDEF - {"__enter__", dbm__enter__, METH_NOARGS, NULL}, - {"__exit__", dbm__exit__, METH_VARARGS, NULL}, + {"__enter__", gdbm__enter__, METH_NOARGS, NULL}, + {"__exit__", gdbm__exit__, METH_VARARGS, NULL}, {NULL, NULL} /* sentinel */ }; -static PyTypeObject Dbmtype = { - PyVarObject_HEAD_INIT(0, 0) - "_gdbm.gdbm", - sizeof(dbmobject), - 0, - (destructor)dbm_dealloc, /*tp_dealloc*/ - 0, /*tp_vectorcall_offset*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_as_async*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - &dbm_as_sequence, /*tp_as_sequence*/ - &dbm_as_mapping, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /*tp_xxx4*/ - gdbm_object__doc__, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - dbm_methods, /*tp_methods*/ +static PyType_Slot gdbmtype_spec_slots[] = { + {Py_tp_dealloc, gdbm_dealloc}, + {Py_tp_methods, gdbm_methods}, + {Py_sq_contains, gdbm_contains}, + {Py_mp_length, gdbm_length}, + {Py_mp_subscript, gdbm_subscript}, + {Py_mp_ass_subscript, gdbm_ass_sub}, + {Py_tp_doc, (char*)gdbm_object__doc__}, + {0, 0} +}; + +static PyType_Spec gdbmtype_spec = { + .name = "_gdbm.gdbm", + .basicsize = sizeof(gdbmobject), + // Calling PyType_GetModuleState() on a subclass is not safe. + // dbmtype_spec does not have Py_TPFLAGS_BASETYPE flag + // which prevents to create a subclass. + // So calling PyType_GetModuleState() in this file is always safe. + .flags = Py_TPFLAGS_DEFAULT, + .slots = gdbmtype_spec_slots, }; /* ----------------------------------------------------------------- */ /*[clinic input] _gdbm.open as dbmopen + filename: unicode flags: str="r" mode: int(py_default="0o666") = 0o666 @@ -601,9 +611,11 @@ when the database has to be created. It defaults to octal 0o666. static PyObject * dbmopen_impl(PyObject *module, PyObject *filename, const char *flags, int mode) -/*[clinic end generated code: output=9527750f5df90764 input=3be0b0875974b928]*/ +/*[clinic end generated code: output=9527750f5df90764 input=812b7d74399ceb0e]*/ { int iflags; + _gdbm_state *state = get_gdbm_state(module); + assert(state != NULL); switch (flags[0]) { case 'r': @@ -619,7 +631,7 @@ dbmopen_impl(PyObject *module, PyObject *filename, const char *flags, iflags = GDBM_NEWDB; break; default: - PyErr_SetString(DbmError, + PyErr_SetString(state->gdbm_error, "First flag must be one of 'r', 'w', 'c' or 'n'"); return NULL; } @@ -644,7 +656,7 @@ dbmopen_impl(PyObject *module, PyObject *filename, const char *flags, default: PyOS_snprintf(buf, sizeof(buf), "Flag '%c' is not supported.", *flags); - PyErr_SetString(DbmError, buf); + PyErr_SetString(state->gdbm_error, buf); return NULL; } } @@ -659,12 +671,12 @@ dbmopen_impl(PyObject *module, PyObject *filename, const char *flags, PyErr_SetString(PyExc_ValueError, "embedded null character"); return NULL; } - PyObject *self = newdbmobject(name, iflags, mode); + PyObject *self = newgdbmobject(state, name, iflags, mode); Py_DECREF(filenamebytes); return self; } -static const char dbmmodule_open_flags[] = "rwcn" +static const char gdbmmodule_open_flags[] = "rwcn" #ifdef GDBM_FAST "f" #endif @@ -676,48 +688,30 @@ static const char dbmmodule_open_flags[] = "rwcn" #endif ; -static PyMethodDef dbmmodule_methods[] = { +static PyMethodDef _gdbm_module_methods[] = { DBMOPEN_METHODDEF { 0, 0 }, }; - -static struct PyModuleDef _gdbmmodule = { - PyModuleDef_HEAD_INIT, - "_gdbm", - gdbmmodule__doc__, - -1, - dbmmodule_methods, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC -PyInit__gdbm(void) { - PyObject *m; - - if (PyType_Ready(&Dbmtype) < 0) - return NULL; - m = PyModule_Create(&_gdbmmodule); - if (m == NULL) { - return NULL; +static int +_gdbm_exec(PyObject *module) +{ + _gdbm_state *state = get_gdbm_state(module); + state->gdbm_type = (PyTypeObject *)PyType_FromModuleAndSpec(module, + &gdbmtype_spec, NULL); + if (state->gdbm_type == NULL) { + return -1; } - - DbmError = PyErr_NewException("_gdbm.error", PyExc_OSError, NULL); - if (DbmError == NULL) { - goto error; + state->gdbm_error = PyErr_NewException("_gdbm.error", PyExc_OSError, NULL); + if (state->gdbm_error == NULL) { + return -1; } - Py_INCREF(DbmError); - if (PyModule_AddObject(m, "error", DbmError) < 0) { - Py_DECREF(DbmError); - goto error; + if (PyModule_AddType(module, (PyTypeObject *)state->gdbm_error) < 0) { + return -1; } - - if (PyModule_AddStringConstant(m, "open_flags", - dbmmodule_open_flags) < 0) { - goto error; + if (PyModule_AddStringConstant(module, "open_flags", + gdbmmodule_open_flags) < 0) { + return -1; } #if defined(GDBM_VERSION_MAJOR) && defined(GDBM_VERSION_MINOR) && \ @@ -725,17 +719,59 @@ PyInit__gdbm(void) { PyObject *obj = Py_BuildValue("iii", GDBM_VERSION_MAJOR, GDBM_VERSION_MINOR, GDBM_VERSION_PATCH); if (obj == NULL) { - goto error; + return -1; } - if (PyModule_AddObject(m, "_GDBM_VERSION", obj) < 0) { + if (PyModule_AddObject(module, "_GDBM_VERSION", obj) < 0) { Py_DECREF(obj); - goto error; + return -1; } #endif - - return m; - -error: - Py_DECREF(m); - return NULL; + return 0; +} + +static int +_gdbm_module_traverse(PyObject *module, visitproc visit, void *arg) +{ + _gdbm_state *state = get_gdbm_state(module); + Py_VISIT(state->gdbm_error); + Py_VISIT(state->gdbm_type); + return 0; +} + +static int +_gdbm_module_clear(PyObject *module) +{ + _gdbm_state *state = get_gdbm_state(module); + Py_CLEAR(state->gdbm_error); + Py_CLEAR(state->gdbm_type); + return 0; +} + +static void +_gdbm_module_free(void *module) +{ + _gdbm_module_clear((PyObject *)module); +} + +static PyModuleDef_Slot _gdbm_module_slots[] = { + {Py_mod_exec, _gdbm_exec}, + {0, NULL} +}; + +static struct PyModuleDef _gdbmmodule = { + PyModuleDef_HEAD_INIT, + .m_name = "_gdbm", + .m_doc = gdbmmodule__doc__, + .m_size = sizeof(_gdbm_state), + .m_methods = _gdbm_module_methods, + .m_slots = _gdbm_module_slots, + .m_traverse = _gdbm_module_traverse, + .m_clear = _gdbm_module_clear, + .m_free = _gdbm_module_free, +}; + +PyMODINIT_FUNC +PyInit__gdbm(void) +{ + return PyModuleDef_Init(&_gdbmmodule); } diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index 0b2ef95a6f1..adc86537732 100644 --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -21,6 +21,7 @@ /* EVP is the preferred interface to hashing in OpenSSL */ #include #include +#include /* We use the object interface to discover what hashes OpenSSL supports. */ #include #include "openssl/err.h" @@ -1833,6 +1834,120 @@ _hashlib_get_fips_mode_impl(PyObject *module) #endif // !LIBRESSL_VERSION_NUMBER +static int +_tscmp(const unsigned char *a, const unsigned char *b, + Py_ssize_t len_a, Py_ssize_t len_b) +{ + /* loop count depends on length of b. Might leak very little timing + * information if sizes are different. + */ + Py_ssize_t length = len_b; + const void *left = a; + const void *right = b; + int result = 0; + + if (len_a != length) { + left = b; + result = 1; + } + + result |= CRYPTO_memcmp(left, right, length); + + return (result == 0); +} + +/* NOTE: Keep in sync with _operator.c implementation. */ + +/*[clinic input] +_hashlib.compare_digest + + a: object + b: object + / + +Return 'a == b'. + +This function uses an approach designed to prevent +timing analysis, making it appropriate for cryptography. + +a and b must both be of the same type: either str (ASCII only), +or any bytes-like object. + +Note: If a and b are of different lengths, or if an error occurs, +a timing attack could theoretically reveal information about the +types and lengths of a and b--but not their values. +[clinic start generated code]*/ + +static PyObject * +_hashlib_compare_digest_impl(PyObject *module, PyObject *a, PyObject *b) +/*[clinic end generated code: output=6f1c13927480aed9 input=9c40c6e566ca12f5]*/ +{ + int rc; + + /* ASCII unicode string */ + if(PyUnicode_Check(a) && PyUnicode_Check(b)) { + if (PyUnicode_READY(a) == -1 || PyUnicode_READY(b) == -1) { + return NULL; + } + if (!PyUnicode_IS_ASCII(a) || !PyUnicode_IS_ASCII(b)) { + PyErr_SetString(PyExc_TypeError, + "comparing strings with non-ASCII characters is " + "not supported"); + return NULL; + } + + rc = _tscmp(PyUnicode_DATA(a), + PyUnicode_DATA(b), + PyUnicode_GET_LENGTH(a), + PyUnicode_GET_LENGTH(b)); + } + /* fallback to buffer interface for bytes, bytesarray and other */ + else { + Py_buffer view_a; + Py_buffer view_b; + + if (PyObject_CheckBuffer(a) == 0 && PyObject_CheckBuffer(b) == 0) { + PyErr_Format(PyExc_TypeError, + "unsupported operand types(s) or combination of types: " + "'%.100s' and '%.100s'", + Py_TYPE(a)->tp_name, Py_TYPE(b)->tp_name); + return NULL; + } + + if (PyObject_GetBuffer(a, &view_a, PyBUF_SIMPLE) == -1) { + return NULL; + } + if (view_a.ndim > 1) { + PyErr_SetString(PyExc_BufferError, + "Buffer must be single dimension"); + PyBuffer_Release(&view_a); + return NULL; + } + + if (PyObject_GetBuffer(b, &view_b, PyBUF_SIMPLE) == -1) { + PyBuffer_Release(&view_a); + return NULL; + } + if (view_b.ndim > 1) { + PyErr_SetString(PyExc_BufferError, + "Buffer must be single dimension"); + PyBuffer_Release(&view_a); + PyBuffer_Release(&view_b); + return NULL; + } + + rc = _tscmp((const unsigned char*)view_a.buf, + (const unsigned char*)view_b.buf, + view_a.len, + view_b.len); + + PyBuffer_Release(&view_a); + PyBuffer_Release(&view_b); + } + + return PyBool_FromLong(rc); +} + /* List of functions exported by this module */ static struct PyMethodDef EVP_functions[] = { @@ -1840,6 +1955,7 @@ static struct PyMethodDef EVP_functions[] = { PBKDF2_HMAC_METHODDEF _HASHLIB_SCRYPT_METHODDEF _HASHLIB_GET_FIPS_MODE_METHODDEF + _HASHLIB_COMPARE_DIGEST_METHODDEF _HASHLIB_HMAC_SINGLESHOT_METHODDEF _HASHLIB_HMAC_NEW_METHODDEF _HASHLIB_OPENSSL_MD5_METHODDEF diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c index 193478d79b4..20468c28f24 100644 --- a/Modules/_heapqmodule.c +++ b/Modules/_heapqmodule.c @@ -7,9 +7,11 @@ annotated by François Pinard, and converted to C by Raymond Hettinger. */ #include "Python.h" +#include "pycore_list.h" // _PyList_ITEMS() #include "clinic/_heapqmodule.c.h" + /*[clinic input] module _heapq [clinic start generated code]*/ diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index d7cadacea1b..e430352a48e 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -532,7 +532,7 @@ PyNumber_AsOff_t(PyObject *item, PyObject *err) { Py_off_t result; PyObject *runerr; - PyObject *value = PyNumber_Index(item); + PyObject *value = _PyNumber_Index(item); if (value == NULL) return -1; @@ -623,9 +623,7 @@ iomodule_traverse(PyObject *mod, visitproc visit, void *arg) { _PyIO_State *state = get_io_state(mod); if (!state->initialized) return 0; - if (state->locale_module != NULL) { - Py_VISIT(state->locale_module); - } + Py_VISIT(state->locale_module); Py_VISIT(state->unsupported_operation); return 0; } diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index f8e21f206f3..5984d34cc08 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -1483,6 +1483,15 @@ _bufferedreader_raw_read(buffered *self, char *start, Py_ssize_t len) } n = PyNumber_AsSsize_t(res, PyExc_ValueError); Py_DECREF(res); + + if (n == -1 && PyErr_Occurred()) { + _PyErr_FormatFromCause( + PyExc_OSError, + "raw readinto() failed" + ); + return -1; + } + if (n < 0 || n > len) { PyErr_Format(PyExc_OSError, "raw readinto() returned invalid length %zd " diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index 1961ed94c55..19543fdf79d 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -122,7 +122,7 @@ _io__Buffered_peek(buffered *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -197,7 +197,7 @@ _io__Buffered_read1(buffered *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -421,7 +421,7 @@ _io_BufferedReader___init__(PyObject *self, PyObject *args, PyObject *kwargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(fastargs[1]); + PyObject *iobj = _PyNumber_Index(fastargs[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -475,7 +475,7 @@ _io_BufferedWriter___init__(PyObject *self, PyObject *args, PyObject *kwargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(fastargs[1]); + PyObject *iobj = _PyNumber_Index(fastargs[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -567,7 +567,7 @@ _io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(PyTuple_GET_ITEM(args, 2)); + PyObject *iobj = _PyNumber_Index(PyTuple_GET_ITEM(args, 2)); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -621,7 +621,7 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(fastargs[1]); + PyObject *iobj = _PyNumber_Index(fastargs[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -637,4 +637,4 @@ skip_optional_pos: exit: return return_value; } -/*[clinic end generated code: output=1882bb497ddc9375 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=98ccf7610c0e82ba input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h index 4720bdd6555..5ea80ae01c1 100644 --- a/Modules/_io/clinic/bytesio.c.h +++ b/Modules/_io/clinic/bytesio.c.h @@ -404,7 +404,7 @@ _io_BytesIO_seek(bytesio *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -505,4 +505,4 @@ skip_optional_pos: exit: return return_value; } -/*[clinic end generated code: output=ba0f302f16397741 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=49a32140eb8c5555 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/iobase.c.h b/Modules/_io/clinic/iobase.c.h index 02a2ab86c4e..4fd6e18c4ef 100644 --- a/Modules/_io/clinic/iobase.c.h +++ b/Modules/_io/clinic/iobase.c.h @@ -276,7 +276,7 @@ _io__RawIOBase_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -310,4 +310,4 @@ _io__RawIOBase_readall(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _io__RawIOBase_readall_impl(self); } -/*[clinic end generated code: output=1f9ce590549593be input=a9049054013a1b77]*/ +/*[clinic end generated code: output=83c1361a7a51ca84 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h index 2b32319f985..147ef668a0b 100644 --- a/Modules/_io/clinic/stringio.c.h +++ b/Modules/_io/clinic/stringio.c.h @@ -179,7 +179,7 @@ _io_StringIO_seek(stringio *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -338,4 +338,4 @@ _io_StringIO_seekable(stringio *self, PyObject *Py_UNUSED(ignored)) { return _io_StringIO_seekable_impl(self); } -/*[clinic end generated code: output=9c428b2942d54991 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=eea93dcab10d0a97 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index f0ad69ce332..0b047ac0aab 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -452,7 +452,7 @@ _io_TextIOWrapper_readline(textio *self, PyObject *const *args, Py_ssize_t nargs } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -671,4 +671,4 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored)) { return _io_TextIOWrapper_close_impl(self); } -/*[clinic end generated code: output=ea96ee1eb3a71f77 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2604c8f3a45b9a03 input=a9049054013a1b77]*/ diff --git a/Modules/_json.c b/Modules/_json.c index 075aa3d2f4f..faa3944eedd 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -647,6 +647,7 @@ scanner_dealloc(PyObject *self) static int scanner_traverse(PyScannerObject *self, visitproc visit, void *arg) { + Py_VISIT(Py_TYPE(self)); Py_VISIT(self->object_hook); Py_VISIT(self->object_pairs_hook); Py_VISIT(self->parse_float); @@ -1745,6 +1746,7 @@ encoder_dealloc(PyObject *self) static int encoder_traverse(PyEncoderObject *self, visitproc visit, void *arg) { + Py_VISIT(Py_TYPE(self)); Py_VISIT(self->markers); Py_VISIT(self->defaultfn); Py_VISIT(self->encoder); diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c index 2a62a683568..24e1d6c2884 100644 --- a/Modules/_lzmamodule.c +++ b/Modules/_lzmamodule.c @@ -23,6 +23,20 @@ } } while (0) #define RELEASE_LOCK(obj) PyThread_release_lock((obj)->lock) +typedef struct { + PyTypeObject *lzma_compressor_type; + PyTypeObject *lzma_decompressor_type; + PyObject *error; + PyObject *empty_tuple; +} _lzma_state; + +static inline _lzma_state* +get_lzma_state(PyObject *module) +{ + void *state = PyModule_GetState(module); + assert(state != NULL); + return (_lzma_state *)state; +} /* Container formats: */ enum { @@ -56,17 +70,10 @@ typedef struct { PyThread_type_lock lock; } Decompressor; -/* LZMAError class object. */ -static PyObject *Error; - -/* An empty tuple, used by the filter specifier parsing code. */ -static PyObject *empty_tuple; - - /* Helper functions. */ static int -catch_lzma_error(lzma_ret lzret) +catch_lzma_error(_lzma_state *state, lzma_ret lzret) { switch (lzret) { case LZMA_OK: @@ -75,31 +82,31 @@ catch_lzma_error(lzma_ret lzret) case LZMA_STREAM_END: return 0; case LZMA_UNSUPPORTED_CHECK: - PyErr_SetString(Error, "Unsupported integrity check"); + PyErr_SetString(state->error, "Unsupported integrity check"); return 1; case LZMA_MEM_ERROR: PyErr_NoMemory(); return 1; case LZMA_MEMLIMIT_ERROR: - PyErr_SetString(Error, "Memory usage limit exceeded"); + PyErr_SetString(state->error, "Memory usage limit exceeded"); return 1; case LZMA_FORMAT_ERROR: - PyErr_SetString(Error, "Input format not supported by decoder"); + PyErr_SetString(state->error, "Input format not supported by decoder"); return 1; case LZMA_OPTIONS_ERROR: - PyErr_SetString(Error, "Invalid or unsupported options"); + PyErr_SetString(state->error, "Invalid or unsupported options"); return 1; case LZMA_DATA_ERROR: - PyErr_SetString(Error, "Corrupt input data"); + PyErr_SetString(state->error, "Corrupt input data"); return 1; case LZMA_BUF_ERROR: - PyErr_SetString(Error, "Insufficient buffer space"); + PyErr_SetString(state->error, "Insufficient buffer space"); return 1; case LZMA_PROG_ERROR: - PyErr_SetString(Error, "Internal error"); + PyErr_SetString(state->error, "Internal error"); return 1; default: - PyErr_Format(Error, "Unrecognized error from liblzma: %d", lzret); + PyErr_Format(state->error, "Unrecognized error from liblzma: %d", lzret); return 1; } } @@ -107,8 +114,9 @@ catch_lzma_error(lzma_ret lzret) static void* PyLzma_Malloc(void *opaque, size_t items, size_t size) { - if (size != 0 && items > (size_t)PY_SSIZE_T_MAX / size) + if (size != 0 && items > (size_t)PY_SSIZE_T_MAX / size) { return NULL; + } /* PyMem_Malloc() cannot be used: the GIL is not held when lzma_code() is called */ return PyMem_RawMalloc(items * size); @@ -132,8 +140,9 @@ grow_buffer(PyObject **buf, Py_ssize_t max_length) Py_ssize_t size = PyBytes_GET_SIZE(*buf); Py_ssize_t newsize = size + (size >> 3) + 6; - if (max_length > 0 && newsize > max_length) + if (max_length > 0 && newsize > max_length) { newsize = max_length; + } return _PyBytes_Resize(buf, newsize); } @@ -186,7 +195,7 @@ INT_TYPE_CONVERTER_FUNC(lzma_match_finder, lzma_mf_converter) the C lzma_filter structs expected by liblzma. */ static void * -parse_filter_spec_lzma(PyObject *spec) +parse_filter_spec_lzma(_lzma_state *state, PyObject *spec) { static char *optnames[] = {"id", "preset", "dict_size", "lc", "lp", "pb", "mode", "nice_len", "mf", "depth", NULL}; @@ -200,28 +209,32 @@ parse_filter_spec_lzma(PyObject *spec) preset_obj = PyMapping_GetItemString(spec, "preset"); if (preset_obj == NULL) { - if (PyErr_ExceptionMatches(PyExc_KeyError)) + if (PyErr_ExceptionMatches(PyExc_KeyError)) { PyErr_Clear(); - else + } + else { return NULL; + } } else { int ok = uint32_converter(preset_obj, &preset); Py_DECREF(preset_obj); - if (!ok) + if (!ok) { return NULL; + } } options = (lzma_options_lzma *)PyMem_Calloc(1, sizeof *options); - if (options == NULL) + if (options == NULL) { return PyErr_NoMemory(); + } if (lzma_lzma_preset(options, preset)) { PyMem_Free(options); - PyErr_Format(Error, "Invalid compression preset: %u", preset); + PyErr_Format(state->error, "Invalid compression preset: %u", preset); return NULL; } - if (!PyArg_ParseTupleAndKeywords(empty_tuple, spec, + if (!PyArg_ParseTupleAndKeywords(state->empty_tuple, spec, "|OOO&O&O&O&O&O&O&O&", optnames, &id, &preset_obj, uint32_converter, &options->dict_size, @@ -235,20 +248,21 @@ parse_filter_spec_lzma(PyObject *spec) PyErr_SetString(PyExc_ValueError, "Invalid filter specifier for LZMA filter"); PyMem_Free(options); - options = NULL; + return NULL; } + return options; } static void * -parse_filter_spec_delta(PyObject *spec) +parse_filter_spec_delta(_lzma_state *state, PyObject *spec) { static char *optnames[] = {"id", "dist", NULL}; PyObject *id; uint32_t dist = 1; lzma_options_delta *options; - if (!PyArg_ParseTupleAndKeywords(empty_tuple, spec, "|OO&", optnames, + if (!PyArg_ParseTupleAndKeywords(state->empty_tuple, spec, "|OO&", optnames, &id, uint32_converter, &dist)) { PyErr_SetString(PyExc_ValueError, "Invalid filter specifier for delta filter"); @@ -256,22 +270,23 @@ parse_filter_spec_delta(PyObject *spec) } options = (lzma_options_delta *)PyMem_Calloc(1, sizeof *options); - if (options == NULL) + if (options == NULL) { return PyErr_NoMemory(); + } options->type = LZMA_DELTA_TYPE_BYTE; options->dist = dist; return options; } static void * -parse_filter_spec_bcj(PyObject *spec) +parse_filter_spec_bcj(_lzma_state *state, PyObject *spec) { static char *optnames[] = {"id", "start_offset", NULL}; PyObject *id; uint32_t start_offset = 0; lzma_options_bcj *options; - if (!PyArg_ParseTupleAndKeywords(empty_tuple, spec, "|OO&", optnames, + if (!PyArg_ParseTupleAndKeywords(state->empty_tuple, spec, "|OO&", optnames, &id, uint32_converter, &start_offset)) { PyErr_SetString(PyExc_ValueError, "Invalid filter specifier for BCJ filter"); @@ -279,14 +294,15 @@ parse_filter_spec_bcj(PyObject *spec) } options = (lzma_options_bcj *)PyMem_Calloc(1, sizeof *options); - if (options == NULL) + if (options == NULL) { return PyErr_NoMemory(); + } options->start_offset = start_offset; return options; } static int -lzma_filter_converter(PyObject *spec, void *ptr) +lzma_filter_converter(_lzma_state *state, PyObject *spec, void *ptr) { lzma_filter *f = (lzma_filter *)ptr; PyObject *id_obj; @@ -305,16 +321,17 @@ lzma_filter_converter(PyObject *spec, void *ptr) } f->id = PyLong_AsUnsignedLongLong(id_obj); Py_DECREF(id_obj); - if (PyErr_Occurred()) + if (PyErr_Occurred()) { return 0; + } switch (f->id) { case LZMA_FILTER_LZMA1: case LZMA_FILTER_LZMA2: - f->options = parse_filter_spec_lzma(spec); + f->options = parse_filter_spec_lzma(state, spec); return f->options != NULL; case LZMA_FILTER_DELTA: - f->options = parse_filter_spec_delta(spec); + f->options = parse_filter_spec_delta(state, spec); return f->options != NULL; case LZMA_FILTER_X86: case LZMA_FILTER_POWERPC: @@ -322,7 +339,7 @@ lzma_filter_converter(PyObject *spec, void *ptr) case LZMA_FILTER_ARM: case LZMA_FILTER_ARMTHUMB: case LZMA_FILTER_SPARC: - f->options = parse_filter_spec_bcj(spec); + f->options = parse_filter_spec_bcj(state, spec); return f->options != NULL; default: PyErr_Format(PyExc_ValueError, "Invalid filter ID: %llu", f->id); @@ -333,20 +350,20 @@ lzma_filter_converter(PyObject *spec, void *ptr) static void free_filter_chain(lzma_filter filters[]) { - int i; - - for (i = 0; filters[i].id != LZMA_VLI_UNKNOWN; i++) + for (int i = 0; filters[i].id != LZMA_VLI_UNKNOWN; i++) { PyMem_Free(filters[i].options); + } } static int -parse_filter_chain_spec(lzma_filter filters[], PyObject *filterspecs) +parse_filter_chain_spec(_lzma_state *state, lzma_filter filters[], PyObject *filterspecs) { Py_ssize_t i, num_filters; num_filters = PySequence_Length(filterspecs); - if (num_filters == -1) + if (num_filters == -1) { return -1; + } if (num_filters > LZMA_FILTERS_MAX) { PyErr_Format(PyExc_ValueError, "Too many filters - liblzma supports a maximum of %d", @@ -357,8 +374,9 @@ parse_filter_chain_spec(lzma_filter filters[], PyObject *filterspecs) for (i = 0; i < num_filters; i++) { int ok = 1; PyObject *spec = PySequence_GetItem(filterspecs, i); - if (spec == NULL || !lzma_filter_converter(spec, &filters[i])) + if (spec == NULL || !lzma_filter_converter(state, spec, &filters[i])) { ok = 0; + } Py_XDECREF(spec); if (!ok) { filters[i].id = LZMA_VLI_UNKNOWN; @@ -383,8 +401,9 @@ spec_add_field(PyObject *spec, _Py_Identifier *key, unsigned long long value) PyObject *value_object; value_object = PyLong_FromUnsignedLongLong(value); - if (value_object == NULL) + if (value_object == NULL) { return -1; + } status = _PyDict_SetItemId(spec, key, value_object); Py_DECREF(value_object); @@ -397,8 +416,9 @@ build_filter_spec(const lzma_filter *f) PyObject *spec; spec = PyDict_New(); - if (spec == NULL) + if (spec == NULL) { return NULL; + } #define ADD_FIELD(SOURCE, FIELD) \ do { \ @@ -492,10 +512,13 @@ compress(Compressor *c, uint8_t *data, size_t len, lzma_action action) { Py_ssize_t data_size = 0; PyObject *result; + _lzma_state *state = PyType_GetModuleState(Py_TYPE(c)); + assert(state != NULL); result = PyBytes_FromStringAndSize(NULL, INITIAL_BUFFER_SIZE); - if (result == NULL) + if (result == NULL) { return NULL; + } c->lzs.next_in = data; c->lzs.avail_in = len; c->lzs.next_out = (uint8_t *)PyBytes_AS_STRING(result); @@ -506,11 +529,13 @@ compress(Compressor *c, uint8_t *data, size_t len, lzma_action action) Py_BEGIN_ALLOW_THREADS lzret = lzma_code(&c->lzs, action); data_size = (char *)c->lzs.next_out - PyBytes_AS_STRING(result); - if (lzret == LZMA_BUF_ERROR && len == 0 && c->lzs.avail_out > 0) + if (lzret == LZMA_BUF_ERROR && len == 0 && c->lzs.avail_out > 0) { lzret = LZMA_OK; /* That wasn't a real error */ + } Py_END_ALLOW_THREADS - if (catch_lzma_error(lzret)) + if (catch_lzma_error(state, lzret)) { goto error; + } if ((action == LZMA_RUN && c->lzs.avail_in == 0) || (action == LZMA_FINISH && lzret == LZMA_STREAM_END)) { break; @@ -522,8 +547,9 @@ compress(Compressor *c, uint8_t *data, size_t len, lzma_action action) } } if (data_size != PyBytes_GET_SIZE(result)) - if (_PyBytes_Resize(&result, data_size) == -1) + if (_PyBytes_Resize(&result, data_size) == -1) { goto error; + } return result; error: @@ -552,10 +578,12 @@ _lzma_LZMACompressor_compress_impl(Compressor *self, Py_buffer *data) PyObject *result = NULL; ACQUIRE_LOCK(self); - if (self->flushed) + if (self->flushed) { PyErr_SetString(PyExc_ValueError, "Compressor has been flushed"); - else + } + else { result = compress(self, data->buf, data->len, LZMA_RUN); + } RELEASE_LOCK(self); return result; } @@ -588,8 +616,8 @@ _lzma_LZMACompressor_flush_impl(Compressor *self) } static int -Compressor_init_xz(lzma_stream *lzs, int check, uint32_t preset, - PyObject *filterspecs) +Compressor_init_xz(_lzma_state *state, lzma_stream *lzs, + int check, uint32_t preset, PyObject *filterspecs) { lzma_ret lzret; @@ -598,19 +626,21 @@ Compressor_init_xz(lzma_stream *lzs, int check, uint32_t preset, } else { lzma_filter filters[LZMA_FILTERS_MAX + 1]; - if (parse_filter_chain_spec(filters, filterspecs) == -1) + if (parse_filter_chain_spec(state, filters, filterspecs) == -1) return -1; lzret = lzma_stream_encoder(lzs, filters, check); free_filter_chain(filters); } - if (catch_lzma_error(lzret)) + if (catch_lzma_error(state, lzret)) { return -1; - else + } + else { return 0; + } } static int -Compressor_init_alone(lzma_stream *lzs, uint32_t preset, PyObject *filterspecs) +Compressor_init_alone(_lzma_state *state, lzma_stream *lzs, uint32_t preset, PyObject *filterspecs) { lzma_ret lzret; @@ -618,14 +648,14 @@ Compressor_init_alone(lzma_stream *lzs, uint32_t preset, PyObject *filterspecs) lzma_options_lzma options; if (lzma_lzma_preset(&options, preset)) { - PyErr_Format(Error, "Invalid compression preset: %u", preset); + PyErr_Format(state->error, "Invalid compression preset: %u", preset); return -1; } lzret = lzma_alone_encoder(lzs, &options); } else { lzma_filter filters[LZMA_FILTERS_MAX + 1]; - if (parse_filter_chain_spec(filters, filterspecs) == -1) + if (parse_filter_chain_spec(state, filters, filterspecs) == -1) return -1; if (filters[0].id == LZMA_FILTER_LZMA1 && filters[1].id == LZMA_VLI_UNKNOWN) { @@ -638,14 +668,16 @@ Compressor_init_alone(lzma_stream *lzs, uint32_t preset, PyObject *filterspecs) } free_filter_chain(filters); } - if (PyErr_Occurred() || catch_lzma_error(lzret)) + if (PyErr_Occurred() || catch_lzma_error(state, lzret)) { return -1; - else + } + else { return 0; + } } static int -Compressor_init_raw(lzma_stream *lzs, PyObject *filterspecs) +Compressor_init_raw(_lzma_state *state, lzma_stream *lzs, PyObject *filterspecs) { lzma_filter filters[LZMA_FILTERS_MAX + 1]; lzma_ret lzret; @@ -655,14 +687,17 @@ Compressor_init_raw(lzma_stream *lzs, PyObject *filterspecs) "Must specify filters for FORMAT_RAW"); return -1; } - if (parse_filter_chain_spec(filters, filterspecs) == -1) + if (parse_filter_chain_spec(state, filters, filterspecs) == -1) { return -1; + } lzret = lzma_raw_encoder(lzs, filters); free_filter_chain(filters); - if (catch_lzma_error(lzret)) + if (catch_lzma_error(state, lzret)) { return -1; - else + } + else { return 0; + } } /*[-clinic input] @@ -706,12 +741,14 @@ Compressor_init(Compressor *self, PyObject *args, PyObject *kwargs) uint32_t preset = LZMA_PRESET_DEFAULT; PyObject *preset_obj = Py_None; PyObject *filterspecs = Py_None; - + _lzma_state *state = PyType_GetModuleState(Py_TYPE(self)); + assert(state != NULL); if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iiOO:LZMACompressor", arg_names, &format, &check, &preset_obj, - &filterspecs)) + &filterspecs)) { return -1; + } if (format != FORMAT_XZ && check != -1 && check != LZMA_CHECK_NONE) { PyErr_SetString(PyExc_ValueError, @@ -725,9 +762,11 @@ Compressor_init(Compressor *self, PyObject *args, PyObject *kwargs) return -1; } - if (preset_obj != Py_None) - if (!uint32_converter(preset_obj, &preset)) + if (preset_obj != Py_None) { + if (!uint32_converter(preset_obj, &preset)) { return -1; + } + } self->alloc.opaque = NULL; self->alloc.alloc = PyLzma_Malloc; @@ -743,20 +782,24 @@ Compressor_init(Compressor *self, PyObject *args, PyObject *kwargs) self->flushed = 0; switch (format) { case FORMAT_XZ: - if (check == -1) + if (check == -1) { check = LZMA_CHECK_CRC64; - if (Compressor_init_xz(&self->lzs, check, preset, filterspecs) != 0) + } + if (Compressor_init_xz(state, &self->lzs, check, preset, filterspecs) != 0) { break; + } return 0; case FORMAT_ALONE: - if (Compressor_init_alone(&self->lzs, preset, filterspecs) != 0) + if (Compressor_init_alone(state, &self->lzs, preset, filterspecs) != 0) { break; + } return 0; case FORMAT_RAW: - if (Compressor_init_raw(&self->lzs, filterspecs) != 0) + if (Compressor_init_raw(state, &self->lzs, filterspecs) != 0) { break; + } return 0; default: @@ -774,17 +817,42 @@ static void Compressor_dealloc(Compressor *self) { lzma_end(&self->lzs); - if (self->lock != NULL) + if (self->lock != NULL) { PyThread_free_lock(self->lock); - Py_TYPE(self)->tp_free((PyObject *)self); + } + PyTypeObject *tp = Py_TYPE(self); + tp->tp_free((PyObject *)self); + Py_DECREF(tp); +} + +/*[clinic input] +_lzma.LZMACompressor.__reduce__ +[clinic start generated code]*/ + +static PyObject * +_lzma_LZMACompressor___reduce___impl(Compressor *self) +/*[clinic end generated code: output=b49a0538d1cad752 input=6be52aba16b513c1]*/ +{ + PyErr_Format(PyExc_TypeError, + "cannot pickle %s object", + Py_TYPE(self)->tp_name); + return NULL; } static PyMethodDef Compressor_methods[] = { _LZMA_LZMACOMPRESSOR_COMPRESS_METHODDEF _LZMA_LZMACOMPRESSOR_FLUSH_METHODDEF + _LZMA_LZMACOMPRESSOR___REDUCE___METHODDEF {NULL} }; +static int +Compressor_traverse(Compressor *self, visitproc visit, void *arg) +{ + Py_VISIT(Py_TYPE(self)); + return 0; +} + PyDoc_STRVAR(Compressor_doc, "LZMACompressor(format=FORMAT_XZ, check=-1, preset=None, filters=None)\n" "\n" @@ -813,47 +881,26 @@ PyDoc_STRVAR(Compressor_doc, "\n" "For one-shot compression, use the compress() function instead.\n"); -static PyTypeObject Compressor_type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_lzma.LZMACompressor", /* tp_name */ - sizeof(Compressor), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)Compressor_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_as_async */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - Compressor_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - Compressor_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Compressor_init, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ +static PyType_Slot lzma_compressor_type_slots[] = { + {Py_tp_dealloc, Compressor_dealloc}, + {Py_tp_methods, Compressor_methods}, + {Py_tp_init, Compressor_init}, + {Py_tp_new, PyType_GenericNew}, + {Py_tp_doc, (char *)Compressor_doc}, + {Py_tp_traverse, Compressor_traverse}, + {0, 0} }; +static PyType_Spec lzma_compressor_type_spec = { + .name = "_lzma.LZMACompressor", + .basicsize = sizeof(Compressor), + // Calling PyType_GetModuleState() on a subclass is not safe. + // lzma_compressor_type_spec does not have Py_TPFLAGS_BASETYPE flag + // which prevents to create a subclass. + // So calling PyType_GetModuleState() in this file is always safe. + .flags = Py_TPFLAGS_DEFAULT, + .slots = lzma_compressor_type_slots, +}; /* LZMADecompressor class. */ @@ -867,13 +914,18 @@ decompress_buf(Decompressor *d, Py_ssize_t max_length) Py_ssize_t data_size = 0; PyObject *result; lzma_stream *lzs = &d->lzs; + _lzma_state *state = PyType_GetModuleState(Py_TYPE(d)); + assert(state != NULL); - if (max_length < 0 || max_length >= INITIAL_BUFFER_SIZE) + if (max_length < 0 || max_length >= INITIAL_BUFFER_SIZE) { result = PyBytes_FromStringAndSize(NULL, INITIAL_BUFFER_SIZE); - else + } + else { result = PyBytes_FromStringAndSize(NULL, max_length); - if (result == NULL) + } + if (result == NULL) { return NULL; + } lzs->next_out = (uint8_t *)PyBytes_AS_STRING(result); lzs->avail_out = PyBytes_GET_SIZE(result); @@ -884,14 +936,17 @@ decompress_buf(Decompressor *d, Py_ssize_t max_length) Py_BEGIN_ALLOW_THREADS lzret = lzma_code(lzs, LZMA_RUN); data_size = (char *)lzs->next_out - PyBytes_AS_STRING(result); - if (lzret == LZMA_BUF_ERROR && lzs->avail_in == 0 && lzs->avail_out > 0) + if (lzret == LZMA_BUF_ERROR && lzs->avail_in == 0 && lzs->avail_out > 0) { lzret = LZMA_OK; /* That wasn't a real error */ + } Py_END_ALLOW_THREADS - if (catch_lzma_error(lzret)) + if (catch_lzma_error(state, lzret)) { goto error; - if (lzret == LZMA_GET_CHECK || lzret == LZMA_NO_CHECK) + } + if (lzret == LZMA_GET_CHECK || lzret == LZMA_NO_CHECK) { d->check = lzma_get_check(&d->lzs); + } if (lzret == LZMA_STREAM_END) { d->eof = 1; break; @@ -900,19 +955,23 @@ decompress_buf(Decompressor *d, Py_ssize_t max_length) Maybe lzs's internal state still have a few bytes can be output, grow the output buffer and continue if max_lengh < 0. */ - if (data_size == max_length) + if (data_size == max_length) { break; - if (grow_buffer(&result, max_length) == -1) + } + if (grow_buffer(&result, max_length) == -1) { goto error; + } lzs->next_out = (uint8_t *)PyBytes_AS_STRING(result) + data_size; lzs->avail_out = PyBytes_GET_SIZE(result) - data_size; } else if (lzs->avail_in == 0) { break; } } - if (data_size != PyBytes_GET_SIZE(result)) - if (_PyBytes_Resize(&result, data_size) == -1) + if (data_size != PyBytes_GET_SIZE(result)) { + if (_PyBytes_Resize(&result, data_size) == -1) { goto error; + } + } return result; @@ -984,8 +1043,9 @@ decompress(Decompressor *d, uint8_t *data, size_t len, Py_ssize_t max_length) if (lzs->avail_in > 0) { Py_XSETREF(d->unused_data, PyBytes_FromStringAndSize((char *)lzs->next_in, lzs->avail_in)); - if (d->unused_data == NULL) + if (d->unused_data == NULL) { goto error; + } } } else if (lzs->avail_in == 0) { @@ -1082,19 +1142,22 @@ _lzma_LZMADecompressor_decompress_impl(Decompressor *self, Py_buffer *data, } static int -Decompressor_init_raw(lzma_stream *lzs, PyObject *filterspecs) +Decompressor_init_raw(_lzma_state *state, lzma_stream *lzs, PyObject *filterspecs) { lzma_filter filters[LZMA_FILTERS_MAX + 1]; lzma_ret lzret; - if (parse_filter_chain_spec(filters, filterspecs) == -1) + if (parse_filter_chain_spec(state, filters, filterspecs) == -1) { return -1; + } lzret = lzma_raw_decoder(lzs, filters); free_filter_chain(filters); - if (catch_lzma_error(lzret)) + if (catch_lzma_error(state, lzret)) { return -1; - else + } + else { return 0; + } } /*[clinic input] @@ -1130,6 +1193,8 @@ _lzma_LZMADecompressor___init___impl(Decompressor *self, int format, const uint32_t decoder_flags = LZMA_TELL_ANY_CHECK | LZMA_TELL_NO_CHECK; uint64_t memlimit_ = UINT64_MAX; lzma_ret lzret; + _lzma_state *state = PyType_GetModuleState(Py_TYPE(self)); + assert(state != NULL); if (memlimit != Py_None) { if (format == FORMAT_RAW) { @@ -1138,8 +1203,9 @@ _lzma_LZMADecompressor___init___impl(Decompressor *self, int format, return -1; } memlimit_ = PyLong_AsUnsignedLongLong(memlimit); - if (PyErr_Occurred()) + if (PyErr_Occurred()) { return -1; + } } if (format == FORMAT_RAW && filters == Py_None) { @@ -1173,33 +1239,38 @@ _lzma_LZMADecompressor___init___impl(Decompressor *self, int format, self->input_buffer = NULL; self->input_buffer_size = 0; Py_XSETREF(self->unused_data, PyBytes_FromStringAndSize(NULL, 0)); - if (self->unused_data == NULL) + if (self->unused_data == NULL) { goto error; + } switch (format) { case FORMAT_AUTO: lzret = lzma_auto_decoder(&self->lzs, memlimit_, decoder_flags); - if (catch_lzma_error(lzret)) + if (catch_lzma_error(state, lzret)) { break; + } return 0; case FORMAT_XZ: lzret = lzma_stream_decoder(&self->lzs, memlimit_, decoder_flags); - if (catch_lzma_error(lzret)) + if (catch_lzma_error(state, lzret)) { break; + } return 0; case FORMAT_ALONE: self->check = LZMA_CHECK_NONE; lzret = lzma_alone_decoder(&self->lzs, memlimit_); - if (catch_lzma_error(lzret)) + if (catch_lzma_error(state, lzret)) { break; + } return 0; case FORMAT_RAW: self->check = LZMA_CHECK_NONE; - if (Decompressor_init_raw(&self->lzs, filters) == -1) + if (Decompressor_init_raw(state, &self->lzs, filters) == -1) { break; + } return 0; default: @@ -1223,13 +1294,38 @@ Decompressor_dealloc(Decompressor *self) lzma_end(&self->lzs); Py_CLEAR(self->unused_data); - if (self->lock != NULL) + if (self->lock != NULL) { PyThread_free_lock(self->lock); - Py_TYPE(self)->tp_free((PyObject *)self); + } + PyTypeObject *tp = Py_TYPE(self); + tp->tp_free((PyObject *)self); + Py_DECREF(tp); +} + +static int +Decompressor_traverse(Decompressor *self, visitproc visit, void *arg) +{ + Py_VISIT(Py_TYPE(self)); + return 0; +} + +/*[clinic input] +_lzma.LZMADecompressor.__reduce__ +[clinic start generated code]*/ + +static PyObject * +_lzma_LZMADecompressor___reduce___impl(Decompressor *self) +/*[clinic end generated code: output=2611fff0104a9c30 input=b9882e030aecd9a5]*/ +{ + PyErr_Format(PyExc_TypeError, + "cannot pickle %s object", + Py_TYPE(self)->tp_name); + return NULL; } static PyMethodDef Decompressor_methods[] = { _LZMA_LZMADECOMPRESSOR_DECOMPRESS_METHODDEF + _LZMA_LZMADECOMPRESSOR___REDUCE___METHODDEF {NULL} }; @@ -1257,45 +1353,26 @@ static PyMemberDef Decompressor_members[] = { {NULL} }; -static PyTypeObject Decompressor_type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_lzma.LZMADecompressor", /* tp_name */ - sizeof(Decompressor), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)Decompressor_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_as_async */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - _lzma_LZMADecompressor___init____doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - Decompressor_methods, /* tp_methods */ - Decompressor_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - _lzma_LZMADecompressor___init__, /* tp_init */ - 0, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ +static PyType_Slot lzma_decompressor_type_slots[] = { + {Py_tp_dealloc, Decompressor_dealloc}, + {Py_tp_methods, Decompressor_methods}, + {Py_tp_init, _lzma_LZMADecompressor___init__}, + {Py_tp_new, PyType_GenericNew}, + {Py_tp_doc, (char *)_lzma_LZMADecompressor___init____doc__}, + {Py_tp_traverse, Decompressor_traverse}, + {Py_tp_members, Decompressor_members}, + {0, 0} +}; + +static PyType_Spec lzma_decompressor_type_spec = { + .name = "_lzma.LZMADecompressor", + .basicsize = sizeof(Decompressor), + // Calling PyType_GetModuleState() on a subclass is not safe. + // lzma_decompressor_type_spec does not have Py_TPFLAGS_BASETYPE flag + // which prevents to create a subclass. + // So calling PyType_GetModuleState() in this file is always safe. + .flags = Py_TPFLAGS_DEFAULT, + .slots = lzma_decompressor_type_slots, }; @@ -1318,27 +1395,52 @@ _lzma_is_check_supported_impl(PyObject *module, int check_id) return PyBool_FromLong(lzma_check_is_supported(check_id)); } +PyDoc_STRVAR(_lzma__encode_filter_properties__doc__, +"_encode_filter_properties($module, filter, /)\n" +"--\n" +"\n" +"Return a bytes object encoding the options (properties) of the filter specified by *filter* (a dict).\n" +"\n" +"The result does not include the filter ID itself, only the options."); -/*[clinic input] -_lzma._encode_filter_properties - filter: lzma_filter(c_default="{LZMA_VLI_UNKNOWN, NULL}") - / +#define _LZMA__ENCODE_FILTER_PROPERTIES_METHODDEF \ + {"_encode_filter_properties", (PyCFunction)_lzma__encode_filter_properties, METH_O, _lzma__encode_filter_properties__doc__}, -Return a bytes object encoding the options (properties) of the filter specified by *filter* (a dict). +static PyObject * +_lzma__encode_filter_properties_impl(PyObject *module, lzma_filter filter); -The result does not include the filter ID itself, only the options. -[clinic start generated code]*/ +static PyObject * +_lzma__encode_filter_properties(PyObject *module, PyObject *arg) +{ + PyObject *return_value = NULL; + lzma_filter filter = {LZMA_VLI_UNKNOWN, NULL}; + _lzma_state *state = get_lzma_state(module); + assert(state != NULL); + if (!lzma_filter_converter(state, arg, &filter)) { + goto exit; + } + return_value = _lzma__encode_filter_properties_impl(module, filter); + +exit: + /* Cleanup for filter */ + if (filter.id != LZMA_VLI_UNKNOWN) { + PyMem_Free(filter.options); + } + + return return_value; +} static PyObject * _lzma__encode_filter_properties_impl(PyObject *module, lzma_filter filter) -/*[clinic end generated code: output=5c93c8e14e7be5a8 input=d4c64f1b557c77d4]*/ { lzma_ret lzret; uint32_t encoded_size; PyObject *result = NULL; + _lzma_state *state = get_lzma_state(module); + assert(state != NULL); lzret = lzma_properties_size(&encoded_size, &filter); - if (catch_lzma_error(lzret)) + if (catch_lzma_error(state, lzret)) goto error; result = PyBytes_FromStringAndSize(NULL, encoded_size); @@ -1347,8 +1449,9 @@ _lzma__encode_filter_properties_impl(PyObject *module, lzma_filter filter) lzret = lzma_properties_encode( &filter, (uint8_t *)PyBytes_AS_STRING(result)); - if (catch_lzma_error(lzret)) + if (catch_lzma_error(state, lzret)) { goto error; + } return result; @@ -1378,11 +1481,14 @@ _lzma__decode_filter_properties_impl(PyObject *module, lzma_vli filter_id, lzma_ret lzret; PyObject *result = NULL; filter.id = filter_id; + _lzma_state *state = get_lzma_state(module); + assert(state != NULL); lzret = lzma_properties_decode( &filter, NULL, encoded_props->buf, encoded_props->len); - if (catch_lzma_error(lzret)) + if (catch_lzma_error(state, lzret)) { return NULL; + } result = build_filter_spec(&filter); @@ -1392,103 +1498,162 @@ _lzma__decode_filter_properties_impl(PyObject *module, lzma_vli filter_id, return result; } - -/* Module initialization. */ - -static PyMethodDef module_methods[] = { - _LZMA_IS_CHECK_SUPPORTED_METHODDEF - _LZMA__ENCODE_FILTER_PROPERTIES_METHODDEF - _LZMA__DECODE_FILTER_PROPERTIES_METHODDEF - {NULL} -}; - -static PyModuleDef _lzmamodule = { - PyModuleDef_HEAD_INIT, - "_lzma", - NULL, - -1, - module_methods, - NULL, - NULL, - NULL, - NULL, -}; - /* Some of our constants are more than 32 bits wide, so PyModule_AddIntConstant would not work correctly on platforms with 32-bit longs. */ static int module_add_int_constant(PyObject *m, const char *name, long long value) { PyObject *o = PyLong_FromLongLong(value); - if (o == NULL) + if (o == NULL) { return -1; - if (PyModule_AddObject(m, name, o) == 0) + } + if (PyModule_AddObject(m, name, o) == 0) { return 0; + } Py_DECREF(o); return -1; } -#define ADD_INT_PREFIX_MACRO(m, macro) \ - module_add_int_constant(m, #macro, LZMA_ ## macro) +static int +lzma_exec(PyObject *module) +{ +#define ADD_INT_PREFIX_MACRO(module, macro) \ + do { \ + if (module_add_int_constant(module, #macro, LZMA_ ## macro) < 0) { \ + return -1; \ + } \ + } while(0) + +#define ADD_INT_MACRO(module, macro) \ + do { \ + if (PyModule_AddIntMacro(module, macro) < 0) { \ + return -1; \ + } \ + } while (0) + + + _lzma_state *state = get_lzma_state(module); + + state->empty_tuple = PyTuple_New(0); + if (state->empty_tuple == NULL) { + return -1; + } + + ADD_INT_MACRO(module, FORMAT_AUTO); + ADD_INT_MACRO(module, FORMAT_XZ); + ADD_INT_MACRO(module, FORMAT_ALONE); + ADD_INT_MACRO(module, FORMAT_RAW); + ADD_INT_PREFIX_MACRO(module, CHECK_NONE); + ADD_INT_PREFIX_MACRO(module, CHECK_CRC32); + ADD_INT_PREFIX_MACRO(module, CHECK_CRC64); + ADD_INT_PREFIX_MACRO(module, CHECK_SHA256); + ADD_INT_PREFIX_MACRO(module, CHECK_ID_MAX); + ADD_INT_PREFIX_MACRO(module, CHECK_UNKNOWN); + ADD_INT_PREFIX_MACRO(module, FILTER_LZMA1); + ADD_INT_PREFIX_MACRO(module, FILTER_LZMA2); + ADD_INT_PREFIX_MACRO(module, FILTER_DELTA); + ADD_INT_PREFIX_MACRO(module, FILTER_X86); + ADD_INT_PREFIX_MACRO(module, FILTER_IA64); + ADD_INT_PREFIX_MACRO(module, FILTER_ARM); + ADD_INT_PREFIX_MACRO(module, FILTER_ARMTHUMB); + ADD_INT_PREFIX_MACRO(module, FILTER_SPARC); + ADD_INT_PREFIX_MACRO(module, FILTER_POWERPC); + ADD_INT_PREFIX_MACRO(module, MF_HC3); + ADD_INT_PREFIX_MACRO(module, MF_HC4); + ADD_INT_PREFIX_MACRO(module, MF_BT2); + ADD_INT_PREFIX_MACRO(module, MF_BT3); + ADD_INT_PREFIX_MACRO(module, MF_BT4); + ADD_INT_PREFIX_MACRO(module, MODE_FAST); + ADD_INT_PREFIX_MACRO(module, MODE_NORMAL); + ADD_INT_PREFIX_MACRO(module, PRESET_DEFAULT); + ADD_INT_PREFIX_MACRO(module, PRESET_EXTREME); + + state->error = PyErr_NewExceptionWithDoc("_lzma.LZMAError", "Call to liblzma failed.", NULL, NULL); + if (state->error == NULL) { + return -1; + } + + if (PyModule_AddType(module, (PyTypeObject *)state->error) < 0) { + return -1; + } + + + state->lzma_compressor_type = (PyTypeObject *)PyType_FromModuleAndSpec(module, + &lzma_compressor_type_spec, NULL); + if (state->lzma_compressor_type == NULL) { + return -1; + } + + if (PyModule_AddType(module, state->lzma_compressor_type) < 0) { + return -1; + } + + state->lzma_decompressor_type = (PyTypeObject *)PyType_FromModuleAndSpec(module, + &lzma_decompressor_type_spec, NULL); + if (state->lzma_decompressor_type == NULL) { + return -1; + } + + if (PyModule_AddType(module, state->lzma_decompressor_type) < 0) { + return -1; + } + + return 0; +} + +static PyMethodDef lzma_methods[] = { + _LZMA_IS_CHECK_SUPPORTED_METHODDEF + _LZMA__ENCODE_FILTER_PROPERTIES_METHODDEF + _LZMA__DECODE_FILTER_PROPERTIES_METHODDEF + {NULL} +}; + +static PyModuleDef_Slot lzma_slots[] = { + {Py_mod_exec, lzma_exec}, + {0, NULL} +}; + +static int +lzma_traverse(PyObject *module, visitproc visit, void *arg) +{ + _lzma_state *state = get_lzma_state(module); + Py_VISIT(state->lzma_compressor_type); + Py_VISIT(state->lzma_decompressor_type); + Py_VISIT(state->error); + Py_VISIT(state->empty_tuple); + return 0; +} + +static int +lzma_clear(PyObject *module) +{ + _lzma_state *state = get_lzma_state(module); + Py_CLEAR(state->lzma_compressor_type); + Py_CLEAR(state->lzma_decompressor_type); + Py_CLEAR(state->error); + Py_CLEAR(state->empty_tuple); + return 0; +} + +static void +lzma_free(void *module) +{ + lzma_clear((PyObject *)module); +} + +static PyModuleDef _lzmamodule = { + PyModuleDef_HEAD_INIT, + .m_name = "_lzma", + .m_size = sizeof(_lzma_state), + .m_methods = lzma_methods, + .m_slots = lzma_slots, + .m_traverse = lzma_traverse, + .m_clear = lzma_clear, + .m_free = lzma_free, +}; PyMODINIT_FUNC PyInit__lzma(void) { - PyObject *m; - - empty_tuple = PyTuple_New(0); - if (empty_tuple == NULL) - return NULL; - - m = PyModule_Create(&_lzmamodule); - if (m == NULL) - return NULL; - - if (PyModule_AddIntMacro(m, FORMAT_AUTO) == -1 || - PyModule_AddIntMacro(m, FORMAT_XZ) == -1 || - PyModule_AddIntMacro(m, FORMAT_ALONE) == -1 || - PyModule_AddIntMacro(m, FORMAT_RAW) == -1 || - ADD_INT_PREFIX_MACRO(m, CHECK_NONE) == -1 || - ADD_INT_PREFIX_MACRO(m, CHECK_CRC32) == -1 || - ADD_INT_PREFIX_MACRO(m, CHECK_CRC64) == -1 || - ADD_INT_PREFIX_MACRO(m, CHECK_SHA256) == -1 || - ADD_INT_PREFIX_MACRO(m, CHECK_ID_MAX) == -1 || - ADD_INT_PREFIX_MACRO(m, CHECK_UNKNOWN) == -1 || - ADD_INT_PREFIX_MACRO(m, FILTER_LZMA1) == -1 || - ADD_INT_PREFIX_MACRO(m, FILTER_LZMA2) == -1 || - ADD_INT_PREFIX_MACRO(m, FILTER_DELTA) == -1 || - ADD_INT_PREFIX_MACRO(m, FILTER_X86) == -1 || - ADD_INT_PREFIX_MACRO(m, FILTER_IA64) == -1 || - ADD_INT_PREFIX_MACRO(m, FILTER_ARM) == -1 || - ADD_INT_PREFIX_MACRO(m, FILTER_ARMTHUMB) == -1 || - ADD_INT_PREFIX_MACRO(m, FILTER_SPARC) == -1 || - ADD_INT_PREFIX_MACRO(m, FILTER_POWERPC) == -1 || - ADD_INT_PREFIX_MACRO(m, MF_HC3) == -1 || - ADD_INT_PREFIX_MACRO(m, MF_HC4) == -1 || - ADD_INT_PREFIX_MACRO(m, MF_BT2) == -1 || - ADD_INT_PREFIX_MACRO(m, MF_BT3) == -1 || - ADD_INT_PREFIX_MACRO(m, MF_BT4) == -1 || - ADD_INT_PREFIX_MACRO(m, MODE_FAST) == -1 || - ADD_INT_PREFIX_MACRO(m, MODE_NORMAL) == -1 || - ADD_INT_PREFIX_MACRO(m, PRESET_DEFAULT) == -1 || - ADD_INT_PREFIX_MACRO(m, PRESET_EXTREME) == -1) - return NULL; - - Error = PyErr_NewExceptionWithDoc( - "_lzma.LZMAError", "Call to liblzma failed.", NULL, NULL); - if (Error == NULL) - return NULL; - Py_INCREF(Error); - if (PyModule_AddObject(m, "LZMAError", Error) == -1) - return NULL; - - if (PyModule_AddType(m, &Compressor_type) < 0) { - return NULL; - } - - if (PyModule_AddType(m, &Decompressor_type) < 0) { - return NULL; - } - - return m; + return PyModuleDef_Init(&_lzmamodule); } diff --git a/Modules/_operator.c b/Modules/_operator.c index 19026b6c38e..8a54829e5bb 100644 --- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -785,6 +785,8 @@ _operator_length_hint_impl(PyObject *module, PyObject *obj, return PyObject_LengthHint(obj, default_value); } +/* NOTE: Keep in sync with _hashopenssl.c implementation. */ + /*[clinic input] _operator._compare_digest = _operator.eq diff --git a/Modules/_peg_parser.c b/Modules/_peg_parser.c deleted file mode 100644 index b66d5a83a84..00000000000 --- a/Modules/_peg_parser.c +++ /dev/null @@ -1,145 +0,0 @@ -#include -#include "pegen_interface.h" - -static int -_mode_str_to_int(char *mode_str) -{ - int mode; - if (strcmp(mode_str, "exec") == 0) { - mode = Py_file_input; - } - else if (strcmp(mode_str, "eval") == 0) { - mode = Py_eval_input; - } - else if (strcmp(mode_str, "single") == 0) { - mode = Py_single_input; - } - else { - mode = -1; - } - return mode; -} - -static mod_ty -_run_parser(char *str, char *filename, int mode, PyCompilerFlags *flags, PyArena *arena, int oldparser) -{ - mod_ty mod; - if (!oldparser) { - mod = PyPegen_ASTFromString(str, filename, mode, flags, arena); - } - else { - mod = PyParser_ASTFromString(str, filename, mode, flags, arena); - } - return mod; -} - -PyObject * -_Py_compile_string(PyObject *self, PyObject *args, PyObject *kwds) -{ - static char *keywords[] = {"string", "filename", "mode", "oldparser", NULL}; - char *the_string; - char *filename = ""; - char *mode_str = "exec"; - int oldparser = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|ssp", keywords, - &the_string, &filename, &mode_str, &oldparser)) { - return NULL; - } - - int mode = _mode_str_to_int(mode_str); - if (mode == -1) { - return PyErr_Format(PyExc_ValueError, "mode must be either 'exec' or 'eval' or 'single'"); - } - - PyCompilerFlags flags = _PyCompilerFlags_INIT; - flags.cf_flags = PyCF_IGNORE_COOKIE; - - PyArena *arena = PyArena_New(); - if (arena == NULL) { - return NULL; - } - - mod_ty mod = _run_parser(the_string, filename, mode, &flags, arena, oldparser); - if (mod == NULL) { - PyArena_Free(arena); - return NULL; - } - - PyObject *filename_ob = PyUnicode_DecodeFSDefault(filename); - if (filename_ob == NULL) { - PyArena_Free(arena); - return NULL; - } - PyCodeObject *result = PyAST_CompileObject(mod, filename_ob, &flags, -1, arena); - Py_XDECREF(filename_ob); - PyArena_Free(arena); - return (PyObject *)result; -} - -PyObject * -_Py_parse_string(PyObject *self, PyObject *args, PyObject *kwds) -{ - static char *keywords[] = {"string", "filename", "mode", "oldparser", NULL}; - char *the_string; - char *filename = ""; - char *mode_str = "exec"; - int oldparser = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|ssp", keywords, - &the_string, &filename, &mode_str, &oldparser)) { - return NULL; - } - - int mode = _mode_str_to_int(mode_str); - if (mode == -1) { - return PyErr_Format(PyExc_ValueError, "mode must be either 'exec' or 'eval' or 'single'"); - } - - PyCompilerFlags flags = _PyCompilerFlags_INIT; - flags.cf_flags = PyCF_IGNORE_COOKIE; - - PyArena *arena = PyArena_New(); - if (arena == NULL) { - return NULL; - } - - mod_ty mod = _run_parser(the_string, filename, mode, &flags, arena, oldparser); - if (mod == NULL) { - PyArena_Free(arena); - return NULL; - } - - PyObject *result = PyAST_mod2obj(mod); - PyArena_Free(arena); - return result; -} - -static PyMethodDef ParseMethods[] = { - { - "parse_string", - (PyCFunction)(void (*)(void))_Py_parse_string, - METH_VARARGS|METH_KEYWORDS, - "Parse a string, return an AST." - }, - { - "compile_string", - (PyCFunction)(void (*)(void))_Py_compile_string, - METH_VARARGS|METH_KEYWORDS, - "Compile a string, return a code object." - }, - {NULL, NULL, 0, NULL} /* Sentinel */ -}; - -static struct PyModuleDef parsemodule = { - PyModuleDef_HEAD_INIT, - .m_name = "peg_parser", - .m_doc = "A parser.", - .m_methods = ParseMethods, -}; - -PyMODINIT_FUNC -PyInit__peg_parser(void) -{ - return PyModule_Create(&parsemodule); -} diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 5539e64025a..25e888db19c 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -1715,7 +1715,7 @@ memo_get(PicklerObject *self, PyObject *key) if (!self->bin) { pdata[0] = GET; PyOS_snprintf(pdata + 1, sizeof(pdata) - 1, - "%" PY_FORMAT_SIZE_T "d\n", *value); + "%zd\n", *value); len = strlen(pdata); } else { @@ -1772,7 +1772,7 @@ memo_put(PicklerObject *self, PyObject *obj) else if (!self->bin) { pdata[0] = PUT; PyOS_snprintf(pdata + 1, sizeof(pdata) - 1, - "%" PY_FORMAT_SIZE_T "d\n", idx); + "%zd\n", idx); len = strlen(pdata); } else { diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index add2962189b..5d1691ace41 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -893,6 +893,7 @@ subprocess_fork_exec(PyObject* self, PyObject *args) if (_enable_gc(need_to_reenable_gc, gc_module)) { pid = -1; } + PyMem_RawFree(groups); Py_XDECREF(preexec_fn_args_tuple); Py_XDECREF(gc_module); diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index 3589173edcb..b8bc0449c1b 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -67,7 +67,6 @@ /* ---------------------------------------------------------------*/ #include "Python.h" -#include "pycore_byteswap.h" // _Py_bswap32() #ifdef HAVE_PROCESS_H # include // getpid() #endif @@ -536,12 +535,30 @@ random_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return (PyObject *)self; } + +/*[clinic input] + +_random.Random.__reduce__ + +[clinic start generated code]*/ + +static PyObject * +_random_Random___reduce___impl(RandomObject *self) +/*[clinic end generated code: output=ddea0dcdb60ffd6d input=bd38ec35fd157e0f]*/ +{ + PyErr_Format(PyExc_TypeError, + "cannot pickle %s object", + Py_TYPE(self)->tp_name); + return NULL; +} + static PyMethodDef random_methods[] = { _RANDOM_RANDOM_RANDOM_METHODDEF _RANDOM_RANDOM_SEED_METHODDEF _RANDOM_RANDOM_GETSTATE_METHODDEF _RANDOM_RANDOM_SETSTATE_METHODDEF _RANDOM_RANDOM_GETRANDBITS_METHODDEF + _RANDOM_RANDOM___REDUCE___METHODDEF {NULL, NULL} /* sentinel */ }; diff --git a/Modules/_sre.c b/Modules/_sre.c index 244e4f1f84d..70bd8baa01e 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -211,7 +211,7 @@ data_stack_grow(SRE_STATE* state, Py_ssize_t size) if (cursize < minsize) { void* stack; cursize = minsize+minsize/4+1024; - TRACE(("allocate/grow stack %" PY_FORMAT_SIZE_T "d\n", cursize)); + TRACE(("allocate/grow stack %zd\n", cursize)); stack = PyMem_REALLOC(state->data_stack, cursize); if (!stack) { data_stack_dealloc(state); @@ -454,7 +454,10 @@ state_init(SRE_STATE* state, PatternObject* pattern, PyObject* string, return string; err: - PyMem_Del(state->mark); + /* We add an explicit cast here because MSVC has a bug when + compiling C code where it believes that `const void**` cannot be + safely casted to `void*`, see bpo-39943 for details. */ + PyMem_Del((void*) state->mark); state->mark = NULL; if (state->buffer.buf) PyBuffer_Release(&state->buffer); @@ -468,7 +471,8 @@ state_fini(SRE_STATE* state) PyBuffer_Release(&state->buffer); Py_XDECREF(state->string); data_stack_dealloc(state); - PyMem_Del(state->mark); + /* See above PyMem_Del for why we explicitly cast here. */ + PyMem_Del((void*) state->mark); state->mark = NULL; } diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 5fe65a8a1d6..5e82fe41a76 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -142,6 +142,24 @@ static void _PySSLFixErrno(void) { # define PY_OPENSSL_1_1_API 1 #endif +/* OpenSSL API compat */ +#ifdef OPENSSL_API_COMPAT +#if OPENSSL_API_COMPAT >= 0x10100000L + +/* OpenSSL API 1.1.0+ does not include version methods */ +#ifndef OPENSSL_NO_TLS1_METHOD +#define OPENSSL_NO_TLS1_METHOD 1 +#endif +#ifndef OPENSSL_NO_TLS1_1_METHOD +#define OPENSSL_NO_TLS1_1_METHOD 1 +#endif +#ifndef OPENSSL_NO_TLS1_2_METHOD +#define OPENSSL_NO_TLS1_2_METHOD 1 +#endif + +#endif /* >= 1.1.0 compcat */ +#endif /* OPENSSL_API_COMPAT */ + /* LibreSSL 2.7.0 provides necessary OpenSSL 1.1.0 APIs */ #if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x2070000fL # define PY_OPENSSL_1_1_API 1 @@ -201,6 +219,12 @@ static void _PySSLFixErrno(void) { #define TLS_method SSLv23_method #define TLS_client_method SSLv23_client_method #define TLS_server_method SSLv23_server_method +#define ASN1_STRING_get0_data ASN1_STRING_data +#define X509_get0_notBefore X509_get_notBefore +#define X509_get0_notAfter X509_get_notAfter +#define OpenSSL_version_num SSLeay +#define OpenSSL_version SSLeay_version +#define OPENSSL_VERSION SSLEAY_VERSION static int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne) { @@ -885,7 +909,7 @@ _ssl_configure_hostname(PySSLSocket *self, const char* server_hostname) goto error; } } else { - if (!X509_VERIFY_PARAM_set1_ip(param, ASN1_STRING_data(ip), + if (!X509_VERIFY_PARAM_set1_ip(param, ASN1_STRING_get0_data(ip), ASN1_STRING_length(ip))) { _setSSLError(NULL, 0, __FILE__, __LINE__); goto error; @@ -1361,7 +1385,7 @@ _get_peer_alt_names (X509 *certificate) { goto fail; } PyTuple_SET_ITEM(t, 0, v); - v = PyUnicode_FromStringAndSize((char *)ASN1_STRING_data(as), + v = PyUnicode_FromStringAndSize((char *)ASN1_STRING_get0_data(as), ASN1_STRING_length(as)); if (v == NULL) { Py_DECREF(t); @@ -1657,7 +1681,7 @@ _decode_certificate(X509 *certificate) { ASN1_INTEGER *serialNumber; char buf[2048]; int len, result; - ASN1_TIME *notBefore, *notAfter; + const ASN1_TIME *notBefore, *notAfter; PyObject *pnotBefore, *pnotAfter; retval = PyDict_New(); @@ -1719,7 +1743,7 @@ _decode_certificate(X509 *certificate) { Py_DECREF(sn_obj); (void) BIO_reset(biobuf); - notBefore = X509_get_notBefore(certificate); + notBefore = X509_get0_notBefore(certificate); ASN1_TIME_print(biobuf, notBefore); len = BIO_gets(biobuf, buf, sizeof(buf)-1); if (len < 0) { @@ -1736,7 +1760,7 @@ _decode_certificate(X509 *certificate) { Py_DECREF(pnotBefore); (void) BIO_reset(biobuf); - notAfter = X509_get_notAfter(certificate); + notAfter = X509_get0_notAfter(certificate); ASN1_TIME_print(biobuf, notAfter); len = BIO_gets(biobuf, buf, sizeof(buf)-1); if (len < 0) { @@ -3079,17 +3103,23 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version) ctx = SSL_CTX_new(SSLv3_method()); break; #endif -#if defined(TLS1_VERSION) && !defined(OPENSSL_NO_TLS1) +#if (defined(TLS1_VERSION) && \ + !defined(OPENSSL_NO_TLS1) && \ + !defined(OPENSSL_NO_TLS1_METHOD)) case PY_SSL_VERSION_TLS1: ctx = SSL_CTX_new(TLSv1_method()); break; #endif -#if defined(TLS1_1_VERSION) && !defined(OPENSSL_NO_TLS1_1) +#if (defined(TLS1_1_VERSION) && \ + !defined(OPENSSL_NO_TLS1_1) && \ + !defined(OPENSSL_NO_TLS1_1_METHOD)) case PY_SSL_VERSION_TLS1_1: ctx = SSL_CTX_new(TLSv1_1_method()); break; #endif -#if defined(TLS1_2_VERSION) && !defined(OPENSSL_NO_TLS1_2) +#if (defined(TLS1_2_VERSION) && \ + !defined(OPENSSL_NO_TLS1_2) && \ + !defined(OPENSSL_NO_TLS1_2_METHOD)) case PY_SSL_VERSION_TLS1_2: ctx = SSL_CTX_new(TLSv1_2_method()); break; @@ -3207,7 +3237,7 @@ _ssl__SSLContext_impl(PyTypeObject *type, int proto_version) conservative and assume it wasn't fixed until release. We do this check at runtime to avoid problems from the dynamic linker. See #25672 for more on this. */ - libver = SSLeay(); + libver = OpenSSL_version_num(); if (!(libver >= 0x10001000UL && libver < 0x1000108fUL) && !(libver >= 0x10000000UL && libver < 0x100000dfUL)) { SSL_CTX_set_mode(self->ctx, SSL_MODE_RELEASE_BUFFERS); @@ -5286,7 +5316,11 @@ PySSL_RAND(int len, int pseudo) if (bytes == NULL) return NULL; if (pseudo) { +#ifdef PY_OPENSSL_1_1_API + ok = RAND_bytes((unsigned char*)PyBytes_AS_STRING(bytes), len); +#else ok = RAND_pseudo_bytes((unsigned char*)PyBytes_AS_STRING(bytes), len); +#endif if (ok == 0 || ok == 1) return Py_BuildValue("NO", bytes, ok == 1 ? Py_True : Py_False); } @@ -6373,7 +6407,7 @@ PyInit__ssl(void) /* SSLeay() gives us the version of the library linked against, which could be different from the headers version. */ - libver = SSLeay(); + libver = OpenSSL_version_num(); r = PyLong_FromUnsignedLong(libver); if (r == NULL) return NULL; @@ -6383,7 +6417,7 @@ PyInit__ssl(void) r = Py_BuildValue("IIIII", major, minor, fix, patch, status); if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION_INFO", r)) return NULL; - r = PyUnicode_FromString(SSLeay_version(SSLEAY_VERSION)); + r = PyUnicode_FromString(OpenSSL_version(OPENSSL_VERSION)); if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION", r)) return NULL; diff --git a/Modules/_ssl/debughelpers.c b/Modules/_ssl/debughelpers.c index 858b3d7955c..b840da2f663 100644 --- a/Modules/_ssl/debughelpers.c +++ b/Modules/_ssl/debughelpers.c @@ -125,6 +125,12 @@ _PySSL_keylog_callback(const SSL *ssl, const char *line) threadstate = PyGILState_Ensure(); + ssl_obj = (PySSLSocket *)SSL_get_app_data(ssl); + assert(PySSLSocket_Check(ssl_obj)); + if (ssl_obj->ctx->keylog_bio == NULL) { + return; + } + /* Allocate a static lock to synchronize writes to keylog file. * The lock is neither released on exit nor on fork(). The lock is * also shared between all SSLContexts although contexts may write to @@ -141,12 +147,6 @@ _PySSL_keylog_callback(const SSL *ssl, const char *line) } } - ssl_obj = (PySSLSocket *)SSL_get_app_data(ssl); - assert(PySSLSocket_Check(ssl_obj)); - if (ssl_obj->ctx->keylog_bio == NULL) { - return; - } - PySSL_BEGIN_ALLOW_THREADS PyThread_acquire_lock(lock, 1); res = BIO_printf(ssl_obj->ctx->keylog_bio, "%s\n", line); diff --git a/Modules/_struct.c b/Modules/_struct.c index 5984bb68114..81cdbb9b817 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -121,7 +121,7 @@ get_pylong(PyObject *v) if (!PyLong_Check(v)) { /* Not an integer; try to use __index__ to convert. */ if (PyIndex_Check(v)) { - v = PyNumber_Index(v); + v = _PyNumber_Index(v); if (v == NULL) return NULL; } @@ -1646,6 +1646,7 @@ unpackiter_dealloc(unpackiterobject *self) static int unpackiter_traverse(unpackiterobject *self, visitproc visit, void *arg) { + Py_VISIT(Py_TYPE(self)); Py_VISIT(self->so); Py_VISIT(self->buf.obj); return 0; diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 101d54932d9..1e4c31fefb2 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1668,6 +1668,10 @@ exit: static volatile int x; +/* Ignore use of deprecated APIs */ +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS + /* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case of an error. */ @@ -1844,6 +1848,7 @@ test_widechar(PyObject *self, PyObject *Py_UNUSED(ignored)) Py_RETURN_NONE; } +_Py_COMP_DIAG_POP static PyObject * unicode_aswidechar(PyObject *self, PyObject *args) @@ -2019,6 +2024,10 @@ unicode_copycharacters(PyObject *self, PyObject *args) return Py_BuildValue("(Nn)", to_copy, copied); } +/* Ignore use of deprecated APIs */ +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS + static PyObject * unicode_encodedecimal(PyObject *self, PyObject *args) { @@ -2086,6 +2095,7 @@ unicode_legacy_string(PyObject *self, PyObject *args) return u; } +_Py_COMP_DIAG_POP static PyObject * getargs_w_star(PyObject *self, PyObject *args) @@ -3458,6 +3468,8 @@ run_in_subinterp(PyObject *self, PyObject *args) const char *code; int r; PyThreadState *substate, *mainstate; + /* only initialise 'cflags.cf_flags' to test backwards compatibility */ + PyCompilerFlags cflags = {0}; if (!PyArg_ParseTuple(args, "s:run_in_subinterp", &code)) @@ -3476,7 +3488,7 @@ run_in_subinterp(PyObject *self, PyObject *args) PyErr_SetString(PyExc_RuntimeError, "sub-interpreter creation failed"); return NULL; } - r = PyRun_SimpleString(code); + r = PyRun_SimpleStringFlags(code, &cflags); Py_EndInterpreter(substate); PyThreadState_Swap(mainstate); @@ -4225,15 +4237,15 @@ static PyObject* pymarshal_write_long_to_file(PyObject* self, PyObject *args) { long value; - char *filename; + PyObject *filename; int version; FILE *fp; - if (!PyArg_ParseTuple(args, "lsi:pymarshal_write_long_to_file", + if (!PyArg_ParseTuple(args, "lOi:pymarshal_write_long_to_file", &value, &filename, &version)) return NULL; - fp = fopen(filename, "wb"); + fp = _Py_fopen_obj(filename, "wb"); if (fp == NULL) { PyErr_SetFromErrno(PyExc_OSError); return NULL; @@ -4251,15 +4263,15 @@ static PyObject* pymarshal_write_object_to_file(PyObject* self, PyObject *args) { PyObject *obj; - char *filename; + PyObject *filename; int version; FILE *fp; - if (!PyArg_ParseTuple(args, "Osi:pymarshal_write_object_to_file", + if (!PyArg_ParseTuple(args, "OOi:pymarshal_write_object_to_file", &obj, &filename, &version)) return NULL; - fp = fopen(filename, "wb"); + fp = _Py_fopen_obj(filename, "wb"); if (fp == NULL) { PyErr_SetFromErrno(PyExc_OSError); return NULL; @@ -4278,13 +4290,13 @@ pymarshal_read_short_from_file(PyObject* self, PyObject *args) { int value; long pos; - char *filename; + PyObject *filename; FILE *fp; - if (!PyArg_ParseTuple(args, "s:pymarshal_read_short_from_file", &filename)) + if (!PyArg_ParseTuple(args, "O:pymarshal_read_short_from_file", &filename)) return NULL; - fp = fopen(filename, "rb"); + fp = _Py_fopen_obj(filename, "rb"); if (fp == NULL) { PyErr_SetFromErrno(PyExc_OSError); return NULL; @@ -4303,13 +4315,13 @@ static PyObject* pymarshal_read_long_from_file(PyObject* self, PyObject *args) { long value, pos; - char *filename; + PyObject *filename; FILE *fp; - if (!PyArg_ParseTuple(args, "s:pymarshal_read_long_from_file", &filename)) + if (!PyArg_ParseTuple(args, "O:pymarshal_read_long_from_file", &filename)) return NULL; - fp = fopen(filename, "rb"); + fp = _Py_fopen_obj(filename, "rb"); if (fp == NULL) { PyErr_SetFromErrno(PyExc_OSError); return NULL; @@ -4329,13 +4341,13 @@ pymarshal_read_last_object_from_file(PyObject* self, PyObject *args) { PyObject *obj; long pos; - char *filename; + PyObject *filename; FILE *fp; - if (!PyArg_ParseTuple(args, "s:pymarshal_read_last_object_from_file", &filename)) + if (!PyArg_ParseTuple(args, "O:pymarshal_read_last_object_from_file", &filename)) return NULL; - fp = fopen(filename, "rb"); + fp = _Py_fopen_obj(filename, "rb"); if (fp == NULL) { PyErr_SetFromErrno(PyExc_OSError); return NULL; @@ -4353,13 +4365,13 @@ pymarshal_read_object_from_file(PyObject* self, PyObject *args) { PyObject *obj; long pos; - char *filename; + PyObject *filename; FILE *fp; - if (!PyArg_ParseTuple(args, "s:pymarshal_read_object_from_file", &filename)) + if (!PyArg_ParseTuple(args, "O:pymarshal_read_object_from_file", &filename)) return NULL; - fp = fopen(filename, "rb"); + fp = _Py_fopen_obj(filename, "rb"); if (fp == NULL) { PyErr_SetFromErrno(PyExc_OSError); return NULL; @@ -6298,6 +6310,47 @@ static PyType_Spec HeapCTypeSubclass_spec = { HeapCTypeSubclass_slots }; +PyDoc_STRVAR(heapctypewithbuffer__doc__, +"Heap type with buffer support.\n\n" +"The buffer is set to [b'1', b'2', b'3', b'4']"); + +typedef struct { + HeapCTypeObject base; + char buffer[4]; +} HeapCTypeWithBufferObject; + +static int +heapctypewithbuffer_getbuffer(HeapCTypeWithBufferObject *self, Py_buffer *view, int flags) +{ + self->buffer[0] = '1'; + self->buffer[1] = '2'; + self->buffer[2] = '3'; + self->buffer[3] = '4'; + return PyBuffer_FillInfo( + view, (PyObject*)self, (void *)self->buffer, 4, 1, flags); +} + +static void +heapctypewithbuffer_releasebuffer(HeapCTypeWithBufferObject *self, Py_buffer *view) +{ + assert(view->obj == (void*) self); +} + +static PyType_Slot HeapCTypeWithBuffer_slots[] = { + {Py_bf_getbuffer, heapctypewithbuffer_getbuffer}, + {Py_bf_releasebuffer, heapctypewithbuffer_releasebuffer}, + {Py_tp_doc, (char*)heapctypewithbuffer__doc__}, + {0, 0}, +}; + +static PyType_Spec HeapCTypeWithBuffer_spec = { + "_testcapi.HeapCTypeWithBuffer", + sizeof(HeapCTypeWithBufferObject), + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + HeapCTypeWithBuffer_slots +}; + PyDoc_STRVAR(heapctypesubclasswithfinalizer__doc__, "Subclass of HeapCType with a finalizer that reassigns __class__.\n\n" "__class__ is set to plain HeapCTypeSubclass during finalization.\n" @@ -6475,6 +6528,80 @@ static PyType_Spec HeapCTypeWithWeakref_spec = { HeapCTypeWithWeakref_slots }; +PyDoc_STRVAR(heapctypesetattr__doc__, +"A heap type without GC, but with overridden __setattr__.\n\n" +"The 'value' attribute is set to 10 in __init__ and updated via attribute setting."); + +typedef struct { + PyObject_HEAD + long value; +} HeapCTypeSetattrObject; + +static struct PyMemberDef heapctypesetattr_members[] = { + {"pvalue", T_LONG, offsetof(HeapCTypeSetattrObject, value)}, + {NULL} /* Sentinel */ +}; + +static int +heapctypesetattr_init(PyObject *self, PyObject *args, PyObject *kwargs) +{ + ((HeapCTypeSetattrObject *)self)->value = 10; + return 0; +} + +static void +heapctypesetattr_dealloc(HeapCTypeSetattrObject *self) +{ + PyTypeObject *tp = Py_TYPE(self); + PyObject_Del(self); + Py_DECREF(tp); +} + +static int +heapctypesetattr_setattro(HeapCTypeSetattrObject *self, PyObject *attr, PyObject *value) +{ + PyObject *svalue = PyUnicode_FromString("value"); + if (svalue == NULL) + return -1; + int eq = PyObject_RichCompareBool(svalue, attr, Py_EQ); + Py_DECREF(svalue); + if (eq < 0) + return -1; + if (!eq) { + return PyObject_GenericSetAttr((PyObject*) self, attr, value); + } + if (value == NULL) { + self->value = 0; + return 0; + } + PyObject *ivalue = PyNumber_Long(value); + if (ivalue == NULL) + return -1; + long v = PyLong_AsLong(ivalue); + Py_DECREF(ivalue); + if (v == -1 && PyErr_Occurred()) + return -1; + self->value = v; + return 0; +} + +static PyType_Slot HeapCTypeSetattr_slots[] = { + {Py_tp_init, heapctypesetattr_init}, + {Py_tp_members, heapctypesetattr_members}, + {Py_tp_setattro, heapctypesetattr_setattro}, + {Py_tp_dealloc, heapctypesetattr_dealloc}, + {Py_tp_doc, (char*)heapctypesetattr__doc__}, + {0, 0}, +}; + +static PyType_Spec HeapCTypeSetattr_spec = { + "_testcapi.HeapCTypeSetattr", + sizeof(HeapCTypeSetattrObject), + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + HeapCTypeSetattr_slots +}; + static PyMethodDef meth_instance_methods[] = { {"meth_varargs", meth_varargs, METH_VARARGS}, {"meth_varargs_keywords", (PyCFunction)(void(*)(void))meth_varargs_keywords, METH_VARARGS|METH_KEYWORDS}, @@ -6775,6 +6902,18 @@ PyInit__testcapi(void) } PyModule_AddObject(m, "HeapCTypeWithWeakref", HeapCTypeWithWeakref); + PyObject *HeapCTypeWithBuffer = PyType_FromSpec(&HeapCTypeWithBuffer_spec); + if (HeapCTypeWithBuffer == NULL) { + return NULL; + } + PyModule_AddObject(m, "HeapCTypeWithBuffer", HeapCTypeWithBuffer); + + PyObject *HeapCTypeSetattr = PyType_FromSpec(&HeapCTypeSetattr_spec); + if (HeapCTypeSetattr == NULL) { + return NULL; + } + PyModule_AddObject(m, "HeapCTypeSetattr", HeapCTypeSetattr); + PyObject *subclass_with_finalizer_bases = PyTuple_Pack(1, HeapCTypeSubclass); if (subclass_with_finalizer_bases == NULL) { return NULL; @@ -6811,29 +6950,36 @@ test_buildvalue_issue38913(PyObject *self, PyObject *Py_UNUSED(ignored)) PyObject *res; const char str[] = "string"; const Py_UNICODE unicode[] = L"unicode"; - PyErr_SetNone(PyExc_ZeroDivisionError); + assert(!PyErr_Occurred()); res = Py_BuildValue("(s#O)", str, 1, Py_None); assert(res == NULL); - if (!PyErr_ExceptionMatches(PyExc_ZeroDivisionError)) { + if (!PyErr_ExceptionMatches(PyExc_SystemError)) { return NULL; } + PyErr_Clear(); + res = Py_BuildValue("(z#O)", str, 1, Py_None); assert(res == NULL); - if (!PyErr_ExceptionMatches(PyExc_ZeroDivisionError)) { + if (!PyErr_ExceptionMatches(PyExc_SystemError)) { return NULL; } + PyErr_Clear(); + res = Py_BuildValue("(y#O)", str, 1, Py_None); assert(res == NULL); - if (!PyErr_ExceptionMatches(PyExc_ZeroDivisionError)) { + if (!PyErr_ExceptionMatches(PyExc_SystemError)) { return NULL; } + PyErr_Clear(); + res = Py_BuildValue("(u#O)", unicode, 1, Py_None); assert(res == NULL); - if (!PyErr_ExceptionMatches(PyExc_ZeroDivisionError)) { + if (!PyErr_ExceptionMatches(PyExc_SystemError)) { return NULL; } - PyErr_Clear(); + + Py_RETURN_NONE; } diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c index 5f217dcb897..f08bf8d83d4 100644 --- a/Modules/_testinternalcapi.c +++ b/Modules/_testinternalcapi.c @@ -12,16 +12,59 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" -#include "pycore_byteswap.h" // _Py_bswap32() +#include "pycore_bitutils.h" // _Py_bswap32() #include "pycore_initconfig.h" // _Py_GetConfigsAsDict() #include "pycore_hashtable.h" // _Py_hashtable_new() #include "pycore_gc.h" // PyGC_Head +#ifdef MS_WINDOWS +#include + +static int +_add_windows_config(PyObject *configs) +{ + HMODULE hPython3; + wchar_t py3path[MAX_PATH]; + PyObject *dict = PyDict_New(); + PyObject *obj = NULL; + if (!dict) { + return -1; + } + + hPython3 = GetModuleHandleW(PY3_DLLNAME); + if (hPython3 && GetModuleFileNameW(hPython3, py3path, MAX_PATH)) { + obj = PyUnicode_FromWideChar(py3path, -1); + } else { + obj = Py_None; + Py_INCREF(obj); + } + if (obj && + !PyDict_SetItemString(dict, "python3_dll", obj) && + !PyDict_SetItemString(configs, "windows", dict)) { + Py_DECREF(obj); + Py_DECREF(dict); + return 0; + } + Py_DECREF(obj); + Py_DECREF(dict); + return -1; +} +#endif + + static PyObject * get_configs(PyObject *self, PyObject *Py_UNUSED(args)) { - return _Py_GetConfigsAsDict(); + PyObject *dict = _Py_GetConfigsAsDict(); +#ifdef MS_WINDOWS + if (dict) { + if (_add_windows_config(dict) < 0) { + Py_CLEAR(dict); + } + } +#endif + return dict; } @@ -63,6 +106,84 @@ test_bswap(PyObject *self, PyObject *Py_UNUSED(args)) } +static int +check_popcount(uint32_t x, int expected) +{ + // Use volatile to prevent the compiler to optimize out the whole test + volatile uint32_t u = x; + int bits = _Py_popcount32(u); + if (bits != expected) { + PyErr_Format(PyExc_AssertionError, + "_Py_popcount32(%lu) returns %i, expected %i", + (unsigned long)x, bits, expected); + return -1; + } + return 0; +} + + +static PyObject* +test_popcount(PyObject *self, PyObject *Py_UNUSED(args)) +{ +#define CHECK(X, RESULT) \ + do { \ + if (check_popcount(X, RESULT) < 0) { \ + return NULL; \ + } \ + } while (0) + + CHECK(0, 0); + CHECK(1, 1); + CHECK(0x08080808, 4); + CHECK(0x10101010, 4); + CHECK(0x10204080, 4); + CHECK(0xDEADCAFE, 22); + CHECK(0xFFFFFFFF, 32); + Py_RETURN_NONE; + +#undef CHECK +} + + +static int +check_bit_length(unsigned long x, int expected) +{ + // Use volatile to prevent the compiler to optimize out the whole test + volatile unsigned long u = x; + int len = _Py_bit_length(u); + if (len != expected) { + PyErr_Format(PyExc_AssertionError, + "_Py_bit_length(%lu) returns %i, expected %i", + x, len, expected); + return -1; + } + return 0; +} + + +static PyObject* +test_bit_length(PyObject *self, PyObject *Py_UNUSED(args)) +{ +#define CHECK(X, RESULT) \ + do { \ + if (check_bit_length(X, RESULT) < 0) { \ + return NULL; \ + } \ + } while (0) + + CHECK(0, 0); + CHECK(1, 1); + CHECK(0x1000, 13); + CHECK(0x1234, 13); + CHECK(0x54321, 19); + CHECK(0x7FFFFFFF, 31); + CHECK(0xFFFFFFFF, 32); + Py_RETURN_NONE; + +#undef CHECK +} + + #define TO_PTR(ch) ((void*)(uintptr_t)ch) #define FROM_PTR(ptr) ((uintptr_t)ptr) #define VALUE(key) (1 + ((int)(key) - 'a')) @@ -119,8 +240,8 @@ test_hashtable(PyObject *self, PyObject *Py_UNUSED(args)) for (key='a'; key <= 'z'; key++) { _Py_hashtable_entry_t *entry = _Py_hashtable_get_entry(table, TO_PTR(key)); assert(entry != NULL); - assert(entry->key = TO_PTR(key)); - assert(entry->value = TO_PTR(VALUE(key))); + assert(entry->key == TO_PTR(key)); + assert(entry->value == TO_PTR(VALUE(key))); } // Test _Py_hashtable_get() @@ -157,6 +278,8 @@ static PyMethodDef TestMethods[] = { {"get_configs", get_configs, METH_NOARGS}, {"get_recursion_depth", get_recursion_depth, METH_NOARGS}, {"test_bswap", test_bswap, METH_NOARGS}, + {"test_popcount", test_popcount, METH_NOARGS}, + {"test_bit_length", test_bit_length, METH_NOARGS}, {"test_hashtable", test_hashtable, METH_NOARGS}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 56757165745..fc91622d392 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -319,10 +319,6 @@ tracemalloc_get_frame(PyFrameObject *pyframe, frame_t *frame) return; } - assert(filename != NULL); - if (filename == NULL) - return; - if (!PyUnicode_Check(filename)) { #ifdef TRACE_DEBUG tracemalloc_error("filename is not a unicode string"); diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index d852c763e2e..a2883495fe7 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -36,8 +36,8 @@ typedef struct { PyObject *key; PyObject *file_repr; PyObject *weakreflist; - unsigned int num_transitions; - unsigned int num_ttinfos; + size_t num_transitions; + size_t num_ttinfos; int64_t *trans_list_utc; int64_t *trans_list_wall[2]; _ttinfo **trans_ttinfos; // References to the ttinfo for each transition @@ -117,14 +117,14 @@ ts_to_local(size_t *trans_idx, int64_t *trans_utc, long *utcoff, static int parse_tz_str(PyObject *tz_str_obj, _tzrule *out); -static ssize_t +static Py_ssize_t parse_abbr(const char *const p, PyObject **abbr); -static ssize_t +static Py_ssize_t parse_tz_delta(const char *const p, long *total_seconds); -static ssize_t +static Py_ssize_t parse_transition_time(const char *const p, int8_t *hour, int8_t *minute, int8_t *second); -static ssize_t +static Py_ssize_t parse_transition_rule(const char *const p, TransitionRuleType **out); static _ttinfo * @@ -278,13 +278,11 @@ zoneinfo_new(PyTypeObject *type, PyObject *args, PyObject *kw) instance = PyObject_CallMethod(weak_cache, "setdefault", "OO", key, tmp); - ((PyZoneInfo_ZoneInfo *)instance)->source = SOURCE_CACHE; - Py_DECREF(tmp); - if (instance == NULL) { return NULL; } + ((PyZoneInfo_ZoneInfo *)instance)->source = SOURCE_CACHE; } update_strong_cache(type, key, instance); @@ -891,12 +889,12 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj) // Load the relevant sizes Py_ssize_t num_transitions = PyTuple_Size(trans_utc); - if (num_transitions == -1) { + if (num_transitions < 0) { goto error; } Py_ssize_t num_ttinfos = PyTuple_Size(utcoff_list); - if (num_ttinfos == -1) { + if (num_ttinfos < 0) { goto error; } @@ -908,7 +906,7 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj) PyMem_Malloc(self->num_transitions * sizeof(int64_t)); trans_idx = PyMem_Malloc(self->num_transitions * sizeof(Py_ssize_t)); - for (Py_ssize_t i = 0; i < self->num_transitions; ++i) { + for (size_t i = 0; i < self->num_transitions; ++i) { PyObject *num = PyTuple_GetItem(trans_utc, i); if (num == NULL) { goto error; @@ -946,7 +944,7 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj) if (utcoff == NULL || isdst == NULL) { goto error; } - for (Py_ssize_t i = 0; i < self->num_ttinfos; ++i) { + for (size_t i = 0; i < self->num_ttinfos; ++i) { PyObject *num = PyTuple_GetItem(utcoff_list, i); if (num == NULL) { goto error; @@ -1468,7 +1466,7 @@ parse_tz_str(PyObject *tz_str_obj, _tzrule *out) char *p = tz_str; // Read the `std` abbreviation, which must be at least 3 characters long. - ssize_t num_chars = parse_abbr(p, &std_abbr); + Py_ssize_t num_chars = parse_abbr(p, &std_abbr); if (num_chars < 1) { PyErr_Format(PyExc_ValueError, "Invalid STD format in %R", tz_str_obj); goto error; @@ -1565,18 +1563,19 @@ error: return -1; } -static ssize_t -parse_uint(const char *const p) +static int +parse_uint(const char *const p, uint8_t *value) { if (!isdigit(*p)) { return -1; } - return (*p) - '0'; + *value = (*p) - '0'; + return 0; } /* Parse the STD and DST abbreviations from a TZ string. */ -static ssize_t +static Py_ssize_t parse_abbr(const char *const p, PyObject **abbr) { const char *ptr = p; @@ -1621,7 +1620,7 @@ parse_abbr(const char *const p, PyObject **abbr) } *abbr = PyUnicode_FromStringAndSize(str_start, str_end - str_start); - if (abbr == NULL) { + if (*abbr == NULL) { return -1; } @@ -1629,7 +1628,7 @@ parse_abbr(const char *const p, PyObject **abbr) } /* Parse a UTC offset from a TZ str. */ -static ssize_t +static Py_ssize_t parse_tz_delta(const char *const p, long *total_seconds) { // From the POSIX spec: @@ -1712,7 +1711,7 @@ complete: } /* Parse the date portion of a transition rule. */ -static ssize_t +static Py_ssize_t parse_transition_rule(const char *const p, TransitionRuleType **out) { // The full transition rule indicates when to change back and forth between @@ -1739,20 +1738,18 @@ parse_transition_rule(const char *const p, TransitionRuleType **out) if (*ptr == 'M') { uint8_t month, week, day; ptr++; - ssize_t tmp = parse_uint(ptr); - if (tmp < 0) { + if (parse_uint(ptr, &month)) { return -1; } - month = (uint8_t)tmp; ptr++; if (*ptr != '.') { - tmp = parse_uint(ptr); - if (tmp < 0) { + uint8_t tmp; + if (parse_uint(ptr, &tmp)) { return -1; } month *= 10; - month += (uint8_t)tmp; + month += tmp; ptr++; } @@ -1763,18 +1760,15 @@ parse_transition_rule(const char *const p, TransitionRuleType **out) } ptr++; - tmp = parse_uint(ptr); - if (tmp < 0) { + if (parse_uint(ptr, values[i])) { return -1; } ptr++; - - *(values[i]) = tmp; } if (*ptr == '/') { ptr++; - ssize_t num_chars = + Py_ssize_t num_chars = parse_transition_time(ptr, &hour, &minute, &second); if (num_chars < 0) { return -1; @@ -1816,7 +1810,7 @@ parse_transition_rule(const char *const p, TransitionRuleType **out) if (*ptr == '/') { ptr++; - ssize_t num_chars = + Py_ssize_t num_chars = parse_transition_time(ptr, &hour, &minute, &second); if (num_chars < 0) { return -1; @@ -1840,7 +1834,7 @@ parse_transition_rule(const char *const p, TransitionRuleType **out) } /* Parse the time portion of a transition rule (e.g. following an /) */ -static ssize_t +static Py_ssize_t parse_transition_time(const char *const p, int8_t *hour, int8_t *minute, int8_t *second) { diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index fb1b82cd6a6..2ba2ff43aa8 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -344,7 +344,7 @@ II_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) int do_decref = 0; /* if nb_int was called */ if (!PyLong_Check(v)) { - v = PyNumber_Index(v); + v = _PyNumber_Index(v); if (NULL == v) { return -1; } @@ -404,7 +404,7 @@ LL_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) int do_decref = 0; /* if nb_int was called */ if (!PyLong_Check(v)) { - v = PyNumber_Index(v); + v = _PyNumber_Index(v); if (NULL == v) { return -1; } @@ -457,7 +457,7 @@ QQ_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) int do_decref = 0; /* if nb_int was called */ if (!PyLong_Check(v)) { - v = PyNumber_Index(v); + v = _PyNumber_Index(v); if (NULL == v) { return -1; } @@ -1130,7 +1130,7 @@ array_array_index(arrayobject *self, PyObject *v) cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); Py_DECREF(selfi); if (cmp > 0) { - return PyLong_FromLong((long)i); + return PyLong_FromSsize_t(i); } else if (cmp < 0) return NULL; @@ -2525,14 +2525,14 @@ array_buffer_getbuf(arrayobject *self, Py_buffer *view, int flags) Py_INCREF(self); if (view->buf == NULL) view->buf = (void *)emptybuf; - view->len = (Py_SIZE(self)) * self->ob_descr->itemsize; + view->len = Py_SIZE(self) * self->ob_descr->itemsize; view->readonly = 0; view->ndim = 1; view->itemsize = self->ob_descr->itemsize; view->suboffsets = NULL; view->shape = NULL; if ((flags & PyBUF_ND)==PyBUF_ND) { - view->shape = &((Py_SIZE(self))); + view->shape = &((PyVarObject*)self)->ob_size; } view->strides = NULL; if ((flags & PyBUF_STRIDES)==PyBUF_STRIDES) @@ -2989,6 +2989,26 @@ array_modexec(PyObject *m) Py_DECREF((PyObject *)&Arraytype); return -1; } + + PyObject *abc_mod = PyImport_ImportModule("collections.abc"); + if (!abc_mod) { + Py_DECREF((PyObject *)&Arraytype); + return -1; + } + PyObject *mutablesequence = PyObject_GetAttrString(abc_mod, "MutableSequence"); + Py_DECREF(abc_mod); + if (!mutablesequence) { + Py_DECREF((PyObject *)&Arraytype); + return -1; + } + PyObject *res = PyObject_CallMethod(mutablesequence, "register", "O", (PyObject *)&Arraytype); + Py_DECREF(mutablesequence); + if (!res) { + Py_DECREF((PyObject *)&Arraytype); + return -1; + } + Py_DECREF(res); + Py_INCREF((PyObject *)&Arraytype); if (PyModule_AddObject(m, "array", (PyObject *)&Arraytype) < 0) { Py_DECREF((PyObject *)&Arraytype); diff --git a/Modules/clinic/_asynciomodule.c.h b/Modules/clinic/_asynciomodule.c.h index d3e59a4bc78..a071efc1e2b 100644 --- a/Modules/clinic/_asynciomodule.c.h +++ b/Modules/clinic/_asynciomodule.c.h @@ -355,86 +355,6 @@ exit: return return_value; } -PyDoc_STRVAR(_asyncio_Task_current_task__doc__, -"current_task($type, /, loop=None)\n" -"--\n" -"\n" -"Return the currently running task in an event loop or None.\n" -"\n" -"By default the current task for the current event loop is returned.\n" -"\n" -"None is returned when called not in the context of a Task."); - -#define _ASYNCIO_TASK_CURRENT_TASK_METHODDEF \ - {"current_task", (PyCFunction)(void(*)(void))_asyncio_Task_current_task, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, _asyncio_Task_current_task__doc__}, - -static PyObject * -_asyncio_Task_current_task_impl(PyTypeObject *type, PyObject *loop); - -static PyObject * -_asyncio_Task_current_task(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) -{ - PyObject *return_value = NULL; - static const char * const _keywords[] = {"loop", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "current_task", 0}; - PyObject *argsbuf[1]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; - PyObject *loop = Py_None; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); - if (!args) { - goto exit; - } - if (!noptargs) { - goto skip_optional_pos; - } - loop = args[0]; -skip_optional_pos: - return_value = _asyncio_Task_current_task_impl(type, loop); - -exit: - return return_value; -} - -PyDoc_STRVAR(_asyncio_Task_all_tasks__doc__, -"all_tasks($type, /, loop=None)\n" -"--\n" -"\n" -"Return a set of all tasks for an event loop.\n" -"\n" -"By default all tasks for the current event loop are returned."); - -#define _ASYNCIO_TASK_ALL_TASKS_METHODDEF \ - {"all_tasks", (PyCFunction)(void(*)(void))_asyncio_Task_all_tasks, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, _asyncio_Task_all_tasks__doc__}, - -static PyObject * -_asyncio_Task_all_tasks_impl(PyTypeObject *type, PyObject *loop); - -static PyObject * -_asyncio_Task_all_tasks(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) -{ - PyObject *return_value = NULL; - static const char * const _keywords[] = {"loop", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "all_tasks", 0}; - PyObject *argsbuf[1]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; - PyObject *loop = Py_None; - - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); - if (!args) { - goto exit; - } - if (!noptargs) { - goto skip_optional_pos; - } - loop = args[0]; -skip_optional_pos: - return_value = _asyncio_Task_all_tasks_impl(type, loop); - -exit: - return return_value; -} - PyDoc_STRVAR(_asyncio_Task__make_cancelled_error__doc__, "_make_cancelled_error($self, /)\n" "--\n" @@ -912,4 +832,4 @@ _asyncio__leave_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, exit: return return_value; } -/*[clinic end generated code: output=0e5c1eb8b692977b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d0fc522bcbff9d61 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_bisectmodule.c.h b/Modules/clinic/_bisectmodule.c.h index 8a0170a2c7f..07fc9060d1d 100644 --- a/Modules/clinic/_bisectmodule.c.h +++ b/Modules/clinic/_bisectmodule.c.h @@ -48,7 +48,7 @@ _bisect_bisect_right(PyObject *module, PyObject *const *args, Py_ssize_t nargs, if (args[2]) { { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -119,7 +119,7 @@ _bisect_insort_right(PyObject *module, PyObject *const *args, Py_ssize_t nargs, if (args[2]) { { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -189,7 +189,7 @@ _bisect_bisect_left(PyObject *module, PyObject *const *args, Py_ssize_t nargs, P if (args[2]) { { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -260,7 +260,7 @@ _bisect_insort_left(PyObject *module, PyObject *const *args, Py_ssize_t nargs, P if (args[2]) { { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -283,4 +283,4 @@ skip_optional_pos: exit: return return_value; } -/*[clinic end generated code: output=e9097a9acd10b13f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6cf46f205659f01a input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_bz2module.c.h b/Modules/clinic/_bz2module.c.h index ab610a141e3..ff67d34155d 100644 --- a/Modules/clinic/_bz2module.c.h +++ b/Modules/clinic/_bz2module.c.h @@ -65,45 +65,21 @@ _bz2_BZ2Compressor_flush(BZ2Compressor *self, PyObject *Py_UNUSED(ignored)) return _bz2_BZ2Compressor_flush_impl(self); } -PyDoc_STRVAR(_bz2_BZ2Compressor___init____doc__, -"BZ2Compressor(compresslevel=9, /)\n" +PyDoc_STRVAR(_bz2_BZ2Compressor___reduce____doc__, +"__reduce__($self, /)\n" "--\n" -"\n" -"Create a compressor object for compressing data incrementally.\n" -"\n" -" compresslevel\n" -" Compression level, as a number between 1 and 9.\n" -"\n" -"For one-shot compression, use the compress() function instead."); +"\n"); -static int -_bz2_BZ2Compressor___init___impl(BZ2Compressor *self, int compresslevel); +#define _BZ2_BZ2COMPRESSOR___REDUCE___METHODDEF \ + {"__reduce__", (PyCFunction)_bz2_BZ2Compressor___reduce__, METH_NOARGS, _bz2_BZ2Compressor___reduce____doc__}, -static int -_bz2_BZ2Compressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) +static PyObject * +_bz2_BZ2Compressor___reduce___impl(BZ2Compressor *self); + +static PyObject * +_bz2_BZ2Compressor___reduce__(BZ2Compressor *self, PyObject *Py_UNUSED(ignored)) { - int return_value = -1; - int compresslevel = 9; - - if (Py_IS_TYPE(self, &BZ2Compressor_Type) && - !_PyArg_NoKeywords("BZ2Compressor", kwargs)) { - goto exit; - } - if (!_PyArg_CheckPositional("BZ2Compressor", PyTuple_GET_SIZE(args), 0, 1)) { - goto exit; - } - if (PyTuple_GET_SIZE(args) < 1) { - goto skip_optional; - } - compresslevel = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0)); - if (compresslevel == -1 && PyErr_Occurred()) { - goto exit; - } -skip_optional: - return_value = _bz2_BZ2Compressor___init___impl((BZ2Compressor *)self, compresslevel); - -exit: - return return_value; + return _bz2_BZ2Compressor___reduce___impl(self); } PyDoc_STRVAR(_bz2_BZ2Decompressor_decompress__doc__, @@ -159,7 +135,7 @@ _bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *const *args, Py } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -181,33 +157,20 @@ exit: return return_value; } -PyDoc_STRVAR(_bz2_BZ2Decompressor___init____doc__, -"BZ2Decompressor()\n" +PyDoc_STRVAR(_bz2_BZ2Decompressor___reduce____doc__, +"__reduce__($self, /)\n" "--\n" -"\n" -"Create a decompressor object for decompressing data incrementally.\n" -"\n" -"For one-shot decompression, use the decompress() function instead."); +"\n"); -static int -_bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self); +#define _BZ2_BZ2DECOMPRESSOR___REDUCE___METHODDEF \ + {"__reduce__", (PyCFunction)_bz2_BZ2Decompressor___reduce__, METH_NOARGS, _bz2_BZ2Decompressor___reduce____doc__}, -static int -_bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) +static PyObject * +_bz2_BZ2Decompressor___reduce___impl(BZ2Decompressor *self); + +static PyObject * +_bz2_BZ2Decompressor___reduce__(BZ2Decompressor *self, PyObject *Py_UNUSED(ignored)) { - int return_value = -1; - - if (Py_IS_TYPE(self, &BZ2Decompressor_Type) && - !_PyArg_NoPositional("BZ2Decompressor", args)) { - goto exit; - } - if (Py_IS_TYPE(self, &BZ2Decompressor_Type) && - !_PyArg_NoKeywords("BZ2Decompressor", kwargs)) { - goto exit; - } - return_value = _bz2_BZ2Decompressor___init___impl((BZ2Decompressor *)self); - -exit: - return return_value; + return _bz2_BZ2Decompressor___reduce___impl(self); } -/*[clinic end generated code: output=c69a7de8e26c2ad1 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=001f31fdacb4cb01 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_collectionsmodule.c.h b/Modules/clinic/_collectionsmodule.c.h index 0cc1466549d..7e18aeb312c 100644 --- a/Modules/clinic/_collectionsmodule.c.h +++ b/Modules/clinic/_collectionsmodule.c.h @@ -52,7 +52,7 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(PyTuple_GET_ITEM(args, 0)); + PyObject *iobj = _PyNumber_Index(PyTuple_GET_ITEM(args, 0)); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -68,4 +68,4 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=439d77631a056b4d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=947186d369f50f1e input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_dbmmodule.c.h b/Modules/clinic/_dbmmodule.c.h index edf29be92af..af288c2586a 100644 --- a/Modules/clinic/_dbmmodule.c.h +++ b/Modules/clinic/_dbmmodule.c.h @@ -27,15 +27,26 @@ PyDoc_STRVAR(_dbm_dbm_keys__doc__, "Return a list of all keys in the database."); #define _DBM_DBM_KEYS_METHODDEF \ - {"keys", (PyCFunction)_dbm_dbm_keys, METH_NOARGS, _dbm_dbm_keys__doc__}, + {"keys", (PyCFunction)(void(*)(void))_dbm_dbm_keys, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _dbm_dbm_keys__doc__}, static PyObject * -_dbm_dbm_keys_impl(dbmobject *self); +_dbm_dbm_keys_impl(dbmobject *self, PyTypeObject *cls); static PyObject * -_dbm_dbm_keys(dbmobject *self, PyObject *Py_UNUSED(ignored)) +_dbm_dbm_keys(dbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _dbm_dbm_keys_impl(self); + PyObject *return_value = NULL; + static const char * const _keywords[] = { NULL}; + static _PyArg_Parser _parser = {":keys", _keywords, 0}; + + if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser + )) { + goto exit; + } + return_value = _dbm_dbm_keys_impl(self, cls); + +exit: + return return_value; } PyDoc_STRVAR(_dbm_dbm_get__doc__, @@ -45,25 +56,27 @@ PyDoc_STRVAR(_dbm_dbm_get__doc__, "Return the value for key if present, otherwise default."); #define _DBM_DBM_GET_METHODDEF \ - {"get", (PyCFunction)(void(*)(void))_dbm_dbm_get, METH_FASTCALL, _dbm_dbm_get__doc__}, + {"get", (PyCFunction)(void(*)(void))_dbm_dbm_get, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _dbm_dbm_get__doc__}, static PyObject * -_dbm_dbm_get_impl(dbmobject *self, const char *key, +_dbm_dbm_get_impl(dbmobject *self, PyTypeObject *cls, const char *key, Py_ssize_clean_t key_length, PyObject *default_value); static PyObject * -_dbm_dbm_get(dbmobject *self, PyObject *const *args, Py_ssize_t nargs) +_dbm_dbm_get(dbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = {"s#|O:get", _keywords, 0}; const char *key; Py_ssize_clean_t key_length; PyObject *default_value = Py_None; - if (!_PyArg_ParseStack(args, nargs, "s#|O:get", + if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, &key, &key_length, &default_value)) { goto exit; } - return_value = _dbm_dbm_get_impl(self, key, key_length, default_value); + return_value = _dbm_dbm_get_impl(self, cls, key, key_length, default_value); exit: return return_value; @@ -78,26 +91,28 @@ PyDoc_STRVAR(_dbm_dbm_setdefault__doc__, "If key is not in the database, it is inserted with default as the value."); #define _DBM_DBM_SETDEFAULT_METHODDEF \ - {"setdefault", (PyCFunction)(void(*)(void))_dbm_dbm_setdefault, METH_FASTCALL, _dbm_dbm_setdefault__doc__}, + {"setdefault", (PyCFunction)(void(*)(void))_dbm_dbm_setdefault, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _dbm_dbm_setdefault__doc__}, static PyObject * -_dbm_dbm_setdefault_impl(dbmobject *self, const char *key, +_dbm_dbm_setdefault_impl(dbmobject *self, PyTypeObject *cls, const char *key, Py_ssize_clean_t key_length, PyObject *default_value); static PyObject * -_dbm_dbm_setdefault(dbmobject *self, PyObject *const *args, Py_ssize_t nargs) +_dbm_dbm_setdefault(dbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + static const char * const _keywords[] = {"", "", NULL}; + static _PyArg_Parser _parser = {"s#|O:setdefault", _keywords, 0}; const char *key; Py_ssize_clean_t key_length; PyObject *default_value = NULL; - if (!_PyArg_ParseStack(args, nargs, "s#|O:setdefault", + if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, &key, &key_length, &default_value)) { goto exit; } - return_value = _dbm_dbm_setdefault_impl(self, key, key_length, default_value); + return_value = _dbm_dbm_setdefault_impl(self, cls, key, key_length, default_value); exit: return return_value; @@ -172,4 +187,4 @@ skip_optional: exit: return return_value; } -/*[clinic end generated code: output=ba4ff07b8c8bbfe4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6947b1115df66f7c input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h index 5934218a52b..2c9ba47823b 100644 --- a/Modules/clinic/_elementtree.c.h +++ b/Modules/clinic/_elementtree.c.h @@ -432,7 +432,7 @@ _elementtree_Element_insert(ElementObject *self, PyObject *const *args, Py_ssize } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -915,4 +915,4 @@ skip_optional: exit: return return_value; } -/*[clinic end generated code: output=c98b210c525a9338 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1385b5e5688f3614 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_gdbmmodule.c.h b/Modules/clinic/_gdbmmodule.c.h index 195159104d9..ffd2179f369 100644 --- a/Modules/clinic/_gdbmmodule.c.h +++ b/Modules/clinic/_gdbmmodule.c.h @@ -12,10 +12,10 @@ PyDoc_STRVAR(_gdbm_gdbm_get__doc__, {"get", (PyCFunction)(void(*)(void))_gdbm_gdbm_get, METH_FASTCALL, _gdbm_gdbm_get__doc__}, static PyObject * -_gdbm_gdbm_get_impl(dbmobject *self, PyObject *key, PyObject *default_value); +_gdbm_gdbm_get_impl(gdbmobject *self, PyObject *key, PyObject *default_value); static PyObject * -_gdbm_gdbm_get(dbmobject *self, PyObject *const *args, Py_ssize_t nargs) +_gdbm_gdbm_get(gdbmobject *self, PyObject *const *args, Py_ssize_t nargs) { PyObject *return_value = NULL; PyObject *key; @@ -46,11 +46,11 @@ PyDoc_STRVAR(_gdbm_gdbm_setdefault__doc__, {"setdefault", (PyCFunction)(void(*)(void))_gdbm_gdbm_setdefault, METH_FASTCALL, _gdbm_gdbm_setdefault__doc__}, static PyObject * -_gdbm_gdbm_setdefault_impl(dbmobject *self, PyObject *key, +_gdbm_gdbm_setdefault_impl(gdbmobject *self, PyObject *key, PyObject *default_value); static PyObject * -_gdbm_gdbm_setdefault(dbmobject *self, PyObject *const *args, Py_ssize_t nargs) +_gdbm_gdbm_setdefault(gdbmobject *self, PyObject *const *args, Py_ssize_t nargs) { PyObject *return_value = NULL; PyObject *key; @@ -81,10 +81,10 @@ PyDoc_STRVAR(_gdbm_gdbm_close__doc__, {"close", (PyCFunction)_gdbm_gdbm_close, METH_NOARGS, _gdbm_gdbm_close__doc__}, static PyObject * -_gdbm_gdbm_close_impl(dbmobject *self); +_gdbm_gdbm_close_impl(gdbmobject *self); static PyObject * -_gdbm_gdbm_close(dbmobject *self, PyObject *Py_UNUSED(ignored)) +_gdbm_gdbm_close(gdbmobject *self, PyObject *Py_UNUSED(ignored)) { return _gdbm_gdbm_close_impl(self); } @@ -96,15 +96,26 @@ PyDoc_STRVAR(_gdbm_gdbm_keys__doc__, "Get a list of all keys in the database."); #define _GDBM_GDBM_KEYS_METHODDEF \ - {"keys", (PyCFunction)_gdbm_gdbm_keys, METH_NOARGS, _gdbm_gdbm_keys__doc__}, + {"keys", (PyCFunction)(void(*)(void))_gdbm_gdbm_keys, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _gdbm_gdbm_keys__doc__}, static PyObject * -_gdbm_gdbm_keys_impl(dbmobject *self); +_gdbm_gdbm_keys_impl(gdbmobject *self, PyTypeObject *cls); static PyObject * -_gdbm_gdbm_keys(dbmobject *self, PyObject *Py_UNUSED(ignored)) +_gdbm_gdbm_keys(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _gdbm_gdbm_keys_impl(self); + PyObject *return_value = NULL; + static const char * const _keywords[] = { NULL}; + static _PyArg_Parser _parser = {":keys", _keywords, 0}; + + if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser + )) { + goto exit; + } + return_value = _gdbm_gdbm_keys_impl(self, cls); + +exit: + return return_value; } PyDoc_STRVAR(_gdbm_gdbm_firstkey__doc__, @@ -118,15 +129,26 @@ PyDoc_STRVAR(_gdbm_gdbm_firstkey__doc__, "hash values, and won\'t be sorted by the key values."); #define _GDBM_GDBM_FIRSTKEY_METHODDEF \ - {"firstkey", (PyCFunction)_gdbm_gdbm_firstkey, METH_NOARGS, _gdbm_gdbm_firstkey__doc__}, + {"firstkey", (PyCFunction)(void(*)(void))_gdbm_gdbm_firstkey, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _gdbm_gdbm_firstkey__doc__}, static PyObject * -_gdbm_gdbm_firstkey_impl(dbmobject *self); +_gdbm_gdbm_firstkey_impl(gdbmobject *self, PyTypeObject *cls); static PyObject * -_gdbm_gdbm_firstkey(dbmobject *self, PyObject *Py_UNUSED(ignored)) +_gdbm_gdbm_firstkey(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _gdbm_gdbm_firstkey_impl(self); + PyObject *return_value = NULL; + static const char * const _keywords[] = { NULL}; + static _PyArg_Parser _parser = {":firstkey", _keywords, 0}; + + if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser + )) { + goto exit; + } + return_value = _gdbm_gdbm_firstkey_impl(self, cls); + +exit: + return return_value; } PyDoc_STRVAR(_gdbm_gdbm_nextkey__doc__, @@ -144,23 +166,26 @@ PyDoc_STRVAR(_gdbm_gdbm_nextkey__doc__, " k = db.nextkey(k)"); #define _GDBM_GDBM_NEXTKEY_METHODDEF \ - {"nextkey", (PyCFunction)_gdbm_gdbm_nextkey, METH_O, _gdbm_gdbm_nextkey__doc__}, + {"nextkey", (PyCFunction)(void(*)(void))_gdbm_gdbm_nextkey, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _gdbm_gdbm_nextkey__doc__}, static PyObject * -_gdbm_gdbm_nextkey_impl(dbmobject *self, const char *key, +_gdbm_gdbm_nextkey_impl(gdbmobject *self, PyTypeObject *cls, const char *key, Py_ssize_clean_t key_length); static PyObject * -_gdbm_gdbm_nextkey(dbmobject *self, PyObject *arg) +_gdbm_gdbm_nextkey(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + static const char * const _keywords[] = {"", NULL}; + static _PyArg_Parser _parser = {"s#:nextkey", _keywords, 0}; const char *key; Py_ssize_clean_t key_length; - if (!PyArg_Parse(arg, "s#:nextkey", &key, &key_length)) { + if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, + &key, &key_length)) { goto exit; } - return_value = _gdbm_gdbm_nextkey_impl(self, key, key_length); + return_value = _gdbm_gdbm_nextkey_impl(self, cls, key, key_length); exit: return return_value; @@ -179,15 +204,26 @@ PyDoc_STRVAR(_gdbm_gdbm_reorganize__doc__, "kept and reused as new (key,value) pairs are added."); #define _GDBM_GDBM_REORGANIZE_METHODDEF \ - {"reorganize", (PyCFunction)_gdbm_gdbm_reorganize, METH_NOARGS, _gdbm_gdbm_reorganize__doc__}, + {"reorganize", (PyCFunction)(void(*)(void))_gdbm_gdbm_reorganize, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _gdbm_gdbm_reorganize__doc__}, static PyObject * -_gdbm_gdbm_reorganize_impl(dbmobject *self); +_gdbm_gdbm_reorganize_impl(gdbmobject *self, PyTypeObject *cls); static PyObject * -_gdbm_gdbm_reorganize(dbmobject *self, PyObject *Py_UNUSED(ignored)) +_gdbm_gdbm_reorganize(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _gdbm_gdbm_reorganize_impl(self); + PyObject *return_value = NULL; + static const char * const _keywords[] = { NULL}; + static _PyArg_Parser _parser = {":reorganize", _keywords, 0}; + + if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser + )) { + goto exit; + } + return_value = _gdbm_gdbm_reorganize_impl(self, cls); + +exit: + return return_value; } PyDoc_STRVAR(_gdbm_gdbm_sync__doc__, @@ -200,15 +236,26 @@ PyDoc_STRVAR(_gdbm_gdbm_sync__doc__, "any unwritten data to be written to the disk."); #define _GDBM_GDBM_SYNC_METHODDEF \ - {"sync", (PyCFunction)_gdbm_gdbm_sync, METH_NOARGS, _gdbm_gdbm_sync__doc__}, + {"sync", (PyCFunction)(void(*)(void))_gdbm_gdbm_sync, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _gdbm_gdbm_sync__doc__}, static PyObject * -_gdbm_gdbm_sync_impl(dbmobject *self); +_gdbm_gdbm_sync_impl(gdbmobject *self, PyTypeObject *cls); static PyObject * -_gdbm_gdbm_sync(dbmobject *self, PyObject *Py_UNUSED(ignored)) +_gdbm_gdbm_sync(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { - return _gdbm_gdbm_sync_impl(self); + PyObject *return_value = NULL; + static const char * const _keywords[] = { NULL}; + static _PyArg_Parser _parser = {":sync", _keywords, 0}; + + if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser + )) { + goto exit; + } + return_value = _gdbm_gdbm_sync_impl(self, cls); + +exit: + return return_value; } PyDoc_STRVAR(dbmopen__doc__, @@ -293,4 +340,4 @@ skip_optional: exit: return return_value; } -/*[clinic end generated code: output=c9d43f42677f4efb input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e84bc6ac82fcb6d4 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h index 619cb1c8516..e72b55885fe 100644 --- a/Modules/clinic/_hashopenssl.c.h +++ b/Modules/clinic/_hashopenssl.c.h @@ -94,7 +94,7 @@ EVPXOF_digest(EVPobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -141,7 +141,7 @@ EVPXOF_hexdigest(EVPobject *self, PyObject *const *args, Py_ssize_t nargs, PyObj } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -1338,6 +1338,46 @@ exit: #endif /* !defined(LIBRESSL_VERSION_NUMBER) */ +PyDoc_STRVAR(_hashlib_compare_digest__doc__, +"compare_digest($module, a, b, /)\n" +"--\n" +"\n" +"Return \'a == b\'.\n" +"\n" +"This function uses an approach designed to prevent\n" +"timing analysis, making it appropriate for cryptography.\n" +"\n" +"a and b must both be of the same type: either str (ASCII only),\n" +"or any bytes-like object.\n" +"\n" +"Note: If a and b are of different lengths, or if an error occurs,\n" +"a timing attack could theoretically reveal information about the\n" +"types and lengths of a and b--but not their values."); + +#define _HASHLIB_COMPARE_DIGEST_METHODDEF \ + {"compare_digest", (PyCFunction)(void(*)(void))_hashlib_compare_digest, METH_FASTCALL, _hashlib_compare_digest__doc__}, + +static PyObject * +_hashlib_compare_digest_impl(PyObject *module, PyObject *a, PyObject *b); + +static PyObject * +_hashlib_compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *a; + PyObject *b; + + if (!_PyArg_CheckPositional("compare_digest", nargs, 2, 2)) { + goto exit; + } + a = args[0]; + b = args[1]; + return_value = _hashlib_compare_digest_impl(module, a, b); + +exit: + return return_value; +} + #ifndef EVPXOF_DIGEST_METHODDEF #define EVPXOF_DIGEST_METHODDEF #endif /* !defined(EVPXOF_DIGEST_METHODDEF) */ @@ -1377,4 +1417,4 @@ exit: #ifndef _HASHLIB_GET_FIPS_MODE_METHODDEF #define _HASHLIB_GET_FIPS_MODE_METHODDEF #endif /* !defined(_HASHLIB_GET_FIPS_MODE_METHODDEF) */ -/*[clinic end generated code: output=d8dddcd85fb11dde input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2bbd6159493f44ea input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_lzmamodule.c.h b/Modules/clinic/_lzmamodule.c.h index 40913ef2954..e15cc0c7e74 100644 --- a/Modules/clinic/_lzmamodule.c.h +++ b/Modules/clinic/_lzmamodule.c.h @@ -65,6 +65,23 @@ _lzma_LZMACompressor_flush(Compressor *self, PyObject *Py_UNUSED(ignored)) return _lzma_LZMACompressor_flush_impl(self); } +PyDoc_STRVAR(_lzma_LZMACompressor___reduce____doc__, +"__reduce__($self, /)\n" +"--\n" +"\n"); + +#define _LZMA_LZMACOMPRESSOR___REDUCE___METHODDEF \ + {"__reduce__", (PyCFunction)_lzma_LZMACompressor___reduce__, METH_NOARGS, _lzma_LZMACompressor___reduce____doc__}, + +static PyObject * +_lzma_LZMACompressor___reduce___impl(Compressor *self); + +static PyObject * +_lzma_LZMACompressor___reduce__(Compressor *self, PyObject *Py_UNUSED(ignored)) +{ + return _lzma_LZMACompressor___reduce___impl(self); +} + PyDoc_STRVAR(_lzma_LZMADecompressor_decompress__doc__, "decompress($self, /, data, max_length=-1)\n" "--\n" @@ -118,7 +135,7 @@ _lzma_LZMADecompressor_decompress(Decompressor *self, PyObject *const *args, Py_ } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -211,6 +228,23 @@ exit: return return_value; } +PyDoc_STRVAR(_lzma_LZMADecompressor___reduce____doc__, +"__reduce__($self, /)\n" +"--\n" +"\n"); + +#define _LZMA_LZMADECOMPRESSOR___REDUCE___METHODDEF \ + {"__reduce__", (PyCFunction)_lzma_LZMADecompressor___reduce__, METH_NOARGS, _lzma_LZMADecompressor___reduce____doc__}, + +static PyObject * +_lzma_LZMADecompressor___reduce___impl(Decompressor *self); + +static PyObject * +_lzma_LZMADecompressor___reduce__(Decompressor *self, PyObject *Py_UNUSED(ignored)) +{ + return _lzma_LZMADecompressor___reduce___impl(self); +} + PyDoc_STRVAR(_lzma_is_check_supported__doc__, "is_check_supported($module, check_id, /)\n" "--\n" @@ -241,39 +275,6 @@ exit: return return_value; } -PyDoc_STRVAR(_lzma__encode_filter_properties__doc__, -"_encode_filter_properties($module, filter, /)\n" -"--\n" -"\n" -"Return a bytes object encoding the options (properties) of the filter specified by *filter* (a dict).\n" -"\n" -"The result does not include the filter ID itself, only the options."); - -#define _LZMA__ENCODE_FILTER_PROPERTIES_METHODDEF \ - {"_encode_filter_properties", (PyCFunction)_lzma__encode_filter_properties, METH_O, _lzma__encode_filter_properties__doc__}, - -static PyObject * -_lzma__encode_filter_properties_impl(PyObject *module, lzma_filter filter); - -static PyObject * -_lzma__encode_filter_properties(PyObject *module, PyObject *arg) -{ - PyObject *return_value = NULL; - lzma_filter filter = {LZMA_VLI_UNKNOWN, NULL}; - - if (!lzma_filter_converter(arg, &filter)) { - goto exit; - } - return_value = _lzma__encode_filter_properties_impl(module, filter); - -exit: - /* Cleanup for filter */ - if (filter.id != LZMA_VLI_UNKNOWN) - PyMem_Free(filter.options); - - return return_value; -} - PyDoc_STRVAR(_lzma__decode_filter_properties__doc__, "_decode_filter_properties($module, filter_id, encoded_props, /)\n" "--\n" @@ -319,4 +320,4 @@ exit: return return_value; } -/*[clinic end generated code: output=a87074ca902bd432 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d89b6159e98544be input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_operator.c.h b/Modules/clinic/_operator.c.h index 2a66f8ff1a5..34b6fdadfb7 100644 --- a/Modules/clinic/_operator.c.h +++ b/Modules/clinic/_operator.c.h @@ -1426,7 +1426,7 @@ _operator_length_hint(PyObject *module, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -1486,4 +1486,4 @@ _operator__compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t na exit: return return_value; } -/*[clinic end generated code: output=1fe4adf4f5761420 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=eae5d08f971a65fd input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_randommodule.c.h b/Modules/clinic/_randommodule.c.h index b3cd435b6f2..3322a370288 100644 --- a/Modules/clinic/_randommodule.c.h +++ b/Modules/clinic/_randommodule.c.h @@ -109,4 +109,21 @@ _random_Random_getrandbits(RandomObject *self, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=cc8a23b2757dc6ba input=a9049054013a1b77]*/ + +PyDoc_STRVAR(_random_Random___reduce____doc__, +"__reduce__($self, /)\n" +"--\n" +"\n"); + +#define _RANDOM_RANDOM___REDUCE___METHODDEF \ + {"__reduce__", (PyCFunction)_random_Random___reduce__, METH_NOARGS, _random_Random___reduce____doc__}, + +static PyObject * +_random_Random___reduce___impl(RandomObject *self); + +static PyObject * +_random_Random___reduce__(RandomObject *self, PyObject *Py_UNUSED(ignored)) +{ + return _random_Random___reduce___impl(self); +} +/*[clinic end generated code: output=450f0961c2c92389 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_sre.c.h b/Modules/clinic/_sre.c.h index fc3ae04792f..2314114a1bc 100644 --- a/Modules/clinic/_sre.c.h +++ b/Modules/clinic/_sre.c.h @@ -193,7 +193,7 @@ _sre_SRE_Pattern_match(PatternObject *self, PyObject *const *args, Py_ssize_t na if (args[1]) { { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -209,7 +209,7 @@ _sre_SRE_Pattern_match(PatternObject *self, PyObject *const *args, Py_ssize_t na } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -262,7 +262,7 @@ _sre_SRE_Pattern_fullmatch(PatternObject *self, PyObject *const *args, Py_ssize_ if (args[1]) { { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -278,7 +278,7 @@ _sre_SRE_Pattern_fullmatch(PatternObject *self, PyObject *const *args, Py_ssize_ } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -333,7 +333,7 @@ _sre_SRE_Pattern_search(PatternObject *self, PyObject *const *args, Py_ssize_t n if (args[1]) { { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -349,7 +349,7 @@ _sre_SRE_Pattern_search(PatternObject *self, PyObject *const *args, Py_ssize_t n } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -402,7 +402,7 @@ _sre_SRE_Pattern_findall(PatternObject *self, PyObject *const *args, Py_ssize_t if (args[1]) { { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -418,7 +418,7 @@ _sre_SRE_Pattern_findall(PatternObject *self, PyObject *const *args, Py_ssize_t } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -473,7 +473,7 @@ _sre_SRE_Pattern_finditer(PatternObject *self, PyObject *const *args, Py_ssize_t if (args[1]) { { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -489,7 +489,7 @@ _sre_SRE_Pattern_finditer(PatternObject *self, PyObject *const *args, Py_ssize_t } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -541,7 +541,7 @@ _sre_SRE_Pattern_scanner(PatternObject *self, PyObject *const *args, Py_ssize_t if (args[1]) { { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -557,7 +557,7 @@ _sre_SRE_Pattern_scanner(PatternObject *self, PyObject *const *args, Py_ssize_t } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -608,7 +608,7 @@ _sre_SRE_Pattern_split(PatternObject *self, PyObject *const *args, Py_ssize_t na } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -661,7 +661,7 @@ _sre_SRE_Pattern_sub(PatternObject *self, PyObject *const *args, Py_ssize_t narg } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -714,7 +714,7 @@ _sre_SRE_Pattern_subn(PatternObject *self, PyObject *const *args, Py_ssize_t nar } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -800,7 +800,7 @@ _sre_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject code = args[2]; { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[3]); + PyObject *iobj = _PyNumber_Index(args[3]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -1102,4 +1102,4 @@ _sre_SRE_Scanner_search(ScannerObject *self, PyObject *Py_UNUSED(ignored)) { return _sre_SRE_Scanner_search_impl(self); } -/*[clinic end generated code: output=7a3360917b40a808 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0e27915b1eb7c0e4 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_struct.c.h b/Modules/clinic/_struct.c.h index 874f30a4450..1cfaef3b713 100644 --- a/Modules/clinic/_struct.c.h +++ b/Modules/clinic/_struct.c.h @@ -126,7 +126,7 @@ Struct_unpack_from(PyStructObject *self, PyObject *const *args, Py_ssize_t nargs } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -312,7 +312,7 @@ unpack_from(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -376,4 +376,4 @@ exit: return return_value; } -/*[clinic end generated code: output=1205daf7f616f0cf input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8089792d8ed0c1be input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_winapi.c.h b/Modules/clinic/_winapi.c.h index e21f2bc2b6f..6022dfe0db4 100644 --- a/Modules/clinic/_winapi.c.h +++ b/Modules/clinic/_winapi.c.h @@ -367,13 +367,22 @@ _winapi_CreateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs) const Py_UNICODE *current_directory; PyObject *startup_info; - if (!_PyArg_ParseStack(args, nargs, "ZOOOikOZO:CreateProcess", - &application_name, &command_line, &proc_attrs, &thread_attrs, &inherit_handles, &creation_flags, &env_mapping, ¤t_directory, &startup_info)) { + if (!_PyArg_ParseStack(args, nargs, "O&OOOikOO&O:CreateProcess", + _PyUnicode_WideCharString_Opt_Converter, &application_name, &command_line, &proc_attrs, &thread_attrs, &inherit_handles, &creation_flags, &env_mapping, _PyUnicode_WideCharString_Opt_Converter, ¤t_directory, &startup_info)) { goto exit; } return_value = _winapi_CreateProcess_impl(module, application_name, command_line, proc_attrs, thread_attrs, inherit_handles, creation_flags, env_mapping, current_directory, startup_info); exit: + /* Cleanup for application_name */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)application_name); + #endif /* USE_UNICODE_WCHAR_CACHE */ + /* Cleanup for current_directory */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)current_directory); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -1097,4 +1106,4 @@ _winapi_GetFileType(PyObject *module, PyObject *const *args, Py_ssize_t nargs, P exit: return return_value; } -/*[clinic end generated code: output=f3897898ea1da99d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=db87076a32fa7abe input=a9049054013a1b77]*/ diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h index 334db39db16..300cd139710 100644 --- a/Modules/clinic/arraymodule.c.h +++ b/Modules/clinic/arraymodule.c.h @@ -84,7 +84,7 @@ array_array_pop(arrayobject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -134,7 +134,7 @@ array_array_insert(arrayobject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -245,7 +245,7 @@ array_array_fromfile(arrayobject *self, PyObject *const *args, Py_ssize_t nargs) f = args[0]; { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -514,4 +514,4 @@ PyDoc_STRVAR(array_arrayiterator___setstate____doc__, #define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \ {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__}, -/*[clinic end generated code: output=c953eb8486c7c8da input=a9049054013a1b77]*/ +/*[clinic end generated code: output=91c1cded65a1285f input=a9049054013a1b77]*/ diff --git a/Modules/clinic/audioop.c.h b/Modules/clinic/audioop.c.h index 56d31d3d721..da12bd17b5a 100644 --- a/Modules/clinic/audioop.c.h +++ b/Modules/clinic/audioop.c.h @@ -39,7 +39,7 @@ audioop_getsample(PyObject *module, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -372,7 +372,7 @@ audioop_findmax(PyObject *module, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -1309,4 +1309,4 @@ exit: return return_value; } -/*[clinic end generated code: output=343e5ae478fc0359 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=840f8c315ebd4946 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/itertoolsmodule.c.h b/Modules/clinic/itertoolsmodule.c.h index c6d6717f89e..c1192bbcb0d 100644 --- a/Modules/clinic/itertoolsmodule.c.h +++ b/Modules/clinic/itertoolsmodule.c.h @@ -172,7 +172,7 @@ itertools_tee(PyObject *module, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -353,7 +353,7 @@ itertools_combinations(PyTypeObject *type, PyObject *args, PyObject *kwargs) iterable = fastargs[0]; { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(fastargs[1]); + PyObject *iobj = _PyNumber_Index(fastargs[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -401,7 +401,7 @@ itertools_combinations_with_replacement(PyTypeObject *type, PyObject *args, PyOb iterable = fastargs[0]; { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(fastargs[1]); + PyObject *iobj = _PyNumber_Index(fastargs[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -627,4 +627,4 @@ skip_optional_pos: exit: return return_value; } -/*[clinic end generated code: output=07211f86c4153050 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d7f58dc477814b45 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 6f180abd254..c15def0a0f2 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -1674,12 +1674,25 @@ os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k { PyObject *return_value = NULL; static const char * const _keywords[] = {"command", NULL}; - static _PyArg_Parser _parser = {"u:system", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "system", 0}; + PyObject *argsbuf[1]; const Py_UNICODE *command; long _return_value; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &command)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("system", "argument 'command'", "str", args[0]); + goto exit; + } + #if USE_UNICODE_WCHAR_CACHE + command = _PyUnicode_AsUnicode(args[0]); + #else /* USE_UNICODE_WCHAR_CACHE */ + command = PyUnicode_AsWideCharString(args[0], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (command == NULL) { goto exit; } _return_value = os_system_impl(module, command); @@ -1689,6 +1702,11 @@ os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k return_value = PyLong_FromLong(_return_value); exit: + /* Cleanup for command */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)command); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -4743,7 +4761,7 @@ os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -4843,7 +4861,7 @@ os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -5112,7 +5130,7 @@ os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[3]); + PyObject *iobj = _PyNumber_Index(args[3]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -5192,7 +5210,7 @@ os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject offobj = args[2]; { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[3]); + PyObject *iobj = _PyNumber_Index(args[3]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -5517,6 +5535,7 @@ PyDoc_STRVAR(os_pwritev__doc__, "\n" "- RWF_DSYNC\n" "- RWF_SYNC\n" +"- RWF_APPEND\n" "\n" "Using non-zero flags requires Linux 4.7 or newer."); @@ -5626,7 +5645,7 @@ os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -6802,8 +6821,7 @@ os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) { goto exit; } - fd = _PyLong_AsInt(args[0]); - if (fd == -1 && PyErr_Occurred()) { + if (!fildes_converter(args[0], &fd)) { goto exit; } if (!conv_path_confname(args[1], &name)) { @@ -6998,19 +7016,44 @@ os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject { PyObject *return_value = NULL; static const char * const _keywords[] = {"filepath", "operation", NULL}; - static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "startfile", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0); const Py_UNICODE *operation = NULL; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - path_converter, &filepath, &operation)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { goto exit; } + if (!path_converter(args[0], &filepath)) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]); + goto exit; + } + #if USE_UNICODE_WCHAR_CACHE + operation = _PyUnicode_AsUnicode(args[1]); + #else /* USE_UNICODE_WCHAR_CACHE */ + operation = PyUnicode_AsWideCharString(args[1], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (operation == NULL) { + goto exit; + } +skip_optional_pos: return_value = os_startfile_impl(module, &filepath, operation); exit: /* Cleanup for filepath */ path_cleanup(&filepath); + /* Cleanup for operation */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)operation); + #endif /* USE_UNICODE_WCHAR_CACHE */ return return_value; } @@ -7511,7 +7554,7 @@ os_urandom(PyObject *module, PyObject *arg) { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(arg); + PyObject *iobj = _PyNumber_Index(arg); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -8159,7 +8202,7 @@ os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -8876,4 +8919,4 @@ exit: #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=b97bbc8cb5078540 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a0fbdea47249ee0c input=a9049054013a1b77]*/ diff --git a/Modules/clinic/selectmodule.c.h b/Modules/clinic/selectmodule.c.h index cd7f3846da6..3a06d6d0ec9 100644 --- a/Modules/clinic/selectmodule.c.h +++ b/Modules/clinic/selectmodule.c.h @@ -65,7 +65,8 @@ exit: #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) PyDoc_STRVAR(select_poll_register__doc__, -"register($self, fd, eventmask=POLLIN | POLLPRI | POLLOUT, /)\n" +"register($self, fd,\n" +" eventmask=select.POLLIN | select.POLLPRI | select.POLLOUT, /)\n" "--\n" "\n" "Register a file descriptor with the polling object.\n" @@ -226,7 +227,8 @@ exit: #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) PyDoc_STRVAR(select_devpoll_register__doc__, -"register($self, fd, eventmask=POLLIN | POLLPRI | POLLOUT, /)\n" +"register($self, fd,\n" +" eventmask=select.POLLIN | select.POLLPRI | select.POLLOUT, /)\n" "--\n" "\n" "Register a file descriptor with the polling object.\n" @@ -275,7 +277,8 @@ exit: #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) PyDoc_STRVAR(select_devpoll_modify__doc__, -"modify($self, fd, eventmask=POLLIN | POLLPRI | POLLOUT, /)\n" +"modify($self, fd,\n" +" eventmask=select.POLLIN | select.POLLPRI | select.POLLOUT, /)\n" "--\n" "\n" "Modify a possible already registered file descriptor.\n" @@ -630,7 +633,8 @@ exit: #if defined(HAVE_EPOLL) PyDoc_STRVAR(select_epoll_register__doc__, -"register($self, /, fd, eventmask=EPOLLIN | EPOLLPRI | EPOLLOUT)\n" +"register($self, /, fd,\n" +" eventmask=select.EPOLLIN | select.EPOLLPRI | select.EPOLLOUT)\n" "--\n" "\n" "Registers a new fd or raises an OSError if the fd is already registered.\n" @@ -1175,4 +1179,4 @@ exit: #ifndef SELECT_KQUEUE_CONTROL_METHODDEF #define SELECT_KQUEUE_CONTROL_METHODDEF #endif /* !defined(SELECT_KQUEUE_CONTROL_METHODDEF) */ -/*[clinic end generated code: output=a055330869acbd16 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7144233c42e18279 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h index 2b72aeb8df5..61dfa9a87b5 100644 --- a/Modules/clinic/zlibmodule.c.h +++ b/Modules/clinic/zlibmodule.c.h @@ -117,7 +117,7 @@ zlib_decompress(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -409,7 +409,7 @@ zlib_Decompress_decompress(compobject *self, PyObject *const *args, Py_ssize_t n } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -611,7 +611,7 @@ zlib_Decompress_flush(compobject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -757,4 +757,4 @@ exit: #ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF #endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */ -/*[clinic end generated code: output=06b6438506aab0cb input=a9049054013a1b77]*/ +/*[clinic end generated code: output=be34f273564e39a8 input=a9049054013a1b77]*/ diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index e7a28503305..67fe1ca9fff 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -1291,59 +1291,55 @@ static PyMethodDef module_methods[] = { {NULL, NULL} /* sentinel */ }; +static int +PyExec_faulthandler(PyObject *module) { + /* Add constants for unit tests */ +#ifdef MS_WINDOWS + /* RaiseException() codes (prefixed by an underscore) */ + if (PyModule_AddIntConstant(module, "_EXCEPTION_ACCESS_VIOLATION", + EXCEPTION_ACCESS_VIOLATION)) { + return -1; + } + if (PyModule_AddIntConstant(module, "_EXCEPTION_INT_DIVIDE_BY_ZERO", + EXCEPTION_INT_DIVIDE_BY_ZERO)) { + return -1; + } + if (PyModule_AddIntConstant(module, "_EXCEPTION_STACK_OVERFLOW", + EXCEPTION_STACK_OVERFLOW)) { + return -1; + } + + /* RaiseException() flags (prefixed by an underscore) */ + if (PyModule_AddIntConstant(module, "_EXCEPTION_NONCONTINUABLE", + EXCEPTION_NONCONTINUABLE)) { + return -1; + } + if (PyModule_AddIntConstant(module, "_EXCEPTION_NONCONTINUABLE_EXCEPTION", + EXCEPTION_NONCONTINUABLE_EXCEPTION)) { + return -1; + } +#endif + return 0; +} + +static PyModuleDef_Slot faulthandler_slots[] = { + {Py_mod_exec, PyExec_faulthandler}, + {0, NULL} +}; + static struct PyModuleDef module_def = { PyModuleDef_HEAD_INIT, - "faulthandler", - module_doc, - 0, /* non-negative size to be able to unload the module */ - module_methods, - NULL, - faulthandler_traverse, - NULL, - NULL + .m_name = "faulthandler", + .m_doc = module_doc, + .m_methods = module_methods, + .m_traverse = faulthandler_traverse, + .m_slots = faulthandler_slots }; PyMODINIT_FUNC PyInit_faulthandler(void) { - PyObject *m = PyModule_Create(&module_def); - if (m == NULL) - return NULL; - - /* Add constants for unit tests */ -#ifdef MS_WINDOWS - /* RaiseException() codes (prefixed by an underscore) */ - if (PyModule_AddIntConstant(m, "_EXCEPTION_ACCESS_VIOLATION", - EXCEPTION_ACCESS_VIOLATION)) { - goto error; - } - if (PyModule_AddIntConstant(m, "_EXCEPTION_INT_DIVIDE_BY_ZERO", - EXCEPTION_INT_DIVIDE_BY_ZERO)) { - goto error; - } - if (PyModule_AddIntConstant(m, "_EXCEPTION_STACK_OVERFLOW", - EXCEPTION_STACK_OVERFLOW)) { - goto error; - } - - /* RaiseException() flags (prefixed by an underscore) */ - if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE", - EXCEPTION_NONCONTINUABLE)) { - goto error; - } - if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE_EXCEPTION", - EXCEPTION_NONCONTINUABLE_EXCEPTION)) { - goto error; - } -#endif - - return m; - -#ifdef MS_WINDOWS -error: - Py_DECREF(m); - return NULL; -#endif + return PyModuleDef_Init(&module_def); } static int diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c index 43f9b22f672..39baea01ec8 100644 --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -662,34 +662,31 @@ all_ins(PyObject* m) return 0; } +static int +fcntl_exec(PyObject *module) +{ + if (all_ins(module) < 0) { + return -1; + } + return 0; +} + +static PyModuleDef_Slot fcntl_slots[] = { + {Py_mod_exec, fcntl_exec}, + {0, NULL} +}; static struct PyModuleDef fcntlmodule = { PyModuleDef_HEAD_INIT, - "fcntl", - module_doc, - -1, - fcntl_methods, - NULL, - NULL, - NULL, - NULL + .m_name = "fcntl", + .m_doc = module_doc, + .m_size = 0, + .m_methods = fcntl_methods, + .m_slots = fcntl_slots, }; PyMODINIT_FUNC PyInit_fcntl(void) { - PyObject *m; - - /* Create the module and add the functions and documentation */ - m = PyModule_Create(&fcntlmodule); - if (m == NULL) - return NULL; - - /* Add some symbolic constants to the module */ - if (all_ins(m) < 0) { - Py_DECREF(m); - return NULL; - } - - return m; + return PyModuleDef_Init(&fcntlmodule); } diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index a44752b1cc4..8833400caba 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -128,6 +128,15 @@ gc_decref(PyGC_Head *g) #define GEN_HEAD(gcstate, n) (&(gcstate)->generations[n].head) + +static GCState * +get_gc_state(void) +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + return &interp->gc; +} + + void _PyGC_InitState(GCState *gcstate) { @@ -1023,15 +1032,15 @@ delete_garbage(PyThreadState *tstate, GCState *gcstate, * Clearing the free lists may give back memory to the OS earlier. */ static void -clear_freelists(void) +clear_freelists(PyThreadState *tstate) { - _PyFrame_ClearFreeList(); - _PyTuple_ClearFreeList(); - _PyFloat_ClearFreeList(); - _PyList_ClearFreeList(); - _PyDict_ClearFreeList(); - _PyAsyncGen_ClearFreeLists(); - _PyContext_ClearFreeList(); + _PyFrame_ClearFreeList(tstate); + _PyTuple_ClearFreeList(tstate); + _PyFloat_ClearFreeList(tstate); + _PyList_ClearFreeList(tstate); + _PyDict_ClearFreeList(tstate); + _PyAsyncGen_ClearFreeLists(tstate); + _PyContext_ClearFreeList(tstate); } // Show stats for objects in each generations @@ -1043,7 +1052,7 @@ show_stats_each_generations(GCState *gcstate) for (int i = 0; i < NUM_GENERATIONS && pos < sizeof(buf); i++) { pos += PyOS_snprintf(buf+pos, sizeof(buf)-pos, - " %"PY_FORMAT_SIZE_T"d", + " %zd", gc_list_size(GEN_HEAD(gcstate, i))); } @@ -1290,8 +1299,7 @@ collect(PyThreadState *tstate, int generation, if (gcstate->debug & DEBUG_STATS) { double d = _PyTime_AsSecondsDouble(_PyTime_GetMonotonicClock() - t1); PySys_WriteStderr( - "gc: done, %" PY_FORMAT_SIZE_T "d unreachable, " - "%" PY_FORMAT_SIZE_T "d uncollectable, %.4fs elapsed\n", + "gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n", n+m, n, d); } @@ -1305,7 +1313,7 @@ collect(PyThreadState *tstate, int generation, /* Clear free list only during the collection of the highest * generation */ if (generation == NUM_GENERATIONS-1) { - clear_freelists(); + clear_freelists(tstate); } if (_PyErr_Occurred(tstate)) { @@ -1466,8 +1474,7 @@ static PyObject * gc_enable_impl(PyObject *module) /*[clinic end generated code: output=45a427e9dce9155c input=81ac4940ca579707]*/ { - PyThreadState *tstate = _PyThreadState_GET(); - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); gcstate->enabled = 1; Py_RETURN_NONE; } @@ -1482,8 +1489,7 @@ static PyObject * gc_disable_impl(PyObject *module) /*[clinic end generated code: output=97d1030f7aa9d279 input=8c2e5a14e800d83b]*/ { - PyThreadState *tstate = _PyThreadState_GET(); - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); gcstate->enabled = 0; Py_RETURN_NONE; } @@ -1498,8 +1504,7 @@ static int gc_isenabled_impl(PyObject *module) /*[clinic end generated code: output=1874298331c49130 input=30005e0422373b31]*/ { - PyThreadState *tstate = _PyThreadState_GET(); - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); return gcstate->enabled; } @@ -1564,8 +1569,7 @@ static PyObject * gc_set_debug_impl(PyObject *module, int flags) /*[clinic end generated code: output=7c8366575486b228 input=5e5ce15e84fbed15]*/ { - PyThreadState *tstate = _PyThreadState_GET(); - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); gcstate->debug = flags; Py_RETURN_NONE; } @@ -1580,8 +1584,7 @@ static int gc_get_debug_impl(PyObject *module) /*[clinic end generated code: output=91242f3506cd1e50 input=91a101e1c3b98366]*/ { - PyThreadState *tstate = _PyThreadState_GET(); - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); return gcstate->debug; } @@ -1594,8 +1597,7 @@ PyDoc_STRVAR(gc_set_thresh__doc__, static PyObject * gc_set_threshold(PyObject *self, PyObject *args) { - PyThreadState *tstate = _PyThreadState_GET(); - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); if (!PyArg_ParseTuple(args, "i|ii:set_threshold", &gcstate->generations[0].threshold, &gcstate->generations[1].threshold, @@ -1618,8 +1620,7 @@ static PyObject * gc_get_threshold_impl(PyObject *module) /*[clinic end generated code: output=7902bc9f41ecbbd8 input=286d79918034d6e6]*/ { - PyThreadState *tstate = _PyThreadState_GET(); - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); return Py_BuildValue("(iii)", gcstate->generations[0].threshold, gcstate->generations[1].threshold, @@ -1636,8 +1637,7 @@ static PyObject * gc_get_count_impl(PyObject *module) /*[clinic end generated code: output=354012e67b16398f input=a392794a08251751]*/ { - PyThreadState *tstate = _PyThreadState_GET(); - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); return Py_BuildValue("(iii)", gcstate->generations[0].count, gcstate->generations[1].count, @@ -1680,15 +1680,13 @@ Return the list of objects that directly refer to any of objs."); static PyObject * gc_get_referrers(PyObject *self, PyObject *args) { - PyThreadState *tstate = _PyThreadState_GET(); - int i; PyObject *result = PyList_New(0); if (!result) { return NULL; } - GCState *gcstate = &tstate->interp->gc; - for (i = 0; i < NUM_GENERATIONS; i++) { + GCState *gcstate = get_gc_state(); + for (int i = 0; i < NUM_GENERATIONS; i++) { if (!(gc_referrers_for(args, GEN_HEAD(gcstate, i), result))) { Py_DECREF(result); return NULL; @@ -1807,11 +1805,10 @@ gc_get_stats_impl(PyObject *module) { int i; struct gc_generation_stats stats[NUM_GENERATIONS], *st; - PyThreadState *tstate = _PyThreadState_GET(); /* To get consistent values despite allocations while constructing the result list, we use a snapshot of the running stats. */ - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); for (i = 0; i < NUM_GENERATIONS; i++) { stats[i] = gcstate->generation_stats[i]; } @@ -1902,8 +1899,7 @@ static PyObject * gc_freeze_impl(PyObject *module) /*[clinic end generated code: output=502159d9cdc4c139 input=b602b16ac5febbe5]*/ { - PyThreadState *tstate = _PyThreadState_GET(); - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); for (int i = 0; i < NUM_GENERATIONS; ++i) { gc_list_merge(GEN_HEAD(gcstate, i), &gcstate->permanent_generation.head); gcstate->generations[i].count = 0; @@ -1923,8 +1919,7 @@ static PyObject * gc_unfreeze_impl(PyObject *module) /*[clinic end generated code: output=1c15f2043b25e169 input=2dd52b170f4cef6c]*/ { - PyThreadState *tstate = _PyThreadState_GET(); - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); gc_list_merge(&gcstate->permanent_generation.head, GEN_HEAD(gcstate, NUM_GENERATIONS-1)); Py_RETURN_NONE; @@ -1940,8 +1935,7 @@ static Py_ssize_t gc_get_freeze_count_impl(PyObject *module) /*[clinic end generated code: output=61cbd9f43aa032e1 input=45ffbc65cfe2a6ed]*/ { - PyThreadState *tstate = _PyThreadState_GET(); - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); return gc_list_size(&gcstate->permanent_generation.head); } @@ -2007,8 +2001,7 @@ static struct PyModuleDef gcmodule = { PyMODINIT_FUNC PyInit_gc(void) { - PyThreadState *tstate = _PyThreadState_GET(); - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); PyObject *m = PyModule_Create(&gcmodule); @@ -2270,8 +2263,10 @@ PyObject * _PyObject_GC_New(PyTypeObject *tp) { PyObject *op = _PyObject_GC_Malloc(_PyObject_SIZE(tp)); - if (op != NULL) - op = PyObject_INIT(op, tp); + if (op == NULL) { + return NULL; + } + _PyObject_Init(op, tp); return op; } @@ -2287,8 +2282,10 @@ _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems) } size = _PyObject_VAR_SIZE(tp, nitems); op = (PyVarObject *) _PyObject_GC_Malloc(size); - if (op != NULL) - op = PyObject_INIT_VAR(op, tp, nitems); + if (op == NULL) { + return NULL; + } + _PyObject_InitVar(op, tp, nitems); return op; } @@ -2317,8 +2314,7 @@ PyObject_GC_Del(void *op) if (_PyObject_GC_IS_TRACKED(op)) { gc_list_remove(g); } - PyThreadState *tstate = _PyThreadState_GET(); - GCState *gcstate = &tstate->interp->gc; + GCState *gcstate = get_gc_state(); if (gcstate->generations[0].count > 0) { gcstate->generations[0].count--; } diff --git a/Modules/getpath.c b/Modules/getpath.c index d9829f8ad3d..f7a6dd40443 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -105,8 +105,8 @@ extern "C" { #if (!defined(PREFIX) || !defined(EXEC_PREFIX) \ - || !defined(VERSION) || !defined(VPATH) || !defined(PLATLIBDIR)) -#error "PREFIX, EXEC_PREFIX, VERSION, VPATH and PLATLIBDIR macros must be defined" + || !defined(VERSION) || !defined(VPATH)) +#error "PREFIX, EXEC_PREFIX, VERSION and VPATH macros must be defined" #endif #ifndef LANDMARK @@ -128,16 +128,16 @@ typedef struct { wchar_t *pythonpath_macro; /* PYTHONPATH macro */ wchar_t *prefix_macro; /* PREFIX macro */ wchar_t *exec_prefix_macro; /* EXEC_PREFIX macro */ - wchar_t *platlibdir_macro; /* PLATLIBDIR macro */ wchar_t *vpath_macro; /* VPATH macro */ - wchar_t *lib_python; /* "lib/pythonX.Y" */ + wchar_t *lib_python; /* / "pythonX.Y" */ int prefix_found; /* found platform independent libraries? */ int exec_prefix_found; /* found the platform dependent libraries? */ int warnings; const wchar_t *pythonpath_env; + const wchar_t *platlibdir; wchar_t *argv0_path; wchar_t *zip_path; @@ -810,8 +810,8 @@ calculate_exec_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig) "Could not find platform dependent libraries \n"); } - /* / "lib-dynload" */ - wchar_t *lib_dynload = joinpath2(calculate->platlibdir_macro, + /* / "lib-dynload" */ + wchar_t *lib_dynload = joinpath2(calculate->platlibdir, L"lib-dynload"); if (lib_dynload == NULL) { return _PyStatus_NO_MEMORY(); @@ -1296,8 +1296,10 @@ calculate_zip_path(PyCalculatePath *calculate) { PyStatus res; - /* Path: / "pythonXY.zip" */ - wchar_t *path = joinpath2(calculate->platlibdir_macro, L"python" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION) L".zip"); + /* Path: / "pythonXY.zip" */ + wchar_t *path = joinpath2(calculate->platlibdir, + L"python" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION) + L".zip"); if (path == NULL) { return _PyStatus_NO_MEMORY(); } @@ -1305,7 +1307,7 @@ calculate_zip_path(PyCalculatePath *calculate) if (calculate->prefix_found > 0) { /* Use the reduced prefix returned by Py_GetPrefix() - Path: / / "pythonXY.zip" */ + Path: / / "pythonXY.zip" */ wchar_t *parent = _PyMem_RawWcsdup(calculate->prefix); if (parent == NULL) { res = _PyStatus_NO_MEMORY(); @@ -1426,6 +1428,11 @@ static PyStatus calculate_init(PyCalculatePath *calculate, const PyConfig *config) { size_t len; + + calculate->warnings = config->pathconfig_warnings; + calculate->pythonpath_env = config->pythonpath_env; + calculate->platlibdir = config->platlibdir; + const char *path = getenv("PATH"); if (path) { calculate->path_env = Py_DecodeLocale(path, &len); @@ -1451,18 +1458,17 @@ calculate_init(PyCalculatePath *calculate, const PyConfig *config) if (!calculate->vpath_macro) { return DECODE_LOCALE_ERR("VPATH macro", len); } - calculate->platlibdir_macro = Py_DecodeLocale(PLATLIBDIR, &len); - if (!calculate->platlibdir_macro) { - return DECODE_LOCALE_ERR("PLATLIBDIR macro", len); - } - calculate->lib_python = Py_DecodeLocale(PLATLIBDIR "/python" VERSION, &len); - if (!calculate->lib_python) { + // / "pythonX.Y" + wchar_t *pyversion = Py_DecodeLocale("python" VERSION, &len); + if (!pyversion) { return DECODE_LOCALE_ERR("VERSION macro", len); } - - calculate->warnings = config->pathconfig_warnings; - calculate->pythonpath_env = config->pythonpath_env; + calculate->lib_python = joinpath2(config->platlibdir, pyversion); + PyMem_RawFree(pyversion); + if (calculate->lib_python == NULL) { + return _PyStatus_NO_MEMORY(); + } return _PyStatus_OK(); } @@ -1475,7 +1481,6 @@ calculate_free(PyCalculatePath *calculate) PyMem_RawFree(calculate->prefix_macro); PyMem_RawFree(calculate->exec_prefix_macro); PyMem_RawFree(calculate->vpath_macro); - PyMem_RawFree(calculate->platlibdir_macro); PyMem_RawFree(calculate->lib_python); PyMem_RawFree(calculate->path_env); PyMem_RawFree(calculate->zip_path); diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 18fcebdf25b..3809dc3843c 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -1,7 +1,7 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" -#include "pycore_tupleobject.h" +#include "pycore_tuple.h" // _PyTuple_ITEMS() #include // offsetof() /* Itertools module written and maintained @@ -999,8 +999,7 @@ cycle_dealloc(cycleobject *lz) static int cycle_traverse(cycleobject *lz, visitproc visit, void *arg) { - if (lz->it) - Py_VISIT(lz->it); + Py_VISIT(lz->it); Py_VISIT(lz->saved); return 0; } diff --git a/Modules/main.c b/Modules/main.c index bc3a2ed8ed8..4a76f4461bf 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -375,29 +375,70 @@ pymain_run_file(const PyConfig *config, PyCompilerFlags *cf) static int pymain_run_startup(PyConfig *config, PyCompilerFlags *cf, int *exitcode) { + int ret; + PyObject *startup_obj = NULL; + if (!config->use_environment) { + return 0; + } +#ifdef MS_WINDOWS + const wchar_t *wstartup = _wgetenv(L"PYTHONSTARTUP"); + if (wstartup == NULL || wstartup[0] == L'\0') { + return 0; + } + PyObject *startup_bytes = NULL; + startup_obj = PyUnicode_FromWideChar(wstartup, wcslen(wstartup)); + if (startup_obj == NULL) { + goto error; + } + startup_bytes = PyUnicode_EncodeFSDefault(startup_obj); + if (startup_bytes == NULL) { + goto error; + } + const char *startup = PyBytes_AS_STRING(startup_bytes); +#else const char *startup = _Py_GetEnv(config->use_environment, "PYTHONSTARTUP"); if (startup == NULL) { return 0; } - if (PySys_Audit("cpython.run_startup", "s", startup) < 0) { - return pymain_err_print(exitcode); + startup_obj = PyUnicode_DecodeFSDefault(startup); + if (startup_obj == NULL) { + goto error; + } +#endif + if (PySys_Audit("cpython.run_startup", "O", startup_obj) < 0) { + goto error; } +#ifdef MS_WINDOWS + FILE *fp = _Py_wfopen(wstartup, L"r"); +#else FILE *fp = _Py_fopen(startup, "r"); +#endif if (fp == NULL) { int save_errno = errno; + PyErr_Clear(); PySys_WriteStderr("Could not open PYTHONSTARTUP\n"); errno = save_errno; - PyErr_SetFromErrnoWithFilename(PyExc_OSError, startup); - - return pymain_err_print(exitcode); + PyErr_SetFromErrnoWithFilenameObjects(PyExc_OSError, startup_obj, NULL); + goto error; } (void) PyRun_SimpleFileExFlags(fp, startup, 0, cf); PyErr_Clear(); fclose(fp); - return 0; + ret = 0; + +done: +#ifdef MS_WINDOWS + Py_XDECREF(startup_bytes); +#endif + Py_XDECREF(startup_obj); + return ret; + +error: + ret = pymain_err_print(exitcode); + goto done; } diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 5b96631d633..411c6eb1935 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -53,6 +53,7 @@ raised for division by zero and mod by zero. */ #include "Python.h" +#include "pycore_bitutils.h" // _Py_bit_length() #include "pycore_dtoa.h" #include "_math.h" @@ -844,7 +845,7 @@ math_gcd(PyObject *module, PyObject * const *args, Py_ssize_t nargs) return res; } for (i = 1; i < nargs; i++) { - x = PyNumber_Index(args[i]); + x = _PyNumber_Index(args[i]); if (x == NULL) { Py_DECREF(res); return NULL; @@ -1255,9 +1256,15 @@ static PyObject * math_floor(PyObject *module, PyObject *number) /*[clinic end generated code: output=c6a65c4884884b8a input=63af6b5d7ebcc3d6]*/ { + double x; + _Py_IDENTIFIER(__floor__); - if (!PyFloat_CheckExact(number)) { + if (PyFloat_CheckExact(number)) { + x = PyFloat_AS_DOUBLE(number); + } + else + { PyObject *method = _PyObject_LookupSpecial(number, &PyId___floor__); if (method != NULL) { PyObject *result = _PyObject_CallNoArg(method); @@ -1266,11 +1273,10 @@ math_floor(PyObject *module, PyObject *number) } if (PyErr_Occurred()) return NULL; + x = PyFloat_AsDouble(number); + if (x == -1.0 && PyErr_Occurred()) + return NULL; } - double x = PyFloat_AsDouble(number); - if (x == -1.0 && PyErr_Occurred()) - return NULL; - return PyLong_FromDouble(floor(x)); } @@ -1723,7 +1729,7 @@ math_isqrt(PyObject *module, PyObject *n) uint64_t m, u; PyObject *a = NULL, *b; - n = PyNumber_Index(n); + n = _PyNumber_Index(n); if (n == NULL) { return NULL; } @@ -3103,24 +3109,11 @@ math_perm_impl(PyObject *module, PyObject *n, PyObject *k) if (n == NULL) { return NULL; } - if (!PyLong_CheckExact(n)) { - Py_SETREF(n, _PyLong_Copy((PyLongObject *)n)); - if (n == NULL) { - return NULL; - } - } k = PyNumber_Index(k); if (k == NULL) { Py_DECREF(n); return NULL; } - if (!PyLong_CheckExact(k)) { - Py_SETREF(k, _PyLong_Copy((PyLongObject *)k)); - if (k == NULL) { - Py_DECREF(n); - return NULL; - } - } if (Py_SIZE(n) < 0) { PyErr_SetString(PyExc_ValueError, @@ -3226,24 +3219,11 @@ math_comb_impl(PyObject *module, PyObject *n, PyObject *k) if (n == NULL) { return NULL; } - if (!PyLong_CheckExact(n)) { - Py_SETREF(n, _PyLong_Copy((PyLongObject *)n)); - if (n == NULL) { - return NULL; - } - } k = PyNumber_Index(k); if (k == NULL) { Py_DECREF(n); return NULL; } - if (!PyLong_CheckExact(k)) { - Py_SETREF(k, _PyLong_Copy((PyLongObject *)k)); - if (k == NULL) { - Py_DECREF(n); - return NULL; - } - } if (Py_SIZE(n) < 0) { PyErr_SetString(PyExc_ValueError, diff --git a/Modules/md5module.c b/Modules/md5module.c index ea2bafb9b65..e4d9db40f22 100644 --- a/Modules/md5module.c +++ b/Modules/md5module.c @@ -552,9 +552,6 @@ static struct PyMethodDef MD5_functions[] = { /* Initialize this module. */ -#define insint(n,v) { PyModule_AddIntConstant(m,n,v); } - - static struct PyModuleDef _md5module = { PyModuleDef_HEAD_INIT, "_md5", diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index a3e22d0a511..463bd40e78f 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -1509,154 +1509,163 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) } #endif /* MS_WINDOWS */ -static void -setint(PyObject *d, const char *name, long value) +static int +mmap_exec(PyObject *module) { - PyObject *o = PyLong_FromLong(value); - if (o) { - PyDict_SetItemString(d, name, o); - Py_DECREF(o); + if (PyType_Ready(&mmap_object_type) < 0) { + return -1; } + + Py_INCREF(PyExc_OSError); + if (PyModule_AddObject(module, "error", PyExc_OSError) < 0) { + Py_DECREF(PyExc_OSError); + return -1; + } + if (PyModule_AddType(module, &mmap_object_type) < 0) { + return -1; + } + +#define ADD_INT_MACRO(module, constant) \ + do { \ + if (PyModule_AddIntConstant(module, #constant, constant) < 0) { \ + return -1; \ + } \ + } while (0) + +#ifdef PROT_EXEC + ADD_INT_MACRO(module, PROT_EXEC); +#endif +#ifdef PROT_READ + ADD_INT_MACRO(module, PROT_READ); +#endif +#ifdef PROT_WRITE + ADD_INT_MACRO(module, PROT_WRITE); +#endif + +#ifdef MAP_SHARED + ADD_INT_MACRO(module, MAP_SHARED); +#endif +#ifdef MAP_PRIVATE + ADD_INT_MACRO(module, MAP_PRIVATE); +#endif +#ifdef MAP_DENYWRITE + ADD_INT_MACRO(module, MAP_DENYWRITE); +#endif +#ifdef MAP_EXECUTABLE + ADD_INT_MACRO(module, MAP_EXECUTABLE); +#endif +#ifdef MAP_ANONYMOUS + if (PyModule_AddIntConstant(module, "MAP_ANON", MAP_ANONYMOUS) < 0 ) { + return -1; + } + ADD_INT_MACRO(module, MAP_ANONYMOUS); +#endif +#ifdef MAP_POPULATE + ADD_INT_MACRO(module, MAP_POPULATE); +#endif + if (PyModule_AddIntConstant(module, "PAGESIZE", (long)my_getpagesize()) < 0 ) { + return -1; + } + + if (PyModule_AddIntConstant(module, "ALLOCATIONGRANULARITY", (long)my_getallocationgranularity()) < 0 ) { + return -1; + } + + ADD_INT_MACRO(module, ACCESS_DEFAULT); + ADD_INT_MACRO(module, ACCESS_READ); + ADD_INT_MACRO(module, ACCESS_WRITE); + ADD_INT_MACRO(module, ACCESS_COPY); + +#ifdef HAVE_MADVISE + // Conventional advice values +#ifdef MADV_NORMAL + ADD_INT_MACRO(module, MADV_NORMAL); +#endif +#ifdef MADV_RANDOM + ADD_INT_MACRO(module, MADV_RANDOM); +#endif +#ifdef MADV_SEQUENTIAL + ADD_INT_MACRO(module, MADV_SEQUENTIAL); +#endif +#ifdef MADV_WILLNEED + ADD_INT_MACRO(module, MADV_WILLNEED); +#endif +#ifdef MADV_DONTNEED + ADD_INT_MACRO(module, MADV_DONTNEED); +#endif + + // Linux-specific advice values +#ifdef MADV_REMOVE + ADD_INT_MACRO(module, MADV_REMOVE); +#endif +#ifdef MADV_DONTFORK + ADD_INT_MACRO(module, MADV_DONTFORK); +#endif +#ifdef MADV_DOFORK + ADD_INT_MACRO(module, MADV_DOFORK); +#endif +#ifdef MADV_HWPOISON + ADD_INT_MACRO(module, MADV_HWPOISON); +#endif +#ifdef MADV_MERGEABLE + ADD_INT_MACRO(module, MADV_MERGEABLE); +#endif +#ifdef MADV_UNMERGEABLE + ADD_INT_MACRO(module, MADV_UNMERGEABLE); +#endif +#ifdef MADV_SOFT_OFFLINE + ADD_INT_MACRO(module, MADV_SOFT_OFFLINE); +#endif +#ifdef MADV_HUGEPAGE + ADD_INT_MACRO(module, MADV_HUGEPAGE); +#endif +#ifdef MADV_NOHUGEPAGE + ADD_INT_MACRO(module, MADV_NOHUGEPAGE); +#endif +#ifdef MADV_DONTDUMP + ADD_INT_MACRO(module, MADV_DONTDUMP); +#endif +#ifdef MADV_DODUMP + ADD_INT_MACRO(module, MADV_DODUMP); +#endif +#ifdef MADV_FREE // (Also present on FreeBSD and macOS.) + ADD_INT_MACRO(module, MADV_FREE); +#endif + + // FreeBSD-specific +#ifdef MADV_NOSYNC + ADD_INT_MACRO(module, MADV_NOSYNC); +#endif +#ifdef MADV_AUTOSYNC + ADD_INT_MACRO(module, MADV_AUTOSYNC); +#endif +#ifdef MADV_NOCORE + ADD_INT_MACRO(module, MADV_NOCORE); +#endif +#ifdef MADV_CORE + ADD_INT_MACRO(module, MADV_CORE); +#endif +#ifdef MADV_PROTECT + ADD_INT_MACRO(module, MADV_PROTECT); +#endif +#endif // HAVE_MADVISE + return 0; } +static PyModuleDef_Slot mmap_slots[] = { + {Py_mod_exec, mmap_exec}, + {0, NULL} +}; static struct PyModuleDef mmapmodule = { PyModuleDef_HEAD_INIT, - "mmap", - NULL, - -1, - NULL, - NULL, - NULL, - NULL, - NULL + .m_name = "mmap", + .m_size = 0, + .m_slots = mmap_slots, }; PyMODINIT_FUNC PyInit_mmap(void) { - PyObject *dict, *module; - - if (PyType_Ready(&mmap_object_type) < 0) - return NULL; - - module = PyModule_Create(&mmapmodule); - if (module == NULL) - return NULL; - dict = PyModule_GetDict(module); - if (!dict) - return NULL; - PyDict_SetItemString(dict, "error", PyExc_OSError); - PyDict_SetItemString(dict, "mmap", (PyObject*) &mmap_object_type); -#ifdef PROT_EXEC - setint(dict, "PROT_EXEC", PROT_EXEC); -#endif -#ifdef PROT_READ - setint(dict, "PROT_READ", PROT_READ); -#endif -#ifdef PROT_WRITE - setint(dict, "PROT_WRITE", PROT_WRITE); -#endif - -#ifdef MAP_SHARED - setint(dict, "MAP_SHARED", MAP_SHARED); -#endif -#ifdef MAP_PRIVATE - setint(dict, "MAP_PRIVATE", MAP_PRIVATE); -#endif -#ifdef MAP_DENYWRITE - setint(dict, "MAP_DENYWRITE", MAP_DENYWRITE); -#endif -#ifdef MAP_EXECUTABLE - setint(dict, "MAP_EXECUTABLE", MAP_EXECUTABLE); -#endif -#ifdef MAP_ANONYMOUS - setint(dict, "MAP_ANON", MAP_ANONYMOUS); - setint(dict, "MAP_ANONYMOUS", MAP_ANONYMOUS); -#endif - - setint(dict, "PAGESIZE", (long)my_getpagesize()); - - setint(dict, "ALLOCATIONGRANULARITY", (long)my_getallocationgranularity()); - - setint(dict, "ACCESS_DEFAULT", ACCESS_DEFAULT); - setint(dict, "ACCESS_READ", ACCESS_READ); - setint(dict, "ACCESS_WRITE", ACCESS_WRITE); - setint(dict, "ACCESS_COPY", ACCESS_COPY); - -#ifdef HAVE_MADVISE - // Conventional advice values -#ifdef MADV_NORMAL - setint(dict, "MADV_NORMAL", MADV_NORMAL); -#endif -#ifdef MADV_RANDOM - setint(dict, "MADV_RANDOM", MADV_RANDOM); -#endif -#ifdef MADV_SEQUENTIAL - setint(dict, "MADV_SEQUENTIAL", MADV_SEQUENTIAL); -#endif -#ifdef MADV_WILLNEED - setint(dict, "MADV_WILLNEED", MADV_WILLNEED); -#endif -#ifdef MADV_DONTNEED - setint(dict, "MADV_DONTNEED", MADV_DONTNEED); -#endif - - // Linux-specific advice values -#ifdef MADV_REMOVE - setint(dict, "MADV_REMOVE", MADV_REMOVE); -#endif -#ifdef MADV_DONTFORK - setint(dict, "MADV_DONTFORK", MADV_DONTFORK); -#endif -#ifdef MADV_DOFORK - setint(dict, "MADV_DOFORK", MADV_DOFORK); -#endif -#ifdef MADV_HWPOISON - setint(dict, "MADV_HWPOISON", MADV_HWPOISON); -#endif -#ifdef MADV_MERGEABLE - setint(dict, "MADV_MERGEABLE", MADV_MERGEABLE); -#endif -#ifdef MADV_UNMERGEABLE - setint(dict, "MADV_UNMERGEABLE", MADV_UNMERGEABLE); -#endif -#ifdef MADV_SOFT_OFFLINE - setint(dict, "MADV_SOFT_OFFLINE", MADV_SOFT_OFFLINE); -#endif -#ifdef MADV_HUGEPAGE - setint(dict, "MADV_HUGEPAGE", MADV_HUGEPAGE); -#endif -#ifdef MADV_NOHUGEPAGE - setint(dict, "MADV_NOHUGEPAGE", MADV_NOHUGEPAGE); -#endif -#ifdef MADV_DONTDUMP - setint(dict, "MADV_DONTDUMP", MADV_DONTDUMP); -#endif -#ifdef MADV_DODUMP - setint(dict, "MADV_DODUMP", MADV_DODUMP); -#endif -#ifdef MADV_FREE // (Also present on FreeBSD and macOS.) - setint(dict, "MADV_FREE", MADV_FREE); -#endif - - // FreeBSD-specific -#ifdef MADV_NOSYNC - setint(dict, "MADV_NOSYNC", MADV_NOSYNC); -#endif -#ifdef MADV_AUTOSYNC - setint(dict, "MADV_AUTOSYNC", MADV_AUTOSYNC); -#endif -#ifdef MADV_NOCORE - setint(dict, "MADV_NOCORE", MADV_NOCORE); -#endif -#ifdef MADV_CORE - setint(dict, "MADV_CORE", MADV_CORE); -#endif -#ifdef MADV_PROTECT - setint(dict, "MADV_PROTECT", MADV_PROTECT); -#endif -#endif // HAVE_MADVISE - - return module; + return PyModuleDef_Init(&mmapmodule); } diff --git a/Modules/nismodule.c b/Modules/nismodule.c index a24978e0686..6655451ebd2 100644 --- a/Modules/nismodule.c +++ b/Modules/nismodule.c @@ -44,12 +44,42 @@ PyDoc_STRVAR(maps__doc__, Returns an array of all available NIS maps within a domain. If domain\n\ is not specified it defaults to the system default domain.\n"); -static PyObject *NisError; +typedef struct { + PyObject *nis_error; +} nis_state; + +static inline nis_state* +get_nis_state(PyObject *module) +{ + void *state = PyModule_GetState(module); + assert(state != NULL); + return (nis_state *)state; +} + +static int +nis_clear(PyObject *m) +{ + Py_CLEAR(get_nis_state(m)->nis_error); + return 0; +} + +static int +nis_traverse(PyObject *m, visitproc visit, void *arg) +{ + Py_VISIT(get_nis_state(m)->nis_error); + return 0; +} + +static void +nis_free(void *m) +{ + nis_clear((PyObject *) m); +} static PyObject * -nis_error (int err) +nis_error(nis_state *state, int err) { - PyErr_SetString(NisError, yperr_string(err)); + PyErr_SetString(state->nis_error, yperr_string(err)); return NULL; } @@ -70,7 +100,7 @@ static struct nis_map { }; static char * -nis_mapname (char *map, int *pfix) +nis_mapname(char *map, int *pfix) { int i; @@ -98,7 +128,7 @@ struct ypcallback_data { }; static int -nis_foreach (int instatus, char *inkey, int inkeylen, char *inval, +nis_foreach(int instatus, char *inkey, int inkeylen, char *inval, int invallen, struct ypcallback_data *indata) { if (instatus == YP_TRUE) { @@ -137,21 +167,22 @@ nis_foreach (int instatus, char *inkey, int inkeylen, char *inval, } static PyObject * -nis_get_default_domain (PyObject *self, PyObject *Py_UNUSED(ignored)) +nis_get_default_domain(PyObject *module, PyObject *Py_UNUSED(ignored)) { char *domain; int err; PyObject *res; - - if ((err = yp_get_default_domain(&domain)) != 0) - return nis_error(err); + nis_state *state = get_nis_state(module); + if ((err = yp_get_default_domain(&domain)) != 0) { + return nis_error(state, err); + } res = PyUnicode_FromStringAndSize (domain, strlen(domain)); return res; } static PyObject * -nis_match (PyObject *self, PyObject *args, PyObject *kwdict) +nis_match(PyObject *module, PyObject *args, PyObject *kwdict) { char *match; char *domain = NULL; @@ -165,18 +196,22 @@ nis_match (PyObject *self, PyObject *args, PyObject *kwdict) if (!PyArg_ParseTupleAndKeywords(args, kwdict, "Us|s:match", kwlist, - &ukey, &map, &domain)) + &ukey, &map, &domain)) { return NULL; - if ((bkey = PyUnicode_EncodeFSDefault(ukey)) == NULL) + } + if ((bkey = PyUnicode_EncodeFSDefault(ukey)) == NULL) { return NULL; + } /* check for embedded null bytes */ if (PyBytes_AsStringAndSize(bkey, &key, &keylen) == -1) { Py_DECREF(bkey); return NULL; } + + nis_state *state = get_nis_state(module); if (!domain && ((err = yp_get_default_domain(&domain)) != 0)) { Py_DECREF(bkey); - return nis_error(err); + return nis_error(state, err); } map = nis_mapname (map, &fix); if (fix) @@ -187,15 +222,16 @@ nis_match (PyObject *self, PyObject *args, PyObject *kwdict) Py_DECREF(bkey); if (fix) len--; - if (err != 0) - return nis_error(err); + if (err != 0) { + return nis_error(state, err); + } res = PyUnicode_DecodeFSDefaultAndSize(match, len); free (match); return res; } static PyObject * -nis_cat (PyObject *self, PyObject *args, PyObject *kwdict) +nis_cat(PyObject *module, PyObject *args, PyObject *kwdict) { char *domain = NULL; char *map; @@ -206,10 +242,13 @@ nis_cat (PyObject *self, PyObject *args, PyObject *kwdict) static char *kwlist[] = {"map", "domain", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwdict, "s|s:cat", - kwlist, &map, &domain)) + kwlist, &map, &domain)) { return NULL; - if (!domain && ((err = yp_get_default_domain(&domain)) != 0)) - return nis_error(err); + } + nis_state *state = get_nis_state(module); + if (!domain && ((err = yp_get_default_domain(&domain)) != 0)) { + return nis_error(state, err); + } dict = PyDict_New (); if (dict == NULL) return NULL; @@ -222,7 +261,7 @@ nis_cat (PyObject *self, PyObject *args, PyObject *kwdict) PyEval_RestoreThread(data.state); if (err != 0) { Py_DECREF(dict); - return nis_error(err); + return nis_error(state, err); } return dict; } @@ -352,7 +391,7 @@ nisproc_maplist_2(domainname *argp, CLIENT *clnt) static nismaplist * -nis_maplist (char *dom) +nis_maplist(nis_state *state, char *dom) { nisresp_maplist *list; CLIENT *cl; @@ -364,12 +403,12 @@ nis_maplist (char *dom) mapi++; } if (!server) { - PyErr_SetString(NisError, "No NIS master found for any map"); + PyErr_SetString(state->nis_error, "No NIS master found for any map"); return NULL; } cl = clnt_create(server, YPPROG, YPVERS, "tcp"); if (cl == NULL) { - PyErr_SetString(NisError, clnt_spcreateerror(server)); + PyErr_SetString(state->nis_error, clnt_spcreateerror(server)); goto finally; } list = nisproc_maplist_2 (&dom, cl); @@ -388,7 +427,7 @@ nis_maplist (char *dom) } static PyObject * -nis_maps (PyObject *self, PyObject *args, PyObject *kwdict) +nis_maps (PyObject *module, PyObject *args, PyObject *kwdict) { char *domain = NULL; nismaplist *maps; @@ -397,17 +436,22 @@ nis_maps (PyObject *self, PyObject *args, PyObject *kwdict) static char *kwlist[] = {"domain", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwdict, - "|s:maps", kwlist, &domain)) - return NULL; - if (!domain && ((err = yp_get_default_domain (&domain)) != 0)) { - nis_error(err); + "|s:maps", kwlist, &domain)) { return NULL; } - if ((maps = nis_maplist (domain)) == NULL) + nis_state *state = get_nis_state(module); + if (!domain && ((err = yp_get_default_domain (&domain)) != 0)) { + nis_error(state, err); return NULL; - if ((list = PyList_New(0)) == NULL) + } + + if ((maps = nis_maplist(state, domain)) == NULL) { return NULL; + } + if ((list = PyList_New(0)) == NULL) { + return NULL; + } for (; maps; maps = maps->next) { PyObject *str = PyUnicode_FromString(maps->map); if (!str || PyList_Append(list, str) < 0) @@ -439,31 +483,45 @@ static PyMethodDef nis_methods[] = { {NULL, NULL} /* Sentinel */ }; +static int +nis_exec(PyObject *module) +{ + nis_state* state = get_nis_state(module); + state->nis_error = PyErr_NewException("nis.error", NULL, NULL); + if (state->nis_error == NULL) { + return -1; + } + + Py_INCREF(state->nis_error); + if (PyModule_AddObject(module, "error", state->nis_error) < 0) { + Py_DECREF(state->nis_error); + return -1; + } + return 0; +} + +static PyModuleDef_Slot nis_slots[] = { + {Py_mod_exec, nis_exec}, + {0, NULL} +}; + PyDoc_STRVAR(nis__doc__, "This module contains functions for accessing NIS maps.\n"); static struct PyModuleDef nismodule = { PyModuleDef_HEAD_INIT, - "nis", - nis__doc__, - -1, - nis_methods, - NULL, - NULL, - NULL, - NULL + .m_name = "nis", + .m_doc = nis__doc__, + .m_size = sizeof(nis_state), + .m_methods = nis_methods, + .m_traverse = nis_traverse, + .m_clear = nis_clear, + .m_free = nis_free, + .m_slots = nis_slots, }; PyMODINIT_FUNC PyInit_nis(void) { - PyObject *m, *d; - m = PyModule_Create(&nismodule); - if (m == NULL) - return NULL; - d = PyModule_GetDict(m); - NisError = PyErr_NewException("nis.error", NULL, NULL); - if (NisError != NULL) - PyDict_SetItemString(d, "error", NisError); - return m; + return PyModuleDef_Init(&nismodule); } diff --git a/Modules/overlapped.c b/Modules/overlapped.c index df6282cba81..eed8fbf0393 100644 --- a/Modules/overlapped.c +++ b/Modules/overlapped.c @@ -1504,12 +1504,8 @@ Overlapped_traverse(OverlappedObject *self, visitproc visit, void *arg) } break; case TYPE_READ_FROM: - if(self->read_from.result) { - Py_VISIT(self->read_from.result); - } - if(self->read_from.allocated_buffer) { - Py_VISIT(self->read_from.allocated_buffer); - } + Py_VISIT(self->read_from.result); + Py_VISIT(self->read_from.allocated_buffer); } return 0; } diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c deleted file mode 100644 index 24b0ffbe36a..00000000000 --- a/Modules/parsermodule.c +++ /dev/null @@ -1,1222 +0,0 @@ -/* parsermodule.c - * - * Copyright 1995-1996 by Fred L. Drake, Jr. and Virginia Polytechnic - * Institute and State University, Blacksburg, Virginia, USA. - * Portions copyright 1991-1995 by Stichting Mathematisch Centrum, - * Amsterdam, The Netherlands. Copying is permitted under the terms - * associated with the main Python distribution, with the additional - * restriction that this additional notice be included and maintained - * on all distributed copies. - * - * This module serves to replace the original parser module written - * by Guido. The functionality is not matched precisely, but the - * original may be implemented on top of this. This is desirable - * since the source of the text to be parsed is now divorced from - * this interface. - * - * Unlike the prior interface, the ability to give a parse tree - * produced by Python code as a tuple to the compiler is enabled by - * this module. See the documentation for more details. - * - * I've added some annotations that help with the lint code-checking - * program, but they're not complete by a long shot. The real errors - * that lint detects are gone, but there are still warnings with - * Py_[X]DECREF() and Py_[X]INCREF() macros. The lint annotations - * look like "NOTE(...)". - * - */ - -#include "Python.h" /* general Python API */ -#include "Python-ast.h" /* mod_ty */ -#undef Yield /* undefine macro conflicting with */ -#include "ast.h" -#include "graminit.h" /* symbols defined in the grammar */ -#include "node.h" /* internal parser structure */ -#include "errcode.h" /* error codes for PyNode_*() */ -#include "token.h" /* token definitions */ - /* ISTERMINAL() / ISNONTERMINAL() */ -#include "grammar.h" -#include "parsetok.h" - -extern grammar _PyParser_Grammar; /* From graminit.c */ - -#ifdef lint -#include -#else -#define NOTE(x) -#endif - -/* String constants used to initialize module attributes. - * - */ -static const char parser_copyright_string[] = -"Copyright 1995-1996 by Virginia Polytechnic Institute & State\n\ -University, Blacksburg, Virginia, USA, and Fred L. Drake, Jr., Reston,\n\ -Virginia, USA. Portions copyright 1991-1995 by Stichting Mathematisch\n\ -Centrum, Amsterdam, The Netherlands."; - - -PyDoc_STRVAR(parser_doc_string, -"This is an interface to Python's internal parser."); - -static const char parser_version_string[] = "0.5"; - - -typedef PyObject* (*SeqMaker) (Py_ssize_t length); -typedef int (*SeqInserter) (PyObject* sequence, - Py_ssize_t index, - PyObject* element); - -/* The function below is copyrighted by Stichting Mathematisch Centrum. The - * original copyright statement is included below, and continues to apply - * in full to the function immediately following. All other material is - * original, copyrighted by Fred L. Drake, Jr. and Virginia Polytechnic - * Institute and State University. Changes were made to comply with the - * new naming conventions. Added arguments to provide support for creating - * lists as well as tuples, and optionally including the line numbers. - */ - - -static PyObject* -node2tuple(node *n, /* node to convert */ - SeqMaker mkseq, /* create sequence */ - SeqInserter addelem, /* func. to add elem. in seq. */ - int lineno, /* include line numbers? */ - int col_offset) /* include column offsets? */ -{ - PyObject *result = NULL, *w; - - if (n == NULL) { - Py_RETURN_NONE; - } - - if (ISNONTERMINAL(TYPE(n))) { - int i; - - result = mkseq(1 + NCH(n) + (TYPE(n) == encoding_decl)); - if (result == NULL) - goto error; - - w = PyLong_FromLong(TYPE(n)); - if (w == NULL) - goto error; - (void) addelem(result, 0, w); - - for (i = 0; i < NCH(n); i++) { - w = node2tuple(CHILD(n, i), mkseq, addelem, lineno, col_offset); - if (w == NULL) - goto error; - (void) addelem(result, i+1, w); - } - - if (TYPE(n) == encoding_decl) { - w = PyUnicode_FromString(STR(n)); - if (w == NULL) - goto error; - (void) addelem(result, i+1, w); - } - } - else if (ISTERMINAL(TYPE(n))) { - result = mkseq(2 + lineno + col_offset); - if (result == NULL) - goto error; - - w = PyLong_FromLong(TYPE(n)); - if (w == NULL) - goto error; - (void) addelem(result, 0, w); - - w = PyUnicode_FromString(STR(n)); - if (w == NULL) - goto error; - (void) addelem(result, 1, w); - - if (lineno) { - w = PyLong_FromLong(n->n_lineno); - if (w == NULL) - goto error; - (void) addelem(result, 2, w); - } - - if (col_offset) { - w = PyLong_FromLong(n->n_col_offset); - if (w == NULL) - goto error; - (void) addelem(result, 2 + lineno, w); - } - } - else { - PyErr_SetString(PyExc_SystemError, - "unrecognized parse tree node type"); - return ((PyObject*) NULL); - } - return result; - -error: - Py_XDECREF(result); - return NULL; -} -/* - * End of material copyrighted by Stichting Mathematisch Centrum. - */ - - - -/* There are two types of intermediate objects we're interested in: - * 'eval' and 'exec' types. These constants can be used in the st_type - * field of the object type to identify which any given object represents. - * These should probably go in an external header to allow other extensions - * to use them, but then, we really should be using C++ too. ;-) - */ - -#define PyST_EXPR 1 -#define PyST_SUITE 2 - - -/* These are the internal objects and definitions required to implement the - * ST type. Most of the internal names are more reminiscent of the 'old' - * naming style, but the code uses the new naming convention. - */ - -static PyObject* -parser_error = 0; - - -typedef struct { - PyObject_HEAD /* standard object header */ - node* st_node; /* the node* returned by the parser */ - int st_type; /* EXPR or SUITE ? */ - PyCompilerFlags st_flags; /* Parser and compiler flags */ -} PyST_Object; - - -static void parser_free(PyST_Object *st); -static PyObject* parser_sizeof(PyST_Object *, void *); -static PyObject* parser_richcompare(PyObject *left, PyObject *right, int op); -static PyObject* parser_compilest(PyST_Object *, PyObject *, PyObject *); -static PyObject* parser_isexpr(PyST_Object *, PyObject *, PyObject *); -static PyObject* parser_issuite(PyST_Object *, PyObject *, PyObject *); -static PyObject* parser_st2list(PyST_Object *, PyObject *, PyObject *); -static PyObject* parser_st2tuple(PyST_Object *, PyObject *, PyObject *); - -#define PUBLIC_METHOD_TYPE (METH_VARARGS|METH_KEYWORDS) - -static PyMethodDef parser_methods[] = { - {"compile", (PyCFunction)(void(*)(void))parser_compilest, PUBLIC_METHOD_TYPE, - PyDoc_STR("Compile this ST object into a code object.")}, - {"isexpr", (PyCFunction)(void(*)(void))parser_isexpr, PUBLIC_METHOD_TYPE, - PyDoc_STR("Determines if this ST object was created from an expression.")}, - {"issuite", (PyCFunction)(void(*)(void))parser_issuite, PUBLIC_METHOD_TYPE, - PyDoc_STR("Determines if this ST object was created from a suite.")}, - {"tolist", (PyCFunction)(void(*)(void))parser_st2list, PUBLIC_METHOD_TYPE, - PyDoc_STR("Creates a list-tree representation of this ST.")}, - {"totuple", (PyCFunction)(void(*)(void))parser_st2tuple, PUBLIC_METHOD_TYPE, - PyDoc_STR("Creates a tuple-tree representation of this ST.")}, - {"__sizeof__", (PyCFunction)parser_sizeof, METH_NOARGS, - PyDoc_STR("Returns size in memory, in bytes.")}, - {NULL, NULL, 0, NULL} -}; - -static -PyTypeObject PyST_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "parser.st", /* tp_name */ - (int) sizeof(PyST_Object), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)parser_free, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_as_async */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - - /* Functions to access object as input/output buffer */ - 0, /* tp_as_buffer */ - - Py_TPFLAGS_DEFAULT, /* tp_flags */ - - /* __doc__ */ - "Intermediate representation of a Python parse tree.", - 0, /* tp_traverse */ - 0, /* tp_clear */ - parser_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - parser_methods, /* tp_methods */ -}; /* PyST_Type */ - - -/* PyST_Type isn't subclassable, so just check ob_type */ -#define PyST_Object_Check(v) Py_IS_TYPE(v, &PyST_Type) - -static int -parser_compare_nodes(node *left, node *right) -{ - int j; - - if (TYPE(left) < TYPE(right)) - return (-1); - - if (TYPE(right) < TYPE(left)) - return (1); - - if (ISTERMINAL(TYPE(left))) - return (strcmp(STR(left), STR(right))); - - if (NCH(left) < NCH(right)) - return (-1); - - if (NCH(right) < NCH(left)) - return (1); - - for (j = 0; j < NCH(left); ++j) { - int v = parser_compare_nodes(CHILD(left, j), CHILD(right, j)); - - if (v != 0) - return (v); - } - return (0); -} - -/* parser_richcompare(PyObject* left, PyObject* right, int op) - * - * Comparison function used by the Python operators ==, !=, <, >, <=, >= - * This really just wraps a call to parser_compare_nodes() with some easy - * checks and protection code. - * - */ - -static PyObject * -parser_richcompare(PyObject *left, PyObject *right, int op) -{ - int result; - - /* neither argument should be NULL, unless something's gone wrong */ - if (left == NULL || right == NULL) { - PyErr_BadInternalCall(); - return NULL; - } - - /* both arguments should be instances of PyST_Object */ - if (!PyST_Object_Check(left) || !PyST_Object_Check(right)) { - Py_RETURN_NOTIMPLEMENTED; - } - - if (left == right) - /* if arguments are identical, they're equal */ - result = 0; - else - result = parser_compare_nodes(((PyST_Object *)left)->st_node, - ((PyST_Object *)right)->st_node); - - Py_RETURN_RICHCOMPARE(result, 0, op); -} - -/* parser_newstobject(node* st) - * - * Allocates a new Python object representing an ST. This is simply the - * 'wrapper' object that holds a node* and allows it to be passed around in - * Python code. - * - */ -static PyObject* -parser_newstobject(node *st, int type) -{ - PyST_Object* o = PyObject_New(PyST_Object, &PyST_Type); - - if (o != 0) { - o->st_node = st; - o->st_type = type; - o->st_flags = _PyCompilerFlags_INIT; - } - else { - PyNode_Free(st); - } - return ((PyObject*)o); -} - - -/* void parser_free(PyST_Object* st) - * - * This is called by a del statement that reduces the reference count to 0. - * - */ -static void -parser_free(PyST_Object *st) -{ - PyNode_Free(st->st_node); - PyObject_Del(st); -} - -static PyObject * -parser_sizeof(PyST_Object *st, void *unused) -{ - Py_ssize_t res; - - res = _PyObject_SIZE(Py_TYPE(st)) + _PyNode_SizeOf(st->st_node); - return PyLong_FromSsize_t(res); -} - - -/* parser_st2tuple(PyObject* self, PyObject* args, PyObject* kw) - * - * This provides conversion from a node* to a tuple object that can be - * returned to the Python-level caller. The ST object is not modified. - * - */ -static PyObject* -parser_st2tuple(PyST_Object *self, PyObject *args, PyObject *kw) -{ - int line_info = 0; - int col_info = 0; - PyObject *res = 0; - int ok; - - static char *keywords[] = {"st", "line_info", "col_info", NULL}; - - if (self == NULL || PyModule_Check(self)) { - ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|pp:st2tuple", keywords, - &PyST_Type, &self, &line_info, - &col_info); - } - else - ok = PyArg_ParseTupleAndKeywords(args, kw, "|pp:totuple", &keywords[1], - &line_info, &col_info); - if (ok != 0) { - /* - * Convert ST into a tuple representation. Use Guido's function, - * since it's known to work already. - */ - res = node2tuple(((PyST_Object*)self)->st_node, - PyTuple_New, PyTuple_SetItem, line_info, col_info); - } - return (res); -} - - -/* parser_st2list(PyObject* self, PyObject* args, PyObject* kw) - * - * This provides conversion from a node* to a list object that can be - * returned to the Python-level caller. The ST object is not modified. - * - */ -static PyObject* -parser_st2list(PyST_Object *self, PyObject *args, PyObject *kw) -{ - int line_info = 0; - int col_info = 0; - PyObject *res = 0; - int ok; - - static char *keywords[] = {"st", "line_info", "col_info", NULL}; - - if (self == NULL || PyModule_Check(self)) - ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|pp:st2list", keywords, - &PyST_Type, &self, &line_info, - &col_info); - else - ok = PyArg_ParseTupleAndKeywords(args, kw, "|pp:tolist", &keywords[1], - &line_info, &col_info); - if (ok) { - /* - * Convert ST into a tuple representation. Use Guido's function, - * since it's known to work already. - */ - res = node2tuple(self->st_node, - PyList_New, PyList_SetItem, line_info, col_info); - } - return (res); -} - - -/* parser_compilest(PyObject* self, PyObject* args) - * - * This function creates code objects from the parse tree represented by - * the passed-in data object. An optional file name is passed in as well. - * - */ -static PyObject* -parser_compilest(PyST_Object *self, PyObject *args, PyObject *kw) -{ - PyObject* res = NULL; - PyArena* arena = NULL; - mod_ty mod; - PyObject* filename = NULL; - int ok; - - static char *keywords[] = {"st", "filename", NULL}; - - if (self == NULL || PyModule_Check(self)) - ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|O&:compilest", keywords, - &PyST_Type, &self, - PyUnicode_FSDecoder, &filename); - else - ok = PyArg_ParseTupleAndKeywords(args, kw, "|O&:compile", &keywords[1], - PyUnicode_FSDecoder, &filename); - if (!ok) - goto error; - - if (filename == NULL) { - filename = PyUnicode_FromString(""); - if (filename == NULL) - goto error; - } - - arena = PyArena_New(); - if (!arena) - goto error; - - mod = PyAST_FromNodeObject(self->st_node, &self->st_flags, - filename, arena); - if (!mod) - goto error; - - res = (PyObject *)PyAST_CompileObject(mod, filename, - &self->st_flags, -1, arena); -error: - Py_XDECREF(filename); - if (arena != NULL) - PyArena_Free(arena); - return res; -} - - -/* PyObject* parser_isexpr(PyObject* self, PyObject* args) - * PyObject* parser_issuite(PyObject* self, PyObject* args) - * - * Checks the passed-in ST object to determine if it is an expression or - * a statement suite, respectively. The return is a Python truth value. - * - */ -static PyObject* -parser_isexpr(PyST_Object *self, PyObject *args, PyObject *kw) -{ - PyObject* res = 0; - int ok; - - static char *keywords[] = {"st", NULL}; - - if (self == NULL || PyModule_Check(self)) - ok = PyArg_ParseTupleAndKeywords(args, kw, "O!:isexpr", keywords, - &PyST_Type, &self); - else - ok = PyArg_ParseTupleAndKeywords(args, kw, ":isexpr", &keywords[1]); - - if (ok) { - /* Check to see if the ST represents an expression or not. */ - res = (self->st_type == PyST_EXPR) ? Py_True : Py_False; - Py_INCREF(res); - } - return (res); -} - - -static PyObject* -parser_issuite(PyST_Object *self, PyObject *args, PyObject *kw) -{ - PyObject* res = 0; - int ok; - - static char *keywords[] = {"st", NULL}; - - if (self == NULL || PyModule_Check(self)) - ok = PyArg_ParseTupleAndKeywords(args, kw, "O!:issuite", keywords, - &PyST_Type, &self); - else - ok = PyArg_ParseTupleAndKeywords(args, kw, ":issuite", &keywords[1]); - - if (ok) { - /* Check to see if the ST represents an expression or not. */ - res = (self->st_type == PyST_EXPR) ? Py_False : Py_True; - Py_INCREF(res); - } - return (res); -} - - -/* err_string(const char* message) - * - * Sets the error string for an exception of type ParserError. - * - */ -static void -err_string(const char *message) -{ - PyErr_SetString(parser_error, message); -} - - -/* PyObject* parser_do_parse(PyObject* args, int type) - * - * Internal function to actually execute the parse and return the result if - * successful or set an exception if not. - * - */ -static PyObject* -parser_do_parse(PyObject *args, PyObject *kw, const char *argspec, int type) -{ - char* string = 0; - PyObject* res = 0; - int flags = 0; - perrdetail err; - - static char *keywords[] = {"source", NULL}; - - if (PyArg_ParseTupleAndKeywords(args, kw, argspec, keywords, &string)) { - node* n = PyParser_ParseStringFlagsFilenameEx(string, NULL, - &_PyParser_Grammar, - (type == PyST_EXPR) - ? eval_input : file_input, - &err, &flags); - - if (n) { - res = parser_newstobject(n, type); - if (res) { - ((PyST_Object *)res)->st_flags.cf_flags = flags & PyCF_MASK; - ((PyST_Object *)res)->st_flags.cf_feature_version = PY_MINOR_VERSION; - } - } - else { - PyParser_SetError(&err); - } - PyParser_ClearError(&err); - } - return (res); -} - - -/* PyObject* parser_expr(PyObject* self, PyObject* args) - * PyObject* parser_suite(PyObject* self, PyObject* args) - * - * External interfaces to the parser itself. Which is called determines if - * the parser attempts to recognize an expression ('eval' form) or statement - * suite ('exec' form). The real work is done by parser_do_parse() above. - * - */ -static PyObject* -parser_expr(PyST_Object *self, PyObject *args, PyObject *kw) -{ - NOTE(ARGUNUSED(self)) - return (parser_do_parse(args, kw, "s:expr", PyST_EXPR)); -} - - -static PyObject* -parser_suite(PyST_Object *self, PyObject *args, PyObject *kw) -{ - NOTE(ARGUNUSED(self)) - return (parser_do_parse(args, kw, "s:suite", PyST_SUITE)); -} - - - -/* This is the messy part of the code. Conversion from a tuple to an ST - * object requires that the input tuple be valid without having to rely on - * catching an exception from the compiler. This is done to allow the - * compiler itself to remain fast, since most of its input will come from - * the parser directly, and therefore be known to be syntactically correct. - * This validation is done to ensure that we don't core dump the compile - * phase, returning an exception instead. - * - * Two aspects can be broken out in this code: creating a node tree from - * the tuple passed in, and verifying that it is indeed valid. It may be - * advantageous to expand the number of ST types to include funcdefs and - * lambdadefs to take advantage of the optimizer, recognizing those STs - * here. They are not necessary, and not quite as useful in a raw form. - * For now, let's get expressions and suites working reliably. - */ - - -static node* build_node_tree(PyObject *tuple); - -static int -validate_node(node *tree) -{ - int type = TYPE(tree); - int nch = NCH(tree); - state *dfa_state; - int pos, arc; - - assert(ISNONTERMINAL(type)); - type -= NT_OFFSET; - if (type >= _PyParser_Grammar.g_ndfas) { - PyErr_Format(parser_error, "Unrecognized node type %d.", TYPE(tree)); - return 0; - } - const dfa *nt_dfa = &_PyParser_Grammar.g_dfa[type]; - REQ(tree, nt_dfa->d_type); - - /* Run the DFA for this nonterminal. */ - dfa_state = nt_dfa->d_state; - for (pos = 0; pos < nch; ++pos) { - node *ch = CHILD(tree, pos); - int ch_type = TYPE(ch); - if ((ch_type >= NT_OFFSET + _PyParser_Grammar.g_ndfas) - || (ISTERMINAL(ch_type) && (ch_type >= N_TOKENS)) - || (ch_type < 0) - ) { - PyErr_Format(parser_error, "Unrecognized node type %d.", ch_type); - return 0; - } - if (ch_type == suite && TYPE(tree) == funcdef) { - /* This is the opposite hack of what we do in parser.c - (search for func_body_suite), except we don't ever - support type comments here. */ - ch_type = func_body_suite; - } - for (arc = 0; arc < dfa_state->s_narcs; ++arc) { - short a_label = dfa_state->s_arc[arc].a_lbl; - assert(a_label < _PyParser_Grammar.g_ll.ll_nlabels); - - const char *label_str = _PyParser_Grammar.g_ll.ll_label[a_label].lb_str; - if ((_PyParser_Grammar.g_ll.ll_label[a_label].lb_type == ch_type) - && ((ch->n_str == NULL) || (label_str == NULL) - || (strcmp(ch->n_str, label_str) == 0)) - ) { - /* The child is acceptable; if non-terminal, validate it recursively. */ - if (ISNONTERMINAL(ch_type) && !validate_node(ch)) - return 0; - - /* Update the state, and move on to the next child. */ - dfa_state = &nt_dfa->d_state[dfa_state->s_arc[arc].a_arrow]; - goto arc_found; - } - } - /* What would this state have accepted? */ - { - short a_label = dfa_state->s_arc->a_lbl; - if (!a_label) /* Wouldn't accept any more children */ - goto illegal_num_children; - - int next_type = _PyParser_Grammar.g_ll.ll_label[a_label].lb_type; - const char *expected_str = _PyParser_Grammar.g_ll.ll_label[a_label].lb_str; - - if (ISNONTERMINAL(next_type)) { - PyErr_Format(parser_error, "Expected %s, got %s.", - _PyParser_Grammar.g_dfa[next_type - NT_OFFSET].d_name, - ISTERMINAL(ch_type) ? _PyParser_TokenNames[ch_type] : - _PyParser_Grammar.g_dfa[ch_type - NT_OFFSET].d_name); - } - else if (expected_str != NULL) { - PyErr_Format(parser_error, "Illegal terminal: expected '%s'.", - expected_str); - } - else { - PyErr_Format(parser_error, "Illegal terminal: expected %s.", - _PyParser_TokenNames[next_type]); - } - return 0; - } - -arc_found: - continue; - } - /* Are we in a final state? If so, return 1 for successful validation. */ - for (arc = 0; arc < dfa_state->s_narcs; ++arc) { - if (!dfa_state->s_arc[arc].a_lbl) { - return 1; - } - } - -illegal_num_children: - PyErr_Format(parser_error, - "Illegal number of children for %s node.", nt_dfa->d_name); - return 0; -} - -/* PyObject* parser_tuple2st(PyObject* self, PyObject* args) - * - * This is the public function, called from the Python code. It receives a - * single tuple object from the caller, and creates an ST object if the - * tuple can be validated. It does this by checking the first code of the - * tuple, and, if acceptable, builds the internal representation. If this - * step succeeds, the internal representation is validated as fully as - * possible with the recursive validate_node() routine defined above. - * - * This function must be changed if support is to be added for PyST_FRAGMENT - * ST objects. - * - */ -static PyObject* -parser_tuple2st(PyST_Object *self, PyObject *args, PyObject *kw) -{ - NOTE(ARGUNUSED(self)) - PyObject *st = 0; - PyObject *tuple; - node *tree; - - static char *keywords[] = {"sequence", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kw, "O:sequence2st", keywords, - &tuple)) - return (0); - if (!PySequence_Check(tuple)) { - PyErr_SetString(PyExc_ValueError, - "sequence2st() requires a single sequence argument"); - return (0); - } - /* - * Convert the tree to the internal form before checking it. - */ - tree = build_node_tree(tuple); - if (tree != 0) { - node *validation_root = NULL; - int tree_type = 0; - switch (TYPE(tree)) { - case eval_input: - /* Might be an eval form. */ - tree_type = PyST_EXPR; - validation_root = tree; - break; - case encoding_decl: - /* This looks like an encoding_decl so far. */ - if (NCH(tree) == 1) { - tree_type = PyST_SUITE; - validation_root = CHILD(tree, 0); - } - else { - err_string("Error Parsing encoding_decl"); - } - break; - case file_input: - /* This looks like an exec form so far. */ - tree_type = PyST_SUITE; - validation_root = tree; - break; - default: - /* This is a fragment, at best. */ - err_string("parse tree does not use a valid start symbol"); - } - - if (validation_root != NULL && validate_node(validation_root)) - st = parser_newstobject(tree, tree_type); - else - PyNode_Free(tree); - } - /* Make sure we raise an exception on all errors. We should never - * get this, but we'd do well to be sure something is done. - */ - if (st == NULL && !PyErr_Occurred()) - err_string("unspecified ST error occurred"); - - return st; -} - - -/* node* build_node_children() - * - * Iterate across the children of the current non-terminal node and build - * their structures. If successful, return the root of this portion of - * the tree, otherwise, 0. Any required exception will be specified already, - * and no memory will have been deallocated. - * - */ -static node* -build_node_children(PyObject *tuple, node *root, int *line_num) -{ - Py_ssize_t len = PyObject_Size(tuple); - Py_ssize_t i; - int err; - - if (len < 0) { - return NULL; - } - for (i = 1; i < len; ++i) { - /* elem must always be a sequence, however simple */ - PyObject* elem = PySequence_GetItem(tuple, i); - int ok = elem != NULL; - int type = 0; - char *strn = 0; - - if (ok) - ok = PySequence_Check(elem); - if (ok) { - PyObject *temp = PySequence_GetItem(elem, 0); - if (temp == NULL) - ok = 0; - else { - ok = PyLong_Check(temp); - if (ok) { - type = _PyLong_AsInt(temp); - if (type == -1 && PyErr_Occurred()) { - Py_DECREF(temp); - Py_DECREF(elem); - return NULL; - } - } - Py_DECREF(temp); - } - } - if (!ok) { - PyObject *err = Py_BuildValue("Os", elem, - "Illegal node construct."); - PyErr_SetObject(parser_error, err); - Py_XDECREF(err); - Py_XDECREF(elem); - return NULL; - } - if (ISTERMINAL(type)) { - Py_ssize_t len = PyObject_Size(elem); - PyObject *temp; - const char *temp_str; - - if ((len != 2) && (len != 3)) { - err_string("terminal nodes must have 2 or 3 entries"); - Py_DECREF(elem); - return NULL; - } - temp = PySequence_GetItem(elem, 1); - if (temp == NULL) { - Py_DECREF(elem); - return NULL; - } - if (!PyUnicode_Check(temp)) { - PyErr_Format(parser_error, - "second item in terminal node must be a string," - " found %s", - Py_TYPE(temp)->tp_name); - Py_DECREF(temp); - Py_DECREF(elem); - return NULL; - } - if (len == 3) { - PyObject *o = PySequence_GetItem(elem, 2); - if (o == NULL) { - Py_DECREF(temp); - Py_DECREF(elem); - return NULL; - } - if (PyLong_Check(o)) { - int num = _PyLong_AsInt(o); - if (num == -1 && PyErr_Occurred()) { - Py_DECREF(o); - Py_DECREF(temp); - Py_DECREF(elem); - return NULL; - } - *line_num = num; - } - else { - PyErr_Format(parser_error, - "third item in terminal node must be an" - " integer, found %s", - Py_TYPE(temp)->tp_name); - Py_DECREF(o); - Py_DECREF(temp); - Py_DECREF(elem); - return NULL; - } - Py_DECREF(o); - } - temp_str = PyUnicode_AsUTF8AndSize(temp, &len); - if (temp_str == NULL) { - Py_DECREF(temp); - Py_DECREF(elem); - return NULL; - } - strn = (char *)PyObject_MALLOC(len + 1); - if (strn == NULL) { - Py_DECREF(temp); - Py_DECREF(elem); - PyErr_NoMemory(); - return NULL; - } - (void) memcpy(strn, temp_str, len + 1); - Py_DECREF(temp); - } - else if (!ISNONTERMINAL(type)) { - /* - * It has to be one or the other; this is an error. - * Raise an exception. - */ - PyObject *err = Py_BuildValue("Os", elem, "unknown node type."); - PyErr_SetObject(parser_error, err); - Py_XDECREF(err); - Py_DECREF(elem); - return NULL; - } - err = PyNode_AddChild(root, type, strn, *line_num, 0, *line_num, 0); - if (err == E_NOMEM) { - Py_DECREF(elem); - PyObject_FREE(strn); - PyErr_NoMemory(); - return NULL; - } - if (err == E_OVERFLOW) { - Py_DECREF(elem); - PyObject_FREE(strn); - PyErr_SetString(PyExc_ValueError, - "unsupported number of child nodes"); - return NULL; - } - - if (ISNONTERMINAL(type)) { - node* new_child = CHILD(root, i - 1); - - if (new_child != build_node_children(elem, new_child, line_num)) { - Py_DECREF(elem); - return NULL; - } - } - else if (type == NEWLINE) { /* It's true: we increment the */ - ++(*line_num); /* line number *after* the newline! */ - } - Py_DECREF(elem); - } - return root; -} - - -static node* -build_node_tree(PyObject *tuple) -{ - node* res = 0; - PyObject *temp = PySequence_GetItem(tuple, 0); - long num = -1; - - if (temp != NULL) - num = PyLong_AsLong(temp); - Py_XDECREF(temp); - if (ISTERMINAL(num)) { - /* - * The tuple is simple, but it doesn't start with a start symbol. - * Raise an exception now and be done with it. - */ - tuple = Py_BuildValue("Os", tuple, - "Illegal syntax-tree; cannot start with terminal symbol."); - PyErr_SetObject(parser_error, tuple); - Py_XDECREF(tuple); - } - else if (ISNONTERMINAL(num)) { - /* - * Not efficient, but that can be handled later. - */ - int line_num = 0; - PyObject *encoding = NULL; - - if (num == encoding_decl) { - encoding = PySequence_GetItem(tuple, 2); - if (encoding == NULL) { - PyErr_SetString(parser_error, "missed encoding"); - return NULL; - } - if (!PyUnicode_Check(encoding)) { - PyErr_Format(parser_error, - "encoding must be a string, found %.200s", - Py_TYPE(encoding)->tp_name); - Py_DECREF(encoding); - return NULL; - } - /* tuple isn't borrowed anymore here, need to DECREF */ - tuple = PySequence_GetSlice(tuple, 0, 2); - if (tuple == NULL) { - Py_DECREF(encoding); - return NULL; - } - } - res = PyNode_New(num); - if (res != NULL) { - if (res != build_node_children(tuple, res, &line_num)) { - PyNode_Free(res); - res = NULL; - } - if (res && encoding) { - Py_ssize_t len; - const char *temp; - temp = PyUnicode_AsUTF8AndSize(encoding, &len); - if (temp == NULL) { - PyNode_Free(res); - Py_DECREF(encoding); - Py_DECREF(tuple); - return NULL; - } - res->n_str = (char *)PyObject_MALLOC(len + 1); - if (res->n_str == NULL) { - PyNode_Free(res); - Py_DECREF(encoding); - Py_DECREF(tuple); - PyErr_NoMemory(); - return NULL; - } - (void) memcpy(res->n_str, temp, len + 1); - } - } - if (encoding != NULL) { - Py_DECREF(encoding); - Py_DECREF(tuple); - } - } - else { - /* The tuple is illegal -- if the number is neither TERMINAL nor - * NONTERMINAL, we can't use it. Not sure the implementation - * allows this condition, but the API doesn't preclude it. - */ - PyObject *err = Py_BuildValue("Os", tuple, - "Illegal component tuple."); - PyErr_SetObject(parser_error, err); - Py_XDECREF(err); - } - - return (res); -} - - -static PyObject* -pickle_constructor = NULL; - - -static PyObject* -parser__pickler(PyObject *self, PyObject *args) -{ - NOTE(ARGUNUSED(self)) - PyObject *result = NULL; - PyObject *st = NULL; - - if (PyArg_ParseTuple(args, "O!:_pickler", &PyST_Type, &st)) { - PyObject *newargs; - PyObject *tuple; - - if ((newargs = PyTuple_Pack(2, st, Py_True)) == NULL) - return NULL; - tuple = parser_st2tuple((PyST_Object*)NULL, newargs, NULL); - if (tuple != NULL) { - result = Py_BuildValue("O(O)", pickle_constructor, tuple); - Py_DECREF(tuple); - } - Py_DECREF(newargs); - } - - return (result); -} - - -/* Functions exported by this module. Most of this should probably - * be converted into an ST object with methods, but that is better - * done directly in Python, allowing subclasses to be created directly. - * We'd really have to write a wrapper around it all anyway to allow - * inheritance. - */ -static PyMethodDef parser_functions[] = { - {"compilest", (PyCFunction)(void(*)(void))parser_compilest, PUBLIC_METHOD_TYPE, - PyDoc_STR("Compiles an ST object into a code object.")}, - {"expr", (PyCFunction)(void(*)(void))parser_expr, PUBLIC_METHOD_TYPE, - PyDoc_STR("Creates an ST object from an expression.")}, - {"isexpr", (PyCFunction)(void(*)(void))parser_isexpr, PUBLIC_METHOD_TYPE, - PyDoc_STR("Determines if an ST object was created from an expression.")}, - {"issuite", (PyCFunction)(void(*)(void))parser_issuite, PUBLIC_METHOD_TYPE, - PyDoc_STR("Determines if an ST object was created from a suite.")}, - {"suite", (PyCFunction)(void(*)(void))parser_suite, PUBLIC_METHOD_TYPE, - PyDoc_STR("Creates an ST object from a suite.")}, - {"sequence2st", (PyCFunction)(void(*)(void))parser_tuple2st, PUBLIC_METHOD_TYPE, - PyDoc_STR("Creates an ST object from a tree representation.")}, - {"st2tuple", (PyCFunction)(void(*)(void))parser_st2tuple, PUBLIC_METHOD_TYPE, - PyDoc_STR("Creates a tuple-tree representation of an ST.")}, - {"st2list", (PyCFunction)(void(*)(void))parser_st2list, PUBLIC_METHOD_TYPE, - PyDoc_STR("Creates a list-tree representation of an ST.")}, - {"tuple2st", (PyCFunction)(void(*)(void))parser_tuple2st, PUBLIC_METHOD_TYPE, - PyDoc_STR("Creates an ST object from a tree representation.")}, - - /* private stuff: support pickle module */ - {"_pickler", (PyCFunction)parser__pickler, METH_VARARGS, - PyDoc_STR("Returns the pickle magic to allow ST objects to be pickled.")}, - - {NULL, NULL, 0, NULL} - }; - - - -static struct PyModuleDef parsermodule = { - PyModuleDef_HEAD_INIT, - "parser", - NULL, - -1, - parser_functions, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC PyInit_parser(void); /* supply a prototype */ - -PyMODINIT_FUNC -PyInit_parser(void) -{ - PyObject *module, *copyreg; - - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "The parser module is deprecated and will be removed " - "in future versions of Python", 7) != 0) { - return NULL; - } - - if (PyType_Ready(&PyST_Type) < 0) - return NULL; - module = PyModule_Create(&parsermodule); - if (module == NULL) - return NULL; - - if (parser_error == 0) - parser_error = PyErr_NewException("parser.ParserError", NULL, NULL); - - if (parser_error == 0) - return NULL; - /* CAUTION: The code next used to skip bumping the refcount on - * parser_error. That's a disaster if PyInit_parser() gets called more - * than once. By incref'ing, we ensure that each module dict that - * gets created owns its reference to the shared parser_error object, - * and the file static parser_error vrbl owns a reference too. - */ - Py_INCREF(parser_error); - if (PyModule_AddObject(module, "ParserError", parser_error) != 0) - return NULL; - - Py_INCREF(&PyST_Type); - PyModule_AddObject(module, "STType", (PyObject*)&PyST_Type); - - PyModule_AddStringConstant(module, "__copyright__", - parser_copyright_string); - PyModule_AddStringConstant(module, "__doc__", - parser_doc_string); - PyModule_AddStringConstant(module, "__version__", - parser_version_string); - - /* Register to support pickling. - * If this fails, the import of this module will fail because an - * exception will be raised here; should we clear the exception? - */ - copyreg = PyImport_ImportModuleNoBlock("copyreg"); - if (copyreg != NULL) { - PyObject *func, *pickler; - _Py_IDENTIFIER(pickle); - _Py_IDENTIFIER(sequence2st); - _Py_IDENTIFIER(_pickler); - - func = _PyObject_GetAttrId(copyreg, &PyId_pickle); - pickle_constructor = _PyObject_GetAttrId(module, &PyId_sequence2st); - pickler = _PyObject_GetAttrId(module, &PyId__pickler); - Py_XINCREF(pickle_constructor); - if ((func != NULL) && (pickle_constructor != NULL) - && (pickler != NULL)) { - PyObject *res; - - res = PyObject_CallFunctionObjArgs(func, &PyST_Type, pickler, - pickle_constructor, NULL); - Py_XDECREF(res); - } - Py_XDECREF(func); - Py_XDECREF(pickle_constructor); - Py_XDECREF(pickler); - Py_DECREF(copyreg); - } - return module; -} diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 59ac47de1a7..a411f28987e 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -34,6 +34,7 @@ #include "pycore_ceval.h" // _PyEval_ReInitThreads() #include "pycore_import.h" // _PyImport_ReInitLock() +#include "pycore_initconfig.h" // _PyStatus_EXCEPTION() #include "pycore_pystate.h" // _PyInterpreterState_GET() #include "structmember.h" // PyMemberDef #ifndef MS_WINDOWS @@ -461,15 +462,45 @@ PyOS_AfterFork_Parent(void) void PyOS_AfterFork_Child(void) { + PyStatus status; _PyRuntimeState *runtime = &_PyRuntime; - _PyGILState_Reinit(runtime); - _PyEval_ReInitThreads(runtime); - _PyImport_ReInitLock(); - _PySignal_AfterFork(); - _PyRuntimeState_ReInitThreads(runtime); - _PyInterpreterState_DeleteExceptMain(runtime); - run_at_forkers(_PyInterpreterState_GET()->after_forkers_child, 0); + status = _PyGILState_Reinit(runtime); + if (_PyStatus_EXCEPTION(status)) { + goto fatal_error; + } + + PyThreadState *tstate = _PyThreadState_GET(); + _Py_EnsureTstateNotNULL(tstate); + + status = _PyEval_ReInitThreads(tstate); + if (_PyStatus_EXCEPTION(status)) { + goto fatal_error; + } + + status = _PyImport_ReInitLock(); + if (_PyStatus_EXCEPTION(status)) { + goto fatal_error; + } + + _PySignal_AfterFork(); + + status = _PyRuntimeState_ReInitThreads(runtime); + if (_PyStatus_EXCEPTION(status)) { + goto fatal_error; + } + + status = _PyInterpreterState_DeleteExceptMain(runtime); + if (_PyStatus_EXCEPTION(status)) { + goto fatal_error; + } + assert(_PyThreadState_GET() == tstate); + + run_at_forkers(tstate->interp->after_forkers_child, 0); + return; + +fatal_error: + Py_ExitStatusException(status); } static int @@ -531,7 +562,7 @@ _Py_Uid_Converter(PyObject *obj, void *p) long result; unsigned long uresult; - index = PyNumber_Index(obj); + index = _PyNumber_Index(obj); if (index == NULL) { PyErr_Format(PyExc_TypeError, "uid should be integer, not %.200s", @@ -637,7 +668,7 @@ _Py_Gid_Converter(PyObject *obj, void *p) long result; unsigned long uresult; - index = PyNumber_Index(obj); + index = _PyNumber_Index(obj); if (index == NULL) { PyErr_Format(PyExc_TypeError, "gid should be integer, not %.200s", @@ -771,7 +802,7 @@ _fd_converter(PyObject *o, int *p) int overflow; long long_value; - PyObject *index = PyNumber_Index(o); + PyObject *index = _PyNumber_Index(o); if (index == NULL) { return 0; } @@ -9778,6 +9809,7 @@ The flags argument contains a bitwise OR of zero or more of the following flags: - RWF_DSYNC - RWF_SYNC +- RWF_APPEND Using non-zero flags requires Linux 4.7 or newer. [clinic start generated code]*/ @@ -9785,7 +9817,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=803dc5ddbf0cfd3b]*/ +/*[clinic end generated code: output=e3dd3e9d11a6a5c7 input=35358c327e1a2a8e]*/ { Py_ssize_t cnt; Py_ssize_t result; @@ -10956,7 +10988,7 @@ conv_path_confname(PyObject *arg, int *valuep) /*[clinic input] os.fpathconf -> long - fd: int + fd: fildes name: path_confname / @@ -10967,7 +10999,7 @@ If there is no limit, return -1. static long os_fpathconf_impl(PyObject *module, int fd, int name) -/*[clinic end generated code: output=d5b7042425fc3e21 input=5942a024d3777810]*/ +/*[clinic end generated code: output=d5b7042425fc3e21 input=5b8d2471cfaae186]*/ { long limit; @@ -14509,6 +14541,9 @@ all_ins(PyObject *m) #ifdef RWF_NOWAIT if (PyModule_AddIntConstant(m, "RWF_NOWAIT", RWF_NOWAIT)) return -1; #endif +#ifdef RWF_APPEND + if (PyModule_AddIntConstant(m, "RWF_APPEND", RWF_APPEND)) return -1; +#endif /* constants for posix_spawn */ #ifdef HAVE_POSIX_SPAWN diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 04e0067eec2..13ffe09c6d4 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -458,7 +458,7 @@ select.poll.register fd: fildes either an integer, or an object with a fileno() method returning an int - eventmask: unsigned_short(c_default="POLLIN | POLLPRI | POLLOUT") = POLLIN | POLLPRI | POLLOUT + eventmask: unsigned_short(c_default="POLLIN | POLLPRI | POLLOUT") = select.POLLIN | select.POLLPRI | select.POLLOUT an optional bitmask describing the type of events to check for / @@ -467,7 +467,7 @@ Register a file descriptor with the polling object. static PyObject * select_poll_register_impl(pollObject *self, int fd, unsigned short eventmask) -/*[clinic end generated code: output=0dc7173c800a4a65 input=f18711d9bb021e25]*/ +/*[clinic end generated code: output=0dc7173c800a4a65 input=34e16cfb28d3c900]*/ { PyObject *key, *value; int err; @@ -845,7 +845,7 @@ select.devpoll.register fd: fildes either an integer, or an object with a fileno() method returning an int - eventmask: unsigned_short(c_default="POLLIN | POLLPRI | POLLOUT") = POLLIN | POLLPRI | POLLOUT + eventmask: unsigned_short(c_default="POLLIN | POLLPRI | POLLOUT") = select.POLLIN | select.POLLPRI | select.POLLOUT an optional bitmask describing the type of events to check for / @@ -855,7 +855,7 @@ Register a file descriptor with the polling object. static PyObject * select_devpoll_register_impl(devpollObject *self, int fd, unsigned short eventmask) -/*[clinic end generated code: output=6e07fe8b74abba0c input=5bd7cacc47a8ee46]*/ +/*[clinic end generated code: output=6e07fe8b74abba0c input=22006fabe9567522]*/ { return internal_devpoll_register(self, fd, eventmask, 0); } @@ -866,7 +866,7 @@ select.devpoll.modify fd: fildes either an integer, or an object with a fileno() method returning an int - eventmask: unsigned_short(c_default="POLLIN | POLLPRI | POLLOUT") = POLLIN | POLLPRI | POLLOUT + eventmask: unsigned_short(c_default="POLLIN | POLLPRI | POLLOUT") = select.POLLIN | select.POLLPRI | select.POLLOUT an optional bitmask describing the type of events to check for / @@ -876,7 +876,7 @@ Modify a possible already registered file descriptor. static PyObject * select_devpoll_modify_impl(devpollObject *self, int fd, unsigned short eventmask) -/*[clinic end generated code: output=bc2e6d23aaff98b4 input=48a820fc5967165d]*/ +/*[clinic end generated code: output=bc2e6d23aaff98b4 input=09fa335db7cdc09e]*/ { return internal_devpoll_register(self, fd, eventmask, 1); } @@ -1475,7 +1475,7 @@ select.epoll.register fd: fildes the target file descriptor of the operation - eventmask: unsigned_int(c_default="EPOLLIN | EPOLLPRI | EPOLLOUT", bitwise=True) = EPOLLIN | EPOLLPRI | EPOLLOUT + eventmask: unsigned_int(c_default="EPOLLIN | EPOLLPRI | EPOLLOUT", bitwise=True) = select.EPOLLIN | select.EPOLLPRI | select.EPOLLOUT a bit set composed of the various EPOLL constants Registers a new fd or raises an OSError if the fd is already registered. @@ -1486,7 +1486,7 @@ The epoll interface supports all file descriptors that support poll. static PyObject * select_epoll_register_impl(pyEpoll_Object *self, int fd, unsigned int eventmask) -/*[clinic end generated code: output=318e5e6386520599 input=6cf699c152dd8ca9]*/ +/*[clinic end generated code: output=318e5e6386520599 input=a5071b71edfe3578]*/ { return pyepoll_internal_ctl(self->epfd, EPOLL_CTL_ADD, fd, eventmask); } @@ -2482,7 +2482,6 @@ PyInit_select(void) if (poll_Type == NULL) return NULL; get_select_state(m)->poll_Type = (PyTypeObject *)poll_Type; - Py_INCREF(poll_Type); PyModule_AddIntMacro(m, POLLIN); PyModule_AddIntMacro(m, POLLPRI); @@ -2518,7 +2517,6 @@ PyInit_select(void) if (devpoll_Type == NULL) return NULL; get_select_state(m)->devpoll_Type = (PyTypeObject *)devpoll_Type; - Py_INCREF(devpoll_Type); #endif #ifdef HAVE_EPOLL diff --git a/Modules/sha1module.c b/Modules/sha1module.c index e066b880229..b0656d83b3a 100644 --- a/Modules/sha1module.c +++ b/Modules/sha1module.c @@ -529,9 +529,6 @@ static struct PyMethodDef SHA1_functions[] = { /* Initialize this module. */ -#define insint(n,v) { PyModule_AddIntConstant(m,n,v); } - - static struct PyModuleDef _sha1module = { PyModuleDef_HEAD_INIT, "_sha1", diff --git a/Modules/sha256module.c b/Modules/sha256module.c index e0ff9b2b3a1..06e4430bd7c 100644 --- a/Modules/sha256module.c +++ b/Modules/sha256module.c @@ -17,7 +17,7 @@ /* SHA objects */ #include "Python.h" -#include "pycore_byteswap.h" // _Py_bswap32() +#include "pycore_bitutils.h" // _Py_bswap32() #include "structmember.h" // PyMemberDef #include "hashlib.h" #include "pystrhex.h" @@ -681,46 +681,45 @@ static struct PyMethodDef SHA_functions[] = { {NULL, NULL} /* Sentinel */ }; - -/* Initialize this module. */ - -#define insint(n,v) { PyModule_AddIntConstant(m,n,v); } - - -static struct PyModuleDef _sha256module = { - PyModuleDef_HEAD_INIT, - "_sha256", - NULL, - -1, - SHA_functions, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC -PyInit__sha256(void) +static int sha256_exec(PyObject *module) { - PyObject *m; - Py_SET_TYPE(&SHA224type, &PyType_Type); if (PyType_Ready(&SHA224type) < 0) { - return NULL; + return -1; } Py_SET_TYPE(&SHA256type, &PyType_Type); if (PyType_Ready(&SHA256type) < 0) { - return NULL; + return -1; } - m = PyModule_Create(&_sha256module); - if (m == NULL) - return NULL; - Py_INCREF((PyObject *)&SHA224type); - PyModule_AddObject(m, "SHA224Type", (PyObject *)&SHA224type); + if (PyModule_AddObject(module, "SHA224Type", (PyObject *)&SHA224type) < 0) { + Py_DECREF((PyObject *)&SHA224type); + return -1; + } Py_INCREF((PyObject *)&SHA256type); - PyModule_AddObject(m, "SHA256Type", (PyObject *)&SHA256type); - return m; - + if (PyModule_AddObject(module, "SHA256Type", (PyObject *)&SHA256type) < 0) { + Py_DECREF((PyObject *)&SHA256type); + return -1; + } + return 0; +} + +static PyModuleDef_Slot _sha256_slots[] = { + {Py_mod_exec, sha256_exec}, + {0, NULL} +}; + +static struct PyModuleDef _sha256module = { + PyModuleDef_HEAD_INIT, + .m_name = "_sha256", + .m_methods = SHA_functions, + .m_slots = _sha256_slots, +}; + +/* Initialize this module. */ +PyMODINIT_FUNC +PyInit__sha256(void) +{ + return PyModuleDef_Init(&_sha256module); } diff --git a/Modules/sha512module.c b/Modules/sha512module.c index 780f8e7f06c..aa2aeedcc6c 100644 --- a/Modules/sha512module.c +++ b/Modules/sha512module.c @@ -17,7 +17,7 @@ /* SHA objects */ #include "Python.h" -#include "pycore_byteswap.h" // _Py_bswap32() +#include "pycore_bitutils.h" // _Py_bswap32() #include "structmember.h" // PyMemberDef #include "hashlib.h" #include "pystrhex.h" @@ -741,9 +741,6 @@ static struct PyMethodDef SHA_functions[] = { /* Initialize this module. */ -#define insint(n,v) { PyModule_AddIntConstant(m,n,v); } - - static struct PyModuleDef _sha512module = { PyModuleDef_HEAD_INIT, "_sha512", diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 8348971c353..ef3536a210b 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -1779,11 +1779,13 @@ PyOS_FiniInterrupts(void) finisignal(); } + +// The caller doesn't have to hold the GIL int -PyOS_InterruptOccurred(void) +_PyOS_InterruptOccurred(PyThreadState *tstate) { - PyInterpreterState *interp = _PyInterpreterState_GET(); - if (!_Py_ThreadCanHandleSignals(interp)) { + _Py_EnsureTstateNotNULL(tstate); + if (!_Py_ThreadCanHandleSignals(tstate->interp)) { return 0; } @@ -1795,14 +1797,26 @@ PyOS_InterruptOccurred(void) return 1; } + +// The caller must to hold the GIL +int +PyOS_InterruptOccurred(void) +{ + PyThreadState *tstate = _PyThreadState_GET(); + return _PyOS_InterruptOccurred(tstate); +} + + +#ifdef HAVE_FORK static void _clear_pending_signals(void) { - int i; - if (!_Py_atomic_load(&is_tripped)) + if (!_Py_atomic_load(&is_tripped)) { return; + } + _Py_atomic_store(&is_tripped, 0); - for (i = 1; i < NSIG; ++i) { + for (int i = 1; i < NSIG; ++i) { _Py_atomic_store_relaxed(&Handlers[i].tripped, 0); } } @@ -1815,6 +1829,8 @@ _PySignal_AfterFork(void) * the interpreter had an opportunity to call the handlers. issue9535. */ _clear_pending_signals(); } +#endif /* HAVE_FORK */ + int _PyOS_IsMainThread(void) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 92c246ebea7..db0eeaafeec 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -197,43 +197,6 @@ if_indextoname(index) -- return the corresponding interface name\n\ # define USE_GETHOSTBYNAME_LOCK #endif -/* To use __FreeBSD_version, __OpenBSD__, and __NetBSD_Version__ */ -#ifdef HAVE_SYS_PARAM_H -#include -#endif -/* On systems on which getaddrinfo() is believed to not be thread-safe, - (this includes the getaddrinfo emulation) protect access with a lock. - - getaddrinfo is thread-safe on Mac OS X 10.5 and later. Originally it was - a mix of code including an unsafe implementation from an old BSD's - libresolv. In 10.5 Apple reimplemented it as a safe IPC call to the - mDNSResponder process. 10.5 is the first be UNIX '03 certified, which - includes the requirement that getaddrinfo be thread-safe. See issue #25924. - - It's thread-safe in OpenBSD starting with 5.4, released Nov 2013: - http://www.openbsd.org/plus54.html - - It's thread-safe in NetBSD starting with 4.0, released Dec 2007: - -http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/net/getaddrinfo.c.diff?r1=1.82&r2=1.83 - */ -#if ((defined(__APPLE__) && \ - MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) || \ - (defined(__FreeBSD__) && __FreeBSD_version+0 < 503000) || \ - (defined(__OpenBSD__) && OpenBSD+0 < 201311) || \ - (defined(__NetBSD__) && __NetBSD_Version__+0 < 400000000) || \ - !defined(HAVE_GETADDRINFO)) -#define USE_GETADDRINFO_LOCK -#endif - -#ifdef USE_GETADDRINFO_LOCK -#define ACQUIRE_GETADDRINFO_LOCK PyThread_acquire_lock(netdb_lock, 1); -#define RELEASE_GETADDRINFO_LOCK PyThread_release_lock(netdb_lock); -#else -#define ACQUIRE_GETADDRINFO_LOCK -#define RELEASE_GETADDRINFO_LOCK -#endif - #if defined(__APPLE__) || defined(__CYGWIN__) || defined(__NetBSD__) # include #endif @@ -473,13 +436,12 @@ remove_unusable_flags(PyObject *m) #endif #ifdef MS_WIN32 -#undef EAFNOSUPPORT -#define EAFNOSUPPORT WSAEAFNOSUPPORT -#define snprintf _snprintf +# undef EAFNOSUPPORT +# define EAFNOSUPPORT WSAEAFNOSUPPORT #endif #ifndef SOCKETCLOSE -#define SOCKETCLOSE close +# define SOCKETCLOSE close #endif #if (defined(HAVE_BLUETOOTH_H) || defined(HAVE_BLUETOOTH_BLUETOOTH_H)) && !defined(__NetBSD__) && !defined(__DragonFly__) @@ -1061,7 +1023,7 @@ new_sockobject(SOCKET_T fd, int family, int type, int proto) /* Lock to allow python interpreter to continue, but only allow one thread to be in gethostbyname or getaddrinfo */ -#if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) +#if defined(USE_GETHOSTBYNAME_LOCK) static PyThread_type_lock netdb_lock; #endif @@ -1086,14 +1048,12 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int hints.ai_socktype = SOCK_DGRAM; /*dummy*/ hints.ai_flags = AI_PASSIVE; Py_BEGIN_ALLOW_THREADS - ACQUIRE_GETADDRINFO_LOCK error = getaddrinfo(NULL, "0", &hints, &res); Py_END_ALLOW_THREADS /* We assume that those thread-unsafe getaddrinfo() versions *are* safe regarding their return value, ie. that a subsequent call to getaddrinfo() does not destroy the outcome of the first call. */ - RELEASE_GETADDRINFO_LOCK if (error) { set_gaierror(error); return -1; @@ -1194,7 +1154,6 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int memset(&hints, 0, sizeof(hints)); hints.ai_family = af; Py_BEGIN_ALLOW_THREADS - ACQUIRE_GETADDRINFO_LOCK error = getaddrinfo(name, NULL, &hints, &res); #if defined(__digital__) && defined(__unix__) if (error == EAI_NONAME && af == AF_UNSPEC) { @@ -1205,7 +1164,6 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int } #endif Py_END_ALLOW_THREADS - RELEASE_GETADDRINFO_LOCK /* see comment in setipaddr() */ if (error) { set_gaierror(error); return -1; @@ -6563,10 +6521,8 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs) hints.ai_protocol = protocol; hints.ai_flags = flags; Py_BEGIN_ALLOW_THREADS - ACQUIRE_GETADDRINFO_LOCK error = getaddrinfo(hptr, pptr, &hints, &res0); Py_END_ALLOW_THREADS - RELEASE_GETADDRINFO_LOCK /* see comment in setipaddr() */ if (error) { set_gaierror(error); goto err; @@ -6659,10 +6615,8 @@ socket_getnameinfo(PyObject *self, PyObject *args) hints.ai_socktype = SOCK_DGRAM; /* make numeric port happy */ hints.ai_flags = AI_NUMERICHOST; /* don't do any name resolution */ Py_BEGIN_ALLOW_THREADS - ACQUIRE_GETADDRINFO_LOCK error = getaddrinfo(hostp, pbuf, &hints, &res); Py_END_ALLOW_THREADS - RELEASE_GETADDRINFO_LOCK /* see comment in setipaddr() */ if (error) { set_gaierror(error); goto fail; @@ -8422,7 +8376,7 @@ PyInit__socket(void) #endif /* _MSTCPIP_ */ /* Initialize gethostbyname lock */ -#if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) +#if defined(USE_GETHOSTBYNAME_LOCK) netdb_lock = PyThread_allocate_lock(); #endif diff --git a/Modules/sre_lib.h b/Modules/sre_lib.h index 9cc786321c5..cfe0a4af2c4 100644 --- a/Modules/sre_lib.h +++ b/Modules/sre_lib.h @@ -323,12 +323,12 @@ SRE(count)(SRE_STATE* state, const SRE_CODE* pattern, Py_ssize_t maxcount) if (!i) break; } - TRACE(("|%p|%p|COUNT %" PY_FORMAT_SIZE_T "d\n", pattern, ptr, + TRACE(("|%p|%p|COUNT %zd\n", pattern, ptr, (SRE_CHAR*) state->ptr - ptr)); return (SRE_CHAR*) state->ptr - ptr; } - TRACE(("|%p|%p|COUNT %" PY_FORMAT_SIZE_T "d\n", pattern, ptr, + TRACE(("|%p|%p|COUNT %zd\n", pattern, ptr, ptr - (SRE_CHAR*) state->ptr)); return ptr - (SRE_CHAR*) state->ptr; } @@ -414,8 +414,7 @@ SRE(info)(SRE_STATE* state, const SRE_CODE* pattern) #define DATA_STACK_ALLOC(state, type, ptr) \ do { \ alloc_pos = state->data_stack_base; \ - TRACE(("allocating %s in %" PY_FORMAT_SIZE_T "d " \ - "(%" PY_FORMAT_SIZE_T "d)\n", \ + TRACE(("allocating %s in %zd (%zd)\n", \ Py_STRINGIFY(type), alloc_pos, sizeof(type))); \ if (sizeof(type) > state->data_stack_size - alloc_pos) { \ int j = data_stack_grow(state, sizeof(type)); \ @@ -429,14 +428,13 @@ do { \ #define DATA_STACK_LOOKUP_AT(state, type, ptr, pos) \ do { \ - TRACE(("looking up %s at %" PY_FORMAT_SIZE_T "d\n", Py_STRINGIFY(type), pos)); \ + TRACE(("looking up %s at %zd\n", Py_STRINGIFY(type), pos)); \ ptr = (type*)(state->data_stack+pos); \ } while (0) #define DATA_STACK_PUSH(state, data, size) \ do { \ - TRACE(("copy data in %p to %" PY_FORMAT_SIZE_T "d " \ - "(%" PY_FORMAT_SIZE_T "d)\n", \ + TRACE(("copy data in %p to %zd (%zd)\n", \ data, state->data_stack_base, size)); \ if (size > state->data_stack_size - state->data_stack_base) { \ int j = data_stack_grow(state, size); \ @@ -448,20 +446,21 @@ do { \ state->data_stack_base += size; \ } while (0) +/* We add an explicit cast to memcpy here because MSVC has a bug when + compiling C code where it believes that `const void**` cannot be + safely casted to `void*`, see bpo-39943 for details. */ #define DATA_STACK_POP(state, data, size, discard) \ do { \ - TRACE(("copy data to %p from %" PY_FORMAT_SIZE_T "d " \ - "(%" PY_FORMAT_SIZE_T "d)\n", \ + TRACE(("copy data to %p from %zd (%zd)\n", \ data, state->data_stack_base-size, size)); \ - memcpy(data, state->data_stack+state->data_stack_base-size, size); \ + memcpy((void*) data, state->data_stack+state->data_stack_base-size, size); \ if (discard) \ state->data_stack_base -= size; \ } while (0) #define DATA_STACK_POP_DISCARD(state, size) \ do { \ - TRACE(("discard data from %" PY_FORMAT_SIZE_T "d " \ - "(%" PY_FORMAT_SIZE_T "d)\n", \ + TRACE(("discard data from %zd (%zd)\n", \ state->data_stack_base-size, size)); \ state->data_stack_base -= size; \ } while(0) @@ -574,8 +573,7 @@ entrance: /* optimization info block */ /* <1=skip> <2=flags> <3=min> ... */ if (ctx->pattern[3] && (uintptr_t)(end - ctx->ptr) < ctx->pattern[3]) { - TRACE(("reject (got %" PY_FORMAT_SIZE_T "d chars, " - "need %" PY_FORMAT_SIZE_T "d)\n", + TRACE(("reject (got %zd chars, need %zd)\n", end - ctx->ptr, (Py_ssize_t) ctx->pattern[3])); RETURN_FAILURE; } @@ -1025,7 +1023,7 @@ entrance: ctx->count = ctx->u.rep->count+1; - TRACE(("|%p|%p|MAX_UNTIL %" PY_FORMAT_SIZE_T "d\n", ctx->pattern, + TRACE(("|%p|%p|MAX_UNTIL %zd\n", ctx->pattern, ctx->ptr, ctx->count)); if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) { @@ -1088,7 +1086,7 @@ entrance: ctx->count = ctx->u.rep->count+1; - TRACE(("|%p|%p|MIN_UNTIL %" PY_FORMAT_SIZE_T "d %p\n", ctx->pattern, + TRACE(("|%p|%p|MIN_UNTIL %zd %p\n", ctx->pattern, ctx->ptr, ctx->count, ctx->u.rep->pattern)); if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) { @@ -1355,7 +1353,7 @@ exit: TRACE(("|%p|%p|JUMP_ASSERT_NOT\n", ctx->pattern, ctx->ptr)); goto jump_assert_not; case JUMP_NONE: - TRACE(("|%p|%p|RETURN %" PY_FORMAT_SIZE_T "d\n", ctx->pattern, + TRACE(("|%p|%p|RETURN %zd\n", ctx->pattern, ctx->ptr, ret)); break; } @@ -1417,7 +1415,7 @@ SRE(search)(SRE_STATE* state, SRE_CODE* pattern) pattern += 1 + pattern[1]; } - TRACE(("prefix = %p %" PY_FORMAT_SIZE_T "d %" PY_FORMAT_SIZE_T "d\n", + TRACE(("prefix = %p %zd %zd\n", prefix, prefix_len, prefix_skip)); TRACE(("charset = %p\n", charset)); diff --git a/Modules/xxlimited.c b/Modules/xxlimited.c index 7ce0b6ec880..5b05a9454a0 100644 --- a/Modules/xxlimited.c +++ b/Modules/xxlimited.c @@ -43,6 +43,7 @@ newXxoObject(PyObject *arg) static int Xxo_traverse(XxoObject *self, visitproc visit, void *arg) { + Py_VISIT(Py_TYPE(self)); Py_VISIT(self->x_attr); return 0; } diff --git a/Objects/abstract.c b/Objects/abstract.c index e8198492c63..3494f33ce38 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -3,7 +3,7 @@ #include "Python.h" #include "pycore_abstract.h" // _PyIndex_Check() #include "pycore_ceval.h" // _Py_EnterRecursiveCall() -#include "pycore_pyerrors.h" +#include "pycore_pyerrors.h" // _PyErr_Occurred() #include "pycore_pystate.h" // _PyThreadState_GET() #include #include // offsetof() @@ -23,9 +23,11 @@ type_error(const char *msg, PyObject *obj) static PyObject * null_error(void) { - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_SystemError, - "null argument to internal routine"); + PyThreadState *tstate = _PyThreadState_GET(); + if (!_PyErr_Occurred(tstate)) { + _PyErr_SetString(tstate, PyExc_SystemError, + "null argument to internal routine"); + } return NULL; } @@ -94,11 +96,12 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) if (_PyObject_HasLen(o)) { res = PyObject_Length(o); if (res < 0) { - assert(PyErr_Occurred()); - if (!PyErr_ExceptionMatches(PyExc_TypeError)) { + PyThreadState *tstate = _PyThreadState_GET(); + assert(_PyErr_Occurred(tstate)); + if (!_PyErr_ExceptionMatches(tstate, PyExc_TypeError)) { return -1; } - PyErr_Clear(); + _PyErr_Clear(tstate); } else { return res; @@ -114,8 +117,9 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) result = _PyObject_CallNoArg(hint); Py_DECREF(hint); if (result == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) { - PyErr_Clear(); + PyThreadState *tstate = _PyThreadState_GET(); + if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError)) { + _PyErr_Clear(tstate); return defaultvalue; } return -1; @@ -288,85 +292,6 @@ PyObject_CheckBuffer(PyObject *obj) } -/* We release the buffer right after use of this function which could - cause issues later on. Don't use these functions in new code. - */ -int -PyObject_CheckReadBuffer(PyObject *obj) -{ - PyBufferProcs *pb = Py_TYPE(obj)->tp_as_buffer; - Py_buffer view; - - if (pb == NULL || - pb->bf_getbuffer == NULL) - return 0; - if ((*pb->bf_getbuffer)(obj, &view, PyBUF_SIMPLE) == -1) { - PyErr_Clear(); - return 0; - } - PyBuffer_Release(&view); - return 1; -} - -static int -as_read_buffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len) -{ - Py_buffer view; - - if (obj == NULL || buffer == NULL || buffer_len == NULL) { - null_error(); - return -1; - } - if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) != 0) - return -1; - - *buffer = view.buf; - *buffer_len = view.len; - PyBuffer_Release(&view); - return 0; -} - -int -PyObject_AsCharBuffer(PyObject *obj, - const char **buffer, - Py_ssize_t *buffer_len) -{ - return as_read_buffer(obj, (const void **)buffer, buffer_len); -} - -int PyObject_AsReadBuffer(PyObject *obj, - const void **buffer, - Py_ssize_t *buffer_len) -{ - return as_read_buffer(obj, buffer, buffer_len); -} - -int PyObject_AsWriteBuffer(PyObject *obj, - void **buffer, - Py_ssize_t *buffer_len) -{ - PyBufferProcs *pb; - Py_buffer view; - - if (obj == NULL || buffer == NULL || buffer_len == NULL) { - null_error(); - return -1; - } - pb = Py_TYPE(obj)->tp_as_buffer; - if (pb == NULL || - pb->bf_getbuffer == NULL || - ((*pb->bf_getbuffer)(obj, &view, PyBUF_WRITABLE) != 0)) { - PyErr_SetString(PyExc_TypeError, - "expected a writable bytes-like object"); - return -1; - } - - *buffer = view.buf; - *buffer_len = view.len; - PyBuffer_Release(&view); - return 0; -} - /* Buffer C-API for Python 3.0 */ int @@ -708,7 +633,7 @@ PyBuffer_FillInfo(Py_buffer *view, PyObject *obj, void *buf, Py_ssize_t len, { if (view == NULL) { PyErr_SetString(PyExc_BufferError, - "PyBuffer_FillInfo: view==NULL argument is obsolete"); + "PyBuffer_FillInfo: view==NULL argument is obsolete"); return -1; } @@ -790,10 +715,12 @@ PyObject_Format(PyObject *obj, PyObject *format_spec) /* Find the (unbound!) __format__ method */ meth = _PyObject_LookupSpecial(obj, &PyId___format__); if (meth == NULL) { - if (!PyErr_Occurred()) - PyErr_Format(PyExc_TypeError, - "Type %.100s doesn't define __format__", - Py_TYPE(obj)->tp_name); + PyThreadState *tstate = _PyThreadState_GET(); + if (!_PyErr_Occurred(tstate)) { + _PyErr_Format(tstate, PyExc_TypeError, + "Type %.100s doesn't define __format__", + Py_TYPE(obj)->tp_name); + } goto done; } @@ -803,8 +730,8 @@ PyObject_Format(PyObject *obj, PyObject *format_spec) if (result && !PyUnicode_Check(result)) { PyErr_Format(PyExc_TypeError, - "__format__ must return a str, not %.200s", - Py_TYPE(result)->tp_name); + "__format__ must return a str, not %.200s", + Py_TYPE(result)->tp_name); Py_DECREF(result); result = NULL; goto done; @@ -1317,11 +1244,12 @@ PyIndex_Check(PyObject *obj) /* Return a Python int from the object item. + Can return an instance of int subclass. Raise TypeError if the result is not an int or if the object cannot be interpreted as an index. */ PyObject * -PyNumber_Index(PyObject *item) +_PyNumber_Index(PyObject *item) { PyObject *result = NULL; if (item == NULL) { @@ -1360,6 +1288,20 @@ PyNumber_Index(PyObject *item) return result; } +/* Return an exact Python int from the object item. + Raise TypeError if the result is not an int + or if the object cannot be interpreted as an index. +*/ +PyObject * +PyNumber_Index(PyObject *item) +{ + PyObject *result = _PyNumber_Index(item); + if (result != NULL && !PyLong_CheckExact(result)) { + Py_SETREF(result, _PyLong_Copy((PyLongObject *)result)); + } + return result; +} + /* Return an error on Overflow only if err is not NULL*/ Py_ssize_t @@ -1367,23 +1309,29 @@ PyNumber_AsSsize_t(PyObject *item, PyObject *err) { Py_ssize_t result; PyObject *runerr; - PyObject *value = PyNumber_Index(item); + PyObject *value = _PyNumber_Index(item); if (value == NULL) return -1; /* We're done if PyLong_AsSsize_t() returns without error. */ result = PyLong_AsSsize_t(value); - if (result != -1 || !(runerr = PyErr_Occurred())) + if (result != -1) goto finish; + PyThreadState *tstate = _PyThreadState_GET(); + runerr = _PyErr_Occurred(tstate); + if (!runerr) { + goto finish; + } + /* Error handling code -- only manage OverflowError differently */ - if (!PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) + if (!PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) { goto finish; + } + _PyErr_Clear(tstate); - PyErr_Clear(); /* If no error-handling desired then the default clipping - is sufficient. - */ + is sufficient. */ if (!err) { assert(PyLong_Check(value)); /* Whether or not it is less than or equal to @@ -1396,9 +1344,9 @@ PyNumber_AsSsize_t(PyObject *item, PyObject *err) } else { /* Otherwise replace the error with caller's error object. */ - PyErr_Format(err, - "cannot fit '%.200s' into an index-sized integer", - Py_TYPE(item)->tp_name); + _PyErr_Format(tstate, err, + "cannot fit '%.200s' into an index-sized integer", + Py_TYPE(item)->tp_name); } finish: @@ -1433,8 +1381,8 @@ PyNumber_Long(PyObject *o) return result; if (!PyLong_Check(result)) { PyErr_Format(PyExc_TypeError, - "__int__ returned non-int (type %.200s)", - result->ob_type->tp_name); + "__int__ returned non-int (type %.200s)", + result->ob_type->tp_name); Py_DECREF(result); return NULL; } @@ -1451,11 +1399,7 @@ PyNumber_Long(PyObject *o) return result; } if (m && m->nb_index) { - result = PyNumber_Index(o); - if (result != NULL && !PyLong_CheckExact(result)) { - Py_SETREF(result, _PyLong_Copy((PyLongObject *)result)); - } - return result; + return PyNumber_Index(o); } trunc_func = _PyObject_LookupSpecial(o, &PyId___trunc__); if (trunc_func) { @@ -1479,16 +1423,13 @@ PyNumber_Long(PyObject *o) return NULL; } Py_SETREF(result, PyNumber_Index(result)); - if (result != NULL && !PyLong_CheckExact(result)) { - Py_SETREF(result, _PyLong_Copy((PyLongObject *)result)); - } return result; } if (PyErr_Occurred()) return NULL; if (PyUnicode_Check(o)) - /* The below check is done in PyLong_FromUnicode(). */ + /* The below check is done in PyLong_FromUnicodeObject(). */ return PyLong_FromUnicodeObject(o, 10); if (PyBytes_Check(o)) @@ -1564,7 +1505,7 @@ PyNumber_Float(PyObject *o) return PyFloat_FromDouble(val); } if (m && m->nb_index) { - PyObject *res = PyNumber_Index(o); + PyObject *res = _PyNumber_Index(o); if (!res) { return NULL; } @@ -1590,7 +1531,7 @@ PyNumber_ToBase(PyObject *n, int base) "PyNumber_ToBase: base must be 2, 8, 10 or 16"); return NULL; } - PyObject *index = PyNumber_Index(n); + PyObject *index = _PyNumber_Index(n); if (!index) return NULL; PyObject *res = _PyLong_Format(index, base); @@ -2044,8 +1985,10 @@ PySequence_Fast(PyObject *v, const char *m) it = PyObject_GetIter(v); if (it == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) - PyErr_SetString(PyExc_TypeError, m); + PyThreadState *tstate = _PyThreadState_GET(); + if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError)) { + _PyErr_SetString(tstate, PyExc_TypeError, m); + } return NULL; } @@ -2075,7 +2018,9 @@ _PySequence_IterSearch(PyObject *seq, PyObject *obj, int operation) it = PyObject_GetIter(seq); if (it == NULL) { - type_error("argument of type '%.200s' is not iterable", seq); + if (PyErr_ExceptionMatches(PyExc_TypeError)) { + type_error("argument of type '%.200s' is not iterable", seq); + } return -1; } @@ -2300,12 +2245,13 @@ method_output_as_list(PyObject *o, _Py_Identifier *meth_id) } it = PyObject_GetIter(meth_output); if (it == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) { - PyErr_Format(PyExc_TypeError, - "%.200s.%U() returned a non-iterable (type %.200s)", - Py_TYPE(o)->tp_name, - _PyUnicode_FromId(meth_id), - Py_TYPE(meth_output)->tp_name); + PyThreadState *tstate = _PyThreadState_GET(); + if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError)) { + _PyErr_Format(tstate, PyExc_TypeError, + "%.200s.%U() returned a non-iterable (type %.200s)", + Py_TYPE(o)->tp_name, + _PyUnicode_FromId(meth_id), + Py_TYPE(meth_output)->tp_name); } Py_DECREF(meth_output); return NULL; @@ -2450,8 +2396,10 @@ check_class(PyObject *cls, const char *error) PyObject *bases = abstract_get_bases(cls); if (bases == NULL) { /* Do not mask errors. */ - if (!PyErr_Occurred()) - PyErr_SetString(PyExc_TypeError, error); + PyThreadState *tstate = _PyThreadState_GET(); + if (!_PyErr_Occurred(tstate)) { + _PyErr_SetString(tstate, PyExc_TypeError, error); + } return 0; } Py_DECREF(bases); @@ -2709,10 +2657,14 @@ PyIter_Next(PyObject *iter) { PyObject *result; result = (*Py_TYPE(iter)->tp_iternext)(iter); - if (result == NULL && - PyErr_Occurred() && - PyErr_ExceptionMatches(PyExc_StopIteration)) - PyErr_Clear(); + if (result == NULL) { + PyThreadState *tstate = _PyThreadState_GET(); + if (_PyErr_Occurred(tstate) + && _PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) + { + _PyErr_Clear(tstate); + } + } return result; } diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 5a803be6277..83c79b200a0 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -22,22 +22,15 @@ char _PyByteArray_empty_string[] = ""; static int _getbytevalue(PyObject* arg, int *value) { - long face_value; + int overflow; + long face_value = PyLong_AsLongAndOverflow(arg, &overflow); - if (PyLong_Check(arg)) { - face_value = PyLong_AsLong(arg); - } else { - PyObject *index = PyNumber_Index(arg); - if (index == NULL) { - *value = -1; - return 0; - } - face_value = PyLong_AsLong(index); - Py_DECREF(index); + if (face_value == -1 && PyErr_Occurred()) { + *value = -1; + return 0; } - if (face_value < 0 || face_value >= 256) { - /* this includes the OverflowError in case the long is too large */ + /* this includes an overflow in converting to C long */ PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); *value = -1; return 0; diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 25d9814dd6d..7632cb5e4dd 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -4,8 +4,9 @@ #include "Python.h" #include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_bytes_methods.h" -#include "pycore_object.h" +#include "pycore_bytes_methods.h" // _Py_bytes_startswith() +#include "pycore_initconfig.h" // _PyStatus_OK() +#include "pycore_object.h" // _PyObject_GC_TRACK #include "pycore_pymem.h" // PYMEM_CLEANBYTE #include "pystrhex.h" @@ -18,9 +19,6 @@ class bytes "PyBytesObject *" "&PyBytes_Type" #include "clinic/bytesobject.c.h" -static PyBytesObject *characters[UCHAR_MAX + 1]; -static PyBytesObject *nullstring; - _Py_IDENTIFIER(__bytes__); /* PyBytesObject_SIZE gives the basic size of a string; any memory allocation @@ -35,6 +33,53 @@ _Py_IDENTIFIER(__bytes__); Py_LOCAL_INLINE(Py_ssize_t) _PyBytesWriter_GetSize(_PyBytesWriter *writer, char *str); + +static struct _Py_bytes_state* +get_bytes_state(void) +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + return &interp->bytes; +} + + +// Return a borrowed reference to the empty bytes string singleton. +static inline PyObject* bytes_get_empty(void) +{ + struct _Py_bytes_state *state = get_bytes_state(); + // bytes_get_empty() must not be called before _PyBytes_Init() + // or after _PyBytes_Fini() + assert(state->empty_string != NULL); + return state->empty_string; +} + + +// Return a strong reference to the empty bytes string singleton. +static inline PyObject* bytes_new_empty(void) +{ + PyObject *empty = bytes_get_empty(); + Py_INCREF(empty); + return (PyObject *)empty; +} + + +static int +bytes_create_empty_string_singleton(struct _Py_bytes_state *state) +{ + // Create the empty bytes string singleton + PyBytesObject *op = (PyBytesObject *)PyObject_Malloc(PyBytesObject_SIZE); + if (op == NULL) { + return -1; + } + _PyObject_InitVar((PyVarObject*)op, &PyBytes_Type, 0); + op->ob_shash = -1; + op->ob_sval[0] = '\0'; + + assert(state->empty_string == NULL); + state->empty_string = (PyObject *)op; + return 0; +} + + /* For PyBytes_FromString(), the parameter `str' points to a null-terminated string containing exactly `size' bytes. @@ -63,9 +108,8 @@ _PyBytes_FromSize(Py_ssize_t size, int use_calloc) PyBytesObject *op; assert(size >= 0); - if (size == 0 && (op = nullstring) != NULL) { - Py_INCREF(op); - return (PyObject *)op; + if (size == 0) { + return bytes_new_empty(); } if ((size_t)size > (size_t)PY_SSIZE_T_MAX - PyBytesObject_SIZE) { @@ -79,16 +123,13 @@ _PyBytes_FromSize(Py_ssize_t size, int use_calloc) op = (PyBytesObject *)PyObject_Calloc(1, PyBytesObject_SIZE + size); else op = (PyBytesObject *)PyObject_Malloc(PyBytesObject_SIZE + size); - if (op == NULL) + if (op == NULL) { return PyErr_NoMemory(); - (void)PyObject_INIT_VAR(op, &PyBytes_Type, size); + } + _PyObject_InitVar((PyVarObject*)op, &PyBytes_Type, size); op->ob_shash = -1; - if (!use_calloc) + if (!use_calloc) { op->ob_sval[size] = '\0'; - /* empty byte string singleton */ - if (size == 0) { - nullstring = op; - Py_INCREF(op); } return (PyObject *) op; } @@ -102,11 +143,16 @@ PyBytes_FromStringAndSize(const char *str, Py_ssize_t size) "Negative size passed to PyBytes_FromStringAndSize"); return NULL; } - if (size == 1 && str != NULL && - (op = characters[*str & UCHAR_MAX]) != NULL) - { - Py_INCREF(op); - return (PyObject *)op; + if (size == 1 && str != NULL) { + struct _Py_bytes_state *state = get_bytes_state(); + op = state->characters[*str & UCHAR_MAX]; + if (op != NULL) { + Py_INCREF(op); + return (PyObject *)op; + } + } + if (size == 0) { + return bytes_new_empty(); } op = (PyBytesObject *)_PyBytes_FromSize(size, 0); @@ -118,8 +164,9 @@ PyBytes_FromStringAndSize(const char *str, Py_ssize_t size) memcpy(op->ob_sval, str, size); /* share short strings */ if (size == 1) { - characters[*str & UCHAR_MAX] = op; + struct _Py_bytes_state *state = get_bytes_state(); Py_INCREF(op); + state->characters[*str & UCHAR_MAX] = op; } return (PyObject *) op; } @@ -137,29 +184,32 @@ PyBytes_FromString(const char *str) "byte string is too long"); return NULL; } - if (size == 0 && (op = nullstring) != NULL) { - Py_INCREF(op); - return (PyObject *)op; + + struct _Py_bytes_state *state = get_bytes_state(); + if (size == 0) { + return bytes_new_empty(); } - if (size == 1 && (op = characters[*str & UCHAR_MAX]) != NULL) { - Py_INCREF(op); - return (PyObject *)op; + else if (size == 1) { + op = state->characters[*str & UCHAR_MAX]; + if (op != NULL) { + Py_INCREF(op); + return (PyObject *)op; + } } /* Inline PyObject_NewVar */ op = (PyBytesObject *)PyObject_MALLOC(PyBytesObject_SIZE + size); - if (op == NULL) + if (op == NULL) { return PyErr_NoMemory(); - (void)PyObject_INIT_VAR(op, &PyBytes_Type, size); + } + _PyObject_InitVar((PyVarObject*)op, &PyBytes_Type, size); op->ob_shash = -1; memcpy(op->ob_sval, str, size+1); /* share short strings */ - if (size == 0) { - nullstring = op; - Py_INCREF(op); - } else if (size == 1) { - characters[*str & UCHAR_MAX] = op; + if (size == 1) { + assert(state->characters[*str & UCHAR_MAX] == NULL); Py_INCREF(op); + state->characters[*str & UCHAR_MAX] = op; } return (PyObject *) op; } @@ -256,27 +306,29 @@ PyBytes_FromFormatV(const char *format, va_list vargs) } case 'd': - if (longflag) + if (longflag) { sprintf(buffer, "%ld", va_arg(vargs, long)); - else if (size_tflag) - sprintf(buffer, "%" PY_FORMAT_SIZE_T "d", - va_arg(vargs, Py_ssize_t)); - else + } + else if (size_tflag) { + sprintf(buffer, "%zd", va_arg(vargs, Py_ssize_t)); + } + else { sprintf(buffer, "%d", va_arg(vargs, int)); + } assert(strlen(buffer) < sizeof(buffer)); WRITE_BYTES(buffer); break; case 'u': - if (longflag) - sprintf(buffer, "%lu", - va_arg(vargs, unsigned long)); - else if (size_tflag) - sprintf(buffer, "%" PY_FORMAT_SIZE_T "u", - va_arg(vargs, size_t)); - else - sprintf(buffer, "%u", - va_arg(vargs, unsigned int)); + if (longflag) { + sprintf(buffer, "%lu", va_arg(vargs, unsigned long)); + } + else if (size_tflag) { + sprintf(buffer, "%zu", va_arg(vargs, size_t)); + } + else { + sprintf(buffer, "%u", va_arg(vargs, unsigned int)); + } assert(strlen(buffer) < sizeof(buffer)); WRITE_BYTES(buffer); break; @@ -455,20 +507,17 @@ formatlong(PyObject *v, int flags, int prec, int type) if (PyNumber_Check(v)) { /* make sure number is a type of integer for o, x, and X */ if (type == 'o' || type == 'x' || type == 'X') - iobj = PyNumber_Index(v); + iobj = _PyNumber_Index(v); else iobj = PyNumber_Long(v); - if (iobj == NULL) { - if (!PyErr_ExceptionMatches(PyExc_TypeError)) - return NULL; - } - else if (!PyLong_Check(iobj)) - Py_CLEAR(iobj); if (iobj != NULL) { + assert(PyLong_Check(iobj)); result = _PyUnicode_FormatLong(iobj, flags & F_ALT, prec, type); Py_DECREF(iobj); return result; } + if (!PyErr_ExceptionMatches(PyExc_TypeError)) + return NULL; } PyErr_Format(PyExc_TypeError, "%%%c format: %s is required, not %.200s", type, @@ -490,26 +539,16 @@ byte_converter(PyObject *arg, char *p) return 1; } else { - PyObject *iobj; - long ival; int overflow; - /* make sure number is a type of integer */ - if (PyLong_Check(arg)) { - ival = PyLong_AsLongAndOverflow(arg, &overflow); - } - else { - iobj = PyNumber_Index(arg); - if (iobj == NULL) { - if (!PyErr_ExceptionMatches(PyExc_TypeError)) - return 0; + long ival = PyLong_AsLongAndOverflow(arg, &overflow); + if (ival == -1 && PyErr_Occurred()) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) { goto onError; } - ival = PyLong_AsLongAndOverflow(iobj, &overflow); - Py_DECREF(iobj); + return 0; } - if (!overflow && ival == -1 && PyErr_Occurred()) - goto onError; - if (overflow || !(0 <= ival && ival <= 255)) { + if (!(0 <= ival && ival <= 255)) { + /* this includes an overflow in converting to C long */ PyErr_SetString(PyExc_OverflowError, "%c arg not in range(256)"); return 0; @@ -1245,6 +1284,8 @@ PyBytes_AsStringAndSize(PyObject *obj, /* -------------------------------------------------------------------- */ /* Methods */ +#define STRINGLIB_GET_EMPTY() bytes_get_empty() + #include "stringlib/stringdefs.h" #include "stringlib/fastsearch.h" @@ -1257,6 +1298,8 @@ PyBytes_AsStringAndSize(PyObject *obj, #include "stringlib/transmogrify.h" +#undef STRINGLIB_GET_EMPTY + PyObject * PyBytes_Repr(PyObject *obj, int smartquotes) { @@ -1433,9 +1476,10 @@ bytes_repeat(PyBytesObject *a, Py_ssize_t n) return NULL; } op = (PyBytesObject *)PyObject_MALLOC(PyBytesObject_SIZE + nbytes); - if (op == NULL) + if (op == NULL) { return PyErr_NoMemory(); - (void)PyObject_INIT_VAR(op, &PyBytes_Type, size); + } + _PyObject_InitVar((PyVarObject*)op, &PyBytes_Type, size); op->ob_shash = -1; op->ob_sval[size] = '\0'; if (Py_SIZE(a) == 1 && n > 0) { @@ -3021,9 +3065,9 @@ _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize) goto error; } if (newsize == 0) { - *pv = _PyBytes_FromSize(0, 0); + *pv = bytes_new_empty(); Py_DECREF(v); - return (*pv == NULL) ? -1 : 0; + return 0; } /* XXX UNREF/NEWREF interface should be more symmetrical */ #ifdef Py_REF_DEBUG @@ -3052,13 +3096,26 @@ error: return -1; } -void -_PyBytes_Fini(void) + +PyStatus +_PyBytes_Init(PyThreadState *tstate) { - int i; - for (i = 0; i < UCHAR_MAX + 1; i++) - Py_CLEAR(characters[i]); - Py_CLEAR(nullstring); + struct _Py_bytes_state *state = &tstate->interp->bytes; + if (bytes_create_empty_string_singleton(state) < 0) { + return _PyStatus_NO_MEMORY(); + } + return _PyStatus_OK(); +} + + +void +_PyBytes_Fini(PyThreadState *tstate) +{ + struct _Py_bytes_state* state = &tstate->interp->bytes; + for (int i = 0; i < UCHAR_MAX + 1; i++) { + Py_CLEAR(state->characters[i]); + } + Py_CLEAR(state->empty_string); } /*********************** Bytes Iterator ****************************/ diff --git a/Objects/call.c b/Objects/call.c index 61426c7e09e..30fa14ccfd7 100644 --- a/Objects/call.c +++ b/Objects/call.c @@ -1,11 +1,11 @@ #include "Python.h" -#include "pycore_call.h" -#include "pycore_ceval.h" // _PyEval_EvalFrame() -#include "pycore_object.h" -#include "pycore_pyerrors.h" -#include "pycore_pystate.h" // _PyThreadState_GET() -#include "pycore_tupleobject.h" -#include "frameobject.h" +#include "pycore_call.h" // _PyObject_CallNoArgTstate() +#include "pycore_ceval.h" // _PyEval_EvalFrame() +#include "pycore_object.h" // _PyObject_GC_TRACK() +#include "pycore_pyerrors.h" // _PyErr_Occurred() +#include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_tuple.h" // _PyTuple_ITEMS() +#include "frameobject.h" // _PyFrame_New_NoTrack() static PyObject *const * diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index 83b0d03c569..cbe6f20344e 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -270,7 +270,7 @@ bytearray_replace(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nar } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -343,7 +343,7 @@ bytearray_split(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -442,7 +442,7 @@ bytearray_rsplit(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -506,7 +506,7 @@ bytearray_insert(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -599,7 +599,7 @@ bytearray_pop(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -1051,4 +1051,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) { return bytearray_sizeof_impl(self); } -/*[clinic end generated code: output=920748990279fb9d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0cd59180c7d5dce5 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h index c4a2d0c3626..201627eee23 100644 --- a/Objects/clinic/bytesobject.c.h +++ b/Objects/clinic/bytesobject.c.h @@ -48,7 +48,7 @@ bytes_split(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -199,7 +199,7 @@ bytes_rsplit(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -485,7 +485,7 @@ bytes_replace(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -809,4 +809,4 @@ skip_optional_pos: exit: return return_value; } -/*[clinic end generated code: output=a0c31faea2671a8c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=dc1bc13e6990e452 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h index 82884a42b57..01e31d76cfa 100644 --- a/Objects/clinic/listobject.c.h +++ b/Objects/clinic/listobject.c.h @@ -26,7 +26,7 @@ list_insert(PyListObject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -125,7 +125,7 @@ list_pop(PyListObject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -352,4 +352,4 @@ list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored)) { return list___reversed___impl(self); } -/*[clinic end generated code: output=137db7b11196b581 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0063aad535edf62d input=a9049054013a1b77]*/ diff --git a/Objects/clinic/longobject.c.h b/Objects/clinic/longobject.c.h index d3d5c1992b3..cf388c50f5a 100644 --- a/Objects/clinic/longobject.c.h +++ b/Objects/clinic/longobject.c.h @@ -138,6 +138,31 @@ int_bit_length(PyObject *self, PyObject *Py_UNUSED(ignored)) return int_bit_length_impl(self); } +PyDoc_STRVAR(int_bit_count__doc__, +"bit_count($self, /)\n" +"--\n" +"\n" +"Number of ones in the binary representation of the absolute value of self.\n" +"\n" +"Also known as the population count.\n" +"\n" +">>> bin(13)\n" +"\'0b1101\'\n" +">>> (13).bit_count()\n" +"3"); + +#define INT_BIT_COUNT_METHODDEF \ + {"bit_count", (PyCFunction)int_bit_count, METH_NOARGS, int_bit_count__doc__}, + +static PyObject * +int_bit_count_impl(PyObject *self); + +static PyObject * +int_bit_count(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + return int_bit_count_impl(self); +} + PyDoc_STRVAR(int_as_integer_ratio__doc__, "as_integer_ratio($self, /)\n" "--\n" @@ -211,7 +236,7 @@ int_to_bytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject * } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -308,4 +333,4 @@ skip_optional_kwonly: exit: return return_value; } -/*[clinic end generated code: output=46d40c8aa6d420b7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4257cfdb155efd00 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index 2d81730d687..ecd409e84cb 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -88,7 +88,7 @@ unicode_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -522,7 +522,7 @@ unicode_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -717,7 +717,7 @@ unicode_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -831,7 +831,7 @@ unicode_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -900,7 +900,7 @@ unicode_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -997,7 +997,7 @@ unicode_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[1]); + PyObject *iobj = _PyNumber_Index(args[1]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -1193,7 +1193,7 @@ unicode_zfill(PyObject *self, PyObject *arg) { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(arg); + PyObject *iobj = _PyNumber_Index(arg); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -1258,4 +1258,4 @@ unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return unicode_sizeof_impl(self); } -/*[clinic end generated code: output=ea1aff10c743be14 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c5eb21e314da78b8 input=a9049054013a1b77]*/ diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 737635943ac..49011db1014 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -4,10 +4,10 @@ #include "code.h" #include "opcode.h" #include "structmember.h" // PyMemberDef -#include "pycore_code.h" +#include "pycore_code.h" // _PyOpcache #include "pycore_interp.h" // PyInterpreterState.co_extra_freefuncs #include "pycore_pystate.h" // _PyInterpreterState_GET() -#include "pycore_tupleobject.h" +#include "pycore_tuple.h" // _PyTuple_ITEMS() #include "clinic/codeobject.c.h" /* Holder for co_extra information */ @@ -166,6 +166,14 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, return NULL; } + /* Make sure that code is indexable with an int, this is + a long running assumption in ceval.c and many parts of + the interpreter. */ + if (PyBytes_GET_SIZE(code) > INT_MAX) { + PyErr_SetString(PyExc_OverflowError, "co_code larger than INT_MAX"); + return NULL; + } + /* Check for any inner or outer closure references */ n_cellvars = PyTuple_GET_SIZE(cellvars); if (!n_cellvars && !PyTuple_GET_SIZE(freevars)) { diff --git a/Objects/complexobject.c b/Objects/complexobject.c index a49037783be..d983a30901d 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -6,8 +6,10 @@ /* Submitted by Jim Hugunin */ #include "Python.h" +#include "pycore_object.h" // _PyObject_Init() #include "structmember.h" // PyMemberDef + /*[clinic input] class complex "PyComplexObject *" "&PyComplex_Type" [clinic start generated code]*/ @@ -229,13 +231,12 @@ complex_subtype_from_c_complex(PyTypeObject *type, Py_complex cval) PyObject * PyComplex_FromCComplex(Py_complex cval) { - PyComplexObject *op; - /* Inline PyObject_New */ - op = (PyComplexObject *) PyObject_MALLOC(sizeof(PyComplexObject)); - if (op == NULL) + PyComplexObject *op = PyObject_MALLOC(sizeof(PyComplexObject)); + if (op == NULL) { return PyErr_NoMemory(); - (void)PyObject_INIT(op, &PyComplex_Type); + } + _PyObject_Init((PyObject*)op, &PyComplex_Type); op->cval = cval; return (PyObject *) op; } diff --git a/Objects/descrobject.c b/Objects/descrobject.c index fce9cdd3090..a8ce13c7aa4 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -1,10 +1,10 @@ /* Descriptors -- a new, flexible way to describe attributes */ #include "Python.h" -#include "pycore_ceval.h" // _Py_EnterRecursiveCall() -#include "pycore_object.h" -#include "pycore_pystate.h" // _PyThreadState_GET() -#include "pycore_tupleobject.h" +#include "pycore_ceval.h" // _Py_EnterRecursiveCall() +#include "pycore_object.h" // _PyObject_GC_UNTRACK() +#include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_tuple.h" // _PyTuple_ITEMS() #include "structmember.h" // PyMemberDef _Py_IDENTIFIER(getattr); diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 809a5ed7787..b1f11b3e695 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -112,7 +112,8 @@ converting the dict to the combined table. #include "Python.h" #include "pycore_gc.h" // _PyObject_GC_IS_TRACKED() -#include "pycore_object.h" +#include "pycore_object.h" // _PyObject_GC_TRACK() +#include "pycore_pyerrors.h" // _PyErr_Fetch() #include "pycore_pystate.h" // _PyThreadState_GET() #include "dict-common.h" #include "stringlib/eq.h" // unicode_eq() @@ -246,58 +247,54 @@ static uint64_t pydict_global_version = 0; #define DICT_NEXT_VERSION() (++pydict_global_version) -/* Dictionary reuse scheme to save calls to malloc and free */ -#ifndef PyDict_MAXFREELIST -#define PyDict_MAXFREELIST 80 -#endif - -/* bpo-40521: dict free lists are shared by all interpreters. */ -#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS -# undef PyDict_MAXFREELIST -# define PyDict_MAXFREELIST 0 -#endif - -#if PyDict_MAXFREELIST > 0 -static PyDictObject *free_list[PyDict_MAXFREELIST]; -static int numfree = 0; -static PyDictKeysObject *keys_free_list[PyDict_MAXFREELIST]; -static int numfreekeys = 0; -#endif - #include "clinic/dictobject.c.h" -void -_PyDict_ClearFreeList(void) + +static struct _Py_dict_state * +get_dict_state(void) { -#if PyDict_MAXFREELIST > 0 - while (numfree) { - PyDictObject *op = free_list[--numfree]; + PyInterpreterState *interp = _PyInterpreterState_GET(); + return &interp->dict_state; +} + + +void +_PyDict_ClearFreeList(PyThreadState *tstate) +{ + struct _Py_dict_state *state = &tstate->interp->dict_state; + while (state->numfree) { + PyDictObject *op = state->free_list[--state->numfree]; assert(PyDict_CheckExact(op)); PyObject_GC_Del(op); } - while (numfreekeys) { - PyObject_FREE(keys_free_list[--numfreekeys]); + while (state->keys_numfree) { + PyObject_FREE(state->keys_free_list[--state->keys_numfree]); } +} + + +void +_PyDict_Fini(PyThreadState *tstate) +{ + _PyDict_ClearFreeList(tstate); +#ifdef Py_DEBUG + struct _Py_dict_state *state = get_dict_state(); + state->numfree = -1; + state->keys_numfree = -1; #endif } + /* Print summary info about the state of the optimized allocator */ void _PyDict_DebugMallocStats(FILE *out) { -#if PyDict_MAXFREELIST > 0 - _PyDebugAllocatorStats(out, - "free PyDictObject", numfree, sizeof(PyDictObject)); -#endif + struct _Py_dict_state *state = get_dict_state(); + _PyDebugAllocatorStats(out, "free PyDictObject", + state->numfree, sizeof(PyDictObject)); } -void -_PyDict_Fini(void) -{ - _PyDict_ClearFreeList(); -} - #define DK_SIZE(dk) ((dk)->dk_size) #if SIZEOF_VOID_P > 4 #define DK_IXSIZE(dk) \ @@ -542,7 +539,8 @@ _PyDict_CheckConsistency(PyObject *op, int check_content) } -static PyDictKeysObject *new_keys_object(Py_ssize_t size) +static PyDictKeysObject* +new_keys_object(Py_ssize_t size) { PyDictKeysObject *dk; Py_ssize_t es, usable; @@ -566,12 +564,15 @@ static PyDictKeysObject *new_keys_object(Py_ssize_t size) es = sizeof(Py_ssize_t); } -#if PyDict_MAXFREELIST > 0 - if (size == PyDict_MINSIZE && numfreekeys > 0) { - dk = keys_free_list[--numfreekeys]; + struct _Py_dict_state *state = get_dict_state(); +#ifdef Py_DEBUG + // new_keys_object() must not be called after _PyDict_Fini() + assert(state->keys_numfree != -1); +#endif + if (size == PyDict_MINSIZE && state->keys_numfree > 0) { + dk = state->keys_free_list[--state->keys_numfree]; } else -#endif { dk = PyObject_MALLOC(sizeof(PyDictKeysObject) + es * size @@ -603,12 +604,15 @@ free_keys_object(PyDictKeysObject *keys) Py_XDECREF(entries[i].me_key); Py_XDECREF(entries[i].me_value); } -#if PyDict_MAXFREELIST > 0 - if (keys->dk_size == PyDict_MINSIZE && numfreekeys < PyDict_MAXFREELIST) { - keys_free_list[numfreekeys++] = keys; + struct _Py_dict_state *state = get_dict_state(); +#ifdef Py_DEBUG + // free_keys_object() must not be called after _PyDict_Fini() + assert(state->keys_numfree != -1); +#endif + if (keys->dk_size == PyDict_MINSIZE && state->keys_numfree < PyDict_MAXFREELIST) { + state->keys_free_list[state->keys_numfree++] = keys; return; } -#endif PyObject_FREE(keys); } @@ -621,16 +625,18 @@ new_dict(PyDictKeysObject *keys, PyObject **values) { PyDictObject *mp; assert(keys != NULL); -#if PyDict_MAXFREELIST > 0 - if (numfree) { - mp = free_list[--numfree]; + struct _Py_dict_state *state = get_dict_state(); +#ifdef Py_DEBUG + // new_dict() must not be called after _PyDict_Fini() + assert(state->numfree != -1); +#endif + if (state->numfree) { + mp = state->free_list[--state->numfree]; assert (mp != NULL); assert (Py_IS_TYPE(mp, &PyDict_Type)); _Py_NewReference((PyObject *)mp); } - else -#endif - { + else { mp = PyObject_GC_New(PyDictObject, &PyDict_Type); if (mp == NULL) { dictkeys_decref(keys); @@ -1279,15 +1285,17 @@ dictresize(PyDictObject *mp, Py_ssize_t minsize) #ifdef Py_REF_DEBUG _Py_RefTotal--; #endif -#if PyDict_MAXFREELIST > 0 - if (oldkeys->dk_size == PyDict_MINSIZE && - numfreekeys < PyDict_MAXFREELIST) - { - keys_free_list[numfreekeys++] = oldkeys; - } - else + struct _Py_dict_state *state = get_dict_state(); +#ifdef Py_DEBUG + // dictresize() must not be called after _PyDict_Fini() + assert(state->keys_numfree != -1); #endif + if (oldkeys->dk_size == PyDict_MINSIZE && + state->keys_numfree < PyDict_MAXFREELIST) { + state->keys_free_list[state->keys_numfree++] = oldkeys; + } + else { PyObject_FREE(oldkeys); } } @@ -1387,14 +1395,12 @@ _PyDict_NewPresized(Py_ssize_t minused) PyObject * PyDict_GetItem(PyObject *op, PyObject *key) { - Py_hash_t hash; - Py_ssize_t ix; - PyDictObject *mp = (PyDictObject *)op; - PyThreadState *tstate; - PyObject *value; - - if (!PyDict_Check(op)) + if (!PyDict_Check(op)) { return NULL; + } + PyDictObject *mp = (PyDictObject *)op; + + Py_hash_t hash; if (!PyUnicode_CheckExact(key) || (hash = ((PyASCIIObject *) key)->hash) == -1) { @@ -1405,28 +1411,26 @@ PyDict_GetItem(PyObject *op, PyObject *key) } } - /* We can arrive here with a NULL tstate during initialization: try - running "python -Wi" for an example related to string interning. - Let's just hope that no exception occurs then... This must be - _PyThreadState_GET() and not PyThreadState_Get() because the latter - abort Python if tstate is NULL. */ - tstate = _PyThreadState_GET(); - if (tstate != NULL && tstate->curexc_type != NULL) { - /* preserve the existing exception */ - PyObject *err_type, *err_value, *err_tb; - PyErr_Fetch(&err_type, &err_value, &err_tb); - ix = (mp->ma_keys->dk_lookup)(mp, key, hash, &value); - /* ignore errors */ - PyErr_Restore(err_type, err_value, err_tb); - if (ix < 0) - return NULL; - } - else { - ix = (mp->ma_keys->dk_lookup)(mp, key, hash, &value); - if (ix < 0) { - PyErr_Clear(); - return NULL; - } + PyThreadState *tstate = _PyThreadState_GET(); +#ifdef Py_DEBUG + // bpo-40839: Before Python 3.10, it was possible to call PyDict_GetItem() + // with the GIL released. + _Py_EnsureTstateNotNULL(tstate); +#endif + + /* Preserve the existing exception */ + PyObject *exc_type, *exc_value, *exc_tb; + PyObject *value; + Py_ssize_t ix; + + _PyErr_Fetch(tstate, &exc_type, &exc_value, &exc_tb); + ix = (mp->ma_keys->dk_lookup)(mp, key, hash, &value); + + /* Ignore any exception raised by the lookup */ + _PyErr_Restore(tstate, exc_type, exc_value, exc_tb); + + if (ix < 0) { + return NULL; } return value; } @@ -2031,13 +2035,15 @@ dict_dealloc(PyDictObject *mp) assert(keys->dk_refcnt == 1); dictkeys_decref(keys); } -#if PyDict_MAXFREELIST > 0 - if (numfree < PyDict_MAXFREELIST && Py_IS_TYPE(mp, &PyDict_Type)) { - free_list[numfree++] = mp; - } - else + struct _Py_dict_state *state = get_dict_state(); +#ifdef Py_DEBUG + // new_dict() must not be called after _PyDict_Fini() + assert(state->numfree != -1); #endif - { + if (state->numfree < PyDict_MAXFREELIST && Py_IS_TYPE(mp, &PyDict_Type)) { + state->free_list[state->numfree++] = mp; + } + else { Py_TYPE(mp)->tp_free((PyObject *)mp); } Py_TRASHCAN_END @@ -4125,6 +4131,22 @@ _PyDictView_New(PyObject *dict, PyTypeObject *type) return (PyObject *)dv; } +static PyObject * +dictview_mapping(PyObject *view, void *Py_UNUSED(ignored)) { + assert(view != NULL); + assert(PyDictKeys_Check(view) + || PyDictValues_Check(view) + || PyDictItems_Check(view)); + PyObject *mapping = (PyObject *)((_PyDictViewObject *)view)->dv_dict; + return PyDictProxy_New(mapping); +} + +static PyGetSetDef dictview_getset[] = { + {"mapping", dictview_mapping, (setter)NULL, + "dictionary that this view refers to", NULL}, + {0} +}; + /* TODO(guido): The views objects are not complete: * support more set operations @@ -4412,9 +4434,99 @@ dictviews_or(PyObject* self, PyObject *other) return result; } +static PyObject * +dictitems_xor(PyObject *self, PyObject *other) +{ + assert(PyDictItems_Check(self)); + assert(PyDictItems_Check(other)); + PyObject *d1 = (PyObject *)((_PyDictViewObject *)self)->dv_dict; + PyObject *d2 = (PyObject *)((_PyDictViewObject *)other)->dv_dict; + + PyObject *temp_dict = PyDict_Copy(d1); + if (temp_dict == NULL) { + return NULL; + } + PyObject *result_set = PySet_New(NULL); + if (result_set == NULL) { + Py_CLEAR(temp_dict); + return NULL; + } + + PyObject *key = NULL, *val1 = NULL, *val2 = NULL; + Py_ssize_t pos = 0; + Py_hash_t hash; + + while (_PyDict_Next(d2, &pos, &key, &val2, &hash)) { + Py_INCREF(key); + Py_INCREF(val2); + val1 = _PyDict_GetItem_KnownHash(temp_dict, key, hash); + + int to_delete; + if (val1 == NULL) { + if (PyErr_Occurred()) { + goto error; + } + to_delete = 0; + } + else { + Py_INCREF(val1); + to_delete = PyObject_RichCompareBool(val1, val2, Py_EQ); + if (to_delete < 0) { + goto error; + } + } + + if (to_delete) { + if (_PyDict_DelItem_KnownHash(temp_dict, key, hash) < 0) { + goto error; + } + } + else { + PyObject *pair = PyTuple_Pack(2, key, val2); + if (pair == NULL) { + goto error; + } + if (PySet_Add(result_set, pair) < 0) { + Py_DECREF(pair); + goto error; + } + Py_DECREF(pair); + } + Py_DECREF(key); + Py_XDECREF(val1); + Py_DECREF(val2); + } + key = val1 = val2 = NULL; + + _Py_IDENTIFIER(items); + PyObject *remaining_pairs = _PyObject_CallMethodIdNoArgs(temp_dict, + &PyId_items); + if (remaining_pairs == NULL) { + goto error; + } + if (_PySet_Update(result_set, remaining_pairs) < 0) { + Py_DECREF(remaining_pairs); + goto error; + } + Py_DECREF(temp_dict); + Py_DECREF(remaining_pairs); + return result_set; + +error: + Py_XDECREF(temp_dict); + Py_XDECREF(result_set); + Py_XDECREF(key); + Py_XDECREF(val1); + Py_XDECREF(val2); + return NULL; +} + static PyObject* dictviews_xor(PyObject* self, PyObject *other) { + if (PyDictItems_Check(self) && PyDictItems_Check(other)) { + return dictitems_xor(self, other); + } PyObject *result = dictviews_to_set(self); if (result == NULL) { return NULL; @@ -4548,7 +4660,7 @@ PyTypeObject PyDictKeys_Type = { (getiterfunc)dictkeys_iter, /* tp_iter */ 0, /* tp_iternext */ dictkeys_methods, /* tp_methods */ - 0, + .tp_getset = dictview_getset, }; static PyObject * @@ -4654,7 +4766,7 @@ PyTypeObject PyDictItems_Type = { (getiterfunc)dictitems_iter, /* tp_iter */ 0, /* tp_iternext */ dictitems_methods, /* tp_methods */ - 0, + .tp_getset = dictview_getset, }; static PyObject * @@ -4735,7 +4847,7 @@ PyTypeObject PyDictValues_Type = { (getiterfunc)dictvalues_iter, /* tp_iter */ 0, /* tp_iternext */ dictvalues_methods, /* tp_methods */ - 0, + .tp_getset = dictview_getset, }; static PyObject * diff --git a/Objects/exceptions.c b/Objects/exceptions.c index db5e3da12b0..1195ba17922 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -19,8 +19,13 @@ PyObject *PyExc_IOError = NULL; PyObject *PyExc_WindowsError = NULL; #endif -/* The dict map from errno codes to OSError subclasses */ -static PyObject *errnomap = NULL; + +static struct _Py_exc_state* +get_exc_state(void) +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + return &interp->exc_state; +} /* NOTE: If the exception class hierarchy changes, don't forget to update @@ -985,10 +990,11 @@ OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) )) goto error; + struct _Py_exc_state *state = get_exc_state(); if (myerrno && PyLong_Check(myerrno) && - errnomap && (PyObject *) type == PyExc_OSError) { + state->errnomap && (PyObject *) type == PyExc_OSError) { PyObject *newtype; - newtype = PyDict_GetItemWithError(errnomap, myerrno); + newtype = PyDict_GetItemWithError(state->errnomap, myerrno); if (newtype) { assert(PyType_Check(newtype)); type = (PyTypeObject *) newtype; @@ -2274,8 +2280,6 @@ SimpleExtendsException(PyExc_Exception, ReferenceError, */ #define MEMERRORS_SAVE 16 -static PyBaseExceptionObject *memerrors_freelist = NULL; -static int memerrors_numfree = 0; static PyObject * MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) @@ -2284,16 +2288,22 @@ MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (type != (PyTypeObject *) PyExc_MemoryError) return BaseException_new(type, args, kwds); - if (memerrors_freelist == NULL) + + struct _Py_exc_state *state = get_exc_state(); + if (state->memerrors_freelist == NULL) { return BaseException_new(type, args, kwds); + } + /* Fetch object from freelist and revive it */ - self = memerrors_freelist; + self = state->memerrors_freelist; self->args = PyTuple_New(0); /* This shouldn't happen since the empty tuple is persistent */ - if (self->args == NULL) + if (self->args == NULL) { return NULL; - memerrors_freelist = (PyBaseExceptionObject *) self->dict; - memerrors_numfree--; + } + + state->memerrors_freelist = (PyBaseExceptionObject *) self->dict; + state->memerrors_numfree--; self->dict = NULL; _Py_NewReference((PyObject *)self); _PyObject_GC_TRACK(self); @@ -2305,12 +2315,15 @@ MemoryError_dealloc(PyBaseExceptionObject *self) { _PyObject_GC_UNTRACK(self); BaseException_clear(self); - if (memerrors_numfree >= MEMERRORS_SAVE) + + struct _Py_exc_state *state = get_exc_state(); + if (state->memerrors_numfree >= MEMERRORS_SAVE) { Py_TYPE(self)->tp_free((PyObject *)self); + } else { - self->dict = (PyObject *) memerrors_freelist; - memerrors_freelist = self; - memerrors_numfree++; + self->dict = (PyObject *) state->memerrors_freelist; + state->memerrors_freelist = self; + state->memerrors_numfree++; } } @@ -2335,11 +2348,11 @@ preallocate_memerrors(void) } static void -free_preallocated_memerrors(void) +free_preallocated_memerrors(struct _Py_exc_state *state) { - while (memerrors_freelist != NULL) { - PyObject *self = (PyObject *) memerrors_freelist; - memerrors_freelist = (PyBaseExceptionObject *) memerrors_freelist->dict; + while (state->memerrors_freelist != NULL) { + PyObject *self = (PyObject *) state->memerrors_freelist; + state->memerrors_freelist = (PyBaseExceptionObject *)state->memerrors_freelist->dict; Py_TYPE(self)->tp_free((PyObject *)self); } } @@ -2507,8 +2520,10 @@ SimpleExtendsException(PyExc_Warning, ResourceWarning, #endif /* MS_WINDOWS */ PyStatus -_PyExc_Init(void) +_PyExc_Init(PyThreadState *tstate) { + struct _Py_exc_state *state = &tstate->interp->exc_state; + #define PRE_INIT(TYPE) \ if (!(_PyExc_ ## TYPE.tp_flags & Py_TPFLAGS_READY)) { \ if (PyType_Ready(&_PyExc_ ## TYPE) < 0) { \ @@ -2521,7 +2536,7 @@ _PyExc_Init(void) do { \ PyObject *_code = PyLong_FromLong(CODE); \ assert(_PyObject_RealIsSubclass(PyExc_ ## TYPE, PyExc_OSError)); \ - if (!_code || PyDict_SetItem(errnomap, _code, PyExc_ ## TYPE)) \ + if (!_code || PyDict_SetItem(state->errnomap, _code, PyExc_ ## TYPE)) \ return _PyStatus_ERR("errmap insertion problem."); \ Py_DECREF(_code); \ } while (0) @@ -2595,15 +2610,14 @@ _PyExc_Init(void) PRE_INIT(TimeoutError); if (preallocate_memerrors() < 0) { - return _PyStatus_ERR("Could not preallocate MemoryError object"); + return _PyStatus_NO_MEMORY(); } /* Add exceptions to errnomap */ - if (!errnomap) { - errnomap = PyDict_New(); - if (!errnomap) { - return _PyStatus_ERR("Cannot allocate map from errnos to OSError subclasses"); - } + assert(state->errnomap == NULL); + state->errnomap = PyDict_New(); + if (!state->errnomap) { + return _PyStatus_NO_MEMORY(); } ADD_ERRNO(BlockingIOError, EAGAIN); @@ -2741,10 +2755,11 @@ _PyBuiltins_AddExceptions(PyObject *bltinmod) } void -_PyExc_Fini(void) +_PyExc_Fini(PyThreadState *tstate) { - free_preallocated_memerrors(); - Py_CLEAR(errnomap); + struct _Py_exc_state *state = &tstate->interp->exc_state; + free_preallocated_memerrors(state); + Py_CLEAR(state->errnomap); } /* Helper to do the equivalent of "raise X from Y" in C, but always using diff --git a/Objects/floatobject.c b/Objects/floatobject.c index cc0ae8ce819..0606f29ff54 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -4,7 +4,10 @@ for any kind of float exception without losing portability. */ #include "Python.h" -#include "pycore_dtoa.h" +#include "pycore_dtoa.h" // _Py_dg_dtoa() +#include "pycore_interp.h" // _PyInterpreterState.float_state +#include "pycore_object.h" // _PyObject_Init() +#include "pycore_pystate.h" // _PyInterpreterState_GET() #include #include @@ -16,16 +19,18 @@ class float "PyObject *" "&PyFloat_Type" #include "clinic/floatobject.c.h" -/* Special free list - free_list is a singly-linked list of available PyFloatObjects, linked - via abuse of their ob_type members. -*/ - #ifndef PyFloat_MAXFREELIST -#define PyFloat_MAXFREELIST 100 +# define PyFloat_MAXFREELIST 100 #endif -static int numfree = 0; -static PyFloatObject *free_list = NULL; + + +static struct _Py_float_state * +get_float_state(void) +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + return &interp->float_state; +} + double PyFloat_GetMax(void) @@ -117,17 +122,23 @@ PyFloat_GetInfo(void) PyObject * PyFloat_FromDouble(double fval) { - PyFloatObject *op = free_list; + struct _Py_float_state *state = get_float_state(); + PyFloatObject *op = state->free_list; if (op != NULL) { - free_list = (PyFloatObject *) Py_TYPE(op); - numfree--; - } else { - op = (PyFloatObject*) PyObject_MALLOC(sizeof(PyFloatObject)); - if (!op) - return PyErr_NoMemory(); +#ifdef Py_DEBUG + // PyFloat_FromDouble() must not be called after _PyFloat_Fini() + assert(state->numfree != -1); +#endif + state->free_list = (PyFloatObject *) Py_TYPE(op); + state->numfree--; } - /* Inline PyObject_New */ - (void)PyObject_INIT(op, &PyFloat_Type); + else { + op = PyObject_Malloc(sizeof(PyFloatObject)); + if (!op) { + return PyErr_NoMemory(); + } + } + _PyObject_Init((PyObject*)op, &PyFloat_Type); op->ob_fval = fval; return (PyObject *) op; } @@ -219,16 +230,22 @@ static void float_dealloc(PyFloatObject *op) { if (PyFloat_CheckExact(op)) { - if (numfree >= PyFloat_MAXFREELIST) { + struct _Py_float_state *state = get_float_state(); +#ifdef Py_DEBUG + // float_dealloc() must not be called after _PyFloat_Fini() + assert(state->numfree != -1); +#endif + if (state->numfree >= PyFloat_MAXFREELIST) { PyObject_FREE(op); return; } - numfree++; - Py_SET_TYPE(op, (PyTypeObject *)free_list); - free_list = op; + state->numfree++; + Py_SET_TYPE(op, (PyTypeObject *)state->free_list); + state->free_list = op; } - else + else { Py_TYPE(op)->tp_free((PyObject *)op); + } } double @@ -250,7 +267,7 @@ PyFloat_AsDouble(PyObject *op) nb = Py_TYPE(op)->tp_as_number; if (nb == NULL || nb->nb_float == NULL) { if (nb && nb->nb_index) { - PyObject *res = PyNumber_Index(op); + PyObject *res = _PyNumber_Index(op); if (!res) { return -1; } @@ -1981,30 +1998,37 @@ _PyFloat_Init(void) } void -_PyFloat_ClearFreeList(void) +_PyFloat_ClearFreeList(PyThreadState *tstate) { - PyFloatObject *f = free_list, *next; - for (; f; f = next) { - next = (PyFloatObject*) Py_TYPE(f); + struct _Py_float_state *state = &tstate->interp->float_state; + PyFloatObject *f = state->free_list; + while (f != NULL) { + PyFloatObject *next = (PyFloatObject*) Py_TYPE(f); PyObject_FREE(f); + f = next; } - free_list = NULL; - numfree = 0; + state->free_list = NULL; + state->numfree = 0; } void -_PyFloat_Fini(void) +_PyFloat_Fini(PyThreadState *tstate) { - _PyFloat_ClearFreeList(); + _PyFloat_ClearFreeList(tstate); +#ifdef Py_DEBUG + struct _Py_float_state *state = &tstate->interp->float_state; + state->numfree = -1; +#endif } /* Print summary info about the state of the optimized allocator */ void _PyFloat_DebugMallocStats(FILE *out) { + struct _Py_float_state *state = get_float_state(); _PyDebugAllocatorStats(out, "free PyFloatObject", - numfree, sizeof(PyFloatObject)); + state->numfree, sizeof(PyFloatObject)); } diff --git a/Objects/frameobject.c b/Objects/frameobject.c index af32276c98b..7c2bce36158 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -22,6 +22,15 @@ static PyMemberDef frame_memberlist[] = { {NULL} /* Sentinel */ }; + +static struct _Py_frame_state * +get_frame_state(void) +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + return &interp->frame; +} + + static PyObject * frame_getlocals(PyFrameObject *f, void *closure) { @@ -397,7 +406,9 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore return -1; } - int len = PyBytes_GET_SIZE(f->f_code->co_code)/sizeof(_Py_CODEUNIT); + /* PyCode_NewWithPosOnlyArgs limits co_code to be under INT_MAX so this + * should never overflow. */ + int len = (int)(PyBytes_GET_SIZE(f->f_code->co_code) / sizeof(_Py_CODEUNIT)); int *lines = marklines(f->f_code, len); if (lines == NULL) { return -1; @@ -559,36 +570,25 @@ static PyGetSetDef frame_getsetlist[] = { /* max value for numfree */ #define PyFrame_MAXFREELIST 200 -/* bpo-40521: frame free lists are shared by all interpreters. */ -#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS -# undef PyFrame_MAXFREELIST -# define PyFrame_MAXFREELIST 0 -#endif - -#if PyFrame_MAXFREELIST > 0 -static PyFrameObject *free_list = NULL; -static int numfree = 0; /* number of frames currently in free_list */ -#endif - static void _Py_HOT_FUNCTION frame_dealloc(PyFrameObject *f) { - PyObject **p, **valuestack; - PyCodeObject *co; - - if (_PyObject_GC_IS_TRACKED(f)) + if (_PyObject_GC_IS_TRACKED(f)) { _PyObject_GC_UNTRACK(f); + } Py_TRASHCAN_SAFE_BEGIN(f) /* Kill all local variables */ - valuestack = f->f_valuestack; - for (p = f->f_localsplus; p < valuestack; p++) + PyObject **valuestack = f->f_valuestack; + for (PyObject **p = f->f_localsplus; p < valuestack; p++) { Py_CLEAR(*p); + } /* Free stack */ if (f->f_stacktop != NULL) { - for (p = valuestack; p < f->f_stacktop; p++) + for (PyObject **p = valuestack; p < f->f_stacktop; p++) { Py_XDECREF(*p); + } } Py_XDECREF(f->f_back); @@ -597,19 +597,24 @@ frame_dealloc(PyFrameObject *f) Py_CLEAR(f->f_locals); Py_CLEAR(f->f_trace); - co = f->f_code; + PyCodeObject *co = f->f_code; if (co->co_zombieframe == NULL) { co->co_zombieframe = f; } -#if PyFrame_MAXFREELIST > 0 - else if (numfree < PyFrame_MAXFREELIST) { - ++numfree; - f->f_back = free_list; - free_list = f; - } -#endif else { - PyObject_GC_Del(f); + struct _Py_frame_state *state = get_frame_state(); +#ifdef Py_DEBUG + // frame_dealloc() must not be called after _PyFrame_Fini() + assert(state->numfree != -1); +#endif + if (state->numfree < PyFrame_MAXFREELIST) { + ++state->numfree; + f->f_back = state->free_list; + state->free_list = f; + } + else { + PyObject_GC_Del(f); + } } Py_DECREF(co); @@ -787,21 +792,23 @@ frame_alloc(PyCodeObject *code) Py_ssize_t ncells = PyTuple_GET_SIZE(code->co_cellvars); Py_ssize_t nfrees = PyTuple_GET_SIZE(code->co_freevars); Py_ssize_t extras = code->co_stacksize + code->co_nlocals + ncells + nfrees; -#if PyFrame_MAXFREELIST > 0 - if (free_list == NULL) -#endif + struct _Py_frame_state *state = get_frame_state(); + if (state->free_list == NULL) { f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras); if (f == NULL) { return NULL; } } -#if PyFrame_MAXFREELIST > 0 else { - assert(numfree > 0); - --numfree; - f = free_list; - free_list = free_list->f_back; +#ifdef Py_DEBUG + // frame_alloc() must not be called after _PyFrame_Fini() + assert(state->numfree != -1); +#endif + assert(state->numfree > 0); + --state->numfree; + f = state->free_list; + state->free_list = state->free_list->f_back; if (Py_SIZE(f) < extras) { PyFrameObject *new_f = PyObject_GC_Resize(PyFrameObject, f, extras); if (new_f == NULL) { @@ -812,7 +819,6 @@ frame_alloc(PyCodeObject *code) } _Py_NewReference((PyObject *)f); } -#endif f->f_code = code; extras = code->co_nlocals + ncells + nfrees; @@ -1181,34 +1187,36 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear) /* Clear out the free list */ void -_PyFrame_ClearFreeList(void) +_PyFrame_ClearFreeList(PyThreadState *tstate) { -#if PyFrame_MAXFREELIST > 0 - while (free_list != NULL) { - PyFrameObject *f = free_list; - free_list = free_list->f_back; + struct _Py_frame_state *state = &tstate->interp->frame; + while (state->free_list != NULL) { + PyFrameObject *f = state->free_list; + state->free_list = state->free_list->f_back; PyObject_GC_Del(f); - --numfree; + --state->numfree; } - assert(numfree == 0); -#endif + assert(state->numfree == 0); } void -_PyFrame_Fini(void) +_PyFrame_Fini(PyThreadState *tstate) { - _PyFrame_ClearFreeList(); + _PyFrame_ClearFreeList(tstate); +#ifdef Py_DEBUG + struct _Py_frame_state *state = &tstate->interp->frame; + state->numfree = -1; +#endif } /* Print summary info about the state of the optimized allocator */ void _PyFrame_DebugMallocStats(FILE *out) { -#if PyFrame_MAXFREELIST > 0 + struct _Py_frame_state *state = get_frame_state(); _PyDebugAllocatorStats(out, "free PyFrameObject", - numfree, sizeof(PyFrameObject)); -#endif + state->numfree, sizeof(PyFrameObject)); } diff --git a/Objects/funcobject.c b/Objects/funcobject.c index bd24f67b974..09a188664e8 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -3,7 +3,6 @@ #include "Python.h" #include "pycore_object.h" -#include "pycore_tupleobject.h" #include "code.h" #include "structmember.h" // PyMemberDef diff --git a/Objects/genobject.c b/Objects/genobject.c index 09efbab69a7..6a68c9484a6 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -231,7 +231,8 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing) if (PyAsyncGen_CheckExact(gen)) { PyErr_SetNone(PyExc_StopAsyncIteration); } - else { + else if (arg) { + /* Set exception if not called by gen_iternext() */ PyErr_SetNone(PyExc_StopIteration); } } @@ -1161,7 +1162,7 @@ typedef enum { } AwaitableState; -typedef struct { +typedef struct PyAsyncGenASend { PyObject_HEAD PyAsyncGenObject *ags_gen; @@ -1173,7 +1174,7 @@ typedef struct { } PyAsyncGenASend; -typedef struct { +typedef struct PyAsyncGenAThrow { PyObject_HEAD PyAsyncGenObject *agt_gen; @@ -1185,28 +1186,12 @@ typedef struct { } PyAsyncGenAThrow; -typedef struct { +typedef struct _PyAsyncGenWrappedValue { PyObject_HEAD PyObject *agw_val; } _PyAsyncGenWrappedValue; -#ifndef _PyAsyncGen_MAXFREELIST -#define _PyAsyncGen_MAXFREELIST 80 -#endif - -/* Freelists boost performance 6-10%; they also reduce memory - fragmentation, as _PyAsyncGenWrappedValue and PyAsyncGenASend - are short-living objects that are instantiated for every - __anext__ call. -*/ - -static _PyAsyncGenWrappedValue *ag_value_freelist[_PyAsyncGen_MAXFREELIST]; -static int ag_value_freelist_free = 0; - -static PyAsyncGenASend *ag_asend_freelist[_PyAsyncGen_MAXFREELIST]; -static int ag_asend_freelist_free = 0; - #define _PyAsyncGenWrappedValue_CheckExact(o) \ Py_IS_TYPE(o, &_PyAsyncGenWrappedValue_Type) @@ -1404,6 +1389,14 @@ PyTypeObject PyAsyncGen_Type = { }; +static struct _Py_async_gen_state * +get_async_gen_state(void) +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + return &interp->async_gen; +} + + PyObject * PyAsyncGen_New(PyFrameObject *f, PyObject *name, PyObject *qualname) { @@ -1422,27 +1415,34 @@ PyAsyncGen_New(PyFrameObject *f, PyObject *name, PyObject *qualname) void -_PyAsyncGen_ClearFreeLists(void) +_PyAsyncGen_ClearFreeLists(PyThreadState *tstate) { - while (ag_value_freelist_free) { + struct _Py_async_gen_state *state = &tstate->interp->async_gen; + + while (state->value_numfree) { _PyAsyncGenWrappedValue *o; - o = ag_value_freelist[--ag_value_freelist_free]; + o = state->value_freelist[--state->value_numfree]; assert(_PyAsyncGenWrappedValue_CheckExact(o)); PyObject_GC_Del(o); } - while (ag_asend_freelist_free) { + while (state->asend_numfree) { PyAsyncGenASend *o; - o = ag_asend_freelist[--ag_asend_freelist_free]; + o = state->asend_freelist[--state->asend_numfree]; assert(Py_IS_TYPE(o, &_PyAsyncGenASend_Type)); PyObject_GC_Del(o); } } void -_PyAsyncGen_Fini(void) +_PyAsyncGen_Fini(PyThreadState *tstate) { - _PyAsyncGen_ClearFreeLists(); + _PyAsyncGen_ClearFreeLists(tstate); +#ifdef Py_DEBUG + struct _Py_async_gen_state *state = &tstate->interp->async_gen; + state->value_numfree = -1; + state->asend_numfree = -1; +#endif } @@ -1485,10 +1485,16 @@ async_gen_asend_dealloc(PyAsyncGenASend *o) _PyObject_GC_UNTRACK((PyObject *)o); Py_CLEAR(o->ags_gen); Py_CLEAR(o->ags_sendval); - if (ag_asend_freelist_free < _PyAsyncGen_MAXFREELIST) { + struct _Py_async_gen_state *state = get_async_gen_state(); +#ifdef Py_DEBUG + // async_gen_asend_dealloc() must not be called after _PyAsyncGen_Fini() + assert(state->asend_numfree != -1); +#endif + if (state->asend_numfree < _PyAsyncGen_MAXFREELIST) { assert(PyAsyncGenASend_CheckExact(o)); - ag_asend_freelist[ag_asend_freelist_free++] = o; - } else { + state->asend_freelist[state->asend_numfree++] = o; + } + else { PyObject_GC_Del(o); } } @@ -1640,11 +1646,17 @@ static PyObject * async_gen_asend_new(PyAsyncGenObject *gen, PyObject *sendval) { PyAsyncGenASend *o; - if (ag_asend_freelist_free) { - ag_asend_freelist_free--; - o = ag_asend_freelist[ag_asend_freelist_free]; + struct _Py_async_gen_state *state = get_async_gen_state(); +#ifdef Py_DEBUG + // async_gen_asend_new() must not be called after _PyAsyncGen_Fini() + assert(state->asend_numfree != -1); +#endif + if (state->asend_numfree) { + state->asend_numfree--; + o = state->asend_freelist[state->asend_numfree]; _Py_NewReference((PyObject *)o); - } else { + } + else { o = PyObject_GC_New(PyAsyncGenASend, &_PyAsyncGenASend_Type); if (o == NULL) { return NULL; @@ -1672,10 +1684,16 @@ async_gen_wrapped_val_dealloc(_PyAsyncGenWrappedValue *o) { _PyObject_GC_UNTRACK((PyObject *)o); Py_CLEAR(o->agw_val); - if (ag_value_freelist_free < _PyAsyncGen_MAXFREELIST) { + struct _Py_async_gen_state *state = get_async_gen_state(); +#ifdef Py_DEBUG + // async_gen_wrapped_val_dealloc() must not be called after _PyAsyncGen_Fini() + assert(state->value_numfree != -1); +#endif + if (state->value_numfree < _PyAsyncGen_MAXFREELIST) { assert(_PyAsyncGenWrappedValue_CheckExact(o)); - ag_value_freelist[ag_value_freelist_free++] = o; - } else { + state->value_freelist[state->value_numfree++] = o; + } + else { PyObject_GC_Del(o); } } @@ -1739,12 +1757,18 @@ _PyAsyncGenValueWrapperNew(PyObject *val) _PyAsyncGenWrappedValue *o; assert(val); - if (ag_value_freelist_free) { - ag_value_freelist_free--; - o = ag_value_freelist[ag_value_freelist_free]; + struct _Py_async_gen_state *state = get_async_gen_state(); +#ifdef Py_DEBUG + // _PyAsyncGenValueWrapperNew() must not be called after _PyAsyncGen_Fini() + assert(state->value_numfree != -1); +#endif + if (state->value_numfree) { + state->value_numfree--; + o = state->value_freelist[state->value_numfree]; assert(_PyAsyncGenWrappedValue_CheckExact(o)); _Py_NewReference((PyObject*)o); - } else { + } + else { o = PyObject_GC_New(_PyAsyncGenWrappedValue, &_PyAsyncGenWrappedValue_Type); if (o == NULL) { diff --git a/Objects/listobject.c b/Objects/listobject.c index 30d26207537..aac87ea1b61 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -1,10 +1,10 @@ /* List object implementation */ #include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_object.h" -#include "pycore_tupleobject.h" -#include "pycore_accu.h" +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_interp.h" // PyInterpreterState.list +#include "pycore_object.h" // _PyObject_GC_TRACK() +#include "pycore_tuple.h" // _PyTuple_FromArray() #ifdef STDC_HEADERS #include @@ -19,6 +19,15 @@ class list "PyListObject *" "&PyList_Type" #include "clinic/listobject.c.h" + +static struct _Py_list_state * +get_list_state(void) +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + return &interp->list; +} + + /* Ensure ob_item has room for at least newsize elements, and set * ob_size to newsize. If newsize > ob_size on entry, the content * of the new slots at exit is undefined heap trash; it's the caller's @@ -60,7 +69,7 @@ list_resize(PyListObject *self, Py_ssize_t newsize) * is PY_SSIZE_T_MAX * (9 / 8) + 6 which always fits in a size_t. */ new_allocated = ((size_t)newsize + (newsize >> 3) + 6) & ~(size_t)3; - /* Do not overallocate if the new size is closer to overalocated size + /* Do not overallocate if the new size is closer to overallocated size * than to the old size. */ if (newsize - Py_SIZE(self) > (Py_ssize_t)(new_allocated - newsize)) @@ -96,65 +105,65 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size) return 0; } -/* Empty list reuse scheme to save calls to malloc and free */ -#ifndef PyList_MAXFREELIST -# define PyList_MAXFREELIST 80 -#endif - -/* bpo-40521: list free lists are shared by all interpreters. */ -#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS -# undef PyList_MAXFREELIST -# define PyList_MAXFREELIST 0 -#endif - -static PyListObject *free_list[PyList_MAXFREELIST]; -static int numfree = 0; - void -_PyList_ClearFreeList(void) +_PyList_ClearFreeList(PyThreadState *tstate) { - while (numfree) { - PyListObject *op = free_list[--numfree]; + struct _Py_list_state *state = &tstate->interp->list; + while (state->numfree) { + PyListObject *op = state->free_list[--state->numfree]; assert(PyList_CheckExact(op)); PyObject_GC_Del(op); } } void -_PyList_Fini(void) +_PyList_Fini(PyThreadState *tstate) { - _PyList_ClearFreeList(); + _PyList_ClearFreeList(tstate); +#ifdef Py_DEBUG + struct _Py_list_state *state = &tstate->interp->list; + state->numfree = -1; +#endif } /* Print summary info about the state of the optimized allocator */ void _PyList_DebugMallocStats(FILE *out) { + struct _Py_list_state *state = get_list_state(); _PyDebugAllocatorStats(out, "free PyListObject", - numfree, sizeof(PyListObject)); + state->numfree, sizeof(PyListObject)); } PyObject * PyList_New(Py_ssize_t size) { - PyListObject *op; - if (size < 0) { PyErr_BadInternalCall(); return NULL; } - if (numfree) { - numfree--; - op = free_list[numfree]; + + struct _Py_list_state *state = get_list_state(); + PyListObject *op; +#ifdef Py_DEBUG + // PyList_New() must not be called after _PyList_Fini() + assert(state->numfree != -1); +#endif + if (state->numfree) { + state->numfree--; + op = state->free_list[state->numfree]; _Py_NewReference((PyObject *)op); - } else { - op = PyObject_GC_New(PyListObject, &PyList_Type); - if (op == NULL) - return NULL; } - if (size <= 0) + else { + op = PyObject_GC_New(PyListObject, &PyList_Type); + if (op == NULL) { + return NULL; + } + } + if (size <= 0) { op->ob_item = NULL; + } else { op->ob_item = (PyObject **) PyMem_Calloc(size, sizeof(PyObject *)); if (op->ob_item == NULL) { @@ -334,10 +343,17 @@ list_dealloc(PyListObject *op) } PyMem_FREE(op->ob_item); } - if (numfree < PyList_MAXFREELIST && PyList_CheckExact(op)) - free_list[numfree++] = op; - else + struct _Py_list_state *state = get_list_state(); +#ifdef Py_DEBUG + // list_dealloc() must not be called after _PyList_Fini() + assert(state->numfree != -1); +#endif + if (state->numfree < PyList_MAXFREELIST && PyList_CheckExact(op)) { + state->free_list[state->numfree++] = op; + } + else { Py_TYPE(op)->tp_free((PyObject *)op); + } Py_TRASHCAN_END } diff --git a/Objects/longobject.c b/Objects/longobject.c index a409948e4ac..571f53a3c00 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -3,8 +3,10 @@ /* XXX The functional organization of this file is terrible */ #include "Python.h" -#include "pycore_interp.h" // _PY_NSMALLPOSINTS -#include "pycore_pystate.h" // _Py_IsMainInterpreter() +#include "pycore_bitutils.h" // _Py_popcount32() +#include "pycore_interp.h" // _PY_NSMALLPOSINTS +#include "pycore_object.h" // _PyObject_InitVar() +#include "pycore_pystate.h" // _Py_IsMainInterpreter() #include "longintrepr.h" #include @@ -40,8 +42,8 @@ static PyObject * get_small_int(sdigit ival) { assert(IS_SMALL_INT(ival)); - PyThreadState *tstate = _PyThreadState_GET(); - PyObject *v = (PyObject*)tstate->interp->small_ints[ival + NSMALLNEGINTS]; + PyInterpreterState *interp = _PyInterpreterState_GET(); + PyObject *v = (PyObject*)interp->small_ints[ival + NSMALLNEGINTS]; Py_INCREF(v); return v; } @@ -145,7 +147,8 @@ _PyLong_New(Py_ssize_t size) PyErr_NoMemory(); return NULL; } - return (PyLongObject*)PyObject_INIT_VAR(result, &PyLong_Type, size); + _PyObject_InitVar((PyVarObject*)result, &PyLong_Type, size); + return result; } PyObject * @@ -363,7 +366,7 @@ PyLong_FromDouble(double dval) #define PY_ABS_LONG_MIN (0-(unsigned long)LONG_MIN) #define PY_ABS_SSIZE_T_MIN (0-(size_t)PY_SSIZE_T_MIN) -/* Get a C long int from an int object or any object that has an __int__ +/* Get a C long int from an int object or any object that has an __index__ method. On overflow, return -1 and set *overflow to 1 or -1 depending on the sign of @@ -382,7 +385,7 @@ PyLong_AsLongAndOverflow(PyObject *vv, int *overflow) long res; Py_ssize_t i; int sign; - int do_decref = 0; /* if nb_int was called */ + int do_decref = 0; /* if PyNumber_Index was called */ *overflow = 0; if (vv == NULL) { @@ -394,7 +397,7 @@ PyLong_AsLongAndOverflow(PyObject *vv, int *overflow) v = (PyLongObject *)vv; } else { - v = (PyLongObject *)PyNumber_Index(vv); + v = (PyLongObject *)_PyNumber_Index(vv); if (v == NULL) return -1; do_decref = 1; @@ -449,7 +452,7 @@ PyLong_AsLongAndOverflow(PyObject *vv, int *overflow) return res; } -/* Get a C long int from an int object or any object that has an __int__ +/* Get a C long int from an int object or any object that has an __index__ method. Return -1 and set an error if overflow occurs. */ long @@ -466,7 +469,7 @@ PyLong_AsLong(PyObject *obj) return result; } -/* Get a C int from an int object or any object that has an __int__ +/* Get a C int from an int object or any object that has an __index__ method. Return -1 and set an error if overflow occurs. */ int @@ -674,7 +677,7 @@ PyLong_AsUnsignedLongMask(PyObject *op) return _PyLong_AsUnsignedLongMask(op); } - lo = (PyLongObject *)PyNumber_Index(op); + lo = (PyLongObject *)_PyNumber_Index(op); if (lo == NULL) return (unsigned long)-1; @@ -694,6 +697,13 @@ _PyLong_Sign(PyObject *vv) return Py_SIZE(v) == 0 ? 0 : (Py_SIZE(v) < 0 ? -1 : 1); } +static int +bit_length_digit(digit x) +{ + Py_BUILD_ASSERT(PyLong_SHIFT <= sizeof(unsigned long) * 8); + return _Py_bit_length((unsigned long)x); +} + size_t _PyLong_NumBits(PyObject *vv) { @@ -711,7 +721,7 @@ _PyLong_NumBits(PyObject *vv) if ((size_t)(ndigits - 1) > SIZE_MAX / (size_t)PyLong_SHIFT) goto Overflow; result = (size_t)(ndigits - 1) * (size_t)PyLong_SHIFT; - msd_bits = _Py_bit_length(msd); + msd_bits = bit_length_digit(msd); if (SIZE_MAX - msd_bits < result) goto Overflow; result += msd_bits; @@ -1113,7 +1123,7 @@ PyLong_FromSsize_t(Py_ssize_t ival) } /* Get a C long long int from an int object or any object that has an - __int__ method. Return -1 and set an error if overflow occurs. */ + __index__ method. Return -1 and set an error if overflow occurs. */ long long PyLong_AsLongLong(PyObject *vv) @@ -1121,7 +1131,7 @@ PyLong_AsLongLong(PyObject *vv) PyLongObject *v; long long bytes; int res; - int do_decref = 0; /* if nb_int was called */ + int do_decref = 0; /* if PyNumber_Index was called */ if (vv == NULL) { PyErr_BadInternalCall(); @@ -1132,7 +1142,7 @@ PyLong_AsLongLong(PyObject *vv) v = (PyLongObject *)vv; } else { - v = (PyLongObject *)PyNumber_Index(vv); + v = (PyLongObject *)_PyNumber_Index(vv); if (v == NULL) return -1; do_decref = 1; @@ -1247,7 +1257,7 @@ PyLong_AsUnsignedLongLongMask(PyObject *op) return _PyLong_AsUnsignedLongLongMask(op); } - lo = (PyLongObject *)PyNumber_Index(op); + lo = (PyLongObject *)_PyNumber_Index(op); if (lo == NULL) return (unsigned long long)-1; @@ -1257,7 +1267,7 @@ PyLong_AsUnsignedLongLongMask(PyObject *op) } /* Get a C long long int from an int object or any object that has an - __int__ method. + __index__ method. On overflow, return -1 and set *overflow to 1 or -1 depending on the sign of the result. Otherwise *overflow is 0. @@ -1275,7 +1285,7 @@ PyLong_AsLongLongAndOverflow(PyObject *vv, int *overflow) long long res; Py_ssize_t i; int sign; - int do_decref = 0; /* if nb_int was called */ + int do_decref = 0; /* if PyNumber_Index was called */ *overflow = 0; if (vv == NULL) { @@ -1287,7 +1297,7 @@ PyLong_AsLongLongAndOverflow(PyObject *vv, int *overflow) v = (PyLongObject *)vv; } else { - v = (PyLongObject *)PyNumber_Index(vv); + v = (PyLongObject *)_PyNumber_Index(vv); if (v == NULL) return -1; do_decref = 1; @@ -1821,7 +1831,7 @@ long_format_binary(PyObject *aa, int base, int alternate, return -1; } size_a_in_bits = (size_a - 1) * PyLong_SHIFT + - _Py_bit_length(a->ob_digit[size_a - 1]); + bit_length_digit(a->ob_digit[size_a - 1]); /* Allow 1 character for a '-' sign. */ sz = negative + (size_a_in_bits + (bits - 1)) / bits; } @@ -2493,17 +2503,6 @@ _PyLong_FromBytes(const char *s, Py_ssize_t len, int base) return NULL; } -PyObject * -PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base) -{ - PyObject *v, *unicode = PyUnicode_FromWideChar(u, length); - if (unicode == NULL) - return NULL; - v = PyLong_FromUnicodeObject(unicode, base); - Py_DECREF(unicode); - return v; -} - PyObject * PyLong_FromUnicodeObject(PyObject *u, int base) { @@ -2641,7 +2640,7 @@ x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem) /* normalize: shift w1 left so that its top digit is >= PyLong_BASE/2. shift v1 left by the same amount. Results go into w and v. */ - d = PyLong_SHIFT - _Py_bit_length(w1->ob_digit[size_w-1]); + d = PyLong_SHIFT - bit_length_digit(w1->ob_digit[size_w-1]); carry = v_lshift(w->ob_digit, w1->ob_digit, size_w, d); assert(carry == 0); carry = v_lshift(v->ob_digit, v1->ob_digit, size_v, d); @@ -2763,7 +2762,7 @@ _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e) *e = 0; return 0.0; } - a_bits = _Py_bit_length(a->ob_digit[a_size-1]); + a_bits = bit_length_digit(a->ob_digit[a_size-1]); /* The following is an overflow-free version of the check "if ((a_size - 1) * PyLong_SHIFT + a_bits > PY_SSIZE_T_MAX) ..." */ if (a_size >= (PY_SSIZE_T_MAX - 1) / PyLong_SHIFT + 1 && @@ -3856,8 +3855,8 @@ long_true_divide(PyObject *v, PyObject *w) /* Extreme underflow */ goto underflow_or_zero; /* Next line is now safe from overflowing a Py_ssize_t */ - diff = diff * PyLong_SHIFT + _Py_bit_length(a->ob_digit[a_size - 1]) - - _Py_bit_length(b->ob_digit[b_size - 1]); + diff = diff * PyLong_SHIFT + bit_length_digit(a->ob_digit[a_size - 1]) - + bit_length_digit(b->ob_digit[b_size - 1]); /* Now diff = a_bits - b_bits. */ if (diff > DBL_MAX_EXP) goto overflow; @@ -3933,7 +3932,7 @@ long_true_divide(PyObject *v, PyObject *w) } x_size = Py_ABS(Py_SIZE(x)); assert(x_size > 0); /* result of division is never zero */ - x_bits = (x_size-1)*PyLong_SHIFT+_Py_bit_length(x->ob_digit[x_size-1]); + x_bits = (x_size-1)*PyLong_SHIFT+bit_length_digit(x->ob_digit[x_size-1]); /* The number of extra bits that have to be rounded away. */ extra_bits = Py_MAX(x_bits, DBL_MIN_EXP - shift) - DBL_MANT_DIG; @@ -4747,7 +4746,7 @@ _PyLong_GCD(PyObject *aarg, PyObject *barg) alloc_b = Py_SIZE(b); /* reduce until a fits into 2 digits */ while ((size_a = Py_SIZE(a)) > 2) { - nbits = _Py_bit_length(a->ob_digit[size_a-1]); + nbits = bit_length_digit(a->ob_digit[size_a-1]); /* extract top 2*PyLong_SHIFT bits of a into x, along with corresponding bits of b into y */ size_b = Py_SIZE(b); @@ -5180,7 +5179,7 @@ long_round(PyObject *self, PyObject *args) if (o_ndigits == NULL) return long_long(self); - ndigits = PyNumber_Index(o_ndigits); + ndigits = _PyNumber_Index(o_ndigits); if (ndigits == NULL) return NULL; @@ -5268,7 +5267,7 @@ int_bit_length_impl(PyObject *self) return PyLong_FromLong(0); msd = ((PyLongObject *)self)->ob_digit[ndigits-1]; - msd_bits = _Py_bit_length(msd); + msd_bits = bit_length_digit(msd); if (ndigits <= PY_SSIZE_T_MAX/PyLong_SHIFT) return PyLong_FromSsize_t((ndigits-1)*PyLong_SHIFT + msd_bits); @@ -5304,6 +5303,73 @@ int_bit_length_impl(PyObject *self) return NULL; } +static int +popcount_digit(digit d) +{ + // digit can be larger than uint32_t, but only PyLong_SHIFT bits + // of it will be ever used. + Py_BUILD_ASSERT(PyLong_SHIFT <= 32); + return _Py_popcount32((uint32_t)d); +} + +/*[clinic input] +int.bit_count + +Number of ones in the binary representation of the absolute value of self. + +Also known as the population count. + +>>> bin(13) +'0b1101' +>>> (13).bit_count() +3 +[clinic start generated code]*/ + +static PyObject * +int_bit_count_impl(PyObject *self) +/*[clinic end generated code: output=2e571970daf1e5c3 input=7e0adef8e8ccdf2e]*/ +{ + assert(self != NULL); + assert(PyLong_Check(self)); + + PyLongObject *z = (PyLongObject *)self; + Py_ssize_t ndigits = Py_ABS(Py_SIZE(z)); + Py_ssize_t bit_count = 0; + + /* Each digit has up to PyLong_SHIFT ones, so the accumulated bit count + from the first PY_SSIZE_T_MAX/PyLong_SHIFT digits can't overflow a + Py_ssize_t. */ + Py_ssize_t ndigits_fast = Py_MIN(ndigits, PY_SSIZE_T_MAX/PyLong_SHIFT); + for (Py_ssize_t i = 0; i < ndigits_fast; i++) { + bit_count += popcount_digit(z->ob_digit[i]); + } + + PyObject *result = PyLong_FromSsize_t(bit_count); + if (result == NULL) { + return NULL; + } + + /* Use Python integers if bit_count would overflow. */ + for (Py_ssize_t i = ndigits_fast; i < ndigits; i++) { + PyObject *x = PyLong_FromLong(popcount_digit(z->ob_digit[i])); + if (x == NULL) { + goto error; + } + PyObject *y = long_add((PyLongObject *)result, (PyLongObject *)x); + Py_DECREF(x); + if (y == NULL) { + goto error; + } + Py_DECREF(result); + result = y; + } + + return result; + + error: + Py_DECREF(result); + return NULL; +} /*[clinic input] int.as_integer_ratio @@ -5460,6 +5526,7 @@ static PyMethodDef long_methods[] = { {"conjugate", long_long_meth, METH_NOARGS, "Returns self, the complex conjugate of any int."}, INT_BIT_LENGTH_METHODDEF + INT_BIT_COUNT_METHODDEF INT_TO_BYTES_METHODDEF INT_FROM_BYTES_METHODDEF INT_AS_INTEGER_RATIO_METHODDEF diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index 682bbe8a61e..e3d3bd6a174 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -1578,7 +1578,7 @@ pylong_as_ld(PyObject *item) PyObject *tmp; long ld; - tmp = PyNumber_Index(item); + tmp = _PyNumber_Index(item); if (tmp == NULL) return -1; @@ -1593,7 +1593,7 @@ pylong_as_lu(PyObject *item) PyObject *tmp; unsigned long lu; - tmp = PyNumber_Index(item); + tmp = _PyNumber_Index(item); if (tmp == NULL) return (unsigned long)-1; @@ -1608,7 +1608,7 @@ pylong_as_lld(PyObject *item) PyObject *tmp; long long lld; - tmp = PyNumber_Index(item); + tmp = _PyNumber_Index(item); if (tmp == NULL) return -1; @@ -1623,7 +1623,7 @@ pylong_as_llu(PyObject *item) PyObject *tmp; unsigned long long llu; - tmp = PyNumber_Index(item); + tmp = _PyNumber_Index(item); if (tmp == NULL) return (unsigned long long)-1; @@ -1638,7 +1638,7 @@ pylong_as_zd(PyObject *item) PyObject *tmp; Py_ssize_t zd; - tmp = PyNumber_Index(item); + tmp = _PyNumber_Index(item); if (tmp == NULL) return -1; @@ -1653,7 +1653,7 @@ pylong_as_zu(PyObject *item) PyObject *tmp; size_t zu; - tmp = PyNumber_Index(item); + tmp = _PyNumber_Index(item); if (tmp == NULL) return (size_t)-1; diff --git a/Objects/object.c b/Objects/object.c index 623ee52eb1e..4481fc91e1d 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -66,8 +66,7 @@ _Py_GetRefTotal(void) void _PyDebug_PrintTotalRefs(void) { fprintf(stderr, - "[%" PY_FORMAT_SIZE_T "d refs, " - "%" PY_FORMAT_SIZE_T "d blocks]\n", + "[%zd refs, %zd blocks]\n", _Py_GetRefTotal(), _Py_GetAllocatedBlocks()); } #endif /* Py_REF_DEBUG */ @@ -140,23 +139,23 @@ Py_DecRef(PyObject *o) PyObject * PyObject_Init(PyObject *op, PyTypeObject *tp) { - /* Any changes should be reflected in PyObject_INIT() macro */ if (op == NULL) { return PyErr_NoMemory(); } - return PyObject_INIT(op, tp); + _PyObject_Init(op, tp); + return op; } PyVarObject * PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, Py_ssize_t size) { - /* Any changes should be reflected in PyObject_INIT_VAR() macro */ if (op == NULL) { return (PyVarObject *) PyErr_NoMemory(); } - return PyObject_INIT_VAR(op, tp, size); + _PyObject_InitVar(op, tp, size); + return op; } PyObject * @@ -166,7 +165,7 @@ _PyObject_New(PyTypeObject *tp) if (op == NULL) { return PyErr_NoMemory(); } - PyObject_INIT(op, tp); + _PyObject_Init(op, tp); return op; } @@ -176,9 +175,11 @@ _PyObject_NewVar(PyTypeObject *tp, Py_ssize_t nitems) PyVarObject *op; const size_t size = _PyObject_VAR_SIZE(tp, nitems); op = (PyVarObject *) PyObject_MALLOC(size); - if (op == NULL) + if (op == NULL) { return (PyVarObject *)PyErr_NoMemory(); - return PyObject_INIT_VAR(op, tp, nitems); + } + _PyObject_InitVar(op, tp, nitems); + return op; } void @@ -1876,9 +1877,10 @@ _Py_PrintReferences(FILE *fp) PyObject *op; fprintf(fp, "Remaining objects:\n"); for (op = refchain._ob_next; op != &refchain; op = op->_ob_next) { - fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] ", (void *)op, Py_REFCNT(op)); - if (PyObject_Print(op, fp, 0) != 0) + fprintf(fp, "%p [%zd] ", (void *)op, Py_REFCNT(op)); + if (PyObject_Print(op, fp, 0) != 0) { PyErr_Clear(); + } putc('\n', fp); } } @@ -1892,7 +1894,7 @@ _Py_PrintReferenceAddresses(FILE *fp) PyObject *op; fprintf(fp, "Remaining object addresses:\n"); for (op = refchain._ob_next; op != &refchain; op = op->_ob_next) - fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] %s\n", (void *)op, + fprintf(fp, "%p [%zd] %s\n", (void *)op, Py_REFCNT(op), Py_TYPE(op)->tp_name); } @@ -2029,8 +2031,8 @@ finally: void _PyTrash_deposit_object(PyObject *op) { - PyThreadState *tstate = _PyThreadState_GET(); - struct _gc_runtime_state *gcstate = &tstate->interp->gc; + PyInterpreterState *interp = _PyInterpreterState_GET(); + struct _gc_runtime_state *gcstate = &interp->gc; _PyObject_ASSERT(op, _PyObject_IS_GC(op)); _PyObject_ASSERT(op, !_PyObject_GC_IS_TRACKED(op)); @@ -2057,8 +2059,8 @@ _PyTrash_thread_deposit_object(PyObject *op) void _PyTrash_destroy_chain(void) { - PyThreadState *tstate = _PyThreadState_GET(); - struct _gc_runtime_state *gcstate = &tstate->interp->gc; + PyInterpreterState *interp = _PyInterpreterState_GET(); + struct _gc_runtime_state *gcstate = &interp->gc; while (gcstate->trash_delete_later) { PyObject *op = gcstate->trash_delete_later; diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index eb34f10bddf..03d0e8e5126 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -2420,8 +2420,7 @@ _PyObject_DebugDumpAddress(const void *p) fprintf(stderr, " API '%c'\n", id); nbytes = read_size_t(q - 2*SST); - fprintf(stderr, " %" PY_FORMAT_SIZE_T "u bytes originally " - "requested\n", nbytes); + fprintf(stderr, " %zu bytes originally requested\n", nbytes); /* In case this is nuts, check the leading pad bytes first. */ fprintf(stderr, " The %d pad bytes at p-%d are ", SST-1, SST-1); @@ -2477,8 +2476,9 @@ _PyObject_DebugDumpAddress(const void *p) #ifdef PYMEM_DEBUG_SERIALNO size_t serial = read_size_t(tail + SST); - fprintf(stderr, " The block was made by call #%" PY_FORMAT_SIZE_T - "u to debug malloc/realloc.\n", serial); + fprintf(stderr, + " The block was made by call #%zu to debug malloc/realloc.\n", + serial); #endif if (nbytes > 0) { @@ -2553,7 +2553,7 @@ _PyDebugAllocatorStats(FILE *out, char buf1[128]; char buf2[128]; PyOS_snprintf(buf1, sizeof(buf1), - "%d %ss * %" PY_FORMAT_SIZE_T "d bytes each", + "%d %ss * %zd bytes each", num_blocks, block_name, sizeof_block); PyOS_snprintf(buf2, sizeof(buf2), "%48s ", buf1); @@ -2694,10 +2694,7 @@ _PyObject_DebugMallocStats(FILE *out) assert(b == 0 && f == 0); continue; } - fprintf(out, "%5u %6u " - "%11" PY_FORMAT_SIZE_T "u " - "%15" PY_FORMAT_SIZE_T "u " - "%13" PY_FORMAT_SIZE_T "u\n", + fprintf(out, "%5u %6u %11zu %15zu %13zu\n", i, size, p, b, f); allocated_bytes += b * size; available_bytes += f * size; @@ -2716,8 +2713,8 @@ _PyObject_DebugMallocStats(FILE *out) (void)printone(out, "# arenas allocated current", narenas); PyOS_snprintf(buf, sizeof(buf), - "%" PY_FORMAT_SIZE_T "u arenas * %d bytes/arena", - narenas, ARENA_SIZE); + "%zu arenas * %d bytes/arena", + narenas, ARENA_SIZE); (void)printone(out, buf, narenas * ARENA_SIZE); fputc('\n', out); diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 751dbb9815d..ba6d4257174 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -1,8 +1,8 @@ /* Range object implementation */ #include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_tupleobject.h" +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_tuple.h" // _PyTuple_ITEMS() #include "structmember.h" // PyMemberDef /* Support objects whose length is > PY_SSIZE_T_MAX. diff --git a/Objects/setobject.c b/Objects/setobject.c index 76b1944db45..b2711495b65 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -975,9 +975,6 @@ make_new_set_basetype(PyTypeObject *type, PyObject *iterable) return make_new_set(type, iterable); } -/* The empty frozenset is a singleton */ -static PyObject *emptyfrozenset = NULL; - static PyObject * make_new_frozenset(PyTypeObject *type, PyObject *iterable) { @@ -985,26 +982,12 @@ make_new_frozenset(PyTypeObject *type, PyObject *iterable) return make_new_set(type, iterable); } - if (iterable != NULL) { - if (PyFrozenSet_CheckExact(iterable)) { - /* frozenset(f) is idempotent */ - Py_INCREF(iterable); - return iterable; - } - PyObject *res = make_new_set((PyTypeObject *)type, iterable); - if (res == NULL || PySet_GET_SIZE(res) != 0) { - return res; - } - /* If the created frozenset is empty, return the empty frozenset singleton instead */ - Py_DECREF(res); + if (iterable != NULL && PyFrozenSet_CheckExact(iterable)) { + /* frozenset(f) is idempotent */ + Py_INCREF(iterable); + return iterable; } - - // The empty frozenset is a singleton - if (emptyfrozenset == NULL) { - emptyfrozenset = make_new_set((PyTypeObject *)type, NULL); - } - Py_XINCREF(emptyfrozenset); - return emptyfrozenset; + return make_new_set((PyTypeObject *)type, iterable); } static PyObject * @@ -2299,12 +2282,6 @@ PySet_Add(PyObject *anyset, PyObject *key) return set_add_key((PySetObject *)anyset, key); } -void -_PySet_Fini(void) -{ - Py_CLEAR(emptyfrozenset); -} - int _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash) { diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index 391711f711a..e8af623142b 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -15,7 +15,7 @@ this type and there is exactly one in existence. #include "Python.h" #include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_object.h" +#include "pycore_object.h" // _PyObject_GC_TRACK() #include "structmember.h" // PyMemberDef static PyObject * @@ -95,16 +95,13 @@ PyObject _Py_EllipsisObject = { /* Slice object implementation */ -/* Using a cache is very effective since typically only a single slice is - * created and then deleted again - */ -static PySliceObject *slice_cache = NULL; -void _PySlice_Fini(void) +void _PySlice_Fini(PyThreadState *tstate) { - PySliceObject *obj = slice_cache; + PyInterpreterState *interp = tstate->interp; + PySliceObject *obj = interp->slice_cache; if (obj != NULL) { - slice_cache = NULL; + interp->slice_cache = NULL; PyObject_GC_Del(obj); } } @@ -116,26 +113,35 @@ void _PySlice_Fini(void) PyObject * PySlice_New(PyObject *start, PyObject *stop, PyObject *step) { - PySliceObject *obj; - if (slice_cache != NULL) { - obj = slice_cache; - slice_cache = NULL; - _Py_NewReference((PyObject *)obj); - } else { - obj = PyObject_GC_New(PySliceObject, &PySlice_Type); - if (obj == NULL) - return NULL; + if (step == NULL) { + step = Py_None; + } + if (start == NULL) { + start = Py_None; + } + if (stop == NULL) { + stop = Py_None; } - if (step == NULL) step = Py_None; - Py_INCREF(step); - if (start == NULL) start = Py_None; - Py_INCREF(start); - if (stop == NULL) stop = Py_None; - Py_INCREF(stop); + PyInterpreterState *interp = _PyInterpreterState_GET(); + PySliceObject *obj; + if (interp->slice_cache != NULL) { + obj = interp->slice_cache; + interp->slice_cache = NULL; + _Py_NewReference((PyObject *)obj); + } + else { + obj = PyObject_GC_New(PySliceObject, &PySlice_Type); + if (obj == NULL) { + return NULL; + } + } + Py_INCREF(step); obj->step = step; + Py_INCREF(start); obj->start = start; + Py_INCREF(stop); obj->stop = stop; _PyObject_GC_TRACK(obj); @@ -324,14 +330,17 @@ Create a slice object. This is used for extended slicing (e.g. a[0:10:2])."); static void slice_dealloc(PySliceObject *r) { + PyInterpreterState *interp = _PyInterpreterState_GET(); _PyObject_GC_UNTRACK(r); Py_DECREF(r->step); Py_DECREF(r->start); Py_DECREF(r->stop); - if (slice_cache == NULL) - slice_cache = r; - else + if (interp->slice_cache == NULL) { + interp->slice_cache = r; + } + else { PyObject_GC_Del(r); + } } static PyObject * diff --git a/Objects/stringlib/README.txt b/Objects/stringlib/README.txt index 8ff6ad8c4fa..e1e329290ac 100644 --- a/Objects/stringlib/README.txt +++ b/Objects/stringlib/README.txt @@ -11,10 +11,10 @@ STRINGLIB_CHAR the type used to hold a character (char or Py_UNICODE) -STRINGLIB_EMPTY +STRINGLIB_GET_EMPTY() - a PyObject representing the empty string, only to be used if - STRINGLIB_MUTABLE is 0 + returns a PyObject representing the empty string, only to be used if + STRINGLIB_MUTABLE is 0. It must not be NULL. Py_ssize_t STRINGLIB_LEN(PyObject*) diff --git a/Objects/stringlib/asciilib.h b/Objects/stringlib/asciilib.h index e69a2c076e3..7749e8fb339 100644 --- a/Objects/stringlib/asciilib.h +++ b/Objects/stringlib/asciilib.h @@ -11,7 +11,6 @@ #define STRINGLIB_CHAR Py_UCS1 #define STRINGLIB_TYPE_NAME "unicode" #define STRINGLIB_PARSE_CODE "U" -#define STRINGLIB_EMPTY unicode_empty #define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE #define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK #define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL diff --git a/Objects/stringlib/clinic/transmogrify.h.h b/Objects/stringlib/clinic/transmogrify.h.h index 8dd7e6b5bb9..a5135a0cba0 100644 --- a/Objects/stringlib/clinic/transmogrify.h.h +++ b/Objects/stringlib/clinic/transmogrify.h.h @@ -70,7 +70,7 @@ stringlib_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -126,7 +126,7 @@ stringlib_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -182,7 +182,7 @@ stringlib_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs) } { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[0]); + PyObject *iobj = _PyNumber_Index(args[0]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -234,7 +234,7 @@ stringlib_zfill(PyObject *self, PyObject *arg) { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(arg); + PyObject *iobj = _PyNumber_Index(arg); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -249,4 +249,4 @@ stringlib_zfill(PyObject *self, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=cd5ecdbf1d9e849a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2d9abc7b1cffeca6 input=a9049054013a1b77]*/ diff --git a/Objects/stringlib/codecs.h b/Objects/stringlib/codecs.h index 9b2a29ba3b8..197605b012e 100644 --- a/Objects/stringlib/codecs.h +++ b/Objects/stringlib/codecs.h @@ -4,7 +4,7 @@ # error "codecs.h is specific to Unicode" #endif -#include "pycore_byteswap.h" // _Py_bswap32() +#include "pycore_bitutils.h" // _Py_bswap32() /* Mask to quickly check whether a C 'long' contains a non-ASCII, UTF8-encoded char. */ diff --git a/Objects/stringlib/partition.h b/Objects/stringlib/partition.h index ed32a6f2b38..bcc217697b2 100644 --- a/Objects/stringlib/partition.h +++ b/Objects/stringlib/partition.h @@ -1,9 +1,14 @@ /* stringlib: partition implementation */ #ifndef STRINGLIB_FASTSEARCH_H -#error must include "stringlib/fastsearch.h" before including this module +# error must include "stringlib/fastsearch.h" before including this module #endif +#if !STRINGLIB_MUTABLE && !defined(STRINGLIB_GET_EMPTY) +# error "STRINGLIB_GET_EMPTY must be defined if STRINGLIB_MUTABLE is zero" +#endif + + Py_LOCAL_INLINE(PyObject*) STRINGLIB(partition)(PyObject* str_obj, const STRINGLIB_CHAR* str, Py_ssize_t str_len, @@ -37,10 +42,12 @@ STRINGLIB(partition)(PyObject* str_obj, #else Py_INCREF(str_obj); PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); - Py_INCREF(STRINGLIB_EMPTY); - PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY); - Py_INCREF(STRINGLIB_EMPTY); - PyTuple_SET_ITEM(out, 2, (PyObject*) STRINGLIB_EMPTY); + PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); + assert(empty != NULL); + Py_INCREF(empty); + PyTuple_SET_ITEM(out, 1, empty); + Py_INCREF(empty); + PyTuple_SET_ITEM(out, 2, empty); #endif return out; } @@ -90,10 +97,12 @@ STRINGLIB(rpartition)(PyObject* str_obj, return NULL; } #else - Py_INCREF(STRINGLIB_EMPTY); - PyTuple_SET_ITEM(out, 0, (PyObject*) STRINGLIB_EMPTY); - Py_INCREF(STRINGLIB_EMPTY); - PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY); + PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); + assert(empty != NULL); + Py_INCREF(empty); + PyTuple_SET_ITEM(out, 0, empty); + Py_INCREF(empty); + PyTuple_SET_ITEM(out, 1, empty); Py_INCREF(str_obj); PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj); #endif diff --git a/Objects/stringlib/stringdefs.h b/Objects/stringlib/stringdefs.h index ce27f3e4081..88641b25d47 100644 --- a/Objects/stringlib/stringdefs.h +++ b/Objects/stringlib/stringdefs.h @@ -13,7 +13,6 @@ #define STRINGLIB_CHAR char #define STRINGLIB_TYPE_NAME "string" #define STRINGLIB_PARSE_CODE "S" -#define STRINGLIB_EMPTY nullstring #define STRINGLIB_ISSPACE Py_ISSPACE #define STRINGLIB_ISLINEBREAK(x) ((x == '\n') || (x == '\r')) #define STRINGLIB_ISDECIMAL(x) ((x >= '0') && (x <= '9')) diff --git a/Objects/stringlib/ucs1lib.h b/Objects/stringlib/ucs1lib.h index bc4b104f112..5b0b8a025e8 100644 --- a/Objects/stringlib/ucs1lib.h +++ b/Objects/stringlib/ucs1lib.h @@ -11,7 +11,6 @@ #define STRINGLIB_CHAR Py_UCS1 #define STRINGLIB_TYPE_NAME "unicode" #define STRINGLIB_PARSE_CODE "U" -#define STRINGLIB_EMPTY unicode_empty #define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE #define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK #define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL diff --git a/Objects/stringlib/ucs2lib.h b/Objects/stringlib/ucs2lib.h index 86a1dff1b56..6af01511c5f 100644 --- a/Objects/stringlib/ucs2lib.h +++ b/Objects/stringlib/ucs2lib.h @@ -11,7 +11,6 @@ #define STRINGLIB_CHAR Py_UCS2 #define STRINGLIB_TYPE_NAME "unicode" #define STRINGLIB_PARSE_CODE "U" -#define STRINGLIB_EMPTY unicode_empty #define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE #define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK #define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL diff --git a/Objects/stringlib/ucs4lib.h b/Objects/stringlib/ucs4lib.h index 3c32a93c96a..39071a0cdf0 100644 --- a/Objects/stringlib/ucs4lib.h +++ b/Objects/stringlib/ucs4lib.h @@ -11,7 +11,6 @@ #define STRINGLIB_CHAR Py_UCS4 #define STRINGLIB_TYPE_NAME "unicode" #define STRINGLIB_PARSE_CODE "U" -#define STRINGLIB_EMPTY unicode_empty #define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE #define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK #define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL diff --git a/Objects/stringlib/unicodedefs.h b/Objects/stringlib/unicodedefs.h index 3db5629e11f..5ea79cd4f50 100644 --- a/Objects/stringlib/unicodedefs.h +++ b/Objects/stringlib/unicodedefs.h @@ -13,7 +13,6 @@ #define STRINGLIB_CHAR Py_UNICODE #define STRINGLIB_TYPE_NAME "unicode" #define STRINGLIB_PARSE_CODE "U" -#define STRINGLIB_EMPTY unicode_empty #define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE #define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK #define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL diff --git a/Objects/structseq.c b/Objects/structseq.c index 9bdda87ae0b..bd20ce3fbdc 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -8,8 +8,8 @@ */ #include "Python.h" -#include "pycore_tupleobject.h" -#include "pycore_object.h" +#include "pycore_tuple.h" // _PyTuple_FromArray() +#include "pycore_object.h" // _PyObject_GC_TRACK() #include "structmember.h" // PyMemberDef static const char visible_length_key[] = "n_sequence_fields"; @@ -70,6 +70,9 @@ PyStructSequence_GetItem(PyObject* op, Py_ssize_t i) static int structseq_traverse(PyStructSequence *obj, visitproc visit, void *arg) { + if (Py_TYPE(obj)->tp_flags & Py_TPFLAGS_HEAPTYPE) { + Py_VISIT(Py_TYPE(obj)); + } Py_ssize_t i, size; size = REAL_SIZE(obj); for (i = 0; i < size; ++i) { diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index e4c0c91cfe8..41677d7e710 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -2,10 +2,10 @@ /* Tuple object implementation */ #include "Python.h" -#include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_accu.h" -#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED() -#include "pycore_object.h" +#include "pycore_abstract.h" // _PyIndex_Check() +#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED() +#include "pycore_initconfig.h" // _PyStatus_OK() +#include "pycore_object.h" // _PyObject_GC_TRACK() /*[clinic input] class tuple "PyTupleObject *" "&PyTuple_Type" @@ -14,47 +14,36 @@ class tuple "PyTupleObject *" "&PyTuple_Type" #include "clinic/tupleobject.c.h" -/* Speed optimization to avoid frequent malloc/free of small tuples */ -#ifndef PyTuple_MAXSAVESIZE -#define PyTuple_MAXSAVESIZE 20 /* Largest tuple to save on free list */ -#endif -#ifndef PyTuple_MAXFREELIST -#define PyTuple_MAXFREELIST 2000 /* Maximum number of tuples of each size to save */ -#endif - -/* bpo-40521: tuple free lists are shared by all interpreters. */ -#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS -# undef PyTuple_MAXSAVESIZE -# define PyTuple_MAXSAVESIZE 0 -#endif #if PyTuple_MAXSAVESIZE > 0 -/* Entries 1 up to PyTuple_MAXSAVESIZE are free lists, entry 0 is the empty - tuple () of which at most one instance will be allocated. -*/ -static PyTupleObject *free_list[PyTuple_MAXSAVESIZE]; -static int numfree[PyTuple_MAXSAVESIZE]; +static struct _Py_tuple_state * +get_tuple_state(void) +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + return &interp->tuple; +} #endif + static inline void tuple_gc_track(PyTupleObject *op) { _PyObject_GC_TRACK(op); } + /* Print summary info about the state of the optimized allocator */ void _PyTuple_DebugMallocStats(FILE *out) { #if PyTuple_MAXSAVESIZE > 0 - int i; - char buf[128]; - for (i = 1; i < PyTuple_MAXSAVESIZE; i++) { + struct _Py_tuple_state *state = get_tuple_state(); + for (int i = 1; i < PyTuple_MAXSAVESIZE; i++) { + char buf[128]; PyOS_snprintf(buf, sizeof(buf), "free %d-sized PyTupleObject", i); - _PyDebugAllocatorStats(out, - buf, - numfree[i], _PyObject_VAR_SIZE(&PyTuple_Type, i)); + _PyDebugAllocatorStats(out, buf, state->numfree[i], + _PyObject_VAR_SIZE(&PyTuple_Type, i)); } #endif } @@ -71,18 +60,29 @@ static PyTupleObject * tuple_alloc(Py_ssize_t size) { PyTupleObject *op; +#if PyTuple_MAXSAVESIZE > 0 + // If Python is built with the empty tuple singleton, + // tuple_alloc(0) must not be called. + assert(size != 0); +#endif if (size < 0) { PyErr_BadInternalCall(); return NULL; } + #if PyTuple_MAXSAVESIZE > 0 - if (size < PyTuple_MAXSAVESIZE && (op = free_list[size]) != NULL) { + struct _Py_tuple_state *state = get_tuple_state(); +#ifdef Py_DEBUG + // tuple_alloc() must not be called after _PyTuple_Fini() + assert(state->numfree[0] != -1); +#endif + if (size < PyTuple_MAXSAVESIZE && (op = state->free_list[size]) != NULL) { assert(size != 0); - free_list[size] = (PyTupleObject *) op->ob_item[0]; - numfree[size]--; - /* Inline PyObject_InitVar */ + state->free_list[size] = (PyTupleObject *) op->ob_item[0]; + state->numfree[size]--; + /* Inlined _PyObject_InitVar() without _PyType_HasFeature() test */ #ifdef Py_TRACE_REFS - Py_SIZE(op) = size; + Py_SET_SIZE(op, size); Py_SET_TYPE(op, &PyTuple_Type); #endif _Py_NewReference((PyObject *)op); @@ -102,15 +102,56 @@ tuple_alloc(Py_ssize_t size) return op; } +static int +tuple_create_empty_tuple_singleton(struct _Py_tuple_state *state) +{ +#if PyTuple_MAXSAVESIZE > 0 + assert(state->free_list[0] == NULL); + + PyTupleObject *op = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, 0); + if (op == NULL) { + return -1; + } + // The empty tuple singleton is not tracked by the GC. + // It does not contain any Python object. + + state->free_list[0] = op; + state->numfree[0]++; + + assert(state->numfree[0] == 1); +#endif + return 0; +} + + +static PyObject * +tuple_get_empty(void) +{ +#if PyTuple_MAXSAVESIZE > 0 + struct _Py_tuple_state *state = get_tuple_state(); + PyTupleObject *op = state->free_list[0]; + // tuple_get_empty() must not be called before _PyTuple_Init() + // or after _PyTuple_Fini() + assert(op != NULL); +#ifdef Py_DEBUG + assert(state->numfree[0] != -1); +#endif + + Py_INCREF(op); + return (PyObject *) op; +#else + return PyTuple_New(0); +#endif +} + + PyObject * PyTuple_New(Py_ssize_t size) { PyTupleObject *op; #if PyTuple_MAXSAVESIZE > 0 - if (size == 0 && free_list[0]) { - op = free_list[0]; - Py_INCREF(op); - return (PyObject *) op; + if (size == 0) { + return tuple_get_empty(); } #endif op = tuple_alloc(size); @@ -120,13 +161,6 @@ PyTuple_New(Py_ssize_t size) for (Py_ssize_t i = 0; i < size; i++) { op->ob_item[i] = NULL; } -#if PyTuple_MAXSAVESIZE > 0 - if (size == 0) { - free_list[0] = op; - ++numfree[0]; - Py_INCREF(op); /* extra INCREF so that this is never freed */ - } -#endif tuple_gc_track(op); return (PyObject *) op; } @@ -207,7 +241,7 @@ PyTuple_Pack(Py_ssize_t n, ...) va_list vargs; if (n == 0) { - return PyTuple_New(0); + return tuple_get_empty(); } va_start(vargs, n); @@ -233,27 +267,33 @@ PyTuple_Pack(Py_ssize_t n, ...) static void tupledealloc(PyTupleObject *op) { - Py_ssize_t i; Py_ssize_t len = Py_SIZE(op); PyObject_GC_UnTrack(op); Py_TRASHCAN_BEGIN(op, tupledealloc) if (len > 0) { - i = len; - while (--i >= 0) + Py_ssize_t i = len; + while (--i >= 0) { Py_XDECREF(op->ob_item[i]); + } #if PyTuple_MAXSAVESIZE > 0 - if (len < PyTuple_MAXSAVESIZE && - numfree[len] < PyTuple_MAXFREELIST && - Py_IS_TYPE(op, &PyTuple_Type)) + struct _Py_tuple_state *state = get_tuple_state(); +#ifdef Py_DEBUG + // tupledealloc() must not be called after _PyTuple_Fini() + assert(state->numfree[0] != -1); +#endif + if (len < PyTuple_MAXSAVESIZE + && state->numfree[len] < PyTuple_MAXFREELIST + && Py_IS_TYPE(op, &PyTuple_Type)) { - op->ob_item[0] = (PyObject *) free_list[len]; - numfree[len]++; - free_list[len] = op; + op->ob_item[0] = (PyObject *) state->free_list[len]; + state->numfree[len]++; + state->free_list[len] = op; goto done; /* return */ } #endif } Py_TYPE(op)->tp_free((PyObject *)op); + #if PyTuple_MAXSAVESIZE > 0 done: #endif @@ -420,7 +460,7 @@ PyObject * _PyTuple_FromArray(PyObject *const *src, Py_ssize_t n) { if (n == 0) { - return PyTuple_New(0); + return tuple_get_empty(); } PyTupleObject *tuple = tuple_alloc(n); @@ -481,7 +521,8 @@ tupleconcat(PyTupleObject *a, PyObject *bb) Py_TYPE(bb)->tp_name); return NULL; } -#define b ((PyTupleObject *)bb) + PyTupleObject *b = (PyTupleObject *)bb; + if (Py_SIZE(b) == 0 && PyTuple_CheckExact(a)) { Py_INCREF(a); return (PyObject *)a; @@ -489,7 +530,7 @@ tupleconcat(PyTupleObject *a, PyObject *bb) assert((size_t)Py_SIZE(a) + (size_t)Py_SIZE(b) < PY_SSIZE_T_MAX); size = Py_SIZE(a) + Py_SIZE(b); if (size == 0) { - return PyTuple_New(0); + return tuple_get_empty(); } np = tuple_alloc(size); @@ -512,7 +553,6 @@ tupleconcat(PyTupleObject *a, PyObject *bb) } tuple_gc_track(np); return (PyObject *)np; -#undef b } static PyObject * @@ -531,7 +571,7 @@ tuplerepeat(PyTupleObject *a, Py_ssize_t n) } } if (Py_SIZE(a) == 0 || n <= 0) { - return PyTuple_New(0); + return tuple_get_empty(); } if (n > PY_SSIZE_T_MAX / Py_SIZE(a)) return PyErr_NoMemory(); @@ -707,10 +747,12 @@ tuple_new_impl(PyTypeObject *type, PyObject *iterable) if (type != &PyTuple_Type) return tuple_subtype_new(type, iterable); - if (iterable == NULL) - return PyTuple_New(0); - else + if (iterable == NULL) { + return tuple_get_empty(); + } + else { return PySequence_Tuple(iterable); + } } static PyObject * @@ -729,7 +771,9 @@ tuple_vectorcall(PyObject *type, PyObject * const*args, if (nargs) { return tuple_new_impl((PyTypeObject *)type, args[0]); } - return PyTuple_New(0); + else { + return tuple_get_empty(); + } } static PyObject * @@ -792,7 +836,7 @@ tuplesubscript(PyTupleObject* self, PyObject* item) &stop, step); if (slicelength <= 0) { - return PyTuple_New(0); + return tuple_get_empty(); } else if (start == 0 && step == 1 && slicelength == PyTuple_GET_SIZE(self) && @@ -963,13 +1007,14 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize) } void -_PyTuple_ClearFreeList(void) +_PyTuple_ClearFreeList(PyThreadState *tstate) { #if PyTuple_MAXSAVESIZE > 0 + struct _Py_tuple_state *state = &tstate->interp->tuple; for (Py_ssize_t i = 1; i < PyTuple_MAXSAVESIZE; i++) { - PyTupleObject *p = free_list[i]; - free_list[i] = NULL; - numfree[i] = 0; + PyTupleObject *p = state->free_list[i]; + state->free_list[i] = NULL; + state->numfree[i] = 0; while (p) { PyTupleObject *q = p; p = (PyTupleObject *)(p->ob_item[0]); @@ -980,15 +1025,30 @@ _PyTuple_ClearFreeList(void) #endif } + +PyStatus +_PyTuple_Init(PyThreadState *tstate) +{ + struct _Py_tuple_state *state = &tstate->interp->tuple; + if (tuple_create_empty_tuple_singleton(state) < 0) { + return _PyStatus_NO_MEMORY(); + } + return _PyStatus_OK(); +} + + void -_PyTuple_Fini(void) +_PyTuple_Fini(PyThreadState *tstate) { #if PyTuple_MAXSAVESIZE > 0 - /* empty tuples are used all over the place and applications may - * rely on the fact that an empty tuple is a singleton. */ - Py_CLEAR(free_list[0]); - - _PyTuple_ClearFreeList(); + struct _Py_tuple_state *state = &tstate->interp->tuple; + // The empty tuple singleton must not be tracked by the GC + assert(!_PyObject_GC_IS_TRACKED(state->free_list[0])); + Py_CLEAR(state->free_list[0]); + _PyTuple_ClearFreeList(tstate); +#ifdef Py_DEBUG + state->numfree[0] = -1; +#endif #endif } diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 0e055d677f1..16f95f0e1bf 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -97,6 +97,9 @@ clear_slotdefs(void); static PyObject * lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound); +static int +slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value); + /* * finds the beginning of the docstring's introspection signature. * if present, returns a pointer pointing to the first '('. @@ -1039,42 +1042,6 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds) return obj; } -PyObject * -PyType_FromSpec_Alloc(PyTypeObject *type, Py_ssize_t nitems) -{ - PyObject *obj; - const size_t size = _Py_SIZE_ROUND_UP( - _PyObject_VAR_SIZE(type, nitems+1) + sizeof(traverseproc), - SIZEOF_VOID_P); - /* note that we need to add one, for the sentinel and space for the - provided tp-traverse: See bpo-40217 for more details */ - - if (PyType_IS_GC(type)) { - obj = _PyObject_GC_Malloc(size); - } - else { - obj = (PyObject *)PyObject_MALLOC(size); - } - - if (obj == NULL) { - return PyErr_NoMemory(); - } - - memset(obj, '\0', size); - - if (type->tp_itemsize == 0) { - (void)PyObject_INIT(obj, type); - } - else { - (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems); - } - - if (PyType_IS_GC(type)) { - _PyObject_GC_TRACK(obj); - } - return obj; -} - PyObject * PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems) { @@ -1096,10 +1063,10 @@ PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems) memset(obj, '\0', size); if (type->tp_itemsize == 0) { - (void)PyObject_INIT(obj, type); + _PyObject_Init(obj, type); } else { - (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems); + _PyObject_InitVar((PyVarObject *)obj, type, nitems); } if (_PyType_IS_GC(type)) { @@ -1164,11 +1131,16 @@ subtype_traverse(PyObject *self, visitproc visit, void *arg) Py_VISIT(*dictptr); } - if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) + if (type->tp_flags & Py_TPFLAGS_HEAPTYPE + && (!basetraverse || !(base->tp_flags & Py_TPFLAGS_HEAPTYPE))) { /* For a heaptype, the instances count as references to the type. Traverse the type so the collector - can find cycles involving this link. */ + can find cycles involving this link. + Skip this visit if basetraverse belongs to a heap type: in that + case, basetraverse will visit the type when we call it later. + */ Py_VISIT(type); + } if (basetraverse) return basetraverse(self, visit, arg); @@ -2910,36 +2882,6 @@ static const short slotoffsets[] = { #include "typeslots.inc" }; -static int -PyType_FromSpec_tp_traverse(PyObject *self, visitproc visit, void *arg) -{ - PyTypeObject *parent = Py_TYPE(self); - - // Only a instance of a type that is directly created by - // PyType_FromSpec (not subclasses) must visit its parent. - if (parent->tp_traverse == PyType_FromSpec_tp_traverse) { - Py_VISIT(parent); - } - - // Search for the original type that was created using PyType_FromSpec - PyTypeObject *base; - base = parent; - while (base->tp_traverse != PyType_FromSpec_tp_traverse) { - base = base->tp_base; - assert(base); - } - - // Extract the user defined traverse function that we placed at the end - // of the type and call it. - size_t size = Py_SIZE(base); - size_t _offset = _PyObject_VAR_SIZE(&PyType_Type, size+1); - traverseproc fun = *(traverseproc*)((char*)base + _offset); - if (fun == NULL) { - return 0; - } - return fun(self, visit, arg); -} - PyObject * PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) { @@ -2985,7 +2927,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) } } - res = (PyHeapTypeObject*)PyType_FromSpec_Alloc(&PyType_Type, nmembers); + res = (PyHeapTypeObject*)PyType_GenericAlloc(&PyType_Type, nmembers); if (res == NULL) return NULL; res_start = (char*)res; @@ -3093,30 +3035,6 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) memcpy(PyHeapType_GET_MEMBERS(res), slot->pfunc, len); type->tp_members = PyHeapType_GET_MEMBERS(res); } - else if (slot->slot == Py_tp_traverse) { - - /* Types created by PyType_FromSpec own a strong reference to their - * type, but this was added in Python 3.8. The tp_traverse function - * needs to call Py_VISIT on the type but all existing traverse - * functions cannot be updated (especially the ones from existing user - * functions) so we need to provide a tp_traverse that manually calls - * Py_VISIT(Py_TYPE(self)) and then call the provided tp_traverse. In - * this way, user functions do not need to be updated, preserve - * backwards compatibility. - * - * We store the user-provided traverse function at the end of the type - * (we have allocated space for it) so we can call it from our - * PyType_FromSpec_tp_traverse wrapper. - * - * Check bpo-40217 for more information and rationale about this issue. - * - * */ - - type->tp_traverse = PyType_FromSpec_tp_traverse; - size_t _offset = _PyObject_VAR_SIZE(&PyType_Type, nmembers+1); - traverseproc *user_traverse = (traverseproc*)((char*)type + _offset); - *user_traverse = slot->pfunc; - } else { /* Copy other slots directly */ *(void**)(res_start + slotoffsets[slot->slot]) = slot->pfunc; @@ -3152,23 +3070,28 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) } /* Set type.__module__ */ - s = strrchr(spec->name, '.'); - if (s != NULL) { - int err; - modname = PyUnicode_FromStringAndSize( - spec->name, (Py_ssize_t)(s - spec->name)); - if (modname == NULL) { + if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___module__) == NULL) { + if (PyErr_Occurred()) { goto fail; } - err = _PyDict_SetItemId(type->tp_dict, &PyId___module__, modname); - Py_DECREF(modname); - if (err != 0) - goto fail; - } else { - if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, - "builtin type %.200s has no __module__ attribute", - spec->name)) - goto fail; + s = strrchr(spec->name, '.'); + if (s != NULL) { + int err; + modname = PyUnicode_FromStringAndSize( + spec->name, (Py_ssize_t)(s - spec->name)); + if (modname == NULL) { + goto fail; + } + err = _PyDict_SetItemId(type->tp_dict, &PyId___module__, modname); + Py_DECREF(modname); + if (err != 0) + goto fail; + } else { + if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "builtin type %.200s has no __module__ attribute", + spec->name)) + goto fail; + } } return (PyObject*)res; @@ -6025,22 +5948,38 @@ wrap_delitem(PyObject *self, PyObject *args, void *wrapped) } /* Helper to check for object.__setattr__ or __delattr__ applied to a type. - This is called the Carlo Verre hack after its discoverer. */ + This is called the Carlo Verre hack after its discoverer. See + https://mail.python.org/pipermail/python-dev/2003-April/034535.html + */ static int hackcheck(PyObject *self, setattrofunc func, const char *what) { PyTypeObject *type = Py_TYPE(self); - while (type && type->tp_flags & Py_TPFLAGS_HEAPTYPE) - type = type->tp_base; - /* If type is NULL now, this is a really weird type. - In the spirit of backwards compatibility (?), just shut up. */ - if (type && type->tp_setattro != func) { - PyErr_Format(PyExc_TypeError, - "can't apply this %s to %s object", - what, - type->tp_name); - return 0; + PyObject *mro = type->tp_mro; + if (!mro) { + /* Probably ok not to check the call in this case. */ + return 1; } + assert(PyTuple_Check(mro)); + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + PyTypeObject *base = (PyTypeObject*) PyTuple_GET_ITEM(mro, i); + if (base->tp_setattro == func) { + /* 'func' is the earliest non-Python implementation in the MRO. */ + break; + } else if (base->tp_setattro != slot_tp_setattro) { + /* 'base' is not a Python class and overrides 'func'. + Its tp_setattro should be called instead. */ + PyErr_Format(PyExc_TypeError, + "can't apply this %s to %s object", + what, + type->tp_name); + return 0; + } + } + /* Either 'func' is not in the mro (which should fail when checking 'self'), + or it's the right slot function to call. */ return 1; } @@ -6419,7 +6358,7 @@ slot_sq_length(PyObject *self) if (res == NULL) return -1; - Py_SETREF(res, PyNumber_Index(res)); + Py_SETREF(res, _PyNumber_Index(res)); if (res == NULL) return -1; diff --git a/Objects/typeslots.inc b/Objects/typeslots.inc index dc750cc0c41..ffc9bb2e1c7 100644 --- a/Objects/typeslots.inc +++ b/Objects/typeslots.inc @@ -1,6 +1,6 @@ /* Generated by typeslots.py */ -0, -0, +offsetof(PyHeapTypeObject, as_buffer.bf_getbuffer), +offsetof(PyHeapTypeObject, as_buffer.bf_releasebuffer), offsetof(PyHeapTypeObject, as_mapping.mp_ass_subscript), offsetof(PyHeapTypeObject, as_mapping.mp_length), offsetof(PyHeapTypeObject, as_mapping.mp_subscript), diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index ea46a44bf5f..809ed85895f 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -41,23 +41,22 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define PY_SSIZE_T_CLEAN #include "Python.h" #include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_bytes_methods.h" -#include "pycore_fileutils.h" -#include "pycore_initconfig.h" +#include "pycore_bytes_methods.h" // _Py_bytes_lower() +#include "pycore_initconfig.h" // _PyStatus_OK() #include "pycore_interp.h" // PyInterpreterState.fs_codec -#include "pycore_object.h" -#include "pycore_pathconfig.h" -#include "pycore_pylifecycle.h" +#include "pycore_object.h" // _PyObject_GC_TRACK() +#include "pycore_pathconfig.h" // _Py_DumpPathConfig() +#include "pycore_pylifecycle.h" // _Py_SetFileSystemEncoding() #include "pycore_pystate.h" // _PyInterpreterState_GET() -#include "ucnhash.h" -#include "stringlib/eq.h" +#include "ucnhash.h" // _PyUnicode_Name_CAPI +#include "stringlib/eq.h" // unicode_eq() #ifdef MS_WINDOWS #include #endif -/* Uncomment to display statistics on interned strings at exit when - using Valgrind or Insecure++. */ +/* Uncomment to display statistics on interned strings at exit + in _PyUnicode_ClearInterned(). */ /* #define INTERNED_STATS 1 */ @@ -120,6 +119,13 @@ extern "C" { _PyUnicode_UTF8_LENGTH(op)) #define _PyUnicode_WSTR(op) \ (((PyASCIIObject*)(op))->wstr) + +/* Don't use deprecated macro of unicodeobject.h */ +#undef PyUnicode_WSTR_LENGTH +#define PyUnicode_WSTR_LENGTH(op) \ + (PyUnicode_IS_COMPACT_ASCII(op) ? \ + ((PyASCIIObject*)op)->length : \ + ((PyCompactUnicodeObject*)op)->wstr_length) #define _PyUnicode_WSTR_LENGTH(op) \ (((PyCompactUnicodeObject*)(op))->wstr_length) #define _PyUnicode_LENGTH(op) \ @@ -215,26 +221,36 @@ extern "C" { static PyObject *interned = NULL; #endif -/* The empty Unicode object is shared to improve performance. */ -static PyObject *unicode_empty = NULL; +static struct _Py_unicode_state* +get_unicode_state(void) +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + return &interp->unicode; +} -#define _Py_INCREF_UNICODE_EMPTY() \ - do { \ - if (unicode_empty != NULL) \ - Py_INCREF(unicode_empty); \ - else { \ - unicode_empty = PyUnicode_New(0, 0); \ - if (unicode_empty != NULL) { \ - Py_INCREF(unicode_empty); \ - assert(_PyUnicode_CheckConsistency(unicode_empty, 1)); \ - } \ - } \ - } while (0) -#define _Py_RETURN_UNICODE_EMPTY() \ - do { \ - _Py_INCREF_UNICODE_EMPTY(); \ - return unicode_empty; \ +// Return a borrowed reference to the empty string singleton. +static inline PyObject* unicode_get_empty(void) +{ + struct _Py_unicode_state *state = get_unicode_state(); + // unicode_get_empty() must not be called before _PyUnicode_Init() + // or after _PyUnicode_Fini() + assert(state->empty_string != NULL); + return state->empty_string; +} + + +// Return a strong reference to the empty string singleton. +static inline PyObject* unicode_new_empty(void) +{ + PyObject *empty = unicode_get_empty(); + Py_INCREF(empty); + return empty; +} + +#define _Py_RETURN_UNICODE_EMPTY() \ + do { \ + return unicode_new_empty(); \ } while (0) static inline void @@ -288,17 +304,6 @@ unicode_decode_utf8(const char *s, Py_ssize_t size, /* List of static strings. */ static _Py_Identifier *static_strings = NULL; -/* bpo-40521: Latin1 singletons are shared by all interpreters. */ -#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS -# define LATIN1_SINGLETONS -#endif - -#ifdef LATIN1_SINGLETONS -/* Single character Unicode strings in the Latin-1 range are being - shared as well. */ -static PyObject *unicode_latin1[256] = {NULL}; -#endif - /* Fast detection of the most frequent whitespace characters */ const unsigned char _Py_ascii_whitespace[] = { 0, 0, 0, 0, 0, 0, 0, 0, @@ -492,20 +497,6 @@ unicode_check_encoding_errors(const char *encoding, const char *errors) } -/* The max unicode value is always 0x10FFFF while using the PEP-393 API. - This function is kept for backward compatibility with the old API. */ -Py_UNICODE -PyUnicode_GetMax(void) -{ -#ifdef Py_UNICODE_WIDE - return 0x10FFFF; -#else - /* This is actually an illegal character, so it should - not be passed to unichr. */ - return 0xFFFF; -#endif -} - int _PyUnicode_CheckConsistency(PyObject *op, int check_content) { @@ -642,9 +633,8 @@ unicode_result_wchar(PyObject *unicode) if (len == 1) { wchar_t ch = _PyUnicode_WSTR(unicode)[0]; if ((Py_UCS4)ch < 256) { - PyObject *latin1_char = get_latin1_char((unsigned char)ch); Py_DECREF(unicode); - return latin1_char; + return get_latin1_char((unsigned char)ch); } } @@ -669,20 +659,21 @@ unicode_result_ready(PyObject *unicode) length = PyUnicode_GET_LENGTH(unicode); if (length == 0) { - if (unicode != unicode_empty) { + PyObject *empty = unicode_get_empty(); + if (unicode != empty) { Py_DECREF(unicode); - _Py_RETURN_UNICODE_EMPTY(); + Py_INCREF(empty); } - return unicode_empty; + return empty; } -#ifdef LATIN1_SINGLETONS if (length == 1) { - const void *data = PyUnicode_DATA(unicode); int kind = PyUnicode_KIND(unicode); - Py_UCS4 ch = PyUnicode_READ(kind, data, 0); - if (ch < 256) { - PyObject *latin1_char = unicode_latin1[ch]; + if (kind == PyUnicode_1BYTE_KIND) { + Py_UCS1 *data = PyUnicode_1BYTE_DATA(unicode); + Py_UCS1 ch = data[0]; + struct _Py_unicode_state *state = get_unicode_state(); + PyObject *latin1_char = state->latin1[ch]; if (latin1_char != NULL) { if (unicode != latin1_char) { Py_INCREF(latin1_char); @@ -693,12 +684,14 @@ unicode_result_ready(PyObject *unicode) else { assert(_PyUnicode_CheckConsistency(unicode, 1)); Py_INCREF(unicode); - unicode_latin1[ch] = unicode; + state->latin1[ch] = unicode; return unicode; } } + else { + assert(PyUnicode_READ_CHAR(unicode, 0) >= 256); + } } -#endif assert(_PyUnicode_CheckConsistency(unicode, 1)); return unicode; @@ -857,7 +850,7 @@ xmlcharrefreplace(_PyBytesWriter *writer, char *str, to keep things simple, we use a single bitmask, using the least 5 bits from each unicode characters as the bit index. */ -/* the linebreak mask is set up by Unicode_Init below */ +/* the linebreak mask is set up by _PyUnicode_Init() below */ #if LONG_BIT >= 128 #define BLOOM_WIDTH 128 @@ -931,6 +924,8 @@ ensure_unicode(PyObject *obj) /* Compilation of templated routines */ +#define STRINGLIB_GET_EMPTY() unicode_get_empty() + #include "stringlib/asciilib.h" #include "stringlib/fastsearch.h" #include "stringlib/partition.h" @@ -970,11 +965,16 @@ ensure_unicode(PyObject *obj) #include "stringlib/find_max_char.h" #include "stringlib/undef.h" +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS #include "stringlib/unicodedefs.h" #include "stringlib/fastsearch.h" #include "stringlib/count.h" #include "stringlib/find.h" #include "stringlib/undef.h" +_Py_COMP_DIAG_POP + +#undef STRINGLIB_GET_EMPTY /* --- Unicode Object ----------------------------------------------------- */ @@ -1224,9 +1224,8 @@ _PyUnicode_New(Py_ssize_t length) size_t new_size; /* Optimization for empty strings */ - if (length == 0 && unicode_empty != NULL) { - Py_INCREF(unicode_empty); - return (PyUnicodeObject*)unicode_empty; + if (length == 0) { + return (PyUnicodeObject *)unicode_new_empty(); } /* Ensure we won't overflow the size. */ @@ -1356,27 +1355,51 @@ _PyUnicode_Dump(PyObject *op) } else data = unicode->data.any; - printf("%s: len=%" PY_FORMAT_SIZE_T "u, ", - unicode_kind_name(op), ascii->length); + printf("%s: len=%zu, ", unicode_kind_name(op), ascii->length); if (ascii->wstr == data) printf("shared "); printf("wstr=%p", (void *)ascii->wstr); if (!(ascii->state.ascii == 1 && ascii->state.compact == 1)) { - printf(" (%" PY_FORMAT_SIZE_T "u), ", compact->wstr_length); - if (!ascii->state.compact && compact->utf8 == unicode->data.any) + printf(" (%zu), ", compact->wstr_length); + if (!ascii->state.compact && compact->utf8 == unicode->data.any) { printf("shared "); - printf("utf8=%p (%" PY_FORMAT_SIZE_T "u)", - (void *)compact->utf8, compact->utf8_length); + } + printf("utf8=%p (%zu)", (void *)compact->utf8, compact->utf8_length); } printf(", data=%p\n", data); } #endif +static int +unicode_create_empty_string_singleton(struct _Py_unicode_state *state) +{ + // Use size=1 rather than size=0, so PyUnicode_New(0, maxchar) can be + // optimized to always use state->empty_string without having to check if + // it is NULL or not. + PyObject *empty = PyUnicode_New(1, 0); + if (empty == NULL) { + return -1; + } + PyUnicode_1BYTE_DATA(empty)[0] = 0; + _PyUnicode_LENGTH(empty) = 0; + assert(_PyUnicode_CheckConsistency(empty, 1)); + + assert(state->empty_string == NULL); + state->empty_string = empty; + return 0; +} + + PyObject * PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar) { + /* Optimization for empty strings */ + if (size == 0) { + return unicode_new_empty(); + } + PyObject *obj; PyCompactUnicodeObject *unicode; void *data; @@ -1385,12 +1408,6 @@ PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar) Py_ssize_t char_size; Py_ssize_t struct_size; - /* Optimization for empty strings */ - if (size == 0 && unicode_empty != NULL) { - Py_INCREF(unicode_empty); - return unicode_empty; - } - is_ascii = 0; is_sharing = 0; struct_size = sizeof(PyCompactUnicodeObject); @@ -1436,11 +1453,10 @@ PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar) * it's data buffer. */ obj = (PyObject *) PyObject_MALLOC(struct_size + (size + 1) * char_size); - if (obj == NULL) + if (obj == NULL) { return PyErr_NoMemory(); - obj = PyObject_INIT(obj, &PyUnicode_Type); - if (obj == NULL) - return NULL; + } + _PyObject_Init(obj, &PyUnicode_Type); unicode = (PyCompactUnicodeObject *)obj; if (is_ascii) @@ -1927,13 +1943,20 @@ unicode_dealloc(PyObject *unicode) break; case SSTATE_INTERNED_MORTAL: - /* revive dead object temporarily for DelItem */ - Py_SET_REFCNT(unicode, 3); #ifdef INTERNED_STRINGS + /* Revive the dead object temporarily. PyDict_DelItem() removes two + references (key and value) which were ignored by + PyUnicode_InternInPlace(). Use refcnt=3 rather than refcnt=2 + to prevent calling unicode_dealloc() again. Adjust refcnt after + PyDict_DelItem(). */ + assert(Py_REFCNT(unicode) == 0); + Py_SET_REFCNT(unicode, 3); if (PyDict_DelItem(interned, unicode) != 0) { _PyErr_WriteUnraisableMsg("deletion of interned string failed", NULL); } + assert(Py_REFCNT(unicode) == 1); + Py_SET_REFCNT(unicode, 0); #endif break; @@ -1962,18 +1985,18 @@ unicode_dealloc(PyObject *unicode) static int unicode_is_singleton(PyObject *unicode) { - if (unicode == unicode_empty) { + struct _Py_unicode_state *state = get_unicode_state(); + if (unicode == state->empty_string) { return 1; } -#ifdef LATIN1_SINGLETONS PyASCIIObject *ascii = (PyASCIIObject *)unicode; if (ascii->state.kind != PyUnicode_WCHAR_KIND && ascii->length == 1) { Py_UCS4 ch = PyUnicode_READ_CHAR(unicode, 0); - if (ch < 256 && unicode_latin1[ch] == unicode) + if (ch < 256 && state->latin1[ch] == unicode) { return 1; + } } -#endif return 0; } #endif @@ -2018,10 +2041,8 @@ unicode_resize(PyObject **p_unicode, Py_ssize_t length) return 0; if (length == 0) { - _Py_INCREF_UNICODE_EMPTY(); - if (!unicode_empty) - return -1; - Py_SETREF(*p_unicode, unicode_empty); + PyObject *empty = unicode_new_empty(); + Py_SETREF(*p_unicode, empty); return 0; } @@ -2113,17 +2134,15 @@ unicode_write_cstr(PyObject *unicode, Py_ssize_t index, } static PyObject* -get_latin1_char(unsigned char ch) +get_latin1_char(Py_UCS1 ch) { - PyObject *unicode; + struct _Py_unicode_state *state = get_unicode_state(); -#ifdef LATIN1_SINGLETONS - unicode = unicode_latin1[ch]; + PyObject *unicode = state->latin1[ch]; if (unicode) { Py_INCREF(unicode); return unicode; } -#endif unicode = PyUnicode_New(1, ch); if (!unicode) { @@ -2133,10 +2152,8 @@ get_latin1_char(unsigned char ch) PyUnicode_1BYTE_DATA(unicode)[0] = ch; assert(_PyUnicode_CheckConsistency(unicode, 1)); -#ifdef LATIN1_SINGLETONS Py_INCREF(unicode); - unicode_latin1[ch] = unicode; -#endif + state->latin1[ch] = unicode; return unicode; } @@ -2147,8 +2164,9 @@ unicode_char(Py_UCS4 ch) assert(ch <= MAX_UNICODE); - if (ch < 256) + if (ch < 256) { return get_latin1_char(ch); + } unicode = PyUnicode_New(1, ch); if (unicode == NULL) @@ -2168,8 +2186,16 @@ unicode_char(Py_UCS4 ch) PyObject * PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size) { - if (u == NULL) + if (u == NULL) { + if (size > 0) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "PyUnicode_FromUnicode(NULL, size) is deprecated; " + "use PyUnicode_New() instead", 1) < 0) { + return NULL; + } + } return (PyObject*)_PyUnicode_New(size); + } if (size < 0) { PyErr_BadInternalCall(); @@ -2255,10 +2281,19 @@ PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size) "Negative size passed to PyUnicode_FromStringAndSize"); return NULL; } - if (u != NULL) + if (u != NULL) { return PyUnicode_DecodeUTF8Stateful(u, size, NULL, NULL); - else + } + else { + if (size > 0) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "PyUnicode_FromStringAndSize(NULL, size) is deprecated; " + "use PyUnicode_New() instead", 1) < 0) { + return NULL; + } + } return (PyObject *)_PyUnicode_New(size); + } } PyObject * @@ -2275,17 +2310,23 @@ PyUnicode_FromString(const char *u) PyObject * _PyUnicode_FromId(_Py_Identifier *id) { - if (!id->object) { - id->object = PyUnicode_DecodeUTF8Stateful(id->string, - strlen(id->string), - NULL, NULL); - if (!id->object) - return NULL; - PyUnicode_InternInPlace(&id->object); - assert(!id->next); - id->next = static_strings; - static_strings = id; + if (id->object) { + return id->object; } + + PyObject *obj; + obj = PyUnicode_DecodeUTF8Stateful(id->string, + strlen(id->string), + NULL, NULL); + if (!obj) { + return NULL; + } + PyUnicode_InternInPlace(&obj); + + assert(!id->next); + id->object = obj; + id->next = static_strings; + static_strings = id; return id->object; } @@ -2344,11 +2385,13 @@ _PyUnicode_FromUCS1(const Py_UCS1* u, Py_ssize_t size) PyObject *res; unsigned char max_char; - if (size == 0) + if (size == 0) { _Py_RETURN_UNICODE_EMPTY(); + } assert(size > 0); - if (size == 1) + if (size == 1) { return get_latin1_char(u[0]); + } max_char = ucs1lib_find_max_char(u, u + size); res = PyUnicode_New(size, max_char); @@ -2839,35 +2882,35 @@ unicode_fromformat_arg(_PyUnicodeWriter *writer, Py_ssize_t arglen; if (*f == 'u') { - if (longflag) - len = sprintf(buffer, "%lu", - va_arg(*vargs, unsigned long)); - else if (longlongflag) - len = sprintf(buffer, "%llu", - va_arg(*vargs, unsigned long long)); - else if (size_tflag) - len = sprintf(buffer, "%" PY_FORMAT_SIZE_T "u", - va_arg(*vargs, size_t)); - else - len = sprintf(buffer, "%u", - va_arg(*vargs, unsigned int)); + if (longflag) { + len = sprintf(buffer, "%lu", va_arg(*vargs, unsigned long)); + } + else if (longlongflag) { + len = sprintf(buffer, "%llu", va_arg(*vargs, unsigned long long)); + } + else if (size_tflag) { + len = sprintf(buffer, "%zu", va_arg(*vargs, size_t)); + } + else { + len = sprintf(buffer, "%u", va_arg(*vargs, unsigned int)); + } } else if (*f == 'x') { len = sprintf(buffer, "%x", va_arg(*vargs, int)); } else { - if (longflag) - len = sprintf(buffer, "%li", - va_arg(*vargs, long)); - else if (longlongflag) - len = sprintf(buffer, "%lli", - va_arg(*vargs, long long)); - else if (size_tflag) - len = sprintf(buffer, "%" PY_FORMAT_SIZE_T "i", - va_arg(*vargs, Py_ssize_t)); - else - len = sprintf(buffer, "%i", - va_arg(*vargs, int)); + if (longflag) { + len = sprintf(buffer, "%li", va_arg(*vargs, long)); + } + else if (longlongflag) { + len = sprintf(buffer, "%lli", va_arg(*vargs, long long)); + } + else if (size_tflag) { + len = sprintf(buffer, "%zi", va_arg(*vargs, Py_ssize_t)); + } + else { + len = sprintf(buffer, "%i", va_arg(*vargs, int)); + } } assert(len >= 0); @@ -3254,6 +3297,74 @@ PyUnicode_AsWideCharString(PyObject *unicode, #endif /* HAVE_WCHAR_H */ +int +_PyUnicode_WideCharString_Converter(PyObject *obj, void *ptr) +{ + wchar_t **p = (wchar_t **)ptr; + if (obj == NULL) { +#if !USE_UNICODE_WCHAR_CACHE + PyMem_Free(*p); +#endif /* USE_UNICODE_WCHAR_CACHE */ + *p = NULL; + return 1; + } + if (PyUnicode_Check(obj)) { +#if USE_UNICODE_WCHAR_CACHE + *p = (wchar_t *)_PyUnicode_AsUnicode(obj); + if (*p == NULL) { + return 0; + } + return 1; +#else /* USE_UNICODE_WCHAR_CACHE */ + *p = PyUnicode_AsWideCharString(obj, NULL); + if (*p == NULL) { + return 0; + } + return Py_CLEANUP_SUPPORTED; +#endif /* USE_UNICODE_WCHAR_CACHE */ + } + PyErr_Format(PyExc_TypeError, + "argument must be str, not %.50s", + obj->ob_type->tp_name); + return 0; +} + +int +_PyUnicode_WideCharString_Opt_Converter(PyObject *obj, void *ptr) +{ + wchar_t **p = (wchar_t **)ptr; + if (obj == NULL) { +#if !USE_UNICODE_WCHAR_CACHE + PyMem_Free(*p); +#endif /* USE_UNICODE_WCHAR_CACHE */ + *p = NULL; + return 1; + } + if (obj == Py_None) { + *p = NULL; + return 1; + } + if (PyUnicode_Check(obj)) { +#if USE_UNICODE_WCHAR_CACHE + *p = (wchar_t *)_PyUnicode_AsUnicode(obj); + if (*p == NULL) { + return 0; + } + return 1; +#else /* USE_UNICODE_WCHAR_CACHE */ + *p = PyUnicode_AsWideCharString(obj, NULL); + if (*p == NULL) { + return 0; + } + return Py_CLEANUP_SUPPORTED; +#endif /* USE_UNICODE_WCHAR_CACHE */ + } + PyErr_Format(PyExc_TypeError, + "argument must be str or None, not %.50s", + obj->ob_type->tp_name); + return 0; +} + PyObject * PyUnicode_FromOrdinal(int ordinal) { @@ -4093,6 +4204,11 @@ PyUnicode_AsUnicodeAndSize(PyObject *unicode, Py_ssize_t *size) return w; } +/* Deprecated APIs */ + +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS + Py_UNICODE * PyUnicode_AsUnicode(PyObject *unicode) { @@ -4131,6 +4247,8 @@ PyUnicode_GetSize(PyObject *unicode) return -1; } +_Py_COMP_DIAG_POP + Py_ssize_t PyUnicode_GetLength(PyObject *unicode) { @@ -4978,8 +5096,9 @@ unicode_decode_utf8(const char *s, Py_ssize_t size, /* ASCII is equivalent to the first 128 ordinals in Unicode. */ if (size == 1 && (unsigned char)s[0] < 128) { - if (consumed) + if (consumed) { *consumed = 1; + } return get_latin1_char((unsigned char)s[0]); } @@ -7146,8 +7265,9 @@ PyUnicode_DecodeASCII(const char *s, _Py_RETURN_UNICODE_EMPTY(); /* ASCII is equivalent to the first 128 ordinals in Unicode. */ - if (size == 1 && (unsigned char)s[0] < 128) + if (size == 1 && (unsigned char)s[0] < 128) { return get_latin1_char((unsigned char)s[0]); + } // Shortcut for simple case PyObject *u = PyUnicode_New(size, 127); @@ -8387,9 +8507,11 @@ PyUnicode_BuildEncodingMap(PyObject* string) /* Create a three-level trie */ result = PyObject_MALLOC(sizeof(struct encoding_map) + 16*count2 + 128*count3 - 1); - if (!result) + if (!result) { return PyErr_NoMemory(); - PyObject_Init(result, &EncodingMapType); + } + + _PyObject_Init(result, &EncodingMapType); mresult = (struct encoding_map*)result; mresult->count2 = count2; mresult->count3 = count3; @@ -10813,10 +10935,7 @@ replace(PyObject *self, PyObject *str1, } new_size = slen + n * (len2 - len1); if (new_size == 0) { - _Py_INCREF_UNICODE_EMPTY(); - if (!unicode_empty) - goto error; - u = unicode_empty; + u = unicode_new_empty(); goto done; } if (new_size > (PY_SSIZE_T_MAX / rkind)) { @@ -11474,10 +11593,13 @@ PyUnicode_Concat(PyObject *left, PyObject *right) return NULL; /* Shortcuts */ - if (left == unicode_empty) + PyObject *empty = unicode_get_empty(); // Borrowed reference + if (left == empty) { return PyUnicode_FromObject(right); - if (right == unicode_empty) + } + if (right == empty) { return PyUnicode_FromObject(left); + } left_len = PyUnicode_GET_LENGTH(left); right_len = PyUnicode_GET_LENGTH(right); @@ -11528,14 +11650,16 @@ PyUnicode_Append(PyObject **p_left, PyObject *right) goto error; /* Shortcuts */ - if (left == unicode_empty) { + PyObject *empty = unicode_get_empty(); // Borrowed reference + if (left == empty) { Py_DECREF(left); Py_INCREF(right); *p_left = right; return; } - if (right == unicode_empty) + if (right == empty) { return; + } left_len = PyUnicode_GET_LENGTH(left); right_len = PyUnicode_GET_LENGTH(right); @@ -12358,6 +12482,8 @@ PyUnicode_IsIdentifier(PyObject *self) return len && i == len; } else { +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS Py_ssize_t i = 0, len = PyUnicode_GET_SIZE(self); if (len == 0) { /* an empty string is not a valid identifier */ @@ -12395,6 +12521,7 @@ PyUnicode_IsIdentifier(PyObject *self) } } return 1; +_Py_COMP_DIAG_POP } } @@ -13229,14 +13356,8 @@ PyUnicode_Partition(PyObject *str_obj, PyObject *sep_obj) len1 = PyUnicode_GET_LENGTH(str_obj); len2 = PyUnicode_GET_LENGTH(sep_obj); if (kind1 < kind2 || len1 < len2) { - _Py_INCREF_UNICODE_EMPTY(); - if (!unicode_empty) - out = NULL; - else { - out = PyTuple_Pack(3, str_obj, unicode_empty, unicode_empty); - Py_DECREF(unicode_empty); - } - return out; + PyObject *empty = unicode_get_empty(); // Borrowed reference + return PyTuple_Pack(3, str_obj, empty, empty); } buf1 = PyUnicode_DATA(str_obj); buf2 = PyUnicode_DATA(sep_obj); @@ -13287,14 +13408,8 @@ PyUnicode_RPartition(PyObject *str_obj, PyObject *sep_obj) len1 = PyUnicode_GET_LENGTH(str_obj); len2 = PyUnicode_GET_LENGTH(sep_obj); if (kind1 < kind2 || len1 < len2) { - _Py_INCREF_UNICODE_EMPTY(); - if (!unicode_empty) - out = NULL; - else { - out = PyTuple_Pack(3, unicode_empty, unicode_empty, str_obj); - Py_DECREF(unicode_empty); - } - return out; + PyObject *empty = unicode_get_empty(); // Borrowed reference + return PyTuple_Pack(3, empty, empty, str_obj); } buf1 = PyUnicode_DATA(str_obj); buf2 = PyUnicode_DATA(sep_obj); @@ -14617,20 +14732,15 @@ mainformatlong(PyObject *v, /* make sure number is a type of integer for o, x, and X */ if (!PyLong_Check(v)) { if (type == 'o' || type == 'x' || type == 'X') { - iobj = PyNumber_Index(v); - if (iobj == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) - goto wrongtype; - return -1; - } + iobj = _PyNumber_Index(v); } else { iobj = PyNumber_Long(v); - if (iobj == NULL ) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) - goto wrongtype; - return -1; - } + } + if (iobj == NULL ) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) + goto wrongtype; + return -1; } assert(PyLong_Check(iobj)); } @@ -14713,24 +14823,17 @@ formatchar(PyObject *v) goto onError; } else { - PyObject *iobj; - long x; - /* make sure number is a type of integer */ - if (!PyLong_Check(v)) { - iobj = PyNumber_Index(v); - if (iobj == NULL) { + int overflow; + long x = PyLong_AsLongAndOverflow(v, &overflow); + if (x == -1 && PyErr_Occurred()) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) { goto onError; } - x = PyLong_AsLong(iobj); - Py_DECREF(iobj); + return (Py_UCS4) -1; } - else { - x = PyLong_AsLong(v); - } - if (x == -1 && PyErr_Occurred()) - goto onError; if (x < 0 || x > MAX_UNICODE) { + /* this includes an overflow in converting to C long */ PyErr_SetString(PyExc_OverflowError, "%c arg not in range(0x110000)"); return (Py_UCS4) -1; @@ -15512,10 +15615,10 @@ PyTypeObject PyUnicode_Type = { /* Initialize the Unicode implementation */ PyStatus -_PyUnicode_Init(void) +_PyUnicode_Init(PyThreadState *tstate) { /* XXX - move this array to unicodectype.c ? */ - Py_UCS2 linebreak[] = { + const Py_UCS2 linebreak[] = { 0x000A, /* LINE FEED */ 0x000D, /* CARRIAGE RETURN */ 0x001C, /* FILE SEPARATOR */ @@ -15526,30 +15629,30 @@ _PyUnicode_Init(void) 0x2029, /* PARAGRAPH SEPARATOR */ }; - /* Init the implementation */ - _Py_INCREF_UNICODE_EMPTY(); - if (!unicode_empty) { - return _PyStatus_ERR("Can't create empty string"); - } - Py_DECREF(unicode_empty); - - if (PyType_Ready(&PyUnicode_Type) < 0) { - return _PyStatus_ERR("Can't initialize unicode type"); + struct _Py_unicode_state *state = &tstate->interp->unicode; + if (unicode_create_empty_string_singleton(state) < 0) { + return _PyStatus_NO_MEMORY(); } - /* initialize the linebreak bloom filter */ - bloom_linebreak = make_bloom_mask( - PyUnicode_2BYTE_KIND, linebreak, - Py_ARRAY_LENGTH(linebreak)); + if (_Py_IsMainInterpreter(tstate)) { + /* initialize the linebreak bloom filter */ + bloom_linebreak = make_bloom_mask( + PyUnicode_2BYTE_KIND, linebreak, + Py_ARRAY_LENGTH(linebreak)); - if (PyType_Ready(&EncodingMapType) < 0) { - return _PyStatus_ERR("Can't initialize encoding map type"); - } - if (PyType_Ready(&PyFieldNameIter_Type) < 0) { - return _PyStatus_ERR("Can't initialize field name iterator type"); - } - if (PyType_Ready(&PyFormatterIter_Type) < 0) { - return _PyStatus_ERR("Can't initialize formatter iter type"); + if (PyType_Ready(&PyUnicode_Type) < 0) { + return _PyStatus_ERR("Can't initialize unicode type"); + } + + if (PyType_Ready(&EncodingMapType) < 0) { + return _PyStatus_ERR("Can't initialize encoding map type"); + } + if (PyType_Ready(&PyFieldNameIter_Type) < 0) { + return _PyStatus_ERR("Can't initialize field name iterator type"); + } + if (PyType_Ready(&PyFormatterIter_Type) < 0) { + return _PyStatus_ERR("Can't initialize formatter iter type"); + } } return _PyStatus_OK(); } @@ -15579,6 +15682,11 @@ PyUnicode_InternInPlace(PyObject **p) } #ifdef INTERNED_STRINGS + if (PyUnicode_READY(s) == -1) { + PyErr_Clear(); + return; + } + if (interned == NULL) { interned = PyDict_New(); if (interned == NULL) { @@ -15603,8 +15711,9 @@ PyUnicode_InternInPlace(PyObject **p) return; } - /* The two references in interned are not counted by refcnt. - The deallocator will take care of this */ + /* The two references in interned dict (key and value) are not counted by + refcnt. unicode_dealloc() and _PyUnicode_ClearInterned() take care of + this. */ Py_SET_REFCNT(s, Py_REFCNT(s) - 2); _PyUnicode_STATE(s).interned = SSTATE_INTERNED_MORTAL; #endif @@ -15631,45 +15740,51 @@ PyUnicode_InternFromString(const char *cp) } -#if defined(WITH_VALGRIND) || defined(__INSURE__) -static void -unicode_release_interned(void) +void +_PyUnicode_ClearInterned(PyThreadState *tstate) { - if (interned == NULL || !PyDict_Check(interned)) { + if (!_Py_IsMainInterpreter(tstate)) { + // interned dict is shared by all interpreters return; } + + if (interned == NULL) { + return; + } + assert(PyDict_CheckExact(interned)); + PyObject *keys = PyDict_Keys(interned); - if (keys == NULL || !PyList_Check(keys)) { + if (keys == NULL) { PyErr_Clear(); return; } + assert(PyList_CheckExact(keys)); - /* Since unicode_release_interned() is intended to help a leak - detector, interned unicode strings are not forcibly deallocated; - rather, we give them their stolen references back, and then clear - and DECREF the interned dict. */ + /* Interned unicode strings are not forcibly deallocated; rather, we give + them their stolen references back, and then clear and DECREF the + interned dict. */ Py_ssize_t n = PyList_GET_SIZE(keys); #ifdef INTERNED_STATS - fprintf(stderr, "releasing %" PY_FORMAT_SIZE_T "d interned strings\n", - n); + fprintf(stderr, "releasing %zd interned strings\n", n); Py_ssize_t immortal_size = 0, mortal_size = 0; #endif for (Py_ssize_t i = 0; i < n; i++) { PyObject *s = PyList_GET_ITEM(keys, i); - if (PyUnicode_READY(s) == -1) { - Py_UNREACHABLE(); - } + assert(PyUnicode_IS_READY(s)); + switch (PyUnicode_CHECK_INTERNED(s)) { case SSTATE_INTERNED_IMMORTAL: - Py_REFCNT(s) += 1; + Py_SET_REFCNT(s, Py_REFCNT(s) + 1); #ifdef INTERNED_STATS immortal_size += PyUnicode_GET_LENGTH(s); #endif break; case SSTATE_INTERNED_MORTAL: - Py_REFCNT(s) += 2; + // Restore the two references (key and value) ignored + // by PyUnicode_InternInPlace(). + Py_SET_REFCNT(s, Py_REFCNT(s) + 2); #ifdef INTERNED_STATS mortal_size += PyUnicode_GET_LENGTH(s); #endif @@ -15682,15 +15797,15 @@ unicode_release_interned(void) _PyUnicode_STATE(s).interned = SSTATE_NOT_INTERNED; } #ifdef INTERNED_STATS - fprintf(stderr, "total size of all interned strings: " - "%" PY_FORMAT_SIZE_T "d/%" PY_FORMAT_SIZE_T "d " - "mortal/immortal\n", mortal_size, immortal_size); + fprintf(stderr, + "total size of all interned strings: %zd/%zd mortal/immortal\n", + mortal_size, immortal_size); #endif Py_DECREF(keys); + PyDict_Clear(interned); Py_CLEAR(interned); } -#endif /********************* Unicode Iterator **************************/ @@ -15852,124 +15967,6 @@ unicode_iter(PyObject *seq) return (PyObject *)it; } - -size_t -Py_UNICODE_strlen(const Py_UNICODE *u) -{ - return wcslen(u); -} - -Py_UNICODE* -Py_UNICODE_strcpy(Py_UNICODE *s1, const Py_UNICODE *s2) -{ - Py_UNICODE *u = s1; - while ((*u++ = *s2++)); - return s1; -} - -Py_UNICODE* -Py_UNICODE_strncpy(Py_UNICODE *s1, const Py_UNICODE *s2, size_t n) -{ - Py_UNICODE *u = s1; - while ((*u++ = *s2++)) - if (n-- == 0) - break; - return s1; -} - -Py_UNICODE* -Py_UNICODE_strcat(Py_UNICODE *s1, const Py_UNICODE *s2) -{ - Py_UNICODE *u1 = s1; - u1 += wcslen(u1); - while ((*u1++ = *s2++)); - return s1; -} - -int -Py_UNICODE_strcmp(const Py_UNICODE *s1, const Py_UNICODE *s2) -{ - while (*s1 && *s2 && *s1 == *s2) - s1++, s2++; - if (*s1 && *s2) - return (*s1 < *s2) ? -1 : +1; - if (*s1) - return 1; - if (*s2) - return -1; - return 0; -} - -int -Py_UNICODE_strncmp(const Py_UNICODE *s1, const Py_UNICODE *s2, size_t n) -{ - Py_UNICODE u1, u2; - for (; n != 0; n--) { - u1 = *s1; - u2 = *s2; - if (u1 != u2) - return (u1 < u2) ? -1 : +1; - if (u1 == '\0') - return 0; - s1++; - s2++; - } - return 0; -} - -Py_UNICODE* -Py_UNICODE_strchr(const Py_UNICODE *s, Py_UNICODE c) -{ - const Py_UNICODE *p; - for (p = s; *p; p++) - if (*p == c) - return (Py_UNICODE*)p; - return NULL; -} - -Py_UNICODE* -Py_UNICODE_strrchr(const Py_UNICODE *s, Py_UNICODE c) -{ - const Py_UNICODE *p; - p = s + wcslen(s); - while (p != s) { - p--; - if (*p == c) - return (Py_UNICODE*)p; - } - return NULL; -} - -Py_UNICODE* -PyUnicode_AsUnicodeCopy(PyObject *unicode) -{ - Py_UNICODE *u, *copy; - Py_ssize_t len, size; - - if (!PyUnicode_Check(unicode)) { - PyErr_BadArgument(); - return NULL; - } - u = PyUnicode_AsUnicodeAndSize(unicode, &len); - if (u == NULL) - return NULL; - /* Ensure we won't overflow the size. */ - if (len > ((PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(Py_UNICODE)) - 1)) { - PyErr_NoMemory(); - return NULL; - } - size = len + 1; /* copy the null character */ - size *= sizeof(Py_UNICODE); - copy = PyMem_Malloc(size); - if (copy == NULL) { - PyErr_NoMemory(); - return NULL; - } - memcpy(copy, u, size); - return copy; -} - - static int encode_wstr_utf8(wchar_t *wstr, char **str, const char *name) { @@ -16177,27 +16174,17 @@ _PyUnicode_EnableLegacyWindowsFSEncoding(void) void _PyUnicode_Fini(PyThreadState *tstate) { + // _PyUnicode_ClearInterned() must be called before + + struct _Py_unicode_state *state = &tstate->interp->unicode; + + Py_CLEAR(state->empty_string); + + for (Py_ssize_t i = 0; i < 256; i++) { + Py_CLEAR(state->latin1[i]); + } + if (_Py_IsMainInterpreter(tstate)) { -#if defined(WITH_VALGRIND) || defined(__INSURE__) - /* Insure++ is a memory analysis tool that aids in discovering - * memory leaks and other memory problems. On Python exit, the - * interned string dictionaries are flagged as being in use at exit - * (which it is). Under normal circumstances, this is fine because - * the memory will be automatically reclaimed by the system. Under - * memory debugging, it's a huge source of useless noise, so we - * trade off slower shutdown for less distraction in the memory - * reports. -baw - */ - unicode_release_interned(); -#endif /* __INSURE__ */ - - Py_CLEAR(unicode_empty); - -#ifdef LATIN1_SINGLETONS - for (Py_ssize_t i = 0; i < 256; i++) { - Py_CLEAR(unicode_latin1[i]); - } -#endif unicode_clear_static_strings(); } diff --git a/PC/_msi.c b/PC/_msi.c index 6ed8724f77f..f725c816206 100644 --- a/PC/_msi.c +++ b/PC/_msi.c @@ -12,10 +12,26 @@ #include #include +/*[clinic input] +module _msi +class _msi.Record "msiobj *" "&record_Type" +class _msi.SummaryInformation "msiobj *" "&summary_Type" +class _msi.View "msiobj *" "&msiview_Type" +class _msi.Database "msiobj *" "&msidb_Type" +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=89a3605762cf4bdc]*/ + static PyObject *MSIError; -static PyObject* -uuidcreate(PyObject* obj, PyObject*args) +/*[clinic input] +_msi.UuidCreate + +Return the string representation of a new unique identifier. +[clinic start generated code]*/ + +static PyObject * +_msi_UuidCreate_impl(PyObject *module) +/*[clinic end generated code: output=534ecf36f10af98e input=168024ab4b3e832b]*/ { UUID result; wchar_t *cresult; @@ -41,21 +57,50 @@ uuidcreate(PyObject* obj, PyObject*args) } +/* Helper for converting file names from UTF-8 to wchat_t*. */ +static wchar_t * +utf8_to_wchar(const char *s, int *err) +{ + PyObject *obj = PyUnicode_FromString(s); + if (obj == NULL) { + if (PyErr_ExceptionMatches(PyExc_MemoryError)) { + *err = ENOMEM; + } + else { + *err = EINVAL; + } + PyErr_Clear(); + return NULL; + } + wchar_t *ws = PyUnicode_AsWideCharString(obj, NULL); + if (ws == NULL) { + *err = ENOMEM; + PyErr_Clear(); + } + Py_DECREF(obj); + return ws; +} + /* FCI callback functions */ static FNFCIALLOC(cb_alloc) { - return malloc(cb); + return PyMem_RawMalloc(cb); } static FNFCIFREE(cb_free) { - free(memory); + PyMem_RawFree(memory); } static FNFCIOPEN(cb_open) { - int result = _open(pszFile, oflag | O_NOINHERIT, pmode); + wchar_t *ws = utf8_to_wchar(pszFile, err); + if (ws == NULL) { + return -1; + } + int result = _wopen(ws, oflag | O_NOINHERIT, pmode); + PyMem_Free(ws); if (result == -1) *err = errno; return result; @@ -95,7 +140,12 @@ static FNFCISEEK(cb_seek) static FNFCIDELETE(cb_delete) { - int result = remove(pszFile); + wchar_t *ws = utf8_to_wchar(pszFile, err); + if (ws == NULL) { + return -1; + } + int result = _wremove(ws); + PyMem_Free(ws); if (result != 0) *err = errno; return result; @@ -159,15 +209,22 @@ static FNFCIGETOPENINFO(cb_getopeninfo) FILETIME filetime; HANDLE handle; - /* Need Win32 handle to get time stamps */ - handle = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (handle == INVALID_HANDLE_VALUE) + wchar_t *ws = utf8_to_wchar(pszName, err); + if (ws == NULL) { return -1; + } - if (GetFileInformationByHandle(handle, &bhfi) == FALSE) - { + /* Need Win32 handle to get time stamps */ + handle = CreateFileW(ws, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (handle == INVALID_HANDLE_VALUE) { + PyMem_Free(ws); + return -1; + } + + if (GetFileInformationByHandle(handle, &bhfi) == FALSE) { CloseHandle(handle); + PyMem_Free(ws); return -1; } @@ -179,22 +236,33 @@ static FNFCIGETOPENINFO(cb_getopeninfo) CloseHandle(handle); - return _open(pszName, _O_RDONLY | _O_BINARY | O_NOINHERIT); + int result = _wopen(ws, _O_RDONLY | _O_BINARY | O_NOINHERIT); + PyMem_Free(ws); + return result; } -static PyObject* fcicreate(PyObject* obj, PyObject* args) +/*[clinic input] +_msi.FCICreate + cabname: str + the name of the CAB file + files: object + a list of tuples, each containing the name of the file on disk, + and the name of the file inside the CAB file + / + +Create a new CAB file. +[clinic start generated code]*/ + +static PyObject * +_msi_FCICreate_impl(PyObject *module, const char *cabname, PyObject *files) +/*[clinic end generated code: output=55dc05728361b799 input=1d2d75fdc8b44b71]*/ { - char *cabname, *p; - PyObject *files; + const char *p; CCAB ccab; HFCI hfci; ERF erf; Py_ssize_t i; - - if (!PyArg_ParseTuple(args, "sO:FCICreate", &cabname, &files)) - return NULL; - if (!PyList_Check(files)) { PyErr_SetString(PyExc_TypeError, "FCICreate expects a list"); return NULL; @@ -212,7 +280,7 @@ static PyObject* fcicreate(PyObject* obj, PyObject* args) ccab.setID = 0; ccab.szDisk[0] = '\0'; - for (i = 0, p = cabname; *p; p = CharNext(p)) + for (i = 0, p = cabname; *p; p++) if (*p == '\\' || *p == '/') i = p - cabname + 1; @@ -344,34 +412,56 @@ msierror(int status) return NULL; } -static PyObject* -msidb_close(msiobj* msidb, PyObject *args) +#include "clinic/_msi.c.h" + +/*[clinic input] +_msi.Database.Close + +Close the database object. +[clinic start generated code]*/ + +static PyObject * +_msi_Database_Close_impl(msiobj *self) +/*[clinic end generated code: output=ddf2d7712ea804f1 input=104330ce4a486187]*/ { int status; - if ((status = MsiCloseHandle(msidb->h)) != ERROR_SUCCESS) { + if ((status = MsiCloseHandle(self->h)) != ERROR_SUCCESS) { return msierror(status); } - msidb->h = 0; + self->h = 0; Py_RETURN_NONE; } /*************************** Record objects **********************/ -static PyObject* -record_getfieldcount(msiobj* record, PyObject* args) +/*[clinic input] +_msi.Record.GetFieldCount + +Return the number of fields of the record. +[clinic start generated code]*/ + +static PyObject * +_msi_Record_GetFieldCount_impl(msiobj *self) +/*[clinic end generated code: output=112795079c904398 input=5fb9d4071b28897b]*/ { - return PyLong_FromLong(MsiRecordGetFieldCount(record->h)); + return PyLong_FromLong(MsiRecordGetFieldCount(self->h)); } -static PyObject* -record_getinteger(msiobj* record, PyObject* args) +/*[clinic input] +_msi.Record.GetInteger + field: unsigned_int(bitwise=True) + / + +Return the value of field as an integer where possible. +[clinic start generated code]*/ + +static PyObject * +_msi_Record_GetInteger_impl(msiobj *self, unsigned int field) +/*[clinic end generated code: output=7174ebb6e8ed1c79 input=d19209947e2bfe61]*/ { - unsigned int field; int status; - if (!PyArg_ParseTuple(args, "I:GetInteger", &field)) - return NULL; - status = MsiRecordGetInteger(record->h, field); + status = MsiRecordGetInteger(self->h, field); if (status == MSI_NULL_INTEGER){ PyErr_SetString(MSIError, "could not convert record field to integer"); return NULL; @@ -379,24 +469,30 @@ record_getinteger(msiobj* record, PyObject* args) return PyLong_FromLong((long) status); } -static PyObject* -record_getstring(msiobj* record, PyObject* args) +/*[clinic input] +_msi.Record.GetString + field: unsigned_int(bitwise=True) + / + +Return the value of field as a string where possible. +[clinic start generated code]*/ + +static PyObject * +_msi_Record_GetString_impl(msiobj *self, unsigned int field) +/*[clinic end generated code: output=f670d1b484cfa47c input=ffa11f21450b77d8]*/ { - unsigned int field; unsigned int status; WCHAR buf[2000]; WCHAR *res = buf; DWORD size = sizeof(buf); PyObject* string; - if (!PyArg_ParseTuple(args, "I:GetString", &field)) - return NULL; - status = MsiRecordGetStringW(record->h, field, res, &size); + status = MsiRecordGetStringW(self->h, field, res, &size); if (status == ERROR_MORE_DATA) { res = (WCHAR*) malloc((size + 1)*sizeof(WCHAR)); if (res == NULL) return PyErr_NoMemory(); - status = MsiRecordGetStringW(record->h, field, res, &size); + status = MsiRecordGetStringW(self->h, field, res, &size); } if (status != ERROR_SUCCESS) return msierror((int) status); @@ -406,59 +502,81 @@ record_getstring(msiobj* record, PyObject* args) return string; } -static PyObject* -record_cleardata(msiobj* record, PyObject *args) +/*[clinic input] +_msi.Record.ClearData + +Set all fields of the record to 0. +[clinic start generated code]*/ + +static PyObject * +_msi_Record_ClearData_impl(msiobj *self) +/*[clinic end generated code: output=1891467214b977f4 input=2a911c95aaded102]*/ { - int status = MsiRecordClearData(record->h); + int status = MsiRecordClearData(self->h); if (status != ERROR_SUCCESS) return msierror(status); Py_RETURN_NONE; } -static PyObject* -record_setstring(msiobj* record, PyObject *args) +/*[clinic input] +_msi.Record.SetString + field: int + value: Py_UNICODE + / + +Set field to a string value. +[clinic start generated code]*/ + +static PyObject * +_msi_Record_SetString_impl(msiobj *self, int field, const Py_UNICODE *value) +/*[clinic end generated code: output=2e37505b0f11f985 input=fb8ec70a2a6148e0]*/ { int status; - int field; - wchar_t *data; - if (!PyArg_ParseTuple(args, "iu:SetString", &field, &data)) - return NULL; - - if ((status = MsiRecordSetStringW(record->h, field, data)) != ERROR_SUCCESS) + if ((status = MsiRecordSetStringW(self->h, field, value)) != ERROR_SUCCESS) return msierror(status); Py_RETURN_NONE; } -static PyObject* -record_setstream(msiobj* record, PyObject *args) +/*[clinic input] +_msi.Record.SetStream + field: int + value: Py_UNICODE + / + +Set field to the contents of the file named value. +[clinic start generated code]*/ + +static PyObject * +_msi_Record_SetStream_impl(msiobj *self, int field, const Py_UNICODE *value) +/*[clinic end generated code: output=442facac16913b48 input=a07aa19b865e8292]*/ { int status; - int field; - wchar_t *data; - if (!PyArg_ParseTuple(args, "iu:SetStream", &field, &data)) - return NULL; - - if ((status = MsiRecordSetStreamW(record->h, field, data)) != ERROR_SUCCESS) + if ((status = MsiRecordSetStreamW(self->h, field, value)) != ERROR_SUCCESS) return msierror(status); Py_RETURN_NONE; } -static PyObject* -record_setinteger(msiobj* record, PyObject *args) +/*[clinic input] +_msi.Record.SetInteger + field: int + value: int + / + +Set field to an integer value. +[clinic start generated code]*/ + +static PyObject * +_msi_Record_SetInteger_impl(msiobj *self, int field, int value) +/*[clinic end generated code: output=669e8647775d0ce7 input=c571aa775e7e451b]*/ { int status; - int field; - int data; - if (!PyArg_ParseTuple(args, "ii:SetInteger", &field, &data)) - return NULL; - - if ((status = MsiRecordSetInteger(record->h, field, data)) != ERROR_SUCCESS) + if ((status = MsiRecordSetInteger(self->h, field, value)) != ERROR_SUCCESS) return msierror(status); Py_RETURN_NONE; @@ -467,20 +585,13 @@ record_setinteger(msiobj* record, PyObject *args) static PyMethodDef record_methods[] = { - { "GetFieldCount", (PyCFunction)record_getfieldcount, METH_NOARGS, - PyDoc_STR("GetFieldCount() -> int\nWraps MsiRecordGetFieldCount")}, - { "GetInteger", (PyCFunction)record_getinteger, METH_VARARGS, - PyDoc_STR("GetInteger(field) -> int\nWraps MsiRecordGetInteger")}, - { "GetString", (PyCFunction)record_getstring, METH_VARARGS, - PyDoc_STR("GetString(field) -> string\nWraps MsiRecordGetString")}, - { "SetString", (PyCFunction)record_setstring, METH_VARARGS, - PyDoc_STR("SetString(field,str) -> None\nWraps MsiRecordSetString")}, - { "SetStream", (PyCFunction)record_setstream, METH_VARARGS, - PyDoc_STR("SetStream(field,filename) -> None\nWraps MsiRecordSetInteger")}, - { "SetInteger", (PyCFunction)record_setinteger, METH_VARARGS, - PyDoc_STR("SetInteger(field,int) -> None\nWraps MsiRecordSetInteger")}, - { "ClearData", (PyCFunction)record_cleardata, METH_NOARGS, - PyDoc_STR("ClearData() -> int\nWraps MsiRecordGClearData")}, + _MSI_RECORD_GETFIELDCOUNT_METHODDEF + _MSI_RECORD_GETINTEGER_METHODDEF + _MSI_RECORD_GETSTRING_METHODDEF + _MSI_RECORD_SETSTRING_METHODDEF + _MSI_RECORD_SETSTREAM_METHODDEF + _MSI_RECORD_SETINTEGER_METHODDEF + _MSI_RECORD_CLEARDATA_METHODDEF { NULL, NULL } }; @@ -544,11 +655,20 @@ record_new(MSIHANDLE h) /*************************** SummaryInformation objects **************/ -static PyObject* -summary_getproperty(msiobj* si, PyObject *args) +/*[clinic input] +_msi.SummaryInformation.GetProperty + field: int + the name of the property, one of the PID_* constants + / + +Return a property of the summary. +[clinic start generated code]*/ + +static PyObject * +_msi_SummaryInformation_GetProperty_impl(msiobj *self, int field) +/*[clinic end generated code: output=f8946a33ee14f6ef input=f8dfe2c890d6cb8b]*/ { int status; - int field; PyObject *result; UINT type; INT ival; @@ -557,10 +677,7 @@ summary_getproperty(msiobj* si, PyObject *args) char *sval = sbuf; DWORD ssize = sizeof(sbuf); - if (!PyArg_ParseTuple(args, "i:GetProperty", &field)) - return NULL; - - status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival, + status = MsiSummaryInfoGetProperty(self->h, field, &type, &ival, &fval, sval, &ssize); if (status == ERROR_MORE_DATA) { ssize++; @@ -568,7 +685,7 @@ summary_getproperty(msiobj* si, PyObject *args) if (sval == NULL) { return PyErr_NoMemory(); } - status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival, + status = MsiSummaryInfoGetProperty(self->h, field, &type, &ival, &fval, sval, &ssize); } if (status != ERROR_SUCCESS) { @@ -601,42 +718,64 @@ summary_getproperty(msiobj* si, PyObject *args) return result; } -static PyObject* -summary_getpropertycount(msiobj* si, PyObject *args) +/*[clinic input] +_msi.SummaryInformation.GetPropertyCount + +Return the number of summary properties. +[clinic start generated code]*/ + +static PyObject * +_msi_SummaryInformation_GetPropertyCount_impl(msiobj *self) +/*[clinic end generated code: output=68e94b2aeee92b3d input=2e71e985586d82dc]*/ { int status; UINT result; - status = MsiSummaryInfoGetPropertyCount(si->h, &result); + status = MsiSummaryInfoGetPropertyCount(self->h, &result); if (status != ERROR_SUCCESS) return msierror(status); return PyLong_FromLong(result); } -static PyObject* -summary_setproperty(msiobj* si, PyObject *args) +/*[clinic input] +_msi.SummaryInformation.SetProperty + field: int + the name of the property, one of the PID_* constants + value as data: object + the new value of the property (integer or string) + / + +Set a property. +[clinic start generated code]*/ + +static PyObject * +_msi_SummaryInformation_SetProperty_impl(msiobj *self, int field, + PyObject *data) +/*[clinic end generated code: output=3d4692c8984bb675 input=f2a7811b905abbed]*/ { int status; - int field; - PyObject* data; - - if (!PyArg_ParseTuple(args, "iO:SetProperty", &field, &data)) - return NULL; if (PyUnicode_Check(data)) { +#if USE_UNICODE_WCHAR_CACHE const WCHAR *value = _PyUnicode_AsUnicode(data); +#else /* USE_UNICODE_WCHAR_CACHE */ + WCHAR *value = PyUnicode_AsWideCharString(data, NULL); +#endif /* USE_UNICODE_WCHAR_CACHE */ if (value == NULL) { return NULL; } - status = MsiSummaryInfoSetPropertyW(si->h, field, VT_LPSTR, + status = MsiSummaryInfoSetPropertyW(self->h, field, VT_LPSTR, 0, NULL, value); +#if !USE_UNICODE_WCHAR_CACHE + PyMem_Free(value); +#endif /* USE_UNICODE_WCHAR_CACHE */ } else if (PyLong_CheckExact(data)) { long value = PyLong_AsLong(data); if (value == -1 && PyErr_Occurred()) { return NULL; } - status = MsiSummaryInfoSetProperty(si->h, field, VT_I4, + status = MsiSummaryInfoSetProperty(self->h, field, VT_I4, value, NULL, NULL); } else { PyErr_SetString(PyExc_TypeError, "unsupported type"); @@ -650,26 +789,29 @@ summary_setproperty(msiobj* si, PyObject *args) } -static PyObject* -summary_persist(msiobj* si, PyObject *args) +/*[clinic input] +_msi.SummaryInformation.Persist + +Write the modified properties to the summary information stream. +[clinic start generated code]*/ + +static PyObject * +_msi_SummaryInformation_Persist_impl(msiobj *self) +/*[clinic end generated code: output=c564bd17f5e122c9 input=e3dda9d530095ef7]*/ { int status; - status = MsiSummaryInfoPersist(si->h); + status = MsiSummaryInfoPersist(self->h); if (status != ERROR_SUCCESS) return msierror(status); Py_RETURN_NONE; } static PyMethodDef summary_methods[] = { - { "GetProperty", (PyCFunction)summary_getproperty, METH_VARARGS, - PyDoc_STR("GetProperty(propid) -> value\nWraps MsiSummaryInfoGetProperty")}, - { "GetPropertyCount", (PyCFunction)summary_getpropertycount, METH_NOARGS, - PyDoc_STR("GetProperty() -> int\nWraps MsiSummaryInfoGetPropertyCount")}, - { "SetProperty", (PyCFunction)summary_setproperty, METH_VARARGS, - PyDoc_STR("SetProperty(value) -> None\nWraps MsiSummaryInfoProperty")}, - { "Persist", (PyCFunction)summary_persist, METH_NOARGS, - PyDoc_STR("Persist() -> None\nWraps MsiSummaryInfoPersist")}, + _MSI_SUMMARYINFORMATION_GETPROPERTY_METHODDEF + _MSI_SUMMARYINFORMATION_GETPROPERTYCOUNT_METHODDEF + _MSI_SUMMARYINFORMATION_SETPROPERTY_METHODDEF + _MSI_SUMMARYINFORMATION_PERSIST_METHODDEF { NULL, NULL } }; @@ -719,15 +861,22 @@ static PyTypeObject summary_Type = { /*************************** View objects **************/ -static PyObject* -view_execute(msiobj *view, PyObject*args) +/*[clinic input] +_msi.View.Execute + params as oparams: object + a record describing actual values of the parameter tokens + in the query or None + / + +Execute the SQL query of the view. +[clinic start generated code]*/ + +static PyObject * +_msi_View_Execute(msiobj *self, PyObject *oparams) +/*[clinic end generated code: output=f0f65fd2900bcb4e input=cb163a15d453348e]*/ { int status; MSIHANDLE params = 0; - PyObject *oparams = Py_None; - - if (!PyArg_ParseTuple(args, "O:Execute", &oparams)) - return NULL; if (oparams != Py_None) { if (oparams->ob_type != &record_Type) { @@ -737,20 +886,27 @@ view_execute(msiobj *view, PyObject*args) params = ((msiobj*)oparams)->h; } - status = MsiViewExecute(view->h, params); + status = MsiViewExecute(self->h, params); if (status != ERROR_SUCCESS) return msierror(status); Py_RETURN_NONE; } -static PyObject* -view_fetch(msiobj *view, PyObject*args) +/*[clinic input] +_msi.View.Fetch + +Return a result record of the query. +[clinic start generated code]*/ + +static PyObject * +_msi_View_Fetch_impl(msiobj *self) +/*[clinic end generated code: output=ba154a3794537d4e input=7f3e3d06c449001c]*/ { int status; MSIHANDLE result; - status = MsiViewFetch(view->h, &result); + status = MsiViewFetch(self->h, &result); if (status == ERROR_NO_MORE_ITEMS) { Py_RETURN_NONE; } else if (status != ERROR_SUCCESS) { @@ -760,65 +916,80 @@ view_fetch(msiobj *view, PyObject*args) return record_new(result); } -static PyObject* -view_getcolumninfo(msiobj *view, PyObject *args) +/*[clinic input] +_msi.View.GetColumnInfo + kind: int + MSICOLINFO_NAMES or MSICOLINFO_TYPES + / + +Return a record describing the columns of the view. +[clinic start generated code]*/ + +static PyObject * +_msi_View_GetColumnInfo_impl(msiobj *self, int kind) +/*[clinic end generated code: output=e7c1697db9403660 input=afedb892bf564a3b]*/ { int status; - int kind; MSIHANDLE result; - if (!PyArg_ParseTuple(args, "i:GetColumnInfo", &kind)) - return NULL; - - if ((status = MsiViewGetColumnInfo(view->h, kind, &result)) != ERROR_SUCCESS) + if ((status = MsiViewGetColumnInfo(self->h, kind, &result)) != ERROR_SUCCESS) return msierror(status); return record_new(result); } -static PyObject* -view_modify(msiobj *view, PyObject *args) -{ - int kind; - PyObject *data; - int status; +/*[clinic input] +_msi.View.Modify + kind: int + one of the MSIMODIFY_* constants + data: object + a record describing the new data + / - if (!PyArg_ParseTuple(args, "iO:Modify", &kind, &data)) - return NULL; +Modify the view. +[clinic start generated code]*/ + +static PyObject * +_msi_View_Modify_impl(msiobj *self, int kind, PyObject *data) +/*[clinic end generated code: output=69aaf3ce8ddac0ba input=2828de22de0d47b4]*/ +{ + int status; if (data->ob_type != &record_Type) { PyErr_SetString(PyExc_TypeError, "Modify expects a record object"); return NULL; } - if ((status = MsiViewModify(view->h, kind, ((msiobj*)data)->h)) != ERROR_SUCCESS) + if ((status = MsiViewModify(self->h, kind, ((msiobj*)data)->h)) != ERROR_SUCCESS) return msierror(status); Py_RETURN_NONE; } -static PyObject* -view_close(msiobj *view, PyObject*args) +/*[clinic input] +_msi.View.Close + +Close the view. +[clinic start generated code]*/ + +static PyObject * +_msi_View_Close_impl(msiobj *self) +/*[clinic end generated code: output=488f7b8645ca104a input=de6927d1308c401c]*/ { int status; - if ((status = MsiViewClose(view->h)) != ERROR_SUCCESS) + if ((status = MsiViewClose(self->h)) != ERROR_SUCCESS) return msierror(status); Py_RETURN_NONE; } static PyMethodDef view_methods[] = { - { "Execute", (PyCFunction)view_execute, METH_VARARGS, - PyDoc_STR("Execute(params=None) -> None\nWraps MsiViewExecute")}, - { "GetColumnInfo", (PyCFunction)view_getcolumninfo, METH_VARARGS, - PyDoc_STR("GetColumnInfo() -> result\nWraps MsiGetColumnInfo")}, - { "Fetch", (PyCFunction)view_fetch, METH_NOARGS, - PyDoc_STR("Fetch() -> result\nWraps MsiViewFetch")}, - { "Modify", (PyCFunction)view_modify, METH_VARARGS, - PyDoc_STR("Modify(mode,record) -> None\nWraps MsiViewModify")}, - { "Close", (PyCFunction)view_close, METH_NOARGS, - PyDoc_STR("Close() -> result\nWraps MsiViewClose")}, + _MSI_VIEW_EXECUTE_METHODDEF + _MSI_VIEW_GETCOLUMNINFO_METHODDEF + _MSI_VIEW_FETCH_METHODDEF + _MSI_VIEW_MODIFY_METHODDEF + _MSI_VIEW_CLOSE_METHODDEF { NULL, NULL } }; @@ -868,18 +1039,24 @@ static PyTypeObject msiview_Type = { /*************************** Database objects **************/ -static PyObject* -msidb_openview(msiobj *msidb, PyObject *args) +/*[clinic input] +_msi.Database.OpenView + sql: Py_UNICODE + the SQL statement to execute + / + +Return a view object. +[clinic start generated code]*/ + +static PyObject * +_msi_Database_OpenView_impl(msiobj *self, const Py_UNICODE *sql) +/*[clinic end generated code: output=e712e6a11229abfd input=50f1771f37e500df]*/ { int status; - char *sql; MSIHANDLE hView; msiobj *result; - if (!PyArg_ParseTuple(args, "s:OpenView", &sql)) - return NULL; - - if ((status = MsiDatabaseOpenView(msidb->h, sql, &hView)) != ERROR_SUCCESS) + if ((status = MsiDatabaseOpenViewW(self->h, sql, &hView)) != ERROR_SUCCESS) return msierror(status); result = PyObject_New(struct msiobj, &msiview_Type); @@ -892,29 +1069,42 @@ msidb_openview(msiobj *msidb, PyObject *args) return (PyObject*)result; } -static PyObject* -msidb_commit(msiobj *msidb, PyObject *args) +/*[clinic input] +_msi.Database.Commit + +Commit the changes pending in the current transaction. +[clinic start generated code]*/ + +static PyObject * +_msi_Database_Commit_impl(msiobj *self) +/*[clinic end generated code: output=f33021feb8b0cdd8 input=375bb120d402266d]*/ { int status; - if ((status = MsiDatabaseCommit(msidb->h)) != ERROR_SUCCESS) + if ((status = MsiDatabaseCommit(self->h)) != ERROR_SUCCESS) return msierror(status); Py_RETURN_NONE; } -static PyObject* -msidb_getsummaryinformation(msiobj *db, PyObject *args) +/*[clinic input] +_msi.Database.GetSummaryInformation + count: int + the maximum number of updated values + / + +Return a new summary information object. +[clinic start generated code]*/ + +static PyObject * +_msi_Database_GetSummaryInformation_impl(msiobj *self, int count) +/*[clinic end generated code: output=781e51a4ea4da847 input=18a899ead6521735]*/ { int status; - int count; MSIHANDLE result; msiobj *oresult; - if (!PyArg_ParseTuple(args, "i:GetSummaryInformation", &count)) - return NULL; - - status = MsiGetSummaryInformation(db->h, NULL, count, &result); + status = MsiGetSummaryInformation(self->h, NULL, count, &result); if (status != ERROR_SUCCESS) return msierror(status); @@ -929,14 +1119,10 @@ msidb_getsummaryinformation(msiobj *db, PyObject *args) } static PyMethodDef db_methods[] = { - { "OpenView", (PyCFunction)msidb_openview, METH_VARARGS, - PyDoc_STR("OpenView(sql) -> viewobj\nWraps MsiDatabaseOpenView")}, - { "Commit", (PyCFunction)msidb_commit, METH_NOARGS, - PyDoc_STR("Commit() -> None\nWraps MsiDatabaseCommit")}, - { "GetSummaryInformation", (PyCFunction)msidb_getsummaryinformation, METH_VARARGS, - PyDoc_STR("GetSummaryInformation(updateCount) -> viewobj\nWraps MsiGetSummaryInformation")}, - { "Close", (PyCFunction)msidb_close, METH_NOARGS, - PyDoc_STR("Close() -> None\nWraps MsiCloseHandle")}, + _MSI_DATABASE_OPENVIEW_METHODDEF + _MSI_DATABASE_COMMIT_METHODDEF + _MSI_DATABASE_GETSUMMARYINFORMATION_METHODDEF + _MSI_DATABASE_CLOSE_METHODDEF { NULL, NULL } }; @@ -995,21 +1181,31 @@ static PyTypeObject msidb_Type = { Py_NOT_PERSIST(x, MSIDBOPEN_CREATE) && \ Py_NOT_PERSIST(x, MSIDBOPEN_CREATEDIRECT)) -static PyObject* msiopendb(PyObject *obj, PyObject *args) +/*[clinic input] +_msi.OpenDatabase + path: Py_UNICODE + the file name of the MSI file + persist: int + the persistence mode + / + +Return a new database object. +[clinic start generated code]*/ + +static PyObject * +_msi_OpenDatabase_impl(PyObject *module, const Py_UNICODE *path, int persist) +/*[clinic end generated code: output=d34b7202b745de05 input=1300f3b97659559b]*/ { int status; - char *path; - int persist; MSIHANDLE h; msiobj *result; - if (!PyArg_ParseTuple(args, "si:MSIOpenDatabase", &path, &persist)) - return NULL; + /* We need to validate that persist is a valid MSIDBOPEN_* value. Otherwise, MsiOpenDatabase may treat the value as a pointer, leading to unexpected behavior. */ if (Py_INVALID_PERSIST(persist)) return msierror(ERROR_INVALID_PARAMETER); - status = MsiOpenDatabase(path, (LPCSTR)(SIZE_T)persist, &h); + status = MsiOpenDatabaseW(path, (LPCWSTR)(SIZE_T)persist, &h); if (status != ERROR_SUCCESS) return msierror(status); @@ -1022,14 +1218,20 @@ static PyObject* msiopendb(PyObject *obj, PyObject *args) return (PyObject*)result; } -static PyObject* -createrecord(PyObject *o, PyObject *args) -{ - int count; - MSIHANDLE h; +/*[clinic input] +_msi.CreateRecord + count: int + the number of fields of the record + / - if (!PyArg_ParseTuple(args, "i:CreateRecord", &count)) - return NULL; +Return a new record object. +[clinic start generated code]*/ + +static PyObject * +_msi_CreateRecord_impl(PyObject *module, int count) +/*[clinic end generated code: output=0ba0a00beea3e99e input=53f17d5b5d9b077d]*/ +{ + MSIHANDLE h; h = MsiCreateRecord(count); if (h == 0) @@ -1040,14 +1242,10 @@ createrecord(PyObject *o, PyObject *args) static PyMethodDef msi_methods[] = { - {"UuidCreate", (PyCFunction)uuidcreate, METH_NOARGS, - PyDoc_STR("UuidCreate() -> string")}, - {"FCICreate", (PyCFunction)fcicreate, METH_VARARGS, - PyDoc_STR("fcicreate(cabname,files) -> None")}, - {"OpenDatabase", (PyCFunction)msiopendb, METH_VARARGS, - PyDoc_STR("OpenDatabase(name, flags) -> dbobj\nWraps MsiOpenDatabase")}, - {"CreateRecord", (PyCFunction)createrecord, METH_VARARGS, - PyDoc_STR("OpenDatabase(name, flags) -> dbobj\nWraps MsiCreateRecord")}, + _MSI_UUIDCREATE_METHODDEF + _MSI_FCICREATE_METHODDEF + _MSI_OPENDATABASE_METHODDEF + _MSI_CREATERECORD_METHODDEF {NULL, NULL} /* sentinel */ }; diff --git a/PC/bdist_wininst/bdist_wininst.vcxproj b/PC/bdist_wininst/bdist_wininst.vcxproj index d2f1bb75e30..390bf4e6272 100644 --- a/PC/bdist_wininst/bdist_wininst.vcxproj +++ b/PC/bdist_wininst/bdist_wininst.vcxproj @@ -87,7 +87,7 @@ MinSpace - $(PySourcePath)Modules\zlib;%(AdditionalIncludeDirectories) + $(zlibDir);%(AdditionalIncludeDirectories) _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) MultiThreadedDebug MultiThreaded @@ -102,15 +102,16 @@ - - - - - - + + + + + + + diff --git a/PC/bdist_wininst/bdist_wininst.vcxproj.filters b/PC/bdist_wininst/bdist_wininst.vcxproj.filters index b4b6a4d514d..c97742e7239 100644 --- a/PC/bdist_wininst/bdist_wininst.vcxproj.filters +++ b/PC/bdist_wininst/bdist_wininst.vcxproj.filters @@ -16,45 +16,51 @@ {0c77c1cf-3f87-4f87-bd86-b425211c2181} ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe + + {d10220c7-69e3-47c5-8d82-c8e0d4d2ac88} + - + Source Files - + Source Files - + Source Files\zlib - + Source Files\zlib - + Source Files\zlib - + Source Files\zlib - + Source Files\zlib - + Source Files\zlib - - Header Files - - - - + Resource Files - + + Header Files + + + Header Files\zlib + + + + Resource Files diff --git a/PC/clinic/_msi.c.h b/PC/clinic/_msi.c.h new file mode 100644 index 00000000000..85c4d226ee4 --- /dev/null +++ b/PC/clinic/_msi.c.h @@ -0,0 +1,716 @@ +/*[clinic input] +preserve +[clinic start generated code]*/ + +PyDoc_STRVAR(_msi_UuidCreate__doc__, +"UuidCreate($module, /)\n" +"--\n" +"\n" +"Return the string representation of a new unique identifier."); + +#define _MSI_UUIDCREATE_METHODDEF \ + {"UuidCreate", (PyCFunction)_msi_UuidCreate, METH_NOARGS, _msi_UuidCreate__doc__}, + +static PyObject * +_msi_UuidCreate_impl(PyObject *module); + +static PyObject * +_msi_UuidCreate(PyObject *module, PyObject *Py_UNUSED(ignored)) +{ + return _msi_UuidCreate_impl(module); +} + +PyDoc_STRVAR(_msi_FCICreate__doc__, +"FCICreate($module, cabname, files, /)\n" +"--\n" +"\n" +"Create a new CAB file.\n" +"\n" +" cabname\n" +" the name of the CAB file\n" +" files\n" +" a list of tuples, each containing the name of the file on disk,\n" +" and the name of the file inside the CAB file"); + +#define _MSI_FCICREATE_METHODDEF \ + {"FCICreate", (PyCFunction)(void(*)(void))_msi_FCICreate, METH_FASTCALL, _msi_FCICreate__doc__}, + +static PyObject * +_msi_FCICreate_impl(PyObject *module, const char *cabname, PyObject *files); + +static PyObject * +_msi_FCICreate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + const char *cabname; + PyObject *files; + + if (!_PyArg_CheckPositional("FCICreate", nargs, 2, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("FCICreate", "argument 1", "str", args[0]); + goto exit; + } + Py_ssize_t cabname_length; + cabname = PyUnicode_AsUTF8AndSize(args[0], &cabname_length); + if (cabname == NULL) { + goto exit; + } + if (strlen(cabname) != (size_t)cabname_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + files = args[1]; + return_value = _msi_FCICreate_impl(module, cabname, files); + +exit: + return return_value; +} + +PyDoc_STRVAR(_msi_Database_Close__doc__, +"Close($self, /)\n" +"--\n" +"\n" +"Close the database object."); + +#define _MSI_DATABASE_CLOSE_METHODDEF \ + {"Close", (PyCFunction)_msi_Database_Close, METH_NOARGS, _msi_Database_Close__doc__}, + +static PyObject * +_msi_Database_Close_impl(msiobj *self); + +static PyObject * +_msi_Database_Close(msiobj *self, PyObject *Py_UNUSED(ignored)) +{ + return _msi_Database_Close_impl(self); +} + +PyDoc_STRVAR(_msi_Record_GetFieldCount__doc__, +"GetFieldCount($self, /)\n" +"--\n" +"\n" +"Return the number of fields of the record."); + +#define _MSI_RECORD_GETFIELDCOUNT_METHODDEF \ + {"GetFieldCount", (PyCFunction)_msi_Record_GetFieldCount, METH_NOARGS, _msi_Record_GetFieldCount__doc__}, + +static PyObject * +_msi_Record_GetFieldCount_impl(msiobj *self); + +static PyObject * +_msi_Record_GetFieldCount(msiobj *self, PyObject *Py_UNUSED(ignored)) +{ + return _msi_Record_GetFieldCount_impl(self); +} + +PyDoc_STRVAR(_msi_Record_GetInteger__doc__, +"GetInteger($self, field, /)\n" +"--\n" +"\n" +"Return the value of field as an integer where possible."); + +#define _MSI_RECORD_GETINTEGER_METHODDEF \ + {"GetInteger", (PyCFunction)_msi_Record_GetInteger, METH_O, _msi_Record_GetInteger__doc__}, + +static PyObject * +_msi_Record_GetInteger_impl(msiobj *self, unsigned int field); + +static PyObject * +_msi_Record_GetInteger(msiobj *self, PyObject *arg) +{ + PyObject *return_value = NULL; + unsigned int field; + + field = (unsigned int)PyLong_AsUnsignedLongMask(arg); + if (field == (unsigned int)-1 && PyErr_Occurred()) { + goto exit; + } + return_value = _msi_Record_GetInteger_impl(self, field); + +exit: + return return_value; +} + +PyDoc_STRVAR(_msi_Record_GetString__doc__, +"GetString($self, field, /)\n" +"--\n" +"\n" +"Return the value of field as a string where possible."); + +#define _MSI_RECORD_GETSTRING_METHODDEF \ + {"GetString", (PyCFunction)_msi_Record_GetString, METH_O, _msi_Record_GetString__doc__}, + +static PyObject * +_msi_Record_GetString_impl(msiobj *self, unsigned int field); + +static PyObject * +_msi_Record_GetString(msiobj *self, PyObject *arg) +{ + PyObject *return_value = NULL; + unsigned int field; + + field = (unsigned int)PyLong_AsUnsignedLongMask(arg); + if (field == (unsigned int)-1 && PyErr_Occurred()) { + goto exit; + } + return_value = _msi_Record_GetString_impl(self, field); + +exit: + return return_value; +} + +PyDoc_STRVAR(_msi_Record_ClearData__doc__, +"ClearData($self, /)\n" +"--\n" +"\n" +"Set all fields of the record to 0."); + +#define _MSI_RECORD_CLEARDATA_METHODDEF \ + {"ClearData", (PyCFunction)_msi_Record_ClearData, METH_NOARGS, _msi_Record_ClearData__doc__}, + +static PyObject * +_msi_Record_ClearData_impl(msiobj *self); + +static PyObject * +_msi_Record_ClearData(msiobj *self, PyObject *Py_UNUSED(ignored)) +{ + return _msi_Record_ClearData_impl(self); +} + +PyDoc_STRVAR(_msi_Record_SetString__doc__, +"SetString($self, field, value, /)\n" +"--\n" +"\n" +"Set field to a string value."); + +#define _MSI_RECORD_SETSTRING_METHODDEF \ + {"SetString", (PyCFunction)(void(*)(void))_msi_Record_SetString, METH_FASTCALL, _msi_Record_SetString__doc__}, + +static PyObject * +_msi_Record_SetString_impl(msiobj *self, int field, const Py_UNICODE *value); + +static PyObject * +_msi_Record_SetString(msiobj *self, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + int field; + const Py_UNICODE *value; + + if (!_PyArg_CheckPositional("SetString", nargs, 2, 2)) { + goto exit; + } + field = _PyLong_AsInt(args[0]); + if (field == -1 && PyErr_Occurred()) { + goto exit; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("SetString", "argument 2", "str", args[1]); + goto exit; + } + #if USE_UNICODE_WCHAR_CACHE + value = _PyUnicode_AsUnicode(args[1]); + #else /* USE_UNICODE_WCHAR_CACHE */ + value = PyUnicode_AsWideCharString(args[1], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (value == NULL) { + goto exit; + } + return_value = _msi_Record_SetString_impl(self, field, value); + +exit: + /* Cleanup for value */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)value); + #endif /* USE_UNICODE_WCHAR_CACHE */ + + return return_value; +} + +PyDoc_STRVAR(_msi_Record_SetStream__doc__, +"SetStream($self, field, value, /)\n" +"--\n" +"\n" +"Set field to the contents of the file named value."); + +#define _MSI_RECORD_SETSTREAM_METHODDEF \ + {"SetStream", (PyCFunction)(void(*)(void))_msi_Record_SetStream, METH_FASTCALL, _msi_Record_SetStream__doc__}, + +static PyObject * +_msi_Record_SetStream_impl(msiobj *self, int field, const Py_UNICODE *value); + +static PyObject * +_msi_Record_SetStream(msiobj *self, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + int field; + const Py_UNICODE *value; + + if (!_PyArg_CheckPositional("SetStream", nargs, 2, 2)) { + goto exit; + } + field = _PyLong_AsInt(args[0]); + if (field == -1 && PyErr_Occurred()) { + goto exit; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("SetStream", "argument 2", "str", args[1]); + goto exit; + } + #if USE_UNICODE_WCHAR_CACHE + value = _PyUnicode_AsUnicode(args[1]); + #else /* USE_UNICODE_WCHAR_CACHE */ + value = PyUnicode_AsWideCharString(args[1], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (value == NULL) { + goto exit; + } + return_value = _msi_Record_SetStream_impl(self, field, value); + +exit: + /* Cleanup for value */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)value); + #endif /* USE_UNICODE_WCHAR_CACHE */ + + return return_value; +} + +PyDoc_STRVAR(_msi_Record_SetInteger__doc__, +"SetInteger($self, field, value, /)\n" +"--\n" +"\n" +"Set field to an integer value."); + +#define _MSI_RECORD_SETINTEGER_METHODDEF \ + {"SetInteger", (PyCFunction)(void(*)(void))_msi_Record_SetInteger, METH_FASTCALL, _msi_Record_SetInteger__doc__}, + +static PyObject * +_msi_Record_SetInteger_impl(msiobj *self, int field, int value); + +static PyObject * +_msi_Record_SetInteger(msiobj *self, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + int field; + int value; + + if (!_PyArg_CheckPositional("SetInteger", nargs, 2, 2)) { + goto exit; + } + field = _PyLong_AsInt(args[0]); + if (field == -1 && PyErr_Occurred()) { + goto exit; + } + value = _PyLong_AsInt(args[1]); + if (value == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = _msi_Record_SetInteger_impl(self, field, value); + +exit: + return return_value; +} + +PyDoc_STRVAR(_msi_SummaryInformation_GetProperty__doc__, +"GetProperty($self, field, /)\n" +"--\n" +"\n" +"Return a property of the summary.\n" +"\n" +" field\n" +" the name of the property, one of the PID_* constants"); + +#define _MSI_SUMMARYINFORMATION_GETPROPERTY_METHODDEF \ + {"GetProperty", (PyCFunction)_msi_SummaryInformation_GetProperty, METH_O, _msi_SummaryInformation_GetProperty__doc__}, + +static PyObject * +_msi_SummaryInformation_GetProperty_impl(msiobj *self, int field); + +static PyObject * +_msi_SummaryInformation_GetProperty(msiobj *self, PyObject *arg) +{ + PyObject *return_value = NULL; + int field; + + field = _PyLong_AsInt(arg); + if (field == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = _msi_SummaryInformation_GetProperty_impl(self, field); + +exit: + return return_value; +} + +PyDoc_STRVAR(_msi_SummaryInformation_GetPropertyCount__doc__, +"GetPropertyCount($self, /)\n" +"--\n" +"\n" +"Return the number of summary properties."); + +#define _MSI_SUMMARYINFORMATION_GETPROPERTYCOUNT_METHODDEF \ + {"GetPropertyCount", (PyCFunction)_msi_SummaryInformation_GetPropertyCount, METH_NOARGS, _msi_SummaryInformation_GetPropertyCount__doc__}, + +static PyObject * +_msi_SummaryInformation_GetPropertyCount_impl(msiobj *self); + +static PyObject * +_msi_SummaryInformation_GetPropertyCount(msiobj *self, PyObject *Py_UNUSED(ignored)) +{ + return _msi_SummaryInformation_GetPropertyCount_impl(self); +} + +PyDoc_STRVAR(_msi_SummaryInformation_SetProperty__doc__, +"SetProperty($self, field, value, /)\n" +"--\n" +"\n" +"Set a property.\n" +"\n" +" field\n" +" the name of the property, one of the PID_* constants\n" +" value\n" +" the new value of the property (integer or string)"); + +#define _MSI_SUMMARYINFORMATION_SETPROPERTY_METHODDEF \ + {"SetProperty", (PyCFunction)(void(*)(void))_msi_SummaryInformation_SetProperty, METH_FASTCALL, _msi_SummaryInformation_SetProperty__doc__}, + +static PyObject * +_msi_SummaryInformation_SetProperty_impl(msiobj *self, int field, + PyObject *data); + +static PyObject * +_msi_SummaryInformation_SetProperty(msiobj *self, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + int field; + PyObject *data; + + if (!_PyArg_CheckPositional("SetProperty", nargs, 2, 2)) { + goto exit; + } + field = _PyLong_AsInt(args[0]); + if (field == -1 && PyErr_Occurred()) { + goto exit; + } + data = args[1]; + return_value = _msi_SummaryInformation_SetProperty_impl(self, field, data); + +exit: + return return_value; +} + +PyDoc_STRVAR(_msi_SummaryInformation_Persist__doc__, +"Persist($self, /)\n" +"--\n" +"\n" +"Write the modified properties to the summary information stream."); + +#define _MSI_SUMMARYINFORMATION_PERSIST_METHODDEF \ + {"Persist", (PyCFunction)_msi_SummaryInformation_Persist, METH_NOARGS, _msi_SummaryInformation_Persist__doc__}, + +static PyObject * +_msi_SummaryInformation_Persist_impl(msiobj *self); + +static PyObject * +_msi_SummaryInformation_Persist(msiobj *self, PyObject *Py_UNUSED(ignored)) +{ + return _msi_SummaryInformation_Persist_impl(self); +} + +PyDoc_STRVAR(_msi_View_Execute__doc__, +"Execute($self, params, /)\n" +"--\n" +"\n" +"Execute the SQL query of the view.\n" +"\n" +" params\n" +" a record describing actual values of the parameter tokens\n" +" in the query or None"); + +#define _MSI_VIEW_EXECUTE_METHODDEF \ + {"Execute", (PyCFunction)_msi_View_Execute, METH_O, _msi_View_Execute__doc__}, + +PyDoc_STRVAR(_msi_View_Fetch__doc__, +"Fetch($self, /)\n" +"--\n" +"\n" +"Return a result record of the query."); + +#define _MSI_VIEW_FETCH_METHODDEF \ + {"Fetch", (PyCFunction)_msi_View_Fetch, METH_NOARGS, _msi_View_Fetch__doc__}, + +static PyObject * +_msi_View_Fetch_impl(msiobj *self); + +static PyObject * +_msi_View_Fetch(msiobj *self, PyObject *Py_UNUSED(ignored)) +{ + return _msi_View_Fetch_impl(self); +} + +PyDoc_STRVAR(_msi_View_GetColumnInfo__doc__, +"GetColumnInfo($self, kind, /)\n" +"--\n" +"\n" +"Return a record describing the columns of the view.\n" +"\n" +" kind\n" +" MSICOLINFO_NAMES or MSICOLINFO_TYPES"); + +#define _MSI_VIEW_GETCOLUMNINFO_METHODDEF \ + {"GetColumnInfo", (PyCFunction)_msi_View_GetColumnInfo, METH_O, _msi_View_GetColumnInfo__doc__}, + +static PyObject * +_msi_View_GetColumnInfo_impl(msiobj *self, int kind); + +static PyObject * +_msi_View_GetColumnInfo(msiobj *self, PyObject *arg) +{ + PyObject *return_value = NULL; + int kind; + + kind = _PyLong_AsInt(arg); + if (kind == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = _msi_View_GetColumnInfo_impl(self, kind); + +exit: + return return_value; +} + +PyDoc_STRVAR(_msi_View_Modify__doc__, +"Modify($self, kind, data, /)\n" +"--\n" +"\n" +"Modify the view.\n" +"\n" +" kind\n" +" one of the MSIMODIFY_* constants\n" +" data\n" +" a record describing the new data"); + +#define _MSI_VIEW_MODIFY_METHODDEF \ + {"Modify", (PyCFunction)(void(*)(void))_msi_View_Modify, METH_FASTCALL, _msi_View_Modify__doc__}, + +static PyObject * +_msi_View_Modify_impl(msiobj *self, int kind, PyObject *data); + +static PyObject * +_msi_View_Modify(msiobj *self, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + int kind; + PyObject *data; + + if (!_PyArg_CheckPositional("Modify", nargs, 2, 2)) { + goto exit; + } + kind = _PyLong_AsInt(args[0]); + if (kind == -1 && PyErr_Occurred()) { + goto exit; + } + data = args[1]; + return_value = _msi_View_Modify_impl(self, kind, data); + +exit: + return return_value; +} + +PyDoc_STRVAR(_msi_View_Close__doc__, +"Close($self, /)\n" +"--\n" +"\n" +"Close the view."); + +#define _MSI_VIEW_CLOSE_METHODDEF \ + {"Close", (PyCFunction)_msi_View_Close, METH_NOARGS, _msi_View_Close__doc__}, + +static PyObject * +_msi_View_Close_impl(msiobj *self); + +static PyObject * +_msi_View_Close(msiobj *self, PyObject *Py_UNUSED(ignored)) +{ + return _msi_View_Close_impl(self); +} + +PyDoc_STRVAR(_msi_Database_OpenView__doc__, +"OpenView($self, sql, /)\n" +"--\n" +"\n" +"Return a view object.\n" +"\n" +" sql\n" +" the SQL statement to execute"); + +#define _MSI_DATABASE_OPENVIEW_METHODDEF \ + {"OpenView", (PyCFunction)_msi_Database_OpenView, METH_O, _msi_Database_OpenView__doc__}, + +static PyObject * +_msi_Database_OpenView_impl(msiobj *self, const Py_UNICODE *sql); + +static PyObject * +_msi_Database_OpenView(msiobj *self, PyObject *arg) +{ + PyObject *return_value = NULL; + const Py_UNICODE *sql; + + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("OpenView", "argument", "str", arg); + goto exit; + } + #if USE_UNICODE_WCHAR_CACHE + sql = _PyUnicode_AsUnicode(arg); + #else /* USE_UNICODE_WCHAR_CACHE */ + sql = PyUnicode_AsWideCharString(arg, NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (sql == NULL) { + goto exit; + } + return_value = _msi_Database_OpenView_impl(self, sql); + +exit: + /* Cleanup for sql */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)sql); + #endif /* USE_UNICODE_WCHAR_CACHE */ + + return return_value; +} + +PyDoc_STRVAR(_msi_Database_Commit__doc__, +"Commit($self, /)\n" +"--\n" +"\n" +"Commit the changes pending in the current transaction."); + +#define _MSI_DATABASE_COMMIT_METHODDEF \ + {"Commit", (PyCFunction)_msi_Database_Commit, METH_NOARGS, _msi_Database_Commit__doc__}, + +static PyObject * +_msi_Database_Commit_impl(msiobj *self); + +static PyObject * +_msi_Database_Commit(msiobj *self, PyObject *Py_UNUSED(ignored)) +{ + return _msi_Database_Commit_impl(self); +} + +PyDoc_STRVAR(_msi_Database_GetSummaryInformation__doc__, +"GetSummaryInformation($self, count, /)\n" +"--\n" +"\n" +"Return a new summary information object.\n" +"\n" +" count\n" +" the maximum number of updated values"); + +#define _MSI_DATABASE_GETSUMMARYINFORMATION_METHODDEF \ + {"GetSummaryInformation", (PyCFunction)_msi_Database_GetSummaryInformation, METH_O, _msi_Database_GetSummaryInformation__doc__}, + +static PyObject * +_msi_Database_GetSummaryInformation_impl(msiobj *self, int count); + +static PyObject * +_msi_Database_GetSummaryInformation(msiobj *self, PyObject *arg) +{ + PyObject *return_value = NULL; + int count; + + count = _PyLong_AsInt(arg); + if (count == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = _msi_Database_GetSummaryInformation_impl(self, count); + +exit: + return return_value; +} + +PyDoc_STRVAR(_msi_OpenDatabase__doc__, +"OpenDatabase($module, path, persist, /)\n" +"--\n" +"\n" +"Return a new database object.\n" +"\n" +" path\n" +" the file name of the MSI file\n" +" persist\n" +" the persistence mode"); + +#define _MSI_OPENDATABASE_METHODDEF \ + {"OpenDatabase", (PyCFunction)(void(*)(void))_msi_OpenDatabase, METH_FASTCALL, _msi_OpenDatabase__doc__}, + +static PyObject * +_msi_OpenDatabase_impl(PyObject *module, const Py_UNICODE *path, int persist); + +static PyObject * +_msi_OpenDatabase(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + const Py_UNICODE *path; + int persist; + + if (!_PyArg_CheckPositional("OpenDatabase", nargs, 2, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("OpenDatabase", "argument 1", "str", args[0]); + goto exit; + } + #if USE_UNICODE_WCHAR_CACHE + path = _PyUnicode_AsUnicode(args[0]); + #else /* USE_UNICODE_WCHAR_CACHE */ + path = PyUnicode_AsWideCharString(args[0], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (path == NULL) { + goto exit; + } + persist = _PyLong_AsInt(args[1]); + if (persist == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = _msi_OpenDatabase_impl(module, path, persist); + +exit: + /* Cleanup for path */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)path); + #endif /* USE_UNICODE_WCHAR_CACHE */ + + return return_value; +} + +PyDoc_STRVAR(_msi_CreateRecord__doc__, +"CreateRecord($module, count, /)\n" +"--\n" +"\n" +"Return a new record object.\n" +"\n" +" count\n" +" the number of fields of the record"); + +#define _MSI_CREATERECORD_METHODDEF \ + {"CreateRecord", (PyCFunction)_msi_CreateRecord, METH_O, _msi_CreateRecord__doc__}, + +static PyObject * +_msi_CreateRecord_impl(PyObject *module, int count); + +static PyObject * +_msi_CreateRecord(PyObject *module, PyObject *arg) +{ + PyObject *return_value = NULL; + int count; + + count = _PyLong_AsInt(arg); + if (count == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = _msi_CreateRecord_impl(module, count); + +exit: + return return_value; +} +/*[clinic end generated code: output=49debf733ee5cab2 input=a9049054013a1b77]*/ diff --git a/PC/clinic/msvcrtmodule.c.h b/PC/clinic/msvcrtmodule.c.h index 9701e8a63be..1ac82cb965b 100644 --- a/PC/clinic/msvcrtmodule.c.h +++ b/PC/clinic/msvcrtmodule.c.h @@ -590,6 +590,24 @@ exit: #endif /* defined(_DEBUG) */ +PyDoc_STRVAR(msvcrt_GetErrorMode__doc__, +"GetErrorMode($module, /)\n" +"--\n" +"\n" +"Wrapper around GetErrorMode."); + +#define MSVCRT_GETERRORMODE_METHODDEF \ + {"GetErrorMode", (PyCFunction)msvcrt_GetErrorMode, METH_NOARGS, msvcrt_GetErrorMode__doc__}, + +static PyObject * +msvcrt_GetErrorMode_impl(PyObject *module); + +static PyObject * +msvcrt_GetErrorMode(PyObject *module, PyObject *Py_UNUSED(ignored)) +{ + return msvcrt_GetErrorMode_impl(module); +} + PyDoc_STRVAR(msvcrt_SetErrorMode__doc__, "SetErrorMode($module, mode, /)\n" "--\n" @@ -629,4 +647,4 @@ exit: #ifndef MSVCRT_SET_ERROR_MODE_METHODDEF #define MSVCRT_SET_ERROR_MODE_METHODDEF #endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */ -/*[clinic end generated code: output=ab3b5ce5c1447f0e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=20dfbc768edce7c0 input=a9049054013a1b77]*/ diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h index 5f37fcda0a9..3301bed9713 100644 --- a/PC/clinic/winreg.c.h +++ b/PC/clinic/winreg.c.h @@ -152,8 +152,27 @@ winreg_ConnectRegistry(PyObject *module, PyObject *const *args, Py_ssize_t nargs HKEY key; HKEY _return_value; - if (!_PyArg_ParseStack(args, nargs, "ZO&:ConnectRegistry", - &computer_name, clinic_HKEY_converter, &key)) { + if (!_PyArg_CheckPositional("ConnectRegistry", nargs, 2, 2)) { + goto exit; + } + if (args[0] == Py_None) { + computer_name = NULL; + } + else if (PyUnicode_Check(args[0])) { + #if USE_UNICODE_WCHAR_CACHE + computer_name = _PyUnicode_AsUnicode(args[0]); + #else /* USE_UNICODE_WCHAR_CACHE */ + computer_name = PyUnicode_AsWideCharString(args[0], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (computer_name == NULL) { + goto exit; + } + } + else { + _PyArg_BadArgument("ConnectRegistry", "argument 1", "str or None", args[0]); + goto exit; + } + if (!clinic_HKEY_converter(args[1], &key)) { goto exit; } _return_value = winreg_ConnectRegistry_impl(module, computer_name, key); @@ -163,6 +182,11 @@ winreg_ConnectRegistry(PyObject *module, PyObject *const *args, Py_ssize_t nargs return_value = PyHKEY_FromHKEY(_return_value); exit: + /* Cleanup for computer_name */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)computer_name); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -199,8 +223,27 @@ winreg_CreateKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) const Py_UNICODE *sub_key; HKEY _return_value; - if (!_PyArg_ParseStack(args, nargs, "O&Z:CreateKey", - clinic_HKEY_converter, &key, &sub_key)) { + if (!_PyArg_CheckPositional("CreateKey", nargs, 2, 2)) { + goto exit; + } + if (!clinic_HKEY_converter(args[0], &key)) { + goto exit; + } + if (args[1] == Py_None) { + sub_key = NULL; + } + else if (PyUnicode_Check(args[1])) { + #if USE_UNICODE_WCHAR_CACHE + sub_key = _PyUnicode_AsUnicode(args[1]); + #else /* USE_UNICODE_WCHAR_CACHE */ + sub_key = PyUnicode_AsWideCharString(args[1], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (sub_key == NULL) { + goto exit; + } + } + else { + _PyArg_BadArgument("CreateKey", "argument 2", "str or None", args[1]); goto exit; } _return_value = winreg_CreateKey_impl(module, key, sub_key); @@ -210,6 +253,11 @@ winreg_CreateKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return_value = PyHKEY_FromHKEY(_return_value); exit: + /* Cleanup for sub_key */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)sub_key); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -251,7 +299,7 @@ winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py { PyObject *return_value = NULL; static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL}; - static _PyArg_Parser _parser = {"O&Z|ii:CreateKeyEx", _keywords, 0}; + static _PyArg_Parser _parser = {"O&O&|ii:CreateKeyEx", _keywords, 0}; HKEY key; const Py_UNICODE *sub_key; int reserved = 0; @@ -259,7 +307,7 @@ winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py HKEY _return_value; if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) { + clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &reserved, &access)) { goto exit; } _return_value = winreg_CreateKeyEx_impl(module, key, sub_key, reserved, access); @@ -269,6 +317,11 @@ winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py return_value = PyHKEY_FromHKEY(_return_value); exit: + /* Cleanup for sub_key */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)sub_key); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -303,13 +356,32 @@ winreg_DeleteKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) HKEY key; const Py_UNICODE *sub_key; - if (!_PyArg_ParseStack(args, nargs, "O&u:DeleteKey", - clinic_HKEY_converter, &key, &sub_key)) { + if (!_PyArg_CheckPositional("DeleteKey", nargs, 2, 2)) { + goto exit; + } + if (!clinic_HKEY_converter(args[0], &key)) { + goto exit; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("DeleteKey", "argument 2", "str", args[1]); + goto exit; + } + #if USE_UNICODE_WCHAR_CACHE + sub_key = _PyUnicode_AsUnicode(args[1]); + #else /* USE_UNICODE_WCHAR_CACHE */ + sub_key = PyUnicode_AsWideCharString(args[1], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (sub_key == NULL) { goto exit; } return_value = winreg_DeleteKey_impl(module, key, sub_key); exit: + /* Cleanup for sub_key */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)sub_key); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -351,19 +423,24 @@ winreg_DeleteKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py { PyObject *return_value = NULL; static const char * const _keywords[] = {"key", "sub_key", "access", "reserved", NULL}; - static _PyArg_Parser _parser = {"O&u|ii:DeleteKeyEx", _keywords, 0}; + static _PyArg_Parser _parser = {"O&O&|ii:DeleteKeyEx", _keywords, 0}; HKEY key; const Py_UNICODE *sub_key; REGSAM access = KEY_WOW64_64KEY; int reserved = 0; if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - clinic_HKEY_converter, &key, &sub_key, &access, &reserved)) { + clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Converter, &sub_key, &access, &reserved)) { goto exit; } return_value = winreg_DeleteKeyEx_impl(module, key, sub_key, access, reserved); exit: + /* Cleanup for sub_key */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)sub_key); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -391,13 +468,37 @@ winreg_DeleteValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) HKEY key; const Py_UNICODE *value; - if (!_PyArg_ParseStack(args, nargs, "O&Z:DeleteValue", - clinic_HKEY_converter, &key, &value)) { + if (!_PyArg_CheckPositional("DeleteValue", nargs, 2, 2)) { + goto exit; + } + if (!clinic_HKEY_converter(args[0], &key)) { + goto exit; + } + if (args[1] == Py_None) { + value = NULL; + } + else if (PyUnicode_Check(args[1])) { + #if USE_UNICODE_WCHAR_CACHE + value = _PyUnicode_AsUnicode(args[1]); + #else /* USE_UNICODE_WCHAR_CACHE */ + value = PyUnicode_AsWideCharString(args[1], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (value == NULL) { + goto exit; + } + } + else { + _PyArg_BadArgument("DeleteValue", "argument 2", "str or None", args[1]); goto exit; } return_value = winreg_DeleteValue_impl(module, key, value); exit: + /* Cleanup for value */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)value); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -517,12 +618,26 @@ winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg) PyObject *return_value = NULL; const Py_UNICODE *string; - if (!PyArg_Parse(arg, "u:ExpandEnvironmentStrings", &string)) { + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("ExpandEnvironmentStrings", "argument", "str", arg); + goto exit; + } + #if USE_UNICODE_WCHAR_CACHE + string = _PyUnicode_AsUnicode(arg); + #else /* USE_UNICODE_WCHAR_CACHE */ + string = PyUnicode_AsWideCharString(arg, NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (string == NULL) { goto exit; } return_value = winreg_ExpandEnvironmentStrings_impl(module, string); exit: + /* Cleanup for string */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)string); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -609,13 +724,48 @@ winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) const Py_UNICODE *sub_key; const Py_UNICODE *file_name; - if (!_PyArg_ParseStack(args, nargs, "O&uu:LoadKey", - clinic_HKEY_converter, &key, &sub_key, &file_name)) { + if (!_PyArg_CheckPositional("LoadKey", nargs, 3, 3)) { + goto exit; + } + if (!clinic_HKEY_converter(args[0], &key)) { + goto exit; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("LoadKey", "argument 2", "str", args[1]); + goto exit; + } + #if USE_UNICODE_WCHAR_CACHE + sub_key = _PyUnicode_AsUnicode(args[1]); + #else /* USE_UNICODE_WCHAR_CACHE */ + sub_key = PyUnicode_AsWideCharString(args[1], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (sub_key == NULL) { + goto exit; + } + if (!PyUnicode_Check(args[2])) { + _PyArg_BadArgument("LoadKey", "argument 3", "str", args[2]); + goto exit; + } + #if USE_UNICODE_WCHAR_CACHE + file_name = _PyUnicode_AsUnicode(args[2]); + #else /* USE_UNICODE_WCHAR_CACHE */ + file_name = PyUnicode_AsWideCharString(args[2], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (file_name == NULL) { goto exit; } return_value = winreg_LoadKey_impl(module, key, sub_key, file_name); exit: + /* Cleanup for sub_key */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)sub_key); + #endif /* USE_UNICODE_WCHAR_CACHE */ + /* Cleanup for file_name */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)file_name); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -650,7 +800,7 @@ winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje { PyObject *return_value = NULL; static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL}; - static _PyArg_Parser _parser = {"O&Z|ii:OpenKey", _keywords, 0}; + static _PyArg_Parser _parser = {"O&O&|ii:OpenKey", _keywords, 0}; HKEY key; const Py_UNICODE *sub_key; int reserved = 0; @@ -658,7 +808,7 @@ winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje HKEY _return_value; if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) { + clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &reserved, &access)) { goto exit; } _return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access); @@ -668,6 +818,11 @@ winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje return_value = PyHKEY_FromHKEY(_return_value); exit: + /* Cleanup for sub_key */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)sub_key); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -702,7 +857,7 @@ winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb { PyObject *return_value = NULL; static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL}; - static _PyArg_Parser _parser = {"O&Z|ii:OpenKeyEx", _keywords, 0}; + static _PyArg_Parser _parser = {"O&O&|ii:OpenKeyEx", _keywords, 0}; HKEY key; const Py_UNICODE *sub_key; int reserved = 0; @@ -710,7 +865,7 @@ winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb HKEY _return_value; if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) { + clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &reserved, &access)) { goto exit; } _return_value = winreg_OpenKeyEx_impl(module, key, sub_key, reserved, access); @@ -720,6 +875,11 @@ winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb return_value = PyHKEY_FromHKEY(_return_value); exit: + /* Cleanup for sub_key */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)sub_key); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -792,13 +952,37 @@ winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) HKEY key; const Py_UNICODE *sub_key; - if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValue", - clinic_HKEY_converter, &key, &sub_key)) { + if (!_PyArg_CheckPositional("QueryValue", nargs, 2, 2)) { + goto exit; + } + if (!clinic_HKEY_converter(args[0], &key)) { + goto exit; + } + if (args[1] == Py_None) { + sub_key = NULL; + } + else if (PyUnicode_Check(args[1])) { + #if USE_UNICODE_WCHAR_CACHE + sub_key = _PyUnicode_AsUnicode(args[1]); + #else /* USE_UNICODE_WCHAR_CACHE */ + sub_key = PyUnicode_AsWideCharString(args[1], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (sub_key == NULL) { + goto exit; + } + } + else { + _PyArg_BadArgument("QueryValue", "argument 2", "str or None", args[1]); goto exit; } return_value = winreg_QueryValue_impl(module, key, sub_key); exit: + /* Cleanup for sub_key */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)sub_key); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -831,13 +1015,37 @@ winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) HKEY key; const Py_UNICODE *name; - if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValueEx", - clinic_HKEY_converter, &key, &name)) { + if (!_PyArg_CheckPositional("QueryValueEx", nargs, 2, 2)) { + goto exit; + } + if (!clinic_HKEY_converter(args[0], &key)) { + goto exit; + } + if (args[1] == Py_None) { + name = NULL; + } + else if (PyUnicode_Check(args[1])) { + #if USE_UNICODE_WCHAR_CACHE + name = _PyUnicode_AsUnicode(args[1]); + #else /* USE_UNICODE_WCHAR_CACHE */ + name = PyUnicode_AsWideCharString(args[1], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (name == NULL) { + goto exit; + } + } + else { + _PyArg_BadArgument("QueryValueEx", "argument 2", "str or None", args[1]); goto exit; } return_value = winreg_QueryValueEx_impl(module, key, name); exit: + /* Cleanup for name */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)name); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -875,13 +1083,32 @@ winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) HKEY key; const Py_UNICODE *file_name; - if (!_PyArg_ParseStack(args, nargs, "O&u:SaveKey", - clinic_HKEY_converter, &key, &file_name)) { + if (!_PyArg_CheckPositional("SaveKey", nargs, 2, 2)) { + goto exit; + } + if (!clinic_HKEY_converter(args[0], &key)) { + goto exit; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("SaveKey", "argument 2", "str", args[1]); + goto exit; + } + #if USE_UNICODE_WCHAR_CACHE + file_name = _PyUnicode_AsUnicode(args[1]); + #else /* USE_UNICODE_WCHAR_CACHE */ + file_name = PyUnicode_AsWideCharString(args[1], NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if (file_name == NULL) { goto exit; } return_value = winreg_SaveKey_impl(module, key, file_name); exit: + /* Cleanup for file_name */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)file_name); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -929,13 +1156,18 @@ winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) const Py_UNICODE *value; Py_ssize_clean_t value_length; - if (!_PyArg_ParseStack(args, nargs, "O&Zku#:SetValue", - clinic_HKEY_converter, &key, &sub_key, &type, &value, &value_length)) { + if (!_PyArg_ParseStack(args, nargs, "O&O&ku#:SetValue", + clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &type, &value, &value_length)) { goto exit; } return_value = winreg_SetValue_impl(module, key, sub_key, type, value, value_length); exit: + /* Cleanup for sub_key */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)sub_key); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -1000,13 +1232,18 @@ winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) DWORD type; PyObject *value; - if (!_PyArg_ParseStack(args, nargs, "O&ZOkO:SetValueEx", - clinic_HKEY_converter, &key, &value_name, &reserved, &type, &value)) { + if (!_PyArg_ParseStack(args, nargs, "O&O&OkO:SetValueEx", + clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &value_name, &reserved, &type, &value)) { goto exit; } return_value = winreg_SetValueEx_impl(module, key, value_name, reserved, type, value); exit: + /* Cleanup for value_name */ + #if !USE_UNICODE_WCHAR_CACHE + PyMem_Free((void *)value_name); + #endif /* USE_UNICODE_WCHAR_CACHE */ + return return_value; } @@ -1111,4 +1348,4 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=f4f996d40d06f14c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=30b1311886c13907 input=a9049054013a1b77]*/ diff --git a/PC/config.c b/PC/config.c index 32af2a81aeb..87cd76d37be 100644 --- a/PC/config.c +++ b/PC/config.c @@ -45,7 +45,6 @@ extern PyObject* PyInit__symtable(void); extern PyObject* PyInit_mmap(void); extern PyObject* PyInit__csv(void); extern PyObject* PyInit__sre(void); -extern PyObject* PyInit_parser(void); extern PyObject* PyInit_winreg(void); extern PyObject* PyInit__struct(void); extern PyObject* PyInit__datetime(void); @@ -75,7 +74,6 @@ extern PyObject* PyInit__opcode(void); extern PyObject* PyInit__contextvars(void); -extern PyObject* PyInit__peg_parser(void); /* tools/freeze/makeconfig.py marker for additional "extern" */ /* -- ADDMODULE MARKER 1 -- */ @@ -127,7 +125,6 @@ struct _inittab _PyImport_Inittab[] = { {"mmap", PyInit_mmap}, {"_csv", PyInit__csv}, {"_sre", PyInit__sre}, - {"parser", PyInit_parser}, {"winreg", PyInit_winreg}, {"_struct", PyInit__struct}, {"_datetime", PyInit__datetime}, @@ -171,7 +168,6 @@ struct _inittab _PyImport_Inittab[] = { {"_opcode", PyInit__opcode}, {"_contextvars", PyInit__contextvars}, - {"_peg_parser", PyInit__peg_parser}, /* Sentinel */ {0, 0} diff --git a/PC/dl_nt.c b/PC/dl_nt.c index 0bf04f1bf3d..7f17ee16872 100644 --- a/PC/dl_nt.c +++ b/PC/dl_nt.c @@ -12,16 +12,10 @@ forgotten) from the programmer. #include "windows.h" #ifdef Py_ENABLE_SHARED -#ifdef MS_DLL_ID -// The string is available at build, so fill the buffer immediately -char dllVersionBuffer[16] = MS_DLL_ID; -#else -char dllVersionBuffer[16] = ""; // a private buffer -#endif // Python Globals HMODULE PyWin_DLLhModule = NULL; -const char *PyWin_DLLVersionString = dllVersionBuffer; +const char *PyWin_DLLVersionString = MS_DLL_ID; BOOL WINAPI DllMain (HANDLE hInst, ULONG ul_reason_for_call, @@ -31,11 +25,6 @@ BOOL WINAPI DllMain (HANDLE hInst, { case DLL_PROCESS_ATTACH: PyWin_DLLhModule = hInst; -#ifndef MS_DLL_ID - // If we have MS_DLL_ID, we don't need to load the string. - // 1000 is a magic number I picked out of the air. Could do with a #define, I spose... - LoadString(hInst, 1000, dllVersionBuffer, sizeof(dllVersionBuffer)); -#endif break; case DLL_PROCESS_DETACH: diff --git a/PC/getpathp.c b/PC/getpathp.c index fd5cfa7e1a8..0939c5fa984 100644 --- a/PC/getpathp.c +++ b/PC/getpathp.c @@ -131,8 +131,6 @@ typedef struct { wchar_t *machine_path; /* from HKEY_LOCAL_MACHINE */ wchar_t *user_path; /* from HKEY_CURRENT_USER */ - wchar_t *dll_path; - const wchar_t *pythonpath_env; } PyCalculatePath; @@ -168,27 +166,37 @@ reduce(wchar_t *dir) static int change_ext(wchar_t *dest, const wchar_t *src, const wchar_t *ext) { - size_t src_len = wcsnlen_s(src, MAXPATHLEN+1); - size_t i = src_len; - if (i >= MAXPATHLEN+1) { - Py_FatalError("buffer overflow in getpathp.c's reduce()"); + if (src && src != dest) { + size_t src_len = wcsnlen_s(src, MAXPATHLEN+1); + size_t i = src_len; + if (i >= MAXPATHLEN+1) { + Py_FatalError("buffer overflow in getpathp.c's reduce()"); + } + + while (i > 0 && src[i] != '.' && !is_sep(src[i])) + --i; + + if (i == 0) { + dest[0] = '\0'; + return -1; + } + + if (is_sep(src[i])) { + i = src_len; + } + + if (wcsncpy_s(dest, MAXPATHLEN+1, src, i)) { + dest[0] = '\0'; + return -1; + } + } else { + wchar_t *s = wcsrchr(dest, L'.'); + if (s) { + s[0] = '\0'; + } } - while (i > 0 && src[i] != '.' && !is_sep(src[i])) - --i; - - if (i == 0) { - dest[0] = '\0'; - return -1; - } - - if (is_sep(src[i])) { - i = src_len; - } - - if (wcsncpy_s(dest, MAXPATHLEN+1, src, i) || - wcscat_s(dest, MAXPATHLEN+1, ext)) - { + if (wcscat_s(dest, MAXPATHLEN+1, ext)) { dest[0] = '\0'; return -1; } @@ -297,6 +305,19 @@ search_for_prefix(wchar_t *prefix, const wchar_t *argv0_path, const wchar_t *lan } +static int +get_dllpath(wchar_t *dllpath) +{ +#ifdef Py_ENABLE_SHARED + extern HANDLE PyWin_DLLhModule; + if (PyWin_DLLhModule && GetModuleFileNameW(PyWin_DLLhModule, dllpath, MAXPATHLEN)) { + return 0; + } +#endif + return -1; +} + + #ifdef Py_ENABLE_SHARED /* a string loaded from the DLL at startup.*/ @@ -468,27 +489,6 @@ done: #endif /* Py_ENABLE_SHARED */ -wchar_t* -_Py_GetDLLPath(void) -{ - wchar_t dll_path[MAXPATHLEN+1]; - memset(dll_path, 0, sizeof(dll_path)); - -#ifdef Py_ENABLE_SHARED - extern HANDLE PyWin_DLLhModule; - if (PyWin_DLLhModule) { - if (!GetModuleFileNameW(PyWin_DLLhModule, dll_path, MAXPATHLEN)) { - dll_path[0] = 0; - } - } -#else - dll_path[0] = 0; -#endif - - return _PyMem_RawWcsdup(dll_path); -} - - static PyStatus get_program_full_path(_PyPathConfig *pathconfig) { @@ -669,19 +669,17 @@ static int get_pth_filename(PyCalculatePath *calculate, wchar_t *filename, const _PyPathConfig *pathconfig) { - if (calculate->dll_path[0]) { - if (!change_ext(filename, calculate->dll_path, L"._pth") && - exists(filename)) - { - return 1; - } + if (get_dllpath(filename) && + !change_ext(filename, filename, L"._pth") && + exists(filename)) + { + return 1; } - if (pathconfig->program_full_path[0]) { - if (!change_ext(filename, pathconfig->program_full_path, L"._pth") && - exists(filename)) - { - return 1; - } + if (pathconfig->program_full_path[0] && + !change_ext(filename, pathconfig->program_full_path, L"._pth") && + exists(filename)) + { + return 1; } return 0; } @@ -994,9 +992,12 @@ calculate_path(PyCalculatePath *calculate, _PyPathConfig *pathconfig) wchar_t zip_path[MAXPATHLEN+1]; memset(zip_path, 0, sizeof(zip_path)); - change_ext(zip_path, - calculate->dll_path[0] ? calculate->dll_path : pathconfig->program_full_path, - L".zip"); + if (get_dllpath(zip_path) || change_ext(zip_path, zip_path, L".zip")) + { + if (change_ext(zip_path, pathconfig->program_full_path, L".zip")) { + zip_path[0] = L'\0'; + } + } calculate_home_prefix(calculate, argv0_path, zip_path, prefix); @@ -1033,11 +1034,6 @@ calculate_init(PyCalculatePath *calculate, _PyPathConfig *pathconfig, calculate->home = pathconfig->home; calculate->path_env = _wgetenv(L"PATH"); - calculate->dll_path = _Py_GetDLLPath(); - if (calculate->dll_path == NULL) { - return _PyStatus_NO_MEMORY(); - } - calculate->pythonpath_env = config->pythonpath_env; return _PyStatus_OK(); @@ -1049,7 +1045,6 @@ calculate_free(PyCalculatePath *calculate) { PyMem_RawFree(calculate->machine_path); PyMem_RawFree(calculate->user_path); - PyMem_RawFree(calculate->dll_path); } @@ -1059,7 +1054,6 @@ calculate_free(PyCalculatePath *calculate) - PyConfig.pythonpath_env: PYTHONPATH environment variable - _PyPathConfig.home: Py_SetPythonHome() or PYTHONHOME environment variable - - DLL path: _Py_GetDLLPath() - PATH environment variable - __PYVENV_LAUNCHER__ environment variable - GetModuleFileNameW(NULL): fully qualified path of the executable file of @@ -1113,33 +1107,35 @@ int _Py_CheckPython3(void) { wchar_t py3path[MAXPATHLEN+1]; - wchar_t *s; if (python3_checked) { return hPython3 != NULL; } python3_checked = 1; /* If there is a python3.dll next to the python3y.dll, - assume this is a build tree; use that DLL */ - if (_Py_dll_path != NULL) { - wcscpy(py3path, _Py_dll_path); + use that DLL */ + if (!get_dllpath(py3path)) { + reduce(py3path); + join(py3path, PY3_DLLNAME); + hPython3 = LoadLibraryExW(py3path, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); + if (hPython3 != NULL) { + return 1; + } } - else { - wcscpy(py3path, L""); - } - s = wcsrchr(py3path, L'\\'); - if (!s) { - s = py3path; - } - wcscpy(s, L"\\python3.dll"); - hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + + /* If we can locate python3.dll in our application dir, + use that DLL */ + hPython3 = LoadLibraryExW(PY3_DLLNAME, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR); if (hPython3 != NULL) { return 1; } - /* Check sys.prefix\DLLs\python3.dll */ + /* For back-compat, also search {sys.prefix}\DLLs, though + that has not been a normal install layout for a while */ wcscpy(py3path, Py_GetPrefix()); - wcscat(py3path, L"\\DLLs\\python3.dll"); - hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + if (py3path[0]) { + join(py3path, L"DLLs\\" PY3_DLLNAME); + hPython3 = LoadLibraryExW(py3path, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); + } return hPython3 != NULL; } diff --git a/PC/launcher.c b/PC/launcher.c index fd5ad0ab1a1..106fc660755 100644 --- a/PC/launcher.c +++ b/PC/launcher.c @@ -1520,7 +1520,7 @@ show_help_text(wchar_t ** argv) Python Launcher for Windows Version %ls\n\n", version_text); fwprintf(stdout, L"\ usage:\n\ -%ls [launcher-args] [python-args] script [script-args]\n\n", argv[0]); +%ls [launcher-args] [python-args] [script [script-args]]\n\n", argv[0]); fputws(L"\ Launcher arguments:\n\n\ -2 : Launch the latest Python 2.x version\n\ @@ -1536,6 +1536,15 @@ Launcher arguments:\n\n\ } fputws(L"\n-0 --list : List the available pythons", stdout); fputws(L"\n-0p --list-paths : List with paths", stdout); + fputws(L"\n\n If no script is specified the specified interpreter is opened.", stdout); + fputws(L"\nIf an exact version is not given, using the latest version can be overridden by", stdout); + fputws(L"\nany of the following, (in priority order):", stdout); + fputws(L"\n An active virtual environment", stdout); + fputws(L"\n A shebang line in the script (if present)", stdout); + fputws(L"\n With -2 or -3 flag a matching PY_PYTHON2 or PY_PYTHON3 Enviroment variable", stdout); + fputws(L"\n A PY_PYTHON Enviroment variable", stdout); + fputws(L"\n From [defaults] in py.ini in your %LOCALAPPDATA%\\py.ini", stdout); + fputws(L"\n From [defaults] in py.ini beside py.exe (use `where py` to locate)", stdout); fputws(L"\n\nThe following help text is from Python:\n\n", stdout); fflush(stdout); } diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c index faceb03fba3..b7ff20ab0fb 100644 --- a/PC/msvcrtmodule.c +++ b/PC/msvcrtmodule.c @@ -482,6 +482,25 @@ msvcrt_set_error_mode_impl(PyObject *module, int mode) } #endif /* _DEBUG */ +/*[clinic input] +msvcrt.GetErrorMode + +Wrapper around GetErrorMode. +[clinic start generated code]*/ + +static PyObject * +msvcrt_GetErrorMode_impl(PyObject *module) +/*[clinic end generated code: output=3103fc6145913591 input=5a7fb083b6dd71fd]*/ +{ + unsigned int res; + + _Py_BEGIN_SUPPRESS_IPH + res = GetErrorMode(); + _Py_END_SUPPRESS_IPH + + return PyLong_FromUnsignedLong(res); +} + /*[clinic input] msvcrt.SetErrorMode @@ -520,6 +539,7 @@ static struct PyMethodDef msvcrt_functions[] = { MSVCRT_GETCHE_METHODDEF MSVCRT_PUTCH_METHODDEF MSVCRT_UNGETCH_METHODDEF + MSVCRT_GETERRORMODE_METHODDEF MSVCRT_SETERRORMODE_METHODDEF MSVCRT_CRTSETREPORTFILE_METHODDEF MSVCRT_CRTSETREPORTMODE_METHODDEF diff --git a/PC/pyshellext.cpp b/PC/pyshellext.cpp index 019880264be..ffca169857c 100644 --- a/PC/pyshellext.cpp +++ b/PC/pyshellext.cpp @@ -12,15 +12,14 @@ #include #include -#include "pyshellext_h.h" - #define DDWM_UPDATEWINDOW (WM_USER+3) static HINSTANCE hModule; static CLIPFORMAT cfDropDescription; static CLIPFORMAT cfDragWindow; -static const LPCWSTR CLASS_SUBKEY = L"Software\\Classes\\CLSID\\{BEA218D2-6950-497B-9434-61683EC065FE}"; +#define CLASS_GUID "{BEA218D2-6950-497B-9434-61683EC065FE}" +static const LPCWSTR CLASS_SUBKEY = L"Software\\Classes\\CLSID\\" CLASS_GUID; static const LPCWSTR DRAG_MESSAGE = L"Open with %1"; using namespace Microsoft::WRL; @@ -121,8 +120,7 @@ HRESULT FilenameListCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, LPCWSTR psz return hr; } - -class PyShellExt : public RuntimeClass< +class DECLSPEC_UUID(CLASS_GUID) PyShellExt : public RuntimeClass< RuntimeClassFlags, IDropTarget, IPersistFile @@ -483,7 +481,7 @@ public: } STDMETHODIMP GetClassID(CLSID *pClassID) { - *pClassID = CLSID_PyShellExt; + *pClassID = __uuidof(PyShellExt); return S_OK; } }; diff --git a/PC/pyshellext.def b/PC/pyshellext.def index 5424bd1180d..288a9adf982 100644 --- a/PC/pyshellext.def +++ b/PC/pyshellext.def @@ -1,4 +1,3 @@ -LIBRARY "pyshellext" EXPORTS DllRegisterServer PRIVATE DllUnregisterServer PRIVATE diff --git a/PC/pyshellext.idl b/PC/pyshellext.idl deleted file mode 100644 index c0a183876ad..00000000000 --- a/PC/pyshellext.idl +++ /dev/null @@ -1,12 +0,0 @@ -import "ocidl.idl"; - -[uuid(44039A76-3BDD-41C1-A31B-71C00202CE81), version(1.0)] -library PyShellExtLib -{ - [uuid(BEA218D2-6950-497B-9434-61683EC065FE), version(1.0)] - coclass PyShellExt - { - [default] interface IDropTarget; - interface IPersistFile; - } -}; \ No newline at end of file diff --git a/PC/pyshellext_d.def b/PC/pyshellext_d.def deleted file mode 100644 index 7d2148bb861..00000000000 --- a/PC/pyshellext_d.def +++ /dev/null @@ -1,6 +0,0 @@ -LIBRARY "pyshellext_d" -EXPORTS - DllRegisterServer PRIVATE - DllUnregisterServer PRIVATE - DllGetClassObject PRIVATE - DllCanUnloadNow PRIVATE diff --git a/PC/python3.def b/PC/python3.def deleted file mode 100644 index 6d54d4eaf71..00000000000 --- a/PC/python3.def +++ /dev/null @@ -1,803 +0,0 @@ -; This file specifies the import forwarding for python3.dll -; It is used when building python3dll.vcxproj -LIBRARY "python3" -EXPORTS - PyArg_Parse=python310.PyArg_Parse - PyArg_ParseTuple=python310.PyArg_ParseTuple - PyArg_ParseTupleAndKeywords=python310.PyArg_ParseTupleAndKeywords - PyArg_UnpackTuple=python310.PyArg_UnpackTuple - PyArg_VaParse=python310.PyArg_VaParse - PyArg_VaParseTupleAndKeywords=python310.PyArg_VaParseTupleAndKeywords - PyArg_ValidateKeywordArguments=python310.PyArg_ValidateKeywordArguments - PyBaseObject_Type=python310.PyBaseObject_Type DATA - PyBool_FromLong=python310.PyBool_FromLong - PyBool_Type=python310.PyBool_Type DATA - PyByteArrayIter_Type=python310.PyByteArrayIter_Type DATA - PyByteArray_AsString=python310.PyByteArray_AsString - PyByteArray_Concat=python310.PyByteArray_Concat - PyByteArray_FromObject=python310.PyByteArray_FromObject - PyByteArray_FromStringAndSize=python310.PyByteArray_FromStringAndSize - PyByteArray_Resize=python310.PyByteArray_Resize - PyByteArray_Size=python310.PyByteArray_Size - PyByteArray_Type=python310.PyByteArray_Type DATA - PyBytesIter_Type=python310.PyBytesIter_Type DATA - PyBytes_AsString=python310.PyBytes_AsString - PyBytes_AsStringAndSize=python310.PyBytes_AsStringAndSize - PyBytes_Concat=python310.PyBytes_Concat - PyBytes_ConcatAndDel=python310.PyBytes_ConcatAndDel - PyBytes_DecodeEscape=python310.PyBytes_DecodeEscape - PyBytes_FromFormat=python310.PyBytes_FromFormat - PyBytes_FromFormatV=python310.PyBytes_FromFormatV - PyBytes_FromObject=python310.PyBytes_FromObject - PyBytes_FromString=python310.PyBytes_FromString - PyBytes_FromStringAndSize=python310.PyBytes_FromStringAndSize - PyBytes_Repr=python310.PyBytes_Repr - PyBytes_Size=python310.PyBytes_Size - PyBytes_Type=python310.PyBytes_Type DATA - PyCFunction_Call=python310.PyCFunction_Call - PyCFunction_GetFlags=python310.PyCFunction_GetFlags - PyCFunction_GetFunction=python310.PyCFunction_GetFunction - PyCFunction_GetSelf=python310.PyCFunction_GetSelf - PyCFunction_New=python310.PyCFunction_New - PyCFunction_NewEx=python310.PyCFunction_NewEx - PyCFunction_Type=python310.PyCFunction_Type DATA - PyCallIter_New=python310.PyCallIter_New - PyCallIter_Type=python310.PyCallIter_Type DATA - PyCallable_Check=python310.PyCallable_Check - PyCapsule_GetContext=python310.PyCapsule_GetContext - PyCapsule_GetDestructor=python310.PyCapsule_GetDestructor - PyCapsule_GetName=python310.PyCapsule_GetName - PyCapsule_GetPointer=python310.PyCapsule_GetPointer - PyCapsule_Import=python310.PyCapsule_Import - PyCapsule_IsValid=python310.PyCapsule_IsValid - PyCapsule_New=python310.PyCapsule_New - PyCapsule_SetContext=python310.PyCapsule_SetContext - PyCapsule_SetDestructor=python310.PyCapsule_SetDestructor - PyCapsule_SetName=python310.PyCapsule_SetName - PyCapsule_SetPointer=python310.PyCapsule_SetPointer - PyCapsule_Type=python310.PyCapsule_Type DATA - PyClassMethodDescr_Type=python310.PyClassMethodDescr_Type DATA - PyCodec_BackslashReplaceErrors=python310.PyCodec_BackslashReplaceErrors - PyCodec_Decode=python310.PyCodec_Decode - PyCodec_Decoder=python310.PyCodec_Decoder - PyCodec_Encode=python310.PyCodec_Encode - PyCodec_Encoder=python310.PyCodec_Encoder - PyCodec_IgnoreErrors=python310.PyCodec_IgnoreErrors - PyCodec_IncrementalDecoder=python310.PyCodec_IncrementalDecoder - PyCodec_IncrementalEncoder=python310.PyCodec_IncrementalEncoder - PyCodec_KnownEncoding=python310.PyCodec_KnownEncoding - PyCodec_LookupError=python310.PyCodec_LookupError - PyCodec_NameReplaceErrors=python310.PyCodec_NameReplaceErrors - PyCodec_Register=python310.PyCodec_Register - PyCodec_RegisterError=python310.PyCodec_RegisterError - PyCodec_ReplaceErrors=python310.PyCodec_ReplaceErrors - PyCodec_StreamReader=python310.PyCodec_StreamReader - PyCodec_StreamWriter=python310.PyCodec_StreamWriter - PyCodec_StrictErrors=python310.PyCodec_StrictErrors - PyCodec_XMLCharRefReplaceErrors=python310.PyCodec_XMLCharRefReplaceErrors - PyComplex_FromDoubles=python310.PyComplex_FromDoubles - PyComplex_ImagAsDouble=python310.PyComplex_ImagAsDouble - PyComplex_RealAsDouble=python310.PyComplex_RealAsDouble - PyComplex_Type=python310.PyComplex_Type DATA - PyDescr_NewClassMethod=python310.PyDescr_NewClassMethod - PyDescr_NewGetSet=python310.PyDescr_NewGetSet - PyDescr_NewMember=python310.PyDescr_NewMember - PyDescr_NewMethod=python310.PyDescr_NewMethod - PyDictItems_Type=python310.PyDictItems_Type DATA - PyDictIterItem_Type=python310.PyDictIterItem_Type DATA - PyDictIterKey_Type=python310.PyDictIterKey_Type DATA - PyDictIterValue_Type=python310.PyDictIterValue_Type DATA - PyDictKeys_Type=python310.PyDictKeys_Type DATA - PyDictProxy_New=python310.PyDictProxy_New - PyDictProxy_Type=python310.PyDictProxy_Type DATA - PyDictValues_Type=python310.PyDictValues_Type DATA - PyDict_Clear=python310.PyDict_Clear - PyDict_Contains=python310.PyDict_Contains - PyDict_Copy=python310.PyDict_Copy - PyDict_DelItem=python310.PyDict_DelItem - PyDict_DelItemString=python310.PyDict_DelItemString - PyDict_GetItem=python310.PyDict_GetItem - PyDict_GetItemString=python310.PyDict_GetItemString - PyDict_GetItemWithError=python310.PyDict_GetItemWithError - PyDict_Items=python310.PyDict_Items - PyDict_Keys=python310.PyDict_Keys - PyDict_Merge=python310.PyDict_Merge - PyDict_MergeFromSeq2=python310.PyDict_MergeFromSeq2 - PyDict_New=python310.PyDict_New - PyDict_Next=python310.PyDict_Next - PyDict_SetItem=python310.PyDict_SetItem - PyDict_SetItemString=python310.PyDict_SetItemString - PyDict_Size=python310.PyDict_Size - PyDict_Type=python310.PyDict_Type DATA - PyDict_Update=python310.PyDict_Update - PyDict_Values=python310.PyDict_Values - PyEllipsis_Type=python310.PyEllipsis_Type DATA - PyEnum_Type=python310.PyEnum_Type DATA - PyErr_BadArgument=python310.PyErr_BadArgument - PyErr_BadInternalCall=python310.PyErr_BadInternalCall - PyErr_CheckSignals=python310.PyErr_CheckSignals - PyErr_Clear=python310.PyErr_Clear - PyErr_Display=python310.PyErr_Display - PyErr_ExceptionMatches=python310.PyErr_ExceptionMatches - PyErr_Fetch=python310.PyErr_Fetch - PyErr_Format=python310.PyErr_Format - PyErr_FormatV=python310.PyErr_FormatV - PyErr_GetExcInfo=python310.PyErr_GetExcInfo - PyErr_GivenExceptionMatches=python310.PyErr_GivenExceptionMatches - PyErr_NewException=python310.PyErr_NewException - PyErr_NewExceptionWithDoc=python310.PyErr_NewExceptionWithDoc - PyErr_NoMemory=python310.PyErr_NoMemory - PyErr_NormalizeException=python310.PyErr_NormalizeException - PyErr_Occurred=python310.PyErr_Occurred - PyErr_Print=python310.PyErr_Print - PyErr_PrintEx=python310.PyErr_PrintEx - PyErr_ProgramText=python310.PyErr_ProgramText - PyErr_ResourceWarning=python310.PyErr_ResourceWarning - PyErr_Restore=python310.PyErr_Restore - PyErr_SetExcFromWindowsErr=python310.PyErr_SetExcFromWindowsErr - PyErr_SetExcFromWindowsErrWithFilename=python310.PyErr_SetExcFromWindowsErrWithFilename - PyErr_SetExcFromWindowsErrWithFilenameObject=python310.PyErr_SetExcFromWindowsErrWithFilenameObject - PyErr_SetExcFromWindowsErrWithFilenameObjects=python310.PyErr_SetExcFromWindowsErrWithFilenameObjects - PyErr_SetExcInfo=python310.PyErr_SetExcInfo - PyErr_SetFromErrno=python310.PyErr_SetFromErrno - PyErr_SetFromErrnoWithFilename=python310.PyErr_SetFromErrnoWithFilename - PyErr_SetFromErrnoWithFilenameObject=python310.PyErr_SetFromErrnoWithFilenameObject - PyErr_SetFromErrnoWithFilenameObjects=python310.PyErr_SetFromErrnoWithFilenameObjects - PyErr_SetFromWindowsErr=python310.PyErr_SetFromWindowsErr - PyErr_SetFromWindowsErrWithFilename=python310.PyErr_SetFromWindowsErrWithFilename - PyErr_SetImportError=python310.PyErr_SetImportError - PyErr_SetImportErrorSubclass=python310.PyErr_SetImportErrorSubclass - PyErr_SetInterrupt=python310.PyErr_SetInterrupt - PyErr_SetNone=python310.PyErr_SetNone - PyErr_SetObject=python310.PyErr_SetObject - PyErr_SetString=python310.PyErr_SetString - PyErr_SyntaxLocation=python310.PyErr_SyntaxLocation - PyErr_SyntaxLocationEx=python310.PyErr_SyntaxLocationEx - PyErr_WarnEx=python310.PyErr_WarnEx - PyErr_WarnExplicit=python310.PyErr_WarnExplicit - PyErr_WarnFormat=python310.PyErr_WarnFormat - PyErr_WriteUnraisable=python310.PyErr_WriteUnraisable - PyEval_AcquireLock=python310.PyEval_AcquireLock - PyEval_AcquireThread=python310.PyEval_AcquireThread - PyEval_CallFunction=python310.PyEval_CallFunction - PyEval_CallMethod=python310.PyEval_CallMethod - PyEval_CallObjectWithKeywords=python310.PyEval_CallObjectWithKeywords - PyEval_EvalCode=python310.PyEval_EvalCode - PyEval_EvalCodeEx=python310.PyEval_EvalCodeEx - PyEval_EvalFrame=python310.PyEval_EvalFrame - PyEval_EvalFrameEx=python310.PyEval_EvalFrameEx - PyEval_GetBuiltins=python310.PyEval_GetBuiltins - PyEval_GetCallStats=python310.PyEval_GetCallStats - PyEval_GetFrame=python310.PyEval_GetFrame - PyEval_GetFuncDesc=python310.PyEval_GetFuncDesc - PyEval_GetFuncName=python310.PyEval_GetFuncName - PyEval_GetGlobals=python310.PyEval_GetGlobals - PyEval_GetLocals=python310.PyEval_GetLocals - PyEval_InitThreads=python310.PyEval_InitThreads - PyEval_ReInitThreads=python310.PyEval_ReInitThreads - PyEval_ReleaseLock=python310.PyEval_ReleaseLock - PyEval_ReleaseThread=python310.PyEval_ReleaseThread - PyEval_RestoreThread=python310.PyEval_RestoreThread - PyEval_SaveThread=python310.PyEval_SaveThread - PyEval_ThreadsInitialized=python310.PyEval_ThreadsInitialized - PyExc_ArithmeticError=python310.PyExc_ArithmeticError DATA - PyExc_AssertionError=python310.PyExc_AssertionError DATA - PyExc_AttributeError=python310.PyExc_AttributeError DATA - PyExc_BaseException=python310.PyExc_BaseException DATA - PyExc_BlockingIOError=python310.PyExc_BlockingIOError DATA - PyExc_BrokenPipeError=python310.PyExc_BrokenPipeError DATA - PyExc_BufferError=python310.PyExc_BufferError DATA - PyExc_BytesWarning=python310.PyExc_BytesWarning DATA - PyExc_ChildProcessError=python310.PyExc_ChildProcessError DATA - PyExc_ConnectionAbortedError=python310.PyExc_ConnectionAbortedError DATA - PyExc_ConnectionError=python310.PyExc_ConnectionError DATA - PyExc_ConnectionRefusedError=python310.PyExc_ConnectionRefusedError DATA - PyExc_ConnectionResetError=python310.PyExc_ConnectionResetError DATA - PyExc_DeprecationWarning=python310.PyExc_DeprecationWarning DATA - PyExc_EOFError=python310.PyExc_EOFError DATA - PyExc_EnvironmentError=python310.PyExc_EnvironmentError DATA - PyExc_Exception=python310.PyExc_Exception DATA - PyExc_FileExistsError=python310.PyExc_FileExistsError DATA - PyExc_FileNotFoundError=python310.PyExc_FileNotFoundError DATA - PyExc_FloatingPointError=python310.PyExc_FloatingPointError DATA - PyExc_FutureWarning=python310.PyExc_FutureWarning DATA - PyExc_GeneratorExit=python310.PyExc_GeneratorExit DATA - PyExc_IOError=python310.PyExc_IOError DATA - PyExc_ImportError=python310.PyExc_ImportError DATA - PyExc_ImportWarning=python310.PyExc_ImportWarning DATA - PyExc_IndentationError=python310.PyExc_IndentationError DATA - PyExc_IndexError=python310.PyExc_IndexError DATA - PyExc_InterruptedError=python310.PyExc_InterruptedError DATA - PyExc_IsADirectoryError=python310.PyExc_IsADirectoryError DATA - PyExc_KeyError=python310.PyExc_KeyError DATA - PyExc_KeyboardInterrupt=python310.PyExc_KeyboardInterrupt DATA - PyExc_LookupError=python310.PyExc_LookupError DATA - PyExc_MemoryError=python310.PyExc_MemoryError DATA - PyExc_ModuleNotFoundError=python310.PyExc_ModuleNotFoundError DATA - PyExc_NameError=python310.PyExc_NameError DATA - PyExc_NotADirectoryError=python310.PyExc_NotADirectoryError DATA - PyExc_NotImplementedError=python310.PyExc_NotImplementedError DATA - PyExc_OSError=python310.PyExc_OSError DATA - PyExc_OverflowError=python310.PyExc_OverflowError DATA - PyExc_PendingDeprecationWarning=python310.PyExc_PendingDeprecationWarning DATA - PyExc_PermissionError=python310.PyExc_PermissionError DATA - PyExc_ProcessLookupError=python310.PyExc_ProcessLookupError DATA - PyExc_RecursionError=python310.PyExc_RecursionError DATA - PyExc_ReferenceError=python310.PyExc_ReferenceError DATA - PyExc_ResourceWarning=python310.PyExc_ResourceWarning DATA - PyExc_RuntimeError=python310.PyExc_RuntimeError DATA - PyExc_RuntimeWarning=python310.PyExc_RuntimeWarning DATA - PyExc_StopAsyncIteration=python310.PyExc_StopAsyncIteration DATA - PyExc_StopIteration=python310.PyExc_StopIteration DATA - PyExc_SyntaxError=python310.PyExc_SyntaxError DATA - PyExc_SyntaxWarning=python310.PyExc_SyntaxWarning DATA - PyExc_SystemError=python310.PyExc_SystemError DATA - PyExc_SystemExit=python310.PyExc_SystemExit DATA - PyExc_TabError=python310.PyExc_TabError DATA - PyExc_TimeoutError=python310.PyExc_TimeoutError DATA - PyExc_TypeError=python310.PyExc_TypeError DATA - PyExc_UnboundLocalError=python310.PyExc_UnboundLocalError DATA - PyExc_UnicodeDecodeError=python310.PyExc_UnicodeDecodeError DATA - PyExc_UnicodeEncodeError=python310.PyExc_UnicodeEncodeError DATA - PyExc_UnicodeError=python310.PyExc_UnicodeError DATA - PyExc_UnicodeTranslateError=python310.PyExc_UnicodeTranslateError DATA - PyExc_UnicodeWarning=python310.PyExc_UnicodeWarning DATA - PyExc_UserWarning=python310.PyExc_UserWarning DATA - PyExc_ValueError=python310.PyExc_ValueError DATA - PyExc_Warning=python310.PyExc_Warning DATA - PyExc_WindowsError=python310.PyExc_WindowsError DATA - PyExc_ZeroDivisionError=python310.PyExc_ZeroDivisionError DATA - PyExceptionClass_Name=python310.PyExceptionClass_Name - PyException_GetCause=python310.PyException_GetCause - PyException_GetContext=python310.PyException_GetContext - PyException_GetTraceback=python310.PyException_GetTraceback - PyException_SetCause=python310.PyException_SetCause - PyException_SetContext=python310.PyException_SetContext - PyException_SetTraceback=python310.PyException_SetTraceback - PyFile_FromFd=python310.PyFile_FromFd - PyFile_GetLine=python310.PyFile_GetLine - PyFile_WriteObject=python310.PyFile_WriteObject - PyFile_WriteString=python310.PyFile_WriteString - PyFilter_Type=python310.PyFilter_Type DATA - PyFloat_AsDouble=python310.PyFloat_AsDouble - PyFloat_FromDouble=python310.PyFloat_FromDouble - PyFloat_FromString=python310.PyFloat_FromString - PyFloat_GetInfo=python310.PyFloat_GetInfo - PyFloat_GetMax=python310.PyFloat_GetMax - PyFloat_GetMin=python310.PyFloat_GetMin - PyFloat_Type=python310.PyFloat_Type DATA - PyFrozenSet_New=python310.PyFrozenSet_New - PyFrozenSet_Type=python310.PyFrozenSet_Type DATA - PyGC_Collect=python310.PyGC_Collect - PyGILState_Ensure=python310.PyGILState_Ensure - PyGILState_GetThisThreadState=python310.PyGILState_GetThisThreadState - PyGILState_Release=python310.PyGILState_Release - PyGetSetDescr_Type=python310.PyGetSetDescr_Type DATA - PyImport_AddModule=python310.PyImport_AddModule - PyImport_AddModuleObject=python310.PyImport_AddModuleObject - PyImport_AppendInittab=python310.PyImport_AppendInittab - PyImport_Cleanup=python310.PyImport_Cleanup - PyImport_ExecCodeModule=python310.PyImport_ExecCodeModule - PyImport_ExecCodeModuleEx=python310.PyImport_ExecCodeModuleEx - PyImport_ExecCodeModuleObject=python310.PyImport_ExecCodeModuleObject - PyImport_ExecCodeModuleWithPathnames=python310.PyImport_ExecCodeModuleWithPathnames - PyImport_GetImporter=python310.PyImport_GetImporter - PyImport_GetMagicNumber=python310.PyImport_GetMagicNumber - PyImport_GetMagicTag=python310.PyImport_GetMagicTag - PyImport_GetModule=python310.PyImport_GetModule - PyImport_GetModuleDict=python310.PyImport_GetModuleDict - PyImport_Import=python310.PyImport_Import - PyImport_ImportFrozenModule=python310.PyImport_ImportFrozenModule - PyImport_ImportFrozenModuleObject=python310.PyImport_ImportFrozenModuleObject - PyImport_ImportModule=python310.PyImport_ImportModule - PyImport_ImportModuleLevel=python310.PyImport_ImportModuleLevel - PyImport_ImportModuleLevelObject=python310.PyImport_ImportModuleLevelObject - PyImport_ImportModuleNoBlock=python310.PyImport_ImportModuleNoBlock - PyImport_ReloadModule=python310.PyImport_ReloadModule - PyIndex_Check=python310.PyIndex_Check - PyInterpreterState_Clear=python310.PyInterpreterState_Clear - PyInterpreterState_Delete=python310.PyInterpreterState_Delete - PyInterpreterState_New=python310.PyInterpreterState_New - PyIter_Check=python310.PyIter_Check - PyIter_Next=python310.PyIter_Next - PyListIter_Type=python310.PyListIter_Type DATA - PyListRevIter_Type=python310.PyListRevIter_Type DATA - PyList_Append=python310.PyList_Append - PyList_AsTuple=python310.PyList_AsTuple - PyList_GetItem=python310.PyList_GetItem - PyList_GetSlice=python310.PyList_GetSlice - PyList_Insert=python310.PyList_Insert - PyList_New=python310.PyList_New - PyList_Reverse=python310.PyList_Reverse - PyList_SetItem=python310.PyList_SetItem - PyList_SetSlice=python310.PyList_SetSlice - PyList_Size=python310.PyList_Size - PyList_Sort=python310.PyList_Sort - PyList_Type=python310.PyList_Type DATA - PyLongRangeIter_Type=python310.PyLongRangeIter_Type DATA - PyLong_AsDouble=python310.PyLong_AsDouble - PyLong_AsLong=python310.PyLong_AsLong - PyLong_AsLongAndOverflow=python310.PyLong_AsLongAndOverflow - PyLong_AsLongLong=python310.PyLong_AsLongLong - PyLong_AsLongLongAndOverflow=python310.PyLong_AsLongLongAndOverflow - PyLong_AsSize_t=python310.PyLong_AsSize_t - PyLong_AsSsize_t=python310.PyLong_AsSsize_t - PyLong_AsUnsignedLong=python310.PyLong_AsUnsignedLong - PyLong_AsUnsignedLongLong=python310.PyLong_AsUnsignedLongLong - PyLong_AsUnsignedLongLongMask=python310.PyLong_AsUnsignedLongLongMask - PyLong_AsUnsignedLongMask=python310.PyLong_AsUnsignedLongMask - PyLong_AsVoidPtr=python310.PyLong_AsVoidPtr - PyLong_FromDouble=python310.PyLong_FromDouble - PyLong_FromLong=python310.PyLong_FromLong - PyLong_FromLongLong=python310.PyLong_FromLongLong - PyLong_FromSize_t=python310.PyLong_FromSize_t - PyLong_FromSsize_t=python310.PyLong_FromSsize_t - PyLong_FromString=python310.PyLong_FromString - PyLong_FromUnsignedLong=python310.PyLong_FromUnsignedLong - PyLong_FromUnsignedLongLong=python310.PyLong_FromUnsignedLongLong - PyLong_FromVoidPtr=python310.PyLong_FromVoidPtr - PyLong_GetInfo=python310.PyLong_GetInfo - PyLong_Type=python310.PyLong_Type DATA - PyMap_Type=python310.PyMap_Type DATA - PyMapping_Check=python310.PyMapping_Check - PyMapping_GetItemString=python310.PyMapping_GetItemString - PyMapping_HasKey=python310.PyMapping_HasKey - PyMapping_HasKeyString=python310.PyMapping_HasKeyString - PyMapping_Items=python310.PyMapping_Items - PyMapping_Keys=python310.PyMapping_Keys - PyMapping_Length=python310.PyMapping_Length - PyMapping_SetItemString=python310.PyMapping_SetItemString - PyMapping_Size=python310.PyMapping_Size - PyMapping_Values=python310.PyMapping_Values - PyMem_Calloc=python310.PyMem_Calloc - PyMem_Free=python310.PyMem_Free - PyMem_Malloc=python310.PyMem_Malloc - PyMem_Realloc=python310.PyMem_Realloc - PyMemberDescr_Type=python310.PyMemberDescr_Type DATA - PyMemoryView_FromMemory=python310.PyMemoryView_FromMemory - PyMemoryView_FromObject=python310.PyMemoryView_FromObject - PyMemoryView_GetContiguous=python310.PyMemoryView_GetContiguous - PyMemoryView_Type=python310.PyMemoryView_Type DATA - PyMethodDescr_Type=python310.PyMethodDescr_Type DATA - PyModuleDef_Init=python310.PyModuleDef_Init - PyModuleDef_Type=python310.PyModuleDef_Type DATA - PyModule_AddFunctions=python310.PyModule_AddFunctions - PyModule_AddIntConstant=python310.PyModule_AddIntConstant - PyModule_AddObject=python310.PyModule_AddObject - PyModule_AddStringConstant=python310.PyModule_AddStringConstant - PyModule_Create2=python310.PyModule_Create2 - PyModule_ExecDef=python310.PyModule_ExecDef - PyModule_FromDefAndSpec2=python310.PyModule_FromDefAndSpec2 - PyModule_GetDef=python310.PyModule_GetDef - PyModule_GetDict=python310.PyModule_GetDict - PyModule_GetFilename=python310.PyModule_GetFilename - PyModule_GetFilenameObject=python310.PyModule_GetFilenameObject - PyModule_GetName=python310.PyModule_GetName - PyModule_GetNameObject=python310.PyModule_GetNameObject - PyModule_GetState=python310.PyModule_GetState - PyModule_New=python310.PyModule_New - PyModule_NewObject=python310.PyModule_NewObject - PyModule_SetDocString=python310.PyModule_SetDocString - PyModule_Type=python310.PyModule_Type DATA - PyNullImporter_Type=python310.PyNullImporter_Type DATA - PyNumber_Absolute=python310.PyNumber_Absolute - PyNumber_Add=python310.PyNumber_Add - PyNumber_And=python310.PyNumber_And - PyNumber_AsSsize_t=python310.PyNumber_AsSsize_t - PyNumber_Check=python310.PyNumber_Check - PyNumber_Divmod=python310.PyNumber_Divmod - PyNumber_Float=python310.PyNumber_Float - PyNumber_FloorDivide=python310.PyNumber_FloorDivide - PyNumber_InPlaceAdd=python310.PyNumber_InPlaceAdd - PyNumber_InPlaceAnd=python310.PyNumber_InPlaceAnd - PyNumber_InPlaceFloorDivide=python310.PyNumber_InPlaceFloorDivide - PyNumber_InPlaceLshift=python310.PyNumber_InPlaceLshift - PyNumber_InPlaceMatrixMultiply=python310.PyNumber_InPlaceMatrixMultiply - PyNumber_InPlaceMultiply=python310.PyNumber_InPlaceMultiply - PyNumber_InPlaceOr=python310.PyNumber_InPlaceOr - PyNumber_InPlacePower=python310.PyNumber_InPlacePower - PyNumber_InPlaceRemainder=python310.PyNumber_InPlaceRemainder - PyNumber_InPlaceRshift=python310.PyNumber_InPlaceRshift - PyNumber_InPlaceSubtract=python310.PyNumber_InPlaceSubtract - PyNumber_InPlaceTrueDivide=python310.PyNumber_InPlaceTrueDivide - PyNumber_InPlaceXor=python310.PyNumber_InPlaceXor - PyNumber_Index=python310.PyNumber_Index - PyNumber_Invert=python310.PyNumber_Invert - PyNumber_Long=python310.PyNumber_Long - PyNumber_Lshift=python310.PyNumber_Lshift - PyNumber_MatrixMultiply=python310.PyNumber_MatrixMultiply - PyNumber_Multiply=python310.PyNumber_Multiply - PyNumber_Negative=python310.PyNumber_Negative - PyNumber_Or=python310.PyNumber_Or - PyNumber_Positive=python310.PyNumber_Positive - PyNumber_Power=python310.PyNumber_Power - PyNumber_Remainder=python310.PyNumber_Remainder - PyNumber_Rshift=python310.PyNumber_Rshift - PyNumber_Subtract=python310.PyNumber_Subtract - PyNumber_ToBase=python310.PyNumber_ToBase - PyNumber_TrueDivide=python310.PyNumber_TrueDivide - PyNumber_Xor=python310.PyNumber_Xor - PyODictItems_Type=python310.PyODictItems_Type DATA - PyODictIter_Type=python310.PyODictIter_Type DATA - PyODictKeys_Type=python310.PyODictKeys_Type DATA - PyODictValues_Type=python310.PyODictValues_Type DATA - PyODict_DelItem=python310.PyODict_DelItem - PyODict_New=python310.PyODict_New - PyODict_SetItem=python310.PyODict_SetItem - PyODict_Type=python310.PyODict_Type DATA - PyOS_AfterFork=python310.PyOS_AfterFork - PyOS_CheckStack=python310.PyOS_CheckStack - PyOS_FSPath=python310.PyOS_FSPath - PyOS_InitInterrupts=python310.PyOS_InitInterrupts - PyOS_InputHook=python310.PyOS_InputHook DATA - PyOS_InterruptOccurred=python310.PyOS_InterruptOccurred - PyOS_ReadlineFunctionPointer=python310.PyOS_ReadlineFunctionPointer DATA - PyOS_double_to_string=python310.PyOS_double_to_string - PyOS_getsig=python310.PyOS_getsig - PyOS_mystricmp=python310.PyOS_mystricmp - PyOS_mystrnicmp=python310.PyOS_mystrnicmp - PyOS_setsig=python310.PyOS_setsig - PyOS_snprintf=python310.PyOS_snprintf - PyOS_string_to_double=python310.PyOS_string_to_double - PyOS_strtol=python310.PyOS_strtol - PyOS_strtoul=python310.PyOS_strtoul - PyOS_vsnprintf=python310.PyOS_vsnprintf - PyObject_ASCII=python310.PyObject_ASCII - PyObject_AsCharBuffer=python310.PyObject_AsCharBuffer - PyObject_AsFileDescriptor=python310.PyObject_AsFileDescriptor - PyObject_AsReadBuffer=python310.PyObject_AsReadBuffer - PyObject_AsWriteBuffer=python310.PyObject_AsWriteBuffer - PyObject_Bytes=python310.PyObject_Bytes - PyObject_Call=python310.PyObject_Call - PyObject_CallFunction=python310.PyObject_CallFunction - PyObject_CallFunctionObjArgs=python310.PyObject_CallFunctionObjArgs - PyObject_CallMethod=python310.PyObject_CallMethod - PyObject_CallMethodObjArgs=python310.PyObject_CallMethodObjArgs - PyObject_CallObject=python310.PyObject_CallObject - PyObject_Calloc=python310.PyObject_Calloc - PyObject_CheckReadBuffer=python310.PyObject_CheckReadBuffer - PyObject_ClearWeakRefs=python310.PyObject_ClearWeakRefs - PyObject_DelItem=python310.PyObject_DelItem - PyObject_DelItemString=python310.PyObject_DelItemString - PyObject_Dir=python310.PyObject_Dir - PyObject_Format=python310.PyObject_Format - PyObject_Free=python310.PyObject_Free - PyObject_GC_Del=python310.PyObject_GC_Del - PyObject_GC_Track=python310.PyObject_GC_Track - PyObject_GC_UnTrack=python310.PyObject_GC_UnTrack - PyObject_GenericGetAttr=python310.PyObject_GenericGetAttr - PyObject_GenericSetAttr=python310.PyObject_GenericSetAttr - PyObject_GenericSetDict=python310.PyObject_GenericSetDict - PyObject_GetAttr=python310.PyObject_GetAttr - PyObject_GetAttrString=python310.PyObject_GetAttrString - PyObject_GetItem=python310.PyObject_GetItem - PyObject_GetIter=python310.PyObject_GetIter - PyObject_HasAttr=python310.PyObject_HasAttr - PyObject_HasAttrString=python310.PyObject_HasAttrString - PyObject_Hash=python310.PyObject_Hash - PyObject_HashNotImplemented=python310.PyObject_HashNotImplemented - PyObject_Init=python310.PyObject_Init - PyObject_InitVar=python310.PyObject_InitVar - PyObject_IsInstance=python310.PyObject_IsInstance - PyObject_IsSubclass=python310.PyObject_IsSubclass - PyObject_IsTrue=python310.PyObject_IsTrue - PyObject_Length=python310.PyObject_Length - PyObject_Malloc=python310.PyObject_Malloc - PyObject_Not=python310.PyObject_Not - PyObject_Realloc=python310.PyObject_Realloc - PyObject_Repr=python310.PyObject_Repr - PyObject_RichCompare=python310.PyObject_RichCompare - PyObject_RichCompareBool=python310.PyObject_RichCompareBool - PyObject_SelfIter=python310.PyObject_SelfIter - PyObject_SetAttr=python310.PyObject_SetAttr - PyObject_SetAttrString=python310.PyObject_SetAttrString - PyObject_SetItem=python310.PyObject_SetItem - PyObject_Size=python310.PyObject_Size - PyObject_Str=python310.PyObject_Str - PyObject_Type=python310.PyObject_Type - PyParser_SimpleParseFileFlags=python310.PyParser_SimpleParseFileFlags - PyParser_SimpleParseStringFlags=python310.PyParser_SimpleParseStringFlags - PyParser_SimpleParseStringFlagsFilename=python310.PyParser_SimpleParseStringFlagsFilename - PyProperty_Type=python310.PyProperty_Type DATA - PyRangeIter_Type=python310.PyRangeIter_Type DATA - PyRange_Type=python310.PyRange_Type DATA - PyReversed_Type=python310.PyReversed_Type DATA - PySeqIter_New=python310.PySeqIter_New - PySeqIter_Type=python310.PySeqIter_Type DATA - PySequence_Check=python310.PySequence_Check - PySequence_Concat=python310.PySequence_Concat - PySequence_Contains=python310.PySequence_Contains - PySequence_Count=python310.PySequence_Count - PySequence_DelItem=python310.PySequence_DelItem - PySequence_DelSlice=python310.PySequence_DelSlice - PySequence_Fast=python310.PySequence_Fast - PySequence_GetItem=python310.PySequence_GetItem - PySequence_GetSlice=python310.PySequence_GetSlice - PySequence_In=python310.PySequence_In - PySequence_InPlaceConcat=python310.PySequence_InPlaceConcat - PySequence_InPlaceRepeat=python310.PySequence_InPlaceRepeat - PySequence_Index=python310.PySequence_Index - PySequence_Length=python310.PySequence_Length - PySequence_List=python310.PySequence_List - PySequence_Repeat=python310.PySequence_Repeat - PySequence_SetItem=python310.PySequence_SetItem - PySequence_SetSlice=python310.PySequence_SetSlice - PySequence_Size=python310.PySequence_Size - PySequence_Tuple=python310.PySequence_Tuple - PySetIter_Type=python310.PySetIter_Type DATA - PySet_Add=python310.PySet_Add - PySet_Clear=python310.PySet_Clear - PySet_Contains=python310.PySet_Contains - PySet_Discard=python310.PySet_Discard - PySet_New=python310.PySet_New - PySet_Pop=python310.PySet_Pop - PySet_Size=python310.PySet_Size - PySet_Type=python310.PySet_Type DATA - PySlice_AdjustIndices=python310.PySlice_AdjustIndices - PySlice_GetIndices=python310.PySlice_GetIndices - PySlice_GetIndicesEx=python310.PySlice_GetIndicesEx - PySlice_New=python310.PySlice_New - PySlice_Type=python310.PySlice_Type DATA - PySlice_Unpack=python310.PySlice_Unpack - PySortWrapper_Type=python310.PySortWrapper_Type DATA - PyInterpreterState_GetID=python310.PyInterpreterState_GetID - PyState_AddModule=python310.PyState_AddModule - PyState_FindModule=python310.PyState_FindModule - PyState_RemoveModule=python310.PyState_RemoveModule - PyStructSequence_GetItem=python310.PyStructSequence_GetItem - PyStructSequence_New=python310.PyStructSequence_New - PyStructSequence_NewType=python310.PyStructSequence_NewType - PyStructSequence_SetItem=python310.PyStructSequence_SetItem - PySuper_Type=python310.PySuper_Type DATA - PySys_AddWarnOption=python310.PySys_AddWarnOption - PySys_AddWarnOptionUnicode=python310.PySys_AddWarnOptionUnicode - PySys_AddXOption=python310.PySys_AddXOption - PySys_FormatStderr=python310.PySys_FormatStderr - PySys_FormatStdout=python310.PySys_FormatStdout - PySys_GetObject=python310.PySys_GetObject - PySys_GetXOptions=python310.PySys_GetXOptions - PySys_HasWarnOptions=python310.PySys_HasWarnOptions - PySys_ResetWarnOptions=python310.PySys_ResetWarnOptions - PySys_SetArgv=python310.PySys_SetArgv - PySys_SetArgvEx=python310.PySys_SetArgvEx - PySys_SetObject=python310.PySys_SetObject - PySys_SetPath=python310.PySys_SetPath - PySys_WriteStderr=python310.PySys_WriteStderr - PySys_WriteStdout=python310.PySys_WriteStdout - PyThreadState_Clear=python310.PyThreadState_Clear - PyThreadState_Delete=python310.PyThreadState_Delete - PyThreadState_DeleteCurrent=python310.PyThreadState_DeleteCurrent - PyThreadState_Get=python310.PyThreadState_Get - PyThreadState_GetDict=python310.PyThreadState_GetDict - PyThreadState_New=python310.PyThreadState_New - PyThreadState_SetAsyncExc=python310.PyThreadState_SetAsyncExc - PyThreadState_Swap=python310.PyThreadState_Swap - PyThread_tss_alloc=python310.PyThread_tss_alloc - PyThread_tss_create=python310.PyThread_tss_create - PyThread_tss_delete=python310.PyThread_tss_delete - PyThread_tss_free=python310.PyThread_tss_free - PyThread_tss_get=python310.PyThread_tss_get - PyThread_tss_is_created=python310.PyThread_tss_is_created - PyThread_tss_set=python310.PyThread_tss_set - PyTraceBack_Here=python310.PyTraceBack_Here - PyTraceBack_Print=python310.PyTraceBack_Print - PyTraceBack_Type=python310.PyTraceBack_Type DATA - PyTupleIter_Type=python310.PyTupleIter_Type DATA - PyTuple_GetItem=python310.PyTuple_GetItem - PyTuple_GetSlice=python310.PyTuple_GetSlice - PyTuple_New=python310.PyTuple_New - PyTuple_Pack=python310.PyTuple_Pack - PyTuple_SetItem=python310.PyTuple_SetItem - PyTuple_Size=python310.PyTuple_Size - PyTuple_Type=python310.PyTuple_Type DATA - PyType_ClearCache=python310.PyType_ClearCache - PyType_FromSpec=python310.PyType_FromSpec - PyType_FromSpecWithBases=python310.PyType_FromSpecWithBases - PyType_GenericAlloc=python310.PyType_GenericAlloc - PyType_GenericNew=python310.PyType_GenericNew - PyType_GetFlags=python310.PyType_GetFlags - PyType_GetSlot=python310.PyType_GetSlot - PyType_IsSubtype=python310.PyType_IsSubtype - PyType_Modified=python310.PyType_Modified - PyType_Ready=python310.PyType_Ready - PyType_Type=python310.PyType_Type DATA - PyUnicodeDecodeError_Create=python310.PyUnicodeDecodeError_Create - PyUnicodeDecodeError_GetEncoding=python310.PyUnicodeDecodeError_GetEncoding - PyUnicodeDecodeError_GetEnd=python310.PyUnicodeDecodeError_GetEnd - PyUnicodeDecodeError_GetObject=python310.PyUnicodeDecodeError_GetObject - PyUnicodeDecodeError_GetReason=python310.PyUnicodeDecodeError_GetReason - PyUnicodeDecodeError_GetStart=python310.PyUnicodeDecodeError_GetStart - PyUnicodeDecodeError_SetEnd=python310.PyUnicodeDecodeError_SetEnd - PyUnicodeDecodeError_SetReason=python310.PyUnicodeDecodeError_SetReason - PyUnicodeDecodeError_SetStart=python310.PyUnicodeDecodeError_SetStart - PyUnicodeEncodeError_GetEncoding=python310.PyUnicodeEncodeError_GetEncoding - PyUnicodeEncodeError_GetEnd=python310.PyUnicodeEncodeError_GetEnd - PyUnicodeEncodeError_GetObject=python310.PyUnicodeEncodeError_GetObject - PyUnicodeEncodeError_GetReason=python310.PyUnicodeEncodeError_GetReason - PyUnicodeEncodeError_GetStart=python310.PyUnicodeEncodeError_GetStart - PyUnicodeEncodeError_SetEnd=python310.PyUnicodeEncodeError_SetEnd - PyUnicodeEncodeError_SetReason=python310.PyUnicodeEncodeError_SetReason - PyUnicodeEncodeError_SetStart=python310.PyUnicodeEncodeError_SetStart - PyUnicodeIter_Type=python310.PyUnicodeIter_Type DATA - PyUnicodeTranslateError_GetEnd=python310.PyUnicodeTranslateError_GetEnd - PyUnicodeTranslateError_GetObject=python310.PyUnicodeTranslateError_GetObject - PyUnicodeTranslateError_GetReason=python310.PyUnicodeTranslateError_GetReason - PyUnicodeTranslateError_GetStart=python310.PyUnicodeTranslateError_GetStart - PyUnicodeTranslateError_SetEnd=python310.PyUnicodeTranslateError_SetEnd - PyUnicodeTranslateError_SetReason=python310.PyUnicodeTranslateError_SetReason - PyUnicodeTranslateError_SetStart=python310.PyUnicodeTranslateError_SetStart - PyUnicode_Append=python310.PyUnicode_Append - PyUnicode_AppendAndDel=python310.PyUnicode_AppendAndDel - PyUnicode_AsASCIIString=python310.PyUnicode_AsASCIIString - PyUnicode_AsCharmapString=python310.PyUnicode_AsCharmapString - PyUnicode_AsDecodedObject=python310.PyUnicode_AsDecodedObject - PyUnicode_AsDecodedUnicode=python310.PyUnicode_AsDecodedUnicode - PyUnicode_AsEncodedObject=python310.PyUnicode_AsEncodedObject - PyUnicode_AsEncodedString=python310.PyUnicode_AsEncodedString - PyUnicode_AsEncodedUnicode=python310.PyUnicode_AsEncodedUnicode - PyUnicode_AsLatin1String=python310.PyUnicode_AsLatin1String - PyUnicode_AsMBCSString=python310.PyUnicode_AsMBCSString - PyUnicode_AsRawUnicodeEscapeString=python310.PyUnicode_AsRawUnicodeEscapeString - PyUnicode_AsUCS4=python310.PyUnicode_AsUCS4 - PyUnicode_AsUCS4Copy=python310.PyUnicode_AsUCS4Copy - PyUnicode_AsUTF16String=python310.PyUnicode_AsUTF16String - PyUnicode_AsUTF32String=python310.PyUnicode_AsUTF32String - PyUnicode_AsUTF8String=python310.PyUnicode_AsUTF8String - PyUnicode_AsUnicodeEscapeString=python310.PyUnicode_AsUnicodeEscapeString - PyUnicode_AsWideChar=python310.PyUnicode_AsWideChar - PyUnicode_AsWideCharString=python310.PyUnicode_AsWideCharString - PyUnicode_BuildEncodingMap=python310.PyUnicode_BuildEncodingMap - PyUnicode_Compare=python310.PyUnicode_Compare - PyUnicode_CompareWithASCIIString=python310.PyUnicode_CompareWithASCIIString - PyUnicode_Concat=python310.PyUnicode_Concat - PyUnicode_Contains=python310.PyUnicode_Contains - PyUnicode_Count=python310.PyUnicode_Count - PyUnicode_Decode=python310.PyUnicode_Decode - PyUnicode_DecodeASCII=python310.PyUnicode_DecodeASCII - PyUnicode_DecodeCharmap=python310.PyUnicode_DecodeCharmap - PyUnicode_DecodeCodePageStateful=python310.PyUnicode_DecodeCodePageStateful - PyUnicode_DecodeFSDefault=python310.PyUnicode_DecodeFSDefault - PyUnicode_DecodeFSDefaultAndSize=python310.PyUnicode_DecodeFSDefaultAndSize - PyUnicode_DecodeLatin1=python310.PyUnicode_DecodeLatin1 - PyUnicode_DecodeLocale=python310.PyUnicode_DecodeLocale - PyUnicode_DecodeLocaleAndSize=python310.PyUnicode_DecodeLocaleAndSize - PyUnicode_DecodeMBCS=python310.PyUnicode_DecodeMBCS - PyUnicode_DecodeMBCSStateful=python310.PyUnicode_DecodeMBCSStateful - PyUnicode_DecodeRawUnicodeEscape=python310.PyUnicode_DecodeRawUnicodeEscape - PyUnicode_DecodeUTF16=python310.PyUnicode_DecodeUTF16 - PyUnicode_DecodeUTF16Stateful=python310.PyUnicode_DecodeUTF16Stateful - PyUnicode_DecodeUTF32=python310.PyUnicode_DecodeUTF32 - PyUnicode_DecodeUTF32Stateful=python310.PyUnicode_DecodeUTF32Stateful - PyUnicode_DecodeUTF7=python310.PyUnicode_DecodeUTF7 - PyUnicode_DecodeUTF7Stateful=python310.PyUnicode_DecodeUTF7Stateful - PyUnicode_DecodeUTF8=python310.PyUnicode_DecodeUTF8 - PyUnicode_DecodeUTF8Stateful=python310.PyUnicode_DecodeUTF8Stateful - PyUnicode_DecodeUnicodeEscape=python310.PyUnicode_DecodeUnicodeEscape - PyUnicode_EncodeCodePage=python310.PyUnicode_EncodeCodePage - PyUnicode_EncodeFSDefault=python310.PyUnicode_EncodeFSDefault - PyUnicode_EncodeLocale=python310.PyUnicode_EncodeLocale - PyUnicode_FSConverter=python310.PyUnicode_FSConverter - PyUnicode_FSDecoder=python310.PyUnicode_FSDecoder - PyUnicode_Find=python310.PyUnicode_Find - PyUnicode_FindChar=python310.PyUnicode_FindChar - PyUnicode_Format=python310.PyUnicode_Format - PyUnicode_FromEncodedObject=python310.PyUnicode_FromEncodedObject - PyUnicode_FromFormat=python310.PyUnicode_FromFormat - PyUnicode_FromFormatV=python310.PyUnicode_FromFormatV - PyUnicode_FromObject=python310.PyUnicode_FromObject - PyUnicode_FromOrdinal=python310.PyUnicode_FromOrdinal - PyUnicode_FromString=python310.PyUnicode_FromString - PyUnicode_FromStringAndSize=python310.PyUnicode_FromStringAndSize - PyUnicode_FromWideChar=python310.PyUnicode_FromWideChar - PyUnicode_GetDefaultEncoding=python310.PyUnicode_GetDefaultEncoding - PyUnicode_GetLength=python310.PyUnicode_GetLength - PyUnicode_GetSize=python310.PyUnicode_GetSize - PyUnicode_InternFromString=python310.PyUnicode_InternFromString - PyUnicode_InternImmortal=python310.PyUnicode_InternImmortal - PyUnicode_InternInPlace=python310.PyUnicode_InternInPlace - PyUnicode_IsIdentifier=python310.PyUnicode_IsIdentifier - PyUnicode_Join=python310.PyUnicode_Join - PyUnicode_Partition=python310.PyUnicode_Partition - PyUnicode_RPartition=python310.PyUnicode_RPartition - PyUnicode_RSplit=python310.PyUnicode_RSplit - PyUnicode_ReadChar=python310.PyUnicode_ReadChar - PyUnicode_Replace=python310.PyUnicode_Replace - PyUnicode_Resize=python310.PyUnicode_Resize - PyUnicode_RichCompare=python310.PyUnicode_RichCompare - PyUnicode_Split=python310.PyUnicode_Split - PyUnicode_Splitlines=python310.PyUnicode_Splitlines - PyUnicode_Substring=python310.PyUnicode_Substring - PyUnicode_Tailmatch=python310.PyUnicode_Tailmatch - PyUnicode_Translate=python310.PyUnicode_Translate - PyUnicode_Type=python310.PyUnicode_Type DATA - PyUnicode_WriteChar=python310.PyUnicode_WriteChar - PyWeakref_GetObject=python310.PyWeakref_GetObject - PyWeakref_NewProxy=python310.PyWeakref_NewProxy - PyWeakref_NewRef=python310.PyWeakref_NewRef - PyWrapperDescr_Type=python310.PyWrapperDescr_Type DATA - PyWrapper_New=python310.PyWrapper_New - PyZip_Type=python310.PyZip_Type DATA - Py_AddPendingCall=python310.Py_AddPendingCall - Py_AtExit=python310.Py_AtExit - Py_BuildValue=python310.Py_BuildValue - Py_CompileString=python310.Py_CompileString - Py_DecRef=python310.Py_DecRef - Py_DecodeLocale=python310.Py_DecodeLocale - Py_EncodeLocale=python310.Py_EncodeLocale - Py_EndInterpreter=python310.Py_EndInterpreter - Py_EnterRecursiveCall=python310.Py_EnterRecursiveCall - Py_Exit=python310.Py_Exit - Py_FatalError=python310.Py_FatalError - Py_FileSystemDefaultEncodeErrors=python310.Py_FileSystemDefaultEncodeErrors DATA - Py_FileSystemDefaultEncoding=python310.Py_FileSystemDefaultEncoding DATA - Py_Finalize=python310.Py_Finalize - Py_FinalizeEx=python310.Py_FinalizeEx - Py_GenericAlias=python310.Py_GenericAlias - Py_GenericAliasType=python310.Py_GenericAliasType - Py_GetBuildInfo=python310.Py_GetBuildInfo - Py_GetCompiler=python310.Py_GetCompiler - Py_GetCopyright=python310.Py_GetCopyright - Py_GetExecPrefix=python310.Py_GetExecPrefix - Py_GetPath=python310.Py_GetPath - Py_GetPlatform=python310.Py_GetPlatform - Py_GetPrefix=python310.Py_GetPrefix - Py_GetProgramFullPath=python310.Py_GetProgramFullPath - Py_GetProgramName=python310.Py_GetProgramName - Py_GetPythonHome=python310.Py_GetPythonHome - Py_GetRecursionLimit=python310.Py_GetRecursionLimit - Py_GetVersion=python310.Py_GetVersion - Py_HasFileSystemDefaultEncoding=python310.Py_HasFileSystemDefaultEncoding DATA - Py_IncRef=python310.Py_IncRef - Py_Initialize=python310.Py_Initialize - Py_InitializeEx=python310.Py_InitializeEx - Py_IsInitialized=python310.Py_IsInitialized - Py_LeaveRecursiveCall=python310.Py_LeaveRecursiveCall - Py_Main=python310.Py_Main - Py_MakePendingCalls=python310.Py_MakePendingCalls - Py_NewInterpreter=python310.Py_NewInterpreter - Py_ReprEnter=python310.Py_ReprEnter - Py_ReprLeave=python310.Py_ReprLeave - Py_SetPath=python310.Py_SetPath - Py_SetProgramName=python310.Py_SetProgramName - Py_SetPythonHome=python310.Py_SetPythonHome - Py_SetRecursionLimit=python310.Py_SetRecursionLimit - Py_SymtableString=python310.Py_SymtableString - Py_UTF8Mode=python310.Py_UTF8Mode DATA - Py_VaBuildValue=python310.Py_VaBuildValue - _PyArg_ParseTupleAndKeywords_SizeT=python310._PyArg_ParseTupleAndKeywords_SizeT - _PyArg_ParseTuple_SizeT=python310._PyArg_ParseTuple_SizeT - _PyArg_Parse_SizeT=python310._PyArg_Parse_SizeT - _PyArg_VaParseTupleAndKeywords_SizeT=python310._PyArg_VaParseTupleAndKeywords_SizeT - _PyArg_VaParse_SizeT=python310._PyArg_VaParse_SizeT - _PyErr_BadInternalCall=python310._PyErr_BadInternalCall - _PyObject_CallFunction_SizeT=python310._PyObject_CallFunction_SizeT - _PyObject_CallMethod_SizeT=python310._PyObject_CallMethod_SizeT - _PyObject_GC_Malloc=python310._PyObject_GC_Malloc - _PyObject_GC_New=python310._PyObject_GC_New - _PyObject_GC_NewVar=python310._PyObject_GC_NewVar - _PyObject_GC_Resize=python310._PyObject_GC_Resize - _PyObject_New=python310._PyObject_New - _PyObject_NewVar=python310._PyObject_NewVar - _PyState_AddModule=python310._PyState_AddModule - _PyThreadState_Init=python310._PyThreadState_Init - _PyThreadState_Prealloc=python310._PyThreadState_Prealloc - _PyTrash_delete_later=python310._PyTrash_delete_later DATA - _PyTrash_delete_nesting=python310._PyTrash_delete_nesting DATA - _PyTrash_deposit_object=python310._PyTrash_deposit_object - _PyTrash_destroy_chain=python310._PyTrash_destroy_chain - _PyTrash_thread_deposit_object=python310._PyTrash_thread_deposit_object - _PyTrash_thread_destroy_chain=python310._PyTrash_thread_destroy_chain - _PyWeakref_CallableProxyType=python310._PyWeakref_CallableProxyType DATA - _PyWeakref_ProxyType=python310._PyWeakref_ProxyType DATA - _PyWeakref_RefType=python310._PyWeakref_RefType DATA - _Py_BuildValue_SizeT=python310._Py_BuildValue_SizeT - _Py_CheckRecursionLimit=python310._Py_CheckRecursionLimit DATA - _Py_CheckRecursiveCall=python310._Py_CheckRecursiveCall - _Py_Dealloc=python310._Py_Dealloc - _Py_EllipsisObject=python310._Py_EllipsisObject DATA - _Py_FalseStruct=python310._Py_FalseStruct DATA - _Py_NoneStruct=python310._Py_NoneStruct DATA - _Py_NotImplementedStruct=python310._Py_NotImplementedStruct DATA - _Py_SwappedOp=python310._Py_SwappedOp DATA - _Py_TrueStruct=python310._Py_TrueStruct DATA - _Py_VaBuildValue_SizeT=python310._Py_VaBuildValue_SizeT diff --git a/PC/python3dll.c b/PC/python3dll.c index ef290711256..f72f2c8af19 100644 --- a/PC/python3dll.c +++ b/PC/python3dll.c @@ -1,9 +1,810 @@ -#include +/* Re-export stable Python API */ -BOOL WINAPI -DllMain(HINSTANCE hInstDLL, - DWORD fdwReason, - LPVOID lpReserved) -{ - return TRUE; -} \ No newline at end of file +#ifdef _M_IX86 +#define DECORATE "_" +#else +#define DECORATE +#endif + +#define EXPORT_FUNC(name) \ + __pragma(comment(linker, "/EXPORT:" DECORATE #name "=" PYTHON_DLL_NAME "." #name)) +#define EXPORT_DATA(name) \ + __pragma(comment(linker, "/EXPORT:" DECORATE #name "=" PYTHON_DLL_NAME "." #name ",DATA")) + +EXPORT_FUNC(_Py_BuildValue_SizeT) +EXPORT_FUNC(_Py_CheckRecursiveCall) +EXPORT_FUNC(_Py_Dealloc) +EXPORT_FUNC(_Py_VaBuildValue_SizeT) +EXPORT_FUNC(_PyArg_Parse_SizeT) +EXPORT_FUNC(_PyArg_ParseTuple_SizeT) +EXPORT_FUNC(_PyArg_ParseTupleAndKeywords_SizeT) +EXPORT_FUNC(_PyArg_VaParse_SizeT) +EXPORT_FUNC(_PyArg_VaParseTupleAndKeywords_SizeT) +EXPORT_FUNC(_PyErr_BadInternalCall) +EXPORT_FUNC(_PyObject_CallFunction_SizeT) +EXPORT_FUNC(_PyObject_CallMethod_SizeT) +EXPORT_FUNC(_PyObject_GC_Malloc) +EXPORT_FUNC(_PyObject_GC_New) +EXPORT_FUNC(_PyObject_GC_NewVar) +EXPORT_FUNC(_PyObject_GC_Resize) +EXPORT_FUNC(_PyObject_New) +EXPORT_FUNC(_PyObject_NewVar) +EXPORT_FUNC(_PyState_AddModule) +EXPORT_FUNC(_PyThreadState_Init) +EXPORT_FUNC(_PyThreadState_Prealloc) +EXPORT_FUNC(_PyTrash_deposit_object) +EXPORT_FUNC(_PyTrash_destroy_chain) +EXPORT_FUNC(_PyTrash_thread_deposit_object) +EXPORT_FUNC(_PyTrash_thread_destroy_chain) +EXPORT_FUNC(Py_AddPendingCall) +EXPORT_FUNC(Py_AtExit) +EXPORT_FUNC(Py_BuildValue) +EXPORT_FUNC(Py_CompileString) +EXPORT_FUNC(Py_DecodeLocale) +EXPORT_FUNC(Py_DecRef) +EXPORT_FUNC(Py_EncodeLocale) +EXPORT_FUNC(Py_EndInterpreter) +EXPORT_FUNC(Py_EnterRecursiveCall) +EXPORT_FUNC(Py_Exit) +EXPORT_FUNC(Py_FatalError) +EXPORT_FUNC(Py_Finalize) +EXPORT_FUNC(Py_FinalizeEx) +EXPORT_FUNC(Py_GenericAlias) +EXPORT_FUNC(Py_GenericAliasType) +EXPORT_FUNC(Py_GetArgcArgv) +EXPORT_FUNC(Py_GetBuildInfo) +EXPORT_FUNC(Py_GetCompiler) +EXPORT_FUNC(Py_GetCopyright) +EXPORT_FUNC(Py_GetExecPrefix) +EXPORT_FUNC(Py_GetPath) +EXPORT_FUNC(Py_GetPlatform) +EXPORT_FUNC(Py_GetPrefix) +EXPORT_FUNC(Py_GetProgramFullPath) +EXPORT_FUNC(Py_GetProgramName) +EXPORT_FUNC(Py_GetPythonHome) +EXPORT_FUNC(Py_GetRecursionLimit) +EXPORT_FUNC(Py_GetVersion) +EXPORT_FUNC(Py_IncRef) +EXPORT_FUNC(Py_Initialize) +EXPORT_FUNC(Py_InitializeEx) +EXPORT_FUNC(Py_IsInitialized) +EXPORT_FUNC(Py_LeaveRecursiveCall) +EXPORT_FUNC(Py_Main) +EXPORT_FUNC(Py_MakePendingCalls) +EXPORT_FUNC(Py_NewInterpreter) +EXPORT_FUNC(Py_ReprEnter) +EXPORT_FUNC(Py_ReprLeave) +EXPORT_FUNC(Py_SetPath) +EXPORT_FUNC(Py_SetProgramName) +EXPORT_FUNC(Py_SetPythonHome) +EXPORT_FUNC(Py_SetRecursionLimit) +EXPORT_FUNC(Py_SymtableString) +EXPORT_FUNC(Py_VaBuildValue) +EXPORT_FUNC(PyArg_Parse) +EXPORT_FUNC(PyArg_ParseTuple) +EXPORT_FUNC(PyArg_ParseTupleAndKeywords) +EXPORT_FUNC(PyArg_UnpackTuple) +EXPORT_FUNC(PyArg_ValidateKeywordArguments) +EXPORT_FUNC(PyArg_VaParse) +EXPORT_FUNC(PyArg_VaParseTupleAndKeywords) +EXPORT_FUNC(PyBool_FromLong) +EXPORT_FUNC(PyByteArray_AsString) +EXPORT_FUNC(PyByteArray_Concat) +EXPORT_FUNC(PyByteArray_FromObject) +EXPORT_FUNC(PyByteArray_FromStringAndSize) +EXPORT_FUNC(PyByteArray_Resize) +EXPORT_FUNC(PyByteArray_Size) +EXPORT_FUNC(PyBytes_AsString) +EXPORT_FUNC(PyBytes_AsStringAndSize) +EXPORT_FUNC(PyBytes_Concat) +EXPORT_FUNC(PyBytes_ConcatAndDel) +EXPORT_FUNC(PyBytes_DecodeEscape) +EXPORT_FUNC(PyBytes_FromFormat) +EXPORT_FUNC(PyBytes_FromFormatV) +EXPORT_FUNC(PyBytes_FromObject) +EXPORT_FUNC(PyBytes_FromString) +EXPORT_FUNC(PyBytes_FromStringAndSize) +EXPORT_FUNC(PyBytes_Repr) +EXPORT_FUNC(PyBytes_Size) +EXPORT_FUNC(PyCallable_Check) +EXPORT_FUNC(PyCallIter_New) +EXPORT_FUNC(PyCapsule_GetContext) +EXPORT_FUNC(PyCapsule_GetDestructor) +EXPORT_FUNC(PyCapsule_GetName) +EXPORT_FUNC(PyCapsule_GetPointer) +EXPORT_FUNC(PyCapsule_Import) +EXPORT_FUNC(PyCapsule_IsValid) +EXPORT_FUNC(PyCapsule_New) +EXPORT_FUNC(PyCapsule_SetContext) +EXPORT_FUNC(PyCapsule_SetDestructor) +EXPORT_FUNC(PyCapsule_SetName) +EXPORT_FUNC(PyCapsule_SetPointer) +EXPORT_FUNC(PyCFunction_Call) +EXPORT_FUNC(PyCFunction_GetFlags) +EXPORT_FUNC(PyCFunction_GetFunction) +EXPORT_FUNC(PyCFunction_GetSelf) +EXPORT_FUNC(PyCFunction_New) +EXPORT_FUNC(PyCFunction_NewEx) +EXPORT_FUNC(PyCodec_BackslashReplaceErrors) +EXPORT_FUNC(PyCodec_Decode) +EXPORT_FUNC(PyCodec_Decoder) +EXPORT_FUNC(PyCodec_Encode) +EXPORT_FUNC(PyCodec_Encoder) +EXPORT_FUNC(PyCodec_IgnoreErrors) +EXPORT_FUNC(PyCodec_IncrementalDecoder) +EXPORT_FUNC(PyCodec_IncrementalEncoder) +EXPORT_FUNC(PyCodec_KnownEncoding) +EXPORT_FUNC(PyCodec_LookupError) +EXPORT_FUNC(PyCodec_NameReplaceErrors) +EXPORT_FUNC(PyCodec_Register) +EXPORT_FUNC(PyCodec_RegisterError) +EXPORT_FUNC(PyCodec_ReplaceErrors) +EXPORT_FUNC(PyCodec_StreamReader) +EXPORT_FUNC(PyCodec_StreamWriter) +EXPORT_FUNC(PyCodec_StrictErrors) +EXPORT_FUNC(PyCodec_XMLCharRefReplaceErrors) +EXPORT_FUNC(PyComplex_FromDoubles) +EXPORT_FUNC(PyComplex_ImagAsDouble) +EXPORT_FUNC(PyComplex_RealAsDouble) +EXPORT_FUNC(PyDescr_NewClassMethod) +EXPORT_FUNC(PyDescr_NewGetSet) +EXPORT_FUNC(PyDescr_NewMember) +EXPORT_FUNC(PyDescr_NewMethod) +EXPORT_FUNC(PyDict_Clear) +EXPORT_FUNC(PyDict_Contains) +EXPORT_FUNC(PyDict_Copy) +EXPORT_FUNC(PyDict_DelItem) +EXPORT_FUNC(PyDict_DelItemString) +EXPORT_FUNC(PyDict_GetItem) +EXPORT_FUNC(PyDict_GetItemString) +EXPORT_FUNC(PyDict_GetItemWithError) +EXPORT_FUNC(PyDict_Items) +EXPORT_FUNC(PyDict_Keys) +EXPORT_FUNC(PyDict_Merge) +EXPORT_FUNC(PyDict_MergeFromSeq2) +EXPORT_FUNC(PyDict_New) +EXPORT_FUNC(PyDict_Next) +EXPORT_FUNC(PyDict_SetItem) +EXPORT_FUNC(PyDict_SetItemString) +EXPORT_FUNC(PyDict_Size) +EXPORT_FUNC(PyDict_Update) +EXPORT_FUNC(PyDict_Values) +EXPORT_FUNC(PyDictProxy_New) +EXPORT_FUNC(PyErr_BadArgument) +EXPORT_FUNC(PyErr_BadInternalCall) +EXPORT_FUNC(PyErr_CheckSignals) +EXPORT_FUNC(PyErr_Clear) +EXPORT_FUNC(PyErr_Display) +EXPORT_FUNC(PyErr_ExceptionMatches) +EXPORT_FUNC(PyErr_Fetch) +EXPORT_FUNC(PyErr_Format) +EXPORT_FUNC(PyErr_FormatV) +EXPORT_FUNC(PyErr_GetExcInfo) +EXPORT_FUNC(PyErr_GivenExceptionMatches) +EXPORT_FUNC(PyErr_NewException) +EXPORT_FUNC(PyErr_NewExceptionWithDoc) +EXPORT_FUNC(PyErr_NoMemory) +EXPORT_FUNC(PyErr_NormalizeException) +EXPORT_FUNC(PyErr_Occurred) +EXPORT_FUNC(PyErr_Print) +EXPORT_FUNC(PyErr_PrintEx) +EXPORT_FUNC(PyErr_ProgramText) +EXPORT_FUNC(PyErr_ResourceWarning) +EXPORT_FUNC(PyErr_Restore) +EXPORT_FUNC(PyErr_SetExcFromWindowsErr) +EXPORT_FUNC(PyErr_SetExcFromWindowsErrWithFilename) +EXPORT_FUNC(PyErr_SetExcFromWindowsErrWithFilenameObject) +EXPORT_FUNC(PyErr_SetExcFromWindowsErrWithFilenameObjects) +EXPORT_FUNC(PyErr_SetExcInfo) +EXPORT_FUNC(PyErr_SetFromErrno) +EXPORT_FUNC(PyErr_SetFromErrnoWithFilename) +EXPORT_FUNC(PyErr_SetFromErrnoWithFilenameObject) +EXPORT_FUNC(PyErr_SetFromErrnoWithFilenameObjects) +EXPORT_FUNC(PyErr_SetFromWindowsErr) +EXPORT_FUNC(PyErr_SetFromWindowsErrWithFilename) +EXPORT_FUNC(PyErr_SetImportError) +EXPORT_FUNC(PyErr_SetImportErrorSubclass) +EXPORT_FUNC(PyErr_SetInterrupt) +EXPORT_FUNC(PyErr_SetNone) +EXPORT_FUNC(PyErr_SetObject) +EXPORT_FUNC(PyErr_SetString) +EXPORT_FUNC(PyErr_SyntaxLocation) +EXPORT_FUNC(PyErr_SyntaxLocationEx) +EXPORT_FUNC(PyErr_WarnEx) +EXPORT_FUNC(PyErr_WarnExplicit) +EXPORT_FUNC(PyErr_WarnFormat) +EXPORT_FUNC(PyErr_WriteUnraisable) +EXPORT_FUNC(PyEval_AcquireLock) +EXPORT_FUNC(PyEval_AcquireThread) +EXPORT_FUNC(PyEval_CallFunction) +EXPORT_FUNC(PyEval_CallMethod) +EXPORT_FUNC(PyEval_CallObjectWithKeywords) +EXPORT_FUNC(PyEval_EvalCode) +EXPORT_FUNC(PyEval_EvalCodeEx) +EXPORT_FUNC(PyEval_EvalFrame) +EXPORT_FUNC(PyEval_EvalFrameEx) +EXPORT_FUNC(PyEval_GetBuiltins) +EXPORT_FUNC(PyEval_GetCallStats) +EXPORT_FUNC(PyEval_GetFrame) +EXPORT_FUNC(PyEval_GetFuncDesc) +EXPORT_FUNC(PyEval_GetFuncName) +EXPORT_FUNC(PyEval_GetGlobals) +EXPORT_FUNC(PyEval_GetLocals) +EXPORT_FUNC(PyEval_InitThreads) +EXPORT_FUNC(PyEval_ReInitThreads) +EXPORT_FUNC(PyEval_ReleaseLock) +EXPORT_FUNC(PyEval_ReleaseThread) +EXPORT_FUNC(PyEval_RestoreThread) +EXPORT_FUNC(PyEval_SaveThread) +EXPORT_FUNC(PyEval_ThreadsInitialized) +EXPORT_FUNC(PyException_GetCause) +EXPORT_FUNC(PyException_GetContext) +EXPORT_FUNC(PyException_GetTraceback) +EXPORT_FUNC(PyException_SetCause) +EXPORT_FUNC(PyException_SetContext) +EXPORT_FUNC(PyException_SetTraceback) +EXPORT_FUNC(PyExceptionClass_Name) +EXPORT_FUNC(PyFile_FromFd) +EXPORT_FUNC(PyFile_GetLine) +EXPORT_FUNC(PyFile_WriteObject) +EXPORT_FUNC(PyFile_WriteString) +EXPORT_FUNC(PyFloat_AsDouble) +EXPORT_FUNC(PyFloat_FromDouble) +EXPORT_FUNC(PyFloat_FromString) +EXPORT_FUNC(PyFloat_GetInfo) +EXPORT_FUNC(PyFloat_GetMax) +EXPORT_FUNC(PyFloat_GetMin) +EXPORT_FUNC(PyFrozenSet_New) +EXPORT_FUNC(PyGC_Collect) +EXPORT_FUNC(PyGILState_Ensure) +EXPORT_FUNC(PyGILState_GetThisThreadState) +EXPORT_FUNC(PyGILState_Release) +EXPORT_FUNC(PyImport_AddModule) +EXPORT_FUNC(PyImport_AddModuleObject) +EXPORT_FUNC(PyImport_AppendInittab) +EXPORT_FUNC(PyImport_Cleanup) +EXPORT_FUNC(PyImport_ExecCodeModule) +EXPORT_FUNC(PyImport_ExecCodeModuleEx) +EXPORT_FUNC(PyImport_ExecCodeModuleObject) +EXPORT_FUNC(PyImport_ExecCodeModuleWithPathnames) +EXPORT_FUNC(PyImport_GetImporter) +EXPORT_FUNC(PyImport_GetMagicNumber) +EXPORT_FUNC(PyImport_GetMagicTag) +EXPORT_FUNC(PyImport_GetModule) +EXPORT_FUNC(PyImport_GetModuleDict) +EXPORT_FUNC(PyImport_Import) +EXPORT_FUNC(PyImport_ImportFrozenModule) +EXPORT_FUNC(PyImport_ImportFrozenModuleObject) +EXPORT_FUNC(PyImport_ImportModule) +EXPORT_FUNC(PyImport_ImportModuleLevel) +EXPORT_FUNC(PyImport_ImportModuleLevelObject) +EXPORT_FUNC(PyImport_ImportModuleNoBlock) +EXPORT_FUNC(PyImport_ReloadModule) +EXPORT_FUNC(PyIndex_Check) +EXPORT_FUNC(PyInterpreterState_Clear) +EXPORT_FUNC(PyInterpreterState_Delete) +EXPORT_FUNC(PyInterpreterState_GetID) +EXPORT_FUNC(PyInterpreterState_New) +EXPORT_FUNC(PyIter_Check) +EXPORT_FUNC(PyIter_Next) +EXPORT_FUNC(PyList_Append) +EXPORT_FUNC(PyList_AsTuple) +EXPORT_FUNC(PyList_GetItem) +EXPORT_FUNC(PyList_GetSlice) +EXPORT_FUNC(PyList_Insert) +EXPORT_FUNC(PyList_New) +EXPORT_FUNC(PyList_Reverse) +EXPORT_FUNC(PyList_SetItem) +EXPORT_FUNC(PyList_SetSlice) +EXPORT_FUNC(PyList_Size) +EXPORT_FUNC(PyList_Sort) +EXPORT_FUNC(PyLong_AsDouble) +EXPORT_FUNC(PyLong_AsLong) +EXPORT_FUNC(PyLong_AsLongAndOverflow) +EXPORT_FUNC(PyLong_AsLongLong) +EXPORT_FUNC(PyLong_AsLongLongAndOverflow) +EXPORT_FUNC(PyLong_AsSize_t) +EXPORT_FUNC(PyLong_AsSsize_t) +EXPORT_FUNC(PyLong_AsUnsignedLong) +EXPORT_FUNC(PyLong_AsUnsignedLongLong) +EXPORT_FUNC(PyLong_AsUnsignedLongLongMask) +EXPORT_FUNC(PyLong_AsUnsignedLongMask) +EXPORT_FUNC(PyLong_AsVoidPtr) +EXPORT_FUNC(PyLong_FromDouble) +EXPORT_FUNC(PyLong_FromLong) +EXPORT_FUNC(PyLong_FromLongLong) +EXPORT_FUNC(PyLong_FromSize_t) +EXPORT_FUNC(PyLong_FromSsize_t) +EXPORT_FUNC(PyLong_FromString) +EXPORT_FUNC(PyLong_FromUnsignedLong) +EXPORT_FUNC(PyLong_FromUnsignedLongLong) +EXPORT_FUNC(PyLong_FromVoidPtr) +EXPORT_FUNC(PyLong_GetInfo) +EXPORT_FUNC(PyMapping_Check) +EXPORT_FUNC(PyMapping_GetItemString) +EXPORT_FUNC(PyMapping_HasKey) +EXPORT_FUNC(PyMapping_HasKeyString) +EXPORT_FUNC(PyMapping_Items) +EXPORT_FUNC(PyMapping_Keys) +EXPORT_FUNC(PyMapping_Length) +EXPORT_FUNC(PyMapping_SetItemString) +EXPORT_FUNC(PyMapping_Size) +EXPORT_FUNC(PyMapping_Values) +EXPORT_FUNC(PyMem_Calloc) +EXPORT_FUNC(PyMem_Free) +EXPORT_FUNC(PyMem_Malloc) +EXPORT_FUNC(PyMem_Realloc) +EXPORT_FUNC(PyMemoryView_FromMemory) +EXPORT_FUNC(PyMemoryView_FromObject) +EXPORT_FUNC(PyMemoryView_GetContiguous) +EXPORT_FUNC(PyModule_AddFunctions) +EXPORT_FUNC(PyModule_AddIntConstant) +EXPORT_FUNC(PyModule_AddObject) +EXPORT_FUNC(PyModule_AddStringConstant) +EXPORT_FUNC(PyModule_Create2) +EXPORT_FUNC(PyModule_ExecDef) +EXPORT_FUNC(PyModule_FromDefAndSpec2) +EXPORT_FUNC(PyModule_GetDef) +EXPORT_FUNC(PyModule_GetDict) +EXPORT_FUNC(PyModule_GetFilename) +EXPORT_FUNC(PyModule_GetFilenameObject) +EXPORT_FUNC(PyModule_GetName) +EXPORT_FUNC(PyModule_GetNameObject) +EXPORT_FUNC(PyModule_GetState) +EXPORT_FUNC(PyModule_New) +EXPORT_FUNC(PyModule_NewObject) +EXPORT_FUNC(PyModule_SetDocString) +EXPORT_FUNC(PyModuleDef_Init) +EXPORT_FUNC(PyNumber_Absolute) +EXPORT_FUNC(PyNumber_Add) +EXPORT_FUNC(PyNumber_And) +EXPORT_FUNC(PyNumber_AsSsize_t) +EXPORT_FUNC(PyNumber_Check) +EXPORT_FUNC(PyNumber_Divmod) +EXPORT_FUNC(PyNumber_Float) +EXPORT_FUNC(PyNumber_FloorDivide) +EXPORT_FUNC(PyNumber_Index) +EXPORT_FUNC(PyNumber_InPlaceAdd) +EXPORT_FUNC(PyNumber_InPlaceAnd) +EXPORT_FUNC(PyNumber_InPlaceFloorDivide) +EXPORT_FUNC(PyNumber_InPlaceLshift) +EXPORT_FUNC(PyNumber_InPlaceMatrixMultiply) +EXPORT_FUNC(PyNumber_InPlaceMultiply) +EXPORT_FUNC(PyNumber_InPlaceOr) +EXPORT_FUNC(PyNumber_InPlacePower) +EXPORT_FUNC(PyNumber_InPlaceRemainder) +EXPORT_FUNC(PyNumber_InPlaceRshift) +EXPORT_FUNC(PyNumber_InPlaceSubtract) +EXPORT_FUNC(PyNumber_InPlaceTrueDivide) +EXPORT_FUNC(PyNumber_InPlaceXor) +EXPORT_FUNC(PyNumber_Invert) +EXPORT_FUNC(PyNumber_Long) +EXPORT_FUNC(PyNumber_Lshift) +EXPORT_FUNC(PyNumber_MatrixMultiply) +EXPORT_FUNC(PyNumber_Multiply) +EXPORT_FUNC(PyNumber_Negative) +EXPORT_FUNC(PyNumber_Or) +EXPORT_FUNC(PyNumber_Positive) +EXPORT_FUNC(PyNumber_Power) +EXPORT_FUNC(PyNumber_Remainder) +EXPORT_FUNC(PyNumber_Rshift) +EXPORT_FUNC(PyNumber_Subtract) +EXPORT_FUNC(PyNumber_ToBase) +EXPORT_FUNC(PyNumber_TrueDivide) +EXPORT_FUNC(PyNumber_Xor) +EXPORT_FUNC(PyObject_ASCII) +EXPORT_FUNC(PyObject_AsFileDescriptor) +EXPORT_FUNC(PyObject_Bytes) +EXPORT_FUNC(PyObject_Call) +EXPORT_FUNC(PyObject_CallFunction) +EXPORT_FUNC(PyObject_CallFunctionObjArgs) +EXPORT_FUNC(PyObject_CallMethod) +EXPORT_FUNC(PyObject_CallMethodObjArgs) +EXPORT_FUNC(PyObject_CallObject) +EXPORT_FUNC(PyObject_Calloc) +EXPORT_FUNC(PyObject_ClearWeakRefs) +EXPORT_FUNC(PyObject_DelItem) +EXPORT_FUNC(PyObject_DelItemString) +EXPORT_FUNC(PyObject_Dir) +EXPORT_FUNC(PyObject_Format) +EXPORT_FUNC(PyObject_Free) +EXPORT_FUNC(PyObject_GC_Del) +EXPORT_FUNC(PyObject_GC_Track) +EXPORT_FUNC(PyObject_GC_UnTrack) +EXPORT_FUNC(PyObject_GenericGetAttr) +EXPORT_FUNC(PyObject_GenericSetAttr) +EXPORT_FUNC(PyObject_GenericSetDict) +EXPORT_FUNC(PyObject_GetAttr) +EXPORT_FUNC(PyObject_GetAttrString) +EXPORT_FUNC(PyObject_GetItem) +EXPORT_FUNC(PyObject_GetIter) +EXPORT_FUNC(PyObject_HasAttr) +EXPORT_FUNC(PyObject_HasAttrString) +EXPORT_FUNC(PyObject_Hash) +EXPORT_FUNC(PyObject_HashNotImplemented) +EXPORT_FUNC(PyObject_Init) +EXPORT_FUNC(PyObject_InitVar) +EXPORT_FUNC(PyObject_IsInstance) +EXPORT_FUNC(PyObject_IsSubclass) +EXPORT_FUNC(PyObject_IsTrue) +EXPORT_FUNC(PyObject_Length) +EXPORT_FUNC(PyObject_Malloc) +EXPORT_FUNC(PyObject_Not) +EXPORT_FUNC(PyObject_Realloc) +EXPORT_FUNC(PyObject_Repr) +EXPORT_FUNC(PyObject_RichCompare) +EXPORT_FUNC(PyObject_RichCompareBool) +EXPORT_FUNC(PyObject_SelfIter) +EXPORT_FUNC(PyObject_SetAttr) +EXPORT_FUNC(PyObject_SetAttrString) +EXPORT_FUNC(PyObject_SetItem) +EXPORT_FUNC(PyObject_Size) +EXPORT_FUNC(PyObject_Str) +EXPORT_FUNC(PyObject_Type) +EXPORT_FUNC(PyODict_DelItem) +EXPORT_FUNC(PyODict_New) +EXPORT_FUNC(PyODict_SetItem) +EXPORT_FUNC(PyOS_AfterFork) +EXPORT_FUNC(PyOS_CheckStack) +EXPORT_FUNC(PyOS_double_to_string) +EXPORT_FUNC(PyOS_FSPath) +EXPORT_FUNC(PyOS_getsig) +EXPORT_FUNC(PyOS_InitInterrupts) +EXPORT_FUNC(PyOS_InterruptOccurred) +EXPORT_FUNC(PyOS_mystricmp) +EXPORT_FUNC(PyOS_mystrnicmp) +EXPORT_FUNC(PyOS_setsig) +EXPORT_FUNC(PyOS_snprintf) +EXPORT_FUNC(PyOS_string_to_double) +EXPORT_FUNC(PyOS_strtol) +EXPORT_FUNC(PyOS_strtoul) +EXPORT_FUNC(PyOS_vsnprintf) +EXPORT_FUNC(PyParser_SimpleParseFileFlags) +EXPORT_FUNC(PyParser_SimpleParseStringFlags) +EXPORT_FUNC(PyParser_SimpleParseStringFlagsFilename) +EXPORT_FUNC(PySeqIter_New) +EXPORT_FUNC(PySequence_Check) +EXPORT_FUNC(PySequence_Concat) +EXPORT_FUNC(PySequence_Contains) +EXPORT_FUNC(PySequence_Count) +EXPORT_FUNC(PySequence_DelItem) +EXPORT_FUNC(PySequence_DelSlice) +EXPORT_FUNC(PySequence_Fast) +EXPORT_FUNC(PySequence_GetItem) +EXPORT_FUNC(PySequence_GetSlice) +EXPORT_FUNC(PySequence_In) +EXPORT_FUNC(PySequence_Index) +EXPORT_FUNC(PySequence_InPlaceConcat) +EXPORT_FUNC(PySequence_InPlaceRepeat) +EXPORT_FUNC(PySequence_Length) +EXPORT_FUNC(PySequence_List) +EXPORT_FUNC(PySequence_Repeat) +EXPORT_FUNC(PySequence_SetItem) +EXPORT_FUNC(PySequence_SetSlice) +EXPORT_FUNC(PySequence_Size) +EXPORT_FUNC(PySequence_Tuple) +EXPORT_FUNC(PySet_Add) +EXPORT_FUNC(PySet_Clear) +EXPORT_FUNC(PySet_Contains) +EXPORT_FUNC(PySet_Discard) +EXPORT_FUNC(PySet_New) +EXPORT_FUNC(PySet_Pop) +EXPORT_FUNC(PySet_Size) +EXPORT_FUNC(PySlice_AdjustIndices) +EXPORT_FUNC(PySlice_GetIndices) +EXPORT_FUNC(PySlice_GetIndicesEx) +EXPORT_FUNC(PySlice_New) +EXPORT_FUNC(PySlice_Unpack) +EXPORT_FUNC(PyState_AddModule) +EXPORT_FUNC(PyState_FindModule) +EXPORT_FUNC(PyState_RemoveModule) +EXPORT_FUNC(PyStructSequence_GetItem) +EXPORT_FUNC(PyStructSequence_New) +EXPORT_FUNC(PyStructSequence_NewType) +EXPORT_FUNC(PyStructSequence_SetItem) +EXPORT_FUNC(PySys_AddWarnOption) +EXPORT_FUNC(PySys_AddWarnOptionUnicode) +EXPORT_FUNC(PySys_AddXOption) +EXPORT_FUNC(PySys_FormatStderr) +EXPORT_FUNC(PySys_FormatStdout) +EXPORT_FUNC(PySys_GetObject) +EXPORT_FUNC(PySys_GetXOptions) +EXPORT_FUNC(PySys_HasWarnOptions) +EXPORT_FUNC(PySys_ResetWarnOptions) +EXPORT_FUNC(PySys_SetArgv) +EXPORT_FUNC(PySys_SetArgvEx) +EXPORT_FUNC(PySys_SetObject) +EXPORT_FUNC(PySys_SetPath) +EXPORT_FUNC(PySys_WriteStderr) +EXPORT_FUNC(PySys_WriteStdout) +EXPORT_FUNC(PyThread_tss_alloc) +EXPORT_FUNC(PyThread_tss_create) +EXPORT_FUNC(PyThread_tss_delete) +EXPORT_FUNC(PyThread_tss_free) +EXPORT_FUNC(PyThread_tss_get) +EXPORT_FUNC(PyThread_tss_is_created) +EXPORT_FUNC(PyThread_tss_set) +EXPORT_FUNC(PyThreadState_Clear) +EXPORT_FUNC(PyThreadState_Delete) +EXPORT_FUNC(PyThreadState_DeleteCurrent) +EXPORT_FUNC(PyThreadState_Get) +EXPORT_FUNC(PyThreadState_GetDict) +EXPORT_FUNC(PyThreadState_New) +EXPORT_FUNC(PyThreadState_SetAsyncExc) +EXPORT_FUNC(PyThreadState_Swap) +EXPORT_FUNC(PyTraceBack_Here) +EXPORT_FUNC(PyTraceBack_Print) +EXPORT_FUNC(PyTuple_GetItem) +EXPORT_FUNC(PyTuple_GetSlice) +EXPORT_FUNC(PyTuple_New) +EXPORT_FUNC(PyTuple_Pack) +EXPORT_FUNC(PyTuple_SetItem) +EXPORT_FUNC(PyTuple_Size) +EXPORT_FUNC(PyType_ClearCache) +EXPORT_FUNC(PyType_FromSpec) +EXPORT_FUNC(PyType_FromSpecWithBases) +EXPORT_FUNC(PyType_GenericAlloc) +EXPORT_FUNC(PyType_GenericNew) +EXPORT_FUNC(PyType_GetFlags) +EXPORT_FUNC(PyType_GetSlot) +EXPORT_FUNC(PyType_IsSubtype) +EXPORT_FUNC(PyType_Modified) +EXPORT_FUNC(PyType_Ready) +EXPORT_FUNC(PyUnicode_Append) +EXPORT_FUNC(PyUnicode_AppendAndDel) +EXPORT_FUNC(PyUnicode_AsASCIIString) +EXPORT_FUNC(PyUnicode_AsCharmapString) +EXPORT_FUNC(PyUnicode_AsDecodedObject) +EXPORT_FUNC(PyUnicode_AsDecodedUnicode) +EXPORT_FUNC(PyUnicode_AsEncodedObject) +EXPORT_FUNC(PyUnicode_AsEncodedString) +EXPORT_FUNC(PyUnicode_AsEncodedUnicode) +EXPORT_FUNC(PyUnicode_AsLatin1String) +EXPORT_FUNC(PyUnicode_AsMBCSString) +EXPORT_FUNC(PyUnicode_AsRawUnicodeEscapeString) +EXPORT_FUNC(PyUnicode_AsUCS4) +EXPORT_FUNC(PyUnicode_AsUCS4Copy) +EXPORT_FUNC(PyUnicode_AsUnicodeEscapeString) +EXPORT_FUNC(PyUnicode_AsUTF16String) +EXPORT_FUNC(PyUnicode_AsUTF32String) +EXPORT_FUNC(PyUnicode_AsUTF8String) +EXPORT_FUNC(PyUnicode_AsWideChar) +EXPORT_FUNC(PyUnicode_AsWideCharString) +EXPORT_FUNC(PyUnicode_BuildEncodingMap) +EXPORT_FUNC(PyUnicode_Compare) +EXPORT_FUNC(PyUnicode_CompareWithASCIIString) +EXPORT_FUNC(PyUnicode_Concat) +EXPORT_FUNC(PyUnicode_Contains) +EXPORT_FUNC(PyUnicode_Count) +EXPORT_FUNC(PyUnicode_Decode) +EXPORT_FUNC(PyUnicode_DecodeASCII) +EXPORT_FUNC(PyUnicode_DecodeCharmap) +EXPORT_FUNC(PyUnicode_DecodeCodePageStateful) +EXPORT_FUNC(PyUnicode_DecodeFSDefault) +EXPORT_FUNC(PyUnicode_DecodeFSDefaultAndSize) +EXPORT_FUNC(PyUnicode_DecodeLatin1) +EXPORT_FUNC(PyUnicode_DecodeLocale) +EXPORT_FUNC(PyUnicode_DecodeLocaleAndSize) +EXPORT_FUNC(PyUnicode_DecodeMBCS) +EXPORT_FUNC(PyUnicode_DecodeMBCSStateful) +EXPORT_FUNC(PyUnicode_DecodeRawUnicodeEscape) +EXPORT_FUNC(PyUnicode_DecodeUnicodeEscape) +EXPORT_FUNC(PyUnicode_DecodeUTF16) +EXPORT_FUNC(PyUnicode_DecodeUTF16Stateful) +EXPORT_FUNC(PyUnicode_DecodeUTF32) +EXPORT_FUNC(PyUnicode_DecodeUTF32Stateful) +EXPORT_FUNC(PyUnicode_DecodeUTF7) +EXPORT_FUNC(PyUnicode_DecodeUTF7Stateful) +EXPORT_FUNC(PyUnicode_DecodeUTF8) +EXPORT_FUNC(PyUnicode_DecodeUTF8Stateful) +EXPORT_FUNC(PyUnicode_EncodeCodePage) +EXPORT_FUNC(PyUnicode_EncodeFSDefault) +EXPORT_FUNC(PyUnicode_EncodeLocale) +EXPORT_FUNC(PyUnicode_Find) +EXPORT_FUNC(PyUnicode_FindChar) +EXPORT_FUNC(PyUnicode_Format) +EXPORT_FUNC(PyUnicode_FromEncodedObject) +EXPORT_FUNC(PyUnicode_FromFormat) +EXPORT_FUNC(PyUnicode_FromFormatV) +EXPORT_FUNC(PyUnicode_FromObject) +EXPORT_FUNC(PyUnicode_FromOrdinal) +EXPORT_FUNC(PyUnicode_FromString) +EXPORT_FUNC(PyUnicode_FromStringAndSize) +EXPORT_FUNC(PyUnicode_FromWideChar) +EXPORT_FUNC(PyUnicode_FSConverter) +EXPORT_FUNC(PyUnicode_FSDecoder) +EXPORT_FUNC(PyUnicode_GetDefaultEncoding) +EXPORT_FUNC(PyUnicode_GetLength) +EXPORT_FUNC(PyUnicode_GetSize) +EXPORT_FUNC(PyUnicode_InternFromString) +EXPORT_FUNC(PyUnicode_InternImmortal) +EXPORT_FUNC(PyUnicode_InternInPlace) +EXPORT_FUNC(PyUnicode_IsIdentifier) +EXPORT_FUNC(PyUnicode_Join) +EXPORT_FUNC(PyUnicode_Partition) +EXPORT_FUNC(PyUnicode_ReadChar) +EXPORT_FUNC(PyUnicode_Replace) +EXPORT_FUNC(PyUnicode_Resize) +EXPORT_FUNC(PyUnicode_RichCompare) +EXPORT_FUNC(PyUnicode_RPartition) +EXPORT_FUNC(PyUnicode_RSplit) +EXPORT_FUNC(PyUnicode_Split) +EXPORT_FUNC(PyUnicode_Splitlines) +EXPORT_FUNC(PyUnicode_Substring) +EXPORT_FUNC(PyUnicode_Tailmatch) +EXPORT_FUNC(PyUnicode_Translate) +EXPORT_FUNC(PyUnicode_WriteChar) +EXPORT_FUNC(PyUnicodeDecodeError_Create) +EXPORT_FUNC(PyUnicodeDecodeError_GetEncoding) +EXPORT_FUNC(PyUnicodeDecodeError_GetEnd) +EXPORT_FUNC(PyUnicodeDecodeError_GetObject) +EXPORT_FUNC(PyUnicodeDecodeError_GetReason) +EXPORT_FUNC(PyUnicodeDecodeError_GetStart) +EXPORT_FUNC(PyUnicodeDecodeError_SetEnd) +EXPORT_FUNC(PyUnicodeDecodeError_SetReason) +EXPORT_FUNC(PyUnicodeDecodeError_SetStart) +EXPORT_FUNC(PyUnicodeEncodeError_GetEncoding) +EXPORT_FUNC(PyUnicodeEncodeError_GetEnd) +EXPORT_FUNC(PyUnicodeEncodeError_GetObject) +EXPORT_FUNC(PyUnicodeEncodeError_GetReason) +EXPORT_FUNC(PyUnicodeEncodeError_GetStart) +EXPORT_FUNC(PyUnicodeEncodeError_SetEnd) +EXPORT_FUNC(PyUnicodeEncodeError_SetReason) +EXPORT_FUNC(PyUnicodeEncodeError_SetStart) +EXPORT_FUNC(PyUnicodeTranslateError_GetEnd) +EXPORT_FUNC(PyUnicodeTranslateError_GetObject) +EXPORT_FUNC(PyUnicodeTranslateError_GetReason) +EXPORT_FUNC(PyUnicodeTranslateError_GetStart) +EXPORT_FUNC(PyUnicodeTranslateError_SetEnd) +EXPORT_FUNC(PyUnicodeTranslateError_SetReason) +EXPORT_FUNC(PyUnicodeTranslateError_SetStart) +EXPORT_FUNC(PyWeakref_GetObject) +EXPORT_FUNC(PyWeakref_NewProxy) +EXPORT_FUNC(PyWeakref_NewRef) +EXPORT_FUNC(PyWrapper_New) + +EXPORT_DATA(_Py_CheckRecursionLimit) +EXPORT_DATA(_Py_EllipsisObject) +EXPORT_DATA(_Py_FalseStruct) +EXPORT_DATA(_Py_NoneStruct) +EXPORT_DATA(_Py_NotImplementedStruct) +EXPORT_DATA(_Py_SwappedOp) +EXPORT_DATA(_Py_TrueStruct) +EXPORT_DATA(_PyTrash_delete_later) +EXPORT_DATA(_PyTrash_delete_nesting) +EXPORT_DATA(_PyWeakref_CallableProxyType) +EXPORT_DATA(_PyWeakref_ProxyType) +EXPORT_DATA(_PyWeakref_RefType) +EXPORT_DATA(Py_FileSystemDefaultEncodeErrors) +EXPORT_DATA(Py_FileSystemDefaultEncoding) +EXPORT_DATA(Py_HasFileSystemDefaultEncoding) +EXPORT_DATA(Py_UTF8Mode) +EXPORT_DATA(PyBaseObject_Type) +EXPORT_DATA(PyBool_Type) +EXPORT_DATA(PyByteArray_Type) +EXPORT_DATA(PyByteArrayIter_Type) +EXPORT_DATA(PyBytes_Type) +EXPORT_DATA(PyBytesIter_Type) +EXPORT_DATA(PyCallIter_Type) +EXPORT_DATA(PyCapsule_Type) +EXPORT_DATA(PyCFunction_Type) +EXPORT_DATA(PyClassMethodDescr_Type) +EXPORT_DATA(PyComplex_Type) +EXPORT_DATA(PyDict_Type) +EXPORT_DATA(PyDictItems_Type) +EXPORT_DATA(PyDictIterItem_Type) +EXPORT_DATA(PyDictIterKey_Type) +EXPORT_DATA(PyDictIterValue_Type) +EXPORT_DATA(PyDictKeys_Type) +EXPORT_DATA(PyDictProxy_Type) +EXPORT_DATA(PyDictValues_Type) +EXPORT_DATA(PyEllipsis_Type) +EXPORT_DATA(PyEnum_Type) +EXPORT_DATA(PyExc_ArithmeticError) +EXPORT_DATA(PyExc_AssertionError) +EXPORT_DATA(PyExc_AttributeError) +EXPORT_DATA(PyExc_BaseException) +EXPORT_DATA(PyExc_BlockingIOError) +EXPORT_DATA(PyExc_BrokenPipeError) +EXPORT_DATA(PyExc_BufferError) +EXPORT_DATA(PyExc_BytesWarning) +EXPORT_DATA(PyExc_ChildProcessError) +EXPORT_DATA(PyExc_ConnectionAbortedError) +EXPORT_DATA(PyExc_ConnectionError) +EXPORT_DATA(PyExc_ConnectionRefusedError) +EXPORT_DATA(PyExc_ConnectionResetError) +EXPORT_DATA(PyExc_DeprecationWarning) +EXPORT_DATA(PyExc_EnvironmentError) +EXPORT_DATA(PyExc_EOFError) +EXPORT_DATA(PyExc_Exception) +EXPORT_DATA(PyExc_FileExistsError) +EXPORT_DATA(PyExc_FileNotFoundError) +EXPORT_DATA(PyExc_FloatingPointError) +EXPORT_DATA(PyExc_FutureWarning) +EXPORT_DATA(PyExc_GeneratorExit) +EXPORT_DATA(PyExc_ImportError) +EXPORT_DATA(PyExc_ImportWarning) +EXPORT_DATA(PyExc_IndentationError) +EXPORT_DATA(PyExc_IndexError) +EXPORT_DATA(PyExc_InterruptedError) +EXPORT_DATA(PyExc_IOError) +EXPORT_DATA(PyExc_IsADirectoryError) +EXPORT_DATA(PyExc_KeyboardInterrupt) +EXPORT_DATA(PyExc_KeyError) +EXPORT_DATA(PyExc_LookupError) +EXPORT_DATA(PyExc_MemoryError) +EXPORT_DATA(PyExc_ModuleNotFoundError) +EXPORT_DATA(PyExc_NameError) +EXPORT_DATA(PyExc_NotADirectoryError) +EXPORT_DATA(PyExc_NotImplementedError) +EXPORT_DATA(PyExc_OSError) +EXPORT_DATA(PyExc_OverflowError) +EXPORT_DATA(PyExc_PendingDeprecationWarning) +EXPORT_DATA(PyExc_PermissionError) +EXPORT_DATA(PyExc_ProcessLookupError) +EXPORT_DATA(PyExc_RecursionError) +EXPORT_DATA(PyExc_ReferenceError) +EXPORT_DATA(PyExc_ResourceWarning) +EXPORT_DATA(PyExc_RuntimeError) +EXPORT_DATA(PyExc_RuntimeWarning) +EXPORT_DATA(PyExc_StopAsyncIteration) +EXPORT_DATA(PyExc_StopIteration) +EXPORT_DATA(PyExc_SyntaxError) +EXPORT_DATA(PyExc_SyntaxWarning) +EXPORT_DATA(PyExc_SystemError) +EXPORT_DATA(PyExc_SystemExit) +EXPORT_DATA(PyExc_TabError) +EXPORT_DATA(PyExc_TimeoutError) +EXPORT_DATA(PyExc_TypeError) +EXPORT_DATA(PyExc_UnboundLocalError) +EXPORT_DATA(PyExc_UnicodeDecodeError) +EXPORT_DATA(PyExc_UnicodeEncodeError) +EXPORT_DATA(PyExc_UnicodeError) +EXPORT_DATA(PyExc_UnicodeTranslateError) +EXPORT_DATA(PyExc_UnicodeWarning) +EXPORT_DATA(PyExc_UserWarning) +EXPORT_DATA(PyExc_ValueError) +EXPORT_DATA(PyExc_Warning) +EXPORT_DATA(PyExc_WindowsError) +EXPORT_DATA(PyExc_ZeroDivisionError) +EXPORT_DATA(PyFilter_Type) +EXPORT_DATA(PyFloat_Type) +EXPORT_DATA(PyFrozenSet_Type) +EXPORT_DATA(PyGetSetDescr_Type) +EXPORT_DATA(PyList_Type) +EXPORT_DATA(PyListIter_Type) +EXPORT_DATA(PyListRevIter_Type) +EXPORT_DATA(PyLong_Type) +EXPORT_DATA(PyLongRangeIter_Type) +EXPORT_DATA(PyMap_Type) +EXPORT_DATA(PyMemberDescr_Type) +EXPORT_DATA(PyMemoryView_Type) +EXPORT_DATA(PyMethodDescr_Type) +EXPORT_DATA(PyModule_Type) +EXPORT_DATA(PyModuleDef_Type) +EXPORT_DATA(PyNullImporter_Type) +EXPORT_DATA(PyODict_Type) +EXPORT_DATA(PyODictItems_Type) +EXPORT_DATA(PyODictIter_Type) +EXPORT_DATA(PyODictKeys_Type) +EXPORT_DATA(PyODictValues_Type) +EXPORT_DATA(PyOS_InputHook) +EXPORT_DATA(PyOS_ReadlineFunctionPointer) +EXPORT_DATA(PyProperty_Type) +EXPORT_DATA(PyRange_Type) +EXPORT_DATA(PyRangeIter_Type) +EXPORT_DATA(PyReversed_Type) +EXPORT_DATA(PySeqIter_Type) +EXPORT_DATA(PySet_Type) +EXPORT_DATA(PySetIter_Type) +EXPORT_DATA(PySlice_Type) +EXPORT_DATA(PySortWrapper_Type) +EXPORT_DATA(PySuper_Type) +EXPORT_DATA(PyTraceBack_Type) +EXPORT_DATA(PyTuple_Type) +EXPORT_DATA(PyTupleIter_Type) +EXPORT_DATA(PyType_Type) +EXPORT_DATA(PyUnicode_Type) +EXPORT_DATA(PyUnicodeIter_Type) +EXPORT_DATA(PyWrapperDescr_Type) +EXPORT_DATA(PyZip_Type) diff --git a/PC/python_nt.rc b/PC/python_nt.rc index fac6105d8a7..b5fb58f26b2 100644 --- a/PC/python_nt.rc +++ b/PC/python_nt.rc @@ -7,12 +7,6 @@ #include 2 RT_MANIFEST "python.manifest" -// String Tables -STRINGTABLE DISCARDABLE -BEGIN - 1000, MS_DLL_ID -END - ///////////////////////////////////////////////////////////////////////////// // // Version @@ -40,7 +34,7 @@ BEGIN VALUE "FileVersion", PYTHON_VERSION VALUE "InternalName", "Python DLL\0" VALUE "LegalCopyright", PYTHON_COPYRIGHT "\0" - VALUE "OriginalFilename", PYTHON_DLL_NAME "\0" + VALUE "OriginalFilename", ORIGINAL_FILENAME "\0" VALUE "ProductName", "Python\0" VALUE "ProductVersion", PYTHON_VERSION END diff --git a/PC/python_ver_rc.h b/PC/python_ver_rc.h index f95e755bb8b..060aecdc675 100644 --- a/PC/python_ver_rc.h +++ b/PC/python_ver_rc.h @@ -1,6 +1,7 @@ // Resource script for Python core DLL. // Currently only holds version information. // +#pragma code_page(1252) #include "winver.h" #define PYTHON_COMPANY "Python Software Foundation" @@ -9,7 +10,6 @@ #define MS_WINDOWS #include "modsupport.h" #include "patchlevel.h" -#include #ifdef _DEBUG # define PYTHON_DEBUG_EXT "_d" #else diff --git a/PC/winreg.c b/PC/winreg.c index 1305b7030fa..7c3b2f4be85 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -14,6 +14,7 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" +#include "pycore_object.h" // _PyObject_Init() #include "structmember.h" // PyMemberDef #include @@ -457,13 +458,12 @@ clinic_HKEY_converter(PyObject *ob, void *p) PyObject * PyHKEY_FromHKEY(HKEY h) { - PyHKEYObject *op; - /* Inline PyObject_New */ - op = (PyHKEYObject *) PyObject_MALLOC(sizeof(PyHKEYObject)); - if (op == NULL) + PyHKEYObject *op = (PyHKEYObject *) PyObject_MALLOC(sizeof(PyHKEYObject)); + if (op == NULL) { return PyErr_NoMemory(); - PyObject_INIT(op, &PyHKEY_Type); + } + _PyObject_Init(op, &PyHKEY_Type); op->hkey = h; return (PyObject *)op; } diff --git a/PCbuild/_asyncio.vcxproj.filters b/PCbuild/_asyncio.vcxproj.filters index 10a186cdad1..a09ae928a9b 100644 --- a/PCbuild/_asyncio.vcxproj.filters +++ b/PCbuild/_asyncio.vcxproj.filters @@ -1,16 +1,21 @@  - - - {2422278e-eeeb-4241-8182-433e2bc5a7fc} + + {41f1cd52-b682-46aa-a7fd-7bdf81a18010} + Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_bz2.vcxproj.filters b/PCbuild/_bz2.vcxproj.filters index eac64dd29d6..7c0b5162537 100644 --- a/PCbuild/_bz2.vcxproj.filters +++ b/PCbuild/_bz2.vcxproj.filters @@ -4,10 +4,16 @@ {f53a859d-dad2-4d5b-ae41-f28d8b571f5a} - + + {b90c3cee-7700-4e87-bf85-0801866e8d0d} + + {7e0bed05-ae33-43b7-8797-656455bbb7f3} - + + {b53f67d8-fdf0-4e10-a987-e44475ff434a} + + {ed574b89-6983-4cdf-9f98-fe7048d9e89c} @@ -16,33 +22,38 @@ Source Files - bzip2 1.0.6 Source Files + Source Files\bzip2 - bzip2 1.0.6 Source Files + Source Files\bzip2 - bzip2 1.0.6 Source Files + Source Files\bzip2 - bzip2 1.0.6 Source Files + Source Files\bzip2 - bzip2 1.0.6 Source Files + Source Files\bzip2 - bzip2 1.0.6 Source Files + Source Files\bzip2 - bzip2 1.0.6 Source Files + Source Files\bzip2 - - bzip2 1.0.6 Header Files - - bzip2 1.0.6 Header Files + Header Files\bzip2 + + + Header Files\bzip2 - + + + Resource Files + + + \ No newline at end of file diff --git a/PCbuild/_ctypes.vcxproj.filters b/PCbuild/_ctypes.vcxproj.filters index 3123286347a..118c4f0698c 100644 --- a/PCbuild/_ctypes.vcxproj.filters +++ b/PCbuild/_ctypes.vcxproj.filters @@ -7,6 +7,9 @@ {dbdea1f2-ad8b-44ca-b782-fcf65d91559b} + + {31a37bb4-c384-41ff-9ec1-8ad98d482e22} + @@ -37,6 +40,8 @@ - + + Resource Files + \ No newline at end of file diff --git a/PCbuild/_ctypes_test.vcxproj.filters b/PCbuild/_ctypes_test.vcxproj.filters index c1e94ce1faa..5174196c52e 100644 --- a/PCbuild/_ctypes_test.vcxproj.filters +++ b/PCbuild/_ctypes_test.vcxproj.filters @@ -7,6 +7,9 @@ {38abc486-e143-49dc-8cf0-8aefab0e0d3d} + + {5030ff8f-daf5-4bc8-b1dd-e8b59d34c511} + @@ -18,4 +21,9 @@ Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_decimal.vcxproj b/PCbuild/_decimal.vcxproj index f0f387f3bfa..4c71cdb6d1d 100644 --- a/PCbuild/_decimal.vcxproj +++ b/PCbuild/_decimal.vcxproj @@ -118,7 +118,6 @@ - diff --git a/PCbuild/_decimal.vcxproj.filters b/PCbuild/_decimal.vcxproj.filters index 1aa9d020d67..0cbd3d0736c 100644 --- a/PCbuild/_decimal.vcxproj.filters +++ b/PCbuild/_decimal.vcxproj.filters @@ -7,58 +7,64 @@ {138089f8-faba-494f-b6ed-051f31fbaf2d} + + {632b24a3-0844-4e57-ad34-b0e4cef886dd} + + + {322d127c-1105-4a31-aed2-e29cdececc77} + + + {780c3b7a-7817-4e89-a2f2-fc522f2c5966} + - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - Header Files + + Header Files\libmpdec + + + Header Files\libmpdec + + + Header Files\libmpdec + + + Header Files\libmpdec + + + Header Files\libmpdec + + + Header Files\libmpdec + - Header Files + Header Files\libmpdec - Header Files + Header Files\libmpdec - Header Files + Header Files\libmpdec - Header Files + Header Files\libmpdec - Header Files + Header Files\libmpdec - Header Files + Header Files\libmpdec - Header Files + Header Files\libmpdec - Header Files + Header Files\libmpdec - Header Files - - - Header Files + Header Files\libmpdec @@ -66,51 +72,56 @@ Source Files - Source Files + Source Files\libmpdec - Source Files + Source Files\libmpdec - Source Files + Source Files\libmpdec - Source Files + Source Files\libmpdec - Source Files + Source Files\libmpdec - Source Files + Source Files\libmpdec - Source Files + Source Files\libmpdec - Source Files + Source Files\libmpdec - Source Files + Source Files\libmpdec - Source Files + Source Files\libmpdec - Source Files + Source Files\libmpdec - Source Files + Source Files\libmpdec - Source Files + Source Files\libmpdec - Source Files + Source Files\libmpdec + + + Resource Files + + - Source Files + Source Files\libmpdec \ No newline at end of file diff --git a/PCbuild/_elementtree.vcxproj.filters b/PCbuild/_elementtree.vcxproj.filters index 6acdf35846a..bc14e31f32b 100644 --- a/PCbuild/_elementtree.vcxproj.filters +++ b/PCbuild/_elementtree.vcxproj.filters @@ -7,52 +7,61 @@ {7b5335ad-059f-486f-85e4-f4757e26a9bf} + + {37d3ef0a-1ea6-492d-bba7-b83865198caa} + + + {6099ed72-6668-4779-adb2-a2362e5da3b9} + + + {f99990ba-cd06-40cc-8f28-d2d424ec13be} + - Header Files + Header Files\expat - Header Files + Header Files\expat - Header Files + Header Files\expat - Header Files + Header Files\expat - Header Files + Header Files\expat - Header Files + Header Files\expat - Header Files + Header Files\expat - Header Files + Header Files\expat - Header Files + Header Files\expat - Header Files + Header Files\expat - Header Files + Header Files\expat - Header Files + Header Files\expat - Header Files + Header Files\expat - Header Files + Header Files\expat - Header Files + Header Files\expat @@ -60,13 +69,18 @@ Source Files - Source Files + Source Files\expat - Source Files + Source Files\expat - Source Files + Source Files\expat - + + + Resource Files + + + \ No newline at end of file diff --git a/PCbuild/_freeze_importlib.vcxproj.filters b/PCbuild/_freeze_importlib.vcxproj.filters index ccad053a9f5..3ee9eb750d6 100644 --- a/PCbuild/_freeze_importlib.vcxproj.filters +++ b/PCbuild/_freeze_importlib.vcxproj.filters @@ -5,13 +5,8 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {eb238244-ace1-48fc-97a4-16ff886f8642} @@ -23,5 +18,11 @@ Source Files + + Python Files + + + Python Files + - + \ No newline at end of file diff --git a/PCbuild/_hashlib.vcxproj.filters b/PCbuild/_hashlib.vcxproj.filters index a9d993eb3ed..7a0700c007f 100644 --- a/PCbuild/_hashlib.vcxproj.filters +++ b/PCbuild/_hashlib.vcxproj.filters @@ -4,10 +4,18 @@ {cc45963d-bd25-4eb8-bdba-a5507090bca4} + + {67630fa4-76e4-4035-bced-043a6df1e2e0} + Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_lzma.vcxproj.filters b/PCbuild/_lzma.vcxproj.filters index 0c5ed74608e..e23e5399df4 100644 --- a/PCbuild/_lzma.vcxproj.filters +++ b/PCbuild/_lzma.vcxproj.filters @@ -4,10 +4,18 @@ {53e68eda-39fc-4336-a658-dc5f5d598760} + + {9e5ecf81-2940-4dd5-af98-58e98810d030} + Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_msi.vcxproj.filters b/PCbuild/_msi.vcxproj.filters index 7dec52de0b3..a94fb18e61e 100644 --- a/PCbuild/_msi.vcxproj.filters +++ b/PCbuild/_msi.vcxproj.filters @@ -4,10 +4,18 @@ {bdef7710-e433-4ac0-84e0-14f34454bd3e} + + {8513f324-7c13-4657-b463-5d686a8a5371} + Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_multiprocessing.vcxproj.filters b/PCbuild/_multiprocessing.vcxproj.filters index 78133ec0ec8..85caddb10db 100644 --- a/PCbuild/_multiprocessing.vcxproj.filters +++ b/PCbuild/_multiprocessing.vcxproj.filters @@ -7,6 +7,9 @@ {34615a62-f999-4659-83f5-19d17a644530} + + {1dcf6347-2248-42e1-ab3c-1b19f4f6f647} + @@ -21,4 +24,9 @@ Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_overlapped.vcxproj.filters b/PCbuild/_overlapped.vcxproj.filters index 78de8950559..29a9b77740b 100644 --- a/PCbuild/_overlapped.vcxproj.filters +++ b/PCbuild/_overlapped.vcxproj.filters @@ -4,10 +4,18 @@ {6f67c8db-7de7-4714-a967-2b0d4bc71f2e} + + {83fe502d-eca2-4505-b626-eddec9b6ea9f} + Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_queue.vcxproj.filters b/PCbuild/_queue.vcxproj.filters index 88b80826adf..ec48e9d3aed 100644 --- a/PCbuild/_queue.vcxproj.filters +++ b/PCbuild/_queue.vcxproj.filters @@ -1,16 +1,21 @@  - - - {c56a5dd3-7838-48e9-a781-855d8be7370f} + + {bc5dc97e-11b8-435a-82e7-2ef3c9b44f5e} + Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_socket.vcxproj.filters b/PCbuild/_socket.vcxproj.filters index 790ffa80dd4..453175c6a43 100644 --- a/PCbuild/_socket.vcxproj.filters +++ b/PCbuild/_socket.vcxproj.filters @@ -7,6 +7,9 @@ {1edfe0d0-7b9d-4dc8-a335-b21fef7cc77a} + + {f8efff18-28ed-4c6b-8e8d-fa816d9a81a8} + @@ -18,4 +21,9 @@ Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_sqlite3.vcxproj.filters b/PCbuild/_sqlite3.vcxproj.filters index dce77c96a80..51830f6a445 100644 --- a/PCbuild/_sqlite3.vcxproj.filters +++ b/PCbuild/_sqlite3.vcxproj.filters @@ -7,6 +7,9 @@ {814b187d-44ad-4f2b-baa7-18ca8a8a6a77} + + {225f58de-2bad-4e4d-bc0b-fe74ed6bf5f1} + @@ -66,4 +69,9 @@ Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_ssl.vcxproj.filters b/PCbuild/_ssl.vcxproj.filters index bd46b609840..716a69a41af 100644 --- a/PCbuild/_ssl.vcxproj.filters +++ b/PCbuild/_ssl.vcxproj.filters @@ -4,6 +4,9 @@ {695348f7-e9f6-4fe1-bc03-5f08ffc8095b} + + {1b18a2e6-040d-46c7-a9ac-ac2ec64fb5d6} + @@ -14,6 +17,8 @@ - + + Resource Files + \ No newline at end of file diff --git a/PCbuild/_testbuffer.vcxproj.filters b/PCbuild/_testbuffer.vcxproj.filters index eadf282750b..bea4260b9f7 100644 --- a/PCbuild/_testbuffer.vcxproj.filters +++ b/PCbuild/_testbuffer.vcxproj.filters @@ -4,10 +4,18 @@ {8d232240-921a-4bc2-87c3-93ffd3462f0a} + + {1e73201a-cca4-4b45-9484-262709cafee7} + Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_testcapi.vcxproj.filters b/PCbuild/_testcapi.vcxproj.filters index 7a6ad1a864e..53f64b7aa1e 100644 --- a/PCbuild/_testcapi.vcxproj.filters +++ b/PCbuild/_testcapi.vcxproj.filters @@ -4,10 +4,18 @@ {a76a90d8-8e8b-4c36-8f58-8bd46abe9f5e} + + {071b2ff4-e5a1-4e79-b0c5-cf46b0094a80} + Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_testconsole.vcxproj.filters b/PCbuild/_testconsole.vcxproj.filters index 0c25101e1b4..321e17785fd 100644 --- a/PCbuild/_testconsole.vcxproj.filters +++ b/PCbuild/_testconsole.vcxproj.filters @@ -5,18 +5,19 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - + Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_testembed.vcxproj.filters b/PCbuild/_testembed.vcxproj.filters index f7f9abeb1df..b90fd85f794 100644 --- a/PCbuild/_testembed.vcxproj.filters +++ b/PCbuild/_testembed.vcxproj.filters @@ -5,10 +5,6 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms @@ -19,4 +15,9 @@ Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_testimportmultiple.vcxproj.filters b/PCbuild/_testimportmultiple.vcxproj.filters index db0d0a65e12..8f63d134825 100644 --- a/PCbuild/_testimportmultiple.vcxproj.filters +++ b/PCbuild/_testimportmultiple.vcxproj.filters @@ -4,10 +4,18 @@ {1ec38ad9-1abf-4b80-8628-ac43ccba324b} + + {0ff128a6-7814-4f8e-826e-860a858104ee} + Source Files - + + + Resource Files + + + \ No newline at end of file diff --git a/PCbuild/_testinternalcapi.vcxproj.filters b/PCbuild/_testinternalcapi.vcxproj.filters index 4644f230be1..7734da0b7b4 100644 --- a/PCbuild/_testinternalcapi.vcxproj.filters +++ b/PCbuild/_testinternalcapi.vcxproj.filters @@ -4,10 +4,18 @@ {136fc5eb-7fe4-4486-8c6d-b49f37a00199} + + {acecc890-f8dd-4942-b6d2-1fd8f73a5d6c} + Source Files - + + + Resource Files + + + \ No newline at end of file diff --git a/PCbuild/_testmultiphase.vcxproj.filters b/PCbuild/_testmultiphase.vcxproj.filters index 0c25101e1b4..8df0a42e9f3 100644 --- a/PCbuild/_testmultiphase.vcxproj.filters +++ b/PCbuild/_testmultiphase.vcxproj.filters @@ -5,10 +5,6 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms @@ -19,4 +15,9 @@ Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_tkinter.vcxproj.filters b/PCbuild/_tkinter.vcxproj.filters index 4e5cd479e30..0d919439a76 100644 --- a/PCbuild/_tkinter.vcxproj.filters +++ b/PCbuild/_tkinter.vcxproj.filters @@ -4,6 +4,9 @@ {b9ce64dd-cb95-472d-bbe8-5583b2cd375b} + + {2bd3a90c-5b2e-45fb-9b2a-fbf1a4faf5f9} + @@ -13,4 +16,9 @@ Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_uuid.vcxproj.filters b/PCbuild/_uuid.vcxproj.filters index 17949292314..705902ff50c 100644 --- a/PCbuild/_uuid.vcxproj.filters +++ b/PCbuild/_uuid.vcxproj.filters @@ -5,10 +5,18 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + {4fa4dbfa-e069-4ab4-86a6-ad389b2ec407} + Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/_zoneinfo.vcxproj.filters b/PCbuild/_zoneinfo.vcxproj.filters index e3c3ef4c72a..57f31e05d56 100644 --- a/PCbuild/_zoneinfo.vcxproj.filters +++ b/PCbuild/_zoneinfo.vcxproj.filters @@ -1,16 +1,21 @@  - - - {2422278e-eeeb-4241-8182-433e2bc5a7fc} + + {0616fb85-7891-4790-83c2-005f906cf555} + Source Files - + + + Resource Files + + + \ No newline at end of file diff --git a/PCbuild/get_externals.bat b/PCbuild/get_externals.bat index fa27cdf369d..4171fd740c7 100644 --- a/PCbuild/get_externals.bat +++ b/PCbuild/get_externals.bat @@ -53,7 +53,7 @@ echo.Fetching external libraries... set libraries= set libraries=%libraries% bzip2-1.0.6 if NOT "%IncludeLibffiSrc%"=="false" set libraries=%libraries% libffi -if NOT "%IncludeSSLSrc%"=="false" set libraries=%libraries% openssl-1.1.1f +if NOT "%IncludeSSLSrc%"=="false" set libraries=%libraries% openssl-1.1.1g set libraries=%libraries% sqlite-3.31.1.0 if NOT "%IncludeTkinterSrc%"=="false" set libraries=%libraries% tcl-core-8.6.9.0 if NOT "%IncludeTkinterSrc%"=="false" set libraries=%libraries% tk-8.6.9.0 @@ -77,7 +77,7 @@ echo.Fetching external binaries... set binaries= if NOT "%IncludeLibffi%"=="false" set binaries=%binaries% libffi -if NOT "%IncludeSSL%"=="false" set binaries=%binaries% openssl-bin-1.1.1f +if NOT "%IncludeSSL%"=="false" set binaries=%binaries% openssl-bin-1.1.1g if NOT "%IncludeTkinter%"=="false" set binaries=%binaries% tcltk-8.6.9.0 if NOT "%IncludeSSLSrc%"=="false" set binaries=%binaries% nasm-2.11.06 diff --git a/PCbuild/lib.pyproj b/PCbuild/lib.pyproj index 7ce88e5690b..f0c51edb9d1 100644 --- a/PCbuild/lib.pyproj +++ b/PCbuild/lib.pyproj @@ -419,6 +419,7 @@ + diff --git a/PCbuild/liblzma.vcxproj b/PCbuild/liblzma.vcxproj index 9ec062e5255..a6bd59ec0ba 100644 --- a/PCbuild/liblzma.vcxproj +++ b/PCbuild/liblzma.vcxproj @@ -91,11 +91,8 @@ - WIN32;HAVE_CONFIG_H;_DEBUG;_LIB;%(PreprocessorDefinitions) - Level3 - ProgramDatabase - Disabled - $(lzmaDir)windows;$(lzmaDir)src/liblzma/common;$(lzmaDir)src/common;$(lzmaDir)src/liblzma/api;$(lzmaDir)src/liblzma/check;$(lzmaDir)src/liblzma/delta;$(lzmaDir)src/liblzma/lz;$(lzmaDir)src/liblzma/lzma;$(lzmaDir)src/liblzma/rangecoder;$(lzmaDir)src/liblzma/simple + WIN32;HAVE_CONFIG_H;_LIB;%(PreprocessorDefinitions) + $(lzmaDir)windows;$(lzmaDir)src/liblzma/common;$(lzmaDir)src/common;$(lzmaDir)src/liblzma/api;$(lzmaDir)src/liblzma/check;$(lzmaDir)src/liblzma/delta;$(lzmaDir)src/liblzma/lz;$(lzmaDir)src/liblzma/lzma;$(lzmaDir)src/liblzma/rangecoder;$(lzmaDir)src/liblzma/simple;%(AdditionalIncludeDirectories) 4028;4113;4133;4244;4267;4996;%(DisableSpecificWarnings) diff --git a/PCbuild/liblzma.vcxproj.filters b/PCbuild/liblzma.vcxproj.filters new file mode 100644 index 00000000000..3f58351fa9e --- /dev/null +++ b/PCbuild/liblzma.vcxproj.filters @@ -0,0 +1,435 @@ + + + + + {cb1870af-3c7e-48ba-bd7f-3e87468f8ed7} + + + {58761ffe-2af0-42a8-9f93-4e57e1954c36} + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/PCbuild/pcbuild.sln b/PCbuild/pcbuild.sln index 61db4e02ad3..4b6dc1e6771 100644 --- a/PCbuild/pcbuild.sln +++ b/PCbuild/pcbuild.sln @@ -1267,6 +1267,38 @@ Global {384C224A-7474-476E-A01B-750EA7DE918C}.Release|Win32.Build.0 = Release|Win32 {384C224A-7474-476E-A01B-750EA7DE918C}.Release|x64.ActiveCfg = Release|x64 {384C224A-7474-476E-A01B-750EA7DE918C}.Release|x64.Build.0 = Release|x64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Debug|ARM.ActiveCfg = Debug|ARM + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Debug|ARM.Build.0 = Debug|ARM + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Debug|ARM64.Build.0 = Debug|ARM64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Debug|Win32.ActiveCfg = Debug|Win32 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Debug|Win32.Build.0 = Debug|Win32 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Debug|x64.ActiveCfg = Debug|x64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Debug|x64.Build.0 = Debug|x64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGInstrument|ARM.ActiveCfg = PGInstrument|ARM + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGInstrument|ARM.Build.0 = PGInstrument|ARM + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGInstrument|ARM64.ActiveCfg = PGInstrument|ARM64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGInstrument|ARM64.Build.0 = PGInstrument|ARM64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGUpdate|ARM.ActiveCfg = PGUpdate|ARM + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGUpdate|ARM.Build.0 = PGUpdate|ARM + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGUpdate|ARM64.ActiveCfg = PGUpdate|ARM64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGUpdate|ARM64.Build.0 = PGUpdate|ARM64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Release|ARM.ActiveCfg = Release|ARM + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Release|ARM.Build.0 = Release|ARM + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Release|ARM64.ActiveCfg = Release|ARM64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Release|ARM64.Build.0 = Release|ARM64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Release|Win32.ActiveCfg = Release|Win32 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Release|Win32.Build.0 = Release|Win32 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Release|x64.ActiveCfg = Release|x64 + {FCBE1EF2-E0F0-40B1-88B5-00A35D378742}.Release|x64.Build.0 = Release|x64 {78D80A15-BD8C-44E2-B49E-1F05B0A0A687}.Debug|ARM.ActiveCfg = Debug|ARM {78D80A15-BD8C-44E2-B49E-1F05B0A0A687}.Debug|ARM.Build.0 = Debug|ARM {78D80A15-BD8C-44E2-B49E-1F05B0A0A687}.Debug|ARM64.ActiveCfg = Debug|ARM64 diff --git a/PCbuild/pyexpat.vcxproj.filters b/PCbuild/pyexpat.vcxproj.filters index f8d46026c9c..fd22fc8c477 100644 --- a/PCbuild/pyexpat.vcxproj.filters +++ b/PCbuild/pyexpat.vcxproj.filters @@ -7,6 +7,9 @@ {5af9d40c-fc46-4640-ad84-3d1dd34a71d7} + + {f1dbbdb5-41e5-4a88-bf8e-13da010c0ce4} + @@ -30,4 +33,9 @@ Source Files - + + + Resource Files + + + \ No newline at end of file diff --git a/PCbuild/pylauncher.vcxproj.filters b/PCbuild/pylauncher.vcxproj.filters index e4b23d2af83..17d0389ca50 100644 --- a/PCbuild/pylauncher.vcxproj.filters +++ b/PCbuild/pylauncher.vcxproj.filters @@ -5,10 +5,6 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms diff --git a/PCbuild/pyproject.props b/PCbuild/pyproject.props index bb918b28e90..c659d14ff8d 100644 --- a/PCbuild/pyproject.props +++ b/PCbuild/pyproject.props @@ -26,11 +26,12 @@ <_PlatformPreprocessorDefinition>_WIN32; <_PlatformPreprocessorDefinition Condition="$(Platform) == 'x64'">_WIN64;_M_X64; <_PydPreprocessorDefinition Condition="$(TargetExt) == '.pyd'">Py_BUILD_CORE_MODULE; + <_Py3NamePreprocessorDefinition>PY3_DLLNAME=L"$(Py3DllName)"; $(PySourcePath)Include;$(PySourcePath)Include\internal;$(PySourcePath)PC;$(IntDir);%(AdditionalIncludeDirectories) - WIN32;$(_PlatformPreprocessorDefinition)$(_DebugPreprocessorDefinition)$(_PydPreprocessorDefinition)%(PreprocessorDefinitions) + WIN32;$(_Py3NamePreprocessorDefinition);$(_PlatformPreprocessorDefinition)$(_DebugPreprocessorDefinition)$(_PydPreprocessorDefinition)%(PreprocessorDefinitions) MaxSpeed true @@ -80,7 +81,7 @@ $(PySourcePath)PC;$(PySourcePath)Include;$(IntDir);%(AdditionalIncludeDirectories) - $(_DebugPreprocessorDefinition)%(PreprocessorDefinitions) + ORIGINAL_FILENAME=\"$(TargetName)$(TargetExt)\";FIELD3=$(Field3Value);$(_DebugPreprocessorDefinition)%(PreprocessorDefinitions) 0x0409 @@ -95,21 +96,6 @@ - - - - - - - diff --git a/PCbuild/pyshellext.vcxproj b/PCbuild/pyshellext.vcxproj index 655054e3723..ea432d6bc9a 100644 --- a/PCbuild/pyshellext.vcxproj +++ b/PCbuild/pyshellext.vcxproj @@ -96,7 +96,7 @@ version.lib;shlwapi.lib;%(AdditionalDependencies) Console - ..\PC\pyshellext$(PyDebugExt).def + ..\PC\pyshellext.def true @@ -104,11 +104,9 @@ - - diff --git a/PCbuild/pyshellext.vcxproj.filters b/PCbuild/pyshellext.vcxproj.filters index 648e499f6f4..77cd3060857 100644 --- a/PCbuild/pyshellext.vcxproj.filters +++ b/PCbuild/pyshellext.vcxproj.filters @@ -5,10 +5,6 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms @@ -19,11 +15,6 @@ Source Files - - - Source Files - - Resource Files @@ -33,8 +24,5 @@ Source Files - - Source Files - \ No newline at end of file diff --git a/PCbuild/python.props b/PCbuild/python.props index d1d16d61be8..bf6f3716ba5 100644 --- a/PCbuild/python.props +++ b/PCbuild/python.props @@ -62,8 +62,8 @@ $(ExternalsDir)libffi\ $(ExternalsDir)libffi\$(ArchName)\ $(libffiOutDir)include - $(ExternalsDir)openssl-1.1.1f\ - $(ExternalsDir)openssl-bin-1.1.1f\$(ArchName)\ + $(ExternalsDir)openssl-1.1.1g\ + $(ExternalsDir)openssl-bin-1.1.1g\$(ArchName)\ $(opensslOutDir)include $(ExternalsDir)\nasm-2.11.06\ $(ExternalsDir)\zlib-1.2.11\ @@ -203,6 +203,8 @@ python$(MajorVersionNumber)$(MinorVersionNumber)$(PyDebugExt) + + python3$(PyDebugExt) .cp$(MajorVersionNumber)$(MinorVersionNumber)-win32 diff --git a/PCbuild/python3dll.vcxproj b/PCbuild/python3dll.vcxproj index ef344bed49e..ec22e6fc76e 100644 --- a/PCbuild/python3dll.vcxproj +++ b/PCbuild/python3dll.vcxproj @@ -88,31 +88,16 @@ <_ProjectFileVersion>10.0.30319.1 - <_Machine>X86 - <_Machine Condition="$(Platform) == 'x64'">X64 - <_Machine Condition="$(Platform) == 'ARM'">ARM - <_Machine Condition="$(Platform) == 'ARM64'">ARM64 - $(ExtensionsToDeleteOnClean);$(IntDir)python3_d.def;$(IntDir)python3stub.def + PYTHON_DLL_NAME="$(PyDllName)";%(PreprocessorDefinitions) false - $(OutDir)$(TargetName)stub.lib - $(PySourcePath)PC\python3.def - $(IntDir)python3_d.def - DllMain + true - - lib /nologo /def:"$(IntDir)python3stub.def" /out:"$(OutDir)$(TargetName)stub.lib" /MACHINE:$(_Machine) - Rebuilding $(TargetName)stub.lib - $(OutDir)$(TargetName)stub.lib - - - - @@ -122,62 +107,4 @@ - - - - <_DefLines Remove="@(_DefLines)" /> - <_Lines Remove="@(_Lines)" /> - <_OriginalLines Remove="@(_OriginalLines)" /> - - - - - - - - - <_Pattern1>(=python$(MajorVersionNumber)$(MinorVersionNumber))\. - <_Sub1>$1_d. - <_Pattern2>"python3" - <_Sub2>"python3_d" - - - <_Lines Include="@(_DefLines)"> - $([System.Text.RegularExpressions.Regex]::Replace($([System.Text.RegularExpressions.Regex]::Replace(`%(Identity)`, `$(_Pattern1)`, `$(_Sub1)`)), `$(_Pattern2)`, `$(_Sub2)`)) - - - - - - - - - - <_DefLines Remove="@(_DefLines)" /> - <_Lines Remove="@(_Lines)" /> - <_OriginalLines Remove="@(_OriginalLines)" /> - - - - - - - - - <_Pattern>^[\w.]+=.+?\.([^ ]+).*$ - <_Sub>$1 - - - <_Lines Include="EXPORTS" /> - <_Symbols Include="@(_DefLines)" Condition="$([System.Text.RegularExpressions.Regex]::IsMatch(`%(Identity)`, `$(_Pattern)`))"> - $([System.Text.RegularExpressions.Regex]::Replace(`%(Identity)`, `$(_Pattern)`, `$(_Sub)`)) - - <_Lines Include="@(_Symbols->'%(Symbol)')" /> - - - - - \ No newline at end of file diff --git a/PCbuild/python3dll.vcxproj.filters b/PCbuild/python3dll.vcxproj.filters index d250c45254e..ba562dfae02 100644 --- a/PCbuild/python3dll.vcxproj.filters +++ b/PCbuild/python3dll.vcxproj.filters @@ -5,20 +5,11 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav - - - Source Files - - Source Files diff --git a/PCbuild/python_uwp.vcxproj.filters b/PCbuild/python_uwp.vcxproj.filters new file mode 100644 index 00000000000..79e87461eb1 --- /dev/null +++ b/PCbuild/python_uwp.vcxproj.filters @@ -0,0 +1,26 @@ + + + + + {fd8bf000-0bbe-4fd4-ac49-29036e5a5c5a} + + + {a0d4ce0b-a7b5-4a77-b6c2-d2ddb9bd49b8} + + + + + Resource Files + + + + + Resource Files + + + + + Source Files + + + \ No newline at end of file diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index b6b0cf3e991..db26e38911b 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -115,7 +115,6 @@ - @@ -135,8 +134,10 @@ + + @@ -162,15 +163,12 @@ - - - + - @@ -178,6 +176,7 @@ + @@ -185,6 +184,7 @@ + @@ -195,7 +195,7 @@ - + @@ -209,15 +209,14 @@ - - + @@ -279,10 +278,9 @@ - - - + + @@ -343,8 +341,6 @@ - - @@ -417,19 +413,13 @@ - - - - - - - - - - + + + + @@ -460,7 +450,6 @@ - diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 10dfffba611..1f3883768c9 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -31,6 +31,12 @@ {c3e03a5c-56c7-45fd-8543-e5d2326b907d} + + {86ffb5eb-c423-43aa-b736-a8850d3277df} + + + {875bf4f2-ac42-46bd-b703-8371a824ec32} + @@ -42,9 +48,6 @@ Include - - Include - Include @@ -78,72 +81,6 @@ Include - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - Include @@ -183,111 +120,9 @@ Include - - Include - - - Include - Include - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - - - Include - Include @@ -318,9 +153,6 @@ Include - - Include - Include @@ -336,9 +168,6 @@ Include - - Include - Include @@ -522,9 +351,6 @@ Objects - - Parser - Parser @@ -564,6 +390,189 @@ Include + + Parser + + + Parser + + + Include + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include\cpython + + + Include + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + + + Include\internal + Modules\zlib @@ -644,9 +653,6 @@ Modules - - Modules - Modules @@ -710,9 +716,6 @@ Modules - - Modules - Modules @@ -908,39 +911,9 @@ Objects - - Parser - - - Parser - - - Parser - - - Parser - - - Parser - - - Parser - - - Parser - Parser - - Parser - - - Parser - - - Parser - Parser @@ -989,9 +962,6 @@ Python - - Python - Python @@ -1031,12 +1001,6 @@ Python - - Python - - - Python - Modules @@ -1154,9 +1118,6 @@ Objects - - PC - Modules @@ -1193,10 +1154,34 @@ Modules\zlib + + Python + + + Parser + + + Parser + + + Parser + + + Modules + + + Parser + + + Python + + + Objects + Resource Files - + \ No newline at end of file diff --git a/PCbuild/pythonw.vcxproj.filters b/PCbuild/pythonw.vcxproj.filters index 259866fbcc2..20d87051e25 100644 --- a/PCbuild/pythonw.vcxproj.filters +++ b/PCbuild/pythonw.vcxproj.filters @@ -8,14 +8,14 @@ {e1d8ea6b-c65d-42f4-9eed-6010846ed378} - - - Resource Files - - Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/pythonw_uwp.vcxproj.filters b/PCbuild/pythonw_uwp.vcxproj.filters new file mode 100644 index 00000000000..2f39bdea9e9 --- /dev/null +++ b/PCbuild/pythonw_uwp.vcxproj.filters @@ -0,0 +1,26 @@ + + + + + {de05f656-4dcb-4fe7-9946-5c325ea2d842} + + + {4102e199-3e5c-42d0-b37b-d42394b20d9e} + + + + + Resource Files + + + + + Resource Files + + + + + Source Files + + + \ No newline at end of file diff --git a/PCbuild/pywlauncher.vcxproj.filters b/PCbuild/pywlauncher.vcxproj.filters index e4b23d2af83..17d0389ca50 100644 --- a/PCbuild/pywlauncher.vcxproj.filters +++ b/PCbuild/pywlauncher.vcxproj.filters @@ -5,10 +5,6 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms diff --git a/PCbuild/regen.vcxproj b/PCbuild/regen.vcxproj index d46fb997dbd..90d6dc68d54 100644 --- a/PCbuild/regen.vcxproj +++ b/PCbuild/regen.vcxproj @@ -133,10 +133,6 @@ - - - - @@ -155,22 +151,11 @@ - - - - - - - - - - - - + - - + + @@ -205,25 +190,20 @@ - - + + + - - - - - - diff --git a/PCbuild/select.vcxproj.filters b/PCbuild/select.vcxproj.filters index 55a2fc834a3..5354820dd49 100644 --- a/PCbuild/select.vcxproj.filters +++ b/PCbuild/select.vcxproj.filters @@ -4,10 +4,18 @@ {98346077-900c-4c7a-852f-a23470e37b40} + + {b47a8e6c-47c0-4490-aa91-1a3624a0905c} + Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/sqlite3.vcxproj.filters b/PCbuild/sqlite3.vcxproj.filters index 86680c1c383..76662ed68d0 100644 --- a/PCbuild/sqlite3.vcxproj.filters +++ b/PCbuild/sqlite3.vcxproj.filters @@ -7,6 +7,9 @@ {0e842fe2-176b-4e83-9d1f-0ad13a859efd} + + {0248795a-00c9-4090-ad61-55ae23438598} + @@ -21,4 +24,9 @@ Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/unicodedata.vcxproj.filters b/PCbuild/unicodedata.vcxproj.filters index 20e640ee11e..7ff97835c96 100644 --- a/PCbuild/unicodedata.vcxproj.filters +++ b/PCbuild/unicodedata.vcxproj.filters @@ -7,6 +7,9 @@ {e2c055bb-ec62-4bbc-aa1c-d88da4d4ad1c} + + {d04f3447-67b0-42aa-b84f-9fc0029d5af7} + @@ -21,4 +24,9 @@ Source Files + + + Resource Files + + \ No newline at end of file diff --git a/PCbuild/venvlauncher.vcxproj.filters b/PCbuild/venvlauncher.vcxproj.filters new file mode 100644 index 00000000000..ec13936bf6c --- /dev/null +++ b/PCbuild/venvlauncher.vcxproj.filters @@ -0,0 +1,26 @@ + + + + + {8f3ab79e-3cba-4e6d-82b2-559ce946de58} + + + {4a2423af-e5d1-4c88-b308-d71b768977df} + + + + + Resource Files + + + + + Resource Files + + + + + Source Files + + + \ No newline at end of file diff --git a/PCbuild/venvwlauncher.vcxproj.filters b/PCbuild/venvwlauncher.vcxproj.filters new file mode 100644 index 00000000000..8addc13e977 --- /dev/null +++ b/PCbuild/venvwlauncher.vcxproj.filters @@ -0,0 +1,26 @@ + + + + + {7683f248-9c32-4e72-a329-5bd84993f63a} + + + {61b34b26-ce53-405d-a743-b370ff505887} + + + + + Source Files + + + + + Resource Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/PCbuild/winsound.vcxproj.filters b/PCbuild/winsound.vcxproj.filters index 7d08931b186..67758026382 100644 --- a/PCbuild/winsound.vcxproj.filters +++ b/PCbuild/winsound.vcxproj.filters @@ -5,10 +5,18 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + {6be42502-398f-4bec-8677-8809a2da0eef} + Source Files + + + Resource Files + + \ No newline at end of file diff --git a/Parser/acceler.c b/Parser/acceler.c deleted file mode 100644 index e515833e1dd..00000000000 --- a/Parser/acceler.c +++ /dev/null @@ -1,123 +0,0 @@ - -/* Parser accelerator module */ - -/* The parser as originally conceived had disappointing performance. - This module does some precomputation that speeds up the selection - of a DFA based upon a token, turning a search through an array - into a simple indexing operation. The parser now cannot work - without the accelerators installed. Note that the accelerators - are installed dynamically when the parser is initialized, they - are not part of the static data structure written on graminit.[ch] - by the parser generator. */ - -#include "Python.h" -#include "grammar.h" -#include "node.h" -#include "token.h" -#include "parser.h" - -/* Forward references */ -static void fixdfa(grammar *, const dfa *); -static void fixstate(grammar *, state *); - -void -PyGrammar_AddAccelerators(grammar *g) -{ - int i; - const dfa *d = g->g_dfa; - for (i = g->g_ndfas; --i >= 0; d++) - fixdfa(g, d); - g->g_accel = 1; -} - -void -PyGrammar_RemoveAccelerators(grammar *g) -{ - int i; - g->g_accel = 0; - const dfa *d = g->g_dfa; - for (i = g->g_ndfas; --i >= 0; d++) { - state *s; - int j; - s = d->d_state; - for (j = 0; j < d->d_nstates; j++, s++) { - if (s->s_accel) - PyObject_FREE(s->s_accel); - s->s_accel = NULL; - } - } -} - -static void -fixdfa(grammar *g, const dfa *d) -{ - state *s; - int j; - s = d->d_state; - for (j = 0; j < d->d_nstates; j++, s++) - fixstate(g, s); -} - -static void -fixstate(grammar *g, state *s) -{ - const arc *a; - int k; - int *accel; - int nl = g->g_ll.ll_nlabels; - s->s_accept = 0; - accel = (int *) PyObject_MALLOC(nl * sizeof(int)); - if (accel == NULL) { - fprintf(stderr, "no mem to build parser accelerators\n"); - exit(1); - } - for (k = 0; k < nl; k++) - accel[k] = -1; - a = s->s_arc; - for (k = s->s_narcs; --k >= 0; a++) { - int lbl = a->a_lbl; - const label *l = &g->g_ll.ll_label[lbl]; - int type = l->lb_type; - if (a->a_arrow >= (1 << 7)) { - printf("XXX too many states!\n"); - continue; - } - if (ISNONTERMINAL(type)) { - const dfa *d1 = PyGrammar_FindDFA(g, type); - int ibit; - if (type - NT_OFFSET >= (1 << 7)) { - printf("XXX too high nonterminal number!\n"); - continue; - } - for (ibit = 0; ibit < g->g_ll.ll_nlabels; ibit++) { - if (testbit(d1->d_first, ibit)) { - if (accel[ibit] != -1) - printf("XXX ambiguity!\n"); - accel[ibit] = a->a_arrow | (1 << 7) | - ((type - NT_OFFSET) << 8); - } - } - } - else if (lbl == EMPTY) - s->s_accept = 1; - else if (lbl >= 0 && lbl < nl) - accel[lbl] = a->a_arrow; - } - while (nl > 0 && accel[nl-1] == -1) - nl--; - for (k = 0; k < nl && accel[k] == -1;) - k++; - if (k < nl) { - int i; - s->s_accel = (int *) PyObject_MALLOC((nl-k) * sizeof(int)); - if (s->s_accel == NULL) { - fprintf(stderr, "no mem to add parser accelerators\n"); - exit(1); - } - s->s_lower = k; - s->s_upper = nl; - for (i = 0; k < nl; i++, k++) - s->s_accel[i] = accel[k]; - } - PyObject_FREE(accel); -} diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index f8729cd170b..6fe44b99f79 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -387,7 +387,7 @@ class PickleVisitor(EmitVisitor): class Obj2ModPrototypeVisitor(PickleVisitor): def visitProduct(self, prod, name): - code = "static int obj2ast_%s(PyObject* obj, %s* out, PyArena* arena);" + code = "static int obj2ast_%s(astmodulestate *state, PyObject* obj, %s* out, PyArena* arena);" self.emit(code % (name, get_c_type(name)), 0) visitSum = visitProduct @@ -397,7 +397,7 @@ class Obj2ModVisitor(PickleVisitor): def funcHeader(self, name): ctype = get_c_type(name) self.emit("int", 0) - self.emit("obj2ast_%s(PyObject* obj, %s* out, PyArena* arena)" % (name, ctype), 0) + self.emit("obj2ast_%s(astmodulestate *state, PyObject* obj, %s* out, PyArena* arena)" % (name, ctype), 0) self.emit("{", 0) self.emit("int isinstance;", 1) self.emit("", 0) @@ -419,7 +419,7 @@ class Obj2ModVisitor(PickleVisitor): self.funcHeader(name) for t in sum.types: line = ("isinstance = PyObject_IsInstance(obj, " - "astmodulestate_global->%s_type);") + "state->%s_type);") self.emit(line % (t.name,), 1) self.emit("if (isinstance == -1) {", 1) self.emit("return 1;", 2) @@ -448,7 +448,7 @@ class Obj2ModVisitor(PickleVisitor): for a in sum.attributes: self.visitField(a, name, sum=sum, depth=1) for t in sum.types: - self.emit("tp = astmodulestate_global->%s_type;" % (t.name,), 1) + self.emit("tp = state->%s_type;" % (t.name,), 1) self.emit("isinstance = PyObject_IsInstance(obj, tp);", 1) self.emit("if (isinstance == -1) {", 1) self.emit("return 1;", 2) @@ -479,7 +479,7 @@ class Obj2ModVisitor(PickleVisitor): def visitProduct(self, prod, name): ctype = get_c_type(name) self.emit("int", 0) - self.emit("obj2ast_%s(PyObject* obj, %s* out, PyArena* arena)" % (name, ctype), 0) + self.emit("obj2ast_%s(astmodulestate *state, PyObject* obj, %s* out, PyArena* arena)" % (name, ctype), 0) self.emit("{", 0) self.emit("PyObject* tmp = NULL;", 1) for f in prod.fields: @@ -525,7 +525,7 @@ class Obj2ModVisitor(PickleVisitor): def visitField(self, field, name, sum=None, prod=None, depth=0): ctype = get_c_type(field.type) - line = "if (_PyObject_LookupAttr(obj, astmodulestate_global->%s, &tmp) < 0) {" + line = "if (_PyObject_LookupAttr(obj, state->%s, &tmp) < 0) {" self.emit(line % field.name, depth) self.emit("return 1;", depth+1) self.emit("}", depth) @@ -568,7 +568,7 @@ class Obj2ModVisitor(PickleVisitor): self.emit("%s val;" % ctype, depth+2) self.emit("PyObject *tmp2 = PyList_GET_ITEM(tmp, i);", depth+2) self.emit("Py_INCREF(tmp2);", depth+2) - self.emit("res = obj2ast_%s(tmp2, &val, arena);" % + self.emit("res = obj2ast_%s(state, tmp2, &val, arena);" % field.type, depth+2, reflow=False) self.emit("Py_DECREF(tmp2);", depth+2) self.emit("if (res != 0) goto failed;", depth+2) @@ -582,7 +582,7 @@ class Obj2ModVisitor(PickleVisitor): self.emit("asdl_seq_SET(%s, i, val);" % field.name, depth+2) self.emit("}", depth+1) else: - self.emit("res = obj2ast_%s(tmp, &%s, arena);" % + self.emit("res = obj2ast_%s(state, tmp, &%s, arena);" % (field.type, field.name), depth+1) self.emit("if (res != 0) goto failed;", depth+1) @@ -604,7 +604,7 @@ class PyTypesDeclareVisitor(PickleVisitor): def visitProduct(self, prod, name): self.emit_type("%s_type" % name) - self.emit("static PyObject* ast2obj_%s(void*);" % name, 0) + self.emit("static PyObject* ast2obj_%s(astmodulestate *state, void*);" % name, 0) if prod.attributes: for a in prod.attributes: self.emit_identifier(a.name) @@ -634,7 +634,7 @@ class PyTypesDeclareVisitor(PickleVisitor): ptype = get_c_type(name) for t in sum.types: self.emit_singleton("%s_singleton" % t.name) - self.emit("static PyObject* ast2obj_%s(%s);" % (name, ptype), 0) + self.emit("static PyObject* ast2obj_%s(astmodulestate *state, %s);" % (name, ptype), 0) for t in sum.types: self.visitConstructor(t, name) @@ -673,6 +673,7 @@ ast_dealloc(AST_object *self) static int ast_traverse(AST_object *self, visitproc visit, void *arg) { + Py_VISIT(Py_TYPE(self)); Py_VISIT(self->dict); return 0; } @@ -687,10 +688,15 @@ ast_clear(AST_object *self) static int ast_type_init(PyObject *self, PyObject *args, PyObject *kw) { + astmodulestate *state = get_global_ast_state(); + if (state == NULL) { + return -1; + } + Py_ssize_t i, numfields = 0; int res = -1; PyObject *key, *value, *fields; - if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { + if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) { goto cleanup; } if (fields) { @@ -758,8 +764,13 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw) static PyObject * ast_type_reduce(PyObject *self, PyObject *unused) { + astmodulestate *state = get_global_ast_state(); + if (state == NULL) { + return NULL; + } + PyObject *dict; - if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { + if (_PyObject_LookupAttr(self, state->__dict__, &dict) < 0) { return NULL; } if (dict) { @@ -808,7 +819,8 @@ static PyType_Spec AST_type_spec = { }; static PyObject * -make_type(const char *type, PyObject* base, const char* const* fields, int num_fields, const char *doc) +make_type(astmodulestate *state, const char *type, PyObject* base, + const char* const* fields, int num_fields, const char *doc) { PyObject *fnames, *result; int i; @@ -824,16 +836,16 @@ make_type(const char *type, PyObject* base, const char* const* fields, int num_f } result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}", type, base, - astmodulestate_global->_fields, fnames, - astmodulestate_global->__module__, - astmodulestate_global->ast, - astmodulestate_global->__doc__, doc); + state->_fields, fnames, + state->__module__, + state->ast, + state->__doc__, doc); Py_DECREF(fnames); return result; } static int -add_attributes(PyObject *type, const char * const *attrs, int num_fields) +add_attributes(astmodulestate *state, PyObject *type, const char * const *attrs, int num_fields) { int i, result; PyObject *s, *l = PyTuple_New(num_fields); @@ -847,14 +859,14 @@ add_attributes(PyObject *type, const char * const *attrs, int num_fields) } PyTuple_SET_ITEM(l, i, s); } - result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; + result = PyObject_SetAttr(type, state->_attributes, l) >= 0; Py_DECREF(l); return result; } /* Conversion AST -> Python */ -static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) +static PyObject* ast2obj_list(astmodulestate *state, asdl_seq *seq, PyObject* (*func)(astmodulestate *state, void*)) { Py_ssize_t i, n = asdl_seq_LEN(seq); PyObject *result = PyList_New(n); @@ -862,7 +874,7 @@ static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) if (!result) return NULL; for (i = 0; i < n; i++) { - value = func(asdl_seq_GET(seq, i)); + value = func(state, asdl_seq_GET(seq, i)); if (!value) { Py_DECREF(result); return NULL; @@ -872,7 +884,7 @@ static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) return result; } -static PyObject* ast2obj_object(void *o) +static PyObject* ast2obj_object(astmodulestate *Py_UNUSED(state), void *o) { if (!o) o = Py_None; @@ -883,14 +895,14 @@ static PyObject* ast2obj_object(void *o) #define ast2obj_identifier ast2obj_object #define ast2obj_string ast2obj_object -static PyObject* ast2obj_int(long b) +static PyObject* ast2obj_int(astmodulestate *Py_UNUSED(state), long b) { return PyLong_FromLong(b); } /* Conversion Python -> AST */ -static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) +static int obj2ast_object(astmodulestate *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena) { if (obj == Py_None) obj = NULL; @@ -905,7 +917,7 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) return 0; } -static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) +static int obj2ast_constant(astmodulestate *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena) { if (PyArena_AddPyObject(arena, obj) < 0) { *out = NULL; @@ -916,25 +928,25 @@ static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) return 0; } -static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) +static int obj2ast_identifier(astmodulestate *state, PyObject* obj, PyObject** out, PyArena* arena) { if (!PyUnicode_CheckExact(obj) && obj != Py_None) { PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); return 1; } - return obj2ast_object(obj, out, arena); + return obj2ast_object(state, obj, out, arena); } -static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) +static int obj2ast_string(astmodulestate *state, PyObject* obj, PyObject** out, PyArena* arena) { if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); return 1; } - return obj2ast_object(obj, out, arena); + return obj2ast_object(state, obj, out, arena); } -static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) +static int obj2ast_int(astmodulestate* Py_UNUSED(state), PyObject* obj, int* out, PyArena* arena) { int i; if (!PyLong_Check(obj)) { @@ -949,13 +961,13 @@ static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) return 0; } -static int add_ast_fields(void) +static int add_ast_fields(astmodulestate *state) { PyObject *empty_tuple; empty_tuple = PyTuple_New(0); if (!empty_tuple || - PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || - PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { + PyObject_SetAttrString(state->AST_type, "_fields", empty_tuple) < 0 || + PyObject_SetAttrString(state->AST_type, "_attributes", empty_tuple) < 0) { Py_XDECREF(empty_tuple); return -1; } @@ -965,20 +977,13 @@ static int add_ast_fields(void) """, 0, reflow=False) - self.emit("static int init_types(void)",0) + self.emit("static int init_types(astmodulestate *state)",0) self.emit("{", 0) - self.emit("PyObject *m;", 1) - self.emit("if (PyState_FindModule(&_astmodule) == NULL) {", 1) - self.emit("m = PyModule_Create(&_astmodule);", 2) - self.emit("if (!m) return 0;", 2) - self.emit("PyState_AddModule(m, &_astmodule);", 2) - self.emit("}", 1) - self.emit("astmodulestate *state = astmodulestate_global;", 1) self.emit("if (state->initialized) return 1;", 1) - self.emit("if (init_identifiers() < 0) return 0;", 1) + self.emit("if (init_identifiers(state) < 0) return 0;", 1) self.emit("state->AST_type = PyType_FromSpec(&AST_type_spec);", 1) self.emit("if (!state->AST_type) return 0;", 1) - self.emit("if (add_ast_fields() < 0) return 0;", 1) + self.emit("if (add_ast_fields(state) < 0) return 0;", 1) for dfn in mod.dfns: self.visit(dfn) self.emit("state->initialized = 1;", 1) @@ -990,31 +995,31 @@ static int add_ast_fields(void) fields = name+"_fields" else: fields = "NULL" - self.emit('state->%s_type = make_type("%s", state->AST_type, %s, %d,' % + self.emit('state->%s_type = make_type(state, "%s", state->AST_type, %s, %d,' % (name, name, fields, len(prod.fields)), 1) self.emit('%s);' % reflow_c_string(asdl_of(name, prod), 2), 2, reflow=False) self.emit("if (!state->%s_type) return 0;" % name, 1) self.emit_type("AST_type") self.emit_type("%s_type" % name) if prod.attributes: - self.emit("if (!add_attributes(state->%s_type, %s_attributes, %d)) return 0;" % + self.emit("if (!add_attributes(state, state->%s_type, %s_attributes, %d)) return 0;" % (name, name, len(prod.attributes)), 1) else: - self.emit("if (!add_attributes(state->%s_type, NULL, 0)) return 0;" % name, 1) + self.emit("if (!add_attributes(state, state->%s_type, NULL, 0)) return 0;" % name, 1) self.emit_defaults(name, prod.fields, 1) self.emit_defaults(name, prod.attributes, 1) def visitSum(self, sum, name): - self.emit('state->%s_type = make_type("%s", state->AST_type, NULL, 0,' % + self.emit('state->%s_type = make_type(state, "%s", state->AST_type, NULL, 0,' % (name, name), 1) self.emit('%s);' % reflow_c_string(asdl_of(name, sum), 2), 2, reflow=False) self.emit_type("%s_type" % name) self.emit("if (!state->%s_type) return 0;" % name, 1) if sum.attributes: - self.emit("if (!add_attributes(state->%s_type, %s_attributes, %d)) return 0;" % + self.emit("if (!add_attributes(state, state->%s_type, %s_attributes, %d)) return 0;" % (name, name, len(sum.attributes)), 1) else: - self.emit("if (!add_attributes(state->%s_type, NULL, 0)) return 0;" % name, 1) + self.emit("if (!add_attributes(state, state->%s_type, NULL, 0)) return 0;" % name, 1) self.emit_defaults(name, sum.attributes, 1) simple = is_simple(sum) for t in sum.types: @@ -1025,7 +1030,7 @@ static int add_ast_fields(void) fields = cons.name+"_fields" else: fields = "NULL" - self.emit('state->%s_type = make_type("%s", state->%s_type, %s, %d,' % + self.emit('state->%s_type = make_type(state, "%s", state->%s_type, %s, %d,' % (cons.name, cons.name, name, fields, len(cons.fields)), 1) self.emit('%s);' % reflow_c_string(asdl_of(cons.name, cons), 2), 2, reflow=False) self.emit("if (!state->%s_type) return 0;" % cons.name, 1) @@ -1048,33 +1053,55 @@ static int add_ast_fields(void) class ASTModuleVisitor(PickleVisitor): def visitModule(self, mod): - self.emit("PyMODINIT_FUNC", 0) - self.emit("PyInit__ast(void)", 0) + self.emit("static int", 0) + self.emit("astmodule_exec(PyObject *m)", 0) self.emit("{", 0) - self.emit("PyObject *m;", 1) - self.emit("if (!init_types()) return NULL;", 1) - self.emit('m = PyState_FindModule(&_astmodule);', 1) - self.emit("if (!m) return NULL;", 1) - self.emit('if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {', 1) - self.emit('goto error;', 2) + self.emit('astmodulestate *state = get_ast_state(m);', 1) + self.emit("", 0) + + self.emit("if (!init_types(state)) {", 1) + self.emit("return -1;", 2) + self.emit("}", 1) + self.emit('if (PyModule_AddObject(m, "AST", state->AST_type) < 0) {', 1) + self.emit('return -1;', 2) self.emit('}', 1) - self.emit('Py_INCREF(astmodulestate(m)->AST_type);', 1) + self.emit('Py_INCREF(state->AST_type);', 1) self.emit('if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {', 1) - self.emit("goto error;", 2) + self.emit("return -1;", 2) self.emit('}', 1) self.emit('if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {', 1) - self.emit("goto error;", 2) + self.emit("return -1;", 2) self.emit('}', 1) self.emit('if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {', 1) - self.emit("goto error;", 2) + self.emit("return -1;", 2) self.emit('}', 1) for dfn in mod.dfns: self.visit(dfn) - self.emit("return m;", 1) - self.emit("error:", 0) - self.emit("Py_DECREF(m);", 1) - self.emit("return NULL;", 1) + self.emit("return 0;", 1) self.emit("}", 0) + self.emit("", 0) + self.emit(""" +static PyModuleDef_Slot astmodule_slots[] = { + {Py_mod_exec, astmodule_exec}, + {0, NULL} +}; + +static struct PyModuleDef _astmodule = { + PyModuleDef_HEAD_INIT, + .m_name = "_ast", + .m_size = sizeof(astmodulestate), + .m_slots = astmodule_slots, + .m_traverse = astmodule_traverse, + .m_clear = astmodule_clear, + .m_free = astmodule_free, +}; + +PyMODINIT_FUNC +PyInit__ast(void) +{ + return PyModuleDef_Init(&_astmodule); +} +""".strip(), 0, reflow=False) def visitProduct(self, prod, name): self.addObj(name) @@ -1089,10 +1116,10 @@ class ASTModuleVisitor(PickleVisitor): def addObj(self, name): self.emit("if (PyModule_AddObject(m, \"%s\", " - "astmodulestate_global->%s_type) < 0) {" % (name, name), 1) - self.emit("goto error;", 2) + "state->%s_type) < 0) {" % (name, name), 1) + self.emit("return -1;", 2) self.emit('}', 1) - self.emit("Py_INCREF(astmodulestate(m)->%s_type);" % name, 1) + self.emit("Py_INCREF(state->%s_type);" % name, 1) _SPECIALIZED_SEQUENCES = ('stmt', 'expr') @@ -1126,7 +1153,7 @@ class ObjVisitor(PickleVisitor): def func_begin(self, name): ctype = get_c_type(name) self.emit("PyObject*", 0) - self.emit("ast2obj_%s(void* _o)" % (name), 0) + self.emit("ast2obj_%s(astmodulestate *state, void* _o)" % (name), 0) self.emit("{", 0) self.emit("%s o = (%s)_o;" % (ctype, ctype), 1) self.emit("PyObject *result = NULL, *value = NULL;", 1) @@ -1134,7 +1161,6 @@ class ObjVisitor(PickleVisitor): self.emit('if (!o) {', 1) self.emit("Py_RETURN_NONE;", 2) self.emit("}", 1) - self.emit('', 0) def func_end(self): self.emit("return result;", 1) @@ -1156,43 +1182,43 @@ class ObjVisitor(PickleVisitor): self.visitConstructor(t, i + 1, name) self.emit("}", 1) for a in sum.attributes: - self.emit("value = ast2obj_%s(o->%s);" % (a.type, a.name), 1) + self.emit("value = ast2obj_%s(state, o->%s);" % (a.type, a.name), 1) self.emit("if (!value) goto failed;", 1) - self.emit('if (PyObject_SetAttr(result, astmodulestate_global->%s, value) < 0)' % a.name, 1) + self.emit('if (PyObject_SetAttr(result, state->%s, value) < 0)' % a.name, 1) self.emit('goto failed;', 2) self.emit('Py_DECREF(value);', 1) self.func_end() def simpleSum(self, sum, name): - self.emit("PyObject* ast2obj_%s(%s_ty o)" % (name, name), 0) + self.emit("PyObject* ast2obj_%s(astmodulestate *state, %s_ty o)" % (name, name), 0) self.emit("{", 0) self.emit("switch(o) {", 1) for t in sum.types: self.emit("case %s:" % t.name, 2) - self.emit("Py_INCREF(astmodulestate_global->%s_singleton);" % t.name, 3) - self.emit("return astmodulestate_global->%s_singleton;" % t.name, 3) + self.emit("Py_INCREF(state->%s_singleton);" % t.name, 3) + self.emit("return state->%s_singleton;" % t.name, 3) self.emit("}", 1) self.emit("Py_UNREACHABLE();", 1); self.emit("}", 0) def visitProduct(self, prod, name): self.func_begin(name) - self.emit("tp = (PyTypeObject *)astmodulestate_global->%s_type;" % name, 1) + self.emit("tp = (PyTypeObject *)state->%s_type;" % name, 1) self.emit("result = PyType_GenericNew(tp, NULL, NULL);", 1); self.emit("if (!result) return NULL;", 1) for field in prod.fields: self.visitField(field, name, 1, True) for a in prod.attributes: - self.emit("value = ast2obj_%s(o->%s);" % (a.type, a.name), 1) + self.emit("value = ast2obj_%s(state, o->%s);" % (a.type, a.name), 1) self.emit("if (!value) goto failed;", 1) - self.emit("if (PyObject_SetAttr(result, astmodulestate_global->%s, value) < 0)" % a.name, 1) + self.emit("if (PyObject_SetAttr(result, state->%s, value) < 0)" % a.name, 1) self.emit('goto failed;', 2) self.emit('Py_DECREF(value);', 1) self.func_end() def visitConstructor(self, cons, enum, name): self.emit("case %s_kind:" % cons.name, 1) - self.emit("tp = (PyTypeObject *)astmodulestate_global->%s_type;" % cons.name, 2) + self.emit("tp = (PyTypeObject *)state->%s_type;" % cons.name, 2) self.emit("result = PyType_GenericNew(tp, NULL, NULL);", 2); self.emit("if (!result) goto failed;", 2) for f in cons.fields: @@ -1208,7 +1234,7 @@ class ObjVisitor(PickleVisitor): value = "o->v.%s.%s" % (name, field.name) self.set(field, value, depth) emit("if (!value) goto failed;", 0) - emit("if (PyObject_SetAttr(result, astmodulestate_global->%s, value) == -1)" % field.name, 0) + emit("if (PyObject_SetAttr(result, state->%s, value) == -1)" % field.name, 0) emit("goto failed;", 1) emit("Py_DECREF(value);", 0) @@ -1236,14 +1262,14 @@ class ObjVisitor(PickleVisitor): self.emit("if (!value) goto failed;", depth+1) self.emit("for(i = 0; i < n; i++)", depth+1) # This cannot fail, so no need for error handling - self.emit("PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(%s, i)));" % value, + self.emit("PyList_SET_ITEM(value, i, ast2obj_cmpop(state, (cmpop_ty)asdl_seq_GET(%s, i)));" % value, depth+2, reflow=False) self.emit("}", depth) else: - self.emit("value = ast2obj_list(%s, ast2obj_%s);" % (value, field.type), depth) + self.emit("value = ast2obj_list(state, %s, ast2obj_%s);" % (value, field.type), depth) else: ctype = get_c_type(field.type) - self.emit("value = ast2obj_%s(%s);" % (field.type, value), depth, reflow=False) + self.emit("value = ast2obj_%s(state, %s);" % (field.type, value), depth, reflow=False) class PartingShots(StaticVisitor): @@ -1251,15 +1277,16 @@ class PartingShots(StaticVisitor): CODE = """ PyObject* PyAST_mod2obj(mod_ty t) { - if (!init_types()) + astmodulestate *state = get_global_ast_state(); + if (state == NULL) { return NULL; - return ast2obj_mod(t); + } + return ast2obj_mod(state, t); } /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) { - PyObject *req_type[3]; const char * const req_name[] = {"Module", "Expression", "Interactive"}; int isinstance; @@ -1267,15 +1294,14 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) return NULL; } - req_type[0] = astmodulestate_global->Module_type; - req_type[1] = astmodulestate_global->Expression_type; - req_type[2] = astmodulestate_global->Interactive_type; + astmodulestate *state = get_global_ast_state(); + PyObject *req_type[3]; + req_type[0] = state->Module_type; + req_type[1] = state->Expression_type; + req_type[2] = state->Interactive_type; assert(0 <= mode && mode <= 2); - if (!init_types()) - return NULL; - isinstance = PyObject_IsInstance(ast, req_type[mode]); if (isinstance == -1) return NULL; @@ -1286,7 +1312,7 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) } mod_ty res = NULL; - if (obj2ast_mod(ast, &res, arena) != 0) + if (obj2ast_mod(state, ast, &res, arena) != 0) return NULL; else return res; @@ -1294,9 +1320,11 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) int PyAST_Check(PyObject* obj) { - if (!init_types()) + astmodulestate *state = get_global_ast_state(); + if (state == NULL) { return -1; - return PyObject_IsInstance(obj, astmodulestate_global->AST_type); + } + return PyObject_IsInstance(obj, state->AST_type); } """ @@ -1346,22 +1374,53 @@ def generate_module_def(f, mod): f.write(' PyObject *' + s + ';\n') f.write('} astmodulestate;\n\n') f.write(""" -#define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o)) +static astmodulestate* +get_ast_state(PyObject *module) +{ + void *state = PyModule_GetState(module); + assert(state != NULL); + return (astmodulestate*)state; +} + +static astmodulestate* +get_global_ast_state(void) +{ + _Py_IDENTIFIER(_ast); + PyObject *name = _PyUnicode_FromId(&PyId__ast); // borrowed reference + if (name == NULL) { + return NULL; + } + PyObject *module = PyImport_GetModule(name); + if (module == NULL) { + if (PyErr_Occurred()) { + return NULL; + } + module = PyImport_Import(name); + if (module == NULL) { + return NULL; + } + } + astmodulestate *state = get_ast_state(module); + Py_DECREF(module); + return state; +} static int astmodule_clear(PyObject *module) { + astmodulestate *state = get_ast_state(module); """) for s in module_state: - f.write(" Py_CLEAR(astmodulestate(module)->" + s + ');\n') + f.write(" Py_CLEAR(state->" + s + ');\n') f.write(""" return 0; } static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) { + astmodulestate *state = get_ast_state(module); """) for s in module_state: - f.write(" Py_VISIT(astmodulestate(module)->" + s + ');\n') + f.write(" Py_VISIT(state->" + s + ');\n') f.write(""" return 0; } @@ -1370,24 +1429,9 @@ static void astmodule_free(void* module) { astmodule_clear((PyObject*)module); } -static struct PyModuleDef _astmodule = { - PyModuleDef_HEAD_INIT, - "_ast", - NULL, - sizeof(astmodulestate), - NULL, - NULL, - astmodule_traverse, - astmodule_clear, - astmodule_free, -}; - -#define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) - """) - f.write('static int init_identifiers(void)\n') + f.write('static int init_identifiers(astmodulestate *state)\n') f.write('{\n') - f.write(' astmodulestate *state = astmodulestate_global;\n') for identifier in state_strings: f.write(' if ((state->' + identifier) f.write(' = PyUnicode_InternFromString("') diff --git a/Parser/grammar1.c b/Parser/grammar1.c deleted file mode 100644 index c702040efdf..00000000000 --- a/Parser/grammar1.c +++ /dev/null @@ -1,47 +0,0 @@ - -/* Grammar subroutines needed by parser */ - -#include "Python.h" -#include "grammar.h" -#include "token.h" - -/* Return the DFA for the given type */ - -const dfa * -PyGrammar_FindDFA(grammar *g, int type) -{ - /* Massive speed-up */ - const dfa *d = &g->g_dfa[type - NT_OFFSET]; - assert(d->d_type == type); - return d; -} - -const char * -PyGrammar_LabelRepr(label *lb) -{ - static char buf[100]; - - if (lb->lb_type == ENDMARKER) - return "EMPTY"; - else if (ISNONTERMINAL(lb->lb_type)) { - if (lb->lb_str == NULL) { - PyOS_snprintf(buf, sizeof(buf), "NT%d", lb->lb_type); - return buf; - } - else - return lb->lb_str; - } - else if (lb->lb_type < N_TOKENS) { - if (lb->lb_str == NULL) - return _PyParser_TokenNames[lb->lb_type]; - else { - PyOS_snprintf(buf, sizeof(buf), "%.32s(%.32s)", - _PyParser_TokenNames[lb->lb_type], lb->lb_str); - return buf; - } - } - else { - Py_FatalError("invalid grammar label"); - return NULL; - } -} diff --git a/Parser/listnode.c b/Parser/listnode.c deleted file mode 100644 index c806b98e48c..00000000000 --- a/Parser/listnode.c +++ /dev/null @@ -1,71 +0,0 @@ - -/* List a node on a file */ - -#include "Python.h" -#include "pycore_interp.h" // PyInterpreterState.parser -#include "pycore_pystate.h" // _PyInterpreterState_GET() -#include "token.h" -#include "node.h" - -/* Forward */ -static void list1node(FILE *, node *); -static void listnode(FILE *, node *); - -void -PyNode_ListTree(node *n) -{ - listnode(stdout, n); -} - -static void -listnode(FILE *fp, node *n) -{ - PyInterpreterState *interp = _PyInterpreterState_GET(); - - interp->parser.listnode.level = 0; - interp->parser.listnode.atbol = 1; - list1node(fp, n); -} - -static void -list1node(FILE *fp, node *n) -{ - PyInterpreterState *interp; - - if (n == NULL) - return; - if (ISNONTERMINAL(TYPE(n))) { - int i; - for (i = 0; i < NCH(n); i++) - list1node(fp, CHILD(n, i)); - } - else if (ISTERMINAL(TYPE(n))) { - interp = _PyInterpreterState_GET(); - switch (TYPE(n)) { - case INDENT: - interp->parser.listnode.level++; - break; - case DEDENT: - interp->parser.listnode.level--; - break; - default: - if (interp->parser.listnode.atbol) { - int i; - for (i = 0; i < interp->parser.listnode.level; ++i) - fprintf(fp, "\t"); - interp->parser.listnode.atbol = 0; - } - if (TYPE(n) == NEWLINE) { - if (STR(n) != NULL) - fprintf(fp, "%s", STR(n)); - fprintf(fp, "\n"); - interp->parser.listnode.atbol = 1; - } - else - fprintf(fp, "%s ", STR(n)); - break; - } - } - else - fprintf(fp, "? "); -} diff --git a/Parser/myreadline.c b/Parser/myreadline.c index 04c2793225c..2dd362321aa 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -24,25 +24,36 @@ static PyThread_type_lock _PyOS_ReadlineLock = NULL; int (*PyOS_InputHook)(void) = NULL; /* This function restarts a fgets() after an EINTR error occurred - except if PyOS_InterruptOccurred() returns true. */ + except if _PyOS_InterruptOccurred() returns true. */ static int -my_fgets(char *buf, int len, FILE *fp) +my_fgets(PyThreadState* tstate, char *buf, int len, FILE *fp) { #ifdef MS_WINDOWS - HANDLE hInterruptEvent; + HANDLE handle; + _Py_BEGIN_SUPPRESS_IPH + handle = (HANDLE)_get_osfhandle(fileno(fp)); + _Py_END_SUPPRESS_IPH + + /* bpo-40826: fgets(fp) does crash if fileno(fp) is closed */ + if (handle == INVALID_HANDLE_VALUE) { + return -1; /* EOF */ + } #endif - char *p; - int err; + while (1) { - if (PyOS_InputHook != NULL) + if (PyOS_InputHook != NULL) { (void)(PyOS_InputHook)(); + } + errno = 0; clearerr(fp); - p = fgets(buf, len, fp); - if (p != NULL) + char *p = fgets(buf, len, fp); + if (p != NULL) { return 0; /* No error */ - err = errno; + } + int err = errno; + #ifdef MS_WINDOWS /* Ctrl-C anywhere on the line or Ctrl-Z if the only character on a line will set ERROR_OPERATION_ABORTED. Under normal @@ -58,7 +69,7 @@ my_fgets(char *buf, int len, FILE *fp) through to check for EOF. */ if (GetLastError()==ERROR_OPERATION_ABORTED) { - hInterruptEvent = _PyOS_SigintEvent(); + HANDLE hInterruptEvent = _PyOS_SigintEvent(); switch (WaitForSingleObjectEx(hInterruptEvent, 10, FALSE)) { case WAIT_OBJECT_0: ResetEvent(hInterruptEvent); @@ -68,23 +79,27 @@ my_fgets(char *buf, int len, FILE *fp) } } #endif /* MS_WINDOWS */ + if (feof(fp)) { clearerr(fp); return -1; /* EOF */ } + #ifdef EINTR if (err == EINTR) { - int s; - PyEval_RestoreThread(_PyOS_ReadlineTState); - s = PyErr_CheckSignals(); + PyEval_RestoreThread(tstate); + int s = PyErr_CheckSignals(); PyEval_SaveThread(); - if (s < 0) - return 1; - /* try again */ + + if (s < 0) { + return 1; + } + /* try again */ continue; } #endif - if (PyOS_InterruptOccurred()) { + + if (_PyOS_InterruptOccurred(tstate)) { return 1; /* Interrupt */ } return -2; /* Error */ @@ -98,7 +113,7 @@ my_fgets(char *buf, int len, FILE *fp) extern char _get_console_type(HANDLE handle); char * -_PyOS_WindowsConsoleReadline(HANDLE hStdIn) +_PyOS_WindowsConsoleReadline(PyThreadState *tstate, HANDLE hStdIn) { static wchar_t wbuf_local[1024 * 16]; const DWORD chunk_size = 1024; @@ -133,11 +148,12 @@ _PyOS_WindowsConsoleReadline(HANDLE hStdIn) if (WaitForSingleObjectEx(hInterruptEvent, 100, FALSE) == WAIT_OBJECT_0) { ResetEvent(hInterruptEvent); - PyEval_RestoreThread(_PyOS_ReadlineTState); + PyEval_RestoreThread(tstate); s = PyErr_CheckSignals(); PyEval_SaveThread(); - if (s < 0) + if (s < 0) { goto exit; + } } break; } @@ -150,17 +166,22 @@ _PyOS_WindowsConsoleReadline(HANDLE hStdIn) if (wbuf == wbuf_local) { wbuf[total_read] = '\0'; wbuf = (wchar_t*)PyMem_RawMalloc(wbuflen * sizeof(wchar_t)); - if (wbuf) + if (wbuf) { wcscpy_s(wbuf, wbuflen, wbuf_local); + } else { + PyEval_RestoreThread(tstate); PyErr_NoMemory(); + PyEval_SaveThread(); goto exit; } } else { wchar_t *tmp = PyMem_RawRealloc(wbuf, wbuflen * sizeof(wchar_t)); if (tmp == NULL) { + PyEval_RestoreThread(tstate); PyErr_NoMemory(); + PyEval_SaveThread(); goto exit; } wbuf = tmp; @@ -169,33 +190,45 @@ _PyOS_WindowsConsoleReadline(HANDLE hStdIn) if (wbuf[0] == '\x1a') { buf = PyMem_RawMalloc(1); - if (buf) + if (buf) { buf[0] = '\0'; + } else { + PyEval_RestoreThread(tstate); PyErr_NoMemory(); + PyEval_SaveThread(); } goto exit; } - u8len = WideCharToMultiByte(CP_UTF8, 0, wbuf, total_read, NULL, 0, NULL, NULL); + u8len = WideCharToMultiByte(CP_UTF8, 0, + wbuf, total_read, + NULL, 0, + NULL, NULL); buf = PyMem_RawMalloc(u8len + 1); if (buf == NULL) { + PyEval_RestoreThread(tstate); PyErr_NoMemory(); + PyEval_SaveThread(); goto exit; } - u8len = WideCharToMultiByte(CP_UTF8, 0, wbuf, total_read, buf, u8len, NULL, NULL); + + u8len = WideCharToMultiByte(CP_UTF8, 0, + wbuf, total_read, + buf, u8len, + NULL, NULL); buf[u8len] = '\0'; exit: - if (wbuf != wbuf_local) + if (wbuf != wbuf_local) { PyMem_RawFree(wbuf); + } if (err) { - PyEval_RestoreThread(_PyOS_ReadlineTState); + PyEval_RestoreThread(tstate); PyErr_SetFromWindowsErr(err); PyEval_SaveThread(); } - return buf; } @@ -209,6 +242,8 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt) { size_t n; char *p, *pr; + PyThreadState *tstate = _PyOS_ReadlineTState; + assert(tstate != NULL); #ifdef MS_WINDOWS if (!Py_LegacyWindowsStdioFlag && sys_stdin == stdin) { @@ -230,7 +265,9 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt) if (wlen) { wbuf = PyMem_RawMalloc(wlen * sizeof(wchar_t)); if (wbuf == NULL) { + PyEval_RestoreThread(tstate); PyErr_NoMemory(); + PyEval_SaveThread(); return NULL; } wlen = MultiByteToWideChar(CP_UTF8, 0, prompt, -1, @@ -249,7 +286,7 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt) } } clearerr(sys_stdin); - return _PyOS_WindowsConsoleReadline(hStdIn); + return _PyOS_WindowsConsoleReadline(tstate, hStdIn); } } #endif @@ -257,16 +294,19 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt) n = 100; p = (char *)PyMem_RawMalloc(n); if (p == NULL) { + PyEval_RestoreThread(tstate); PyErr_NoMemory(); + PyEval_SaveThread(); return NULL; } fflush(sys_stdout); - if (prompt) + if (prompt) { fprintf(stderr, "%s", prompt); + } fflush(stderr); - switch (my_fgets(p, (int)n, sys_stdin)) { + switch (my_fgets(tstate, p, (int)n, sys_stdin)) { case 0: /* Normal case */ break; case 1: /* Interrupt */ @@ -278,29 +318,40 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt) *p = '\0'; break; } + n = strlen(p); while (n > 0 && p[n-1] != '\n') { size_t incr = n+2; if (incr > INT_MAX) { PyMem_RawFree(p); + PyEval_RestoreThread(tstate); PyErr_SetString(PyExc_OverflowError, "input line too long"); + PyEval_SaveThread(); return NULL; } + pr = (char *)PyMem_RawRealloc(p, n + incr); if (pr == NULL) { PyMem_RawFree(p); + PyEval_RestoreThread(tstate); PyErr_NoMemory(); + PyEval_SaveThread(); return NULL; } p = pr; - if (my_fgets(p+n, (int)incr, sys_stdin) != 0) + + if (my_fgets(tstate, p+n, (int)incr, sys_stdin) != 0) { break; + } n += strlen(p+n); } + pr = (char *)PyMem_RawRealloc(p, n+1); if (pr == NULL) { PyMem_RawFree(p); + PyEval_RestoreThread(tstate); PyErr_NoMemory(); + PyEval_SaveThread(); return NULL; } return pr; @@ -323,7 +374,8 @@ PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt) char *rv, *res; size_t len; - if (_PyOS_ReadlineTState == _PyThreadState_GET()) { + PyThreadState *tstate = _PyThreadState_GET(); + if (_PyOS_ReadlineTState == tstate) { PyErr_SetString(PyExc_RuntimeError, "can't re-enter readline"); return NULL; @@ -342,7 +394,7 @@ PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt) } } - _PyOS_ReadlineTState = _PyThreadState_GET(); + _PyOS_ReadlineTState = tstate; Py_BEGIN_ALLOW_THREADS PyThread_acquire_lock(_PyOS_ReadlineLock, 1); diff --git a/Parser/node.c b/Parser/node.c deleted file mode 100644 index 8789e01e9b8..00000000000 --- a/Parser/node.c +++ /dev/null @@ -1,189 +0,0 @@ -/* Parse tree node implementation */ - -#include "Python.h" -#include "node.h" -#include "errcode.h" - -node * -PyNode_New(int type) -{ - node *n = (node *) PyObject_MALLOC(1 * sizeof(node)); - if (n == NULL) - return NULL; - n->n_type = type; - n->n_str = NULL; - n->n_lineno = 0; - n->n_end_lineno = 0; - n->n_col_offset = 0; - n->n_end_col_offset = -1; - n->n_nchildren = 0; - n->n_child = NULL; - return n; -} - -/* See comments at XXXROUNDUP below. Returns -1 on overflow. */ -static int -fancy_roundup(int n) -{ - /* Round up to the closest power of 2 >= n. */ - int result = 256; - assert(n > 128); - while (result < n) { - result <<= 1; - if (result <= 0) - return -1; - } - return result; -} - -/* A gimmick to make massive numbers of reallocs quicker. The result is - * a number >= the input. In PyNode_AddChild, it's used like so, when - * we're about to add child number current_size + 1: - * - * if XXXROUNDUP(current_size) < XXXROUNDUP(current_size + 1): - * allocate space for XXXROUNDUP(current_size + 1) total children - * else: - * we already have enough space - * - * Since a node starts out empty, we must have - * - * XXXROUNDUP(0) < XXXROUNDUP(1) - * - * so that we allocate space for the first child. One-child nodes are very - * common (presumably that would change if we used a more abstract form - * of syntax tree), so to avoid wasting memory it's desirable that - * XXXROUNDUP(1) == 1. That in turn forces XXXROUNDUP(0) == 0. - * - * Else for 2 <= n <= 128, we round up to the closest multiple of 4. Why 4? - * Rounding up to a multiple of an exact power of 2 is very efficient, and - * most nodes with more than one child have <= 4 kids. - * - * Else we call fancy_roundup() to grow proportionately to n. We've got an - * extreme case then (like test_longexp.py), and on many platforms doing - * anything less than proportional growth leads to exorbitant runtime - * (e.g., MacPython), or extreme fragmentation of user address space (e.g., - * Win98). - * - * In a run of compileall across the 2.3a0 Lib directory, Andrew MacIntyre - * reported that, with this scheme, 89% of PyObject_REALLOC calls in - * PyNode_AddChild passed 1 for the size, and 9% passed 4. So this usually - * wastes very little memory, but is very effective at sidestepping - * platform-realloc disasters on vulnerable platforms. - * - * Note that this would be straightforward if a node stored its current - * capacity. The code is tricky to avoid that. - */ -#define XXXROUNDUP(n) ((n) <= 1 ? (n) : \ - (n) <= 128 ? (int)_Py_SIZE_ROUND_UP((n), 4) : \ - fancy_roundup(n)) - - -void -_PyNode_FinalizeEndPos(node *n) -{ - int nch = NCH(n); - node *last; - if (nch == 0) { - return; - } - last = CHILD(n, nch - 1); - _PyNode_FinalizeEndPos(last); - n->n_end_lineno = last->n_end_lineno; - n->n_end_col_offset = last->n_end_col_offset; -} - -int -PyNode_AddChild(node *n1, int type, char *str, int lineno, int col_offset, - int end_lineno, int end_col_offset) -{ - const int nch = n1->n_nchildren; - int current_capacity; - int required_capacity; - node *n; - - // finalize end position of previous node (if any) - if (nch > 0) { - _PyNode_FinalizeEndPos(CHILD(n1, nch - 1)); - } - - if (nch == INT_MAX || nch < 0) - return E_OVERFLOW; - - current_capacity = XXXROUNDUP(nch); - required_capacity = XXXROUNDUP(nch + 1); - if (current_capacity < 0 || required_capacity < 0) - return E_OVERFLOW; - if (current_capacity < required_capacity) { - if ((size_t)required_capacity > SIZE_MAX / sizeof(node)) { - return E_NOMEM; - } - n = n1->n_child; - n = (node *) PyObject_REALLOC(n, - required_capacity * sizeof(node)); - if (n == NULL) - return E_NOMEM; - n1->n_child = n; - } - - n = &n1->n_child[n1->n_nchildren++]; - n->n_type = type; - n->n_str = str; - n->n_lineno = lineno; - n->n_col_offset = col_offset; - n->n_end_lineno = end_lineno; // this and below will be updates after all children are added. - n->n_end_col_offset = end_col_offset; - n->n_nchildren = 0; - n->n_child = NULL; - return 0; -} - -/* Forward */ -static void freechildren(node *); -static Py_ssize_t sizeofchildren(node *n); - - -void -PyNode_Free(node *n) -{ - if (n != NULL) { - freechildren(n); - PyObject_FREE(n); - } -} - -Py_ssize_t -_PyNode_SizeOf(node *n) -{ - Py_ssize_t res = 0; - - if (n != NULL) - res = sizeof(node) + sizeofchildren(n); - return res; -} - -static void -freechildren(node *n) -{ - int i; - for (i = NCH(n); --i >= 0; ) - freechildren(CHILD(n, i)); - if (n->n_child != NULL) - PyObject_FREE(n->n_child); - if (STR(n) != NULL) - PyObject_FREE(STR(n)); -} - -static Py_ssize_t -sizeofchildren(node *n) -{ - Py_ssize_t res = 0; - int i; - for (i = NCH(n); --i >= 0; ) - res += sizeofchildren(CHILD(n, i)); - if (n->n_child != NULL) - /* allocated size of n->n_child array */ - res += XXXROUNDUP(NCH(n)) * sizeof(node); - if (STR(n) != NULL) - res += strlen(STR(n)) + 1; - return res; -} diff --git a/Parser/parser.c b/Parser/parser.c index a61b2f5ebf7..75dc7176a5e 100644 --- a/Parser/parser.c +++ b/Parser/parser.c @@ -1,463 +1,24722 @@ +// @generated by pegen.py from ./Grammar/python.gram +#include "pegen.h" -/* Parser implementation */ - -/* For a description, see the comments at end of this file */ - -/* XXX To do: error recovery */ - -#include "Python.h" -#include "token.h" -#include "grammar.h" -#include "node.h" -#include "parser.h" -#include "errcode.h" -#include "graminit.h" - - -#ifdef Py_DEBUG +#if defined(Py_DEBUG) && defined(Py_BUILD_CORE) extern int Py_DebugFlag; -#define D(x) if (!Py_DebugFlag); else x +#define D(x) if (Py_DebugFlag) x; #else #define D(x) #endif +static const int n_keyword_lists = 9; +static KeywordToken *reserved_keywords[] = { + (KeywordToken[]) {{NULL, -1}}, + (KeywordToken[]) {{NULL, -1}}, + (KeywordToken[]) { + {"if", 510}, + {"in", 518}, + {"as", 520}, + {"is", 527}, + {"or", 531}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"del", 503}, + {"try", 511}, + {"for", 517}, + {"def", 523}, + {"not", 526}, + {"and", 532}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"pass", 502}, + {"from", 514}, + {"elif", 515}, + {"else", 516}, + {"with", 519}, + {"True", 528}, + {"None", 530}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"raise", 501}, + {"yield", 504}, + {"break", 506}, + {"while", 512}, + {"class", 524}, + {"False", 529}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"return", 500}, + {"assert", 505}, + {"global", 508}, + {"import", 513}, + {"except", 521}, + {"lambda", 525}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"finally", 522}, + {NULL, -1}, + }, + (KeywordToken[]) { + {"continue", 507}, + {"nonlocal", 509}, + {NULL, -1}, + }, +}; +#define file_type 1000 +#define interactive_type 1001 +#define eval_type 1002 +#define func_type_type 1003 +#define fstring_type 1004 +#define type_expressions_type 1005 +#define statements_type 1006 +#define statement_type 1007 +#define statement_newline_type 1008 +#define simple_stmt_type 1009 +#define small_stmt_type 1010 +#define compound_stmt_type 1011 +#define assignment_type 1012 +#define augassign_type 1013 +#define global_stmt_type 1014 +#define nonlocal_stmt_type 1015 +#define yield_stmt_type 1016 +#define assert_stmt_type 1017 +#define del_stmt_type 1018 +#define import_stmt_type 1019 +#define import_name_type 1020 +#define import_from_type 1021 +#define import_from_targets_type 1022 +#define import_from_as_names_type 1023 +#define import_from_as_name_type 1024 +#define dotted_as_names_type 1025 +#define dotted_as_name_type 1026 +#define dotted_name_type 1027 // Left-recursive +#define if_stmt_type 1028 +#define elif_stmt_type 1029 +#define else_block_type 1030 +#define while_stmt_type 1031 +#define for_stmt_type 1032 +#define with_stmt_type 1033 +#define with_item_type 1034 +#define try_stmt_type 1035 +#define except_block_type 1036 +#define finally_block_type 1037 +#define return_stmt_type 1038 +#define raise_stmt_type 1039 +#define function_def_type 1040 +#define function_def_raw_type 1041 +#define func_type_comment_type 1042 +#define params_type 1043 +#define parameters_type 1044 +#define slash_no_default_type 1045 +#define slash_with_default_type 1046 +#define star_etc_type 1047 +#define kwds_type 1048 +#define param_no_default_type 1049 +#define param_with_default_type 1050 +#define param_maybe_default_type 1051 +#define param_type 1052 +#define annotation_type 1053 +#define default_type 1054 +#define decorators_type 1055 +#define class_def_type 1056 +#define class_def_raw_type 1057 +#define block_type 1058 +#define expressions_list_type 1059 +#define star_expressions_type 1060 +#define star_expression_type 1061 +#define star_named_expressions_type 1062 +#define star_named_expression_type 1063 +#define named_expression_type 1064 +#define annotated_rhs_type 1065 +#define expressions_type 1066 +#define expression_type 1067 +#define lambdef_type 1068 +#define lambda_params_type 1069 +#define lambda_parameters_type 1070 +#define lambda_slash_no_default_type 1071 +#define lambda_slash_with_default_type 1072 +#define lambda_star_etc_type 1073 +#define lambda_kwds_type 1074 +#define lambda_param_no_default_type 1075 +#define lambda_param_with_default_type 1076 +#define lambda_param_maybe_default_type 1077 +#define lambda_param_type 1078 +#define disjunction_type 1079 +#define conjunction_type 1080 +#define inversion_type 1081 +#define comparison_type 1082 +#define compare_op_bitwise_or_pair_type 1083 +#define eq_bitwise_or_type 1084 +#define noteq_bitwise_or_type 1085 +#define lte_bitwise_or_type 1086 +#define lt_bitwise_or_type 1087 +#define gte_bitwise_or_type 1088 +#define gt_bitwise_or_type 1089 +#define notin_bitwise_or_type 1090 +#define in_bitwise_or_type 1091 +#define isnot_bitwise_or_type 1092 +#define is_bitwise_or_type 1093 +#define bitwise_or_type 1094 // Left-recursive +#define bitwise_xor_type 1095 // Left-recursive +#define bitwise_and_type 1096 // Left-recursive +#define shift_expr_type 1097 // Left-recursive +#define sum_type 1098 // Left-recursive +#define term_type 1099 // Left-recursive +#define factor_type 1100 +#define power_type 1101 +#define await_primary_type 1102 +#define primary_type 1103 // Left-recursive +#define slices_type 1104 +#define slice_type 1105 +#define atom_type 1106 +#define strings_type 1107 +#define list_type 1108 +#define listcomp_type 1109 +#define tuple_type 1110 +#define group_type 1111 +#define genexp_type 1112 +#define set_type 1113 +#define setcomp_type 1114 +#define dict_type 1115 +#define dictcomp_type 1116 +#define double_starred_kvpairs_type 1117 +#define double_starred_kvpair_type 1118 +#define kvpair_type 1119 +#define for_if_clauses_type 1120 +#define for_if_clause_type 1121 +#define yield_expr_type 1122 +#define arguments_type 1123 +#define args_type 1124 +#define kwargs_type 1125 +#define starred_expression_type 1126 +#define kwarg_or_starred_type 1127 +#define kwarg_or_double_starred_type 1128 +#define star_targets_type 1129 +#define star_targets_seq_type 1130 +#define star_target_type 1131 +#define star_atom_type 1132 +#define single_target_type 1133 +#define single_subscript_attribute_target_type 1134 +#define del_targets_type 1135 +#define del_target_type 1136 +#define del_t_atom_type 1137 +#define targets_type 1138 +#define target_type 1139 +#define t_primary_type 1140 // Left-recursive +#define t_lookahead_type 1141 +#define t_atom_type 1142 +#define incorrect_arguments_type 1143 +#define invalid_kwarg_type 1144 +#define invalid_named_expression_type 1145 +#define invalid_assignment_type 1146 +#define invalid_ann_assign_target_type 1147 +#define invalid_del_stmt_type 1148 +#define invalid_block_type 1149 +#define invalid_comprehension_type 1150 +#define invalid_dict_comprehension_type 1151 +#define invalid_parameters_type 1152 +#define invalid_lambda_parameters_type 1153 +#define invalid_star_etc_type 1154 +#define invalid_lambda_star_etc_type 1155 +#define invalid_double_type_comments_type 1156 +#define invalid_with_item_type 1157 +#define invalid_for_target_type 1158 +#define invalid_group_type 1159 +#define invalid_import_from_targets_type 1160 +#define _loop0_1_type 1161 +#define _loop0_2_type 1162 +#define _loop0_4_type 1163 +#define _gather_3_type 1164 +#define _loop0_6_type 1165 +#define _gather_5_type 1166 +#define _loop0_8_type 1167 +#define _gather_7_type 1168 +#define _loop0_10_type 1169 +#define _gather_9_type 1170 +#define _loop1_11_type 1171 +#define _loop0_13_type 1172 +#define _gather_12_type 1173 +#define _tmp_14_type 1174 +#define _tmp_15_type 1175 +#define _tmp_16_type 1176 +#define _tmp_17_type 1177 +#define _tmp_18_type 1178 +#define _tmp_19_type 1179 +#define _tmp_20_type 1180 +#define _tmp_21_type 1181 +#define _loop1_22_type 1182 +#define _tmp_23_type 1183 +#define _tmp_24_type 1184 +#define _loop0_26_type 1185 +#define _gather_25_type 1186 +#define _loop0_28_type 1187 +#define _gather_27_type 1188 +#define _tmp_29_type 1189 +#define _tmp_30_type 1190 +#define _loop0_31_type 1191 +#define _loop1_32_type 1192 +#define _loop0_34_type 1193 +#define _gather_33_type 1194 +#define _tmp_35_type 1195 +#define _loop0_37_type 1196 +#define _gather_36_type 1197 +#define _tmp_38_type 1198 +#define _loop0_40_type 1199 +#define _gather_39_type 1200 +#define _loop0_42_type 1201 +#define _gather_41_type 1202 +#define _loop0_44_type 1203 +#define _gather_43_type 1204 +#define _loop0_46_type 1205 +#define _gather_45_type 1206 +#define _tmp_47_type 1207 +#define _loop1_48_type 1208 +#define _tmp_49_type 1209 +#define _tmp_50_type 1210 +#define _tmp_51_type 1211 +#define _tmp_52_type 1212 +#define _tmp_53_type 1213 +#define _loop0_54_type 1214 +#define _loop0_55_type 1215 +#define _loop0_56_type 1216 +#define _loop1_57_type 1217 +#define _loop0_58_type 1218 +#define _loop1_59_type 1219 +#define _loop1_60_type 1220 +#define _loop1_61_type 1221 +#define _loop0_62_type 1222 +#define _loop1_63_type 1223 +#define _loop0_64_type 1224 +#define _loop1_65_type 1225 +#define _loop0_66_type 1226 +#define _loop1_67_type 1227 +#define _loop1_68_type 1228 +#define _tmp_69_type 1229 +#define _loop0_71_type 1230 +#define _gather_70_type 1231 +#define _loop1_72_type 1232 +#define _loop0_74_type 1233 +#define _gather_73_type 1234 +#define _loop1_75_type 1235 +#define _loop0_76_type 1236 +#define _loop0_77_type 1237 +#define _loop0_78_type 1238 +#define _loop1_79_type 1239 +#define _loop0_80_type 1240 +#define _loop1_81_type 1241 +#define _loop1_82_type 1242 +#define _loop1_83_type 1243 +#define _loop0_84_type 1244 +#define _loop1_85_type 1245 +#define _loop0_86_type 1246 +#define _loop1_87_type 1247 +#define _loop0_88_type 1248 +#define _loop1_89_type 1249 +#define _loop1_90_type 1250 +#define _loop1_91_type 1251 +#define _loop1_92_type 1252 +#define _tmp_93_type 1253 +#define _loop0_95_type 1254 +#define _gather_94_type 1255 +#define _tmp_96_type 1256 +#define _tmp_97_type 1257 +#define _tmp_98_type 1258 +#define _tmp_99_type 1259 +#define _loop1_100_type 1260 +#define _tmp_101_type 1261 +#define _tmp_102_type 1262 +#define _loop0_104_type 1263 +#define _gather_103_type 1264 +#define _loop1_105_type 1265 +#define _loop0_106_type 1266 +#define _loop0_107_type 1267 +#define _tmp_108_type 1268 +#define _tmp_109_type 1269 +#define _loop0_111_type 1270 +#define _gather_110_type 1271 +#define _loop0_113_type 1272 +#define _gather_112_type 1273 +#define _loop0_115_type 1274 +#define _gather_114_type 1275 +#define _loop0_117_type 1276 +#define _gather_116_type 1277 +#define _loop0_118_type 1278 +#define _loop0_120_type 1279 +#define _gather_119_type 1280 +#define _tmp_121_type 1281 +#define _loop0_123_type 1282 +#define _gather_122_type 1283 +#define _loop0_125_type 1284 +#define _gather_124_type 1285 +#define _tmp_126_type 1286 +#define _loop0_127_type 1287 +#define _loop0_128_type 1288 +#define _loop0_129_type 1289 +#define _tmp_130_type 1290 +#define _tmp_131_type 1291 +#define _loop0_132_type 1292 +#define _tmp_133_type 1293 +#define _loop0_134_type 1294 +#define _tmp_135_type 1295 +#define _tmp_136_type 1296 +#define _tmp_137_type 1297 +#define _tmp_138_type 1298 +#define _tmp_139_type 1299 +#define _tmp_140_type 1300 +#define _tmp_141_type 1301 +#define _tmp_142_type 1302 +#define _tmp_143_type 1303 +#define _tmp_144_type 1304 +#define _tmp_145_type 1305 +#define _tmp_146_type 1306 +#define _tmp_147_type 1307 +#define _tmp_148_type 1308 +#define _tmp_149_type 1309 +#define _tmp_150_type 1310 +#define _loop1_151_type 1311 +#define _loop1_152_type 1312 +#define _tmp_153_type 1313 +#define _tmp_154_type 1314 + +static mod_ty file_rule(Parser *p); +static mod_ty interactive_rule(Parser *p); +static mod_ty eval_rule(Parser *p); +static mod_ty func_type_rule(Parser *p); +static expr_ty fstring_rule(Parser *p); +static asdl_seq* type_expressions_rule(Parser *p); +static asdl_seq* statements_rule(Parser *p); +static asdl_seq* statement_rule(Parser *p); +static asdl_seq* statement_newline_rule(Parser *p); +static asdl_seq* simple_stmt_rule(Parser *p); +static stmt_ty small_stmt_rule(Parser *p); +static stmt_ty compound_stmt_rule(Parser *p); +static stmt_ty assignment_rule(Parser *p); +static AugOperator* augassign_rule(Parser *p); +static stmt_ty global_stmt_rule(Parser *p); +static stmt_ty nonlocal_stmt_rule(Parser *p); +static stmt_ty yield_stmt_rule(Parser *p); +static stmt_ty assert_stmt_rule(Parser *p); +static stmt_ty del_stmt_rule(Parser *p); +static stmt_ty import_stmt_rule(Parser *p); +static stmt_ty import_name_rule(Parser *p); +static stmt_ty import_from_rule(Parser *p); +static asdl_seq* import_from_targets_rule(Parser *p); +static asdl_seq* import_from_as_names_rule(Parser *p); +static alias_ty import_from_as_name_rule(Parser *p); +static asdl_seq* dotted_as_names_rule(Parser *p); +static alias_ty dotted_as_name_rule(Parser *p); +static expr_ty dotted_name_rule(Parser *p); +static stmt_ty if_stmt_rule(Parser *p); +static stmt_ty elif_stmt_rule(Parser *p); +static asdl_seq* else_block_rule(Parser *p); +static stmt_ty while_stmt_rule(Parser *p); +static stmt_ty for_stmt_rule(Parser *p); +static stmt_ty with_stmt_rule(Parser *p); +static withitem_ty with_item_rule(Parser *p); +static stmt_ty try_stmt_rule(Parser *p); +static excepthandler_ty except_block_rule(Parser *p); +static asdl_seq* finally_block_rule(Parser *p); +static stmt_ty return_stmt_rule(Parser *p); +static stmt_ty raise_stmt_rule(Parser *p); +static stmt_ty function_def_rule(Parser *p); +static stmt_ty function_def_raw_rule(Parser *p); +static Token* func_type_comment_rule(Parser *p); +static arguments_ty params_rule(Parser *p); +static arguments_ty parameters_rule(Parser *p); +static asdl_seq* slash_no_default_rule(Parser *p); +static SlashWithDefault* slash_with_default_rule(Parser *p); +static StarEtc* star_etc_rule(Parser *p); +static arg_ty kwds_rule(Parser *p); +static arg_ty param_no_default_rule(Parser *p); +static NameDefaultPair* param_with_default_rule(Parser *p); +static NameDefaultPair* param_maybe_default_rule(Parser *p); +static arg_ty param_rule(Parser *p); +static expr_ty annotation_rule(Parser *p); +static expr_ty default_rule(Parser *p); +static asdl_seq* decorators_rule(Parser *p); +static stmt_ty class_def_rule(Parser *p); +static stmt_ty class_def_raw_rule(Parser *p); +static asdl_seq* block_rule(Parser *p); +static asdl_seq* expressions_list_rule(Parser *p); +static expr_ty star_expressions_rule(Parser *p); +static expr_ty star_expression_rule(Parser *p); +static asdl_seq* star_named_expressions_rule(Parser *p); +static expr_ty star_named_expression_rule(Parser *p); +static expr_ty named_expression_rule(Parser *p); +static expr_ty annotated_rhs_rule(Parser *p); +static expr_ty expressions_rule(Parser *p); +static expr_ty expression_rule(Parser *p); +static expr_ty lambdef_rule(Parser *p); +static arguments_ty lambda_params_rule(Parser *p); +static arguments_ty lambda_parameters_rule(Parser *p); +static asdl_seq* lambda_slash_no_default_rule(Parser *p); +static SlashWithDefault* lambda_slash_with_default_rule(Parser *p); +static StarEtc* lambda_star_etc_rule(Parser *p); +static arg_ty lambda_kwds_rule(Parser *p); +static arg_ty lambda_param_no_default_rule(Parser *p); +static NameDefaultPair* lambda_param_with_default_rule(Parser *p); +static NameDefaultPair* lambda_param_maybe_default_rule(Parser *p); +static arg_ty lambda_param_rule(Parser *p); +static expr_ty disjunction_rule(Parser *p); +static expr_ty conjunction_rule(Parser *p); +static expr_ty inversion_rule(Parser *p); +static expr_ty comparison_rule(Parser *p); +static CmpopExprPair* compare_op_bitwise_or_pair_rule(Parser *p); +static CmpopExprPair* eq_bitwise_or_rule(Parser *p); +static CmpopExprPair* noteq_bitwise_or_rule(Parser *p); +static CmpopExprPair* lte_bitwise_or_rule(Parser *p); +static CmpopExprPair* lt_bitwise_or_rule(Parser *p); +static CmpopExprPair* gte_bitwise_or_rule(Parser *p); +static CmpopExprPair* gt_bitwise_or_rule(Parser *p); +static CmpopExprPair* notin_bitwise_or_rule(Parser *p); +static CmpopExprPair* in_bitwise_or_rule(Parser *p); +static CmpopExprPair* isnot_bitwise_or_rule(Parser *p); +static CmpopExprPair* is_bitwise_or_rule(Parser *p); +static expr_ty bitwise_or_rule(Parser *p); +static expr_ty bitwise_xor_rule(Parser *p); +static expr_ty bitwise_and_rule(Parser *p); +static expr_ty shift_expr_rule(Parser *p); +static expr_ty sum_rule(Parser *p); +static expr_ty term_rule(Parser *p); +static expr_ty factor_rule(Parser *p); +static expr_ty power_rule(Parser *p); +static expr_ty await_primary_rule(Parser *p); +static expr_ty primary_rule(Parser *p); +static expr_ty slices_rule(Parser *p); +static expr_ty slice_rule(Parser *p); +static expr_ty atom_rule(Parser *p); +static expr_ty strings_rule(Parser *p); +static expr_ty list_rule(Parser *p); +static expr_ty listcomp_rule(Parser *p); +static expr_ty tuple_rule(Parser *p); +static expr_ty group_rule(Parser *p); +static expr_ty genexp_rule(Parser *p); +static expr_ty set_rule(Parser *p); +static expr_ty setcomp_rule(Parser *p); +static expr_ty dict_rule(Parser *p); +static expr_ty dictcomp_rule(Parser *p); +static asdl_seq* double_starred_kvpairs_rule(Parser *p); +static KeyValuePair* double_starred_kvpair_rule(Parser *p); +static KeyValuePair* kvpair_rule(Parser *p); +static asdl_seq* for_if_clauses_rule(Parser *p); +static comprehension_ty for_if_clause_rule(Parser *p); +static expr_ty yield_expr_rule(Parser *p); +static expr_ty arguments_rule(Parser *p); +static expr_ty args_rule(Parser *p); +static asdl_seq* kwargs_rule(Parser *p); +static expr_ty starred_expression_rule(Parser *p); +static KeywordOrStarred* kwarg_or_starred_rule(Parser *p); +static KeywordOrStarred* kwarg_or_double_starred_rule(Parser *p); +static expr_ty star_targets_rule(Parser *p); +static asdl_seq* star_targets_seq_rule(Parser *p); +static expr_ty star_target_rule(Parser *p); +static expr_ty star_atom_rule(Parser *p); +static expr_ty single_target_rule(Parser *p); +static expr_ty single_subscript_attribute_target_rule(Parser *p); +static asdl_seq* del_targets_rule(Parser *p); +static expr_ty del_target_rule(Parser *p); +static expr_ty del_t_atom_rule(Parser *p); +static asdl_seq* targets_rule(Parser *p); +static expr_ty target_rule(Parser *p); +static expr_ty t_primary_rule(Parser *p); +static void *t_lookahead_rule(Parser *p); +static expr_ty t_atom_rule(Parser *p); +static void *incorrect_arguments_rule(Parser *p); +static void *invalid_kwarg_rule(Parser *p); +static void *invalid_named_expression_rule(Parser *p); +static void *invalid_assignment_rule(Parser *p); +static expr_ty invalid_ann_assign_target_rule(Parser *p); +static void *invalid_del_stmt_rule(Parser *p); +static void *invalid_block_rule(Parser *p); +static void *invalid_comprehension_rule(Parser *p); +static void *invalid_dict_comprehension_rule(Parser *p); +static void *invalid_parameters_rule(Parser *p); +static void *invalid_lambda_parameters_rule(Parser *p); +static void *invalid_star_etc_rule(Parser *p); +static void *invalid_lambda_star_etc_rule(Parser *p); +static void *invalid_double_type_comments_rule(Parser *p); +static void *invalid_with_item_rule(Parser *p); +static void *invalid_for_target_rule(Parser *p); +static void *invalid_group_rule(Parser *p); +static void *invalid_import_from_targets_rule(Parser *p); +static asdl_seq *_loop0_1_rule(Parser *p); +static asdl_seq *_loop0_2_rule(Parser *p); +static asdl_seq *_loop0_4_rule(Parser *p); +static asdl_seq *_gather_3_rule(Parser *p); +static asdl_seq *_loop0_6_rule(Parser *p); +static asdl_seq *_gather_5_rule(Parser *p); +static asdl_seq *_loop0_8_rule(Parser *p); +static asdl_seq *_gather_7_rule(Parser *p); +static asdl_seq *_loop0_10_rule(Parser *p); +static asdl_seq *_gather_9_rule(Parser *p); +static asdl_seq *_loop1_11_rule(Parser *p); +static asdl_seq *_loop0_13_rule(Parser *p); +static asdl_seq *_gather_12_rule(Parser *p); +static void *_tmp_14_rule(Parser *p); +static void *_tmp_15_rule(Parser *p); +static void *_tmp_16_rule(Parser *p); +static void *_tmp_17_rule(Parser *p); +static void *_tmp_18_rule(Parser *p); +static void *_tmp_19_rule(Parser *p); +static void *_tmp_20_rule(Parser *p); +static void *_tmp_21_rule(Parser *p); +static asdl_seq *_loop1_22_rule(Parser *p); +static void *_tmp_23_rule(Parser *p); +static void *_tmp_24_rule(Parser *p); +static asdl_seq *_loop0_26_rule(Parser *p); +static asdl_seq *_gather_25_rule(Parser *p); +static asdl_seq *_loop0_28_rule(Parser *p); +static asdl_seq *_gather_27_rule(Parser *p); +static void *_tmp_29_rule(Parser *p); +static void *_tmp_30_rule(Parser *p); +static asdl_seq *_loop0_31_rule(Parser *p); +static asdl_seq *_loop1_32_rule(Parser *p); +static asdl_seq *_loop0_34_rule(Parser *p); +static asdl_seq *_gather_33_rule(Parser *p); +static void *_tmp_35_rule(Parser *p); +static asdl_seq *_loop0_37_rule(Parser *p); +static asdl_seq *_gather_36_rule(Parser *p); +static void *_tmp_38_rule(Parser *p); +static asdl_seq *_loop0_40_rule(Parser *p); +static asdl_seq *_gather_39_rule(Parser *p); +static asdl_seq *_loop0_42_rule(Parser *p); +static asdl_seq *_gather_41_rule(Parser *p); +static asdl_seq *_loop0_44_rule(Parser *p); +static asdl_seq *_gather_43_rule(Parser *p); +static asdl_seq *_loop0_46_rule(Parser *p); +static asdl_seq *_gather_45_rule(Parser *p); +static void *_tmp_47_rule(Parser *p); +static asdl_seq *_loop1_48_rule(Parser *p); +static void *_tmp_49_rule(Parser *p); +static void *_tmp_50_rule(Parser *p); +static void *_tmp_51_rule(Parser *p); +static void *_tmp_52_rule(Parser *p); +static void *_tmp_53_rule(Parser *p); +static asdl_seq *_loop0_54_rule(Parser *p); +static asdl_seq *_loop0_55_rule(Parser *p); +static asdl_seq *_loop0_56_rule(Parser *p); +static asdl_seq *_loop1_57_rule(Parser *p); +static asdl_seq *_loop0_58_rule(Parser *p); +static asdl_seq *_loop1_59_rule(Parser *p); +static asdl_seq *_loop1_60_rule(Parser *p); +static asdl_seq *_loop1_61_rule(Parser *p); +static asdl_seq *_loop0_62_rule(Parser *p); +static asdl_seq *_loop1_63_rule(Parser *p); +static asdl_seq *_loop0_64_rule(Parser *p); +static asdl_seq *_loop1_65_rule(Parser *p); +static asdl_seq *_loop0_66_rule(Parser *p); +static asdl_seq *_loop1_67_rule(Parser *p); +static asdl_seq *_loop1_68_rule(Parser *p); +static void *_tmp_69_rule(Parser *p); +static asdl_seq *_loop0_71_rule(Parser *p); +static asdl_seq *_gather_70_rule(Parser *p); +static asdl_seq *_loop1_72_rule(Parser *p); +static asdl_seq *_loop0_74_rule(Parser *p); +static asdl_seq *_gather_73_rule(Parser *p); +static asdl_seq *_loop1_75_rule(Parser *p); +static asdl_seq *_loop0_76_rule(Parser *p); +static asdl_seq *_loop0_77_rule(Parser *p); +static asdl_seq *_loop0_78_rule(Parser *p); +static asdl_seq *_loop1_79_rule(Parser *p); +static asdl_seq *_loop0_80_rule(Parser *p); +static asdl_seq *_loop1_81_rule(Parser *p); +static asdl_seq *_loop1_82_rule(Parser *p); +static asdl_seq *_loop1_83_rule(Parser *p); +static asdl_seq *_loop0_84_rule(Parser *p); +static asdl_seq *_loop1_85_rule(Parser *p); +static asdl_seq *_loop0_86_rule(Parser *p); +static asdl_seq *_loop1_87_rule(Parser *p); +static asdl_seq *_loop0_88_rule(Parser *p); +static asdl_seq *_loop1_89_rule(Parser *p); +static asdl_seq *_loop1_90_rule(Parser *p); +static asdl_seq *_loop1_91_rule(Parser *p); +static asdl_seq *_loop1_92_rule(Parser *p); +static void *_tmp_93_rule(Parser *p); +static asdl_seq *_loop0_95_rule(Parser *p); +static asdl_seq *_gather_94_rule(Parser *p); +static void *_tmp_96_rule(Parser *p); +static void *_tmp_97_rule(Parser *p); +static void *_tmp_98_rule(Parser *p); +static void *_tmp_99_rule(Parser *p); +static asdl_seq *_loop1_100_rule(Parser *p); +static void *_tmp_101_rule(Parser *p); +static void *_tmp_102_rule(Parser *p); +static asdl_seq *_loop0_104_rule(Parser *p); +static asdl_seq *_gather_103_rule(Parser *p); +static asdl_seq *_loop1_105_rule(Parser *p); +static asdl_seq *_loop0_106_rule(Parser *p); +static asdl_seq *_loop0_107_rule(Parser *p); +static void *_tmp_108_rule(Parser *p); +static void *_tmp_109_rule(Parser *p); +static asdl_seq *_loop0_111_rule(Parser *p); +static asdl_seq *_gather_110_rule(Parser *p); +static asdl_seq *_loop0_113_rule(Parser *p); +static asdl_seq *_gather_112_rule(Parser *p); +static asdl_seq *_loop0_115_rule(Parser *p); +static asdl_seq *_gather_114_rule(Parser *p); +static asdl_seq *_loop0_117_rule(Parser *p); +static asdl_seq *_gather_116_rule(Parser *p); +static asdl_seq *_loop0_118_rule(Parser *p); +static asdl_seq *_loop0_120_rule(Parser *p); +static asdl_seq *_gather_119_rule(Parser *p); +static void *_tmp_121_rule(Parser *p); +static asdl_seq *_loop0_123_rule(Parser *p); +static asdl_seq *_gather_122_rule(Parser *p); +static asdl_seq *_loop0_125_rule(Parser *p); +static asdl_seq *_gather_124_rule(Parser *p); +static void *_tmp_126_rule(Parser *p); +static asdl_seq *_loop0_127_rule(Parser *p); +static asdl_seq *_loop0_128_rule(Parser *p); +static asdl_seq *_loop0_129_rule(Parser *p); +static void *_tmp_130_rule(Parser *p); +static void *_tmp_131_rule(Parser *p); +static asdl_seq *_loop0_132_rule(Parser *p); +static void *_tmp_133_rule(Parser *p); +static asdl_seq *_loop0_134_rule(Parser *p); +static void *_tmp_135_rule(Parser *p); +static void *_tmp_136_rule(Parser *p); +static void *_tmp_137_rule(Parser *p); +static void *_tmp_138_rule(Parser *p); +static void *_tmp_139_rule(Parser *p); +static void *_tmp_140_rule(Parser *p); +static void *_tmp_141_rule(Parser *p); +static void *_tmp_142_rule(Parser *p); +static void *_tmp_143_rule(Parser *p); +static void *_tmp_144_rule(Parser *p); +static void *_tmp_145_rule(Parser *p); +static void *_tmp_146_rule(Parser *p); +static void *_tmp_147_rule(Parser *p); +static void *_tmp_148_rule(Parser *p); +static void *_tmp_149_rule(Parser *p); +static void *_tmp_150_rule(Parser *p); +static asdl_seq *_loop1_151_rule(Parser *p); +static asdl_seq *_loop1_152_rule(Parser *p); +static void *_tmp_153_rule(Parser *p); +static void *_tmp_154_rule(Parser *p); -/* STACK DATA TYPE */ - -static void s_reset(stack *); - -static void -s_reset(stack *s) +// file: statements? $ +static mod_ty +file_rule(Parser *p) { - s->s_top = &s->s_base[MAXSTACK]; -} - -#define s_empty(s) ((s)->s_top == &(s)->s_base[MAXSTACK]) - -static int -s_push(stack *s, const dfa *d, node *parent) -{ - stackentry *top; - if (s->s_top == s->s_base) { - fprintf(stderr, "s_push: parser stack overflow\n"); - return E_NOMEM; - } - top = --s->s_top; - top->s_dfa = d; - top->s_parent = parent; - top->s_state = 0; - return 0; -} - -#ifdef Py_DEBUG - -static void -s_pop(stack *s) -{ - if (s_empty(s)) { - Py_FatalError("parser stack underflow"); - } - s->s_top++; -} - -#else /* !Py_DEBUG */ - -#define s_pop(s) (s)->s_top++ - -#endif - - -/* PARSER CREATION */ - -parser_state * -PyParser_New(grammar *g, int start) -{ - parser_state *ps; - - if (!g->g_accel) - PyGrammar_AddAccelerators(g); - ps = (parser_state *)PyMem_MALLOC(sizeof(parser_state)); - if (ps == NULL) - return NULL; - ps->p_grammar = g; -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD - ps->p_flags = 0; -#endif - ps->p_tree = PyNode_New(start); - if (ps->p_tree == NULL) { - PyMem_FREE(ps); + D(p->level++); + if (p->error_indicator) { + D(p->level--); return NULL; } - s_reset(&ps->p_stack); - (void) s_push(&ps->p_stack, PyGrammar_FindDFA(g, start), ps->p_tree); - return ps; -} - -void -PyParser_Delete(parser_state *ps) -{ - /* NB If you want to save the parse tree, - you must set p_tree to NULL before calling delparser! */ - PyNode_Free(ps->p_tree); - PyMem_FREE(ps); -} - - -/* PARSER STACK OPERATIONS */ - -static int -shift(stack *s, int type, char *str, int newstate, int lineno, int col_offset, - int end_lineno, int end_col_offset) -{ - int err; - assert(!s_empty(s)); - err = PyNode_AddChild(s->s_top->s_parent, type, str, lineno, col_offset, - end_lineno, end_col_offset); - if (err) - return err; - s->s_top->s_state = newstate; - return 0; -} - -static int -push(stack *s, int type, const dfa *d, int newstate, int lineno, int col_offset, - int end_lineno, int end_col_offset) -{ - int err; - node *n; - n = s->s_top->s_parent; - assert(!s_empty(s)); - err = PyNode_AddChild(n, type, (char *)NULL, lineno, col_offset, - end_lineno, end_col_offset); - if (err) - return err; - s->s_top->s_state = newstate; - return s_push(s, d, CHILD(n, NCH(n)-1)); -} - - -/* PARSER PROPER */ - -static int -classify(parser_state *ps, int type, const char *str) -{ - grammar *g = ps->p_grammar; - int n = g->g_ll.ll_nlabels; - - if (type == NAME) { - const label *l = g->g_ll.ll_label; - int i; - for (i = n; i > 0; i--, l++) { - if (l->lb_type != NAME || l->lb_str == NULL || - l->lb_str[0] != str[0] || - strcmp(l->lb_str, str) != 0) - continue; -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD -#if 0 - /* Leaving this in as an example */ - if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) { - if (str[0] == 'w' && strcmp(str, "with") == 0) - break; /* not a keyword yet */ - else if (str[0] == 'a' && strcmp(str, "as") == 0) - break; /* not a keyword yet */ + mod_ty _res = NULL; + int _mark = p->mark; + { // statements? $ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> file[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "statements? $")); + void *a; + Token * endmarker_var; + if ( + (a = statements_rule(p), 1) // statements? + && + (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' + ) + { + D(fprintf(stderr, "%*c+ file[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "statements? $")); + _res = _PyPegen_make_module ( p , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; } -#endif -#endif - D(printf("It's a keyword\n")); - return n - i; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s file[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "statements? $")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// interactive: statement_newline +static mod_ty +interactive_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + mod_ty _res = NULL; + int _mark = p->mark; + { // statement_newline + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> interactive[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "statement_newline")); + asdl_seq* a; + if ( + (a = statement_newline_rule(p)) // statement_newline + ) + { + D(fprintf(stderr, "%*c+ interactive[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "statement_newline")); + _res = Interactive ( a , p -> arena ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s interactive[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "statement_newline")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// eval: expressions NEWLINE* $ +static mod_ty +eval_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + mod_ty _res = NULL; + int _mark = p->mark; + { // expressions NEWLINE* $ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> eval[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expressions NEWLINE* $")); + asdl_seq * _loop0_1_var; + expr_ty a; + Token * endmarker_var; + if ( + (a = expressions_rule(p)) // expressions + && + (_loop0_1_var = _loop0_1_rule(p)) // NEWLINE* + && + (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' + ) + { + D(fprintf(stderr, "%*c+ eval[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expressions NEWLINE* $")); + _res = Expression ( a , p -> arena ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s eval[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expressions NEWLINE* $")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// func_type: '(' type_expressions? ')' '->' expression NEWLINE* $ +static mod_ty +func_type_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + mod_ty _res = NULL; + int _mark = p->mark; + { // '(' type_expressions? ')' '->' expression NEWLINE* $ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> func_type[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' type_expressions? ')' '->' expression NEWLINE* $")); + Token * _literal; + Token * _literal_1; + Token * _literal_2; + asdl_seq * _loop0_2_var; + void *a; + expr_ty b; + Token * endmarker_var; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = type_expressions_rule(p), 1) // type_expressions? + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + && + (_literal_2 = _PyPegen_expect_token(p, 51)) // token='->' + && + (b = expression_rule(p)) // expression + && + (_loop0_2_var = _loop0_2_rule(p)) // NEWLINE* + && + (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' + ) + { + D(fprintf(stderr, "%*c+ func_type[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' type_expressions? ')' '->' expression NEWLINE* $")); + _res = FunctionType ( a , b , p -> arena ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s func_type[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' type_expressions? ')' '->' expression NEWLINE* $")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// fstring: star_expressions +static expr_ty +fstring_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + { // star_expressions + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> fstring[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions")); + expr_ty star_expressions_var; + if ( + (star_expressions_var = star_expressions_rule(p)) // star_expressions + ) + { + D(fprintf(stderr, "%*c+ fstring[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions")); + _res = star_expressions_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s fstring[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// type_expressions: +// | ','.expression+ ',' '*' expression ',' '**' expression +// | ','.expression+ ',' '*' expression +// | ','.expression+ ',' '**' expression +// | '*' expression ',' '**' expression +// | '*' expression +// | '**' expression +// | ','.expression+ +static asdl_seq* +type_expressions_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // ','.expression+ ',' '*' expression ',' '**' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.expression+ ',' '*' expression ',' '**' expression")); + Token * _literal; + Token * _literal_1; + Token * _literal_2; + Token * _literal_3; + asdl_seq * a; + expr_ty b; + expr_ty c; + if ( + (a = _gather_3_rule(p)) // ','.expression+ + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (_literal_1 = _PyPegen_expect_token(p, 16)) // token='*' + && + (b = expression_rule(p)) // expression + && + (_literal_2 = _PyPegen_expect_token(p, 12)) // token=',' + && + (_literal_3 = _PyPegen_expect_token(p, 35)) // token='**' + && + (c = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.expression+ ',' '*' expression ',' '**' expression")); + _res = _PyPegen_seq_append_to_end ( p , CHECK ( _PyPegen_seq_append_to_end ( p , a , b ) ) , c ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.expression+ ',' '*' expression ',' '**' expression")); + } + { // ','.expression+ ',' '*' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.expression+ ',' '*' expression")); + Token * _literal; + Token * _literal_1; + asdl_seq * a; + expr_ty b; + if ( + (a = _gather_5_rule(p)) // ','.expression+ + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (_literal_1 = _PyPegen_expect_token(p, 16)) // token='*' + && + (b = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.expression+ ',' '*' expression")); + _res = _PyPegen_seq_append_to_end ( p , a , b ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.expression+ ',' '*' expression")); + } + { // ','.expression+ ',' '**' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.expression+ ',' '**' expression")); + Token * _literal; + Token * _literal_1; + asdl_seq * a; + expr_ty b; + if ( + (a = _gather_7_rule(p)) // ','.expression+ + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (_literal_1 = _PyPegen_expect_token(p, 35)) // token='**' + && + (b = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.expression+ ',' '**' expression")); + _res = _PyPegen_seq_append_to_end ( p , a , b ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.expression+ ',' '**' expression")); + } + { // '*' expression ',' '**' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' expression ',' '**' expression")); + Token * _literal; + Token * _literal_1; + Token * _literal_2; + expr_ty a; + expr_ty b; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = expression_rule(p)) // expression + && + (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + && + (_literal_2 = _PyPegen_expect_token(p, 35)) // token='**' + && + (b = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' expression ',' '**' expression")); + _res = _PyPegen_seq_append_to_end ( p , CHECK ( _PyPegen_singleton_seq ( p , a ) ) , b ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' expression ',' '**' expression")); + } + { // '*' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' expression")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' expression")); + _res = _PyPegen_singleton_seq ( p , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' expression")); + } + { // '**' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**' expression")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 35)) // token='**' + && + (a = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**' expression")); + _res = _PyPegen_singleton_seq ( p , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**' expression")); + } + { // ','.expression+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.expression+")); + asdl_seq * _gather_9_var; + if ( + (_gather_9_var = _gather_9_rule(p)) // ','.expression+ + ) + { + D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.expression+")); + _res = _gather_9_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.expression+")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// statements: statement+ +static asdl_seq* +statements_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // statement+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> statements[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "statement+")); + asdl_seq * a; + if ( + (a = _loop1_11_rule(p)) // statement+ + ) + { + D(fprintf(stderr, "%*c+ statements[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "statement+")); + _res = _PyPegen_seq_flatten ( p , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s statements[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "statement+")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// statement: compound_stmt | simple_stmt +static asdl_seq* +statement_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // compound_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> statement[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "compound_stmt")); + stmt_ty a; + if ( + (a = compound_stmt_rule(p)) // compound_stmt + ) + { + D(fprintf(stderr, "%*c+ statement[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "compound_stmt")); + _res = _PyPegen_singleton_seq ( p , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s statement[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "compound_stmt")); + } + { // simple_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> statement[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "simple_stmt")); + asdl_seq* simple_stmt_var; + if ( + (simple_stmt_var = simple_stmt_rule(p)) // simple_stmt + ) + { + D(fprintf(stderr, "%*c+ statement[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "simple_stmt")); + _res = simple_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s statement[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "simple_stmt")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// statement_newline: compound_stmt NEWLINE | simple_stmt | NEWLINE | $ +static asdl_seq* +statement_newline_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // compound_stmt NEWLINE + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> statement_newline[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "compound_stmt NEWLINE")); + stmt_ty a; + Token * newline_var; + if ( + (a = compound_stmt_rule(p)) // compound_stmt + && + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + D(fprintf(stderr, "%*c+ statement_newline[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "compound_stmt NEWLINE")); + _res = _PyPegen_singleton_seq ( p , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s statement_newline[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "compound_stmt NEWLINE")); + } + { // simple_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> statement_newline[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "simple_stmt")); + asdl_seq* simple_stmt_var; + if ( + (simple_stmt_var = simple_stmt_rule(p)) // simple_stmt + ) + { + D(fprintf(stderr, "%*c+ statement_newline[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "simple_stmt")); + _res = simple_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s statement_newline[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "simple_stmt")); + } + { // NEWLINE + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> statement_newline[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE")); + Token * newline_var; + if ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + D(fprintf(stderr, "%*c+ statement_newline[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NEWLINE")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _PyPegen_singleton_seq ( p , CHECK ( _Py_Pass ( EXTRA ) ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s statement_newline[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE")); + } + { // $ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> statement_newline[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "$")); + Token * endmarker_var; + if ( + (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' + ) + { + D(fprintf(stderr, "%*c+ statement_newline[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "$")); + _res = _PyPegen_interactive_exit ( p ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s statement_newline[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "$")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// simple_stmt: small_stmt !';' NEWLINE | ';'.small_stmt+ ';'? NEWLINE +static asdl_seq* +simple_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // small_stmt !';' NEWLINE + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> simple_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "small_stmt !';' NEWLINE")); + stmt_ty a; + Token * newline_var; + if ( + (a = small_stmt_rule(p)) // small_stmt + && + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 13) // token=';' + && + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + D(fprintf(stderr, "%*c+ simple_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "small_stmt !';' NEWLINE")); + _res = _PyPegen_singleton_seq ( p , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s simple_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "small_stmt !';' NEWLINE")); + } + { // ';'.small_stmt+ ';'? NEWLINE + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> simple_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "';'.small_stmt+ ';'? NEWLINE")); + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + asdl_seq * a; + Token * newline_var; + if ( + (a = _gather_12_rule(p)) // ';'.small_stmt+ + && + (_opt_var = _PyPegen_expect_token(p, 13), 1) // ';'? + && + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + D(fprintf(stderr, "%*c+ simple_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "';'.small_stmt+ ';'? NEWLINE")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s simple_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "';'.small_stmt+ ';'? NEWLINE")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// small_stmt: +// | assignment +// | star_expressions +// | &'return' return_stmt +// | &('import' | 'from') import_stmt +// | &'raise' raise_stmt +// | 'pass' +// | &'del' del_stmt +// | &'yield' yield_stmt +// | &'assert' assert_stmt +// | 'break' +// | 'continue' +// | &'global' global_stmt +// | &'nonlocal' nonlocal_stmt +static stmt_ty +small_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + if (_PyPegen_is_memoized(p, small_stmt_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // assignment + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "assignment")); + stmt_ty assignment_var; + if ( + (assignment_var = assignment_rule(p)) // assignment + ) + { + D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "assignment")); + _res = assignment_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "assignment")); + } + { // star_expressions + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions")); + expr_ty e; + if ( + (e = star_expressions_rule(p)) // star_expressions + ) + { + D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Expr ( e , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions")); + } + { // &'return' return_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'return' return_stmt")); + stmt_ty return_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 500) // token='return' + && + (return_stmt_var = return_stmt_rule(p)) // return_stmt + ) + { + D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'return' return_stmt")); + _res = return_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'return' return_stmt")); + } + { // &('import' | 'from') import_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&('import' | 'from') import_stmt")); + stmt_ty import_stmt_var; + if ( + _PyPegen_lookahead(1, _tmp_14_rule, p) + && + (import_stmt_var = import_stmt_rule(p)) // import_stmt + ) + { + D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&('import' | 'from') import_stmt")); + _res = import_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&('import' | 'from') import_stmt")); + } + { // &'raise' raise_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'raise' raise_stmt")); + stmt_ty raise_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 501) // token='raise' + && + (raise_stmt_var = raise_stmt_rule(p)) // raise_stmt + ) + { + D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'raise' raise_stmt")); + _res = raise_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'raise' raise_stmt")); + } + { // 'pass' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'pass'")); + Token * _keyword; + if ( + (_keyword = _PyPegen_expect_token(p, 502)) // token='pass' + ) + { + D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'pass'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Pass ( EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'pass'")); + } + { // &'del' del_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'del' del_stmt")); + stmt_ty del_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 503) // token='del' + && + (del_stmt_var = del_stmt_rule(p)) // del_stmt + ) + { + D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'del' del_stmt")); + _res = del_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'del' del_stmt")); + } + { // &'yield' yield_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'yield' yield_stmt")); + stmt_ty yield_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 504) // token='yield' + && + (yield_stmt_var = yield_stmt_rule(p)) // yield_stmt + ) + { + D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'yield' yield_stmt")); + _res = yield_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'yield' yield_stmt")); + } + { // &'assert' assert_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'assert' assert_stmt")); + stmt_ty assert_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 505) // token='assert' + && + (assert_stmt_var = assert_stmt_rule(p)) // assert_stmt + ) + { + D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'assert' assert_stmt")); + _res = assert_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'assert' assert_stmt")); + } + { // 'break' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'break'")); + Token * _keyword; + if ( + (_keyword = _PyPegen_expect_token(p, 506)) // token='break' + ) + { + D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'break'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Break ( EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'break'")); + } + { // 'continue' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'continue'")); + Token * _keyword; + if ( + (_keyword = _PyPegen_expect_token(p, 507)) // token='continue' + ) + { + D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'continue'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Continue ( EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'continue'")); + } + { // &'global' global_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'global' global_stmt")); + stmt_ty global_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 508) // token='global' + && + (global_stmt_var = global_stmt_rule(p)) // global_stmt + ) + { + D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'global' global_stmt")); + _res = global_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'global' global_stmt")); + } + { // &'nonlocal' nonlocal_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'nonlocal' nonlocal_stmt")); + stmt_ty nonlocal_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 509) // token='nonlocal' + && + (nonlocal_stmt_var = nonlocal_stmt_rule(p)) // nonlocal_stmt + ) + { + D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'nonlocal' nonlocal_stmt")); + _res = nonlocal_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'nonlocal' nonlocal_stmt")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, small_stmt_type, _res); + D(p->level--); + return _res; +} + +// compound_stmt: +// | &('def' | '@' | ASYNC) function_def +// | &'if' if_stmt +// | &('class' | '@') class_def +// | &('with' | ASYNC) with_stmt +// | &('for' | ASYNC) for_stmt +// | &'try' try_stmt +// | &'while' while_stmt +static stmt_ty +compound_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + { // &('def' | '@' | ASYNC) function_def + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&('def' | '@' | ASYNC) function_def")); + stmt_ty function_def_var; + if ( + _PyPegen_lookahead(1, _tmp_15_rule, p) + && + (function_def_var = function_def_rule(p)) // function_def + ) + { + D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&('def' | '@' | ASYNC) function_def")); + _res = function_def_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&('def' | '@' | ASYNC) function_def")); + } + { // &'if' if_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'if' if_stmt")); + stmt_ty if_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 510) // token='if' + && + (if_stmt_var = if_stmt_rule(p)) // if_stmt + ) + { + D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'if' if_stmt")); + _res = if_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'if' if_stmt")); + } + { // &('class' | '@') class_def + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&('class' | '@') class_def")); + stmt_ty class_def_var; + if ( + _PyPegen_lookahead(1, _tmp_16_rule, p) + && + (class_def_var = class_def_rule(p)) // class_def + ) + { + D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&('class' | '@') class_def")); + _res = class_def_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&('class' | '@') class_def")); + } + { // &('with' | ASYNC) with_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&('with' | ASYNC) with_stmt")); + stmt_ty with_stmt_var; + if ( + _PyPegen_lookahead(1, _tmp_17_rule, p) + && + (with_stmt_var = with_stmt_rule(p)) // with_stmt + ) + { + D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&('with' | ASYNC) with_stmt")); + _res = with_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&('with' | ASYNC) with_stmt")); + } + { // &('for' | ASYNC) for_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&('for' | ASYNC) for_stmt")); + stmt_ty for_stmt_var; + if ( + _PyPegen_lookahead(1, _tmp_18_rule, p) + && + (for_stmt_var = for_stmt_rule(p)) // for_stmt + ) + { + D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&('for' | ASYNC) for_stmt")); + _res = for_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&('for' | ASYNC) for_stmt")); + } + { // &'try' try_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'try' try_stmt")); + stmt_ty try_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 511) // token='try' + && + (try_stmt_var = try_stmt_rule(p)) // try_stmt + ) + { + D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'try' try_stmt")); + _res = try_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'try' try_stmt")); + } + { // &'while' while_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'while' while_stmt")); + stmt_ty while_stmt_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 512) // token='while' + && + (while_stmt_var = while_stmt_rule(p)) // while_stmt + ) + { + D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'while' while_stmt")); + _res = while_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'while' while_stmt")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// assignment: +// | NAME ':' expression ['=' annotated_rhs] +// | ('(' single_target ')' | single_subscript_attribute_target) ':' expression ['=' annotated_rhs] +// | ((star_targets '='))+ (yield_expr | star_expressions) !'=' TYPE_COMMENT? +// | single_target augassign ~ (yield_expr | star_expressions) +// | invalid_assignment +static stmt_ty +assignment_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // NAME ':' expression ['=' annotated_rhs] + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME ':' expression ['=' annotated_rhs]")); + Token * _literal; + expr_ty a; + expr_ty b; + void *c; + if ( + (a = _PyPegen_name_token(p)) // NAME + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = expression_rule(p)) // expression + && + (c = _tmp_19_rule(p), 1) // ['=' annotated_rhs] + ) + { + D(fprintf(stderr, "%*c+ assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME ':' expression ['=' annotated_rhs]")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = CHECK_VERSION ( 6 , "Variable annotation syntax is" , _Py_AnnAssign ( CHECK ( _PyPegen_set_expr_context ( p , a , Store ) ) , b , c , 1 , EXTRA ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s assignment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME ':' expression ['=' annotated_rhs]")); + } + { // ('(' single_target ')' | single_subscript_attribute_target) ':' expression ['=' annotated_rhs] + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('(' single_target ')' | single_subscript_attribute_target) ':' expression ['=' annotated_rhs]")); + Token * _literal; + void *a; + expr_ty b; + void *c; + if ( + (a = _tmp_20_rule(p)) // '(' single_target ')' | single_subscript_attribute_target + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = expression_rule(p)) // expression + && + (c = _tmp_21_rule(p), 1) // ['=' annotated_rhs] + ) + { + D(fprintf(stderr, "%*c+ assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "('(' single_target ')' | single_subscript_attribute_target) ':' expression ['=' annotated_rhs]")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = CHECK_VERSION ( 6 , "Variable annotations syntax is" , _Py_AnnAssign ( a , b , c , 0 , EXTRA ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s assignment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('(' single_target ')' | single_subscript_attribute_target) ':' expression ['=' annotated_rhs]")); + } + { // ((star_targets '='))+ (yield_expr | star_expressions) !'=' TYPE_COMMENT? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "((star_targets '='))+ (yield_expr | star_expressions) !'=' TYPE_COMMENT?")); + asdl_seq * a; + void *b; + void *tc; + if ( + (a = _loop1_22_rule(p)) // ((star_targets '='))+ + && + (b = _tmp_23_rule(p)) // yield_expr | star_expressions + && + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 22) // token='=' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + ) + { + D(fprintf(stderr, "%*c+ assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "((star_targets '='))+ (yield_expr | star_expressions) !'=' TYPE_COMMENT?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Assign ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s assignment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "((star_targets '='))+ (yield_expr | star_expressions) !'=' TYPE_COMMENT?")); + } + { // single_target augassign ~ (yield_expr | star_expressions) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "single_target augassign ~ (yield_expr | star_expressions)")); + int _cut_var = 0; + expr_ty a; + AugOperator* b; + void *c; + if ( + (a = single_target_rule(p)) // single_target + && + (b = augassign_rule(p)) // augassign + && + (_cut_var = 1) + && + (c = _tmp_24_rule(p)) // yield_expr | star_expressions + ) + { + D(fprintf(stderr, "%*c+ assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "single_target augassign ~ (yield_expr | star_expressions)")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_AugAssign ( a , b -> kind , c , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s assignment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "single_target augassign ~ (yield_expr | star_expressions)")); + if (_cut_var) { + D(p->level--); + return NULL; } } - - { - const label *l = g->g_ll.ll_label; - int i; - for (i = n; i > 0; i--, l++) { - if (l->lb_type == type && l->lb_str == NULL) { - D(printf("It's a token we know\n")); - return n - i; - } + { // invalid_assignment + if (p->error_indicator) { + D(p->level--); + return NULL; } + D(fprintf(stderr, "%*c> assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_assignment")); + void *invalid_assignment_var; + if ( + (invalid_assignment_var = invalid_assignment_rule(p)) // invalid_assignment + ) + { + D(fprintf(stderr, "%*c+ assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_assignment")); + _res = invalid_assignment_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s assignment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_assignment")); } - - D(printf("Illegal token\n")); - return -1; + _res = NULL; + done: + D(p->level--); + return _res; } -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD -#if 0 -/* Leaving this in as an example */ -static void -future_hack(parser_state *ps) +// augassign: +// | '+=' +// | '-=' +// | '*=' +// | '@=' +// | '/=' +// | '%=' +// | '&=' +// | '|=' +// | '^=' +// | '<<=' +// | '>>=' +// | '**=' +// | '//=' +static AugOperator* +augassign_rule(Parser *p) { - node *n = ps->p_stack.s_top->s_parent; - node *ch, *cch; - int i; - - /* from __future__ import ..., must have at least 4 children */ - n = CHILD(n, 0); - if (NCH(n) < 4) - return; - ch = CHILD(n, 0); - if (STR(ch) == NULL || strcmp(STR(ch), "from") != 0) - return; - ch = CHILD(n, 1); - if (NCH(ch) == 1 && STR(CHILD(ch, 0)) && - strcmp(STR(CHILD(ch, 0)), "__future__") != 0) - return; - ch = CHILD(n, 3); - /* ch can be a star, a parenthesis or import_as_names */ - if (TYPE(ch) == STAR) - return; - if (TYPE(ch) == LPAR) - ch = CHILD(n, 4); - - for (i = 0; i < NCH(ch); i += 2) { - cch = CHILD(ch, i); - if (NCH(cch) >= 1 && TYPE(CHILD(cch, 0)) == NAME) { - char *str_ch = STR(CHILD(cch, 0)); - if (strcmp(str_ch, FUTURE_WITH_STATEMENT) == 0) { - ps->p_flags |= CO_FUTURE_WITH_STATEMENT; - } else if (strcmp(str_ch, FUTURE_PRINT_FUNCTION) == 0) { - ps->p_flags |= CO_FUTURE_PRINT_FUNCTION; - } else if (strcmp(str_ch, FUTURE_UNICODE_LITERALS) == 0) { - ps->p_flags |= CO_FUTURE_UNICODE_LITERALS; + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + AugOperator* _res = NULL; + int _mark = p->mark; + { // '+=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'+='")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 36)) // token='+=' + ) + { + D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'+='")); + _res = _PyPegen_augoperator ( p , Add ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'+='")); + } + { // '-=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'-='")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 37)) // token='-=' + ) + { + D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'-='")); + _res = _PyPegen_augoperator ( p , Sub ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'-='")); + } + { // '*=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*='")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 38)) // token='*=' + ) + { + D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*='")); + _res = _PyPegen_augoperator ( p , Mult ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*='")); + } + { // '@=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'@='")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 50)) // token='@=' + ) + { + D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'@='")); + _res = CHECK_VERSION ( 5 , "The '@' operator is" , _PyPegen_augoperator ( p , MatMult ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'@='")); + } + { // '/=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'/='")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 39)) // token='/=' + ) + { + D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'/='")); + _res = _PyPegen_augoperator ( p , Div ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'/='")); + } + { // '%=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'%='")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 40)) // token='%=' + ) + { + D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'%='")); + _res = _PyPegen_augoperator ( p , Mod ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'%='")); + } + { // '&=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'&='")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 41)) // token='&=' + ) + { + D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'&='")); + _res = _PyPegen_augoperator ( p , BitAnd ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'&='")); + } + { // '|=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'|='")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 42)) // token='|=' + ) + { + D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'|='")); + _res = _PyPegen_augoperator ( p , BitOr ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'|='")); + } + { // '^=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'^='")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 43)) // token='^=' + ) + { + D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'^='")); + _res = _PyPegen_augoperator ( p , BitXor ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'^='")); + } + { // '<<=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'<<='")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 44)) // token='<<=' + ) + { + D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'<<='")); + _res = _PyPegen_augoperator ( p , LShift ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'<<='")); + } + { // '>>=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'>>='")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 45)) // token='>>=' + ) + { + D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'>>='")); + _res = _PyPegen_augoperator ( p , RShift ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'>>='")); + } + { // '**=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**='")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 46)) // token='**=' + ) + { + D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**='")); + _res = _PyPegen_augoperator ( p , Pow ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**='")); + } + { // '//=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'//='")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 48)) // token='//=' + ) + { + D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'//='")); + _res = _PyPegen_augoperator ( p , FloorDiv ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'//='")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// global_stmt: 'global' ','.NAME+ +static stmt_ty +global_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'global' ','.NAME+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> global_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'global' ','.NAME+")); + Token * _keyword; + asdl_seq * a; + if ( + (_keyword = _PyPegen_expect_token(p, 508)) // token='global' + && + (a = _gather_25_rule(p)) // ','.NAME+ + ) + { + D(fprintf(stderr, "%*c+ global_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'global' ','.NAME+")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Global ( CHECK ( _PyPegen_map_names_to_ids ( p , a ) ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s global_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'global' ','.NAME+")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// nonlocal_stmt: 'nonlocal' ','.NAME+ +static stmt_ty +nonlocal_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'nonlocal' ','.NAME+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> nonlocal_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'nonlocal' ','.NAME+")); + Token * _keyword; + asdl_seq * a; + if ( + (_keyword = _PyPegen_expect_token(p, 509)) // token='nonlocal' + && + (a = _gather_27_rule(p)) // ','.NAME+ + ) + { + D(fprintf(stderr, "%*c+ nonlocal_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'nonlocal' ','.NAME+")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Nonlocal ( CHECK ( _PyPegen_map_names_to_ids ( p , a ) ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s nonlocal_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'nonlocal' ','.NAME+")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// yield_stmt: yield_expr +static stmt_ty +yield_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // yield_expr + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> yield_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "yield_expr")); + expr_ty y; + if ( + (y = yield_expr_rule(p)) // yield_expr + ) + { + D(fprintf(stderr, "%*c+ yield_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "yield_expr")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Expr ( y , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s yield_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "yield_expr")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// assert_stmt: 'assert' expression [',' expression] +static stmt_ty +assert_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'assert' expression [',' expression] + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> assert_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'assert' expression [',' expression]")); + Token * _keyword; + expr_ty a; + void *b; + if ( + (_keyword = _PyPegen_expect_token(p, 505)) // token='assert' + && + (a = expression_rule(p)) // expression + && + (b = _tmp_29_rule(p), 1) // [',' expression] + ) + { + D(fprintf(stderr, "%*c+ assert_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'assert' expression [',' expression]")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Assert ( a , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s assert_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'assert' expression [',' expression]")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// del_stmt: 'del' del_targets &(';' | NEWLINE) | invalid_del_stmt +static stmt_ty +del_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'del' del_targets &(';' | NEWLINE) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> del_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'del' del_targets &(';' | NEWLINE)")); + Token * _keyword; + asdl_seq* a; + if ( + (_keyword = _PyPegen_expect_token(p, 503)) // token='del' + && + (a = del_targets_rule(p)) // del_targets + && + _PyPegen_lookahead(1, _tmp_30_rule, p) + ) + { + D(fprintf(stderr, "%*c+ del_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'del' del_targets &(';' | NEWLINE)")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Delete ( a , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s del_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'del' del_targets &(';' | NEWLINE)")); + } + { // invalid_del_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> del_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_del_stmt")); + void *invalid_del_stmt_var; + if ( + (invalid_del_stmt_var = invalid_del_stmt_rule(p)) // invalid_del_stmt + ) + { + D(fprintf(stderr, "%*c+ del_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_del_stmt")); + _res = invalid_del_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s del_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_del_stmt")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// import_stmt: import_name | import_from +static stmt_ty +import_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + { // import_name + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> import_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "import_name")); + stmt_ty import_name_var; + if ( + (import_name_var = import_name_rule(p)) // import_name + ) + { + D(fprintf(stderr, "%*c+ import_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "import_name")); + _res = import_name_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s import_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "import_name")); + } + { // import_from + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> import_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "import_from")); + stmt_ty import_from_var; + if ( + (import_from_var = import_from_rule(p)) // import_from + ) + { + D(fprintf(stderr, "%*c+ import_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "import_from")); + _res = import_from_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s import_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "import_from")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// import_name: 'import' dotted_as_names +static stmt_ty +import_name_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'import' dotted_as_names + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> import_name[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'import' dotted_as_names")); + Token * _keyword; + asdl_seq* a; + if ( + (_keyword = _PyPegen_expect_token(p, 513)) // token='import' + && + (a = dotted_as_names_rule(p)) // dotted_as_names + ) + { + D(fprintf(stderr, "%*c+ import_name[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'import' dotted_as_names")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Import ( a , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s import_name[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'import' dotted_as_names")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// import_from: +// | 'from' (('.' | '...'))* dotted_name 'import' import_from_targets +// | 'from' (('.' | '...'))+ 'import' import_from_targets +static stmt_ty +import_from_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'from' (('.' | '...'))* dotted_name 'import' import_from_targets + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> import_from[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'from' (('.' | '...'))* dotted_name 'import' import_from_targets")); + Token * _keyword; + Token * _keyword_1; + asdl_seq * a; + expr_ty b; + asdl_seq* c; + if ( + (_keyword = _PyPegen_expect_token(p, 514)) // token='from' + && + (a = _loop0_31_rule(p)) // (('.' | '...'))* + && + (b = dotted_name_rule(p)) // dotted_name + && + (_keyword_1 = _PyPegen_expect_token(p, 513)) // token='import' + && + (c = import_from_targets_rule(p)) // import_from_targets + ) + { + D(fprintf(stderr, "%*c+ import_from[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'from' (('.' | '...'))* dotted_name 'import' import_from_targets")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_ImportFrom ( b -> v . Name . id , c , _PyPegen_seq_count_dots ( a ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s import_from[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'from' (('.' | '...'))* dotted_name 'import' import_from_targets")); + } + { // 'from' (('.' | '...'))+ 'import' import_from_targets + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> import_from[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'from' (('.' | '...'))+ 'import' import_from_targets")); + Token * _keyword; + Token * _keyword_1; + asdl_seq * a; + asdl_seq* b; + if ( + (_keyword = _PyPegen_expect_token(p, 514)) // token='from' + && + (a = _loop1_32_rule(p)) // (('.' | '...'))+ + && + (_keyword_1 = _PyPegen_expect_token(p, 513)) // token='import' + && + (b = import_from_targets_rule(p)) // import_from_targets + ) + { + D(fprintf(stderr, "%*c+ import_from[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'from' (('.' | '...'))+ 'import' import_from_targets")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_ImportFrom ( NULL , b , _PyPegen_seq_count_dots ( a ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s import_from[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'from' (('.' | '...'))+ 'import' import_from_targets")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// import_from_targets: +// | '(' import_from_as_names ','? ')' +// | import_from_as_names !',' +// | '*' +// | invalid_import_from_targets +static asdl_seq* +import_from_targets_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // '(' import_from_as_names ','? ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> import_from_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' import_from_as_names ','? ')'")); + Token * _literal; + Token * _literal_1; + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + asdl_seq* a; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = import_from_as_names_rule(p)) // import_from_as_names + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ import_from_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' import_from_as_names ','? ')'")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s import_from_targets[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' import_from_as_names ','? ')'")); + } + { // import_from_as_names !',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> import_from_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "import_from_as_names !','")); + asdl_seq* import_from_as_names_var; + if ( + (import_from_as_names_var = import_from_as_names_rule(p)) // import_from_as_names + && + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 12) // token=',' + ) + { + D(fprintf(stderr, "%*c+ import_from_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "import_from_as_names !','")); + _res = import_from_as_names_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s import_from_targets[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "import_from_as_names !','")); + } + { // '*' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> import_from_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + ) + { + D(fprintf(stderr, "%*c+ import_from_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*'")); + _res = _PyPegen_singleton_seq ( p , CHECK ( _PyPegen_alias_for_star ( p ) ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s import_from_targets[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*'")); + } + { // invalid_import_from_targets + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> import_from_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_import_from_targets")); + void *invalid_import_from_targets_var; + if ( + (invalid_import_from_targets_var = invalid_import_from_targets_rule(p)) // invalid_import_from_targets + ) + { + D(fprintf(stderr, "%*c+ import_from_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_import_from_targets")); + _res = invalid_import_from_targets_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s import_from_targets[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_import_from_targets")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// import_from_as_names: ','.import_from_as_name+ +static asdl_seq* +import_from_as_names_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // ','.import_from_as_name+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> import_from_as_names[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.import_from_as_name+")); + asdl_seq * a; + if ( + (a = _gather_33_rule(p)) // ','.import_from_as_name+ + ) + { + D(fprintf(stderr, "%*c+ import_from_as_names[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.import_from_as_name+")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s import_from_as_names[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.import_from_as_name+")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// import_from_as_name: NAME ['as' NAME] +static alias_ty +import_from_as_name_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + alias_ty _res = NULL; + int _mark = p->mark; + { // NAME ['as' NAME] + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> import_from_as_name[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME ['as' NAME]")); + expr_ty a; + void *b; + if ( + (a = _PyPegen_name_token(p)) // NAME + && + (b = _tmp_35_rule(p), 1) // ['as' NAME] + ) + { + D(fprintf(stderr, "%*c+ import_from_as_name[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME ['as' NAME]")); + _res = _Py_alias ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Name . id : NULL , p -> arena ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s import_from_as_name[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME ['as' NAME]")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// dotted_as_names: ','.dotted_as_name+ +static asdl_seq* +dotted_as_names_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // ','.dotted_as_name+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> dotted_as_names[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.dotted_as_name+")); + asdl_seq * a; + if ( + (a = _gather_36_rule(p)) // ','.dotted_as_name+ + ) + { + D(fprintf(stderr, "%*c+ dotted_as_names[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.dotted_as_name+")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s dotted_as_names[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.dotted_as_name+")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// dotted_as_name: dotted_name ['as' NAME] +static alias_ty +dotted_as_name_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + alias_ty _res = NULL; + int _mark = p->mark; + { // dotted_name ['as' NAME] + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> dotted_as_name[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "dotted_name ['as' NAME]")); + expr_ty a; + void *b; + if ( + (a = dotted_name_rule(p)) // dotted_name + && + (b = _tmp_38_rule(p), 1) // ['as' NAME] + ) + { + D(fprintf(stderr, "%*c+ dotted_as_name[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "dotted_name ['as' NAME]")); + _res = _Py_alias ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Name . id : NULL , p -> arena ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s dotted_as_name[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "dotted_name ['as' NAME]")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// Left-recursive +// dotted_name: dotted_name '.' NAME | NAME +static expr_ty dotted_name_raw(Parser *); +static expr_ty +dotted_name_rule(Parser *p) +{ + D(p->level++); + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, dotted_name_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + int _resmark = p->mark; + while (1) { + int tmpvar_0 = _PyPegen_update_memo(p, _mark, dotted_name_type, _res); + if (tmpvar_0) { + D(p->level--); + return _res; + } + p->mark = _mark; + void *_raw = dotted_name_raw(p); + if (_raw == NULL || p->mark <= _resmark) + break; + _resmark = p->mark; + _res = _raw; + } + p->mark = _resmark; + D(p->level--); + return _res; +} +static expr_ty +dotted_name_raw(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + { // dotted_name '.' NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> dotted_name[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "dotted_name '.' NAME")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = dotted_name_rule(p)) // dotted_name + && + (_literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + ) + { + D(fprintf(stderr, "%*c+ dotted_name[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "dotted_name '.' NAME")); + _res = _PyPegen_join_names_with_dot ( p , a , b ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s dotted_name[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "dotted_name '.' NAME")); + } + { // NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> dotted_name[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME")); + expr_ty name_var; + if ( + (name_var = _PyPegen_name_token(p)) // NAME + ) + { + D(fprintf(stderr, "%*c+ dotted_name[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME")); + _res = name_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s dotted_name[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// if_stmt: +// | 'if' named_expression ':' block elif_stmt +// | 'if' named_expression ':' block else_block? +static stmt_ty +if_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'if' named_expression ':' block elif_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> if_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'if' named_expression ':' block elif_stmt")); + Token * _keyword; + Token * _literal; + expr_ty a; + asdl_seq* b; + stmt_ty c; + if ( + (_keyword = _PyPegen_expect_token(p, 510)) // token='if' + && + (a = named_expression_rule(p)) // named_expression + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (c = elif_stmt_rule(p)) // elif_stmt + ) + { + D(fprintf(stderr, "%*c+ if_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'if' named_expression ':' block elif_stmt")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_If ( a , b , CHECK ( _PyPegen_singleton_seq ( p , c ) ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s if_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'if' named_expression ':' block elif_stmt")); + } + { // 'if' named_expression ':' block else_block? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> if_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'if' named_expression ':' block else_block?")); + Token * _keyword; + Token * _literal; + expr_ty a; + asdl_seq* b; + void *c; + if ( + (_keyword = _PyPegen_expect_token(p, 510)) // token='if' + && + (a = named_expression_rule(p)) // named_expression + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (c = else_block_rule(p), 1) // else_block? + ) + { + D(fprintf(stderr, "%*c+ if_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'if' named_expression ':' block else_block?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_If ( a , b , c , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s if_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'if' named_expression ':' block else_block?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// elif_stmt: +// | 'elif' named_expression ':' block elif_stmt +// | 'elif' named_expression ':' block else_block? +static stmt_ty +elif_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'elif' named_expression ':' block elif_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> elif_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'elif' named_expression ':' block elif_stmt")); + Token * _keyword; + Token * _literal; + expr_ty a; + asdl_seq* b; + stmt_ty c; + if ( + (_keyword = _PyPegen_expect_token(p, 515)) // token='elif' + && + (a = named_expression_rule(p)) // named_expression + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (c = elif_stmt_rule(p)) // elif_stmt + ) + { + D(fprintf(stderr, "%*c+ elif_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'elif' named_expression ':' block elif_stmt")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_If ( a , b , CHECK ( _PyPegen_singleton_seq ( p , c ) ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s elif_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'elif' named_expression ':' block elif_stmt")); + } + { // 'elif' named_expression ':' block else_block? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> elif_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'elif' named_expression ':' block else_block?")); + Token * _keyword; + Token * _literal; + expr_ty a; + asdl_seq* b; + void *c; + if ( + (_keyword = _PyPegen_expect_token(p, 515)) // token='elif' + && + (a = named_expression_rule(p)) // named_expression + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (c = else_block_rule(p), 1) // else_block? + ) + { + D(fprintf(stderr, "%*c+ elif_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'elif' named_expression ':' block else_block?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_If ( a , b , c , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s elif_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'elif' named_expression ':' block else_block?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// else_block: 'else' ':' block +static asdl_seq* +else_block_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // 'else' ':' block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> else_block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'else' ':' block")); + Token * _keyword; + Token * _literal; + asdl_seq* b; + if ( + (_keyword = _PyPegen_expect_token(p, 516)) // token='else' + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + ) + { + D(fprintf(stderr, "%*c+ else_block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'else' ':' block")); + _res = b; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s else_block[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'else' ':' block")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// while_stmt: 'while' named_expression ':' block else_block? +static stmt_ty +while_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'while' named_expression ':' block else_block? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> while_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'while' named_expression ':' block else_block?")); + Token * _keyword; + Token * _literal; + expr_ty a; + asdl_seq* b; + void *c; + if ( + (_keyword = _PyPegen_expect_token(p, 512)) // token='while' + && + (a = named_expression_rule(p)) // named_expression + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (c = else_block_rule(p), 1) // else_block? + ) + { + D(fprintf(stderr, "%*c+ while_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'while' named_expression ':' block else_block?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_While ( a , b , c , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s while_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'while' named_expression ':' block else_block?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// for_stmt: +// | 'for' star_targets 'in' ~ star_expressions ':' TYPE_COMMENT? block else_block? +// | ASYNC 'for' star_targets 'in' ~ star_expressions ':' TYPE_COMMENT? block else_block? +// | invalid_for_target +static stmt_ty +for_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'for' star_targets 'in' ~ star_expressions ':' TYPE_COMMENT? block else_block? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> for_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'for' star_targets 'in' ~ star_expressions ':' TYPE_COMMENT? block else_block?")); + int _cut_var = 0; + Token * _keyword; + Token * _keyword_1; + Token * _literal; + asdl_seq* b; + void *el; + expr_ty ex; + expr_ty t; + void *tc; + if ( + (_keyword = _PyPegen_expect_token(p, 517)) // token='for' + && + (t = star_targets_rule(p)) // star_targets + && + (_keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + && + (_cut_var = 1) + && + (ex = star_expressions_rule(p)) // star_expressions + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + (b = block_rule(p)) // block + && + (el = else_block_rule(p), 1) // else_block? + ) + { + D(fprintf(stderr, "%*c+ for_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'for' star_targets 'in' ~ star_expressions ':' TYPE_COMMENT? block else_block?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_For ( t , ex , b , el , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s for_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'for' star_targets 'in' ~ star_expressions ':' TYPE_COMMENT? block else_block?")); + if (_cut_var) { + D(p->level--); + return NULL; } } + { // ASYNC 'for' star_targets 'in' ~ star_expressions ':' TYPE_COMMENT? block else_block? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> for_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC 'for' star_targets 'in' ~ star_expressions ':' TYPE_COMMENT? block else_block?")); + int _cut_var = 0; + Token * _keyword; + Token * _keyword_1; + Token * _literal; + Token * async_var; + asdl_seq* b; + void *el; + expr_ty ex; + expr_ty t; + void *tc; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + && + (_keyword = _PyPegen_expect_token(p, 517)) // token='for' + && + (t = star_targets_rule(p)) // star_targets + && + (_keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + && + (_cut_var = 1) + && + (ex = star_expressions_rule(p)) // star_expressions + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + (b = block_rule(p)) // block + && + (el = else_block_rule(p), 1) // else_block? + ) + { + D(fprintf(stderr, "%*c+ for_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC 'for' star_targets 'in' ~ star_expressions ':' TYPE_COMMENT? block else_block?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = CHECK_VERSION ( 5 , "Async for loops are" , _Py_AsyncFor ( t , ex , b , el , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s for_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC 'for' star_targets 'in' ~ star_expressions ':' TYPE_COMMENT? block else_block?")); + if (_cut_var) { + D(p->level--); + return NULL; + } + } + { // invalid_for_target + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> for_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_for_target")); + void *invalid_for_target_var; + if ( + (invalid_for_target_var = invalid_for_target_rule(p)) // invalid_for_target + ) + { + D(fprintf(stderr, "%*c+ for_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_for_target")); + _res = invalid_for_target_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s for_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_for_target")); + } + _res = NULL; + done: + D(p->level--); + return _res; } -#endif -#endif /* future keyword */ -int -PyParser_AddToken(parser_state *ps, int type, char *str, - int lineno, int col_offset, - int end_lineno, int end_col_offset, - int *expected_ret) +// with_stmt: +// | 'with' '(' ','.with_item+ ','? ')' ':' block +// | 'with' ','.with_item+ ':' TYPE_COMMENT? block +// | ASYNC 'with' '(' ','.with_item+ ','? ')' ':' block +// | ASYNC 'with' ','.with_item+ ':' TYPE_COMMENT? block +static stmt_ty +with_stmt_rule(Parser *p) { - int ilabel; - int err; + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'with' '(' ','.with_item+ ','? ')' ':' block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> with_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'with' '(' ','.with_item+ ','? ')' ':' block")); + Token * _keyword; + Token * _literal; + Token * _literal_1; + Token * _literal_2; + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + asdl_seq * a; + asdl_seq* b; + if ( + (_keyword = _PyPegen_expect_token(p, 519)) // token='with' + && + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = _gather_39_rule(p)) // ','.with_item+ + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + && + (_literal_2 = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + ) + { + D(fprintf(stderr, "%*c+ with_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'with' '(' ','.with_item+ ','? ')' ':' block")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_With ( a , b , NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s with_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'with' '(' ','.with_item+ ','? ')' ':' block")); + } + { // 'with' ','.with_item+ ':' TYPE_COMMENT? block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> with_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'with' ','.with_item+ ':' TYPE_COMMENT? block")); + Token * _keyword; + Token * _literal; + asdl_seq * a; + asdl_seq* b; + void *tc; + if ( + (_keyword = _PyPegen_expect_token(p, 519)) // token='with' + && + (a = _gather_41_rule(p)) // ','.with_item+ + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + (b = block_rule(p)) // block + ) + { + D(fprintf(stderr, "%*c+ with_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'with' ','.with_item+ ':' TYPE_COMMENT? block")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_With ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s with_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'with' ','.with_item+ ':' TYPE_COMMENT? block")); + } + { // ASYNC 'with' '(' ','.with_item+ ','? ')' ':' block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> with_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC 'with' '(' ','.with_item+ ','? ')' ':' block")); + Token * _keyword; + Token * _literal; + Token * _literal_1; + Token * _literal_2; + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + asdl_seq * a; + Token * async_var; + asdl_seq* b; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + && + (_keyword = _PyPegen_expect_token(p, 519)) // token='with' + && + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = _gather_43_rule(p)) // ','.with_item+ + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + && + (_literal_2 = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + ) + { + D(fprintf(stderr, "%*c+ with_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC 'with' '(' ','.with_item+ ','? ')' ':' block")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = CHECK_VERSION ( 5 , "Async with statements are" , _Py_AsyncWith ( a , b , NULL , EXTRA ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s with_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC 'with' '(' ','.with_item+ ','? ')' ':' block")); + } + { // ASYNC 'with' ','.with_item+ ':' TYPE_COMMENT? block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> with_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC 'with' ','.with_item+ ':' TYPE_COMMENT? block")); + Token * _keyword; + Token * _literal; + asdl_seq * a; + Token * async_var; + asdl_seq* b; + void *tc; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + && + (_keyword = _PyPegen_expect_token(p, 519)) // token='with' + && + (a = _gather_45_rule(p)) // ','.with_item+ + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + (b = block_rule(p)) // block + ) + { + D(fprintf(stderr, "%*c+ with_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC 'with' ','.with_item+ ':' TYPE_COMMENT? block")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = CHECK_VERSION ( 5 , "Async with statements are" , _Py_AsyncWith ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s with_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC 'with' ','.with_item+ ':' TYPE_COMMENT? block")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} - D(printf("Token %s/'%s' ... ", _PyParser_TokenNames[type], str)); +// with_item: expression 'as' target &(',' | ')' | ':') | invalid_with_item | expression +static withitem_ty +with_item_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + withitem_ty _res = NULL; + int _mark = p->mark; + { // expression 'as' target &(',' | ')' | ':') + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> with_item[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression 'as' target &(',' | ')' | ':')")); + Token * _keyword; + expr_ty e; + expr_ty t; + if ( + (e = expression_rule(p)) // expression + && + (_keyword = _PyPegen_expect_token(p, 520)) // token='as' + && + (t = target_rule(p)) // target + && + _PyPegen_lookahead(1, _tmp_47_rule, p) + ) + { + D(fprintf(stderr, "%*c+ with_item[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression 'as' target &(',' | ')' | ':')")); + _res = _Py_withitem ( e , t , p -> arena ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s with_item[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression 'as' target &(',' | ')' | ':')")); + } + { // invalid_with_item + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> with_item[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_with_item")); + void *invalid_with_item_var; + if ( + (invalid_with_item_var = invalid_with_item_rule(p)) // invalid_with_item + ) + { + D(fprintf(stderr, "%*c+ with_item[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_with_item")); + _res = invalid_with_item_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s with_item[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_with_item")); + } + { // expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> with_item[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression")); + expr_ty e; + if ( + (e = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ with_item[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression")); + _res = _Py_withitem ( e , NULL , p -> arena ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s with_item[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} - /* Find out which label this token is */ - ilabel = classify(ps, type, str); - if (ilabel < 0) - return E_SYNTAX; +// try_stmt: +// | 'try' ':' block finally_block +// | 'try' ':' block except_block+ else_block? finally_block? +static stmt_ty +try_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'try' ':' block finally_block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> try_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'try' ':' block finally_block")); + Token * _keyword; + Token * _literal; + asdl_seq* b; + asdl_seq* f; + if ( + (_keyword = _PyPegen_expect_token(p, 511)) // token='try' + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (f = finally_block_rule(p)) // finally_block + ) + { + D(fprintf(stderr, "%*c+ try_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'try' ':' block finally_block")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Try ( b , NULL , NULL , f , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s try_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'try' ':' block finally_block")); + } + { // 'try' ':' block except_block+ else_block? finally_block? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> try_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'try' ':' block except_block+ else_block? finally_block?")); + Token * _keyword; + Token * _literal; + asdl_seq* b; + void *el; + asdl_seq * ex; + void *f; + if ( + (_keyword = _PyPegen_expect_token(p, 511)) // token='try' + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + && + (ex = _loop1_48_rule(p)) // except_block+ + && + (el = else_block_rule(p), 1) // else_block? + && + (f = finally_block_rule(p), 1) // finally_block? + ) + { + D(fprintf(stderr, "%*c+ try_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'try' ':' block except_block+ else_block? finally_block?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Try ( b , ex , el , f , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s try_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'try' ':' block except_block+ else_block? finally_block?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} - /* Loop until the token is shifted or an error occurred */ - for (;;) { - /* Fetch the current dfa and state */ - const dfa *d = ps->p_stack.s_top->s_dfa; - state *s = &d->d_state[ps->p_stack.s_top->s_state]; +// except_block: 'except' expression ['as' NAME] ':' block | 'except' ':' block +static excepthandler_ty +except_block_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + excepthandler_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'except' expression ['as' NAME] ':' block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> except_block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'except' expression ['as' NAME] ':' block")); + Token * _keyword; + Token * _literal; + asdl_seq* b; + expr_ty e; + void *t; + if ( + (_keyword = _PyPegen_expect_token(p, 521)) // token='except' + && + (e = expression_rule(p)) // expression + && + (t = _tmp_49_rule(p), 1) // ['as' NAME] + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + ) + { + D(fprintf(stderr, "%*c+ except_block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'except' expression ['as' NAME] ':' block")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_ExceptHandler ( e , ( t ) ? ( ( expr_ty ) t ) -> v . Name . id : NULL , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s except_block[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'except' expression ['as' NAME] ':' block")); + } + { // 'except' ':' block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> except_block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'except' ':' block")); + Token * _keyword; + Token * _literal; + asdl_seq* b; + if ( + (_keyword = _PyPegen_expect_token(p, 521)) // token='except' + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = block_rule(p)) // block + ) + { + D(fprintf(stderr, "%*c+ except_block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'except' ':' block")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_ExceptHandler ( NULL , NULL , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s except_block[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'except' ':' block")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} - D(printf(" DFA '%s', state %d:", - d->d_name, ps->p_stack.s_top->s_state)); +// finally_block: 'finally' ':' block +static asdl_seq* +finally_block_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // 'finally' ':' block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> finally_block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'finally' ':' block")); + Token * _keyword; + Token * _literal; + asdl_seq* a; + if ( + (_keyword = _PyPegen_expect_token(p, 522)) // token='finally' + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (a = block_rule(p)) // block + ) + { + D(fprintf(stderr, "%*c+ finally_block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'finally' ':' block")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s finally_block[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'finally' ':' block")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} - /* Check accelerator */ - if (s->s_lower <= ilabel && ilabel < s->s_upper) { - int x = s->s_accel[ilabel - s->s_lower]; - if (x != -1) { - if (x & (1<<7)) { - /* Push non-terminal */ - int nt = (x >> 8) + NT_OFFSET; - int arrow = x & ((1<<7)-1); - if (nt == func_body_suite && !(ps->p_flags & PyCF_TYPE_COMMENTS)) { - /* When parsing type comments is not requested, - we can provide better errors about bad indentation - by using 'suite' for the body of a funcdef */ - D(printf(" [switch func_body_suite to suite]")); - nt = suite; - } - const dfa *d1 = PyGrammar_FindDFA( - ps->p_grammar, nt); - if ((err = push(&ps->p_stack, nt, d1, - arrow, lineno, col_offset, - end_lineno, end_col_offset)) > 0) { - D(printf(" MemError: push\n")); - return err; - } - D(printf(" Push '%s'\n", d1->d_name)); - continue; +// return_stmt: 'return' star_expressions? +static stmt_ty +return_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'return' star_expressions? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> return_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'return' star_expressions?")); + Token * _keyword; + void *a; + if ( + (_keyword = _PyPegen_expect_token(p, 500)) // token='return' + && + (a = star_expressions_rule(p), 1) // star_expressions? + ) + { + D(fprintf(stderr, "%*c+ return_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'return' star_expressions?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Return ( a , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s return_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'return' star_expressions?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// raise_stmt: 'raise' expression ['from' expression] | 'raise' +static stmt_ty +raise_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'raise' expression ['from' expression] + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> raise_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'raise' expression ['from' expression]")); + Token * _keyword; + expr_ty a; + void *b; + if ( + (_keyword = _PyPegen_expect_token(p, 501)) // token='raise' + && + (a = expression_rule(p)) // expression + && + (b = _tmp_50_rule(p), 1) // ['from' expression] + ) + { + D(fprintf(stderr, "%*c+ raise_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'raise' expression ['from' expression]")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Raise ( a , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s raise_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'raise' expression ['from' expression]")); + } + { // 'raise' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> raise_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'raise'")); + Token * _keyword; + if ( + (_keyword = _PyPegen_expect_token(p, 501)) // token='raise' + ) + { + D(fprintf(stderr, "%*c+ raise_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'raise'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Raise ( NULL , NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s raise_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'raise'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// function_def: decorators function_def_raw | function_def_raw +static stmt_ty +function_def_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + { // decorators function_def_raw + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> function_def[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "decorators function_def_raw")); + asdl_seq* d; + stmt_ty f; + if ( + (d = decorators_rule(p)) // decorators + && + (f = function_def_raw_rule(p)) // function_def_raw + ) + { + D(fprintf(stderr, "%*c+ function_def[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "decorators function_def_raw")); + _res = _PyPegen_function_def_decorators ( p , d , f ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s function_def[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "decorators function_def_raw")); + } + { // function_def_raw + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> function_def[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "function_def_raw")); + stmt_ty function_def_raw_var; + if ( + (function_def_raw_var = function_def_raw_rule(p)) // function_def_raw + ) + { + D(fprintf(stderr, "%*c+ function_def[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "function_def_raw")); + _res = function_def_raw_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s function_def[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "function_def_raw")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// function_def_raw: +// | 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block +// | ASYNC 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block +static stmt_ty +function_def_raw_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> function_def_raw[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block")); + Token * _keyword; + Token * _literal; + Token * _literal_1; + Token * _literal_2; + void *a; + asdl_seq* b; + expr_ty n; + void *params; + void *tc; + if ( + (_keyword = _PyPegen_expect_token(p, 523)) // token='def' + && + (n = _PyPegen_name_token(p)) // NAME + && + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (params = params_rule(p), 1) // params? + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + && + (a = _tmp_51_rule(p), 1) // ['->' expression] + && + (_literal_2 = _PyPegen_expect_token(p, 11)) // token=':' + && + (tc = func_type_comment_rule(p), 1) // func_type_comment? + && + (b = block_rule(p)) // block + ) + { + D(fprintf(stderr, "%*c+ function_def_raw[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_FunctionDef ( n -> v . Name . id , ( params ) ? params : CHECK ( _PyPegen_empty_arguments ( p ) ) , b , NULL , a , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s function_def_raw[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block")); + } + { // ASYNC 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> function_def_raw[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block")); + Token * _keyword; + Token * _literal; + Token * _literal_1; + Token * _literal_2; + void *a; + Token * async_var; + asdl_seq* b; + expr_ty n; + void *params; + void *tc; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + && + (_keyword = _PyPegen_expect_token(p, 523)) // token='def' + && + (n = _PyPegen_name_token(p)) // NAME + && + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (params = params_rule(p), 1) // params? + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + && + (a = _tmp_52_rule(p), 1) // ['->' expression] + && + (_literal_2 = _PyPegen_expect_token(p, 11)) // token=':' + && + (tc = func_type_comment_rule(p), 1) // func_type_comment? + && + (b = block_rule(p)) // block + ) + { + D(fprintf(stderr, "%*c+ function_def_raw[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = CHECK_VERSION ( 5 , "Async functions are" , _Py_AsyncFunctionDef ( n -> v . Name . id , ( params ) ? params : CHECK ( _PyPegen_empty_arguments ( p ) ) , b , NULL , a , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s function_def_raw[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// func_type_comment: +// | NEWLINE TYPE_COMMENT &(NEWLINE INDENT) +// | invalid_double_type_comments +// | TYPE_COMMENT +static Token* +func_type_comment_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + Token* _res = NULL; + int _mark = p->mark; + { // NEWLINE TYPE_COMMENT &(NEWLINE INDENT) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> func_type_comment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE TYPE_COMMENT &(NEWLINE INDENT)")); + Token * newline_var; + Token * t; + if ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + && + (t = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' + && + _PyPegen_lookahead(1, _tmp_53_rule, p) + ) + { + D(fprintf(stderr, "%*c+ func_type_comment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NEWLINE TYPE_COMMENT &(NEWLINE INDENT)")); + _res = t; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s func_type_comment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE TYPE_COMMENT &(NEWLINE INDENT)")); + } + { // invalid_double_type_comments + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> func_type_comment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_double_type_comments")); + void *invalid_double_type_comments_var; + if ( + (invalid_double_type_comments_var = invalid_double_type_comments_rule(p)) // invalid_double_type_comments + ) + { + D(fprintf(stderr, "%*c+ func_type_comment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_double_type_comments")); + _res = invalid_double_type_comments_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s func_type_comment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_double_type_comments")); + } + { // TYPE_COMMENT + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> func_type_comment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "TYPE_COMMENT")); + Token * type_comment_var; + if ( + (type_comment_var = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' + ) + { + D(fprintf(stderr, "%*c+ func_type_comment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "TYPE_COMMENT")); + _res = type_comment_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s func_type_comment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "TYPE_COMMENT")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// params: invalid_parameters | parameters +static arguments_ty +params_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + arguments_ty _res = NULL; + int _mark = p->mark; + { // invalid_parameters + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> params[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_parameters")); + void *invalid_parameters_var; + if ( + (invalid_parameters_var = invalid_parameters_rule(p)) // invalid_parameters + ) + { + D(fprintf(stderr, "%*c+ params[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_parameters")); + _res = invalid_parameters_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s params[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_parameters")); + } + { // parameters + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> params[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "parameters")); + arguments_ty parameters_var; + if ( + (parameters_var = parameters_rule(p)) // parameters + ) + { + D(fprintf(stderr, "%*c+ params[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "parameters")); + _res = parameters_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s params[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "parameters")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// parameters: +// | slash_no_default param_no_default* param_with_default* star_etc? +// | slash_with_default param_with_default* star_etc? +// | param_no_default+ param_with_default* star_etc? +// | param_with_default+ star_etc? +// | star_etc +static arguments_ty +parameters_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + arguments_ty _res = NULL; + int _mark = p->mark; + { // slash_no_default param_no_default* param_with_default* star_etc? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "slash_no_default param_no_default* param_with_default* star_etc?")); + asdl_seq* a; + asdl_seq * b; + asdl_seq * c; + void *d; + if ( + (a = slash_no_default_rule(p)) // slash_no_default + && + (b = _loop0_54_rule(p)) // param_no_default* + && + (c = _loop0_55_rule(p)) // param_with_default* + && + (d = star_etc_rule(p), 1) // star_etc? + ) + { + D(fprintf(stderr, "%*c+ parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "slash_no_default param_no_default* param_with_default* star_etc?")); + _res = _PyPegen_make_arguments ( p , a , NULL , b , c , d ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s parameters[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "slash_no_default param_no_default* param_with_default* star_etc?")); + } + { // slash_with_default param_with_default* star_etc? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "slash_with_default param_with_default* star_etc?")); + SlashWithDefault* a; + asdl_seq * b; + void *c; + if ( + (a = slash_with_default_rule(p)) // slash_with_default + && + (b = _loop0_56_rule(p)) // param_with_default* + && + (c = star_etc_rule(p), 1) // star_etc? + ) + { + D(fprintf(stderr, "%*c+ parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "slash_with_default param_with_default* star_etc?")); + _res = _PyPegen_make_arguments ( p , NULL , a , NULL , b , c ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s parameters[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "slash_with_default param_with_default* star_etc?")); + } + { // param_no_default+ param_with_default* star_etc? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default+ param_with_default* star_etc?")); + asdl_seq * a; + asdl_seq * b; + void *c; + if ( + (a = _loop1_57_rule(p)) // param_no_default+ + && + (b = _loop0_58_rule(p)) // param_with_default* + && + (c = star_etc_rule(p), 1) // star_etc? + ) + { + D(fprintf(stderr, "%*c+ parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_no_default+ param_with_default* star_etc?")); + _res = _PyPegen_make_arguments ( p , NULL , NULL , a , b , c ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s parameters[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default+ param_with_default* star_etc?")); + } + { // param_with_default+ star_etc? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default+ star_etc?")); + asdl_seq * a; + void *b; + if ( + (a = _loop1_59_rule(p)) // param_with_default+ + && + (b = star_etc_rule(p), 1) // star_etc? + ) + { + D(fprintf(stderr, "%*c+ parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_with_default+ star_etc?")); + _res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , a , b ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s parameters[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default+ star_etc?")); + } + { // star_etc + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_etc")); + StarEtc* a; + if ( + (a = star_etc_rule(p)) // star_etc + ) + { + D(fprintf(stderr, "%*c+ parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_etc")); + _res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , NULL , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s parameters[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_etc")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// slash_no_default: param_no_default+ '/' ',' | param_no_default+ '/' &')' +static asdl_seq* +slash_no_default_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // param_no_default+ '/' ',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> slash_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default+ '/' ','")); + Token * _literal; + Token * _literal_1; + asdl_seq * a; + if ( + (a = _loop1_60_rule(p)) // param_no_default+ + && + (_literal = _PyPegen_expect_token(p, 17)) // token='/' + && + (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + D(fprintf(stderr, "%*c+ slash_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_no_default+ '/' ','")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s slash_no_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default+ '/' ','")); + } + { // param_no_default+ '/' &')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> slash_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default+ '/' &')'")); + Token * _literal; + asdl_seq * a; + if ( + (a = _loop1_61_rule(p)) // param_no_default+ + && + (_literal = _PyPegen_expect_token(p, 17)) // token='/' + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + ) + { + D(fprintf(stderr, "%*c+ slash_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_no_default+ '/' &')'")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s slash_no_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default+ '/' &')'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// slash_with_default: +// | param_no_default* param_with_default+ '/' ',' +// | param_no_default* param_with_default+ '/' &')' +static SlashWithDefault* +slash_with_default_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + SlashWithDefault* _res = NULL; + int _mark = p->mark; + { // param_no_default* param_with_default+ '/' ',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> slash_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default* param_with_default+ '/' ','")); + Token * _literal; + Token * _literal_1; + asdl_seq * a; + asdl_seq * b; + if ( + (a = _loop0_62_rule(p)) // param_no_default* + && + (b = _loop1_63_rule(p)) // param_with_default+ + && + (_literal = _PyPegen_expect_token(p, 17)) // token='/' + && + (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + D(fprintf(stderr, "%*c+ slash_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_no_default* param_with_default+ '/' ','")); + _res = _PyPegen_slash_with_default ( p , a , b ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s slash_with_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default* param_with_default+ '/' ','")); + } + { // param_no_default* param_with_default+ '/' &')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> slash_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default* param_with_default+ '/' &')'")); + Token * _literal; + asdl_seq * a; + asdl_seq * b; + if ( + (a = _loop0_64_rule(p)) // param_no_default* + && + (b = _loop1_65_rule(p)) // param_with_default+ + && + (_literal = _PyPegen_expect_token(p, 17)) // token='/' + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + ) + { + D(fprintf(stderr, "%*c+ slash_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_no_default* param_with_default+ '/' &')'")); + _res = _PyPegen_slash_with_default ( p , a , b ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s slash_with_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default* param_with_default+ '/' &')'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// star_etc: +// | '*' param_no_default param_maybe_default* kwds? +// | '*' ',' param_maybe_default+ kwds? +// | kwds +// | invalid_star_etc +static StarEtc* +star_etc_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + StarEtc* _res = NULL; + int _mark = p->mark; + { // '*' param_no_default param_maybe_default* kwds? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' param_no_default param_maybe_default* kwds?")); + Token * _literal; + arg_ty a; + asdl_seq * b; + void *c; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = param_no_default_rule(p)) // param_no_default + && + (b = _loop0_66_rule(p)) // param_maybe_default* + && + (c = kwds_rule(p), 1) // kwds? + ) + { + D(fprintf(stderr, "%*c+ star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' param_no_default param_maybe_default* kwds?")); + _res = _PyPegen_star_etc ( p , a , b , c ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_etc[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' param_no_default param_maybe_default* kwds?")); + } + { // '*' ',' param_maybe_default+ kwds? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' ',' param_maybe_default+ kwds?")); + Token * _literal; + Token * _literal_1; + asdl_seq * b; + void *c; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + && + (b = _loop1_67_rule(p)) // param_maybe_default+ + && + (c = kwds_rule(p), 1) // kwds? + ) + { + D(fprintf(stderr, "%*c+ star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' ',' param_maybe_default+ kwds?")); + _res = _PyPegen_star_etc ( p , NULL , b , c ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_etc[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' ',' param_maybe_default+ kwds?")); + } + { // kwds + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kwds")); + arg_ty a; + if ( + (a = kwds_rule(p)) // kwds + ) + { + D(fprintf(stderr, "%*c+ star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kwds")); + _res = _PyPegen_star_etc ( p , NULL , NULL , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_etc[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kwds")); + } + { // invalid_star_etc + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_star_etc")); + void *invalid_star_etc_var; + if ( + (invalid_star_etc_var = invalid_star_etc_rule(p)) // invalid_star_etc + ) + { + D(fprintf(stderr, "%*c+ star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_star_etc")); + _res = invalid_star_etc_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_etc[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_star_etc")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// kwds: '**' param_no_default +static arg_ty +kwds_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + arg_ty _res = NULL; + int _mark = p->mark; + { // '**' param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> kwds[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**' param_no_default")); + Token * _literal; + arg_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 35)) // token='**' + && + (a = param_no_default_rule(p)) // param_no_default + ) + { + D(fprintf(stderr, "%*c+ kwds[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**' param_no_default")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s kwds[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**' param_no_default")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// param_no_default: param ',' TYPE_COMMENT? | param TYPE_COMMENT? &')' +static arg_ty +param_no_default_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + arg_ty _res = NULL; + int _mark = p->mark; + { // param ',' TYPE_COMMENT? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> param_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param ',' TYPE_COMMENT?")); + Token * _literal; + arg_ty a; + void *tc; + if ( + (a = param_rule(p)) // param + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + ) + { + D(fprintf(stderr, "%*c+ param_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param ',' TYPE_COMMENT?")); + _res = _PyPegen_add_type_comment_to_arg ( p , a , tc ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s param_no_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param ',' TYPE_COMMENT?")); + } + { // param TYPE_COMMENT? &')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> param_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param TYPE_COMMENT? &')'")); + arg_ty a; + void *tc; + if ( + (a = param_rule(p)) // param + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + ) + { + D(fprintf(stderr, "%*c+ param_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param TYPE_COMMENT? &')'")); + _res = _PyPegen_add_type_comment_to_arg ( p , a , tc ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s param_no_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param TYPE_COMMENT? &')'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// param_with_default: param default ',' TYPE_COMMENT? | param default TYPE_COMMENT? &')' +static NameDefaultPair* +param_with_default_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + NameDefaultPair* _res = NULL; + int _mark = p->mark; + { // param default ',' TYPE_COMMENT? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> param_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param default ',' TYPE_COMMENT?")); + Token * _literal; + arg_ty a; + expr_ty c; + void *tc; + if ( + (a = param_rule(p)) // param + && + (c = default_rule(p)) // default + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + ) + { + D(fprintf(stderr, "%*c+ param_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param default ',' TYPE_COMMENT?")); + _res = _PyPegen_name_default_pair ( p , a , c , tc ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s param_with_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param default ',' TYPE_COMMENT?")); + } + { // param default TYPE_COMMENT? &')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> param_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param default TYPE_COMMENT? &')'")); + arg_ty a; + expr_ty c; + void *tc; + if ( + (a = param_rule(p)) // param + && + (c = default_rule(p)) // default + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + ) + { + D(fprintf(stderr, "%*c+ param_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param default TYPE_COMMENT? &')'")); + _res = _PyPegen_name_default_pair ( p , a , c , tc ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s param_with_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param default TYPE_COMMENT? &')'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// param_maybe_default: +// | param default? ',' TYPE_COMMENT? +// | param default? TYPE_COMMENT? &')' +static NameDefaultPair* +param_maybe_default_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + NameDefaultPair* _res = NULL; + int _mark = p->mark; + { // param default? ',' TYPE_COMMENT? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> param_maybe_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param default? ',' TYPE_COMMENT?")); + Token * _literal; + arg_ty a; + void *c; + void *tc; + if ( + (a = param_rule(p)) // param + && + (c = default_rule(p), 1) // default? + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + ) + { + D(fprintf(stderr, "%*c+ param_maybe_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param default? ',' TYPE_COMMENT?")); + _res = _PyPegen_name_default_pair ( p , a , c , tc ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s param_maybe_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param default? ',' TYPE_COMMENT?")); + } + { // param default? TYPE_COMMENT? &')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> param_maybe_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param default? TYPE_COMMENT? &')'")); + arg_ty a; + void *c; + void *tc; + if ( + (a = param_rule(p)) // param + && + (c = default_rule(p), 1) // default? + && + (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + ) + { + D(fprintf(stderr, "%*c+ param_maybe_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param default? TYPE_COMMENT? &')'")); + _res = _PyPegen_name_default_pair ( p , a , c , tc ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s param_maybe_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param default? TYPE_COMMENT? &')'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// param: NAME annotation? +static arg_ty +param_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + arg_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // NAME annotation? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> param[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME annotation?")); + expr_ty a; + void *b; + if ( + (a = _PyPegen_name_token(p)) // NAME + && + (b = annotation_rule(p), 1) // annotation? + ) + { + D(fprintf(stderr, "%*c+ param[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME annotation?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_arg ( a -> v . Name . id , b , NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s param[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME annotation?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// annotation: ':' expression +static expr_ty +annotation_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + { // ':' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> annotation[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "':' expression")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (a = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ annotation[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "':' expression")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s annotation[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "':' expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// default: '=' expression +static expr_ty +default_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + { // '=' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'=' expression")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 22)) // token='=' + && + (a = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'=' expression")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'=' expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// decorators: (('@' named_expression NEWLINE))+ +static asdl_seq* +decorators_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // (('@' named_expression NEWLINE))+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> decorators[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "(('@' named_expression NEWLINE))+")); + asdl_seq * a; + if ( + (a = _loop1_68_rule(p)) // (('@' named_expression NEWLINE))+ + ) + { + D(fprintf(stderr, "%*c+ decorators[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "(('@' named_expression NEWLINE))+")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s decorators[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "(('@' named_expression NEWLINE))+")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// class_def: decorators class_def_raw | class_def_raw +static stmt_ty +class_def_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + { // decorators class_def_raw + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> class_def[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "decorators class_def_raw")); + asdl_seq* a; + stmt_ty b; + if ( + (a = decorators_rule(p)) // decorators + && + (b = class_def_raw_rule(p)) // class_def_raw + ) + { + D(fprintf(stderr, "%*c+ class_def[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "decorators class_def_raw")); + _res = _PyPegen_class_def_decorators ( p , a , b ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s class_def[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "decorators class_def_raw")); + } + { // class_def_raw + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> class_def[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "class_def_raw")); + stmt_ty class_def_raw_var; + if ( + (class_def_raw_var = class_def_raw_rule(p)) // class_def_raw + ) + { + D(fprintf(stderr, "%*c+ class_def[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "class_def_raw")); + _res = class_def_raw_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s class_def[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "class_def_raw")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// class_def_raw: 'class' NAME ['(' arguments? ')'] ':' block +static stmt_ty +class_def_raw_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + stmt_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'class' NAME ['(' arguments? ')'] ':' block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> class_def_raw[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'class' NAME ['(' arguments? ')'] ':' block")); + Token * _keyword; + Token * _literal; + expr_ty a; + void *b; + asdl_seq* c; + if ( + (_keyword = _PyPegen_expect_token(p, 524)) // token='class' + && + (a = _PyPegen_name_token(p)) // NAME + && + (b = _tmp_69_rule(p), 1) // ['(' arguments? ')'] + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (c = block_rule(p)) // block + ) + { + D(fprintf(stderr, "%*c+ class_def_raw[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'class' NAME ['(' arguments? ')'] ':' block")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_ClassDef ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , c , NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s class_def_raw[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'class' NAME ['(' arguments? ')'] ':' block")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// block: NEWLINE INDENT statements DEDENT | simple_stmt | invalid_block +static asdl_seq* +block_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + if (_PyPegen_is_memoized(p, block_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + { // NEWLINE INDENT statements DEDENT + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE INDENT statements DEDENT")); + asdl_seq* a; + Token * dedent_var; + Token * indent_var; + Token * newline_var; + if ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + && + (indent_var = _PyPegen_expect_token(p, INDENT)) // token='INDENT' + && + (a = statements_rule(p)) // statements + && + (dedent_var = _PyPegen_expect_token(p, DEDENT)) // token='DEDENT' + ) + { + D(fprintf(stderr, "%*c+ block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NEWLINE INDENT statements DEDENT")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s block[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE INDENT statements DEDENT")); + } + { // simple_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "simple_stmt")); + asdl_seq* simple_stmt_var; + if ( + (simple_stmt_var = simple_stmt_rule(p)) // simple_stmt + ) + { + D(fprintf(stderr, "%*c+ block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "simple_stmt")); + _res = simple_stmt_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s block[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "simple_stmt")); + } + { // invalid_block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_block")); + void *invalid_block_var; + if ( + (invalid_block_var = invalid_block_rule(p)) // invalid_block + ) + { + D(fprintf(stderr, "%*c+ block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_block")); + _res = invalid_block_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s block[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_block")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, block_type, _res); + D(p->level--); + return _res; +} + +// expressions_list: ','.star_expression+ ','? +static asdl_seq* +expressions_list_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // ','.star_expression+ ','? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> expressions_list[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.star_expression+ ','?")); + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + asdl_seq * a; + if ( + (a = _gather_70_rule(p)) // ','.star_expression+ + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + D(fprintf(stderr, "%*c+ expressions_list[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.star_expression+ ','?")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s expressions_list[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.star_expression+ ','?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// star_expressions: +// | star_expression ((',' star_expression))+ ','? +// | star_expression ',' +// | star_expression +static expr_ty +star_expressions_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // star_expression ((',' star_expression))+ ','? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expression ((',' star_expression))+ ','?")); + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + expr_ty a; + asdl_seq * b; + if ( + (a = star_expression_rule(p)) // star_expression + && + (b = _loop1_72_rule(p)) // ((',' star_expression))+ + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + D(fprintf(stderr, "%*c+ star_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expression ((',' star_expression))+ ','?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expression ((',' star_expression))+ ','?")); + } + { // star_expression ',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expression ','")); + Token * _literal; + expr_ty a; + if ( + (a = star_expression_rule(p)) // star_expression + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + D(fprintf(stderr, "%*c+ star_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expression ','")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Tuple ( CHECK ( _PyPegen_singleton_seq ( p , a ) ) , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expression ','")); + } + { // star_expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expression")); + expr_ty star_expression_var; + if ( + (star_expression_var = star_expression_rule(p)) // star_expression + ) + { + D(fprintf(stderr, "%*c+ star_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expression")); + _res = star_expression_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// star_expression: '*' bitwise_or | expression +static expr_ty +star_expression_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, star_expression_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // '*' bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' bitwise_or")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ star_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' bitwise_or")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Starred ( a , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_expression[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' bitwise_or")); + } + { // expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression")); + expr_ty expression_var; + if ( + (expression_var = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ star_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression")); + _res = expression_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_expression[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, star_expression_type, _res); + D(p->level--); + return _res; +} + +// star_named_expressions: ','.star_named_expression+ ','? +static asdl_seq* +star_named_expressions_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // ','.star_named_expression+ ','? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_named_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.star_named_expression+ ','?")); + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + asdl_seq * a; + if ( + (a = _gather_73_rule(p)) // ','.star_named_expression+ + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + D(fprintf(stderr, "%*c+ star_named_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.star_named_expression+ ','?")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_named_expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.star_named_expression+ ','?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// star_named_expression: '*' bitwise_or | named_expression +static expr_ty +star_named_expression_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // '*' bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_named_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' bitwise_or")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ star_named_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' bitwise_or")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Starred ( a , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_named_expression[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' bitwise_or")); + } + { // named_expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_named_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "named_expression")); + expr_ty named_expression_var; + if ( + (named_expression_var = named_expression_rule(p)) // named_expression + ) + { + D(fprintf(stderr, "%*c+ star_named_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "named_expression")); + _res = named_expression_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_named_expression[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "named_expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// named_expression: NAME ':=' ~ expression | expression !':=' | invalid_named_expression +static expr_ty +named_expression_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // NAME ':=' ~ expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> named_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME ':=' ~ expression")); + int _cut_var = 0; + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = _PyPegen_name_token(p)) // NAME + && + (_literal = _PyPegen_expect_token(p, 53)) // token=':=' + && + (_cut_var = 1) + && + (b = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ named_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME ':=' ~ expression")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_NamedExpr ( CHECK ( _PyPegen_set_expr_context ( p , a , Store ) ) , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s named_expression[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME ':=' ~ expression")); + if (_cut_var) { + D(p->level--); + return NULL; + } + } + { // expression !':=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> named_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression !':='")); + expr_ty expression_var; + if ( + (expression_var = expression_rule(p)) // expression + && + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 53) // token=':=' + ) + { + D(fprintf(stderr, "%*c+ named_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression !':='")); + _res = expression_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s named_expression[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression !':='")); + } + { // invalid_named_expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> named_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_named_expression")); + void *invalid_named_expression_var; + if ( + (invalid_named_expression_var = invalid_named_expression_rule(p)) // invalid_named_expression + ) + { + D(fprintf(stderr, "%*c+ named_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_named_expression")); + _res = invalid_named_expression_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s named_expression[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_named_expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// annotated_rhs: yield_expr | star_expressions +static expr_ty +annotated_rhs_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + { // yield_expr + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> annotated_rhs[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "yield_expr")); + expr_ty yield_expr_var; + if ( + (yield_expr_var = yield_expr_rule(p)) // yield_expr + ) + { + D(fprintf(stderr, "%*c+ annotated_rhs[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "yield_expr")); + _res = yield_expr_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s annotated_rhs[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "yield_expr")); + } + { // star_expressions + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> annotated_rhs[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions")); + expr_ty star_expressions_var; + if ( + (star_expressions_var = star_expressions_rule(p)) // star_expressions + ) + { + D(fprintf(stderr, "%*c+ annotated_rhs[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions")); + _res = star_expressions_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s annotated_rhs[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// expressions: expression ((',' expression))+ ','? | expression ',' | expression +static expr_ty +expressions_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // expression ((',' expression))+ ','? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression ((',' expression))+ ','?")); + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + expr_ty a; + asdl_seq * b; + if ( + (a = expression_rule(p)) // expression + && + (b = _loop1_75_rule(p)) // ((',' expression))+ + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + D(fprintf(stderr, "%*c+ expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression ((',' expression))+ ','?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression ((',' expression))+ ','?")); + } + { // expression ',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression ','")); + Token * _literal; + expr_ty a; + if ( + (a = expression_rule(p)) // expression + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + D(fprintf(stderr, "%*c+ expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression ','")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Tuple ( CHECK ( _PyPegen_singleton_seq ( p , a ) ) , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression ','")); + } + { // expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression")); + expr_ty expression_var; + if ( + (expression_var = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression")); + _res = expression_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s expressions[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// expression: disjunction 'if' disjunction 'else' expression | disjunction | lambdef +static expr_ty +expression_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, expression_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // disjunction 'if' disjunction 'else' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "disjunction 'if' disjunction 'else' expression")); + Token * _keyword; + Token * _keyword_1; + expr_ty a; + expr_ty b; + expr_ty c; + if ( + (a = disjunction_rule(p)) // disjunction + && + (_keyword = _PyPegen_expect_token(p, 510)) // token='if' + && + (b = disjunction_rule(p)) // disjunction + && + (_keyword_1 = _PyPegen_expect_token(p, 516)) // token='else' + && + (c = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "disjunction 'if' disjunction 'else' expression")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_IfExp ( b , a , c , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s expression[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "disjunction 'if' disjunction 'else' expression")); + } + { // disjunction + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "disjunction")); + expr_ty disjunction_var; + if ( + (disjunction_var = disjunction_rule(p)) // disjunction + ) + { + D(fprintf(stderr, "%*c+ expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "disjunction")); + _res = disjunction_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s expression[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "disjunction")); + } + { // lambdef + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambdef")); + expr_ty lambdef_var; + if ( + (lambdef_var = lambdef_rule(p)) // lambdef + ) + { + D(fprintf(stderr, "%*c+ expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambdef")); + _res = lambdef_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s expression[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambdef")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, expression_type, _res); + D(p->level--); + return _res; +} + +// lambdef: 'lambda' lambda_params? ':' expression +static expr_ty +lambdef_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'lambda' lambda_params? ':' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambdef[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'lambda' lambda_params? ':' expression")); + Token * _keyword; + Token * _literal; + void *a; + expr_ty b; + if ( + (_keyword = _PyPegen_expect_token(p, 525)) // token='lambda' + && + (a = lambda_params_rule(p), 1) // lambda_params? + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ lambdef[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'lambda' lambda_params? ':' expression")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Lambda ( ( a ) ? a : CHECK ( _PyPegen_empty_arguments ( p ) ) , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambdef[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'lambda' lambda_params? ':' expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// lambda_params: invalid_lambda_parameters | lambda_parameters +static arguments_ty +lambda_params_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + arguments_ty _res = NULL; + int _mark = p->mark; + { // invalid_lambda_parameters + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_params[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_lambda_parameters")); + void *invalid_lambda_parameters_var; + if ( + (invalid_lambda_parameters_var = invalid_lambda_parameters_rule(p)) // invalid_lambda_parameters + ) + { + D(fprintf(stderr, "%*c+ lambda_params[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_lambda_parameters")); + _res = invalid_lambda_parameters_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_params[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_lambda_parameters")); + } + { // lambda_parameters + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_params[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_parameters")); + arguments_ty lambda_parameters_var; + if ( + (lambda_parameters_var = lambda_parameters_rule(p)) // lambda_parameters + ) + { + D(fprintf(stderr, "%*c+ lambda_params[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_parameters")); + _res = lambda_parameters_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_params[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_parameters")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// lambda_parameters: +// | lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc? +// | lambda_slash_with_default lambda_param_with_default* lambda_star_etc? +// | lambda_param_no_default+ lambda_param_with_default* lambda_star_etc? +// | lambda_param_with_default+ lambda_star_etc? +// | lambda_star_etc +static arguments_ty +lambda_parameters_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + arguments_ty _res = NULL; + int _mark = p->mark; + { // lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc?")); + asdl_seq* a; + asdl_seq * b; + asdl_seq * c; + void *d; + if ( + (a = lambda_slash_no_default_rule(p)) // lambda_slash_no_default + && + (b = _loop0_76_rule(p)) // lambda_param_no_default* + && + (c = _loop0_77_rule(p)) // lambda_param_with_default* + && + (d = lambda_star_etc_rule(p), 1) // lambda_star_etc? + ) + { + D(fprintf(stderr, "%*c+ lambda_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc?")); + _res = _PyPegen_make_arguments ( p , a , NULL , b , c , d ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_parameters[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc?")); + } + { // lambda_slash_with_default lambda_param_with_default* lambda_star_etc? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_slash_with_default lambda_param_with_default* lambda_star_etc?")); + SlashWithDefault* a; + asdl_seq * b; + void *c; + if ( + (a = lambda_slash_with_default_rule(p)) // lambda_slash_with_default + && + (b = _loop0_78_rule(p)) // lambda_param_with_default* + && + (c = lambda_star_etc_rule(p), 1) // lambda_star_etc? + ) + { + D(fprintf(stderr, "%*c+ lambda_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_slash_with_default lambda_param_with_default* lambda_star_etc?")); + _res = _PyPegen_make_arguments ( p , NULL , a , NULL , b , c ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_parameters[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_slash_with_default lambda_param_with_default* lambda_star_etc?")); + } + { // lambda_param_no_default+ lambda_param_with_default* lambda_star_etc? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default+ lambda_param_with_default* lambda_star_etc?")); + asdl_seq * a; + asdl_seq * b; + void *c; + if ( + (a = _loop1_79_rule(p)) // lambda_param_no_default+ + && + (b = _loop0_80_rule(p)) // lambda_param_with_default* + && + (c = lambda_star_etc_rule(p), 1) // lambda_star_etc? + ) + { + D(fprintf(stderr, "%*c+ lambda_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default+ lambda_param_with_default* lambda_star_etc?")); + _res = _PyPegen_make_arguments ( p , NULL , NULL , a , b , c ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_parameters[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default+ lambda_param_with_default* lambda_star_etc?")); + } + { // lambda_param_with_default+ lambda_star_etc? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default+ lambda_star_etc?")); + asdl_seq * a; + void *b; + if ( + (a = _loop1_81_rule(p)) // lambda_param_with_default+ + && + (b = lambda_star_etc_rule(p), 1) // lambda_star_etc? + ) + { + D(fprintf(stderr, "%*c+ lambda_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default+ lambda_star_etc?")); + _res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , a , b ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_parameters[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default+ lambda_star_etc?")); + } + { // lambda_star_etc + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_star_etc")); + StarEtc* a; + if ( + (a = lambda_star_etc_rule(p)) // lambda_star_etc + ) + { + D(fprintf(stderr, "%*c+ lambda_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_star_etc")); + _res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , NULL , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_parameters[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_star_etc")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// lambda_slash_no_default: +// | lambda_param_no_default+ '/' ',' +// | lambda_param_no_default+ '/' &':' +static asdl_seq* +lambda_slash_no_default_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // lambda_param_no_default+ '/' ',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_slash_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default+ '/' ','")); + Token * _literal; + Token * _literal_1; + asdl_seq * a; + if ( + (a = _loop1_82_rule(p)) // lambda_param_no_default+ + && + (_literal = _PyPegen_expect_token(p, 17)) // token='/' + && + (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + D(fprintf(stderr, "%*c+ lambda_slash_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default+ '/' ','")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_slash_no_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default+ '/' ','")); + } + { // lambda_param_no_default+ '/' &':' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_slash_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default+ '/' &':'")); + Token * _literal; + asdl_seq * a; + if ( + (a = _loop1_83_rule(p)) // lambda_param_no_default+ + && + (_literal = _PyPegen_expect_token(p, 17)) // token='/' + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + ) + { + D(fprintf(stderr, "%*c+ lambda_slash_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default+ '/' &':'")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_slash_no_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default+ '/' &':'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// lambda_slash_with_default: +// | lambda_param_no_default* lambda_param_with_default+ '/' ',' +// | lambda_param_no_default* lambda_param_with_default+ '/' &':' +static SlashWithDefault* +lambda_slash_with_default_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + SlashWithDefault* _res = NULL; + int _mark = p->mark; + { // lambda_param_no_default* lambda_param_with_default+ '/' ',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_slash_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default* lambda_param_with_default+ '/' ','")); + Token * _literal; + Token * _literal_1; + asdl_seq * a; + asdl_seq * b; + if ( + (a = _loop0_84_rule(p)) // lambda_param_no_default* + && + (b = _loop1_85_rule(p)) // lambda_param_with_default+ + && + (_literal = _PyPegen_expect_token(p, 17)) // token='/' + && + (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + D(fprintf(stderr, "%*c+ lambda_slash_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default* lambda_param_with_default+ '/' ','")); + _res = _PyPegen_slash_with_default ( p , a , b ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_slash_with_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default* lambda_param_with_default+ '/' ','")); + } + { // lambda_param_no_default* lambda_param_with_default+ '/' &':' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_slash_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default* lambda_param_with_default+ '/' &':'")); + Token * _literal; + asdl_seq * a; + asdl_seq * b; + if ( + (a = _loop0_86_rule(p)) // lambda_param_no_default* + && + (b = _loop1_87_rule(p)) // lambda_param_with_default+ + && + (_literal = _PyPegen_expect_token(p, 17)) // token='/' + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + ) + { + D(fprintf(stderr, "%*c+ lambda_slash_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default* lambda_param_with_default+ '/' &':'")); + _res = _PyPegen_slash_with_default ( p , a , b ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_slash_with_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default* lambda_param_with_default+ '/' &':'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// lambda_star_etc: +// | '*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds? +// | '*' ',' lambda_param_maybe_default+ lambda_kwds? +// | lambda_kwds +// | invalid_lambda_star_etc +static StarEtc* +lambda_star_etc_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + StarEtc* _res = NULL; + int _mark = p->mark; + { // '*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds?")); + Token * _literal; + arg_ty a; + asdl_seq * b; + void *c; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = lambda_param_no_default_rule(p)) // lambda_param_no_default + && + (b = _loop0_88_rule(p)) // lambda_param_maybe_default* + && + (c = lambda_kwds_rule(p), 1) // lambda_kwds? + ) + { + D(fprintf(stderr, "%*c+ lambda_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds?")); + _res = _PyPegen_star_etc ( p , a , b , c ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_star_etc[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds?")); + } + { // '*' ',' lambda_param_maybe_default+ lambda_kwds? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' ',' lambda_param_maybe_default+ lambda_kwds?")); + Token * _literal; + Token * _literal_1; + asdl_seq * b; + void *c; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + && + (b = _loop1_89_rule(p)) // lambda_param_maybe_default+ + && + (c = lambda_kwds_rule(p), 1) // lambda_kwds? + ) + { + D(fprintf(stderr, "%*c+ lambda_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' ',' lambda_param_maybe_default+ lambda_kwds?")); + _res = _PyPegen_star_etc ( p , NULL , b , c ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_star_etc[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' ',' lambda_param_maybe_default+ lambda_kwds?")); + } + { // lambda_kwds + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_kwds")); + arg_ty a; + if ( + (a = lambda_kwds_rule(p)) // lambda_kwds + ) + { + D(fprintf(stderr, "%*c+ lambda_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_kwds")); + _res = _PyPegen_star_etc ( p , NULL , NULL , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_star_etc[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_kwds")); + } + { // invalid_lambda_star_etc + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_lambda_star_etc")); + void *invalid_lambda_star_etc_var; + if ( + (invalid_lambda_star_etc_var = invalid_lambda_star_etc_rule(p)) // invalid_lambda_star_etc + ) + { + D(fprintf(stderr, "%*c+ lambda_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_lambda_star_etc")); + _res = invalid_lambda_star_etc_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_star_etc[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_lambda_star_etc")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// lambda_kwds: '**' lambda_param_no_default +static arg_ty +lambda_kwds_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + arg_ty _res = NULL; + int _mark = p->mark; + { // '**' lambda_param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_kwds[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**' lambda_param_no_default")); + Token * _literal; + arg_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 35)) // token='**' + && + (a = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + D(fprintf(stderr, "%*c+ lambda_kwds[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**' lambda_param_no_default")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_kwds[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**' lambda_param_no_default")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// lambda_param_no_default: lambda_param ',' | lambda_param &':' +static arg_ty +lambda_param_no_default_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + arg_ty _res = NULL; + int _mark = p->mark; + { // lambda_param ',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_param_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param ','")); + Token * _literal; + arg_ty a; + if ( + (a = lambda_param_rule(p)) // lambda_param + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + D(fprintf(stderr, "%*c+ lambda_param_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param ','")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_param_no_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param ','")); + } + { // lambda_param &':' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_param_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param &':'")); + arg_ty a; + if ( + (a = lambda_param_rule(p)) // lambda_param + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + ) + { + D(fprintf(stderr, "%*c+ lambda_param_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param &':'")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_param_no_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param &':'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// lambda_param_with_default: lambda_param default ',' | lambda_param default &':' +static NameDefaultPair* +lambda_param_with_default_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + NameDefaultPair* _res = NULL; + int _mark = p->mark; + { // lambda_param default ',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_param_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param default ','")); + Token * _literal; + arg_ty a; + expr_ty c; + if ( + (a = lambda_param_rule(p)) // lambda_param + && + (c = default_rule(p)) // default + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + D(fprintf(stderr, "%*c+ lambda_param_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param default ','")); + _res = _PyPegen_name_default_pair ( p , a , c , NULL ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_param_with_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param default ','")); + } + { // lambda_param default &':' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_param_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param default &':'")); + arg_ty a; + expr_ty c; + if ( + (a = lambda_param_rule(p)) // lambda_param + && + (c = default_rule(p)) // default + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + ) + { + D(fprintf(stderr, "%*c+ lambda_param_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param default &':'")); + _res = _PyPegen_name_default_pair ( p , a , c , NULL ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_param_with_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param default &':'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// lambda_param_maybe_default: lambda_param default? ',' | lambda_param default? &':' +static NameDefaultPair* +lambda_param_maybe_default_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + NameDefaultPair* _res = NULL; + int _mark = p->mark; + { // lambda_param default? ',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_param_maybe_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param default? ','")); + Token * _literal; + arg_ty a; + void *c; + if ( + (a = lambda_param_rule(p)) // lambda_param + && + (c = default_rule(p), 1) // default? + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + D(fprintf(stderr, "%*c+ lambda_param_maybe_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param default? ','")); + _res = _PyPegen_name_default_pair ( p , a , c , NULL ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_param_maybe_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param default? ','")); + } + { // lambda_param default? &':' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_param_maybe_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param default? &':'")); + arg_ty a; + void *c; + if ( + (a = lambda_param_rule(p)) // lambda_param + && + (c = default_rule(p), 1) // default? + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' + ) + { + D(fprintf(stderr, "%*c+ lambda_param_maybe_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param default? &':'")); + _res = _PyPegen_name_default_pair ( p , a , c , NULL ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_param_maybe_default[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param default? &':'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// lambda_param: NAME +static arg_ty +lambda_param_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + arg_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lambda_param[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME")); + expr_ty a; + if ( + (a = _PyPegen_name_token(p)) // NAME + ) + { + D(fprintf(stderr, "%*c+ lambda_param[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_arg ( a -> v . Name . id , NULL , NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lambda_param[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// disjunction: conjunction (('or' conjunction))+ | conjunction +static expr_ty +disjunction_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, disjunction_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // conjunction (('or' conjunction))+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> disjunction[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "conjunction (('or' conjunction))+")); + expr_ty a; + asdl_seq * b; + if ( + (a = conjunction_rule(p)) // conjunction + && + (b = _loop1_90_rule(p)) // (('or' conjunction))+ + ) + { + D(fprintf(stderr, "%*c+ disjunction[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "conjunction (('or' conjunction))+")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BoolOp ( Or , CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s disjunction[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "conjunction (('or' conjunction))+")); + } + { // conjunction + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> disjunction[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "conjunction")); + expr_ty conjunction_var; + if ( + (conjunction_var = conjunction_rule(p)) // conjunction + ) + { + D(fprintf(stderr, "%*c+ disjunction[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "conjunction")); + _res = conjunction_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s disjunction[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "conjunction")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, disjunction_type, _res); + D(p->level--); + return _res; +} + +// conjunction: inversion (('and' inversion))+ | inversion +static expr_ty +conjunction_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, conjunction_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // inversion (('and' inversion))+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> conjunction[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "inversion (('and' inversion))+")); + expr_ty a; + asdl_seq * b; + if ( + (a = inversion_rule(p)) // inversion + && + (b = _loop1_91_rule(p)) // (('and' inversion))+ + ) + { + D(fprintf(stderr, "%*c+ conjunction[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "inversion (('and' inversion))+")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BoolOp ( And , CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s conjunction[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "inversion (('and' inversion))+")); + } + { // inversion + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> conjunction[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "inversion")); + expr_ty inversion_var; + if ( + (inversion_var = inversion_rule(p)) // inversion + ) + { + D(fprintf(stderr, "%*c+ conjunction[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "inversion")); + _res = inversion_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s conjunction[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "inversion")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, conjunction_type, _res); + D(p->level--); + return _res; +} + +// inversion: 'not' inversion | comparison +static expr_ty +inversion_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, inversion_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'not' inversion + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> inversion[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'not' inversion")); + Token * _keyword; + expr_ty a; + if ( + (_keyword = _PyPegen_expect_token(p, 526)) // token='not' + && + (a = inversion_rule(p)) // inversion + ) + { + D(fprintf(stderr, "%*c+ inversion[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'not' inversion")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_UnaryOp ( Not , a , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s inversion[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'not' inversion")); + } + { // comparison + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> inversion[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "comparison")); + expr_ty comparison_var; + if ( + (comparison_var = comparison_rule(p)) // comparison + ) + { + D(fprintf(stderr, "%*c+ inversion[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "comparison")); + _res = comparison_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s inversion[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "comparison")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, inversion_type, _res); + D(p->level--); + return _res; +} + +// comparison: bitwise_or compare_op_bitwise_or_pair+ | bitwise_or +static expr_ty +comparison_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // bitwise_or compare_op_bitwise_or_pair+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> comparison[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_or compare_op_bitwise_or_pair+")); + expr_ty a; + asdl_seq * b; + if ( + (a = bitwise_or_rule(p)) // bitwise_or + && + (b = _loop1_92_rule(p)) // compare_op_bitwise_or_pair+ + ) + { + D(fprintf(stderr, "%*c+ comparison[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_or compare_op_bitwise_or_pair+")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Compare ( a , CHECK ( _PyPegen_get_cmpops ( p , b ) ) , CHECK ( _PyPegen_get_exprs ( p , b ) ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s comparison[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_or compare_op_bitwise_or_pair+")); + } + { // bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> comparison[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_or")); + expr_ty bitwise_or_var; + if ( + (bitwise_or_var = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ comparison[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_or")); + _res = bitwise_or_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s comparison[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_or")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// compare_op_bitwise_or_pair: +// | eq_bitwise_or +// | noteq_bitwise_or +// | lte_bitwise_or +// | lt_bitwise_or +// | gte_bitwise_or +// | gt_bitwise_or +// | notin_bitwise_or +// | in_bitwise_or +// | isnot_bitwise_or +// | is_bitwise_or +static CmpopExprPair* +compare_op_bitwise_or_pair_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + CmpopExprPair* _res = NULL; + int _mark = p->mark; + { // eq_bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "eq_bitwise_or")); + CmpopExprPair* eq_bitwise_or_var; + if ( + (eq_bitwise_or_var = eq_bitwise_or_rule(p)) // eq_bitwise_or + ) + { + D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "eq_bitwise_or")); + _res = eq_bitwise_or_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "eq_bitwise_or")); + } + { // noteq_bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "noteq_bitwise_or")); + CmpopExprPair* noteq_bitwise_or_var; + if ( + (noteq_bitwise_or_var = noteq_bitwise_or_rule(p)) // noteq_bitwise_or + ) + { + D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "noteq_bitwise_or")); + _res = noteq_bitwise_or_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "noteq_bitwise_or")); + } + { // lte_bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lte_bitwise_or")); + CmpopExprPair* lte_bitwise_or_var; + if ( + (lte_bitwise_or_var = lte_bitwise_or_rule(p)) // lte_bitwise_or + ) + { + D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lte_bitwise_or")); + _res = lte_bitwise_or_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lte_bitwise_or")); + } + { // lt_bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lt_bitwise_or")); + CmpopExprPair* lt_bitwise_or_var; + if ( + (lt_bitwise_or_var = lt_bitwise_or_rule(p)) // lt_bitwise_or + ) + { + D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lt_bitwise_or")); + _res = lt_bitwise_or_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lt_bitwise_or")); + } + { // gte_bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "gte_bitwise_or")); + CmpopExprPair* gte_bitwise_or_var; + if ( + (gte_bitwise_or_var = gte_bitwise_or_rule(p)) // gte_bitwise_or + ) + { + D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "gte_bitwise_or")); + _res = gte_bitwise_or_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "gte_bitwise_or")); + } + { // gt_bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "gt_bitwise_or")); + CmpopExprPair* gt_bitwise_or_var; + if ( + (gt_bitwise_or_var = gt_bitwise_or_rule(p)) // gt_bitwise_or + ) + { + D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "gt_bitwise_or")); + _res = gt_bitwise_or_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "gt_bitwise_or")); + } + { // notin_bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "notin_bitwise_or")); + CmpopExprPair* notin_bitwise_or_var; + if ( + (notin_bitwise_or_var = notin_bitwise_or_rule(p)) // notin_bitwise_or + ) + { + D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "notin_bitwise_or")); + _res = notin_bitwise_or_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "notin_bitwise_or")); + } + { // in_bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "in_bitwise_or")); + CmpopExprPair* in_bitwise_or_var; + if ( + (in_bitwise_or_var = in_bitwise_or_rule(p)) // in_bitwise_or + ) + { + D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "in_bitwise_or")); + _res = in_bitwise_or_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "in_bitwise_or")); + } + { // isnot_bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "isnot_bitwise_or")); + CmpopExprPair* isnot_bitwise_or_var; + if ( + (isnot_bitwise_or_var = isnot_bitwise_or_rule(p)) // isnot_bitwise_or + ) + { + D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "isnot_bitwise_or")); + _res = isnot_bitwise_or_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "isnot_bitwise_or")); + } + { // is_bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "is_bitwise_or")); + CmpopExprPair* is_bitwise_or_var; + if ( + (is_bitwise_or_var = is_bitwise_or_rule(p)) // is_bitwise_or + ) + { + D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "is_bitwise_or")); + _res = is_bitwise_or_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "is_bitwise_or")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// eq_bitwise_or: '==' bitwise_or +static CmpopExprPair* +eq_bitwise_or_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + CmpopExprPair* _res = NULL; + int _mark = p->mark; + { // '==' bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> eq_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'==' bitwise_or")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 27)) // token='==' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ eq_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'==' bitwise_or")); + _res = _PyPegen_cmpop_expr_pair ( p , Eq , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s eq_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'==' bitwise_or")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// noteq_bitwise_or: ('!=') bitwise_or +static CmpopExprPair* +noteq_bitwise_or_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + CmpopExprPair* _res = NULL; + int _mark = p->mark; + { // ('!=') bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> noteq_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('!=') bitwise_or")); + void *_tmp_93_var; + expr_ty a; + if ( + (_tmp_93_var = _tmp_93_rule(p)) // '!=' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ noteq_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "('!=') bitwise_or")); + _res = _PyPegen_cmpop_expr_pair ( p , NotEq , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s noteq_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('!=') bitwise_or")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// lte_bitwise_or: '<=' bitwise_or +static CmpopExprPair* +lte_bitwise_or_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + CmpopExprPair* _res = NULL; + int _mark = p->mark; + { // '<=' bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lte_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'<=' bitwise_or")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 29)) // token='<=' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ lte_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'<=' bitwise_or")); + _res = _PyPegen_cmpop_expr_pair ( p , LtE , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lte_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'<=' bitwise_or")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// lt_bitwise_or: '<' bitwise_or +static CmpopExprPair* +lt_bitwise_or_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + CmpopExprPair* _res = NULL; + int _mark = p->mark; + { // '<' bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> lt_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'<' bitwise_or")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 20)) // token='<' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ lt_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'<' bitwise_or")); + _res = _PyPegen_cmpop_expr_pair ( p , Lt , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s lt_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'<' bitwise_or")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// gte_bitwise_or: '>=' bitwise_or +static CmpopExprPair* +gte_bitwise_or_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + CmpopExprPair* _res = NULL; + int _mark = p->mark; + { // '>=' bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> gte_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'>=' bitwise_or")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 30)) // token='>=' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ gte_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'>=' bitwise_or")); + _res = _PyPegen_cmpop_expr_pair ( p , GtE , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s gte_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'>=' bitwise_or")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// gt_bitwise_or: '>' bitwise_or +static CmpopExprPair* +gt_bitwise_or_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + CmpopExprPair* _res = NULL; + int _mark = p->mark; + { // '>' bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> gt_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'>' bitwise_or")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 21)) // token='>' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ gt_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'>' bitwise_or")); + _res = _PyPegen_cmpop_expr_pair ( p , Gt , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s gt_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'>' bitwise_or")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// notin_bitwise_or: 'not' 'in' bitwise_or +static CmpopExprPair* +notin_bitwise_or_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + CmpopExprPair* _res = NULL; + int _mark = p->mark; + { // 'not' 'in' bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> notin_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'not' 'in' bitwise_or")); + Token * _keyword; + Token * _keyword_1; + expr_ty a; + if ( + (_keyword = _PyPegen_expect_token(p, 526)) // token='not' + && + (_keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ notin_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'not' 'in' bitwise_or")); + _res = _PyPegen_cmpop_expr_pair ( p , NotIn , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s notin_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'not' 'in' bitwise_or")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// in_bitwise_or: 'in' bitwise_or +static CmpopExprPair* +in_bitwise_or_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + CmpopExprPair* _res = NULL; + int _mark = p->mark; + { // 'in' bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> in_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'in' bitwise_or")); + Token * _keyword; + expr_ty a; + if ( + (_keyword = _PyPegen_expect_token(p, 518)) // token='in' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ in_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'in' bitwise_or")); + _res = _PyPegen_cmpop_expr_pair ( p , In , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s in_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'in' bitwise_or")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// isnot_bitwise_or: 'is' 'not' bitwise_or +static CmpopExprPair* +isnot_bitwise_or_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + CmpopExprPair* _res = NULL; + int _mark = p->mark; + { // 'is' 'not' bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> isnot_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'is' 'not' bitwise_or")); + Token * _keyword; + Token * _keyword_1; + expr_ty a; + if ( + (_keyword = _PyPegen_expect_token(p, 527)) // token='is' + && + (_keyword_1 = _PyPegen_expect_token(p, 526)) // token='not' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ isnot_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'is' 'not' bitwise_or")); + _res = _PyPegen_cmpop_expr_pair ( p , IsNot , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s isnot_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'is' 'not' bitwise_or")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// is_bitwise_or: 'is' bitwise_or +static CmpopExprPair* +is_bitwise_or_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + CmpopExprPair* _res = NULL; + int _mark = p->mark; + { // 'is' bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> is_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'is' bitwise_or")); + Token * _keyword; + expr_ty a; + if ( + (_keyword = _PyPegen_expect_token(p, 527)) // token='is' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ is_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'is' bitwise_or")); + _res = _PyPegen_cmpop_expr_pair ( p , Is , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s is_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'is' bitwise_or")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// Left-recursive +// bitwise_or: bitwise_or '|' bitwise_xor | bitwise_xor +static expr_ty bitwise_or_raw(Parser *); +static expr_ty +bitwise_or_rule(Parser *p) +{ + D(p->level++); + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, bitwise_or_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + int _resmark = p->mark; + while (1) { + int tmpvar_1 = _PyPegen_update_memo(p, _mark, bitwise_or_type, _res); + if (tmpvar_1) { + D(p->level--); + return _res; + } + p->mark = _mark; + void *_raw = bitwise_or_raw(p); + if (_raw == NULL || p->mark <= _resmark) + break; + _resmark = p->mark; + _res = _raw; + } + p->mark = _resmark; + D(p->level--); + return _res; +} +static expr_ty +bitwise_or_raw(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // bitwise_or '|' bitwise_xor + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_or '|' bitwise_xor")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = bitwise_or_rule(p)) // bitwise_or + && + (_literal = _PyPegen_expect_token(p, 18)) // token='|' + && + (b = bitwise_xor_rule(p)) // bitwise_xor + ) + { + D(fprintf(stderr, "%*c+ bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_or '|' bitwise_xor")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BinOp ( a , BitOr , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_or '|' bitwise_xor")); + } + { // bitwise_xor + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_xor")); + expr_ty bitwise_xor_var; + if ( + (bitwise_xor_var = bitwise_xor_rule(p)) // bitwise_xor + ) + { + D(fprintf(stderr, "%*c+ bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_xor")); + _res = bitwise_xor_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_xor")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// Left-recursive +// bitwise_xor: bitwise_xor '^' bitwise_and | bitwise_and +static expr_ty bitwise_xor_raw(Parser *); +static expr_ty +bitwise_xor_rule(Parser *p) +{ + D(p->level++); + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, bitwise_xor_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + int _resmark = p->mark; + while (1) { + int tmpvar_2 = _PyPegen_update_memo(p, _mark, bitwise_xor_type, _res); + if (tmpvar_2) { + D(p->level--); + return _res; + } + p->mark = _mark; + void *_raw = bitwise_xor_raw(p); + if (_raw == NULL || p->mark <= _resmark) + break; + _resmark = p->mark; + _res = _raw; + } + p->mark = _resmark; + D(p->level--); + return _res; +} +static expr_ty +bitwise_xor_raw(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // bitwise_xor '^' bitwise_and + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> bitwise_xor[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_xor '^' bitwise_and")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = bitwise_xor_rule(p)) // bitwise_xor + && + (_literal = _PyPegen_expect_token(p, 32)) // token='^' + && + (b = bitwise_and_rule(p)) // bitwise_and + ) + { + D(fprintf(stderr, "%*c+ bitwise_xor[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_xor '^' bitwise_and")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BinOp ( a , BitXor , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s bitwise_xor[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_xor '^' bitwise_and")); + } + { // bitwise_and + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> bitwise_xor[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_and")); + expr_ty bitwise_and_var; + if ( + (bitwise_and_var = bitwise_and_rule(p)) // bitwise_and + ) + { + D(fprintf(stderr, "%*c+ bitwise_xor[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_and")); + _res = bitwise_and_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s bitwise_xor[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_and")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// Left-recursive +// bitwise_and: bitwise_and '&' shift_expr | shift_expr +static expr_ty bitwise_and_raw(Parser *); +static expr_ty +bitwise_and_rule(Parser *p) +{ + D(p->level++); + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, bitwise_and_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + int _resmark = p->mark; + while (1) { + int tmpvar_3 = _PyPegen_update_memo(p, _mark, bitwise_and_type, _res); + if (tmpvar_3) { + D(p->level--); + return _res; + } + p->mark = _mark; + void *_raw = bitwise_and_raw(p); + if (_raw == NULL || p->mark <= _resmark) + break; + _resmark = p->mark; + _res = _raw; + } + p->mark = _resmark; + D(p->level--); + return _res; +} +static expr_ty +bitwise_and_raw(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // bitwise_and '&' shift_expr + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> bitwise_and[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_and '&' shift_expr")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = bitwise_and_rule(p)) // bitwise_and + && + (_literal = _PyPegen_expect_token(p, 19)) // token='&' + && + (b = shift_expr_rule(p)) // shift_expr + ) + { + D(fprintf(stderr, "%*c+ bitwise_and[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_and '&' shift_expr")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BinOp ( a , BitAnd , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s bitwise_and[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_and '&' shift_expr")); + } + { // shift_expr + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> bitwise_and[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "shift_expr")); + expr_ty shift_expr_var; + if ( + (shift_expr_var = shift_expr_rule(p)) // shift_expr + ) + { + D(fprintf(stderr, "%*c+ bitwise_and[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "shift_expr")); + _res = shift_expr_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s bitwise_and[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "shift_expr")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// Left-recursive +// shift_expr: shift_expr '<<' sum | shift_expr '>>' sum | sum +static expr_ty shift_expr_raw(Parser *); +static expr_ty +shift_expr_rule(Parser *p) +{ + D(p->level++); + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, shift_expr_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + int _resmark = p->mark; + while (1) { + int tmpvar_4 = _PyPegen_update_memo(p, _mark, shift_expr_type, _res); + if (tmpvar_4) { + D(p->level--); + return _res; + } + p->mark = _mark; + void *_raw = shift_expr_raw(p); + if (_raw == NULL || p->mark <= _resmark) + break; + _resmark = p->mark; + _res = _raw; + } + p->mark = _resmark; + D(p->level--); + return _res; +} +static expr_ty +shift_expr_raw(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // shift_expr '<<' sum + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> shift_expr[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "shift_expr '<<' sum")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = shift_expr_rule(p)) // shift_expr + && + (_literal = _PyPegen_expect_token(p, 33)) // token='<<' + && + (b = sum_rule(p)) // sum + ) + { + D(fprintf(stderr, "%*c+ shift_expr[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "shift_expr '<<' sum")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BinOp ( a , LShift , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s shift_expr[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "shift_expr '<<' sum")); + } + { // shift_expr '>>' sum + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> shift_expr[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "shift_expr '>>' sum")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = shift_expr_rule(p)) // shift_expr + && + (_literal = _PyPegen_expect_token(p, 34)) // token='>>' + && + (b = sum_rule(p)) // sum + ) + { + D(fprintf(stderr, "%*c+ shift_expr[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "shift_expr '>>' sum")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BinOp ( a , RShift , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s shift_expr[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "shift_expr '>>' sum")); + } + { // sum + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> shift_expr[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "sum")); + expr_ty sum_var; + if ( + (sum_var = sum_rule(p)) // sum + ) + { + D(fprintf(stderr, "%*c+ shift_expr[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "sum")); + _res = sum_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s shift_expr[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "sum")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// Left-recursive +// sum: sum '+' term | sum '-' term | term +static expr_ty sum_raw(Parser *); +static expr_ty +sum_rule(Parser *p) +{ + D(p->level++); + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, sum_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + int _resmark = p->mark; + while (1) { + int tmpvar_5 = _PyPegen_update_memo(p, _mark, sum_type, _res); + if (tmpvar_5) { + D(p->level--); + return _res; + } + p->mark = _mark; + void *_raw = sum_raw(p); + if (_raw == NULL || p->mark <= _resmark) + break; + _resmark = p->mark; + _res = _raw; + } + p->mark = _resmark; + D(p->level--); + return _res; +} +static expr_ty +sum_raw(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // sum '+' term + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> sum[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "sum '+' term")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = sum_rule(p)) // sum + && + (_literal = _PyPegen_expect_token(p, 14)) // token='+' + && + (b = term_rule(p)) // term + ) + { + D(fprintf(stderr, "%*c+ sum[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "sum '+' term")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BinOp ( a , Add , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s sum[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "sum '+' term")); + } + { // sum '-' term + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> sum[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "sum '-' term")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = sum_rule(p)) // sum + && + (_literal = _PyPegen_expect_token(p, 15)) // token='-' + && + (b = term_rule(p)) // term + ) + { + D(fprintf(stderr, "%*c+ sum[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "sum '-' term")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BinOp ( a , Sub , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s sum[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "sum '-' term")); + } + { // term + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> sum[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "term")); + expr_ty term_var; + if ( + (term_var = term_rule(p)) // term + ) + { + D(fprintf(stderr, "%*c+ sum[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "term")); + _res = term_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s sum[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "term")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// Left-recursive +// term: +// | term '*' factor +// | term '/' factor +// | term '//' factor +// | term '%' factor +// | term '@' factor +// | factor +static expr_ty term_raw(Parser *); +static expr_ty +term_rule(Parser *p) +{ + D(p->level++); + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, term_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + int _resmark = p->mark; + while (1) { + int tmpvar_6 = _PyPegen_update_memo(p, _mark, term_type, _res); + if (tmpvar_6) { + D(p->level--); + return _res; + } + p->mark = _mark; + void *_raw = term_raw(p); + if (_raw == NULL || p->mark <= _resmark) + break; + _resmark = p->mark; + _res = _raw; + } + p->mark = _resmark; + D(p->level--); + return _res; +} +static expr_ty +term_raw(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // term '*' factor + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> term[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "term '*' factor")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = term_rule(p)) // term + && + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (b = factor_rule(p)) // factor + ) + { + D(fprintf(stderr, "%*c+ term[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "term '*' factor")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BinOp ( a , Mult , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "term '*' factor")); + } + { // term '/' factor + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> term[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "term '/' factor")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = term_rule(p)) // term + && + (_literal = _PyPegen_expect_token(p, 17)) // token='/' + && + (b = factor_rule(p)) // factor + ) + { + D(fprintf(stderr, "%*c+ term[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "term '/' factor")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BinOp ( a , Div , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "term '/' factor")); + } + { // term '//' factor + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> term[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "term '//' factor")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = term_rule(p)) // term + && + (_literal = _PyPegen_expect_token(p, 47)) // token='//' + && + (b = factor_rule(p)) // factor + ) + { + D(fprintf(stderr, "%*c+ term[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "term '//' factor")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BinOp ( a , FloorDiv , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "term '//' factor")); + } + { // term '%' factor + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> term[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "term '%' factor")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = term_rule(p)) // term + && + (_literal = _PyPegen_expect_token(p, 24)) // token='%' + && + (b = factor_rule(p)) // factor + ) + { + D(fprintf(stderr, "%*c+ term[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "term '%' factor")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BinOp ( a , Mod , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "term '%' factor")); + } + { // term '@' factor + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> term[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "term '@' factor")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = term_rule(p)) // term + && + (_literal = _PyPegen_expect_token(p, 49)) // token='@' + && + (b = factor_rule(p)) // factor + ) + { + D(fprintf(stderr, "%*c+ term[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "term '@' factor")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = CHECK_VERSION ( 5 , "The '@' operator is" , _Py_BinOp ( a , MatMult , b , EXTRA ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "term '@' factor")); + } + { // factor + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> term[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "factor")); + expr_ty factor_var; + if ( + (factor_var = factor_rule(p)) // factor + ) + { + D(fprintf(stderr, "%*c+ term[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "factor")); + _res = factor_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "factor")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// factor: '+' factor | '-' factor | '~' factor | power +static expr_ty +factor_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, factor_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // '+' factor + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> factor[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'+' factor")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 14)) // token='+' + && + (a = factor_rule(p)) // factor + ) + { + D(fprintf(stderr, "%*c+ factor[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'+' factor")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_UnaryOp ( UAdd , a , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s factor[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'+' factor")); + } + { // '-' factor + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> factor[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'-' factor")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 15)) // token='-' + && + (a = factor_rule(p)) // factor + ) + { + D(fprintf(stderr, "%*c+ factor[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'-' factor")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_UnaryOp ( USub , a , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s factor[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'-' factor")); + } + { // '~' factor + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> factor[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'~' factor")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 31)) // token='~' + && + (a = factor_rule(p)) // factor + ) + { + D(fprintf(stderr, "%*c+ factor[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'~' factor")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_UnaryOp ( Invert , a , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s factor[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'~' factor")); + } + { // power + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> factor[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "power")); + expr_ty power_var; + if ( + (power_var = power_rule(p)) // power + ) + { + D(fprintf(stderr, "%*c+ factor[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "power")); + _res = power_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s factor[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "power")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, factor_type, _res); + D(p->level--); + return _res; +} + +// power: await_primary '**' factor | await_primary +static expr_ty +power_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // await_primary '**' factor + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> power[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "await_primary '**' factor")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = await_primary_rule(p)) // await_primary + && + (_literal = _PyPegen_expect_token(p, 35)) // token='**' + && + (b = factor_rule(p)) // factor + ) + { + D(fprintf(stderr, "%*c+ power[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "await_primary '**' factor")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_BinOp ( a , Pow , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s power[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "await_primary '**' factor")); + } + { // await_primary + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> power[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "await_primary")); + expr_ty await_primary_var; + if ( + (await_primary_var = await_primary_rule(p)) // await_primary + ) + { + D(fprintf(stderr, "%*c+ power[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "await_primary")); + _res = await_primary_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s power[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "await_primary")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// await_primary: AWAIT primary | primary +static expr_ty +await_primary_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, await_primary_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // AWAIT primary + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> await_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "AWAIT primary")); + expr_ty a; + Token * await_var; + if ( + (await_var = _PyPegen_expect_token(p, AWAIT)) // token='AWAIT' + && + (a = primary_rule(p)) // primary + ) + { + D(fprintf(stderr, "%*c+ await_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "AWAIT primary")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = CHECK_VERSION ( 5 , "Await expressions are" , _Py_Await ( a , EXTRA ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s await_primary[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "AWAIT primary")); + } + { // primary + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> await_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "primary")); + expr_ty primary_var; + if ( + (primary_var = primary_rule(p)) // primary + ) + { + D(fprintf(stderr, "%*c+ await_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "primary")); + _res = primary_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s await_primary[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "primary")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, await_primary_type, _res); + D(p->level--); + return _res; +} + +// Left-recursive +// primary: +// | primary '.' NAME +// | primary genexp +// | primary '(' arguments? ')' +// | primary '[' slices ']' +// | atom +static expr_ty primary_raw(Parser *); +static expr_ty +primary_rule(Parser *p) +{ + D(p->level++); + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, primary_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + int _resmark = p->mark; + while (1) { + int tmpvar_7 = _PyPegen_update_memo(p, _mark, primary_type, _res); + if (tmpvar_7) { + D(p->level--); + return _res; + } + p->mark = _mark; + void *_raw = primary_raw(p); + if (_raw == NULL || p->mark <= _resmark) + break; + _resmark = p->mark; + _res = _raw; + } + p->mark = _resmark; + D(p->level--); + return _res; +} +static expr_ty +primary_raw(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // primary '.' NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "primary '.' NAME")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = primary_rule(p)) // primary + && + (_literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + ) + { + D(fprintf(stderr, "%*c+ primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "primary '.' NAME")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Attribute ( a , b -> v . Name . id , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s primary[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "primary '.' NAME")); + } + { // primary genexp + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "primary genexp")); + expr_ty a; + expr_ty b; + if ( + (a = primary_rule(p)) // primary + && + (b = genexp_rule(p)) // genexp + ) + { + D(fprintf(stderr, "%*c+ primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "primary genexp")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Call ( a , CHECK ( _PyPegen_singleton_seq ( p , b ) ) , NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s primary[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "primary genexp")); + } + { // primary '(' arguments? ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "primary '(' arguments? ')'")); + Token * _literal; + Token * _literal_1; + expr_ty a; + void *b; + if ( + (a = primary_rule(p)) // primary + && + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (b = arguments_rule(p), 1) // arguments? + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "primary '(' arguments? ')'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Call ( a , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s primary[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "primary '(' arguments? ')'")); + } + { // primary '[' slices ']' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "primary '[' slices ']'")); + Token * _literal; + Token * _literal_1; + expr_ty a; + expr_ty b; + if ( + (a = primary_rule(p)) // primary + && + (_literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = slices_rule(p)) // slices + && + (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + ) + { + D(fprintf(stderr, "%*c+ primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "primary '[' slices ']'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Subscript ( a , b , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s primary[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "primary '[' slices ']'")); + } + { // atom + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "atom")); + expr_ty atom_var; + if ( + (atom_var = atom_rule(p)) // atom + ) + { + D(fprintf(stderr, "%*c+ primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "atom")); + _res = atom_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s primary[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "atom")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// slices: slice !',' | ','.slice+ ','? +static expr_ty +slices_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // slice !',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> slices[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "slice !','")); + expr_ty a; + if ( + (a = slice_rule(p)) // slice + && + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 12) // token=',' + ) + { + D(fprintf(stderr, "%*c+ slices[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "slice !','")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s slices[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "slice !','")); + } + { // ','.slice+ ','? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> slices[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.slice+ ','?")); + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + asdl_seq * a; + if ( + (a = _gather_94_rule(p)) // ','.slice+ + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + D(fprintf(stderr, "%*c+ slices[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.slice+ ','?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Tuple ( a , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s slices[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.slice+ ','?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// slice: expression? ':' expression? [':' expression?] | expression +static expr_ty +slice_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // expression? ':' expression? [':' expression?] + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> slice[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression? ':' expression? [':' expression?]")); + Token * _literal; + void *a; + void *b; + void *c; + if ( + (a = expression_rule(p), 1) // expression? + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = expression_rule(p), 1) // expression? + && + (c = _tmp_96_rule(p), 1) // [':' expression?] + ) + { + D(fprintf(stderr, "%*c+ slice[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression? ':' expression? [':' expression?]")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Slice ( a , b , c , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s slice[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression? ':' expression? [':' expression?]")); + } + { // expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> slice[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression")); + expr_ty a; + if ( + (a = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ slice[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s slice[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// atom: +// | NAME +// | 'True' +// | 'False' +// | 'None' +// | &STRING strings +// | NUMBER +// | &'(' (tuple | group | genexp) +// | &'[' (list | listcomp) +// | &'{' (dict | set | dictcomp | setcomp) +// | '...' +static expr_ty +atom_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME")); + expr_ty name_var; + if ( + (name_var = _PyPegen_name_token(p)) // NAME + ) + { + D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME")); + _res = name_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME")); + } + { // 'True' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'True'")); + Token * _keyword; + if ( + (_keyword = _PyPegen_expect_token(p, 528)) // token='True' + ) + { + D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'True'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Constant ( Py_True , NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'True'")); + } + { // 'False' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'False'")); + Token * _keyword; + if ( + (_keyword = _PyPegen_expect_token(p, 529)) // token='False' + ) + { + D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'False'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Constant ( Py_False , NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'False'")); + } + { // 'None' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'None'")); + Token * _keyword; + if ( + (_keyword = _PyPegen_expect_token(p, 530)) // token='None' + ) + { + D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'None'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Constant ( Py_None , NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'None'")); + } + { // &STRING strings + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&STRING strings")); + expr_ty strings_var; + if ( + _PyPegen_lookahead(1, _PyPegen_string_token, p) + && + (strings_var = strings_rule(p)) // strings + ) + { + D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&STRING strings")); + _res = strings_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&STRING strings")); + } + { // NUMBER + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NUMBER")); + expr_ty number_var; + if ( + (number_var = _PyPegen_number_token(p)) // NUMBER + ) + { + D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NUMBER")); + _res = number_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NUMBER")); + } + { // &'(' (tuple | group | genexp) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'(' (tuple | group | genexp)")); + void *_tmp_97_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 7) // token='(' + && + (_tmp_97_var = _tmp_97_rule(p)) // tuple | group | genexp + ) + { + D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'(' (tuple | group | genexp)")); + _res = _tmp_97_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'(' (tuple | group | genexp)")); + } + { // &'[' (list | listcomp) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'[' (list | listcomp)")); + void *_tmp_98_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 9) // token='[' + && + (_tmp_98_var = _tmp_98_rule(p)) // list | listcomp + ) + { + D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'[' (list | listcomp)")); + _res = _tmp_98_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'[' (list | listcomp)")); + } + { // &'{' (dict | set | dictcomp | setcomp) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'{' (dict | set | dictcomp | setcomp)")); + void *_tmp_99_var; + if ( + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 25) // token='{' + && + (_tmp_99_var = _tmp_99_rule(p)) // dict | set | dictcomp | setcomp + ) + { + D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'{' (dict | set | dictcomp | setcomp)")); + _res = _tmp_99_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'{' (dict | set | dictcomp | setcomp)")); + } + { // '...' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'...'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 52)) // token='...' + ) + { + D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'...'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Constant ( Py_Ellipsis , NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'...'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// strings: STRING+ +static expr_ty +strings_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, strings_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + { // STRING+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> strings[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "STRING+")); + asdl_seq * a; + if ( + (a = _loop1_100_rule(p)) // STRING+ + ) + { + D(fprintf(stderr, "%*c+ strings[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "STRING+")); + _res = _PyPegen_concatenate_strings ( p , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s strings[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "STRING+")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, strings_type, _res); + D(p->level--); + return _res; +} + +// list: '[' star_named_expressions? ']' +static expr_ty +list_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // '[' star_named_expressions? ']' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> list[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'[' star_named_expressions? ']'")); + Token * _literal; + Token * _literal_1; + void *a; + if ( + (_literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (a = star_named_expressions_rule(p), 1) // star_named_expressions? + && + (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + ) + { + D(fprintf(stderr, "%*c+ list[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'[' star_named_expressions? ']'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_List ( a , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s list[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'[' star_named_expressions? ']'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// listcomp: '[' named_expression ~ for_if_clauses ']' | invalid_comprehension +static expr_ty +listcomp_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // '[' named_expression ~ for_if_clauses ']' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> listcomp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'[' named_expression ~ for_if_clauses ']'")); + int _cut_var = 0; + Token * _literal; + Token * _literal_1; + expr_ty a; + asdl_seq* b; + if ( + (_literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (a = named_expression_rule(p)) // named_expression + && + (_cut_var = 1) + && + (b = for_if_clauses_rule(p)) // for_if_clauses + && + (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + ) + { + D(fprintf(stderr, "%*c+ listcomp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'[' named_expression ~ for_if_clauses ']'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_ListComp ( a , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s listcomp[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'[' named_expression ~ for_if_clauses ']'")); + if (_cut_var) { + D(p->level--); + return NULL; + } + } + { // invalid_comprehension + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> listcomp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_comprehension")); + void *invalid_comprehension_var; + if ( + (invalid_comprehension_var = invalid_comprehension_rule(p)) // invalid_comprehension + ) + { + D(fprintf(stderr, "%*c+ listcomp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_comprehension")); + _res = invalid_comprehension_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s listcomp[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_comprehension")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// tuple: '(' [star_named_expression ',' star_named_expressions?] ')' +static expr_ty +tuple_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // '(' [star_named_expression ',' star_named_expressions?] ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> tuple[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' [star_named_expression ',' star_named_expressions?] ')'")); + Token * _literal; + Token * _literal_1; + void *a; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = _tmp_101_rule(p), 1) // [star_named_expression ',' star_named_expressions?] + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ tuple[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' [star_named_expression ',' star_named_expressions?] ')'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Tuple ( a , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s tuple[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' [star_named_expression ',' star_named_expressions?] ')'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// group: '(' (yield_expr | named_expression) ')' | invalid_group +static expr_ty +group_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + { // '(' (yield_expr | named_expression) ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> group[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' (yield_expr | named_expression) ')'")); + Token * _literal; + Token * _literal_1; + void *a; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = _tmp_102_rule(p)) // yield_expr | named_expression + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ group[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' (yield_expr | named_expression) ')'")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s group[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' (yield_expr | named_expression) ')'")); + } + { // invalid_group + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> group[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_group")); + void *invalid_group_var; + if ( + (invalid_group_var = invalid_group_rule(p)) // invalid_group + ) + { + D(fprintf(stderr, "%*c+ group[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_group")); + _res = invalid_group_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s group[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_group")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// genexp: '(' expression ~ for_if_clauses ')' | invalid_comprehension +static expr_ty +genexp_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // '(' expression ~ for_if_clauses ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> genexp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' expression ~ for_if_clauses ')'")); + int _cut_var = 0; + Token * _literal; + Token * _literal_1; + expr_ty a; + asdl_seq* b; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = expression_rule(p)) // expression + && + (_cut_var = 1) + && + (b = for_if_clauses_rule(p)) // for_if_clauses + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ genexp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' expression ~ for_if_clauses ')'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_GeneratorExp ( a , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s genexp[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' expression ~ for_if_clauses ')'")); + if (_cut_var) { + D(p->level--); + return NULL; + } + } + { // invalid_comprehension + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> genexp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_comprehension")); + void *invalid_comprehension_var; + if ( + (invalid_comprehension_var = invalid_comprehension_rule(p)) // invalid_comprehension + ) + { + D(fprintf(stderr, "%*c+ genexp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_comprehension")); + _res = invalid_comprehension_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s genexp[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_comprehension")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// set: '{' expressions_list '}' +static expr_ty +set_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // '{' expressions_list '}' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> set[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'{' expressions_list '}'")); + Token * _literal; + Token * _literal_1; + asdl_seq* a; + if ( + (_literal = _PyPegen_expect_token(p, 25)) // token='{' + && + (a = expressions_list_rule(p)) // expressions_list + && + (_literal_1 = _PyPegen_expect_token(p, 26)) // token='}' + ) + { + D(fprintf(stderr, "%*c+ set[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'{' expressions_list '}'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Set ( a , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s set[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'{' expressions_list '}'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// setcomp: '{' expression ~ for_if_clauses '}' | invalid_comprehension +static expr_ty +setcomp_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // '{' expression ~ for_if_clauses '}' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> setcomp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'{' expression ~ for_if_clauses '}'")); + int _cut_var = 0; + Token * _literal; + Token * _literal_1; + expr_ty a; + asdl_seq* b; + if ( + (_literal = _PyPegen_expect_token(p, 25)) // token='{' + && + (a = expression_rule(p)) // expression + && + (_cut_var = 1) + && + (b = for_if_clauses_rule(p)) // for_if_clauses + && + (_literal_1 = _PyPegen_expect_token(p, 26)) // token='}' + ) + { + D(fprintf(stderr, "%*c+ setcomp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'{' expression ~ for_if_clauses '}'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_SetComp ( a , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s setcomp[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'{' expression ~ for_if_clauses '}'")); + if (_cut_var) { + D(p->level--); + return NULL; + } + } + { // invalid_comprehension + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> setcomp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_comprehension")); + void *invalid_comprehension_var; + if ( + (invalid_comprehension_var = invalid_comprehension_rule(p)) // invalid_comprehension + ) + { + D(fprintf(stderr, "%*c+ setcomp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_comprehension")); + _res = invalid_comprehension_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s setcomp[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_comprehension")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// dict: '{' double_starred_kvpairs? '}' +static expr_ty +dict_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // '{' double_starred_kvpairs? '}' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> dict[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'{' double_starred_kvpairs? '}'")); + Token * _literal; + Token * _literal_1; + void *a; + if ( + (_literal = _PyPegen_expect_token(p, 25)) // token='{' + && + (a = double_starred_kvpairs_rule(p), 1) // double_starred_kvpairs? + && + (_literal_1 = _PyPegen_expect_token(p, 26)) // token='}' + ) + { + D(fprintf(stderr, "%*c+ dict[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'{' double_starred_kvpairs? '}'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Dict ( CHECK ( _PyPegen_get_keys ( p , a ) ) , CHECK ( _PyPegen_get_values ( p , a ) ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s dict[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'{' double_starred_kvpairs? '}'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// dictcomp: '{' kvpair for_if_clauses '}' | invalid_dict_comprehension +static expr_ty +dictcomp_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // '{' kvpair for_if_clauses '}' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> dictcomp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'{' kvpair for_if_clauses '}'")); + Token * _literal; + Token * _literal_1; + KeyValuePair* a; + asdl_seq* b; + if ( + (_literal = _PyPegen_expect_token(p, 25)) // token='{' + && + (a = kvpair_rule(p)) // kvpair + && + (b = for_if_clauses_rule(p)) // for_if_clauses + && + (_literal_1 = _PyPegen_expect_token(p, 26)) // token='}' + ) + { + D(fprintf(stderr, "%*c+ dictcomp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'{' kvpair for_if_clauses '}'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_DictComp ( a -> key , a -> value , b , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s dictcomp[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'{' kvpair for_if_clauses '}'")); + } + { // invalid_dict_comprehension + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> dictcomp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_dict_comprehension")); + void *invalid_dict_comprehension_var; + if ( + (invalid_dict_comprehension_var = invalid_dict_comprehension_rule(p)) // invalid_dict_comprehension + ) + { + D(fprintf(stderr, "%*c+ dictcomp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_dict_comprehension")); + _res = invalid_dict_comprehension_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s dictcomp[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_dict_comprehension")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// double_starred_kvpairs: ','.double_starred_kvpair+ ','? +static asdl_seq* +double_starred_kvpairs_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // ','.double_starred_kvpair+ ','? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> double_starred_kvpairs[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.double_starred_kvpair+ ','?")); + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + asdl_seq * a; + if ( + (a = _gather_103_rule(p)) // ','.double_starred_kvpair+ + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + D(fprintf(stderr, "%*c+ double_starred_kvpairs[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.double_starred_kvpair+ ','?")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s double_starred_kvpairs[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.double_starred_kvpair+ ','?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// double_starred_kvpair: '**' bitwise_or | kvpair +static KeyValuePair* +double_starred_kvpair_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + KeyValuePair* _res = NULL; + int _mark = p->mark; + { // '**' bitwise_or + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> double_starred_kvpair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**' bitwise_or")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 35)) // token='**' + && + (a = bitwise_or_rule(p)) // bitwise_or + ) + { + D(fprintf(stderr, "%*c+ double_starred_kvpair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**' bitwise_or")); + _res = _PyPegen_key_value_pair ( p , NULL , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s double_starred_kvpair[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**' bitwise_or")); + } + { // kvpair + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> double_starred_kvpair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kvpair")); + KeyValuePair* kvpair_var; + if ( + (kvpair_var = kvpair_rule(p)) // kvpair + ) + { + D(fprintf(stderr, "%*c+ double_starred_kvpair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kvpair")); + _res = kvpair_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s double_starred_kvpair[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kvpair")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// kvpair: expression ':' expression +static KeyValuePair* +kvpair_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + KeyValuePair* _res = NULL; + int _mark = p->mark; + { // expression ':' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> kvpair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression ':' expression")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = expression_rule(p)) // expression + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (b = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ kvpair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression ':' expression")); + _res = _PyPegen_key_value_pair ( p , a , b ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s kvpair[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression ':' expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// for_if_clauses: for_if_clause+ +static asdl_seq* +for_if_clauses_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // for_if_clause+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> for_if_clauses[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "for_if_clause+")); + asdl_seq * _loop1_105_var; + if ( + (_loop1_105_var = _loop1_105_rule(p)) // for_if_clause+ + ) + { + D(fprintf(stderr, "%*c+ for_if_clauses[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "for_if_clause+")); + _res = _loop1_105_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s for_if_clauses[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "for_if_clause+")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// for_if_clause: +// | ASYNC 'for' star_targets 'in' ~ disjunction (('if' disjunction))* +// | 'for' star_targets 'in' ~ disjunction (('if' disjunction))* +// | invalid_for_target +static comprehension_ty +for_if_clause_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + comprehension_ty _res = NULL; + int _mark = p->mark; + { // ASYNC 'for' star_targets 'in' ~ disjunction (('if' disjunction))* + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> for_if_clause[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC 'for' star_targets 'in' ~ disjunction (('if' disjunction))*")); + int _cut_var = 0; + Token * _keyword; + Token * _keyword_1; + expr_ty a; + Token * async_var; + expr_ty b; + asdl_seq * c; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + && + (_keyword = _PyPegen_expect_token(p, 517)) // token='for' + && + (a = star_targets_rule(p)) // star_targets + && + (_keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + && + (_cut_var = 1) + && + (b = disjunction_rule(p)) // disjunction + && + (c = _loop0_106_rule(p)) // (('if' disjunction))* + ) + { + D(fprintf(stderr, "%*c+ for_if_clause[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC 'for' star_targets 'in' ~ disjunction (('if' disjunction))*")); + _res = CHECK_VERSION ( 6 , "Async comprehensions are" , _Py_comprehension ( a , b , c , 1 , p -> arena ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s for_if_clause[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC 'for' star_targets 'in' ~ disjunction (('if' disjunction))*")); + if (_cut_var) { + D(p->level--); + return NULL; + } + } + { // 'for' star_targets 'in' ~ disjunction (('if' disjunction))* + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> for_if_clause[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'for' star_targets 'in' ~ disjunction (('if' disjunction))*")); + int _cut_var = 0; + Token * _keyword; + Token * _keyword_1; + expr_ty a; + expr_ty b; + asdl_seq * c; + if ( + (_keyword = _PyPegen_expect_token(p, 517)) // token='for' + && + (a = star_targets_rule(p)) // star_targets + && + (_keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' + && + (_cut_var = 1) + && + (b = disjunction_rule(p)) // disjunction + && + (c = _loop0_107_rule(p)) // (('if' disjunction))* + ) + { + D(fprintf(stderr, "%*c+ for_if_clause[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'for' star_targets 'in' ~ disjunction (('if' disjunction))*")); + _res = _Py_comprehension ( a , b , c , 0 , p -> arena ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s for_if_clause[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'for' star_targets 'in' ~ disjunction (('if' disjunction))*")); + if (_cut_var) { + D(p->level--); + return NULL; + } + } + { // invalid_for_target + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> for_if_clause[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_for_target")); + void *invalid_for_target_var; + if ( + (invalid_for_target_var = invalid_for_target_rule(p)) // invalid_for_target + ) + { + D(fprintf(stderr, "%*c+ for_if_clause[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_for_target")); + _res = invalid_for_target_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s for_if_clause[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_for_target")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// yield_expr: 'yield' 'from' expression | 'yield' star_expressions? +static expr_ty +yield_expr_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // 'yield' 'from' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> yield_expr[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'yield' 'from' expression")); + Token * _keyword; + Token * _keyword_1; + expr_ty a; + if ( + (_keyword = _PyPegen_expect_token(p, 504)) // token='yield' + && + (_keyword_1 = _PyPegen_expect_token(p, 514)) // token='from' + && + (a = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ yield_expr[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'yield' 'from' expression")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_YieldFrom ( a , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s yield_expr[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'yield' 'from' expression")); + } + { // 'yield' star_expressions? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> yield_expr[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'yield' star_expressions?")); + Token * _keyword; + void *a; + if ( + (_keyword = _PyPegen_expect_token(p, 504)) // token='yield' + && + (a = star_expressions_rule(p), 1) // star_expressions? + ) + { + D(fprintf(stderr, "%*c+ yield_expr[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'yield' star_expressions?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Yield ( a , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s yield_expr[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'yield' star_expressions?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// arguments: args ','? &')' | incorrect_arguments +static expr_ty +arguments_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, arguments_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + { // args ','? &')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "args ','? &')'")); + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + expr_ty a; + if ( + (a = args_rule(p)) // args + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + && + _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' + ) + { + D(fprintf(stderr, "%*c+ arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "args ','? &')'")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s arguments[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "args ','? &')'")); + } + { // incorrect_arguments + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "incorrect_arguments")); + void *incorrect_arguments_var; + if ( + (incorrect_arguments_var = incorrect_arguments_rule(p)) // incorrect_arguments + ) + { + D(fprintf(stderr, "%*c+ arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "incorrect_arguments")); + _res = incorrect_arguments_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s arguments[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "incorrect_arguments")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, arguments_type, _res); + D(p->level--); + return _res; +} + +// args: starred_expression [',' args] | kwargs | named_expression [',' args] +static expr_ty +args_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // starred_expression [',' args] + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> args[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "starred_expression [',' args]")); + expr_ty a; + void *b; + if ( + (a = starred_expression_rule(p)) // starred_expression + && + (b = _tmp_108_rule(p), 1) // [',' args] + ) + { + D(fprintf(stderr, "%*c+ args[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "starred_expression [',' args]")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Call ( _PyPegen_dummy_name ( p ) , ( b ) ? CHECK ( _PyPegen_seq_insert_in_front ( p , a , ( ( expr_ty ) b ) -> v . Call . args ) ) : CHECK ( _PyPegen_singleton_seq ( p , a ) ) , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s args[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "starred_expression [',' args]")); + } + { // kwargs + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> args[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kwargs")); + asdl_seq* a; + if ( + (a = kwargs_rule(p)) // kwargs + ) + { + D(fprintf(stderr, "%*c+ args[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kwargs")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Call ( _PyPegen_dummy_name ( p ) , CHECK_NULL_ALLOWED ( _PyPegen_seq_extract_starred_exprs ( p , a ) ) , CHECK_NULL_ALLOWED ( _PyPegen_seq_delete_starred_exprs ( p , a ) ) , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s args[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kwargs")); + } + { // named_expression [',' args] + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> args[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "named_expression [',' args]")); + expr_ty a; + void *b; + if ( + (a = named_expression_rule(p)) // named_expression + && + (b = _tmp_109_rule(p), 1) // [',' args] + ) + { + D(fprintf(stderr, "%*c+ args[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "named_expression [',' args]")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Call ( _PyPegen_dummy_name ( p ) , ( b ) ? CHECK ( _PyPegen_seq_insert_in_front ( p , a , ( ( expr_ty ) b ) -> v . Call . args ) ) : CHECK ( _PyPegen_singleton_seq ( p , a ) ) , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s args[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "named_expression [',' args]")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// kwargs: +// | ','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+ +// | ','.kwarg_or_starred+ +// | ','.kwarg_or_double_starred+ +static asdl_seq* +kwargs_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // ','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> kwargs[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+")); + Token * _literal; + asdl_seq * a; + asdl_seq * b; + if ( + (a = _gather_110_rule(p)) // ','.kwarg_or_starred+ + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (b = _gather_112_rule(p)) // ','.kwarg_or_double_starred+ + ) + { + D(fprintf(stderr, "%*c+ kwargs[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+")); + _res = _PyPegen_join_sequences ( p , a , b ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s kwargs[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+")); + } + { // ','.kwarg_or_starred+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> kwargs[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.kwarg_or_starred+")); + asdl_seq * _gather_114_var; + if ( + (_gather_114_var = _gather_114_rule(p)) // ','.kwarg_or_starred+ + ) + { + D(fprintf(stderr, "%*c+ kwargs[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.kwarg_or_starred+")); + _res = _gather_114_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s kwargs[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.kwarg_or_starred+")); + } + { // ','.kwarg_or_double_starred+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> kwargs[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.kwarg_or_double_starred+")); + asdl_seq * _gather_116_var; + if ( + (_gather_116_var = _gather_116_rule(p)) // ','.kwarg_or_double_starred+ + ) + { + D(fprintf(stderr, "%*c+ kwargs[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.kwarg_or_double_starred+")); + _res = _gather_116_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s kwargs[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.kwarg_or_double_starred+")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// starred_expression: '*' expression +static expr_ty +starred_expression_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // '*' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> starred_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' expression")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ starred_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' expression")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Starred ( a , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s starred_expression[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// kwarg_or_starred: NAME '=' expression | starred_expression | invalid_kwarg +static KeywordOrStarred* +kwarg_or_starred_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + KeywordOrStarred* _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // NAME '=' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> kwarg_or_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME '=' expression")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = _PyPegen_name_token(p)) // NAME + && + (_literal = _PyPegen_expect_token(p, 22)) // token='=' + && + (b = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ kwarg_or_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME '=' expression")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( a -> v . Name . id , b , EXTRA ) ) , 1 ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s kwarg_or_starred[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME '=' expression")); + } + { // starred_expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> kwarg_or_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "starred_expression")); + expr_ty a; + if ( + (a = starred_expression_rule(p)) // starred_expression + ) + { + D(fprintf(stderr, "%*c+ kwarg_or_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "starred_expression")); + _res = _PyPegen_keyword_or_starred ( p , a , 0 ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s kwarg_or_starred[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "starred_expression")); + } + { // invalid_kwarg + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> kwarg_or_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_kwarg")); + void *invalid_kwarg_var; + if ( + (invalid_kwarg_var = invalid_kwarg_rule(p)) // invalid_kwarg + ) + { + D(fprintf(stderr, "%*c+ kwarg_or_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_kwarg")); + _res = invalid_kwarg_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s kwarg_or_starred[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_kwarg")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// kwarg_or_double_starred: NAME '=' expression | '**' expression | invalid_kwarg +static KeywordOrStarred* +kwarg_or_double_starred_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + KeywordOrStarred* _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // NAME '=' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> kwarg_or_double_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME '=' expression")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = _PyPegen_name_token(p)) // NAME + && + (_literal = _PyPegen_expect_token(p, 22)) // token='=' + && + (b = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ kwarg_or_double_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME '=' expression")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( a -> v . Name . id , b , EXTRA ) ) , 1 ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s kwarg_or_double_starred[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME '=' expression")); + } + { // '**' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> kwarg_or_double_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**' expression")); + Token * _literal; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 35)) // token='**' + && + (a = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ kwarg_or_double_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**' expression")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( NULL , a , EXTRA ) ) , 1 ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s kwarg_or_double_starred[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**' expression")); + } + { // invalid_kwarg + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> kwarg_or_double_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_kwarg")); + void *invalid_kwarg_var; + if ( + (invalid_kwarg_var = invalid_kwarg_rule(p)) // invalid_kwarg + ) + { + D(fprintf(stderr, "%*c+ kwarg_or_double_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_kwarg")); + _res = invalid_kwarg_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s kwarg_or_double_starred[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_kwarg")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// star_targets: star_target !',' | star_target ((',' star_target))* ','? +static expr_ty +star_targets_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // star_target !',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_target !','")); + expr_ty a; + if ( + (a = star_target_rule(p)) // star_target + && + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 12) // token=',' + ) + { + D(fprintf(stderr, "%*c+ star_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_target !','")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_targets[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_target !','")); + } + { // star_target ((',' star_target))* ','? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_target ((',' star_target))* ','?")); + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + expr_ty a; + asdl_seq * b; + if ( + (a = star_target_rule(p)) // star_target + && + (b = _loop0_118_rule(p)) // ((',' star_target))* + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + D(fprintf(stderr, "%*c+ star_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_target ((',' star_target))* ','?")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , Store , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_targets[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_target ((',' star_target))* ','?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// star_targets_seq: ','.star_target+ ','? +static asdl_seq* +star_targets_seq_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // ','.star_target+ ','? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_targets_seq[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.star_target+ ','?")); + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + asdl_seq * a; + if ( + (a = _gather_119_rule(p)) // ','.star_target+ + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + D(fprintf(stderr, "%*c+ star_targets_seq[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.star_target+ ','?")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_targets_seq[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.star_target+ ','?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// star_target: +// | '*' (!'*' star_target) +// | t_primary '.' NAME !t_lookahead +// | t_primary '[' slices ']' !t_lookahead +// | star_atom +static expr_ty +star_target_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, star_target_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // '*' (!'*' star_target) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' (!'*' star_target)")); + Token * _literal; + void *a; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (a = _tmp_121_rule(p)) // !'*' star_target + ) + { + D(fprintf(stderr, "%*c+ star_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' (!'*' star_target)")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Starred ( CHECK ( _PyPegen_set_expr_context ( p , a , Store ) ) , Store , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' (!'*' star_target)")); + } + { // t_primary '.' NAME !t_lookahead + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = t_primary_rule(p)) // t_primary + && + (_literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + D(fprintf(stderr, "%*c+ star_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Attribute ( a , b -> v . Name . id , Store , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '.' NAME !t_lookahead")); + } + { // t_primary '[' slices ']' !t_lookahead + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); + Token * _literal; + Token * _literal_1; + expr_ty a; + expr_ty b; + if ( + (a = t_primary_rule(p)) // t_primary + && + (_literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = slices_rule(p)) // slices + && + (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + D(fprintf(stderr, "%*c+ star_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Subscript ( a , b , Store , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); + } + { // star_atom + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_atom")); + expr_ty star_atom_var; + if ( + (star_atom_var = star_atom_rule(p)) // star_atom + ) + { + D(fprintf(stderr, "%*c+ star_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_atom")); + _res = star_atom_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_atom")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, star_target_type, _res); + D(p->level--); + return _res; +} + +// star_atom: +// | NAME +// | '(' star_target ')' +// | '(' star_targets_seq? ')' +// | '[' star_targets_seq? ']' +static expr_ty +star_atom_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME")); + expr_ty a; + if ( + (a = _PyPegen_name_token(p)) // NAME + ) + { + D(fprintf(stderr, "%*c+ star_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME")); + _res = _PyPegen_set_expr_context ( p , a , Store ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME")); + } + { // '(' star_target ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' star_target ')'")); + Token * _literal; + Token * _literal_1; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = star_target_rule(p)) // star_target + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ star_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' star_target ')'")); + _res = _PyPegen_set_expr_context ( p , a , Store ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' star_target ')'")); + } + { // '(' star_targets_seq? ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' star_targets_seq? ')'")); + Token * _literal; + Token * _literal_1; + void *a; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = star_targets_seq_rule(p), 1) // star_targets_seq? + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ star_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' star_targets_seq? ')'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Tuple ( a , Store , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' star_targets_seq? ')'")); + } + { // '[' star_targets_seq? ']' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> star_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'[' star_targets_seq? ']'")); + Token * _literal; + Token * _literal_1; + void *a; + if ( + (_literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (a = star_targets_seq_rule(p), 1) // star_targets_seq? + && + (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + ) + { + D(fprintf(stderr, "%*c+ star_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'[' star_targets_seq? ']'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_List ( a , Store , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s star_atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'[' star_targets_seq? ']'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// single_target: single_subscript_attribute_target | NAME | '(' single_target ')' +static expr_ty +single_target_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + { // single_subscript_attribute_target + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> single_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "single_subscript_attribute_target")); + expr_ty single_subscript_attribute_target_var; + if ( + (single_subscript_attribute_target_var = single_subscript_attribute_target_rule(p)) // single_subscript_attribute_target + ) + { + D(fprintf(stderr, "%*c+ single_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "single_subscript_attribute_target")); + _res = single_subscript_attribute_target_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s single_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "single_subscript_attribute_target")); + } + { // NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> single_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME")); + expr_ty a; + if ( + (a = _PyPegen_name_token(p)) // NAME + ) + { + D(fprintf(stderr, "%*c+ single_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME")); + _res = _PyPegen_set_expr_context ( p , a , Store ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s single_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME")); + } + { // '(' single_target ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> single_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' single_target ')'")); + Token * _literal; + Token * _literal_1; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = single_target_rule(p)) // single_target + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ single_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' single_target ')'")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s single_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' single_target ')'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// single_subscript_attribute_target: +// | t_primary '.' NAME !t_lookahead +// | t_primary '[' slices ']' !t_lookahead +static expr_ty +single_subscript_attribute_target_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // t_primary '.' NAME !t_lookahead + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> single_subscript_attribute_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = t_primary_rule(p)) // t_primary + && + (_literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + D(fprintf(stderr, "%*c+ single_subscript_attribute_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Attribute ( a , b -> v . Name . id , Store , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s single_subscript_attribute_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '.' NAME !t_lookahead")); + } + { // t_primary '[' slices ']' !t_lookahead + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> single_subscript_attribute_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); + Token * _literal; + Token * _literal_1; + expr_ty a; + expr_ty b; + if ( + (a = t_primary_rule(p)) // t_primary + && + (_literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = slices_rule(p)) // slices + && + (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + D(fprintf(stderr, "%*c+ single_subscript_attribute_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Subscript ( a , b , Store , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s single_subscript_attribute_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// del_targets: ','.del_target+ ','? +static asdl_seq* +del_targets_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // ','.del_target+ ','? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> del_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.del_target+ ','?")); + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + asdl_seq * a; + if ( + (a = _gather_122_rule(p)) // ','.del_target+ + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + D(fprintf(stderr, "%*c+ del_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.del_target+ ','?")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s del_targets[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.del_target+ ','?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// del_target: +// | t_primary '.' NAME !t_lookahead +// | t_primary '[' slices ']' !t_lookahead +// | del_t_atom +static expr_ty +del_target_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, del_target_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // t_primary '.' NAME !t_lookahead + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> del_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = t_primary_rule(p)) // t_primary + && + (_literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + D(fprintf(stderr, "%*c+ del_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Attribute ( a , b -> v . Name . id , Del , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s del_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '.' NAME !t_lookahead")); + } + { // t_primary '[' slices ']' !t_lookahead + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> del_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); + Token * _literal; + Token * _literal_1; + expr_ty a; + expr_ty b; + if ( + (a = t_primary_rule(p)) // t_primary + && + (_literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = slices_rule(p)) // slices + && + (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + D(fprintf(stderr, "%*c+ del_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Subscript ( a , b , Del , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s del_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); + } + { // del_t_atom + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> del_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "del_t_atom")); + expr_ty del_t_atom_var; + if ( + (del_t_atom_var = del_t_atom_rule(p)) // del_t_atom + ) + { + D(fprintf(stderr, "%*c+ del_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "del_t_atom")); + _res = del_t_atom_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s del_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "del_t_atom")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, del_target_type, _res); + D(p->level--); + return _res; +} + +// del_t_atom: NAME | '(' del_target ')' | '(' del_targets? ')' | '[' del_targets? ']' +static expr_ty +del_t_atom_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> del_t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME")); + expr_ty a; + if ( + (a = _PyPegen_name_token(p)) // NAME + ) + { + D(fprintf(stderr, "%*c+ del_t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME")); + _res = _PyPegen_set_expr_context ( p , a , Del ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s del_t_atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME")); + } + { // '(' del_target ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> del_t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' del_target ')'")); + Token * _literal; + Token * _literal_1; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = del_target_rule(p)) // del_target + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ del_t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' del_target ')'")); + _res = _PyPegen_set_expr_context ( p , a , Del ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s del_t_atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' del_target ')'")); + } + { // '(' del_targets? ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> del_t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' del_targets? ')'")); + Token * _literal; + Token * _literal_1; + void *a; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = del_targets_rule(p), 1) // del_targets? + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ del_t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' del_targets? ')'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Tuple ( a , Del , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s del_t_atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' del_targets? ')'")); + } + { // '[' del_targets? ']' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> del_t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'[' del_targets? ']'")); + Token * _literal; + Token * _literal_1; + void *a; + if ( + (_literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (a = del_targets_rule(p), 1) // del_targets? + && + (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + ) + { + D(fprintf(stderr, "%*c+ del_t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'[' del_targets? ']'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_List ( a , Del , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s del_t_atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'[' del_targets? ']'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// targets: ','.target+ ','? +static asdl_seq* +targets_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq* _res = NULL; + int _mark = p->mark; + { // ','.target+ ','? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.target+ ','?")); + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + asdl_seq * a; + if ( + (a = _gather_124_rule(p)) // ','.target+ + && + (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? + ) + { + D(fprintf(stderr, "%*c+ targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.target+ ','?")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s targets[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.target+ ','?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// target: +// | t_primary '.' NAME !t_lookahead +// | t_primary '[' slices ']' !t_lookahead +// | t_atom +static expr_ty +target_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, target_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // t_primary '.' NAME !t_lookahead + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = t_primary_rule(p)) // t_primary + && + (_literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + D(fprintf(stderr, "%*c+ target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Attribute ( a , b -> v . Name . id , Store , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '.' NAME !t_lookahead")); + } + { // t_primary '[' slices ']' !t_lookahead + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); + Token * _literal; + Token * _literal_1; + expr_ty a; + expr_ty b; + if ( + (a = t_primary_rule(p)) // t_primary + && + (_literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = slices_rule(p)) // slices + && + (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + && + _PyPegen_lookahead(0, t_lookahead_rule, p) + ) + { + D(fprintf(stderr, "%*c+ target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Subscript ( a , b , Store , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); + } + { // t_atom + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_atom")); + expr_ty t_atom_var; + if ( + (t_atom_var = t_atom_rule(p)) // t_atom + ) + { + D(fprintf(stderr, "%*c+ target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_atom")); + _res = t_atom_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_atom")); + } + _res = NULL; + done: + _PyPegen_insert_memo(p, _mark, target_type, _res); + D(p->level--); + return _res; +} + +// Left-recursive +// t_primary: +// | t_primary '.' NAME &t_lookahead +// | t_primary '[' slices ']' &t_lookahead +// | t_primary genexp &t_lookahead +// | t_primary '(' arguments? ')' &t_lookahead +// | atom &t_lookahead +static expr_ty t_primary_raw(Parser *); +static expr_ty +t_primary_rule(Parser *p) +{ + D(p->level++); + expr_ty _res = NULL; + if (_PyPegen_is_memoized(p, t_primary_type, &_res)) { + D(p->level--); + return _res; + } + int _mark = p->mark; + int _resmark = p->mark; + while (1) { + int tmpvar_8 = _PyPegen_update_memo(p, _mark, t_primary_type, _res); + if (tmpvar_8) { + D(p->level--); + return _res; + } + p->mark = _mark; + void *_raw = t_primary_raw(p); + if (_raw == NULL || p->mark <= _resmark) + break; + _resmark = p->mark; + _res = _raw; + } + p->mark = _resmark; + D(p->level--); + return _res; +} +static expr_ty +t_primary_raw(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // t_primary '.' NAME &t_lookahead + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> t_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME &t_lookahead")); + Token * _literal; + expr_ty a; + expr_ty b; + if ( + (a = t_primary_rule(p)) // t_primary + && + (_literal = _PyPegen_expect_token(p, 23)) // token='.' + && + (b = _PyPegen_name_token(p)) // NAME + && + _PyPegen_lookahead(1, t_lookahead_rule, p) + ) + { + D(fprintf(stderr, "%*c+ t_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME &t_lookahead")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Attribute ( a , b -> v . Name . id , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s t_primary[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '.' NAME &t_lookahead")); + } + { // t_primary '[' slices ']' &t_lookahead + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> t_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' &t_lookahead")); + Token * _literal; + Token * _literal_1; + expr_ty a; + expr_ty b; + if ( + (a = t_primary_rule(p)) // t_primary + && + (_literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = slices_rule(p)) // slices + && + (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + && + _PyPegen_lookahead(1, t_lookahead_rule, p) + ) + { + D(fprintf(stderr, "%*c+ t_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' &t_lookahead")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Subscript ( a , b , Load , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s t_primary[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '[' slices ']' &t_lookahead")); + } + { // t_primary genexp &t_lookahead + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> t_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary genexp &t_lookahead")); + expr_ty a; + expr_ty b; + if ( + (a = t_primary_rule(p)) // t_primary + && + (b = genexp_rule(p)) // genexp + && + _PyPegen_lookahead(1, t_lookahead_rule, p) + ) + { + D(fprintf(stderr, "%*c+ t_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary genexp &t_lookahead")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Call ( a , CHECK ( _PyPegen_singleton_seq ( p , b ) ) , NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s t_primary[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary genexp &t_lookahead")); + } + { // t_primary '(' arguments? ')' &t_lookahead + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> t_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '(' arguments? ')' &t_lookahead")); + Token * _literal; + Token * _literal_1; + expr_ty a; + void *b; + if ( + (a = t_primary_rule(p)) // t_primary + && + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (b = arguments_rule(p), 1) // arguments? + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + && + _PyPegen_lookahead(1, t_lookahead_rule, p) + ) + { + D(fprintf(stderr, "%*c+ t_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '(' arguments? ')' &t_lookahead")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Call ( a , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s t_primary[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '(' arguments? ')' &t_lookahead")); + } + { // atom &t_lookahead + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> t_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "atom &t_lookahead")); + expr_ty a; + if ( + (a = atom_rule(p)) // atom + && + _PyPegen_lookahead(1, t_lookahead_rule, p) + ) + { + D(fprintf(stderr, "%*c+ t_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "atom &t_lookahead")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s t_primary[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "atom &t_lookahead")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// t_lookahead: '(' | '[' | '.' +static void * +t_lookahead_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '(' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> t_lookahead[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'('")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + ) + { + D(fprintf(stderr, "%*c+ t_lookahead[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'('")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s t_lookahead[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'('")); + } + { // '[' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> t_lookahead[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'['")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 9)) // token='[' + ) + { + D(fprintf(stderr, "%*c+ t_lookahead[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'['")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s t_lookahead[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'['")); + } + { // '.' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> t_lookahead[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'.'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 23)) // token='.' + ) + { + D(fprintf(stderr, "%*c+ t_lookahead[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'.'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s t_lookahead[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'.'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// t_atom: NAME | '(' target ')' | '(' targets? ')' | '[' targets? ']' +static expr_ty +t_atom_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + int _start_lineno = p->tokens[_mark]->lineno; + UNUSED(_start_lineno); // Only used by EXTRA macro + int _start_col_offset = p->tokens[_mark]->col_offset; + UNUSED(_start_col_offset); // Only used by EXTRA macro + { // NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME")); + expr_ty a; + if ( + (a = _PyPegen_name_token(p)) // NAME + ) + { + D(fprintf(stderr, "%*c+ t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME")); + _res = _PyPegen_set_expr_context ( p , a , Store ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s t_atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME")); + } + { // '(' target ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' target ')'")); + Token * _literal; + Token * _literal_1; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = target_rule(p)) // target + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' target ')'")); + _res = _PyPegen_set_expr_context ( p , a , Store ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s t_atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' target ')'")); + } + { // '(' targets? ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' targets? ')'")); + Token * _literal; + Token * _literal_1; + void *b; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (b = targets_rule(p), 1) // targets? + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' targets? ')'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_Tuple ( b , Store , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s t_atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' targets? ')'")); + } + { // '[' targets? ']' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'[' targets? ']'")); + Token * _literal; + Token * _literal_1; + void *b; + if ( + (_literal = _PyPegen_expect_token(p, 9)) // token='[' + && + (b = targets_rule(p), 1) // targets? + && + (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' + ) + { + D(fprintf(stderr, "%*c+ t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'[' targets? ']'")); + Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); + if (_token == NULL) { + D(p->level--); + return NULL; + } + int _end_lineno = _token->end_lineno; + UNUSED(_end_lineno); // Only used by EXTRA macro + int _end_col_offset = _token->end_col_offset; + UNUSED(_end_col_offset); // Only used by EXTRA macro + _res = _Py_List ( b , Store , EXTRA ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s t_atom[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'[' targets? ']'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// incorrect_arguments: +// | args ',' '*' +// | expression for_if_clauses ',' [args | expression for_if_clauses] +// | args for_if_clauses +// | args ',' expression for_if_clauses +// | args ',' args +static void * +incorrect_arguments_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // args ',' '*' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> incorrect_arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "args ',' '*'")); + Token * _literal; + Token * _literal_1; + expr_ty args_var; + if ( + (args_var = args_rule(p)) // args + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (_literal_1 = _PyPegen_expect_token(p, 16)) // token='*' + ) + { + D(fprintf(stderr, "%*c+ incorrect_arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "args ',' '*'")); + _res = RAISE_SYNTAX_ERROR ( "iterable argument unpacking follows keyword argument unpacking" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s incorrect_arguments[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "args ',' '*'")); + } + { // expression for_if_clauses ',' [args | expression for_if_clauses] + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> incorrect_arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression for_if_clauses ',' [args | expression for_if_clauses]")); + Token * _literal; + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + expr_ty a; + asdl_seq* for_if_clauses_var; + if ( + (a = expression_rule(p)) // expression + && + (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (_opt_var = _tmp_126_rule(p), 1) // [args | expression for_if_clauses] + ) + { + D(fprintf(stderr, "%*c+ incorrect_arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression for_if_clauses ',' [args | expression for_if_clauses]")); + _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "Generator expression must be parenthesized" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s incorrect_arguments[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression for_if_clauses ',' [args | expression for_if_clauses]")); + } + { // args for_if_clauses + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> incorrect_arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "args for_if_clauses")); + expr_ty a; + asdl_seq* for_if_clauses_var; + if ( + (a = args_rule(p)) // args + && + (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses + ) + { + D(fprintf(stderr, "%*c+ incorrect_arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "args for_if_clauses")); + _res = _PyPegen_nonparen_genexp_in_call ( p , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s incorrect_arguments[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "args for_if_clauses")); + } + { // args ',' expression for_if_clauses + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> incorrect_arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "args ',' expression for_if_clauses")); + Token * _literal; + expr_ty a; + expr_ty args_var; + asdl_seq* for_if_clauses_var; + if ( + (args_var = args_rule(p)) // args + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (a = expression_rule(p)) // expression + && + (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses + ) + { + D(fprintf(stderr, "%*c+ incorrect_arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "args ',' expression for_if_clauses")); + _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "Generator expression must be parenthesized" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s incorrect_arguments[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "args ',' expression for_if_clauses")); + } + { // args ',' args + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> incorrect_arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "args ',' args")); + Token * _literal; + expr_ty a; + expr_ty args_var; + if ( + (a = args_rule(p)) // args + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (args_var = args_rule(p)) // args + ) + { + D(fprintf(stderr, "%*c+ incorrect_arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "args ',' args")); + _res = _PyPegen_arguments_parsing_error ( p , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s incorrect_arguments[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "args ',' args")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_kwarg: expression '=' +static void * +invalid_kwarg_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // expression '=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_kwarg[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression '='")); + Token * _literal; + expr_ty a; + if ( + (a = expression_rule(p)) // expression + && + (_literal = _PyPegen_expect_token(p, 22)) // token='=' + ) + { + D(fprintf(stderr, "%*c+ invalid_kwarg[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression '='")); + _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "expression cannot contain assignment, perhaps you meant \"==\"?" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_kwarg[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression '='")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_named_expression: expression ':=' expression +static void * +invalid_named_expression_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // expression ':=' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_named_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression ':=' expression")); + Token * _literal; + expr_ty a; + expr_ty expression_var; + if ( + (a = expression_rule(p)) // expression + && + (_literal = _PyPegen_expect_token(p, 53)) // token=':=' + && + (expression_var = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ invalid_named_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression ':=' expression")); + _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "cannot use assignment expressions with %s" , _PyPegen_get_expr_name ( a ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_named_expression[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression ':=' expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_assignment: +// | invalid_ann_assign_target ':' expression +// | star_named_expression ',' star_named_expressions* ':' expression +// | expression ':' expression +// | ((star_targets '='))* star_expressions '=' +// | ((star_targets '='))* yield_expr '=' +// | star_expressions augassign (yield_expr | star_expressions) +static void * +invalid_assignment_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // invalid_ann_assign_target ':' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_ann_assign_target ':' expression")); + Token * _literal; + expr_ty a; + expr_ty expression_var; + if ( + (a = invalid_ann_assign_target_rule(p)) // invalid_ann_assign_target + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (expression_var = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ invalid_assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_ann_assign_target ':' expression")); + _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "only single target (not %s) can be annotated" , _PyPegen_get_expr_name ( a ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_assignment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_ann_assign_target ':' expression")); + } + { // star_named_expression ',' star_named_expressions* ':' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_named_expression ',' star_named_expressions* ':' expression")); + Token * _literal; + Token * _literal_1; + asdl_seq * _loop0_127_var; + expr_ty a; + expr_ty expression_var; + if ( + (a = star_named_expression_rule(p)) // star_named_expression + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (_loop0_127_var = _loop0_127_rule(p)) // star_named_expressions* + && + (_literal_1 = _PyPegen_expect_token(p, 11)) // token=':' + && + (expression_var = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ invalid_assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_named_expression ',' star_named_expressions* ':' expression")); + _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "only single target (not tuple) can be annotated" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_assignment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_named_expression ',' star_named_expressions* ':' expression")); + } + { // expression ':' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression ':' expression")); + Token * _literal; + expr_ty a; + expr_ty expression_var; + if ( + (a = expression_rule(p)) // expression + && + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (expression_var = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ invalid_assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression ':' expression")); + _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "illegal target for annotation" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_assignment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression ':' expression")); + } + { // ((star_targets '='))* star_expressions '=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "((star_targets '='))* star_expressions '='")); + Token * _literal; + asdl_seq * _loop0_128_var; + expr_ty a; + if ( + (_loop0_128_var = _loop0_128_rule(p)) // ((star_targets '='))* + && + (a = star_expressions_rule(p)) // star_expressions + && + (_literal = _PyPegen_expect_token(p, 22)) // token='=' + ) + { + D(fprintf(stderr, "%*c+ invalid_assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "((star_targets '='))* star_expressions '='")); + _res = RAISE_SYNTAX_ERROR_INVALID_TARGET ( STAR_TARGETS , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_assignment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "((star_targets '='))* star_expressions '='")); + } + { // ((star_targets '='))* yield_expr '=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "((star_targets '='))* yield_expr '='")); + Token * _literal; + asdl_seq * _loop0_129_var; + expr_ty a; + if ( + (_loop0_129_var = _loop0_129_rule(p)) // ((star_targets '='))* + && + (a = yield_expr_rule(p)) // yield_expr + && + (_literal = _PyPegen_expect_token(p, 22)) // token='=' + ) + { + D(fprintf(stderr, "%*c+ invalid_assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "((star_targets '='))* yield_expr '='")); + _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "assignment to yield expression not possible" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_assignment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "((star_targets '='))* yield_expr '='")); + } + { // star_expressions augassign (yield_expr | star_expressions) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions augassign (yield_expr | star_expressions)")); + void *_tmp_130_var; + expr_ty a; + AugOperator* augassign_var; + if ( + (a = star_expressions_rule(p)) // star_expressions + && + (augassign_var = augassign_rule(p)) // augassign + && + (_tmp_130_var = _tmp_130_rule(p)) // yield_expr | star_expressions + ) + { + D(fprintf(stderr, "%*c+ invalid_assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions augassign (yield_expr | star_expressions)")); + _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "'%s' is an illegal expression for augmented assignment" , _PyPegen_get_expr_name ( a ) ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_assignment[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions augassign (yield_expr | star_expressions)")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_ann_assign_target: list | tuple | '(' invalid_ann_assign_target ')' +static expr_ty +invalid_ann_assign_target_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + expr_ty _res = NULL; + int _mark = p->mark; + { // list + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_ann_assign_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "list")); + expr_ty list_var; + if ( + (list_var = list_rule(p)) // list + ) + { + D(fprintf(stderr, "%*c+ invalid_ann_assign_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "list")); + _res = list_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_ann_assign_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "list")); + } + { // tuple + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_ann_assign_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "tuple")); + expr_ty tuple_var; + if ( + (tuple_var = tuple_rule(p)) // tuple + ) + { + D(fprintf(stderr, "%*c+ invalid_ann_assign_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "tuple")); + _res = tuple_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_ann_assign_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "tuple")); + } + { // '(' invalid_ann_assign_target ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_ann_assign_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' invalid_ann_assign_target ')'")); + Token * _literal; + Token * _literal_1; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = invalid_ann_assign_target_rule(p)) // invalid_ann_assign_target + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ invalid_ann_assign_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' invalid_ann_assign_target ')'")); + _res = a; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_ann_assign_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' invalid_ann_assign_target ')'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_del_stmt: 'del' star_expressions +static void * +invalid_del_stmt_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'del' star_expressions + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_del_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'del' star_expressions")); + Token * _keyword; + expr_ty a; + if ( + (_keyword = _PyPegen_expect_token(p, 503)) // token='del' + && + (a = star_expressions_rule(p)) // star_expressions + ) + { + D(fprintf(stderr, "%*c+ invalid_del_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'del' star_expressions")); + _res = RAISE_SYNTAX_ERROR_INVALID_TARGET ( DEL_TARGETS , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_del_stmt[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'del' star_expressions")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_block: NEWLINE !INDENT +static void * +invalid_block_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // NEWLINE !INDENT + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE !INDENT")); + Token * newline_var; + if ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + && + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, INDENT) // token=INDENT + ) + { + D(fprintf(stderr, "%*c+ invalid_block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NEWLINE !INDENT")); + _res = RAISE_INDENTATION_ERROR ( "expected an indented block" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_block[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE !INDENT")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_comprehension: ('[' | '(' | '{') starred_expression for_if_clauses +static void * +invalid_comprehension_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ('[' | '(' | '{') starred_expression for_if_clauses + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_comprehension[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('[' | '(' | '{') starred_expression for_if_clauses")); + void *_tmp_131_var; + expr_ty a; + asdl_seq* for_if_clauses_var; + if ( + (_tmp_131_var = _tmp_131_rule(p)) // '[' | '(' | '{' + && + (a = starred_expression_rule(p)) // starred_expression + && + (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses + ) + { + D(fprintf(stderr, "%*c+ invalid_comprehension[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "('[' | '(' | '{') starred_expression for_if_clauses")); + _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "iterable unpacking cannot be used in comprehension" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_comprehension[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('[' | '(' | '{') starred_expression for_if_clauses")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_dict_comprehension: '{' '**' bitwise_or for_if_clauses '}' +static void * +invalid_dict_comprehension_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '{' '**' bitwise_or for_if_clauses '}' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_dict_comprehension[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'{' '**' bitwise_or for_if_clauses '}'")); + Token * _literal; + Token * _literal_1; + Token * a; + expr_ty bitwise_or_var; + asdl_seq* for_if_clauses_var; + if ( + (_literal = _PyPegen_expect_token(p, 25)) // token='{' + && + (a = _PyPegen_expect_token(p, 35)) // token='**' + && + (bitwise_or_var = bitwise_or_rule(p)) // bitwise_or + && + (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses + && + (_literal_1 = _PyPegen_expect_token(p, 26)) // token='}' + ) + { + D(fprintf(stderr, "%*c+ invalid_dict_comprehension[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'{' '**' bitwise_or for_if_clauses '}'")); + _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "dict unpacking cannot be used in dict comprehension" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_dict_comprehension[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'{' '**' bitwise_or for_if_clauses '}'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_parameters: +// | param_no_default* (slash_with_default | param_with_default+) param_no_default +static void * +invalid_parameters_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // param_no_default* (slash_with_default | param_with_default+) param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default* (slash_with_default | param_with_default+) param_no_default")); + asdl_seq * _loop0_132_var; + void *_tmp_133_var; + arg_ty param_no_default_var; + if ( + (_loop0_132_var = _loop0_132_rule(p)) // param_no_default* + && + (_tmp_133_var = _tmp_133_rule(p)) // slash_with_default | param_with_default+ + && + (param_no_default_var = param_no_default_rule(p)) // param_no_default + ) + { + D(fprintf(stderr, "%*c+ invalid_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_no_default* (slash_with_default | param_with_default+) param_no_default")); + _res = RAISE_SYNTAX_ERROR ( "non-default argument follows default argument" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_parameters[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default* (slash_with_default | param_with_default+) param_no_default")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_lambda_parameters: +// | lambda_param_no_default* (lambda_slash_with_default | lambda_param_with_default+) lambda_param_no_default +static void * +invalid_lambda_parameters_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // lambda_param_no_default* (lambda_slash_with_default | lambda_param_with_default+) lambda_param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_lambda_parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default* (lambda_slash_with_default | lambda_param_with_default+) lambda_param_no_default")); + asdl_seq * _loop0_134_var; + void *_tmp_135_var; + arg_ty lambda_param_no_default_var; + if ( + (_loop0_134_var = _loop0_134_rule(p)) // lambda_param_no_default* + && + (_tmp_135_var = _tmp_135_rule(p)) // lambda_slash_with_default | lambda_param_with_default+ + && + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + D(fprintf(stderr, "%*c+ invalid_lambda_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default* (lambda_slash_with_default | lambda_param_with_default+) lambda_param_no_default")); + _res = RAISE_SYNTAX_ERROR ( "non-default argument follows default argument" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_lambda_parameters[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default* (lambda_slash_with_default | lambda_param_with_default+) lambda_param_no_default")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_star_etc: '*' (')' | ',' (')' | '**')) | '*' ',' TYPE_COMMENT +static void * +invalid_star_etc_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '*' (')' | ',' (')' | '**')) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' (')' | ',' (')' | '**'))")); + Token * _literal; + void *_tmp_136_var; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (_tmp_136_var = _tmp_136_rule(p)) // ')' | ',' (')' | '**') + ) + { + D(fprintf(stderr, "%*c+ invalid_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' (')' | ',' (')' | '**'))")); + _res = RAISE_SYNTAX_ERROR ( "named arguments must follow bare *" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_star_etc[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' (')' | ',' (')' | '**'))")); + } + { // '*' ',' TYPE_COMMENT + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' ',' TYPE_COMMENT")); + Token * _literal; + Token * _literal_1; + Token * type_comment_var; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' + && + (type_comment_var = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' + ) + { + D(fprintf(stderr, "%*c+ invalid_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' ',' TYPE_COMMENT")); + _res = RAISE_SYNTAX_ERROR ( "bare * has associated type comment" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_star_etc[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' ',' TYPE_COMMENT")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_lambda_star_etc: '*' (':' | ',' (':' | '**')) +static void * +invalid_lambda_star_etc_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '*' (':' | ',' (':' | '**')) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_lambda_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' (':' | ',' (':' | '**'))")); + Token * _literal; + void *_tmp_137_var; + if ( + (_literal = _PyPegen_expect_token(p, 16)) // token='*' + && + (_tmp_137_var = _tmp_137_rule(p)) // ':' | ',' (':' | '**') + ) + { + D(fprintf(stderr, "%*c+ invalid_lambda_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' (':' | ',' (':' | '**'))")); + _res = RAISE_SYNTAX_ERROR ( "named arguments must follow bare *" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_lambda_star_etc[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' (':' | ',' (':' | '**'))")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_double_type_comments: TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT +static void * +invalid_double_type_comments_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_double_type_comments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT")); + Token * indent_var; + Token * newline_var; + Token * newline_var_1; + Token * type_comment_var; + Token * type_comment_var_1; + if ( + (type_comment_var = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' + && + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + && + (type_comment_var_1 = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' + && + (newline_var_1 = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + && + (indent_var = _PyPegen_expect_token(p, INDENT)) // token='INDENT' + ) + { + D(fprintf(stderr, "%*c+ invalid_double_type_comments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT")); + _res = RAISE_SYNTAX_ERROR ( "Cannot have two type comments on def" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_double_type_comments[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_with_item: expression 'as' expression +static void * +invalid_with_item_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // expression 'as' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_with_item[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression 'as' expression")); + Token * _keyword; + expr_ty a; + expr_ty expression_var; + if ( + (expression_var = expression_rule(p)) // expression + && + (_keyword = _PyPegen_expect_token(p, 520)) // token='as' + && + (a = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ invalid_with_item[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression 'as' expression")); + _res = RAISE_SYNTAX_ERROR_INVALID_TARGET ( STAR_TARGETS , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_with_item[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression 'as' expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_for_target: ASYNC? 'for' star_expressions +static void * +invalid_for_target_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ASYNC? 'for' star_expressions + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_for_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC? 'for' star_expressions")); + Token * _keyword; + void *_opt_var; + UNUSED(_opt_var); // Silence compiler warnings + expr_ty a; + if ( + (_opt_var = _PyPegen_expect_token(p, ASYNC), 1) // ASYNC? + && + (_keyword = _PyPegen_expect_token(p, 517)) // token='for' + && + (a = star_expressions_rule(p)) // star_expressions + ) + { + D(fprintf(stderr, "%*c+ invalid_for_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC? 'for' star_expressions")); + _res = RAISE_SYNTAX_ERROR_INVALID_TARGET ( FOR_TARGETS , a ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_for_target[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC? 'for' star_expressions")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_group: '(' starred_expression ')' +static void * +invalid_group_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '(' starred_expression ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_group[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' starred_expression ')'")); + Token * _literal; + Token * _literal_1; + expr_ty a; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (a = starred_expression_rule(p)) // starred_expression + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ invalid_group[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' starred_expression ')'")); + _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "can't use starred expression here" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_group[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' starred_expression ')'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// invalid_import_from_targets: import_from_as_names ',' +static void * +invalid_import_from_targets_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // import_from_as_names ',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> invalid_import_from_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "import_from_as_names ','")); + Token * _literal; + asdl_seq* import_from_as_names_var; + if ( + (import_from_as_names_var = import_from_as_names_rule(p)) // import_from_as_names + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + D(fprintf(stderr, "%*c+ invalid_import_from_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "import_from_as_names ','")); + _res = RAISE_SYNTAX_ERROR ( "trailing comma not allowed without surrounding parentheses" ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s invalid_import_from_targets[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "import_from_as_names ','")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_1: NEWLINE +static asdl_seq * +_loop0_1_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // NEWLINE + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_1[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE")); + Token * newline_var; + while ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + _res = newline_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_1[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_1_type, _seq); + D(p->level--); + return _seq; +} - /* Shift the token */ - if ((err = shift(&ps->p_stack, type, str, - x, lineno, col_offset, - end_lineno, end_col_offset)) > 0) { - D(printf(" MemError: shift.\n")); - return err; +// _loop0_2: NEWLINE +static asdl_seq * +_loop0_2_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // NEWLINE + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_2[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE")); + Token * newline_var; + while ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + _res = newline_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; } - D(printf(" Shift.\n")); - /* Pop while we are in an accept-only state */ - while (s = &d->d_state - [ps->p_stack.s_top->s_state], - s->s_accept && s->s_narcs == 1) { - D(printf(" DFA '%s', state %d: " - "Direct pop.\n", - d->d_name, - ps->p_stack.s_top->s_state)); -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD -#if 0 - if (d->d_name[0] == 'i' && - strcmp(d->d_name, - "import_stmt") == 0) - future_hack(ps); -#endif -#endif - s_pop(&ps->p_stack); - if (s_empty(&ps->p_stack)) { - D(printf(" ACCEPT.\n")); - return E_DONE; - } - d = ps->p_stack.s_top->s_dfa; + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_2[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_2_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_4: ',' expression +static asdl_seq * +_loop0_4_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_4[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' expression")); + Token * _literal; + expr_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = expression_rule(p)) // expression + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; } - return E_OK; + _children = _new_children; } + _children[_n++] = _res; + _mark = p->mark; } - - if (s->s_accept) { -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD -#if 0 - if (d->d_name[0] == 'i' && - strcmp(d->d_name, "import_stmt") == 0) - future_hack(ps); -#endif -#endif - /* Pop this dfa and try again */ - s_pop(&ps->p_stack); - D(printf(" Pop ...\n")); - if (s_empty(&ps->p_stack)) { - D(printf(" Error: bottom of stack.\n")); - return E_SYNTAX; - } - continue; - } - - /* Stuck, report syntax error */ - D(printf(" Error.\n")); - if (expected_ret) { - if (s->s_lower == s->s_upper - 1) { - /* Only one possible expected token */ - *expected_ret = ps->p_grammar-> - g_ll.ll_label[s->s_lower].lb_type; - } - else - *expected_ret = -1; - } - return E_SYNTAX; + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_4[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' expression")); } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_4_type, _seq); + D(p->level--); + return _seq; } - -#ifdef Py_DEBUG - -/* DEBUG OUTPUT */ - -void -dumptree(grammar *g, node *n) +// _gather_3: expression _loop0_4 +static asdl_seq * +_gather_3_rule(Parser *p) { - int i; - - if (n == NULL) - printf("NIL"); - else { - label l; - l.lb_type = TYPE(n); - l.lb_str = STR(n); - printf("%s", PyGrammar_LabelRepr(&l)); - if (ISNONTERMINAL(TYPE(n))) { - printf("("); - for (i = 0; i < NCH(n); i++) { - if (i > 0) - printf(","); - dumptree(g, CHILD(n, i)); - } - printf(")"); + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // expression _loop0_4 + if (p->error_indicator) { + D(p->level--); + return NULL; } + D(fprintf(stderr, "%*c> _gather_3[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression _loop0_4")); + expr_ty elem; + asdl_seq * seq; + if ( + (elem = expression_rule(p)) // expression + && + (seq = _loop0_4_rule(p)) // _loop0_4 + ) + { + D(fprintf(stderr, "%*c+ _gather_3[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression _loop0_4")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_3[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression _loop0_4")); } + _res = NULL; + done: + D(p->level--); + return _res; } -void -showtree(grammar *g, node *n) +// _loop0_6: ',' expression +static asdl_seq * +_loop0_6_rule(Parser *p) { - int i; - - if (n == NULL) - return; - if (ISNONTERMINAL(TYPE(n))) { - for (i = 0; i < NCH(n); i++) - showtree(g, CHILD(n, i)); + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; } - else if (ISTERMINAL(TYPE(n))) { - printf("%s", _PyParser_TokenNames[TYPE(n)]); - if (TYPE(n) == NUMBER || TYPE(n) == NAME) - printf("(%s)", STR(n)); - printf(" "); + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; } - else - printf("? "); + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_6[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' expression")); + Token * _literal; + expr_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = expression_rule(p)) // expression + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_6[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' expression")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_6_type, _seq); + D(p->level--); + return _seq; } -void -printtree(parser_state *ps) +// _gather_5: expression _loop0_6 +static asdl_seq * +_gather_5_rule(Parser *p) { - if (Py_DebugFlag) { - printf("Parse tree:\n"); - dumptree(ps->p_grammar, ps->p_tree); - printf("\n"); - printf("Tokens:\n"); - showtree(ps->p_grammar, ps->p_tree); - printf("\n"); + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; } - printf("Listing:\n"); - PyNode_ListTree(ps->p_tree); - printf("\n"); + asdl_seq * _res = NULL; + int _mark = p->mark; + { // expression _loop0_6 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_5[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression _loop0_6")); + expr_ty elem; + asdl_seq * seq; + if ( + (elem = expression_rule(p)) // expression + && + (seq = _loop0_6_rule(p)) // _loop0_6 + ) + { + D(fprintf(stderr, "%*c+ _gather_5[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression _loop0_6")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_5[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression _loop0_6")); + } + _res = NULL; + done: + D(p->level--); + return _res; } -#endif /* Py_DEBUG */ +// _loop0_8: ',' expression +static asdl_seq * +_loop0_8_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_8[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' expression")); + Token * _literal; + expr_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = expression_rule(p)) // expression + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_8[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' expression")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_8_type, _seq); + D(p->level--); + return _seq; +} -/* +// _gather_7: expression _loop0_8 +static asdl_seq * +_gather_7_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // expression _loop0_8 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_7[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression _loop0_8")); + expr_ty elem; + asdl_seq * seq; + if ( + (elem = expression_rule(p)) // expression + && + (seq = _loop0_8_rule(p)) // _loop0_8 + ) + { + D(fprintf(stderr, "%*c+ _gather_7[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression _loop0_8")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_7[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression _loop0_8")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} -Description ------------ +// _loop0_10: ',' expression +static asdl_seq * +_loop0_10_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_10[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' expression")); + Token * _literal; + expr_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = expression_rule(p)) // expression + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_10[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' expression")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_10_type, _seq); + D(p->level--); + return _seq; +} -The parser's interface is different than usual: the function addtoken() -must be called for each token in the input. This makes it possible to -turn it into an incremental parsing system later. The parsing system -constructs a parse tree as it goes. +// _gather_9: expression _loop0_10 +static asdl_seq * +_gather_9_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // expression _loop0_10 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_9[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression _loop0_10")); + expr_ty elem; + asdl_seq * seq; + if ( + (elem = expression_rule(p)) // expression + && + (seq = _loop0_10_rule(p)) // _loop0_10 + ) + { + D(fprintf(stderr, "%*c+ _gather_9[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression _loop0_10")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_9[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression _loop0_10")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} -A parsing rule is represented as a Deterministic Finite-state Automaton -(DFA). A node in a DFA represents a state of the parser; an arc represents -a transition. Transitions are either labeled with terminal symbols or -with non-terminals. When the parser decides to follow an arc labeled -with a non-terminal, it is invoked recursively with the DFA representing -the parsing rule for that as its initial state; when that DFA accepts, -the parser that invoked it continues. The parse tree constructed by the -recursively called parser is inserted as a child in the current parse tree. +// _loop1_11: statement +static asdl_seq * +_loop1_11_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // statement + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_11[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "statement")); + asdl_seq* statement_var; + while ( + (statement_var = statement_rule(p)) // statement + ) + { + _res = statement_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_11[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "statement")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_11_type, _seq); + D(p->level--); + return _seq; +} -The DFA's can be constructed automatically from a more conventional -language description. An extended LL(1) grammar (ELL(1)) is suitable. -Certain restrictions make the parser's life easier: rules that can produce -the empty string should be outlawed (there are other ways to put loops -or optional parts in the language). To avoid the need to construct -FIRST sets, we can require that all but the last alternative of a rule -(really: arc going out of a DFA's state) must begin with a terminal -symbol. +// _loop0_13: ';' small_stmt +static asdl_seq * +_loop0_13_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ';' small_stmt + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_13[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "';' small_stmt")); + Token * _literal; + stmt_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 13)) // token=';' + && + (elem = small_stmt_rule(p)) // small_stmt + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_13[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "';' small_stmt")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_13_type, _seq); + D(p->level--); + return _seq; +} -As an example, consider this grammar: +// _gather_12: small_stmt _loop0_13 +static asdl_seq * +_gather_12_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // small_stmt _loop0_13 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_12[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "small_stmt _loop0_13")); + stmt_ty elem; + asdl_seq * seq; + if ( + (elem = small_stmt_rule(p)) // small_stmt + && + (seq = _loop0_13_rule(p)) // _loop0_13 + ) + { + D(fprintf(stderr, "%*c+ _gather_12[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "small_stmt _loop0_13")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_12[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "small_stmt _loop0_13")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} -expr: term (OP term)* -term: CONSTANT | '(' expr ')' +// _tmp_14: 'import' | 'from' +static void * +_tmp_14_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'import' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_14[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'import'")); + Token * _keyword; + if ( + (_keyword = _PyPegen_expect_token(p, 513)) // token='import' + ) + { + D(fprintf(stderr, "%*c+ _tmp_14[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'import'")); + _res = _keyword; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_14[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'import'")); + } + { // 'from' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_14[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'from'")); + Token * _keyword; + if ( + (_keyword = _PyPegen_expect_token(p, 514)) // token='from' + ) + { + D(fprintf(stderr, "%*c+ _tmp_14[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'from'")); + _res = _keyword; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_14[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'from'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} -The DFA corresponding to the rule for expr is: +// _tmp_15: 'def' | '@' | ASYNC +static void * +_tmp_15_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'def' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_15[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'def'")); + Token * _keyword; + if ( + (_keyword = _PyPegen_expect_token(p, 523)) // token='def' + ) + { + D(fprintf(stderr, "%*c+ _tmp_15[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'def'")); + _res = _keyword; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_15[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'def'")); + } + { // '@' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_15[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'@'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 49)) // token='@' + ) + { + D(fprintf(stderr, "%*c+ _tmp_15[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'@'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_15[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'@'")); + } + { // ASYNC + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_15[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC")); + Token * async_var; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + ) + { + D(fprintf(stderr, "%*c+ _tmp_15[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC")); + _res = async_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_15[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} -------->.---term-->.-------> - ^ | - | | - \----OP----/ +// _tmp_16: 'class' | '@' +static void * +_tmp_16_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'class' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_16[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'class'")); + Token * _keyword; + if ( + (_keyword = _PyPegen_expect_token(p, 524)) // token='class' + ) + { + D(fprintf(stderr, "%*c+ _tmp_16[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'class'")); + _res = _keyword; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_16[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'class'")); + } + { // '@' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_16[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'@'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 49)) // token='@' + ) + { + D(fprintf(stderr, "%*c+ _tmp_16[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'@'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_16[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'@'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} -The parse tree generated for the input a+b is: +// _tmp_17: 'with' | ASYNC +static void * +_tmp_17_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'with' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_17[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'with'")); + Token * _keyword; + if ( + (_keyword = _PyPegen_expect_token(p, 519)) // token='with' + ) + { + D(fprintf(stderr, "%*c+ _tmp_17[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'with'")); + _res = _keyword; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_17[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'with'")); + } + { // ASYNC + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_17[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC")); + Token * async_var; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + ) + { + D(fprintf(stderr, "%*c+ _tmp_17[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC")); + _res = async_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_17[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} -(expr: (term: (NAME: a)), (OP: +), (term: (NAME: b))) +// _tmp_18: 'for' | ASYNC +static void * +_tmp_18_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'for' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_18[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'for'")); + Token * _keyword; + if ( + (_keyword = _PyPegen_expect_token(p, 517)) // token='for' + ) + { + D(fprintf(stderr, "%*c+ _tmp_18[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'for'")); + _res = _keyword; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_18[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'for'")); + } + { // ASYNC + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_18[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC")); + Token * async_var; + if ( + (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' + ) + { + D(fprintf(stderr, "%*c+ _tmp_18[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC")); + _res = async_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_18[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} -*/ +// _tmp_19: '=' annotated_rhs +static void * +_tmp_19_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '=' annotated_rhs + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_19[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'=' annotated_rhs")); + Token * _literal; + expr_ty d; + if ( + (_literal = _PyPegen_expect_token(p, 22)) // token='=' + && + (d = annotated_rhs_rule(p)) // annotated_rhs + ) + { + D(fprintf(stderr, "%*c+ _tmp_19[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'=' annotated_rhs")); + _res = d; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_19[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'=' annotated_rhs")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_20: '(' single_target ')' | single_subscript_attribute_target +static void * +_tmp_20_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '(' single_target ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_20[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' single_target ')'")); + Token * _literal; + Token * _literal_1; + expr_ty b; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (b = single_target_rule(p)) // single_target + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ _tmp_20[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' single_target ')'")); + _res = b; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_20[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' single_target ')'")); + } + { // single_subscript_attribute_target + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_20[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "single_subscript_attribute_target")); + expr_ty single_subscript_attribute_target_var; + if ( + (single_subscript_attribute_target_var = single_subscript_attribute_target_rule(p)) // single_subscript_attribute_target + ) + { + D(fprintf(stderr, "%*c+ _tmp_20[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "single_subscript_attribute_target")); + _res = single_subscript_attribute_target_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_20[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "single_subscript_attribute_target")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_21: '=' annotated_rhs +static void * +_tmp_21_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '=' annotated_rhs + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_21[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'=' annotated_rhs")); + Token * _literal; + expr_ty d; + if ( + (_literal = _PyPegen_expect_token(p, 22)) // token='=' + && + (d = annotated_rhs_rule(p)) // annotated_rhs + ) + { + D(fprintf(stderr, "%*c+ _tmp_21[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'=' annotated_rhs")); + _res = d; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_21[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'=' annotated_rhs")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop1_22: (star_targets '=') +static asdl_seq * +_loop1_22_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // (star_targets '=') + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_22[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "(star_targets '=')")); + void *_tmp_138_var; + while ( + (_tmp_138_var = _tmp_138_rule(p)) // star_targets '=' + ) + { + _res = _tmp_138_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_22[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "(star_targets '=')")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_22_type, _seq); + D(p->level--); + return _seq; +} + +// _tmp_23: yield_expr | star_expressions +static void * +_tmp_23_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // yield_expr + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_23[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "yield_expr")); + expr_ty yield_expr_var; + if ( + (yield_expr_var = yield_expr_rule(p)) // yield_expr + ) + { + D(fprintf(stderr, "%*c+ _tmp_23[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "yield_expr")); + _res = yield_expr_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_23[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "yield_expr")); + } + { // star_expressions + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_23[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions")); + expr_ty star_expressions_var; + if ( + (star_expressions_var = star_expressions_rule(p)) // star_expressions + ) + { + D(fprintf(stderr, "%*c+ _tmp_23[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions")); + _res = star_expressions_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_23[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_24: yield_expr | star_expressions +static void * +_tmp_24_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // yield_expr + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_24[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "yield_expr")); + expr_ty yield_expr_var; + if ( + (yield_expr_var = yield_expr_rule(p)) // yield_expr + ) + { + D(fprintf(stderr, "%*c+ _tmp_24[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "yield_expr")); + _res = yield_expr_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_24[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "yield_expr")); + } + { // star_expressions + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_24[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions")); + expr_ty star_expressions_var; + if ( + (star_expressions_var = star_expressions_rule(p)) // star_expressions + ) + { + D(fprintf(stderr, "%*c+ _tmp_24[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions")); + _res = star_expressions_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_24[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_26: ',' NAME +static asdl_seq * +_loop0_26_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_26[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' NAME")); + Token * _literal; + expr_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = _PyPegen_name_token(p)) // NAME + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_26[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' NAME")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_26_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_25: NAME _loop0_26 +static asdl_seq * +_gather_25_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // NAME _loop0_26 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_25[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME _loop0_26")); + expr_ty elem; + asdl_seq * seq; + if ( + (elem = _PyPegen_name_token(p)) // NAME + && + (seq = _loop0_26_rule(p)) // _loop0_26 + ) + { + D(fprintf(stderr, "%*c+ _gather_25[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME _loop0_26")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_25[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME _loop0_26")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_28: ',' NAME +static asdl_seq * +_loop0_28_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_28[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' NAME")); + Token * _literal; + expr_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = _PyPegen_name_token(p)) // NAME + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_28[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' NAME")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_28_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_27: NAME _loop0_28 +static asdl_seq * +_gather_27_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // NAME _loop0_28 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_27[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME _loop0_28")); + expr_ty elem; + asdl_seq * seq; + if ( + (elem = _PyPegen_name_token(p)) // NAME + && + (seq = _loop0_28_rule(p)) // _loop0_28 + ) + { + D(fprintf(stderr, "%*c+ _gather_27[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME _loop0_28")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_27[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME _loop0_28")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_29: ',' expression +static void * +_tmp_29_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ',' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_29[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' expression")); + Token * _literal; + expr_ty z; + if ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (z = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ _tmp_29[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' expression")); + _res = z; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_29[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_30: ';' | NEWLINE +static void * +_tmp_30_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ';' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_30[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "';'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 13)) // token=';' + ) + { + D(fprintf(stderr, "%*c+ _tmp_30[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "';'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_30[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "';'")); + } + { // NEWLINE + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_30[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE")); + Token * newline_var; + if ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + D(fprintf(stderr, "%*c+ _tmp_30[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NEWLINE")); + _res = newline_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_30[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_31: ('.' | '...') +static asdl_seq * +_loop0_31_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ('.' | '...') + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_31[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('.' | '...')")); + void *_tmp_139_var; + while ( + (_tmp_139_var = _tmp_139_rule(p)) // '.' | '...' + ) + { + _res = _tmp_139_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_31[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('.' | '...')")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_31_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_32: ('.' | '...') +static asdl_seq * +_loop1_32_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ('.' | '...') + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_32[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('.' | '...')")); + void *_tmp_140_var; + while ( + (_tmp_140_var = _tmp_140_rule(p)) // '.' | '...' + ) + { + _res = _tmp_140_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_32[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('.' | '...')")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_32_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_34: ',' import_from_as_name +static asdl_seq * +_loop0_34_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' import_from_as_name + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_34[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' import_from_as_name")); + Token * _literal; + alias_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = import_from_as_name_rule(p)) // import_from_as_name + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_34[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' import_from_as_name")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_34_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_33: import_from_as_name _loop0_34 +static asdl_seq * +_gather_33_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // import_from_as_name _loop0_34 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_33[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "import_from_as_name _loop0_34")); + alias_ty elem; + asdl_seq * seq; + if ( + (elem = import_from_as_name_rule(p)) // import_from_as_name + && + (seq = _loop0_34_rule(p)) // _loop0_34 + ) + { + D(fprintf(stderr, "%*c+ _gather_33[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "import_from_as_name _loop0_34")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_33[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "import_from_as_name _loop0_34")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_35: 'as' NAME +static void * +_tmp_35_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'as' NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_35[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'as' NAME")); + Token * _keyword; + expr_ty z; + if ( + (_keyword = _PyPegen_expect_token(p, 520)) // token='as' + && + (z = _PyPegen_name_token(p)) // NAME + ) + { + D(fprintf(stderr, "%*c+ _tmp_35[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'as' NAME")); + _res = z; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_35[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'as' NAME")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_37: ',' dotted_as_name +static asdl_seq * +_loop0_37_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' dotted_as_name + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_37[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' dotted_as_name")); + Token * _literal; + alias_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = dotted_as_name_rule(p)) // dotted_as_name + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_37[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' dotted_as_name")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_37_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_36: dotted_as_name _loop0_37 +static asdl_seq * +_gather_36_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // dotted_as_name _loop0_37 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_36[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "dotted_as_name _loop0_37")); + alias_ty elem; + asdl_seq * seq; + if ( + (elem = dotted_as_name_rule(p)) // dotted_as_name + && + (seq = _loop0_37_rule(p)) // _loop0_37 + ) + { + D(fprintf(stderr, "%*c+ _gather_36[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "dotted_as_name _loop0_37")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_36[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "dotted_as_name _loop0_37")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_38: 'as' NAME +static void * +_tmp_38_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'as' NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_38[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'as' NAME")); + Token * _keyword; + expr_ty z; + if ( + (_keyword = _PyPegen_expect_token(p, 520)) // token='as' + && + (z = _PyPegen_name_token(p)) // NAME + ) + { + D(fprintf(stderr, "%*c+ _tmp_38[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'as' NAME")); + _res = z; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_38[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'as' NAME")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_40: ',' with_item +static asdl_seq * +_loop0_40_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' with_item + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_40[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' with_item")); + Token * _literal; + withitem_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = with_item_rule(p)) // with_item + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_40[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' with_item")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_40_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_39: with_item _loop0_40 +static asdl_seq * +_gather_39_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // with_item _loop0_40 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_39[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "with_item _loop0_40")); + withitem_ty elem; + asdl_seq * seq; + if ( + (elem = with_item_rule(p)) // with_item + && + (seq = _loop0_40_rule(p)) // _loop0_40 + ) + { + D(fprintf(stderr, "%*c+ _gather_39[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "with_item _loop0_40")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_39[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "with_item _loop0_40")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_42: ',' with_item +static asdl_seq * +_loop0_42_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' with_item + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_42[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' with_item")); + Token * _literal; + withitem_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = with_item_rule(p)) // with_item + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_42[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' with_item")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_42_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_41: with_item _loop0_42 +static asdl_seq * +_gather_41_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // with_item _loop0_42 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_41[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "with_item _loop0_42")); + withitem_ty elem; + asdl_seq * seq; + if ( + (elem = with_item_rule(p)) // with_item + && + (seq = _loop0_42_rule(p)) // _loop0_42 + ) + { + D(fprintf(stderr, "%*c+ _gather_41[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "with_item _loop0_42")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_41[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "with_item _loop0_42")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_44: ',' with_item +static asdl_seq * +_loop0_44_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' with_item + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_44[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' with_item")); + Token * _literal; + withitem_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = with_item_rule(p)) // with_item + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_44[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' with_item")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_44_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_43: with_item _loop0_44 +static asdl_seq * +_gather_43_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // with_item _loop0_44 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_43[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "with_item _loop0_44")); + withitem_ty elem; + asdl_seq * seq; + if ( + (elem = with_item_rule(p)) // with_item + && + (seq = _loop0_44_rule(p)) // _loop0_44 + ) + { + D(fprintf(stderr, "%*c+ _gather_43[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "with_item _loop0_44")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_43[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "with_item _loop0_44")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_46: ',' with_item +static asdl_seq * +_loop0_46_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' with_item + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_46[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' with_item")); + Token * _literal; + withitem_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = with_item_rule(p)) // with_item + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_46[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' with_item")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_46_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_45: with_item _loop0_46 +static asdl_seq * +_gather_45_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // with_item _loop0_46 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_45[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "with_item _loop0_46")); + withitem_ty elem; + asdl_seq * seq; + if ( + (elem = with_item_rule(p)) // with_item + && + (seq = _loop0_46_rule(p)) // _loop0_46 + ) + { + D(fprintf(stderr, "%*c+ _gather_45[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "with_item _loop0_46")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_45[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "with_item _loop0_46")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_47: ',' | ')' | ':' +static void * +_tmp_47_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ',' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_47[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + ) + { + D(fprintf(stderr, "%*c+ _tmp_47[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_47[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','")); + } + { // ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_47[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "')'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ _tmp_47[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "')'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_47[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "')'")); + } + { // ':' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_47[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "':'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + ) + { + D(fprintf(stderr, "%*c+ _tmp_47[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "':'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_47[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "':'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop1_48: except_block +static asdl_seq * +_loop1_48_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // except_block + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_48[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "except_block")); + excepthandler_ty except_block_var; + while ( + (except_block_var = except_block_rule(p)) // except_block + ) + { + _res = except_block_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_48[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "except_block")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_48_type, _seq); + D(p->level--); + return _seq; +} + +// _tmp_49: 'as' NAME +static void * +_tmp_49_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'as' NAME + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_49[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'as' NAME")); + Token * _keyword; + expr_ty z; + if ( + (_keyword = _PyPegen_expect_token(p, 520)) // token='as' + && + (z = _PyPegen_name_token(p)) // NAME + ) + { + D(fprintf(stderr, "%*c+ _tmp_49[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'as' NAME")); + _res = z; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_49[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'as' NAME")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_50: 'from' expression +static void * +_tmp_50_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'from' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_50[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'from' expression")); + Token * _keyword; + expr_ty z; + if ( + (_keyword = _PyPegen_expect_token(p, 514)) // token='from' + && + (z = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ _tmp_50[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'from' expression")); + _res = z; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_50[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'from' expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_51: '->' expression +static void * +_tmp_51_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '->' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_51[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'->' expression")); + Token * _literal; + expr_ty z; + if ( + (_literal = _PyPegen_expect_token(p, 51)) // token='->' + && + (z = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ _tmp_51[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'->' expression")); + _res = z; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_51[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'->' expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_52: '->' expression +static void * +_tmp_52_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '->' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_52[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'->' expression")); + Token * _literal; + expr_ty z; + if ( + (_literal = _PyPegen_expect_token(p, 51)) // token='->' + && + (z = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ _tmp_52[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'->' expression")); + _res = z; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_52[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'->' expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_53: NEWLINE INDENT +static void * +_tmp_53_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // NEWLINE INDENT + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_53[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE INDENT")); + Token * indent_var; + Token * newline_var; + if ( + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + && + (indent_var = _PyPegen_expect_token(p, INDENT)) // token='INDENT' + ) + { + D(fprintf(stderr, "%*c+ _tmp_53[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NEWLINE INDENT")); + _res = _PyPegen_dummy_name(p, newline_var, indent_var); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_53[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE INDENT")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_54: param_no_default +static asdl_seq * +_loop0_54_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_54[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); + arg_ty param_no_default_var; + while ( + (param_no_default_var = param_no_default_rule(p)) // param_no_default + ) + { + _res = param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_54[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_54_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_55: param_with_default +static asdl_seq * +_loop0_55_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_55[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); + NameDefaultPair* param_with_default_var; + while ( + (param_with_default_var = param_with_default_rule(p)) // param_with_default + ) + { + _res = param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_55[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_55_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_56: param_with_default +static asdl_seq * +_loop0_56_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_56[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); + NameDefaultPair* param_with_default_var; + while ( + (param_with_default_var = param_with_default_rule(p)) // param_with_default + ) + { + _res = param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_56[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_56_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_57: param_no_default +static asdl_seq * +_loop1_57_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_57[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); + arg_ty param_no_default_var; + while ( + (param_no_default_var = param_no_default_rule(p)) // param_no_default + ) + { + _res = param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_57[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_57_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_58: param_with_default +static asdl_seq * +_loop0_58_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_58[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); + NameDefaultPair* param_with_default_var; + while ( + (param_with_default_var = param_with_default_rule(p)) // param_with_default + ) + { + _res = param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_58[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_58_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_59: param_with_default +static asdl_seq * +_loop1_59_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_59[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); + NameDefaultPair* param_with_default_var; + while ( + (param_with_default_var = param_with_default_rule(p)) // param_with_default + ) + { + _res = param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_59[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_59_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_60: param_no_default +static asdl_seq * +_loop1_60_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_60[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); + arg_ty param_no_default_var; + while ( + (param_no_default_var = param_no_default_rule(p)) // param_no_default + ) + { + _res = param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_60[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_60_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_61: param_no_default +static asdl_seq * +_loop1_61_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_61[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); + arg_ty param_no_default_var; + while ( + (param_no_default_var = param_no_default_rule(p)) // param_no_default + ) + { + _res = param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_61[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_61_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_62: param_no_default +static asdl_seq * +_loop0_62_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_62[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); + arg_ty param_no_default_var; + while ( + (param_no_default_var = param_no_default_rule(p)) // param_no_default + ) + { + _res = param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_62[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_62_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_63: param_with_default +static asdl_seq * +_loop1_63_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_63[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); + NameDefaultPair* param_with_default_var; + while ( + (param_with_default_var = param_with_default_rule(p)) // param_with_default + ) + { + _res = param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_63[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_63_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_64: param_no_default +static asdl_seq * +_loop0_64_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_64[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); + arg_ty param_no_default_var; + while ( + (param_no_default_var = param_no_default_rule(p)) // param_no_default + ) + { + _res = param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_64[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_64_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_65: param_with_default +static asdl_seq * +_loop1_65_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_65[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); + NameDefaultPair* param_with_default_var; + while ( + (param_with_default_var = param_with_default_rule(p)) // param_with_default + ) + { + _res = param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_65[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_65_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_66: param_maybe_default +static asdl_seq * +_loop0_66_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_maybe_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_66[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_maybe_default")); + NameDefaultPair* param_maybe_default_var; + while ( + (param_maybe_default_var = param_maybe_default_rule(p)) // param_maybe_default + ) + { + _res = param_maybe_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_66[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_maybe_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_66_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_67: param_maybe_default +static asdl_seq * +_loop1_67_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_maybe_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_67[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_maybe_default")); + NameDefaultPair* param_maybe_default_var; + while ( + (param_maybe_default_var = param_maybe_default_rule(p)) // param_maybe_default + ) + { + _res = param_maybe_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_67[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_maybe_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_67_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_68: ('@' named_expression NEWLINE) +static asdl_seq * +_loop1_68_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ('@' named_expression NEWLINE) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_68[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('@' named_expression NEWLINE)")); + void *_tmp_141_var; + while ( + (_tmp_141_var = _tmp_141_rule(p)) // '@' named_expression NEWLINE + ) + { + _res = _tmp_141_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_68[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('@' named_expression NEWLINE)")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_68_type, _seq); + D(p->level--); + return _seq; +} + +// _tmp_69: '(' arguments? ')' +static void * +_tmp_69_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '(' arguments? ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_69[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' arguments? ')'")); + Token * _literal; + Token * _literal_1; + void *z; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + && + (z = arguments_rule(p), 1) // arguments? + && + (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ _tmp_69[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' arguments? ')'")); + _res = z; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_69[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' arguments? ')'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_71: ',' star_expression +static asdl_seq * +_loop0_71_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' star_expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_71[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' star_expression")); + Token * _literal; + expr_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = star_expression_rule(p)) // star_expression + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_71[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' star_expression")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_71_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_70: star_expression _loop0_71 +static asdl_seq * +_gather_70_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // star_expression _loop0_71 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_70[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expression _loop0_71")); + expr_ty elem; + asdl_seq * seq; + if ( + (elem = star_expression_rule(p)) // star_expression + && + (seq = _loop0_71_rule(p)) // _loop0_71 + ) + { + D(fprintf(stderr, "%*c+ _gather_70[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expression _loop0_71")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_70[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expression _loop0_71")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop1_72: (',' star_expression) +static asdl_seq * +_loop1_72_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // (',' star_expression) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_72[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "(',' star_expression)")); + void *_tmp_142_var; + while ( + (_tmp_142_var = _tmp_142_rule(p)) // ',' star_expression + ) + { + _res = _tmp_142_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_72[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "(',' star_expression)")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_72_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_74: ',' star_named_expression +static asdl_seq * +_loop0_74_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' star_named_expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_74[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' star_named_expression")); + Token * _literal; + expr_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = star_named_expression_rule(p)) // star_named_expression + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_74[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' star_named_expression")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_74_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_73: star_named_expression _loop0_74 +static asdl_seq * +_gather_73_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // star_named_expression _loop0_74 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_73[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_named_expression _loop0_74")); + expr_ty elem; + asdl_seq * seq; + if ( + (elem = star_named_expression_rule(p)) // star_named_expression + && + (seq = _loop0_74_rule(p)) // _loop0_74 + ) + { + D(fprintf(stderr, "%*c+ _gather_73[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_named_expression _loop0_74")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_73[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_named_expression _loop0_74")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop1_75: (',' expression) +static asdl_seq * +_loop1_75_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // (',' expression) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_75[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "(',' expression)")); + void *_tmp_143_var; + while ( + (_tmp_143_var = _tmp_143_rule(p)) // ',' expression + ) + { + _res = _tmp_143_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_75[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "(',' expression)")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_75_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_76: lambda_param_no_default +static asdl_seq * +_loop0_76_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_76[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default")); + arg_ty lambda_param_no_default_var; + while ( + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + _res = lambda_param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_76[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_76_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_77: lambda_param_with_default +static asdl_seq * +_loop0_77_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_77[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default")); + NameDefaultPair* lambda_param_with_default_var; + while ( + (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default + ) + { + _res = lambda_param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_77[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_77_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_78: lambda_param_with_default +static asdl_seq * +_loop0_78_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_78[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default")); + NameDefaultPair* lambda_param_with_default_var; + while ( + (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default + ) + { + _res = lambda_param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_78[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_78_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_79: lambda_param_no_default +static asdl_seq * +_loop1_79_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_79[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default")); + arg_ty lambda_param_no_default_var; + while ( + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + _res = lambda_param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_79[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_79_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_80: lambda_param_with_default +static asdl_seq * +_loop0_80_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_80[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default")); + NameDefaultPair* lambda_param_with_default_var; + while ( + (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default + ) + { + _res = lambda_param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_80[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_80_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_81: lambda_param_with_default +static asdl_seq * +_loop1_81_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_81[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default")); + NameDefaultPair* lambda_param_with_default_var; + while ( + (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default + ) + { + _res = lambda_param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_81[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_81_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_82: lambda_param_no_default +static asdl_seq * +_loop1_82_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_82[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default")); + arg_ty lambda_param_no_default_var; + while ( + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + _res = lambda_param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_82[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_82_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_83: lambda_param_no_default +static asdl_seq * +_loop1_83_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_83[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default")); + arg_ty lambda_param_no_default_var; + while ( + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + _res = lambda_param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_83[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_83_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_84: lambda_param_no_default +static asdl_seq * +_loop0_84_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_84[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default")); + arg_ty lambda_param_no_default_var; + while ( + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + _res = lambda_param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_84[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_84_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_85: lambda_param_with_default +static asdl_seq * +_loop1_85_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_85[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default")); + NameDefaultPair* lambda_param_with_default_var; + while ( + (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default + ) + { + _res = lambda_param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_85[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_85_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_86: lambda_param_no_default +static asdl_seq * +_loop0_86_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_86[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default")); + arg_ty lambda_param_no_default_var; + while ( + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + _res = lambda_param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_86[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_86_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_87: lambda_param_with_default +static asdl_seq * +_loop1_87_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_87[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default")); + NameDefaultPair* lambda_param_with_default_var; + while ( + (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default + ) + { + _res = lambda_param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_87[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_87_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_88: lambda_param_maybe_default +static asdl_seq * +_loop0_88_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_maybe_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_88[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_maybe_default")); + NameDefaultPair* lambda_param_maybe_default_var; + while ( + (lambda_param_maybe_default_var = lambda_param_maybe_default_rule(p)) // lambda_param_maybe_default + ) + { + _res = lambda_param_maybe_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_88[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_maybe_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_88_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_89: lambda_param_maybe_default +static asdl_seq * +_loop1_89_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_maybe_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_89[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_maybe_default")); + NameDefaultPair* lambda_param_maybe_default_var; + while ( + (lambda_param_maybe_default_var = lambda_param_maybe_default_rule(p)) // lambda_param_maybe_default + ) + { + _res = lambda_param_maybe_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_89[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_maybe_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_89_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_90: ('or' conjunction) +static asdl_seq * +_loop1_90_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ('or' conjunction) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_90[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('or' conjunction)")); + void *_tmp_144_var; + while ( + (_tmp_144_var = _tmp_144_rule(p)) // 'or' conjunction + ) + { + _res = _tmp_144_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_90[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('or' conjunction)")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_90_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_91: ('and' inversion) +static asdl_seq * +_loop1_91_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ('and' inversion) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_91[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('and' inversion)")); + void *_tmp_145_var; + while ( + (_tmp_145_var = _tmp_145_rule(p)) // 'and' inversion + ) + { + _res = _tmp_145_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_91[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('and' inversion)")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_91_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_92: compare_op_bitwise_or_pair +static asdl_seq * +_loop1_92_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // compare_op_bitwise_or_pair + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_92[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "compare_op_bitwise_or_pair")); + CmpopExprPair* compare_op_bitwise_or_pair_var; + while ( + (compare_op_bitwise_or_pair_var = compare_op_bitwise_or_pair_rule(p)) // compare_op_bitwise_or_pair + ) + { + _res = compare_op_bitwise_or_pair_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_92[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "compare_op_bitwise_or_pair")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_92_type, _seq); + D(p->level--); + return _seq; +} + +// _tmp_93: '!=' +static void * +_tmp_93_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '!=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_93[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'!='")); + Token * tok; + if ( + (tok = _PyPegen_expect_token(p, 28)) // token='!=' + ) + { + D(fprintf(stderr, "%*c+ _tmp_93[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'!='")); + _res = _PyPegen_check_barry_as_flufl ( p ) ? NULL : tok; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_93[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'!='")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_95: ',' slice +static asdl_seq * +_loop0_95_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' slice + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_95[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' slice")); + Token * _literal; + expr_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = slice_rule(p)) // slice + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_95[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' slice")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_95_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_94: slice _loop0_95 +static asdl_seq * +_gather_94_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // slice _loop0_95 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_94[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "slice _loop0_95")); + expr_ty elem; + asdl_seq * seq; + if ( + (elem = slice_rule(p)) // slice + && + (seq = _loop0_95_rule(p)) // _loop0_95 + ) + { + D(fprintf(stderr, "%*c+ _gather_94[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "slice _loop0_95")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_94[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "slice _loop0_95")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_96: ':' expression? +static void * +_tmp_96_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ':' expression? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_96[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "':' expression?")); + Token * _literal; + void *d; + if ( + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + && + (d = expression_rule(p), 1) // expression? + ) + { + D(fprintf(stderr, "%*c+ _tmp_96[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "':' expression?")); + _res = d; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_96[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "':' expression?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_97: tuple | group | genexp +static void * +_tmp_97_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // tuple + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_97[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "tuple")); + expr_ty tuple_var; + if ( + (tuple_var = tuple_rule(p)) // tuple + ) + { + D(fprintf(stderr, "%*c+ _tmp_97[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "tuple")); + _res = tuple_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_97[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "tuple")); + } + { // group + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_97[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "group")); + expr_ty group_var; + if ( + (group_var = group_rule(p)) // group + ) + { + D(fprintf(stderr, "%*c+ _tmp_97[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "group")); + _res = group_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_97[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "group")); + } + { // genexp + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_97[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "genexp")); + expr_ty genexp_var; + if ( + (genexp_var = genexp_rule(p)) // genexp + ) + { + D(fprintf(stderr, "%*c+ _tmp_97[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "genexp")); + _res = genexp_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_97[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "genexp")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_98: list | listcomp +static void * +_tmp_98_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // list + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_98[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "list")); + expr_ty list_var; + if ( + (list_var = list_rule(p)) // list + ) + { + D(fprintf(stderr, "%*c+ _tmp_98[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "list")); + _res = list_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_98[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "list")); + } + { // listcomp + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_98[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "listcomp")); + expr_ty listcomp_var; + if ( + (listcomp_var = listcomp_rule(p)) // listcomp + ) + { + D(fprintf(stderr, "%*c+ _tmp_98[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "listcomp")); + _res = listcomp_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_98[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "listcomp")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_99: dict | set | dictcomp | setcomp +static void * +_tmp_99_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // dict + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_99[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "dict")); + expr_ty dict_var; + if ( + (dict_var = dict_rule(p)) // dict + ) + { + D(fprintf(stderr, "%*c+ _tmp_99[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "dict")); + _res = dict_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_99[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "dict")); + } + { // set + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_99[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "set")); + expr_ty set_var; + if ( + (set_var = set_rule(p)) // set + ) + { + D(fprintf(stderr, "%*c+ _tmp_99[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "set")); + _res = set_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_99[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "set")); + } + { // dictcomp + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_99[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "dictcomp")); + expr_ty dictcomp_var; + if ( + (dictcomp_var = dictcomp_rule(p)) // dictcomp + ) + { + D(fprintf(stderr, "%*c+ _tmp_99[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "dictcomp")); + _res = dictcomp_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_99[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "dictcomp")); + } + { // setcomp + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_99[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "setcomp")); + expr_ty setcomp_var; + if ( + (setcomp_var = setcomp_rule(p)) // setcomp + ) + { + D(fprintf(stderr, "%*c+ _tmp_99[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "setcomp")); + _res = setcomp_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_99[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "setcomp")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop1_100: STRING +static asdl_seq * +_loop1_100_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // STRING + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_100[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "STRING")); + expr_ty string_var; + while ( + (string_var = _PyPegen_string_token(p)) // STRING + ) + { + _res = string_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_100[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "STRING")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_100_type, _seq); + D(p->level--); + return _seq; +} + +// _tmp_101: star_named_expression ',' star_named_expressions? +static void * +_tmp_101_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // star_named_expression ',' star_named_expressions? + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_101[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_named_expression ',' star_named_expressions?")); + Token * _literal; + expr_ty y; + void *z; + if ( + (y = star_named_expression_rule(p)) // star_named_expression + && + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (z = star_named_expressions_rule(p), 1) // star_named_expressions? + ) + { + D(fprintf(stderr, "%*c+ _tmp_101[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_named_expression ',' star_named_expressions?")); + _res = _PyPegen_seq_insert_in_front ( p , y , z ); + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_101[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_named_expression ',' star_named_expressions?")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_102: yield_expr | named_expression +static void * +_tmp_102_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // yield_expr + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_102[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "yield_expr")); + expr_ty yield_expr_var; + if ( + (yield_expr_var = yield_expr_rule(p)) // yield_expr + ) + { + D(fprintf(stderr, "%*c+ _tmp_102[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "yield_expr")); + _res = yield_expr_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_102[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "yield_expr")); + } + { // named_expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_102[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "named_expression")); + expr_ty named_expression_var; + if ( + (named_expression_var = named_expression_rule(p)) // named_expression + ) + { + D(fprintf(stderr, "%*c+ _tmp_102[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "named_expression")); + _res = named_expression_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_102[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "named_expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_104: ',' double_starred_kvpair +static asdl_seq * +_loop0_104_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' double_starred_kvpair + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_104[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' double_starred_kvpair")); + Token * _literal; + KeyValuePair* elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = double_starred_kvpair_rule(p)) // double_starred_kvpair + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_104[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' double_starred_kvpair")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_104_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_103: double_starred_kvpair _loop0_104 +static asdl_seq * +_gather_103_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // double_starred_kvpair _loop0_104 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_103[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "double_starred_kvpair _loop0_104")); + KeyValuePair* elem; + asdl_seq * seq; + if ( + (elem = double_starred_kvpair_rule(p)) // double_starred_kvpair + && + (seq = _loop0_104_rule(p)) // _loop0_104 + ) + { + D(fprintf(stderr, "%*c+ _gather_103[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "double_starred_kvpair _loop0_104")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_103[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "double_starred_kvpair _loop0_104")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop1_105: for_if_clause +static asdl_seq * +_loop1_105_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // for_if_clause + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_105[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "for_if_clause")); + comprehension_ty for_if_clause_var; + while ( + (for_if_clause_var = for_if_clause_rule(p)) // for_if_clause + ) + { + _res = for_if_clause_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_105[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "for_if_clause")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_105_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_106: ('if' disjunction) +static asdl_seq * +_loop0_106_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ('if' disjunction) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_106[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('if' disjunction)")); + void *_tmp_146_var; + while ( + (_tmp_146_var = _tmp_146_rule(p)) // 'if' disjunction + ) + { + _res = _tmp_146_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_106[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('if' disjunction)")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_106_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_107: ('if' disjunction) +static asdl_seq * +_loop0_107_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ('if' disjunction) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_107[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('if' disjunction)")); + void *_tmp_147_var; + while ( + (_tmp_147_var = _tmp_147_rule(p)) // 'if' disjunction + ) + { + _res = _tmp_147_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_107[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('if' disjunction)")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_107_type, _seq); + D(p->level--); + return _seq; +} + +// _tmp_108: ',' args +static void * +_tmp_108_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ',' args + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_108[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' args")); + Token * _literal; + expr_ty c; + if ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (c = args_rule(p)) // args + ) + { + D(fprintf(stderr, "%*c+ _tmp_108[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' args")); + _res = c; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_108[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' args")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_109: ',' args +static void * +_tmp_109_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ',' args + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_109[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' args")); + Token * _literal; + expr_ty c; + if ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (c = args_rule(p)) // args + ) + { + D(fprintf(stderr, "%*c+ _tmp_109[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' args")); + _res = c; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_109[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' args")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_111: ',' kwarg_or_starred +static asdl_seq * +_loop0_111_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' kwarg_or_starred + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_111[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' kwarg_or_starred")); + Token * _literal; + KeywordOrStarred* elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_111[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' kwarg_or_starred")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_111_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_110: kwarg_or_starred _loop0_111 +static asdl_seq * +_gather_110_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // kwarg_or_starred _loop0_111 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_110[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kwarg_or_starred _loop0_111")); + KeywordOrStarred* elem; + asdl_seq * seq; + if ( + (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred + && + (seq = _loop0_111_rule(p)) // _loop0_111 + ) + { + D(fprintf(stderr, "%*c+ _gather_110[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kwarg_or_starred _loop0_111")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_110[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kwarg_or_starred _loop0_111")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_113: ',' kwarg_or_double_starred +static asdl_seq * +_loop0_113_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' kwarg_or_double_starred + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_113[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' kwarg_or_double_starred")); + Token * _literal; + KeywordOrStarred* elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_113[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' kwarg_or_double_starred")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_113_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_112: kwarg_or_double_starred _loop0_113 +static asdl_seq * +_gather_112_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // kwarg_or_double_starred _loop0_113 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_112[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kwarg_or_double_starred _loop0_113")); + KeywordOrStarred* elem; + asdl_seq * seq; + if ( + (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred + && + (seq = _loop0_113_rule(p)) // _loop0_113 + ) + { + D(fprintf(stderr, "%*c+ _gather_112[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kwarg_or_double_starred _loop0_113")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_112[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kwarg_or_double_starred _loop0_113")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_115: ',' kwarg_or_starred +static asdl_seq * +_loop0_115_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' kwarg_or_starred + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_115[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' kwarg_or_starred")); + Token * _literal; + KeywordOrStarred* elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_115[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' kwarg_or_starred")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_115_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_114: kwarg_or_starred _loop0_115 +static asdl_seq * +_gather_114_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // kwarg_or_starred _loop0_115 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_114[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kwarg_or_starred _loop0_115")); + KeywordOrStarred* elem; + asdl_seq * seq; + if ( + (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred + && + (seq = _loop0_115_rule(p)) // _loop0_115 + ) + { + D(fprintf(stderr, "%*c+ _gather_114[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kwarg_or_starred _loop0_115")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_114[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kwarg_or_starred _loop0_115")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_117: ',' kwarg_or_double_starred +static asdl_seq * +_loop0_117_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' kwarg_or_double_starred + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_117[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' kwarg_or_double_starred")); + Token * _literal; + KeywordOrStarred* elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_117[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' kwarg_or_double_starred")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_117_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_116: kwarg_or_double_starred _loop0_117 +static asdl_seq * +_gather_116_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // kwarg_or_double_starred _loop0_117 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_116[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kwarg_or_double_starred _loop0_117")); + KeywordOrStarred* elem; + asdl_seq * seq; + if ( + (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred + && + (seq = _loop0_117_rule(p)) // _loop0_117 + ) + { + D(fprintf(stderr, "%*c+ _gather_116[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kwarg_or_double_starred _loop0_117")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_116[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kwarg_or_double_starred _loop0_117")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_118: (',' star_target) +static asdl_seq * +_loop0_118_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // (',' star_target) + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_118[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "(',' star_target)")); + void *_tmp_148_var; + while ( + (_tmp_148_var = _tmp_148_rule(p)) // ',' star_target + ) + { + _res = _tmp_148_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_118[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "(',' star_target)")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_118_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_120: ',' star_target +static asdl_seq * +_loop0_120_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' star_target + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_120[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' star_target")); + Token * _literal; + expr_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = star_target_rule(p)) // star_target + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_120[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' star_target")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_120_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_119: star_target _loop0_120 +static asdl_seq * +_gather_119_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // star_target _loop0_120 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_119[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_target _loop0_120")); + expr_ty elem; + asdl_seq * seq; + if ( + (elem = star_target_rule(p)) // star_target + && + (seq = _loop0_120_rule(p)) // _loop0_120 + ) + { + D(fprintf(stderr, "%*c+ _gather_119[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_target _loop0_120")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_119[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_target _loop0_120")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_121: !'*' star_target +static void * +_tmp_121_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // !'*' star_target + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_121[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "!'*' star_target")); + expr_ty star_target_var; + if ( + _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 16) // token='*' + && + (star_target_var = star_target_rule(p)) // star_target + ) + { + D(fprintf(stderr, "%*c+ _tmp_121[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "!'*' star_target")); + _res = star_target_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_121[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "!'*' star_target")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_123: ',' del_target +static asdl_seq * +_loop0_123_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' del_target + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_123[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' del_target")); + Token * _literal; + expr_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = del_target_rule(p)) // del_target + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_123[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' del_target")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_123_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_122: del_target _loop0_123 +static asdl_seq * +_gather_122_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // del_target _loop0_123 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_122[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "del_target _loop0_123")); + expr_ty elem; + asdl_seq * seq; + if ( + (elem = del_target_rule(p)) // del_target + && + (seq = _loop0_123_rule(p)) // _loop0_123 + ) + { + D(fprintf(stderr, "%*c+ _gather_122[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "del_target _loop0_123")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_122[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "del_target _loop0_123")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_125: ',' target +static asdl_seq * +_loop0_125_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // ',' target + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_125[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' target")); + Token * _literal; + expr_ty elem; + while ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (elem = target_rule(p)) // target + ) + { + _res = elem; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + PyMem_Free(_children); + D(p->level--); + return NULL; + } + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_125[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' target")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_125_type, _seq); + D(p->level--); + return _seq; +} + +// _gather_124: target _loop0_125 +static asdl_seq * +_gather_124_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + asdl_seq * _res = NULL; + int _mark = p->mark; + { // target _loop0_125 + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _gather_124[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "target _loop0_125")); + expr_ty elem; + asdl_seq * seq; + if ( + (elem = target_rule(p)) // target + && + (seq = _loop0_125_rule(p)) // _loop0_125 + ) + { + D(fprintf(stderr, "%*c+ _gather_124[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "target _loop0_125")); + _res = _PyPegen_seq_insert_in_front(p, elem, seq); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _gather_124[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "target _loop0_125")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_126: args | expression for_if_clauses +static void * +_tmp_126_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // args + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_126[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "args")); + expr_ty args_var; + if ( + (args_var = args_rule(p)) // args + ) + { + D(fprintf(stderr, "%*c+ _tmp_126[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "args")); + _res = args_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_126[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "args")); + } + { // expression for_if_clauses + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_126[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression for_if_clauses")); + expr_ty expression_var; + asdl_seq* for_if_clauses_var; + if ( + (expression_var = expression_rule(p)) // expression + && + (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses + ) + { + D(fprintf(stderr, "%*c+ _tmp_126[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression for_if_clauses")); + _res = _PyPegen_dummy_name(p, expression_var, for_if_clauses_var); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_126[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression for_if_clauses")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_127: star_named_expressions +static asdl_seq * +_loop0_127_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // star_named_expressions + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_127[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_named_expressions")); + asdl_seq* star_named_expressions_var; + while ( + (star_named_expressions_var = star_named_expressions_rule(p)) // star_named_expressions + ) + { + _res = star_named_expressions_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_127[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_named_expressions")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_127_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_128: (star_targets '=') +static asdl_seq * +_loop0_128_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // (star_targets '=') + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_128[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "(star_targets '=')")); + void *_tmp_149_var; + while ( + (_tmp_149_var = _tmp_149_rule(p)) // star_targets '=' + ) + { + _res = _tmp_149_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_128[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "(star_targets '=')")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_128_type, _seq); + D(p->level--); + return _seq; +} + +// _loop0_129: (star_targets '=') +static asdl_seq * +_loop0_129_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // (star_targets '=') + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_129[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "(star_targets '=')")); + void *_tmp_150_var; + while ( + (_tmp_150_var = _tmp_150_rule(p)) // star_targets '=' + ) + { + _res = _tmp_150_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_129[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "(star_targets '=')")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_129_type, _seq); + D(p->level--); + return _seq; +} + +// _tmp_130: yield_expr | star_expressions +static void * +_tmp_130_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // yield_expr + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_130[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "yield_expr")); + expr_ty yield_expr_var; + if ( + (yield_expr_var = yield_expr_rule(p)) // yield_expr + ) + { + D(fprintf(stderr, "%*c+ _tmp_130[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "yield_expr")); + _res = yield_expr_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_130[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "yield_expr")); + } + { // star_expressions + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_130[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions")); + expr_ty star_expressions_var; + if ( + (star_expressions_var = star_expressions_rule(p)) // star_expressions + ) + { + D(fprintf(stderr, "%*c+ _tmp_130[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions")); + _res = star_expressions_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_130[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_131: '[' | '(' | '{' +static void * +_tmp_131_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '[' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_131[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'['")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 9)) // token='[' + ) + { + D(fprintf(stderr, "%*c+ _tmp_131[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'['")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_131[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'['")); + } + { // '(' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_131[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'('")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 7)) // token='(' + ) + { + D(fprintf(stderr, "%*c+ _tmp_131[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'('")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_131[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'('")); + } + { // '{' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_131[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'{'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 25)) // token='{' + ) + { + D(fprintf(stderr, "%*c+ _tmp_131[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'{'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_131[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'{'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_132: param_no_default +static asdl_seq * +_loop0_132_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_132[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); + arg_ty param_no_default_var; + while ( + (param_no_default_var = param_no_default_rule(p)) // param_no_default + ) + { + _res = param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_132[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_132_type, _seq); + D(p->level--); + return _seq; +} + +// _tmp_133: slash_with_default | param_with_default+ +static void * +_tmp_133_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // slash_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_133[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "slash_with_default")); + SlashWithDefault* slash_with_default_var; + if ( + (slash_with_default_var = slash_with_default_rule(p)) // slash_with_default + ) + { + D(fprintf(stderr, "%*c+ _tmp_133[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "slash_with_default")); + _res = slash_with_default_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_133[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "slash_with_default")); + } + { // param_with_default+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_133[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default+")); + asdl_seq * _loop1_151_var; + if ( + (_loop1_151_var = _loop1_151_rule(p)) // param_with_default+ + ) + { + D(fprintf(stderr, "%*c+ _tmp_133[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_with_default+")); + _res = _loop1_151_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_133[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default+")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop0_134: lambda_param_no_default +static asdl_seq * +_loop0_134_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_no_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop0_134[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default")); + arg_ty lambda_param_no_default_var; + while ( + (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default + ) + { + _res = lambda_param_no_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop0_134[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default")); + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop0_134_type, _seq); + D(p->level--); + return _seq; +} + +// _tmp_135: lambda_slash_with_default | lambda_param_with_default+ +static void * +_tmp_135_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // lambda_slash_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_135[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_slash_with_default")); + SlashWithDefault* lambda_slash_with_default_var; + if ( + (lambda_slash_with_default_var = lambda_slash_with_default_rule(p)) // lambda_slash_with_default + ) + { + D(fprintf(stderr, "%*c+ _tmp_135[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_slash_with_default")); + _res = lambda_slash_with_default_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_135[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_slash_with_default")); + } + { // lambda_param_with_default+ + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_135[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default+")); + asdl_seq * _loop1_152_var; + if ( + (_loop1_152_var = _loop1_152_rule(p)) // lambda_param_with_default+ + ) + { + D(fprintf(stderr, "%*c+ _tmp_135[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default+")); + _res = _loop1_152_var; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_135[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default+")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_136: ')' | ',' (')' | '**') +static void * +_tmp_136_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_136[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "')'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ _tmp_136[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "')'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_136[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "')'")); + } + { // ',' (')' | '**') + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_136[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' (')' | '**')")); + Token * _literal; + void *_tmp_153_var; + if ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (_tmp_153_var = _tmp_153_rule(p)) // ')' | '**' + ) + { + D(fprintf(stderr, "%*c+ _tmp_136[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' (')' | '**')")); + _res = _PyPegen_dummy_name(p, _literal, _tmp_153_var); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_136[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' (')' | '**')")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_137: ':' | ',' (':' | '**') +static void * +_tmp_137_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ':' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_137[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "':'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + ) + { + D(fprintf(stderr, "%*c+ _tmp_137[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "':'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_137[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "':'")); + } + { // ',' (':' | '**') + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_137[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' (':' | '**')")); + Token * _literal; + void *_tmp_154_var; + if ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (_tmp_154_var = _tmp_154_rule(p)) // ':' | '**' + ) + { + D(fprintf(stderr, "%*c+ _tmp_137[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' (':' | '**')")); + _res = _PyPegen_dummy_name(p, _literal, _tmp_154_var); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_137[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' (':' | '**')")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_138: star_targets '=' +static void * +_tmp_138_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // star_targets '=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_138[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_targets '='")); + Token * _literal; + expr_ty z; + if ( + (z = star_targets_rule(p)) // star_targets + && + (_literal = _PyPegen_expect_token(p, 22)) // token='=' + ) + { + D(fprintf(stderr, "%*c+ _tmp_138[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_targets '='")); + _res = z; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_138[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_targets '='")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_139: '.' | '...' +static void * +_tmp_139_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '.' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_139[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'.'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 23)) // token='.' + ) + { + D(fprintf(stderr, "%*c+ _tmp_139[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'.'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_139[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'.'")); + } + { // '...' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_139[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'...'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 52)) // token='...' + ) + { + D(fprintf(stderr, "%*c+ _tmp_139[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'...'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_139[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'...'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_140: '.' | '...' +static void * +_tmp_140_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '.' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_140[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'.'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 23)) // token='.' + ) + { + D(fprintf(stderr, "%*c+ _tmp_140[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'.'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_140[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'.'")); + } + { // '...' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_140[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'...'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 52)) // token='...' + ) + { + D(fprintf(stderr, "%*c+ _tmp_140[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'...'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_140[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'...'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_141: '@' named_expression NEWLINE +static void * +_tmp_141_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // '@' named_expression NEWLINE + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_141[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'@' named_expression NEWLINE")); + Token * _literal; + expr_ty f; + Token * newline_var; + if ( + (_literal = _PyPegen_expect_token(p, 49)) // token='@' + && + (f = named_expression_rule(p)) // named_expression + && + (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' + ) + { + D(fprintf(stderr, "%*c+ _tmp_141[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'@' named_expression NEWLINE")); + _res = f; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_141[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'@' named_expression NEWLINE")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_142: ',' star_expression +static void * +_tmp_142_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ',' star_expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_142[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' star_expression")); + Token * _literal; + expr_ty c; + if ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (c = star_expression_rule(p)) // star_expression + ) + { + D(fprintf(stderr, "%*c+ _tmp_142[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' star_expression")); + _res = c; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_142[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' star_expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_143: ',' expression +static void * +_tmp_143_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ',' expression + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_143[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' expression")); + Token * _literal; + expr_ty c; + if ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (c = expression_rule(p)) // expression + ) + { + D(fprintf(stderr, "%*c+ _tmp_143[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' expression")); + _res = c; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_143[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' expression")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_144: 'or' conjunction +static void * +_tmp_144_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'or' conjunction + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_144[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'or' conjunction")); + Token * _keyword; + expr_ty c; + if ( + (_keyword = _PyPegen_expect_token(p, 531)) // token='or' + && + (c = conjunction_rule(p)) // conjunction + ) + { + D(fprintf(stderr, "%*c+ _tmp_144[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'or' conjunction")); + _res = c; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_144[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'or' conjunction")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_145: 'and' inversion +static void * +_tmp_145_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'and' inversion + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_145[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'and' inversion")); + Token * _keyword; + expr_ty c; + if ( + (_keyword = _PyPegen_expect_token(p, 532)) // token='and' + && + (c = inversion_rule(p)) // inversion + ) + { + D(fprintf(stderr, "%*c+ _tmp_145[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'and' inversion")); + _res = c; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_145[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'and' inversion")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_146: 'if' disjunction +static void * +_tmp_146_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'if' disjunction + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_146[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'if' disjunction")); + Token * _keyword; + expr_ty z; + if ( + (_keyword = _PyPegen_expect_token(p, 510)) // token='if' + && + (z = disjunction_rule(p)) // disjunction + ) + { + D(fprintf(stderr, "%*c+ _tmp_146[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'if' disjunction")); + _res = z; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_146[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'if' disjunction")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_147: 'if' disjunction +static void * +_tmp_147_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // 'if' disjunction + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_147[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'if' disjunction")); + Token * _keyword; + expr_ty z; + if ( + (_keyword = _PyPegen_expect_token(p, 510)) // token='if' + && + (z = disjunction_rule(p)) // disjunction + ) + { + D(fprintf(stderr, "%*c+ _tmp_147[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'if' disjunction")); + _res = z; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_147[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'if' disjunction")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_148: ',' star_target +static void * +_tmp_148_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ',' star_target + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_148[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' star_target")); + Token * _literal; + expr_ty c; + if ( + (_literal = _PyPegen_expect_token(p, 12)) // token=',' + && + (c = star_target_rule(p)) // star_target + ) + { + D(fprintf(stderr, "%*c+ _tmp_148[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' star_target")); + _res = c; + if (_res == NULL && PyErr_Occurred()) { + p->error_indicator = 1; + D(p->level--); + return NULL; + } + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_148[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' star_target")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_149: star_targets '=' +static void * +_tmp_149_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // star_targets '=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_149[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_targets '='")); + Token * _literal; + expr_ty star_targets_var; + if ( + (star_targets_var = star_targets_rule(p)) // star_targets + && + (_literal = _PyPegen_expect_token(p, 22)) // token='=' + ) + { + D(fprintf(stderr, "%*c+ _tmp_149[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_targets '='")); + _res = _PyPegen_dummy_name(p, star_targets_var, _literal); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_149[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_targets '='")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_150: star_targets '=' +static void * +_tmp_150_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // star_targets '=' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_150[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_targets '='")); + Token * _literal; + expr_ty star_targets_var; + if ( + (star_targets_var = star_targets_rule(p)) // star_targets + && + (_literal = _PyPegen_expect_token(p, 22)) // token='=' + ) + { + D(fprintf(stderr, "%*c+ _tmp_150[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_targets '='")); + _res = _PyPegen_dummy_name(p, star_targets_var, _literal); + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_150[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_targets '='")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _loop1_151: param_with_default +static asdl_seq * +_loop1_151_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_151[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); + NameDefaultPair* param_with_default_var; + while ( + (param_with_default_var = param_with_default_rule(p)) // param_with_default + ) + { + _res = param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_151[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_151_type, _seq); + D(p->level--); + return _seq; +} + +// _loop1_152: lambda_param_with_default +static asdl_seq * +_loop1_152_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void *_res = NULL; + int _mark = p->mark; + int _start_mark = p->mark; + void **_children = PyMem_Malloc(sizeof(void *)); + if (!_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + ssize_t _children_capacity = 1; + ssize_t _n = 0; + { // lambda_param_with_default + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _loop1_152[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default")); + NameDefaultPair* lambda_param_with_default_var; + while ( + (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default + ) + { + _res = lambda_param_with_default_var; + if (_n == _children_capacity) { + _children_capacity *= 2; + void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); + if (!_new_children) { + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + _children = _new_children; + } + _children[_n++] = _res; + _mark = p->mark; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _loop1_152[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default")); + } + if (_n == 0 || p->error_indicator) { + PyMem_Free(_children); + D(p->level--); + return NULL; + } + asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); + if (!_seq) { + PyMem_Free(_children); + p->error_indicator = 1; + PyErr_NoMemory(); + D(p->level--); + return NULL; + } + for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); + PyMem_Free(_children); + _PyPegen_insert_memo(p, _start_mark, _loop1_152_type, _seq); + D(p->level--); + return _seq; +} + +// _tmp_153: ')' | '**' +static void * +_tmp_153_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ')' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_153[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "')'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 8)) // token=')' + ) + { + D(fprintf(stderr, "%*c+ _tmp_153[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "')'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_153[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "')'")); + } + { // '**' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_153[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 35)) // token='**' + ) + { + D(fprintf(stderr, "%*c+ _tmp_153[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_153[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +// _tmp_154: ':' | '**' +static void * +_tmp_154_rule(Parser *p) +{ + D(p->level++); + if (p->error_indicator) { + D(p->level--); + return NULL; + } + void * _res = NULL; + int _mark = p->mark; + { // ':' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_154[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "':'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 11)) // token=':' + ) + { + D(fprintf(stderr, "%*c+ _tmp_154[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "':'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_154[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "':'")); + } + { // '**' + if (p->error_indicator) { + D(p->level--); + return NULL; + } + D(fprintf(stderr, "%*c> _tmp_154[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**'")); + Token * _literal; + if ( + (_literal = _PyPegen_expect_token(p, 35)) // token='**' + ) + { + D(fprintf(stderr, "%*c+ _tmp_154[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**'")); + _res = _literal; + goto done; + } + p->mark = _mark; + D(fprintf(stderr, "%*c%s _tmp_154[%d-%d]: %s failed!\n", p->level, ' ', + p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**'")); + } + _res = NULL; + done: + D(p->level--); + return _res; +} + +void * +_PyPegen_parse(Parser *p) +{ + // Initialize keywords + p->keywords = reserved_keywords; + p->n_keyword_lists = n_keyword_lists; + + // Run parser + void *result = NULL; + if (p->start_rule == Py_file_input) { + result = file_rule(p); + } else if (p->start_rule == Py_single_input) { + result = interactive_rule(p); + } else if (p->start_rule == Py_eval_input) { + result = eval_rule(p); + } else if (p->start_rule == Py_func_type_input) { + result = func_type_rule(p); + } else if (p->start_rule == Py_fstring_input) { + result = fstring_rule(p); + } + + return result; +} + +// The end diff --git a/Parser/parser.h b/Parser/parser.h deleted file mode 100644 index b16075e7f29..00000000000 --- a/Parser/parser.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef Py_PARSER_H -#define Py_PARSER_H -#ifdef __cplusplus -extern "C" { -#endif - - -/* Parser interface */ - -#define MAXSTACK 1700 - -typedef struct { - int s_state; /* State in current DFA */ - const dfa *s_dfa; /* Current DFA */ - struct _node *s_parent; /* Where to add next node */ -} stackentry; - -typedef struct { - stackentry *s_top; /* Top entry */ - stackentry s_base[MAXSTACK];/* Array of stack entries */ - /* NB The stack grows down */ -} stack; - -typedef struct { - stack p_stack; /* Stack of parser states */ - grammar *p_grammar; /* Grammar to use */ - node *p_tree; /* Top of parse tree */ -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD - unsigned long p_flags; /* see co_flags in Include/code.h */ -#endif -} parser_state; - -parser_state *PyParser_New(grammar *g, int start); -void PyParser_Delete(parser_state *ps); -int PyParser_AddToken(parser_state *ps, int type, char *str, - int lineno, int col_offset, - int end_lineno, int end_col_offset, - int *expected_ret); -void PyGrammar_AddAccelerators(grammar *g); - - -#define showtree _Py_showtree -#define printtree _Py_printtree -#define dumptree _Py_dumptree - -#ifdef __cplusplus -} -#endif -#endif /* !Py_PARSER_H */ diff --git a/Parser/parsetok.c b/Parser/parsetok.c deleted file mode 100644 index 1ecb2c4a16d..00000000000 --- a/Parser/parsetok.c +++ /dev/null @@ -1,486 +0,0 @@ - -/* Parser-tokenizer link implementation */ - -#include "Python.h" -#include "tokenizer.h" -#include "node.h" -#include "grammar.h" -#include "parser.h" -#include "parsetok.h" -#include "errcode.h" -#include "graminit.h" - - -/* Forward */ -static node *parsetok(struct tok_state *, grammar *, int, perrdetail *, int *); -static int initerr(perrdetail *err_ret, PyObject * filename); - -typedef struct { - struct { - int lineno; - char *comment; - } *items; - size_t size; - size_t num_items; -} growable_comment_array; - -static int -growable_comment_array_init(growable_comment_array *arr, size_t initial_size) { - assert(initial_size > 0); - arr->items = malloc(initial_size * sizeof(*arr->items)); - arr->size = initial_size; - arr->num_items = 0; - - return arr->items != NULL; -} - -static int -growable_comment_array_add(growable_comment_array *arr, int lineno, char *comment) { - if (arr->num_items >= arr->size) { - size_t new_size = arr->size * 2; - void *new_items_array = realloc(arr->items, new_size * sizeof(*arr->items)); - if (!new_items_array) { - return 0; - } - arr->items = new_items_array; - arr->size = new_size; - } - - arr->items[arr->num_items].lineno = lineno; - arr->items[arr->num_items].comment = comment; - arr->num_items++; - return 1; -} - -static void -growable_comment_array_deallocate(growable_comment_array *arr) { - for (unsigned i = 0; i < arr->num_items; i++) { - PyObject_FREE(arr->items[i].comment); - } - free(arr->items); -} - -/* Parse input coming from a string. Return error code, print some errors. */ -node * -PyParser_ParseString(const char *s, grammar *g, int start, perrdetail *err_ret) -{ - return PyParser_ParseStringFlagsFilename(s, NULL, g, start, err_ret, 0); -} - -node * -PyParser_ParseStringFlags(const char *s, grammar *g, int start, - perrdetail *err_ret, int flags) -{ - return PyParser_ParseStringFlagsFilename(s, NULL, - g, start, err_ret, flags); -} - -node * -PyParser_ParseStringFlagsFilename(const char *s, const char *filename, - grammar *g, int start, - perrdetail *err_ret, int flags) -{ - int iflags = flags; - return PyParser_ParseStringFlagsFilenameEx(s, filename, g, start, - err_ret, &iflags); -} - -node * -PyParser_ParseStringObject(const char *s, PyObject *filename, - grammar *g, int start, - perrdetail *err_ret, int *flags) -{ - struct tok_state *tok; - int exec_input = start == file_input; - - if (initerr(err_ret, filename) < 0) - return NULL; - - if (PySys_Audit("compile", "yO", s, err_ret->filename) < 0) { - err_ret->error = E_ERROR; - return NULL; - } - - if (*flags & PyPARSE_IGNORE_COOKIE) - tok = PyTokenizer_FromUTF8(s, exec_input); - else - tok = PyTokenizer_FromString(s, exec_input); - if (tok == NULL) { - err_ret->error = PyErr_Occurred() ? E_DECODE : E_NOMEM; - return NULL; - } - if (*flags & PyPARSE_TYPE_COMMENTS) { - tok->type_comments = 1; - } - - Py_INCREF(err_ret->filename); - tok->filename = err_ret->filename; - if (*flags & PyPARSE_ASYNC_HACKS) - tok->async_hacks = 1; - return parsetok(tok, g, start, err_ret, flags); -} - -node * -PyParser_ParseStringFlagsFilenameEx(const char *s, const char *filename_str, - grammar *g, int start, - perrdetail *err_ret, int *flags) -{ - node *n; - PyObject *filename = NULL; - if (filename_str != NULL) { - filename = PyUnicode_DecodeFSDefault(filename_str); - if (filename == NULL) { - err_ret->error = E_ERROR; - return NULL; - } - } - n = PyParser_ParseStringObject(s, filename, g, start, err_ret, flags); - Py_XDECREF(filename); - return n; -} - -/* Parse input coming from a file. Return error code, print some errors. */ - -node * -PyParser_ParseFile(FILE *fp, const char *filename, grammar *g, int start, - const char *ps1, const char *ps2, - perrdetail *err_ret) -{ - return PyParser_ParseFileFlags(fp, filename, NULL, - g, start, ps1, ps2, err_ret, 0); -} - -node * -PyParser_ParseFileFlags(FILE *fp, const char *filename, const char *enc, - grammar *g, int start, - const char *ps1, const char *ps2, - perrdetail *err_ret, int flags) -{ - int iflags = flags; - return PyParser_ParseFileFlagsEx(fp, filename, enc, g, start, ps1, - ps2, err_ret, &iflags); -} - -node * -PyParser_ParseFileObject(FILE *fp, PyObject *filename, - const char *enc, grammar *g, int start, - const char *ps1, const char *ps2, - perrdetail *err_ret, int *flags) -{ - struct tok_state *tok; - - if (initerr(err_ret, filename) < 0) - return NULL; - - if (PySys_Audit("compile", "OO", Py_None, err_ret->filename) < 0) { - return NULL; - } - - if ((tok = PyTokenizer_FromFile(fp, enc, ps1, ps2)) == NULL) { - err_ret->error = E_NOMEM; - return NULL; - } - if (*flags & PyPARSE_TYPE_COMMENTS) { - tok->type_comments = 1; - } - Py_INCREF(err_ret->filename); - tok->filename = err_ret->filename; - return parsetok(tok, g, start, err_ret, flags); -} - -node * -PyParser_ParseFileFlagsEx(FILE *fp, const char *filename, - const char *enc, grammar *g, int start, - const char *ps1, const char *ps2, - perrdetail *err_ret, int *flags) -{ - node *n; - PyObject *fileobj = NULL; - if (filename != NULL) { - fileobj = PyUnicode_DecodeFSDefault(filename); - if (fileobj == NULL) { - err_ret->error = E_ERROR; - return NULL; - } - } - n = PyParser_ParseFileObject(fp, fileobj, enc, g, - start, ps1, ps2, err_ret, flags); - Py_XDECREF(fileobj); - return n; -} - -/* Parse input coming from the given tokenizer structure. - Return error code. */ - -static node * -parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, - int *flags) -{ - parser_state *ps; - node *n; - int started = 0; - int col_offset, end_col_offset; - growable_comment_array type_ignores; - - if (!growable_comment_array_init(&type_ignores, 10)) { - err_ret->error = E_NOMEM; - PyTokenizer_Free(tok); - return NULL; - } - - if ((ps = PyParser_New(g, start)) == NULL) { - err_ret->error = E_NOMEM; - growable_comment_array_deallocate(&type_ignores); - PyTokenizer_Free(tok); - return NULL; - } -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD - if (*flags & PyPARSE_BARRY_AS_BDFL) - ps->p_flags |= CO_FUTURE_BARRY_AS_BDFL; - if (*flags & PyPARSE_TYPE_COMMENTS) - ps->p_flags |= PyCF_TYPE_COMMENTS; -#endif - - for (;;) { - const char *a, *b; - int type; - size_t len; - char *str; - col_offset = -1; - int lineno; - const char *line_start; - - type = PyTokenizer_Get(tok, &a, &b); - - len = (a != NULL && b != NULL) ? b - a : 0; - str = (char *) PyObject_MALLOC(len + 1); - if (str == NULL) { - err_ret->error = E_NOMEM; - break; - } - if (len > 0) - strncpy(str, a, len); - str[len] = '\0'; - -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD - if (type == NOTEQUAL) { - if (!(ps->p_flags & CO_FUTURE_BARRY_AS_BDFL) && - strcmp(str, "!=")) { - PyObject_FREE(str); - err_ret->error = E_SYNTAX; - break; - } - else if ((ps->p_flags & CO_FUTURE_BARRY_AS_BDFL) && - strcmp(str, "<>")) { - PyObject_FREE(str); - err_ret->expected = NOTEQUAL; - err_ret->error = E_SYNTAX; - break; - } - } -#endif - - /* Nodes of type STRING, especially multi line strings - must be handled differently in order to get both - the starting line number and the column offset right. - (cf. issue 16806) */ - lineno = type == STRING ? tok->first_lineno : tok->lineno; - line_start = type == STRING ? tok->multi_line_start : tok->line_start; - if (a != NULL && a >= line_start) { - col_offset = Py_SAFE_DOWNCAST(a - line_start, - intptr_t, int); - } - else { - col_offset = -1; - } - - if (b != NULL && b >= tok->line_start) { - end_col_offset = Py_SAFE_DOWNCAST(b - tok->line_start, - intptr_t, int); - } - else { - end_col_offset = -1; - } - - if (type == TYPE_IGNORE) { - if (!growable_comment_array_add(&type_ignores, tok->lineno, str)) { - err_ret->error = E_NOMEM; - break; - } - continue; - } - - if (type == ERRORTOKEN) { - err_ret->error = tok->done; - break; - } - if (type == ENDMARKER && started) { - type = NEWLINE; /* Add an extra newline */ - started = 0; - /* Add the right number of dedent tokens, - except if a certain flag is given -- - codeop.py uses this. */ - if (tok->indent && - !(*flags & PyPARSE_DONT_IMPLY_DEDENT)) - { - tok->pendin = -tok->indent; - tok->indent = 0; - } - } - else { - started = 1; - } - - if ((err_ret->error = - PyParser_AddToken(ps, (int)type, str, - lineno, col_offset, tok->lineno, end_col_offset, - &(err_ret->expected))) != E_OK) { - if (tok->done == E_EOF && !ISWHITESPACE(type)) { - tok->done = E_SYNTAX; - } - if (err_ret->error != E_DONE) { - PyObject_FREE(str); - err_ret->token = type; - } - break; - } - } - - if (err_ret->error == E_DONE) { - n = ps->p_tree; - ps->p_tree = NULL; - - if (n->n_type == file_input) { - /* Put type_ignore nodes in the ENDMARKER of file_input. */ - int num; - node *ch; - size_t i; - - num = NCH(n); - ch = CHILD(n, num - 1); - REQ(ch, ENDMARKER); - - for (i = 0; i < type_ignores.num_items; i++) { - int res = PyNode_AddChild(ch, TYPE_IGNORE, type_ignores.items[i].comment, - type_ignores.items[i].lineno, 0, - type_ignores.items[i].lineno, 0); - if (res != 0) { - err_ret->error = res; - PyNode_Free(n); - n = NULL; - break; - } - type_ignores.items[i].comment = NULL; - } - } - - /* Check that the source for a single input statement really - is a single statement by looking at what is left in the - buffer after parsing. Trailing whitespace and comments - are OK. */ - if (err_ret->error == E_DONE && start == single_input) { - const char *cur = tok->cur; - char c = *tok->cur; - - for (;;) { - while (c == ' ' || c == '\t' || c == '\n' || c == '\014') - c = *++cur; - - if (!c) - break; - - if (c != '#') { - err_ret->error = E_BADSINGLE; - PyNode_Free(n); - n = NULL; - break; - } - - /* Suck up comment. */ - while (c && c != '\n') - c = *++cur; - } - } - } - else - n = NULL; - - growable_comment_array_deallocate(&type_ignores); - -#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD - *flags = ps->p_flags; -#endif - PyParser_Delete(ps); - - if (n == NULL) { - if (tok->done == E_EOF) - err_ret->error = E_EOF; - err_ret->lineno = tok->lineno; - if (tok->buf != NULL) { - size_t len; - assert(tok->cur - tok->buf < INT_MAX); - /* if we've managed to parse a token, point the offset to its start, - * else use the current reading position of the tokenizer - */ - err_ret->offset = col_offset != -1 ? col_offset + 1 : ((int)(tok->cur - tok->buf)); - len = tok->inp - tok->buf; - err_ret->text = (char *) PyObject_MALLOC(len + 1); - if (err_ret->text != NULL) { - if (len > 0) - strncpy(err_ret->text, tok->buf, len); - err_ret->text[len] = '\0'; - } - } - } else if (tok->encoding != NULL) { - /* 'nodes->n_str' uses PyObject_*, while 'tok->encoding' was - * allocated using PyMem_ - */ - node* r = PyNode_New(encoding_decl); - if (r) - r->n_str = PyObject_MALLOC(strlen(tok->encoding)+1); - if (!r || !r->n_str) { - err_ret->error = E_NOMEM; - if (r) - PyObject_FREE(r); - n = NULL; - goto done; - } - strcpy(r->n_str, tok->encoding); - PyMem_FREE(tok->encoding); - tok->encoding = NULL; - r->n_nchildren = 1; - r->n_child = n; - n = r; - } - -done: - PyTokenizer_Free(tok); - - if (n != NULL) { - _PyNode_FinalizeEndPos(n); - } - return n; -} - -static int -initerr(perrdetail *err_ret, PyObject *filename) -{ - err_ret->error = E_OK; - err_ret->lineno = 0; - err_ret->offset = 0; - err_ret->text = NULL; - err_ret->token = -1; - err_ret->expected = -1; - if (filename) { - Py_INCREF(filename); - err_ret->filename = filename; - } - else { - err_ret->filename = PyUnicode_FromString(""); - if (err_ret->filename == NULL) { - err_ret->error = E_ERROR; - return -1; - } - } - return 0; -} diff --git a/Parser/pegen/peg_api.c b/Parser/peg_api.c similarity index 51% rename from Parser/pegen/peg_api.c rename to Parser/peg_api.c index 5e71ecdb13c..8381d5e86b0 100644 --- a/Parser/pegen/peg_api.c +++ b/Parser/peg_api.c @@ -1,23 +1,23 @@ -#include "pegen_interface.h" +#include "parser_interface.h" -#include "../tokenizer.h" +#include "tokenizer.h" #include "pegen.h" mod_ty -PyPegen_ASTFromString(const char *str, const char *filename, int mode, +PyParser_ASTFromString(const char *str, const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena) { PyObject *filename_ob = PyUnicode_FromString(filename); if (filename_ob == NULL) { return NULL; } - mod_ty result = PyPegen_ASTFromStringObject(str, filename_ob, mode, flags, arena); + mod_ty result = PyParser_ASTFromStringObject(str, filename_ob, mode, flags, arena); Py_XDECREF(filename_ob); return result; } mod_ty -PyPegen_ASTFromStringObject(const char *str, PyObject* filename, int mode, +PyParser_ASTFromStringObject(const char *str, PyObject* filename, int mode, PyCompilerFlags *flags, PyArena *arena) { if (PySys_Audit("compile", "yO", str, filename) < 0) { @@ -29,7 +29,7 @@ PyPegen_ASTFromStringObject(const char *str, PyObject* filename, int mode, } mod_ty -PyPegen_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena) +PyParser_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena) { PyObject *filename_ob = PyUnicode_FromString(filename); if (filename_ob == NULL) { @@ -42,8 +42,23 @@ PyPegen_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags, } mod_ty -PyPegen_ASTFromFileObject(FILE *fp, PyObject *filename_ob, int mode, - const char *enc, const char *ps1, const char* ps2, +PyParser_ASTFromFile(FILE *fp, const char *filename, const char *enc, + int mode, const char *ps1, const char* ps2, + PyCompilerFlags *flags, int *errcode, PyArena *arena) +{ + PyObject *filename_ob = PyUnicode_FromString(filename); + if (filename_ob == NULL) { + return NULL; + } + mod_ty result = PyParser_ASTFromFileObject(fp, filename_ob, enc, mode, + ps1, ps2, flags, errcode, arena); + Py_XDECREF(filename_ob); + return result; +} + +mod_ty +PyParser_ASTFromFileObject(FILE *fp, PyObject *filename_ob, const char *enc, + int mode, const char *ps1, const char* ps2, PyCompilerFlags *flags, int *errcode, PyArena *arena) { if (PySys_Audit("compile", "OO", Py_None, filename_ob) < 0) { diff --git a/Parser/pegen/pegen.c b/Parser/pegen.c similarity index 93% rename from Parser/pegen/pegen.c rename to Parser/pegen.c index ee30c2c0688..42f9e0c41bf 100644 --- a/Parser/pegen/pegen.c +++ b/Parser/pegen.c @@ -1,9 +1,9 @@ #include #include -#include "../tokenizer.h" +#include "tokenizer.h" #include "pegen.h" -#include "parse_string.h" +#include "string_parser.h" PyObject * _PyPegen_new_type_comment(Parser *p, char *s) @@ -67,10 +67,11 @@ _PyPegen_check_barry_as_flufl(Parser *p) { assert(t->type == NOTEQUAL); char* tok_str = PyBytes_AS_STRING(t->bytes); - if (p->flags & PyPARSE_BARRY_AS_BDFL && strcmp(tok_str, "<>")){ + if (p->flags & PyPARSE_BARRY_AS_BDFL && strcmp(tok_str, "<>") != 0) { RAISE_SYNTAX_ERROR("with Barry as BDFL, use '<>' instead of '!='"); return -1; - } else if (!(p->flags & PyPARSE_BARRY_AS_BDFL)) { + } + if (!(p->flags & PyPARSE_BARRY_AS_BDFL)) { return strcmp(tok_str, "!="); } return 0; @@ -139,21 +140,18 @@ _create_dummy_identifier(Parser *p) } static inline Py_ssize_t -byte_offset_to_character_offset(PyObject *line, int col_offset) +byte_offset_to_character_offset(PyObject *line, Py_ssize_t col_offset) { const char *str = PyUnicode_AsUTF8(line); if (!str) { return 0; } + assert(col_offset >= 0 && (unsigned long)col_offset <= strlen(str)); PyObject *text = PyUnicode_DecodeUTF8(str, col_offset, "replace"); if (!text) { return 0; } Py_ssize_t size = PyUnicode_GET_LENGTH(text); - str = PyUnicode_AsUTF8(text); - if (str != NULL && (int)strlen(str) == col_offset) { - size = strlen(str); - } Py_DECREF(text); return size; } @@ -161,6 +159,7 @@ byte_offset_to_character_offset(PyObject *line, int col_offset) const char * _PyPegen_get_expr_name(expr_ty e) { + assert(e != NULL); switch (e->kind) { case Attribute_kind: return "attribute"; @@ -244,7 +243,10 @@ raise_decode_error(Parser *p) errtype = "value error"; } if (errtype) { - PyObject *type, *value, *tback, *errstr; + PyObject *type; + PyObject *value; + PyObject *tback; + PyObject *errstr; PyErr_Fetch(&type, &value, &tback); errstr = PyObject_Str(value); if (errstr) { @@ -273,7 +275,9 @@ raise_tokenizer_init_error(PyObject *filename) } PyObject *errstr = NULL; PyObject *tuple = NULL; - PyObject *type, *value, *tback; + PyObject *type; + PyObject *value; + PyObject *tback; PyErr_Fetch(&type, &value, &tback); errstr = PyObject_Str(value); if (!errstr) { @@ -359,7 +363,7 @@ void * _PyPegen_raise_error(Parser *p, PyObject *errtype, const char *errmsg, ...) { Token *t = p->known_err_token != NULL ? p->known_err_token : p->tokens[p->fill - 1]; - int col_offset; + Py_ssize_t col_offset; if (t->col_offset == -1) { col_offset = Py_SAFE_DOWNCAST(p->tok->cur - p->tok->buf, intptr_t, int); @@ -376,10 +380,9 @@ _PyPegen_raise_error(Parser *p, PyObject *errtype, const char *errmsg, ...) return NULL; } - void * _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype, - int lineno, int col_offset, + Py_ssize_t lineno, Py_ssize_t col_offset, const char *errmsg, va_list va) { PyObject *value = NULL; @@ -388,27 +391,46 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype, PyObject *tmp = NULL; p->error_indicator = 1; + if (p->start_rule == Py_fstring_input) { + const char *fstring_msg = "f-string: "; + Py_ssize_t len = strlen(fstring_msg) + strlen(errmsg); + + char *new_errmsg = PyMem_Malloc(len + 1); // Lengths of both strings plus NULL character + if (!new_errmsg) { + return (void *) PyErr_NoMemory(); + } + + // Copy both strings into new buffer + memcpy(new_errmsg, fstring_msg, strlen(fstring_msg)); + memcpy(new_errmsg + strlen(fstring_msg), errmsg, strlen(errmsg)); + new_errmsg[len] = 0; + errmsg = new_errmsg; + } errstr = PyUnicode_FromFormatV(errmsg, va); if (!errstr) { goto error; } if (p->start_rule == Py_file_input) { - error_line = PyErr_ProgramTextObject(p->tok->filename, lineno); + error_line = PyErr_ProgramTextObject(p->tok->filename, (int) lineno); } if (!error_line) { Py_ssize_t size = p->tok->inp - p->tok->buf; - if (size && p->tok->buf[size-1] == '\n') { - size--; - } error_line = PyUnicode_DecodeUTF8(p->tok->buf, size, "replace"); if (!error_line) { goto error; } } - Py_ssize_t col_number = byte_offset_to_character_offset(error_line, col_offset); + if (p->start_rule == Py_fstring_input) { + col_offset -= p->starting_col_offset; + } + Py_ssize_t col_number = col_offset; + + if (p->tok->encoding != NULL) { + col_number = byte_offset_to_character_offset(error_line, col_offset); + } tmp = Py_BuildValue("(OiiN)", p->tok->filename, lineno, col_number, error_line); if (!tmp) { @@ -423,11 +445,17 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype, Py_DECREF(errstr); Py_DECREF(value); + if (p->start_rule == Py_fstring_input) { + PyMem_Free((void *)errmsg); + } return NULL; error: Py_XDECREF(errstr); Py_XDECREF(error_line); + if (p->start_rule == Py_fstring_input) { + PyMem_Free((void *)errmsg); + } return NULL; } @@ -497,10 +525,13 @@ _PyPegen_dummy_name(Parser *p, ...) static int _get_keyword_or_name_type(Parser *p, const char *name, int name_len) { - if (name_len >= p->n_keyword_lists || p->keywords[name_len] == NULL) { + assert(name_len != 0); + if (name_len >= p->n_keyword_lists || + p->keywords[name_len] == NULL || + p->keywords[name_len]->type == -1) { return NAME; } - for (KeywordToken *k = p->keywords[name_len]; k->type != -1; k++) { + for (KeywordToken *k = p->keywords[name_len]; k != NULL && k->type != -1; k++) { if (strncmp(k->str, name, name_len) == 0) { return k->type; } @@ -547,7 +578,8 @@ growable_comment_array_deallocate(growable_comment_array *arr) { int _PyPegen_fill_token(Parser *p) { - const char *start, *end; + const char *start; + const char *end; int type = PyTokenizer_Get(p->tok, &start, &end); // Record and skip '# type: ignore' comments @@ -588,9 +620,8 @@ _PyPegen_fill_token(Parser *p) PyErr_NoMemory(); return -1; } - else { - p->tokens = new_tokens; - } + p->tokens = new_tokens; + for (int i = p->size; i < newsize; i++) { p->tokens[i] = PyMem_Malloc(sizeof(Token)); if (p->tokens[i] == NULL) { @@ -614,7 +645,8 @@ _PyPegen_fill_token(Parser *p) int lineno = type == STRING ? p->tok->first_lineno : p->tok->lineno; const char *line_start = type == STRING ? p->tok->multi_line_start : p->tok->line_start; int end_lineno = p->tok->lineno; - int col_offset = -1, end_col_offset = -1; + int col_offset = -1; + int end_col_offset = -1; if (start != NULL && start >= line_start) { col_offset = (int)(start - line_start); } @@ -633,9 +665,8 @@ _PyPegen_fill_token(Parser *p) if (p->tok->done == E_DECODE) { return raise_decode_error(p); } - else { - return tokenizer_error(p); - } + return tokenizer_error(p); + } return 0; @@ -718,6 +749,15 @@ _PyPegen_lookahead_with_name(int positive, expr_ty (func)(Parser *), Parser *p) return (res != NULL) == positive; } +int +_PyPegen_lookahead_with_string(int positive, expr_ty (func)(Parser *, const char*), Parser *p, const char* arg) +{ + int mark = p->mark; + void *res = func(p, arg); + p->mark = mark; + return (res != NULL) == positive; +} + int _PyPegen_lookahead_with_int(int positive, Token *(func)(Parser *, int), Parser *p, int arg) { @@ -766,15 +806,15 @@ _PyPegen_expect_soft_keyword(Parser *p, const char *keyword) if (t->type != NAME) { return NULL; } - char* s = PyBytes_AsString(t->bytes); + char *s = PyBytes_AsString(t->bytes); if (!s) { + p->error_indicator = 1; return NULL; } if (strcmp(s, keyword) != 0) { return NULL; } - expr_ty res = _PyPegen_name_token(p); - return res; + return _PyPegen_name_token(p); } Token * @@ -800,10 +840,12 @@ _PyPegen_name_token(Parser *p) } char* s = PyBytes_AsString(t->bytes); if (!s) { + p->error_indicator = 1; return NULL; } PyObject *id = _PyPegen_new_identifier(p, s); if (id == NULL) { + p->error_indicator = 1; return NULL; } return Name(id, Load, t->lineno, t->col_offset, t->end_lineno, t->end_col_offset, @@ -835,33 +877,36 @@ parsenumber_raw(const char *s) return PyLong_FromString(s, (char **)0, 0); } } - else + else { x = PyOS_strtol(s, (char **)&end, 0); + } if (*end == '\0') { - if (errno != 0) + if (errno != 0) { return PyLong_FromString(s, (char **)0, 0); + } return PyLong_FromLong(x); } /* XXX Huge floats may silently fail */ if (imflag) { compl.real = 0.; compl.imag = PyOS_string_to_double(s, (char **)&end, NULL); - if (compl.imag == -1.0 && PyErr_Occurred()) + if (compl.imag == -1.0 && PyErr_Occurred()) { return NULL; + } return PyComplex_FromCComplex(compl); } - else { - dx = PyOS_string_to_double(s, NULL, NULL); - if (dx == -1.0 && PyErr_Occurred()) - return NULL; - return PyFloat_FromDouble(dx); + dx = PyOS_string_to_double(s, NULL, NULL); + if (dx == -1.0 && PyErr_Occurred()) { + return NULL; } + return PyFloat_FromDouble(dx); } static PyObject * parsenumber(const char *s) { - char *dup, *end; + char *dup; + char *end; PyObject *res = NULL; assert(s != NULL); @@ -896,6 +941,7 @@ _PyPegen_number_token(Parser *p) char *num_raw = PyBytes_AsString(t->bytes); if (num_raw == NULL) { + p->error_indicator = 1; return NULL; } @@ -908,11 +954,13 @@ _PyPegen_number_token(Parser *p) PyObject *c = parsenumber(num_raw); if (c == NULL) { + p->error_indicator = 1; return NULL; } if (PyArena_AddPyObject(p->arena, c) < 0) { Py_DECREF(c); + p->error_indicator = 1; return NULL; } @@ -923,8 +971,8 @@ _PyPegen_number_token(Parser *p) static int // bool newline_in_string(Parser *p, const char *cur) { - for (char c = *cur; cur >= p->tok->buf; c = *--cur) { - if (c == '\'' || c == '"') { + for (const char *c = cur; c >= p->tok->buf; c--) { + if (*c == '\'' || *c == '"') { return 1; } } @@ -997,7 +1045,7 @@ compute_parser_flags(PyCompilerFlags *flags) if (flags->cf_flags & PyCF_TYPE_COMMENTS) { parser_flags |= PyPARSE_TYPE_COMMENTS; } - if (flags->cf_feature_version < 7) { + if ((flags->cf_flags & PyCF_ONLY_AST) && flags->cf_feature_version < 7) { parser_flags |= PyPARSE_ASYNC_HACKS; } return parser_flags; @@ -1170,7 +1218,8 @@ _PyPegen_run_parser_from_string(const char *str, int start_rule, PyObject *filen mod_ty result = NULL; int parser_flags = compute_parser_flags(flags); - int feature_version = flags ? flags->cf_feature_version : PY_MINOR_VERSION; + int feature_version = flags && (flags->cf_flags & PyCF_ONLY_AST) ? + flags->cf_feature_version : PY_MINOR_VERSION; Parser *p = _PyPegen_Parser_New(tok, start_rule, parser_flags, feature_version, NULL, arena); if (p == NULL) { @@ -2064,7 +2113,7 @@ _PyPegen_make_module(Parser *p, asdl_seq *a) { // Error reporting helpers expr_ty -_PyPegen_get_invalid_target(expr_ty e) +_PyPegen_get_invalid_target(expr_ty e, TARGETS_TYPE targets_type) { if (e == NULL) { return NULL; @@ -2074,7 +2123,7 @@ _PyPegen_get_invalid_target(expr_ty e) Py_ssize_t len = asdl_seq_LEN(CONTAINER->v.TYPE.elts);\ for (Py_ssize_t i = 0; i < len; i++) {\ expr_ty other = asdl_seq_GET(CONTAINER->v.TYPE.elts, i);\ - expr_ty child = _PyPegen_get_invalid_target(other);\ + expr_ty child = _PyPegen_get_invalid_target(other, targets_type);\ if (child != NULL) {\ return child;\ }\ @@ -2088,16 +2137,29 @@ _PyPegen_get_invalid_target(expr_ty e) // we don't need to visit it recursively. switch (e->kind) { - case List_kind: { + case List_kind: VISIT_CONTAINER(e, List); return NULL; - } - case Tuple_kind: { + case Tuple_kind: VISIT_CONTAINER(e, Tuple); return NULL; - } case Starred_kind: - return _PyPegen_get_invalid_target(e->v.Starred.value); + if (targets_type == DEL_TARGETS) { + return e; + } + return _PyPegen_get_invalid_target(e->v.Starred.value, targets_type); + case Compare_kind: + // This is needed, because the `a in b` in `for a in b` gets parsed + // as a comparison, and so we need to search the left side of the comparison + // for invalid targets. + if (targets_type == FOR_TARGETS) { + cmpop_ty cmpop = (cmpop_ty) asdl_seq_GET(e->v.Compare.ops, 0); + if (cmpop == In) { + return _PyPegen_get_invalid_target(e->v.Compare.left, targets_type); + } + return NULL; + } + return e; case Name_kind: case Subscript_kind: case Attribute_kind: diff --git a/Parser/pegen/pegen.h b/Parser/pegen.h similarity index 88% rename from Parser/pegen/pegen.h rename to Parser/pegen.h index 9507d9955ae..f407709863c 100644 --- a/Parser/pegen/pegen.h +++ b/Parser/pegen.h @@ -119,6 +119,7 @@ int _PyPegen_is_memoized(Parser *p, int type, void *pres); int _PyPegen_lookahead_with_name(int, expr_ty (func)(Parser *), Parser *); int _PyPegen_lookahead_with_int(int, Token *(func)(Parser *, int), Parser *, int); +int _PyPegen_lookahead_with_string(int , expr_ty (func)(Parser *, const char*), Parser *, const char*); int _PyPegen_lookahead(int, void *(func)(Parser *), Parser *); Token *_PyPegen_expect_token(Parser *p, int type); @@ -131,7 +132,7 @@ void *_PyPegen_string_token(Parser *p); const char *_PyPegen_get_expr_name(expr_ty); void *_PyPegen_raise_error(Parser *p, PyObject *errtype, const char *errmsg, ...); void *_PyPegen_raise_error_known_location(Parser *p, PyObject *errtype, - int lineno, int col_offset, + Py_ssize_t lineno, Py_ssize_t col_offset, const char *errmsg, va_list va); void *_PyPegen_dummy_name(Parser *p, ...); @@ -262,11 +263,40 @@ int _PyPegen_check_barry_as_flufl(Parser *); mod_ty _PyPegen_make_module(Parser *, asdl_seq *); // Error reporting helpers -expr_ty _PyPegen_get_invalid_target(expr_ty e); +typedef enum { + STAR_TARGETS, + DEL_TARGETS, + FOR_TARGETS +} TARGETS_TYPE; +expr_ty _PyPegen_get_invalid_target(expr_ty e, TARGETS_TYPE targets_type); +#define RAISE_SYNTAX_ERROR_INVALID_TARGET(type, e) _RAISE_SYNTAX_ERROR_INVALID_TARGET(p, type, e) + +Py_LOCAL_INLINE(void *) +_RAISE_SYNTAX_ERROR_INVALID_TARGET(Parser *p, TARGETS_TYPE type, void *e) +{ + expr_ty invalid_target = CHECK_NULL_ALLOWED(_PyPegen_get_invalid_target(e, type)); + if (invalid_target != NULL) { + const char *msg; + if (type == STAR_TARGETS || type == FOR_TARGETS) { + msg = "cannot assign to %s"; + } + else { + msg = "cannot delete %s"; + } + return RAISE_SYNTAX_ERROR_KNOWN_LOCATION( + invalid_target, + msg, + _PyPegen_get_expr_name(invalid_target) + ); + } + return RAISE_SYNTAX_ERROR("invalid syntax"); +} + void *_PyPegen_arguments_parsing_error(Parser *, expr_ty); void *_PyPegen_nonparen_genexp_in_call(Parser *p, expr_ty args); +// Generated function in parse.c - function definition in python.gram void *_PyPegen_parse(Parser *); #endif diff --git a/Parser/pegen/parse.c b/Parser/pegen/parse.c deleted file mode 100644 index b63924177d4..00000000000 --- a/Parser/pegen/parse.c +++ /dev/null @@ -1,23950 +0,0 @@ -// @generated by pegen.py from ./Grammar/python.gram -#include "pegen.h" - -#if defined(Py_DEBUG) && defined(Py_BUILD_CORE) -extern int Py_DebugFlag; -#define D(x) if (Py_DebugFlag) x; -#else -#define D(x) -#endif -static const int n_keyword_lists = 15; -static KeywordToken *reserved_keywords[] = { - NULL, - NULL, - (KeywordToken[]) { - {"if", 510}, - {"in", 518}, - {"is", 526}, - {"as", 531}, - {"or", 532}, - {NULL, -1}, - }, - (KeywordToken[]) { - {"del", 503}, - {"try", 511}, - {"for", 517}, - {"def", 522}, - {"not", 525}, - {"and", 533}, - {NULL, -1}, - }, - (KeywordToken[]) { - {"pass", 502}, - {"from", 514}, - {"elif", 515}, - {"else", 516}, - {"with", 519}, - {"True", 527}, - {"None", 529}, - {NULL, -1}, - }, - (KeywordToken[]) { - {"raise", 501}, - {"yield", 504}, - {"break", 506}, - {"while", 512}, - {"class", 523}, - {"False", 528}, - {NULL, -1}, - }, - (KeywordToken[]) { - {"return", 500}, - {"assert", 505}, - {"global", 508}, - {"import", 513}, - {"except", 520}, - {"lambda", 524}, - {NULL, -1}, - }, - (KeywordToken[]) { - {"finally", 521}, - {NULL, -1}, - }, - (KeywordToken[]) { - {"continue", 507}, - {"nonlocal", 509}, - {NULL, -1}, - }, - NULL, - NULL, - NULL, - NULL, - NULL, - (KeywordToken[]) { - {"__new_parser__", 530}, - {NULL, -1}, - }, -}; -#define file_type 1000 -#define interactive_type 1001 -#define eval_type 1002 -#define func_type_type 1003 -#define fstring_type 1004 -#define type_expressions_type 1005 -#define statements_type 1006 -#define statement_type 1007 -#define statement_newline_type 1008 -#define simple_stmt_type 1009 -#define small_stmt_type 1010 -#define compound_stmt_type 1011 -#define assignment_type 1012 -#define augassign_type 1013 -#define global_stmt_type 1014 -#define nonlocal_stmt_type 1015 -#define yield_stmt_type 1016 -#define assert_stmt_type 1017 -#define del_stmt_type 1018 -#define import_stmt_type 1019 -#define import_name_type 1020 -#define import_from_type 1021 -#define import_from_targets_type 1022 -#define import_from_as_names_type 1023 -#define import_from_as_name_type 1024 -#define dotted_as_names_type 1025 -#define dotted_as_name_type 1026 -#define dotted_name_type 1027 // Left-recursive -#define if_stmt_type 1028 -#define elif_stmt_type 1029 -#define else_block_type 1030 -#define while_stmt_type 1031 -#define for_stmt_type 1032 -#define with_stmt_type 1033 -#define with_item_type 1034 -#define try_stmt_type 1035 -#define except_block_type 1036 -#define finally_block_type 1037 -#define return_stmt_type 1038 -#define raise_stmt_type 1039 -#define function_def_type 1040 -#define function_def_raw_type 1041 -#define func_type_comment_type 1042 -#define params_type 1043 -#define parameters_type 1044 -#define slash_no_default_type 1045 -#define slash_with_default_type 1046 -#define star_etc_type 1047 -#define kwds_type 1048 -#define param_no_default_type 1049 -#define param_with_default_type 1050 -#define param_maybe_default_type 1051 -#define param_type 1052 -#define annotation_type 1053 -#define default_type 1054 -#define decorators_type 1055 -#define class_def_type 1056 -#define class_def_raw_type 1057 -#define block_type 1058 -#define expressions_list_type 1059 -#define star_expressions_type 1060 -#define star_expression_type 1061 -#define star_named_expressions_type 1062 -#define star_named_expression_type 1063 -#define named_expression_type 1064 -#define annotated_rhs_type 1065 -#define expressions_type 1066 -#define expression_type 1067 -#define lambdef_type 1068 -#define lambda_parameters_type 1069 -#define lambda_slash_no_default_type 1070 -#define lambda_slash_with_default_type 1071 -#define lambda_star_etc_type 1072 -#define lambda_kwds_type 1073 -#define lambda_param_no_default_type 1074 -#define lambda_param_with_default_type 1075 -#define lambda_param_maybe_default_type 1076 -#define lambda_param_type 1077 -#define disjunction_type 1078 -#define conjunction_type 1079 -#define inversion_type 1080 -#define comparison_type 1081 -#define compare_op_bitwise_or_pair_type 1082 -#define eq_bitwise_or_type 1083 -#define noteq_bitwise_or_type 1084 -#define lte_bitwise_or_type 1085 -#define lt_bitwise_or_type 1086 -#define gte_bitwise_or_type 1087 -#define gt_bitwise_or_type 1088 -#define notin_bitwise_or_type 1089 -#define in_bitwise_or_type 1090 -#define isnot_bitwise_or_type 1091 -#define is_bitwise_or_type 1092 -#define bitwise_or_type 1093 // Left-recursive -#define bitwise_xor_type 1094 // Left-recursive -#define bitwise_and_type 1095 // Left-recursive -#define shift_expr_type 1096 // Left-recursive -#define sum_type 1097 // Left-recursive -#define term_type 1098 // Left-recursive -#define factor_type 1099 -#define power_type 1100 -#define await_primary_type 1101 -#define primary_type 1102 // Left-recursive -#define slices_type 1103 -#define slice_type 1104 -#define atom_type 1105 -#define strings_type 1106 -#define list_type 1107 -#define listcomp_type 1108 -#define tuple_type 1109 -#define group_type 1110 -#define genexp_type 1111 -#define set_type 1112 -#define setcomp_type 1113 -#define dict_type 1114 -#define dictcomp_type 1115 -#define double_starred_kvpairs_type 1116 -#define double_starred_kvpair_type 1117 -#define kvpair_type 1118 -#define for_if_clauses_type 1119 -#define for_if_clause_type 1120 -#define yield_expr_type 1121 -#define arguments_type 1122 -#define args_type 1123 -#define kwargs_type 1124 -#define starred_expression_type 1125 -#define kwarg_or_starred_type 1126 -#define kwarg_or_double_starred_type 1127 -#define star_targets_type 1128 -#define star_targets_seq_type 1129 -#define star_target_type 1130 -#define star_atom_type 1131 -#define single_target_type 1132 -#define single_subscript_attribute_target_type 1133 -#define del_targets_type 1134 -#define del_target_type 1135 -#define del_t_atom_type 1136 -#define del_target_end_type 1137 -#define targets_type 1138 -#define target_type 1139 -#define t_primary_type 1140 // Left-recursive -#define t_lookahead_type 1141 -#define t_atom_type 1142 -#define incorrect_arguments_type 1143 -#define invalid_kwarg_type 1144 -#define invalid_named_expression_type 1145 -#define invalid_assignment_type 1146 -#define invalid_block_type 1147 -#define invalid_comprehension_type 1148 -#define invalid_dict_comprehension_type 1149 -#define invalid_parameters_type 1150 -#define invalid_star_etc_type 1151 -#define invalid_lambda_star_etc_type 1152 -#define invalid_double_type_comments_type 1153 -#define invalid_del_target_type 1154 -#define invalid_import_from_targets_type 1155 -#define _loop0_1_type 1156 -#define _loop0_2_type 1157 -#define _loop0_4_type 1158 -#define _gather_3_type 1159 -#define _loop0_6_type 1160 -#define _gather_5_type 1161 -#define _loop0_8_type 1162 -#define _gather_7_type 1163 -#define _loop0_10_type 1164 -#define _gather_9_type 1165 -#define _loop1_11_type 1166 -#define _loop0_13_type 1167 -#define _gather_12_type 1168 -#define _tmp_14_type 1169 -#define _tmp_15_type 1170 -#define _tmp_16_type 1171 -#define _tmp_17_type 1172 -#define _tmp_18_type 1173 -#define _tmp_19_type 1174 -#define _tmp_20_type 1175 -#define _tmp_21_type 1176 -#define _loop1_22_type 1177 -#define _tmp_23_type 1178 -#define _tmp_24_type 1179 -#define _loop0_26_type 1180 -#define _gather_25_type 1181 -#define _loop0_28_type 1182 -#define _gather_27_type 1183 -#define _tmp_29_type 1184 -#define _loop0_30_type 1185 -#define _loop1_31_type 1186 -#define _loop0_33_type 1187 -#define _gather_32_type 1188 -#define _tmp_34_type 1189 -#define _loop0_36_type 1190 -#define _gather_35_type 1191 -#define _tmp_37_type 1192 -#define _loop0_39_type 1193 -#define _gather_38_type 1194 -#define _loop0_41_type 1195 -#define _gather_40_type 1196 -#define _loop0_43_type 1197 -#define _gather_42_type 1198 -#define _loop0_45_type 1199 -#define _gather_44_type 1200 -#define _tmp_46_type 1201 -#define _loop1_47_type 1202 -#define _tmp_48_type 1203 -#define _tmp_49_type 1204 -#define _tmp_50_type 1205 -#define _tmp_51_type 1206 -#define _tmp_52_type 1207 -#define _loop0_53_type 1208 -#define _loop0_54_type 1209 -#define _loop0_55_type 1210 -#define _loop1_56_type 1211 -#define _loop0_57_type 1212 -#define _loop1_58_type 1213 -#define _loop1_59_type 1214 -#define _loop1_60_type 1215 -#define _loop0_61_type 1216 -#define _loop1_62_type 1217 -#define _loop0_63_type 1218 -#define _loop1_64_type 1219 -#define _loop0_65_type 1220 -#define _loop1_66_type 1221 -#define _loop1_67_type 1222 -#define _tmp_68_type 1223 -#define _loop0_70_type 1224 -#define _gather_69_type 1225 -#define _loop1_71_type 1226 -#define _loop0_73_type 1227 -#define _gather_72_type 1228 -#define _loop1_74_type 1229 -#define _loop0_75_type 1230 -#define _loop0_76_type 1231 -#define _loop0_77_type 1232 -#define _loop1_78_type 1233 -#define _loop0_79_type 1234 -#define _loop1_80_type 1235 -#define _loop1_81_type 1236 -#define _loop1_82_type 1237 -#define _loop0_83_type 1238 -#define _loop1_84_type 1239 -#define _loop0_85_type 1240 -#define _loop1_86_type 1241 -#define _loop0_87_type 1242 -#define _loop1_88_type 1243 -#define _loop1_89_type 1244 -#define _loop1_90_type 1245 -#define _loop1_91_type 1246 -#define _tmp_92_type 1247 -#define _loop0_94_type 1248 -#define _gather_93_type 1249 -#define _tmp_95_type 1250 -#define _tmp_96_type 1251 -#define _tmp_97_type 1252 -#define _tmp_98_type 1253 -#define _loop1_99_type 1254 -#define _tmp_100_type 1255 -#define _tmp_101_type 1256 -#define _loop0_103_type 1257 -#define _gather_102_type 1258 -#define _loop1_104_type 1259 -#define _loop0_105_type 1260 -#define _loop0_106_type 1261 -#define _tmp_107_type 1262 -#define _tmp_108_type 1263 -#define _loop0_110_type 1264 -#define _gather_109_type 1265 -#define _loop0_112_type 1266 -#define _gather_111_type 1267 -#define _loop0_114_type 1268 -#define _gather_113_type 1269 -#define _loop0_116_type 1270 -#define _gather_115_type 1271 -#define _loop0_117_type 1272 -#define _loop0_119_type 1273 -#define _gather_118_type 1274 -#define _tmp_120_type 1275 -#define _loop0_122_type 1276 -#define _gather_121_type 1277 -#define _loop0_124_type 1278 -#define _gather_123_type 1279 -#define _tmp_125_type 1280 -#define _loop0_126_type 1281 -#define _tmp_127_type 1282 -#define _tmp_128_type 1283 -#define _tmp_129_type 1284 -#define _tmp_130_type 1285 -#define _loop0_131_type 1286 -#define _tmp_132_type 1287 -#define _tmp_133_type 1288 -#define _tmp_134_type 1289 -#define _tmp_135_type 1290 -#define _tmp_136_type 1291 -#define _tmp_137_type 1292 -#define _tmp_138_type 1293 -#define _tmp_139_type 1294 -#define _tmp_140_type 1295 -#define _tmp_141_type 1296 -#define _tmp_142_type 1297 -#define _tmp_143_type 1298 -#define _tmp_144_type 1299 -#define _tmp_145_type 1300 -#define _loop1_146_type 1301 -#define _tmp_147_type 1302 -#define _tmp_148_type 1303 - -static mod_ty file_rule(Parser *p); -static mod_ty interactive_rule(Parser *p); -static mod_ty eval_rule(Parser *p); -static mod_ty func_type_rule(Parser *p); -static expr_ty fstring_rule(Parser *p); -static asdl_seq* type_expressions_rule(Parser *p); -static asdl_seq* statements_rule(Parser *p); -static asdl_seq* statement_rule(Parser *p); -static asdl_seq* statement_newline_rule(Parser *p); -static asdl_seq* simple_stmt_rule(Parser *p); -static stmt_ty small_stmt_rule(Parser *p); -static stmt_ty compound_stmt_rule(Parser *p); -static stmt_ty assignment_rule(Parser *p); -static AugOperator* augassign_rule(Parser *p); -static stmt_ty global_stmt_rule(Parser *p); -static stmt_ty nonlocal_stmt_rule(Parser *p); -static stmt_ty yield_stmt_rule(Parser *p); -static stmt_ty assert_stmt_rule(Parser *p); -static stmt_ty del_stmt_rule(Parser *p); -static stmt_ty import_stmt_rule(Parser *p); -static stmt_ty import_name_rule(Parser *p); -static stmt_ty import_from_rule(Parser *p); -static asdl_seq* import_from_targets_rule(Parser *p); -static asdl_seq* import_from_as_names_rule(Parser *p); -static alias_ty import_from_as_name_rule(Parser *p); -static asdl_seq* dotted_as_names_rule(Parser *p); -static alias_ty dotted_as_name_rule(Parser *p); -static expr_ty dotted_name_rule(Parser *p); -static stmt_ty if_stmt_rule(Parser *p); -static stmt_ty elif_stmt_rule(Parser *p); -static asdl_seq* else_block_rule(Parser *p); -static stmt_ty while_stmt_rule(Parser *p); -static stmt_ty for_stmt_rule(Parser *p); -static stmt_ty with_stmt_rule(Parser *p); -static withitem_ty with_item_rule(Parser *p); -static stmt_ty try_stmt_rule(Parser *p); -static excepthandler_ty except_block_rule(Parser *p); -static asdl_seq* finally_block_rule(Parser *p); -static stmt_ty return_stmt_rule(Parser *p); -static stmt_ty raise_stmt_rule(Parser *p); -static stmt_ty function_def_rule(Parser *p); -static stmt_ty function_def_raw_rule(Parser *p); -static Token* func_type_comment_rule(Parser *p); -static arguments_ty params_rule(Parser *p); -static arguments_ty parameters_rule(Parser *p); -static asdl_seq* slash_no_default_rule(Parser *p); -static SlashWithDefault* slash_with_default_rule(Parser *p); -static StarEtc* star_etc_rule(Parser *p); -static arg_ty kwds_rule(Parser *p); -static arg_ty param_no_default_rule(Parser *p); -static NameDefaultPair* param_with_default_rule(Parser *p); -static NameDefaultPair* param_maybe_default_rule(Parser *p); -static arg_ty param_rule(Parser *p); -static expr_ty annotation_rule(Parser *p); -static expr_ty default_rule(Parser *p); -static asdl_seq* decorators_rule(Parser *p); -static stmt_ty class_def_rule(Parser *p); -static stmt_ty class_def_raw_rule(Parser *p); -static asdl_seq* block_rule(Parser *p); -static asdl_seq* expressions_list_rule(Parser *p); -static expr_ty star_expressions_rule(Parser *p); -static expr_ty star_expression_rule(Parser *p); -static asdl_seq* star_named_expressions_rule(Parser *p); -static expr_ty star_named_expression_rule(Parser *p); -static expr_ty named_expression_rule(Parser *p); -static expr_ty annotated_rhs_rule(Parser *p); -static expr_ty expressions_rule(Parser *p); -static expr_ty expression_rule(Parser *p); -static expr_ty lambdef_rule(Parser *p); -static arguments_ty lambda_parameters_rule(Parser *p); -static asdl_seq* lambda_slash_no_default_rule(Parser *p); -static SlashWithDefault* lambda_slash_with_default_rule(Parser *p); -static StarEtc* lambda_star_etc_rule(Parser *p); -static arg_ty lambda_kwds_rule(Parser *p); -static arg_ty lambda_param_no_default_rule(Parser *p); -static NameDefaultPair* lambda_param_with_default_rule(Parser *p); -static NameDefaultPair* lambda_param_maybe_default_rule(Parser *p); -static arg_ty lambda_param_rule(Parser *p); -static expr_ty disjunction_rule(Parser *p); -static expr_ty conjunction_rule(Parser *p); -static expr_ty inversion_rule(Parser *p); -static expr_ty comparison_rule(Parser *p); -static CmpopExprPair* compare_op_bitwise_or_pair_rule(Parser *p); -static CmpopExprPair* eq_bitwise_or_rule(Parser *p); -static CmpopExprPair* noteq_bitwise_or_rule(Parser *p); -static CmpopExprPair* lte_bitwise_or_rule(Parser *p); -static CmpopExprPair* lt_bitwise_or_rule(Parser *p); -static CmpopExprPair* gte_bitwise_or_rule(Parser *p); -static CmpopExprPair* gt_bitwise_or_rule(Parser *p); -static CmpopExprPair* notin_bitwise_or_rule(Parser *p); -static CmpopExprPair* in_bitwise_or_rule(Parser *p); -static CmpopExprPair* isnot_bitwise_or_rule(Parser *p); -static CmpopExprPair* is_bitwise_or_rule(Parser *p); -static expr_ty bitwise_or_rule(Parser *p); -static expr_ty bitwise_xor_rule(Parser *p); -static expr_ty bitwise_and_rule(Parser *p); -static expr_ty shift_expr_rule(Parser *p); -static expr_ty sum_rule(Parser *p); -static expr_ty term_rule(Parser *p); -static expr_ty factor_rule(Parser *p); -static expr_ty power_rule(Parser *p); -static expr_ty await_primary_rule(Parser *p); -static expr_ty primary_rule(Parser *p); -static expr_ty slices_rule(Parser *p); -static expr_ty slice_rule(Parser *p); -static expr_ty atom_rule(Parser *p); -static expr_ty strings_rule(Parser *p); -static expr_ty list_rule(Parser *p); -static expr_ty listcomp_rule(Parser *p); -static expr_ty tuple_rule(Parser *p); -static expr_ty group_rule(Parser *p); -static expr_ty genexp_rule(Parser *p); -static expr_ty set_rule(Parser *p); -static expr_ty setcomp_rule(Parser *p); -static expr_ty dict_rule(Parser *p); -static expr_ty dictcomp_rule(Parser *p); -static asdl_seq* double_starred_kvpairs_rule(Parser *p); -static KeyValuePair* double_starred_kvpair_rule(Parser *p); -static KeyValuePair* kvpair_rule(Parser *p); -static asdl_seq* for_if_clauses_rule(Parser *p); -static comprehension_ty for_if_clause_rule(Parser *p); -static expr_ty yield_expr_rule(Parser *p); -static expr_ty arguments_rule(Parser *p); -static expr_ty args_rule(Parser *p); -static asdl_seq* kwargs_rule(Parser *p); -static expr_ty starred_expression_rule(Parser *p); -static KeywordOrStarred* kwarg_or_starred_rule(Parser *p); -static KeywordOrStarred* kwarg_or_double_starred_rule(Parser *p); -static expr_ty star_targets_rule(Parser *p); -static asdl_seq* star_targets_seq_rule(Parser *p); -static expr_ty star_target_rule(Parser *p); -static expr_ty star_atom_rule(Parser *p); -static expr_ty single_target_rule(Parser *p); -static expr_ty single_subscript_attribute_target_rule(Parser *p); -static asdl_seq* del_targets_rule(Parser *p); -static expr_ty del_target_rule(Parser *p); -static expr_ty del_t_atom_rule(Parser *p); -static void *del_target_end_rule(Parser *p); -static asdl_seq* targets_rule(Parser *p); -static expr_ty target_rule(Parser *p); -static expr_ty t_primary_rule(Parser *p); -static void *t_lookahead_rule(Parser *p); -static expr_ty t_atom_rule(Parser *p); -static void *incorrect_arguments_rule(Parser *p); -static void *invalid_kwarg_rule(Parser *p); -static void *invalid_named_expression_rule(Parser *p); -static void *invalid_assignment_rule(Parser *p); -static void *invalid_block_rule(Parser *p); -static void *invalid_comprehension_rule(Parser *p); -static void *invalid_dict_comprehension_rule(Parser *p); -static void *invalid_parameters_rule(Parser *p); -static void *invalid_star_etc_rule(Parser *p); -static void *invalid_lambda_star_etc_rule(Parser *p); -static void *invalid_double_type_comments_rule(Parser *p); -static void *invalid_del_target_rule(Parser *p); -static void *invalid_import_from_targets_rule(Parser *p); -static asdl_seq *_loop0_1_rule(Parser *p); -static asdl_seq *_loop0_2_rule(Parser *p); -static asdl_seq *_loop0_4_rule(Parser *p); -static asdl_seq *_gather_3_rule(Parser *p); -static asdl_seq *_loop0_6_rule(Parser *p); -static asdl_seq *_gather_5_rule(Parser *p); -static asdl_seq *_loop0_8_rule(Parser *p); -static asdl_seq *_gather_7_rule(Parser *p); -static asdl_seq *_loop0_10_rule(Parser *p); -static asdl_seq *_gather_9_rule(Parser *p); -static asdl_seq *_loop1_11_rule(Parser *p); -static asdl_seq *_loop0_13_rule(Parser *p); -static asdl_seq *_gather_12_rule(Parser *p); -static void *_tmp_14_rule(Parser *p); -static void *_tmp_15_rule(Parser *p); -static void *_tmp_16_rule(Parser *p); -static void *_tmp_17_rule(Parser *p); -static void *_tmp_18_rule(Parser *p); -static void *_tmp_19_rule(Parser *p); -static void *_tmp_20_rule(Parser *p); -static void *_tmp_21_rule(Parser *p); -static asdl_seq *_loop1_22_rule(Parser *p); -static void *_tmp_23_rule(Parser *p); -static void *_tmp_24_rule(Parser *p); -static asdl_seq *_loop0_26_rule(Parser *p); -static asdl_seq *_gather_25_rule(Parser *p); -static asdl_seq *_loop0_28_rule(Parser *p); -static asdl_seq *_gather_27_rule(Parser *p); -static void *_tmp_29_rule(Parser *p); -static asdl_seq *_loop0_30_rule(Parser *p); -static asdl_seq *_loop1_31_rule(Parser *p); -static asdl_seq *_loop0_33_rule(Parser *p); -static asdl_seq *_gather_32_rule(Parser *p); -static void *_tmp_34_rule(Parser *p); -static asdl_seq *_loop0_36_rule(Parser *p); -static asdl_seq *_gather_35_rule(Parser *p); -static void *_tmp_37_rule(Parser *p); -static asdl_seq *_loop0_39_rule(Parser *p); -static asdl_seq *_gather_38_rule(Parser *p); -static asdl_seq *_loop0_41_rule(Parser *p); -static asdl_seq *_gather_40_rule(Parser *p); -static asdl_seq *_loop0_43_rule(Parser *p); -static asdl_seq *_gather_42_rule(Parser *p); -static asdl_seq *_loop0_45_rule(Parser *p); -static asdl_seq *_gather_44_rule(Parser *p); -static void *_tmp_46_rule(Parser *p); -static asdl_seq *_loop1_47_rule(Parser *p); -static void *_tmp_48_rule(Parser *p); -static void *_tmp_49_rule(Parser *p); -static void *_tmp_50_rule(Parser *p); -static void *_tmp_51_rule(Parser *p); -static void *_tmp_52_rule(Parser *p); -static asdl_seq *_loop0_53_rule(Parser *p); -static asdl_seq *_loop0_54_rule(Parser *p); -static asdl_seq *_loop0_55_rule(Parser *p); -static asdl_seq *_loop1_56_rule(Parser *p); -static asdl_seq *_loop0_57_rule(Parser *p); -static asdl_seq *_loop1_58_rule(Parser *p); -static asdl_seq *_loop1_59_rule(Parser *p); -static asdl_seq *_loop1_60_rule(Parser *p); -static asdl_seq *_loop0_61_rule(Parser *p); -static asdl_seq *_loop1_62_rule(Parser *p); -static asdl_seq *_loop0_63_rule(Parser *p); -static asdl_seq *_loop1_64_rule(Parser *p); -static asdl_seq *_loop0_65_rule(Parser *p); -static asdl_seq *_loop1_66_rule(Parser *p); -static asdl_seq *_loop1_67_rule(Parser *p); -static void *_tmp_68_rule(Parser *p); -static asdl_seq *_loop0_70_rule(Parser *p); -static asdl_seq *_gather_69_rule(Parser *p); -static asdl_seq *_loop1_71_rule(Parser *p); -static asdl_seq *_loop0_73_rule(Parser *p); -static asdl_seq *_gather_72_rule(Parser *p); -static asdl_seq *_loop1_74_rule(Parser *p); -static asdl_seq *_loop0_75_rule(Parser *p); -static asdl_seq *_loop0_76_rule(Parser *p); -static asdl_seq *_loop0_77_rule(Parser *p); -static asdl_seq *_loop1_78_rule(Parser *p); -static asdl_seq *_loop0_79_rule(Parser *p); -static asdl_seq *_loop1_80_rule(Parser *p); -static asdl_seq *_loop1_81_rule(Parser *p); -static asdl_seq *_loop1_82_rule(Parser *p); -static asdl_seq *_loop0_83_rule(Parser *p); -static asdl_seq *_loop1_84_rule(Parser *p); -static asdl_seq *_loop0_85_rule(Parser *p); -static asdl_seq *_loop1_86_rule(Parser *p); -static asdl_seq *_loop0_87_rule(Parser *p); -static asdl_seq *_loop1_88_rule(Parser *p); -static asdl_seq *_loop1_89_rule(Parser *p); -static asdl_seq *_loop1_90_rule(Parser *p); -static asdl_seq *_loop1_91_rule(Parser *p); -static void *_tmp_92_rule(Parser *p); -static asdl_seq *_loop0_94_rule(Parser *p); -static asdl_seq *_gather_93_rule(Parser *p); -static void *_tmp_95_rule(Parser *p); -static void *_tmp_96_rule(Parser *p); -static void *_tmp_97_rule(Parser *p); -static void *_tmp_98_rule(Parser *p); -static asdl_seq *_loop1_99_rule(Parser *p); -static void *_tmp_100_rule(Parser *p); -static void *_tmp_101_rule(Parser *p); -static asdl_seq *_loop0_103_rule(Parser *p); -static asdl_seq *_gather_102_rule(Parser *p); -static asdl_seq *_loop1_104_rule(Parser *p); -static asdl_seq *_loop0_105_rule(Parser *p); -static asdl_seq *_loop0_106_rule(Parser *p); -static void *_tmp_107_rule(Parser *p); -static void *_tmp_108_rule(Parser *p); -static asdl_seq *_loop0_110_rule(Parser *p); -static asdl_seq *_gather_109_rule(Parser *p); -static asdl_seq *_loop0_112_rule(Parser *p); -static asdl_seq *_gather_111_rule(Parser *p); -static asdl_seq *_loop0_114_rule(Parser *p); -static asdl_seq *_gather_113_rule(Parser *p); -static asdl_seq *_loop0_116_rule(Parser *p); -static asdl_seq *_gather_115_rule(Parser *p); -static asdl_seq *_loop0_117_rule(Parser *p); -static asdl_seq *_loop0_119_rule(Parser *p); -static asdl_seq *_gather_118_rule(Parser *p); -static void *_tmp_120_rule(Parser *p); -static asdl_seq *_loop0_122_rule(Parser *p); -static asdl_seq *_gather_121_rule(Parser *p); -static asdl_seq *_loop0_124_rule(Parser *p); -static asdl_seq *_gather_123_rule(Parser *p); -static void *_tmp_125_rule(Parser *p); -static asdl_seq *_loop0_126_rule(Parser *p); -static void *_tmp_127_rule(Parser *p); -static void *_tmp_128_rule(Parser *p); -static void *_tmp_129_rule(Parser *p); -static void *_tmp_130_rule(Parser *p); -static asdl_seq *_loop0_131_rule(Parser *p); -static void *_tmp_132_rule(Parser *p); -static void *_tmp_133_rule(Parser *p); -static void *_tmp_134_rule(Parser *p); -static void *_tmp_135_rule(Parser *p); -static void *_tmp_136_rule(Parser *p); -static void *_tmp_137_rule(Parser *p); -static void *_tmp_138_rule(Parser *p); -static void *_tmp_139_rule(Parser *p); -static void *_tmp_140_rule(Parser *p); -static void *_tmp_141_rule(Parser *p); -static void *_tmp_142_rule(Parser *p); -static void *_tmp_143_rule(Parser *p); -static void *_tmp_144_rule(Parser *p); -static void *_tmp_145_rule(Parser *p); -static asdl_seq *_loop1_146_rule(Parser *p); -static void *_tmp_147_rule(Parser *p); -static void *_tmp_148_rule(Parser *p); - - -// file: statements? $ -static mod_ty -file_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - mod_ty _res = NULL; - int _mark = p->mark; - { // statements? $ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> file[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "statements? $")); - void *a; - Token * endmarker_var; - if ( - (a = statements_rule(p), 1) // statements? - && - (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' - ) - { - D(fprintf(stderr, "%*c+ file[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "statements? $")); - _res = _PyPegen_make_module ( p , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s file[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "statements? $")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// interactive: statement_newline -static mod_ty -interactive_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - mod_ty _res = NULL; - int _mark = p->mark; - { // statement_newline - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> interactive[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "statement_newline")); - asdl_seq* a; - if ( - (a = statement_newline_rule(p)) // statement_newline - ) - { - D(fprintf(stderr, "%*c+ interactive[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "statement_newline")); - _res = Interactive ( a , p -> arena ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s interactive[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "statement_newline")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// eval: expressions NEWLINE* $ -static mod_ty -eval_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - mod_ty _res = NULL; - int _mark = p->mark; - { // expressions NEWLINE* $ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> eval[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expressions NEWLINE* $")); - asdl_seq * _loop0_1_var; - expr_ty a; - Token * endmarker_var; - if ( - (a = expressions_rule(p)) // expressions - && - (_loop0_1_var = _loop0_1_rule(p)) // NEWLINE* - && - (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' - ) - { - D(fprintf(stderr, "%*c+ eval[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expressions NEWLINE* $")); - _res = Expression ( a , p -> arena ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s eval[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expressions NEWLINE* $")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// func_type: '(' type_expressions? ')' '->' expression NEWLINE* $ -static mod_ty -func_type_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - mod_ty _res = NULL; - int _mark = p->mark; - { // '(' type_expressions? ')' '->' expression NEWLINE* $ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> func_type[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' type_expressions? ')' '->' expression NEWLINE* $")); - Token * _literal; - Token * _literal_1; - Token * _literal_2; - asdl_seq * _loop0_2_var; - void *a; - expr_ty b; - Token * endmarker_var; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (a = type_expressions_rule(p), 1) // type_expressions? - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - && - (_literal_2 = _PyPegen_expect_token(p, 51)) // token='->' - && - (b = expression_rule(p)) // expression - && - (_loop0_2_var = _loop0_2_rule(p)) // NEWLINE* - && - (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' - ) - { - D(fprintf(stderr, "%*c+ func_type[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' type_expressions? ')' '->' expression NEWLINE* $")); - _res = FunctionType ( a , b , p -> arena ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s func_type[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' type_expressions? ')' '->' expression NEWLINE* $")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// fstring: star_expressions -static expr_ty -fstring_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - { // star_expressions - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> fstring[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions")); - expr_ty star_expressions_var; - if ( - (star_expressions_var = star_expressions_rule(p)) // star_expressions - ) - { - D(fprintf(stderr, "%*c+ fstring[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions")); - _res = star_expressions_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s fstring[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// type_expressions: -// | ','.expression+ ',' '*' expression ',' '**' expression -// | ','.expression+ ',' '*' expression -// | ','.expression+ ',' '**' expression -// | '*' expression ',' '**' expression -// | '*' expression -// | '**' expression -// | ','.expression+ -static asdl_seq* -type_expressions_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // ','.expression+ ',' '*' expression ',' '**' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.expression+ ',' '*' expression ',' '**' expression")); - Token * _literal; - Token * _literal_1; - Token * _literal_2; - Token * _literal_3; - asdl_seq * a; - expr_ty b; - expr_ty c; - if ( - (a = _gather_3_rule(p)) // ','.expression+ - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (_literal_1 = _PyPegen_expect_token(p, 16)) // token='*' - && - (b = expression_rule(p)) // expression - && - (_literal_2 = _PyPegen_expect_token(p, 12)) // token=',' - && - (_literal_3 = _PyPegen_expect_token(p, 35)) // token='**' - && - (c = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.expression+ ',' '*' expression ',' '**' expression")); - _res = _PyPegen_seq_append_to_end ( p , CHECK ( _PyPegen_seq_append_to_end ( p , a , b ) ) , c ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.expression+ ',' '*' expression ',' '**' expression")); - } - { // ','.expression+ ',' '*' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.expression+ ',' '*' expression")); - Token * _literal; - Token * _literal_1; - asdl_seq * a; - expr_ty b; - if ( - (a = _gather_5_rule(p)) // ','.expression+ - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (_literal_1 = _PyPegen_expect_token(p, 16)) // token='*' - && - (b = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.expression+ ',' '*' expression")); - _res = _PyPegen_seq_append_to_end ( p , a , b ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.expression+ ',' '*' expression")); - } - { // ','.expression+ ',' '**' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.expression+ ',' '**' expression")); - Token * _literal; - Token * _literal_1; - asdl_seq * a; - expr_ty b; - if ( - (a = _gather_7_rule(p)) // ','.expression+ - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (_literal_1 = _PyPegen_expect_token(p, 35)) // token='**' - && - (b = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.expression+ ',' '**' expression")); - _res = _PyPegen_seq_append_to_end ( p , a , b ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.expression+ ',' '**' expression")); - } - { // '*' expression ',' '**' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' expression ',' '**' expression")); - Token * _literal; - Token * _literal_1; - Token * _literal_2; - expr_ty a; - expr_ty b; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (a = expression_rule(p)) // expression - && - (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' - && - (_literal_2 = _PyPegen_expect_token(p, 35)) // token='**' - && - (b = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' expression ',' '**' expression")); - _res = _PyPegen_seq_append_to_end ( p , CHECK ( _PyPegen_singleton_seq ( p , a ) ) , b ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' expression ',' '**' expression")); - } - { // '*' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' expression")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (a = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' expression")); - _res = _PyPegen_singleton_seq ( p , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' expression")); - } - { // '**' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**' expression")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 35)) // token='**' - && - (a = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**' expression")); - _res = _PyPegen_singleton_seq ( p , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**' expression")); - } - { // ','.expression+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> type_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.expression+")); - asdl_seq * _gather_9_var; - if ( - (_gather_9_var = _gather_9_rule(p)) // ','.expression+ - ) - { - D(fprintf(stderr, "%*c+ type_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.expression+")); - _res = _gather_9_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s type_expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.expression+")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// statements: statement+ -static asdl_seq* -statements_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // statement+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> statements[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "statement+")); - asdl_seq * a; - if ( - (a = _loop1_11_rule(p)) // statement+ - ) - { - D(fprintf(stderr, "%*c+ statements[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "statement+")); - _res = _PyPegen_seq_flatten ( p , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s statements[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "statement+")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// statement: compound_stmt | simple_stmt -static asdl_seq* -statement_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // compound_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> statement[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "compound_stmt")); - stmt_ty a; - if ( - (a = compound_stmt_rule(p)) // compound_stmt - ) - { - D(fprintf(stderr, "%*c+ statement[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "compound_stmt")); - _res = _PyPegen_singleton_seq ( p , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s statement[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "compound_stmt")); - } - { // simple_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> statement[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "simple_stmt")); - asdl_seq* simple_stmt_var; - if ( - (simple_stmt_var = simple_stmt_rule(p)) // simple_stmt - ) - { - D(fprintf(stderr, "%*c+ statement[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "simple_stmt")); - _res = simple_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s statement[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "simple_stmt")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// statement_newline: compound_stmt NEWLINE | simple_stmt | NEWLINE | $ -static asdl_seq* -statement_newline_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // compound_stmt NEWLINE - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> statement_newline[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "compound_stmt NEWLINE")); - stmt_ty a; - Token * newline_var; - if ( - (a = compound_stmt_rule(p)) // compound_stmt - && - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - ) - { - D(fprintf(stderr, "%*c+ statement_newline[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "compound_stmt NEWLINE")); - _res = _PyPegen_singleton_seq ( p , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s statement_newline[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "compound_stmt NEWLINE")); - } - { // simple_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> statement_newline[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "simple_stmt")); - asdl_seq* simple_stmt_var; - if ( - (simple_stmt_var = simple_stmt_rule(p)) // simple_stmt - ) - { - D(fprintf(stderr, "%*c+ statement_newline[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "simple_stmt")); - _res = simple_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s statement_newline[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "simple_stmt")); - } - { // NEWLINE - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> statement_newline[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE")); - Token * newline_var; - if ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - ) - { - D(fprintf(stderr, "%*c+ statement_newline[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NEWLINE")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _PyPegen_singleton_seq ( p , CHECK ( _Py_Pass ( EXTRA ) ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s statement_newline[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE")); - } - { // $ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> statement_newline[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "$")); - Token * endmarker_var; - if ( - (endmarker_var = _PyPegen_expect_token(p, ENDMARKER)) // token='ENDMARKER' - ) - { - D(fprintf(stderr, "%*c+ statement_newline[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "$")); - _res = _PyPegen_interactive_exit ( p ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s statement_newline[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "$")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// simple_stmt: small_stmt !';' NEWLINE | ';'.small_stmt+ ';'? NEWLINE -static asdl_seq* -simple_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // small_stmt !';' NEWLINE - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> simple_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "small_stmt !';' NEWLINE")); - stmt_ty a; - Token * newline_var; - if ( - (a = small_stmt_rule(p)) // small_stmt - && - _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 13) // token=';' - && - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - ) - { - D(fprintf(stderr, "%*c+ simple_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "small_stmt !';' NEWLINE")); - _res = _PyPegen_singleton_seq ( p , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s simple_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "small_stmt !';' NEWLINE")); - } - { // ';'.small_stmt+ ';'? NEWLINE - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> simple_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "';'.small_stmt+ ';'? NEWLINE")); - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - asdl_seq * a; - Token * newline_var; - if ( - (a = _gather_12_rule(p)) // ';'.small_stmt+ - && - (_opt_var = _PyPegen_expect_token(p, 13), 1) // ';'? - && - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - ) - { - D(fprintf(stderr, "%*c+ simple_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "';'.small_stmt+ ';'? NEWLINE")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s simple_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "';'.small_stmt+ ';'? NEWLINE")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// small_stmt: -// | assignment -// | star_expressions -// | &'return' return_stmt -// | &('import' | 'from') import_stmt -// | &'raise' raise_stmt -// | 'pass' -// | &'del' del_stmt -// | &'yield' yield_stmt -// | &'assert' assert_stmt -// | 'break' -// | 'continue' -// | &'global' global_stmt -// | &'nonlocal' nonlocal_stmt -static stmt_ty -small_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - if (_PyPegen_is_memoized(p, small_stmt_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // assignment - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "assignment")); - stmt_ty assignment_var; - if ( - (assignment_var = assignment_rule(p)) // assignment - ) - { - D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "assignment")); - _res = assignment_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "assignment")); - } - { // star_expressions - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions")); - expr_ty e; - if ( - (e = star_expressions_rule(p)) // star_expressions - ) - { - D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Expr ( e , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions")); - } - { // &'return' return_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'return' return_stmt")); - stmt_ty return_stmt_var; - if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 500) // token='return' - && - (return_stmt_var = return_stmt_rule(p)) // return_stmt - ) - { - D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'return' return_stmt")); - _res = return_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'return' return_stmt")); - } - { // &('import' | 'from') import_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&('import' | 'from') import_stmt")); - stmt_ty import_stmt_var; - if ( - _PyPegen_lookahead(1, _tmp_14_rule, p) - && - (import_stmt_var = import_stmt_rule(p)) // import_stmt - ) - { - D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&('import' | 'from') import_stmt")); - _res = import_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&('import' | 'from') import_stmt")); - } - { // &'raise' raise_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'raise' raise_stmt")); - stmt_ty raise_stmt_var; - if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 501) // token='raise' - && - (raise_stmt_var = raise_stmt_rule(p)) // raise_stmt - ) - { - D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'raise' raise_stmt")); - _res = raise_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'raise' raise_stmt")); - } - { // 'pass' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'pass'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 502)) // token='pass' - ) - { - D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'pass'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Pass ( EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'pass'")); - } - { // &'del' del_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'del' del_stmt")); - stmt_ty del_stmt_var; - if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 503) // token='del' - && - (del_stmt_var = del_stmt_rule(p)) // del_stmt - ) - { - D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'del' del_stmt")); - _res = del_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'del' del_stmt")); - } - { // &'yield' yield_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'yield' yield_stmt")); - stmt_ty yield_stmt_var; - if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 504) // token='yield' - && - (yield_stmt_var = yield_stmt_rule(p)) // yield_stmt - ) - { - D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'yield' yield_stmt")); - _res = yield_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'yield' yield_stmt")); - } - { // &'assert' assert_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'assert' assert_stmt")); - stmt_ty assert_stmt_var; - if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 505) // token='assert' - && - (assert_stmt_var = assert_stmt_rule(p)) // assert_stmt - ) - { - D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'assert' assert_stmt")); - _res = assert_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'assert' assert_stmt")); - } - { // 'break' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'break'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 506)) // token='break' - ) - { - D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'break'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Break ( EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'break'")); - } - { // 'continue' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'continue'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 507)) // token='continue' - ) - { - D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'continue'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Continue ( EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'continue'")); - } - { // &'global' global_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'global' global_stmt")); - stmt_ty global_stmt_var; - if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 508) // token='global' - && - (global_stmt_var = global_stmt_rule(p)) // global_stmt - ) - { - D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'global' global_stmt")); - _res = global_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'global' global_stmt")); - } - { // &'nonlocal' nonlocal_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> small_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'nonlocal' nonlocal_stmt")); - stmt_ty nonlocal_stmt_var; - if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 509) // token='nonlocal' - && - (nonlocal_stmt_var = nonlocal_stmt_rule(p)) // nonlocal_stmt - ) - { - D(fprintf(stderr, "%*c+ small_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'nonlocal' nonlocal_stmt")); - _res = nonlocal_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s small_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'nonlocal' nonlocal_stmt")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, small_stmt_type, _res); - D(p->level--); - return _res; -} - -// compound_stmt: -// | &('def' | '@' | ASYNC) function_def -// | &'if' if_stmt -// | &('class' | '@') class_def -// | &('with' | ASYNC) with_stmt -// | &('for' | ASYNC) for_stmt -// | &'try' try_stmt -// | &'while' while_stmt -static stmt_ty -compound_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - { // &('def' | '@' | ASYNC) function_def - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&('def' | '@' | ASYNC) function_def")); - stmt_ty function_def_var; - if ( - _PyPegen_lookahead(1, _tmp_15_rule, p) - && - (function_def_var = function_def_rule(p)) // function_def - ) - { - D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&('def' | '@' | ASYNC) function_def")); - _res = function_def_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&('def' | '@' | ASYNC) function_def")); - } - { // &'if' if_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'if' if_stmt")); - stmt_ty if_stmt_var; - if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 510) // token='if' - && - (if_stmt_var = if_stmt_rule(p)) // if_stmt - ) - { - D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'if' if_stmt")); - _res = if_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'if' if_stmt")); - } - { // &('class' | '@') class_def - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&('class' | '@') class_def")); - stmt_ty class_def_var; - if ( - _PyPegen_lookahead(1, _tmp_16_rule, p) - && - (class_def_var = class_def_rule(p)) // class_def - ) - { - D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&('class' | '@') class_def")); - _res = class_def_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&('class' | '@') class_def")); - } - { // &('with' | ASYNC) with_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&('with' | ASYNC) with_stmt")); - stmt_ty with_stmt_var; - if ( - _PyPegen_lookahead(1, _tmp_17_rule, p) - && - (with_stmt_var = with_stmt_rule(p)) // with_stmt - ) - { - D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&('with' | ASYNC) with_stmt")); - _res = with_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&('with' | ASYNC) with_stmt")); - } - { // &('for' | ASYNC) for_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&('for' | ASYNC) for_stmt")); - stmt_ty for_stmt_var; - if ( - _PyPegen_lookahead(1, _tmp_18_rule, p) - && - (for_stmt_var = for_stmt_rule(p)) // for_stmt - ) - { - D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&('for' | ASYNC) for_stmt")); - _res = for_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&('for' | ASYNC) for_stmt")); - } - { // &'try' try_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'try' try_stmt")); - stmt_ty try_stmt_var; - if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 511) // token='try' - && - (try_stmt_var = try_stmt_rule(p)) // try_stmt - ) - { - D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'try' try_stmt")); - _res = try_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'try' try_stmt")); - } - { // &'while' while_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compound_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'while' while_stmt")); - stmt_ty while_stmt_var; - if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 512) // token='while' - && - (while_stmt_var = while_stmt_rule(p)) // while_stmt - ) - { - D(fprintf(stderr, "%*c+ compound_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'while' while_stmt")); - _res = while_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compound_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'while' while_stmt")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// assignment: -// | NAME ':' expression ['=' annotated_rhs] -// | ('(' single_target ')' | single_subscript_attribute_target) ':' expression ['=' annotated_rhs] -// | ((star_targets '='))+ (yield_expr | star_expressions) TYPE_COMMENT? -// | single_target augassign (yield_expr | star_expressions) -// | invalid_assignment -static stmt_ty -assignment_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // NAME ':' expression ['=' annotated_rhs] - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME ':' expression ['=' annotated_rhs]")); - Token * _literal; - expr_ty a; - expr_ty b; - void *c; - if ( - (a = _PyPegen_name_token(p)) // NAME - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = expression_rule(p)) // expression - && - (c = _tmp_19_rule(p), 1) // ['=' annotated_rhs] - ) - { - D(fprintf(stderr, "%*c+ assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME ':' expression ['=' annotated_rhs]")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = CHECK_VERSION ( 6 , "Variable annotation syntax is" , _Py_AnnAssign ( CHECK ( _PyPegen_set_expr_context ( p , a , Store ) ) , b , c , 1 , EXTRA ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s assignment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME ':' expression ['=' annotated_rhs]")); - } - { // ('(' single_target ')' | single_subscript_attribute_target) ':' expression ['=' annotated_rhs] - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('(' single_target ')' | single_subscript_attribute_target) ':' expression ['=' annotated_rhs]")); - Token * _literal; - void *a; - expr_ty b; - void *c; - if ( - (a = _tmp_20_rule(p)) // '(' single_target ')' | single_subscript_attribute_target - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = expression_rule(p)) // expression - && - (c = _tmp_21_rule(p), 1) // ['=' annotated_rhs] - ) - { - D(fprintf(stderr, "%*c+ assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "('(' single_target ')' | single_subscript_attribute_target) ':' expression ['=' annotated_rhs]")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = CHECK_VERSION ( 6 , "Variable annotations syntax is" , _Py_AnnAssign ( a , b , c , 0 , EXTRA ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s assignment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('(' single_target ')' | single_subscript_attribute_target) ':' expression ['=' annotated_rhs]")); - } - { // ((star_targets '='))+ (yield_expr | star_expressions) TYPE_COMMENT? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "((star_targets '='))+ (yield_expr | star_expressions) TYPE_COMMENT?")); - asdl_seq * a; - void *b; - void *tc; - if ( - (a = _loop1_22_rule(p)) // ((star_targets '='))+ - && - (b = _tmp_23_rule(p)) // yield_expr | star_expressions - && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? - ) - { - D(fprintf(stderr, "%*c+ assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "((star_targets '='))+ (yield_expr | star_expressions) TYPE_COMMENT?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Assign ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s assignment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "((star_targets '='))+ (yield_expr | star_expressions) TYPE_COMMENT?")); - } - { // single_target augassign (yield_expr | star_expressions) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "single_target augassign (yield_expr | star_expressions)")); - expr_ty a; - AugOperator* b; - void *c; - if ( - (a = single_target_rule(p)) // single_target - && - (b = augassign_rule(p)) // augassign - && - (c = _tmp_24_rule(p)) // yield_expr | star_expressions - ) - { - D(fprintf(stderr, "%*c+ assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "single_target augassign (yield_expr | star_expressions)")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_AugAssign ( a , b -> kind , c , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s assignment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "single_target augassign (yield_expr | star_expressions)")); - } - { // invalid_assignment - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_assignment")); - void *invalid_assignment_var; - if ( - (invalid_assignment_var = invalid_assignment_rule(p)) // invalid_assignment - ) - { - D(fprintf(stderr, "%*c+ assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_assignment")); - _res = invalid_assignment_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s assignment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_assignment")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// augassign: -// | '+=' -// | '-=' -// | '*=' -// | '@=' -// | '/=' -// | '%=' -// | '&=' -// | '|=' -// | '^=' -// | '<<=' -// | '>>=' -// | '**=' -// | '//=' -static AugOperator* -augassign_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - AugOperator* _res = NULL; - int _mark = p->mark; - { // '+=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'+='")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 36)) // token='+=' - ) - { - D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'+='")); - _res = _PyPegen_augoperator ( p , Add ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'+='")); - } - { // '-=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'-='")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 37)) // token='-=' - ) - { - D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'-='")); - _res = _PyPegen_augoperator ( p , Sub ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'-='")); - } - { // '*=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*='")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 38)) // token='*=' - ) - { - D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*='")); - _res = _PyPegen_augoperator ( p , Mult ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*='")); - } - { // '@=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'@='")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 50)) // token='@=' - ) - { - D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'@='")); - _res = CHECK_VERSION ( 5 , "The '@' operator is" , _PyPegen_augoperator ( p , MatMult ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'@='")); - } - { // '/=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'/='")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 39)) // token='/=' - ) - { - D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'/='")); - _res = _PyPegen_augoperator ( p , Div ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'/='")); - } - { // '%=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'%='")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 40)) // token='%=' - ) - { - D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'%='")); - _res = _PyPegen_augoperator ( p , Mod ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'%='")); - } - { // '&=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'&='")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 41)) // token='&=' - ) - { - D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'&='")); - _res = _PyPegen_augoperator ( p , BitAnd ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'&='")); - } - { // '|=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'|='")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 42)) // token='|=' - ) - { - D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'|='")); - _res = _PyPegen_augoperator ( p , BitOr ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'|='")); - } - { // '^=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'^='")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 43)) // token='^=' - ) - { - D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'^='")); - _res = _PyPegen_augoperator ( p , BitXor ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'^='")); - } - { // '<<=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'<<='")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 44)) // token='<<=' - ) - { - D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'<<='")); - _res = _PyPegen_augoperator ( p , LShift ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'<<='")); - } - { // '>>=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'>>='")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 45)) // token='>>=' - ) - { - D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'>>='")); - _res = _PyPegen_augoperator ( p , RShift ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'>>='")); - } - { // '**=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**='")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 46)) // token='**=' - ) - { - D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**='")); - _res = _PyPegen_augoperator ( p , Pow ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**='")); - } - { // '//=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> augassign[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'//='")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 48)) // token='//=' - ) - { - D(fprintf(stderr, "%*c+ augassign[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'//='")); - _res = _PyPegen_augoperator ( p , FloorDiv ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s augassign[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'//='")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// global_stmt: 'global' ','.NAME+ -static stmt_ty -global_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'global' ','.NAME+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> global_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'global' ','.NAME+")); - Token * _keyword; - asdl_seq * a; - if ( - (_keyword = _PyPegen_expect_token(p, 508)) // token='global' - && - (a = _gather_25_rule(p)) // ','.NAME+ - ) - { - D(fprintf(stderr, "%*c+ global_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'global' ','.NAME+")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Global ( CHECK ( _PyPegen_map_names_to_ids ( p , a ) ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s global_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'global' ','.NAME+")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// nonlocal_stmt: 'nonlocal' ','.NAME+ -static stmt_ty -nonlocal_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'nonlocal' ','.NAME+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> nonlocal_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'nonlocal' ','.NAME+")); - Token * _keyword; - asdl_seq * a; - if ( - (_keyword = _PyPegen_expect_token(p, 509)) // token='nonlocal' - && - (a = _gather_27_rule(p)) // ','.NAME+ - ) - { - D(fprintf(stderr, "%*c+ nonlocal_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'nonlocal' ','.NAME+")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Nonlocal ( CHECK ( _PyPegen_map_names_to_ids ( p , a ) ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s nonlocal_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'nonlocal' ','.NAME+")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// yield_stmt: yield_expr -static stmt_ty -yield_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // yield_expr - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> yield_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "yield_expr")); - expr_ty y; - if ( - (y = yield_expr_rule(p)) // yield_expr - ) - { - D(fprintf(stderr, "%*c+ yield_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "yield_expr")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Expr ( y , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s yield_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "yield_expr")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// assert_stmt: 'assert' expression [',' expression] -static stmt_ty -assert_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'assert' expression [',' expression] - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> assert_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'assert' expression [',' expression]")); - Token * _keyword; - expr_ty a; - void *b; - if ( - (_keyword = _PyPegen_expect_token(p, 505)) // token='assert' - && - (a = expression_rule(p)) // expression - && - (b = _tmp_29_rule(p), 1) // [',' expression] - ) - { - D(fprintf(stderr, "%*c+ assert_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'assert' expression [',' expression]")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Assert ( a , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s assert_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'assert' expression [',' expression]")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// del_stmt: 'del' del_targets -static stmt_ty -del_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'del' del_targets - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'del' del_targets")); - Token * _keyword; - asdl_seq* a; - if ( - (_keyword = _PyPegen_expect_token(p, 503)) // token='del' - && - (a = del_targets_rule(p)) // del_targets - ) - { - D(fprintf(stderr, "%*c+ del_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'del' del_targets")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Delete ( a , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'del' del_targets")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// import_stmt: import_name | import_from -static stmt_ty -import_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - { // import_name - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> import_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "import_name")); - stmt_ty import_name_var; - if ( - (import_name_var = import_name_rule(p)) // import_name - ) - { - D(fprintf(stderr, "%*c+ import_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "import_name")); - _res = import_name_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s import_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "import_name")); - } - { // import_from - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> import_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "import_from")); - stmt_ty import_from_var; - if ( - (import_from_var = import_from_rule(p)) // import_from - ) - { - D(fprintf(stderr, "%*c+ import_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "import_from")); - _res = import_from_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s import_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "import_from")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// import_name: 'import' dotted_as_names -static stmt_ty -import_name_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'import' dotted_as_names - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> import_name[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'import' dotted_as_names")); - Token * _keyword; - asdl_seq* a; - if ( - (_keyword = _PyPegen_expect_token(p, 513)) // token='import' - && - (a = dotted_as_names_rule(p)) // dotted_as_names - ) - { - D(fprintf(stderr, "%*c+ import_name[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'import' dotted_as_names")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Import ( a , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s import_name[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'import' dotted_as_names")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// import_from: -// | 'from' (('.' | '...'))* dotted_name 'import' import_from_targets -// | 'from' (('.' | '...'))+ 'import' import_from_targets -static stmt_ty -import_from_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'from' (('.' | '...'))* dotted_name 'import' import_from_targets - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> import_from[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'from' (('.' | '...'))* dotted_name 'import' import_from_targets")); - Token * _keyword; - Token * _keyword_1; - asdl_seq * a; - expr_ty b; - asdl_seq* c; - if ( - (_keyword = _PyPegen_expect_token(p, 514)) // token='from' - && - (a = _loop0_30_rule(p)) // (('.' | '...'))* - && - (b = dotted_name_rule(p)) // dotted_name - && - (_keyword_1 = _PyPegen_expect_token(p, 513)) // token='import' - && - (c = import_from_targets_rule(p)) // import_from_targets - ) - { - D(fprintf(stderr, "%*c+ import_from[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'from' (('.' | '...'))* dotted_name 'import' import_from_targets")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_ImportFrom ( b -> v . Name . id , c , _PyPegen_seq_count_dots ( a ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s import_from[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'from' (('.' | '...'))* dotted_name 'import' import_from_targets")); - } - { // 'from' (('.' | '...'))+ 'import' import_from_targets - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> import_from[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'from' (('.' | '...'))+ 'import' import_from_targets")); - Token * _keyword; - Token * _keyword_1; - asdl_seq * a; - asdl_seq* b; - if ( - (_keyword = _PyPegen_expect_token(p, 514)) // token='from' - && - (a = _loop1_31_rule(p)) // (('.' | '...'))+ - && - (_keyword_1 = _PyPegen_expect_token(p, 513)) // token='import' - && - (b = import_from_targets_rule(p)) // import_from_targets - ) - { - D(fprintf(stderr, "%*c+ import_from[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'from' (('.' | '...'))+ 'import' import_from_targets")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_ImportFrom ( NULL , b , _PyPegen_seq_count_dots ( a ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s import_from[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'from' (('.' | '...'))+ 'import' import_from_targets")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// import_from_targets: -// | '(' import_from_as_names ','? ')' -// | import_from_as_names !',' -// | '*' -// | invalid_import_from_targets -static asdl_seq* -import_from_targets_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // '(' import_from_as_names ','? ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> import_from_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' import_from_as_names ','? ')'")); - Token * _literal; - Token * _literal_1; - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - asdl_seq* a; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (a = import_from_as_names_rule(p)) // import_from_as_names - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ import_from_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' import_from_as_names ','? ')'")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s import_from_targets[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' import_from_as_names ','? ')'")); - } - { // import_from_as_names !',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> import_from_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "import_from_as_names !','")); - asdl_seq* import_from_as_names_var; - if ( - (import_from_as_names_var = import_from_as_names_rule(p)) // import_from_as_names - && - _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 12) // token=',' - ) - { - D(fprintf(stderr, "%*c+ import_from_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "import_from_as_names !','")); - _res = import_from_as_names_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s import_from_targets[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "import_from_as_names !','")); - } - { // '*' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> import_from_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - ) - { - D(fprintf(stderr, "%*c+ import_from_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*'")); - _res = _PyPegen_singleton_seq ( p , CHECK ( _PyPegen_alias_for_star ( p ) ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s import_from_targets[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*'")); - } - { // invalid_import_from_targets - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> import_from_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_import_from_targets")); - void *invalid_import_from_targets_var; - if ( - (invalid_import_from_targets_var = invalid_import_from_targets_rule(p)) // invalid_import_from_targets - ) - { - D(fprintf(stderr, "%*c+ import_from_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_import_from_targets")); - _res = invalid_import_from_targets_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s import_from_targets[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_import_from_targets")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// import_from_as_names: ','.import_from_as_name+ -static asdl_seq* -import_from_as_names_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // ','.import_from_as_name+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> import_from_as_names[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.import_from_as_name+")); - asdl_seq * a; - if ( - (a = _gather_32_rule(p)) // ','.import_from_as_name+ - ) - { - D(fprintf(stderr, "%*c+ import_from_as_names[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.import_from_as_name+")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s import_from_as_names[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.import_from_as_name+")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// import_from_as_name: NAME ['as' NAME] -static alias_ty -import_from_as_name_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - alias_ty _res = NULL; - int _mark = p->mark; - { // NAME ['as' NAME] - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> import_from_as_name[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME ['as' NAME]")); - expr_ty a; - void *b; - if ( - (a = _PyPegen_name_token(p)) // NAME - && - (b = _tmp_34_rule(p), 1) // ['as' NAME] - ) - { - D(fprintf(stderr, "%*c+ import_from_as_name[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME ['as' NAME]")); - _res = _Py_alias ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Name . id : NULL , p -> arena ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s import_from_as_name[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME ['as' NAME]")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// dotted_as_names: ','.dotted_as_name+ -static asdl_seq* -dotted_as_names_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // ','.dotted_as_name+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> dotted_as_names[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.dotted_as_name+")); - asdl_seq * a; - if ( - (a = _gather_35_rule(p)) // ','.dotted_as_name+ - ) - { - D(fprintf(stderr, "%*c+ dotted_as_names[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.dotted_as_name+")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s dotted_as_names[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.dotted_as_name+")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// dotted_as_name: dotted_name ['as' NAME] -static alias_ty -dotted_as_name_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - alias_ty _res = NULL; - int _mark = p->mark; - { // dotted_name ['as' NAME] - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> dotted_as_name[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "dotted_name ['as' NAME]")); - expr_ty a; - void *b; - if ( - (a = dotted_name_rule(p)) // dotted_name - && - (b = _tmp_37_rule(p), 1) // ['as' NAME] - ) - { - D(fprintf(stderr, "%*c+ dotted_as_name[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "dotted_name ['as' NAME]")); - _res = _Py_alias ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Name . id : NULL , p -> arena ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s dotted_as_name[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "dotted_name ['as' NAME]")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// Left-recursive -// dotted_name: dotted_name '.' NAME | NAME -static expr_ty dotted_name_raw(Parser *); -static expr_ty -dotted_name_rule(Parser *p) -{ - D(p->level++); - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, dotted_name_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - int _resmark = p->mark; - while (1) { - int tmpvar_0 = _PyPegen_update_memo(p, _mark, dotted_name_type, _res); - if (tmpvar_0) { - D(p->level--); - return _res; - } - p->mark = _mark; - void *_raw = dotted_name_raw(p); - if (_raw == NULL || p->mark <= _resmark) - break; - _resmark = p->mark; - _res = _raw; - } - p->mark = _resmark; - D(p->level--); - return _res; -} -static expr_ty -dotted_name_raw(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - { // dotted_name '.' NAME - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> dotted_name[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "dotted_name '.' NAME")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = dotted_name_rule(p)) // dotted_name - && - (_literal = _PyPegen_expect_token(p, 23)) // token='.' - && - (b = _PyPegen_name_token(p)) // NAME - ) - { - D(fprintf(stderr, "%*c+ dotted_name[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "dotted_name '.' NAME")); - _res = _PyPegen_join_names_with_dot ( p , a , b ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s dotted_name[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "dotted_name '.' NAME")); - } - { // NAME - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> dotted_name[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME")); - expr_ty name_var; - if ( - (name_var = _PyPegen_name_token(p)) // NAME - ) - { - D(fprintf(stderr, "%*c+ dotted_name[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME")); - _res = name_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s dotted_name[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// if_stmt: -// | 'if' named_expression ':' block elif_stmt -// | 'if' named_expression ':' block else_block? -static stmt_ty -if_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'if' named_expression ':' block elif_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> if_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'if' named_expression ':' block elif_stmt")); - Token * _keyword; - Token * _literal; - expr_ty a; - asdl_seq* b; - stmt_ty c; - if ( - (_keyword = _PyPegen_expect_token(p, 510)) // token='if' - && - (a = named_expression_rule(p)) // named_expression - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = block_rule(p)) // block - && - (c = elif_stmt_rule(p)) // elif_stmt - ) - { - D(fprintf(stderr, "%*c+ if_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'if' named_expression ':' block elif_stmt")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_If ( a , b , CHECK ( _PyPegen_singleton_seq ( p , c ) ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s if_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'if' named_expression ':' block elif_stmt")); - } - { // 'if' named_expression ':' block else_block? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> if_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'if' named_expression ':' block else_block?")); - Token * _keyword; - Token * _literal; - expr_ty a; - asdl_seq* b; - void *c; - if ( - (_keyword = _PyPegen_expect_token(p, 510)) // token='if' - && - (a = named_expression_rule(p)) // named_expression - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = block_rule(p)) // block - && - (c = else_block_rule(p), 1) // else_block? - ) - { - D(fprintf(stderr, "%*c+ if_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'if' named_expression ':' block else_block?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_If ( a , b , c , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s if_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'if' named_expression ':' block else_block?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// elif_stmt: -// | 'elif' named_expression ':' block elif_stmt -// | 'elif' named_expression ':' block else_block? -static stmt_ty -elif_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'elif' named_expression ':' block elif_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> elif_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'elif' named_expression ':' block elif_stmt")); - Token * _keyword; - Token * _literal; - expr_ty a; - asdl_seq* b; - stmt_ty c; - if ( - (_keyword = _PyPegen_expect_token(p, 515)) // token='elif' - && - (a = named_expression_rule(p)) // named_expression - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = block_rule(p)) // block - && - (c = elif_stmt_rule(p)) // elif_stmt - ) - { - D(fprintf(stderr, "%*c+ elif_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'elif' named_expression ':' block elif_stmt")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_If ( a , b , CHECK ( _PyPegen_singleton_seq ( p , c ) ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s elif_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'elif' named_expression ':' block elif_stmt")); - } - { // 'elif' named_expression ':' block else_block? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> elif_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'elif' named_expression ':' block else_block?")); - Token * _keyword; - Token * _literal; - expr_ty a; - asdl_seq* b; - void *c; - if ( - (_keyword = _PyPegen_expect_token(p, 515)) // token='elif' - && - (a = named_expression_rule(p)) // named_expression - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = block_rule(p)) // block - && - (c = else_block_rule(p), 1) // else_block? - ) - { - D(fprintf(stderr, "%*c+ elif_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'elif' named_expression ':' block else_block?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_If ( a , b , c , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s elif_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'elif' named_expression ':' block else_block?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// else_block: 'else' ':' block -static asdl_seq* -else_block_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // 'else' ':' block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> else_block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'else' ':' block")); - Token * _keyword; - Token * _literal; - asdl_seq* b; - if ( - (_keyword = _PyPegen_expect_token(p, 516)) // token='else' - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = block_rule(p)) // block - ) - { - D(fprintf(stderr, "%*c+ else_block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'else' ':' block")); - _res = b; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s else_block[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'else' ':' block")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// while_stmt: 'while' named_expression ':' block else_block? -static stmt_ty -while_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'while' named_expression ':' block else_block? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> while_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'while' named_expression ':' block else_block?")); - Token * _keyword; - Token * _literal; - expr_ty a; - asdl_seq* b; - void *c; - if ( - (_keyword = _PyPegen_expect_token(p, 512)) // token='while' - && - (a = named_expression_rule(p)) // named_expression - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = block_rule(p)) // block - && - (c = else_block_rule(p), 1) // else_block? - ) - { - D(fprintf(stderr, "%*c+ while_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'while' named_expression ':' block else_block?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_While ( a , b , c , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s while_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'while' named_expression ':' block else_block?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// for_stmt: -// | 'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block? -// | ASYNC 'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block? -static stmt_ty -for_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> for_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block?")); - Token * _keyword; - Token * _keyword_1; - Token * _literal; - asdl_seq* b; - void *el; - expr_ty ex; - expr_ty t; - void *tc; - if ( - (_keyword = _PyPegen_expect_token(p, 517)) // token='for' - && - (t = star_targets_rule(p)) // star_targets - && - (_keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' - && - (ex = star_expressions_rule(p)) // star_expressions - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? - && - (b = block_rule(p)) // block - && - (el = else_block_rule(p), 1) // else_block? - ) - { - D(fprintf(stderr, "%*c+ for_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_For ( t , ex , b , el , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s for_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block?")); - } - { // ASYNC 'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> for_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC 'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block?")); - Token * _keyword; - Token * _keyword_1; - Token * _literal; - Token * async_var; - asdl_seq* b; - void *el; - expr_ty ex; - expr_ty t; - void *tc; - if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' - && - (_keyword = _PyPegen_expect_token(p, 517)) // token='for' - && - (t = star_targets_rule(p)) // star_targets - && - (_keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' - && - (ex = star_expressions_rule(p)) // star_expressions - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? - && - (b = block_rule(p)) // block - && - (el = else_block_rule(p), 1) // else_block? - ) - { - D(fprintf(stderr, "%*c+ for_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC 'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = CHECK_VERSION ( 5 , "Async for loops are" , _Py_AsyncFor ( t , ex , b , el , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s for_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC 'for' star_targets 'in' star_expressions ':' TYPE_COMMENT? block else_block?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// with_stmt: -// | 'with' '(' ','.with_item+ ','? ')' ':' block -// | 'with' ','.with_item+ ':' TYPE_COMMENT? block -// | ASYNC 'with' '(' ','.with_item+ ','? ')' ':' block -// | ASYNC 'with' ','.with_item+ ':' TYPE_COMMENT? block -static stmt_ty -with_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'with' '(' ','.with_item+ ','? ')' ':' block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> with_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'with' '(' ','.with_item+ ','? ')' ':' block")); - Token * _keyword; - Token * _literal; - Token * _literal_1; - Token * _literal_2; - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - asdl_seq * a; - asdl_seq* b; - if ( - (_keyword = _PyPegen_expect_token(p, 519)) // token='with' - && - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (a = _gather_38_rule(p)) // ','.with_item+ - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - && - (_literal_2 = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = block_rule(p)) // block - ) - { - D(fprintf(stderr, "%*c+ with_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'with' '(' ','.with_item+ ','? ')' ':' block")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_With ( a , b , NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s with_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'with' '(' ','.with_item+ ','? ')' ':' block")); - } - { // 'with' ','.with_item+ ':' TYPE_COMMENT? block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> with_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'with' ','.with_item+ ':' TYPE_COMMENT? block")); - Token * _keyword; - Token * _literal; - asdl_seq * a; - asdl_seq* b; - void *tc; - if ( - (_keyword = _PyPegen_expect_token(p, 519)) // token='with' - && - (a = _gather_40_rule(p)) // ','.with_item+ - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? - && - (b = block_rule(p)) // block - ) - { - D(fprintf(stderr, "%*c+ with_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'with' ','.with_item+ ':' TYPE_COMMENT? block")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_With ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s with_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'with' ','.with_item+ ':' TYPE_COMMENT? block")); - } - { // ASYNC 'with' '(' ','.with_item+ ','? ')' ':' block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> with_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC 'with' '(' ','.with_item+ ','? ')' ':' block")); - Token * _keyword; - Token * _literal; - Token * _literal_1; - Token * _literal_2; - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - asdl_seq * a; - Token * async_var; - asdl_seq* b; - if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' - && - (_keyword = _PyPegen_expect_token(p, 519)) // token='with' - && - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (a = _gather_42_rule(p)) // ','.with_item+ - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - && - (_literal_2 = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = block_rule(p)) // block - ) - { - D(fprintf(stderr, "%*c+ with_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC 'with' '(' ','.with_item+ ','? ')' ':' block")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = CHECK_VERSION ( 5 , "Async with statements are" , _Py_AsyncWith ( a , b , NULL , EXTRA ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s with_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC 'with' '(' ','.with_item+ ','? ')' ':' block")); - } - { // ASYNC 'with' ','.with_item+ ':' TYPE_COMMENT? block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> with_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC 'with' ','.with_item+ ':' TYPE_COMMENT? block")); - Token * _keyword; - Token * _literal; - asdl_seq * a; - Token * async_var; - asdl_seq* b; - void *tc; - if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' - && - (_keyword = _PyPegen_expect_token(p, 519)) // token='with' - && - (a = _gather_44_rule(p)) // ','.with_item+ - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? - && - (b = block_rule(p)) // block - ) - { - D(fprintf(stderr, "%*c+ with_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC 'with' ','.with_item+ ':' TYPE_COMMENT? block")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = CHECK_VERSION ( 5 , "Async with statements are" , _Py_AsyncWith ( a , b , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s with_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC 'with' ','.with_item+ ':' TYPE_COMMENT? block")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// with_item: expression ['as' target] -static withitem_ty -with_item_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - withitem_ty _res = NULL; - int _mark = p->mark; - { // expression ['as' target] - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> with_item[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression ['as' target]")); - expr_ty e; - void *o; - if ( - (e = expression_rule(p)) // expression - && - (o = _tmp_46_rule(p), 1) // ['as' target] - ) - { - D(fprintf(stderr, "%*c+ with_item[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression ['as' target]")); - _res = _Py_withitem ( e , o , p -> arena ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s with_item[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression ['as' target]")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// try_stmt: -// | 'try' ':' block finally_block -// | 'try' ':' block except_block+ else_block? finally_block? -static stmt_ty -try_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'try' ':' block finally_block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> try_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'try' ':' block finally_block")); - Token * _keyword; - Token * _literal; - asdl_seq* b; - asdl_seq* f; - if ( - (_keyword = _PyPegen_expect_token(p, 511)) // token='try' - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = block_rule(p)) // block - && - (f = finally_block_rule(p)) // finally_block - ) - { - D(fprintf(stderr, "%*c+ try_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'try' ':' block finally_block")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Try ( b , NULL , NULL , f , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s try_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'try' ':' block finally_block")); - } - { // 'try' ':' block except_block+ else_block? finally_block? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> try_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'try' ':' block except_block+ else_block? finally_block?")); - Token * _keyword; - Token * _literal; - asdl_seq* b; - void *el; - asdl_seq * ex; - void *f; - if ( - (_keyword = _PyPegen_expect_token(p, 511)) // token='try' - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = block_rule(p)) // block - && - (ex = _loop1_47_rule(p)) // except_block+ - && - (el = else_block_rule(p), 1) // else_block? - && - (f = finally_block_rule(p), 1) // finally_block? - ) - { - D(fprintf(stderr, "%*c+ try_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'try' ':' block except_block+ else_block? finally_block?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Try ( b , ex , el , f , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s try_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'try' ':' block except_block+ else_block? finally_block?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// except_block: 'except' expression ['as' NAME] ':' block | 'except' ':' block -static excepthandler_ty -except_block_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - excepthandler_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'except' expression ['as' NAME] ':' block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> except_block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'except' expression ['as' NAME] ':' block")); - Token * _keyword; - Token * _literal; - asdl_seq* b; - expr_ty e; - void *t; - if ( - (_keyword = _PyPegen_expect_token(p, 520)) // token='except' - && - (e = expression_rule(p)) // expression - && - (t = _tmp_48_rule(p), 1) // ['as' NAME] - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = block_rule(p)) // block - ) - { - D(fprintf(stderr, "%*c+ except_block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'except' expression ['as' NAME] ':' block")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_ExceptHandler ( e , ( t ) ? ( ( expr_ty ) t ) -> v . Name . id : NULL , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s except_block[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'except' expression ['as' NAME] ':' block")); - } - { // 'except' ':' block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> except_block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'except' ':' block")); - Token * _keyword; - Token * _literal; - asdl_seq* b; - if ( - (_keyword = _PyPegen_expect_token(p, 520)) // token='except' - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = block_rule(p)) // block - ) - { - D(fprintf(stderr, "%*c+ except_block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'except' ':' block")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_ExceptHandler ( NULL , NULL , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s except_block[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'except' ':' block")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// finally_block: 'finally' ':' block -static asdl_seq* -finally_block_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // 'finally' ':' block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> finally_block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'finally' ':' block")); - Token * _keyword; - Token * _literal; - asdl_seq* a; - if ( - (_keyword = _PyPegen_expect_token(p, 521)) // token='finally' - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (a = block_rule(p)) // block - ) - { - D(fprintf(stderr, "%*c+ finally_block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'finally' ':' block")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s finally_block[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'finally' ':' block")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// return_stmt: 'return' star_expressions? -static stmt_ty -return_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'return' star_expressions? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> return_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'return' star_expressions?")); - Token * _keyword; - void *a; - if ( - (_keyword = _PyPegen_expect_token(p, 500)) // token='return' - && - (a = star_expressions_rule(p), 1) // star_expressions? - ) - { - D(fprintf(stderr, "%*c+ return_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'return' star_expressions?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Return ( a , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s return_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'return' star_expressions?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// raise_stmt: 'raise' expression ['from' expression] | 'raise' -static stmt_ty -raise_stmt_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'raise' expression ['from' expression] - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> raise_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'raise' expression ['from' expression]")); - Token * _keyword; - expr_ty a; - void *b; - if ( - (_keyword = _PyPegen_expect_token(p, 501)) // token='raise' - && - (a = expression_rule(p)) // expression - && - (b = _tmp_49_rule(p), 1) // ['from' expression] - ) - { - D(fprintf(stderr, "%*c+ raise_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'raise' expression ['from' expression]")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Raise ( a , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s raise_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'raise' expression ['from' expression]")); - } - { // 'raise' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> raise_stmt[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'raise'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 501)) // token='raise' - ) - { - D(fprintf(stderr, "%*c+ raise_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'raise'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Raise ( NULL , NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s raise_stmt[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'raise'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// function_def: decorators function_def_raw | function_def_raw -static stmt_ty -function_def_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - { // decorators function_def_raw - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> function_def[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "decorators function_def_raw")); - asdl_seq* d; - stmt_ty f; - if ( - (d = decorators_rule(p)) // decorators - && - (f = function_def_raw_rule(p)) // function_def_raw - ) - { - D(fprintf(stderr, "%*c+ function_def[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "decorators function_def_raw")); - _res = _PyPegen_function_def_decorators ( p , d , f ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s function_def[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "decorators function_def_raw")); - } - { // function_def_raw - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> function_def[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "function_def_raw")); - stmt_ty function_def_raw_var; - if ( - (function_def_raw_var = function_def_raw_rule(p)) // function_def_raw - ) - { - D(fprintf(stderr, "%*c+ function_def[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "function_def_raw")); - _res = function_def_raw_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s function_def[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "function_def_raw")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// function_def_raw: -// | 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block -// | ASYNC 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block -static stmt_ty -function_def_raw_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> function_def_raw[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block")); - Token * _keyword; - Token * _literal; - Token * _literal_1; - Token * _literal_2; - void *a; - asdl_seq* b; - expr_ty n; - void *params; - void *tc; - if ( - (_keyword = _PyPegen_expect_token(p, 522)) // token='def' - && - (n = _PyPegen_name_token(p)) // NAME - && - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (params = params_rule(p), 1) // params? - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - && - (a = _tmp_50_rule(p), 1) // ['->' expression] - && - (_literal_2 = _PyPegen_expect_token(p, 11)) // token=':' - && - (tc = func_type_comment_rule(p), 1) // func_type_comment? - && - (b = block_rule(p)) // block - ) - { - D(fprintf(stderr, "%*c+ function_def_raw[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_FunctionDef ( n -> v . Name . id , ( params ) ? params : CHECK ( _PyPegen_empty_arguments ( p ) ) , b , NULL , a , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s function_def_raw[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block")); - } - { // ASYNC 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> function_def_raw[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block")); - Token * _keyword; - Token * _literal; - Token * _literal_1; - Token * _literal_2; - void *a; - Token * async_var; - asdl_seq* b; - expr_ty n; - void *params; - void *tc; - if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' - && - (_keyword = _PyPegen_expect_token(p, 522)) // token='def' - && - (n = _PyPegen_name_token(p)) // NAME - && - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (params = params_rule(p), 1) // params? - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - && - (a = _tmp_51_rule(p), 1) // ['->' expression] - && - (_literal_2 = _PyPegen_expect_token(p, 11)) // token=':' - && - (tc = func_type_comment_rule(p), 1) // func_type_comment? - && - (b = block_rule(p)) // block - ) - { - D(fprintf(stderr, "%*c+ function_def_raw[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = CHECK_VERSION ( 5 , "Async functions are" , _Py_AsyncFunctionDef ( n -> v . Name . id , ( params ) ? params : CHECK ( _PyPegen_empty_arguments ( p ) ) , b , NULL , a , NEW_TYPE_COMMENT ( p , tc ) , EXTRA ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s function_def_raw[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC 'def' NAME '(' params? ')' ['->' expression] ':' func_type_comment? block")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// func_type_comment: -// | NEWLINE TYPE_COMMENT &(NEWLINE INDENT) -// | invalid_double_type_comments -// | TYPE_COMMENT -static Token* -func_type_comment_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - Token* _res = NULL; - int _mark = p->mark; - { // NEWLINE TYPE_COMMENT &(NEWLINE INDENT) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> func_type_comment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE TYPE_COMMENT &(NEWLINE INDENT)")); - Token * newline_var; - Token * t; - if ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - && - (t = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' - && - _PyPegen_lookahead(1, _tmp_52_rule, p) - ) - { - D(fprintf(stderr, "%*c+ func_type_comment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NEWLINE TYPE_COMMENT &(NEWLINE INDENT)")); - _res = t; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s func_type_comment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE TYPE_COMMENT &(NEWLINE INDENT)")); - } - { // invalid_double_type_comments - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> func_type_comment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_double_type_comments")); - void *invalid_double_type_comments_var; - if ( - (invalid_double_type_comments_var = invalid_double_type_comments_rule(p)) // invalid_double_type_comments - ) - { - D(fprintf(stderr, "%*c+ func_type_comment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_double_type_comments")); - _res = invalid_double_type_comments_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s func_type_comment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_double_type_comments")); - } - { // TYPE_COMMENT - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> func_type_comment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "TYPE_COMMENT")); - Token * type_comment_var; - if ( - (type_comment_var = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' - ) - { - D(fprintf(stderr, "%*c+ func_type_comment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "TYPE_COMMENT")); - _res = type_comment_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s func_type_comment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "TYPE_COMMENT")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// params: invalid_parameters | parameters -static arguments_ty -params_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - arguments_ty _res = NULL; - int _mark = p->mark; - { // invalid_parameters - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> params[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_parameters")); - void *invalid_parameters_var; - if ( - (invalid_parameters_var = invalid_parameters_rule(p)) // invalid_parameters - ) - { - D(fprintf(stderr, "%*c+ params[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_parameters")); - _res = invalid_parameters_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s params[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_parameters")); - } - { // parameters - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> params[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "parameters")); - arguments_ty parameters_var; - if ( - (parameters_var = parameters_rule(p)) // parameters - ) - { - D(fprintf(stderr, "%*c+ params[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "parameters")); - _res = parameters_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s params[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "parameters")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// parameters: -// | slash_no_default param_no_default* param_with_default* star_etc? -// | slash_with_default param_with_default* star_etc? -// | param_no_default+ param_with_default* star_etc? -// | param_with_default+ star_etc? -// | star_etc -static arguments_ty -parameters_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - arguments_ty _res = NULL; - int _mark = p->mark; - { // slash_no_default param_no_default* param_with_default* star_etc? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "slash_no_default param_no_default* param_with_default* star_etc?")); - asdl_seq* a; - asdl_seq * b; - asdl_seq * c; - void *d; - if ( - (a = slash_no_default_rule(p)) // slash_no_default - && - (b = _loop0_53_rule(p)) // param_no_default* - && - (c = _loop0_54_rule(p)) // param_with_default* - && - (d = star_etc_rule(p), 1) // star_etc? - ) - { - D(fprintf(stderr, "%*c+ parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "slash_no_default param_no_default* param_with_default* star_etc?")); - _res = _PyPegen_make_arguments ( p , a , NULL , b , c , d ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s parameters[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "slash_no_default param_no_default* param_with_default* star_etc?")); - } - { // slash_with_default param_with_default* star_etc? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "slash_with_default param_with_default* star_etc?")); - SlashWithDefault* a; - asdl_seq * b; - void *c; - if ( - (a = slash_with_default_rule(p)) // slash_with_default - && - (b = _loop0_55_rule(p)) // param_with_default* - && - (c = star_etc_rule(p), 1) // star_etc? - ) - { - D(fprintf(stderr, "%*c+ parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "slash_with_default param_with_default* star_etc?")); - _res = _PyPegen_make_arguments ( p , NULL , a , NULL , b , c ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s parameters[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "slash_with_default param_with_default* star_etc?")); - } - { // param_no_default+ param_with_default* star_etc? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default+ param_with_default* star_etc?")); - asdl_seq * a; - asdl_seq * b; - void *c; - if ( - (a = _loop1_56_rule(p)) // param_no_default+ - && - (b = _loop0_57_rule(p)) // param_with_default* - && - (c = star_etc_rule(p), 1) // star_etc? - ) - { - D(fprintf(stderr, "%*c+ parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_no_default+ param_with_default* star_etc?")); - _res = _PyPegen_make_arguments ( p , NULL , NULL , a , b , c ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s parameters[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default+ param_with_default* star_etc?")); - } - { // param_with_default+ star_etc? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default+ star_etc?")); - asdl_seq * a; - void *b; - if ( - (a = _loop1_58_rule(p)) // param_with_default+ - && - (b = star_etc_rule(p), 1) // star_etc? - ) - { - D(fprintf(stderr, "%*c+ parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_with_default+ star_etc?")); - _res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , a , b ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s parameters[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default+ star_etc?")); - } - { // star_etc - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_etc")); - StarEtc* a; - if ( - (a = star_etc_rule(p)) // star_etc - ) - { - D(fprintf(stderr, "%*c+ parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_etc")); - _res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , NULL , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s parameters[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_etc")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// slash_no_default: param_no_default+ '/' ',' | param_no_default+ '/' &')' -static asdl_seq* -slash_no_default_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // param_no_default+ '/' ',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> slash_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default+ '/' ','")); - Token * _literal; - Token * _literal_1; - asdl_seq * a; - if ( - (a = _loop1_59_rule(p)) // param_no_default+ - && - (_literal = _PyPegen_expect_token(p, 17)) // token='/' - && - (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' - ) - { - D(fprintf(stderr, "%*c+ slash_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_no_default+ '/' ','")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s slash_no_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default+ '/' ','")); - } - { // param_no_default+ '/' &')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> slash_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default+ '/' &')'")); - Token * _literal; - asdl_seq * a; - if ( - (a = _loop1_60_rule(p)) // param_no_default+ - && - (_literal = _PyPegen_expect_token(p, 17)) // token='/' - && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' - ) - { - D(fprintf(stderr, "%*c+ slash_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_no_default+ '/' &')'")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s slash_no_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default+ '/' &')'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// slash_with_default: -// | param_no_default* param_with_default+ '/' ',' -// | param_no_default* param_with_default+ '/' &')' -static SlashWithDefault* -slash_with_default_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - SlashWithDefault* _res = NULL; - int _mark = p->mark; - { // param_no_default* param_with_default+ '/' ',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> slash_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default* param_with_default+ '/' ','")); - Token * _literal; - Token * _literal_1; - asdl_seq * a; - asdl_seq * b; - if ( - (a = _loop0_61_rule(p)) // param_no_default* - && - (b = _loop1_62_rule(p)) // param_with_default+ - && - (_literal = _PyPegen_expect_token(p, 17)) // token='/' - && - (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' - ) - { - D(fprintf(stderr, "%*c+ slash_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_no_default* param_with_default+ '/' ','")); - _res = _PyPegen_slash_with_default ( p , a , b ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s slash_with_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default* param_with_default+ '/' ','")); - } - { // param_no_default* param_with_default+ '/' &')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> slash_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default* param_with_default+ '/' &')'")); - Token * _literal; - asdl_seq * a; - asdl_seq * b; - if ( - (a = _loop0_63_rule(p)) // param_no_default* - && - (b = _loop1_64_rule(p)) // param_with_default+ - && - (_literal = _PyPegen_expect_token(p, 17)) // token='/' - && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' - ) - { - D(fprintf(stderr, "%*c+ slash_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_no_default* param_with_default+ '/' &')'")); - _res = _PyPegen_slash_with_default ( p , a , b ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s slash_with_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default* param_with_default+ '/' &')'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// star_etc: -// | '*' param_no_default param_maybe_default* kwds? -// | '*' ',' param_maybe_default+ kwds? -// | kwds -// | invalid_star_etc -static StarEtc* -star_etc_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - StarEtc* _res = NULL; - int _mark = p->mark; - { // '*' param_no_default param_maybe_default* kwds? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' param_no_default param_maybe_default* kwds?")); - Token * _literal; - arg_ty a; - asdl_seq * b; - void *c; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (a = param_no_default_rule(p)) // param_no_default - && - (b = _loop0_65_rule(p)) // param_maybe_default* - && - (c = kwds_rule(p), 1) // kwds? - ) - { - D(fprintf(stderr, "%*c+ star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' param_no_default param_maybe_default* kwds?")); - _res = _PyPegen_star_etc ( p , a , b , c ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_etc[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' param_no_default param_maybe_default* kwds?")); - } - { // '*' ',' param_maybe_default+ kwds? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' ',' param_maybe_default+ kwds?")); - Token * _literal; - Token * _literal_1; - asdl_seq * b; - void *c; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' - && - (b = _loop1_66_rule(p)) // param_maybe_default+ - && - (c = kwds_rule(p), 1) // kwds? - ) - { - D(fprintf(stderr, "%*c+ star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' ',' param_maybe_default+ kwds?")); - _res = _PyPegen_star_etc ( p , NULL , b , c ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_etc[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' ',' param_maybe_default+ kwds?")); - } - { // kwds - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kwds")); - arg_ty a; - if ( - (a = kwds_rule(p)) // kwds - ) - { - D(fprintf(stderr, "%*c+ star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kwds")); - _res = _PyPegen_star_etc ( p , NULL , NULL , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_etc[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kwds")); - } - { // invalid_star_etc - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_star_etc")); - void *invalid_star_etc_var; - if ( - (invalid_star_etc_var = invalid_star_etc_rule(p)) // invalid_star_etc - ) - { - D(fprintf(stderr, "%*c+ star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_star_etc")); - _res = invalid_star_etc_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_etc[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_star_etc")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// kwds: '**' param_no_default -static arg_ty -kwds_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - arg_ty _res = NULL; - int _mark = p->mark; - { // '**' param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> kwds[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**' param_no_default")); - Token * _literal; - arg_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 35)) // token='**' - && - (a = param_no_default_rule(p)) // param_no_default - ) - { - D(fprintf(stderr, "%*c+ kwds[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**' param_no_default")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s kwds[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**' param_no_default")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// param_no_default: param ',' TYPE_COMMENT? | param TYPE_COMMENT? &')' -static arg_ty -param_no_default_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - arg_ty _res = NULL; - int _mark = p->mark; - { // param ',' TYPE_COMMENT? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> param_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param ',' TYPE_COMMENT?")); - Token * _literal; - arg_ty a; - void *tc; - if ( - (a = param_rule(p)) // param - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? - ) - { - D(fprintf(stderr, "%*c+ param_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param ',' TYPE_COMMENT?")); - _res = _PyPegen_add_type_comment_to_arg ( p , a , tc ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s param_no_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param ',' TYPE_COMMENT?")); - } - { // param TYPE_COMMENT? &')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> param_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param TYPE_COMMENT? &')'")); - arg_ty a; - void *tc; - if ( - (a = param_rule(p)) // param - && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? - && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' - ) - { - D(fprintf(stderr, "%*c+ param_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param TYPE_COMMENT? &')'")); - _res = _PyPegen_add_type_comment_to_arg ( p , a , tc ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s param_no_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param TYPE_COMMENT? &')'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// param_with_default: param default ',' TYPE_COMMENT? | param default TYPE_COMMENT? &')' -static NameDefaultPair* -param_with_default_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - NameDefaultPair* _res = NULL; - int _mark = p->mark; - { // param default ',' TYPE_COMMENT? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> param_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param default ',' TYPE_COMMENT?")); - Token * _literal; - arg_ty a; - expr_ty c; - void *tc; - if ( - (a = param_rule(p)) // param - && - (c = default_rule(p)) // default - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? - ) - { - D(fprintf(stderr, "%*c+ param_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param default ',' TYPE_COMMENT?")); - _res = _PyPegen_name_default_pair ( p , a , c , tc ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s param_with_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param default ',' TYPE_COMMENT?")); - } - { // param default TYPE_COMMENT? &')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> param_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param default TYPE_COMMENT? &')'")); - arg_ty a; - expr_ty c; - void *tc; - if ( - (a = param_rule(p)) // param - && - (c = default_rule(p)) // default - && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? - && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' - ) - { - D(fprintf(stderr, "%*c+ param_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param default TYPE_COMMENT? &')'")); - _res = _PyPegen_name_default_pair ( p , a , c , tc ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s param_with_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param default TYPE_COMMENT? &')'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// param_maybe_default: -// | param default? ',' TYPE_COMMENT? -// | param default? TYPE_COMMENT? &')' -static NameDefaultPair* -param_maybe_default_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - NameDefaultPair* _res = NULL; - int _mark = p->mark; - { // param default? ',' TYPE_COMMENT? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> param_maybe_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param default? ',' TYPE_COMMENT?")); - Token * _literal; - arg_ty a; - void *c; - void *tc; - if ( - (a = param_rule(p)) // param - && - (c = default_rule(p), 1) // default? - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? - ) - { - D(fprintf(stderr, "%*c+ param_maybe_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param default? ',' TYPE_COMMENT?")); - _res = _PyPegen_name_default_pair ( p , a , c , tc ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s param_maybe_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param default? ',' TYPE_COMMENT?")); - } - { // param default? TYPE_COMMENT? &')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> param_maybe_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param default? TYPE_COMMENT? &')'")); - arg_ty a; - void *c; - void *tc; - if ( - (a = param_rule(p)) // param - && - (c = default_rule(p), 1) // default? - && - (tc = _PyPegen_expect_token(p, TYPE_COMMENT), 1) // TYPE_COMMENT? - && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' - ) - { - D(fprintf(stderr, "%*c+ param_maybe_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param default? TYPE_COMMENT? &')'")); - _res = _PyPegen_name_default_pair ( p , a , c , tc ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s param_maybe_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param default? TYPE_COMMENT? &')'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// param: NAME annotation? -static arg_ty -param_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - arg_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // NAME annotation? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> param[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME annotation?")); - expr_ty a; - void *b; - if ( - (a = _PyPegen_name_token(p)) // NAME - && - (b = annotation_rule(p), 1) // annotation? - ) - { - D(fprintf(stderr, "%*c+ param[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME annotation?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_arg ( a -> v . Name . id , b , NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s param[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME annotation?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// annotation: ':' expression -static expr_ty -annotation_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - { // ':' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> annotation[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "':' expression")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (a = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ annotation[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "':' expression")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s annotation[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "':' expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// default: '=' expression -static expr_ty -default_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - { // '=' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'=' expression")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 22)) // token='=' - && - (a = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'=' expression")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'=' expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// decorators: (('@' named_expression NEWLINE))+ -static asdl_seq* -decorators_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // (('@' named_expression NEWLINE))+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> decorators[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "(('@' named_expression NEWLINE))+")); - asdl_seq * a; - if ( - (a = _loop1_67_rule(p)) // (('@' named_expression NEWLINE))+ - ) - { - D(fprintf(stderr, "%*c+ decorators[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "(('@' named_expression NEWLINE))+")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s decorators[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "(('@' named_expression NEWLINE))+")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// class_def: decorators class_def_raw | class_def_raw -static stmt_ty -class_def_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - { // decorators class_def_raw - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> class_def[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "decorators class_def_raw")); - asdl_seq* a; - stmt_ty b; - if ( - (a = decorators_rule(p)) // decorators - && - (b = class_def_raw_rule(p)) // class_def_raw - ) - { - D(fprintf(stderr, "%*c+ class_def[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "decorators class_def_raw")); - _res = _PyPegen_class_def_decorators ( p , a , b ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s class_def[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "decorators class_def_raw")); - } - { // class_def_raw - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> class_def[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "class_def_raw")); - stmt_ty class_def_raw_var; - if ( - (class_def_raw_var = class_def_raw_rule(p)) // class_def_raw - ) - { - D(fprintf(stderr, "%*c+ class_def[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "class_def_raw")); - _res = class_def_raw_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s class_def[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "class_def_raw")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// class_def_raw: 'class' NAME ['(' arguments? ')'] ':' block -static stmt_ty -class_def_raw_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - stmt_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'class' NAME ['(' arguments? ')'] ':' block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> class_def_raw[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'class' NAME ['(' arguments? ')'] ':' block")); - Token * _keyword; - Token * _literal; - expr_ty a; - void *b; - asdl_seq* c; - if ( - (_keyword = _PyPegen_expect_token(p, 523)) // token='class' - && - (a = _PyPegen_name_token(p)) // NAME - && - (b = _tmp_68_rule(p), 1) // ['(' arguments? ')'] - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (c = block_rule(p)) // block - ) - { - D(fprintf(stderr, "%*c+ class_def_raw[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'class' NAME ['(' arguments? ')'] ':' block")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_ClassDef ( a -> v . Name . id , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , c , NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s class_def_raw[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'class' NAME ['(' arguments? ')'] ':' block")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// block: NEWLINE INDENT statements DEDENT | simple_stmt | invalid_block -static asdl_seq* -block_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - if (_PyPegen_is_memoized(p, block_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - { // NEWLINE INDENT statements DEDENT - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE INDENT statements DEDENT")); - asdl_seq* a; - Token * dedent_var; - Token * indent_var; - Token * newline_var; - if ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - && - (indent_var = _PyPegen_expect_token(p, INDENT)) // token='INDENT' - && - (a = statements_rule(p)) // statements - && - (dedent_var = _PyPegen_expect_token(p, DEDENT)) // token='DEDENT' - ) - { - D(fprintf(stderr, "%*c+ block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NEWLINE INDENT statements DEDENT")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s block[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE INDENT statements DEDENT")); - } - { // simple_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "simple_stmt")); - asdl_seq* simple_stmt_var; - if ( - (simple_stmt_var = simple_stmt_rule(p)) // simple_stmt - ) - { - D(fprintf(stderr, "%*c+ block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "simple_stmt")); - _res = simple_stmt_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s block[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "simple_stmt")); - } - { // invalid_block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_block")); - void *invalid_block_var; - if ( - (invalid_block_var = invalid_block_rule(p)) // invalid_block - ) - { - D(fprintf(stderr, "%*c+ block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_block")); - _res = invalid_block_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s block[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_block")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, block_type, _res); - D(p->level--); - return _res; -} - -// expressions_list: ','.star_expression+ ','? -static asdl_seq* -expressions_list_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // ','.star_expression+ ','? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> expressions_list[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.star_expression+ ','?")); - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - asdl_seq * a; - if ( - (a = _gather_69_rule(p)) // ','.star_expression+ - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - ) - { - D(fprintf(stderr, "%*c+ expressions_list[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.star_expression+ ','?")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s expressions_list[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.star_expression+ ','?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// star_expressions: -// | star_expression ((',' star_expression))+ ','? -// | star_expression ',' -// | star_expression -static expr_ty -star_expressions_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // star_expression ((',' star_expression))+ ','? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expression ((',' star_expression))+ ','?")); - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - expr_ty a; - asdl_seq * b; - if ( - (a = star_expression_rule(p)) // star_expression - && - (b = _loop1_71_rule(p)) // ((',' star_expression))+ - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - ) - { - D(fprintf(stderr, "%*c+ star_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expression ((',' star_expression))+ ','?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expression ((',' star_expression))+ ','?")); - } - { // star_expression ',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expression ','")); - Token * _literal; - expr_ty a; - if ( - (a = star_expression_rule(p)) // star_expression - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - ) - { - D(fprintf(stderr, "%*c+ star_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expression ','")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Tuple ( CHECK ( _PyPegen_singleton_seq ( p , a ) ) , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expression ','")); - } - { // star_expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expression")); - expr_ty star_expression_var; - if ( - (star_expression_var = star_expression_rule(p)) // star_expression - ) - { - D(fprintf(stderr, "%*c+ star_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expression")); - _res = star_expression_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// star_expression: '*' bitwise_or | expression -static expr_ty -star_expression_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, star_expression_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // '*' bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' bitwise_or")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (a = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ star_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' bitwise_or")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Starred ( a , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_expression[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' bitwise_or")); - } - { // expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression")); - expr_ty expression_var; - if ( - (expression_var = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ star_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression")); - _res = expression_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_expression[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, star_expression_type, _res); - D(p->level--); - return _res; -} - -// star_named_expressions: ','.star_named_expression+ ','? -static asdl_seq* -star_named_expressions_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // ','.star_named_expression+ ','? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_named_expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.star_named_expression+ ','?")); - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - asdl_seq * a; - if ( - (a = _gather_72_rule(p)) // ','.star_named_expression+ - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - ) - { - D(fprintf(stderr, "%*c+ star_named_expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.star_named_expression+ ','?")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_named_expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.star_named_expression+ ','?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// star_named_expression: '*' bitwise_or | named_expression -static expr_ty -star_named_expression_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // '*' bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_named_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' bitwise_or")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (a = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ star_named_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' bitwise_or")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Starred ( a , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_named_expression[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' bitwise_or")); - } - { // named_expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_named_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "named_expression")); - expr_ty named_expression_var; - if ( - (named_expression_var = named_expression_rule(p)) // named_expression - ) - { - D(fprintf(stderr, "%*c+ star_named_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "named_expression")); - _res = named_expression_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_named_expression[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "named_expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// named_expression: NAME ':=' expression | expression !':=' | invalid_named_expression -static expr_ty -named_expression_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // NAME ':=' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> named_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME ':=' expression")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = _PyPegen_name_token(p)) // NAME - && - (_literal = _PyPegen_expect_token(p, 53)) // token=':=' - && - (b = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ named_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME ':=' expression")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_NamedExpr ( CHECK ( _PyPegen_set_expr_context ( p , a , Store ) ) , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s named_expression[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME ':=' expression")); - } - { // expression !':=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> named_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression !':='")); - expr_ty expression_var; - if ( - (expression_var = expression_rule(p)) // expression - && - _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 53) // token=':=' - ) - { - D(fprintf(stderr, "%*c+ named_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression !':='")); - _res = expression_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s named_expression[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression !':='")); - } - { // invalid_named_expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> named_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_named_expression")); - void *invalid_named_expression_var; - if ( - (invalid_named_expression_var = invalid_named_expression_rule(p)) // invalid_named_expression - ) - { - D(fprintf(stderr, "%*c+ named_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_named_expression")); - _res = invalid_named_expression_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s named_expression[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_named_expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// annotated_rhs: yield_expr | star_expressions -static expr_ty -annotated_rhs_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - { // yield_expr - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> annotated_rhs[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "yield_expr")); - expr_ty yield_expr_var; - if ( - (yield_expr_var = yield_expr_rule(p)) // yield_expr - ) - { - D(fprintf(stderr, "%*c+ annotated_rhs[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "yield_expr")); - _res = yield_expr_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s annotated_rhs[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "yield_expr")); - } - { // star_expressions - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> annotated_rhs[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions")); - expr_ty star_expressions_var; - if ( - (star_expressions_var = star_expressions_rule(p)) // star_expressions - ) - { - D(fprintf(stderr, "%*c+ annotated_rhs[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions")); - _res = star_expressions_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s annotated_rhs[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// expressions: expression ((',' expression))+ ','? | expression ',' | expression -static expr_ty -expressions_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // expression ((',' expression))+ ','? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression ((',' expression))+ ','?")); - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - expr_ty a; - asdl_seq * b; - if ( - (a = expression_rule(p)) // expression - && - (b = _loop1_74_rule(p)) // ((',' expression))+ - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - ) - { - D(fprintf(stderr, "%*c+ expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression ((',' expression))+ ','?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression ((',' expression))+ ','?")); - } - { // expression ',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression ','")); - Token * _literal; - expr_ty a; - if ( - (a = expression_rule(p)) // expression - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - ) - { - D(fprintf(stderr, "%*c+ expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression ','")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Tuple ( CHECK ( _PyPegen_singleton_seq ( p , a ) ) , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression ','")); - } - { // expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> expressions[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression")); - expr_ty expression_var; - if ( - (expression_var = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ expressions[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression")); - _res = expression_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s expressions[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// expression: disjunction 'if' disjunction 'else' expression | disjunction | lambdef -static expr_ty -expression_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, expression_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // disjunction 'if' disjunction 'else' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "disjunction 'if' disjunction 'else' expression")); - Token * _keyword; - Token * _keyword_1; - expr_ty a; - expr_ty b; - expr_ty c; - if ( - (a = disjunction_rule(p)) // disjunction - && - (_keyword = _PyPegen_expect_token(p, 510)) // token='if' - && - (b = disjunction_rule(p)) // disjunction - && - (_keyword_1 = _PyPegen_expect_token(p, 516)) // token='else' - && - (c = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "disjunction 'if' disjunction 'else' expression")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_IfExp ( b , a , c , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s expression[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "disjunction 'if' disjunction 'else' expression")); - } - { // disjunction - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "disjunction")); - expr_ty disjunction_var; - if ( - (disjunction_var = disjunction_rule(p)) // disjunction - ) - { - D(fprintf(stderr, "%*c+ expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "disjunction")); - _res = disjunction_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s expression[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "disjunction")); - } - { // lambdef - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambdef")); - expr_ty lambdef_var; - if ( - (lambdef_var = lambdef_rule(p)) // lambdef - ) - { - D(fprintf(stderr, "%*c+ expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambdef")); - _res = lambdef_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s expression[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambdef")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, expression_type, _res); - D(p->level--); - return _res; -} - -// lambdef: 'lambda' lambda_parameters? ':' expression -static expr_ty -lambdef_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'lambda' lambda_parameters? ':' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambdef[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'lambda' lambda_parameters? ':' expression")); - Token * _keyword; - Token * _literal; - void *a; - expr_ty b; - if ( - (_keyword = _PyPegen_expect_token(p, 524)) // token='lambda' - && - (a = lambda_parameters_rule(p), 1) // lambda_parameters? - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ lambdef[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'lambda' lambda_parameters? ':' expression")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Lambda ( ( a ) ? a : CHECK ( _PyPegen_empty_arguments ( p ) ) , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambdef[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'lambda' lambda_parameters? ':' expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// lambda_parameters: -// | lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc? -// | lambda_slash_with_default lambda_param_with_default* lambda_star_etc? -// | lambda_param_no_default+ lambda_param_with_default* lambda_star_etc? -// | lambda_param_with_default+ lambda_star_etc? -// | lambda_star_etc -static arguments_ty -lambda_parameters_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - arguments_ty _res = NULL; - int _mark = p->mark; - { // lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc?")); - asdl_seq* a; - asdl_seq * b; - asdl_seq * c; - void *d; - if ( - (a = lambda_slash_no_default_rule(p)) // lambda_slash_no_default - && - (b = _loop0_75_rule(p)) // lambda_param_no_default* - && - (c = _loop0_76_rule(p)) // lambda_param_with_default* - && - (d = lambda_star_etc_rule(p), 1) // lambda_star_etc? - ) - { - D(fprintf(stderr, "%*c+ lambda_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc?")); - _res = _PyPegen_make_arguments ( p , a , NULL , b , c , d ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_parameters[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc?")); - } - { // lambda_slash_with_default lambda_param_with_default* lambda_star_etc? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_slash_with_default lambda_param_with_default* lambda_star_etc?")); - SlashWithDefault* a; - asdl_seq * b; - void *c; - if ( - (a = lambda_slash_with_default_rule(p)) // lambda_slash_with_default - && - (b = _loop0_77_rule(p)) // lambda_param_with_default* - && - (c = lambda_star_etc_rule(p), 1) // lambda_star_etc? - ) - { - D(fprintf(stderr, "%*c+ lambda_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_slash_with_default lambda_param_with_default* lambda_star_etc?")); - _res = _PyPegen_make_arguments ( p , NULL , a , NULL , b , c ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_parameters[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_slash_with_default lambda_param_with_default* lambda_star_etc?")); - } - { // lambda_param_no_default+ lambda_param_with_default* lambda_star_etc? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default+ lambda_param_with_default* lambda_star_etc?")); - asdl_seq * a; - asdl_seq * b; - void *c; - if ( - (a = _loop1_78_rule(p)) // lambda_param_no_default+ - && - (b = _loop0_79_rule(p)) // lambda_param_with_default* - && - (c = lambda_star_etc_rule(p), 1) // lambda_star_etc? - ) - { - D(fprintf(stderr, "%*c+ lambda_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default+ lambda_param_with_default* lambda_star_etc?")); - _res = _PyPegen_make_arguments ( p , NULL , NULL , a , b , c ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_parameters[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default+ lambda_param_with_default* lambda_star_etc?")); - } - { // lambda_param_with_default+ lambda_star_etc? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default+ lambda_star_etc?")); - asdl_seq * a; - void *b; - if ( - (a = _loop1_80_rule(p)) // lambda_param_with_default+ - && - (b = lambda_star_etc_rule(p), 1) // lambda_star_etc? - ) - { - D(fprintf(stderr, "%*c+ lambda_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default+ lambda_star_etc?")); - _res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , a , b ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_parameters[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default+ lambda_star_etc?")); - } - { // lambda_star_etc - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_star_etc")); - StarEtc* a; - if ( - (a = lambda_star_etc_rule(p)) // lambda_star_etc - ) - { - D(fprintf(stderr, "%*c+ lambda_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_star_etc")); - _res = _PyPegen_make_arguments ( p , NULL , NULL , NULL , NULL , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_parameters[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_star_etc")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// lambda_slash_no_default: -// | lambda_param_no_default+ '/' ',' -// | lambda_param_no_default+ '/' &':' -static asdl_seq* -lambda_slash_no_default_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // lambda_param_no_default+ '/' ',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_slash_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default+ '/' ','")); - Token * _literal; - Token * _literal_1; - asdl_seq * a; - if ( - (a = _loop1_81_rule(p)) // lambda_param_no_default+ - && - (_literal = _PyPegen_expect_token(p, 17)) // token='/' - && - (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' - ) - { - D(fprintf(stderr, "%*c+ lambda_slash_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default+ '/' ','")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_slash_no_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default+ '/' ','")); - } - { // lambda_param_no_default+ '/' &':' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_slash_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default+ '/' &':'")); - Token * _literal; - asdl_seq * a; - if ( - (a = _loop1_82_rule(p)) // lambda_param_no_default+ - && - (_literal = _PyPegen_expect_token(p, 17)) // token='/' - && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' - ) - { - D(fprintf(stderr, "%*c+ lambda_slash_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default+ '/' &':'")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_slash_no_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default+ '/' &':'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// lambda_slash_with_default: -// | lambda_param_no_default* lambda_param_with_default+ '/' ',' -// | lambda_param_no_default* lambda_param_with_default+ '/' &':' -static SlashWithDefault* -lambda_slash_with_default_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - SlashWithDefault* _res = NULL; - int _mark = p->mark; - { // lambda_param_no_default* lambda_param_with_default+ '/' ',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_slash_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default* lambda_param_with_default+ '/' ','")); - Token * _literal; - Token * _literal_1; - asdl_seq * a; - asdl_seq * b; - if ( - (a = _loop0_83_rule(p)) // lambda_param_no_default* - && - (b = _loop1_84_rule(p)) // lambda_param_with_default+ - && - (_literal = _PyPegen_expect_token(p, 17)) // token='/' - && - (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' - ) - { - D(fprintf(stderr, "%*c+ lambda_slash_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default* lambda_param_with_default+ '/' ','")); - _res = _PyPegen_slash_with_default ( p , a , b ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_slash_with_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default* lambda_param_with_default+ '/' ','")); - } - { // lambda_param_no_default* lambda_param_with_default+ '/' &':' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_slash_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default* lambda_param_with_default+ '/' &':'")); - Token * _literal; - asdl_seq * a; - asdl_seq * b; - if ( - (a = _loop0_85_rule(p)) // lambda_param_no_default* - && - (b = _loop1_86_rule(p)) // lambda_param_with_default+ - && - (_literal = _PyPegen_expect_token(p, 17)) // token='/' - && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' - ) - { - D(fprintf(stderr, "%*c+ lambda_slash_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default* lambda_param_with_default+ '/' &':'")); - _res = _PyPegen_slash_with_default ( p , a , b ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_slash_with_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default* lambda_param_with_default+ '/' &':'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// lambda_star_etc: -// | '*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds? -// | '*' ',' lambda_param_maybe_default+ lambda_kwds? -// | lambda_kwds -// | invalid_lambda_star_etc -static StarEtc* -lambda_star_etc_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - StarEtc* _res = NULL; - int _mark = p->mark; - { // '*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds?")); - Token * _literal; - arg_ty a; - asdl_seq * b; - void *c; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (a = lambda_param_no_default_rule(p)) // lambda_param_no_default - && - (b = _loop0_87_rule(p)) // lambda_param_maybe_default* - && - (c = lambda_kwds_rule(p), 1) // lambda_kwds? - ) - { - D(fprintf(stderr, "%*c+ lambda_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds?")); - _res = _PyPegen_star_etc ( p , a , b , c ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_star_etc[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds?")); - } - { // '*' ',' lambda_param_maybe_default+ lambda_kwds? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' ',' lambda_param_maybe_default+ lambda_kwds?")); - Token * _literal; - Token * _literal_1; - asdl_seq * b; - void *c; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' - && - (b = _loop1_88_rule(p)) // lambda_param_maybe_default+ - && - (c = lambda_kwds_rule(p), 1) // lambda_kwds? - ) - { - D(fprintf(stderr, "%*c+ lambda_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' ',' lambda_param_maybe_default+ lambda_kwds?")); - _res = _PyPegen_star_etc ( p , NULL , b , c ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_star_etc[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' ',' lambda_param_maybe_default+ lambda_kwds?")); - } - { // lambda_kwds - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_kwds")); - arg_ty a; - if ( - (a = lambda_kwds_rule(p)) // lambda_kwds - ) - { - D(fprintf(stderr, "%*c+ lambda_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_kwds")); - _res = _PyPegen_star_etc ( p , NULL , NULL , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_star_etc[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_kwds")); - } - { // invalid_lambda_star_etc - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_lambda_star_etc")); - void *invalid_lambda_star_etc_var; - if ( - (invalid_lambda_star_etc_var = invalid_lambda_star_etc_rule(p)) // invalid_lambda_star_etc - ) - { - D(fprintf(stderr, "%*c+ lambda_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_lambda_star_etc")); - _res = invalid_lambda_star_etc_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_star_etc[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_lambda_star_etc")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// lambda_kwds: '**' lambda_param_no_default -static arg_ty -lambda_kwds_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - arg_ty _res = NULL; - int _mark = p->mark; - { // '**' lambda_param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_kwds[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**' lambda_param_no_default")); - Token * _literal; - arg_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 35)) // token='**' - && - (a = lambda_param_no_default_rule(p)) // lambda_param_no_default - ) - { - D(fprintf(stderr, "%*c+ lambda_kwds[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**' lambda_param_no_default")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_kwds[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**' lambda_param_no_default")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// lambda_param_no_default: lambda_param ',' | lambda_param &':' -static arg_ty -lambda_param_no_default_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - arg_ty _res = NULL; - int _mark = p->mark; - { // lambda_param ',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_param_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param ','")); - Token * _literal; - arg_ty a; - if ( - (a = lambda_param_rule(p)) // lambda_param - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - ) - { - D(fprintf(stderr, "%*c+ lambda_param_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param ','")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_param_no_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param ','")); - } - { // lambda_param &':' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_param_no_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param &':'")); - arg_ty a; - if ( - (a = lambda_param_rule(p)) // lambda_param - && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' - ) - { - D(fprintf(stderr, "%*c+ lambda_param_no_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param &':'")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_param_no_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param &':'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// lambda_param_with_default: lambda_param default ',' | lambda_param default &':' -static NameDefaultPair* -lambda_param_with_default_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - NameDefaultPair* _res = NULL; - int _mark = p->mark; - { // lambda_param default ',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_param_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param default ','")); - Token * _literal; - arg_ty a; - expr_ty c; - if ( - (a = lambda_param_rule(p)) // lambda_param - && - (c = default_rule(p)) // default - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - ) - { - D(fprintf(stderr, "%*c+ lambda_param_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param default ','")); - _res = _PyPegen_name_default_pair ( p , a , c , NULL ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_param_with_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param default ','")); - } - { // lambda_param default &':' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_param_with_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param default &':'")); - arg_ty a; - expr_ty c; - if ( - (a = lambda_param_rule(p)) // lambda_param - && - (c = default_rule(p)) // default - && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' - ) - { - D(fprintf(stderr, "%*c+ lambda_param_with_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param default &':'")); - _res = _PyPegen_name_default_pair ( p , a , c , NULL ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_param_with_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param default &':'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// lambda_param_maybe_default: lambda_param default? ',' | lambda_param default? &':' -static NameDefaultPair* -lambda_param_maybe_default_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - NameDefaultPair* _res = NULL; - int _mark = p->mark; - { // lambda_param default? ',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_param_maybe_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param default? ','")); - Token * _literal; - arg_ty a; - void *c; - if ( - (a = lambda_param_rule(p)) // lambda_param - && - (c = default_rule(p), 1) // default? - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - ) - { - D(fprintf(stderr, "%*c+ lambda_param_maybe_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param default? ','")); - _res = _PyPegen_name_default_pair ( p , a , c , NULL ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_param_maybe_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param default? ','")); - } - { // lambda_param default? &':' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_param_maybe_default[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param default? &':'")); - arg_ty a; - void *c; - if ( - (a = lambda_param_rule(p)) // lambda_param - && - (c = default_rule(p), 1) // default? - && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 11) // token=':' - ) - { - D(fprintf(stderr, "%*c+ lambda_param_maybe_default[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_param default? &':'")); - _res = _PyPegen_name_default_pair ( p , a , c , NULL ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_param_maybe_default[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param default? &':'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// lambda_param: NAME -static arg_ty -lambda_param_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - arg_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // NAME - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lambda_param[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME")); - expr_ty a; - if ( - (a = _PyPegen_name_token(p)) // NAME - ) - { - D(fprintf(stderr, "%*c+ lambda_param[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_arg ( a -> v . Name . id , NULL , NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lambda_param[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// disjunction: conjunction (('or' conjunction))+ | conjunction -static expr_ty -disjunction_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, disjunction_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // conjunction (('or' conjunction))+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> disjunction[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "conjunction (('or' conjunction))+")); - expr_ty a; - asdl_seq * b; - if ( - (a = conjunction_rule(p)) // conjunction - && - (b = _loop1_89_rule(p)) // (('or' conjunction))+ - ) - { - D(fprintf(stderr, "%*c+ disjunction[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "conjunction (('or' conjunction))+")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BoolOp ( Or , CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s disjunction[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "conjunction (('or' conjunction))+")); - } - { // conjunction - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> disjunction[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "conjunction")); - expr_ty conjunction_var; - if ( - (conjunction_var = conjunction_rule(p)) // conjunction - ) - { - D(fprintf(stderr, "%*c+ disjunction[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "conjunction")); - _res = conjunction_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s disjunction[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "conjunction")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, disjunction_type, _res); - D(p->level--); - return _res; -} - -// conjunction: inversion (('and' inversion))+ | inversion -static expr_ty -conjunction_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, conjunction_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // inversion (('and' inversion))+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> conjunction[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "inversion (('and' inversion))+")); - expr_ty a; - asdl_seq * b; - if ( - (a = inversion_rule(p)) // inversion - && - (b = _loop1_90_rule(p)) // (('and' inversion))+ - ) - { - D(fprintf(stderr, "%*c+ conjunction[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "inversion (('and' inversion))+")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BoolOp ( And , CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s conjunction[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "inversion (('and' inversion))+")); - } - { // inversion - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> conjunction[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "inversion")); - expr_ty inversion_var; - if ( - (inversion_var = inversion_rule(p)) // inversion - ) - { - D(fprintf(stderr, "%*c+ conjunction[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "inversion")); - _res = inversion_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s conjunction[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "inversion")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, conjunction_type, _res); - D(p->level--); - return _res; -} - -// inversion: 'not' inversion | comparison -static expr_ty -inversion_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, inversion_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'not' inversion - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> inversion[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'not' inversion")); - Token * _keyword; - expr_ty a; - if ( - (_keyword = _PyPegen_expect_token(p, 525)) // token='not' - && - (a = inversion_rule(p)) // inversion - ) - { - D(fprintf(stderr, "%*c+ inversion[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'not' inversion")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_UnaryOp ( Not , a , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s inversion[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'not' inversion")); - } - { // comparison - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> inversion[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "comparison")); - expr_ty comparison_var; - if ( - (comparison_var = comparison_rule(p)) // comparison - ) - { - D(fprintf(stderr, "%*c+ inversion[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "comparison")); - _res = comparison_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s inversion[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "comparison")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, inversion_type, _res); - D(p->level--); - return _res; -} - -// comparison: bitwise_or compare_op_bitwise_or_pair+ | bitwise_or -static expr_ty -comparison_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // bitwise_or compare_op_bitwise_or_pair+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> comparison[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_or compare_op_bitwise_or_pair+")); - expr_ty a; - asdl_seq * b; - if ( - (a = bitwise_or_rule(p)) // bitwise_or - && - (b = _loop1_91_rule(p)) // compare_op_bitwise_or_pair+ - ) - { - D(fprintf(stderr, "%*c+ comparison[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_or compare_op_bitwise_or_pair+")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Compare ( a , CHECK ( _PyPegen_get_cmpops ( p , b ) ) , CHECK ( _PyPegen_get_exprs ( p , b ) ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s comparison[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_or compare_op_bitwise_or_pair+")); - } - { // bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> comparison[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_or")); - expr_ty bitwise_or_var; - if ( - (bitwise_or_var = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ comparison[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_or")); - _res = bitwise_or_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s comparison[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_or")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// compare_op_bitwise_or_pair: -// | eq_bitwise_or -// | noteq_bitwise_or -// | lte_bitwise_or -// | lt_bitwise_or -// | gte_bitwise_or -// | gt_bitwise_or -// | notin_bitwise_or -// | in_bitwise_or -// | isnot_bitwise_or -// | is_bitwise_or -static CmpopExprPair* -compare_op_bitwise_or_pair_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - CmpopExprPair* _res = NULL; - int _mark = p->mark; - { // eq_bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "eq_bitwise_or")); - CmpopExprPair* eq_bitwise_or_var; - if ( - (eq_bitwise_or_var = eq_bitwise_or_rule(p)) // eq_bitwise_or - ) - { - D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "eq_bitwise_or")); - _res = eq_bitwise_or_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "eq_bitwise_or")); - } - { // noteq_bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "noteq_bitwise_or")); - CmpopExprPair* noteq_bitwise_or_var; - if ( - (noteq_bitwise_or_var = noteq_bitwise_or_rule(p)) // noteq_bitwise_or - ) - { - D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "noteq_bitwise_or")); - _res = noteq_bitwise_or_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "noteq_bitwise_or")); - } - { // lte_bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lte_bitwise_or")); - CmpopExprPair* lte_bitwise_or_var; - if ( - (lte_bitwise_or_var = lte_bitwise_or_rule(p)) // lte_bitwise_or - ) - { - D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lte_bitwise_or")); - _res = lte_bitwise_or_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lte_bitwise_or")); - } - { // lt_bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lt_bitwise_or")); - CmpopExprPair* lt_bitwise_or_var; - if ( - (lt_bitwise_or_var = lt_bitwise_or_rule(p)) // lt_bitwise_or - ) - { - D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lt_bitwise_or")); - _res = lt_bitwise_or_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lt_bitwise_or")); - } - { // gte_bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "gte_bitwise_or")); - CmpopExprPair* gte_bitwise_or_var; - if ( - (gte_bitwise_or_var = gte_bitwise_or_rule(p)) // gte_bitwise_or - ) - { - D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "gte_bitwise_or")); - _res = gte_bitwise_or_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "gte_bitwise_or")); - } - { // gt_bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "gt_bitwise_or")); - CmpopExprPair* gt_bitwise_or_var; - if ( - (gt_bitwise_or_var = gt_bitwise_or_rule(p)) // gt_bitwise_or - ) - { - D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "gt_bitwise_or")); - _res = gt_bitwise_or_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "gt_bitwise_or")); - } - { // notin_bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "notin_bitwise_or")); - CmpopExprPair* notin_bitwise_or_var; - if ( - (notin_bitwise_or_var = notin_bitwise_or_rule(p)) // notin_bitwise_or - ) - { - D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "notin_bitwise_or")); - _res = notin_bitwise_or_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "notin_bitwise_or")); - } - { // in_bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "in_bitwise_or")); - CmpopExprPair* in_bitwise_or_var; - if ( - (in_bitwise_or_var = in_bitwise_or_rule(p)) // in_bitwise_or - ) - { - D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "in_bitwise_or")); - _res = in_bitwise_or_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "in_bitwise_or")); - } - { // isnot_bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "isnot_bitwise_or")); - CmpopExprPair* isnot_bitwise_or_var; - if ( - (isnot_bitwise_or_var = isnot_bitwise_or_rule(p)) // isnot_bitwise_or - ) - { - D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "isnot_bitwise_or")); - _res = isnot_bitwise_or_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "isnot_bitwise_or")); - } - { // is_bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> compare_op_bitwise_or_pair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "is_bitwise_or")); - CmpopExprPair* is_bitwise_or_var; - if ( - (is_bitwise_or_var = is_bitwise_or_rule(p)) // is_bitwise_or - ) - { - D(fprintf(stderr, "%*c+ compare_op_bitwise_or_pair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "is_bitwise_or")); - _res = is_bitwise_or_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s compare_op_bitwise_or_pair[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "is_bitwise_or")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// eq_bitwise_or: '==' bitwise_or -static CmpopExprPair* -eq_bitwise_or_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - CmpopExprPair* _res = NULL; - int _mark = p->mark; - { // '==' bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> eq_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'==' bitwise_or")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 27)) // token='==' - && - (a = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ eq_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'==' bitwise_or")); - _res = _PyPegen_cmpop_expr_pair ( p , Eq , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s eq_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'==' bitwise_or")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// noteq_bitwise_or: ('!=') bitwise_or -static CmpopExprPair* -noteq_bitwise_or_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - CmpopExprPair* _res = NULL; - int _mark = p->mark; - { // ('!=') bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> noteq_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('!=') bitwise_or")); - void *_tmp_92_var; - expr_ty a; - if ( - (_tmp_92_var = _tmp_92_rule(p)) // '!=' - && - (a = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ noteq_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "('!=') bitwise_or")); - _res = _PyPegen_cmpop_expr_pair ( p , NotEq , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s noteq_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('!=') bitwise_or")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// lte_bitwise_or: '<=' bitwise_or -static CmpopExprPair* -lte_bitwise_or_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - CmpopExprPair* _res = NULL; - int _mark = p->mark; - { // '<=' bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lte_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'<=' bitwise_or")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 29)) // token='<=' - && - (a = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ lte_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'<=' bitwise_or")); - _res = _PyPegen_cmpop_expr_pair ( p , LtE , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lte_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'<=' bitwise_or")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// lt_bitwise_or: '<' bitwise_or -static CmpopExprPair* -lt_bitwise_or_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - CmpopExprPair* _res = NULL; - int _mark = p->mark; - { // '<' bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> lt_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'<' bitwise_or")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 20)) // token='<' - && - (a = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ lt_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'<' bitwise_or")); - _res = _PyPegen_cmpop_expr_pair ( p , Lt , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s lt_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'<' bitwise_or")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// gte_bitwise_or: '>=' bitwise_or -static CmpopExprPair* -gte_bitwise_or_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - CmpopExprPair* _res = NULL; - int _mark = p->mark; - { // '>=' bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> gte_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'>=' bitwise_or")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 30)) // token='>=' - && - (a = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ gte_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'>=' bitwise_or")); - _res = _PyPegen_cmpop_expr_pair ( p , GtE , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s gte_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'>=' bitwise_or")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// gt_bitwise_or: '>' bitwise_or -static CmpopExprPair* -gt_bitwise_or_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - CmpopExprPair* _res = NULL; - int _mark = p->mark; - { // '>' bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> gt_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'>' bitwise_or")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 21)) // token='>' - && - (a = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ gt_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'>' bitwise_or")); - _res = _PyPegen_cmpop_expr_pair ( p , Gt , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s gt_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'>' bitwise_or")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// notin_bitwise_or: 'not' 'in' bitwise_or -static CmpopExprPair* -notin_bitwise_or_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - CmpopExprPair* _res = NULL; - int _mark = p->mark; - { // 'not' 'in' bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> notin_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'not' 'in' bitwise_or")); - Token * _keyword; - Token * _keyword_1; - expr_ty a; - if ( - (_keyword = _PyPegen_expect_token(p, 525)) // token='not' - && - (_keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' - && - (a = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ notin_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'not' 'in' bitwise_or")); - _res = _PyPegen_cmpop_expr_pair ( p , NotIn , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s notin_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'not' 'in' bitwise_or")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// in_bitwise_or: 'in' bitwise_or -static CmpopExprPair* -in_bitwise_or_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - CmpopExprPair* _res = NULL; - int _mark = p->mark; - { // 'in' bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> in_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'in' bitwise_or")); - Token * _keyword; - expr_ty a; - if ( - (_keyword = _PyPegen_expect_token(p, 518)) // token='in' - && - (a = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ in_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'in' bitwise_or")); - _res = _PyPegen_cmpop_expr_pair ( p , In , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s in_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'in' bitwise_or")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// isnot_bitwise_or: 'is' 'not' bitwise_or -static CmpopExprPair* -isnot_bitwise_or_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - CmpopExprPair* _res = NULL; - int _mark = p->mark; - { // 'is' 'not' bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> isnot_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'is' 'not' bitwise_or")); - Token * _keyword; - Token * _keyword_1; - expr_ty a; - if ( - (_keyword = _PyPegen_expect_token(p, 526)) // token='is' - && - (_keyword_1 = _PyPegen_expect_token(p, 525)) // token='not' - && - (a = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ isnot_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'is' 'not' bitwise_or")); - _res = _PyPegen_cmpop_expr_pair ( p , IsNot , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s isnot_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'is' 'not' bitwise_or")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// is_bitwise_or: 'is' bitwise_or -static CmpopExprPair* -is_bitwise_or_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - CmpopExprPair* _res = NULL; - int _mark = p->mark; - { // 'is' bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> is_bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'is' bitwise_or")); - Token * _keyword; - expr_ty a; - if ( - (_keyword = _PyPegen_expect_token(p, 526)) // token='is' - && - (a = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ is_bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'is' bitwise_or")); - _res = _PyPegen_cmpop_expr_pair ( p , Is , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s is_bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'is' bitwise_or")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// Left-recursive -// bitwise_or: bitwise_or '|' bitwise_xor | bitwise_xor -static expr_ty bitwise_or_raw(Parser *); -static expr_ty -bitwise_or_rule(Parser *p) -{ - D(p->level++); - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, bitwise_or_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - int _resmark = p->mark; - while (1) { - int tmpvar_1 = _PyPegen_update_memo(p, _mark, bitwise_or_type, _res); - if (tmpvar_1) { - D(p->level--); - return _res; - } - p->mark = _mark; - void *_raw = bitwise_or_raw(p); - if (_raw == NULL || p->mark <= _resmark) - break; - _resmark = p->mark; - _res = _raw; - } - p->mark = _resmark; - D(p->level--); - return _res; -} -static expr_ty -bitwise_or_raw(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // bitwise_or '|' bitwise_xor - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_or '|' bitwise_xor")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = bitwise_or_rule(p)) // bitwise_or - && - (_literal = _PyPegen_expect_token(p, 18)) // token='|' - && - (b = bitwise_xor_rule(p)) // bitwise_xor - ) - { - D(fprintf(stderr, "%*c+ bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_or '|' bitwise_xor")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BinOp ( a , BitOr , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_or '|' bitwise_xor")); - } - { // bitwise_xor - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> bitwise_or[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_xor")); - expr_ty bitwise_xor_var; - if ( - (bitwise_xor_var = bitwise_xor_rule(p)) // bitwise_xor - ) - { - D(fprintf(stderr, "%*c+ bitwise_or[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_xor")); - _res = bitwise_xor_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s bitwise_or[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_xor")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// Left-recursive -// bitwise_xor: bitwise_xor '^' bitwise_and | bitwise_and -static expr_ty bitwise_xor_raw(Parser *); -static expr_ty -bitwise_xor_rule(Parser *p) -{ - D(p->level++); - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, bitwise_xor_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - int _resmark = p->mark; - while (1) { - int tmpvar_2 = _PyPegen_update_memo(p, _mark, bitwise_xor_type, _res); - if (tmpvar_2) { - D(p->level--); - return _res; - } - p->mark = _mark; - void *_raw = bitwise_xor_raw(p); - if (_raw == NULL || p->mark <= _resmark) - break; - _resmark = p->mark; - _res = _raw; - } - p->mark = _resmark; - D(p->level--); - return _res; -} -static expr_ty -bitwise_xor_raw(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // bitwise_xor '^' bitwise_and - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> bitwise_xor[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_xor '^' bitwise_and")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = bitwise_xor_rule(p)) // bitwise_xor - && - (_literal = _PyPegen_expect_token(p, 32)) // token='^' - && - (b = bitwise_and_rule(p)) // bitwise_and - ) - { - D(fprintf(stderr, "%*c+ bitwise_xor[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_xor '^' bitwise_and")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BinOp ( a , BitXor , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s bitwise_xor[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_xor '^' bitwise_and")); - } - { // bitwise_and - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> bitwise_xor[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_and")); - expr_ty bitwise_and_var; - if ( - (bitwise_and_var = bitwise_and_rule(p)) // bitwise_and - ) - { - D(fprintf(stderr, "%*c+ bitwise_xor[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_and")); - _res = bitwise_and_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s bitwise_xor[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_and")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// Left-recursive -// bitwise_and: bitwise_and '&' shift_expr | shift_expr -static expr_ty bitwise_and_raw(Parser *); -static expr_ty -bitwise_and_rule(Parser *p) -{ - D(p->level++); - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, bitwise_and_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - int _resmark = p->mark; - while (1) { - int tmpvar_3 = _PyPegen_update_memo(p, _mark, bitwise_and_type, _res); - if (tmpvar_3) { - D(p->level--); - return _res; - } - p->mark = _mark; - void *_raw = bitwise_and_raw(p); - if (_raw == NULL || p->mark <= _resmark) - break; - _resmark = p->mark; - _res = _raw; - } - p->mark = _resmark; - D(p->level--); - return _res; -} -static expr_ty -bitwise_and_raw(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // bitwise_and '&' shift_expr - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> bitwise_and[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "bitwise_and '&' shift_expr")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = bitwise_and_rule(p)) // bitwise_and - && - (_literal = _PyPegen_expect_token(p, 19)) // token='&' - && - (b = shift_expr_rule(p)) // shift_expr - ) - { - D(fprintf(stderr, "%*c+ bitwise_and[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "bitwise_and '&' shift_expr")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BinOp ( a , BitAnd , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s bitwise_and[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "bitwise_and '&' shift_expr")); - } - { // shift_expr - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> bitwise_and[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "shift_expr")); - expr_ty shift_expr_var; - if ( - (shift_expr_var = shift_expr_rule(p)) // shift_expr - ) - { - D(fprintf(stderr, "%*c+ bitwise_and[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "shift_expr")); - _res = shift_expr_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s bitwise_and[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "shift_expr")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// Left-recursive -// shift_expr: shift_expr '<<' sum | shift_expr '>>' sum | sum -static expr_ty shift_expr_raw(Parser *); -static expr_ty -shift_expr_rule(Parser *p) -{ - D(p->level++); - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, shift_expr_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - int _resmark = p->mark; - while (1) { - int tmpvar_4 = _PyPegen_update_memo(p, _mark, shift_expr_type, _res); - if (tmpvar_4) { - D(p->level--); - return _res; - } - p->mark = _mark; - void *_raw = shift_expr_raw(p); - if (_raw == NULL || p->mark <= _resmark) - break; - _resmark = p->mark; - _res = _raw; - } - p->mark = _resmark; - D(p->level--); - return _res; -} -static expr_ty -shift_expr_raw(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // shift_expr '<<' sum - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> shift_expr[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "shift_expr '<<' sum")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = shift_expr_rule(p)) // shift_expr - && - (_literal = _PyPegen_expect_token(p, 33)) // token='<<' - && - (b = sum_rule(p)) // sum - ) - { - D(fprintf(stderr, "%*c+ shift_expr[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "shift_expr '<<' sum")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BinOp ( a , LShift , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s shift_expr[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "shift_expr '<<' sum")); - } - { // shift_expr '>>' sum - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> shift_expr[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "shift_expr '>>' sum")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = shift_expr_rule(p)) // shift_expr - && - (_literal = _PyPegen_expect_token(p, 34)) // token='>>' - && - (b = sum_rule(p)) // sum - ) - { - D(fprintf(stderr, "%*c+ shift_expr[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "shift_expr '>>' sum")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BinOp ( a , RShift , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s shift_expr[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "shift_expr '>>' sum")); - } - { // sum - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> shift_expr[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "sum")); - expr_ty sum_var; - if ( - (sum_var = sum_rule(p)) // sum - ) - { - D(fprintf(stderr, "%*c+ shift_expr[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "sum")); - _res = sum_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s shift_expr[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "sum")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// Left-recursive -// sum: sum '+' term | sum '-' term | term -static expr_ty sum_raw(Parser *); -static expr_ty -sum_rule(Parser *p) -{ - D(p->level++); - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, sum_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - int _resmark = p->mark; - while (1) { - int tmpvar_5 = _PyPegen_update_memo(p, _mark, sum_type, _res); - if (tmpvar_5) { - D(p->level--); - return _res; - } - p->mark = _mark; - void *_raw = sum_raw(p); - if (_raw == NULL || p->mark <= _resmark) - break; - _resmark = p->mark; - _res = _raw; - } - p->mark = _resmark; - D(p->level--); - return _res; -} -static expr_ty -sum_raw(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // sum '+' term - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> sum[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "sum '+' term")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = sum_rule(p)) // sum - && - (_literal = _PyPegen_expect_token(p, 14)) // token='+' - && - (b = term_rule(p)) // term - ) - { - D(fprintf(stderr, "%*c+ sum[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "sum '+' term")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BinOp ( a , Add , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s sum[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "sum '+' term")); - } - { // sum '-' term - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> sum[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "sum '-' term")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = sum_rule(p)) // sum - && - (_literal = _PyPegen_expect_token(p, 15)) // token='-' - && - (b = term_rule(p)) // term - ) - { - D(fprintf(stderr, "%*c+ sum[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "sum '-' term")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BinOp ( a , Sub , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s sum[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "sum '-' term")); - } - { // term - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> sum[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "term")); - expr_ty term_var; - if ( - (term_var = term_rule(p)) // term - ) - { - D(fprintf(stderr, "%*c+ sum[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "term")); - _res = term_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s sum[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "term")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// Left-recursive -// term: -// | term '*' factor -// | term '/' factor -// | term '//' factor -// | term '%' factor -// | term '@' factor -// | factor -static expr_ty term_raw(Parser *); -static expr_ty -term_rule(Parser *p) -{ - D(p->level++); - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, term_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - int _resmark = p->mark; - while (1) { - int tmpvar_6 = _PyPegen_update_memo(p, _mark, term_type, _res); - if (tmpvar_6) { - D(p->level--); - return _res; - } - p->mark = _mark; - void *_raw = term_raw(p); - if (_raw == NULL || p->mark <= _resmark) - break; - _resmark = p->mark; - _res = _raw; - } - p->mark = _resmark; - D(p->level--); - return _res; -} -static expr_ty -term_raw(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // term '*' factor - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> term[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "term '*' factor")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = term_rule(p)) // term - && - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (b = factor_rule(p)) // factor - ) - { - D(fprintf(stderr, "%*c+ term[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "term '*' factor")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BinOp ( a , Mult , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "term '*' factor")); - } - { // term '/' factor - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> term[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "term '/' factor")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = term_rule(p)) // term - && - (_literal = _PyPegen_expect_token(p, 17)) // token='/' - && - (b = factor_rule(p)) // factor - ) - { - D(fprintf(stderr, "%*c+ term[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "term '/' factor")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BinOp ( a , Div , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "term '/' factor")); - } - { // term '//' factor - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> term[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "term '//' factor")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = term_rule(p)) // term - && - (_literal = _PyPegen_expect_token(p, 47)) // token='//' - && - (b = factor_rule(p)) // factor - ) - { - D(fprintf(stderr, "%*c+ term[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "term '//' factor")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BinOp ( a , FloorDiv , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "term '//' factor")); - } - { // term '%' factor - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> term[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "term '%' factor")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = term_rule(p)) // term - && - (_literal = _PyPegen_expect_token(p, 24)) // token='%' - && - (b = factor_rule(p)) // factor - ) - { - D(fprintf(stderr, "%*c+ term[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "term '%' factor")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BinOp ( a , Mod , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "term '%' factor")); - } - { // term '@' factor - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> term[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "term '@' factor")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = term_rule(p)) // term - && - (_literal = _PyPegen_expect_token(p, 49)) // token='@' - && - (b = factor_rule(p)) // factor - ) - { - D(fprintf(stderr, "%*c+ term[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "term '@' factor")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = CHECK_VERSION ( 5 , "The '@' operator is" , _Py_BinOp ( a , MatMult , b , EXTRA ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "term '@' factor")); - } - { // factor - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> term[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "factor")); - expr_ty factor_var; - if ( - (factor_var = factor_rule(p)) // factor - ) - { - D(fprintf(stderr, "%*c+ term[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "factor")); - _res = factor_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "factor")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// factor: '+' factor | '-' factor | '~' factor | power -static expr_ty -factor_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, factor_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // '+' factor - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> factor[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'+' factor")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 14)) // token='+' - && - (a = factor_rule(p)) // factor - ) - { - D(fprintf(stderr, "%*c+ factor[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'+' factor")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_UnaryOp ( UAdd , a , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s factor[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'+' factor")); - } - { // '-' factor - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> factor[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'-' factor")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 15)) // token='-' - && - (a = factor_rule(p)) // factor - ) - { - D(fprintf(stderr, "%*c+ factor[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'-' factor")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_UnaryOp ( USub , a , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s factor[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'-' factor")); - } - { // '~' factor - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> factor[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'~' factor")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 31)) // token='~' - && - (a = factor_rule(p)) // factor - ) - { - D(fprintf(stderr, "%*c+ factor[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'~' factor")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_UnaryOp ( Invert , a , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s factor[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'~' factor")); - } - { // power - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> factor[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "power")); - expr_ty power_var; - if ( - (power_var = power_rule(p)) // power - ) - { - D(fprintf(stderr, "%*c+ factor[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "power")); - _res = power_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s factor[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "power")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, factor_type, _res); - D(p->level--); - return _res; -} - -// power: await_primary '**' factor | await_primary -static expr_ty -power_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // await_primary '**' factor - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> power[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "await_primary '**' factor")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = await_primary_rule(p)) // await_primary - && - (_literal = _PyPegen_expect_token(p, 35)) // token='**' - && - (b = factor_rule(p)) // factor - ) - { - D(fprintf(stderr, "%*c+ power[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "await_primary '**' factor")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_BinOp ( a , Pow , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s power[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "await_primary '**' factor")); - } - { // await_primary - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> power[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "await_primary")); - expr_ty await_primary_var; - if ( - (await_primary_var = await_primary_rule(p)) // await_primary - ) - { - D(fprintf(stderr, "%*c+ power[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "await_primary")); - _res = await_primary_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s power[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "await_primary")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// await_primary: AWAIT primary | primary -static expr_ty -await_primary_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, await_primary_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // AWAIT primary - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> await_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "AWAIT primary")); - expr_ty a; - Token * await_var; - if ( - (await_var = _PyPegen_expect_token(p, AWAIT)) // token='AWAIT' - && - (a = primary_rule(p)) // primary - ) - { - D(fprintf(stderr, "%*c+ await_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "AWAIT primary")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = CHECK_VERSION ( 5 , "Await expressions are" , _Py_Await ( a , EXTRA ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s await_primary[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "AWAIT primary")); - } - { // primary - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> await_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "primary")); - expr_ty primary_var; - if ( - (primary_var = primary_rule(p)) // primary - ) - { - D(fprintf(stderr, "%*c+ await_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "primary")); - _res = primary_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s await_primary[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "primary")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, await_primary_type, _res); - D(p->level--); - return _res; -} - -// Left-recursive -// primary: -// | primary '.' NAME -// | primary genexp -// | primary '(' arguments? ')' -// | primary '[' slices ']' -// | atom -static expr_ty primary_raw(Parser *); -static expr_ty -primary_rule(Parser *p) -{ - D(p->level++); - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, primary_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - int _resmark = p->mark; - while (1) { - int tmpvar_7 = _PyPegen_update_memo(p, _mark, primary_type, _res); - if (tmpvar_7) { - D(p->level--); - return _res; - } - p->mark = _mark; - void *_raw = primary_raw(p); - if (_raw == NULL || p->mark <= _resmark) - break; - _resmark = p->mark; - _res = _raw; - } - p->mark = _resmark; - D(p->level--); - return _res; -} -static expr_ty -primary_raw(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // primary '.' NAME - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "primary '.' NAME")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = primary_rule(p)) // primary - && - (_literal = _PyPegen_expect_token(p, 23)) // token='.' - && - (b = _PyPegen_name_token(p)) // NAME - ) - { - D(fprintf(stderr, "%*c+ primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "primary '.' NAME")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Attribute ( a , b -> v . Name . id , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s primary[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "primary '.' NAME")); - } - { // primary genexp - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "primary genexp")); - expr_ty a; - expr_ty b; - if ( - (a = primary_rule(p)) // primary - && - (b = genexp_rule(p)) // genexp - ) - { - D(fprintf(stderr, "%*c+ primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "primary genexp")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Call ( a , CHECK ( _PyPegen_singleton_seq ( p , b ) ) , NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s primary[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "primary genexp")); - } - { // primary '(' arguments? ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "primary '(' arguments? ')'")); - Token * _literal; - Token * _literal_1; - expr_ty a; - void *b; - if ( - (a = primary_rule(p)) // primary - && - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (b = arguments_rule(p), 1) // arguments? - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "primary '(' arguments? ')'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Call ( a , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s primary[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "primary '(' arguments? ')'")); - } - { // primary '[' slices ']' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "primary '[' slices ']'")); - Token * _literal; - Token * _literal_1; - expr_ty a; - expr_ty b; - if ( - (a = primary_rule(p)) // primary - && - (_literal = _PyPegen_expect_token(p, 9)) // token='[' - && - (b = slices_rule(p)) // slices - && - (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' - ) - { - D(fprintf(stderr, "%*c+ primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "primary '[' slices ']'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Subscript ( a , b , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s primary[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "primary '[' slices ']'")); - } - { // atom - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "atom")); - expr_ty atom_var; - if ( - (atom_var = atom_rule(p)) // atom - ) - { - D(fprintf(stderr, "%*c+ primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "atom")); - _res = atom_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s primary[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "atom")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// slices: slice !',' | ','.slice+ ','? -static expr_ty -slices_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // slice !',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> slices[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "slice !','")); - expr_ty a; - if ( - (a = slice_rule(p)) // slice - && - _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 12) // token=',' - ) - { - D(fprintf(stderr, "%*c+ slices[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "slice !','")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s slices[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "slice !','")); - } - { // ','.slice+ ','? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> slices[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.slice+ ','?")); - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - asdl_seq * a; - if ( - (a = _gather_93_rule(p)) // ','.slice+ - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - ) - { - D(fprintf(stderr, "%*c+ slices[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.slice+ ','?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Tuple ( a , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s slices[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.slice+ ','?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// slice: expression? ':' expression? [':' expression?] | expression -static expr_ty -slice_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // expression? ':' expression? [':' expression?] - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> slice[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression? ':' expression? [':' expression?]")); - Token * _literal; - void *a; - void *b; - void *c; - if ( - (a = expression_rule(p), 1) // expression? - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = expression_rule(p), 1) // expression? - && - (c = _tmp_95_rule(p), 1) // [':' expression?] - ) - { - D(fprintf(stderr, "%*c+ slice[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression? ':' expression? [':' expression?]")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Slice ( a , b , c , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s slice[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression? ':' expression? [':' expression?]")); - } - { // expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> slice[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression")); - expr_ty a; - if ( - (a = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ slice[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s slice[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// atom: -// | NAME -// | 'True' -// | 'False' -// | 'None' -// | '__new_parser__' -// | &STRING strings -// | NUMBER -// | &'(' (tuple | group | genexp) -// | &'[' (list | listcomp) -// | &'{' (dict | set | dictcomp | setcomp) -// | '...' -static expr_ty -atom_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // NAME - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME")); - expr_ty name_var; - if ( - (name_var = _PyPegen_name_token(p)) // NAME - ) - { - D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME")); - _res = name_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME")); - } - { // 'True' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'True'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 527)) // token='True' - ) - { - D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'True'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Constant ( Py_True , NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'True'")); - } - { // 'False' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'False'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 528)) // token='False' - ) - { - D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'False'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Constant ( Py_False , NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'False'")); - } - { // 'None' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'None'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 529)) // token='None' - ) - { - D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'None'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Constant ( Py_None , NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'None'")); - } - { // '__new_parser__' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'__new_parser__'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 530)) // token='__new_parser__' - ) - { - D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'__new_parser__'")); - _res = RAISE_SYNTAX_ERROR ( "You found it!" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'__new_parser__'")); - } - { // &STRING strings - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&STRING strings")); - expr_ty strings_var; - if ( - _PyPegen_lookahead(1, _PyPegen_string_token, p) - && - (strings_var = strings_rule(p)) // strings - ) - { - D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&STRING strings")); - _res = strings_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&STRING strings")); - } - { // NUMBER - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NUMBER")); - expr_ty number_var; - if ( - (number_var = _PyPegen_number_token(p)) // NUMBER - ) - { - D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NUMBER")); - _res = number_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NUMBER")); - } - { // &'(' (tuple | group | genexp) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'(' (tuple | group | genexp)")); - void *_tmp_96_var; - if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 7) // token='(' - && - (_tmp_96_var = _tmp_96_rule(p)) // tuple | group | genexp - ) - { - D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'(' (tuple | group | genexp)")); - _res = _tmp_96_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'(' (tuple | group | genexp)")); - } - { // &'[' (list | listcomp) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'[' (list | listcomp)")); - void *_tmp_97_var; - if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 9) // token='[' - && - (_tmp_97_var = _tmp_97_rule(p)) // list | listcomp - ) - { - D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'[' (list | listcomp)")); - _res = _tmp_97_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'[' (list | listcomp)")); - } - { // &'{' (dict | set | dictcomp | setcomp) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "&'{' (dict | set | dictcomp | setcomp)")); - void *_tmp_98_var; - if ( - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 25) // token='{' - && - (_tmp_98_var = _tmp_98_rule(p)) // dict | set | dictcomp | setcomp - ) - { - D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "&'{' (dict | set | dictcomp | setcomp)")); - _res = _tmp_98_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "&'{' (dict | set | dictcomp | setcomp)")); - } - { // '...' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'...'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 52)) // token='...' - ) - { - D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'...'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Constant ( Py_Ellipsis , NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'...'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// strings: STRING+ -static expr_ty -strings_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, strings_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - { // STRING+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> strings[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "STRING+")); - asdl_seq * a; - if ( - (a = _loop1_99_rule(p)) // STRING+ - ) - { - D(fprintf(stderr, "%*c+ strings[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "STRING+")); - _res = _PyPegen_concatenate_strings ( p , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s strings[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "STRING+")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, strings_type, _res); - D(p->level--); - return _res; -} - -// list: '[' star_named_expressions? ']' -static expr_ty -list_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // '[' star_named_expressions? ']' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> list[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'[' star_named_expressions? ']'")); - Token * _literal; - Token * _literal_1; - void *a; - if ( - (_literal = _PyPegen_expect_token(p, 9)) // token='[' - && - (a = star_named_expressions_rule(p), 1) // star_named_expressions? - && - (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' - ) - { - D(fprintf(stderr, "%*c+ list[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'[' star_named_expressions? ']'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_List ( a , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s list[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'[' star_named_expressions? ']'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// listcomp: '[' named_expression for_if_clauses ']' | invalid_comprehension -static expr_ty -listcomp_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // '[' named_expression for_if_clauses ']' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> listcomp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'[' named_expression for_if_clauses ']'")); - Token * _literal; - Token * _literal_1; - expr_ty a; - asdl_seq* b; - if ( - (_literal = _PyPegen_expect_token(p, 9)) // token='[' - && - (a = named_expression_rule(p)) // named_expression - && - (b = for_if_clauses_rule(p)) // for_if_clauses - && - (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' - ) - { - D(fprintf(stderr, "%*c+ listcomp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'[' named_expression for_if_clauses ']'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_ListComp ( a , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s listcomp[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'[' named_expression for_if_clauses ']'")); - } - { // invalid_comprehension - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> listcomp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_comprehension")); - void *invalid_comprehension_var; - if ( - (invalid_comprehension_var = invalid_comprehension_rule(p)) // invalid_comprehension - ) - { - D(fprintf(stderr, "%*c+ listcomp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_comprehension")); - _res = invalid_comprehension_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s listcomp[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_comprehension")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// tuple: '(' [star_named_expression ',' star_named_expressions?] ')' -static expr_ty -tuple_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // '(' [star_named_expression ',' star_named_expressions?] ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> tuple[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' [star_named_expression ',' star_named_expressions?] ')'")); - Token * _literal; - Token * _literal_1; - void *a; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (a = _tmp_100_rule(p), 1) // [star_named_expression ',' star_named_expressions?] - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ tuple[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' [star_named_expression ',' star_named_expressions?] ')'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Tuple ( a , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s tuple[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' [star_named_expression ',' star_named_expressions?] ')'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// group: '(' (yield_expr | named_expression) ')' -static expr_ty -group_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - { // '(' (yield_expr | named_expression) ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> group[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' (yield_expr | named_expression) ')'")); - Token * _literal; - Token * _literal_1; - void *a; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (a = _tmp_101_rule(p)) // yield_expr | named_expression - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ group[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' (yield_expr | named_expression) ')'")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s group[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' (yield_expr | named_expression) ')'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// genexp: '(' expression for_if_clauses ')' | invalid_comprehension -static expr_ty -genexp_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // '(' expression for_if_clauses ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> genexp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' expression for_if_clauses ')'")); - Token * _literal; - Token * _literal_1; - expr_ty a; - asdl_seq* b; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (a = expression_rule(p)) // expression - && - (b = for_if_clauses_rule(p)) // for_if_clauses - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ genexp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' expression for_if_clauses ')'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_GeneratorExp ( a , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s genexp[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' expression for_if_clauses ')'")); - } - { // invalid_comprehension - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> genexp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_comprehension")); - void *invalid_comprehension_var; - if ( - (invalid_comprehension_var = invalid_comprehension_rule(p)) // invalid_comprehension - ) - { - D(fprintf(stderr, "%*c+ genexp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_comprehension")); - _res = invalid_comprehension_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s genexp[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_comprehension")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// set: '{' expressions_list '}' -static expr_ty -set_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // '{' expressions_list '}' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> set[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'{' expressions_list '}'")); - Token * _literal; - Token * _literal_1; - asdl_seq* a; - if ( - (_literal = _PyPegen_expect_token(p, 25)) // token='{' - && - (a = expressions_list_rule(p)) // expressions_list - && - (_literal_1 = _PyPegen_expect_token(p, 26)) // token='}' - ) - { - D(fprintf(stderr, "%*c+ set[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'{' expressions_list '}'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Set ( a , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s set[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'{' expressions_list '}'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// setcomp: '{' expression for_if_clauses '}' | invalid_comprehension -static expr_ty -setcomp_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // '{' expression for_if_clauses '}' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> setcomp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'{' expression for_if_clauses '}'")); - Token * _literal; - Token * _literal_1; - expr_ty a; - asdl_seq* b; - if ( - (_literal = _PyPegen_expect_token(p, 25)) // token='{' - && - (a = expression_rule(p)) // expression - && - (b = for_if_clauses_rule(p)) // for_if_clauses - && - (_literal_1 = _PyPegen_expect_token(p, 26)) // token='}' - ) - { - D(fprintf(stderr, "%*c+ setcomp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'{' expression for_if_clauses '}'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_SetComp ( a , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s setcomp[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'{' expression for_if_clauses '}'")); - } - { // invalid_comprehension - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> setcomp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_comprehension")); - void *invalid_comprehension_var; - if ( - (invalid_comprehension_var = invalid_comprehension_rule(p)) // invalid_comprehension - ) - { - D(fprintf(stderr, "%*c+ setcomp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_comprehension")); - _res = invalid_comprehension_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s setcomp[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_comprehension")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// dict: '{' double_starred_kvpairs? '}' -static expr_ty -dict_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // '{' double_starred_kvpairs? '}' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> dict[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'{' double_starred_kvpairs? '}'")); - Token * _literal; - Token * _literal_1; - void *a; - if ( - (_literal = _PyPegen_expect_token(p, 25)) // token='{' - && - (a = double_starred_kvpairs_rule(p), 1) // double_starred_kvpairs? - && - (_literal_1 = _PyPegen_expect_token(p, 26)) // token='}' - ) - { - D(fprintf(stderr, "%*c+ dict[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'{' double_starred_kvpairs? '}'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Dict ( CHECK ( _PyPegen_get_keys ( p , a ) ) , CHECK ( _PyPegen_get_values ( p , a ) ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s dict[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'{' double_starred_kvpairs? '}'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// dictcomp: '{' kvpair for_if_clauses '}' | invalid_dict_comprehension -static expr_ty -dictcomp_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // '{' kvpair for_if_clauses '}' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> dictcomp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'{' kvpair for_if_clauses '}'")); - Token * _literal; - Token * _literal_1; - KeyValuePair* a; - asdl_seq* b; - if ( - (_literal = _PyPegen_expect_token(p, 25)) // token='{' - && - (a = kvpair_rule(p)) // kvpair - && - (b = for_if_clauses_rule(p)) // for_if_clauses - && - (_literal_1 = _PyPegen_expect_token(p, 26)) // token='}' - ) - { - D(fprintf(stderr, "%*c+ dictcomp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'{' kvpair for_if_clauses '}'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_DictComp ( a -> key , a -> value , b , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s dictcomp[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'{' kvpair for_if_clauses '}'")); - } - { // invalid_dict_comprehension - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> dictcomp[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_dict_comprehension")); - void *invalid_dict_comprehension_var; - if ( - (invalid_dict_comprehension_var = invalid_dict_comprehension_rule(p)) // invalid_dict_comprehension - ) - { - D(fprintf(stderr, "%*c+ dictcomp[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_dict_comprehension")); - _res = invalid_dict_comprehension_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s dictcomp[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_dict_comprehension")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// double_starred_kvpairs: ','.double_starred_kvpair+ ','? -static asdl_seq* -double_starred_kvpairs_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // ','.double_starred_kvpair+ ','? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> double_starred_kvpairs[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.double_starred_kvpair+ ','?")); - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - asdl_seq * a; - if ( - (a = _gather_102_rule(p)) // ','.double_starred_kvpair+ - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - ) - { - D(fprintf(stderr, "%*c+ double_starred_kvpairs[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.double_starred_kvpair+ ','?")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s double_starred_kvpairs[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.double_starred_kvpair+ ','?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// double_starred_kvpair: '**' bitwise_or | kvpair -static KeyValuePair* -double_starred_kvpair_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - KeyValuePair* _res = NULL; - int _mark = p->mark; - { // '**' bitwise_or - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> double_starred_kvpair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**' bitwise_or")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 35)) // token='**' - && - (a = bitwise_or_rule(p)) // bitwise_or - ) - { - D(fprintf(stderr, "%*c+ double_starred_kvpair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**' bitwise_or")); - _res = _PyPegen_key_value_pair ( p , NULL , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s double_starred_kvpair[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**' bitwise_or")); - } - { // kvpair - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> double_starred_kvpair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kvpair")); - KeyValuePair* kvpair_var; - if ( - (kvpair_var = kvpair_rule(p)) // kvpair - ) - { - D(fprintf(stderr, "%*c+ double_starred_kvpair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kvpair")); - _res = kvpair_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s double_starred_kvpair[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kvpair")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// kvpair: expression ':' expression -static KeyValuePair* -kvpair_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - KeyValuePair* _res = NULL; - int _mark = p->mark; - { // expression ':' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> kvpair[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression ':' expression")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = expression_rule(p)) // expression - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (b = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ kvpair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression ':' expression")); - _res = _PyPegen_key_value_pair ( p , a , b ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s kvpair[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression ':' expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// for_if_clauses: for_if_clause+ -static asdl_seq* -for_if_clauses_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // for_if_clause+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> for_if_clauses[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "for_if_clause+")); - asdl_seq * _loop1_104_var; - if ( - (_loop1_104_var = _loop1_104_rule(p)) // for_if_clause+ - ) - { - D(fprintf(stderr, "%*c+ for_if_clauses[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "for_if_clause+")); - _res = _loop1_104_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s for_if_clauses[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "for_if_clause+")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// for_if_clause: -// | ASYNC 'for' star_targets 'in' disjunction (('if' disjunction))* -// | 'for' star_targets 'in' disjunction (('if' disjunction))* -static comprehension_ty -for_if_clause_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - comprehension_ty _res = NULL; - int _mark = p->mark; - { // ASYNC 'for' star_targets 'in' disjunction (('if' disjunction))* - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> for_if_clause[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC 'for' star_targets 'in' disjunction (('if' disjunction))*")); - Token * _keyword; - Token * _keyword_1; - expr_ty a; - Token * async_var; - expr_ty b; - asdl_seq * c; - if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' - && - (_keyword = _PyPegen_expect_token(p, 517)) // token='for' - && - (a = star_targets_rule(p)) // star_targets - && - (_keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' - && - (b = disjunction_rule(p)) // disjunction - && - (c = _loop0_105_rule(p)) // (('if' disjunction))* - ) - { - D(fprintf(stderr, "%*c+ for_if_clause[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC 'for' star_targets 'in' disjunction (('if' disjunction))*")); - _res = CHECK_VERSION ( 6 , "Async comprehensions are" , _Py_comprehension ( a , b , c , 1 , p -> arena ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s for_if_clause[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC 'for' star_targets 'in' disjunction (('if' disjunction))*")); - } - { // 'for' star_targets 'in' disjunction (('if' disjunction))* - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> for_if_clause[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'for' star_targets 'in' disjunction (('if' disjunction))*")); - Token * _keyword; - Token * _keyword_1; - expr_ty a; - expr_ty b; - asdl_seq * c; - if ( - (_keyword = _PyPegen_expect_token(p, 517)) // token='for' - && - (a = star_targets_rule(p)) // star_targets - && - (_keyword_1 = _PyPegen_expect_token(p, 518)) // token='in' - && - (b = disjunction_rule(p)) // disjunction - && - (c = _loop0_106_rule(p)) // (('if' disjunction))* - ) - { - D(fprintf(stderr, "%*c+ for_if_clause[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'for' star_targets 'in' disjunction (('if' disjunction))*")); - _res = _Py_comprehension ( a , b , c , 0 , p -> arena ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s for_if_clause[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'for' star_targets 'in' disjunction (('if' disjunction))*")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// yield_expr: 'yield' 'from' expression | 'yield' star_expressions? -static expr_ty -yield_expr_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // 'yield' 'from' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> yield_expr[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'yield' 'from' expression")); - Token * _keyword; - Token * _keyword_1; - expr_ty a; - if ( - (_keyword = _PyPegen_expect_token(p, 504)) // token='yield' - && - (_keyword_1 = _PyPegen_expect_token(p, 514)) // token='from' - && - (a = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ yield_expr[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'yield' 'from' expression")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_YieldFrom ( a , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s yield_expr[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'yield' 'from' expression")); - } - { // 'yield' star_expressions? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> yield_expr[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'yield' star_expressions?")); - Token * _keyword; - void *a; - if ( - (_keyword = _PyPegen_expect_token(p, 504)) // token='yield' - && - (a = star_expressions_rule(p), 1) // star_expressions? - ) - { - D(fprintf(stderr, "%*c+ yield_expr[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'yield' star_expressions?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Yield ( a , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s yield_expr[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'yield' star_expressions?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// arguments: args ','? &')' | incorrect_arguments -static expr_ty -arguments_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, arguments_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - { // args ','? &')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "args ','? &')'")); - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - expr_ty a; - if ( - (a = args_rule(p)) // args - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - && - _PyPegen_lookahead_with_int(1, _PyPegen_expect_token, p, 8) // token=')' - ) - { - D(fprintf(stderr, "%*c+ arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "args ','? &')'")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s arguments[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "args ','? &')'")); - } - { // incorrect_arguments - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "incorrect_arguments")); - void *incorrect_arguments_var; - if ( - (incorrect_arguments_var = incorrect_arguments_rule(p)) // incorrect_arguments - ) - { - D(fprintf(stderr, "%*c+ arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "incorrect_arguments")); - _res = incorrect_arguments_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s arguments[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "incorrect_arguments")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, arguments_type, _res); - D(p->level--); - return _res; -} - -// args: starred_expression [',' args] | kwargs | named_expression [',' args] -static expr_ty -args_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // starred_expression [',' args] - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> args[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "starred_expression [',' args]")); - expr_ty a; - void *b; - if ( - (a = starred_expression_rule(p)) // starred_expression - && - (b = _tmp_107_rule(p), 1) // [',' args] - ) - { - D(fprintf(stderr, "%*c+ args[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "starred_expression [',' args]")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Call ( _PyPegen_dummy_name ( p ) , ( b ) ? CHECK ( _PyPegen_seq_insert_in_front ( p , a , ( ( expr_ty ) b ) -> v . Call . args ) ) : CHECK ( _PyPegen_singleton_seq ( p , a ) ) , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s args[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "starred_expression [',' args]")); - } - { // kwargs - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> args[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kwargs")); - asdl_seq* a; - if ( - (a = kwargs_rule(p)) // kwargs - ) - { - D(fprintf(stderr, "%*c+ args[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kwargs")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Call ( _PyPegen_dummy_name ( p ) , CHECK_NULL_ALLOWED ( _PyPegen_seq_extract_starred_exprs ( p , a ) ) , CHECK_NULL_ALLOWED ( _PyPegen_seq_delete_starred_exprs ( p , a ) ) , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s args[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kwargs")); - } - { // named_expression [',' args] - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> args[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "named_expression [',' args]")); - expr_ty a; - void *b; - if ( - (a = named_expression_rule(p)) // named_expression - && - (b = _tmp_108_rule(p), 1) // [',' args] - ) - { - D(fprintf(stderr, "%*c+ args[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "named_expression [',' args]")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Call ( _PyPegen_dummy_name ( p ) , ( b ) ? CHECK ( _PyPegen_seq_insert_in_front ( p , a , ( ( expr_ty ) b ) -> v . Call . args ) ) : CHECK ( _PyPegen_singleton_seq ( p , a ) ) , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s args[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "named_expression [',' args]")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// kwargs: -// | ','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+ -// | ','.kwarg_or_starred+ -// | ','.kwarg_or_double_starred+ -static asdl_seq* -kwargs_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // ','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> kwargs[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+")); - Token * _literal; - asdl_seq * a; - asdl_seq * b; - if ( - (a = _gather_109_rule(p)) // ','.kwarg_or_starred+ - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (b = _gather_111_rule(p)) // ','.kwarg_or_double_starred+ - ) - { - D(fprintf(stderr, "%*c+ kwargs[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+")); - _res = _PyPegen_join_sequences ( p , a , b ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s kwargs[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+")); - } - { // ','.kwarg_or_starred+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> kwargs[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.kwarg_or_starred+")); - asdl_seq * _gather_113_var; - if ( - (_gather_113_var = _gather_113_rule(p)) // ','.kwarg_or_starred+ - ) - { - D(fprintf(stderr, "%*c+ kwargs[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.kwarg_or_starred+")); - _res = _gather_113_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s kwargs[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.kwarg_or_starred+")); - } - { // ','.kwarg_or_double_starred+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> kwargs[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.kwarg_or_double_starred+")); - asdl_seq * _gather_115_var; - if ( - (_gather_115_var = _gather_115_rule(p)) // ','.kwarg_or_double_starred+ - ) - { - D(fprintf(stderr, "%*c+ kwargs[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.kwarg_or_double_starred+")); - _res = _gather_115_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s kwargs[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.kwarg_or_double_starred+")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// starred_expression: '*' expression -static expr_ty -starred_expression_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // '*' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> starred_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' expression")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (a = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ starred_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' expression")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Starred ( a , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s starred_expression[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// kwarg_or_starred: NAME '=' expression | starred_expression | invalid_kwarg -static KeywordOrStarred* -kwarg_or_starred_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - KeywordOrStarred* _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // NAME '=' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> kwarg_or_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME '=' expression")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = _PyPegen_name_token(p)) // NAME - && - (_literal = _PyPegen_expect_token(p, 22)) // token='=' - && - (b = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ kwarg_or_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME '=' expression")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( a -> v . Name . id , b , EXTRA ) ) , 1 ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s kwarg_or_starred[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME '=' expression")); - } - { // starred_expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> kwarg_or_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "starred_expression")); - expr_ty a; - if ( - (a = starred_expression_rule(p)) // starred_expression - ) - { - D(fprintf(stderr, "%*c+ kwarg_or_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "starred_expression")); - _res = _PyPegen_keyword_or_starred ( p , a , 0 ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s kwarg_or_starred[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "starred_expression")); - } - { // invalid_kwarg - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> kwarg_or_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_kwarg")); - void *invalid_kwarg_var; - if ( - (invalid_kwarg_var = invalid_kwarg_rule(p)) // invalid_kwarg - ) - { - D(fprintf(stderr, "%*c+ kwarg_or_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_kwarg")); - _res = invalid_kwarg_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s kwarg_or_starred[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_kwarg")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// kwarg_or_double_starred: NAME '=' expression | '**' expression | invalid_kwarg -static KeywordOrStarred* -kwarg_or_double_starred_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - KeywordOrStarred* _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // NAME '=' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> kwarg_or_double_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME '=' expression")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = _PyPegen_name_token(p)) // NAME - && - (_literal = _PyPegen_expect_token(p, 22)) // token='=' - && - (b = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ kwarg_or_double_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME '=' expression")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( a -> v . Name . id , b , EXTRA ) ) , 1 ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s kwarg_or_double_starred[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME '=' expression")); - } - { // '**' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> kwarg_or_double_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**' expression")); - Token * _literal; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 35)) // token='**' - && - (a = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ kwarg_or_double_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**' expression")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _PyPegen_keyword_or_starred ( p , CHECK ( _Py_keyword ( NULL , a , EXTRA ) ) , 1 ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s kwarg_or_double_starred[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**' expression")); - } - { // invalid_kwarg - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> kwarg_or_double_starred[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_kwarg")); - void *invalid_kwarg_var; - if ( - (invalid_kwarg_var = invalid_kwarg_rule(p)) // invalid_kwarg - ) - { - D(fprintf(stderr, "%*c+ kwarg_or_double_starred[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_kwarg")); - _res = invalid_kwarg_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s kwarg_or_double_starred[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_kwarg")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// star_targets: star_target !',' | star_target ((',' star_target))* ','? -static expr_ty -star_targets_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // star_target !',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_target !','")); - expr_ty a; - if ( - (a = star_target_rule(p)) // star_target - && - _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 12) // token=',' - ) - { - D(fprintf(stderr, "%*c+ star_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_target !','")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_targets[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_target !','")); - } - { // star_target ((',' star_target))* ','? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_target ((',' star_target))* ','?")); - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - expr_ty a; - asdl_seq * b; - if ( - (a = star_target_rule(p)) // star_target - && - (b = _loop0_117_rule(p)) // ((',' star_target))* - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - ) - { - D(fprintf(stderr, "%*c+ star_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_target ((',' star_target))* ','?")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Tuple ( CHECK ( _PyPegen_seq_insert_in_front ( p , a , b ) ) , Store , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_targets[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_target ((',' star_target))* ','?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// star_targets_seq: ','.star_target+ ','? -static asdl_seq* -star_targets_seq_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // ','.star_target+ ','? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_targets_seq[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.star_target+ ','?")); - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - asdl_seq * a; - if ( - (a = _gather_118_rule(p)) // ','.star_target+ - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - ) - { - D(fprintf(stderr, "%*c+ star_targets_seq[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.star_target+ ','?")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_targets_seq[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.star_target+ ','?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// star_target: -// | '*' (!'*' star_target) -// | t_primary '.' NAME !t_lookahead -// | t_primary '[' slices ']' !t_lookahead -// | star_atom -static expr_ty -star_target_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, star_target_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // '*' (!'*' star_target) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' (!'*' star_target)")); - Token * _literal; - void *a; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (a = _tmp_120_rule(p)) // !'*' star_target - ) - { - D(fprintf(stderr, "%*c+ star_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' (!'*' star_target)")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Starred ( CHECK ( _PyPegen_set_expr_context ( p , a , Store ) ) , Store , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' (!'*' star_target)")); - } - { // t_primary '.' NAME !t_lookahead - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = t_primary_rule(p)) // t_primary - && - (_literal = _PyPegen_expect_token(p, 23)) // token='.' - && - (b = _PyPegen_name_token(p)) // NAME - && - _PyPegen_lookahead(0, t_lookahead_rule, p) - ) - { - D(fprintf(stderr, "%*c+ star_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Attribute ( a , b -> v . Name . id , Store , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '.' NAME !t_lookahead")); - } - { // t_primary '[' slices ']' !t_lookahead - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); - Token * _literal; - Token * _literal_1; - expr_ty a; - expr_ty b; - if ( - (a = t_primary_rule(p)) // t_primary - && - (_literal = _PyPegen_expect_token(p, 9)) // token='[' - && - (b = slices_rule(p)) // slices - && - (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' - && - _PyPegen_lookahead(0, t_lookahead_rule, p) - ) - { - D(fprintf(stderr, "%*c+ star_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Subscript ( a , b , Store , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); - } - { // star_atom - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_atom")); - expr_ty star_atom_var; - if ( - (star_atom_var = star_atom_rule(p)) // star_atom - ) - { - D(fprintf(stderr, "%*c+ star_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_atom")); - _res = star_atom_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_atom")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, star_target_type, _res); - D(p->level--); - return _res; -} - -// star_atom: -// | NAME -// | '(' star_target ')' -// | '(' star_targets_seq? ')' -// | '[' star_targets_seq? ']' -static expr_ty -star_atom_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // NAME - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME")); - expr_ty a; - if ( - (a = _PyPegen_name_token(p)) // NAME - ) - { - D(fprintf(stderr, "%*c+ star_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME")); - _res = _PyPegen_set_expr_context ( p , a , Store ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME")); - } - { // '(' star_target ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' star_target ')'")); - Token * _literal; - Token * _literal_1; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (a = star_target_rule(p)) // star_target - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ star_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' star_target ')'")); - _res = _PyPegen_set_expr_context ( p , a , Store ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' star_target ')'")); - } - { // '(' star_targets_seq? ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' star_targets_seq? ')'")); - Token * _literal; - Token * _literal_1; - void *a; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (a = star_targets_seq_rule(p), 1) // star_targets_seq? - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ star_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' star_targets_seq? ')'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Tuple ( a , Store , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' star_targets_seq? ')'")); - } - { // '[' star_targets_seq? ']' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> star_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'[' star_targets_seq? ']'")); - Token * _literal; - Token * _literal_1; - void *a; - if ( - (_literal = _PyPegen_expect_token(p, 9)) // token='[' - && - (a = star_targets_seq_rule(p), 1) // star_targets_seq? - && - (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' - ) - { - D(fprintf(stderr, "%*c+ star_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'[' star_targets_seq? ']'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_List ( a , Store , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s star_atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'[' star_targets_seq? ']'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// single_target: single_subscript_attribute_target | NAME | '(' single_target ')' -static expr_ty -single_target_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - { // single_subscript_attribute_target - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> single_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "single_subscript_attribute_target")); - expr_ty single_subscript_attribute_target_var; - if ( - (single_subscript_attribute_target_var = single_subscript_attribute_target_rule(p)) // single_subscript_attribute_target - ) - { - D(fprintf(stderr, "%*c+ single_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "single_subscript_attribute_target")); - _res = single_subscript_attribute_target_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s single_target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "single_subscript_attribute_target")); - } - { // NAME - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> single_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME")); - expr_ty a; - if ( - (a = _PyPegen_name_token(p)) // NAME - ) - { - D(fprintf(stderr, "%*c+ single_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME")); - _res = _PyPegen_set_expr_context ( p , a , Store ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s single_target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME")); - } - { // '(' single_target ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> single_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' single_target ')'")); - Token * _literal; - Token * _literal_1; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (a = single_target_rule(p)) // single_target - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ single_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' single_target ')'")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s single_target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' single_target ')'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// single_subscript_attribute_target: -// | t_primary '.' NAME !t_lookahead -// | t_primary '[' slices ']' !t_lookahead -static expr_ty -single_subscript_attribute_target_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // t_primary '.' NAME !t_lookahead - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> single_subscript_attribute_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = t_primary_rule(p)) // t_primary - && - (_literal = _PyPegen_expect_token(p, 23)) // token='.' - && - (b = _PyPegen_name_token(p)) // NAME - && - _PyPegen_lookahead(0, t_lookahead_rule, p) - ) - { - D(fprintf(stderr, "%*c+ single_subscript_attribute_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Attribute ( a , b -> v . Name . id , Store , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s single_subscript_attribute_target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '.' NAME !t_lookahead")); - } - { // t_primary '[' slices ']' !t_lookahead - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> single_subscript_attribute_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); - Token * _literal; - Token * _literal_1; - expr_ty a; - expr_ty b; - if ( - (a = t_primary_rule(p)) // t_primary - && - (_literal = _PyPegen_expect_token(p, 9)) // token='[' - && - (b = slices_rule(p)) // slices - && - (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' - && - _PyPegen_lookahead(0, t_lookahead_rule, p) - ) - { - D(fprintf(stderr, "%*c+ single_subscript_attribute_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Subscript ( a , b , Store , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s single_subscript_attribute_target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// del_targets: ','.del_target+ ','? -static asdl_seq* -del_targets_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // ','.del_target+ ','? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.del_target+ ','?")); - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - asdl_seq * a; - if ( - (a = _gather_121_rule(p)) // ','.del_target+ - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - ) - { - D(fprintf(stderr, "%*c+ del_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.del_target+ ','?")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_targets[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.del_target+ ','?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// del_target: -// | t_primary '.' NAME &del_target_end -// | t_primary '[' slices ']' &del_target_end -// | del_t_atom -static expr_ty -del_target_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, del_target_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // t_primary '.' NAME &del_target_end - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME &del_target_end")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = t_primary_rule(p)) // t_primary - && - (_literal = _PyPegen_expect_token(p, 23)) // token='.' - && - (b = _PyPegen_name_token(p)) // NAME - && - _PyPegen_lookahead(1, del_target_end_rule, p) - ) - { - D(fprintf(stderr, "%*c+ del_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME &del_target_end")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Attribute ( a , b -> v . Name . id , Del , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '.' NAME &del_target_end")); - } - { // t_primary '[' slices ']' &del_target_end - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' &del_target_end")); - Token * _literal; - Token * _literal_1; - expr_ty a; - expr_ty b; - if ( - (a = t_primary_rule(p)) // t_primary - && - (_literal = _PyPegen_expect_token(p, 9)) // token='[' - && - (b = slices_rule(p)) // slices - && - (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' - && - _PyPegen_lookahead(1, del_target_end_rule, p) - ) - { - D(fprintf(stderr, "%*c+ del_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' &del_target_end")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Subscript ( a , b , Del , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '[' slices ']' &del_target_end")); - } - { // del_t_atom - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "del_t_atom")); - expr_ty del_t_atom_var; - if ( - (del_t_atom_var = del_t_atom_rule(p)) // del_t_atom - ) - { - D(fprintf(stderr, "%*c+ del_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "del_t_atom")); - _res = del_t_atom_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "del_t_atom")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, del_target_type, _res); - D(p->level--); - return _res; -} - -// del_t_atom: -// | NAME &del_target_end -// | '(' del_target ')' -// | '(' del_targets? ')' -// | '[' del_targets? ']' -// | invalid_del_target -static expr_ty -del_t_atom_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // NAME &del_target_end - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME &del_target_end")); - expr_ty a; - if ( - (a = _PyPegen_name_token(p)) // NAME - && - _PyPegen_lookahead(1, del_target_end_rule, p) - ) - { - D(fprintf(stderr, "%*c+ del_t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME &del_target_end")); - _res = _PyPegen_set_expr_context ( p , a , Del ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_t_atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME &del_target_end")); - } - { // '(' del_target ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' del_target ')'")); - Token * _literal; - Token * _literal_1; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (a = del_target_rule(p)) // del_target - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ del_t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' del_target ')'")); - _res = _PyPegen_set_expr_context ( p , a , Del ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_t_atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' del_target ')'")); - } - { // '(' del_targets? ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' del_targets? ')'")); - Token * _literal; - Token * _literal_1; - void *a; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (a = del_targets_rule(p), 1) // del_targets? - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ del_t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' del_targets? ')'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Tuple ( a , Del , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_t_atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' del_targets? ')'")); - } - { // '[' del_targets? ']' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'[' del_targets? ']'")); - Token * _literal; - Token * _literal_1; - void *a; - if ( - (_literal = _PyPegen_expect_token(p, 9)) // token='[' - && - (a = del_targets_rule(p), 1) // del_targets? - && - (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' - ) - { - D(fprintf(stderr, "%*c+ del_t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'[' del_targets? ']'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_List ( a , Del , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_t_atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'[' del_targets? ']'")); - } - { // invalid_del_target - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_del_target")); - void *invalid_del_target_var; - if ( - (invalid_del_target_var = invalid_del_target_rule(p)) // invalid_del_target - ) - { - D(fprintf(stderr, "%*c+ del_t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_del_target")); - _res = invalid_del_target_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_t_atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_del_target")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// del_target_end: ')' | ']' | ',' | ';' | NEWLINE -static void * -del_target_end_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_target_end[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "')'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ del_target_end[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "')'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_target_end[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "')'")); - } - { // ']' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_target_end[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "']'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 10)) // token=']' - ) - { - D(fprintf(stderr, "%*c+ del_target_end[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "']'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_target_end[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "']'")); - } - { // ',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_target_end[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - ) - { - D(fprintf(stderr, "%*c+ del_target_end[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_target_end[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','")); - } - { // ';' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_target_end[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "';'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 13)) // token=';' - ) - { - D(fprintf(stderr, "%*c+ del_target_end[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "';'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_target_end[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "';'")); - } - { // NEWLINE - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> del_target_end[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE")); - Token * newline_var; - if ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - ) - { - D(fprintf(stderr, "%*c+ del_target_end[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NEWLINE")); - _res = newline_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s del_target_end[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// targets: ','.target+ ','? -static asdl_seq* -targets_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq* _res = NULL; - int _mark = p->mark; - { // ','.target+ ','? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "','.target+ ','?")); - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - asdl_seq * a; - if ( - (a = _gather_123_rule(p)) // ','.target+ - && - (_opt_var = _PyPegen_expect_token(p, 12), 1) // ','? - ) - { - D(fprintf(stderr, "%*c+ targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "','.target+ ','?")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s targets[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "','.target+ ','?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// target: -// | t_primary '.' NAME !t_lookahead -// | t_primary '[' slices ']' !t_lookahead -// | t_atom -static expr_ty -target_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, target_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // t_primary '.' NAME !t_lookahead - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = t_primary_rule(p)) // t_primary - && - (_literal = _PyPegen_expect_token(p, 23)) // token='.' - && - (b = _PyPegen_name_token(p)) // NAME - && - _PyPegen_lookahead(0, t_lookahead_rule, p) - ) - { - D(fprintf(stderr, "%*c+ target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME !t_lookahead")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Attribute ( a , b -> v . Name . id , Store , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '.' NAME !t_lookahead")); - } - { // t_primary '[' slices ']' !t_lookahead - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); - Token * _literal; - Token * _literal_1; - expr_ty a; - expr_ty b; - if ( - (a = t_primary_rule(p)) // t_primary - && - (_literal = _PyPegen_expect_token(p, 9)) // token='[' - && - (b = slices_rule(p)) // slices - && - (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' - && - _PyPegen_lookahead(0, t_lookahead_rule, p) - ) - { - D(fprintf(stderr, "%*c+ target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Subscript ( a , b , Store , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '[' slices ']' !t_lookahead")); - } - { // t_atom - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_atom")); - expr_ty t_atom_var; - if ( - (t_atom_var = t_atom_rule(p)) // t_atom - ) - { - D(fprintf(stderr, "%*c+ target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_atom")); - _res = t_atom_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_atom")); - } - _res = NULL; - done: - _PyPegen_insert_memo(p, _mark, target_type, _res); - D(p->level--); - return _res; -} - -// Left-recursive -// t_primary: -// | t_primary '.' NAME &t_lookahead -// | t_primary '[' slices ']' &t_lookahead -// | t_primary genexp &t_lookahead -// | t_primary '(' arguments? ')' &t_lookahead -// | atom &t_lookahead -static expr_ty t_primary_raw(Parser *); -static expr_ty -t_primary_rule(Parser *p) -{ - D(p->level++); - expr_ty _res = NULL; - if (_PyPegen_is_memoized(p, t_primary_type, &_res)) { - D(p->level--); - return _res; - } - int _mark = p->mark; - int _resmark = p->mark; - while (1) { - int tmpvar_8 = _PyPegen_update_memo(p, _mark, t_primary_type, _res); - if (tmpvar_8) { - D(p->level--); - return _res; - } - p->mark = _mark; - void *_raw = t_primary_raw(p); - if (_raw == NULL || p->mark <= _resmark) - break; - _resmark = p->mark; - _res = _raw; - } - p->mark = _resmark; - D(p->level--); - return _res; -} -static expr_ty -t_primary_raw(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // t_primary '.' NAME &t_lookahead - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> t_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME &t_lookahead")); - Token * _literal; - expr_ty a; - expr_ty b; - if ( - (a = t_primary_rule(p)) // t_primary - && - (_literal = _PyPegen_expect_token(p, 23)) // token='.' - && - (b = _PyPegen_name_token(p)) // NAME - && - _PyPegen_lookahead(1, t_lookahead_rule, p) - ) - { - D(fprintf(stderr, "%*c+ t_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '.' NAME &t_lookahead")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Attribute ( a , b -> v . Name . id , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s t_primary[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '.' NAME &t_lookahead")); - } - { // t_primary '[' slices ']' &t_lookahead - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> t_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' &t_lookahead")); - Token * _literal; - Token * _literal_1; - expr_ty a; - expr_ty b; - if ( - (a = t_primary_rule(p)) // t_primary - && - (_literal = _PyPegen_expect_token(p, 9)) // token='[' - && - (b = slices_rule(p)) // slices - && - (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' - && - _PyPegen_lookahead(1, t_lookahead_rule, p) - ) - { - D(fprintf(stderr, "%*c+ t_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '[' slices ']' &t_lookahead")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Subscript ( a , b , Load , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s t_primary[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '[' slices ']' &t_lookahead")); - } - { // t_primary genexp &t_lookahead - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> t_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary genexp &t_lookahead")); - expr_ty a; - expr_ty b; - if ( - (a = t_primary_rule(p)) // t_primary - && - (b = genexp_rule(p)) // genexp - && - _PyPegen_lookahead(1, t_lookahead_rule, p) - ) - { - D(fprintf(stderr, "%*c+ t_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary genexp &t_lookahead")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Call ( a , CHECK ( _PyPegen_singleton_seq ( p , b ) ) , NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s t_primary[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary genexp &t_lookahead")); - } - { // t_primary '(' arguments? ')' &t_lookahead - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> t_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "t_primary '(' arguments? ')' &t_lookahead")); - Token * _literal; - Token * _literal_1; - expr_ty a; - void *b; - if ( - (a = t_primary_rule(p)) // t_primary - && - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (b = arguments_rule(p), 1) // arguments? - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - && - _PyPegen_lookahead(1, t_lookahead_rule, p) - ) - { - D(fprintf(stderr, "%*c+ t_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "t_primary '(' arguments? ')' &t_lookahead")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Call ( a , ( b ) ? ( ( expr_ty ) b ) -> v . Call . args : NULL , ( b ) ? ( ( expr_ty ) b ) -> v . Call . keywords : NULL , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s t_primary[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "t_primary '(' arguments? ')' &t_lookahead")); - } - { // atom &t_lookahead - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> t_primary[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "atom &t_lookahead")); - expr_ty a; - if ( - (a = atom_rule(p)) // atom - && - _PyPegen_lookahead(1, t_lookahead_rule, p) - ) - { - D(fprintf(stderr, "%*c+ t_primary[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "atom &t_lookahead")); - _res = a; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s t_primary[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "atom &t_lookahead")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// t_lookahead: '(' | '[' | '.' -static void * -t_lookahead_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '(' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> t_lookahead[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'('")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - ) - { - D(fprintf(stderr, "%*c+ t_lookahead[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'('")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s t_lookahead[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'('")); - } - { // '[' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> t_lookahead[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'['")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 9)) // token='[' - ) - { - D(fprintf(stderr, "%*c+ t_lookahead[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'['")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s t_lookahead[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'['")); - } - { // '.' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> t_lookahead[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'.'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 23)) // token='.' - ) - { - D(fprintf(stderr, "%*c+ t_lookahead[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'.'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s t_lookahead[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'.'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// t_atom: NAME | '(' target ')' | '(' targets? ')' | '[' targets? ']' -static expr_ty -t_atom_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - expr_ty _res = NULL; - int _mark = p->mark; - if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - int _start_lineno = p->tokens[_mark]->lineno; - UNUSED(_start_lineno); // Only used by EXTRA macro - int _start_col_offset = p->tokens[_mark]->col_offset; - UNUSED(_start_col_offset); // Only used by EXTRA macro - { // NAME - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME")); - expr_ty a; - if ( - (a = _PyPegen_name_token(p)) // NAME - ) - { - D(fprintf(stderr, "%*c+ t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME")); - _res = _PyPegen_set_expr_context ( p , a , Store ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s t_atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME")); - } - { // '(' target ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' target ')'")); - Token * _literal; - Token * _literal_1; - expr_ty a; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (a = target_rule(p)) // target - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' target ')'")); - _res = _PyPegen_set_expr_context ( p , a , Store ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s t_atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' target ')'")); - } - { // '(' targets? ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' targets? ')'")); - Token * _literal; - Token * _literal_1; - void *b; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (b = targets_rule(p), 1) // targets? - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' targets? ')'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_Tuple ( b , Store , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s t_atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' targets? ')'")); - } - { // '[' targets? ']' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> t_atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'[' targets? ']'")); - Token * _literal; - Token * _literal_1; - void *b; - if ( - (_literal = _PyPegen_expect_token(p, 9)) // token='[' - && - (b = targets_rule(p), 1) // targets? - && - (_literal_1 = _PyPegen_expect_token(p, 10)) // token=']' - ) - { - D(fprintf(stderr, "%*c+ t_atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'[' targets? ']'")); - Token *_token = _PyPegen_get_last_nonnwhitespace_token(p); - if (_token == NULL) { - D(p->level--); - return NULL; - } - int _end_lineno = _token->end_lineno; - UNUSED(_end_lineno); // Only used by EXTRA macro - int _end_col_offset = _token->end_col_offset; - UNUSED(_end_col_offset); // Only used by EXTRA macro - _res = _Py_List ( b , Store , EXTRA ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s t_atom[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'[' targets? ']'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// incorrect_arguments: -// | args ',' '*' -// | expression for_if_clauses ',' [args | expression for_if_clauses] -// | args for_if_clauses -// | args ',' expression for_if_clauses -// | args ',' args -static void * -incorrect_arguments_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // args ',' '*' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> incorrect_arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "args ',' '*'")); - Token * _literal; - Token * _literal_1; - expr_ty args_var; - if ( - (args_var = args_rule(p)) // args - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (_literal_1 = _PyPegen_expect_token(p, 16)) // token='*' - ) - { - D(fprintf(stderr, "%*c+ incorrect_arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "args ',' '*'")); - _res = RAISE_SYNTAX_ERROR ( "iterable argument unpacking follows keyword argument unpacking" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s incorrect_arguments[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "args ',' '*'")); - } - { // expression for_if_clauses ',' [args | expression for_if_clauses] - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> incorrect_arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression for_if_clauses ',' [args | expression for_if_clauses]")); - Token * _literal; - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - expr_ty a; - asdl_seq* for_if_clauses_var; - if ( - (a = expression_rule(p)) // expression - && - (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (_opt_var = _tmp_125_rule(p), 1) // [args | expression for_if_clauses] - ) - { - D(fprintf(stderr, "%*c+ incorrect_arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression for_if_clauses ',' [args | expression for_if_clauses]")); - _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "Generator expression must be parenthesized" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s incorrect_arguments[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression for_if_clauses ',' [args | expression for_if_clauses]")); - } - { // args for_if_clauses - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> incorrect_arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "args for_if_clauses")); - expr_ty a; - asdl_seq* for_if_clauses_var; - if ( - (a = args_rule(p)) // args - && - (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses - ) - { - D(fprintf(stderr, "%*c+ incorrect_arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "args for_if_clauses")); - _res = _PyPegen_nonparen_genexp_in_call ( p , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s incorrect_arguments[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "args for_if_clauses")); - } - { // args ',' expression for_if_clauses - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> incorrect_arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "args ',' expression for_if_clauses")); - Token * _literal; - expr_ty a; - expr_ty args_var; - asdl_seq* for_if_clauses_var; - if ( - (args_var = args_rule(p)) // args - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (a = expression_rule(p)) // expression - && - (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses - ) - { - D(fprintf(stderr, "%*c+ incorrect_arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "args ',' expression for_if_clauses")); - _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "Generator expression must be parenthesized" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s incorrect_arguments[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "args ',' expression for_if_clauses")); - } - { // args ',' args - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> incorrect_arguments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "args ',' args")); - Token * _literal; - expr_ty a; - expr_ty args_var; - if ( - (a = args_rule(p)) // args - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (args_var = args_rule(p)) // args - ) - { - D(fprintf(stderr, "%*c+ incorrect_arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "args ',' args")); - _res = _PyPegen_arguments_parsing_error ( p , a ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s incorrect_arguments[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "args ',' args")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// invalid_kwarg: expression '=' -static void * -invalid_kwarg_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // expression '=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_kwarg[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression '='")); - Token * _literal; - expr_ty a; - if ( - (a = expression_rule(p)) // expression - && - (_literal = _PyPegen_expect_token(p, 22)) // token='=' - ) - { - D(fprintf(stderr, "%*c+ invalid_kwarg[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression '='")); - _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "expression cannot contain assignment, perhaps you meant \"==\"?" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_kwarg[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression '='")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// invalid_named_expression: expression ':=' expression -static void * -invalid_named_expression_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // expression ':=' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_named_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression ':=' expression")); - Token * _literal; - expr_ty a; - expr_ty expression_var; - if ( - (a = expression_rule(p)) // expression - && - (_literal = _PyPegen_expect_token(p, 53)) // token=':=' - && - (expression_var = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ invalid_named_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression ':=' expression")); - _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "cannot use assignment expressions with %s" , _PyPegen_get_expr_name ( a ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_named_expression[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression ':=' expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// invalid_assignment: -// | list ':' -// | tuple ':' -// | star_named_expression ',' star_named_expressions* ':' -// | expression ':' expression ['=' annotated_rhs] -// | star_expressions '=' (yield_expr | star_expressions) -// | star_expressions augassign (yield_expr | star_expressions) -static void * -invalid_assignment_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // list ':' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "list ':'")); - Token * _literal; - expr_ty a; - if ( - (a = list_rule(p)) // list - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - ) - { - D(fprintf(stderr, "%*c+ invalid_assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "list ':'")); - _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "only single target (not list) can be annotated" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_assignment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "list ':'")); - } - { // tuple ':' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "tuple ':'")); - Token * _literal; - expr_ty a; - if ( - (a = tuple_rule(p)) // tuple - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - ) - { - D(fprintf(stderr, "%*c+ invalid_assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "tuple ':'")); - _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "only single target (not tuple) can be annotated" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_assignment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "tuple ':'")); - } - { // star_named_expression ',' star_named_expressions* ':' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_named_expression ',' star_named_expressions* ':'")); - Token * _literal; - Token * _literal_1; - asdl_seq * _loop0_126_var; - expr_ty a; - if ( - (a = star_named_expression_rule(p)) // star_named_expression - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (_loop0_126_var = _loop0_126_rule(p)) // star_named_expressions* - && - (_literal_1 = _PyPegen_expect_token(p, 11)) // token=':' - ) - { - D(fprintf(stderr, "%*c+ invalid_assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_named_expression ',' star_named_expressions* ':'")); - _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "only single target (not tuple) can be annotated" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_assignment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_named_expression ',' star_named_expressions* ':'")); - } - { // expression ':' expression ['=' annotated_rhs] - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression ':' expression ['=' annotated_rhs]")); - Token * _literal; - void *_opt_var; - UNUSED(_opt_var); // Silence compiler warnings - expr_ty a; - expr_ty expression_var; - if ( - (a = expression_rule(p)) // expression - && - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (expression_var = expression_rule(p)) // expression - && - (_opt_var = _tmp_127_rule(p), 1) // ['=' annotated_rhs] - ) - { - D(fprintf(stderr, "%*c+ invalid_assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression ':' expression ['=' annotated_rhs]")); - _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "illegal target for annotation" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_assignment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression ':' expression ['=' annotated_rhs]")); - } - { // star_expressions '=' (yield_expr | star_expressions) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions '=' (yield_expr | star_expressions)")); - Token * _literal; - void *_tmp_128_var; - expr_ty a; - if ( - (a = star_expressions_rule(p)) // star_expressions - && - (_literal = _PyPegen_expect_token(p, 22)) // token='=' - && - (_tmp_128_var = _tmp_128_rule(p)) // yield_expr | star_expressions - ) - { - D(fprintf(stderr, "%*c+ invalid_assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions '=' (yield_expr | star_expressions)")); - _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( _PyPegen_get_invalid_target ( a ) , "cannot assign to %s" , _PyPegen_get_expr_name ( _PyPegen_get_invalid_target ( a ) ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_assignment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions '=' (yield_expr | star_expressions)")); - } - { // star_expressions augassign (yield_expr | star_expressions) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_assignment[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions augassign (yield_expr | star_expressions)")); - void *_tmp_129_var; - expr_ty a; - AugOperator* augassign_var; - if ( - (a = star_expressions_rule(p)) // star_expressions - && - (augassign_var = augassign_rule(p)) // augassign - && - (_tmp_129_var = _tmp_129_rule(p)) // yield_expr | star_expressions - ) - { - D(fprintf(stderr, "%*c+ invalid_assignment[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions augassign (yield_expr | star_expressions)")); - _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "'%s' is an illegal expression for augmented assignment" , _PyPegen_get_expr_name ( a ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_assignment[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions augassign (yield_expr | star_expressions)")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// invalid_block: NEWLINE !INDENT -static void * -invalid_block_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // NEWLINE !INDENT - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_block[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE !INDENT")); - Token * newline_var; - if ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - && - _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, INDENT) // token=INDENT - ) - { - D(fprintf(stderr, "%*c+ invalid_block[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NEWLINE !INDENT")); - _res = RAISE_INDENTATION_ERROR ( "expected an indented block" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_block[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE !INDENT")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// invalid_comprehension: ('[' | '(' | '{') starred_expression for_if_clauses -static void * -invalid_comprehension_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // ('[' | '(' | '{') starred_expression for_if_clauses - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_comprehension[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('[' | '(' | '{') starred_expression for_if_clauses")); - void *_tmp_130_var; - expr_ty a; - asdl_seq* for_if_clauses_var; - if ( - (_tmp_130_var = _tmp_130_rule(p)) // '[' | '(' | '{' - && - (a = starred_expression_rule(p)) // starred_expression - && - (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses - ) - { - D(fprintf(stderr, "%*c+ invalid_comprehension[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "('[' | '(' | '{') starred_expression for_if_clauses")); - _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "iterable unpacking cannot be used in comprehension" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_comprehension[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('[' | '(' | '{') starred_expression for_if_clauses")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// invalid_dict_comprehension: '{' '**' bitwise_or for_if_clauses '}' -static void * -invalid_dict_comprehension_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '{' '**' bitwise_or for_if_clauses '}' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_dict_comprehension[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'{' '**' bitwise_or for_if_clauses '}'")); - Token * _literal; - Token * _literal_1; - Token * a; - expr_ty bitwise_or_var; - asdl_seq* for_if_clauses_var; - if ( - (_literal = _PyPegen_expect_token(p, 25)) // token='{' - && - (a = _PyPegen_expect_token(p, 35)) // token='**' - && - (bitwise_or_var = bitwise_or_rule(p)) // bitwise_or - && - (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses - && - (_literal_1 = _PyPegen_expect_token(p, 26)) // token='}' - ) - { - D(fprintf(stderr, "%*c+ invalid_dict_comprehension[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'{' '**' bitwise_or for_if_clauses '}'")); - _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "dict unpacking cannot be used in dict comprehension" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_dict_comprehension[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'{' '**' bitwise_or for_if_clauses '}'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// invalid_parameters: -// | param_no_default* (slash_with_default | param_with_default+) param_no_default -static void * -invalid_parameters_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // param_no_default* (slash_with_default | param_with_default+) param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_parameters[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default* (slash_with_default | param_with_default+) param_no_default")); - asdl_seq * _loop0_131_var; - void *_tmp_132_var; - arg_ty param_no_default_var; - if ( - (_loop0_131_var = _loop0_131_rule(p)) // param_no_default* - && - (_tmp_132_var = _tmp_132_rule(p)) // slash_with_default | param_with_default+ - && - (param_no_default_var = param_no_default_rule(p)) // param_no_default - ) - { - D(fprintf(stderr, "%*c+ invalid_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_no_default* (slash_with_default | param_with_default+) param_no_default")); - _res = RAISE_SYNTAX_ERROR ( "non-default argument follows default argument" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_parameters[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default* (slash_with_default | param_with_default+) param_no_default")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// invalid_star_etc: '*' (')' | ',' (')' | '**')) | '*' ',' TYPE_COMMENT -static void * -invalid_star_etc_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '*' (')' | ',' (')' | '**')) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' (')' | ',' (')' | '**'))")); - Token * _literal; - void *_tmp_133_var; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (_tmp_133_var = _tmp_133_rule(p)) // ')' | ',' (')' | '**') - ) - { - D(fprintf(stderr, "%*c+ invalid_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' (')' | ',' (')' | '**'))")); - _res = RAISE_SYNTAX_ERROR ( "named arguments must follow bare *" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_star_etc[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' (')' | ',' (')' | '**'))")); - } - { // '*' ',' TYPE_COMMENT - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' ',' TYPE_COMMENT")); - Token * _literal; - Token * _literal_1; - Token * type_comment_var; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (_literal_1 = _PyPegen_expect_token(p, 12)) // token=',' - && - (type_comment_var = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' - ) - { - D(fprintf(stderr, "%*c+ invalid_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' ',' TYPE_COMMENT")); - _res = RAISE_SYNTAX_ERROR ( "bare * has associated type comment" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_star_etc[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' ',' TYPE_COMMENT")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// invalid_lambda_star_etc: '*' (':' | ',' (':' | '**')) -static void * -invalid_lambda_star_etc_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '*' (':' | ',' (':' | '**')) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_lambda_star_etc[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'*' (':' | ',' (':' | '**'))")); - Token * _literal; - void *_tmp_134_var; - if ( - (_literal = _PyPegen_expect_token(p, 16)) // token='*' - && - (_tmp_134_var = _tmp_134_rule(p)) // ':' | ',' (':' | '**') - ) - { - D(fprintf(stderr, "%*c+ invalid_lambda_star_etc[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'*' (':' | ',' (':' | '**'))")); - _res = RAISE_SYNTAX_ERROR ( "named arguments must follow bare *" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_lambda_star_etc[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'*' (':' | ',' (':' | '**'))")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// invalid_double_type_comments: TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT -static void * -invalid_double_type_comments_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_double_type_comments[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT")); - Token * indent_var; - Token * newline_var; - Token * newline_var_1; - Token * type_comment_var; - Token * type_comment_var_1; - if ( - (type_comment_var = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' - && - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - && - (type_comment_var_1 = _PyPegen_expect_token(p, TYPE_COMMENT)) // token='TYPE_COMMENT' - && - (newline_var_1 = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - && - (indent_var = _PyPegen_expect_token(p, INDENT)) // token='INDENT' - ) - { - D(fprintf(stderr, "%*c+ invalid_double_type_comments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT")); - _res = RAISE_SYNTAX_ERROR ( "Cannot have two type comments on def" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_double_type_comments[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// invalid_del_target: star_expression &del_target_end -static void * -invalid_del_target_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // star_expression &del_target_end - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_del_target[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expression &del_target_end")); - expr_ty a; - if ( - (a = star_expression_rule(p)) // star_expression - && - _PyPegen_lookahead(1, del_target_end_rule, p) - ) - { - D(fprintf(stderr, "%*c+ invalid_del_target[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expression &del_target_end")); - _res = RAISE_SYNTAX_ERROR_KNOWN_LOCATION ( a , "cannot delete %s" , _PyPegen_get_expr_name ( a ) ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_del_target[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expression &del_target_end")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// invalid_import_from_targets: import_from_as_names ',' -static void * -invalid_import_from_targets_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // import_from_as_names ',' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> invalid_import_from_targets[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "import_from_as_names ','")); - Token * _literal; - asdl_seq* import_from_as_names_var; - if ( - (import_from_as_names_var = import_from_as_names_rule(p)) // import_from_as_names - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - ) - { - D(fprintf(stderr, "%*c+ invalid_import_from_targets[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "import_from_as_names ','")); - _res = RAISE_SYNTAX_ERROR ( "trailing comma not allowed without surrounding parentheses" ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s invalid_import_from_targets[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "import_from_as_names ','")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_1: NEWLINE -static asdl_seq * -_loop0_1_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // NEWLINE - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_1[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE")); - Token * newline_var; - while ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - ) - { - _res = newline_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_1[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_1_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_2: NEWLINE -static asdl_seq * -_loop0_2_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // NEWLINE - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_2[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE")); - Token * newline_var; - while ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - ) - { - _res = newline_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_2[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_2_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_4: ',' expression -static asdl_seq * -_loop0_4_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_4[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' expression")); - Token * _literal; - expr_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = expression_rule(p)) // expression - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_4[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' expression")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_4_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_3: expression _loop0_4 -static asdl_seq * -_gather_3_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // expression _loop0_4 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_3[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression _loop0_4")); - expr_ty elem; - asdl_seq * seq; - if ( - (elem = expression_rule(p)) // expression - && - (seq = _loop0_4_rule(p)) // _loop0_4 - ) - { - D(fprintf(stderr, "%*c+ _gather_3[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression _loop0_4")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_3[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression _loop0_4")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_6: ',' expression -static asdl_seq * -_loop0_6_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_6[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' expression")); - Token * _literal; - expr_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = expression_rule(p)) // expression - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_6[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' expression")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_6_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_5: expression _loop0_6 -static asdl_seq * -_gather_5_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // expression _loop0_6 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_5[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression _loop0_6")); - expr_ty elem; - asdl_seq * seq; - if ( - (elem = expression_rule(p)) // expression - && - (seq = _loop0_6_rule(p)) // _loop0_6 - ) - { - D(fprintf(stderr, "%*c+ _gather_5[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression _loop0_6")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_5[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression _loop0_6")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_8: ',' expression -static asdl_seq * -_loop0_8_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_8[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' expression")); - Token * _literal; - expr_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = expression_rule(p)) // expression - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_8[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' expression")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_8_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_7: expression _loop0_8 -static asdl_seq * -_gather_7_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // expression _loop0_8 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_7[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression _loop0_8")); - expr_ty elem; - asdl_seq * seq; - if ( - (elem = expression_rule(p)) // expression - && - (seq = _loop0_8_rule(p)) // _loop0_8 - ) - { - D(fprintf(stderr, "%*c+ _gather_7[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression _loop0_8")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_7[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression _loop0_8")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_10: ',' expression -static asdl_seq * -_loop0_10_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_10[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' expression")); - Token * _literal; - expr_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = expression_rule(p)) // expression - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_10[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' expression")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_10_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_9: expression _loop0_10 -static asdl_seq * -_gather_9_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // expression _loop0_10 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_9[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression _loop0_10")); - expr_ty elem; - asdl_seq * seq; - if ( - (elem = expression_rule(p)) // expression - && - (seq = _loop0_10_rule(p)) // _loop0_10 - ) - { - D(fprintf(stderr, "%*c+ _gather_9[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression _loop0_10")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_9[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression _loop0_10")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop1_11: statement -static asdl_seq * -_loop1_11_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // statement - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_11[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "statement")); - asdl_seq* statement_var; - while ( - (statement_var = statement_rule(p)) // statement - ) - { - _res = statement_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_11[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "statement")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_11_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_13: ';' small_stmt -static asdl_seq * -_loop0_13_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ';' small_stmt - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_13[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "';' small_stmt")); - Token * _literal; - stmt_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 13)) // token=';' - && - (elem = small_stmt_rule(p)) // small_stmt - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_13[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "';' small_stmt")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_13_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_12: small_stmt _loop0_13 -static asdl_seq * -_gather_12_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // small_stmt _loop0_13 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_12[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "small_stmt _loop0_13")); - stmt_ty elem; - asdl_seq * seq; - if ( - (elem = small_stmt_rule(p)) // small_stmt - && - (seq = _loop0_13_rule(p)) // _loop0_13 - ) - { - D(fprintf(stderr, "%*c+ _gather_12[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "small_stmt _loop0_13")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_12[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "small_stmt _loop0_13")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_14: 'import' | 'from' -static void * -_tmp_14_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'import' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_14[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'import'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 513)) // token='import' - ) - { - D(fprintf(stderr, "%*c+ _tmp_14[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'import'")); - _res = _keyword; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_14[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'import'")); - } - { // 'from' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_14[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'from'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 514)) // token='from' - ) - { - D(fprintf(stderr, "%*c+ _tmp_14[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'from'")); - _res = _keyword; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_14[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'from'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_15: 'def' | '@' | ASYNC -static void * -_tmp_15_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'def' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_15[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'def'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 522)) // token='def' - ) - { - D(fprintf(stderr, "%*c+ _tmp_15[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'def'")); - _res = _keyword; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_15[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'def'")); - } - { // '@' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_15[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'@'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 49)) // token='@' - ) - { - D(fprintf(stderr, "%*c+ _tmp_15[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'@'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_15[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'@'")); - } - { // ASYNC - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_15[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC")); - Token * async_var; - if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' - ) - { - D(fprintf(stderr, "%*c+ _tmp_15[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC")); - _res = async_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_15[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_16: 'class' | '@' -static void * -_tmp_16_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'class' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_16[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'class'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 523)) // token='class' - ) - { - D(fprintf(stderr, "%*c+ _tmp_16[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'class'")); - _res = _keyword; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_16[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'class'")); - } - { // '@' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_16[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'@'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 49)) // token='@' - ) - { - D(fprintf(stderr, "%*c+ _tmp_16[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'@'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_16[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'@'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_17: 'with' | ASYNC -static void * -_tmp_17_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'with' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_17[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'with'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 519)) // token='with' - ) - { - D(fprintf(stderr, "%*c+ _tmp_17[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'with'")); - _res = _keyword; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_17[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'with'")); - } - { // ASYNC - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_17[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC")); - Token * async_var; - if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' - ) - { - D(fprintf(stderr, "%*c+ _tmp_17[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC")); - _res = async_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_17[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_18: 'for' | ASYNC -static void * -_tmp_18_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'for' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_18[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'for'")); - Token * _keyword; - if ( - (_keyword = _PyPegen_expect_token(p, 517)) // token='for' - ) - { - D(fprintf(stderr, "%*c+ _tmp_18[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'for'")); - _res = _keyword; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_18[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'for'")); - } - { // ASYNC - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_18[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "ASYNC")); - Token * async_var; - if ( - (async_var = _PyPegen_expect_token(p, ASYNC)) // token='ASYNC' - ) - { - D(fprintf(stderr, "%*c+ _tmp_18[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "ASYNC")); - _res = async_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_18[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "ASYNC")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_19: '=' annotated_rhs -static void * -_tmp_19_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '=' annotated_rhs - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_19[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'=' annotated_rhs")); - Token * _literal; - expr_ty d; - if ( - (_literal = _PyPegen_expect_token(p, 22)) // token='=' - && - (d = annotated_rhs_rule(p)) // annotated_rhs - ) - { - D(fprintf(stderr, "%*c+ _tmp_19[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'=' annotated_rhs")); - _res = d; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_19[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'=' annotated_rhs")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_20: '(' single_target ')' | single_subscript_attribute_target -static void * -_tmp_20_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '(' single_target ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_20[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' single_target ')'")); - Token * _literal; - Token * _literal_1; - expr_ty b; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (b = single_target_rule(p)) // single_target - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ _tmp_20[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' single_target ')'")); - _res = b; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_20[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' single_target ')'")); - } - { // single_subscript_attribute_target - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_20[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "single_subscript_attribute_target")); - expr_ty single_subscript_attribute_target_var; - if ( - (single_subscript_attribute_target_var = single_subscript_attribute_target_rule(p)) // single_subscript_attribute_target - ) - { - D(fprintf(stderr, "%*c+ _tmp_20[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "single_subscript_attribute_target")); - _res = single_subscript_attribute_target_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_20[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "single_subscript_attribute_target")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_21: '=' annotated_rhs -static void * -_tmp_21_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '=' annotated_rhs - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_21[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'=' annotated_rhs")); - Token * _literal; - expr_ty d; - if ( - (_literal = _PyPegen_expect_token(p, 22)) // token='=' - && - (d = annotated_rhs_rule(p)) // annotated_rhs - ) - { - D(fprintf(stderr, "%*c+ _tmp_21[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'=' annotated_rhs")); - _res = d; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_21[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'=' annotated_rhs")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop1_22: (star_targets '=') -static asdl_seq * -_loop1_22_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // (star_targets '=') - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_22[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "(star_targets '=')")); - void *_tmp_135_var; - while ( - (_tmp_135_var = _tmp_135_rule(p)) // star_targets '=' - ) - { - _res = _tmp_135_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_22[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "(star_targets '=')")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_22_type, _seq); - D(p->level--); - return _seq; -} - -// _tmp_23: yield_expr | star_expressions -static void * -_tmp_23_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // yield_expr - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_23[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "yield_expr")); - expr_ty yield_expr_var; - if ( - (yield_expr_var = yield_expr_rule(p)) // yield_expr - ) - { - D(fprintf(stderr, "%*c+ _tmp_23[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "yield_expr")); - _res = yield_expr_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_23[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "yield_expr")); - } - { // star_expressions - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_23[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions")); - expr_ty star_expressions_var; - if ( - (star_expressions_var = star_expressions_rule(p)) // star_expressions - ) - { - D(fprintf(stderr, "%*c+ _tmp_23[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions")); - _res = star_expressions_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_23[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_24: yield_expr | star_expressions -static void * -_tmp_24_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // yield_expr - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_24[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "yield_expr")); - expr_ty yield_expr_var; - if ( - (yield_expr_var = yield_expr_rule(p)) // yield_expr - ) - { - D(fprintf(stderr, "%*c+ _tmp_24[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "yield_expr")); - _res = yield_expr_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_24[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "yield_expr")); - } - { // star_expressions - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_24[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions")); - expr_ty star_expressions_var; - if ( - (star_expressions_var = star_expressions_rule(p)) // star_expressions - ) - { - D(fprintf(stderr, "%*c+ _tmp_24[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions")); - _res = star_expressions_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_24[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_26: ',' NAME -static asdl_seq * -_loop0_26_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' NAME - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_26[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' NAME")); - Token * _literal; - expr_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = _PyPegen_name_token(p)) // NAME - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_26[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' NAME")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_26_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_25: NAME _loop0_26 -static asdl_seq * -_gather_25_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // NAME _loop0_26 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_25[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME _loop0_26")); - expr_ty elem; - asdl_seq * seq; - if ( - (elem = _PyPegen_name_token(p)) // NAME - && - (seq = _loop0_26_rule(p)) // _loop0_26 - ) - { - D(fprintf(stderr, "%*c+ _gather_25[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME _loop0_26")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_25[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME _loop0_26")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_28: ',' NAME -static asdl_seq * -_loop0_28_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' NAME - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_28[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' NAME")); - Token * _literal; - expr_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = _PyPegen_name_token(p)) // NAME - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_28[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' NAME")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_28_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_27: NAME _loop0_28 -static asdl_seq * -_gather_27_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // NAME _loop0_28 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_27[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME _loop0_28")); - expr_ty elem; - asdl_seq * seq; - if ( - (elem = _PyPegen_name_token(p)) // NAME - && - (seq = _loop0_28_rule(p)) // _loop0_28 - ) - { - D(fprintf(stderr, "%*c+ _gather_27[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME _loop0_28")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_27[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME _loop0_28")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_29: ',' expression -static void * -_tmp_29_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // ',' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_29[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' expression")); - Token * _literal; - expr_ty z; - if ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (z = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ _tmp_29[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' expression")); - _res = z; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_29[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_30: ('.' | '...') -static asdl_seq * -_loop0_30_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ('.' | '...') - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_30[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('.' | '...')")); - void *_tmp_136_var; - while ( - (_tmp_136_var = _tmp_136_rule(p)) // '.' | '...' - ) - { - _res = _tmp_136_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_30[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('.' | '...')")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_30_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_31: ('.' | '...') -static asdl_seq * -_loop1_31_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ('.' | '...') - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_31[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('.' | '...')")); - void *_tmp_137_var; - while ( - (_tmp_137_var = _tmp_137_rule(p)) // '.' | '...' - ) - { - _res = _tmp_137_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_31[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('.' | '...')")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_31_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_33: ',' import_from_as_name -static asdl_seq * -_loop0_33_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' import_from_as_name - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_33[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' import_from_as_name")); - Token * _literal; - alias_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = import_from_as_name_rule(p)) // import_from_as_name - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_33[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' import_from_as_name")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_33_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_32: import_from_as_name _loop0_33 -static asdl_seq * -_gather_32_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // import_from_as_name _loop0_33 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_32[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "import_from_as_name _loop0_33")); - alias_ty elem; - asdl_seq * seq; - if ( - (elem = import_from_as_name_rule(p)) // import_from_as_name - && - (seq = _loop0_33_rule(p)) // _loop0_33 - ) - { - D(fprintf(stderr, "%*c+ _gather_32[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "import_from_as_name _loop0_33")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_32[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "import_from_as_name _loop0_33")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_34: 'as' NAME -static void * -_tmp_34_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'as' NAME - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_34[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'as' NAME")); - Token * _keyword; - expr_ty z; - if ( - (_keyword = _PyPegen_expect_token(p, 531)) // token='as' - && - (z = _PyPegen_name_token(p)) // NAME - ) - { - D(fprintf(stderr, "%*c+ _tmp_34[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'as' NAME")); - _res = z; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_34[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'as' NAME")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_36: ',' dotted_as_name -static asdl_seq * -_loop0_36_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' dotted_as_name - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_36[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' dotted_as_name")); - Token * _literal; - alias_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = dotted_as_name_rule(p)) // dotted_as_name - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_36[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' dotted_as_name")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_36_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_35: dotted_as_name _loop0_36 -static asdl_seq * -_gather_35_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // dotted_as_name _loop0_36 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_35[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "dotted_as_name _loop0_36")); - alias_ty elem; - asdl_seq * seq; - if ( - (elem = dotted_as_name_rule(p)) // dotted_as_name - && - (seq = _loop0_36_rule(p)) // _loop0_36 - ) - { - D(fprintf(stderr, "%*c+ _gather_35[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "dotted_as_name _loop0_36")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_35[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "dotted_as_name _loop0_36")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_37: 'as' NAME -static void * -_tmp_37_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'as' NAME - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_37[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'as' NAME")); - Token * _keyword; - expr_ty z; - if ( - (_keyword = _PyPegen_expect_token(p, 531)) // token='as' - && - (z = _PyPegen_name_token(p)) // NAME - ) - { - D(fprintf(stderr, "%*c+ _tmp_37[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'as' NAME")); - _res = z; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_37[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'as' NAME")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_39: ',' with_item -static asdl_seq * -_loop0_39_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' with_item - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_39[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' with_item")); - Token * _literal; - withitem_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = with_item_rule(p)) // with_item - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_39[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' with_item")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_39_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_38: with_item _loop0_39 -static asdl_seq * -_gather_38_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // with_item _loop0_39 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_38[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "with_item _loop0_39")); - withitem_ty elem; - asdl_seq * seq; - if ( - (elem = with_item_rule(p)) // with_item - && - (seq = _loop0_39_rule(p)) // _loop0_39 - ) - { - D(fprintf(stderr, "%*c+ _gather_38[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "with_item _loop0_39")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_38[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "with_item _loop0_39")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_41: ',' with_item -static asdl_seq * -_loop0_41_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' with_item - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_41[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' with_item")); - Token * _literal; - withitem_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = with_item_rule(p)) // with_item - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_41[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' with_item")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_41_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_40: with_item _loop0_41 -static asdl_seq * -_gather_40_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // with_item _loop0_41 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_40[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "with_item _loop0_41")); - withitem_ty elem; - asdl_seq * seq; - if ( - (elem = with_item_rule(p)) // with_item - && - (seq = _loop0_41_rule(p)) // _loop0_41 - ) - { - D(fprintf(stderr, "%*c+ _gather_40[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "with_item _loop0_41")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_40[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "with_item _loop0_41")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_43: ',' with_item -static asdl_seq * -_loop0_43_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' with_item - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_43[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' with_item")); - Token * _literal; - withitem_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = with_item_rule(p)) // with_item - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_43[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' with_item")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_43_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_42: with_item _loop0_43 -static asdl_seq * -_gather_42_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // with_item _loop0_43 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_42[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "with_item _loop0_43")); - withitem_ty elem; - asdl_seq * seq; - if ( - (elem = with_item_rule(p)) // with_item - && - (seq = _loop0_43_rule(p)) // _loop0_43 - ) - { - D(fprintf(stderr, "%*c+ _gather_42[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "with_item _loop0_43")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_42[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "with_item _loop0_43")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_45: ',' with_item -static asdl_seq * -_loop0_45_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' with_item - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_45[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' with_item")); - Token * _literal; - withitem_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = with_item_rule(p)) // with_item - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_45[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' with_item")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_45_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_44: with_item _loop0_45 -static asdl_seq * -_gather_44_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // with_item _loop0_45 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_44[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "with_item _loop0_45")); - withitem_ty elem; - asdl_seq * seq; - if ( - (elem = with_item_rule(p)) // with_item - && - (seq = _loop0_45_rule(p)) // _loop0_45 - ) - { - D(fprintf(stderr, "%*c+ _gather_44[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "with_item _loop0_45")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_44[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "with_item _loop0_45")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_46: 'as' target -static void * -_tmp_46_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'as' target - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_46[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'as' target")); - Token * _keyword; - expr_ty t; - if ( - (_keyword = _PyPegen_expect_token(p, 531)) // token='as' - && - (t = target_rule(p)) // target - ) - { - D(fprintf(stderr, "%*c+ _tmp_46[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'as' target")); - _res = t; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_46[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'as' target")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop1_47: except_block -static asdl_seq * -_loop1_47_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // except_block - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_47[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "except_block")); - excepthandler_ty except_block_var; - while ( - (except_block_var = except_block_rule(p)) // except_block - ) - { - _res = except_block_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_47[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "except_block")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_47_type, _seq); - D(p->level--); - return _seq; -} - -// _tmp_48: 'as' NAME -static void * -_tmp_48_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'as' NAME - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_48[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'as' NAME")); - Token * _keyword; - expr_ty z; - if ( - (_keyword = _PyPegen_expect_token(p, 531)) // token='as' - && - (z = _PyPegen_name_token(p)) // NAME - ) - { - D(fprintf(stderr, "%*c+ _tmp_48[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'as' NAME")); - _res = z; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_48[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'as' NAME")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_49: 'from' expression -static void * -_tmp_49_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'from' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_49[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'from' expression")); - Token * _keyword; - expr_ty z; - if ( - (_keyword = _PyPegen_expect_token(p, 514)) // token='from' - && - (z = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ _tmp_49[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'from' expression")); - _res = z; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_49[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'from' expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_50: '->' expression -static void * -_tmp_50_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '->' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_50[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'->' expression")); - Token * _literal; - expr_ty z; - if ( - (_literal = _PyPegen_expect_token(p, 51)) // token='->' - && - (z = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ _tmp_50[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'->' expression")); - _res = z; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_50[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'->' expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_51: '->' expression -static void * -_tmp_51_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '->' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_51[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'->' expression")); - Token * _literal; - expr_ty z; - if ( - (_literal = _PyPegen_expect_token(p, 51)) // token='->' - && - (z = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ _tmp_51[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'->' expression")); - _res = z; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_51[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'->' expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_52: NEWLINE INDENT -static void * -_tmp_52_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // NEWLINE INDENT - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_52[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NEWLINE INDENT")); - Token * indent_var; - Token * newline_var; - if ( - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - && - (indent_var = _PyPegen_expect_token(p, INDENT)) // token='INDENT' - ) - { - D(fprintf(stderr, "%*c+ _tmp_52[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NEWLINE INDENT")); - _res = _PyPegen_dummy_name(p, newline_var, indent_var); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_52[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NEWLINE INDENT")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_53: param_no_default -static asdl_seq * -_loop0_53_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_53[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); - arg_ty param_no_default_var; - while ( - (param_no_default_var = param_no_default_rule(p)) // param_no_default - ) - { - _res = param_no_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_53[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_53_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_54: param_with_default -static asdl_seq * -_loop0_54_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_54[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); - NameDefaultPair* param_with_default_var; - while ( - (param_with_default_var = param_with_default_rule(p)) // param_with_default - ) - { - _res = param_with_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_54[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_54_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_55: param_with_default -static asdl_seq * -_loop0_55_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_55[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); - NameDefaultPair* param_with_default_var; - while ( - (param_with_default_var = param_with_default_rule(p)) // param_with_default - ) - { - _res = param_with_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_55[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_55_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_56: param_no_default -static asdl_seq * -_loop1_56_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_56[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); - arg_ty param_no_default_var; - while ( - (param_no_default_var = param_no_default_rule(p)) // param_no_default - ) - { - _res = param_no_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_56[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_56_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_57: param_with_default -static asdl_seq * -_loop0_57_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_57[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); - NameDefaultPair* param_with_default_var; - while ( - (param_with_default_var = param_with_default_rule(p)) // param_with_default - ) - { - _res = param_with_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_57[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_57_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_58: param_with_default -static asdl_seq * -_loop1_58_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_58[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); - NameDefaultPair* param_with_default_var; - while ( - (param_with_default_var = param_with_default_rule(p)) // param_with_default - ) - { - _res = param_with_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_58[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_58_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_59: param_no_default -static asdl_seq * -_loop1_59_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_59[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); - arg_ty param_no_default_var; - while ( - (param_no_default_var = param_no_default_rule(p)) // param_no_default - ) - { - _res = param_no_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_59[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_59_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_60: param_no_default -static asdl_seq * -_loop1_60_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_60[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); - arg_ty param_no_default_var; - while ( - (param_no_default_var = param_no_default_rule(p)) // param_no_default - ) - { - _res = param_no_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_60[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_60_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_61: param_no_default -static asdl_seq * -_loop0_61_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_61[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); - arg_ty param_no_default_var; - while ( - (param_no_default_var = param_no_default_rule(p)) // param_no_default - ) - { - _res = param_no_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_61[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_61_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_62: param_with_default -static asdl_seq * -_loop1_62_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_62[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); - NameDefaultPair* param_with_default_var; - while ( - (param_with_default_var = param_with_default_rule(p)) // param_with_default - ) - { - _res = param_with_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_62[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_62_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_63: param_no_default -static asdl_seq * -_loop0_63_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_63[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); - arg_ty param_no_default_var; - while ( - (param_no_default_var = param_no_default_rule(p)) // param_no_default - ) - { - _res = param_no_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_63[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_63_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_64: param_with_default -static asdl_seq * -_loop1_64_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_64[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); - NameDefaultPair* param_with_default_var; - while ( - (param_with_default_var = param_with_default_rule(p)) // param_with_default - ) - { - _res = param_with_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_64[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_64_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_65: param_maybe_default -static asdl_seq * -_loop0_65_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_maybe_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_65[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_maybe_default")); - NameDefaultPair* param_maybe_default_var; - while ( - (param_maybe_default_var = param_maybe_default_rule(p)) // param_maybe_default - ) - { - _res = param_maybe_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_65[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_maybe_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_65_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_66: param_maybe_default -static asdl_seq * -_loop1_66_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_maybe_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_66[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_maybe_default")); - NameDefaultPair* param_maybe_default_var; - while ( - (param_maybe_default_var = param_maybe_default_rule(p)) // param_maybe_default - ) - { - _res = param_maybe_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_66[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_maybe_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_66_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_67: ('@' named_expression NEWLINE) -static asdl_seq * -_loop1_67_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ('@' named_expression NEWLINE) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_67[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('@' named_expression NEWLINE)")); - void *_tmp_138_var; - while ( - (_tmp_138_var = _tmp_138_rule(p)) // '@' named_expression NEWLINE - ) - { - _res = _tmp_138_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_67[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('@' named_expression NEWLINE)")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_67_type, _seq); - D(p->level--); - return _seq; -} - -// _tmp_68: '(' arguments? ')' -static void * -_tmp_68_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '(' arguments? ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_68[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'(' arguments? ')'")); - Token * _literal; - Token * _literal_1; - void *z; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - && - (z = arguments_rule(p), 1) // arguments? - && - (_literal_1 = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ _tmp_68[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'(' arguments? ')'")); - _res = z; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_68[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'(' arguments? ')'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_70: ',' star_expression -static asdl_seq * -_loop0_70_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' star_expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_70[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' star_expression")); - Token * _literal; - expr_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = star_expression_rule(p)) // star_expression - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_70[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' star_expression")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_70_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_69: star_expression _loop0_70 -static asdl_seq * -_gather_69_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // star_expression _loop0_70 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_69[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expression _loop0_70")); - expr_ty elem; - asdl_seq * seq; - if ( - (elem = star_expression_rule(p)) // star_expression - && - (seq = _loop0_70_rule(p)) // _loop0_70 - ) - { - D(fprintf(stderr, "%*c+ _gather_69[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expression _loop0_70")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_69[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expression _loop0_70")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop1_71: (',' star_expression) -static asdl_seq * -_loop1_71_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // (',' star_expression) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_71[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "(',' star_expression)")); - void *_tmp_139_var; - while ( - (_tmp_139_var = _tmp_139_rule(p)) // ',' star_expression - ) - { - _res = _tmp_139_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_71[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "(',' star_expression)")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_71_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_73: ',' star_named_expression -static asdl_seq * -_loop0_73_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' star_named_expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_73[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' star_named_expression")); - Token * _literal; - expr_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = star_named_expression_rule(p)) // star_named_expression - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_73[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' star_named_expression")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_73_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_72: star_named_expression _loop0_73 -static asdl_seq * -_gather_72_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // star_named_expression _loop0_73 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_72[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_named_expression _loop0_73")); - expr_ty elem; - asdl_seq * seq; - if ( - (elem = star_named_expression_rule(p)) // star_named_expression - && - (seq = _loop0_73_rule(p)) // _loop0_73 - ) - { - D(fprintf(stderr, "%*c+ _gather_72[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_named_expression _loop0_73")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_72[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_named_expression _loop0_73")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop1_74: (',' expression) -static asdl_seq * -_loop1_74_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // (',' expression) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_74[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "(',' expression)")); - void *_tmp_140_var; - while ( - (_tmp_140_var = _tmp_140_rule(p)) // ',' expression - ) - { - _res = _tmp_140_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_74[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "(',' expression)")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_74_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_75: lambda_param_no_default -static asdl_seq * -_loop0_75_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_75[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default")); - arg_ty lambda_param_no_default_var; - while ( - (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default - ) - { - _res = lambda_param_no_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_75[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_75_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_76: lambda_param_with_default -static asdl_seq * -_loop0_76_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_76[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default")); - NameDefaultPair* lambda_param_with_default_var; - while ( - (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default - ) - { - _res = lambda_param_with_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_76[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_76_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_77: lambda_param_with_default -static asdl_seq * -_loop0_77_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_77[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default")); - NameDefaultPair* lambda_param_with_default_var; - while ( - (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default - ) - { - _res = lambda_param_with_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_77[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_77_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_78: lambda_param_no_default -static asdl_seq * -_loop1_78_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_78[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default")); - arg_ty lambda_param_no_default_var; - while ( - (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default - ) - { - _res = lambda_param_no_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_78[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_78_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_79: lambda_param_with_default -static asdl_seq * -_loop0_79_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_79[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default")); - NameDefaultPair* lambda_param_with_default_var; - while ( - (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default - ) - { - _res = lambda_param_with_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_79[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_79_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_80: lambda_param_with_default -static asdl_seq * -_loop1_80_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_80[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default")); - NameDefaultPair* lambda_param_with_default_var; - while ( - (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default - ) - { - _res = lambda_param_with_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_80[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_80_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_81: lambda_param_no_default -static asdl_seq * -_loop1_81_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_81[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default")); - arg_ty lambda_param_no_default_var; - while ( - (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default - ) - { - _res = lambda_param_no_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_81[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_81_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_82: lambda_param_no_default -static asdl_seq * -_loop1_82_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_82[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default")); - arg_ty lambda_param_no_default_var; - while ( - (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default - ) - { - _res = lambda_param_no_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_82[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_82_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_83: lambda_param_no_default -static asdl_seq * -_loop0_83_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_83[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default")); - arg_ty lambda_param_no_default_var; - while ( - (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default - ) - { - _res = lambda_param_no_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_83[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_83_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_84: lambda_param_with_default -static asdl_seq * -_loop1_84_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_84[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default")); - NameDefaultPair* lambda_param_with_default_var; - while ( - (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default - ) - { - _res = lambda_param_with_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_84[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_84_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_85: lambda_param_no_default -static asdl_seq * -_loop0_85_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_85[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_no_default")); - arg_ty lambda_param_no_default_var; - while ( - (lambda_param_no_default_var = lambda_param_no_default_rule(p)) // lambda_param_no_default - ) - { - _res = lambda_param_no_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_85[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_no_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_85_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_86: lambda_param_with_default -static asdl_seq * -_loop1_86_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_86[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_with_default")); - NameDefaultPair* lambda_param_with_default_var; - while ( - (lambda_param_with_default_var = lambda_param_with_default_rule(p)) // lambda_param_with_default - ) - { - _res = lambda_param_with_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_86[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_with_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_86_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_87: lambda_param_maybe_default -static asdl_seq * -_loop0_87_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_maybe_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_87[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_maybe_default")); - NameDefaultPair* lambda_param_maybe_default_var; - while ( - (lambda_param_maybe_default_var = lambda_param_maybe_default_rule(p)) // lambda_param_maybe_default - ) - { - _res = lambda_param_maybe_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_87[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_maybe_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_87_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_88: lambda_param_maybe_default -static asdl_seq * -_loop1_88_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // lambda_param_maybe_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_88[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "lambda_param_maybe_default")); - NameDefaultPair* lambda_param_maybe_default_var; - while ( - (lambda_param_maybe_default_var = lambda_param_maybe_default_rule(p)) // lambda_param_maybe_default - ) - { - _res = lambda_param_maybe_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_88[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "lambda_param_maybe_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_88_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_89: ('or' conjunction) -static asdl_seq * -_loop1_89_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ('or' conjunction) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_89[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('or' conjunction)")); - void *_tmp_141_var; - while ( - (_tmp_141_var = _tmp_141_rule(p)) // 'or' conjunction - ) - { - _res = _tmp_141_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_89[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('or' conjunction)")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_89_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_90: ('and' inversion) -static asdl_seq * -_loop1_90_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ('and' inversion) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_90[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('and' inversion)")); - void *_tmp_142_var; - while ( - (_tmp_142_var = _tmp_142_rule(p)) // 'and' inversion - ) - { - _res = _tmp_142_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_90[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('and' inversion)")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_90_type, _seq); - D(p->level--); - return _seq; -} - -// _loop1_91: compare_op_bitwise_or_pair -static asdl_seq * -_loop1_91_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // compare_op_bitwise_or_pair - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_91[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "compare_op_bitwise_or_pair")); - CmpopExprPair* compare_op_bitwise_or_pair_var; - while ( - (compare_op_bitwise_or_pair_var = compare_op_bitwise_or_pair_rule(p)) // compare_op_bitwise_or_pair - ) - { - _res = compare_op_bitwise_or_pair_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_91[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "compare_op_bitwise_or_pair")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_91_type, _seq); - D(p->level--); - return _seq; -} - -// _tmp_92: '!=' -static void * -_tmp_92_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '!=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_92[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'!='")); - Token * tok; - if ( - (tok = _PyPegen_expect_token(p, 28)) // token='!=' - ) - { - D(fprintf(stderr, "%*c+ _tmp_92[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'!='")); - _res = _PyPegen_check_barry_as_flufl ( p ) ? NULL : tok; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_92[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'!='")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_94: ',' slice -static asdl_seq * -_loop0_94_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' slice - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_94[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' slice")); - Token * _literal; - expr_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = slice_rule(p)) // slice - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_94[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' slice")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_94_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_93: slice _loop0_94 -static asdl_seq * -_gather_93_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // slice _loop0_94 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_93[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "slice _loop0_94")); - expr_ty elem; - asdl_seq * seq; - if ( - (elem = slice_rule(p)) // slice - && - (seq = _loop0_94_rule(p)) // _loop0_94 - ) - { - D(fprintf(stderr, "%*c+ _gather_93[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "slice _loop0_94")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_93[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "slice _loop0_94")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_95: ':' expression? -static void * -_tmp_95_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // ':' expression? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_95[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "':' expression?")); - Token * _literal; - void *d; - if ( - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - && - (d = expression_rule(p), 1) // expression? - ) - { - D(fprintf(stderr, "%*c+ _tmp_95[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "':' expression?")); - _res = d; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_95[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "':' expression?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_96: tuple | group | genexp -static void * -_tmp_96_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // tuple - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_96[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "tuple")); - expr_ty tuple_var; - if ( - (tuple_var = tuple_rule(p)) // tuple - ) - { - D(fprintf(stderr, "%*c+ _tmp_96[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "tuple")); - _res = tuple_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_96[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "tuple")); - } - { // group - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_96[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "group")); - expr_ty group_var; - if ( - (group_var = group_rule(p)) // group - ) - { - D(fprintf(stderr, "%*c+ _tmp_96[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "group")); - _res = group_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_96[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "group")); - } - { // genexp - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_96[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "genexp")); - expr_ty genexp_var; - if ( - (genexp_var = genexp_rule(p)) // genexp - ) - { - D(fprintf(stderr, "%*c+ _tmp_96[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "genexp")); - _res = genexp_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_96[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "genexp")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_97: list | listcomp -static void * -_tmp_97_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // list - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_97[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "list")); - expr_ty list_var; - if ( - (list_var = list_rule(p)) // list - ) - { - D(fprintf(stderr, "%*c+ _tmp_97[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "list")); - _res = list_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_97[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "list")); - } - { // listcomp - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_97[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "listcomp")); - expr_ty listcomp_var; - if ( - (listcomp_var = listcomp_rule(p)) // listcomp - ) - { - D(fprintf(stderr, "%*c+ _tmp_97[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "listcomp")); - _res = listcomp_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_97[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "listcomp")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_98: dict | set | dictcomp | setcomp -static void * -_tmp_98_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // dict - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_98[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "dict")); - expr_ty dict_var; - if ( - (dict_var = dict_rule(p)) // dict - ) - { - D(fprintf(stderr, "%*c+ _tmp_98[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "dict")); - _res = dict_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_98[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "dict")); - } - { // set - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_98[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "set")); - expr_ty set_var; - if ( - (set_var = set_rule(p)) // set - ) - { - D(fprintf(stderr, "%*c+ _tmp_98[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "set")); - _res = set_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_98[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "set")); - } - { // dictcomp - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_98[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "dictcomp")); - expr_ty dictcomp_var; - if ( - (dictcomp_var = dictcomp_rule(p)) // dictcomp - ) - { - D(fprintf(stderr, "%*c+ _tmp_98[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "dictcomp")); - _res = dictcomp_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_98[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "dictcomp")); - } - { // setcomp - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_98[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "setcomp")); - expr_ty setcomp_var; - if ( - (setcomp_var = setcomp_rule(p)) // setcomp - ) - { - D(fprintf(stderr, "%*c+ _tmp_98[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "setcomp")); - _res = setcomp_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_98[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "setcomp")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop1_99: STRING -static asdl_seq * -_loop1_99_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // STRING - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_99[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "STRING")); - expr_ty string_var; - while ( - (string_var = _PyPegen_string_token(p)) // STRING - ) - { - _res = string_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_99[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "STRING")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_99_type, _seq); - D(p->level--); - return _seq; -} - -// _tmp_100: star_named_expression ',' star_named_expressions? -static void * -_tmp_100_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // star_named_expression ',' star_named_expressions? - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_100[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_named_expression ',' star_named_expressions?")); - Token * _literal; - expr_ty y; - void *z; - if ( - (y = star_named_expression_rule(p)) // star_named_expression - && - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (z = star_named_expressions_rule(p), 1) // star_named_expressions? - ) - { - D(fprintf(stderr, "%*c+ _tmp_100[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_named_expression ',' star_named_expressions?")); - _res = _PyPegen_seq_insert_in_front ( p , y , z ); - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_100[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_named_expression ',' star_named_expressions?")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_101: yield_expr | named_expression -static void * -_tmp_101_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // yield_expr - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_101[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "yield_expr")); - expr_ty yield_expr_var; - if ( - (yield_expr_var = yield_expr_rule(p)) // yield_expr - ) - { - D(fprintf(stderr, "%*c+ _tmp_101[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "yield_expr")); - _res = yield_expr_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_101[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "yield_expr")); - } - { // named_expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_101[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "named_expression")); - expr_ty named_expression_var; - if ( - (named_expression_var = named_expression_rule(p)) // named_expression - ) - { - D(fprintf(stderr, "%*c+ _tmp_101[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "named_expression")); - _res = named_expression_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_101[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "named_expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_103: ',' double_starred_kvpair -static asdl_seq * -_loop0_103_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' double_starred_kvpair - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_103[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' double_starred_kvpair")); - Token * _literal; - KeyValuePair* elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = double_starred_kvpair_rule(p)) // double_starred_kvpair - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_103[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' double_starred_kvpair")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_103_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_102: double_starred_kvpair _loop0_103 -static asdl_seq * -_gather_102_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // double_starred_kvpair _loop0_103 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_102[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "double_starred_kvpair _loop0_103")); - KeyValuePair* elem; - asdl_seq * seq; - if ( - (elem = double_starred_kvpair_rule(p)) // double_starred_kvpair - && - (seq = _loop0_103_rule(p)) // _loop0_103 - ) - { - D(fprintf(stderr, "%*c+ _gather_102[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "double_starred_kvpair _loop0_103")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_102[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "double_starred_kvpair _loop0_103")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop1_104: for_if_clause -static asdl_seq * -_loop1_104_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // for_if_clause - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_104[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "for_if_clause")); - comprehension_ty for_if_clause_var; - while ( - (for_if_clause_var = for_if_clause_rule(p)) // for_if_clause - ) - { - _res = for_if_clause_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_104[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "for_if_clause")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_104_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_105: ('if' disjunction) -static asdl_seq * -_loop0_105_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ('if' disjunction) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_105[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('if' disjunction)")); - void *_tmp_143_var; - while ( - (_tmp_143_var = _tmp_143_rule(p)) // 'if' disjunction - ) - { - _res = _tmp_143_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_105[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('if' disjunction)")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_105_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_106: ('if' disjunction) -static asdl_seq * -_loop0_106_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ('if' disjunction) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_106[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "('if' disjunction)")); - void *_tmp_144_var; - while ( - (_tmp_144_var = _tmp_144_rule(p)) // 'if' disjunction - ) - { - _res = _tmp_144_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_106[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "('if' disjunction)")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_106_type, _seq); - D(p->level--); - return _seq; -} - -// _tmp_107: ',' args -static void * -_tmp_107_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // ',' args - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_107[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' args")); - Token * _literal; - expr_ty c; - if ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (c = args_rule(p)) // args - ) - { - D(fprintf(stderr, "%*c+ _tmp_107[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' args")); - _res = c; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_107[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' args")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_108: ',' args -static void * -_tmp_108_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // ',' args - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_108[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' args")); - Token * _literal; - expr_ty c; - if ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (c = args_rule(p)) // args - ) - { - D(fprintf(stderr, "%*c+ _tmp_108[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' args")); - _res = c; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_108[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' args")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_110: ',' kwarg_or_starred -static asdl_seq * -_loop0_110_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' kwarg_or_starred - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_110[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' kwarg_or_starred")); - Token * _literal; - KeywordOrStarred* elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_110[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' kwarg_or_starred")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_110_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_109: kwarg_or_starred _loop0_110 -static asdl_seq * -_gather_109_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // kwarg_or_starred _loop0_110 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_109[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kwarg_or_starred _loop0_110")); - KeywordOrStarred* elem; - asdl_seq * seq; - if ( - (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred - && - (seq = _loop0_110_rule(p)) // _loop0_110 - ) - { - D(fprintf(stderr, "%*c+ _gather_109[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kwarg_or_starred _loop0_110")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_109[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kwarg_or_starred _loop0_110")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_112: ',' kwarg_or_double_starred -static asdl_seq * -_loop0_112_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' kwarg_or_double_starred - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_112[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' kwarg_or_double_starred")); - Token * _literal; - KeywordOrStarred* elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_112[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' kwarg_or_double_starred")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_112_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_111: kwarg_or_double_starred _loop0_112 -static asdl_seq * -_gather_111_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // kwarg_or_double_starred _loop0_112 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_111[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kwarg_or_double_starred _loop0_112")); - KeywordOrStarred* elem; - asdl_seq * seq; - if ( - (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred - && - (seq = _loop0_112_rule(p)) // _loop0_112 - ) - { - D(fprintf(stderr, "%*c+ _gather_111[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kwarg_or_double_starred _loop0_112")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_111[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kwarg_or_double_starred _loop0_112")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_114: ',' kwarg_or_starred -static asdl_seq * -_loop0_114_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' kwarg_or_starred - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_114[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' kwarg_or_starred")); - Token * _literal; - KeywordOrStarred* elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_114[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' kwarg_or_starred")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_114_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_113: kwarg_or_starred _loop0_114 -static asdl_seq * -_gather_113_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // kwarg_or_starred _loop0_114 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_113[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kwarg_or_starred _loop0_114")); - KeywordOrStarred* elem; - asdl_seq * seq; - if ( - (elem = kwarg_or_starred_rule(p)) // kwarg_or_starred - && - (seq = _loop0_114_rule(p)) // _loop0_114 - ) - { - D(fprintf(stderr, "%*c+ _gather_113[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kwarg_or_starred _loop0_114")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_113[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kwarg_or_starred _loop0_114")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_116: ',' kwarg_or_double_starred -static asdl_seq * -_loop0_116_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' kwarg_or_double_starred - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_116[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' kwarg_or_double_starred")); - Token * _literal; - KeywordOrStarred* elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_116[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' kwarg_or_double_starred")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_116_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_115: kwarg_or_double_starred _loop0_116 -static asdl_seq * -_gather_115_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // kwarg_or_double_starred _loop0_116 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_115[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "kwarg_or_double_starred _loop0_116")); - KeywordOrStarred* elem; - asdl_seq * seq; - if ( - (elem = kwarg_or_double_starred_rule(p)) // kwarg_or_double_starred - && - (seq = _loop0_116_rule(p)) // _loop0_116 - ) - { - D(fprintf(stderr, "%*c+ _gather_115[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "kwarg_or_double_starred _loop0_116")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_115[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "kwarg_or_double_starred _loop0_116")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_117: (',' star_target) -static asdl_seq * -_loop0_117_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // (',' star_target) - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_117[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "(',' star_target)")); - void *_tmp_145_var; - while ( - (_tmp_145_var = _tmp_145_rule(p)) // ',' star_target - ) - { - _res = _tmp_145_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_117[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "(',' star_target)")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_117_type, _seq); - D(p->level--); - return _seq; -} - -// _loop0_119: ',' star_target -static asdl_seq * -_loop0_119_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' star_target - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_119[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' star_target")); - Token * _literal; - expr_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = star_target_rule(p)) // star_target - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_119[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' star_target")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_119_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_118: star_target _loop0_119 -static asdl_seq * -_gather_118_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // star_target _loop0_119 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_118[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_target _loop0_119")); - expr_ty elem; - asdl_seq * seq; - if ( - (elem = star_target_rule(p)) // star_target - && - (seq = _loop0_119_rule(p)) // _loop0_119 - ) - { - D(fprintf(stderr, "%*c+ _gather_118[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_target _loop0_119")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_118[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_target _loop0_119")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_120: !'*' star_target -static void * -_tmp_120_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // !'*' star_target - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_120[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "!'*' star_target")); - expr_ty star_target_var; - if ( - _PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 16) // token='*' - && - (star_target_var = star_target_rule(p)) // star_target - ) - { - D(fprintf(stderr, "%*c+ _tmp_120[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "!'*' star_target")); - _res = star_target_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_120[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "!'*' star_target")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_122: ',' del_target -static asdl_seq * -_loop0_122_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' del_target - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_122[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' del_target")); - Token * _literal; - expr_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = del_target_rule(p)) // del_target - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_122[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' del_target")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_122_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_121: del_target _loop0_122 -static asdl_seq * -_gather_121_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // del_target _loop0_122 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_121[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "del_target _loop0_122")); - expr_ty elem; - asdl_seq * seq; - if ( - (elem = del_target_rule(p)) // del_target - && - (seq = _loop0_122_rule(p)) // _loop0_122 - ) - { - D(fprintf(stderr, "%*c+ _gather_121[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "del_target _loop0_122")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_121[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "del_target _loop0_122")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_124: ',' target -static asdl_seq * -_loop0_124_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // ',' target - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_124[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' target")); - Token * _literal; - expr_ty elem; - while ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (elem = target_rule(p)) // target - ) - { - _res = elem; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - PyMem_Free(_children); - D(p->level--); - return NULL; - } - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_124[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' target")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_124_type, _seq); - D(p->level--); - return _seq; -} - -// _gather_123: target _loop0_124 -static asdl_seq * -_gather_123_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - asdl_seq * _res = NULL; - int _mark = p->mark; - { // target _loop0_124 - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _gather_123[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "target _loop0_124")); - expr_ty elem; - asdl_seq * seq; - if ( - (elem = target_rule(p)) // target - && - (seq = _loop0_124_rule(p)) // _loop0_124 - ) - { - D(fprintf(stderr, "%*c+ _gather_123[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "target _loop0_124")); - _res = _PyPegen_seq_insert_in_front(p, elem, seq); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _gather_123[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "target _loop0_124")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_125: args | expression for_if_clauses -static void * -_tmp_125_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // args - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_125[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "args")); - expr_ty args_var; - if ( - (args_var = args_rule(p)) // args - ) - { - D(fprintf(stderr, "%*c+ _tmp_125[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "args")); - _res = args_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_125[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "args")); - } - { // expression for_if_clauses - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_125[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression for_if_clauses")); - expr_ty expression_var; - asdl_seq* for_if_clauses_var; - if ( - (expression_var = expression_rule(p)) // expression - && - (for_if_clauses_var = for_if_clauses_rule(p)) // for_if_clauses - ) - { - D(fprintf(stderr, "%*c+ _tmp_125[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression for_if_clauses")); - _res = _PyPegen_dummy_name(p, expression_var, for_if_clauses_var); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_125[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression for_if_clauses")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_126: star_named_expressions -static asdl_seq * -_loop0_126_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // star_named_expressions - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_126[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_named_expressions")); - asdl_seq* star_named_expressions_var; - while ( - (star_named_expressions_var = star_named_expressions_rule(p)) // star_named_expressions - ) - { - _res = star_named_expressions_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_126[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_named_expressions")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_126_type, _seq); - D(p->level--); - return _seq; -} - -// _tmp_127: '=' annotated_rhs -static void * -_tmp_127_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '=' annotated_rhs - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_127[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'=' annotated_rhs")); - Token * _literal; - expr_ty annotated_rhs_var; - if ( - (_literal = _PyPegen_expect_token(p, 22)) // token='=' - && - (annotated_rhs_var = annotated_rhs_rule(p)) // annotated_rhs - ) - { - D(fprintf(stderr, "%*c+ _tmp_127[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'=' annotated_rhs")); - _res = _PyPegen_dummy_name(p, _literal, annotated_rhs_var); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_127[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'=' annotated_rhs")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_128: yield_expr | star_expressions -static void * -_tmp_128_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // yield_expr - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_128[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "yield_expr")); - expr_ty yield_expr_var; - if ( - (yield_expr_var = yield_expr_rule(p)) // yield_expr - ) - { - D(fprintf(stderr, "%*c+ _tmp_128[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "yield_expr")); - _res = yield_expr_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_128[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "yield_expr")); - } - { // star_expressions - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_128[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions")); - expr_ty star_expressions_var; - if ( - (star_expressions_var = star_expressions_rule(p)) // star_expressions - ) - { - D(fprintf(stderr, "%*c+ _tmp_128[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions")); - _res = star_expressions_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_128[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_129: yield_expr | star_expressions -static void * -_tmp_129_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // yield_expr - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_129[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "yield_expr")); - expr_ty yield_expr_var; - if ( - (yield_expr_var = yield_expr_rule(p)) // yield_expr - ) - { - D(fprintf(stderr, "%*c+ _tmp_129[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "yield_expr")); - _res = yield_expr_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_129[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "yield_expr")); - } - { // star_expressions - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_129[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_expressions")); - expr_ty star_expressions_var; - if ( - (star_expressions_var = star_expressions_rule(p)) // star_expressions - ) - { - D(fprintf(stderr, "%*c+ _tmp_129[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_expressions")); - _res = star_expressions_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_129[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_expressions")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_130: '[' | '(' | '{' -static void * -_tmp_130_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '[' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_130[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'['")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 9)) // token='[' - ) - { - D(fprintf(stderr, "%*c+ _tmp_130[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'['")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_130[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'['")); - } - { // '(' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_130[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'('")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 7)) // token='(' - ) - { - D(fprintf(stderr, "%*c+ _tmp_130[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'('")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_130[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'('")); - } - { // '{' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_130[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'{'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 25)) // token='{' - ) - { - D(fprintf(stderr, "%*c+ _tmp_130[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'{'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_130[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'{'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop0_131: param_no_default -static asdl_seq * -_loop0_131_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_no_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop0_131[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_no_default")); - arg_ty param_no_default_var; - while ( - (param_no_default_var = param_no_default_rule(p)) // param_no_default - ) - { - _res = param_no_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop0_131[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_no_default")); - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop0_131_type, _seq); - D(p->level--); - return _seq; -} - -// _tmp_132: slash_with_default | param_with_default+ -static void * -_tmp_132_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // slash_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_132[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "slash_with_default")); - SlashWithDefault* slash_with_default_var; - if ( - (slash_with_default_var = slash_with_default_rule(p)) // slash_with_default - ) - { - D(fprintf(stderr, "%*c+ _tmp_132[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "slash_with_default")); - _res = slash_with_default_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_132[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "slash_with_default")); - } - { // param_with_default+ - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_132[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default+")); - asdl_seq * _loop1_146_var; - if ( - (_loop1_146_var = _loop1_146_rule(p)) // param_with_default+ - ) - { - D(fprintf(stderr, "%*c+ _tmp_132[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "param_with_default+")); - _res = _loop1_146_var; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_132[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default+")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_133: ')' | ',' (')' | '**') -static void * -_tmp_133_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_133[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "')'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ _tmp_133[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "')'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_133[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "')'")); - } - { // ',' (')' | '**') - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_133[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' (')' | '**')")); - Token * _literal; - void *_tmp_147_var; - if ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (_tmp_147_var = _tmp_147_rule(p)) // ')' | '**' - ) - { - D(fprintf(stderr, "%*c+ _tmp_133[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' (')' | '**')")); - _res = _PyPegen_dummy_name(p, _literal, _tmp_147_var); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_133[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' (')' | '**')")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_134: ':' | ',' (':' | '**') -static void * -_tmp_134_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // ':' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_134[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "':'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - ) - { - D(fprintf(stderr, "%*c+ _tmp_134[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "':'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_134[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "':'")); - } - { // ',' (':' | '**') - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_134[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' (':' | '**')")); - Token * _literal; - void *_tmp_148_var; - if ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (_tmp_148_var = _tmp_148_rule(p)) // ':' | '**' - ) - { - D(fprintf(stderr, "%*c+ _tmp_134[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' (':' | '**')")); - _res = _PyPegen_dummy_name(p, _literal, _tmp_148_var); - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_134[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' (':' | '**')")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_135: star_targets '=' -static void * -_tmp_135_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // star_targets '=' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_135[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "star_targets '='")); - Token * _literal; - expr_ty z; - if ( - (z = star_targets_rule(p)) // star_targets - && - (_literal = _PyPegen_expect_token(p, 22)) // token='=' - ) - { - D(fprintf(stderr, "%*c+ _tmp_135[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "star_targets '='")); - _res = z; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_135[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "star_targets '='")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_136: '.' | '...' -static void * -_tmp_136_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '.' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_136[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'.'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 23)) // token='.' - ) - { - D(fprintf(stderr, "%*c+ _tmp_136[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'.'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_136[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'.'")); - } - { // '...' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_136[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'...'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 52)) // token='...' - ) - { - D(fprintf(stderr, "%*c+ _tmp_136[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'...'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_136[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'...'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_137: '.' | '...' -static void * -_tmp_137_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '.' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_137[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'.'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 23)) // token='.' - ) - { - D(fprintf(stderr, "%*c+ _tmp_137[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'.'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_137[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'.'")); - } - { // '...' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_137[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'...'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 52)) // token='...' - ) - { - D(fprintf(stderr, "%*c+ _tmp_137[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'...'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_137[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'...'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_138: '@' named_expression NEWLINE -static void * -_tmp_138_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // '@' named_expression NEWLINE - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_138[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'@' named_expression NEWLINE")); - Token * _literal; - expr_ty f; - Token * newline_var; - if ( - (_literal = _PyPegen_expect_token(p, 49)) // token='@' - && - (f = named_expression_rule(p)) // named_expression - && - (newline_var = _PyPegen_expect_token(p, NEWLINE)) // token='NEWLINE' - ) - { - D(fprintf(stderr, "%*c+ _tmp_138[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'@' named_expression NEWLINE")); - _res = f; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_138[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'@' named_expression NEWLINE")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_139: ',' star_expression -static void * -_tmp_139_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // ',' star_expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_139[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' star_expression")); - Token * _literal; - expr_ty c; - if ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (c = star_expression_rule(p)) // star_expression - ) - { - D(fprintf(stderr, "%*c+ _tmp_139[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' star_expression")); - _res = c; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_139[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' star_expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_140: ',' expression -static void * -_tmp_140_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // ',' expression - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_140[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' expression")); - Token * _literal; - expr_ty c; - if ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (c = expression_rule(p)) // expression - ) - { - D(fprintf(stderr, "%*c+ _tmp_140[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' expression")); - _res = c; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_140[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' expression")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_141: 'or' conjunction -static void * -_tmp_141_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'or' conjunction - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_141[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'or' conjunction")); - Token * _keyword; - expr_ty c; - if ( - (_keyword = _PyPegen_expect_token(p, 532)) // token='or' - && - (c = conjunction_rule(p)) // conjunction - ) - { - D(fprintf(stderr, "%*c+ _tmp_141[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'or' conjunction")); - _res = c; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_141[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'or' conjunction")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_142: 'and' inversion -static void * -_tmp_142_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'and' inversion - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_142[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'and' inversion")); - Token * _keyword; - expr_ty c; - if ( - (_keyword = _PyPegen_expect_token(p, 533)) // token='and' - && - (c = inversion_rule(p)) // inversion - ) - { - D(fprintf(stderr, "%*c+ _tmp_142[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'and' inversion")); - _res = c; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_142[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'and' inversion")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_143: 'if' disjunction -static void * -_tmp_143_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'if' disjunction - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_143[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'if' disjunction")); - Token * _keyword; - expr_ty z; - if ( - (_keyword = _PyPegen_expect_token(p, 510)) // token='if' - && - (z = disjunction_rule(p)) // disjunction - ) - { - D(fprintf(stderr, "%*c+ _tmp_143[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'if' disjunction")); - _res = z; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_143[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'if' disjunction")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_144: 'if' disjunction -static void * -_tmp_144_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // 'if' disjunction - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_144[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'if' disjunction")); - Token * _keyword; - expr_ty z; - if ( - (_keyword = _PyPegen_expect_token(p, 510)) // token='if' - && - (z = disjunction_rule(p)) // disjunction - ) - { - D(fprintf(stderr, "%*c+ _tmp_144[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'if' disjunction")); - _res = z; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_144[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'if' disjunction")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_145: ',' star_target -static void * -_tmp_145_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // ',' star_target - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_145[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "',' star_target")); - Token * _literal; - expr_ty c; - if ( - (_literal = _PyPegen_expect_token(p, 12)) // token=',' - && - (c = star_target_rule(p)) // star_target - ) - { - D(fprintf(stderr, "%*c+ _tmp_145[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "',' star_target")); - _res = c; - if (_res == NULL && PyErr_Occurred()) { - p->error_indicator = 1; - D(p->level--); - return NULL; - } - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_145[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "',' star_target")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _loop1_146: param_with_default -static asdl_seq * -_loop1_146_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void *_res = NULL; - int _mark = p->mark; - int _start_mark = p->mark; - void **_children = PyMem_Malloc(sizeof(void *)); - if (!_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - ssize_t _children_capacity = 1; - ssize_t _n = 0; - { // param_with_default - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _loop1_146[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "param_with_default")); - NameDefaultPair* param_with_default_var; - while ( - (param_with_default_var = param_with_default_rule(p)) // param_with_default - ) - { - _res = param_with_default_var; - if (_n == _children_capacity) { - _children_capacity *= 2; - void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); - if (!_new_children) { - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - _children = _new_children; - } - _children[_n++] = _res; - _mark = p->mark; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _loop1_146[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "param_with_default")); - } - if (_n == 0 || p->error_indicator) { - PyMem_Free(_children); - D(p->level--); - return NULL; - } - asdl_seq *_seq = _Py_asdl_seq_new(_n, p->arena); - if (!_seq) { - PyMem_Free(_children); - p->error_indicator = 1; - PyErr_NoMemory(); - D(p->level--); - return NULL; - } - for (int i = 0; i < _n; i++) asdl_seq_SET(_seq, i, _children[i]); - PyMem_Free(_children); - _PyPegen_insert_memo(p, _start_mark, _loop1_146_type, _seq); - D(p->level--); - return _seq; -} - -// _tmp_147: ')' | '**' -static void * -_tmp_147_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // ')' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_147[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "')'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 8)) // token=')' - ) - { - D(fprintf(stderr, "%*c+ _tmp_147[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "')'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_147[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "')'")); - } - { // '**' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_147[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 35)) // token='**' - ) - { - D(fprintf(stderr, "%*c+ _tmp_147[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_147[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -// _tmp_148: ':' | '**' -static void * -_tmp_148_rule(Parser *p) -{ - D(p->level++); - if (p->error_indicator) { - D(p->level--); - return NULL; - } - void * _res = NULL; - int _mark = p->mark; - { // ':' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_148[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "':'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 11)) // token=':' - ) - { - D(fprintf(stderr, "%*c+ _tmp_148[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "':'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_148[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "':'")); - } - { // '**' - if (p->error_indicator) { - D(p->level--); - return NULL; - } - D(fprintf(stderr, "%*c> _tmp_148[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'**'")); - Token * _literal; - if ( - (_literal = _PyPegen_expect_token(p, 35)) // token='**' - ) - { - D(fprintf(stderr, "%*c+ _tmp_148[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'**'")); - _res = _literal; - goto done; - } - p->mark = _mark; - D(fprintf(stderr, "%*c%s _tmp_148[%d-%d]: %s failed!\n", p->level, ' ', - p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'**'")); - } - _res = NULL; - done: - D(p->level--); - return _res; -} - -void * -_PyPegen_parse(Parser *p) -{ - // Initialize keywords - p->keywords = reserved_keywords; - p->n_keyword_lists = n_keyword_lists; - - // Run parser - void *result = NULL; - if (p->start_rule == Py_file_input) { - result = file_rule(p); - } else if (p->start_rule == Py_single_input) { - result = interactive_rule(p); - } else if (p->start_rule == Py_eval_input) { - result = eval_rule(p); - } else if (p->start_rule == Py_func_type_input) { - result = func_type_rule(p); - } else if (p->start_rule == Py_fstring_input) { - result = fstring_rule(p); - } - - return result; -} - -// The end diff --git a/Parser/pgen/__init__.py b/Parser/pgen/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/Parser/pgen/__main__.py b/Parser/pgen/__main__.py deleted file mode 100644 index d3780a7b77d..00000000000 --- a/Parser/pgen/__main__.py +++ /dev/null @@ -1,43 +0,0 @@ -import argparse - -from .pgen import ParserGenerator - - -def main(): - parser = argparse.ArgumentParser(description="Parser generator main program.") - parser.add_argument( - "grammar", type=str, help="The file with the grammar definition in EBNF format" - ) - parser.add_argument("tokens", type=str, help="The file with the token definitions") - parser.add_argument( - "graminit_h", - type=argparse.FileType("w"), - help="The path to write the grammar's non-terminals as #defines", - ) - parser.add_argument( - "graminit_c", - type=argparse.FileType("w"), - help="The path to write the grammar as initialized data", - ) - - parser.add_argument("--verbose", "-v", action="count") - parser.add_argument( - "--graph", - type=argparse.FileType("w"), - action="store", - metavar="GRAPH_OUTPUT_FILE", - help="Dumps a DOT representation of the generated automata in a file", - ) - - args = parser.parse_args() - - p = ParserGenerator( - args.grammar, args.tokens, verbose=args.verbose, graph_file=args.graph - ) - grammar = p.make_grammar() - grammar.produce_graminit_h(args.graminit_h.write) - grammar.produce_graminit_c(args.graminit_c.write) - - -if __name__ == "__main__": - main() diff --git a/Parser/pgen/automata.py b/Parser/pgen/automata.py deleted file mode 100644 index f2ed221e285..00000000000 --- a/Parser/pgen/automata.py +++ /dev/null @@ -1,400 +0,0 @@ -"""Classes representing state-machine concepts""" - -class NFA: - """A non deterministic finite automata - - A non deterministic automata is a form of a finite state - machine. An NFA's rules are less restrictive than a DFA. - The NFA rules are: - - * A transition can be non-deterministic and can result in - nothing, one, or two or more states. - - * An epsilon transition consuming empty input is valid. - Transitions consuming labeled symbols are also permitted. - - This class assumes that there is only one starting state and one - accepting (ending) state. - - Attributes: - name (str): The name of the rule the NFA is representing. - start (NFAState): The starting state. - end (NFAState): The ending state - """ - - def __init__(self, start, end): - self.name = start.rule_name - self.start = start - self.end = end - - def __repr__(self): - return "NFA(start={}, end={})".format(self.start, self.end) - - def dump(self, writer=print): - """Dump a graphical representation of the NFA""" - todo = [self.start] - for i, state in enumerate(todo): - writer(" State", i, state is self.end and "(final)" or "") - for arc in state.arcs: - label = arc.label - next = arc.target - if next in todo: - j = todo.index(next) - else: - j = len(todo) - todo.append(next) - if label is None: - writer(" -> %d" % j) - else: - writer(" %s -> %d" % (label, j)) - - def dump_graph(self, writer): - """Dump a DOT representation of the NFA""" - writer('digraph %s_nfa {\n' % self.name) - todo = [self.start] - for i, state in enumerate(todo): - writer(' %d [label="State %d %s"];\n' % (i, i, state is self.end and "(final)" or "")) - for arc in state.arcs: - label = arc.label - next = arc.target - if next in todo: - j = todo.index(next) - else: - j = len(todo) - todo.append(next) - if label is None: - writer(" %d -> %d [style=dotted label=ε];\n" % (i, j)) - else: - writer(" %d -> %d [label=%s];\n" % (i, j, label.replace("'", '"'))) - writer('}\n') - - -class NFAArc: - """An arc representing a transition between two NFA states. - - NFA states can be connected via two ways: - - * A label transition: An input equal to the label must - be consumed to perform the transition. - * An epsilon transition: The transition can be taken without - consuming any input symbol. - - Attributes: - target (NFAState): The ending state of the transition arc. - label (Optional[str]): The label that must be consumed to make - the transition. An epsilon transition is represented - using `None`. - """ - - def __init__(self, target, label): - self.target = target - self.label = label - - def __repr__(self): - return "<%s: %s>" % (self.__class__.__name__, self.label) - - -class NFAState: - """A state of a NFA, non deterministic finite automata. - - Attributes: - target (rule_name): The name of the rule used to represent the NFA's - ending state after a transition. - arcs (Dict[Optional[str], NFAState]): A mapping representing transitions - between the current NFA state and another NFA state via following - a label. - """ - - def __init__(self, rule_name): - self.rule_name = rule_name - self.arcs = [] - - def add_arc(self, target, label=None): - """Add a new arc to connect the state to a target state within the NFA - - The method adds a new arc to the list of arcs available as transitions - from the present state. An optional label indicates a named transition - that consumes an input while the absence of a label represents an epsilon - transition. - - Attributes: - target (NFAState): The end of the transition that the arc represents. - label (Optional[str]): The label that must be consumed for making - the transition. If the label is not provided the transition is assumed - to be an epsilon-transition. - """ - assert label is None or isinstance(label, str) - assert isinstance(target, NFAState) - self.arcs.append(NFAArc(target, label)) - - def __repr__(self): - return "<%s: from %s>" % (self.__class__.__name__, self.rule_name) - - -class DFA: - """A deterministic finite automata - - A deterministic finite automata is a form of a finite state machine - that obeys the following rules: - - * Each of the transitions is uniquely determined by - the source state and input symbol - * Reading an input symbol is required for each state - transition (no epsilon transitions). - - The finite-state machine will accept or reject a string of symbols - and only produces a unique computation of the automaton for each input - string. The DFA must have a unique starting state (represented as the first - element in the list of states) but can have multiple final states. - - Attributes: - name (str): The name of the rule the DFA is representing. - states (List[DFAState]): A collection of DFA states. - """ - - def __init__(self, name, states): - self.name = name - self.states = states - - @classmethod - def from_nfa(cls, nfa): - """Constructs a DFA from a NFA using the Rabin–Scott construction algorithm. - - To simulate the operation of a DFA on a given input string, it's - necessary to keep track of a single state at any time, or more precisely, - the state that the automaton will reach after seeing a prefix of the - input. In contrast, to simulate an NFA, it's necessary to keep track of - a set of states: all of the states that the automaton could reach after - seeing the same prefix of the input, according to the nondeterministic - choices made by the automaton. There are two possible sources of - non-determinism: - - 1) Multiple (one or more) transitions with the same label - - 'A' +-------+ - +----------->+ State +----------->+ - | | 2 | - +-------+ +-------+ - | State | - | 1 | +-------+ - +-------+ | State | - +----------->+ 3 +----------->+ - 'A' +-------+ - - 2) Epsilon transitions (transitions that can be taken without consuming any input) - - +-------+ +-------+ - | State | ε | State | - | 1 +----------->+ 2 +----------->+ - +-------+ +-------+ - - Looking at the first case above, we can't determine which transition should be - followed when given an input A. We could choose whether or not to follow the - transition while in the second case the problem is that we can choose both to - follow the transition or not doing it. To solve this problem we can imagine that - we follow all possibilities at the same time and we construct new states from the - set of all possible reachable states. For every case in the previous example: - - - 1) For multiple transitions with the same label we colapse all of the - final states under the same one - - +-------+ +-------+ - | State | 'A' | State | - | 1 +----------->+ 2-3 +----------->+ - +-------+ +-------+ - - 2) For epsilon transitions we collapse all epsilon-reachable states - into the same one - - +-------+ - | State | - | 1-2 +-----------> - +-------+ - - Because the DFA states consist of sets of NFA states, an n-state NFA - may be converted to a DFA with at most 2**n states. Notice that the - constructed DFA is not minimal and can be simplified or reduced - afterwards. - - Parameters: - name (NFA): The NFA to transform to DFA. - """ - assert isinstance(nfa, NFA) - - def add_closure(nfa_state, base_nfa_set): - """Calculate the epsilon-closure of a given state - - Add to the *base_nfa_set* all the states that are - reachable from *nfa_state* via epsilon-transitions. - """ - assert isinstance(nfa_state, NFAState) - if nfa_state in base_nfa_set: - return - base_nfa_set.add(nfa_state) - for nfa_arc in nfa_state.arcs: - if nfa_arc.label is None: - add_closure(nfa_arc.target, base_nfa_set) - - # Calculate the epsilon-closure of the starting state - base_nfa_set = set() - add_closure(nfa.start, base_nfa_set) - - # Start by visiting the NFA starting state (there is only one). - states = [DFAState(nfa.name, base_nfa_set, nfa.end)] - - for state in states: # NB states grow while we're iterating - - # Find transitions from the current state to other reachable states - # and store them in mapping that correlates the label to all the - # possible reachable states that can be obtained by consuming a - # token equal to the label. Each set of all the states that can - # be reached after following a label will be the a DFA state. - arcs = {} - for nfa_state in state.nfa_set: - for nfa_arc in nfa_state.arcs: - if nfa_arc.label is not None: - nfa_set = arcs.setdefault(nfa_arc.label, set()) - # All states that can be reached by epsilon-transitions - # are also included in the set of reachable states. - add_closure(nfa_arc.target, nfa_set) - - # Now create new DFAs by visiting all posible transitions between - # the current DFA state and the new power-set states (each nfa_set) - # via the different labels. As the nodes are appended to *states* this - # is performing a breadth-first search traversal over the power-set of - # the states of the original NFA. - for label, nfa_set in sorted(arcs.items()): - for exisisting_state in states: - if exisisting_state.nfa_set == nfa_set: - # The DFA state already exists for this rule. - next_state = exisisting_state - break - else: - next_state = DFAState(nfa.name, nfa_set, nfa.end) - states.append(next_state) - - # Add a transition between the current DFA state and the new - # DFA state (the power-set state) via the current label. - state.add_arc(next_state, label) - - return cls(nfa.name, states) - - def __iter__(self): - return iter(self.states) - - def simplify(self): - """Attempt to reduce the number of states of the DFA - - Transform the DFA into an equivalent DFA that has fewer states. Two - classes of states can be removed or merged from the original DFA without - affecting the language it accepts to minimize it: - - * Unreachable states can not be reached from the initial - state of the DFA, for any input string. - * Nondistinguishable states are those that cannot be distinguished - from one another for any input string. - - This algorithm does not achieve the optimal fully-reduced solution, but it - works well enough for the particularities of the Python grammar. The - algorithm repeatedly looks for two states that have the same set of - arcs (same labels pointing to the same nodes) and unifies them, until - things stop changing. - """ - changes = True - while changes: - changes = False - for i, state_i in enumerate(self.states): - for j in range(i + 1, len(self.states)): - state_j = self.states[j] - if state_i == state_j: - del self.states[j] - for state in self.states: - state.unifystate(state_j, state_i) - changes = True - break - - def dump(self, writer=print): - """Dump a graphical representation of the DFA""" - for i, state in enumerate(self.states): - writer(" State", i, state.is_final and "(final)" or "") - for label, next in sorted(state.arcs.items()): - writer(" %s -> %d" % (label, self.states.index(next))) - - def dump_graph(self, writer): - """Dump a DOT representation of the DFA""" - writer('digraph %s_dfa {\n' % self.name) - for i, state in enumerate(self.states): - writer(' %d [label="State %d %s"];\n' % (i, i, state.is_final and "(final)" or "")) - for label, next in sorted(state.arcs.items()): - writer(" %d -> %d [label=%s];\n" % (i, self.states.index(next), label.replace("'", '"'))) - writer('}\n') - - -class DFAState(object): - """A state of a DFA - - Attributes: - rule_name (rule_name): The name of the DFA rule containing the represented state. - nfa_set (Set[NFAState]): The set of NFA states used to create this state. - final (bool): True if the state represents an accepting state of the DFA - containing this state. - arcs (Dict[label, DFAState]): A mapping representing transitions between - the current DFA state and another DFA state via following a label. - """ - - def __init__(self, rule_name, nfa_set, final): - assert isinstance(nfa_set, set) - assert isinstance(next(iter(nfa_set)), NFAState) - assert isinstance(final, NFAState) - self.rule_name = rule_name - self.nfa_set = nfa_set - self.arcs = {} # map from terminals/nonterminals to DFAState - self.is_final = final in nfa_set - - def add_arc(self, target, label): - """Add a new arc to the current state. - - Parameters: - target (DFAState): The DFA state at the end of the arc. - label (str): The label respresenting the token that must be consumed - to perform this transition. - """ - assert isinstance(label, str) - assert label not in self.arcs - assert isinstance(target, DFAState) - self.arcs[label] = target - - def unifystate(self, old, new): - """Replace all arcs from the current node to *old* with *new*. - - Parameters: - old (DFAState): The DFA state to remove from all existing arcs. - new (DFAState): The DFA state to replace in all existing arcs. - """ - for label, next_ in self.arcs.items(): - if next_ is old: - self.arcs[label] = new - - def __eq__(self, other): - # The nfa_set does not matter for equality - assert isinstance(other, DFAState) - if self.is_final != other.is_final: - return False - # We cannot just return self.arcs == other.arcs because that - # would invoke this method recursively if there are any cycles. - if len(self.arcs) != len(other.arcs): - return False - for label, next_ in self.arcs.items(): - if next_ is not other.arcs.get(label): - return False - return True - - __hash__ = None # For Py3 compatibility. - - def __repr__(self): - return "<%s: %s is_final=%s>" % ( - self.__class__.__name__, - self.rule_name, - self.is_final, - ) diff --git a/Parser/pgen/grammar.py b/Parser/pgen/grammar.py deleted file mode 100644 index ce40e160ca8..00000000000 --- a/Parser/pgen/grammar.py +++ /dev/null @@ -1,147 +0,0 @@ -import collections - - -class Grammar: - """Pgen parsing tables class. - - The instance variables are as follows: - - symbol2number -- a dict mapping symbol names to numbers. Symbol - numbers are always 256 or higher, to distinguish - them from token numbers, which are between 0 and - 255 (inclusive). - - number2symbol -- a dict mapping numbers to symbol names; - these two are each other's inverse. - - states -- a list of DFAs, where each DFA is a list of - states, each state is a list of arcs, and each - arc is a (i, j) pair where i is a label and j is - a state number. The DFA number is the index into - this list. (This name is slightly confusing.) - Final states are represented by a special arc of - the form (0, j) where j is its own state number. - - dfas -- a dict mapping symbol numbers to (DFA, first) - pairs, where DFA is an item from the states list - above, and first is a set of tokens that can - begin this grammar rule. - - labels -- a list of (x, y) pairs where x is either a token - number or a symbol number, and y is either None - or a string; the strings are keywords. The label - number is the index in this list; label numbers - are used to mark state transitions (arcs) in the - DFAs. - - start -- the number of the grammar's start symbol. - - keywords -- a dict mapping keyword strings to arc labels. - - tokens -- a dict mapping token numbers to arc labels. - - """ - - def __init__(self): - self.symbol2number = collections.OrderedDict() - self.number2symbol = collections.OrderedDict() - self.states = [] - self.dfas = collections.OrderedDict() - self.labels = [(0, "EMPTY")] - self.keywords = collections.OrderedDict() - self.tokens = collections.OrderedDict() - self.symbol2label = collections.OrderedDict() - self.start = 256 - - def produce_graminit_h(self, writer): - writer("/* Generated by Parser/pgen */\n\n") - for number, symbol in self.number2symbol.items(): - writer("#define {} {}\n".format(symbol, number)) - - def produce_graminit_c(self, writer): - writer("/* Generated by Parser/pgen */\n\n") - - writer('#include "exports.h"\n') - writer('#include "grammar.h"\n') - writer("Py_EXPORTED_SYMBOL grammar _PyParser_Grammar;\n") - - self.print_dfas(writer) - self.print_labels(writer) - - writer("Py_EXPORTED_SYMBOL grammar _PyParser_Grammar = {\n") - writer(" {n_dfas},\n".format(n_dfas=len(self.dfas))) - writer(" dfas,\n") - writer(" {{{n_labels}, labels}},\n".format(n_labels=len(self.labels))) - writer(" {start_number}\n".format(start_number=self.start)) - writer("};\n") - - def print_labels(self, writer): - writer( - "static const label labels[{n_labels}] = {{\n".format( - n_labels=len(self.labels) - ) - ) - for label, name in self.labels: - label_name = '"{}"'.format(name) if name is not None else 0 - writer( - " {{{label}, {label_name}}},\n".format( - label=label, label_name=label_name - ) - ) - writer("};\n") - - def print_dfas(self, writer): - self.print_states(writer) - writer("static const dfa dfas[{}] = {{\n".format(len(self.dfas))) - for dfaindex, dfa_elem in enumerate(self.dfas.items()): - symbol, (dfa, first_sets) = dfa_elem - writer( - ' {{{dfa_symbol}, "{symbol_name}", '.format( - dfa_symbol=symbol, symbol_name=self.number2symbol[symbol] - ) - + "{n_states}, states_{dfa_index},\n".format( - n_states=len(dfa), dfa_index=dfaindex - ) - + ' "' - ) - - bitset = bytearray((len(self.labels) >> 3) + 1) - for token in first_sets: - bitset[token >> 3] |= 1 << (token & 7) - for byte in bitset: - writer("\\%03o" % (byte & 0xFF)) - writer('"},\n') - writer("};\n") - - def print_states(self, write): - for dfaindex, dfa in enumerate(self.states): - self.print_arcs(write, dfaindex, dfa) - write( - "static state states_{dfa_index}[{n_states}] = {{\n".format( - dfa_index=dfaindex, n_states=len(dfa) - ) - ) - for stateindex, state in enumerate(dfa): - narcs = len(state) - write( - " {{{n_arcs}, arcs_{dfa_index}_{state_index}}},\n".format( - n_arcs=narcs, dfa_index=dfaindex, state_index=stateindex - ) - ) - write("};\n") - - def print_arcs(self, write, dfaindex, states): - for stateindex, state in enumerate(states): - narcs = len(state) - write( - "static const arc arcs_{dfa_index}_{state_index}[{n_arcs}] = {{\n".format( - dfa_index=dfaindex, state_index=stateindex, n_arcs=narcs - ) - ) - for a, b in state: - write( - " {{{from_label}, {to_state}}},\n".format( - from_label=a, to_state=b - ) - ) - write("};\n") diff --git a/Parser/pgen/keywordgen.py b/Parser/pgen/keywordgen.py deleted file mode 100644 index f0234a81b62..00000000000 --- a/Parser/pgen/keywordgen.py +++ /dev/null @@ -1,59 +0,0 @@ -"""Generate Lib/keyword.py from the Grammar and Tokens files using pgen""" - -import argparse - -from .pgen import ParserGenerator - -TEMPLATE = r''' -"""Keywords (from "Grammar/Grammar") - -This file is automatically generated; please don't muck it up! - -To update the symbols in this file, 'cd' to the top directory of -the python source tree and run: - - python3 -m Parser.pgen.keywordgen Grammar/Grammar \ - Grammar/Tokens \ - Lib/keyword.py - -Alternatively, you can run 'make regen-keyword'. -""" - -__all__ = ["iskeyword", "kwlist"] - -kwlist = [ - {keywords} -] - -iskeyword = frozenset(kwlist).__contains__ -'''.lstrip() - -EXTRA_KEYWORDS = ["async", "await"] - - -def main(): - parser = argparse.ArgumentParser( - description="Generate the Lib/keywords.py " "file from the grammar." - ) - parser.add_argument( - "grammar", type=str, help="The file with the grammar definition in EBNF format" - ) - parser.add_argument("tokens", type=str, help="The file with the token definitions") - parser.add_argument( - "keyword_file", - type=argparse.FileType("w"), - help="The path to write the keyword definitions", - ) - args = parser.parse_args() - p = ParserGenerator(args.grammar, args.tokens) - grammar = p.make_grammar() - - with args.keyword_file as thefile: - all_keywords = sorted(list(grammar.keywords) + EXTRA_KEYWORDS) - - keywords = ",\n ".join(map(repr, all_keywords)) - thefile.write(TEMPLATE.format(keywords=keywords)) - - -if __name__ == "__main__": - main() diff --git a/Parser/pgen/metaparser.py b/Parser/pgen/metaparser.py deleted file mode 100644 index 074a083fb74..00000000000 --- a/Parser/pgen/metaparser.py +++ /dev/null @@ -1,152 +0,0 @@ -"""Parser for the Python metagrammar""" - -import io -import tokenize # from stdlib - -from .automata import NFA, NFAState - - -class GrammarParser: - """Parser for Python grammar files.""" - - _translation_table = { - tokenize.NAME: "NAME", - tokenize.STRING: "STRING", - tokenize.NEWLINE: "NEWLINE", - tokenize.NL: "NL", - tokenize.OP: "OP", - tokenize.ENDMARKER: "ENDMARKER", - tokenize.COMMENT: "COMMENT", - } - - def __init__(self, grammar): - self.grammar = grammar - grammar_adaptor = io.StringIO(grammar) - self.generator = tokenize.generate_tokens(grammar_adaptor.readline) - self._gettoken() # Initialize lookahead - self._current_rule_name = None - - def parse(self): - """Turn the grammar into a collection of NFAs""" - # grammar: (NEWLINE | rule)* ENDMARKER - while self.type != tokenize.ENDMARKER: - while self.type == tokenize.NEWLINE: - self._gettoken() - # rule: NAME ':' rhs NEWLINE - self._current_rule_name = self._expect(tokenize.NAME) - self._expect(tokenize.OP, ":") - a, z = self._parse_rhs() - self._expect(tokenize.NEWLINE) - - yield NFA(a, z) - - def _parse_rhs(self): - # rhs: items ('|' items)* - a, z = self._parse_items() - if self.value != "|": - return a, z - else: - aa = NFAState(self._current_rule_name) - zz = NFAState(self._current_rule_name) - while True: - # Allow to transit directly to the previous state and connect the end of the - # previous state to the end of the current one, effectively allowing to skip - # the current state. - aa.add_arc(a) - z.add_arc(zz) - if self.value != "|": - break - - self._gettoken() - a, z = self._parse_items() - return aa, zz - - def _parse_items(self): - # items: item+ - a, b = self._parse_item() - while self.type in (tokenize.NAME, tokenize.STRING) or self.value in ("(", "["): - c, d = self._parse_item() - # Allow a transition between the end of the previous state - # and the beginning of the new one, connecting all the items - # together. In this way we can only reach the end if we visit - # all the items. - b.add_arc(c) - b = d - return a, b - - def _parse_item(self): - # item: '[' rhs ']' | atom ['+' | '*'] - if self.value == "[": - self._gettoken() - a, z = self._parse_rhs() - self._expect(tokenize.OP, "]") - # Make a transition from the beginning to the end so it is possible to - # advance for free to the next state of this item # without consuming - # anything from the rhs. - a.add_arc(z) - return a, z - else: - a, z = self._parse_atom() - value = self.value - if value not in ("+", "*"): - return a, z - self._gettoken() - z.add_arc(a) - if value == "+": - # Create a cycle to the beginning so we go back to the old state in this - # item and repeat. - return a, z - else: - # The end state is the same as the beginning, so we can cycle arbitrarily - # and end in the beginning if necessary. - return a, a - - def _parse_atom(self): - # atom: '(' rhs ')' | NAME | STRING - if self.value == "(": - self._gettoken() - a, z = self._parse_rhs() - self._expect(tokenize.OP, ")") - return a, z - elif self.type in (tokenize.NAME, tokenize.STRING): - a = NFAState(self._current_rule_name) - z = NFAState(self._current_rule_name) - # We can transit to the next state only if we consume the value. - a.add_arc(z, self.value) - self._gettoken() - return a, z - else: - self._raise_error( - "expected (...) or NAME or STRING, got {} ({})", - self._translation_table.get(self.type, self.type), - self.value, - ) - - def _expect(self, type_, value=None): - if self.type != type_: - self._raise_error( - "expected {}, got {} ({})", - self._translation_table.get(type_, type_), - self._translation_table.get(self.type, self.type), - self.value, - ) - if value is not None and self.value != value: - self._raise_error("expected {}, got {}", value, self.value) - value = self.value - self._gettoken() - return value - - def _gettoken(self): - tup = next(self.generator) - while tup[0] in (tokenize.COMMENT, tokenize.NL): - tup = next(self.generator) - self.type, self.value, self.begin, self.end, self.line = tup - - def _raise_error(self, msg, *args): - if args: - try: - msg = msg.format(*args) - except Exception: - msg = " ".join([msg] + list(map(str, args))) - line = self.grammar.splitlines()[self.begin[0] - 1] - raise SyntaxError(msg, ("", self.begin[0], self.begin[1], line)) diff --git a/Parser/pgen/pgen.py b/Parser/pgen/pgen.py deleted file mode 100644 index 03032d4ed8c..00000000000 --- a/Parser/pgen/pgen.py +++ /dev/null @@ -1,310 +0,0 @@ -"""Python parser generator - - -This parser generator transforms a Python grammar file into parsing tables -that can be consumed by Python's LL(1) parser written in C. - -Concepts --------- - -* An LL(1) parser (Left-to-right, Leftmost derivation, 1 token-lookahead) is a - top-down parser for a subset of context-free languages. It parses the input - from Left to right, performing Leftmost derivation of the sentence, and can - only use 1 token of lookahead when parsing a sentence. - -* A parsing table is a collection of data that a generic implementation of the - LL(1) parser consumes to know how to parse a given context-free grammar. In - this case the collection of data involves Deterministic Finite Automatons, - calculated first sets, keywords and transition labels. - -* A grammar is defined by production rules (or just 'productions') that specify - which symbols may replace which other symbols; these rules may be used to - generate strings, or to parse them. Each such rule has a head, or left-hand - side, which consists of the string that may be replaced, and a body, or - right-hand side, which consists of a string that may replace it. In the - Python grammar, rules are written in the form - - rule_name: rule_description; - - meaning the rule 'a: b' specifies that a can be replaced by b. A context-free - grammar is a grammar in which the left-hand side of each production rule - consists of only a single nonterminal symbol. Context-free grammars can - always be recognized by a Non-Deterministic Automatons. - -* Terminal symbols are literal symbols which may appear in the outputs of the - production rules of the grammar and which cannot be changed using the rules - of the grammar. Applying the rules recursively to a source string of symbols - will usually terminate in a final output string consisting only of terminal - symbols. - -* Nonterminal symbols are those symbols which can be replaced. The grammar - includes a start symbol a designated member of the set of nonterminals from - which all the strings in the language may be derived by successive - applications of the production rules. - -* The language defined by the grammar is defined as the set of terminal strings - that can be derived using the production rules. - -* The first sets of a rule (FIRST(rule)) are defined to be the set of terminals - that can appear in the first position of any string derived from the rule. - This is useful for LL(1) parsers as the parser is only allowed to look at the - next token in the input to know which rule needs to parse. For example, given - this grammar: - - start: '(' A | B ')' - A: 'a' '<' - B: 'b' '<' - - and the input '(b<)' the parser can only look at 'b' to know if it needs - to parse A o B. Because FIRST(A) = {'a'} and FIRST(B) = {'b'} it knows - that needs to continue parsing rule B because only that rule can start - with 'b'. - -Description ------------ - -The input for the parser generator is a grammar in extended BNF form (using * -for repetition, + for at-least-once repetition, [] for optional parts, | for -alternatives and () for grouping). - -Each rule in the grammar file is considered as a regular expression in its -own right. It is turned into a Non-deterministic Finite Automaton (NFA), -which is then turned into a Deterministic Finite Automaton (DFA), which is -then optimized to reduce the number of states. See [Aho&Ullman 77] chapter 3, -or similar compiler books (this technique is more often used for lexical -analyzers). - -The DFA's are used by the parser as parsing tables in a special way that's -probably unique. Before they are usable, the FIRST sets of all non-terminals -are computed so the LL(1) parser consuming the parsing tables can distinguish -between different transitions. -Reference ---------- - -[Aho&Ullman 77] - Aho&Ullman, Principles of Compiler Design, Addison-Wesley 1977 - (first edition) -""" - -from ast import literal_eval -import collections - -from . import grammar, token -from .automata import DFA -from .metaparser import GrammarParser - -import enum - - -class LabelType(enum.Enum): - NONTERMINAL = 0 - NAMED_TOKEN = 1 - KEYWORD = 2 - OPERATOR = 3 - NONE = 4 - - -class Label(str): - def __init__(self, value): - self.type = self._get_type() - - def _get_type(self): - if self[0].isalpha(): - if self.upper() == self: - # NAMED tokens (ASYNC, NAME...) are all uppercase by convention - return LabelType.NAMED_TOKEN - else: - # If is not uppercase it must be a non terminal. - return LabelType.NONTERMINAL - else: - # Keywords and operators are wrapped in quotes - assert self[0] == self[-1] in ('"', "'"), self - value = literal_eval(self) - if value[0].isalpha(): - return LabelType.KEYWORD - else: - return LabelType.OPERATOR - - def __repr__(self): - return "{}({})".format(self.type, super().__repr__()) - - -class ParserGenerator(object): - def __init__(self, grammar_file, token_file, verbose=False, graph_file=None): - with open(grammar_file) as f: - self.grammar = f.read() - with open(token_file) as tok_file: - token_lines = tok_file.readlines() - self.tokens = dict(token.generate_tokens(token_lines)) - self.opmap = dict(token.generate_opmap(token_lines)) - # Manually add <> so it does not collide with != - self.opmap["<>"] = "NOTEQUAL" - self.verbose = verbose - self.filename = grammar_file - self.graph_file = graph_file - self.dfas, self.startsymbol = self.create_dfas() - self.first = {} # map from symbol name to set of tokens - self.calculate_first_sets() - - def create_dfas(self): - rule_to_dfas = collections.OrderedDict() - start_nonterminal = None - for nfa in GrammarParser(self.grammar).parse(): - if self.verbose: - print("Dump of NFA for", nfa.name) - nfa.dump() - if self.graph_file is not None: - nfa.dump_graph(self.graph_file.write) - dfa = DFA.from_nfa(nfa) - if self.verbose: - print("Dump of DFA for", dfa.name) - dfa.dump() - dfa.simplify() - if self.graph_file is not None: - dfa.dump_graph(self.graph_file.write) - rule_to_dfas[dfa.name] = dfa - - if start_nonterminal is None: - start_nonterminal = dfa.name - - return rule_to_dfas, start_nonterminal - - def make_grammar(self): - c = grammar.Grammar() - c.all_labels = set() - names = list(self.dfas.keys()) - names.remove(self.startsymbol) - names.insert(0, self.startsymbol) - for name in names: - i = 256 + len(c.symbol2number) - c.symbol2number[Label(name)] = i - c.number2symbol[i] = Label(name) - c.all_labels.add(name) - for name in names: - self.make_label(c, name) - dfa = self.dfas[name] - states = [] - for state in dfa: - arcs = [] - for label, next in sorted(state.arcs.items()): - c.all_labels.add(label) - arcs.append((self.make_label(c, label), dfa.states.index(next))) - if state.is_final: - arcs.append((0, dfa.states.index(state))) - states.append(arcs) - c.states.append(states) - c.dfas[c.symbol2number[name]] = (states, self.make_first_sets(c, name)) - c.start = c.symbol2number[self.startsymbol] - - if self.verbose: - print("") - print("Grammar summary") - print("===============") - - print("- {n_labels} labels".format(n_labels=len(c.labels))) - print("- {n_dfas} dfas".format(n_dfas=len(c.dfas))) - print("- {n_tokens} tokens".format(n_tokens=len(c.tokens))) - print("- {n_keywords} keywords".format(n_keywords=len(c.keywords))) - print( - "- Start symbol: {start_symbol}".format( - start_symbol=c.number2symbol[c.start] - ) - ) - return c - - def make_first_sets(self, c, name): - rawfirst = self.first[name] - first = set() - for label in sorted(rawfirst): - ilabel = self.make_label(c, label) - ##assert ilabel not in first # XXX failed on <> ... != - first.add(ilabel) - return first - - def make_label(self, c, label): - label = Label(label) - ilabel = len(c.labels) - - if label.type == LabelType.NONTERMINAL: - if label in c.symbol2label: - return c.symbol2label[label] - else: - c.labels.append((c.symbol2number[label], None)) - c.symbol2label[label] = ilabel - return ilabel - elif label.type == LabelType.NAMED_TOKEN: - # A named token (NAME, NUMBER, STRING) - itoken = self.tokens.get(label, None) - assert isinstance(itoken, int), label - assert itoken in self.tokens.values(), label - if itoken in c.tokens: - return c.tokens[itoken] - else: - c.labels.append((itoken, None)) - c.tokens[itoken] = ilabel - return ilabel - elif label.type == LabelType.KEYWORD: - # A keyword - value = literal_eval(label) - if value in c.keywords: - return c.keywords[value] - else: - c.labels.append((self.tokens["NAME"], value)) - c.keywords[value] = ilabel - return ilabel - elif label.type == LabelType.OPERATOR: - # An operator (any non-numeric token) - value = literal_eval(label) - tok_name = self.opmap[value] # Fails if unknown token - itoken = self.tokens[tok_name] - if itoken in c.tokens: - return c.tokens[itoken] - else: - c.labels.append((itoken, None)) - c.tokens[itoken] = ilabel - return ilabel - else: - raise ValueError("Cannot categorize label {}".format(label)) - - def calculate_first_sets(self): - names = list(self.dfas.keys()) - for name in names: - if name not in self.first: - self.calculate_first_sets_for_rule(name) - - if self.verbose: - print("First set for {dfa_name}".format(dfa_name=name)) - for item in self.first[name]: - print(" - {terminal}".format(terminal=item)) - - def calculate_first_sets_for_rule(self, name): - dfa = self.dfas[name] - self.first[name] = None # dummy to detect left recursion - state = dfa.states[0] - totalset = set() - overlapcheck = {} - for label, next in state.arcs.items(): - if label in self.dfas: - if label in self.first: - fset = self.first[label] - if fset is None: - raise ValueError("recursion for rule %r" % name) - else: - self.calculate_first_sets_for_rule(label) - fset = self.first[label] - totalset.update(fset) - overlapcheck[label] = fset - else: - totalset.add(label) - overlapcheck[label] = {label} - inverse = {} - for label, itsfirst in overlapcheck.items(): - for symbol in itsfirst: - if symbol in inverse: - raise ValueError( - "rule %s is ambiguous; %s is in the" - " first sets of %s as well as %s" - % (name, symbol, label, inverse[symbol]) - ) - inverse[symbol] = label - self.first[name] = totalset diff --git a/Parser/pgen/token.py b/Parser/pgen/token.py deleted file mode 100644 index 2cff62ce3b2..00000000000 --- a/Parser/pgen/token.py +++ /dev/null @@ -1,38 +0,0 @@ -import itertools - - -def generate_tokens(tokens): - numbers = itertools.count(0) - for line in tokens: - line = line.strip() - - if not line or line.startswith("#"): - continue - - name = line.split()[0] - yield (name, next(numbers)) - - yield ("N_TOKENS", next(numbers)) - yield ("NT_OFFSET", 256) - - -def generate_opmap(tokens): - for line in tokens: - line = line.strip() - - if not line or line.startswith("#"): - continue - - pieces = line.split() - - if len(pieces) != 2: - continue - - name, op = pieces - yield (op.strip("'"), name) - - # Yield independently <>. This is needed so it does not collide - # with the token generation in "generate_tokens" because if this - # symbol is included in Grammar/Tokens, it will collide with != - # as it has the same name (NOTEQUAL). - yield ("<>", "NOTEQUAL") diff --git a/Parser/pegen/parse_string.c b/Parser/string_parser.c similarity index 75% rename from Parser/pegen/parse_string.c rename to Parser/string_parser.c index a0ec698fa56..9f56ce21d0f 100644 --- a/Parser/pegen/parse_string.c +++ b/Parser/string_parser.c @@ -1,16 +1,11 @@ #include -#include "../tokenizer.h" +#include "tokenizer.h" #include "pegen.h" -#include "parse_string.h" +#include "string_parser.h" //// STRING HANDLING FUNCTIONS //// -// These functions are ported directly from Python/ast.c with some modifications -// to account for the use of "Parser *p", the fact that don't have parser nodes -// to pass around and the usage of some specialized APIs present only in this -// file (like "_PyPegen_raise_syntax_error"). - static int warn_invalid_escape_sequence(Parser *p, unsigned char first_invalid_escape_char, Token *t) { @@ -42,7 +37,8 @@ warn_invalid_escape_sequence(Parser *p, unsigned char first_invalid_escape_char, static PyObject * decode_utf8(const char **sPtr, const char *end) { - const char *s, *t; + const char *s; + const char *t; t = s = *sPtr; while (s < end && (*s & 0x80)) { s++; @@ -54,7 +50,8 @@ decode_utf8(const char **sPtr, const char *end) static PyObject * decode_unicode_with_escapes(Parser *parser, const char *s, size_t len, Token *t) { - PyObject *v, *u; + PyObject *v; + PyObject *u; char *buf; char *p; const char *end; @@ -86,7 +83,8 @@ decode_unicode_with_escapes(Parser *parser, const char *s, size_t len, Token *t) PyObject *w; int kind; void *data; - Py_ssize_t len, i; + Py_ssize_t w_len; + Py_ssize_t i; w = decode_utf8(&s, end); if (w == NULL) { Py_DECREF(u); @@ -94,8 +92,8 @@ decode_unicode_with_escapes(Parser *parser, const char *s, size_t len, Token *t) } kind = PyUnicode_KIND(w); data = PyUnicode_DATA(w); - len = PyUnicode_GET_LENGTH(w); - for (i = 0; i < len; i++) { + w_len = PyUnicode_GET_LENGTH(w); + for (i = 0; i < w_len; i++) { Py_UCS4 chr = PyUnicode_READ(kind, data, i); sprintf(p, "\\U%08x", chr); p += 10; @@ -169,18 +167,18 @@ _PyPegen_parsestr(Parser *p, int *bytesmode, int *rawmode, PyObject **result, if (Py_ISALPHA(quote)) { while (!*bytesmode || !*rawmode) { if (quote == 'b' || quote == 'B') { - quote = *++s; + quote =(unsigned char)*++s; *bytesmode = 1; } else if (quote == 'u' || quote == 'U') { - quote = *++s; + quote = (unsigned char)*++s; } else if (quote == 'r' || quote == 'R') { - quote = *++s; + quote = (unsigned char)*++s; *rawmode = 1; } else if (quote == 'f' || quote == 'F') { - quote = *++s; + quote = (unsigned char)*++s; fmode = 1; } else { @@ -273,232 +271,6 @@ _PyPegen_parsestr(Parser *p, int *bytesmode, int *rawmode, PyObject **result, // FSTRING STUFF -static void fstring_shift_expr_locations(expr_ty n, int lineno, int col_offset); -static void fstring_shift_argument(expr_ty parent, arg_ty args, int lineno, int col_offset); - - -static inline void shift_expr(expr_ty parent, expr_ty n, int line, int col) { - if (parent->lineno < n->lineno) { - col = 0; - } - fstring_shift_expr_locations(n, line, col); -} - -static inline void shift_arg(expr_ty parent, arg_ty n, int line, int col) { - if (parent->lineno < n->lineno) { - col = 0; - } - fstring_shift_argument(parent, n, line, col); -} - -static void fstring_shift_seq_locations(expr_ty parent, asdl_seq *seq, int lineno, int col_offset) { - for (Py_ssize_t i = 0, l = asdl_seq_LEN(seq); i < l; i++) { - expr_ty expr = asdl_seq_GET(seq, i); - if (expr == NULL){ - continue; - } - shift_expr(parent, expr, lineno, col_offset); - } -} - -static void fstring_shift_slice_locations(expr_ty parent, expr_ty slice, int lineno, int col_offset) { - switch (slice->kind) { - case Slice_kind: - if (slice->v.Slice.lower) { - shift_expr(parent, slice->v.Slice.lower, lineno, col_offset); - } - if (slice->v.Slice.upper) { - shift_expr(parent, slice->v.Slice.upper, lineno, col_offset); - } - if (slice->v.Slice.step) { - shift_expr(parent, slice->v.Slice.step, lineno, col_offset); - } - break; - case Tuple_kind: - fstring_shift_seq_locations(parent, slice->v.Tuple.elts, lineno, col_offset); - break; - default: - break; - } -} - -static void fstring_shift_comprehension(expr_ty parent, comprehension_ty comp, int lineno, int col_offset) { - shift_expr(parent, comp->target, lineno, col_offset); - shift_expr(parent, comp->iter, lineno, col_offset); - fstring_shift_seq_locations(parent, comp->ifs, lineno, col_offset); -} - -static void fstring_shift_argument(expr_ty parent, arg_ty arg, int lineno, int col_offset) { - if (arg->annotation != NULL){ - shift_expr(parent, arg->annotation, lineno, col_offset); - } - arg->col_offset = arg->col_offset + col_offset; - arg->end_col_offset = arg->end_col_offset + col_offset; - arg->lineno = arg->lineno + lineno; - arg->end_lineno = arg->end_lineno + lineno; -} - -static void fstring_shift_arguments(expr_ty parent, arguments_ty args, int lineno, int col_offset) { - for (Py_ssize_t i = 0, l = asdl_seq_LEN(args->posonlyargs); i < l; i++) { - arg_ty arg = asdl_seq_GET(args->posonlyargs, i); - shift_arg(parent, arg, lineno, col_offset); - } - - for (Py_ssize_t i = 0, l = asdl_seq_LEN(args->args); i < l; i++) { - arg_ty arg = asdl_seq_GET(args->args, i); - shift_arg(parent, arg, lineno, col_offset); - } - - if (args->vararg != NULL) { - shift_arg(parent, args->vararg, lineno, col_offset); - } - - for (Py_ssize_t i = 0, l = asdl_seq_LEN(args->kwonlyargs); i < l; i++) { - arg_ty arg = asdl_seq_GET(args->kwonlyargs, i); - shift_arg(parent, arg, lineno, col_offset); - } - - fstring_shift_seq_locations(parent, args->kw_defaults, lineno, col_offset); - - if (args->kwarg != NULL) { - shift_arg(parent, args->kwarg, lineno, col_offset); - } - - fstring_shift_seq_locations(parent, args->defaults, lineno, col_offset); -} - -static void fstring_shift_children_locations(expr_ty n, int lineno, int col_offset) { - switch (n->kind) { - case BoolOp_kind: - fstring_shift_seq_locations(n, n->v.BoolOp.values, lineno, col_offset); - break; - case NamedExpr_kind: - shift_expr(n, n->v.NamedExpr.target, lineno, col_offset); - shift_expr(n, n->v.NamedExpr.value, lineno, col_offset); - break; - case BinOp_kind: - shift_expr(n, n->v.BinOp.left, lineno, col_offset); - shift_expr(n, n->v.BinOp.right, lineno, col_offset); - break; - case UnaryOp_kind: - shift_expr(n, n->v.UnaryOp.operand, lineno, col_offset); - break; - case Lambda_kind: - fstring_shift_arguments(n, n->v.Lambda.args, lineno, col_offset); - shift_expr(n, n->v.Lambda.body, lineno, col_offset); - break; - case IfExp_kind: - shift_expr(n, n->v.IfExp.test, lineno, col_offset); - shift_expr(n, n->v.IfExp.body, lineno, col_offset); - shift_expr(n, n->v.IfExp.orelse, lineno, col_offset); - break; - case Dict_kind: - fstring_shift_seq_locations(n, n->v.Dict.keys, lineno, col_offset); - fstring_shift_seq_locations(n, n->v.Dict.values, lineno, col_offset); - break; - case Set_kind: - fstring_shift_seq_locations(n, n->v.Set.elts, lineno, col_offset); - break; - case ListComp_kind: - shift_expr(n, n->v.ListComp.elt, lineno, col_offset); - for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.ListComp.generators); i < l; i++) { - comprehension_ty comp = asdl_seq_GET(n->v.ListComp.generators, i); - fstring_shift_comprehension(n, comp, lineno, col_offset); - } - break; - case SetComp_kind: - shift_expr(n, n->v.SetComp.elt, lineno, col_offset); - for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.SetComp.generators); i < l; i++) { - comprehension_ty comp = asdl_seq_GET(n->v.SetComp.generators, i); - fstring_shift_comprehension(n, comp, lineno, col_offset); - } - break; - case DictComp_kind: - shift_expr(n, n->v.DictComp.key, lineno, col_offset); - shift_expr(n, n->v.DictComp.value, lineno, col_offset); - for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.DictComp.generators); i < l; i++) { - comprehension_ty comp = asdl_seq_GET(n->v.DictComp.generators, i); - fstring_shift_comprehension(n, comp, lineno, col_offset); - } - break; - case GeneratorExp_kind: - shift_expr(n, n->v.GeneratorExp.elt, lineno, col_offset); - for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.GeneratorExp.generators); i < l; i++) { - comprehension_ty comp = asdl_seq_GET(n->v.GeneratorExp.generators, i); - fstring_shift_comprehension(n, comp, lineno, col_offset); - } - break; - case Await_kind: - shift_expr(n, n->v.Await.value, lineno, col_offset); - break; - case Yield_kind: - shift_expr(n, n->v.Yield.value, lineno, col_offset); - break; - case YieldFrom_kind: - shift_expr(n, n->v.YieldFrom.value, lineno, col_offset); - break; - case Compare_kind: - shift_expr(n, n->v.Compare.left, lineno, col_offset); - fstring_shift_seq_locations(n, n->v.Compare.comparators, lineno, col_offset); - break; - case Call_kind: - shift_expr(n, n->v.Call.func, lineno, col_offset); - fstring_shift_seq_locations(n, n->v.Call.args, lineno, col_offset); - for (Py_ssize_t i = 0, l = asdl_seq_LEN(n->v.Call.keywords); i < l; i++) { - keyword_ty keyword = asdl_seq_GET(n->v.Call.keywords, i); - shift_expr(n, keyword->value, lineno, col_offset); - } - break; - case Attribute_kind: - shift_expr(n, n->v.Attribute.value, lineno, col_offset); - break; - case Subscript_kind: - shift_expr(n, n->v.Subscript.value, lineno, col_offset); - fstring_shift_slice_locations(n, n->v.Subscript.slice, lineno, col_offset); - shift_expr(n, n->v.Subscript.slice, lineno, col_offset); - break; - case Starred_kind: - shift_expr(n, n->v.Starred.value, lineno, col_offset); - break; - case List_kind: - fstring_shift_seq_locations(n, n->v.List.elts, lineno, col_offset); - break; - case Tuple_kind: - fstring_shift_seq_locations(n, n->v.Tuple.elts, lineno, col_offset); - break; - case JoinedStr_kind: - fstring_shift_seq_locations(n, n->v.JoinedStr.values, lineno, col_offset); - break; - case FormattedValue_kind: - shift_expr(n, n->v.FormattedValue.value, lineno, col_offset); - if (n->v.FormattedValue.format_spec) { - shift_expr(n, n->v.FormattedValue.format_spec, lineno, col_offset); - } - break; - default: - return; - } -} - -/* Shift locations for the given node and all its children by adding `lineno` - and `col_offset` to existing locations. Note that n is the already parsed - expression. */ -static void fstring_shift_expr_locations(expr_ty n, int lineno, int col_offset) -{ - n->col_offset = n->col_offset + col_offset; - - // The following is needed, in order for nodes spanning across multiple lines - // to be shifted correctly. An example of such a node is a Call node, the closing - // parenthesis of which is not on the same line as its name. - if (n->lineno == n->end_lineno) { - n->end_col_offset = n->end_col_offset + col_offset; - } - - fstring_shift_children_locations(n, lineno, col_offset); - n->lineno = n->lineno + lineno; - n->end_lineno = n->end_lineno + lineno; -} - /* Fix locations for the given node and its children. `parent` is the enclosing node. @@ -506,7 +278,7 @@ static void fstring_shift_expr_locations(expr_ty n, int lineno, int col_offset) `expr_str` is the child node's string representation, including braces. */ static void -fstring_fix_expr_location(Token *parent, expr_ty n, char *expr_str) +fstring_find_expr_location(Token *parent, char *expr_str, int *p_lines, int *p_cols) { char *substr = NULL; char *start; @@ -551,7 +323,8 @@ fstring_fix_expr_location(Token *parent, expr_ty n, char *expr_str) } } } - fstring_shift_expr_locations(n, lines, cols); + *p_lines = lines; + *p_cols = cols; } @@ -591,19 +364,35 @@ fstring_compile_expr(Parser *p, const char *expr_start, const char *expr_end, len = expr_end - expr_start; /* Allocate 3 extra bytes: open paren, close paren, null byte. */ - str = PyMem_RawMalloc(len + 3); + str = PyMem_Malloc(len + 3); if (str == NULL) { PyErr_NoMemory(); return NULL; } - str[0] = '('; + // The call to fstring_find_expr_location is responsible for finding the column offset + // the generated AST nodes need to be shifted to the right, which is equal to the number + // of the f-string characters before the expression starts. In order to correctly compute + // this offset, strstr gets called in fstring_find_expr_location which only succeeds + // if curly braces appear before and after the f-string expression (exactly like they do + // in the f-string itself), hence the following lines. + str[0] = '{'; memcpy(str+1, expr_start, len); - str[len+1] = ')'; + str[len+1] = '}'; str[len+2] = 0; + int lines, cols; + fstring_find_expr_location(t, str, &lines, &cols); + + // The parentheses are needed in order to allow for leading whitespace withing + // the f-string expression. This consequently gets parsed as a group (see the + // group rule in python.gram). + str[0] = '('; + str[len+1] = ')'; + struct tok_state* tok = PyTokenizer_FromString(str, 1); if (tok == NULL) { + PyMem_Free(str); return NULL; } Py_INCREF(p->tok->filename); @@ -611,24 +400,18 @@ fstring_compile_expr(Parser *p, const char *expr_start, const char *expr_end, Parser *p2 = _PyPegen_Parser_New(tok, Py_fstring_input, p->flags, p->feature_version, NULL, p->arena); - p2->starting_lineno = p->starting_lineno + p->tok->first_lineno - 1; - p2->starting_col_offset = p->tok->first_lineno == p->tok->lineno - ? p->starting_col_offset + t->col_offset : 0; + p2->starting_lineno = t->lineno + lines - 1; + p2->starting_col_offset = p->tok->first_lineno == p->tok->lineno ? t->col_offset + cols : cols; expr = _PyPegen_run_parser(p2); if (expr == NULL) { goto exit; } - - /* Reuse str to find the correct column offset. */ - str[0] = '{'; - str[len+1] = '}'; - fstring_fix_expr_location(t, expr, str); - result = expr; exit: + PyMem_Free(str); _PyPegen_Parser_Free(p2); PyTokenizer_Free(tok); return result; @@ -705,15 +488,17 @@ fstring_find_literal(Parser *p, const char **str, const char *end, int raw, assert(s == end || *s == '{' || *s == '}'); done: if (literal_start != s) { - if (raw) + if (raw) { *literal = PyUnicode_DecodeUTF8Stateful(literal_start, s - literal_start, NULL, NULL); - else + } else { *literal = decode_unicode_with_escapes(p, literal_start, s - literal_start, t); - if (!*literal) + } + if (!*literal) { return -1; + } } return result; } @@ -785,10 +570,11 @@ fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int rec /* Loop invariants. */ assert(nested_depth >= 0); assert(*str >= expr_start && *str < end); - if (quote_char) + if (quote_char) { assert(string_type == 1 || string_type == 3); - else + } else { assert(string_type == 0); + } ch = **str; /* Nowhere inside an expression is a backslash allowed. */ @@ -885,7 +671,7 @@ fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int rec goto error; } nested_depth--; - int opening = parenstack[nested_depth]; + int opening = (unsigned char)parenstack[nested_depth]; if (!((opening == '(' && ch == ')') || (opening == '[' && ch == ']') || (opening == '{' && ch == '}'))) @@ -910,24 +696,31 @@ fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int rec goto error; } if (nested_depth) { - int opening = parenstack[nested_depth - 1]; + int opening = (unsigned char)parenstack[nested_depth - 1]; RAISE_SYNTAX_ERROR("f-string: unmatched '%c'", opening); goto error; } - if (*str >= end) + if (*str >= end) { goto unexpected_end_of_string; + } /* Compile the expression as soon as possible, so we show errors related to the expression before errors related to the conversion or format_spec. */ simple_expression = fstring_compile_expr(p, expr_start, expr_end, t); - if (!simple_expression) + if (!simple_expression) { goto error; + } /* Check for =, which puts the text value of the expression in expr_text. */ if (**str == '=') { + if (p->feature_version < 8) { + RAISE_SYNTAX_ERROR("f-string: self documenting expressions are " + "only supported in Python 3.8 and greater"); + goto error; + } *str += 1; /* Skip over ASCII whitespace. No need to test for end of string @@ -947,10 +740,11 @@ fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int rec /* Check for a conversion char, if present. */ if (**str == '!') { *str += 1; - if (*str >= end) + if (*str >= end) { goto unexpected_end_of_string; + } - conversion = **str; + conversion = (unsigned char)**str; *str += 1; /* Validate the conversion. */ @@ -964,22 +758,26 @@ fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int rec } /* Check for the format spec, if present. */ - if (*str >= end) + if (*str >= end) { goto unexpected_end_of_string; + } if (**str == ':') { *str += 1; - if (*str >= end) + if (*str >= end) { goto unexpected_end_of_string; + } /* Parse the format spec. */ format_spec = fstring_parse(p, str, end, raw, recurse_lvl+1, first_token, t, last_token); - if (!format_spec) + if (!format_spec) { goto error; + } } - if (*str >= end || **str != '}') + if (*str >= end || **str != '}') { goto unexpected_end_of_string; + } /* We're at a right brace. Consume it. */ assert(*str < end); @@ -999,8 +797,9 @@ fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int rec format_spec, first_token->lineno, first_token->col_offset, last_token->end_lineno, last_token->end_col_offset, p->arena); - if (!*expression) + if (!*expression) { goto error; + } return 0; @@ -1049,28 +848,32 @@ fstring_find_literal_and_expr(Parser *p, const char **str, const char *end, int /* Get any literal string. */ result = fstring_find_literal(p, str, end, raw, literal, recurse_lvl, t); - if (result < 0) + if (result < 0) { goto error; + } assert(result == 0 || result == 1); - if (result == 1) + if (result == 1) { /* We have a literal, but don't look at the expression. */ return 1; + } - if (*str >= end || **str == '}') + if (*str >= end || **str == '}') { /* We're at the end of the string or the end of a nested f-string: no expression. The top-level error case where we expect to be at the end of the string but we're at a '}' is handled later. */ return 0; + } /* We must now be the start of an expression, on a '{'. */ assert(**str == '{'); if (fstring_find_expr(p, str, end, raw, recurse_lvl, expr_text, - expression, first_token, t, last_token) < 0) + expression, first_token, t, last_token) < 0) { goto error; + } return 0; @@ -1089,8 +892,9 @@ ExprList_check_invariants(ExprList *l) hasn't been deallocated. */ assert(l->size >= 0); assert(l->p != NULL); - if (l->size <= EXPRLIST_N_CACHED) + if (l->size <= EXPRLIST_N_CACHED) { assert(l->data == l->p); + } } #endif @@ -1119,17 +923,19 @@ ExprList_Append(ExprList *l, expr_ty exp) Py_ssize_t i; /* We're still using the cached data. Switch to alloc-ing. */ - l->p = PyMem_RawMalloc(sizeof(expr_ty) * new_size); - if (!l->p) + l->p = PyMem_Malloc(sizeof(expr_ty) * new_size); + if (!l->p) { return -1; + } /* Copy the cached data into the new buffer. */ - for (i = 0; i < l->size; i++) + for (i = 0; i < l->size; i++) { l->p[i] = l->data[i]; + } } else { /* Just realloc. */ - expr_ty *tmp = PyMem_RawRealloc(l->p, sizeof(expr_ty) * new_size); + expr_ty *tmp = PyMem_Realloc(l->p, sizeof(expr_ty) * new_size); if (!tmp) { - PyMem_RawFree(l->p); + PyMem_Free(l->p); l->p = NULL; return -1; } @@ -1157,7 +963,7 @@ ExprList_Dealloc(ExprList *l) /* Do nothing. */ } else { /* We have dynamically allocated. Free the memory. */ - PyMem_RawFree(l->p); + PyMem_Free(l->p); } l->p = NULL; l->size = -1; @@ -1174,8 +980,9 @@ ExprList_Finish(ExprList *l, PyArena *arena) seq = _Py_asdl_seq_new(l->size, arena); if (seq) { Py_ssize_t i; - for (i = 0; i < l->size; i++) + for (i = 0; i < l->size; i++) { asdl_seq_SET(seq, i, l->p[i]); + } } ExprList_Dealloc(l); return seq; @@ -1187,8 +994,9 @@ ExprList_Finish(ExprList *l, PyArena *arena) static void FstringParser_check_invariants(FstringParser *state) { - if (state->last_str) + if (state->last_str) { assert(PyUnicode_CheckExact(state->last_str)); + } ExprList_check_invariants(&state->expr_list); } #endif @@ -1258,8 +1066,9 @@ _PyPegen_FstringParser_ConcatAndDel(FstringParser *state, PyObject *str) } else { /* Concatenate this with the previous string. */ PyUnicode_AppendAndDel(&state->last_str, str); - if (!state->last_str) + if (!state->last_str) { return -1; + } } FstringParser_check_invariants(state); return 0; @@ -1288,8 +1097,9 @@ _PyPegen_FstringParser_ConcatFstring(Parser *p, FstringParser *state, const char int result = fstring_find_literal_and_expr(p, str, end, raw, recurse_lvl, &literal, &expr_text, &expression, first_token, t, last_token); - if (result < 0) + if (result < 0) { return -1; + } /* Add the literal, if any. */ if (literal && _PyPegen_FstringParser_ConcatAndDel(state, literal) < 0) { @@ -1308,12 +1118,14 @@ _PyPegen_FstringParser_ConcatFstring(Parser *p, FstringParser *state, const char and expression, while ignoring the expression this time. This is used for un-doubling braces, as an optimization. */ - if (result == 1) + if (result == 1) { continue; + } - if (!expression) + if (!expression) { /* We're done with this f-string. */ break; + } /* We know we have an expression. Convert any existing string to a Constant node. */ @@ -1321,13 +1133,15 @@ _PyPegen_FstringParser_ConcatFstring(Parser *p, FstringParser *state, const char /* Do nothing. No previous literal. */ } else { /* Convert the existing last_str literal to a Constant node. */ - expr_ty str = make_str_node_and_del(p, &state->last_str, first_token, last_token); - if (!str || ExprList_Append(&state->expr_list, str) < 0) + expr_ty last_str = make_str_node_and_del(p, &state->last_str, first_token, last_token); + if (!last_str || ExprList_Append(&state->expr_list, last_str) < 0) { return -1; + } } - if (ExprList_Append(&state->expr_list, expression) < 0) + if (ExprList_Append(&state->expr_list, expression) < 0) { return -1; + } } /* If recurse_lvl is zero, then we must be at the end of the @@ -1363,8 +1177,9 @@ _PyPegen_FstringParser_Finish(Parser *p, FstringParser *state, Token* first_toke if (!state->last_str) { /* Create a zero length string. */ state->last_str = PyUnicode_FromStringAndSize(NULL, 0); - if (!state->last_str) + if (!state->last_str) { goto error; + } } return make_str_node_and_del(p, &state->last_str, first_token, last_token); } @@ -1373,15 +1188,17 @@ _PyPegen_FstringParser_Finish(Parser *p, FstringParser *state, Token* first_toke last node in our expression list. */ if (state->last_str) { expr_ty str = make_str_node_and_del(p, &state->last_str, first_token, last_token); - if (!str || ExprList_Append(&state->expr_list, str) < 0) + if (!str || ExprList_Append(&state->expr_list, str) < 0) { goto error; + } } /* This has already been freed. */ assert(state->last_str == NULL); seq = ExprList_Finish(&state->expr_list, p->arena); - if (!seq) + if (!seq) { goto error; + } return _Py_JoinedStr(seq, first_token->lineno, first_token->col_offset, last_token->end_lineno, last_token->end_col_offset, p->arena); diff --git a/Parser/pegen/parse_string.h b/Parser/string_parser.h similarity index 100% rename from Parser/pegen/parse_string.h rename to Parser/string_parser.h diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index cebfadc8e89..f3c1d9b20ad 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -1133,7 +1133,7 @@ verify_identifier(struct tok_state *tok) Py_DECREF(s); // PyUnicode_FromFormatV() does not support %X char hex[9]; - snprintf(hex, sizeof(hex), "%04X", ch); + (void)PyOS_snprintf(hex, sizeof(hex), "%04X", ch); if (Py_UNICODE_ISPRINTABLE(ch)) { syntaxerror(tok, "invalid character '%c' (U+%s)", ch, hex); } @@ -1203,8 +1203,9 @@ tok_get(struct tok_state *tok, const char **p_start, const char **p_end) } } tok_backup(tok, c); - if (c == '#' || c == '\n') { + if (c == '#' || c == '\n' || c == '\\') { /* Lines with only whitespace and/or comments + and/or a line continuation character shouldn't affect the indentation and are not passed to the parser as NEWLINE tokens, except *totally* empty lines in interactive diff --git a/Programs/_testembed.c b/Programs/_testembed.c index 5c83678f650..5aad16a6f7c 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -485,9 +485,6 @@ static int test_init_from_config(void) config.install_signal_handlers = 0; - putenv("PYTHONOLDPARSER=1"); - config._use_peg_parser = 0; - /* FIXME: test use_environment */ putenv("PYTHONHASHSEED=42"); @@ -548,6 +545,13 @@ static int test_init_from_config(void) /* FIXME: test home */ /* FIXME: test path config: module_search_path .. dll_path */ + putenv("PYTHONPLATLIBDIR=env_platlibdir"); + status = PyConfig_SetBytesString(&config, &config.platlibdir, "my_platlibdir"); + if (PyStatus_Exception(status)) { + PyConfig_Clear(&config); + Py_ExitStatusException(status); + } + putenv("PYTHONVERBOSE=0"); Py_VerboseFlag = 0; config.verbose = 1; @@ -667,7 +671,7 @@ static void set_most_env_vars(void) putenv("PYTHONNOUSERSITE=1"); putenv("PYTHONFAULTHANDLER=1"); putenv("PYTHONIOENCODING=iso8859-1:replace"); - putenv("PYTHONOLDPARSER=1"); + putenv("PYTHONPLATLIBDIR=env_platlibdir"); } @@ -1108,8 +1112,11 @@ static int test_open_code_hook(void) return result; } +static int _audit_hook_clear_count = 0; + static int _audit_hook(const char *event, PyObject *args, void *userdata) { + assert(args && PyTuple_CheckExact(args)); if (strcmp(event, "_testembed.raise") == 0) { PyErr_SetString(PyExc_RuntimeError, "Intentional error"); return -1; @@ -1118,6 +1125,8 @@ static int _audit_hook(const char *event, PyObject *args, void *userdata) return -1; } return 0; + } else if (strcmp(event, "cpython._PySys_ClearAuditHooks") == 0) { + _audit_hook_clear_count += 1; } return 0; } @@ -1163,6 +1172,9 @@ static int test_audit(void) { int result = _test_audit(42); Py_Finalize(); + if (_audit_hook_clear_count != 1) { + return 0x1000 | _audit_hook_clear_count; + } return result; } @@ -1326,6 +1338,7 @@ static int test_init_read_set(void) return 0; fail: + PyConfig_Clear(&config); Py_ExitStatusException(status); } @@ -1584,6 +1597,46 @@ static int test_run_main(void) } +static int test_get_argc_argv(void) +{ + PyConfig config; + PyConfig_InitPythonConfig(&config); + + wchar_t *argv[] = {L"python3", L"-c", + (L"import sys; " + L"print(f'Py_RunMain(): sys.argv={sys.argv}')"), + L"arg2"}; + config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv); + config_set_string(&config, &config.program_name, L"./python3"); + + // Calling PyConfig_Read() twice must not change Py_GetArgcArgv() result. + // The second call is done by Py_InitializeFromConfig(). + PyStatus status = PyConfig_Read(&config); + if (PyStatus_Exception(status)) { + PyConfig_Clear(&config); + Py_ExitStatusException(status); + } + + init_from_config_clear(&config); + + int get_argc; + wchar_t **get_argv; + Py_GetArgcArgv(&get_argc, &get_argv); + printf("argc: %i\n", get_argc); + assert(get_argc == Py_ARRAY_LENGTH(argv)); + for (int i=0; i < get_argc; i++) { + printf("argv[%i]: %ls\n", i, get_argv[i]); + assert(wcscmp(get_argv[i], argv[i]) == 0); + } + + Py_Finalize(); + + printf("\n"); + printf("test ok\n"); + return 0; +} + + /* ********************************************************* * List of test cases and the function that implements it. * @@ -1641,6 +1694,7 @@ static struct TestCase TestCases[] = { {"test_init_setpythonhome", test_init_setpythonhome}, {"test_init_warnoptions", test_init_warnoptions}, {"test_run_main", test_run_main}, + {"test_get_argc_argv", test_get_argc_argv}, {"test_open_code_hook", test_open_code_hook}, {"test_audit", test_audit}, diff --git a/Python/Python-ast.c b/Python/Python-ast.c index d2edf74c812..396a6832702 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -224,442 +224,473 @@ typedef struct { } astmodulestate; -#define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o)) +static astmodulestate* +get_ast_state(PyObject *module) +{ + void *state = PyModule_GetState(module); + assert(state != NULL); + return (astmodulestate*)state; +} + +static astmodulestate* +get_global_ast_state(void) +{ + _Py_IDENTIFIER(_ast); + PyObject *name = _PyUnicode_FromId(&PyId__ast); // borrowed reference + if (name == NULL) { + return NULL; + } + PyObject *module = PyImport_GetModule(name); + if (module == NULL) { + if (PyErr_Occurred()) { + return NULL; + } + module = PyImport_Import(name); + if (module == NULL) { + return NULL; + } + } + astmodulestate *state = get_ast_state(module); + Py_DECREF(module); + return state; +} static int astmodule_clear(PyObject *module) { - Py_CLEAR(astmodulestate(module)->AST_type); - Py_CLEAR(astmodulestate(module)->Add_singleton); - Py_CLEAR(astmodulestate(module)->Add_type); - Py_CLEAR(astmodulestate(module)->And_singleton); - Py_CLEAR(astmodulestate(module)->And_type); - Py_CLEAR(astmodulestate(module)->AnnAssign_type); - Py_CLEAR(astmodulestate(module)->Assert_type); - Py_CLEAR(astmodulestate(module)->Assign_type); - Py_CLEAR(astmodulestate(module)->AsyncFor_type); - Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type); - Py_CLEAR(astmodulestate(module)->AsyncWith_type); - Py_CLEAR(astmodulestate(module)->Attribute_type); - Py_CLEAR(astmodulestate(module)->AugAssign_type); - Py_CLEAR(astmodulestate(module)->Await_type); - Py_CLEAR(astmodulestate(module)->BinOp_type); - Py_CLEAR(astmodulestate(module)->BitAnd_singleton); - Py_CLEAR(astmodulestate(module)->BitAnd_type); - Py_CLEAR(astmodulestate(module)->BitOr_singleton); - Py_CLEAR(astmodulestate(module)->BitOr_type); - Py_CLEAR(astmodulestate(module)->BitXor_singleton); - Py_CLEAR(astmodulestate(module)->BitXor_type); - Py_CLEAR(astmodulestate(module)->BoolOp_type); - Py_CLEAR(astmodulestate(module)->Break_type); - Py_CLEAR(astmodulestate(module)->Call_type); - Py_CLEAR(astmodulestate(module)->ClassDef_type); - Py_CLEAR(astmodulestate(module)->Compare_type); - Py_CLEAR(astmodulestate(module)->Constant_type); - Py_CLEAR(astmodulestate(module)->Continue_type); - Py_CLEAR(astmodulestate(module)->Del_singleton); - Py_CLEAR(astmodulestate(module)->Del_type); - Py_CLEAR(astmodulestate(module)->Delete_type); - Py_CLEAR(astmodulestate(module)->DictComp_type); - Py_CLEAR(astmodulestate(module)->Dict_type); - Py_CLEAR(astmodulestate(module)->Div_singleton); - Py_CLEAR(astmodulestate(module)->Div_type); - Py_CLEAR(astmodulestate(module)->Eq_singleton); - Py_CLEAR(astmodulestate(module)->Eq_type); - Py_CLEAR(astmodulestate(module)->ExceptHandler_type); - Py_CLEAR(astmodulestate(module)->Expr_type); - Py_CLEAR(astmodulestate(module)->Expression_type); - Py_CLEAR(astmodulestate(module)->FloorDiv_singleton); - Py_CLEAR(astmodulestate(module)->FloorDiv_type); - Py_CLEAR(astmodulestate(module)->For_type); - Py_CLEAR(astmodulestate(module)->FormattedValue_type); - Py_CLEAR(astmodulestate(module)->FunctionDef_type); - Py_CLEAR(astmodulestate(module)->FunctionType_type); - Py_CLEAR(astmodulestate(module)->GeneratorExp_type); - Py_CLEAR(astmodulestate(module)->Global_type); - Py_CLEAR(astmodulestate(module)->GtE_singleton); - Py_CLEAR(astmodulestate(module)->GtE_type); - Py_CLEAR(astmodulestate(module)->Gt_singleton); - Py_CLEAR(astmodulestate(module)->Gt_type); - Py_CLEAR(astmodulestate(module)->IfExp_type); - Py_CLEAR(astmodulestate(module)->If_type); - Py_CLEAR(astmodulestate(module)->ImportFrom_type); - Py_CLEAR(astmodulestate(module)->Import_type); - Py_CLEAR(astmodulestate(module)->In_singleton); - Py_CLEAR(astmodulestate(module)->In_type); - Py_CLEAR(astmodulestate(module)->Interactive_type); - Py_CLEAR(astmodulestate(module)->Invert_singleton); - Py_CLEAR(astmodulestate(module)->Invert_type); - Py_CLEAR(astmodulestate(module)->IsNot_singleton); - Py_CLEAR(astmodulestate(module)->IsNot_type); - Py_CLEAR(astmodulestate(module)->Is_singleton); - Py_CLEAR(astmodulestate(module)->Is_type); - Py_CLEAR(astmodulestate(module)->JoinedStr_type); - Py_CLEAR(astmodulestate(module)->LShift_singleton); - Py_CLEAR(astmodulestate(module)->LShift_type); - Py_CLEAR(astmodulestate(module)->Lambda_type); - Py_CLEAR(astmodulestate(module)->ListComp_type); - Py_CLEAR(astmodulestate(module)->List_type); - Py_CLEAR(astmodulestate(module)->Load_singleton); - Py_CLEAR(astmodulestate(module)->Load_type); - Py_CLEAR(astmodulestate(module)->LtE_singleton); - Py_CLEAR(astmodulestate(module)->LtE_type); - Py_CLEAR(astmodulestate(module)->Lt_singleton); - Py_CLEAR(astmodulestate(module)->Lt_type); - Py_CLEAR(astmodulestate(module)->MatMult_singleton); - Py_CLEAR(astmodulestate(module)->MatMult_type); - Py_CLEAR(astmodulestate(module)->Mod_singleton); - Py_CLEAR(astmodulestate(module)->Mod_type); - Py_CLEAR(astmodulestate(module)->Module_type); - Py_CLEAR(astmodulestate(module)->Mult_singleton); - Py_CLEAR(astmodulestate(module)->Mult_type); - Py_CLEAR(astmodulestate(module)->Name_type); - Py_CLEAR(astmodulestate(module)->NamedExpr_type); - Py_CLEAR(astmodulestate(module)->Nonlocal_type); - Py_CLEAR(astmodulestate(module)->NotEq_singleton); - Py_CLEAR(astmodulestate(module)->NotEq_type); - Py_CLEAR(astmodulestate(module)->NotIn_singleton); - Py_CLEAR(astmodulestate(module)->NotIn_type); - Py_CLEAR(astmodulestate(module)->Not_singleton); - Py_CLEAR(astmodulestate(module)->Not_type); - Py_CLEAR(astmodulestate(module)->Or_singleton); - Py_CLEAR(astmodulestate(module)->Or_type); - Py_CLEAR(astmodulestate(module)->Pass_type); - Py_CLEAR(astmodulestate(module)->Pow_singleton); - Py_CLEAR(astmodulestate(module)->Pow_type); - Py_CLEAR(astmodulestate(module)->RShift_singleton); - Py_CLEAR(astmodulestate(module)->RShift_type); - Py_CLEAR(astmodulestate(module)->Raise_type); - Py_CLEAR(astmodulestate(module)->Return_type); - Py_CLEAR(astmodulestate(module)->SetComp_type); - Py_CLEAR(astmodulestate(module)->Set_type); - Py_CLEAR(astmodulestate(module)->Slice_type); - Py_CLEAR(astmodulestate(module)->Starred_type); - Py_CLEAR(astmodulestate(module)->Store_singleton); - Py_CLEAR(astmodulestate(module)->Store_type); - Py_CLEAR(astmodulestate(module)->Sub_singleton); - Py_CLEAR(astmodulestate(module)->Sub_type); - Py_CLEAR(astmodulestate(module)->Subscript_type); - Py_CLEAR(astmodulestate(module)->Try_type); - Py_CLEAR(astmodulestate(module)->Tuple_type); - Py_CLEAR(astmodulestate(module)->TypeIgnore_type); - Py_CLEAR(astmodulestate(module)->UAdd_singleton); - Py_CLEAR(astmodulestate(module)->UAdd_type); - Py_CLEAR(astmodulestate(module)->USub_singleton); - Py_CLEAR(astmodulestate(module)->USub_type); - Py_CLEAR(astmodulestate(module)->UnaryOp_type); - Py_CLEAR(astmodulestate(module)->While_type); - Py_CLEAR(astmodulestate(module)->With_type); - Py_CLEAR(astmodulestate(module)->YieldFrom_type); - Py_CLEAR(astmodulestate(module)->Yield_type); - Py_CLEAR(astmodulestate(module)->__dict__); - Py_CLEAR(astmodulestate(module)->__doc__); - Py_CLEAR(astmodulestate(module)->__module__); - Py_CLEAR(astmodulestate(module)->_attributes); - Py_CLEAR(astmodulestate(module)->_fields); - Py_CLEAR(astmodulestate(module)->alias_type); - Py_CLEAR(astmodulestate(module)->annotation); - Py_CLEAR(astmodulestate(module)->arg); - Py_CLEAR(astmodulestate(module)->arg_type); - Py_CLEAR(astmodulestate(module)->args); - Py_CLEAR(astmodulestate(module)->argtypes); - Py_CLEAR(astmodulestate(module)->arguments_type); - Py_CLEAR(astmodulestate(module)->asname); - Py_CLEAR(astmodulestate(module)->ast); - Py_CLEAR(astmodulestate(module)->attr); - Py_CLEAR(astmodulestate(module)->bases); - Py_CLEAR(astmodulestate(module)->body); - Py_CLEAR(astmodulestate(module)->boolop_type); - Py_CLEAR(astmodulestate(module)->cause); - Py_CLEAR(astmodulestate(module)->cmpop_type); - Py_CLEAR(astmodulestate(module)->col_offset); - Py_CLEAR(astmodulestate(module)->comparators); - Py_CLEAR(astmodulestate(module)->comprehension_type); - Py_CLEAR(astmodulestate(module)->context_expr); - Py_CLEAR(astmodulestate(module)->conversion); - Py_CLEAR(astmodulestate(module)->ctx); - Py_CLEAR(astmodulestate(module)->decorator_list); - Py_CLEAR(astmodulestate(module)->defaults); - Py_CLEAR(astmodulestate(module)->elt); - Py_CLEAR(astmodulestate(module)->elts); - Py_CLEAR(astmodulestate(module)->end_col_offset); - Py_CLEAR(astmodulestate(module)->end_lineno); - Py_CLEAR(astmodulestate(module)->exc); - Py_CLEAR(astmodulestate(module)->excepthandler_type); - Py_CLEAR(astmodulestate(module)->expr_context_type); - Py_CLEAR(astmodulestate(module)->expr_type); - Py_CLEAR(astmodulestate(module)->finalbody); - Py_CLEAR(astmodulestate(module)->format_spec); - Py_CLEAR(astmodulestate(module)->func); - Py_CLEAR(astmodulestate(module)->generators); - Py_CLEAR(astmodulestate(module)->handlers); - Py_CLEAR(astmodulestate(module)->id); - Py_CLEAR(astmodulestate(module)->ifs); - Py_CLEAR(astmodulestate(module)->is_async); - Py_CLEAR(astmodulestate(module)->items); - Py_CLEAR(astmodulestate(module)->iter); - Py_CLEAR(astmodulestate(module)->key); - Py_CLEAR(astmodulestate(module)->keys); - Py_CLEAR(astmodulestate(module)->keyword_type); - Py_CLEAR(astmodulestate(module)->keywords); - Py_CLEAR(astmodulestate(module)->kind); - Py_CLEAR(astmodulestate(module)->kw_defaults); - Py_CLEAR(astmodulestate(module)->kwarg); - Py_CLEAR(astmodulestate(module)->kwonlyargs); - Py_CLEAR(astmodulestate(module)->left); - Py_CLEAR(astmodulestate(module)->level); - Py_CLEAR(astmodulestate(module)->lineno); - Py_CLEAR(astmodulestate(module)->lower); - Py_CLEAR(astmodulestate(module)->mod_type); - Py_CLEAR(astmodulestate(module)->module); - Py_CLEAR(astmodulestate(module)->msg); - Py_CLEAR(astmodulestate(module)->name); - Py_CLEAR(astmodulestate(module)->names); - Py_CLEAR(astmodulestate(module)->op); - Py_CLEAR(astmodulestate(module)->operand); - Py_CLEAR(astmodulestate(module)->operator_type); - Py_CLEAR(astmodulestate(module)->ops); - Py_CLEAR(astmodulestate(module)->optional_vars); - Py_CLEAR(astmodulestate(module)->orelse); - Py_CLEAR(astmodulestate(module)->posonlyargs); - Py_CLEAR(astmodulestate(module)->returns); - Py_CLEAR(astmodulestate(module)->right); - Py_CLEAR(astmodulestate(module)->simple); - Py_CLEAR(astmodulestate(module)->slice); - Py_CLEAR(astmodulestate(module)->step); - Py_CLEAR(astmodulestate(module)->stmt_type); - Py_CLEAR(astmodulestate(module)->tag); - Py_CLEAR(astmodulestate(module)->target); - Py_CLEAR(astmodulestate(module)->targets); - Py_CLEAR(astmodulestate(module)->test); - Py_CLEAR(astmodulestate(module)->type); - Py_CLEAR(astmodulestate(module)->type_comment); - Py_CLEAR(astmodulestate(module)->type_ignore_type); - Py_CLEAR(astmodulestate(module)->type_ignores); - Py_CLEAR(astmodulestate(module)->unaryop_type); - Py_CLEAR(astmodulestate(module)->upper); - Py_CLEAR(astmodulestate(module)->value); - Py_CLEAR(astmodulestate(module)->values); - Py_CLEAR(astmodulestate(module)->vararg); - Py_CLEAR(astmodulestate(module)->withitem_type); + astmodulestate *state = get_ast_state(module); + Py_CLEAR(state->AST_type); + Py_CLEAR(state->Add_singleton); + Py_CLEAR(state->Add_type); + Py_CLEAR(state->And_singleton); + Py_CLEAR(state->And_type); + Py_CLEAR(state->AnnAssign_type); + Py_CLEAR(state->Assert_type); + Py_CLEAR(state->Assign_type); + Py_CLEAR(state->AsyncFor_type); + Py_CLEAR(state->AsyncFunctionDef_type); + Py_CLEAR(state->AsyncWith_type); + Py_CLEAR(state->Attribute_type); + Py_CLEAR(state->AugAssign_type); + Py_CLEAR(state->Await_type); + Py_CLEAR(state->BinOp_type); + Py_CLEAR(state->BitAnd_singleton); + Py_CLEAR(state->BitAnd_type); + Py_CLEAR(state->BitOr_singleton); + Py_CLEAR(state->BitOr_type); + Py_CLEAR(state->BitXor_singleton); + Py_CLEAR(state->BitXor_type); + Py_CLEAR(state->BoolOp_type); + Py_CLEAR(state->Break_type); + Py_CLEAR(state->Call_type); + Py_CLEAR(state->ClassDef_type); + Py_CLEAR(state->Compare_type); + Py_CLEAR(state->Constant_type); + Py_CLEAR(state->Continue_type); + Py_CLEAR(state->Del_singleton); + Py_CLEAR(state->Del_type); + Py_CLEAR(state->Delete_type); + Py_CLEAR(state->DictComp_type); + Py_CLEAR(state->Dict_type); + Py_CLEAR(state->Div_singleton); + Py_CLEAR(state->Div_type); + Py_CLEAR(state->Eq_singleton); + Py_CLEAR(state->Eq_type); + Py_CLEAR(state->ExceptHandler_type); + Py_CLEAR(state->Expr_type); + Py_CLEAR(state->Expression_type); + Py_CLEAR(state->FloorDiv_singleton); + Py_CLEAR(state->FloorDiv_type); + Py_CLEAR(state->For_type); + Py_CLEAR(state->FormattedValue_type); + Py_CLEAR(state->FunctionDef_type); + Py_CLEAR(state->FunctionType_type); + Py_CLEAR(state->GeneratorExp_type); + Py_CLEAR(state->Global_type); + Py_CLEAR(state->GtE_singleton); + Py_CLEAR(state->GtE_type); + Py_CLEAR(state->Gt_singleton); + Py_CLEAR(state->Gt_type); + Py_CLEAR(state->IfExp_type); + Py_CLEAR(state->If_type); + Py_CLEAR(state->ImportFrom_type); + Py_CLEAR(state->Import_type); + Py_CLEAR(state->In_singleton); + Py_CLEAR(state->In_type); + Py_CLEAR(state->Interactive_type); + Py_CLEAR(state->Invert_singleton); + Py_CLEAR(state->Invert_type); + Py_CLEAR(state->IsNot_singleton); + Py_CLEAR(state->IsNot_type); + Py_CLEAR(state->Is_singleton); + Py_CLEAR(state->Is_type); + Py_CLEAR(state->JoinedStr_type); + Py_CLEAR(state->LShift_singleton); + Py_CLEAR(state->LShift_type); + Py_CLEAR(state->Lambda_type); + Py_CLEAR(state->ListComp_type); + Py_CLEAR(state->List_type); + Py_CLEAR(state->Load_singleton); + Py_CLEAR(state->Load_type); + Py_CLEAR(state->LtE_singleton); + Py_CLEAR(state->LtE_type); + Py_CLEAR(state->Lt_singleton); + Py_CLEAR(state->Lt_type); + Py_CLEAR(state->MatMult_singleton); + Py_CLEAR(state->MatMult_type); + Py_CLEAR(state->Mod_singleton); + Py_CLEAR(state->Mod_type); + Py_CLEAR(state->Module_type); + Py_CLEAR(state->Mult_singleton); + Py_CLEAR(state->Mult_type); + Py_CLEAR(state->Name_type); + Py_CLEAR(state->NamedExpr_type); + Py_CLEAR(state->Nonlocal_type); + Py_CLEAR(state->NotEq_singleton); + Py_CLEAR(state->NotEq_type); + Py_CLEAR(state->NotIn_singleton); + Py_CLEAR(state->NotIn_type); + Py_CLEAR(state->Not_singleton); + Py_CLEAR(state->Not_type); + Py_CLEAR(state->Or_singleton); + Py_CLEAR(state->Or_type); + Py_CLEAR(state->Pass_type); + Py_CLEAR(state->Pow_singleton); + Py_CLEAR(state->Pow_type); + Py_CLEAR(state->RShift_singleton); + Py_CLEAR(state->RShift_type); + Py_CLEAR(state->Raise_type); + Py_CLEAR(state->Return_type); + Py_CLEAR(state->SetComp_type); + Py_CLEAR(state->Set_type); + Py_CLEAR(state->Slice_type); + Py_CLEAR(state->Starred_type); + Py_CLEAR(state->Store_singleton); + Py_CLEAR(state->Store_type); + Py_CLEAR(state->Sub_singleton); + Py_CLEAR(state->Sub_type); + Py_CLEAR(state->Subscript_type); + Py_CLEAR(state->Try_type); + Py_CLEAR(state->Tuple_type); + Py_CLEAR(state->TypeIgnore_type); + Py_CLEAR(state->UAdd_singleton); + Py_CLEAR(state->UAdd_type); + Py_CLEAR(state->USub_singleton); + Py_CLEAR(state->USub_type); + Py_CLEAR(state->UnaryOp_type); + Py_CLEAR(state->While_type); + Py_CLEAR(state->With_type); + Py_CLEAR(state->YieldFrom_type); + Py_CLEAR(state->Yield_type); + Py_CLEAR(state->__dict__); + Py_CLEAR(state->__doc__); + Py_CLEAR(state->__module__); + Py_CLEAR(state->_attributes); + Py_CLEAR(state->_fields); + Py_CLEAR(state->alias_type); + Py_CLEAR(state->annotation); + Py_CLEAR(state->arg); + Py_CLEAR(state->arg_type); + Py_CLEAR(state->args); + Py_CLEAR(state->argtypes); + Py_CLEAR(state->arguments_type); + Py_CLEAR(state->asname); + Py_CLEAR(state->ast); + Py_CLEAR(state->attr); + Py_CLEAR(state->bases); + Py_CLEAR(state->body); + Py_CLEAR(state->boolop_type); + Py_CLEAR(state->cause); + Py_CLEAR(state->cmpop_type); + Py_CLEAR(state->col_offset); + Py_CLEAR(state->comparators); + Py_CLEAR(state->comprehension_type); + Py_CLEAR(state->context_expr); + Py_CLEAR(state->conversion); + Py_CLEAR(state->ctx); + Py_CLEAR(state->decorator_list); + Py_CLEAR(state->defaults); + Py_CLEAR(state->elt); + Py_CLEAR(state->elts); + Py_CLEAR(state->end_col_offset); + Py_CLEAR(state->end_lineno); + Py_CLEAR(state->exc); + Py_CLEAR(state->excepthandler_type); + Py_CLEAR(state->expr_context_type); + Py_CLEAR(state->expr_type); + Py_CLEAR(state->finalbody); + Py_CLEAR(state->format_spec); + Py_CLEAR(state->func); + Py_CLEAR(state->generators); + Py_CLEAR(state->handlers); + Py_CLEAR(state->id); + Py_CLEAR(state->ifs); + Py_CLEAR(state->is_async); + Py_CLEAR(state->items); + Py_CLEAR(state->iter); + Py_CLEAR(state->key); + Py_CLEAR(state->keys); + Py_CLEAR(state->keyword_type); + Py_CLEAR(state->keywords); + Py_CLEAR(state->kind); + Py_CLEAR(state->kw_defaults); + Py_CLEAR(state->kwarg); + Py_CLEAR(state->kwonlyargs); + Py_CLEAR(state->left); + Py_CLEAR(state->level); + Py_CLEAR(state->lineno); + Py_CLEAR(state->lower); + Py_CLEAR(state->mod_type); + Py_CLEAR(state->module); + Py_CLEAR(state->msg); + Py_CLEAR(state->name); + Py_CLEAR(state->names); + Py_CLEAR(state->op); + Py_CLEAR(state->operand); + Py_CLEAR(state->operator_type); + Py_CLEAR(state->ops); + Py_CLEAR(state->optional_vars); + Py_CLEAR(state->orelse); + Py_CLEAR(state->posonlyargs); + Py_CLEAR(state->returns); + Py_CLEAR(state->right); + Py_CLEAR(state->simple); + Py_CLEAR(state->slice); + Py_CLEAR(state->step); + Py_CLEAR(state->stmt_type); + Py_CLEAR(state->tag); + Py_CLEAR(state->target); + Py_CLEAR(state->targets); + Py_CLEAR(state->test); + Py_CLEAR(state->type); + Py_CLEAR(state->type_comment); + Py_CLEAR(state->type_ignore_type); + Py_CLEAR(state->type_ignores); + Py_CLEAR(state->unaryop_type); + Py_CLEAR(state->upper); + Py_CLEAR(state->value); + Py_CLEAR(state->values); + Py_CLEAR(state->vararg); + Py_CLEAR(state->withitem_type); return 0; } static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) { - Py_VISIT(astmodulestate(module)->AST_type); - Py_VISIT(astmodulestate(module)->Add_singleton); - Py_VISIT(astmodulestate(module)->Add_type); - Py_VISIT(astmodulestate(module)->And_singleton); - Py_VISIT(astmodulestate(module)->And_type); - Py_VISIT(astmodulestate(module)->AnnAssign_type); - Py_VISIT(astmodulestate(module)->Assert_type); - Py_VISIT(astmodulestate(module)->Assign_type); - Py_VISIT(astmodulestate(module)->AsyncFor_type); - Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type); - Py_VISIT(astmodulestate(module)->AsyncWith_type); - Py_VISIT(astmodulestate(module)->Attribute_type); - Py_VISIT(astmodulestate(module)->AugAssign_type); - Py_VISIT(astmodulestate(module)->Await_type); - Py_VISIT(astmodulestate(module)->BinOp_type); - Py_VISIT(astmodulestate(module)->BitAnd_singleton); - Py_VISIT(astmodulestate(module)->BitAnd_type); - Py_VISIT(astmodulestate(module)->BitOr_singleton); - Py_VISIT(astmodulestate(module)->BitOr_type); - Py_VISIT(astmodulestate(module)->BitXor_singleton); - Py_VISIT(astmodulestate(module)->BitXor_type); - Py_VISIT(astmodulestate(module)->BoolOp_type); - Py_VISIT(astmodulestate(module)->Break_type); - Py_VISIT(astmodulestate(module)->Call_type); - Py_VISIT(astmodulestate(module)->ClassDef_type); - Py_VISIT(astmodulestate(module)->Compare_type); - Py_VISIT(astmodulestate(module)->Constant_type); - Py_VISIT(astmodulestate(module)->Continue_type); - Py_VISIT(astmodulestate(module)->Del_singleton); - Py_VISIT(astmodulestate(module)->Del_type); - Py_VISIT(astmodulestate(module)->Delete_type); - Py_VISIT(astmodulestate(module)->DictComp_type); - Py_VISIT(astmodulestate(module)->Dict_type); - Py_VISIT(astmodulestate(module)->Div_singleton); - Py_VISIT(astmodulestate(module)->Div_type); - Py_VISIT(astmodulestate(module)->Eq_singleton); - Py_VISIT(astmodulestate(module)->Eq_type); - Py_VISIT(astmodulestate(module)->ExceptHandler_type); - Py_VISIT(astmodulestate(module)->Expr_type); - Py_VISIT(astmodulestate(module)->Expression_type); - Py_VISIT(astmodulestate(module)->FloorDiv_singleton); - Py_VISIT(astmodulestate(module)->FloorDiv_type); - Py_VISIT(astmodulestate(module)->For_type); - Py_VISIT(astmodulestate(module)->FormattedValue_type); - Py_VISIT(astmodulestate(module)->FunctionDef_type); - Py_VISIT(astmodulestate(module)->FunctionType_type); - Py_VISIT(astmodulestate(module)->GeneratorExp_type); - Py_VISIT(astmodulestate(module)->Global_type); - Py_VISIT(astmodulestate(module)->GtE_singleton); - Py_VISIT(astmodulestate(module)->GtE_type); - Py_VISIT(astmodulestate(module)->Gt_singleton); - Py_VISIT(astmodulestate(module)->Gt_type); - Py_VISIT(astmodulestate(module)->IfExp_type); - Py_VISIT(astmodulestate(module)->If_type); - Py_VISIT(astmodulestate(module)->ImportFrom_type); - Py_VISIT(astmodulestate(module)->Import_type); - Py_VISIT(astmodulestate(module)->In_singleton); - Py_VISIT(astmodulestate(module)->In_type); - Py_VISIT(astmodulestate(module)->Interactive_type); - Py_VISIT(astmodulestate(module)->Invert_singleton); - Py_VISIT(astmodulestate(module)->Invert_type); - Py_VISIT(astmodulestate(module)->IsNot_singleton); - Py_VISIT(astmodulestate(module)->IsNot_type); - Py_VISIT(astmodulestate(module)->Is_singleton); - Py_VISIT(astmodulestate(module)->Is_type); - Py_VISIT(astmodulestate(module)->JoinedStr_type); - Py_VISIT(astmodulestate(module)->LShift_singleton); - Py_VISIT(astmodulestate(module)->LShift_type); - Py_VISIT(astmodulestate(module)->Lambda_type); - Py_VISIT(astmodulestate(module)->ListComp_type); - Py_VISIT(astmodulestate(module)->List_type); - Py_VISIT(astmodulestate(module)->Load_singleton); - Py_VISIT(astmodulestate(module)->Load_type); - Py_VISIT(astmodulestate(module)->LtE_singleton); - Py_VISIT(astmodulestate(module)->LtE_type); - Py_VISIT(astmodulestate(module)->Lt_singleton); - Py_VISIT(astmodulestate(module)->Lt_type); - Py_VISIT(astmodulestate(module)->MatMult_singleton); - Py_VISIT(astmodulestate(module)->MatMult_type); - Py_VISIT(astmodulestate(module)->Mod_singleton); - Py_VISIT(astmodulestate(module)->Mod_type); - Py_VISIT(astmodulestate(module)->Module_type); - Py_VISIT(astmodulestate(module)->Mult_singleton); - Py_VISIT(astmodulestate(module)->Mult_type); - Py_VISIT(astmodulestate(module)->Name_type); - Py_VISIT(astmodulestate(module)->NamedExpr_type); - Py_VISIT(astmodulestate(module)->Nonlocal_type); - Py_VISIT(astmodulestate(module)->NotEq_singleton); - Py_VISIT(astmodulestate(module)->NotEq_type); - Py_VISIT(astmodulestate(module)->NotIn_singleton); - Py_VISIT(astmodulestate(module)->NotIn_type); - Py_VISIT(astmodulestate(module)->Not_singleton); - Py_VISIT(astmodulestate(module)->Not_type); - Py_VISIT(astmodulestate(module)->Or_singleton); - Py_VISIT(astmodulestate(module)->Or_type); - Py_VISIT(astmodulestate(module)->Pass_type); - Py_VISIT(astmodulestate(module)->Pow_singleton); - Py_VISIT(astmodulestate(module)->Pow_type); - Py_VISIT(astmodulestate(module)->RShift_singleton); - Py_VISIT(astmodulestate(module)->RShift_type); - Py_VISIT(astmodulestate(module)->Raise_type); - Py_VISIT(astmodulestate(module)->Return_type); - Py_VISIT(astmodulestate(module)->SetComp_type); - Py_VISIT(astmodulestate(module)->Set_type); - Py_VISIT(astmodulestate(module)->Slice_type); - Py_VISIT(astmodulestate(module)->Starred_type); - Py_VISIT(astmodulestate(module)->Store_singleton); - Py_VISIT(astmodulestate(module)->Store_type); - Py_VISIT(astmodulestate(module)->Sub_singleton); - Py_VISIT(astmodulestate(module)->Sub_type); - Py_VISIT(astmodulestate(module)->Subscript_type); - Py_VISIT(astmodulestate(module)->Try_type); - Py_VISIT(astmodulestate(module)->Tuple_type); - Py_VISIT(astmodulestate(module)->TypeIgnore_type); - Py_VISIT(astmodulestate(module)->UAdd_singleton); - Py_VISIT(astmodulestate(module)->UAdd_type); - Py_VISIT(astmodulestate(module)->USub_singleton); - Py_VISIT(astmodulestate(module)->USub_type); - Py_VISIT(astmodulestate(module)->UnaryOp_type); - Py_VISIT(astmodulestate(module)->While_type); - Py_VISIT(astmodulestate(module)->With_type); - Py_VISIT(astmodulestate(module)->YieldFrom_type); - Py_VISIT(astmodulestate(module)->Yield_type); - Py_VISIT(astmodulestate(module)->__dict__); - Py_VISIT(astmodulestate(module)->__doc__); - Py_VISIT(astmodulestate(module)->__module__); - Py_VISIT(astmodulestate(module)->_attributes); - Py_VISIT(astmodulestate(module)->_fields); - Py_VISIT(astmodulestate(module)->alias_type); - Py_VISIT(astmodulestate(module)->annotation); - Py_VISIT(astmodulestate(module)->arg); - Py_VISIT(astmodulestate(module)->arg_type); - Py_VISIT(astmodulestate(module)->args); - Py_VISIT(astmodulestate(module)->argtypes); - Py_VISIT(astmodulestate(module)->arguments_type); - Py_VISIT(astmodulestate(module)->asname); - Py_VISIT(astmodulestate(module)->ast); - Py_VISIT(astmodulestate(module)->attr); - Py_VISIT(astmodulestate(module)->bases); - Py_VISIT(astmodulestate(module)->body); - Py_VISIT(astmodulestate(module)->boolop_type); - Py_VISIT(astmodulestate(module)->cause); - Py_VISIT(astmodulestate(module)->cmpop_type); - Py_VISIT(astmodulestate(module)->col_offset); - Py_VISIT(astmodulestate(module)->comparators); - Py_VISIT(astmodulestate(module)->comprehension_type); - Py_VISIT(astmodulestate(module)->context_expr); - Py_VISIT(astmodulestate(module)->conversion); - Py_VISIT(astmodulestate(module)->ctx); - Py_VISIT(astmodulestate(module)->decorator_list); - Py_VISIT(astmodulestate(module)->defaults); - Py_VISIT(astmodulestate(module)->elt); - Py_VISIT(astmodulestate(module)->elts); - Py_VISIT(astmodulestate(module)->end_col_offset); - Py_VISIT(astmodulestate(module)->end_lineno); - Py_VISIT(astmodulestate(module)->exc); - Py_VISIT(astmodulestate(module)->excepthandler_type); - Py_VISIT(astmodulestate(module)->expr_context_type); - Py_VISIT(astmodulestate(module)->expr_type); - Py_VISIT(astmodulestate(module)->finalbody); - Py_VISIT(astmodulestate(module)->format_spec); - Py_VISIT(astmodulestate(module)->func); - Py_VISIT(astmodulestate(module)->generators); - Py_VISIT(astmodulestate(module)->handlers); - Py_VISIT(astmodulestate(module)->id); - Py_VISIT(astmodulestate(module)->ifs); - Py_VISIT(astmodulestate(module)->is_async); - Py_VISIT(astmodulestate(module)->items); - Py_VISIT(astmodulestate(module)->iter); - Py_VISIT(astmodulestate(module)->key); - Py_VISIT(astmodulestate(module)->keys); - Py_VISIT(astmodulestate(module)->keyword_type); - Py_VISIT(astmodulestate(module)->keywords); - Py_VISIT(astmodulestate(module)->kind); - Py_VISIT(astmodulestate(module)->kw_defaults); - Py_VISIT(astmodulestate(module)->kwarg); - Py_VISIT(astmodulestate(module)->kwonlyargs); - Py_VISIT(astmodulestate(module)->left); - Py_VISIT(astmodulestate(module)->level); - Py_VISIT(astmodulestate(module)->lineno); - Py_VISIT(astmodulestate(module)->lower); - Py_VISIT(astmodulestate(module)->mod_type); - Py_VISIT(astmodulestate(module)->module); - Py_VISIT(astmodulestate(module)->msg); - Py_VISIT(astmodulestate(module)->name); - Py_VISIT(astmodulestate(module)->names); - Py_VISIT(astmodulestate(module)->op); - Py_VISIT(astmodulestate(module)->operand); - Py_VISIT(astmodulestate(module)->operator_type); - Py_VISIT(astmodulestate(module)->ops); - Py_VISIT(astmodulestate(module)->optional_vars); - Py_VISIT(astmodulestate(module)->orelse); - Py_VISIT(astmodulestate(module)->posonlyargs); - Py_VISIT(astmodulestate(module)->returns); - Py_VISIT(astmodulestate(module)->right); - Py_VISIT(astmodulestate(module)->simple); - Py_VISIT(astmodulestate(module)->slice); - Py_VISIT(astmodulestate(module)->step); - Py_VISIT(astmodulestate(module)->stmt_type); - Py_VISIT(astmodulestate(module)->tag); - Py_VISIT(astmodulestate(module)->target); - Py_VISIT(astmodulestate(module)->targets); - Py_VISIT(astmodulestate(module)->test); - Py_VISIT(astmodulestate(module)->type); - Py_VISIT(astmodulestate(module)->type_comment); - Py_VISIT(astmodulestate(module)->type_ignore_type); - Py_VISIT(astmodulestate(module)->type_ignores); - Py_VISIT(astmodulestate(module)->unaryop_type); - Py_VISIT(astmodulestate(module)->upper); - Py_VISIT(astmodulestate(module)->value); - Py_VISIT(astmodulestate(module)->values); - Py_VISIT(astmodulestate(module)->vararg); - Py_VISIT(astmodulestate(module)->withitem_type); + astmodulestate *state = get_ast_state(module); + Py_VISIT(state->AST_type); + Py_VISIT(state->Add_singleton); + Py_VISIT(state->Add_type); + Py_VISIT(state->And_singleton); + Py_VISIT(state->And_type); + Py_VISIT(state->AnnAssign_type); + Py_VISIT(state->Assert_type); + Py_VISIT(state->Assign_type); + Py_VISIT(state->AsyncFor_type); + Py_VISIT(state->AsyncFunctionDef_type); + Py_VISIT(state->AsyncWith_type); + Py_VISIT(state->Attribute_type); + Py_VISIT(state->AugAssign_type); + Py_VISIT(state->Await_type); + Py_VISIT(state->BinOp_type); + Py_VISIT(state->BitAnd_singleton); + Py_VISIT(state->BitAnd_type); + Py_VISIT(state->BitOr_singleton); + Py_VISIT(state->BitOr_type); + Py_VISIT(state->BitXor_singleton); + Py_VISIT(state->BitXor_type); + Py_VISIT(state->BoolOp_type); + Py_VISIT(state->Break_type); + Py_VISIT(state->Call_type); + Py_VISIT(state->ClassDef_type); + Py_VISIT(state->Compare_type); + Py_VISIT(state->Constant_type); + Py_VISIT(state->Continue_type); + Py_VISIT(state->Del_singleton); + Py_VISIT(state->Del_type); + Py_VISIT(state->Delete_type); + Py_VISIT(state->DictComp_type); + Py_VISIT(state->Dict_type); + Py_VISIT(state->Div_singleton); + Py_VISIT(state->Div_type); + Py_VISIT(state->Eq_singleton); + Py_VISIT(state->Eq_type); + Py_VISIT(state->ExceptHandler_type); + Py_VISIT(state->Expr_type); + Py_VISIT(state->Expression_type); + Py_VISIT(state->FloorDiv_singleton); + Py_VISIT(state->FloorDiv_type); + Py_VISIT(state->For_type); + Py_VISIT(state->FormattedValue_type); + Py_VISIT(state->FunctionDef_type); + Py_VISIT(state->FunctionType_type); + Py_VISIT(state->GeneratorExp_type); + Py_VISIT(state->Global_type); + Py_VISIT(state->GtE_singleton); + Py_VISIT(state->GtE_type); + Py_VISIT(state->Gt_singleton); + Py_VISIT(state->Gt_type); + Py_VISIT(state->IfExp_type); + Py_VISIT(state->If_type); + Py_VISIT(state->ImportFrom_type); + Py_VISIT(state->Import_type); + Py_VISIT(state->In_singleton); + Py_VISIT(state->In_type); + Py_VISIT(state->Interactive_type); + Py_VISIT(state->Invert_singleton); + Py_VISIT(state->Invert_type); + Py_VISIT(state->IsNot_singleton); + Py_VISIT(state->IsNot_type); + Py_VISIT(state->Is_singleton); + Py_VISIT(state->Is_type); + Py_VISIT(state->JoinedStr_type); + Py_VISIT(state->LShift_singleton); + Py_VISIT(state->LShift_type); + Py_VISIT(state->Lambda_type); + Py_VISIT(state->ListComp_type); + Py_VISIT(state->List_type); + Py_VISIT(state->Load_singleton); + Py_VISIT(state->Load_type); + Py_VISIT(state->LtE_singleton); + Py_VISIT(state->LtE_type); + Py_VISIT(state->Lt_singleton); + Py_VISIT(state->Lt_type); + Py_VISIT(state->MatMult_singleton); + Py_VISIT(state->MatMult_type); + Py_VISIT(state->Mod_singleton); + Py_VISIT(state->Mod_type); + Py_VISIT(state->Module_type); + Py_VISIT(state->Mult_singleton); + Py_VISIT(state->Mult_type); + Py_VISIT(state->Name_type); + Py_VISIT(state->NamedExpr_type); + Py_VISIT(state->Nonlocal_type); + Py_VISIT(state->NotEq_singleton); + Py_VISIT(state->NotEq_type); + Py_VISIT(state->NotIn_singleton); + Py_VISIT(state->NotIn_type); + Py_VISIT(state->Not_singleton); + Py_VISIT(state->Not_type); + Py_VISIT(state->Or_singleton); + Py_VISIT(state->Or_type); + Py_VISIT(state->Pass_type); + Py_VISIT(state->Pow_singleton); + Py_VISIT(state->Pow_type); + Py_VISIT(state->RShift_singleton); + Py_VISIT(state->RShift_type); + Py_VISIT(state->Raise_type); + Py_VISIT(state->Return_type); + Py_VISIT(state->SetComp_type); + Py_VISIT(state->Set_type); + Py_VISIT(state->Slice_type); + Py_VISIT(state->Starred_type); + Py_VISIT(state->Store_singleton); + Py_VISIT(state->Store_type); + Py_VISIT(state->Sub_singleton); + Py_VISIT(state->Sub_type); + Py_VISIT(state->Subscript_type); + Py_VISIT(state->Try_type); + Py_VISIT(state->Tuple_type); + Py_VISIT(state->TypeIgnore_type); + Py_VISIT(state->UAdd_singleton); + Py_VISIT(state->UAdd_type); + Py_VISIT(state->USub_singleton); + Py_VISIT(state->USub_type); + Py_VISIT(state->UnaryOp_type); + Py_VISIT(state->While_type); + Py_VISIT(state->With_type); + Py_VISIT(state->YieldFrom_type); + Py_VISIT(state->Yield_type); + Py_VISIT(state->__dict__); + Py_VISIT(state->__doc__); + Py_VISIT(state->__module__); + Py_VISIT(state->_attributes); + Py_VISIT(state->_fields); + Py_VISIT(state->alias_type); + Py_VISIT(state->annotation); + Py_VISIT(state->arg); + Py_VISIT(state->arg_type); + Py_VISIT(state->args); + Py_VISIT(state->argtypes); + Py_VISIT(state->arguments_type); + Py_VISIT(state->asname); + Py_VISIT(state->ast); + Py_VISIT(state->attr); + Py_VISIT(state->bases); + Py_VISIT(state->body); + Py_VISIT(state->boolop_type); + Py_VISIT(state->cause); + Py_VISIT(state->cmpop_type); + Py_VISIT(state->col_offset); + Py_VISIT(state->comparators); + Py_VISIT(state->comprehension_type); + Py_VISIT(state->context_expr); + Py_VISIT(state->conversion); + Py_VISIT(state->ctx); + Py_VISIT(state->decorator_list); + Py_VISIT(state->defaults); + Py_VISIT(state->elt); + Py_VISIT(state->elts); + Py_VISIT(state->end_col_offset); + Py_VISIT(state->end_lineno); + Py_VISIT(state->exc); + Py_VISIT(state->excepthandler_type); + Py_VISIT(state->expr_context_type); + Py_VISIT(state->expr_type); + Py_VISIT(state->finalbody); + Py_VISIT(state->format_spec); + Py_VISIT(state->func); + Py_VISIT(state->generators); + Py_VISIT(state->handlers); + Py_VISIT(state->id); + Py_VISIT(state->ifs); + Py_VISIT(state->is_async); + Py_VISIT(state->items); + Py_VISIT(state->iter); + Py_VISIT(state->key); + Py_VISIT(state->keys); + Py_VISIT(state->keyword_type); + Py_VISIT(state->keywords); + Py_VISIT(state->kind); + Py_VISIT(state->kw_defaults); + Py_VISIT(state->kwarg); + Py_VISIT(state->kwonlyargs); + Py_VISIT(state->left); + Py_VISIT(state->level); + Py_VISIT(state->lineno); + Py_VISIT(state->lower); + Py_VISIT(state->mod_type); + Py_VISIT(state->module); + Py_VISIT(state->msg); + Py_VISIT(state->name); + Py_VISIT(state->names); + Py_VISIT(state->op); + Py_VISIT(state->operand); + Py_VISIT(state->operator_type); + Py_VISIT(state->ops); + Py_VISIT(state->optional_vars); + Py_VISIT(state->orelse); + Py_VISIT(state->posonlyargs); + Py_VISIT(state->returns); + Py_VISIT(state->right); + Py_VISIT(state->simple); + Py_VISIT(state->slice); + Py_VISIT(state->step); + Py_VISIT(state->stmt_type); + Py_VISIT(state->tag); + Py_VISIT(state->target); + Py_VISIT(state->targets); + Py_VISIT(state->test); + Py_VISIT(state->type); + Py_VISIT(state->type_comment); + Py_VISIT(state->type_ignore_type); + Py_VISIT(state->type_ignores); + Py_VISIT(state->unaryop_type); + Py_VISIT(state->upper); + Py_VISIT(state->value); + Py_VISIT(state->values); + Py_VISIT(state->vararg); + Py_VISIT(state->withitem_type); return 0; } @@ -668,23 +699,8 @@ static void astmodule_free(void* module) { astmodule_clear((PyObject*)module); } -static struct PyModuleDef _astmodule = { - PyModuleDef_HEAD_INIT, - "_ast", - NULL, - sizeof(astmodulestate), - NULL, - NULL, - astmodule_traverse, - astmodule_clear, - astmodule_free, -}; - -#define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) - -static int init_identifiers(void) +static int init_identifiers(astmodulestate *state) { - astmodulestate *state = astmodulestate_global; if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0; if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0; if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0; @@ -762,7 +778,7 @@ static int init_identifiers(void) return 1; }; -static PyObject* ast2obj_mod(void*); +static PyObject* ast2obj_mod(astmodulestate *state, void*); static const char * const Module_fields[]={ "body", "type_ignores", @@ -783,7 +799,7 @@ static const char * const stmt_attributes[] = { "end_lineno", "end_col_offset", }; -static PyObject* ast2obj_stmt(void*); +static PyObject* ast2obj_stmt(astmodulestate *state, void*); static const char * const FunctionDef_fields[]={ "name", "args", @@ -900,7 +916,7 @@ static const char * const expr_attributes[] = { "end_lineno", "end_col_offset", }; -static PyObject* ast2obj_expr(void*); +static PyObject* ast2obj_expr(astmodulestate *state, void*); static const char * const BoolOp_fields[]={ "op", "values", @@ -1013,12 +1029,12 @@ static const char * const Slice_fields[]={ "upper", "step", }; -static PyObject* ast2obj_expr_context(expr_context_ty); -static PyObject* ast2obj_boolop(boolop_ty); -static PyObject* ast2obj_operator(operator_ty); -static PyObject* ast2obj_unaryop(unaryop_ty); -static PyObject* ast2obj_cmpop(cmpop_ty); -static PyObject* ast2obj_comprehension(void*); +static PyObject* ast2obj_expr_context(astmodulestate *state, expr_context_ty); +static PyObject* ast2obj_boolop(astmodulestate *state, boolop_ty); +static PyObject* ast2obj_operator(astmodulestate *state, operator_ty); +static PyObject* ast2obj_unaryop(astmodulestate *state, unaryop_ty); +static PyObject* ast2obj_cmpop(astmodulestate *state, cmpop_ty); +static PyObject* ast2obj_comprehension(astmodulestate *state, void*); static const char * const comprehension_fields[]={ "target", "iter", @@ -1031,13 +1047,13 @@ static const char * const excepthandler_attributes[] = { "end_lineno", "end_col_offset", }; -static PyObject* ast2obj_excepthandler(void*); +static PyObject* ast2obj_excepthandler(astmodulestate *state, void*); static const char * const ExceptHandler_fields[]={ "type", "name", "body", }; -static PyObject* ast2obj_arguments(void*); +static PyObject* ast2obj_arguments(astmodulestate *state, void*); static const char * const arguments_fields[]={ "posonlyargs", "args", @@ -1047,7 +1063,7 @@ static const char * const arguments_fields[]={ "kwarg", "defaults", }; -static PyObject* ast2obj_arg(void*); +static PyObject* ast2obj_arg(astmodulestate *state, void*); static const char * const arg_attributes[] = { "lineno", "col_offset", @@ -1059,7 +1075,7 @@ static const char * const arg_fields[]={ "annotation", "type_comment", }; -static PyObject* ast2obj_keyword(void*); +static PyObject* ast2obj_keyword(astmodulestate *state, void*); static const char * const keyword_attributes[] = { "lineno", "col_offset", @@ -1070,17 +1086,17 @@ static const char * const keyword_fields[]={ "arg", "value", }; -static PyObject* ast2obj_alias(void*); +static PyObject* ast2obj_alias(astmodulestate *state, void*); static const char * const alias_fields[]={ "name", "asname", }; -static PyObject* ast2obj_withitem(void*); +static PyObject* ast2obj_withitem(astmodulestate *state, void*); static const char * const withitem_fields[]={ "context_expr", "optional_vars", }; -static PyObject* ast2obj_type_ignore(void*); +static PyObject* ast2obj_type_ignore(astmodulestate *state, void*); static const char * const TypeIgnore_fields[]={ "lineno", "tag", @@ -1109,6 +1125,7 @@ ast_dealloc(AST_object *self) static int ast_traverse(AST_object *self, visitproc visit, void *arg) { + Py_VISIT(Py_TYPE(self)); Py_VISIT(self->dict); return 0; } @@ -1123,10 +1140,15 @@ ast_clear(AST_object *self) static int ast_type_init(PyObject *self, PyObject *args, PyObject *kw) { + astmodulestate *state = get_global_ast_state(); + if (state == NULL) { + return -1; + } + Py_ssize_t i, numfields = 0; int res = -1; PyObject *key, *value, *fields; - if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { + if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) { goto cleanup; } if (fields) { @@ -1194,8 +1216,13 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw) static PyObject * ast_type_reduce(PyObject *self, PyObject *unused) { + astmodulestate *state = get_global_ast_state(); + if (state == NULL) { + return NULL; + } + PyObject *dict; - if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { + if (_PyObject_LookupAttr(self, state->__dict__, &dict) < 0) { return NULL; } if (dict) { @@ -1244,7 +1271,8 @@ static PyType_Spec AST_type_spec = { }; static PyObject * -make_type(const char *type, PyObject* base, const char* const* fields, int num_fields, const char *doc) +make_type(astmodulestate *state, const char *type, PyObject* base, + const char* const* fields, int num_fields, const char *doc) { PyObject *fnames, *result; int i; @@ -1260,16 +1288,16 @@ make_type(const char *type, PyObject* base, const char* const* fields, int num_f } result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}", type, base, - astmodulestate_global->_fields, fnames, - astmodulestate_global->__module__, - astmodulestate_global->ast, - astmodulestate_global->__doc__, doc); + state->_fields, fnames, + state->__module__, + state->ast, + state->__doc__, doc); Py_DECREF(fnames); return result; } static int -add_attributes(PyObject *type, const char * const *attrs, int num_fields) +add_attributes(astmodulestate *state, PyObject *type, const char * const *attrs, int num_fields) { int i, result; PyObject *s, *l = PyTuple_New(num_fields); @@ -1283,14 +1311,14 @@ add_attributes(PyObject *type, const char * const *attrs, int num_fields) } PyTuple_SET_ITEM(l, i, s); } - result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; + result = PyObject_SetAttr(type, state->_attributes, l) >= 0; Py_DECREF(l); return result; } /* Conversion AST -> Python */ -static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) +static PyObject* ast2obj_list(astmodulestate *state, asdl_seq *seq, PyObject* (*func)(astmodulestate *state, void*)) { Py_ssize_t i, n = asdl_seq_LEN(seq); PyObject *result = PyList_New(n); @@ -1298,7 +1326,7 @@ static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) if (!result) return NULL; for (i = 0; i < n; i++) { - value = func(asdl_seq_GET(seq, i)); + value = func(state, asdl_seq_GET(seq, i)); if (!value) { Py_DECREF(result); return NULL; @@ -1308,7 +1336,7 @@ static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) return result; } -static PyObject* ast2obj_object(void *o) +static PyObject* ast2obj_object(astmodulestate *Py_UNUSED(state), void *o) { if (!o) o = Py_None; @@ -1319,14 +1347,14 @@ static PyObject* ast2obj_object(void *o) #define ast2obj_identifier ast2obj_object #define ast2obj_string ast2obj_object -static PyObject* ast2obj_int(long b) +static PyObject* ast2obj_int(astmodulestate *Py_UNUSED(state), long b) { return PyLong_FromLong(b); } /* Conversion Python -> AST */ -static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) +static int obj2ast_object(astmodulestate *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena) { if (obj == Py_None) obj = NULL; @@ -1341,7 +1369,7 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) return 0; } -static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) +static int obj2ast_constant(astmodulestate *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena) { if (PyArena_AddPyObject(arena, obj) < 0) { *out = NULL; @@ -1352,25 +1380,25 @@ static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) return 0; } -static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) +static int obj2ast_identifier(astmodulestate *state, PyObject* obj, PyObject** out, PyArena* arena) { if (!PyUnicode_CheckExact(obj) && obj != Py_None) { PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); return 1; } - return obj2ast_object(obj, out, arena); + return obj2ast_object(state, obj, out, arena); } -static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) +static int obj2ast_string(astmodulestate *state, PyObject* obj, PyObject** out, PyArena* arena) { if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); return 1; } - return obj2ast_object(obj, out, arena); + return obj2ast_object(state, obj, out, arena); } -static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) +static int obj2ast_int(astmodulestate* Py_UNUSED(state), PyObject* obj, int* out, PyArena* arena) { int i; if (!PyLong_Check(obj)) { @@ -1385,13 +1413,13 @@ static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) return 0; } -static int add_ast_fields(void) +static int add_ast_fields(astmodulestate *state) { PyObject *empty_tuple; empty_tuple = PyTuple_New(0); if (!empty_tuple || - PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || - PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { + PyObject_SetAttrString(state->AST_type, "_fields", empty_tuple) < 0 || + PyObject_SetAttrString(state->AST_type, "_attributes", empty_tuple) < 0) { Py_XDECREF(empty_tuple); return -1; } @@ -1400,43 +1428,38 @@ static int add_ast_fields(void) } -static int init_types(void) +static int init_types(astmodulestate *state) { - PyObject *m; - if (PyState_FindModule(&_astmodule) == NULL) { - m = PyModule_Create(&_astmodule); - if (!m) return 0; - PyState_AddModule(m, &_astmodule); - } - astmodulestate *state = astmodulestate_global; if (state->initialized) return 1; - if (init_identifiers() < 0) return 0; + if (init_identifiers(state) < 0) return 0; state->AST_type = PyType_FromSpec(&AST_type_spec); if (!state->AST_type) return 0; - if (add_ast_fields() < 0) return 0; - state->mod_type = make_type("mod", state->AST_type, NULL, 0, + if (add_ast_fields(state) < 0) return 0; + state->mod_type = make_type(state, "mod", state->AST_type, NULL, 0, "mod = Module(stmt* body, type_ignore* type_ignores)\n" " | Interactive(stmt* body)\n" " | Expression(expr body)\n" " | FunctionType(expr* argtypes, expr returns)"); if (!state->mod_type) return 0; - if (!add_attributes(state->mod_type, NULL, 0)) return 0; - state->Module_type = make_type("Module", state->mod_type, Module_fields, 2, + if (!add_attributes(state, state->mod_type, NULL, 0)) return 0; + state->Module_type = make_type(state, "Module", state->mod_type, + Module_fields, 2, "Module(stmt* body, type_ignore* type_ignores)"); if (!state->Module_type) return 0; - state->Interactive_type = make_type("Interactive", state->mod_type, + state->Interactive_type = make_type(state, "Interactive", state->mod_type, Interactive_fields, 1, "Interactive(stmt* body)"); if (!state->Interactive_type) return 0; - state->Expression_type = make_type("Expression", state->mod_type, + state->Expression_type = make_type(state, "Expression", state->mod_type, Expression_fields, 1, "Expression(expr body)"); if (!state->Expression_type) return 0; - state->FunctionType_type = make_type("FunctionType", state->mod_type, - FunctionType_fields, 2, + state->FunctionType_type = make_type(state, "FunctionType", + state->mod_type, FunctionType_fields, + 2, "FunctionType(expr* argtypes, expr returns)"); if (!state->FunctionType_type) return 0; - state->stmt_type = make_type("stmt", state->AST_type, NULL, 0, + state->stmt_type = make_type(state, "stmt", state->AST_type, NULL, 0, "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n" @@ -1463,13 +1486,13 @@ static int init_types(void) " | Break\n" " | Continue"); if (!state->stmt_type) return 0; - if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0; + if (!add_attributes(state, state->stmt_type, stmt_attributes, 4)) return 0; if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1) return 0; if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) == -1) return 0; - state->FunctionDef_type = make_type("FunctionDef", state->stmt_type, + state->FunctionDef_type = make_type(state, "FunctionDef", state->stmt_type, FunctionDef_fields, 6, "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); if (!state->FunctionDef_type) return 0; @@ -1479,7 +1502,7 @@ static int init_types(void) if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None) == -1) return 0; - state->AsyncFunctionDef_type = make_type("AsyncFunctionDef", + state->AsyncFunctionDef_type = make_type(state, "AsyncFunctionDef", state->stmt_type, AsyncFunctionDef_fields, 6, "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); @@ -1490,83 +1513,91 @@ static int init_types(void) if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment, Py_None) == -1) return 0; - state->ClassDef_type = make_type("ClassDef", state->stmt_type, + state->ClassDef_type = make_type(state, "ClassDef", state->stmt_type, ClassDef_fields, 5, "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)"); if (!state->ClassDef_type) return 0; - state->Return_type = make_type("Return", state->stmt_type, Return_fields, 1, + state->Return_type = make_type(state, "Return", state->stmt_type, + Return_fields, 1, "Return(expr? value)"); if (!state->Return_type) return 0; if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1) return 0; - state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, 1, + state->Delete_type = make_type(state, "Delete", state->stmt_type, + Delete_fields, 1, "Delete(expr* targets)"); if (!state->Delete_type) return 0; - state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, 3, + state->Assign_type = make_type(state, "Assign", state->stmt_type, + Assign_fields, 3, "Assign(expr* targets, expr value, string? type_comment)"); if (!state->Assign_type) return 0; if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) == -1) return 0; - state->AugAssign_type = make_type("AugAssign", state->stmt_type, + state->AugAssign_type = make_type(state, "AugAssign", state->stmt_type, AugAssign_fields, 3, "AugAssign(expr target, operator op, expr value)"); if (!state->AugAssign_type) return 0; - state->AnnAssign_type = make_type("AnnAssign", state->stmt_type, + state->AnnAssign_type = make_type(state, "AnnAssign", state->stmt_type, AnnAssign_fields, 4, "AnnAssign(expr target, expr annotation, expr? value, int simple)"); if (!state->AnnAssign_type) return 0; if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1) return 0; - state->For_type = make_type("For", state->stmt_type, For_fields, 5, + state->For_type = make_type(state, "For", state->stmt_type, For_fields, 5, "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); if (!state->For_type) return 0; if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1) return 0; - state->AsyncFor_type = make_type("AsyncFor", state->stmt_type, + state->AsyncFor_type = make_type(state, "AsyncFor", state->stmt_type, AsyncFor_fields, 5, "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); if (!state->AsyncFor_type) return 0; if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) == -1) return 0; - state->While_type = make_type("While", state->stmt_type, While_fields, 3, + state->While_type = make_type(state, "While", state->stmt_type, + While_fields, 3, "While(expr test, stmt* body, stmt* orelse)"); if (!state->While_type) return 0; - state->If_type = make_type("If", state->stmt_type, If_fields, 3, + state->If_type = make_type(state, "If", state->stmt_type, If_fields, 3, "If(expr test, stmt* body, stmt* orelse)"); if (!state->If_type) return 0; - state->With_type = make_type("With", state->stmt_type, With_fields, 3, + state->With_type = make_type(state, "With", state->stmt_type, With_fields, + 3, "With(withitem* items, stmt* body, string? type_comment)"); if (!state->With_type) return 0; if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1) return 0; - state->AsyncWith_type = make_type("AsyncWith", state->stmt_type, + state->AsyncWith_type = make_type(state, "AsyncWith", state->stmt_type, AsyncWith_fields, 3, "AsyncWith(withitem* items, stmt* body, string? type_comment)"); if (!state->AsyncWith_type) return 0; if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None) == -1) return 0; - state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2, + state->Raise_type = make_type(state, "Raise", state->stmt_type, + Raise_fields, 2, "Raise(expr? exc, expr? cause)"); if (!state->Raise_type) return 0; if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1) return 0; if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1) return 0; - state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4, + state->Try_type = make_type(state, "Try", state->stmt_type, Try_fields, 4, "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)"); if (!state->Try_type) return 0; - state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, 2, + state->Assert_type = make_type(state, "Assert", state->stmt_type, + Assert_fields, 2, "Assert(expr test, expr? msg)"); if (!state->Assert_type) return 0; if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1) return 0; - state->Import_type = make_type("Import", state->stmt_type, Import_fields, 1, + state->Import_type = make_type(state, "Import", state->stmt_type, + Import_fields, 1, "Import(alias* names)"); if (!state->Import_type) return 0; - state->ImportFrom_type = make_type("ImportFrom", state->stmt_type, + state->ImportFrom_type = make_type(state, "ImportFrom", state->stmt_type, ImportFrom_fields, 3, "ImportFrom(identifier? module, alias* names, int? level)"); if (!state->ImportFrom_type) return 0; @@ -1574,26 +1605,29 @@ static int init_types(void) return 0; if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1) return 0; - state->Global_type = make_type("Global", state->stmt_type, Global_fields, 1, + state->Global_type = make_type(state, "Global", state->stmt_type, + Global_fields, 1, "Global(identifier* names)"); if (!state->Global_type) return 0; - state->Nonlocal_type = make_type("Nonlocal", state->stmt_type, + state->Nonlocal_type = make_type(state, "Nonlocal", state->stmt_type, Nonlocal_fields, 1, "Nonlocal(identifier* names)"); if (!state->Nonlocal_type) return 0; - state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1, + state->Expr_type = make_type(state, "Expr", state->stmt_type, Expr_fields, + 1, "Expr(expr value)"); if (!state->Expr_type) return 0; - state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0, + state->Pass_type = make_type(state, "Pass", state->stmt_type, NULL, 0, "Pass"); if (!state->Pass_type) return 0; - state->Break_type = make_type("Break", state->stmt_type, NULL, 0, + state->Break_type = make_type(state, "Break", state->stmt_type, NULL, 0, "Break"); if (!state->Break_type) return 0; - state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0, + state->Continue_type = make_type(state, "Continue", state->stmt_type, NULL, + 0, "Continue"); if (!state->Continue_type) return 0; - state->expr_type = make_type("expr", state->AST_type, NULL, 0, + state->expr_type = make_type(state, "expr", state->AST_type, NULL, 0, "expr = BoolOp(boolop op, expr* values)\n" " | NamedExpr(expr target, expr value)\n" " | BinOp(expr left, operator op, expr right)\n" @@ -1622,74 +1656,84 @@ static int init_types(void) " | Tuple(expr* elts, expr_context ctx)\n" " | Slice(expr? lower, expr? upper, expr? step)"); if (!state->expr_type) return 0; - if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0; + if (!add_attributes(state, state->expr_type, expr_attributes, 4)) return 0; if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1) return 0; if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) == -1) return 0; - state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, 2, + state->BoolOp_type = make_type(state, "BoolOp", state->expr_type, + BoolOp_fields, 2, "BoolOp(boolop op, expr* values)"); if (!state->BoolOp_type) return 0; - state->NamedExpr_type = make_type("NamedExpr", state->expr_type, + state->NamedExpr_type = make_type(state, "NamedExpr", state->expr_type, NamedExpr_fields, 2, "NamedExpr(expr target, expr value)"); if (!state->NamedExpr_type) return 0; - state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3, + state->BinOp_type = make_type(state, "BinOp", state->expr_type, + BinOp_fields, 3, "BinOp(expr left, operator op, expr right)"); if (!state->BinOp_type) return 0; - state->UnaryOp_type = make_type("UnaryOp", state->expr_type, + state->UnaryOp_type = make_type(state, "UnaryOp", state->expr_type, UnaryOp_fields, 2, "UnaryOp(unaryop op, expr operand)"); if (!state->UnaryOp_type) return 0; - state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, 2, + state->Lambda_type = make_type(state, "Lambda", state->expr_type, + Lambda_fields, 2, "Lambda(arguments args, expr body)"); if (!state->Lambda_type) return 0; - state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3, + state->IfExp_type = make_type(state, "IfExp", state->expr_type, + IfExp_fields, 3, "IfExp(expr test, expr body, expr orelse)"); if (!state->IfExp_type) return 0; - state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2, + state->Dict_type = make_type(state, "Dict", state->expr_type, Dict_fields, + 2, "Dict(expr* keys, expr* values)"); if (!state->Dict_type) return 0; - state->Set_type = make_type("Set", state->expr_type, Set_fields, 1, + state->Set_type = make_type(state, "Set", state->expr_type, Set_fields, 1, "Set(expr* elts)"); if (!state->Set_type) return 0; - state->ListComp_type = make_type("ListComp", state->expr_type, + state->ListComp_type = make_type(state, "ListComp", state->expr_type, ListComp_fields, 2, "ListComp(expr elt, comprehension* generators)"); if (!state->ListComp_type) return 0; - state->SetComp_type = make_type("SetComp", state->expr_type, + state->SetComp_type = make_type(state, "SetComp", state->expr_type, SetComp_fields, 2, "SetComp(expr elt, comprehension* generators)"); if (!state->SetComp_type) return 0; - state->DictComp_type = make_type("DictComp", state->expr_type, + state->DictComp_type = make_type(state, "DictComp", state->expr_type, DictComp_fields, 3, "DictComp(expr key, expr value, comprehension* generators)"); if (!state->DictComp_type) return 0; - state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type, - GeneratorExp_fields, 2, + state->GeneratorExp_type = make_type(state, "GeneratorExp", + state->expr_type, GeneratorExp_fields, + 2, "GeneratorExp(expr elt, comprehension* generators)"); if (!state->GeneratorExp_type) return 0; - state->Await_type = make_type("Await", state->expr_type, Await_fields, 1, + state->Await_type = make_type(state, "Await", state->expr_type, + Await_fields, 1, "Await(expr value)"); if (!state->Await_type) return 0; - state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1, + state->Yield_type = make_type(state, "Yield", state->expr_type, + Yield_fields, 1, "Yield(expr? value)"); if (!state->Yield_type) return 0; if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1) return 0; - state->YieldFrom_type = make_type("YieldFrom", state->expr_type, + state->YieldFrom_type = make_type(state, "YieldFrom", state->expr_type, YieldFrom_fields, 1, "YieldFrom(expr value)"); if (!state->YieldFrom_type) return 0; - state->Compare_type = make_type("Compare", state->expr_type, + state->Compare_type = make_type(state, "Compare", state->expr_type, Compare_fields, 3, "Compare(expr left, cmpop* ops, expr* comparators)"); if (!state->Compare_type) return 0; - state->Call_type = make_type("Call", state->expr_type, Call_fields, 3, + state->Call_type = make_type(state, "Call", state->expr_type, Call_fields, + 3, "Call(expr func, expr* args, keyword* keywords)"); if (!state->Call_type) return 0; - state->FormattedValue_type = make_type("FormattedValue", state->expr_type, + state->FormattedValue_type = make_type(state, "FormattedValue", + state->expr_type, FormattedValue_fields, 3, "FormattedValue(expr value, int? conversion, expr? format_spec)"); if (!state->FormattedValue_type) return 0; @@ -1699,38 +1743,42 @@ static int init_types(void) if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec, Py_None) == -1) return 0; - state->JoinedStr_type = make_type("JoinedStr", state->expr_type, + state->JoinedStr_type = make_type(state, "JoinedStr", state->expr_type, JoinedStr_fields, 1, "JoinedStr(expr* values)"); if (!state->JoinedStr_type) return 0; - state->Constant_type = make_type("Constant", state->expr_type, + state->Constant_type = make_type(state, "Constant", state->expr_type, Constant_fields, 2, "Constant(constant value, string? kind)"); if (!state->Constant_type) return 0; if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1) return 0; - state->Attribute_type = make_type("Attribute", state->expr_type, + state->Attribute_type = make_type(state, "Attribute", state->expr_type, Attribute_fields, 3, "Attribute(expr value, identifier attr, expr_context ctx)"); if (!state->Attribute_type) return 0; - state->Subscript_type = make_type("Subscript", state->expr_type, + state->Subscript_type = make_type(state, "Subscript", state->expr_type, Subscript_fields, 3, "Subscript(expr value, expr slice, expr_context ctx)"); if (!state->Subscript_type) return 0; - state->Starred_type = make_type("Starred", state->expr_type, + state->Starred_type = make_type(state, "Starred", state->expr_type, Starred_fields, 2, "Starred(expr value, expr_context ctx)"); if (!state->Starred_type) return 0; - state->Name_type = make_type("Name", state->expr_type, Name_fields, 2, + state->Name_type = make_type(state, "Name", state->expr_type, Name_fields, + 2, "Name(identifier id, expr_context ctx)"); if (!state->Name_type) return 0; - state->List_type = make_type("List", state->expr_type, List_fields, 2, + state->List_type = make_type(state, "List", state->expr_type, List_fields, + 2, "List(expr* elts, expr_context ctx)"); if (!state->List_type) return 0; - state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2, + state->Tuple_type = make_type(state, "Tuple", state->expr_type, + Tuple_fields, 2, "Tuple(expr* elts, expr_context ctx)"); if (!state->Tuple_type) return 0; - state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3, + state->Slice_type = make_type(state, "Slice", state->expr_type, + Slice_fields, 3, "Slice(expr? lower, expr? upper, expr? step)"); if (!state->Slice_type) return 0; if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1) @@ -1739,244 +1787,255 @@ static int init_types(void) return 0; if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1) return 0; - state->expr_context_type = make_type("expr_context", state->AST_type, NULL, - 0, + state->expr_context_type = make_type(state, "expr_context", + state->AST_type, NULL, 0, "expr_context = Load | Store | Del"); if (!state->expr_context_type) return 0; - if (!add_attributes(state->expr_context_type, NULL, 0)) return 0; - state->Load_type = make_type("Load", state->expr_context_type, NULL, 0, + if (!add_attributes(state, state->expr_context_type, NULL, 0)) return 0; + state->Load_type = make_type(state, "Load", state->expr_context_type, NULL, + 0, "Load"); if (!state->Load_type) return 0; state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type, NULL, NULL); if (!state->Load_singleton) return 0; - state->Store_type = make_type("Store", state->expr_context_type, NULL, 0, + state->Store_type = make_type(state, "Store", state->expr_context_type, + NULL, 0, "Store"); if (!state->Store_type) return 0; state->Store_singleton = PyType_GenericNew((PyTypeObject *)state->Store_type, NULL, NULL); if (!state->Store_singleton) return 0; - state->Del_type = make_type("Del", state->expr_context_type, NULL, 0, + state->Del_type = make_type(state, "Del", state->expr_context_type, NULL, 0, "Del"); if (!state->Del_type) return 0; state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type, NULL, NULL); if (!state->Del_singleton) return 0; - state->boolop_type = make_type("boolop", state->AST_type, NULL, 0, + state->boolop_type = make_type(state, "boolop", state->AST_type, NULL, 0, "boolop = And | Or"); if (!state->boolop_type) return 0; - if (!add_attributes(state->boolop_type, NULL, 0)) return 0; - state->And_type = make_type("And", state->boolop_type, NULL, 0, + if (!add_attributes(state, state->boolop_type, NULL, 0)) return 0; + state->And_type = make_type(state, "And", state->boolop_type, NULL, 0, "And"); if (!state->And_type) return 0; state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type, NULL, NULL); if (!state->And_singleton) return 0; - state->Or_type = make_type("Or", state->boolop_type, NULL, 0, + state->Or_type = make_type(state, "Or", state->boolop_type, NULL, 0, "Or"); if (!state->Or_type) return 0; state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type, NULL, NULL); if (!state->Or_singleton) return 0; - state->operator_type = make_type("operator", state->AST_type, NULL, 0, + state->operator_type = make_type(state, "operator", state->AST_type, NULL, + 0, "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv"); if (!state->operator_type) return 0; - if (!add_attributes(state->operator_type, NULL, 0)) return 0; - state->Add_type = make_type("Add", state->operator_type, NULL, 0, + if (!add_attributes(state, state->operator_type, NULL, 0)) return 0; + state->Add_type = make_type(state, "Add", state->operator_type, NULL, 0, "Add"); if (!state->Add_type) return 0; state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type, NULL, NULL); if (!state->Add_singleton) return 0; - state->Sub_type = make_type("Sub", state->operator_type, NULL, 0, + state->Sub_type = make_type(state, "Sub", state->operator_type, NULL, 0, "Sub"); if (!state->Sub_type) return 0; state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type, NULL, NULL); if (!state->Sub_singleton) return 0; - state->Mult_type = make_type("Mult", state->operator_type, NULL, 0, + state->Mult_type = make_type(state, "Mult", state->operator_type, NULL, 0, "Mult"); if (!state->Mult_type) return 0; state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type, NULL, NULL); if (!state->Mult_singleton) return 0; - state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0, + state->MatMult_type = make_type(state, "MatMult", state->operator_type, + NULL, 0, "MatMult"); if (!state->MatMult_type) return 0; state->MatMult_singleton = PyType_GenericNew((PyTypeObject *)state->MatMult_type, NULL, NULL); if (!state->MatMult_singleton) return 0; - state->Div_type = make_type("Div", state->operator_type, NULL, 0, + state->Div_type = make_type(state, "Div", state->operator_type, NULL, 0, "Div"); if (!state->Div_type) return 0; state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type, NULL, NULL); if (!state->Div_singleton) return 0; - state->Mod_type = make_type("Mod", state->operator_type, NULL, 0, + state->Mod_type = make_type(state, "Mod", state->operator_type, NULL, 0, "Mod"); if (!state->Mod_type) return 0; state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type, NULL, NULL); if (!state->Mod_singleton) return 0; - state->Pow_type = make_type("Pow", state->operator_type, NULL, 0, + state->Pow_type = make_type(state, "Pow", state->operator_type, NULL, 0, "Pow"); if (!state->Pow_type) return 0; state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type, NULL, NULL); if (!state->Pow_singleton) return 0; - state->LShift_type = make_type("LShift", state->operator_type, NULL, 0, + state->LShift_type = make_type(state, "LShift", state->operator_type, NULL, + 0, "LShift"); if (!state->LShift_type) return 0; state->LShift_singleton = PyType_GenericNew((PyTypeObject *)state->LShift_type, NULL, NULL); if (!state->LShift_singleton) return 0; - state->RShift_type = make_type("RShift", state->operator_type, NULL, 0, + state->RShift_type = make_type(state, "RShift", state->operator_type, NULL, + 0, "RShift"); if (!state->RShift_type) return 0; state->RShift_singleton = PyType_GenericNew((PyTypeObject *)state->RShift_type, NULL, NULL); if (!state->RShift_singleton) return 0; - state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0, + state->BitOr_type = make_type(state, "BitOr", state->operator_type, NULL, 0, "BitOr"); if (!state->BitOr_type) return 0; state->BitOr_singleton = PyType_GenericNew((PyTypeObject *)state->BitOr_type, NULL, NULL); if (!state->BitOr_singleton) return 0; - state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0, + state->BitXor_type = make_type(state, "BitXor", state->operator_type, NULL, + 0, "BitXor"); if (!state->BitXor_type) return 0; state->BitXor_singleton = PyType_GenericNew((PyTypeObject *)state->BitXor_type, NULL, NULL); if (!state->BitXor_singleton) return 0; - state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0, + state->BitAnd_type = make_type(state, "BitAnd", state->operator_type, NULL, + 0, "BitAnd"); if (!state->BitAnd_type) return 0; state->BitAnd_singleton = PyType_GenericNew((PyTypeObject *)state->BitAnd_type, NULL, NULL); if (!state->BitAnd_singleton) return 0; - state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0, + state->FloorDiv_type = make_type(state, "FloorDiv", state->operator_type, + NULL, 0, "FloorDiv"); if (!state->FloorDiv_type) return 0; state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject *)state->FloorDiv_type, NULL, NULL); if (!state->FloorDiv_singleton) return 0; - state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0, + state->unaryop_type = make_type(state, "unaryop", state->AST_type, NULL, 0, "unaryop = Invert | Not | UAdd | USub"); if (!state->unaryop_type) return 0; - if (!add_attributes(state->unaryop_type, NULL, 0)) return 0; - state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0, + if (!add_attributes(state, state->unaryop_type, NULL, 0)) return 0; + state->Invert_type = make_type(state, "Invert", state->unaryop_type, NULL, + 0, "Invert"); if (!state->Invert_type) return 0; state->Invert_singleton = PyType_GenericNew((PyTypeObject *)state->Invert_type, NULL, NULL); if (!state->Invert_singleton) return 0; - state->Not_type = make_type("Not", state->unaryop_type, NULL, 0, + state->Not_type = make_type(state, "Not", state->unaryop_type, NULL, 0, "Not"); if (!state->Not_type) return 0; state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type, NULL, NULL); if (!state->Not_singleton) return 0; - state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0, + state->UAdd_type = make_type(state, "UAdd", state->unaryop_type, NULL, 0, "UAdd"); if (!state->UAdd_type) return 0; state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type, NULL, NULL); if (!state->UAdd_singleton) return 0; - state->USub_type = make_type("USub", state->unaryop_type, NULL, 0, + state->USub_type = make_type(state, "USub", state->unaryop_type, NULL, 0, "USub"); if (!state->USub_type) return 0; state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type, NULL, NULL); if (!state->USub_singleton) return 0; - state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0, + state->cmpop_type = make_type(state, "cmpop", state->AST_type, NULL, 0, "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn"); if (!state->cmpop_type) return 0; - if (!add_attributes(state->cmpop_type, NULL, 0)) return 0; - state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0, + if (!add_attributes(state, state->cmpop_type, NULL, 0)) return 0; + state->Eq_type = make_type(state, "Eq", state->cmpop_type, NULL, 0, "Eq"); if (!state->Eq_type) return 0; state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type, NULL, NULL); if (!state->Eq_singleton) return 0; - state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0, + state->NotEq_type = make_type(state, "NotEq", state->cmpop_type, NULL, 0, "NotEq"); if (!state->NotEq_type) return 0; state->NotEq_singleton = PyType_GenericNew((PyTypeObject *)state->NotEq_type, NULL, NULL); if (!state->NotEq_singleton) return 0; - state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0, + state->Lt_type = make_type(state, "Lt", state->cmpop_type, NULL, 0, "Lt"); if (!state->Lt_type) return 0; state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type, NULL, NULL); if (!state->Lt_singleton) return 0; - state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0, + state->LtE_type = make_type(state, "LtE", state->cmpop_type, NULL, 0, "LtE"); if (!state->LtE_type) return 0; state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type, NULL, NULL); if (!state->LtE_singleton) return 0; - state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0, + state->Gt_type = make_type(state, "Gt", state->cmpop_type, NULL, 0, "Gt"); if (!state->Gt_type) return 0; state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type, NULL, NULL); if (!state->Gt_singleton) return 0; - state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0, + state->GtE_type = make_type(state, "GtE", state->cmpop_type, NULL, 0, "GtE"); if (!state->GtE_type) return 0; state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type, NULL, NULL); if (!state->GtE_singleton) return 0; - state->Is_type = make_type("Is", state->cmpop_type, NULL, 0, + state->Is_type = make_type(state, "Is", state->cmpop_type, NULL, 0, "Is"); if (!state->Is_type) return 0; state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type, NULL, NULL); if (!state->Is_singleton) return 0; - state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0, + state->IsNot_type = make_type(state, "IsNot", state->cmpop_type, NULL, 0, "IsNot"); if (!state->IsNot_type) return 0; state->IsNot_singleton = PyType_GenericNew((PyTypeObject *)state->IsNot_type, NULL, NULL); if (!state->IsNot_singleton) return 0; - state->In_type = make_type("In", state->cmpop_type, NULL, 0, + state->In_type = make_type(state, "In", state->cmpop_type, NULL, 0, "In"); if (!state->In_type) return 0; state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type, NULL, NULL); if (!state->In_singleton) return 0; - state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0, + state->NotIn_type = make_type(state, "NotIn", state->cmpop_type, NULL, 0, "NotIn"); if (!state->NotIn_type) return 0; state->NotIn_singleton = PyType_GenericNew((PyTypeObject *)state->NotIn_type, NULL, NULL); if (!state->NotIn_singleton) return 0; - state->comprehension_type = make_type("comprehension", state->AST_type, + state->comprehension_type = make_type(state, "comprehension", + state->AST_type, comprehension_fields, 4, "comprehension(expr target, expr iter, expr* ifs, int is_async)"); if (!state->comprehension_type) return 0; - if (!add_attributes(state->comprehension_type, NULL, 0)) return 0; - state->excepthandler_type = make_type("excepthandler", state->AST_type, - NULL, 0, + if (!add_attributes(state, state->comprehension_type, NULL, 0)) return 0; + state->excepthandler_type = make_type(state, "excepthandler", + state->AST_type, NULL, 0, "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)"); if (!state->excepthandler_type) return 0; - if (!add_attributes(state->excepthandler_type, excepthandler_attributes, - 4)) return 0; + if (!add_attributes(state, state->excepthandler_type, + excepthandler_attributes, 4)) return 0; if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None) == -1) return 0; if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset, Py_None) == -1) return 0; - state->ExceptHandler_type = make_type("ExceptHandler", + state->ExceptHandler_type = make_type(state, "ExceptHandler", state->excepthandler_type, ExceptHandler_fields, 3, "ExceptHandler(expr? type, identifier? name, stmt* body)"); @@ -1985,19 +2044,19 @@ static int init_types(void) return 0; if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1) return 0; - state->arguments_type = make_type("arguments", state->AST_type, + state->arguments_type = make_type(state, "arguments", state->AST_type, arguments_fields, 7, "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)"); if (!state->arguments_type) return 0; - if (!add_attributes(state->arguments_type, NULL, 0)) return 0; + if (!add_attributes(state, state->arguments_type, NULL, 0)) return 0; if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1) return 0; if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1) return 0; - state->arg_type = make_type("arg", state->AST_type, arg_fields, 3, + state->arg_type = make_type(state, "arg", state->AST_type, arg_fields, 3, "arg(identifier arg, expr? annotation, string? type_comment)"); if (!state->arg_type) return 0; - if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0; + if (!add_attributes(state, state->arg_type, arg_attributes, 4)) return 0; if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1) return 0; if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1) @@ -2006,11 +2065,12 @@ static int init_types(void) return 0; if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1) return 0; - state->keyword_type = make_type("keyword", state->AST_type, keyword_fields, - 2, + state->keyword_type = make_type(state, "keyword", state->AST_type, + keyword_fields, 2, "keyword(identifier? arg, expr value)"); if (!state->keyword_type) return 0; - if (!add_attributes(state->keyword_type, keyword_attributes, 4)) return 0; + if (!add_attributes(state, state->keyword_type, keyword_attributes, 4)) + return 0; if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1) return 0; if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1) @@ -2018,25 +2078,28 @@ static int init_types(void) if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None) == -1) return 0; - state->alias_type = make_type("alias", state->AST_type, alias_fields, 2, + state->alias_type = make_type(state, "alias", state->AST_type, + alias_fields, 2, "alias(identifier name, identifier? asname)"); if (!state->alias_type) return 0; - if (!add_attributes(state->alias_type, NULL, 0)) return 0; + if (!add_attributes(state, state->alias_type, NULL, 0)) return 0; if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1) return 0; - state->withitem_type = make_type("withitem", state->AST_type, + state->withitem_type = make_type(state, "withitem", state->AST_type, withitem_fields, 2, "withitem(expr context_expr, expr? optional_vars)"); if (!state->withitem_type) return 0; - if (!add_attributes(state->withitem_type, NULL, 0)) return 0; + if (!add_attributes(state, state->withitem_type, NULL, 0)) return 0; if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None) == -1) return 0; - state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, 0, + state->type_ignore_type = make_type(state, "type_ignore", state->AST_type, + NULL, 0, "type_ignore = TypeIgnore(int lineno, string tag)"); if (!state->type_ignore_type) return 0; - if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0; - state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type, + if (!add_attributes(state, state->type_ignore_type, NULL, 0)) return 0; + state->TypeIgnore_type = make_type(state, "TypeIgnore", + state->type_ignore_type, TypeIgnore_fields, 2, "TypeIgnore(int lineno, string tag)"); if (!state->TypeIgnore_type) return 0; @@ -2044,26 +2107,38 @@ static int init_types(void) return 1; } -static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); -static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); -static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); -static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* - arena); -static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); -static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); -static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); -static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); -static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* - arena); -static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* - arena); -static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); -static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); -static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); -static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); -static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); -static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* - arena); +static int obj2ast_mod(astmodulestate *state, PyObject* obj, mod_ty* out, + PyArena* arena); +static int obj2ast_stmt(astmodulestate *state, PyObject* obj, stmt_ty* out, + PyArena* arena); +static int obj2ast_expr(astmodulestate *state, PyObject* obj, expr_ty* out, + PyArena* arena); +static int obj2ast_expr_context(astmodulestate *state, PyObject* obj, + expr_context_ty* out, PyArena* arena); +static int obj2ast_boolop(astmodulestate *state, PyObject* obj, boolop_ty* out, + PyArena* arena); +static int obj2ast_operator(astmodulestate *state, PyObject* obj, operator_ty* + out, PyArena* arena); +static int obj2ast_unaryop(astmodulestate *state, PyObject* obj, unaryop_ty* + out, PyArena* arena); +static int obj2ast_cmpop(astmodulestate *state, PyObject* obj, cmpop_ty* out, + PyArena* arena); +static int obj2ast_comprehension(astmodulestate *state, PyObject* obj, + comprehension_ty* out, PyArena* arena); +static int obj2ast_excepthandler(astmodulestate *state, PyObject* obj, + excepthandler_ty* out, PyArena* arena); +static int obj2ast_arguments(astmodulestate *state, PyObject* obj, + arguments_ty* out, PyArena* arena); +static int obj2ast_arg(astmodulestate *state, PyObject* obj, arg_ty* out, + PyArena* arena); +static int obj2ast_keyword(astmodulestate *state, PyObject* obj, keyword_ty* + out, PyArena* arena); +static int obj2ast_alias(astmodulestate *state, PyObject* obj, alias_ty* out, + PyArena* arena); +static int obj2ast_withitem(astmodulestate *state, PyObject* obj, withitem_ty* + out, PyArena* arena); +static int obj2ast_type_ignore(astmodulestate *state, PyObject* obj, + type_ignore_ty* out, PyArena* arena); mod_ty Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) @@ -3527,7 +3602,7 @@ TypeIgnore(int lineno, string tag, PyArena *arena) PyObject* -ast2obj_mod(void* _o) +ast2obj_mod(astmodulestate *state, void* _o) { mod_ty o = (mod_ty)_o; PyObject *result = NULL, *value = NULL; @@ -3535,58 +3610,55 @@ ast2obj_mod(void* _o) if (!o) { Py_RETURN_NONE; } - switch (o->kind) { case Module_kind: - tp = (PyTypeObject *)astmodulestate_global->Module_type; + tp = (PyTypeObject *)state->Module_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.Module.body, ast2obj_stmt); + value = ast2obj_list(state, o->v.Module.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); + value = ast2obj_list(state, o->v.Module.type_ignores, + ast2obj_type_ignore); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->type_ignores, - value) == -1) + if (PyObject_SetAttr(result, state->type_ignores, value) == -1) goto failed; Py_DECREF(value); break; case Interactive_kind: - tp = (PyTypeObject *)astmodulestate_global->Interactive_type; + tp = (PyTypeObject *)state->Interactive_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); + value = ast2obj_list(state, o->v.Interactive.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); break; case Expression_kind: - tp = (PyTypeObject *)astmodulestate_global->Expression_type; + tp = (PyTypeObject *)state->Expression_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.Expression.body); + value = ast2obj_expr(state, o->v.Expression.body); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); break; case FunctionType_kind: - tp = (PyTypeObject *)astmodulestate_global->FunctionType_type; + tp = (PyTypeObject *)state->FunctionType_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); + value = ast2obj_list(state, o->v.FunctionType.argtypes, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) == - -1) + if (PyObject_SetAttr(result, state->argtypes, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.FunctionType.returns); + value = ast2obj_expr(state, o->v.FunctionType.returns); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == - -1) + if (PyObject_SetAttr(result, state->returns, value) == -1) goto failed; Py_DECREF(value); break; @@ -3599,7 +3671,7 @@ failed: } PyObject* -ast2obj_stmt(void* _o) +ast2obj_stmt(astmodulestate *state, void* _o) { stmt_ty o = (stmt_ty)_o; PyObject *result = NULL, *value = NULL; @@ -3607,513 +3679,483 @@ ast2obj_stmt(void* _o) if (!o) { Py_RETURN_NONE; } - switch (o->kind) { case FunctionDef_kind: - tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type; + tp = (PyTypeObject *)state->FunctionDef_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_identifier(o->v.FunctionDef.name); + value = ast2obj_identifier(state, o->v.FunctionDef.name); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) + if (PyObject_SetAttr(result, state->name, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_arguments(o->v.FunctionDef.args); + value = ast2obj_arguments(state, o->v.FunctionDef.args); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) + if (PyObject_SetAttr(result, state->args, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); + value = ast2obj_list(state, o->v.FunctionDef.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); + value = ast2obj_list(state, o->v.FunctionDef.decorator_list, + ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, - value) == -1) + if (PyObject_SetAttr(result, state->decorator_list, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.FunctionDef.returns); + value = ast2obj_expr(state, o->v.FunctionDef.returns); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == - -1) + if (PyObject_SetAttr(result, state->returns, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_string(o->v.FunctionDef.type_comment); + value = ast2obj_string(state, o->v.FunctionDef.type_comment); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->type_comment, - value) == -1) + if (PyObject_SetAttr(result, state->type_comment, value) == -1) goto failed; Py_DECREF(value); break; case AsyncFunctionDef_kind: - tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type; + tp = (PyTypeObject *)state->AsyncFunctionDef_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_identifier(o->v.AsyncFunctionDef.name); + value = ast2obj_identifier(state, o->v.AsyncFunctionDef.name); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) + if (PyObject_SetAttr(result, state->name, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_arguments(o->v.AsyncFunctionDef.args); + value = ast2obj_arguments(state, o->v.AsyncFunctionDef.args); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) + if (PyObject_SetAttr(result, state->args, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); + value = ast2obj_list(state, o->v.AsyncFunctionDef.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, + value = ast2obj_list(state, o->v.AsyncFunctionDef.decorator_list, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, - value) == -1) + if (PyObject_SetAttr(result, state->decorator_list, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.AsyncFunctionDef.returns); + value = ast2obj_expr(state, o->v.AsyncFunctionDef.returns); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == - -1) + if (PyObject_SetAttr(result, state->returns, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); + value = ast2obj_string(state, o->v.AsyncFunctionDef.type_comment); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->type_comment, - value) == -1) + if (PyObject_SetAttr(result, state->type_comment, value) == -1) goto failed; Py_DECREF(value); break; case ClassDef_kind: - tp = (PyTypeObject *)astmodulestate_global->ClassDef_type; + tp = (PyTypeObject *)state->ClassDef_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_identifier(o->v.ClassDef.name); + value = ast2obj_identifier(state, o->v.ClassDef.name); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) + if (PyObject_SetAttr(result, state->name, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); + value = ast2obj_list(state, o->v.ClassDef.bases, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1) + if (PyObject_SetAttr(result, state->bases, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); + value = ast2obj_list(state, o->v.ClassDef.keywords, ast2obj_keyword); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == - -1) + if (PyObject_SetAttr(result, state->keywords, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); + value = ast2obj_list(state, o->v.ClassDef.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); + value = ast2obj_list(state, o->v.ClassDef.decorator_list, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, - value) == -1) + if (PyObject_SetAttr(result, state->decorator_list, value) == -1) goto failed; Py_DECREF(value); break; case Return_kind: - tp = (PyTypeObject *)astmodulestate_global->Return_type; + tp = (PyTypeObject *)state->Return_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.Return.value); + value = ast2obj_expr(state, o->v.Return.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); break; case Delete_kind: - tp = (PyTypeObject *)astmodulestate_global->Delete_type; + tp = (PyTypeObject *)state->Delete_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); + value = ast2obj_list(state, o->v.Delete.targets, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == - -1) + if (PyObject_SetAttr(result, state->targets, value) == -1) goto failed; Py_DECREF(value); break; case Assign_kind: - tp = (PyTypeObject *)astmodulestate_global->Assign_type; + tp = (PyTypeObject *)state->Assign_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); + value = ast2obj_list(state, o->v.Assign.targets, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == - -1) + if (PyObject_SetAttr(result, state->targets, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.Assign.value); + value = ast2obj_expr(state, o->v.Assign.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_string(o->v.Assign.type_comment); + value = ast2obj_string(state, o->v.Assign.type_comment); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->type_comment, - value) == -1) + if (PyObject_SetAttr(result, state->type_comment, value) == -1) goto failed; Py_DECREF(value); break; case AugAssign_kind: - tp = (PyTypeObject *)astmodulestate_global->AugAssign_type; + tp = (PyTypeObject *)state->AugAssign_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.AugAssign.target); + value = ast2obj_expr(state, o->v.AugAssign.target); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->target, value) == - -1) + if (PyObject_SetAttr(result, state->target, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_operator(o->v.AugAssign.op); + value = ast2obj_operator(state, o->v.AugAssign.op); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) + if (PyObject_SetAttr(result, state->op, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.AugAssign.value); + value = ast2obj_expr(state, o->v.AugAssign.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); break; case AnnAssign_kind: - tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type; + tp = (PyTypeObject *)state->AnnAssign_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.AnnAssign.target); + value = ast2obj_expr(state, o->v.AnnAssign.target); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->target, value) == - -1) + if (PyObject_SetAttr(result, state->target, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.AnnAssign.annotation); + value = ast2obj_expr(state, o->v.AnnAssign.annotation); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) - == -1) + if (PyObject_SetAttr(result, state->annotation, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.AnnAssign.value); + value = ast2obj_expr(state, o->v.AnnAssign.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_int(o->v.AnnAssign.simple); + value = ast2obj_int(state, o->v.AnnAssign.simple); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->simple, value) == - -1) + if (PyObject_SetAttr(result, state->simple, value) == -1) goto failed; Py_DECREF(value); break; case For_kind: - tp = (PyTypeObject *)astmodulestate_global->For_type; + tp = (PyTypeObject *)state->For_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.For.target); + value = ast2obj_expr(state, o->v.For.target); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->target, value) == - -1) + if (PyObject_SetAttr(result, state->target, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.For.iter); + value = ast2obj_expr(state, o->v.For.iter); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) + if (PyObject_SetAttr(result, state->iter, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.For.body, ast2obj_stmt); + value = ast2obj_list(state, o->v.For.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); + value = ast2obj_list(state, o->v.For.orelse, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == - -1) + if (PyObject_SetAttr(result, state->orelse, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_string(o->v.For.type_comment); + value = ast2obj_string(state, o->v.For.type_comment); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->type_comment, - value) == -1) + if (PyObject_SetAttr(result, state->type_comment, value) == -1) goto failed; Py_DECREF(value); break; case AsyncFor_kind: - tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type; + tp = (PyTypeObject *)state->AsyncFor_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.AsyncFor.target); + value = ast2obj_expr(state, o->v.AsyncFor.target); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->target, value) == - -1) + if (PyObject_SetAttr(result, state->target, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.AsyncFor.iter); + value = ast2obj_expr(state, o->v.AsyncFor.iter); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) + if (PyObject_SetAttr(result, state->iter, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); + value = ast2obj_list(state, o->v.AsyncFor.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); + value = ast2obj_list(state, o->v.AsyncFor.orelse, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == - -1) + if (PyObject_SetAttr(result, state->orelse, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_string(o->v.AsyncFor.type_comment); + value = ast2obj_string(state, o->v.AsyncFor.type_comment); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->type_comment, - value) == -1) + if (PyObject_SetAttr(result, state->type_comment, value) == -1) goto failed; Py_DECREF(value); break; case While_kind: - tp = (PyTypeObject *)astmodulestate_global->While_type; + tp = (PyTypeObject *)state->While_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.While.test); + value = ast2obj_expr(state, o->v.While.test); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) + if (PyObject_SetAttr(result, state->test, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.While.body, ast2obj_stmt); + value = ast2obj_list(state, o->v.While.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); + value = ast2obj_list(state, o->v.While.orelse, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == - -1) + if (PyObject_SetAttr(result, state->orelse, value) == -1) goto failed; Py_DECREF(value); break; case If_kind: - tp = (PyTypeObject *)astmodulestate_global->If_type; + tp = (PyTypeObject *)state->If_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.If.test); + value = ast2obj_expr(state, o->v.If.test); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) + if (PyObject_SetAttr(result, state->test, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.If.body, ast2obj_stmt); + value = ast2obj_list(state, o->v.If.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); + value = ast2obj_list(state, o->v.If.orelse, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == - -1) + if (PyObject_SetAttr(result, state->orelse, value) == -1) goto failed; Py_DECREF(value); break; case With_kind: - tp = (PyTypeObject *)astmodulestate_global->With_type; + tp = (PyTypeObject *)state->With_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.With.items, ast2obj_withitem); + value = ast2obj_list(state, o->v.With.items, ast2obj_withitem); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) + if (PyObject_SetAttr(result, state->items, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.With.body, ast2obj_stmt); + value = ast2obj_list(state, o->v.With.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_string(o->v.With.type_comment); + value = ast2obj_string(state, o->v.With.type_comment); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->type_comment, - value) == -1) + if (PyObject_SetAttr(result, state->type_comment, value) == -1) goto failed; Py_DECREF(value); break; case AsyncWith_kind: - tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type; + tp = (PyTypeObject *)state->AsyncWith_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); + value = ast2obj_list(state, o->v.AsyncWith.items, ast2obj_withitem); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) + if (PyObject_SetAttr(result, state->items, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); + value = ast2obj_list(state, o->v.AsyncWith.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_string(o->v.AsyncWith.type_comment); + value = ast2obj_string(state, o->v.AsyncWith.type_comment); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->type_comment, - value) == -1) + if (PyObject_SetAttr(result, state->type_comment, value) == -1) goto failed; Py_DECREF(value); break; case Raise_kind: - tp = (PyTypeObject *)astmodulestate_global->Raise_type; + tp = (PyTypeObject *)state->Raise_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.Raise.exc); + value = ast2obj_expr(state, o->v.Raise.exc); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1) + if (PyObject_SetAttr(result, state->exc, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.Raise.cause); + value = ast2obj_expr(state, o->v.Raise.cause); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1) + if (PyObject_SetAttr(result, state->cause, value) == -1) goto failed; Py_DECREF(value); break; case Try_kind: - tp = (PyTypeObject *)astmodulestate_global->Try_type; + tp = (PyTypeObject *)state->Try_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.Try.body, ast2obj_stmt); + value = ast2obj_list(state, o->v.Try.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); + value = ast2obj_list(state, o->v.Try.handlers, ast2obj_excepthandler); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) == - -1) + if (PyObject_SetAttr(result, state->handlers, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); + value = ast2obj_list(state, o->v.Try.orelse, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == - -1) + if (PyObject_SetAttr(result, state->orelse, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); + value = ast2obj_list(state, o->v.Try.finalbody, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value) - == -1) + if (PyObject_SetAttr(result, state->finalbody, value) == -1) goto failed; Py_DECREF(value); break; case Assert_kind: - tp = (PyTypeObject *)astmodulestate_global->Assert_type; + tp = (PyTypeObject *)state->Assert_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.Assert.test); + value = ast2obj_expr(state, o->v.Assert.test); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) + if (PyObject_SetAttr(result, state->test, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.Assert.msg); + value = ast2obj_expr(state, o->v.Assert.msg); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1) + if (PyObject_SetAttr(result, state->msg, value) == -1) goto failed; Py_DECREF(value); break; case Import_kind: - tp = (PyTypeObject *)astmodulestate_global->Import_type; + tp = (PyTypeObject *)state->Import_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.Import.names, ast2obj_alias); + value = ast2obj_list(state, o->v.Import.names, ast2obj_alias); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) + if (PyObject_SetAttr(result, state->names, value) == -1) goto failed; Py_DECREF(value); break; case ImportFrom_kind: - tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type; + tp = (PyTypeObject *)state->ImportFrom_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_identifier(o->v.ImportFrom.module); + value = ast2obj_identifier(state, o->v.ImportFrom.module); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->module, value) == - -1) + if (PyObject_SetAttr(result, state->module, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); + value = ast2obj_list(state, o->v.ImportFrom.names, ast2obj_alias); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) + if (PyObject_SetAttr(result, state->names, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_int(o->v.ImportFrom.level); + value = ast2obj_int(state, o->v.ImportFrom.level); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1) + if (PyObject_SetAttr(result, state->level, value) == -1) goto failed; Py_DECREF(value); break; case Global_kind: - tp = (PyTypeObject *)astmodulestate_global->Global_type; + tp = (PyTypeObject *)state->Global_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.Global.names, ast2obj_identifier); + value = ast2obj_list(state, o->v.Global.names, ast2obj_identifier); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) + if (PyObject_SetAttr(result, state->names, value) == -1) goto failed; Py_DECREF(value); break; case Nonlocal_kind: - tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type; + tp = (PyTypeObject *)state->Nonlocal_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); + value = ast2obj_list(state, o->v.Nonlocal.names, ast2obj_identifier); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) + if (PyObject_SetAttr(result, state->names, value) == -1) goto failed; Py_DECREF(value); break; case Expr_kind: - tp = (PyTypeObject *)astmodulestate_global->Expr_type; + tp = (PyTypeObject *)state->Expr_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.Expr.value); + value = ast2obj_expr(state, o->v.Expr.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); break; case Pass_kind: - tp = (PyTypeObject *)astmodulestate_global->Pass_type; + tp = (PyTypeObject *)state->Pass_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; break; case Break_kind: - tp = (PyTypeObject *)astmodulestate_global->Break_type; + tp = (PyTypeObject *)state->Break_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; break; case Continue_kind: - tp = (PyTypeObject *)astmodulestate_global->Continue_type; + tp = (PyTypeObject *)state->Continue_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; break; } - value = ast2obj_int(o->lineno); + value = ast2obj_int(state, o->lineno); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) + if (PyObject_SetAttr(result, state->lineno, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->col_offset); + value = ast2obj_int(state, o->col_offset); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) + if (PyObject_SetAttr(result, state->col_offset, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->end_lineno); + value = ast2obj_int(state, o->end_lineno); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) + if (PyObject_SetAttr(result, state->end_lineno, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->end_col_offset); + value = ast2obj_int(state, o->end_col_offset); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) - < 0) + if (PyObject_SetAttr(result, state->end_col_offset, value) < 0) goto failed; Py_DECREF(value); return result; @@ -4124,7 +4166,7 @@ failed: } PyObject* -ast2obj_expr(void* _o) +ast2obj_expr(astmodulestate *state, void* _o) { expr_ty o = (expr_ty)_o; PyObject *result = NULL, *value = NULL; @@ -4132,245 +4174,238 @@ ast2obj_expr(void* _o) if (!o) { Py_RETURN_NONE; } - switch (o->kind) { case BoolOp_kind: - tp = (PyTypeObject *)astmodulestate_global->BoolOp_type; + tp = (PyTypeObject *)state->BoolOp_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_boolop(o->v.BoolOp.op); + value = ast2obj_boolop(state, o->v.BoolOp.op); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) + if (PyObject_SetAttr(result, state->op, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); + value = ast2obj_list(state, o->v.BoolOp.values, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->values, value) == - -1) + if (PyObject_SetAttr(result, state->values, value) == -1) goto failed; Py_DECREF(value); break; case NamedExpr_kind: - tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type; + tp = (PyTypeObject *)state->NamedExpr_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.NamedExpr.target); + value = ast2obj_expr(state, o->v.NamedExpr.target); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->target, value) == - -1) + if (PyObject_SetAttr(result, state->target, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.NamedExpr.value); + value = ast2obj_expr(state, o->v.NamedExpr.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); break; case BinOp_kind: - tp = (PyTypeObject *)astmodulestate_global->BinOp_type; + tp = (PyTypeObject *)state->BinOp_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.BinOp.left); + value = ast2obj_expr(state, o->v.BinOp.left); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) + if (PyObject_SetAttr(result, state->left, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_operator(o->v.BinOp.op); + value = ast2obj_operator(state, o->v.BinOp.op); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) + if (PyObject_SetAttr(result, state->op, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.BinOp.right); + value = ast2obj_expr(state, o->v.BinOp.right); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1) + if (PyObject_SetAttr(result, state->right, value) == -1) goto failed; Py_DECREF(value); break; case UnaryOp_kind: - tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type; + tp = (PyTypeObject *)state->UnaryOp_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_unaryop(o->v.UnaryOp.op); + value = ast2obj_unaryop(state, o->v.UnaryOp.op); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) + if (PyObject_SetAttr(result, state->op, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.UnaryOp.operand); + value = ast2obj_expr(state, o->v.UnaryOp.operand); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->operand, value) == - -1) + if (PyObject_SetAttr(result, state->operand, value) == -1) goto failed; Py_DECREF(value); break; case Lambda_kind: - tp = (PyTypeObject *)astmodulestate_global->Lambda_type; + tp = (PyTypeObject *)state->Lambda_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_arguments(o->v.Lambda.args); + value = ast2obj_arguments(state, o->v.Lambda.args); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) + if (PyObject_SetAttr(result, state->args, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.Lambda.body); + value = ast2obj_expr(state, o->v.Lambda.body); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); break; case IfExp_kind: - tp = (PyTypeObject *)astmodulestate_global->IfExp_type; + tp = (PyTypeObject *)state->IfExp_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.IfExp.test); + value = ast2obj_expr(state, o->v.IfExp.test); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) + if (PyObject_SetAttr(result, state->test, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.IfExp.body); + value = ast2obj_expr(state, o->v.IfExp.body); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.IfExp.orelse); + value = ast2obj_expr(state, o->v.IfExp.orelse); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == - -1) + if (PyObject_SetAttr(result, state->orelse, value) == -1) goto failed; Py_DECREF(value); break; case Dict_kind: - tp = (PyTypeObject *)astmodulestate_global->Dict_type; + tp = (PyTypeObject *)state->Dict_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); + value = ast2obj_list(state, o->v.Dict.keys, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1) + if (PyObject_SetAttr(result, state->keys, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.Dict.values, ast2obj_expr); + value = ast2obj_list(state, o->v.Dict.values, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->values, value) == - -1) + if (PyObject_SetAttr(result, state->values, value) == -1) goto failed; Py_DECREF(value); break; case Set_kind: - tp = (PyTypeObject *)astmodulestate_global->Set_type; + tp = (PyTypeObject *)state->Set_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.Set.elts, ast2obj_expr); + value = ast2obj_list(state, o->v.Set.elts, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) + if (PyObject_SetAttr(result, state->elts, value) == -1) goto failed; Py_DECREF(value); break; case ListComp_kind: - tp = (PyTypeObject *)astmodulestate_global->ListComp_type; + tp = (PyTypeObject *)state->ListComp_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.ListComp.elt); + value = ast2obj_expr(state, o->v.ListComp.elt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) + if (PyObject_SetAttr(result, state->elt, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); + value = ast2obj_list(state, o->v.ListComp.generators, + ast2obj_comprehension); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->generators, value) - == -1) + if (PyObject_SetAttr(result, state->generators, value) == -1) goto failed; Py_DECREF(value); break; case SetComp_kind: - tp = (PyTypeObject *)astmodulestate_global->SetComp_type; + tp = (PyTypeObject *)state->SetComp_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.SetComp.elt); + value = ast2obj_expr(state, o->v.SetComp.elt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) + if (PyObject_SetAttr(result, state->elt, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); + value = ast2obj_list(state, o->v.SetComp.generators, + ast2obj_comprehension); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->generators, value) - == -1) + if (PyObject_SetAttr(result, state->generators, value) == -1) goto failed; Py_DECREF(value); break; case DictComp_kind: - tp = (PyTypeObject *)astmodulestate_global->DictComp_type; + tp = (PyTypeObject *)state->DictComp_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.DictComp.key); + value = ast2obj_expr(state, o->v.DictComp.key); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1) + if (PyObject_SetAttr(result, state->key, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.DictComp.value); + value = ast2obj_expr(state, o->v.DictComp.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); + value = ast2obj_list(state, o->v.DictComp.generators, + ast2obj_comprehension); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->generators, value) - == -1) + if (PyObject_SetAttr(result, state->generators, value) == -1) goto failed; Py_DECREF(value); break; case GeneratorExp_kind: - tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type; + tp = (PyTypeObject *)state->GeneratorExp_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.GeneratorExp.elt); + value = ast2obj_expr(state, o->v.GeneratorExp.elt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) + if (PyObject_SetAttr(result, state->elt, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.GeneratorExp.generators, + value = ast2obj_list(state, o->v.GeneratorExp.generators, ast2obj_comprehension); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->generators, value) - == -1) + if (PyObject_SetAttr(result, state->generators, value) == -1) goto failed; Py_DECREF(value); break; case Await_kind: - tp = (PyTypeObject *)astmodulestate_global->Await_type; + tp = (PyTypeObject *)state->Await_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.Await.value); + value = ast2obj_expr(state, o->v.Await.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); break; case Yield_kind: - tp = (PyTypeObject *)astmodulestate_global->Yield_type; + tp = (PyTypeObject *)state->Yield_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.Yield.value); + value = ast2obj_expr(state, o->v.Yield.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); break; case YieldFrom_kind: - tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type; + tp = (PyTypeObject *)state->YieldFrom_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.YieldFrom.value); + value = ast2obj_expr(state, o->v.YieldFrom.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); break; case Compare_kind: - tp = (PyTypeObject *)astmodulestate_global->Compare_type; + tp = (PyTypeObject *)state->Compare_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.Compare.left); + value = ast2obj_expr(state, o->v.Compare.left); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) + if (PyObject_SetAttr(result, state->left, value) == -1) goto failed; Py_DECREF(value); { @@ -4378,228 +4413,222 @@ ast2obj_expr(void* _o) value = PyList_New(n); if (!value) goto failed; for(i = 0; i < n; i++) - PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); + PyList_SET_ITEM(value, i, ast2obj_cmpop(state, (cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); } if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1) + if (PyObject_SetAttr(result, state->ops, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); + value = ast2obj_list(state, o->v.Compare.comparators, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->comparators, value) - == -1) + if (PyObject_SetAttr(result, state->comparators, value) == -1) goto failed; Py_DECREF(value); break; case Call_kind: - tp = (PyTypeObject *)astmodulestate_global->Call_type; + tp = (PyTypeObject *)state->Call_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.Call.func); + value = ast2obj_expr(state, o->v.Call.func); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1) + if (PyObject_SetAttr(result, state->func, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.Call.args, ast2obj_expr); + value = ast2obj_list(state, o->v.Call.args, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) + if (PyObject_SetAttr(result, state->args, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); + value = ast2obj_list(state, o->v.Call.keywords, ast2obj_keyword); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == - -1) + if (PyObject_SetAttr(result, state->keywords, value) == -1) goto failed; Py_DECREF(value); break; case FormattedValue_kind: - tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type; + tp = (PyTypeObject *)state->FormattedValue_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.FormattedValue.value); + value = ast2obj_expr(state, o->v.FormattedValue.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_int(o->v.FormattedValue.conversion); + value = ast2obj_int(state, o->v.FormattedValue.conversion); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->conversion, value) - == -1) + if (PyObject_SetAttr(result, state->conversion, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.FormattedValue.format_spec); + value = ast2obj_expr(state, o->v.FormattedValue.format_spec); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value) - == -1) + if (PyObject_SetAttr(result, state->format_spec, value) == -1) goto failed; Py_DECREF(value); break; case JoinedStr_kind: - tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type; + tp = (PyTypeObject *)state->JoinedStr_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); + value = ast2obj_list(state, o->v.JoinedStr.values, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->values, value) == - -1) + if (PyObject_SetAttr(result, state->values, value) == -1) goto failed; Py_DECREF(value); break; case Constant_kind: - tp = (PyTypeObject *)astmodulestate_global->Constant_type; + tp = (PyTypeObject *)state->Constant_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_constant(o->v.Constant.value); + value = ast2obj_constant(state, o->v.Constant.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_string(o->v.Constant.kind); + value = ast2obj_string(state, o->v.Constant.kind); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1) + if (PyObject_SetAttr(result, state->kind, value) == -1) goto failed; Py_DECREF(value); break; case Attribute_kind: - tp = (PyTypeObject *)astmodulestate_global->Attribute_type; + tp = (PyTypeObject *)state->Attribute_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.Attribute.value); + value = ast2obj_expr(state, o->v.Attribute.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_identifier(o->v.Attribute.attr); + value = ast2obj_identifier(state, o->v.Attribute.attr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1) + if (PyObject_SetAttr(result, state->attr, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr_context(o->v.Attribute.ctx); + value = ast2obj_expr_context(state, o->v.Attribute.ctx); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) + if (PyObject_SetAttr(result, state->ctx, value) == -1) goto failed; Py_DECREF(value); break; case Subscript_kind: - tp = (PyTypeObject *)astmodulestate_global->Subscript_type; + tp = (PyTypeObject *)state->Subscript_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.Subscript.value); + value = ast2obj_expr(state, o->v.Subscript.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.Subscript.slice); + value = ast2obj_expr(state, o->v.Subscript.slice); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1) + if (PyObject_SetAttr(result, state->slice, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr_context(o->v.Subscript.ctx); + value = ast2obj_expr_context(state, o->v.Subscript.ctx); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) + if (PyObject_SetAttr(result, state->ctx, value) == -1) goto failed; Py_DECREF(value); break; case Starred_kind: - tp = (PyTypeObject *)astmodulestate_global->Starred_type; + tp = (PyTypeObject *)state->Starred_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.Starred.value); + value = ast2obj_expr(state, o->v.Starred.value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr_context(o->v.Starred.ctx); + value = ast2obj_expr_context(state, o->v.Starred.ctx); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) + if (PyObject_SetAttr(result, state->ctx, value) == -1) goto failed; Py_DECREF(value); break; case Name_kind: - tp = (PyTypeObject *)astmodulestate_global->Name_type; + tp = (PyTypeObject *)state->Name_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_identifier(o->v.Name.id); + value = ast2obj_identifier(state, o->v.Name.id); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1) + if (PyObject_SetAttr(result, state->id, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr_context(o->v.Name.ctx); + value = ast2obj_expr_context(state, o->v.Name.ctx); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) + if (PyObject_SetAttr(result, state->ctx, value) == -1) goto failed; Py_DECREF(value); break; case List_kind: - tp = (PyTypeObject *)astmodulestate_global->List_type; + tp = (PyTypeObject *)state->List_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.List.elts, ast2obj_expr); + value = ast2obj_list(state, o->v.List.elts, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) + if (PyObject_SetAttr(result, state->elts, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr_context(o->v.List.ctx); + value = ast2obj_expr_context(state, o->v.List.ctx); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) + if (PyObject_SetAttr(result, state->ctx, value) == -1) goto failed; Py_DECREF(value); break; case Tuple_kind: - tp = (PyTypeObject *)astmodulestate_global->Tuple_type; + tp = (PyTypeObject *)state->Tuple_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); + value = ast2obj_list(state, o->v.Tuple.elts, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) + if (PyObject_SetAttr(result, state->elts, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr_context(o->v.Tuple.ctx); + value = ast2obj_expr_context(state, o->v.Tuple.ctx); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) + if (PyObject_SetAttr(result, state->ctx, value) == -1) goto failed; Py_DECREF(value); break; case Slice_kind: - tp = (PyTypeObject *)astmodulestate_global->Slice_type; + tp = (PyTypeObject *)state->Slice_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.Slice.lower); + value = ast2obj_expr(state, o->v.Slice.lower); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1) + if (PyObject_SetAttr(result, state->lower, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.Slice.upper); + value = ast2obj_expr(state, o->v.Slice.upper); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1) + if (PyObject_SetAttr(result, state->upper, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.Slice.step); + value = ast2obj_expr(state, o->v.Slice.step); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1) + if (PyObject_SetAttr(result, state->step, value) == -1) goto failed; Py_DECREF(value); break; } - value = ast2obj_int(o->lineno); + value = ast2obj_int(state, o->lineno); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) + if (PyObject_SetAttr(result, state->lineno, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->col_offset); + value = ast2obj_int(state, o->col_offset); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) + if (PyObject_SetAttr(result, state->col_offset, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->end_lineno); + value = ast2obj_int(state, o->end_lineno); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) + if (PyObject_SetAttr(result, state->end_lineno, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->end_col_offset); + value = ast2obj_int(state, o->end_col_offset); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) - < 0) + if (PyObject_SetAttr(result, state->end_col_offset, value) < 0) goto failed; Py_DECREF(value); return result; @@ -4609,134 +4638,134 @@ failed: return NULL; } -PyObject* ast2obj_expr_context(expr_context_ty o) +PyObject* ast2obj_expr_context(astmodulestate *state, expr_context_ty o) { switch(o) { case Load: - Py_INCREF(astmodulestate_global->Load_singleton); - return astmodulestate_global->Load_singleton; + Py_INCREF(state->Load_singleton); + return state->Load_singleton; case Store: - Py_INCREF(astmodulestate_global->Store_singleton); - return astmodulestate_global->Store_singleton; + Py_INCREF(state->Store_singleton); + return state->Store_singleton; case Del: - Py_INCREF(astmodulestate_global->Del_singleton); - return astmodulestate_global->Del_singleton; + Py_INCREF(state->Del_singleton); + return state->Del_singleton; } Py_UNREACHABLE(); } -PyObject* ast2obj_boolop(boolop_ty o) +PyObject* ast2obj_boolop(astmodulestate *state, boolop_ty o) { switch(o) { case And: - Py_INCREF(astmodulestate_global->And_singleton); - return astmodulestate_global->And_singleton; + Py_INCREF(state->And_singleton); + return state->And_singleton; case Or: - Py_INCREF(astmodulestate_global->Or_singleton); - return astmodulestate_global->Or_singleton; + Py_INCREF(state->Or_singleton); + return state->Or_singleton; } Py_UNREACHABLE(); } -PyObject* ast2obj_operator(operator_ty o) +PyObject* ast2obj_operator(astmodulestate *state, operator_ty o) { switch(o) { case Add: - Py_INCREF(astmodulestate_global->Add_singleton); - return astmodulestate_global->Add_singleton; + Py_INCREF(state->Add_singleton); + return state->Add_singleton; case Sub: - Py_INCREF(astmodulestate_global->Sub_singleton); - return astmodulestate_global->Sub_singleton; + Py_INCREF(state->Sub_singleton); + return state->Sub_singleton; case Mult: - Py_INCREF(astmodulestate_global->Mult_singleton); - return astmodulestate_global->Mult_singleton; + Py_INCREF(state->Mult_singleton); + return state->Mult_singleton; case MatMult: - Py_INCREF(astmodulestate_global->MatMult_singleton); - return astmodulestate_global->MatMult_singleton; + Py_INCREF(state->MatMult_singleton); + return state->MatMult_singleton; case Div: - Py_INCREF(astmodulestate_global->Div_singleton); - return astmodulestate_global->Div_singleton; + Py_INCREF(state->Div_singleton); + return state->Div_singleton; case Mod: - Py_INCREF(astmodulestate_global->Mod_singleton); - return astmodulestate_global->Mod_singleton; + Py_INCREF(state->Mod_singleton); + return state->Mod_singleton; case Pow: - Py_INCREF(astmodulestate_global->Pow_singleton); - return astmodulestate_global->Pow_singleton; + Py_INCREF(state->Pow_singleton); + return state->Pow_singleton; case LShift: - Py_INCREF(astmodulestate_global->LShift_singleton); - return astmodulestate_global->LShift_singleton; + Py_INCREF(state->LShift_singleton); + return state->LShift_singleton; case RShift: - Py_INCREF(astmodulestate_global->RShift_singleton); - return astmodulestate_global->RShift_singleton; + Py_INCREF(state->RShift_singleton); + return state->RShift_singleton; case BitOr: - Py_INCREF(astmodulestate_global->BitOr_singleton); - return astmodulestate_global->BitOr_singleton; + Py_INCREF(state->BitOr_singleton); + return state->BitOr_singleton; case BitXor: - Py_INCREF(astmodulestate_global->BitXor_singleton); - return astmodulestate_global->BitXor_singleton; + Py_INCREF(state->BitXor_singleton); + return state->BitXor_singleton; case BitAnd: - Py_INCREF(astmodulestate_global->BitAnd_singleton); - return astmodulestate_global->BitAnd_singleton; + Py_INCREF(state->BitAnd_singleton); + return state->BitAnd_singleton; case FloorDiv: - Py_INCREF(astmodulestate_global->FloorDiv_singleton); - return astmodulestate_global->FloorDiv_singleton; + Py_INCREF(state->FloorDiv_singleton); + return state->FloorDiv_singleton; } Py_UNREACHABLE(); } -PyObject* ast2obj_unaryop(unaryop_ty o) +PyObject* ast2obj_unaryop(astmodulestate *state, unaryop_ty o) { switch(o) { case Invert: - Py_INCREF(astmodulestate_global->Invert_singleton); - return astmodulestate_global->Invert_singleton; + Py_INCREF(state->Invert_singleton); + return state->Invert_singleton; case Not: - Py_INCREF(astmodulestate_global->Not_singleton); - return astmodulestate_global->Not_singleton; + Py_INCREF(state->Not_singleton); + return state->Not_singleton; case UAdd: - Py_INCREF(astmodulestate_global->UAdd_singleton); - return astmodulestate_global->UAdd_singleton; + Py_INCREF(state->UAdd_singleton); + return state->UAdd_singleton; case USub: - Py_INCREF(astmodulestate_global->USub_singleton); - return astmodulestate_global->USub_singleton; + Py_INCREF(state->USub_singleton); + return state->USub_singleton; } Py_UNREACHABLE(); } -PyObject* ast2obj_cmpop(cmpop_ty o) +PyObject* ast2obj_cmpop(astmodulestate *state, cmpop_ty o) { switch(o) { case Eq: - Py_INCREF(astmodulestate_global->Eq_singleton); - return astmodulestate_global->Eq_singleton; + Py_INCREF(state->Eq_singleton); + return state->Eq_singleton; case NotEq: - Py_INCREF(astmodulestate_global->NotEq_singleton); - return astmodulestate_global->NotEq_singleton; + Py_INCREF(state->NotEq_singleton); + return state->NotEq_singleton; case Lt: - Py_INCREF(astmodulestate_global->Lt_singleton); - return astmodulestate_global->Lt_singleton; + Py_INCREF(state->Lt_singleton); + return state->Lt_singleton; case LtE: - Py_INCREF(astmodulestate_global->LtE_singleton); - return astmodulestate_global->LtE_singleton; + Py_INCREF(state->LtE_singleton); + return state->LtE_singleton; case Gt: - Py_INCREF(astmodulestate_global->Gt_singleton); - return astmodulestate_global->Gt_singleton; + Py_INCREF(state->Gt_singleton); + return state->Gt_singleton; case GtE: - Py_INCREF(astmodulestate_global->GtE_singleton); - return astmodulestate_global->GtE_singleton; + Py_INCREF(state->GtE_singleton); + return state->GtE_singleton; case Is: - Py_INCREF(astmodulestate_global->Is_singleton); - return astmodulestate_global->Is_singleton; + Py_INCREF(state->Is_singleton); + return state->Is_singleton; case IsNot: - Py_INCREF(astmodulestate_global->IsNot_singleton); - return astmodulestate_global->IsNot_singleton; + Py_INCREF(state->IsNot_singleton); + return state->IsNot_singleton; case In: - Py_INCREF(astmodulestate_global->In_singleton); - return astmodulestate_global->In_singleton; + Py_INCREF(state->In_singleton); + return state->In_singleton; case NotIn: - Py_INCREF(astmodulestate_global->NotIn_singleton); - return astmodulestate_global->NotIn_singleton; + Py_INCREF(state->NotIn_singleton); + return state->NotIn_singleton; } Py_UNREACHABLE(); } PyObject* -ast2obj_comprehension(void* _o) +ast2obj_comprehension(astmodulestate *state, void* _o) { comprehension_ty o = (comprehension_ty)_o; PyObject *result = NULL, *value = NULL; @@ -4744,28 +4773,27 @@ ast2obj_comprehension(void* _o) if (!o) { Py_RETURN_NONE; } - - tp = (PyTypeObject *)astmodulestate_global->comprehension_type; + tp = (PyTypeObject *)state->comprehension_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) return NULL; - value = ast2obj_expr(o->target); + value = ast2obj_expr(state, o->target); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1) + if (PyObject_SetAttr(result, state->target, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->iter); + value = ast2obj_expr(state, o->iter); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) + if (PyObject_SetAttr(result, state->iter, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->ifs, ast2obj_expr); + value = ast2obj_list(state, o->ifs, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1) + if (PyObject_SetAttr(result, state->ifs, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_int(o->is_async); + value = ast2obj_int(state, o->is_async); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1) + if (PyObject_SetAttr(result, state->is_async, value) == -1) goto failed; Py_DECREF(value); return result; @@ -4776,7 +4804,7 @@ failed: } PyObject* -ast2obj_excepthandler(void* _o) +ast2obj_excepthandler(astmodulestate *state, void* _o) { excepthandler_ty o = (excepthandler_ty)_o; PyObject *result = NULL, *value = NULL; @@ -4784,48 +4812,46 @@ ast2obj_excepthandler(void* _o) if (!o) { Py_RETURN_NONE; } - switch (o->kind) { case ExceptHandler_kind: - tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type; + tp = (PyTypeObject *)state->ExceptHandler_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.ExceptHandler.type); + value = ast2obj_expr(state, o->v.ExceptHandler.type); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1) + if (PyObject_SetAttr(result, state->type, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_identifier(o->v.ExceptHandler.name); + value = ast2obj_identifier(state, o->v.ExceptHandler.name); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) + if (PyObject_SetAttr(result, state->name, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); + value = ast2obj_list(state, o->v.ExceptHandler.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) + if (PyObject_SetAttr(result, state->body, value) == -1) goto failed; Py_DECREF(value); break; } - value = ast2obj_int(o->lineno); + value = ast2obj_int(state, o->lineno); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) + if (PyObject_SetAttr(result, state->lineno, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->col_offset); + value = ast2obj_int(state, o->col_offset); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) + if (PyObject_SetAttr(result, state->col_offset, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->end_lineno); + value = ast2obj_int(state, o->end_lineno); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) + if (PyObject_SetAttr(result, state->end_lineno, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->end_col_offset); + value = ast2obj_int(state, o->end_col_offset); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) - < 0) + if (PyObject_SetAttr(result, state->end_col_offset, value) < 0) goto failed; Py_DECREF(value); return result; @@ -4836,7 +4862,7 @@ failed: } PyObject* -ast2obj_arguments(void* _o) +ast2obj_arguments(astmodulestate *state, void* _o) { arguments_ty o = (arguments_ty)_o; PyObject *result = NULL, *value = NULL; @@ -4844,46 +4870,42 @@ ast2obj_arguments(void* _o) if (!o) { Py_RETURN_NONE; } - - tp = (PyTypeObject *)astmodulestate_global->arguments_type; + tp = (PyTypeObject *)state->arguments_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) return NULL; - value = ast2obj_list(o->posonlyargs, ast2obj_arg); + value = ast2obj_list(state, o->posonlyargs, ast2obj_arg); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) == - -1) + if (PyObject_SetAttr(result, state->posonlyargs, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->args, ast2obj_arg); + value = ast2obj_list(state, o->args, ast2obj_arg); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) + if (PyObject_SetAttr(result, state->args, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_arg(o->vararg); + value = ast2obj_arg(state, o->vararg); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1) + if (PyObject_SetAttr(result, state->vararg, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->kwonlyargs, ast2obj_arg); + value = ast2obj_list(state, o->kwonlyargs, ast2obj_arg); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) == - -1) + if (PyObject_SetAttr(result, state->kwonlyargs, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->kw_defaults, ast2obj_expr); + value = ast2obj_list(state, o->kw_defaults, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) == - -1) + if (PyObject_SetAttr(result, state->kw_defaults, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_arg(o->kwarg); + value = ast2obj_arg(state, o->kwarg); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1) + if (PyObject_SetAttr(result, state->kwarg, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->defaults, ast2obj_expr); + value = ast2obj_list(state, o->defaults, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1) + if (PyObject_SetAttr(result, state->defaults, value) == -1) goto failed; Py_DECREF(value); return result; @@ -4894,7 +4916,7 @@ failed: } PyObject* -ast2obj_arg(void* _o) +ast2obj_arg(astmodulestate *state, void* _o) { arg_ty o = (arg_ty)_o; PyObject *result = NULL, *value = NULL; @@ -4902,46 +4924,42 @@ ast2obj_arg(void* _o) if (!o) { Py_RETURN_NONE; } - - tp = (PyTypeObject *)astmodulestate_global->arg_type; + tp = (PyTypeObject *)state->arg_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) return NULL; - value = ast2obj_identifier(o->arg); + value = ast2obj_identifier(state, o->arg); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) + if (PyObject_SetAttr(result, state->arg, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->annotation); + value = ast2obj_expr(state, o->annotation); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) == - -1) + if (PyObject_SetAttr(result, state->annotation, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_string(o->type_comment); + value = ast2obj_string(state, o->type_comment); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) == - -1) + if (PyObject_SetAttr(result, state->type_comment, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_int(o->lineno); + value = ast2obj_int(state, o->lineno); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) + if (PyObject_SetAttr(result, state->lineno, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->col_offset); + value = ast2obj_int(state, o->col_offset); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) + if (PyObject_SetAttr(result, state->col_offset, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->end_lineno); + value = ast2obj_int(state, o->end_lineno); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) + if (PyObject_SetAttr(result, state->end_lineno, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->end_col_offset); + value = ast2obj_int(state, o->end_col_offset); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) - < 0) + if (PyObject_SetAttr(result, state->end_col_offset, value) < 0) goto failed; Py_DECREF(value); return result; @@ -4952,7 +4970,7 @@ failed: } PyObject* -ast2obj_keyword(void* _o) +ast2obj_keyword(astmodulestate *state, void* _o) { keyword_ty o = (keyword_ty)_o; PyObject *result = NULL, *value = NULL; @@ -4960,39 +4978,37 @@ ast2obj_keyword(void* _o) if (!o) { Py_RETURN_NONE; } - - tp = (PyTypeObject *)astmodulestate_global->keyword_type; + tp = (PyTypeObject *)state->keyword_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) return NULL; - value = ast2obj_identifier(o->arg); + value = ast2obj_identifier(state, o->arg); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) + if (PyObject_SetAttr(result, state->arg, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->value); + value = ast2obj_expr(state, o->value); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) + if (PyObject_SetAttr(result, state->value, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_int(o->lineno); + value = ast2obj_int(state, o->lineno); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) + if (PyObject_SetAttr(result, state->lineno, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->col_offset); + value = ast2obj_int(state, o->col_offset); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) + if (PyObject_SetAttr(result, state->col_offset, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->end_lineno); + value = ast2obj_int(state, o->end_lineno); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) + if (PyObject_SetAttr(result, state->end_lineno, value) < 0) goto failed; Py_DECREF(value); - value = ast2obj_int(o->end_col_offset); + value = ast2obj_int(state, o->end_col_offset); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) - < 0) + if (PyObject_SetAttr(result, state->end_col_offset, value) < 0) goto failed; Py_DECREF(value); return result; @@ -5003,7 +5019,7 @@ failed: } PyObject* -ast2obj_alias(void* _o) +ast2obj_alias(astmodulestate *state, void* _o) { alias_ty o = (alias_ty)_o; PyObject *result = NULL, *value = NULL; @@ -5011,18 +5027,17 @@ ast2obj_alias(void* _o) if (!o) { Py_RETURN_NONE; } - - tp = (PyTypeObject *)astmodulestate_global->alias_type; + tp = (PyTypeObject *)state->alias_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) return NULL; - value = ast2obj_identifier(o->name); + value = ast2obj_identifier(state, o->name); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) + if (PyObject_SetAttr(result, state->name, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_identifier(o->asname); + value = ast2obj_identifier(state, o->asname); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1) + if (PyObject_SetAttr(result, state->asname, value) == -1) goto failed; Py_DECREF(value); return result; @@ -5033,7 +5048,7 @@ failed: } PyObject* -ast2obj_withitem(void* _o) +ast2obj_withitem(astmodulestate *state, void* _o) { withitem_ty o = (withitem_ty)_o; PyObject *result = NULL, *value = NULL; @@ -5041,20 +5056,17 @@ ast2obj_withitem(void* _o) if (!o) { Py_RETURN_NONE; } - - tp = (PyTypeObject *)astmodulestate_global->withitem_type; + tp = (PyTypeObject *)state->withitem_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) return NULL; - value = ast2obj_expr(o->context_expr); + value = ast2obj_expr(state, o->context_expr); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) == - -1) + if (PyObject_SetAttr(result, state->context_expr, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->optional_vars); + value = ast2obj_expr(state, o->optional_vars); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value) - == -1) + if (PyObject_SetAttr(result, state->optional_vars, value) == -1) goto failed; Py_DECREF(value); return result; @@ -5065,7 +5077,7 @@ failed: } PyObject* -ast2obj_type_ignore(void* _o) +ast2obj_type_ignore(astmodulestate *state, void* _o) { type_ignore_ty o = (type_ignore_ty)_o; PyObject *result = NULL, *value = NULL; @@ -5073,21 +5085,19 @@ ast2obj_type_ignore(void* _o) if (!o) { Py_RETURN_NONE; } - switch (o->kind) { case TypeIgnore_kind: - tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type; + tp = (PyTypeObject *)state->TypeIgnore_type; result = PyType_GenericNew(tp, NULL, NULL); if (!result) goto failed; - value = ast2obj_int(o->v.TypeIgnore.lineno); + value = ast2obj_int(state, o->v.TypeIgnore.lineno); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) == - -1) + if (PyObject_SetAttr(result, state->lineno, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_string(o->v.TypeIgnore.tag); + value = ast2obj_string(state, o->v.TypeIgnore.tag); if (!value) goto failed; - if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1) + if (PyObject_SetAttr(result, state->tag, value) == -1) goto failed; Py_DECREF(value); break; @@ -5101,7 +5111,7 @@ failed: int -obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) +obj2ast_mod(astmodulestate *state, PyObject* obj, mod_ty* out, PyArena* arena) { int isinstance; @@ -5112,7 +5122,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) *out = NULL; return 0; } - tp = astmodulestate_global->Module_type; + tp = state->Module_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -5121,7 +5131,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* type_ignores; - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5143,7 +5153,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5154,8 +5164,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, - &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->type_ignores, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5177,7 +5186,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) type_ignore_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_type_ignore(tmp2, &val, arena); + res = obj2ast_type_ignore(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5192,7 +5201,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Interactive_type; + tp = state->Interactive_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -5200,7 +5209,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (isinstance) { asdl_seq* body; - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5222,7 +5231,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5237,7 +5246,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Expression_type; + tp = state->Expression_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -5245,7 +5254,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (isinstance) { expr_ty body; - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5254,7 +5263,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &body, arena); + res = obj2ast_expr(state, tmp, &body, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -5262,7 +5271,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->FunctionType_type; + tp = state->FunctionType_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -5271,8 +5280,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) asdl_seq* argtypes; expr_ty returns; - if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->argtypes, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5294,7 +5302,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5305,8 +5313,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5315,7 +5322,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &returns, arena); + res = obj2ast_expr(state, tmp, &returns, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -5331,7 +5338,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) } int -obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) +obj2ast_stmt(astmodulestate *state, PyObject* obj, stmt_ty* out, PyArena* arena) { int isinstance; @@ -5346,7 +5353,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) *out = NULL; return 0; } - if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5355,12 +5362,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &lineno, arena); + res = obj2ast_int(state, tmp, &lineno, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5369,12 +5375,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &col_offset, arena); + res = obj2ast_int(state, tmp, &col_offset, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5383,12 +5388,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &end_lineno, arena); + res = obj2ast_int(state, tmp, &end_lineno, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) - < 0) { + if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5397,11 +5401,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &end_col_offset, arena); + res = obj2ast_int(state, tmp, &end_col_offset, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - tp = astmodulestate_global->FunctionDef_type; + tp = state->FunctionDef_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -5414,7 +5418,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty returns; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5423,11 +5427,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_identifier(tmp, &name, arena); + res = obj2ast_identifier(state, tmp, &name, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5436,11 +5440,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_arguments(tmp, &args, arena); + res = obj2ast_arguments(state, tmp, &args, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5462,7 +5466,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5473,8 +5477,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, - &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5496,7 +5499,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5507,8 +5510,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5517,12 +5519,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &returns, arena); + res = obj2ast_expr(state, tmp, &returns, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5531,7 +5532,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_string(tmp, &type_comment, arena); + res = obj2ast_string(state, tmp, &type_comment, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -5541,7 +5542,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->AsyncFunctionDef_type; + tp = state->AsyncFunctionDef_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -5554,7 +5555,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty returns; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5563,11 +5564,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_identifier(tmp, &name, arena); + res = obj2ast_identifier(state, tmp, &name, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5576,11 +5577,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_arguments(tmp, &args, arena); + res = obj2ast_arguments(state, tmp, &args, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5602,7 +5603,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5613,8 +5614,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, - &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5636,7 +5636,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5647,8 +5647,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5657,12 +5656,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &returns, arena); + res = obj2ast_expr(state, tmp, &returns, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5671,7 +5669,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_string(tmp, &type_comment, arena); + res = obj2ast_string(state, tmp, &type_comment, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -5681,7 +5679,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->ClassDef_type; + tp = state->ClassDef_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -5693,7 +5691,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* decorator_list; - if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5702,11 +5700,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_identifier(tmp, &name, arena); + res = obj2ast_identifier(state, tmp, &name, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->bases, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5728,7 +5726,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5739,8 +5737,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5762,7 +5759,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) keyword_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_keyword(tmp2, &val, arena); + res = obj2ast_keyword(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5773,7 +5770,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5795,7 +5792,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5806,8 +5803,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, - &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5829,7 +5825,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5845,7 +5841,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Return_type; + tp = state->Return_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -5853,7 +5849,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5862,7 +5858,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -5871,7 +5867,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Delete_type; + tp = state->Delete_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -5879,8 +5875,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { asdl_seq* targets; - if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5902,7 +5897,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5918,7 +5913,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Assign_type; + tp = state->Assign_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -5928,8 +5923,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty value; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5951,7 +5945,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -5962,7 +5956,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -5971,12 +5965,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -5985,7 +5978,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_string(tmp, &type_comment, arena); + res = obj2ast_string(state, tmp, &type_comment, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -5994,7 +5987,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->AugAssign_type; + tp = state->AugAssign_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -6004,8 +5997,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) operator_ty op; expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6014,11 +6006,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &target, arena); + res = obj2ast_expr(state, tmp, &target, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6027,11 +6019,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_operator(tmp, &op, arena); + res = obj2ast_operator(state, tmp, &op, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6040,7 +6032,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -6049,7 +6041,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->AnnAssign_type; + tp = state->AnnAssign_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -6060,8 +6052,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty value; int simple; - if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6070,12 +6061,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &target, arena); + res = obj2ast_expr(state, tmp, &target, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) - < 0) { + if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6084,11 +6074,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &annotation, arena); + res = obj2ast_expr(state, tmp, &annotation, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6097,12 +6087,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->simple, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6111,7 +6100,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &simple, arena); + res = obj2ast_int(state, tmp, &simple, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -6120,7 +6109,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->For_type; + tp = state->For_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -6132,8 +6121,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* orelse; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6142,11 +6130,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &target, arena); + res = obj2ast_expr(state, tmp, &target, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6155,11 +6143,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &iter, arena); + res = obj2ast_expr(state, tmp, &iter, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6181,7 +6169,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6192,8 +6180,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6215,7 +6202,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6226,8 +6213,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6236,7 +6222,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_string(tmp, &type_comment, arena); + res = obj2ast_string(state, tmp, &type_comment, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -6245,7 +6231,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->AsyncFor_type; + tp = state->AsyncFor_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -6257,8 +6243,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* orelse; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6267,11 +6252,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &target, arena); + res = obj2ast_expr(state, tmp, &target, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6280,11 +6265,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &iter, arena); + res = obj2ast_expr(state, tmp, &iter, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6306,7 +6291,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6317,8 +6302,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6340,7 +6324,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6351,8 +6335,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6361,7 +6344,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_string(tmp, &type_comment, arena); + res = obj2ast_string(state, tmp, &type_comment, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -6370,7 +6353,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->While_type; + tp = state->While_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -6380,7 +6363,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* orelse; - if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6389,11 +6372,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &test, arena); + res = obj2ast_expr(state, tmp, &test, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6415,7 +6398,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6426,8 +6409,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6449,7 +6431,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6465,7 +6447,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->If_type; + tp = state->If_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -6475,7 +6457,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* orelse; - if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6484,11 +6466,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &test, arena); + res = obj2ast_expr(state, tmp, &test, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6510,7 +6492,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6521,8 +6503,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6544,7 +6525,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6560,7 +6541,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->With_type; + tp = state->With_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -6570,7 +6551,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6592,7 +6573,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) withitem_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_withitem(tmp2, &val, arena); + res = obj2ast_withitem(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6603,7 +6584,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6625,7 +6606,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6636,8 +6617,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6646,7 +6626,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_string(tmp, &type_comment, arena); + res = obj2ast_string(state, tmp, &type_comment, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -6655,7 +6635,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->AsyncWith_type; + tp = state->AsyncWith_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -6665,7 +6645,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; string type_comment; - if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6687,7 +6667,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) withitem_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_withitem(tmp2, &val, arena); + res = obj2ast_withitem(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6698,7 +6678,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6720,7 +6700,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6731,8 +6711,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, - &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6741,7 +6720,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_string(tmp, &type_comment, arena); + res = obj2ast_string(state, tmp, &type_comment, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -6750,7 +6729,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Raise_type; + tp = state->Raise_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -6759,7 +6738,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty exc; expr_ty cause; - if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->exc, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6768,11 +6747,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &exc, arena); + res = obj2ast_expr(state, tmp, &exc, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->cause, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6781,7 +6760,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &cause, arena); + res = obj2ast_expr(state, tmp, &cause, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -6790,7 +6769,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Try_type; + tp = state->Try_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -6801,7 +6780,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* orelse; asdl_seq* finalbody; - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6823,7 +6802,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6834,8 +6813,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->handlers, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6857,7 +6835,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) excepthandler_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_excepthandler(tmp2, &val, arena); + res = obj2ast_excepthandler(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6868,8 +6846,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6891,7 +6868,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6902,8 +6879,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->finalbody, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6925,7 +6901,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -6941,7 +6917,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Assert_type; + tp = state->Assert_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -6950,7 +6926,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty test; expr_ty msg; - if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -6959,11 +6935,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &test, arena); + res = obj2ast_expr(state, tmp, &test, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->msg, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -6972,7 +6948,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &msg, arena); + res = obj2ast_expr(state, tmp, &msg, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -6981,7 +6957,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Import_type; + tp = state->Import_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -6989,7 +6965,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { asdl_seq* names; - if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7011,7 +6987,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) alias_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_alias(tmp2, &val, arena); + res = obj2ast_alias(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -7027,7 +7003,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->ImportFrom_type; + tp = state->ImportFrom_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7037,8 +7013,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* names; int level; - if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->module, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -7047,11 +7022,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_identifier(tmp, &module, arena); + res = obj2ast_identifier(state, tmp, &module, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7073,7 +7048,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) alias_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_alias(tmp2, &val, arena); + res = obj2ast_alias(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -7084,7 +7059,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->level, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -7093,7 +7068,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &level, arena); + res = obj2ast_int(state, tmp, &level, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -7102,7 +7077,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Global_type; + tp = state->Global_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7110,7 +7085,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { asdl_seq* names; - if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7132,7 +7107,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) identifier val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_identifier(tmp2, &val, arena); + res = obj2ast_identifier(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -7148,7 +7123,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Nonlocal_type; + tp = state->Nonlocal_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7156,7 +7131,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { asdl_seq* names; - if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7178,7 +7153,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) identifier val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_identifier(tmp2, &val, arena); + res = obj2ast_identifier(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -7194,7 +7169,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Expr_type; + tp = state->Expr_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7202,7 +7177,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7211,7 +7186,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -7220,7 +7195,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Pass_type; + tp = state->Pass_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7231,7 +7206,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Break_type; + tp = state->Break_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7242,7 +7217,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Continue_type; + tp = state->Continue_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7261,7 +7236,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } int -obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) +obj2ast_expr(astmodulestate *state, PyObject* obj, expr_ty* out, PyArena* arena) { int isinstance; @@ -7276,7 +7251,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) *out = NULL; return 0; } - if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7285,12 +7260,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &lineno, arena); + res = obj2ast_int(state, tmp, &lineno, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7299,12 +7273,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &col_offset, arena); + res = obj2ast_int(state, tmp, &col_offset, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -7313,12 +7286,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &end_lineno, arena); + res = obj2ast_int(state, tmp, &end_lineno, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) - < 0) { + if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -7327,11 +7299,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &end_col_offset, arena); + res = obj2ast_int(state, tmp, &end_col_offset, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - tp = astmodulestate_global->BoolOp_type; + tp = state->BoolOp_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7340,7 +7312,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) boolop_ty op; asdl_seq* values; - if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7349,12 +7321,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_boolop(tmp, &op, arena); + res = obj2ast_boolop(state, tmp, &op, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7376,7 +7347,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -7392,7 +7363,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->NamedExpr_type; + tp = state->NamedExpr_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7401,8 +7372,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty target; expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7411,11 +7381,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &target, arena); + res = obj2ast_expr(state, tmp, &target, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7424,7 +7394,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -7433,7 +7403,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->BinOp_type; + tp = state->BinOp_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7443,7 +7413,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) operator_ty op; expr_ty right; - if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7452,11 +7422,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &left, arena); + res = obj2ast_expr(state, tmp, &left, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7465,11 +7435,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_operator(tmp, &op, arena); + res = obj2ast_operator(state, tmp, &op, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->right, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7478,7 +7448,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &right, arena); + res = obj2ast_expr(state, tmp, &right, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -7487,7 +7457,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->UnaryOp_type; + tp = state->UnaryOp_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7496,7 +7466,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) unaryop_ty op; expr_ty operand; - if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7505,12 +7475,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_unaryop(tmp, &op, arena); + res = obj2ast_unaryop(state, tmp, &op, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->operand, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7519,7 +7488,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &operand, arena); + res = obj2ast_expr(state, tmp, &operand, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -7528,7 +7497,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Lambda_type; + tp = state->Lambda_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7537,7 +7506,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) arguments_ty args; expr_ty body; - if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7546,11 +7515,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_arguments(tmp, &args, arena); + res = obj2ast_arguments(state, tmp, &args, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7559,7 +7528,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &body, arena); + res = obj2ast_expr(state, tmp, &body, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -7568,7 +7537,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->IfExp_type; + tp = state->IfExp_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7578,7 +7547,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty body; expr_ty orelse; - if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7587,11 +7556,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &test, arena); + res = obj2ast_expr(state, tmp, &test, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7600,12 +7569,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &body, arena); + res = obj2ast_expr(state, tmp, &body, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7614,7 +7582,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &orelse, arena); + res = obj2ast_expr(state, tmp, &orelse, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -7623,7 +7591,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Dict_type; + tp = state->Dict_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7632,7 +7600,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* keys; asdl_seq* values; - if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7654,7 +7622,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -7665,8 +7633,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7688,7 +7655,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -7704,7 +7671,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Set_type; + tp = state->Set_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7712,7 +7679,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { asdl_seq* elts; - if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7734,7 +7701,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -7749,7 +7716,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->ListComp_type; + tp = state->ListComp_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7758,7 +7725,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty elt; asdl_seq* generators; - if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7767,12 +7734,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &elt, arena); + res = obj2ast_expr(state, tmp, &elt, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) - < 0) { + if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7794,7 +7760,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) comprehension_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_comprehension(tmp2, &val, arena); + res = obj2ast_comprehension(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -7810,7 +7776,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->SetComp_type; + tp = state->SetComp_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7819,7 +7785,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty elt; asdl_seq* generators; - if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7828,12 +7794,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &elt, arena); + res = obj2ast_expr(state, tmp, &elt, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) - < 0) { + if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7855,7 +7820,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) comprehension_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_comprehension(tmp2, &val, arena); + res = obj2ast_comprehension(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -7871,7 +7836,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->DictComp_type; + tp = state->DictComp_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7881,7 +7846,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty value; asdl_seq* generators; - if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->key, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7890,11 +7855,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &key, arena); + res = obj2ast_expr(state, tmp, &key, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7903,12 +7868,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) - < 0) { + if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7930,7 +7894,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) comprehension_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_comprehension(tmp2, &val, arena); + res = obj2ast_comprehension(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -7946,7 +7910,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->GeneratorExp_type; + tp = state->GeneratorExp_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -7955,7 +7919,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty elt; asdl_seq* generators; - if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7964,12 +7928,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &elt, arena); + res = obj2ast_expr(state, tmp, &elt, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) - < 0) { + if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -7991,7 +7954,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) comprehension_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_comprehension(tmp2, &val, arena); + res = obj2ast_comprehension(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -8007,7 +7970,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Await_type; + tp = state->Await_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8015,7 +7978,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8024,7 +7987,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -8033,7 +7996,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Yield_type; + tp = state->Yield_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8041,7 +8004,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8050,7 +8013,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -8059,7 +8022,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->YieldFrom_type; + tp = state->YieldFrom_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8067,7 +8030,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8076,7 +8039,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -8085,7 +8048,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Compare_type; + tp = state->Compare_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8095,7 +8058,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_int_seq* ops; asdl_seq* comparators; - if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8104,11 +8067,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &left, arena); + res = obj2ast_expr(state, tmp, &left, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->ops, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8130,7 +8093,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) cmpop_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_cmpop(tmp2, &val, arena); + res = obj2ast_cmpop(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -8141,8 +8104,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) - < 0) { + if (_PyObject_LookupAttr(obj, state->comparators, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8164,7 +8126,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -8180,7 +8142,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Call_type; + tp = state->Call_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8190,7 +8152,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* args; asdl_seq* keywords; - if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->func, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8199,11 +8161,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &func, arena); + res = obj2ast_expr(state, tmp, &func, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8225,7 +8187,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -8236,8 +8198,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8259,7 +8220,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) keyword_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_keyword(tmp2, &val, arena); + res = obj2ast_keyword(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -8275,7 +8236,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->FormattedValue_type; + tp = state->FormattedValue_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8285,7 +8246,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) int conversion; expr_ty format_spec; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8294,12 +8255,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) - < 0) { + if (_PyObject_LookupAttr(obj, state->conversion, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8308,12 +8268,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &conversion, arena); + res = obj2ast_int(state, tmp, &conversion, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) - < 0) { + if (_PyObject_LookupAttr(obj, state->format_spec, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8322,7 +8281,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &format_spec, arena); + res = obj2ast_expr(state, tmp, &format_spec, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -8331,7 +8290,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->JoinedStr_type; + tp = state->JoinedStr_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8339,8 +8298,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { asdl_seq* values; - if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8362,7 +8320,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -8378,7 +8336,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Constant_type; + tp = state->Constant_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8387,7 +8345,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) constant value; string kind; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8396,11 +8354,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_constant(tmp, &value, arena); + res = obj2ast_constant(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->kind, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8409,7 +8367,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_string(tmp, &kind, arena); + res = obj2ast_string(state, tmp, &kind, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -8418,7 +8376,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Attribute_type; + tp = state->Attribute_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8428,7 +8386,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) identifier attr; expr_context_ty ctx; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8437,11 +8395,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->attr, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8450,11 +8408,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_identifier(tmp, &attr, arena); + res = obj2ast_identifier(state, tmp, &attr, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8463,7 +8421,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr_context(tmp, &ctx, arena); + res = obj2ast_expr_context(state, tmp, &ctx, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -8472,7 +8430,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Subscript_type; + tp = state->Subscript_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8482,7 +8440,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty slice; expr_context_ty ctx; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8491,11 +8449,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->slice, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8504,11 +8462,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &slice, arena); + res = obj2ast_expr(state, tmp, &slice, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8517,7 +8475,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr_context(tmp, &ctx, arena); + res = obj2ast_expr_context(state, tmp, &ctx, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -8526,7 +8484,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Starred_type; + tp = state->Starred_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8535,7 +8493,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty value; expr_context_ty ctx; - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8544,11 +8502,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8557,7 +8515,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr_context(tmp, &ctx, arena); + res = obj2ast_expr_context(state, tmp, &ctx, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -8566,7 +8524,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Name_type; + tp = state->Name_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8575,7 +8533,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) identifier id; expr_context_ty ctx; - if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->id, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8584,11 +8542,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_identifier(tmp, &id, arena); + res = obj2ast_identifier(state, tmp, &id, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8597,7 +8555,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr_context(tmp, &ctx, arena); + res = obj2ast_expr_context(state, tmp, &ctx, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -8606,7 +8564,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->List_type; + tp = state->List_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8615,7 +8573,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* elts; expr_context_ty ctx; - if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8637,7 +8595,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -8648,7 +8606,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8657,7 +8615,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr_context(tmp, &ctx, arena); + res = obj2ast_expr_context(state, tmp, &ctx, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -8666,7 +8624,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Tuple_type; + tp = state->Tuple_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8675,7 +8633,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* elts; expr_context_ty ctx; - if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8697,7 +8655,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -8708,7 +8666,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -8717,7 +8675,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr_context(tmp, &ctx, arena); + res = obj2ast_expr_context(state, tmp, &ctx, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -8726,7 +8684,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - tp = astmodulestate_global->Slice_type; + tp = state->Slice_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -8736,7 +8694,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty upper; expr_ty step; - if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->lower, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8745,11 +8703,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &lower, arena); + res = obj2ast_expr(state, tmp, &lower, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->upper, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8758,11 +8716,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &upper, arena); + res = obj2ast_expr(state, tmp, &upper, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->step, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -8771,7 +8729,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &step, arena); + res = obj2ast_expr(state, tmp, &step, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -8788,11 +8746,12 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } int -obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) +obj2ast_expr_context(astmodulestate *state, PyObject* obj, expr_context_ty* + out, PyArena* arena) { int isinstance; - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type); + isinstance = PyObject_IsInstance(obj, state->Load_type); if (isinstance == -1) { return 1; } @@ -8800,7 +8759,7 @@ obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) *out = Load; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type); + isinstance = PyObject_IsInstance(obj, state->Store_type); if (isinstance == -1) { return 1; } @@ -8808,7 +8767,7 @@ obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) *out = Store; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type); + isinstance = PyObject_IsInstance(obj, state->Del_type); if (isinstance == -1) { return 1; } @@ -8822,11 +8781,12 @@ obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) } int -obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) +obj2ast_boolop(astmodulestate *state, PyObject* obj, boolop_ty* out, PyArena* + arena) { int isinstance; - isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type); + isinstance = PyObject_IsInstance(obj, state->And_type); if (isinstance == -1) { return 1; } @@ -8834,7 +8794,7 @@ obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) *out = And; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type); + isinstance = PyObject_IsInstance(obj, state->Or_type); if (isinstance == -1) { return 1; } @@ -8848,11 +8808,12 @@ obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) } int -obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) +obj2ast_operator(astmodulestate *state, PyObject* obj, operator_ty* out, + PyArena* arena) { int isinstance; - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type); + isinstance = PyObject_IsInstance(obj, state->Add_type); if (isinstance == -1) { return 1; } @@ -8860,7 +8821,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = Add; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type); + isinstance = PyObject_IsInstance(obj, state->Sub_type); if (isinstance == -1) { return 1; } @@ -8868,7 +8829,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = Sub; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type); + isinstance = PyObject_IsInstance(obj, state->Mult_type); if (isinstance == -1) { return 1; } @@ -8876,7 +8837,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = Mult; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type); + isinstance = PyObject_IsInstance(obj, state->MatMult_type); if (isinstance == -1) { return 1; } @@ -8884,7 +8845,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = MatMult; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type); + isinstance = PyObject_IsInstance(obj, state->Div_type); if (isinstance == -1) { return 1; } @@ -8892,7 +8853,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = Div; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type); + isinstance = PyObject_IsInstance(obj, state->Mod_type); if (isinstance == -1) { return 1; } @@ -8900,7 +8861,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = Mod; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type); + isinstance = PyObject_IsInstance(obj, state->Pow_type); if (isinstance == -1) { return 1; } @@ -8908,7 +8869,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = Pow; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type); + isinstance = PyObject_IsInstance(obj, state->LShift_type); if (isinstance == -1) { return 1; } @@ -8916,7 +8877,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = LShift; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type); + isinstance = PyObject_IsInstance(obj, state->RShift_type); if (isinstance == -1) { return 1; } @@ -8924,7 +8885,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = RShift; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type); + isinstance = PyObject_IsInstance(obj, state->BitOr_type); if (isinstance == -1) { return 1; } @@ -8932,7 +8893,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = BitOr; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type); + isinstance = PyObject_IsInstance(obj, state->BitXor_type); if (isinstance == -1) { return 1; } @@ -8940,7 +8901,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = BitXor; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type); + isinstance = PyObject_IsInstance(obj, state->BitAnd_type); if (isinstance == -1) { return 1; } @@ -8948,7 +8909,7 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) *out = BitAnd; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type); + isinstance = PyObject_IsInstance(obj, state->FloorDiv_type); if (isinstance == -1) { return 1; } @@ -8962,11 +8923,12 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) } int -obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) +obj2ast_unaryop(astmodulestate *state, PyObject* obj, unaryop_ty* out, PyArena* + arena) { int isinstance; - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type); + isinstance = PyObject_IsInstance(obj, state->Invert_type); if (isinstance == -1) { return 1; } @@ -8974,7 +8936,7 @@ obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) *out = Invert; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type); + isinstance = PyObject_IsInstance(obj, state->Not_type); if (isinstance == -1) { return 1; } @@ -8982,7 +8944,7 @@ obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) *out = Not; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type); + isinstance = PyObject_IsInstance(obj, state->UAdd_type); if (isinstance == -1) { return 1; } @@ -8990,7 +8952,7 @@ obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) *out = UAdd; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type); + isinstance = PyObject_IsInstance(obj, state->USub_type); if (isinstance == -1) { return 1; } @@ -9004,11 +8966,12 @@ obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) } int -obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) +obj2ast_cmpop(astmodulestate *state, PyObject* obj, cmpop_ty* out, PyArena* + arena) { int isinstance; - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type); + isinstance = PyObject_IsInstance(obj, state->Eq_type); if (isinstance == -1) { return 1; } @@ -9016,7 +8979,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = Eq; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type); + isinstance = PyObject_IsInstance(obj, state->NotEq_type); if (isinstance == -1) { return 1; } @@ -9024,7 +8987,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = NotEq; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type); + isinstance = PyObject_IsInstance(obj, state->Lt_type); if (isinstance == -1) { return 1; } @@ -9032,7 +8995,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = Lt; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type); + isinstance = PyObject_IsInstance(obj, state->LtE_type); if (isinstance == -1) { return 1; } @@ -9040,7 +9003,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = LtE; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type); + isinstance = PyObject_IsInstance(obj, state->Gt_type); if (isinstance == -1) { return 1; } @@ -9048,7 +9011,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = Gt; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type); + isinstance = PyObject_IsInstance(obj, state->GtE_type); if (isinstance == -1) { return 1; } @@ -9056,7 +9019,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = GtE; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type); + isinstance = PyObject_IsInstance(obj, state->Is_type); if (isinstance == -1) { return 1; } @@ -9064,7 +9027,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = Is; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type); + isinstance = PyObject_IsInstance(obj, state->IsNot_type); if (isinstance == -1) { return 1; } @@ -9072,7 +9035,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = IsNot; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type); + isinstance = PyObject_IsInstance(obj, state->In_type); if (isinstance == -1) { return 1; } @@ -9080,7 +9043,7 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) *out = In; return 0; } - isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type); + isinstance = PyObject_IsInstance(obj, state->NotIn_type); if (isinstance == -1) { return 1; } @@ -9094,7 +9057,8 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) } int -obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) +obj2ast_comprehension(astmodulestate *state, PyObject* obj, comprehension_ty* + out, PyArena* arena) { PyObject* tmp = NULL; expr_ty target; @@ -9102,7 +9066,7 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) asdl_seq* ifs; int is_async; - if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9111,11 +9075,11 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &target, arena); + res = obj2ast_expr(state, tmp, &target, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9124,11 +9088,11 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &iter, arena); + res = obj2ast_expr(state, tmp, &iter, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->ifs, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9150,7 +9114,7 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -9161,7 +9125,7 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->is_async, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9170,7 +9134,7 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &is_async, arena); + res = obj2ast_int(state, tmp, &is_async, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -9182,7 +9146,8 @@ failed: } int -obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) +obj2ast_excepthandler(astmodulestate *state, PyObject* obj, excepthandler_ty* + out, PyArena* arena) { int isinstance; @@ -9197,7 +9162,7 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) *out = NULL; return 0; } - if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9206,12 +9171,11 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &lineno, arena); + res = obj2ast_int(state, tmp, &lineno, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9220,12 +9184,11 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &col_offset, arena); + res = obj2ast_int(state, tmp, &col_offset, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9234,12 +9197,11 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &end_lineno, arena); + res = obj2ast_int(state, tmp, &end_lineno, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) - < 0) { + if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9248,11 +9210,11 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &end_col_offset, arena); + res = obj2ast_int(state, tmp, &end_col_offset, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - tp = astmodulestate_global->ExceptHandler_type; + tp = state->ExceptHandler_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -9262,7 +9224,7 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) identifier name; asdl_seq* body; - if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->type, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9271,11 +9233,11 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &type, arena); + res = obj2ast_expr(state, tmp, &type, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9284,11 +9246,11 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) } else { int res; - res = obj2ast_identifier(tmp, &name, arena); + res = obj2ast_identifier(state, tmp, &name, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9310,7 +9272,7 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) stmt_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_stmt(tmp2, &val, arena); + res = obj2ast_stmt(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -9334,7 +9296,8 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) } int -obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) +obj2ast_arguments(astmodulestate *state, PyObject* obj, arguments_ty* out, + PyArena* arena) { PyObject* tmp = NULL; asdl_seq* posonlyargs; @@ -9345,8 +9308,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) arg_ty kwarg; asdl_seq* defaults; - if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->posonlyargs, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9368,7 +9330,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) arg_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_arg(tmp2, &val, arena); + res = obj2ast_arg(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -9379,7 +9341,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9401,7 +9363,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) arg_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_arg(tmp2, &val, arena); + res = obj2ast_arg(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -9412,7 +9374,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->vararg, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9421,12 +9383,11 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } else { int res; - res = obj2ast_arg(tmp, &vararg, arena); + res = obj2ast_arg(state, tmp, &vararg, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->kwonlyargs, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9448,7 +9409,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) arg_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_arg(tmp2, &val, arena); + res = obj2ast_arg(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -9459,8 +9420,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->kw_defaults, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9482,7 +9442,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -9493,7 +9453,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->kwarg, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9502,11 +9462,11 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } else { int res; - res = obj2ast_arg(tmp, &kwarg, arena); + res = obj2ast_arg(state, tmp, &kwarg, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->defaults, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9528,7 +9488,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) expr_ty val; PyObject *tmp2 = PyList_GET_ITEM(tmp, i); Py_INCREF(tmp2); - res = obj2ast_expr(tmp2, &val, arena); + res = obj2ast_expr(state, tmp2, &val, arena); Py_DECREF(tmp2); if (res != 0) goto failed; if (len != PyList_GET_SIZE(tmp)) { @@ -9548,7 +9508,7 @@ failed: } int -obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) +obj2ast_arg(astmodulestate *state, PyObject* obj, arg_ty* out, PyArena* arena) { PyObject* tmp = NULL; identifier arg; @@ -9559,7 +9519,7 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) int end_lineno; int end_col_offset; - if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9568,12 +9528,11 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) } else { int res; - res = obj2ast_identifier(tmp, &arg, arena); + res = obj2ast_identifier(state, tmp, &arg, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9582,12 +9541,11 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &annotation, arena); + res = obj2ast_expr(state, tmp, &annotation, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9596,11 +9554,11 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) } else { int res; - res = obj2ast_string(tmp, &type_comment, arena); + res = obj2ast_string(state, tmp, &type_comment, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9609,12 +9567,11 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &lineno, arena); + res = obj2ast_int(state, tmp, &lineno, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9623,12 +9580,11 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &col_offset, arena); + res = obj2ast_int(state, tmp, &col_offset, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9637,12 +9593,11 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &end_lineno, arena); + res = obj2ast_int(state, tmp, &end_lineno, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) - < 0) { + if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9651,7 +9606,7 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &end_col_offset, arena); + res = obj2ast_int(state, tmp, &end_col_offset, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -9664,7 +9619,8 @@ failed: } int -obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) +obj2ast_keyword(astmodulestate *state, PyObject* obj, keyword_ty* out, PyArena* + arena) { PyObject* tmp = NULL; identifier arg; @@ -9674,7 +9630,7 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) int end_lineno; int end_col_offset; - if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9683,11 +9639,11 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) } else { int res; - res = obj2ast_identifier(tmp, &arg, arena); + res = obj2ast_identifier(state, tmp, &arg, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9696,11 +9652,11 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &value, arena); + res = obj2ast_expr(state, tmp, &value, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9709,12 +9665,11 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &lineno, arena); + res = obj2ast_int(state, tmp, &lineno, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9723,12 +9678,11 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &col_offset, arena); + res = obj2ast_int(state, tmp, &col_offset, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9737,12 +9691,11 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &end_lineno, arena); + res = obj2ast_int(state, tmp, &end_lineno, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) - < 0) { + if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9751,7 +9704,7 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &end_col_offset, arena); + res = obj2ast_int(state, tmp, &end_col_offset, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -9764,13 +9717,14 @@ failed: } int -obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) +obj2ast_alias(astmodulestate *state, PyObject* obj, alias_ty* out, PyArena* + arena) { PyObject* tmp = NULL; identifier name; identifier asname; - if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9779,11 +9733,11 @@ obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) } else { int res; - res = obj2ast_identifier(tmp, &name, arena); + res = obj2ast_identifier(state, tmp, &name, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->asname, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9792,7 +9746,7 @@ obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) } else { int res; - res = obj2ast_identifier(tmp, &asname, arena); + res = obj2ast_identifier(state, tmp, &asname, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -9804,14 +9758,14 @@ failed: } int -obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) +obj2ast_withitem(astmodulestate *state, PyObject* obj, withitem_ty* out, + PyArena* arena) { PyObject* tmp = NULL; expr_ty context_expr; expr_ty optional_vars; - if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->context_expr, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9820,12 +9774,11 @@ obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &context_expr, arena); + res = obj2ast_expr(state, tmp, &context_expr, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < - 0) { + if (_PyObject_LookupAttr(obj, state->optional_vars, &tmp) < 0) { return 1; } if (tmp == NULL || tmp == Py_None) { @@ -9834,7 +9787,7 @@ obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) } else { int res; - res = obj2ast_expr(tmp, &optional_vars, arena); + res = obj2ast_expr(state, tmp, &optional_vars, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -9846,7 +9799,8 @@ failed: } int -obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) +obj2ast_type_ignore(astmodulestate *state, PyObject* obj, type_ignore_ty* out, + PyArena* arena) { int isinstance; @@ -9857,7 +9811,7 @@ obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) *out = NULL; return 0; } - tp = astmodulestate_global->TypeIgnore_type; + tp = state->TypeIgnore_type; isinstance = PyObject_IsInstance(obj, tp); if (isinstance == -1) { return 1; @@ -9866,8 +9820,7 @@ obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) int lineno; string tag; - if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) - { + if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9876,11 +9829,11 @@ obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) } else { int res; - res = obj2ast_int(tmp, &lineno, arena); + res = obj2ast_int(state, tmp, &lineno, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } - if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { + if (_PyObject_LookupAttr(obj, state->tag, &tmp) < 0) { return 1; } if (tmp == NULL) { @@ -9889,7 +9842,7 @@ obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) } else { int res; - res = obj2ast_string(tmp, &tag, arena); + res = obj2ast_string(state, tmp, &tag, arena); if (res != 0) goto failed; Py_CLEAR(tmp); } @@ -9905,523 +9858,490 @@ obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) } +static int +astmodule_exec(PyObject *m) +{ + astmodulestate *state = get_ast_state(m); + + if (!init_types(state)) { + return -1; + } + if (PyModule_AddObject(m, "AST", state->AST_type) < 0) { + return -1; + } + Py_INCREF(state->AST_type); + if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) { + return -1; + } + if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) { + return -1; + } + if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) { + return -1; + } + if (PyModule_AddObject(m, "mod", state->mod_type) < 0) { + return -1; + } + Py_INCREF(state->mod_type); + if (PyModule_AddObject(m, "Module", state->Module_type) < 0) { + return -1; + } + Py_INCREF(state->Module_type); + if (PyModule_AddObject(m, "Interactive", state->Interactive_type) < 0) { + return -1; + } + Py_INCREF(state->Interactive_type); + if (PyModule_AddObject(m, "Expression", state->Expression_type) < 0) { + return -1; + } + Py_INCREF(state->Expression_type); + if (PyModule_AddObject(m, "FunctionType", state->FunctionType_type) < 0) { + return -1; + } + Py_INCREF(state->FunctionType_type); + if (PyModule_AddObject(m, "stmt", state->stmt_type) < 0) { + return -1; + } + Py_INCREF(state->stmt_type); + if (PyModule_AddObject(m, "FunctionDef", state->FunctionDef_type) < 0) { + return -1; + } + Py_INCREF(state->FunctionDef_type); + if (PyModule_AddObject(m, "AsyncFunctionDef", state->AsyncFunctionDef_type) + < 0) { + return -1; + } + Py_INCREF(state->AsyncFunctionDef_type); + if (PyModule_AddObject(m, "ClassDef", state->ClassDef_type) < 0) { + return -1; + } + Py_INCREF(state->ClassDef_type); + if (PyModule_AddObject(m, "Return", state->Return_type) < 0) { + return -1; + } + Py_INCREF(state->Return_type); + if (PyModule_AddObject(m, "Delete", state->Delete_type) < 0) { + return -1; + } + Py_INCREF(state->Delete_type); + if (PyModule_AddObject(m, "Assign", state->Assign_type) < 0) { + return -1; + } + Py_INCREF(state->Assign_type); + if (PyModule_AddObject(m, "AugAssign", state->AugAssign_type) < 0) { + return -1; + } + Py_INCREF(state->AugAssign_type); + if (PyModule_AddObject(m, "AnnAssign", state->AnnAssign_type) < 0) { + return -1; + } + Py_INCREF(state->AnnAssign_type); + if (PyModule_AddObject(m, "For", state->For_type) < 0) { + return -1; + } + Py_INCREF(state->For_type); + if (PyModule_AddObject(m, "AsyncFor", state->AsyncFor_type) < 0) { + return -1; + } + Py_INCREF(state->AsyncFor_type); + if (PyModule_AddObject(m, "While", state->While_type) < 0) { + return -1; + } + Py_INCREF(state->While_type); + if (PyModule_AddObject(m, "If", state->If_type) < 0) { + return -1; + } + Py_INCREF(state->If_type); + if (PyModule_AddObject(m, "With", state->With_type) < 0) { + return -1; + } + Py_INCREF(state->With_type); + if (PyModule_AddObject(m, "AsyncWith", state->AsyncWith_type) < 0) { + return -1; + } + Py_INCREF(state->AsyncWith_type); + if (PyModule_AddObject(m, "Raise", state->Raise_type) < 0) { + return -1; + } + Py_INCREF(state->Raise_type); + if (PyModule_AddObject(m, "Try", state->Try_type) < 0) { + return -1; + } + Py_INCREF(state->Try_type); + if (PyModule_AddObject(m, "Assert", state->Assert_type) < 0) { + return -1; + } + Py_INCREF(state->Assert_type); + if (PyModule_AddObject(m, "Import", state->Import_type) < 0) { + return -1; + } + Py_INCREF(state->Import_type); + if (PyModule_AddObject(m, "ImportFrom", state->ImportFrom_type) < 0) { + return -1; + } + Py_INCREF(state->ImportFrom_type); + if (PyModule_AddObject(m, "Global", state->Global_type) < 0) { + return -1; + } + Py_INCREF(state->Global_type); + if (PyModule_AddObject(m, "Nonlocal", state->Nonlocal_type) < 0) { + return -1; + } + Py_INCREF(state->Nonlocal_type); + if (PyModule_AddObject(m, "Expr", state->Expr_type) < 0) { + return -1; + } + Py_INCREF(state->Expr_type); + if (PyModule_AddObject(m, "Pass", state->Pass_type) < 0) { + return -1; + } + Py_INCREF(state->Pass_type); + if (PyModule_AddObject(m, "Break", state->Break_type) < 0) { + return -1; + } + Py_INCREF(state->Break_type); + if (PyModule_AddObject(m, "Continue", state->Continue_type) < 0) { + return -1; + } + Py_INCREF(state->Continue_type); + if (PyModule_AddObject(m, "expr", state->expr_type) < 0) { + return -1; + } + Py_INCREF(state->expr_type); + if (PyModule_AddObject(m, "BoolOp", state->BoolOp_type) < 0) { + return -1; + } + Py_INCREF(state->BoolOp_type); + if (PyModule_AddObject(m, "NamedExpr", state->NamedExpr_type) < 0) { + return -1; + } + Py_INCREF(state->NamedExpr_type); + if (PyModule_AddObject(m, "BinOp", state->BinOp_type) < 0) { + return -1; + } + Py_INCREF(state->BinOp_type); + if (PyModule_AddObject(m, "UnaryOp", state->UnaryOp_type) < 0) { + return -1; + } + Py_INCREF(state->UnaryOp_type); + if (PyModule_AddObject(m, "Lambda", state->Lambda_type) < 0) { + return -1; + } + Py_INCREF(state->Lambda_type); + if (PyModule_AddObject(m, "IfExp", state->IfExp_type) < 0) { + return -1; + } + Py_INCREF(state->IfExp_type); + if (PyModule_AddObject(m, "Dict", state->Dict_type) < 0) { + return -1; + } + Py_INCREF(state->Dict_type); + if (PyModule_AddObject(m, "Set", state->Set_type) < 0) { + return -1; + } + Py_INCREF(state->Set_type); + if (PyModule_AddObject(m, "ListComp", state->ListComp_type) < 0) { + return -1; + } + Py_INCREF(state->ListComp_type); + if (PyModule_AddObject(m, "SetComp", state->SetComp_type) < 0) { + return -1; + } + Py_INCREF(state->SetComp_type); + if (PyModule_AddObject(m, "DictComp", state->DictComp_type) < 0) { + return -1; + } + Py_INCREF(state->DictComp_type); + if (PyModule_AddObject(m, "GeneratorExp", state->GeneratorExp_type) < 0) { + return -1; + } + Py_INCREF(state->GeneratorExp_type); + if (PyModule_AddObject(m, "Await", state->Await_type) < 0) { + return -1; + } + Py_INCREF(state->Await_type); + if (PyModule_AddObject(m, "Yield", state->Yield_type) < 0) { + return -1; + } + Py_INCREF(state->Yield_type); + if (PyModule_AddObject(m, "YieldFrom", state->YieldFrom_type) < 0) { + return -1; + } + Py_INCREF(state->YieldFrom_type); + if (PyModule_AddObject(m, "Compare", state->Compare_type) < 0) { + return -1; + } + Py_INCREF(state->Compare_type); + if (PyModule_AddObject(m, "Call", state->Call_type) < 0) { + return -1; + } + Py_INCREF(state->Call_type); + if (PyModule_AddObject(m, "FormattedValue", state->FormattedValue_type) < + 0) { + return -1; + } + Py_INCREF(state->FormattedValue_type); + if (PyModule_AddObject(m, "JoinedStr", state->JoinedStr_type) < 0) { + return -1; + } + Py_INCREF(state->JoinedStr_type); + if (PyModule_AddObject(m, "Constant", state->Constant_type) < 0) { + return -1; + } + Py_INCREF(state->Constant_type); + if (PyModule_AddObject(m, "Attribute", state->Attribute_type) < 0) { + return -1; + } + Py_INCREF(state->Attribute_type); + if (PyModule_AddObject(m, "Subscript", state->Subscript_type) < 0) { + return -1; + } + Py_INCREF(state->Subscript_type); + if (PyModule_AddObject(m, "Starred", state->Starred_type) < 0) { + return -1; + } + Py_INCREF(state->Starred_type); + if (PyModule_AddObject(m, "Name", state->Name_type) < 0) { + return -1; + } + Py_INCREF(state->Name_type); + if (PyModule_AddObject(m, "List", state->List_type) < 0) { + return -1; + } + Py_INCREF(state->List_type); + if (PyModule_AddObject(m, "Tuple", state->Tuple_type) < 0) { + return -1; + } + Py_INCREF(state->Tuple_type); + if (PyModule_AddObject(m, "Slice", state->Slice_type) < 0) { + return -1; + } + Py_INCREF(state->Slice_type); + if (PyModule_AddObject(m, "expr_context", state->expr_context_type) < 0) { + return -1; + } + Py_INCREF(state->expr_context_type); + if (PyModule_AddObject(m, "Load", state->Load_type) < 0) { + return -1; + } + Py_INCREF(state->Load_type); + if (PyModule_AddObject(m, "Store", state->Store_type) < 0) { + return -1; + } + Py_INCREF(state->Store_type); + if (PyModule_AddObject(m, "Del", state->Del_type) < 0) { + return -1; + } + Py_INCREF(state->Del_type); + if (PyModule_AddObject(m, "boolop", state->boolop_type) < 0) { + return -1; + } + Py_INCREF(state->boolop_type); + if (PyModule_AddObject(m, "And", state->And_type) < 0) { + return -1; + } + Py_INCREF(state->And_type); + if (PyModule_AddObject(m, "Or", state->Or_type) < 0) { + return -1; + } + Py_INCREF(state->Or_type); + if (PyModule_AddObject(m, "operator", state->operator_type) < 0) { + return -1; + } + Py_INCREF(state->operator_type); + if (PyModule_AddObject(m, "Add", state->Add_type) < 0) { + return -1; + } + Py_INCREF(state->Add_type); + if (PyModule_AddObject(m, "Sub", state->Sub_type) < 0) { + return -1; + } + Py_INCREF(state->Sub_type); + if (PyModule_AddObject(m, "Mult", state->Mult_type) < 0) { + return -1; + } + Py_INCREF(state->Mult_type); + if (PyModule_AddObject(m, "MatMult", state->MatMult_type) < 0) { + return -1; + } + Py_INCREF(state->MatMult_type); + if (PyModule_AddObject(m, "Div", state->Div_type) < 0) { + return -1; + } + Py_INCREF(state->Div_type); + if (PyModule_AddObject(m, "Mod", state->Mod_type) < 0) { + return -1; + } + Py_INCREF(state->Mod_type); + if (PyModule_AddObject(m, "Pow", state->Pow_type) < 0) { + return -1; + } + Py_INCREF(state->Pow_type); + if (PyModule_AddObject(m, "LShift", state->LShift_type) < 0) { + return -1; + } + Py_INCREF(state->LShift_type); + if (PyModule_AddObject(m, "RShift", state->RShift_type) < 0) { + return -1; + } + Py_INCREF(state->RShift_type); + if (PyModule_AddObject(m, "BitOr", state->BitOr_type) < 0) { + return -1; + } + Py_INCREF(state->BitOr_type); + if (PyModule_AddObject(m, "BitXor", state->BitXor_type) < 0) { + return -1; + } + Py_INCREF(state->BitXor_type); + if (PyModule_AddObject(m, "BitAnd", state->BitAnd_type) < 0) { + return -1; + } + Py_INCREF(state->BitAnd_type); + if (PyModule_AddObject(m, "FloorDiv", state->FloorDiv_type) < 0) { + return -1; + } + Py_INCREF(state->FloorDiv_type); + if (PyModule_AddObject(m, "unaryop", state->unaryop_type) < 0) { + return -1; + } + Py_INCREF(state->unaryop_type); + if (PyModule_AddObject(m, "Invert", state->Invert_type) < 0) { + return -1; + } + Py_INCREF(state->Invert_type); + if (PyModule_AddObject(m, "Not", state->Not_type) < 0) { + return -1; + } + Py_INCREF(state->Not_type); + if (PyModule_AddObject(m, "UAdd", state->UAdd_type) < 0) { + return -1; + } + Py_INCREF(state->UAdd_type); + if (PyModule_AddObject(m, "USub", state->USub_type) < 0) { + return -1; + } + Py_INCREF(state->USub_type); + if (PyModule_AddObject(m, "cmpop", state->cmpop_type) < 0) { + return -1; + } + Py_INCREF(state->cmpop_type); + if (PyModule_AddObject(m, "Eq", state->Eq_type) < 0) { + return -1; + } + Py_INCREF(state->Eq_type); + if (PyModule_AddObject(m, "NotEq", state->NotEq_type) < 0) { + return -1; + } + Py_INCREF(state->NotEq_type); + if (PyModule_AddObject(m, "Lt", state->Lt_type) < 0) { + return -1; + } + Py_INCREF(state->Lt_type); + if (PyModule_AddObject(m, "LtE", state->LtE_type) < 0) { + return -1; + } + Py_INCREF(state->LtE_type); + if (PyModule_AddObject(m, "Gt", state->Gt_type) < 0) { + return -1; + } + Py_INCREF(state->Gt_type); + if (PyModule_AddObject(m, "GtE", state->GtE_type) < 0) { + return -1; + } + Py_INCREF(state->GtE_type); + if (PyModule_AddObject(m, "Is", state->Is_type) < 0) { + return -1; + } + Py_INCREF(state->Is_type); + if (PyModule_AddObject(m, "IsNot", state->IsNot_type) < 0) { + return -1; + } + Py_INCREF(state->IsNot_type); + if (PyModule_AddObject(m, "In", state->In_type) < 0) { + return -1; + } + Py_INCREF(state->In_type); + if (PyModule_AddObject(m, "NotIn", state->NotIn_type) < 0) { + return -1; + } + Py_INCREF(state->NotIn_type); + if (PyModule_AddObject(m, "comprehension", state->comprehension_type) < 0) { + return -1; + } + Py_INCREF(state->comprehension_type); + if (PyModule_AddObject(m, "excepthandler", state->excepthandler_type) < 0) { + return -1; + } + Py_INCREF(state->excepthandler_type); + if (PyModule_AddObject(m, "ExceptHandler", state->ExceptHandler_type) < 0) { + return -1; + } + Py_INCREF(state->ExceptHandler_type); + if (PyModule_AddObject(m, "arguments", state->arguments_type) < 0) { + return -1; + } + Py_INCREF(state->arguments_type); + if (PyModule_AddObject(m, "arg", state->arg_type) < 0) { + return -1; + } + Py_INCREF(state->arg_type); + if (PyModule_AddObject(m, "keyword", state->keyword_type) < 0) { + return -1; + } + Py_INCREF(state->keyword_type); + if (PyModule_AddObject(m, "alias", state->alias_type) < 0) { + return -1; + } + Py_INCREF(state->alias_type); + if (PyModule_AddObject(m, "withitem", state->withitem_type) < 0) { + return -1; + } + Py_INCREF(state->withitem_type); + if (PyModule_AddObject(m, "type_ignore", state->type_ignore_type) < 0) { + return -1; + } + Py_INCREF(state->type_ignore_type); + if (PyModule_AddObject(m, "TypeIgnore", state->TypeIgnore_type) < 0) { + return -1; + } + Py_INCREF(state->TypeIgnore_type); + return 0; +} + +static PyModuleDef_Slot astmodule_slots[] = { + {Py_mod_exec, astmodule_exec}, + {0, NULL} +}; + +static struct PyModuleDef _astmodule = { + PyModuleDef_HEAD_INIT, + .m_name = "_ast", + .m_size = sizeof(astmodulestate), + .m_slots = astmodule_slots, + .m_traverse = astmodule_traverse, + .m_clear = astmodule_clear, + .m_free = astmodule_free, +}; + PyMODINIT_FUNC PyInit__ast(void) { - PyObject *m; - if (!init_types()) return NULL; - m = PyState_FindModule(&_astmodule); - if (!m) return NULL; - if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->AST_type); - if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) { - goto error; - } - if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) { - goto error; - } - if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) { - goto error; - } - if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->mod_type); - if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Module_type); - if (PyModule_AddObject(m, "Interactive", - astmodulestate_global->Interactive_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Interactive_type); - if (PyModule_AddObject(m, "Expression", - astmodulestate_global->Expression_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Expression_type); - if (PyModule_AddObject(m, "FunctionType", - astmodulestate_global->FunctionType_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->FunctionType_type); - if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->stmt_type); - if (PyModule_AddObject(m, "FunctionDef", - astmodulestate_global->FunctionDef_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->FunctionDef_type); - if (PyModule_AddObject(m, "AsyncFunctionDef", - astmodulestate_global->AsyncFunctionDef_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type); - if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type) - < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->ClassDef_type); - if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Return_type); - if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Delete_type); - if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Assign_type); - if (PyModule_AddObject(m, "AugAssign", - astmodulestate_global->AugAssign_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->AugAssign_type); - if (PyModule_AddObject(m, "AnnAssign", - astmodulestate_global->AnnAssign_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->AnnAssign_type); - if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->For_type); - if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type) - < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->AsyncFor_type); - if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->While_type); - if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->If_type); - if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->With_type); - if (PyModule_AddObject(m, "AsyncWith", - astmodulestate_global->AsyncWith_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->AsyncWith_type); - if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Raise_type); - if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Try_type); - if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Assert_type); - if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Import_type); - if (PyModule_AddObject(m, "ImportFrom", - astmodulestate_global->ImportFrom_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->ImportFrom_type); - if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Global_type); - if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type) - < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Nonlocal_type); - if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Expr_type); - if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Pass_type); - if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Break_type); - if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type) - < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Continue_type); - if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->expr_type); - if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->BoolOp_type); - if (PyModule_AddObject(m, "NamedExpr", - astmodulestate_global->NamedExpr_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->NamedExpr_type); - if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->BinOp_type); - if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->UnaryOp_type); - if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Lambda_type); - if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->IfExp_type); - if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Dict_type); - if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Set_type); - if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type) - < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->ListComp_type); - if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->SetComp_type); - if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type) - < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->DictComp_type); - if (PyModule_AddObject(m, "GeneratorExp", - astmodulestate_global->GeneratorExp_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->GeneratorExp_type); - if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Await_type); - if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Yield_type); - if (PyModule_AddObject(m, "YieldFrom", - astmodulestate_global->YieldFrom_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->YieldFrom_type); - if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Compare_type); - if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Call_type); - if (PyModule_AddObject(m, "FormattedValue", - astmodulestate_global->FormattedValue_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->FormattedValue_type); - if (PyModule_AddObject(m, "JoinedStr", - astmodulestate_global->JoinedStr_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->JoinedStr_type); - if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type) - < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Constant_type); - if (PyModule_AddObject(m, "Attribute", - astmodulestate_global->Attribute_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Attribute_type); - if (PyModule_AddObject(m, "Subscript", - astmodulestate_global->Subscript_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Subscript_type); - if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Starred_type); - if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Name_type); - if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->List_type); - if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Tuple_type); - if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Slice_type); - if (PyModule_AddObject(m, "expr_context", - astmodulestate_global->expr_context_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->expr_context_type); - if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Load_type); - if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Store_type); - if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Del_type); - if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->boolop_type); - if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->And_type); - if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Or_type); - if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type) - < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->operator_type); - if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Add_type); - if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Sub_type); - if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Mult_type); - if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->MatMult_type); - if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Div_type); - if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Mod_type); - if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Pow_type); - if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->LShift_type); - if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->RShift_type); - if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->BitOr_type); - if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->BitXor_type); - if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->BitAnd_type); - if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type) - < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->FloorDiv_type); - if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->unaryop_type); - if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Invert_type); - if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Not_type); - if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->UAdd_type); - if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->USub_type); - if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->cmpop_type); - if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Eq_type); - if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->NotEq_type); - if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Lt_type); - if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->LtE_type); - if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Gt_type); - if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->GtE_type); - if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->Is_type); - if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->IsNot_type); - if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->In_type); - if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->NotIn_type); - if (PyModule_AddObject(m, "comprehension", - astmodulestate_global->comprehension_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->comprehension_type); - if (PyModule_AddObject(m, "excepthandler", - astmodulestate_global->excepthandler_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->excepthandler_type); - if (PyModule_AddObject(m, "ExceptHandler", - astmodulestate_global->ExceptHandler_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->ExceptHandler_type); - if (PyModule_AddObject(m, "arguments", - astmodulestate_global->arguments_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->arguments_type); - if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->arg_type); - if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) < - 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->keyword_type); - if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->alias_type); - if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type) - < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->withitem_type); - if (PyModule_AddObject(m, "type_ignore", - astmodulestate_global->type_ignore_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->type_ignore_type); - if (PyModule_AddObject(m, "TypeIgnore", - astmodulestate_global->TypeIgnore_type) < 0) { - goto error; - } - Py_INCREF(astmodulestate(m)->TypeIgnore_type); - return m; -error: - Py_DECREF(m); - return NULL; + return PyModuleDef_Init(&_astmodule); } PyObject* PyAST_mod2obj(mod_ty t) { - if (!init_types()) + astmodulestate *state = get_global_ast_state(); + if (state == NULL) { return NULL; - return ast2obj_mod(t); + } + return ast2obj_mod(state, t); } /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) { - PyObject *req_type[3]; const char * const req_name[] = {"Module", "Expression", "Interactive"}; int isinstance; @@ -10429,15 +10349,14 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) return NULL; } - req_type[0] = astmodulestate_global->Module_type; - req_type[1] = astmodulestate_global->Expression_type; - req_type[2] = astmodulestate_global->Interactive_type; + astmodulestate *state = get_global_ast_state(); + PyObject *req_type[3]; + req_type[0] = state->Module_type; + req_type[1] = state->Expression_type; + req_type[2] = state->Interactive_type; assert(0 <= mode && mode <= 2); - if (!init_types()) - return NULL; - isinstance = PyObject_IsInstance(ast, req_type[mode]); if (isinstance == -1) return NULL; @@ -10448,7 +10367,7 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) } mod_ty res = NULL; - if (obj2ast_mod(ast, &res, arena) != 0) + if (obj2ast_mod(state, ast, &res, arena) != 0) return NULL; else return res; @@ -10456,9 +10375,11 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) int PyAST_Check(PyObject* obj) { - if (!init_types()) + astmodulestate *state = get_global_ast_state(); + if (state == NULL) { return -1; - return PyObject_IsInstance(obj, astmodulestate_global->AST_type); + } + return PyObject_IsInstance(obj, state->AST_type); } diff --git a/Python/_warnings.c b/Python/_warnings.c index 4d65bb30c8e..86bbfa1c8db 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -32,14 +32,14 @@ _Py_IDENTIFIER(__name__); static WarningsState * warnings_get_state(void) { - PyThreadState *tstate = _PyThreadState_GET(); - if (tstate == NULL) { - _PyErr_SetString(tstate, PyExc_RuntimeError, - "warnings_get_state: could not identify " - "current interpreter"); + PyInterpreterState *interp = _PyInterpreterState_GET(); + if (interp == NULL) { + PyErr_SetString(PyExc_RuntimeError, + "warnings_get_state: could not identify " + "current interpreter"); return NULL; } - return &tstate->interp->warnings; + return &interp->warnings; } /* Clear the given warnings module state. */ diff --git a/Python/ast.c b/Python/ast.c index 2d20ca62aa8..7bf66e50aa1 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -5,7 +5,6 @@ */ #include "Python.h" #include "Python-ast.h" -#include "node.h" #include "ast.h" #include "token.h" #include "pythonrun.h" @@ -21,6 +20,25 @@ static int validate_nonempty_seq(asdl_seq *, const char *, const char *); static int validate_stmt(stmt_ty); static int validate_expr(expr_ty, expr_context_ty); +static int +validate_name(PyObject *name) +{ + assert(PyUnicode_Check(name)); + static const char * const forbidden[] = { + "None", + "True", + "False", + NULL + }; + for (int i = 0; forbidden[i] != NULL; i++) { + if (_PyUnicode_EqualToASCIIString(name, forbidden[i])) { + PyErr_Format(PyExc_ValueError, "Name node can't be used with '%s' constant", forbidden[i]); + return 0; + } + } + return 1; +} + static int validate_comprehension(asdl_seq *gens) { @@ -173,6 +191,9 @@ validate_expr(expr_ty exp, expr_context_ty ctx) actual_ctx = exp->v.Starred.ctx; break; case Name_kind: + if (!validate_name(exp->v.Name.id)) { + return 0; + } actual_ctx = exp->v.Name.ctx; break; case List_kind: @@ -528,5289 +549,6 @@ PyAST_Validate(mod_ty mod) return res; } -/* This is done here, so defines like "test" don't interfere with AST use above. */ -#include "grammar.h" -#include "parsetok.h" -#include "graminit.h" - -/* Data structure used internally */ -struct compiling { - PyArena *c_arena; /* Arena for allocating memory. */ - PyObject *c_filename; /* filename */ - PyObject *c_normalize; /* Normalization function from unicodedata. */ - int c_feature_version; /* Latest minor version of Python for allowed features */ -}; - -static asdl_seq *seq_for_testlist(struct compiling *, const node *); -static expr_ty ast_for_expr(struct compiling *, const node *); -static stmt_ty ast_for_stmt(struct compiling *, const node *); -static asdl_seq *ast_for_suite(struct compiling *c, const node *n); -static asdl_seq *ast_for_exprlist(struct compiling *, const node *, - expr_context_ty); -static expr_ty ast_for_testlist(struct compiling *, const node *); -static stmt_ty ast_for_classdef(struct compiling *, const node *, asdl_seq *); - -static stmt_ty ast_for_with_stmt(struct compiling *, const node *, bool); -static stmt_ty ast_for_for_stmt(struct compiling *, const node *, bool); - -/* Note different signature for ast_for_call */ -static expr_ty ast_for_call(struct compiling *, const node *, expr_ty, - const node *, const node *, const node *); - -static PyObject *parsenumber(struct compiling *, const char *); -static expr_ty parsestrplus(struct compiling *, const node *n); -static void get_last_end_pos(asdl_seq *, int *, int *); - -#define COMP_GENEXP 0 -#define COMP_LISTCOMP 1 -#define COMP_SETCOMP 2 - -static int -init_normalization(struct compiling *c) -{ - PyObject *m = PyImport_ImportModuleNoBlock("unicodedata"); - if (!m) - return 0; - c->c_normalize = PyObject_GetAttrString(m, "normalize"); - Py_DECREF(m); - if (!c->c_normalize) - return 0; - return 1; -} - -static identifier -new_identifier(const char *n, struct compiling *c) -{ - PyObject *id = PyUnicode_DecodeUTF8(n, strlen(n), NULL); - if (!id) - return NULL; - /* PyUnicode_DecodeUTF8 should always return a ready string. */ - assert(PyUnicode_IS_READY(id)); - /* Check whether there are non-ASCII characters in the - identifier; if so, normalize to NFKC. */ - if (!PyUnicode_IS_ASCII(id)) { - PyObject *id2; - if (!c->c_normalize && !init_normalization(c)) { - Py_DECREF(id); - return NULL; - } - PyObject *form = PyUnicode_InternFromString("NFKC"); - if (form == NULL) { - Py_DECREF(id); - return NULL; - } - PyObject *args[2] = {form, id}; - id2 = _PyObject_FastCall(c->c_normalize, args, 2); - Py_DECREF(id); - Py_DECREF(form); - if (!id2) - return NULL; - if (!PyUnicode_Check(id2)) { - PyErr_Format(PyExc_TypeError, - "unicodedata.normalize() must return a string, not " - "%.200s", - _PyType_Name(Py_TYPE(id2))); - Py_DECREF(id2); - return NULL; - } - id = id2; - } - PyUnicode_InternInPlace(&id); - if (PyArena_AddPyObject(c->c_arena, id) < 0) { - Py_DECREF(id); - return NULL; - } - return id; -} - -#define NEW_IDENTIFIER(n) new_identifier(STR(n), c) - -static int -ast_error(struct compiling *c, const node *n, const char *errmsg, ...) -{ - PyObject *value, *errstr, *loc, *tmp; - va_list va; - - va_start(va, errmsg); - errstr = PyUnicode_FromFormatV(errmsg, va); - va_end(va); - if (!errstr) { - return 0; - } - loc = PyErr_ProgramTextObject(c->c_filename, LINENO(n)); - if (!loc) { - Py_INCREF(Py_None); - loc = Py_None; - } - tmp = Py_BuildValue("(OiiN)", c->c_filename, LINENO(n), n->n_col_offset + 1, loc); - if (!tmp) { - Py_DECREF(errstr); - return 0; - } - value = PyTuple_Pack(2, errstr, tmp); - Py_DECREF(errstr); - Py_DECREF(tmp); - if (value) { - PyErr_SetObject(PyExc_SyntaxError, value); - Py_DECREF(value); - } - return 0; -} - -/* num_stmts() returns number of contained statements. - - Use this routine to determine how big a sequence is needed for - the statements in a parse tree. Its raison d'etre is this bit of - grammar: - - stmt: simple_stmt | compound_stmt - simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE - - A simple_stmt can contain multiple small_stmt elements joined - by semicolons. If the arg is a simple_stmt, the number of - small_stmt elements is returned. -*/ - -static string -new_type_comment(const char *s, struct compiling *c) -{ - PyObject *res = PyUnicode_DecodeUTF8(s, strlen(s), NULL); - if (res == NULL) - return NULL; - if (PyArena_AddPyObject(c->c_arena, res) < 0) { - Py_DECREF(res); - return NULL; - } - return res; -} -#define NEW_TYPE_COMMENT(n) new_type_comment(STR(n), c) - -static int -num_stmts(const node *n) -{ - int i, l; - node *ch; - - switch (TYPE(n)) { - case single_input: - if (TYPE(CHILD(n, 0)) == NEWLINE) - return 0; - else - return num_stmts(CHILD(n, 0)); - case file_input: - l = 0; - for (i = 0; i < NCH(n); i++) { - ch = CHILD(n, i); - if (TYPE(ch) == stmt) - l += num_stmts(ch); - } - return l; - case stmt: - return num_stmts(CHILD(n, 0)); - case compound_stmt: - return 1; - case simple_stmt: - return NCH(n) / 2; /* Divide by 2 to remove count of semi-colons */ - case suite: - case func_body_suite: - /* func_body_suite: simple_stmt | NEWLINE [TYPE_COMMENT NEWLINE] INDENT stmt+ DEDENT */ - /* suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT */ - if (NCH(n) == 1) - return num_stmts(CHILD(n, 0)); - else { - i = 2; - l = 0; - if (TYPE(CHILD(n, 1)) == TYPE_COMMENT) - i += 2; - for (; i < (NCH(n) - 1); i++) - l += num_stmts(CHILD(n, i)); - return l; - } - default: { - _Py_FatalErrorFormat(__func__, "Non-statement found: %d %d", - TYPE(n), NCH(n)); - } - } - Py_UNREACHABLE(); -} - -/* Transform the CST rooted at node * to the appropriate AST -*/ - -mod_ty -PyAST_FromNodeObject(const node *n, PyCompilerFlags *flags, - PyObject *filename, PyArena *arena) -{ - int i, j, k, num; - asdl_seq *stmts = NULL; - asdl_seq *type_ignores = NULL; - stmt_ty s; - node *ch; - struct compiling c; - mod_ty res = NULL; - asdl_seq *argtypes = NULL; - expr_ty ret, arg; - - c.c_arena = arena; - /* borrowed reference */ - c.c_filename = filename; - c.c_normalize = NULL; - c.c_feature_version = flags ? flags->cf_feature_version : PY_MINOR_VERSION; - - if (TYPE(n) == encoding_decl) - n = CHILD(n, 0); - - k = 0; - switch (TYPE(n)) { - case file_input: - stmts = _Py_asdl_seq_new(num_stmts(n), arena); - if (!stmts) - goto out; - for (i = 0; i < NCH(n) - 1; i++) { - ch = CHILD(n, i); - if (TYPE(ch) == NEWLINE) - continue; - REQ(ch, stmt); - num = num_stmts(ch); - if (num == 1) { - s = ast_for_stmt(&c, ch); - if (!s) - goto out; - asdl_seq_SET(stmts, k++, s); - } - else { - ch = CHILD(ch, 0); - REQ(ch, simple_stmt); - for (j = 0; j < num; j++) { - s = ast_for_stmt(&c, CHILD(ch, j * 2)); - if (!s) - goto out; - asdl_seq_SET(stmts, k++, s); - } - } - } - - /* Type ignores are stored under the ENDMARKER in file_input. */ - ch = CHILD(n, NCH(n) - 1); - REQ(ch, ENDMARKER); - num = NCH(ch); - type_ignores = _Py_asdl_seq_new(num, arena); - if (!type_ignores) - goto out; - - for (i = 0; i < num; i++) { - string type_comment = new_type_comment(STR(CHILD(ch, i)), &c); - if (!type_comment) - goto out; - type_ignore_ty ti = TypeIgnore(LINENO(CHILD(ch, i)), type_comment, arena); - if (!ti) - goto out; - asdl_seq_SET(type_ignores, i, ti); - } - - res = Module(stmts, type_ignores, arena); - break; - case eval_input: { - expr_ty testlist_ast; - - /* XXX Why not comp_for here? */ - testlist_ast = ast_for_testlist(&c, CHILD(n, 0)); - if (!testlist_ast) - goto out; - res = Expression(testlist_ast, arena); - break; - } - case single_input: - if (TYPE(CHILD(n, 0)) == NEWLINE) { - stmts = _Py_asdl_seq_new(1, arena); - if (!stmts) - goto out; - asdl_seq_SET(stmts, 0, Pass(n->n_lineno, n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, - arena)); - if (!asdl_seq_GET(stmts, 0)) - goto out; - res = Interactive(stmts, arena); - } - else { - n = CHILD(n, 0); - num = num_stmts(n); - stmts = _Py_asdl_seq_new(num, arena); - if (!stmts) - goto out; - if (num == 1) { - s = ast_for_stmt(&c, n); - if (!s) - goto out; - asdl_seq_SET(stmts, 0, s); - } - else { - /* Only a simple_stmt can contain multiple statements. */ - REQ(n, simple_stmt); - for (i = 0; i < NCH(n); i += 2) { - if (TYPE(CHILD(n, i)) == NEWLINE) - break; - s = ast_for_stmt(&c, CHILD(n, i)); - if (!s) - goto out; - asdl_seq_SET(stmts, i / 2, s); - } - } - - res = Interactive(stmts, arena); - } - break; - case func_type_input: - n = CHILD(n, 0); - REQ(n, func_type); - - if (TYPE(CHILD(n, 1)) == typelist) { - ch = CHILD(n, 1); - /* this is overly permissive -- we don't pay any attention to - * stars on the args -- just parse them into an ordered list */ - num = 0; - for (i = 0; i < NCH(ch); i++) { - if (TYPE(CHILD(ch, i)) == test) { - num++; - } - } - - argtypes = _Py_asdl_seq_new(num, arena); - if (!argtypes) - goto out; - - j = 0; - for (i = 0; i < NCH(ch); i++) { - if (TYPE(CHILD(ch, i)) == test) { - arg = ast_for_expr(&c, CHILD(ch, i)); - if (!arg) - goto out; - asdl_seq_SET(argtypes, j++, arg); - } - } - } - else { - argtypes = _Py_asdl_seq_new(0, arena); - if (!argtypes) - goto out; - } - - ret = ast_for_expr(&c, CHILD(n, NCH(n) - 1)); - if (!ret) - goto out; - res = FunctionType(argtypes, ret, arena); - break; - default: - PyErr_Format(PyExc_SystemError, - "invalid node %d for PyAST_FromNode", TYPE(n)); - goto out; - } - out: - if (c.c_normalize) { - Py_DECREF(c.c_normalize); - } - return res; -} - -mod_ty -PyAST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename_str, - PyArena *arena) -{ - mod_ty mod; - PyObject *filename; - filename = PyUnicode_DecodeFSDefault(filename_str); - if (filename == NULL) - return NULL; - mod = PyAST_FromNodeObject(n, flags, filename, arena); - Py_DECREF(filename); - return mod; - -} - -/* Return the AST repr. of the operator represented as syntax (|, ^, etc.) -*/ - -static operator_ty -get_operator(struct compiling *c, const node *n) -{ - switch (TYPE(n)) { - case VBAR: - return BitOr; - case CIRCUMFLEX: - return BitXor; - case AMPER: - return BitAnd; - case LEFTSHIFT: - return LShift; - case RIGHTSHIFT: - return RShift; - case PLUS: - return Add; - case MINUS: - return Sub; - case STAR: - return Mult; - case AT: - if (c->c_feature_version < 5) { - ast_error(c, n, - "The '@' operator is only supported in Python 3.5 and greater"); - return (operator_ty)0; - } - return MatMult; - case SLASH: - return Div; - case DOUBLESLASH: - return FloorDiv; - case PERCENT: - return Mod; - default: - return (operator_ty)0; - } -} - -static const char * const FORBIDDEN[] = { - "None", - "True", - "False", - "__debug__", - NULL, -}; - -static int -forbidden_name(struct compiling *c, identifier name, const node *n, - int full_checks) -{ - assert(PyUnicode_Check(name)); - const char * const *p = FORBIDDEN; - if (!full_checks) { - /* In most cases, the parser will protect True, False, and None - from being assign to. */ - p += 3; - } - for (; *p; p++) { - if (_PyUnicode_EqualToASCIIString(name, *p)) { - ast_error(c, n, "cannot assign to %U", name); - return 1; - } - } - return 0; -} - -static expr_ty -copy_location(expr_ty e, const node *n, const node *end) -{ - if (e) { - e->lineno = LINENO(n); - e->col_offset = n->n_col_offset; - e->end_lineno = end->n_end_lineno; - e->end_col_offset = end->n_end_col_offset; - } - return e; -} - -static const char * -get_expr_name(expr_ty e) -{ - switch (e->kind) { - case Attribute_kind: - return "attribute"; - case Subscript_kind: - return "subscript"; - case Starred_kind: - return "starred"; - case Name_kind: - return "name"; - case List_kind: - return "list"; - case Tuple_kind: - return "tuple"; - case Lambda_kind: - return "lambda"; - case Call_kind: - return "function call"; - case BoolOp_kind: - case BinOp_kind: - case UnaryOp_kind: - return "operator"; - case GeneratorExp_kind: - return "generator expression"; - case Yield_kind: - case YieldFrom_kind: - return "yield expression"; - case Await_kind: - return "await expression"; - case ListComp_kind: - return "list comprehension"; - case SetComp_kind: - return "set comprehension"; - case DictComp_kind: - return "dict comprehension"; - case Dict_kind: - return "dict display"; - case Set_kind: - return "set display"; - case JoinedStr_kind: - case FormattedValue_kind: - return "f-string expression"; - case Constant_kind: { - PyObject *value = e->v.Constant.value; - if (value == Py_None) { - return "None"; - } - if (value == Py_False) { - return "False"; - } - if (value == Py_True) { - return "True"; - } - if (value == Py_Ellipsis) { - return "Ellipsis"; - } - return "literal"; - } - case Compare_kind: - return "comparison"; - case IfExp_kind: - return "conditional expression"; - case NamedExpr_kind: - return "named expression"; - default: - PyErr_Format(PyExc_SystemError, - "unexpected expression in assignment %d (line %d)", - e->kind, e->lineno); - return NULL; - } -} - -/* Set the context ctx for expr_ty e, recursively traversing e. - - Only sets context for expr kinds that "can appear in assignment context" - (according to ../Parser/Python.asdl). For other expr kinds, it sets - an appropriate syntax error and returns false. -*/ - -static int -set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n) -{ - asdl_seq *s = NULL; - - /* Expressions in an augmented assignment have a Store context. */ - - switch (e->kind) { - case Attribute_kind: - e->v.Attribute.ctx = ctx; - if (ctx == Store && forbidden_name(c, e->v.Attribute.attr, n, 1)) - return 0; - break; - case Subscript_kind: - e->v.Subscript.ctx = ctx; - break; - case Starred_kind: - e->v.Starred.ctx = ctx; - if (!set_context(c, e->v.Starred.value, ctx, n)) - return 0; - break; - case Name_kind: - if (ctx == Store) { - if (forbidden_name(c, e->v.Name.id, n, 0)) - return 0; /* forbidden_name() calls ast_error() */ - } - e->v.Name.ctx = ctx; - break; - case List_kind: - e->v.List.ctx = ctx; - s = e->v.List.elts; - break; - case Tuple_kind: - e->v.Tuple.ctx = ctx; - s = e->v.Tuple.elts; - break; - default: { - const char *expr_name = get_expr_name(e); - if (expr_name != NULL) { - ast_error(c, n, "cannot %s %s", - ctx == Store ? "assign to" : "delete", - expr_name); - } - return 0; - } - } - - /* If the LHS is a list or tuple, we need to set the assignment - context for all the contained elements. - */ - if (s) { - Py_ssize_t i; - - for (i = 0; i < asdl_seq_LEN(s); i++) { - if (!set_context(c, (expr_ty)asdl_seq_GET(s, i), ctx, n)) - return 0; - } - } - return 1; -} - -static operator_ty -ast_for_augassign(struct compiling *c, const node *n) -{ - REQ(n, augassign); - n = CHILD(n, 0); - switch (STR(n)[0]) { - case '+': - return Add; - case '-': - return Sub; - case '/': - if (STR(n)[1] == '/') - return FloorDiv; - else - return Div; - case '%': - return Mod; - case '<': - return LShift; - case '>': - return RShift; - case '&': - return BitAnd; - case '^': - return BitXor; - case '|': - return BitOr; - case '*': - if (STR(n)[1] == '*') - return Pow; - else - return Mult; - case '@': - if (c->c_feature_version < 5) { - ast_error(c, n, - "The '@' operator is only supported in Python 3.5 and greater"); - return (operator_ty)0; - } - return MatMult; - default: - PyErr_Format(PyExc_SystemError, "invalid augassign: %s", STR(n)); - return (operator_ty)0; - } -} - -static cmpop_ty -ast_for_comp_op(struct compiling *c, const node *n) -{ - /* comp_op: '<'|'>'|'=='|'>='|'<='|'!='|'in'|'not' 'in'|'is' - |'is' 'not' - */ - REQ(n, comp_op); - if (NCH(n) == 1) { - n = CHILD(n, 0); - switch (TYPE(n)) { - case LESS: - return Lt; - case GREATER: - return Gt; - case EQEQUAL: /* == */ - return Eq; - case LESSEQUAL: - return LtE; - case GREATEREQUAL: - return GtE; - case NOTEQUAL: - return NotEq; - case NAME: - if (strcmp(STR(n), "in") == 0) - return In; - if (strcmp(STR(n), "is") == 0) - return Is; - /* fall through */ - default: - PyErr_Format(PyExc_SystemError, "invalid comp_op: %s", - STR(n)); - return (cmpop_ty)0; - } - } - else if (NCH(n) == 2) { - /* handle "not in" and "is not" */ - switch (TYPE(CHILD(n, 0))) { - case NAME: - if (strcmp(STR(CHILD(n, 1)), "in") == 0) - return NotIn; - if (strcmp(STR(CHILD(n, 0)), "is") == 0) - return IsNot; - /* fall through */ - default: - PyErr_Format(PyExc_SystemError, "invalid comp_op: %s %s", - STR(CHILD(n, 0)), STR(CHILD(n, 1))); - return (cmpop_ty)0; - } - } - PyErr_Format(PyExc_SystemError, "invalid comp_op: has %d children", - NCH(n)); - return (cmpop_ty)0; -} - -static asdl_seq * -seq_for_testlist(struct compiling *c, const node *n) -{ - /* testlist: test (',' test)* [','] - testlist_star_expr: test|star_expr (',' test|star_expr)* [','] - */ - asdl_seq *seq; - expr_ty expression; - int i; - assert(TYPE(n) == testlist || TYPE(n) == testlist_star_expr || TYPE(n) == testlist_comp); - - seq = _Py_asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); - if (!seq) - return NULL; - - for (i = 0; i < NCH(n); i += 2) { - const node *ch = CHILD(n, i); - assert(TYPE(ch) == test || TYPE(ch) == test_nocond || TYPE(ch) == star_expr || TYPE(ch) == namedexpr_test); - - expression = ast_for_expr(c, ch); - if (!expression) - return NULL; - - assert(i / 2 < seq->size); - asdl_seq_SET(seq, i / 2, expression); - } - return seq; -} - -static arg_ty -ast_for_arg(struct compiling *c, const node *n) -{ - identifier name; - expr_ty annotation = NULL; - node *ch; - arg_ty ret; - - assert(TYPE(n) == tfpdef || TYPE(n) == vfpdef); - ch = CHILD(n, 0); - name = NEW_IDENTIFIER(ch); - if (!name) - return NULL; - if (forbidden_name(c, name, ch, 0)) - return NULL; - - if (NCH(n) == 3 && TYPE(CHILD(n, 1)) == COLON) { - annotation = ast_for_expr(c, CHILD(n, 2)); - if (!annotation) - return NULL; - } - - ret = arg(name, annotation, NULL, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - if (!ret) - return NULL; - return ret; -} - -/* returns -1 if failed to handle keyword only arguments - returns new position to keep processing if successful - (',' tfpdef ['=' test])* - ^^^ - start pointing here - */ -static int -handle_keywordonly_args(struct compiling *c, const node *n, int start, - asdl_seq *kwonlyargs, asdl_seq *kwdefaults) -{ - PyObject *argname; - node *ch; - expr_ty expression, annotation; - arg_ty arg = NULL; - int i = start; - int j = 0; /* index for kwdefaults and kwonlyargs */ - - if (kwonlyargs == NULL) { - ast_error(c, CHILD(n, start), "named arguments must follow bare *"); - return -1; - } - assert(kwdefaults != NULL); - while (i < NCH(n)) { - ch = CHILD(n, i); - switch (TYPE(ch)) { - case vfpdef: - case tfpdef: - if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) { - expression = ast_for_expr(c, CHILD(n, i + 2)); - if (!expression) - goto error; - asdl_seq_SET(kwdefaults, j, expression); - i += 2; /* '=' and test */ - } - else { /* setting NULL if no default value exists */ - asdl_seq_SET(kwdefaults, j, NULL); - } - if (NCH(ch) == 3) { - /* ch is NAME ':' test */ - annotation = ast_for_expr(c, CHILD(ch, 2)); - if (!annotation) - goto error; - } - else { - annotation = NULL; - } - ch = CHILD(ch, 0); - argname = NEW_IDENTIFIER(ch); - if (!argname) - goto error; - if (forbidden_name(c, argname, ch, 0)) - goto error; - arg = arg(argname, annotation, NULL, LINENO(ch), ch->n_col_offset, - ch->n_end_lineno, ch->n_end_col_offset, - c->c_arena); - if (!arg) - goto error; - asdl_seq_SET(kwonlyargs, j++, arg); - i += 1; /* the name */ - if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA) - i += 1; /* the comma, if present */ - break; - case TYPE_COMMENT: - /* arg will be equal to the last argument processed */ - arg->type_comment = NEW_TYPE_COMMENT(ch); - if (!arg->type_comment) - goto error; - i += 1; - break; - case DOUBLESTAR: - return i; - default: - ast_error(c, ch, "unexpected node"); - goto error; - } - } - return i; - error: - return -1; -} - -/* Create AST for argument list. */ - -static arguments_ty -ast_for_arguments(struct compiling *c, const node *n) -{ - /* This function handles both typedargslist (function definition) - and varargslist (lambda definition). - - parameters: '(' [typedargslist] ')' - - The following definition for typedarglist is equivalent to this set of rules: - - arguments = argument (',' [TYPE_COMMENT] argument)* - argument = tfpdef ['=' test] - kwargs = '**' tfpdef [','] [TYPE_COMMENT] - args = '*' [tfpdef] - kwonly_kwargs = (',' [TYPE_COMMENT] argument)* (TYPE_COMMENT | [',' - [TYPE_COMMENT] [kwargs]]) - args_kwonly_kwargs = args kwonly_kwargs | kwargs - poskeyword_args_kwonly_kwargs = arguments ( TYPE_COMMENT | [',' - [TYPE_COMMENT] [args_kwonly_kwargs]]) - typedargslist_no_posonly = poskeyword_args_kwonly_kwargs | args_kwonly_kwargs - typedarglist = (arguments ',' [TYPE_COMMENT] '/' [',' [[TYPE_COMMENT] - typedargslist_no_posonly]])|(typedargslist_no_posonly)" - - typedargslist: ( (tfpdef ['=' test] (',' [TYPE_COMMENT] tfpdef ['=' test])* - ',' [TYPE_COMMENT] '/' [',' [ [TYPE_COMMENT] tfpdef ['=' test] ( ',' - [TYPE_COMMENT] tfpdef ['=' test])* (TYPE_COMMENT | [',' [TYPE_COMMENT] [ '*' - [tfpdef] (',' [TYPE_COMMENT] tfpdef ['=' test])* (TYPE_COMMENT | [',' - [TYPE_COMMENT] ['**' tfpdef [','] [TYPE_COMMENT]]]) | '**' tfpdef [','] - [TYPE_COMMENT]]]) | '*' [tfpdef] (',' [TYPE_COMMENT] tfpdef ['=' test])* - (TYPE_COMMENT | [',' [TYPE_COMMENT] ['**' tfpdef [','] [TYPE_COMMENT]]]) | - '**' tfpdef [','] [TYPE_COMMENT]]] ) | (tfpdef ['=' test] (',' - [TYPE_COMMENT] tfpdef ['=' test])* (TYPE_COMMENT | [',' [TYPE_COMMENT] [ '*' - [tfpdef] (',' [TYPE_COMMENT] tfpdef ['=' test])* (TYPE_COMMENT | [',' - [TYPE_COMMENT] ['**' tfpdef [','] [TYPE_COMMENT]]]) | '**' tfpdef [','] - [TYPE_COMMENT]]]) | '*' [tfpdef] (',' [TYPE_COMMENT] tfpdef ['=' test])* - (TYPE_COMMENT | [',' [TYPE_COMMENT] ['**' tfpdef [','] [TYPE_COMMENT]]]) | - '**' tfpdef [','] [TYPE_COMMENT])) - - tfpdef: NAME [':' test] - - The following definition for varargslist is equivalent to this set of rules: - - arguments = argument (',' argument )* - argument = vfpdef ['=' test] - kwargs = '**' vfpdef [','] - args = '*' [vfpdef] - kwonly_kwargs = (',' argument )* [',' [kwargs]] - args_kwonly_kwargs = args kwonly_kwargs | kwargs - poskeyword_args_kwonly_kwargs = arguments [',' [args_kwonly_kwargs]] - vararglist_no_posonly = poskeyword_args_kwonly_kwargs | args_kwonly_kwargs - varargslist = arguments ',' '/' [','[(vararglist_no_posonly)]] | - (vararglist_no_posonly) - - varargslist: vfpdef ['=' test ](',' vfpdef ['=' test])* ',' '/' [',' [ (vfpdef ['=' - test] (',' vfpdef ['=' test])* [',' [ '*' [vfpdef] (',' vfpdef ['=' test])* [',' - ['**' vfpdef [',']]] | '**' vfpdef [',']]] | '*' [vfpdef] (',' vfpdef ['=' test])* - [',' ['**' vfpdef [',']]] | '**' vfpdef [',']) ]] | (vfpdef ['=' test] (',' vfpdef - ['=' test])* [',' [ '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]] - | '**' vfpdef [',']]] | '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef - [',']]] | '**' vfpdef [',']) - - vfpdef: NAME - - */ - int i, j, k, l, nposonlyargs=0, nposargs = 0, nkwonlyargs = 0; - int nposdefaults = 0, found_default = 0; - asdl_seq *posonlyargs, *posargs, *posdefaults, *kwonlyargs, *kwdefaults; - arg_ty vararg = NULL, kwarg = NULL; - arg_ty arg = NULL; - node *ch; - - if (TYPE(n) == parameters) { - if (NCH(n) == 2) /* () as argument list */ - return arguments(NULL, NULL, NULL, NULL, NULL, NULL, NULL, c->c_arena); - n = CHILD(n, 1); - } - assert(TYPE(n) == typedargslist || TYPE(n) == varargslist); - - /* First count the number of positional args & defaults. The - variable i is the loop index for this for loop and the next. - The next loop picks up where the first leaves off. - */ - for (i = 0; i < NCH(n); i++) { - ch = CHILD(n, i); - if (TYPE(ch) == STAR) { - /* skip star */ - i++; - if (i < NCH(n) && /* skip argument following star */ - (TYPE(CHILD(n, i)) == tfpdef || - TYPE(CHILD(n, i)) == vfpdef)) { - i++; - } - break; - } - if (TYPE(ch) == DOUBLESTAR) break; - if (TYPE(ch) == vfpdef || TYPE(ch) == tfpdef) nposargs++; - if (TYPE(ch) == EQUAL) nposdefaults++; - if (TYPE(ch) == SLASH ) { - nposonlyargs = nposargs; - nposargs = 0; - } - } - /* count the number of keyword only args & - defaults for keyword only args */ - for ( ; i < NCH(n); ++i) { - ch = CHILD(n, i); - if (TYPE(ch) == DOUBLESTAR) break; - if (TYPE(ch) == tfpdef || TYPE(ch) == vfpdef) nkwonlyargs++; - } - posonlyargs = (nposonlyargs ? _Py_asdl_seq_new(nposonlyargs, c->c_arena) : NULL); - if (!posonlyargs && nposonlyargs) { - return NULL; - } - posargs = (nposargs ? _Py_asdl_seq_new(nposargs, c->c_arena) : NULL); - if (!posargs && nposargs) - return NULL; - kwonlyargs = (nkwonlyargs ? - _Py_asdl_seq_new(nkwonlyargs, c->c_arena) : NULL); - if (!kwonlyargs && nkwonlyargs) - return NULL; - posdefaults = (nposdefaults ? - _Py_asdl_seq_new(nposdefaults, c->c_arena) : NULL); - if (!posdefaults && nposdefaults) - return NULL; - /* The length of kwonlyargs and kwdefaults are same - since we set NULL as default for keyword only argument w/o default - - we have sequence data structure, but no dictionary */ - kwdefaults = (nkwonlyargs ? - _Py_asdl_seq_new(nkwonlyargs, c->c_arena) : NULL); - if (!kwdefaults && nkwonlyargs) - return NULL; - - /* tfpdef: NAME [':' test] - vfpdef: NAME - */ - i = 0; - j = 0; /* index for defaults */ - k = 0; /* index for args */ - l = 0; /* index for posonlyargs */ - while (i < NCH(n)) { - ch = CHILD(n, i); - switch (TYPE(ch)) { - case tfpdef: - case vfpdef: - /* XXX Need to worry about checking if TYPE(CHILD(n, i+1)) is - anything other than EQUAL or a comma? */ - /* XXX Should NCH(n) check be made a separate check? */ - if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) { - expr_ty expression = ast_for_expr(c, CHILD(n, i + 2)); - if (!expression) - return NULL; - assert(posdefaults != NULL); - asdl_seq_SET(posdefaults, j++, expression); - i += 2; - found_default = 1; - } - else if (found_default) { - ast_error(c, n, - "non-default argument follows default argument"); - return NULL; - } - arg = ast_for_arg(c, ch); - if (!arg) - return NULL; - if (l < nposonlyargs) { - asdl_seq_SET(posonlyargs, l++, arg); - } else { - asdl_seq_SET(posargs, k++, arg); - } - i += 1; /* the name */ - if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA) - i += 1; /* the comma, if present */ - break; - case SLASH: - /* Advance the slash and the comma. If there are more names - * after the slash there will be a comma so we are advancing - * the correct number of nodes. If the slash is the last item, - * we will be advancing an extra token but then * i > NCH(n) - * and the enclosing while will finish correctly. */ - i += 2; - break; - case STAR: - if (i+1 >= NCH(n) || - (i+2 == NCH(n) && (TYPE(CHILD(n, i+1)) == COMMA - || TYPE(CHILD(n, i+1)) == TYPE_COMMENT))) { - ast_error(c, CHILD(n, i), - "named arguments must follow bare *"); - return NULL; - } - ch = CHILD(n, i+1); /* tfpdef or COMMA */ - if (TYPE(ch) == COMMA) { - int res = 0; - i += 2; /* now follows keyword only arguments */ - - if (i < NCH(n) && TYPE(CHILD(n, i)) == TYPE_COMMENT) { - ast_error(c, CHILD(n, i), - "bare * has associated type comment"); - return NULL; - } - - res = handle_keywordonly_args(c, n, i, - kwonlyargs, kwdefaults); - if (res == -1) return NULL; - i = res; /* res has new position to process */ - } - else { - vararg = ast_for_arg(c, ch); - if (!vararg) - return NULL; - - i += 2; /* the star and the name */ - if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA) - i += 1; /* the comma, if present */ - - if (i < NCH(n) && TYPE(CHILD(n, i)) == TYPE_COMMENT) { - vararg->type_comment = NEW_TYPE_COMMENT(CHILD(n, i)); - if (!vararg->type_comment) - return NULL; - i += 1; - } - - if (i < NCH(n) && (TYPE(CHILD(n, i)) == tfpdef - || TYPE(CHILD(n, i)) == vfpdef)) { - int res = 0; - res = handle_keywordonly_args(c, n, i, - kwonlyargs, kwdefaults); - if (res == -1) return NULL; - i = res; /* res has new position to process */ - } - } - break; - case DOUBLESTAR: - ch = CHILD(n, i+1); /* tfpdef */ - assert(TYPE(ch) == tfpdef || TYPE(ch) == vfpdef); - kwarg = ast_for_arg(c, ch); - if (!kwarg) - return NULL; - i += 2; /* the double star and the name */ - if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA) - i += 1; /* the comma, if present */ - break; - case TYPE_COMMENT: - assert(i); - - if (kwarg) - arg = kwarg; - - /* arg will be equal to the last argument processed */ - arg->type_comment = NEW_TYPE_COMMENT(ch); - if (!arg->type_comment) - return NULL; - i += 1; - break; - default: - PyErr_Format(PyExc_SystemError, - "unexpected node in varargslist: %d @ %d", - TYPE(ch), i); - return NULL; - } - } - return arguments(posonlyargs, posargs, vararg, kwonlyargs, kwdefaults, kwarg, posdefaults, c->c_arena); -} - -static expr_ty -ast_for_decorator(struct compiling *c, const node *n) -{ - /* decorator: '@' namedexpr_test NEWLINE */ - - REQ(n, decorator); - REQ(CHILD(n, 0), AT); - REQ(CHILD(n, 2), NEWLINE); - - return ast_for_expr(c, CHILD(n, 1)); -} - -static asdl_seq* -ast_for_decorators(struct compiling *c, const node *n) -{ - asdl_seq* decorator_seq; - expr_ty d; - int i; - - REQ(n, decorators); - decorator_seq = _Py_asdl_seq_new(NCH(n), c->c_arena); - if (!decorator_seq) - return NULL; - - for (i = 0; i < NCH(n); i++) { - d = ast_for_decorator(c, CHILD(n, i)); - if (!d) - return NULL; - asdl_seq_SET(decorator_seq, i, d); - } - return decorator_seq; -} - -static stmt_ty -ast_for_funcdef_impl(struct compiling *c, const node *n0, - asdl_seq *decorator_seq, bool is_async) -{ - /* funcdef: 'def' NAME parameters ['->' test] ':' [TYPE_COMMENT] suite */ - const node * const n = is_async ? CHILD(n0, 1) : n0; - identifier name; - arguments_ty args; - asdl_seq *body; - expr_ty returns = NULL; - int name_i = 1; - int end_lineno, end_col_offset; - node *tc; - string type_comment = NULL; - - if (is_async && c->c_feature_version < 5) { - ast_error(c, n, - "Async functions are only supported in Python 3.5 and greater"); - return NULL; - } - - REQ(n, funcdef); - - name = NEW_IDENTIFIER(CHILD(n, name_i)); - if (!name) - return NULL; - if (forbidden_name(c, name, CHILD(n, name_i), 0)) - return NULL; - args = ast_for_arguments(c, CHILD(n, name_i + 1)); - if (!args) - return NULL; - if (TYPE(CHILD(n, name_i+2)) == RARROW) { - returns = ast_for_expr(c, CHILD(n, name_i + 3)); - if (!returns) - return NULL; - name_i += 2; - } - if (TYPE(CHILD(n, name_i + 3)) == TYPE_COMMENT) { - type_comment = NEW_TYPE_COMMENT(CHILD(n, name_i + 3)); - if (!type_comment) - return NULL; - name_i += 1; - } - body = ast_for_suite(c, CHILD(n, name_i + 3)); - if (!body) - return NULL; - get_last_end_pos(body, &end_lineno, &end_col_offset); - - if (NCH(CHILD(n, name_i + 3)) > 1) { - /* Check if the suite has a type comment in it. */ - tc = CHILD(CHILD(n, name_i + 3), 1); - - if (TYPE(tc) == TYPE_COMMENT) { - if (type_comment != NULL) { - ast_error(c, n, "Cannot have two type comments on def"); - return NULL; - } - type_comment = NEW_TYPE_COMMENT(tc); - if (!type_comment) - return NULL; - } - } - - if (is_async) - return AsyncFunctionDef(name, args, body, decorator_seq, returns, type_comment, - LINENO(n0), n0->n_col_offset, end_lineno, end_col_offset, c->c_arena); - else - return FunctionDef(name, args, body, decorator_seq, returns, type_comment, - LINENO(n), n->n_col_offset, end_lineno, end_col_offset, c->c_arena); -} - -static stmt_ty -ast_for_async_funcdef(struct compiling *c, const node *n, asdl_seq *decorator_seq) -{ - /* async_funcdef: ASYNC funcdef */ - REQ(n, async_funcdef); - REQ(CHILD(n, 0), ASYNC); - REQ(CHILD(n, 1), funcdef); - - return ast_for_funcdef_impl(c, n, decorator_seq, - true /* is_async */); -} - -static stmt_ty -ast_for_funcdef(struct compiling *c, const node *n, asdl_seq *decorator_seq) -{ - /* funcdef: 'def' NAME parameters ['->' test] ':' suite */ - return ast_for_funcdef_impl(c, n, decorator_seq, - false /* is_async */); -} - - -static stmt_ty -ast_for_async_stmt(struct compiling *c, const node *n) -{ - /* async_stmt: ASYNC (funcdef | with_stmt | for_stmt) */ - REQ(n, async_stmt); - REQ(CHILD(n, 0), ASYNC); - - switch (TYPE(CHILD(n, 1))) { - case funcdef: - return ast_for_funcdef_impl(c, n, NULL, - true /* is_async */); - case with_stmt: - return ast_for_with_stmt(c, n, - true /* is_async */); - - case for_stmt: - return ast_for_for_stmt(c, n, - true /* is_async */); - - default: - PyErr_Format(PyExc_SystemError, - "invalid async stament: %s", - STR(CHILD(n, 1))); - return NULL; - } -} - -static stmt_ty -ast_for_decorated(struct compiling *c, const node *n) -{ - /* decorated: decorators (classdef | funcdef | async_funcdef) */ - stmt_ty thing = NULL; - asdl_seq *decorator_seq = NULL; - - REQ(n, decorated); - - decorator_seq = ast_for_decorators(c, CHILD(n, 0)); - if (!decorator_seq) - return NULL; - - assert(TYPE(CHILD(n, 1)) == funcdef || - TYPE(CHILD(n, 1)) == async_funcdef || - TYPE(CHILD(n, 1)) == classdef); - - if (TYPE(CHILD(n, 1)) == funcdef) { - thing = ast_for_funcdef(c, CHILD(n, 1), decorator_seq); - } else if (TYPE(CHILD(n, 1)) == classdef) { - thing = ast_for_classdef(c, CHILD(n, 1), decorator_seq); - } else if (TYPE(CHILD(n, 1)) == async_funcdef) { - thing = ast_for_async_funcdef(c, CHILD(n, 1), decorator_seq); - } - return thing; -} - -static expr_ty -ast_for_namedexpr(struct compiling *c, const node *n) -{ - /* namedexpr_test: test [':=' test] - argument: ( test [comp_for] | - test ':=' test | - test '=' test | - '**' test | - '*' test ) - */ - expr_ty target, value; - - target = ast_for_expr(c, CHILD(n, 0)); - if (!target) - return NULL; - - value = ast_for_expr(c, CHILD(n, 2)); - if (!value) - return NULL; - - if (target->kind != Name_kind) { - const char *expr_name = get_expr_name(target); - if (expr_name != NULL) { - ast_error(c, n, "cannot use assignment expressions with %s", expr_name); - } - return NULL; - } - - if (!set_context(c, target, Store, n)) - return NULL; - - return NamedExpr(target, value, LINENO(n), n->n_col_offset, n->n_end_lineno, - n->n_end_col_offset, c->c_arena); -} - -static expr_ty -ast_for_lambdef(struct compiling *c, const node *n) -{ - /* lambdef: 'lambda' [varargslist] ':' test - lambdef_nocond: 'lambda' [varargslist] ':' test_nocond */ - arguments_ty args; - expr_ty expression; - - if (NCH(n) == 3) { - args = arguments(NULL, NULL, NULL, NULL, NULL, NULL, NULL, c->c_arena); - if (!args) - return NULL; - expression = ast_for_expr(c, CHILD(n, 2)); - if (!expression) - return NULL; - } - else { - args = ast_for_arguments(c, CHILD(n, 1)); - if (!args) - return NULL; - expression = ast_for_expr(c, CHILD(n, 3)); - if (!expression) - return NULL; - } - - return Lambda(args, expression, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); -} - -static expr_ty -ast_for_ifexpr(struct compiling *c, const node *n) -{ - /* test: or_test 'if' or_test 'else' test */ - expr_ty expression, body, orelse; - - assert(NCH(n) == 5); - body = ast_for_expr(c, CHILD(n, 0)); - if (!body) - return NULL; - expression = ast_for_expr(c, CHILD(n, 2)); - if (!expression) - return NULL; - orelse = ast_for_expr(c, CHILD(n, 4)); - if (!orelse) - return NULL; - return IfExp(expression, body, orelse, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, - c->c_arena); -} - -/* - Count the number of 'for' loops in a comprehension. - - Helper for ast_for_comprehension(). -*/ - -static int -count_comp_fors(struct compiling *c, const node *n) -{ - int n_fors = 0; - - count_comp_for: - n_fors++; - REQ(n, comp_for); - if (NCH(n) == 2) { - REQ(CHILD(n, 0), ASYNC); - n = CHILD(n, 1); - } - else if (NCH(n) == 1) { - n = CHILD(n, 0); - } - else { - goto error; - } - if (NCH(n) == (5)) { - n = CHILD(n, 4); - } - else { - return n_fors; - } - count_comp_iter: - REQ(n, comp_iter); - n = CHILD(n, 0); - if (TYPE(n) == comp_for) - goto count_comp_for; - else if (TYPE(n) == comp_if) { - if (NCH(n) == 3) { - n = CHILD(n, 2); - goto count_comp_iter; - } - else - return n_fors; - } - - error: - /* Should never be reached */ - PyErr_SetString(PyExc_SystemError, - "logic error in count_comp_fors"); - return -1; -} - -/* Count the number of 'if' statements in a comprehension. - - Helper for ast_for_comprehension(). -*/ - -static int -count_comp_ifs(struct compiling *c, const node *n) -{ - int n_ifs = 0; - - while (1) { - REQ(n, comp_iter); - if (TYPE(CHILD(n, 0)) == comp_for) - return n_ifs; - n = CHILD(n, 0); - REQ(n, comp_if); - n_ifs++; - if (NCH(n) == 2) - return n_ifs; - n = CHILD(n, 2); - } -} - -static asdl_seq * -ast_for_comprehension(struct compiling *c, const node *n) -{ - int i, n_fors; - asdl_seq *comps; - - n_fors = count_comp_fors(c, n); - if (n_fors == -1) - return NULL; - - comps = _Py_asdl_seq_new(n_fors, c->c_arena); - if (!comps) - return NULL; - - for (i = 0; i < n_fors; i++) { - comprehension_ty comp; - asdl_seq *t; - expr_ty expression, first; - node *for_ch; - node *sync_n; - int is_async = 0; - - REQ(n, comp_for); - - if (NCH(n) == 2) { - is_async = 1; - REQ(CHILD(n, 0), ASYNC); - sync_n = CHILD(n, 1); - } - else { - sync_n = CHILD(n, 0); - } - REQ(sync_n, sync_comp_for); - - /* Async comprehensions only allowed in Python 3.6 and greater */ - if (is_async && c->c_feature_version < 6) { - ast_error(c, n, - "Async comprehensions are only supported in Python 3.6 and greater"); - return NULL; - } - - for_ch = CHILD(sync_n, 1); - t = ast_for_exprlist(c, for_ch, Store); - if (!t) - return NULL; - expression = ast_for_expr(c, CHILD(sync_n, 3)); - if (!expression) - return NULL; - - /* Check the # of children rather than the length of t, since - (x for x, in ...) has 1 element in t, but still requires a Tuple. */ - first = (expr_ty)asdl_seq_GET(t, 0); - if (NCH(for_ch) == 1) - comp = comprehension(first, expression, NULL, - is_async, c->c_arena); - else - comp = comprehension(Tuple(t, Store, first->lineno, first->col_offset, - for_ch->n_end_lineno, for_ch->n_end_col_offset, - c->c_arena), - expression, NULL, is_async, c->c_arena); - if (!comp) - return NULL; - - if (NCH(sync_n) == 5) { - int j, n_ifs; - asdl_seq *ifs; - - n = CHILD(sync_n, 4); - n_ifs = count_comp_ifs(c, n); - if (n_ifs == -1) - return NULL; - - ifs = _Py_asdl_seq_new(n_ifs, c->c_arena); - if (!ifs) - return NULL; - - for (j = 0; j < n_ifs; j++) { - REQ(n, comp_iter); - n = CHILD(n, 0); - REQ(n, comp_if); - - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - asdl_seq_SET(ifs, j, expression); - if (NCH(n) == 3) - n = CHILD(n, 2); - } - /* on exit, must guarantee that n is a comp_for */ - if (TYPE(n) == comp_iter) - n = CHILD(n, 0); - comp->ifs = ifs; - } - asdl_seq_SET(comps, i, comp); - } - return comps; -} - -static expr_ty -ast_for_itercomp(struct compiling *c, const node *n, int type) -{ - /* testlist_comp: (test|star_expr) - * ( comp_for | (',' (test|star_expr))* [','] ) */ - expr_ty elt; - asdl_seq *comps; - node *ch; - - assert(NCH(n) > 1); - - ch = CHILD(n, 0); - elt = ast_for_expr(c, ch); - if (!elt) - return NULL; - if (elt->kind == Starred_kind) { - ast_error(c, ch, "iterable unpacking cannot be used in comprehension"); - return NULL; - } - - comps = ast_for_comprehension(c, CHILD(n, 1)); - if (!comps) - return NULL; - - if (type == COMP_GENEXP) - return GeneratorExp(elt, comps, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - else if (type == COMP_LISTCOMP) - return ListComp(elt, comps, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - else if (type == COMP_SETCOMP) - return SetComp(elt, comps, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - else - /* Should never happen */ - return NULL; -} - -/* Fills in the key, value pair corresponding to the dict element. In case - * of an unpacking, key is NULL. *i is advanced by the number of ast - * elements. Iff successful, nonzero is returned. - */ -static int -ast_for_dictelement(struct compiling *c, const node *n, int *i, - expr_ty *key, expr_ty *value) -{ - expr_ty expression; - if (TYPE(CHILD(n, *i)) == DOUBLESTAR) { - assert(NCH(n) - *i >= 2); - - expression = ast_for_expr(c, CHILD(n, *i + 1)); - if (!expression) - return 0; - *key = NULL; - *value = expression; - - *i += 2; - } - else { - assert(NCH(n) - *i >= 3); - - expression = ast_for_expr(c, CHILD(n, *i)); - if (!expression) - return 0; - *key = expression; - - REQ(CHILD(n, *i + 1), COLON); - - expression = ast_for_expr(c, CHILD(n, *i + 2)); - if (!expression) - return 0; - *value = expression; - - *i += 3; - } - return 1; -} - -static expr_ty -ast_for_dictcomp(struct compiling *c, const node *n) -{ - expr_ty key, value; - asdl_seq *comps; - int i = 0; - - if (!ast_for_dictelement(c, n, &i, &key, &value)) - return NULL; - assert(key); - assert(NCH(n) - i >= 1); - - comps = ast_for_comprehension(c, CHILD(n, i)); - if (!comps) - return NULL; - - return DictComp(key, value, comps, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); -} - -static expr_ty -ast_for_dictdisplay(struct compiling *c, const node *n) -{ - int i; - int j; - int size; - asdl_seq *keys, *values; - - size = (NCH(n) + 1) / 3; /* +1 in case no trailing comma */ - keys = _Py_asdl_seq_new(size, c->c_arena); - if (!keys) - return NULL; - - values = _Py_asdl_seq_new(size, c->c_arena); - if (!values) - return NULL; - - j = 0; - for (i = 0; i < NCH(n); i++) { - expr_ty key, value; - - if (!ast_for_dictelement(c, n, &i, &key, &value)) - return NULL; - asdl_seq_SET(keys, j, key); - asdl_seq_SET(values, j, value); - - j++; - } - keys->size = j; - values->size = j; - return Dict(keys, values, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); -} - -static expr_ty -ast_for_genexp(struct compiling *c, const node *n) -{ - assert(TYPE(n) == (testlist_comp) || TYPE(n) == (argument)); - return ast_for_itercomp(c, n, COMP_GENEXP); -} - -static expr_ty -ast_for_listcomp(struct compiling *c, const node *n) -{ - assert(TYPE(n) == (testlist_comp)); - return ast_for_itercomp(c, n, COMP_LISTCOMP); -} - -static expr_ty -ast_for_setcomp(struct compiling *c, const node *n) -{ - assert(TYPE(n) == (dictorsetmaker)); - return ast_for_itercomp(c, n, COMP_SETCOMP); -} - -static expr_ty -ast_for_setdisplay(struct compiling *c, const node *n) -{ - int i; - int size; - asdl_seq *elts; - - assert(TYPE(n) == (dictorsetmaker)); - size = (NCH(n) + 1) / 2; /* +1 in case no trailing comma */ - elts = _Py_asdl_seq_new(size, c->c_arena); - if (!elts) - return NULL; - for (i = 0; i < NCH(n); i += 2) { - expr_ty expression; - expression = ast_for_expr(c, CHILD(n, i)); - if (!expression) - return NULL; - asdl_seq_SET(elts, i / 2, expression); - } - return Set(elts, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); -} - -static expr_ty -ast_for_atom(struct compiling *c, const node *n) -{ - /* atom: '(' [yield_expr|testlist_comp] ')' | '[' [testlist_comp] ']' - | '{' [dictmaker|testlist_comp] '}' | NAME | NUMBER | STRING+ - | '...' | 'None' | 'True' | 'False' - */ - node *ch = CHILD(n, 0); - - switch (TYPE(ch)) { - case NAME: { - PyObject *name; - const char *s = STR(ch); - size_t len = strlen(s); - if (len >= 4 && len <= 5) { - if (!strcmp(s, "None")) - return Constant(Py_None, NULL, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - if (!strcmp(s, "True")) - return Constant(Py_True, NULL, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - if (!strcmp(s, "False")) - return Constant(Py_False, NULL, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - name = new_identifier(s, c); - if (!name) - return NULL; - /* All names start in Load context, but may later be changed. */ - return Name(name, Load, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - case STRING: { - expr_ty str = parsestrplus(c, n); - if (!str) { - const char *errtype = NULL; - if (PyErr_ExceptionMatches(PyExc_UnicodeError)) - errtype = "unicode error"; - else if (PyErr_ExceptionMatches(PyExc_ValueError)) - errtype = "value error"; - if (errtype) { - PyObject *type, *value, *tback, *errstr; - PyErr_Fetch(&type, &value, &tback); - errstr = PyObject_Str(value); - if (errstr) { - ast_error(c, n, "(%s) %U", errtype, errstr); - Py_DECREF(errstr); - } - else { - PyErr_Clear(); - ast_error(c, n, "(%s) unknown error", errtype); - } - Py_DECREF(type); - Py_XDECREF(value); - Py_XDECREF(tback); - } - return NULL; - } - return str; - } - case NUMBER: { - PyObject *pynum; - /* Underscores in numeric literals are only allowed in Python 3.6 or greater */ - /* Check for underscores here rather than in parse_number so we can report a line number on error */ - if (c->c_feature_version < 6 && strchr(STR(ch), '_') != NULL) { - ast_error(c, ch, - "Underscores in numeric literals are only supported in Python 3.6 and greater"); - return NULL; - } - pynum = parsenumber(c, STR(ch)); - if (!pynum) - return NULL; - - if (PyArena_AddPyObject(c->c_arena, pynum) < 0) { - Py_DECREF(pynum); - return NULL; - } - return Constant(pynum, NULL, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - case ELLIPSIS: /* Ellipsis */ - return Constant(Py_Ellipsis, NULL, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - case LPAR: /* some parenthesized expressions */ - ch = CHILD(n, 1); - - if (TYPE(ch) == RPAR) - return Tuple(NULL, Load, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - - if (TYPE(ch) == yield_expr) - return ast_for_expr(c, ch); - - /* testlist_comp: test ( comp_for | (',' test)* [','] ) */ - if (NCH(ch) == 1) { - return ast_for_testlist(c, ch); - } - - if (TYPE(CHILD(ch, 1)) == comp_for) { - return copy_location(ast_for_genexp(c, ch), n, n); - } - else { - return copy_location(ast_for_testlist(c, ch), n, n); - } - case LSQB: /* list (or list comprehension) */ - ch = CHILD(n, 1); - - if (TYPE(ch) == RSQB) - return List(NULL, Load, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - - REQ(ch, testlist_comp); - if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) { - asdl_seq *elts = seq_for_testlist(c, ch); - if (!elts) - return NULL; - - return List(elts, Load, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - else { - return copy_location(ast_for_listcomp(c, ch), n, n); - } - case LBRACE: { - /* dictorsetmaker: ( ((test ':' test | '**' test) - * (comp_for | (',' (test ':' test | '**' test))* [','])) | - * ((test | '*' test) - * (comp_for | (',' (test | '*' test))* [','])) ) */ - expr_ty res; - ch = CHILD(n, 1); - if (TYPE(ch) == RBRACE) { - /* It's an empty dict. */ - return Dict(NULL, NULL, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - else { - int is_dict = (TYPE(CHILD(ch, 0)) == DOUBLESTAR); - if (NCH(ch) == 1 || - (NCH(ch) > 1 && - TYPE(CHILD(ch, 1)) == COMMA)) { - /* It's a set display. */ - res = ast_for_setdisplay(c, ch); - } - else if (NCH(ch) > 1 && - TYPE(CHILD(ch, 1)) == comp_for) { - /* It's a set comprehension. */ - res = ast_for_setcomp(c, ch); - } - else if (NCH(ch) > 3 - is_dict && - TYPE(CHILD(ch, 3 - is_dict)) == comp_for) { - /* It's a dictionary comprehension. */ - if (is_dict) { - ast_error(c, n, - "dict unpacking cannot be used in dict comprehension"); - return NULL; - } - res = ast_for_dictcomp(c, ch); - } - else { - /* It's a dictionary display. */ - res = ast_for_dictdisplay(c, ch); - } - return copy_location(res, n, n); - } - } - default: - PyErr_Format(PyExc_SystemError, "unhandled atom %d", TYPE(ch)); - return NULL; - } -} - -static expr_ty -ast_for_slice(struct compiling *c, const node *n) -{ - node *ch; - expr_ty lower = NULL, upper = NULL, step = NULL; - - REQ(n, subscript); - - /* - subscript: test | [test] ':' [test] [sliceop] - sliceop: ':' [test] - */ - ch = CHILD(n, 0); - if (NCH(n) == 1 && TYPE(ch) == test) { - return ast_for_expr(c, ch); - } - - if (TYPE(ch) == test) { - lower = ast_for_expr(c, ch); - if (!lower) - return NULL; - } - - /* If there's an upper bound it's in the second or third position. */ - if (TYPE(ch) == COLON) { - if (NCH(n) > 1) { - node *n2 = CHILD(n, 1); - - if (TYPE(n2) == test) { - upper = ast_for_expr(c, n2); - if (!upper) - return NULL; - } - } - } else if (NCH(n) > 2) { - node *n2 = CHILD(n, 2); - - if (TYPE(n2) == test) { - upper = ast_for_expr(c, n2); - if (!upper) - return NULL; - } - } - - ch = CHILD(n, NCH(n) - 1); - if (TYPE(ch) == sliceop) { - if (NCH(ch) != 1) { - ch = CHILD(ch, 1); - if (TYPE(ch) == test) { - step = ast_for_expr(c, ch); - if (!step) - return NULL; - } - } - } - - return Slice(lower, upper, step, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); -} - -static expr_ty -ast_for_binop(struct compiling *c, const node *n) -{ - /* Must account for a sequence of expressions. - How should A op B op C by represented? - BinOp(BinOp(A, op, B), op, C). - */ - - int i, nops; - expr_ty expr1, expr2, result; - operator_ty newoperator; - - expr1 = ast_for_expr(c, CHILD(n, 0)); - if (!expr1) - return NULL; - - expr2 = ast_for_expr(c, CHILD(n, 2)); - if (!expr2) - return NULL; - - newoperator = get_operator(c, CHILD(n, 1)); - if (!newoperator) - return NULL; - - result = BinOp(expr1, newoperator, expr2, LINENO(n), n->n_col_offset, - CHILD(n, 2)->n_end_lineno, CHILD(n, 2)->n_end_col_offset, - c->c_arena); - if (!result) - return NULL; - - nops = (NCH(n) - 1) / 2; - for (i = 1; i < nops; i++) { - expr_ty tmp_result, tmp; - const node* next_oper = CHILD(n, i * 2 + 1); - - newoperator = get_operator(c, next_oper); - if (!newoperator) - return NULL; - - tmp = ast_for_expr(c, CHILD(n, i * 2 + 2)); - if (!tmp) - return NULL; - - tmp_result = BinOp(result, newoperator, tmp, - LINENO(n), n->n_col_offset, - CHILD(n, i * 2 + 2)->n_end_lineno, - CHILD(n, i * 2 + 2)->n_end_col_offset, - c->c_arena); - if (!tmp_result) - return NULL; - result = tmp_result; - } - return result; -} - -static expr_ty -ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr, const node *start) -{ - /* trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME - subscriptlist: subscript (',' subscript)* [','] - subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop] - */ - const node *n_copy = n; - REQ(n, trailer); - if (TYPE(CHILD(n, 0)) == LPAR) { - if (NCH(n) == 2) - return Call(left_expr, NULL, NULL, LINENO(start), start->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - else - return ast_for_call(c, CHILD(n, 1), left_expr, - start, CHILD(n, 0), CHILD(n, 2)); - } - else if (TYPE(CHILD(n, 0)) == DOT) { - PyObject *attr_id = NEW_IDENTIFIER(CHILD(n, 1)); - if (!attr_id) - return NULL; - return Attribute(left_expr, attr_id, Load, - LINENO(start), start->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - else { - REQ(CHILD(n, 0), LSQB); - REQ(CHILD(n, 2), RSQB); - n = CHILD(n, 1); - if (NCH(n) == 1) { - expr_ty slc = ast_for_slice(c, CHILD(n, 0)); - if (!slc) - return NULL; - return Subscript(left_expr, slc, Load, LINENO(start), start->n_col_offset, - n_copy->n_end_lineno, n_copy->n_end_col_offset, - c->c_arena); - } - else { - int j; - expr_ty slc, e; - asdl_seq *elts; - elts = _Py_asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); - if (!elts) - return NULL; - for (j = 0; j < NCH(n); j += 2) { - slc = ast_for_slice(c, CHILD(n, j)); - if (!slc) - return NULL; - asdl_seq_SET(elts, j / 2, slc); - } - e = Tuple(elts, Load, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, - c->c_arena); - if (!e) - return NULL; - return Subscript(left_expr, e, - Load, LINENO(start), start->n_col_offset, - n_copy->n_end_lineno, n_copy->n_end_col_offset, - c->c_arena); - } - } -} - -static expr_ty -ast_for_factor(struct compiling *c, const node *n) -{ - expr_ty expression; - - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - - switch (TYPE(CHILD(n, 0))) { - case PLUS: - return UnaryOp(UAdd, expression, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, - c->c_arena); - case MINUS: - return UnaryOp(USub, expression, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, - c->c_arena); - case TILDE: - return UnaryOp(Invert, expression, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, - c->c_arena); - } - PyErr_Format(PyExc_SystemError, "unhandled factor: %d", - TYPE(CHILD(n, 0))); - return NULL; -} - -static expr_ty -ast_for_atom_expr(struct compiling *c, const node *n) -{ - int i, nch, start = 0; - expr_ty e; - - REQ(n, atom_expr); - nch = NCH(n); - - if (TYPE(CHILD(n, 0)) == AWAIT) { - if (c->c_feature_version < 5) { - ast_error(c, n, - "Await expressions are only supported in Python 3.5 and greater"); - return NULL; - } - start = 1; - assert(nch > 1); - } - - e = ast_for_atom(c, CHILD(n, start)); - if (!e) - return NULL; - if (nch == 1) - return e; - if (start && nch == 2) { - return Await(e, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - - for (i = start + 1; i < nch; i++) { - node *ch = CHILD(n, i); - if (TYPE(ch) != trailer) - break; - e = ast_for_trailer(c, ch, e, CHILD(n, start)); - if (!e) - return NULL; - } - - if (start) { - /* there was an 'await' */ - return Await(e, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - else { - return e; - } -} - -static expr_ty -ast_for_power(struct compiling *c, const node *n) -{ - /* power: atom trailer* ('**' factor)* - */ - expr_ty e; - REQ(n, power); - e = ast_for_atom_expr(c, CHILD(n, 0)); - if (!e) - return NULL; - if (NCH(n) == 1) - return e; - if (TYPE(CHILD(n, NCH(n) - 1)) == factor) { - expr_ty f = ast_for_expr(c, CHILD(n, NCH(n) - 1)); - if (!f) - return NULL; - e = BinOp(e, Pow, f, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - return e; -} - -static expr_ty -ast_for_starred(struct compiling *c, const node *n) -{ - expr_ty tmp; - REQ(n, star_expr); - - tmp = ast_for_expr(c, CHILD(n, 1)); - if (!tmp) - return NULL; - - /* The Load context is changed later. */ - return Starred(tmp, Load, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); -} - - -/* Do not name a variable 'expr'! Will cause a compile error. -*/ - -static expr_ty -ast_for_expr(struct compiling *c, const node *n) -{ - /* handle the full range of simple expressions - namedexpr_test: test [':=' test] - test: or_test ['if' or_test 'else' test] | lambdef - test_nocond: or_test | lambdef_nocond - or_test: and_test ('or' and_test)* - and_test: not_test ('and' not_test)* - not_test: 'not' not_test | comparison - comparison: expr (comp_op expr)* - expr: xor_expr ('|' xor_expr)* - xor_expr: and_expr ('^' and_expr)* - and_expr: shift_expr ('&' shift_expr)* - shift_expr: arith_expr (('<<'|'>>') arith_expr)* - arith_expr: term (('+'|'-') term)* - term: factor (('*'|'@'|'/'|'%'|'//') factor)* - factor: ('+'|'-'|'~') factor | power - power: atom_expr ['**' factor] - atom_expr: [AWAIT] atom trailer* - yield_expr: 'yield' [yield_arg] - */ - - asdl_seq *seq; - int i; - - loop: - switch (TYPE(n)) { - case namedexpr_test: - if (NCH(n) == 3) - return ast_for_namedexpr(c, n); - /* Fallthrough */ - case test: - case test_nocond: - if (TYPE(CHILD(n, 0)) == lambdef || - TYPE(CHILD(n, 0)) == lambdef_nocond) - return ast_for_lambdef(c, CHILD(n, 0)); - else if (NCH(n) > 1) - return ast_for_ifexpr(c, n); - /* Fallthrough */ - case or_test: - case and_test: - if (NCH(n) == 1) { - n = CHILD(n, 0); - goto loop; - } - seq = _Py_asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); - if (!seq) - return NULL; - for (i = 0; i < NCH(n); i += 2) { - expr_ty e = ast_for_expr(c, CHILD(n, i)); - if (!e) - return NULL; - asdl_seq_SET(seq, i / 2, e); - } - if (!strcmp(STR(CHILD(n, 1)), "and")) - return BoolOp(And, seq, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, - c->c_arena); - assert(!strcmp(STR(CHILD(n, 1)), "or")); - return BoolOp(Or, seq, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - case not_test: - if (NCH(n) == 1) { - n = CHILD(n, 0); - goto loop; - } - else { - expr_ty expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - - return UnaryOp(Not, expression, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, - c->c_arena); - } - case comparison: - if (NCH(n) == 1) { - n = CHILD(n, 0); - goto loop; - } - else { - expr_ty expression; - asdl_int_seq *ops; - asdl_seq *cmps; - ops = _Py_asdl_int_seq_new(NCH(n) / 2, c->c_arena); - if (!ops) - return NULL; - cmps = _Py_asdl_seq_new(NCH(n) / 2, c->c_arena); - if (!cmps) { - return NULL; - } - for (i = 1; i < NCH(n); i += 2) { - cmpop_ty newoperator; - - newoperator = ast_for_comp_op(c, CHILD(n, i)); - if (!newoperator) { - return NULL; - } - - expression = ast_for_expr(c, CHILD(n, i + 1)); - if (!expression) { - return NULL; - } - - asdl_seq_SET(ops, i / 2, newoperator); - asdl_seq_SET(cmps, i / 2, expression); - } - expression = ast_for_expr(c, CHILD(n, 0)); - if (!expression) { - return NULL; - } - - return Compare(expression, ops, cmps, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - - case star_expr: - return ast_for_starred(c, n); - /* The next five cases all handle BinOps. The main body of code - is the same in each case, but the switch turned inside out to - reuse the code for each type of operator. - */ - case expr: - case xor_expr: - case and_expr: - case shift_expr: - case arith_expr: - case term: - if (NCH(n) == 1) { - n = CHILD(n, 0); - goto loop; - } - return ast_for_binop(c, n); - case yield_expr: { - node *an = NULL; - node *en = NULL; - int is_from = 0; - expr_ty exp = NULL; - if (NCH(n) > 1) - an = CHILD(n, 1); /* yield_arg */ - if (an) { - en = CHILD(an, NCH(an) - 1); - if (NCH(an) == 2) { - is_from = 1; - exp = ast_for_expr(c, en); - } - else - exp = ast_for_testlist(c, en); - if (!exp) - return NULL; - } - if (is_from) - return YieldFrom(exp, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - return Yield(exp, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - case factor: - if (NCH(n) == 1) { - n = CHILD(n, 0); - goto loop; - } - return ast_for_factor(c, n); - case power: - return ast_for_power(c, n); - default: - PyErr_Format(PyExc_SystemError, "unhandled expr: %d", TYPE(n)); - return NULL; - } - /* should never get here unless if error is set */ - return NULL; -} - -static expr_ty -ast_for_call(struct compiling *c, const node *n, expr_ty func, - const node *start, const node *maybegenbeg, const node *closepar) -{ - /* - arglist: argument (',' argument)* [','] - argument: ( test [comp_for] | '*' test | test '=' test | '**' test ) - */ - - int i, nargs, nkeywords; - int ndoublestars; - asdl_seq *args; - asdl_seq *keywords; - - REQ(n, arglist); - - nargs = 0; - nkeywords = 0; - for (i = 0; i < NCH(n); i++) { - node *ch = CHILD(n, i); - if (TYPE(ch) == argument) { - if (NCH(ch) == 1) - nargs++; - else if (TYPE(CHILD(ch, 1)) == comp_for) { - nargs++; - if (!maybegenbeg) { - ast_error(c, ch, "invalid syntax"); - return NULL; - } - if (NCH(n) > 1) { - ast_error(c, ch, "Generator expression must be parenthesized"); - return NULL; - } - } - else if (TYPE(CHILD(ch, 0)) == STAR) - nargs++; - else if (TYPE(CHILD(ch, 1)) == COLONEQUAL) { - nargs++; - } - else - /* TYPE(CHILD(ch, 0)) == DOUBLESTAR or keyword argument */ - nkeywords++; - } - } - - args = _Py_asdl_seq_new(nargs, c->c_arena); - if (!args) - return NULL; - keywords = _Py_asdl_seq_new(nkeywords, c->c_arena); - if (!keywords) - return NULL; - - nargs = 0; /* positional arguments + iterable argument unpackings */ - nkeywords = 0; /* keyword arguments + keyword argument unpackings */ - ndoublestars = 0; /* just keyword argument unpackings */ - for (i = 0; i < NCH(n); i++) { - node *ch = CHILD(n, i); - if (TYPE(ch) == argument) { - expr_ty e; - node *chch = CHILD(ch, 0); - if (NCH(ch) == 1) { - /* a positional argument */ - if (nkeywords) { - if (ndoublestars) { - ast_error(c, chch, - "positional argument follows " - "keyword argument unpacking"); - } - else { - ast_error(c, chch, - "positional argument follows " - "keyword argument"); - } - return NULL; - } - e = ast_for_expr(c, chch); - if (!e) - return NULL; - asdl_seq_SET(args, nargs++, e); - } - else if (TYPE(chch) == STAR) { - /* an iterable argument unpacking */ - expr_ty starred; - if (ndoublestars) { - ast_error(c, chch, - "iterable argument unpacking follows " - "keyword argument unpacking"); - return NULL; - } - e = ast_for_expr(c, CHILD(ch, 1)); - if (!e) - return NULL; - starred = Starred(e, Load, LINENO(chch), - chch->n_col_offset, - e->end_lineno, e->end_col_offset, - c->c_arena); - if (!starred) - return NULL; - asdl_seq_SET(args, nargs++, starred); - - } - else if (TYPE(chch) == DOUBLESTAR) { - /* a keyword argument unpacking */ - keyword_ty kw; - i++; - e = ast_for_expr(c, CHILD(ch, 1)); - if (!e) - return NULL; - kw = keyword(NULL, e, chch->n_lineno, chch->n_col_offset, - e->end_lineno, e->end_col_offset, c->c_arena); - asdl_seq_SET(keywords, nkeywords++, kw); - ndoublestars++; - } - else if (TYPE(CHILD(ch, 1)) == comp_for) { - /* the lone generator expression */ - e = copy_location(ast_for_genexp(c, ch), maybegenbeg, closepar); - if (!e) - return NULL; - asdl_seq_SET(args, nargs++, e); - } - else if (TYPE(CHILD(ch, 1)) == COLONEQUAL) { - /* treat colon equal as positional argument */ - if (nkeywords) { - if (ndoublestars) { - ast_error(c, chch, - "positional argument follows " - "keyword argument unpacking"); - } - else { - ast_error(c, chch, - "positional argument follows " - "keyword argument"); - } - return NULL; - } - e = ast_for_namedexpr(c, ch); - if (!e) - return NULL; - asdl_seq_SET(args, nargs++, e); - } - else { - /* a keyword argument */ - keyword_ty kw; - identifier key; - - // To remain LL(1), the grammar accepts any test (basically, any - // expression) in the keyword slot of a call site. So, we need - // to manually enforce that the keyword is a NAME here. - static const int name_tree[] = { - test, - or_test, - and_test, - not_test, - comparison, - expr, - xor_expr, - and_expr, - shift_expr, - arith_expr, - term, - factor, - power, - atom_expr, - atom, - 0, - }; - node *expr_node = chch; - for (int i = 0; name_tree[i]; i++) { - if (TYPE(expr_node) != name_tree[i]) - break; - if (NCH(expr_node) != 1) - break; - expr_node = CHILD(expr_node, 0); - } - if (TYPE(expr_node) != NAME) { - ast_error(c, chch, - "expression cannot contain assignment, " - "perhaps you meant \"==\"?"); - return NULL; - } - key = new_identifier(STR(expr_node), c); - if (key == NULL) { - return NULL; - } - if (forbidden_name(c, key, chch, 1)) { - return NULL; - } - e = ast_for_expr(c, CHILD(ch, 2)); - if (!e) - return NULL; - kw = keyword(key, e, chch->n_lineno, chch->n_col_offset, - e->end_lineno, e->end_col_offset, c->c_arena); - - if (!kw) - return NULL; - asdl_seq_SET(keywords, nkeywords++, kw); - } - } - } - - return Call(func, args, keywords, LINENO(start), start->n_col_offset, - closepar->n_end_lineno, closepar->n_end_col_offset, c->c_arena); -} - -static expr_ty -ast_for_testlist(struct compiling *c, const node* n) -{ - /* testlist_comp: test (comp_for | (',' test)* [',']) */ - /* testlist: test (',' test)* [','] */ - assert(NCH(n) > 0); - if (TYPE(n) == testlist_comp) { - if (NCH(n) > 1) - assert(TYPE(CHILD(n, 1)) != comp_for); - } - else { - assert(TYPE(n) == testlist || - TYPE(n) == testlist_star_expr); - } - if (NCH(n) == 1) - return ast_for_expr(c, CHILD(n, 0)); - else { - asdl_seq *tmp = seq_for_testlist(c, n); - if (!tmp) - return NULL; - return Tuple(tmp, Load, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } -} - -static stmt_ty -ast_for_expr_stmt(struct compiling *c, const node *n) -{ - REQ(n, expr_stmt); - /* expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) | - [('=' (yield_expr|testlist_star_expr))+ [TYPE_COMMENT]] ) - annassign: ':' test ['=' (yield_expr|testlist)] - testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [','] - augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' | - '<<=' | '>>=' | '**=' | '//=') - test: ... here starts the operator precedence dance - */ - int num = NCH(n); - - if (num == 1) { - expr_ty e = ast_for_testlist(c, CHILD(n, 0)); - if (!e) - return NULL; - - return Expr(e, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - else if (TYPE(CHILD(n, 1)) == augassign) { - expr_ty expr1, expr2; - operator_ty newoperator; - node *ch = CHILD(n, 0); - - expr1 = ast_for_testlist(c, ch); - if (!expr1) - return NULL; - /* Augmented assignments can only have a name, a subscript, or an - attribute on the left, though, so we have to explicitly check for - those. */ - switch (expr1->kind) { - case Name_kind: - case Attribute_kind: - case Subscript_kind: - break; - default: - ast_error(c, ch, "'%s' is an illegal expression for augmented assignment", - get_expr_name(expr1)); - return NULL; - } - - /* set_context checks that most expressions are not the left side. */ - if(!set_context(c, expr1, Store, ch)) { - return NULL; - } - - ch = CHILD(n, 2); - if (TYPE(ch) == testlist) - expr2 = ast_for_testlist(c, ch); - else - expr2 = ast_for_expr(c, ch); - if (!expr2) - return NULL; - - newoperator = ast_for_augassign(c, CHILD(n, 1)); - if (!newoperator) - return NULL; - - return AugAssign(expr1, newoperator, expr2, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - else if (TYPE(CHILD(n, 1)) == annassign) { - expr_ty expr1, expr2, expr3; - node *ch = CHILD(n, 0); - node *deep, *ann = CHILD(n, 1); - int simple = 1; - - /* AnnAssigns are only allowed in Python 3.6 or greater */ - if (c->c_feature_version < 6) { - ast_error(c, ch, - "Variable annotation syntax is only supported in Python 3.6 and greater"); - return NULL; - } - - /* we keep track of parens to qualify (x) as expression not name */ - deep = ch; - while (NCH(deep) == 1) { - deep = CHILD(deep, 0); - } - if (NCH(deep) > 0 && TYPE(CHILD(deep, 0)) == LPAR) { - simple = 0; - } - expr1 = ast_for_testlist(c, ch); - if (!expr1) { - return NULL; - } - switch (expr1->kind) { - case Name_kind: - if (forbidden_name(c, expr1->v.Name.id, n, 0)) { - return NULL; - } - expr1->v.Name.ctx = Store; - break; - case Attribute_kind: - if (forbidden_name(c, expr1->v.Attribute.attr, n, 1)) { - return NULL; - } - expr1->v.Attribute.ctx = Store; - break; - case Subscript_kind: - expr1->v.Subscript.ctx = Store; - break; - case List_kind: - ast_error(c, ch, - "only single target (not list) can be annotated"); - return NULL; - case Tuple_kind: - ast_error(c, ch, - "only single target (not tuple) can be annotated"); - return NULL; - default: - ast_error(c, ch, - "illegal target for annotation"); - return NULL; - } - - if (expr1->kind != Name_kind) { - simple = 0; - } - ch = CHILD(ann, 1); - expr2 = ast_for_expr(c, ch); - if (!expr2) { - return NULL; - } - if (NCH(ann) == 2) { - return AnnAssign(expr1, expr2, NULL, simple, - LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - else { - ch = CHILD(ann, 3); - if (TYPE(ch) == testlist_star_expr) { - expr3 = ast_for_testlist(c, ch); - } - else { - expr3 = ast_for_expr(c, ch); - } - if (!expr3) { - return NULL; - } - return AnnAssign(expr1, expr2, expr3, simple, - LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - } - else { - int i, nch_minus_type, has_type_comment; - asdl_seq *targets; - node *value; - expr_ty expression; - string type_comment; - - /* a normal assignment */ - REQ(CHILD(n, 1), EQUAL); - - has_type_comment = TYPE(CHILD(n, num - 1)) == TYPE_COMMENT; - nch_minus_type = num - has_type_comment; - - targets = _Py_asdl_seq_new(nch_minus_type / 2, c->c_arena); - if (!targets) - return NULL; - for (i = 0; i < nch_minus_type - 2; i += 2) { - expr_ty e; - node *ch = CHILD(n, i); - if (TYPE(ch) == yield_expr) { - ast_error(c, ch, "assignment to yield expression not possible"); - return NULL; - } - e = ast_for_testlist(c, ch); - if (!e) - return NULL; - - /* set context to assign */ - if (!set_context(c, e, Store, CHILD(n, i))) - return NULL; - - asdl_seq_SET(targets, i / 2, e); - } - value = CHILD(n, nch_minus_type - 1); - if (TYPE(value) == testlist_star_expr) - expression = ast_for_testlist(c, value); - else - expression = ast_for_expr(c, value); - if (!expression) - return NULL; - if (has_type_comment) { - type_comment = NEW_TYPE_COMMENT(CHILD(n, nch_minus_type)); - if (!type_comment) - return NULL; - } - else - type_comment = NULL; - return Assign(targets, expression, type_comment, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } -} - - -static asdl_seq * -ast_for_exprlist(struct compiling *c, const node *n, expr_context_ty context) -{ - asdl_seq *seq; - int i; - expr_ty e; - - REQ(n, exprlist); - - seq = _Py_asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); - if (!seq) - return NULL; - for (i = 0; i < NCH(n); i += 2) { - e = ast_for_expr(c, CHILD(n, i)); - if (!e) - return NULL; - asdl_seq_SET(seq, i / 2, e); - if (context && !set_context(c, e, context, CHILD(n, i))) - return NULL; - } - return seq; -} - -static stmt_ty -ast_for_del_stmt(struct compiling *c, const node *n) -{ - asdl_seq *expr_list; - - /* del_stmt: 'del' exprlist */ - REQ(n, del_stmt); - - expr_list = ast_for_exprlist(c, CHILD(n, 1), Del); - if (!expr_list) - return NULL; - return Delete(expr_list, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); -} - -static stmt_ty -ast_for_flow_stmt(struct compiling *c, const node *n) -{ - /* - flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt - | yield_stmt - break_stmt: 'break' - continue_stmt: 'continue' - return_stmt: 'return' [testlist] - yield_stmt: yield_expr - yield_expr: 'yield' testlist | 'yield' 'from' test - raise_stmt: 'raise' [test [',' test [',' test]]] - */ - node *ch; - - REQ(n, flow_stmt); - ch = CHILD(n, 0); - switch (TYPE(ch)) { - case break_stmt: - return Break(LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - case continue_stmt: - return Continue(LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - case yield_stmt: { /* will reduce to yield_expr */ - expr_ty exp = ast_for_expr(c, CHILD(ch, 0)); - if (!exp) - return NULL; - return Expr(exp, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - case return_stmt: - if (NCH(ch) == 1) - return Return(NULL, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - else { - expr_ty expression = ast_for_testlist(c, CHILD(ch, 1)); - if (!expression) - return NULL; - return Return(expression, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - case raise_stmt: - if (NCH(ch) == 1) - return Raise(NULL, NULL, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - else if (NCH(ch) >= 2) { - expr_ty cause = NULL; - expr_ty expression = ast_for_expr(c, CHILD(ch, 1)); - if (!expression) - return NULL; - if (NCH(ch) == 4) { - cause = ast_for_expr(c, CHILD(ch, 3)); - if (!cause) - return NULL; - } - return Raise(expression, cause, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - /* fall through */ - default: - PyErr_Format(PyExc_SystemError, - "unexpected flow_stmt: %d", TYPE(ch)); - return NULL; - } -} - -static alias_ty -alias_for_import_name(struct compiling *c, const node *n, int store) -{ - /* - import_as_name: NAME ['as' NAME] - dotted_as_name: dotted_name ['as' NAME] - dotted_name: NAME ('.' NAME)* - */ - identifier str, name; - - loop: - switch (TYPE(n)) { - case import_as_name: { - node *name_node = CHILD(n, 0); - str = NULL; - name = NEW_IDENTIFIER(name_node); - if (!name) - return NULL; - if (NCH(n) == 3) { - node *str_node = CHILD(n, 2); - str = NEW_IDENTIFIER(str_node); - if (!str) - return NULL; - if (store && forbidden_name(c, str, str_node, 0)) - return NULL; - } - else { - if (forbidden_name(c, name, name_node, 0)) - return NULL; - } - return alias(name, str, c->c_arena); - } - case dotted_as_name: - if (NCH(n) == 1) { - n = CHILD(n, 0); - goto loop; - } - else { - node *asname_node = CHILD(n, 2); - alias_ty a = alias_for_import_name(c, CHILD(n, 0), 0); - if (!a) - return NULL; - assert(!a->asname); - a->asname = NEW_IDENTIFIER(asname_node); - if (!a->asname) - return NULL; - if (forbidden_name(c, a->asname, asname_node, 0)) - return NULL; - return a; - } - case dotted_name: - if (NCH(n) == 1) { - node *name_node = CHILD(n, 0); - name = NEW_IDENTIFIER(name_node); - if (!name) - return NULL; - if (store && forbidden_name(c, name, name_node, 0)) - return NULL; - return alias(name, NULL, c->c_arena); - } - else { - /* Create a string of the form "a.b.c" */ - int i; - size_t len; - char *s; - PyObject *uni; - - len = 0; - for (i = 0; i < NCH(n); i += 2) - /* length of string plus one for the dot */ - len += strlen(STR(CHILD(n, i))) + 1; - len--; /* the last name doesn't have a dot */ - str = PyBytes_FromStringAndSize(NULL, len); - if (!str) - return NULL; - s = PyBytes_AS_STRING(str); - if (!s) - return NULL; - for (i = 0; i < NCH(n); i += 2) { - char *sch = STR(CHILD(n, i)); - strcpy(s, STR(CHILD(n, i))); - s += strlen(sch); - *s++ = '.'; - } - --s; - *s = '\0'; - uni = PyUnicode_DecodeUTF8(PyBytes_AS_STRING(str), - PyBytes_GET_SIZE(str), - NULL); - Py_DECREF(str); - if (!uni) - return NULL; - str = uni; - PyUnicode_InternInPlace(&str); - if (PyArena_AddPyObject(c->c_arena, str) < 0) { - Py_DECREF(str); - return NULL; - } - return alias(str, NULL, c->c_arena); - } - case STAR: - str = PyUnicode_InternFromString("*"); - if (!str) - return NULL; - if (PyArena_AddPyObject(c->c_arena, str) < 0) { - Py_DECREF(str); - return NULL; - } - return alias(str, NULL, c->c_arena); - default: - PyErr_Format(PyExc_SystemError, - "unexpected import name: %d", TYPE(n)); - return NULL; - } -} - -static stmt_ty -ast_for_import_stmt(struct compiling *c, const node *n) -{ - /* - import_stmt: import_name | import_from - import_name: 'import' dotted_as_names - import_from: 'from' (('.' | '...')* dotted_name | ('.' | '...')+) - 'import' ('*' | '(' import_as_names ')' | import_as_names) - */ - int lineno; - int col_offset; - int i; - asdl_seq *aliases; - - REQ(n, import_stmt); - lineno = LINENO(n); - col_offset = n->n_col_offset; - n = CHILD(n, 0); - if (TYPE(n) == import_name) { - n = CHILD(n, 1); - REQ(n, dotted_as_names); - aliases = _Py_asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); - if (!aliases) - return NULL; - for (i = 0; i < NCH(n); i += 2) { - alias_ty import_alias = alias_for_import_name(c, CHILD(n, i), 1); - if (!import_alias) - return NULL; - asdl_seq_SET(aliases, i / 2, import_alias); - } - // Even though n is modified above, the end position is not changed - return Import(aliases, lineno, col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - else if (TYPE(n) == import_from) { - int n_children; - int idx, ndots = 0; - const node *n_copy = n; - alias_ty mod = NULL; - identifier modname = NULL; - - /* Count the number of dots (for relative imports) and check for the - optional module name */ - for (idx = 1; idx < NCH(n); idx++) { - if (TYPE(CHILD(n, idx)) == dotted_name) { - mod = alias_for_import_name(c, CHILD(n, idx), 0); - if (!mod) - return NULL; - idx++; - break; - } else if (TYPE(CHILD(n, idx)) == ELLIPSIS) { - /* three consecutive dots are tokenized as one ELLIPSIS */ - ndots += 3; - continue; - } else if (TYPE(CHILD(n, idx)) != DOT) { - break; - } - ndots++; - } - idx++; /* skip over the 'import' keyword */ - switch (TYPE(CHILD(n, idx))) { - case STAR: - /* from ... import * */ - n = CHILD(n, idx); - n_children = 1; - break; - case LPAR: - /* from ... import (x, y, z) */ - n = CHILD(n, idx + 1); - n_children = NCH(n); - break; - case import_as_names: - /* from ... import x, y, z */ - n = CHILD(n, idx); - n_children = NCH(n); - if (n_children % 2 == 0) { - ast_error(c, n, - "trailing comma not allowed without" - " surrounding parentheses"); - return NULL; - } - break; - default: - ast_error(c, n, "Unexpected node-type in from-import"); - return NULL; - } - - aliases = _Py_asdl_seq_new((n_children + 1) / 2, c->c_arena); - if (!aliases) - return NULL; - - /* handle "from ... import *" special b/c there's no children */ - if (TYPE(n) == STAR) { - alias_ty import_alias = alias_for_import_name(c, n, 1); - if (!import_alias) - return NULL; - asdl_seq_SET(aliases, 0, import_alias); - } - else { - for (i = 0; i < NCH(n); i += 2) { - alias_ty import_alias = alias_for_import_name(c, CHILD(n, i), 1); - if (!import_alias) - return NULL; - asdl_seq_SET(aliases, i / 2, import_alias); - } - } - if (mod != NULL) - modname = mod->name; - return ImportFrom(modname, aliases, ndots, lineno, col_offset, - n_copy->n_end_lineno, n_copy->n_end_col_offset, - c->c_arena); - } - PyErr_Format(PyExc_SystemError, - "unknown import statement: starts with command '%s'", - STR(CHILD(n, 0))); - return NULL; -} - -static stmt_ty -ast_for_global_stmt(struct compiling *c, const node *n) -{ - /* global_stmt: 'global' NAME (',' NAME)* */ - identifier name; - asdl_seq *s; - int i; - - REQ(n, global_stmt); - s = _Py_asdl_seq_new(NCH(n) / 2, c->c_arena); - if (!s) - return NULL; - for (i = 1; i < NCH(n); i += 2) { - name = NEW_IDENTIFIER(CHILD(n, i)); - if (!name) - return NULL; - asdl_seq_SET(s, i / 2, name); - } - return Global(s, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); -} - -static stmt_ty -ast_for_nonlocal_stmt(struct compiling *c, const node *n) -{ - /* nonlocal_stmt: 'nonlocal' NAME (',' NAME)* */ - identifier name; - asdl_seq *s; - int i; - - REQ(n, nonlocal_stmt); - s = _Py_asdl_seq_new(NCH(n) / 2, c->c_arena); - if (!s) - return NULL; - for (i = 1; i < NCH(n); i += 2) { - name = NEW_IDENTIFIER(CHILD(n, i)); - if (!name) - return NULL; - asdl_seq_SET(s, i / 2, name); - } - return Nonlocal(s, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); -} - -static stmt_ty -ast_for_assert_stmt(struct compiling *c, const node *n) -{ - /* assert_stmt: 'assert' test [',' test] */ - REQ(n, assert_stmt); - if (NCH(n) == 2) { - expr_ty expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - return Assert(expression, NULL, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - else if (NCH(n) == 4) { - expr_ty expr1, expr2; - - expr1 = ast_for_expr(c, CHILD(n, 1)); - if (!expr1) - return NULL; - expr2 = ast_for_expr(c, CHILD(n, 3)); - if (!expr2) - return NULL; - - return Assert(expr1, expr2, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - PyErr_Format(PyExc_SystemError, - "improper number of parts to 'assert' statement: %d", - NCH(n)); - return NULL; -} - -static asdl_seq * -ast_for_suite(struct compiling *c, const node *n) -{ - /* suite: simple_stmt | NEWLINE [TYPE_COMMENT NEWLINE] INDENT stmt+ DEDENT */ - asdl_seq *seq; - stmt_ty s; - int i, total, num, end, pos = 0; - node *ch; - - if (TYPE(n) != func_body_suite) { - REQ(n, suite); - } - - total = num_stmts(n); - seq = _Py_asdl_seq_new(total, c->c_arena); - if (!seq) - return NULL; - if (TYPE(CHILD(n, 0)) == simple_stmt) { - n = CHILD(n, 0); - /* simple_stmt always ends with a NEWLINE, - and may have a trailing SEMI - */ - end = NCH(n) - 1; - if (TYPE(CHILD(n, end - 1)) == SEMI) - end--; - /* loop by 2 to skip semi-colons */ - for (i = 0; i < end; i += 2) { - ch = CHILD(n, i); - s = ast_for_stmt(c, ch); - if (!s) - return NULL; - asdl_seq_SET(seq, pos++, s); - } - } - else { - i = 2; - if (TYPE(CHILD(n, 1)) == TYPE_COMMENT) { - i += 2; - REQ(CHILD(n, 2), NEWLINE); - } - - for (; i < (NCH(n) - 1); i++) { - ch = CHILD(n, i); - REQ(ch, stmt); - num = num_stmts(ch); - if (num == 1) { - /* small_stmt or compound_stmt with only one child */ - s = ast_for_stmt(c, ch); - if (!s) - return NULL; - asdl_seq_SET(seq, pos++, s); - } - else { - int j; - ch = CHILD(ch, 0); - REQ(ch, simple_stmt); - for (j = 0; j < NCH(ch); j += 2) { - /* statement terminates with a semi-colon ';' */ - if (NCH(CHILD(ch, j)) == 0) { - assert((j + 1) == NCH(ch)); - break; - } - s = ast_for_stmt(c, CHILD(ch, j)); - if (!s) - return NULL; - asdl_seq_SET(seq, pos++, s); - } - } - } - } - assert(pos == seq->size); - return seq; -} - -static void -get_last_end_pos(asdl_seq *s, int *end_lineno, int *end_col_offset) -{ - Py_ssize_t tot = asdl_seq_LEN(s); - // There must be no empty suites. - assert(tot > 0); - stmt_ty last = asdl_seq_GET(s, tot - 1); - *end_lineno = last->end_lineno; - *end_col_offset = last->end_col_offset; -} - -static stmt_ty -ast_for_if_stmt(struct compiling *c, const node *n) -{ - /* if_stmt: 'if' test ':' suite ('elif' test ':' suite)* - ['else' ':' suite] - */ - char *s; - int end_lineno, end_col_offset; - - REQ(n, if_stmt); - - if (NCH(n) == 4) { - expr_ty expression; - asdl_seq *suite_seq; - - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, CHILD(n, 3)); - if (!suite_seq) - return NULL; - get_last_end_pos(suite_seq, &end_lineno, &end_col_offset); - - return If(expression, suite_seq, NULL, LINENO(n), n->n_col_offset, - end_lineno, end_col_offset, c->c_arena); - } - - s = STR(CHILD(n, 4)); - /* s[2], the third character in the string, will be - 's' for el_s_e, or - 'i' for el_i_f - */ - if (s[2] == 's') { - expr_ty expression; - asdl_seq *seq1, *seq2; - - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - seq1 = ast_for_suite(c, CHILD(n, 3)); - if (!seq1) - return NULL; - seq2 = ast_for_suite(c, CHILD(n, 6)); - if (!seq2) - return NULL; - get_last_end_pos(seq2, &end_lineno, &end_col_offset); - - return If(expression, seq1, seq2, LINENO(n), n->n_col_offset, - end_lineno, end_col_offset, c->c_arena); - } - else if (s[2] == 'i') { - int i, n_elif, has_else = 0; - expr_ty expression; - asdl_seq *suite_seq; - asdl_seq *orelse = NULL; - n_elif = NCH(n) - 4; - /* must reference the child n_elif+1 since 'else' token is third, - not fourth, child from the end. */ - if (TYPE(CHILD(n, (n_elif + 1))) == NAME - && STR(CHILD(n, (n_elif + 1)))[2] == 's') { - has_else = 1; - n_elif -= 3; - } - n_elif /= 4; - - if (has_else) { - asdl_seq *suite_seq2; - - orelse = _Py_asdl_seq_new(1, c->c_arena); - if (!orelse) - return NULL; - expression = ast_for_expr(c, CHILD(n, NCH(n) - 6)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, CHILD(n, NCH(n) - 4)); - if (!suite_seq) - return NULL; - suite_seq2 = ast_for_suite(c, CHILD(n, NCH(n) - 1)); - if (!suite_seq2) - return NULL; - get_last_end_pos(suite_seq2, &end_lineno, &end_col_offset); - - asdl_seq_SET(orelse, 0, - If(expression, suite_seq, suite_seq2, - LINENO(CHILD(n, NCH(n) - 7)), - CHILD(n, NCH(n) - 7)->n_col_offset, - end_lineno, end_col_offset, c->c_arena)); - /* the just-created orelse handled the last elif */ - n_elif--; - } - - for (i = 0; i < n_elif; i++) { - int off = 5 + (n_elif - i - 1) * 4; - asdl_seq *newobj = _Py_asdl_seq_new(1, c->c_arena); - if (!newobj) - return NULL; - expression = ast_for_expr(c, CHILD(n, off)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, CHILD(n, off + 2)); - if (!suite_seq) - return NULL; - - if (orelse != NULL) { - get_last_end_pos(orelse, &end_lineno, &end_col_offset); - } else { - get_last_end_pos(suite_seq, &end_lineno, &end_col_offset); - } - asdl_seq_SET(newobj, 0, - If(expression, suite_seq, orelse, - LINENO(CHILD(n, off - 1)), - CHILD(n, off - 1)->n_col_offset, - end_lineno, end_col_offset, c->c_arena)); - orelse = newobj; - } - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, CHILD(n, 3)); - if (!suite_seq) - return NULL; - get_last_end_pos(orelse, &end_lineno, &end_col_offset); - return If(expression, suite_seq, orelse, - LINENO(n), n->n_col_offset, - end_lineno, end_col_offset, c->c_arena); - } - - PyErr_Format(PyExc_SystemError, - "unexpected token in 'if' statement: %s", s); - return NULL; -} - -static stmt_ty -ast_for_while_stmt(struct compiling *c, const node *n) -{ - /* while_stmt: 'while' test ':' suite ['else' ':' suite] */ - REQ(n, while_stmt); - int end_lineno, end_col_offset; - - if (NCH(n) == 4) { - expr_ty expression; - asdl_seq *suite_seq; - - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, CHILD(n, 3)); - if (!suite_seq) - return NULL; - get_last_end_pos(suite_seq, &end_lineno, &end_col_offset); - return While(expression, suite_seq, NULL, LINENO(n), n->n_col_offset, - end_lineno, end_col_offset, c->c_arena); - } - else if (NCH(n) == 7) { - expr_ty expression; - asdl_seq *seq1, *seq2; - - expression = ast_for_expr(c, CHILD(n, 1)); - if (!expression) - return NULL; - seq1 = ast_for_suite(c, CHILD(n, 3)); - if (!seq1) - return NULL; - seq2 = ast_for_suite(c, CHILD(n, 6)); - if (!seq2) - return NULL; - get_last_end_pos(seq2, &end_lineno, &end_col_offset); - - return While(expression, seq1, seq2, LINENO(n), n->n_col_offset, - end_lineno, end_col_offset, c->c_arena); - } - - PyErr_Format(PyExc_SystemError, - "wrong number of tokens for 'while' statement: %d", - NCH(n)); - return NULL; -} - -static stmt_ty -ast_for_for_stmt(struct compiling *c, const node *n0, bool is_async) -{ - const node * const n = is_async ? CHILD(n0, 1) : n0; - asdl_seq *_target, *seq = NULL, *suite_seq; - expr_ty expression; - expr_ty target, first; - const node *node_target; - int end_lineno, end_col_offset; - int has_type_comment; - string type_comment; - - if (is_async && c->c_feature_version < 5) { - ast_error(c, n, - "Async for loops are only supported in Python 3.5 and greater"); - return NULL; - } - - /* for_stmt: 'for' exprlist 'in' testlist ':' [TYPE_COMMENT] suite ['else' ':' suite] */ - REQ(n, for_stmt); - - has_type_comment = TYPE(CHILD(n, 5)) == TYPE_COMMENT; - - if (NCH(n) == 9 + has_type_comment) { - seq = ast_for_suite(c, CHILD(n, 8 + has_type_comment)); - if (!seq) - return NULL; - } - - node_target = CHILD(n, 1); - _target = ast_for_exprlist(c, node_target, Store); - if (!_target) - return NULL; - /* Check the # of children rather than the length of _target, since - for x, in ... has 1 element in _target, but still requires a Tuple. */ - first = (expr_ty)asdl_seq_GET(_target, 0); - if (NCH(node_target) == 1) - target = first; - else - target = Tuple(_target, Store, first->lineno, first->col_offset, - node_target->n_end_lineno, node_target->n_end_col_offset, - c->c_arena); - - expression = ast_for_testlist(c, CHILD(n, 3)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, CHILD(n, 5 + has_type_comment)); - if (!suite_seq) - return NULL; - - if (seq != NULL) { - get_last_end_pos(seq, &end_lineno, &end_col_offset); - } else { - get_last_end_pos(suite_seq, &end_lineno, &end_col_offset); - } - - if (has_type_comment) { - type_comment = NEW_TYPE_COMMENT(CHILD(n, 5)); - if (!type_comment) - return NULL; - } - else - type_comment = NULL; - - if (is_async) - return AsyncFor(target, expression, suite_seq, seq, type_comment, - LINENO(n0), n0->n_col_offset, - end_lineno, end_col_offset, c->c_arena); - else - return For(target, expression, suite_seq, seq, type_comment, - LINENO(n), n->n_col_offset, - end_lineno, end_col_offset, c->c_arena); -} - -static excepthandler_ty -ast_for_except_clause(struct compiling *c, const node *exc, node *body) -{ - /* except_clause: 'except' [test ['as' test]] */ - int end_lineno, end_col_offset; - REQ(exc, except_clause); - REQ(body, suite); - - if (NCH(exc) == 1) { - asdl_seq *suite_seq = ast_for_suite(c, body); - if (!suite_seq) - return NULL; - get_last_end_pos(suite_seq, &end_lineno, &end_col_offset); - - return ExceptHandler(NULL, NULL, suite_seq, LINENO(exc), - exc->n_col_offset, - end_lineno, end_col_offset, c->c_arena); - } - else if (NCH(exc) == 2) { - expr_ty expression; - asdl_seq *suite_seq; - - expression = ast_for_expr(c, CHILD(exc, 1)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, body); - if (!suite_seq) - return NULL; - get_last_end_pos(suite_seq, &end_lineno, &end_col_offset); - - return ExceptHandler(expression, NULL, suite_seq, LINENO(exc), - exc->n_col_offset, - end_lineno, end_col_offset, c->c_arena); - } - else if (NCH(exc) == 4) { - asdl_seq *suite_seq; - expr_ty expression; - identifier e = NEW_IDENTIFIER(CHILD(exc, 3)); - if (!e) - return NULL; - if (forbidden_name(c, e, CHILD(exc, 3), 0)) - return NULL; - expression = ast_for_expr(c, CHILD(exc, 1)); - if (!expression) - return NULL; - suite_seq = ast_for_suite(c, body); - if (!suite_seq) - return NULL; - get_last_end_pos(suite_seq, &end_lineno, &end_col_offset); - - return ExceptHandler(expression, e, suite_seq, LINENO(exc), - exc->n_col_offset, - end_lineno, end_col_offset, c->c_arena); - } - - PyErr_Format(PyExc_SystemError, - "wrong number of children for 'except' clause: %d", - NCH(exc)); - return NULL; -} - -static stmt_ty -ast_for_try_stmt(struct compiling *c, const node *n) -{ - const int nch = NCH(n); - int end_lineno, end_col_offset, n_except = (nch - 3)/3; - asdl_seq *body, *handlers = NULL, *orelse = NULL, *finally = NULL; - excepthandler_ty last_handler; - - REQ(n, try_stmt); - - body = ast_for_suite(c, CHILD(n, 2)); - if (body == NULL) - return NULL; - - if (TYPE(CHILD(n, nch - 3)) == NAME) { - if (strcmp(STR(CHILD(n, nch - 3)), "finally") == 0) { - if (nch >= 9 && TYPE(CHILD(n, nch - 6)) == NAME) { - /* we can assume it's an "else", - because nch >= 9 for try-else-finally and - it would otherwise have a type of except_clause */ - orelse = ast_for_suite(c, CHILD(n, nch - 4)); - if (orelse == NULL) - return NULL; - n_except--; - } - - finally = ast_for_suite(c, CHILD(n, nch - 1)); - if (finally == NULL) - return NULL; - n_except--; - } - else { - /* we can assume it's an "else", - otherwise it would have a type of except_clause */ - orelse = ast_for_suite(c, CHILD(n, nch - 1)); - if (orelse == NULL) - return NULL; - n_except--; - } - } - else if (TYPE(CHILD(n, nch - 3)) != except_clause) { - ast_error(c, n, "malformed 'try' statement"); - return NULL; - } - - if (n_except > 0) { - int i; - /* process except statements to create a try ... except */ - handlers = _Py_asdl_seq_new(n_except, c->c_arena); - if (handlers == NULL) - return NULL; - - for (i = 0; i < n_except; i++) { - excepthandler_ty e = ast_for_except_clause(c, CHILD(n, 3 + i * 3), - CHILD(n, 5 + i * 3)); - if (!e) - return NULL; - asdl_seq_SET(handlers, i, e); - } - } - - assert(finally != NULL || asdl_seq_LEN(handlers)); - if (finally != NULL) { - // finally is always last - get_last_end_pos(finally, &end_lineno, &end_col_offset); - } else if (orelse != NULL) { - // otherwise else is last - get_last_end_pos(orelse, &end_lineno, &end_col_offset); - } else { - // inline the get_last_end_pos logic due to layout mismatch - last_handler = (excepthandler_ty) asdl_seq_GET(handlers, n_except - 1); - end_lineno = last_handler->end_lineno; - end_col_offset = last_handler->end_col_offset; - } - return Try(body, handlers, orelse, finally, LINENO(n), n->n_col_offset, - end_lineno, end_col_offset, c->c_arena); -} - -/* with_item: test ['as' expr] */ -static withitem_ty -ast_for_with_item(struct compiling *c, const node *n) -{ - expr_ty context_expr, optional_vars = NULL; - - REQ(n, with_item); - context_expr = ast_for_expr(c, CHILD(n, 0)); - if (!context_expr) - return NULL; - if (NCH(n) == 3) { - optional_vars = ast_for_expr(c, CHILD(n, 2)); - - if (!optional_vars) { - return NULL; - } - if (!set_context(c, optional_vars, Store, n)) { - return NULL; - } - } - - return withitem(context_expr, optional_vars, c->c_arena); -} - -/* with_stmt: 'with' with_item (',' with_item)* ':' [TYPE_COMMENT] suite */ -static stmt_ty -ast_for_with_stmt(struct compiling *c, const node *n0, bool is_async) -{ - const node * const n = is_async ? CHILD(n0, 1) : n0; - int i, n_items, nch_minus_type, has_type_comment, end_lineno, end_col_offset; - asdl_seq *items, *body; - string type_comment; - - if (is_async && c->c_feature_version < 5) { - ast_error(c, n, - "Async with statements are only supported in Python 3.5 and greater"); - return NULL; - } - - REQ(n, with_stmt); - - has_type_comment = TYPE(CHILD(n, NCH(n) - 2)) == TYPE_COMMENT; - nch_minus_type = NCH(n) - has_type_comment; - - n_items = (nch_minus_type - 2) / 2; - items = _Py_asdl_seq_new(n_items, c->c_arena); - if (!items) - return NULL; - for (i = 1; i < nch_minus_type - 2; i += 2) { - withitem_ty item = ast_for_with_item(c, CHILD(n, i)); - if (!item) - return NULL; - asdl_seq_SET(items, (i - 1) / 2, item); - } - - body = ast_for_suite(c, CHILD(n, NCH(n) - 1)); - if (!body) - return NULL; - get_last_end_pos(body, &end_lineno, &end_col_offset); - - if (has_type_comment) { - type_comment = NEW_TYPE_COMMENT(CHILD(n, NCH(n) - 2)); - if (!type_comment) - return NULL; - } - else - type_comment = NULL; - - if (is_async) - return AsyncWith(items, body, type_comment, LINENO(n0), n0->n_col_offset, - end_lineno, end_col_offset, c->c_arena); - else - return With(items, body, type_comment, LINENO(n), n->n_col_offset, - end_lineno, end_col_offset, c->c_arena); -} - -static stmt_ty -ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq) -{ - /* classdef: 'class' NAME ['(' arglist ')'] ':' suite */ - PyObject *classname; - asdl_seq *s; - expr_ty call; - int end_lineno, end_col_offset; - - REQ(n, classdef); - - if (NCH(n) == 4) { /* class NAME ':' suite */ - s = ast_for_suite(c, CHILD(n, 3)); - if (!s) - return NULL; - get_last_end_pos(s, &end_lineno, &end_col_offset); - - classname = NEW_IDENTIFIER(CHILD(n, 1)); - if (!classname) - return NULL; - if (forbidden_name(c, classname, CHILD(n, 3), 0)) - return NULL; - return ClassDef(classname, NULL, NULL, s, decorator_seq, - LINENO(n), n->n_col_offset, - end_lineno, end_col_offset, c->c_arena); - } - - if (TYPE(CHILD(n, 3)) == RPAR) { /* class NAME '(' ')' ':' suite */ - s = ast_for_suite(c, CHILD(n, 5)); - if (!s) - return NULL; - get_last_end_pos(s, &end_lineno, &end_col_offset); - - classname = NEW_IDENTIFIER(CHILD(n, 1)); - if (!classname) - return NULL; - if (forbidden_name(c, classname, CHILD(n, 3), 0)) - return NULL; - return ClassDef(classname, NULL, NULL, s, decorator_seq, - LINENO(n), n->n_col_offset, - end_lineno, end_col_offset, c->c_arena); - } - - /* class NAME '(' arglist ')' ':' suite */ - /* build up a fake Call node so we can extract its pieces */ - { - PyObject *dummy_name; - expr_ty dummy; - dummy_name = NEW_IDENTIFIER(CHILD(n, 1)); - if (!dummy_name) - return NULL; - dummy = Name(dummy_name, Load, LINENO(n), n->n_col_offset, - CHILD(n, 1)->n_end_lineno, CHILD(n, 1)->n_end_col_offset, - c->c_arena); - call = ast_for_call(c, CHILD(n, 3), dummy, - CHILD(n, 1), NULL, CHILD(n, 4)); - if (!call) - return NULL; - } - s = ast_for_suite(c, CHILD(n, 6)); - if (!s) - return NULL; - get_last_end_pos(s, &end_lineno, &end_col_offset); - - classname = NEW_IDENTIFIER(CHILD(n, 1)); - if (!classname) - return NULL; - if (forbidden_name(c, classname, CHILD(n, 1), 0)) - return NULL; - - return ClassDef(classname, call->v.Call.args, call->v.Call.keywords, s, - decorator_seq, LINENO(n), n->n_col_offset, - end_lineno, end_col_offset, c->c_arena); -} - -static stmt_ty -ast_for_stmt(struct compiling *c, const node *n) -{ - if (TYPE(n) == stmt) { - assert(NCH(n) == 1); - n = CHILD(n, 0); - } - if (TYPE(n) == simple_stmt) { - assert(num_stmts(n) == 1); - n = CHILD(n, 0); - } - if (TYPE(n) == small_stmt) { - n = CHILD(n, 0); - /* small_stmt: expr_stmt | del_stmt | pass_stmt | flow_stmt - | import_stmt | global_stmt | nonlocal_stmt | assert_stmt - */ - switch (TYPE(n)) { - case expr_stmt: - return ast_for_expr_stmt(c, n); - case del_stmt: - return ast_for_del_stmt(c, n); - case pass_stmt: - return Pass(LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - case flow_stmt: - return ast_for_flow_stmt(c, n); - case import_stmt: - return ast_for_import_stmt(c, n); - case global_stmt: - return ast_for_global_stmt(c, n); - case nonlocal_stmt: - return ast_for_nonlocal_stmt(c, n); - case assert_stmt: - return ast_for_assert_stmt(c, n); - default: - PyErr_Format(PyExc_SystemError, - "unhandled small_stmt: TYPE=%d NCH=%d\n", - TYPE(n), NCH(n)); - return NULL; - } - } - else { - /* compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt - | funcdef | classdef | decorated | async_stmt - */ - node *ch = CHILD(n, 0); - REQ(n, compound_stmt); - switch (TYPE(ch)) { - case if_stmt: - return ast_for_if_stmt(c, ch); - case while_stmt: - return ast_for_while_stmt(c, ch); - case for_stmt: - return ast_for_for_stmt(c, ch, 0); - case try_stmt: - return ast_for_try_stmt(c, ch); - case with_stmt: - return ast_for_with_stmt(c, ch, 0); - case funcdef: - return ast_for_funcdef(c, ch, NULL); - case classdef: - return ast_for_classdef(c, ch, NULL); - case decorated: - return ast_for_decorated(c, ch); - case async_stmt: - return ast_for_async_stmt(c, ch); - default: - PyErr_Format(PyExc_SystemError, - "unhandled compound_stmt: TYPE=%d NCH=%d\n", - TYPE(n), NCH(n)); - return NULL; - } - } -} - -static PyObject * -parsenumber_raw(struct compiling *c, const char *s) -{ - const char *end; - long x; - double dx; - Py_complex compl; - int imflag; - - assert(s != NULL); - errno = 0; - end = s + strlen(s) - 1; - imflag = *end == 'j' || *end == 'J'; - if (s[0] == '0') { - x = (long) PyOS_strtoul(s, (char **)&end, 0); - if (x < 0 && errno == 0) { - return PyLong_FromString(s, (char **)0, 0); - } - } - else - x = PyOS_strtol(s, (char **)&end, 0); - if (*end == '\0') { - if (errno != 0) - return PyLong_FromString(s, (char **)0, 0); - return PyLong_FromLong(x); - } - /* XXX Huge floats may silently fail */ - if (imflag) { - compl.real = 0.; - compl.imag = PyOS_string_to_double(s, (char **)&end, NULL); - if (compl.imag == -1.0 && PyErr_Occurred()) - return NULL; - return PyComplex_FromCComplex(compl); - } - else - { - dx = PyOS_string_to_double(s, NULL, NULL); - if (dx == -1.0 && PyErr_Occurred()) - return NULL; - return PyFloat_FromDouble(dx); - } -} - -static PyObject * -parsenumber(struct compiling *c, const char *s) -{ - char *dup, *end; - PyObject *res = NULL; - - assert(s != NULL); - - if (strchr(s, '_') == NULL) { - return parsenumber_raw(c, s); - } - /* Create a duplicate without underscores. */ - dup = PyMem_Malloc(strlen(s) + 1); - if (dup == NULL) { - return PyErr_NoMemory(); - } - end = dup; - for (; *s; s++) { - if (*s != '_') { - *end++ = *s; - } - } - *end = '\0'; - res = parsenumber_raw(c, dup); - PyMem_Free(dup); - return res; -} - -static PyObject * -decode_utf8(struct compiling *c, const char **sPtr, const char *end) -{ - const char *s, *t; - t = s = *sPtr; - /* while (s < end && *s != '\\') s++; */ /* inefficient for u".." */ - while (s < end && (*s & 0x80)) s++; - *sPtr = s; - return PyUnicode_DecodeUTF8(t, s - t, NULL); -} - -static int -warn_invalid_escape_sequence(struct compiling *c, const node *n, - unsigned char first_invalid_escape_char) -{ - PyObject *msg = PyUnicode_FromFormat("invalid escape sequence \\%c", - first_invalid_escape_char); - if (msg == NULL) { - return -1; - } - if (PyErr_WarnExplicitObject(PyExc_DeprecationWarning, msg, - c->c_filename, LINENO(n), - NULL, NULL) < 0) - { - if (PyErr_ExceptionMatches(PyExc_DeprecationWarning)) { - /* Replace the DeprecationWarning exception with a SyntaxError - to get a more accurate error report */ - PyErr_Clear(); - ast_error(c, n, "%U", msg); - } - Py_DECREF(msg); - return -1; - } - Py_DECREF(msg); - return 0; -} - -static PyObject * -decode_unicode_with_escapes(struct compiling *c, const node *n, const char *s, - size_t len) -{ - PyObject *v, *u; - char *buf; - char *p; - const char *end; - - /* check for integer overflow */ - if (len > SIZE_MAX / 6) - return NULL; - /* "ä" (2 bytes) may become "\U000000E4" (10 bytes), or 1:5 - "\ä" (3 bytes) may become "\u005c\U000000E4" (16 bytes), or ~1:6 */ - u = PyBytes_FromStringAndSize((char *)NULL, len * 6); - if (u == NULL) - return NULL; - p = buf = PyBytes_AsString(u); - end = s + len; - while (s < end) { - if (*s == '\\') { - *p++ = *s++; - if (s >= end || *s & 0x80) { - strcpy(p, "u005c"); - p += 5; - if (s >= end) - break; - } - } - if (*s & 0x80) { /* XXX inefficient */ - PyObject *w; - int kind; - const void *data; - Py_ssize_t len, i; - w = decode_utf8(c, &s, end); - if (w == NULL) { - Py_DECREF(u); - return NULL; - } - kind = PyUnicode_KIND(w); - data = PyUnicode_DATA(w); - len = PyUnicode_GET_LENGTH(w); - for (i = 0; i < len; i++) { - Py_UCS4 chr = PyUnicode_READ(kind, data, i); - sprintf(p, "\\U%08x", chr); - p += 10; - } - /* Should be impossible to overflow */ - assert(p - buf <= PyBytes_GET_SIZE(u)); - Py_DECREF(w); - } else { - *p++ = *s++; - } - } - len = p - buf; - s = buf; - - const char *first_invalid_escape; - v = _PyUnicode_DecodeUnicodeEscape(s, len, NULL, &first_invalid_escape); - - if (v != NULL && first_invalid_escape != NULL) { - if (warn_invalid_escape_sequence(c, n, *first_invalid_escape) < 0) { - /* We have not decref u before because first_invalid_escape points - inside u. */ - Py_XDECREF(u); - Py_DECREF(v); - return NULL; - } - } - Py_XDECREF(u); - return v; -} - -static PyObject * -decode_bytes_with_escapes(struct compiling *c, const node *n, const char *s, - size_t len) -{ - const char *first_invalid_escape; - PyObject *result = _PyBytes_DecodeEscape(s, len, NULL, - &first_invalid_escape); - if (result == NULL) - return NULL; - - if (first_invalid_escape != NULL) { - if (warn_invalid_escape_sequence(c, n, *first_invalid_escape) < 0) { - Py_DECREF(result); - return NULL; - } - } - return result; -} - -/* Shift locations for the given node and all its children by adding `lineno` - and `col_offset` to existing locations. */ -static void fstring_shift_node_locations(node *n, int lineno, int col_offset) -{ - n->n_col_offset = n->n_col_offset + col_offset; - n->n_end_col_offset = n->n_end_col_offset + col_offset; - for (int i = 0; i < NCH(n); ++i) { - if (n->n_lineno && n->n_lineno < CHILD(n, i)->n_lineno) { - /* Shifting column offsets unnecessary if there's been newlines. */ - col_offset = 0; - } - fstring_shift_node_locations(CHILD(n, i), lineno, col_offset); - } - n->n_lineno = n->n_lineno + lineno; - n->n_end_lineno = n->n_end_lineno + lineno; -} - -/* Fix locations for the given node and its children. - - `parent` is the enclosing node. - `n` is the node which locations are going to be fixed relative to parent. - `expr_str` is the child node's string representation, including braces. -*/ -static void -fstring_fix_node_location(const node *parent, node *n, char *expr_str) -{ - char *substr = NULL; - char *start; - int lines = LINENO(parent) - 1; - int cols = parent->n_col_offset; - /* Find the full fstring to fix location information in `n`. */ - while (parent && parent->n_type != STRING) - parent = parent->n_child; - if (parent && parent->n_str) { - substr = strstr(parent->n_str, expr_str); - if (substr) { - start = substr; - while (start > parent->n_str) { - if (start[0] == '\n') - break; - start--; - } - cols += (int)(substr - start); - /* adjust the start based on the number of newlines encountered - before the f-string expression */ - for (char* p = parent->n_str; p < substr; p++) { - if (*p == '\n') { - lines++; - } - } - } - } - fstring_shift_node_locations(n, lines, cols); -} - -/* Compile this expression in to an expr_ty. Add parens around the - expression, in order to allow leading spaces in the expression. */ -static expr_ty -fstring_compile_expr(const char *expr_start, const char *expr_end, - struct compiling *c, const node *n) - -{ - node *mod_n; - mod_ty mod; - char *str; - Py_ssize_t len; - const char *s; - - assert(expr_end >= expr_start); - assert(*(expr_start-1) == '{'); - assert(*expr_end == '}' || *expr_end == '!' || *expr_end == ':' || - *expr_end == '='); - - /* If the substring is all whitespace, it's an error. We need to catch this - here, and not when we call PyParser_SimpleParseStringFlagsFilename, - because turning the expression '' in to '()' would go from being invalid - to valid. */ - for (s = expr_start; s != expr_end; s++) { - char c = *s; - /* The Python parser ignores only the following whitespace - characters (\r already is converted to \n). */ - if (!(c == ' ' || c == '\t' || c == '\n' || c == '\f')) { - break; - } - } - if (s == expr_end) { - ast_error(c, n, "f-string: empty expression not allowed"); - return NULL; - } - - len = expr_end - expr_start; - /* Allocate 3 extra bytes: open paren, close paren, null byte. */ - str = PyMem_RawMalloc(len + 3); - if (str == NULL) { - PyErr_NoMemory(); - return NULL; - } - - str[0] = '('; - memcpy(str+1, expr_start, len); - str[len+1] = ')'; - str[len+2] = 0; - - PyCompilerFlags cf = _PyCompilerFlags_INIT; - cf.cf_flags = PyCF_ONLY_AST; - mod_n = PyParser_SimpleParseStringFlagsFilename(str, "", - Py_eval_input, 0); - if (!mod_n) { - PyMem_RawFree(str); - return NULL; - } - /* Reuse str to find the correct column offset. */ - str[0] = '{'; - str[len+1] = '}'; - fstring_fix_node_location(n, mod_n, str); - mod = PyAST_FromNode(mod_n, &cf, "", c->c_arena); - PyMem_RawFree(str); - PyNode_Free(mod_n); - if (!mod) - return NULL; - return mod->v.Expression.body; -} - -/* Return -1 on error. - - Return 0 if we reached the end of the literal. - - Return 1 if we haven't reached the end of the literal, but we want - the caller to process the literal up to this point. Used for - doubled braces. -*/ -static int -fstring_find_literal(const char **str, const char *end, int raw, - PyObject **literal, int recurse_lvl, - struct compiling *c, const node *n) -{ - /* Get any literal string. It ends when we hit an un-doubled left - brace (which isn't part of a unicode name escape such as - "\N{EULER CONSTANT}"), or the end of the string. */ - - const char *s = *str; - const char *literal_start = s; - int result = 0; - - assert(*literal == NULL); - while (s < end) { - char ch = *s++; - if (!raw && ch == '\\' && s < end) { - ch = *s++; - if (ch == 'N') { - if (s < end && *s++ == '{') { - while (s < end && *s++ != '}') { - } - continue; - } - break; - } - if (ch == '{' && warn_invalid_escape_sequence(c, n, ch) < 0) { - return -1; - } - } - if (ch == '{' || ch == '}') { - /* Check for doubled braces, but only at the top level. If - we checked at every level, then f'{0:{3}}' would fail - with the two closing braces. */ - if (recurse_lvl == 0) { - if (s < end && *s == ch) { - /* We're going to tell the caller that the literal ends - here, but that they should continue scanning. But also - skip over the second brace when we resume scanning. */ - *str = s + 1; - result = 1; - goto done; - } - - /* Where a single '{' is the start of a new expression, a - single '}' is not allowed. */ - if (ch == '}') { - *str = s - 1; - ast_error(c, n, "f-string: single '}' is not allowed"); - return -1; - } - } - /* We're either at a '{', which means we're starting another - expression; or a '}', which means we're at the end of this - f-string (for a nested format_spec). */ - s--; - break; - } - } - *str = s; - assert(s <= end); - assert(s == end || *s == '{' || *s == '}'); -done: - if (literal_start != s) { - if (raw) - *literal = PyUnicode_DecodeUTF8Stateful(literal_start, - s - literal_start, - NULL, NULL); - else - *literal = decode_unicode_with_escapes(c, n, literal_start, - s - literal_start); - if (!*literal) - return -1; - } - return result; -} - -/* Forward declaration because parsing is recursive. */ -static expr_ty -fstring_parse(const char **str, const char *end, int raw, int recurse_lvl, - struct compiling *c, const node *n); - -/* Parse the f-string at *str, ending at end. We know *str starts an - expression (so it must be a '{'). Returns the FormattedValue node, which - includes the expression, conversion character, format_spec expression, and - optionally the text of the expression (if = is used). - - Note that I don't do a perfect job here: I don't make sure that a - closing brace doesn't match an opening paren, for example. It - doesn't need to error on all invalid expressions, just correctly - find the end of all valid ones. Any errors inside the expression - will be caught when we parse it later. - - *expression is set to the expression. For an '=' "debug" expression, - *expr_text is set to the debug text (the original text of the expression, - including the '=' and any whitespace around it, as a string object). If - not a debug expression, *expr_text set to NULL. */ -static int -fstring_find_expr(const char **str, const char *end, int raw, int recurse_lvl, - PyObject **expr_text, expr_ty *expression, - struct compiling *c, const node *n) -{ - /* Return -1 on error, else 0. */ - - const char *expr_start; - const char *expr_end; - expr_ty simple_expression; - expr_ty format_spec = NULL; /* Optional format specifier. */ - int conversion = -1; /* The conversion char. Use default if not - specified, or !r if using = and no format - spec. */ - - /* 0 if we're not in a string, else the quote char we're trying to - match (single or double quote). */ - char quote_char = 0; - - /* If we're inside a string, 1=normal, 3=triple-quoted. */ - int string_type = 0; - - /* Keep track of nesting level for braces/parens/brackets in - expressions. */ - Py_ssize_t nested_depth = 0; - char parenstack[MAXLEVEL]; - - *expr_text = NULL; - - /* Can only nest one level deep. */ - if (recurse_lvl >= 2) { - ast_error(c, n, "f-string: expressions nested too deeply"); - goto error; - } - - /* The first char must be a left brace, or we wouldn't have gotten - here. Skip over it. */ - assert(**str == '{'); - *str += 1; - - expr_start = *str; - for (; *str < end; (*str)++) { - char ch; - - /* Loop invariants. */ - assert(nested_depth >= 0); - assert(*str >= expr_start && *str < end); - if (quote_char) - assert(string_type == 1 || string_type == 3); - else - assert(string_type == 0); - - ch = **str; - /* Nowhere inside an expression is a backslash allowed. */ - if (ch == '\\') { - /* Error: can't include a backslash character, inside - parens or strings or not. */ - ast_error(c, n, - "f-string expression part " - "cannot include a backslash"); - goto error; - } - if (quote_char) { - /* We're inside a string. See if we're at the end. */ - /* This code needs to implement the same non-error logic - as tok_get from tokenizer.c, at the letter_quote - label. To actually share that code would be a - nightmare. But, it's unlikely to change and is small, - so duplicate it here. Note we don't need to catch all - of the errors, since they'll be caught when parsing the - expression. We just need to match the non-error - cases. Thus we can ignore \n in single-quoted strings, - for example. Or non-terminated strings. */ - if (ch == quote_char) { - /* Does this match the string_type (single or triple - quoted)? */ - if (string_type == 3) { - if (*str+2 < end && *(*str+1) == ch && *(*str+2) == ch) { - /* We're at the end of a triple quoted string. */ - *str += 2; - string_type = 0; - quote_char = 0; - continue; - } - } else { - /* We're at the end of a normal string. */ - quote_char = 0; - string_type = 0; - continue; - } - } - } else if (ch == '\'' || ch == '"') { - /* Is this a triple quoted string? */ - if (*str+2 < end && *(*str+1) == ch && *(*str+2) == ch) { - string_type = 3; - *str += 2; - } else { - /* Start of a normal string. */ - string_type = 1; - } - /* Start looking for the end of the string. */ - quote_char = ch; - } else if (ch == '[' || ch == '{' || ch == '(') { - if (nested_depth >= MAXLEVEL) { - ast_error(c, n, "f-string: too many nested parenthesis"); - goto error; - } - parenstack[nested_depth] = ch; - nested_depth++; - } else if (ch == '#') { - /* Error: can't include a comment character, inside parens - or not. */ - ast_error(c, n, "f-string expression part cannot include '#'"); - goto error; - } else if (nested_depth == 0 && - (ch == '!' || ch == ':' || ch == '}' || - ch == '=' || ch == '>' || ch == '<')) { - /* See if there's a next character. */ - if (*str+1 < end) { - char next = *(*str+1); - - /* For "!=". since '=' is not an allowed conversion character, - nothing is lost in this test. */ - if ((ch == '!' && next == '=') || /* != */ - (ch == '=' && next == '=') || /* == */ - (ch == '<' && next == '=') || /* <= */ - (ch == '>' && next == '=') /* >= */ - ) { - *str += 1; - continue; - } - /* Don't get out of the loop for these, if they're single - chars (not part of 2-char tokens). If by themselves, they - don't end an expression (unlike say '!'). */ - if (ch == '>' || ch == '<') { - continue; - } - } - - /* Normal way out of this loop. */ - break; - } else if (ch == ']' || ch == '}' || ch == ')') { - if (!nested_depth) { - ast_error(c, n, "f-string: unmatched '%c'", ch); - goto error; - } - nested_depth--; - int opening = parenstack[nested_depth]; - if (!((opening == '(' && ch == ')') || - (opening == '[' && ch == ']') || - (opening == '{' && ch == '}'))) - { - ast_error(c, n, - "f-string: closing parenthesis '%c' " - "does not match opening parenthesis '%c'", - ch, opening); - goto error; - } - } else { - /* Just consume this char and loop around. */ - } - } - expr_end = *str; - /* If we leave this loop in a string or with mismatched parens, we - don't care. We'll get a syntax error when compiling the - expression. But, we can produce a better error message, so - let's just do that.*/ - if (quote_char) { - ast_error(c, n, "f-string: unterminated string"); - goto error; - } - if (nested_depth) { - int opening = parenstack[nested_depth - 1]; - ast_error(c, n, "f-string: unmatched '%c'", opening); - goto error; - } - - if (*str >= end) - goto unexpected_end_of_string; - - /* Compile the expression as soon as possible, so we show errors - related to the expression before errors related to the - conversion or format_spec. */ - simple_expression = fstring_compile_expr(expr_start, expr_end, c, n); - if (!simple_expression) - goto error; - - /* Check for =, which puts the text value of the expression in - expr_text. */ - if (**str == '=') { - *str += 1; - - /* Skip over ASCII whitespace. No need to test for end of string - here, since we know there's at least a trailing quote somewhere - ahead. */ - while (Py_ISSPACE(**str)) { - *str += 1; - } - - /* Set *expr_text to the text of the expression. */ - *expr_text = PyUnicode_FromStringAndSize(expr_start, *str-expr_start); - if (!*expr_text) { - goto error; - } - } - - /* Check for a conversion char, if present. */ - if (**str == '!') { - *str += 1; - if (*str >= end) - goto unexpected_end_of_string; - - conversion = **str; - *str += 1; - - /* Validate the conversion. */ - if (!(conversion == 's' || conversion == 'r' || conversion == 'a')) { - ast_error(c, n, - "f-string: invalid conversion character: " - "expected 's', 'r', or 'a'"); - goto error; - } - - } - - /* Check for the format spec, if present. */ - if (*str >= end) - goto unexpected_end_of_string; - if (**str == ':') { - *str += 1; - if (*str >= end) - goto unexpected_end_of_string; - - /* Parse the format spec. */ - format_spec = fstring_parse(str, end, raw, recurse_lvl+1, c, n); - if (!format_spec) - goto error; - } - - if (*str >= end || **str != '}') - goto unexpected_end_of_string; - - /* We're at a right brace. Consume it. */ - assert(*str < end); - assert(**str == '}'); - *str += 1; - - /* If we're in = mode (detected by non-NULL expr_text), and have no format - spec and no explicit conversion, set the conversion to 'r'. */ - if (*expr_text && format_spec == NULL && conversion == -1) { - conversion = 'r'; - } - - /* And now create the FormattedValue node that represents this - entire expression with the conversion and format spec. */ - *expression = FormattedValue(simple_expression, conversion, - format_spec, LINENO(n), - n->n_col_offset, n->n_end_lineno, - n->n_end_col_offset, c->c_arena); - if (!*expression) - goto error; - - return 0; - -unexpected_end_of_string: - ast_error(c, n, "f-string: expecting '}'"); - /* Falls through to error. */ - -error: - Py_XDECREF(*expr_text); - return -1; - -} - -/* Return -1 on error. - - Return 0 if we have a literal (possible zero length) and an - expression (zero length if at the end of the string. - - Return 1 if we have a literal, but no expression, and we want the - caller to call us again. This is used to deal with doubled - braces. - - When called multiple times on the string 'a{{b{0}c', this function - will return: - - 1. the literal 'a{' with no expression, and a return value - of 1. Despite the fact that there's no expression, the return - value of 1 means we're not finished yet. - - 2. the literal 'b' and the expression '0', with a return value of - 0. The fact that there's an expression means we're not finished. - - 3. literal 'c' with no expression and a return value of 0. The - combination of the return value of 0 with no expression means - we're finished. -*/ -static int -fstring_find_literal_and_expr(const char **str, const char *end, int raw, - int recurse_lvl, PyObject **literal, - PyObject **expr_text, expr_ty *expression, - struct compiling *c, const node *n) -{ - int result; - - assert(*literal == NULL && *expression == NULL); - - /* Get any literal string. */ - result = fstring_find_literal(str, end, raw, literal, recurse_lvl, c, n); - if (result < 0) - goto error; - - assert(result == 0 || result == 1); - - if (result == 1) - /* We have a literal, but don't look at the expression. */ - return 1; - - if (*str >= end || **str == '}') - /* We're at the end of the string or the end of a nested - f-string: no expression. The top-level error case where we - expect to be at the end of the string but we're at a '}' is - handled later. */ - return 0; - - /* We must now be the start of an expression, on a '{'. */ - assert(**str == '{'); - - if (fstring_find_expr(str, end, raw, recurse_lvl, expr_text, - expression, c, n) < 0) - goto error; - - return 0; - -error: - Py_CLEAR(*literal); - return -1; -} - -#define EXPRLIST_N_CACHED 64 - -typedef struct { - /* Incrementally build an array of expr_ty, so be used in an - asdl_seq. Cache some small but reasonably sized number of - expr_ty's, and then after that start dynamically allocating, - doubling the number allocated each time. Note that the f-string - f'{0}a{1}' contains 3 expr_ty's: 2 FormattedValue's, and one - Constant for the literal 'a'. So you add expr_ty's about twice as - fast as you add expressions in an f-string. */ - - Py_ssize_t allocated; /* Number we've allocated. */ - Py_ssize_t size; /* Number we've used. */ - expr_ty *p; /* Pointer to the memory we're actually - using. Will point to 'data' until we - start dynamically allocating. */ - expr_ty data[EXPRLIST_N_CACHED]; -} ExprList; - -#ifdef NDEBUG -#define ExprList_check_invariants(l) -#else -static void -ExprList_check_invariants(ExprList *l) -{ - /* Check our invariants. Make sure this object is "live", and - hasn't been deallocated. */ - assert(l->size >= 0); - assert(l->p != NULL); - if (l->size <= EXPRLIST_N_CACHED) - assert(l->data == l->p); -} -#endif - -static void -ExprList_Init(ExprList *l) -{ - l->allocated = EXPRLIST_N_CACHED; - l->size = 0; - - /* Until we start allocating dynamically, p points to data. */ - l->p = l->data; - - ExprList_check_invariants(l); -} - -static int -ExprList_Append(ExprList *l, expr_ty exp) -{ - ExprList_check_invariants(l); - if (l->size >= l->allocated) { - /* We need to alloc (or realloc) the memory. */ - Py_ssize_t new_size = l->allocated * 2; - - /* See if we've ever allocated anything dynamically. */ - if (l->p == l->data) { - Py_ssize_t i; - /* We're still using the cached data. Switch to - alloc-ing. */ - l->p = PyMem_RawMalloc(sizeof(expr_ty) * new_size); - if (!l->p) - return -1; - /* Copy the cached data into the new buffer. */ - for (i = 0; i < l->size; i++) - l->p[i] = l->data[i]; - } else { - /* Just realloc. */ - expr_ty *tmp = PyMem_RawRealloc(l->p, sizeof(expr_ty) * new_size); - if (!tmp) { - PyMem_RawFree(l->p); - l->p = NULL; - return -1; - } - l->p = tmp; - } - - l->allocated = new_size; - assert(l->allocated == 2 * l->size); - } - - l->p[l->size++] = exp; - - ExprList_check_invariants(l); - return 0; -} - -static void -ExprList_Dealloc(ExprList *l) -{ - ExprList_check_invariants(l); - - /* If there's been an error, or we've never dynamically allocated, - do nothing. */ - if (!l->p || l->p == l->data) { - /* Do nothing. */ - } else { - /* We have dynamically allocated. Free the memory. */ - PyMem_RawFree(l->p); - } - l->p = NULL; - l->size = -1; -} - -static asdl_seq * -ExprList_Finish(ExprList *l, PyArena *arena) -{ - asdl_seq *seq; - - ExprList_check_invariants(l); - - /* Allocate the asdl_seq and copy the expressions in to it. */ - seq = _Py_asdl_seq_new(l->size, arena); - if (seq) { - Py_ssize_t i; - for (i = 0; i < l->size; i++) - asdl_seq_SET(seq, i, l->p[i]); - } - ExprList_Dealloc(l); - return seq; -} - -/* The FstringParser is designed to add a mix of strings and - f-strings, and concat them together as needed. Ultimately, it - generates an expr_ty. */ -typedef struct { - PyObject *last_str; - ExprList expr_list; - int fmode; -} FstringParser; - -#ifdef NDEBUG -#define FstringParser_check_invariants(state) -#else -static void -FstringParser_check_invariants(FstringParser *state) -{ - if (state->last_str) - assert(PyUnicode_CheckExact(state->last_str)); - ExprList_check_invariants(&state->expr_list); -} -#endif - -static void -FstringParser_Init(FstringParser *state) -{ - state->last_str = NULL; - state->fmode = 0; - ExprList_Init(&state->expr_list); - FstringParser_check_invariants(state); -} - -static void -FstringParser_Dealloc(FstringParser *state) -{ - FstringParser_check_invariants(state); - - Py_XDECREF(state->last_str); - ExprList_Dealloc(&state->expr_list); -} - -/* Constants for the following */ -static PyObject *u_kind; - -/* Compute 'kind' field for string Constant (either 'u' or None) */ -static PyObject * -make_kind(struct compiling *c, const node *n) -{ - char *s = NULL; - PyObject *kind = NULL; - - /* Find the first string literal, if any */ - while (TYPE(n) != STRING) { - if (NCH(n) == 0) - return NULL; - n = CHILD(n, 0); - } - REQ(n, STRING); - - /* If it starts with 'u', return a PyUnicode "u" string */ - s = STR(n); - if (s && *s == 'u') { - if (!u_kind) { - u_kind = PyUnicode_InternFromString("u"); - if (!u_kind) - return NULL; - } - kind = u_kind; - if (PyArena_AddPyObject(c->c_arena, kind) < 0) { - return NULL; - } - Py_INCREF(kind); - } - return kind; -} - -/* Make a Constant node, but decref the PyUnicode object being added. */ -static expr_ty -make_str_node_and_del(PyObject **str, struct compiling *c, const node* n) -{ - PyObject *s = *str; - PyObject *kind = NULL; - *str = NULL; - assert(PyUnicode_CheckExact(s)); - if (PyArena_AddPyObject(c->c_arena, s) < 0) { - Py_DECREF(s); - return NULL; - } - kind = make_kind(c, n); - if (kind == NULL && PyErr_Occurred()) - return NULL; - return Constant(s, kind, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); -} - -/* Add a non-f-string (that is, a regular literal string). str is - decref'd. */ -static int -FstringParser_ConcatAndDel(FstringParser *state, PyObject *str) -{ - FstringParser_check_invariants(state); - - assert(PyUnicode_CheckExact(str)); - - if (PyUnicode_GET_LENGTH(str) == 0) { - Py_DECREF(str); - return 0; - } - - if (!state->last_str) { - /* We didn't have a string before, so just remember this one. */ - state->last_str = str; - } else { - /* Concatenate this with the previous string. */ - PyUnicode_AppendAndDel(&state->last_str, str); - if (!state->last_str) - return -1; - } - FstringParser_check_invariants(state); - return 0; -} - -/* Parse an f-string. The f-string is in *str to end, with no - 'f' or quotes. */ -static int -FstringParser_ConcatFstring(FstringParser *state, const char **str, - const char *end, int raw, int recurse_lvl, - struct compiling *c, const node *n) -{ - FstringParser_check_invariants(state); - state->fmode = 1; - - /* Parse the f-string. */ - while (1) { - PyObject *literal = NULL; - PyObject *expr_text = NULL; - expr_ty expression = NULL; - - /* If there's a zero length literal in front of the - expression, literal will be NULL. If we're at the end of - the f-string, expression will be NULL (unless result == 1, - see below). */ - int result = fstring_find_literal_and_expr(str, end, raw, recurse_lvl, - &literal, &expr_text, - &expression, c, n); - if (result < 0) - return -1; - - /* Add the literal, if any. */ - if (literal && FstringParser_ConcatAndDel(state, literal) < 0) { - Py_XDECREF(expr_text); - return -1; - } - /* Add the expr_text, if any. */ - if (expr_text && FstringParser_ConcatAndDel(state, expr_text) < 0) { - return -1; - } - - /* We've dealt with the literal and expr_text, their ownership has - been transferred to the state object. Don't look at them again. */ - - /* See if we should just loop around to get the next literal - and expression, while ignoring the expression this - time. This is used for un-doubling braces, as an - optimization. */ - if (result == 1) - continue; - - if (!expression) - /* We're done with this f-string. */ - break; - - /* We know we have an expression. Convert any existing string - to a Constant node. */ - if (!state->last_str) { - /* Do nothing. No previous literal. */ - } else { - /* Convert the existing last_str literal to a Constant node. */ - expr_ty str = make_str_node_and_del(&state->last_str, c, n); - if (!str || ExprList_Append(&state->expr_list, str) < 0) - return -1; - } - - if (ExprList_Append(&state->expr_list, expression) < 0) - return -1; - } - - /* If recurse_lvl is zero, then we must be at the end of the - string. Otherwise, we must be at a right brace. */ - - if (recurse_lvl == 0 && *str < end-1) { - ast_error(c, n, "f-string: unexpected end of string"); - return -1; - } - if (recurse_lvl != 0 && **str != '}') { - ast_error(c, n, "f-string: expecting '}'"); - return -1; - } - - FstringParser_check_invariants(state); - return 0; -} - -/* Convert the partial state reflected in last_str and expr_list to an - expr_ty. The expr_ty can be a Constant, or a JoinedStr. */ -static expr_ty -FstringParser_Finish(FstringParser *state, struct compiling *c, - const node *n) -{ - asdl_seq *seq; - - FstringParser_check_invariants(state); - - /* If we're just a constant string with no expressions, return - that. */ - if (!state->fmode) { - assert(!state->expr_list.size); - if (!state->last_str) { - /* Create a zero length string. */ - state->last_str = PyUnicode_FromStringAndSize(NULL, 0); - if (!state->last_str) - goto error; - } - return make_str_node_and_del(&state->last_str, c, n); - } - - /* Create a Constant node out of last_str, if needed. It will be the - last node in our expression list. */ - if (state->last_str) { - expr_ty str = make_str_node_and_del(&state->last_str, c, n); - if (!str || ExprList_Append(&state->expr_list, str) < 0) - goto error; - } - /* This has already been freed. */ - assert(state->last_str == NULL); - - seq = ExprList_Finish(&state->expr_list, c->c_arena); - if (!seq) - goto error; - - return JoinedStr(seq, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - -error: - FstringParser_Dealloc(state); - return NULL; -} - -/* Given an f-string (with no 'f' or quotes) that's in *str and ends - at end, parse it into an expr_ty. Return NULL on error. Adjust - str to point past the parsed portion. */ -static expr_ty -fstring_parse(const char **str, const char *end, int raw, int recurse_lvl, - struct compiling *c, const node *n) -{ - FstringParser state; - - FstringParser_Init(&state); - if (FstringParser_ConcatFstring(&state, str, end, raw, recurse_lvl, - c, n) < 0) { - FstringParser_Dealloc(&state); - return NULL; - } - - return FstringParser_Finish(&state, c, n); -} - -/* n is a Python string literal, including the bracketing quote - characters, and r, b, u, &/or f prefixes (if any), and embedded - escape sequences (if any). parsestr parses it, and sets *result to - decoded Python string object. If the string is an f-string, set - *fstr and *fstrlen to the unparsed string object. Return 0 if no - errors occurred. -*/ -static int -parsestr(struct compiling *c, const node *n, int *bytesmode, int *rawmode, - PyObject **result, const char **fstr, Py_ssize_t *fstrlen) -{ - size_t len; - const char *s = STR(n); - int quote = Py_CHARMASK(*s); - int fmode = 0; - *bytesmode = 0; - *rawmode = 0; - *result = NULL; - *fstr = NULL; - if (Py_ISALPHA(quote)) { - while (!*bytesmode || !*rawmode) { - if (quote == 'b' || quote == 'B') { - quote = *++s; - *bytesmode = 1; - } - else if (quote == 'u' || quote == 'U') { - quote = *++s; - } - else if (quote == 'r' || quote == 'R') { - quote = *++s; - *rawmode = 1; - } - else if (quote == 'f' || quote == 'F') { - quote = *++s; - fmode = 1; - } - else { - break; - } - } - } - - /* fstrings are only allowed in Python 3.6 and greater */ - if (fmode && c->c_feature_version < 6) { - ast_error(c, n, "Format strings are only supported in Python 3.6 and greater"); - return -1; - } - - if (fmode && *bytesmode) { - PyErr_BadInternalCall(); - return -1; - } - if (quote != '\'' && quote != '\"') { - PyErr_BadInternalCall(); - return -1; - } - /* Skip the leading quote char. */ - s++; - len = strlen(s); - if (len > INT_MAX) { - PyErr_SetString(PyExc_OverflowError, - "string to parse is too long"); - return -1; - } - if (s[--len] != quote) { - /* Last quote char must match the first. */ - PyErr_BadInternalCall(); - return -1; - } - if (len >= 4 && s[0] == quote && s[1] == quote) { - /* A triple quoted string. We've already skipped one quote at - the start and one at the end of the string. Now skip the - two at the start. */ - s += 2; - len -= 2; - /* And check that the last two match. */ - if (s[--len] != quote || s[--len] != quote) { - PyErr_BadInternalCall(); - return -1; - } - } - - if (fmode) { - /* Just return the bytes. The caller will parse the resulting - string. */ - *fstr = s; - *fstrlen = len; - return 0; - } - - /* Not an f-string. */ - /* Avoid invoking escape decoding routines if possible. */ - *rawmode = *rawmode || strchr(s, '\\') == NULL; - if (*bytesmode) { - /* Disallow non-ASCII characters. */ - const char *ch; - for (ch = s; *ch; ch++) { - if (Py_CHARMASK(*ch) >= 0x80) { - ast_error(c, n, - "bytes can only contain ASCII " - "literal characters."); - return -1; - } - } - if (*rawmode) - *result = PyBytes_FromStringAndSize(s, len); - else - *result = decode_bytes_with_escapes(c, n, s, len); - } else { - if (*rawmode) - *result = PyUnicode_DecodeUTF8Stateful(s, len, NULL, NULL); - else - *result = decode_unicode_with_escapes(c, n, s, len); - } - return *result == NULL ? -1 : 0; -} - -/* Accepts a STRING+ atom, and produces an expr_ty node. Run through - each STRING atom, and process it as needed. For bytes, just - concatenate them together, and the result will be a Constant node. For - normal strings and f-strings, concatenate them together. The result - will be a Constant node if there were no f-strings; a FormattedValue - node if there's just an f-string (with no leading or trailing - literals), or a JoinedStr node if there are multiple f-strings or - any literals involved. */ -static expr_ty -parsestrplus(struct compiling *c, const node *n) -{ - int bytesmode = 0; - PyObject *bytes_str = NULL; - int i; - - FstringParser state; - FstringParser_Init(&state); - - for (i = 0; i < NCH(n); i++) { - int this_bytesmode; - int this_rawmode; - PyObject *s; - const char *fstr; - Py_ssize_t fstrlen = -1; /* Silence a compiler warning. */ - - REQ(CHILD(n, i), STRING); - if (parsestr(c, CHILD(n, i), &this_bytesmode, &this_rawmode, &s, - &fstr, &fstrlen) != 0) - goto error; - - /* Check that we're not mixing bytes with unicode. */ - if (i != 0 && bytesmode != this_bytesmode) { - ast_error(c, n, "cannot mix bytes and nonbytes literals"); - /* s is NULL if the current string part is an f-string. */ - Py_XDECREF(s); - goto error; - } - bytesmode = this_bytesmode; - - if (fstr != NULL) { - int result; - assert(s == NULL && !bytesmode); - /* This is an f-string. Parse and concatenate it. */ - result = FstringParser_ConcatFstring(&state, &fstr, fstr+fstrlen, - this_rawmode, 0, c, n); - if (result < 0) - goto error; - } else { - /* A string or byte string. */ - assert(s != NULL && fstr == NULL); - - assert(bytesmode ? PyBytes_CheckExact(s) : - PyUnicode_CheckExact(s)); - - if (bytesmode) { - /* For bytes, concat as we go. */ - if (i == 0) { - /* First time, just remember this value. */ - bytes_str = s; - } else { - PyBytes_ConcatAndDel(&bytes_str, s); - if (!bytes_str) - goto error; - } - } else { - /* This is a regular string. Concatenate it. */ - if (FstringParser_ConcatAndDel(&state, s) < 0) - goto error; - } - } - } - if (bytesmode) { - /* Just return the bytes object and we're done. */ - if (PyArena_AddPyObject(c->c_arena, bytes_str) < 0) - goto error; - return Constant(bytes_str, NULL, LINENO(n), n->n_col_offset, - n->n_end_lineno, n->n_end_col_offset, c->c_arena); - } - - /* We're not a bytes string, bytes_str should never have been set. */ - assert(bytes_str == NULL); - - return FstringParser_Finish(&state, c, n); - -error: - Py_XDECREF(bytes_str); - FstringParser_Dealloc(&state); - return NULL; -} - PyObject * _PyAST_GetDocString(asdl_seq *body) { diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 199b09c4d8c..89b7fce8f4a 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -4,10 +4,10 @@ #include #include "ast.h" #undef Yield /* undefine macro conflicting with */ -#include "pycore_object.h" -#include "pycore_pyerrors.h" -#include "pycore_pystate.h" // _PyThreadState_GET() -#include "pycore_tupleobject.h" +#include "pycore_object.h" // _Py_AddToAllObjects() +#include "pycore_pyerrors.h" // _PyErr_NoMemory() +#include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_tuple.h" // _PyTuple_FromArray() _Py_IDENTIFIER(__builtins__); _Py_IDENTIFIER(__dict__); @@ -2494,17 +2494,17 @@ issubclass as builtin_issubclass class_or_tuple: object / -Return whether 'cls' is a derived from another class or is the same class. +Return whether 'cls' is derived from another class or is the same class. A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B) -or ...`` etc. +or ...``. [clinic start generated code]*/ static PyObject * builtin_issubclass_impl(PyObject *module, PyObject *cls, PyObject *class_or_tuple) -/*[clinic end generated code: output=358412410cd7a250 input=af5f35e9ceaddaf6]*/ +/*[clinic end generated code: output=358412410cd7a250 input=a24b9f3d58c370d6]*/ { int retval; @@ -2517,9 +2517,10 @@ builtin_issubclass_impl(PyObject *module, PyObject *cls, typedef struct { PyObject_HEAD - Py_ssize_t tuplesize; - PyObject *ittuple; /* tuple of iterators */ + Py_ssize_t tuplesize; + PyObject *ittuple; /* tuple of iterators */ PyObject *result; + int strict; } zipobject; static PyObject * @@ -2530,9 +2531,21 @@ zip_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyObject *ittuple; /* tuple of iterators */ PyObject *result; Py_ssize_t tuplesize; + int strict = 0; - if (type == &PyZip_Type && !_PyArg_NoKeywords("zip", kwds)) - return NULL; + if (kwds) { + PyObject *empty = PyTuple_New(0); + if (empty == NULL) { + return NULL; + } + static char *kwlist[] = {"strict", NULL}; + int parsed = PyArg_ParseTupleAndKeywords( + empty, kwds, "|$p:zip", kwlist, &strict); + Py_DECREF(empty); + if (!parsed) { + return NULL; + } + } /* args must be a tuple */ assert(PyTuple_Check(args)); @@ -2573,6 +2586,7 @@ zip_new(PyTypeObject *type, PyObject *args, PyObject *kwds) lz->ittuple = ittuple; lz->tuplesize = tuplesize; lz->result = result; + lz->strict = strict; return (PyObject *)lz; } @@ -2613,6 +2627,9 @@ zip_next(zipobject *lz) item = (*Py_TYPE(it)->tp_iternext)(it); if (item == NULL) { Py_DECREF(result); + if (lz->strict) { + goto check; + } return NULL; } olditem = PyTuple_GET_ITEM(result, i); @@ -2628,28 +2645,85 @@ zip_next(zipobject *lz) item = (*Py_TYPE(it)->tp_iternext)(it); if (item == NULL) { Py_DECREF(result); + if (lz->strict) { + goto check; + } return NULL; } PyTuple_SET_ITEM(result, i, item); } } return result; +check: + if (PyErr_Occurred()) { + if (!PyErr_ExceptionMatches(PyExc_StopIteration)) { + // next() on argument i raised an exception (not StopIteration) + return NULL; + } + PyErr_Clear(); + } + if (i) { + // ValueError: zip() argument 2 is shorter than argument 1 + // ValueError: zip() argument 3 is shorter than arguments 1-2 + const char* plural = i == 1 ? " " : "s 1-"; + return PyErr_Format(PyExc_ValueError, + "zip() argument %d is shorter than argument%s%d", + i + 1, plural, i); + } + for (i = 1; i < tuplesize; i++) { + it = PyTuple_GET_ITEM(lz->ittuple, i); + item = (*Py_TYPE(it)->tp_iternext)(it); + if (item) { + Py_DECREF(item); + const char* plural = i == 1 ? " " : "s 1-"; + return PyErr_Format(PyExc_ValueError, + "zip() argument %d is longer than argument%s%d", + i + 1, plural, i); + } + if (PyErr_Occurred()) { + if (!PyErr_ExceptionMatches(PyExc_StopIteration)) { + // next() on argument i raised an exception (not StopIteration) + return NULL; + } + PyErr_Clear(); + } + // Argument i is exhausted. So far so good... + } + // All arguments are exhausted. Success! + return NULL; } static PyObject * zip_reduce(zipobject *lz, PyObject *Py_UNUSED(ignored)) { /* Just recreate the zip with the internal iterator tuple */ - return Py_BuildValue("OO", Py_TYPE(lz), lz->ittuple); + if (lz->strict) { + return PyTuple_Pack(3, Py_TYPE(lz), lz->ittuple, Py_True); + } + return PyTuple_Pack(2, Py_TYPE(lz), lz->ittuple); +} + +PyDoc_STRVAR(setstate_doc, "Set state information for unpickling."); + +static PyObject * +zip_setstate(zipobject *lz, PyObject *state) +{ + int strict = PyObject_IsTrue(state); + if (strict < 0) { + return NULL; + } + lz->strict = strict; + Py_RETURN_NONE; } static PyMethodDef zip_methods[] = { {"__reduce__", (PyCFunction)zip_reduce, METH_NOARGS, reduce_doc}, - {NULL, NULL} /* sentinel */ + {"__setstate__", (PyCFunction)zip_setstate, METH_O, setstate_doc}, + {NULL} /* sentinel */ }; PyDoc_STRVAR(zip_doc, -"zip(*iterables) --> A zip object yielding tuples until an input is exhausted.\n\ +"zip(*iterables, strict=False) --> Yield tuples until an input is exhausted.\n\ \n\ >>> list(zip('abcdefg', range(3), range(4)))\n\ [('a', 0, 0), ('b', 1, 1), ('c', 2, 2)]\n\ @@ -2657,7 +2731,10 @@ PyDoc_STRVAR(zip_doc, The zip object yields n-length tuples, where n is the number of iterables\n\ passed as positional arguments to zip(). The i-th element in every tuple\n\ comes from the i-th iterable argument to zip(). This continues until the\n\ -shortest argument is exhausted."); +shortest argument is exhausted.\n\ +\n\ +If strict is true and one of the arguments is exhausted before the others,\n\ +raise a ValueError."); PyTypeObject PyZip_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) diff --git a/Python/bootstrap_hash.c b/Python/bootstrap_hash.c index b2109275014..47369305ee8 100644 --- a/Python/bootstrap_hash.c +++ b/Python/bootstrap_hash.c @@ -580,7 +580,7 @@ _Py_HashRandomization_Init(const PyConfig *config) res = pyurandom(secret, secret_size, 0, 0); if (res < 0) { return _PyStatus_ERR("failed to get random numbers " - "to initialize Python"); + "to initialize Python"); } } return _PyStatus_OK(); diff --git a/Python/ceval.c b/Python/ceval.c index a79773f8511..0386929a5b2 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -11,17 +11,17 @@ #include "Python.h" #include "pycore_abstract.h" // _PyIndex_Check() -#include "pycore_call.h" -#include "pycore_ceval.h" -#include "pycore_code.h" -#include "pycore_initconfig.h" -#include "pycore_object.h" -#include "pycore_pyerrors.h" -#include "pycore_pylifecycle.h" +#include "pycore_call.h" // _PyObject_FastCallDictTstate() +#include "pycore_ceval.h" // _PyEval_SignalAsyncExc() +#include "pycore_code.h" // _PyCode_InitOpcache() +#include "pycore_initconfig.h" // _PyStatus_OK() +#include "pycore_object.h" // _PyObject_GC_TRACK() +#include "pycore_pyerrors.h" // _PyErr_Fetch() +#include "pycore_pylifecycle.h" // _PyErr_Print() #include "pycore_pymem.h" // _PyMem_IsPtrFreed() #include "pycore_pystate.h" // _PyInterpreterState_GET() -#include "pycore_sysmodule.h" -#include "pycore_tupleobject.h" +#include "pycore_sysmodule.h" // _PySys_Audit() +#include "pycore_tuple.h" // _PyTuple_ITEMS() #include "code.h" #include "dictobject.h" @@ -240,16 +240,15 @@ UNSIGNAL_ASYNC_EXC(PyInterpreterState *interp) #endif #include "ceval_gil.h" -static void -ensure_tstate_not_null(const char *func, PyThreadState *tstate) +void _Py_NO_RETURN +_Py_FatalError_TstateNULL(const char *func) { - if (tstate == NULL) { - _Py_FatalErrorFunc(func, - "current thread state is NULL (released GIL?)"); - } + _Py_FatalErrorFunc(func, + "the function must be called with the GIL held, " + "but the GIL is released " + "(the current Python thread state is NULL)"); } - #ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS int _PyEval_ThreadsInitialized(PyInterpreterState *interp) @@ -374,7 +373,7 @@ PyEval_AcquireLock(void) { _PyRuntimeState *runtime = &_PyRuntime; PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime); - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); take_gil(tstate); } @@ -403,7 +402,7 @@ _PyEval_ReleaseLock(PyThreadState *tstate) void PyEval_AcquireThread(PyThreadState *tstate) { - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); take_gil(tstate); @@ -434,15 +433,12 @@ PyEval_ReleaseThread(PyThreadState *tstate) #ifdef HAVE_FORK /* This function is called from PyOS_AfterFork_Child to destroy all threads - * which are not running in the child process, and clear internal locks - * which might be held by those threads. - */ - -void -_PyEval_ReInitThreads(_PyRuntimeState *runtime) + which are not running in the child process, and clear internal locks + which might be held by those threads. */ +PyStatus +_PyEval_ReInitThreads(PyThreadState *tstate) { - PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime); - ensure_tstate_not_null(__func__, tstate); + _PyRuntimeState *runtime = tstate->interp->runtime; #ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS struct _gil_runtime_state *gil = &tstate->interp->ceval.gil; @@ -450,7 +446,7 @@ _PyEval_ReInitThreads(_PyRuntimeState *runtime) struct _gil_runtime_state *gil = &runtime->ceval.gil; #endif if (!gil_created(gil)) { - return; + return _PyStatus_OK(); } recreate_gil(gil); @@ -458,11 +454,12 @@ _PyEval_ReInitThreads(_PyRuntimeState *runtime) struct _pending_calls *pending = &tstate->interp->ceval.pending; if (_PyThread_at_fork_reinit(&pending->lock) < 0) { - Py_FatalError("Can't initialize threads for pending calls"); + return _PyStatus_ERR("Can't reinitialize pending calls lock"); } /* Destroy all threads except the current one */ _PyThreadState_DeleteExcept(runtime, tstate); + return _PyStatus_OK(); } #endif @@ -486,7 +483,7 @@ PyEval_SaveThread(void) #else PyThreadState *tstate = _PyThreadState_Swap(&runtime->gilstate, NULL); #endif - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); struct _ceval_runtime_state *ceval = &runtime->ceval; struct _ceval_state *ceval2 = &tstate->interp->ceval; @@ -502,7 +499,7 @@ PyEval_SaveThread(void) void PyEval_RestoreThread(PyThreadState *tstate) { - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); take_gil(tstate); @@ -791,8 +788,8 @@ _PyEval_FiniState(struct _ceval_state *ceval) int Py_GetRecursionLimit(void) { - PyThreadState *tstate = _PyThreadState_GET(); - return tstate->interp->ceval.recursion_limit; + PyInterpreterState *interp = _PyInterpreterState_GET(); + return interp->ceval.recursion_limit; } void @@ -944,7 +941,7 @@ eval_frame_handle_pending(PyThreadState *tstate) PyObject* _Py_HOT_FUNCTION _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag) { - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); #ifdef DXPAIRS int lastopcode = 0; @@ -1160,7 +1157,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag) #define SET_SECOND(v) (stack_pointer[-2] = (v)) #define SET_THIRD(v) (stack_pointer[-3] = (v)) #define SET_FOURTH(v) (stack_pointer[-4] = (v)) -#define SET_VALUE(n, v) (stack_pointer[-(n)] = (v)) #define BASIC_STACKADJ(n) (stack_pointer += n) #define BASIC_PUSH(v) (*stack_pointer++ = (v)) #define BASIC_POP() (*--stack_pointer) @@ -4110,14 +4106,22 @@ _PyEval_EvalCode(PyThreadState *tstate, { assert(is_tstate_valid(tstate)); - PyCodeObject* co = (PyCodeObject*)_co; - PyFrameObject *f; + PyCodeObject *co = (PyCodeObject*)_co; + + if (!name) { + name = co->co_name; + } + assert(name != NULL); + assert(PyUnicode_Check(name)); + + if (!qualname) { + qualname = name; + } + assert(qualname != NULL); + assert(PyUnicode_Check(qualname)); + PyObject *retval = NULL; - PyObject **fastlocals, **freevars; - PyObject *x, *u; const Py_ssize_t total_args = co->co_argcount + co->co_kwonlyargcount; - Py_ssize_t i, j, n; - PyObject *kwdict; if (globals == NULL) { _PyErr_SetString(tstate, PyExc_SystemError, @@ -4126,14 +4130,16 @@ _PyEval_EvalCode(PyThreadState *tstate, } /* Create the frame */ - f = _PyFrame_New_NoTrack(tstate, co, globals, locals); + PyFrameObject *f = _PyFrame_New_NoTrack(tstate, co, globals, locals); if (f == NULL) { return NULL; } - fastlocals = f->f_localsplus; - freevars = f->f_localsplus + co->co_nlocals; + PyObject **fastlocals = f->f_localsplus; + PyObject **freevars = f->f_localsplus + co->co_nlocals; /* Create a dictionary for keyword parameters (**kwags) */ + PyObject *kwdict; + Py_ssize_t i; if (co->co_flags & CO_VARKEYWORDS) { kwdict = PyDict_New(); if (kwdict == NULL) @@ -4149,6 +4155,7 @@ _PyEval_EvalCode(PyThreadState *tstate, } /* Copy all positional arguments into local variables */ + Py_ssize_t j, n; if (argcount > co->co_argcount) { n = co->co_argcount; } @@ -4156,14 +4163,14 @@ _PyEval_EvalCode(PyThreadState *tstate, n = argcount; } for (j = 0; j < n; j++) { - x = args[j]; + PyObject *x = args[j]; Py_INCREF(x); SETLOCAL(j, x); } /* Pack other positional arguments into the *args argument */ if (co->co_flags & CO_VARARGS) { - u = _PyTuple_FromArray(args + n, argcount - n); + PyObject *u = _PyTuple_FromArray(args + n, argcount - n); if (u == NULL) { goto fail; } @@ -4189,16 +4196,16 @@ _PyEval_EvalCode(PyThreadState *tstate, normally interned this should almost always hit. */ co_varnames = ((PyTupleObject *)(co->co_varnames))->ob_item; for (j = co->co_posonlyargcount; j < total_args; j++) { - PyObject *name = co_varnames[j]; - if (name == keyword) { + PyObject *varname = co_varnames[j]; + if (varname == keyword) { goto kw_found; } } /* Slow fallback, just in case */ for (j = co->co_posonlyargcount; j < total_args; j++) { - PyObject *name = co_varnames[j]; - int cmp = PyObject_RichCompareBool( keyword, name, Py_EQ); + PyObject *varname = co_varnames[j]; + int cmp = PyObject_RichCompareBool( keyword, varname, Py_EQ); if (cmp > 0) { goto kw_found; } @@ -4212,7 +4219,8 @@ _PyEval_EvalCode(PyThreadState *tstate, if (co->co_posonlyargcount && positional_only_passed_as_keyword(tstate, co, - kwcount, kwnames, qualname)) + kwcount, kwnames, + qualname)) { goto fail; } @@ -4241,7 +4249,8 @@ _PyEval_EvalCode(PyThreadState *tstate, /* Check the number of positional arguments */ if ((argcount > co->co_argcount) && !(co->co_flags & CO_VARARGS)) { - too_many_positional(tstate, co, argcount, defcount, fastlocals, qualname); + too_many_positional(tstate, co, argcount, defcount, fastlocals, + qualname); goto fail; } @@ -4255,7 +4264,8 @@ _PyEval_EvalCode(PyThreadState *tstate, } } if (missing) { - missing_arguments(tstate, co, missing, defcount, fastlocals, qualname); + missing_arguments(tstate, co, missing, defcount, fastlocals, + qualname); goto fail; } if (n > m) @@ -4275,12 +4285,11 @@ _PyEval_EvalCode(PyThreadState *tstate, if (co->co_kwonlyargcount > 0) { Py_ssize_t missing = 0; for (i = co->co_argcount; i < total_args; i++) { - PyObject *name; if (GETLOCAL(i) != NULL) continue; - name = PyTuple_GET_ITEM(co->co_varnames, i); + PyObject *varname = PyTuple_GET_ITEM(co->co_varnames, i); if (kwdefs != NULL) { - PyObject *def = PyDict_GetItemWithError(kwdefs, name); + PyObject *def = PyDict_GetItemWithError(kwdefs, varname); if (def) { Py_INCREF(def); SETLOCAL(i, def); @@ -4293,7 +4302,8 @@ _PyEval_EvalCode(PyThreadState *tstate, missing++; } if (missing) { - missing_arguments(tstate, co, missing, -1, fastlocals, qualname); + missing_arguments(tstate, co, missing, -1, fastlocals, + qualname); goto fail; } } diff --git a/Python/clinic/_warnings.c.h b/Python/clinic/_warnings.c.h index 80ed2ae8ab1..ad6b9a8e242 100644 --- a/Python/clinic/_warnings.c.h +++ b/Python/clinic/_warnings.c.h @@ -45,7 +45,7 @@ warnings_warn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec if (args[2]) { { Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index(args[2]); + PyObject *iobj = _PyNumber_Index(args[2]); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -66,4 +66,4 @@ skip_optional_pos: exit: return return_value; } -/*[clinic end generated code: output=484e5ffe94edf0f0 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=eb9997fa998fdbad input=a9049054013a1b77]*/ diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h index 377afded9f8..bc3b5187928 100644 --- a/Python/clinic/bltinmodule.c.h +++ b/Python/clinic/bltinmodule.c.h @@ -800,11 +800,11 @@ PyDoc_STRVAR(builtin_issubclass__doc__, "issubclass($module, cls, class_or_tuple, /)\n" "--\n" "\n" -"Return whether \'cls\' is a derived from another class or is the same class.\n" +"Return whether \'cls\' is derived from another class or is the same class.\n" "\n" "A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n" "check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n" -"or ...`` etc."); +"or ...``."); #define BUILTIN_ISSUBCLASS_METHODDEF \ {"issubclass", (PyCFunction)(void(*)(void))builtin_issubclass, METH_FASTCALL, builtin_issubclass__doc__}, @@ -830,4 +830,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=780fd9712ec6a6db input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e2fcf0201790367c input=a9049054013a1b77]*/ diff --git a/Python/compile.c b/Python/compile.c index 4a587c00fd4..4a9b511961e 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -67,8 +67,6 @@ typedef struct basicblock_ { /* If b_next is non-NULL, it is a pointer to the next block reached by normal control flow. */ struct basicblock_ *b_next; - /* b_seen is used to perform a DFS of basicblocks. */ - unsigned b_seen : 1; /* b_return is true if a RETURN_VALUE opcode is inserted. */ unsigned b_return : 1; /* depth of stack upon entry of block, computed by stackdepth() */ @@ -390,21 +388,6 @@ PyAST_CompileEx(mod_ty mod, const char *filename_str, PyCompilerFlags *flags, } -PyCodeObject * -PyNode_Compile(struct _node *n, const char *filename) -{ - PyCodeObject *co = NULL; - mod_ty mod; - PyArena *arena = PyArena_New(); - if (!arena) - return NULL; - mod = PyAST_FromNode(n, NULL, filename, arena); - if (mod) - co = PyAST_Compile(mod, filename, NULL, arena); - PyArena_Free(arena); - return co; -} - static void compiler_free(struct compiler *c) { @@ -4321,6 +4304,9 @@ ex_call: if (!compiler_subkwargs(c, keywords, i - nseen, i)) { return 0; } + if (have_dict) { + ADDOP_I(c, DICT_MERGE, 1); + } have_dict = 1; nseen = 0; } @@ -5425,7 +5411,7 @@ struct assembler { PyObject *a_bytecode; /* string containing bytecode */ int a_offset; /* offset into bytecode */ int a_nblocks; /* number of reachable blocks */ - basicblock **a_postorder; /* list of blocks in dfs postorder */ + basicblock **a_reverse_postorder; /* list of blocks in dfs postorder */ PyObject *a_lnotab; /* string containing lnotab */ int a_lnotab_off; /* offset into lnotab */ int a_lineno; /* last lineno of emitted instruction */ @@ -5435,26 +5421,14 @@ struct assembler { static void dfs(struct compiler *c, basicblock *b, struct assembler *a, int end) { - int i, j; - /* Get rid of recursion for normal control flow. - Since the number of blocks is limited, unused space in a_postorder - (from a_nblocks to end) can be used as a stack for still not ordered - blocks. */ - for (j = end; b && !b->b_seen; b = b->b_next) { - b->b_seen = 1; - assert(a->a_nblocks < j); - a->a_postorder[--j] = b; - } - while (j < end) { - b = a->a_postorder[j++]; - for (i = 0; i < b->b_iused; i++) { - struct instr *instr = &b->b_instr[i]; - if (instr->i_jrel || instr->i_jabs) - dfs(c, instr->i_target, a, j); - } - assert(a->a_nblocks < j); - a->a_postorder[a->a_nblocks++] = b; + /* There is no real depth-first-search to do here because all the + * blocks are emitted in topological order already, so we just need to + * follow the b_next pointers and place them in a->a_reverse_postorder in + * reverse order and make sure that the first one starts at 0. */ + + for (a->a_nblocks = 0; b != NULL; b = b->b_next) { + a->a_reverse_postorder[a->a_nblocks++] = b; } } @@ -5555,9 +5529,9 @@ assemble_init(struct assembler *a, int nblocks, int firstlineno) PyErr_NoMemory(); return 0; } - a->a_postorder = (basicblock **)PyObject_Malloc( + a->a_reverse_postorder = (basicblock **)PyObject_Malloc( sizeof(basicblock *) * nblocks); - if (!a->a_postorder) { + if (!a->a_reverse_postorder) { PyErr_NoMemory(); return 0; } @@ -5569,8 +5543,8 @@ assemble_free(struct assembler *a) { Py_XDECREF(a->a_bytecode); Py_XDECREF(a->a_lnotab); - if (a->a_postorder) - PyObject_Free(a->a_postorder); + if (a->a_reverse_postorder) + PyObject_Free(a->a_reverse_postorder); } static int @@ -5731,8 +5705,8 @@ assemble_jump_offsets(struct assembler *a, struct compiler *c) Replace block pointer with position in bytecode. */ do { totsize = 0; - for (i = a->a_nblocks - 1; i >= 0; i--) { - b = a->a_postorder[i]; + for (i = 0; i < a->a_nblocks; i++) { + b = a->a_reverse_postorder[i]; bsize = blocksize(b); b->b_offset = totsize; totsize += bsize; @@ -5987,10 +5961,9 @@ dump_instr(const struct instr *i) static void dump_basicblock(const basicblock *b) { - const char *seen = b->b_seen ? "seen " : ""; const char *b_return = b->b_return ? "return " : ""; - fprintf(stderr, "used: %d, depth: %d, offset: %d %s%s\n", - b->b_iused, b->b_startdepth, b->b_offset, seen, b_return); + fprintf(stderr, "used: %d, depth: %d, offset: %d %s\n", + b->b_iused, b->b_startdepth, b->b_offset, b_return); if (b->b_instr) { int i; for (i = 0; i < b->b_iused; i++) { @@ -6042,8 +6015,8 @@ assemble(struct compiler *c, int addNone) assemble_jump_offsets(&a, c); /* Emit code in reverse postorder from dfs. */ - for (i = a.a_nblocks - 1; i >= 0; i--) { - b = a.a_postorder[i]; + for (i = 0; i < a.a_nblocks; i++) { + b = a.a_reverse_postorder[i]; for (j = 0; j < b->b_iused; j++) if (!assemble_emit(&a, &b->b_instr[j])) goto error; diff --git a/Python/context.c b/Python/context.c index bacc7010c45..15d8b8ea4b9 100644 --- a/Python/context.c +++ b/Python/context.c @@ -10,8 +10,6 @@ #define CONTEXT_FREELIST_MAXLEN 255 -static PyContext *ctx_freelist = NULL; -static int ctx_freelist_len = 0; #include "clinic/context.c.h" @@ -68,6 +66,14 @@ static int contextvar_del(PyContextVar *var); +static struct _Py_context_state * +get_context_state(void) +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + return &interp->context; +} + + PyObject * _PyContext_NewHamtForTests(void) { @@ -334,11 +340,16 @@ class _contextvars.Context "PyContext *" "&PyContext_Type" static inline PyContext * _context_alloc(void) { + struct _Py_context_state *state = get_context_state(); PyContext *ctx; - if (ctx_freelist_len) { - ctx_freelist_len--; - ctx = ctx_freelist; - ctx_freelist = (PyContext *)ctx->ctx_weakreflist; +#ifdef Py_DEBUG + // _context_alloc() must not be called after _PyContext_Fini() + assert(state->numfree != -1); +#endif + if (state->numfree) { + state->numfree--; + ctx = state->freelist; + state->freelist = (PyContext *)ctx->ctx_weakreflist; ctx->ctx_weakreflist = NULL; _Py_NewReference((PyObject *)ctx); } @@ -458,10 +469,15 @@ context_tp_dealloc(PyContext *self) } (void)context_tp_clear(self); - if (ctx_freelist_len < CONTEXT_FREELIST_MAXLEN) { - ctx_freelist_len++; - self->ctx_weakreflist = (PyObject *)ctx_freelist; - ctx_freelist = self; + struct _Py_context_state *state = get_context_state(); +#ifdef Py_DEBUG + // _context_alloc() must not be called after _PyContext_Fini() + assert(state->numfree != -1); +#endif + if (state->numfree < CONTEXT_FREELIST_MAXLEN) { + state->numfree++; + self->ctx_weakreflist = (PyObject *)state->freelist; + state->freelist = self; } else { Py_TYPE(self)->tp_free(self); @@ -1271,11 +1287,12 @@ get_token_missing(void) void -_PyContext_ClearFreeList(void) +_PyContext_ClearFreeList(PyThreadState *tstate) { - for (; ctx_freelist_len; ctx_freelist_len--) { - PyContext *ctx = ctx_freelist; - ctx_freelist = (PyContext *)ctx->ctx_weakreflist; + struct _Py_context_state *state = &tstate->interp->context; + for (; state->numfree; state->numfree--) { + PyContext *ctx = state->freelist; + state->freelist = (PyContext *)ctx->ctx_weakreflist; ctx->ctx_weakreflist = NULL; PyObject_GC_Del(ctx); } @@ -1283,10 +1300,16 @@ _PyContext_ClearFreeList(void) void -_PyContext_Fini(void) +_PyContext_Fini(PyThreadState *tstate) { - Py_CLEAR(_token_missing); - _PyContext_ClearFreeList(); + if (_Py_IsMainInterpreter(tstate)) { + Py_CLEAR(_token_missing); + } + _PyContext_ClearFreeList(tstate); +#ifdef Py_DEBUG + struct _Py_context_state *state = &tstate->interp->context; + state->numfree = -1; +#endif _PyHamt_Fini(); } diff --git a/Python/dtoa.c b/Python/dtoa.c index 822adc61296..e629b296426 100644 --- a/Python/dtoa.c +++ b/Python/dtoa.c @@ -64,6 +64,9 @@ * 7. _Py_dg_strtod has been modified so that it doesn't accept strings with * leading whitespace. * + * 8. A corner case where _Py_dg_dtoa didn't strip trailing zeros has been + * fixed. (bugs.python.org/issue40780) + * ***************************************************************/ /* Please send bug reports for the original dtoa.c code to David M. Gay (dmg @@ -2563,6 +2566,14 @@ _Py_dg_dtoa(double dd, int mode, int ndigits, } ++*s++; } + else { + /* Strip trailing zeros. This branch was missing from the + original dtoa.c, leading to surplus trailing zeros in + some cases. See bugs.python.org/issue40780. */ + while (s > s0 && s[-1] == '0') { + --s; + } + } break; } } diff --git a/Python/dynload_win.c b/Python/dynload_win.c index 2bf3384b9eb..8431c5b3b2f 100644 --- a/Python/dynload_win.c +++ b/Python/dynload_win.c @@ -168,9 +168,7 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, char funcname[258], *import_python; const wchar_t *wpathname; -#ifndef _DEBUG _Py_CheckPython3(); -#endif wpathname = _PyUnicode_AsUnicode(pathname); if (wpathname == NULL) diff --git a/Python/errors.c b/Python/errors.c index 70365aaca58..720f18bc224 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -1079,7 +1079,6 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict) { PyThreadState *tstate = _PyThreadState_GET(); PyObject *modulename = NULL; - PyObject *classname = NULL; PyObject *mydict = NULL; PyObject *bases = NULL; PyObject *result = NULL; @@ -1125,7 +1124,6 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict) failure: Py_XDECREF(bases); Py_XDECREF(mydict); - Py_XDECREF(classname); Py_XDECREF(modulename); return result; } @@ -1426,7 +1424,7 @@ void _PyErr_WriteUnraisableMsg(const char *err_msg_str, PyObject *obj) { PyThreadState *tstate = _PyThreadState_GET(); - assert(tstate != NULL); + _Py_EnsureTstateNotNULL(tstate); PyObject *err_msg = NULL; PyObject *exc_type, *exc_value, *exc_tb; @@ -1648,16 +1646,18 @@ err_programtext(PyThreadState *tstate, FILE *fp, int lineno) { int i; char linebuf[1000]; - - if (fp == NULL) + if (fp == NULL) { return NULL; + } + for (i = 0; i < lineno; i++) { char *pLastChar = &linebuf[sizeof(linebuf) - 2]; do { *pLastChar = '\0'; if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, - fp, NULL) == NULL) - break; + fp, NULL) == NULL) { + goto after_loop; + } /* fgets read *something*; if it didn't get as far as pLastChar, it must have found a newline or hit the end of the file; if pLastChar is \n, @@ -1665,6 +1665,8 @@ err_programtext(PyThreadState *tstate, FILE *fp, int lineno) yet seen a newline, so must continue */ } while (*pLastChar != '\0' && *pLastChar != '\n'); } + +after_loop: fclose(fp); if (i == lineno) { PyObject *res; diff --git a/Python/fileutils.c b/Python/fileutils.c index 439bc351596..2c86828ba98 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -1274,7 +1274,12 @@ _Py_open_impl(const char *pathname, int flags, int gil_held) #endif if (gil_held) { - if (PySys_Audit("open", "sOi", pathname, Py_None, flags) < 0) { + PyObject *pathname_obj = PyUnicode_DecodeFSDefault(pathname); + if (pathname_obj == NULL) { + return -1; + } + if (PySys_Audit("open", "OOi", pathname_obj, Py_None, flags) < 0) { + Py_DECREF(pathname_obj); return -1; } @@ -1284,12 +1289,16 @@ _Py_open_impl(const char *pathname, int flags, int gil_held) Py_END_ALLOW_THREADS } while (fd < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); - if (async_err) - return -1; - if (fd < 0) { - PyErr_SetFromErrnoWithFilename(PyExc_OSError, pathname); + if (async_err) { + Py_DECREF(pathname_obj); return -1; } + if (fd < 0) { + PyErr_SetFromErrnoWithFilenameObjects(PyExc_OSError, pathname_obj, NULL); + Py_DECREF(pathname_obj); + return -1; + } + Py_DECREF(pathname_obj); } else { fd = open(pathname, flags); @@ -1385,9 +1394,15 @@ _Py_wfopen(const wchar_t *path, const wchar_t *mode) FILE* _Py_fopen(const char *pathname, const char *mode) { - if (PySys_Audit("open", "ssi", pathname, mode, 0) < 0) { + PyObject *pathname_obj = PyUnicode_DecodeFSDefault(pathname); + if (pathname_obj == NULL) { return NULL; } + if (PySys_Audit("open", "Osi", pathname_obj, mode, 0) < 0) { + Py_DECREF(pathname_obj); + return NULL; + } + Py_DECREF(pathname_obj); FILE *f = fopen(pathname, mode); if (f == NULL) @@ -1461,6 +1476,7 @@ _Py_fopen_obj(PyObject *path, const char *mode) path_bytes = PyBytes_AS_STRING(bytes); if (PySys_Audit("open", "Osi", path, mode, 0) < 0) { + Py_DECREF(bytes); return NULL; } diff --git a/Python/future.c b/Python/future.c index 1663a38a6fd..56da4d8c798 100644 --- a/Python/future.c +++ b/Python/future.c @@ -1,8 +1,6 @@ #include "Python.h" #include "Python-ast.h" -#include "node.h" #include "token.h" -#include "graminit.h" #include "code.h" #include "symtable.h" #include "ast.h" diff --git a/Python/getargs.c b/Python/getargs.c index 63afae25494..c85ff6d4777 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -2,7 +2,7 @@ /* New getargs implementation */ #include "Python.h" -#include "pycore_tupleobject.h" +#include "pycore_tuple.h" // _PyTuple_ITEMS() #include #include @@ -452,7 +452,7 @@ seterror(Py_ssize_t iarg, const char *msg, int *levels, const char *fname, } if (iarg != 0) { PyOS_snprintf(p, sizeof(buf) - (p - buf), - "argument %" PY_FORMAT_SIZE_T "d", iarg); + "argument %zd", iarg); i = 0; p += strlen(p); while (i < 32 && levels[i] > 0 && (int)(p-buf) < 220) { @@ -540,15 +540,14 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags, levels[0] = 0; if (toplevel) { PyOS_snprintf(msgbuf, bufsize, - "expected %d argument%s, not %" PY_FORMAT_SIZE_T "d", + "expected %d argument%s, not %zd", n, n == 1 ? "" : "s", len); } else { PyOS_snprintf(msgbuf, bufsize, - "must be sequence of length %d, " - "not %" PY_FORMAT_SIZE_T "d", + "must be sequence of length %d, not %zd", n, len); } return msgbuf; @@ -657,27 +656,12 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, char *msgbuf, size_t bufsize, freelist_t *freelist) { /* For # codes */ -#define FETCH_SIZE int *q=NULL;Py_ssize_t *q2=NULL;\ - if (flags & FLAG_SIZE_T) q2=va_arg(*p_va, Py_ssize_t*); \ - else { \ - if (PyErr_WarnEx(PyExc_DeprecationWarning, \ - "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) { \ - return NULL; \ - } \ - q=va_arg(*p_va, int*); \ +#define REQUIRE_PY_SSIZE_T_CLEAN \ + if (!(flags & FLAG_SIZE_T)) { \ + PyErr_SetString(PyExc_SystemError, \ + "PY_SSIZE_T_CLEAN macro must be defined for '#' formats"); \ + return NULL; \ } -#define STORE_SIZE(s) \ - if (flags & FLAG_SIZE_T) \ - *q2=s; \ - else { \ - if (INT_MAX < s) { \ - PyErr_SetString(PyExc_OverflowError, \ - "size does not fit in an int"); \ - return converterr("", arg, msgbuf, bufsize); \ - } \ - *q = (int)s; \ - } -#define BUFFER_LEN ((flags & FLAG_SIZE_T) ? *q2:*q) #define RETURN_ERR_OCCURRED return msgbuf const char *format = *p_format; @@ -784,7 +768,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, PyObject *iobj; Py_ssize_t *p = va_arg(*p_va, Py_ssize_t *); Py_ssize_t ival = -1; - iobj = PyNumber_Index(arg); + iobj = _PyNumber_Index(arg); if (iobj != NULL) { ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -932,8 +916,9 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, if (count < 0) return converterr(buf, arg, msgbuf, bufsize); if (*format == '#') { - FETCH_SIZE; - STORE_SIZE(count); + REQUIRE_PY_SSIZE_T_CLEAN; + Py_ssize_t *psize = va_arg(*p_va, Py_ssize_t*); + *psize = count; format++; } else { if (strlen(*p) != (size_t)count) { @@ -975,11 +960,12 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, } else if (*format == '#') { /* a string or read-only bytes-like object */ /* "s#" or "z#" */ const void **p = (const void **)va_arg(*p_va, const char **); - FETCH_SIZE; + REQUIRE_PY_SSIZE_T_CLEAN; + Py_ssize_t *psize = va_arg(*p_va, Py_ssize_t*); if (c == 'z' && arg == Py_None) { *p = NULL; - STORE_SIZE(0); + *psize = 0; } else if (PyUnicode_Check(arg)) { Py_ssize_t len; @@ -988,7 +974,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, return converterr(CONV_UNICODE, arg, msgbuf, bufsize); *p = sarg; - STORE_SIZE(len); + *psize = len; } else { /* read-only bytes-like object */ /* XXX Really? */ @@ -996,7 +982,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, Py_ssize_t count = convertbuffer(arg, p, &buf); if (count < 0) return converterr(buf, arg, msgbuf, bufsize); - STORE_SIZE(count); + *psize = count; } format++; } else { @@ -1028,22 +1014,26 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, case 'u': /* raw unicode buffer (Py_UNICODE *) */ case 'Z': /* raw unicode buffer or None */ { + // TODO: Raise DeprecationWarning +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **); if (*format == '#') { /* "u#" or "Z#" */ - FETCH_SIZE; + REQUIRE_PY_SSIZE_T_CLEAN; + Py_ssize_t *psize = va_arg(*p_va, Py_ssize_t*); if (c == 'Z' && arg == Py_None) { *p = NULL; - STORE_SIZE(0); + *psize = 0; } else if (PyUnicode_Check(arg)) { Py_ssize_t len; *p = PyUnicode_AsUnicodeAndSize(arg, &len); if (*p == NULL) RETURN_ERR_OCCURRED; - STORE_SIZE(len); + *psize = len; } else return converterr(c == 'Z' ? "str or None" : "str", @@ -1067,6 +1057,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, arg, msgbuf, bufsize); } break; +_Py_COMP_DIAG_POP } case 'e': {/* encoded string */ @@ -1157,22 +1148,11 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, trailing 0-byte */ - int *q = NULL; Py_ssize_t *q2 = NULL; - if (flags & FLAG_SIZE_T) { - q2 = va_arg(*p_va, Py_ssize_t*); - } - else { - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) - { - Py_DECREF(s); - return NULL; - } - q = va_arg(*p_va, int*); - } + REQUIRE_PY_SSIZE_T_CLEAN; + Py_ssize_t *psize = va_arg(*p_va, Py_ssize_t*); format++; - if (q == NULL && q2 == NULL) { + if (psize == NULL) { Py_DECREF(s); return converterr( "(buffer_len is NULL)", @@ -1192,30 +1172,20 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, arg, msgbuf, bufsize); } } else { - if (size + 1 > BUFFER_LEN) { + if (size + 1 > *psize) { Py_DECREF(s); PyErr_Format(PyExc_ValueError, "encoded string too long " "(%zd, maximum length %zd)", - (Py_ssize_t)size, (Py_ssize_t)(BUFFER_LEN-1)); + (Py_ssize_t)size, (Py_ssize_t)(*psize - 1)); RETURN_ERR_OCCURRED; } } memcpy(*buffer, ptr, size+1); - if (flags & FLAG_SIZE_T) { - *q2 = size; - } - else { - if (INT_MAX < size) { - Py_DECREF(s); - PyErr_SetString(PyExc_OverflowError, - "size does not fit in an int"); - return converterr("", arg, msgbuf, bufsize); - } - *q = (int)size; - } - } else { + *psize = size; + } + else { /* Using a 0-terminated buffer: - the encoded string has to be 0-terminated @@ -1353,9 +1323,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, *p_format = format; return NULL; -#undef FETCH_SIZE -#undef STORE_SIZE -#undef BUFFER_LEN +#undef REQUIRE_PY_SSIZE_T_CLEAN #undef RETURN_ERR_OCCURRED } diff --git a/Python/graminit.c b/Python/graminit.c deleted file mode 100644 index b7aa52895f8..00000000000 --- a/Python/graminit.c +++ /dev/null @@ -1,2688 +0,0 @@ -/* Generated by Parser/pgen */ - -#include "exports.h" -#include "grammar.h" -Py_EXPORTED_SYMBOL grammar _PyParser_Grammar; -static const arc arcs_0_0[3] = { - {2, 1}, - {3, 2}, - {4, 1}, -}; -static const arc arcs_0_1[1] = { - {0, 1}, -}; -static const arc arcs_0_2[1] = { - {2, 1}, -}; -static state states_0[3] = { - {3, arcs_0_0}, - {1, arcs_0_1}, - {1, arcs_0_2}, -}; -static const arc arcs_1_0[3] = { - {44, 1}, - {2, 0}, - {45, 0}, -}; -static const arc arcs_1_1[1] = { - {0, 1}, -}; -static state states_1[2] = { - {3, arcs_1_0}, - {1, arcs_1_1}, -}; -static const arc arcs_2_0[1] = { - {47, 1}, -}; -static const arc arcs_2_1[2] = { - {44, 2}, - {2, 1}, -}; -static const arc arcs_2_2[1] = { - {0, 2}, -}; -static state states_2[3] = { - {1, arcs_2_0}, - {2, arcs_2_1}, - {1, arcs_2_2}, -}; -static const arc arcs_3_0[1] = { - {10, 1}, -}; -static const arc arcs_3_1[1] = { - {49, 2}, -}; -static const arc arcs_3_2[1] = { - {2, 3}, -}; -static const arc arcs_3_3[1] = { - {0, 3}, -}; -static state states_3[4] = { - {1, arcs_3_0}, - {1, arcs_3_1}, - {1, arcs_3_2}, - {1, arcs_3_3}, -}; -static const arc arcs_4_0[1] = { - {48, 1}, -}; -static const arc arcs_4_1[2] = { - {48, 1}, - {0, 1}, -}; -static state states_4[2] = { - {1, arcs_4_0}, - {2, arcs_4_1}, -}; -static const arc arcs_5_0[1] = { - {50, 1}, -}; -static const arc arcs_5_1[3] = { - {52, 2}, - {53, 2}, - {54, 2}, -}; -static const arc arcs_5_2[1] = { - {0, 2}, -}; -static state states_5[3] = { - {1, arcs_5_0}, - {3, arcs_5_1}, - {1, arcs_5_2}, -}; -static const arc arcs_6_0[1] = { - {38, 1}, -}; -static const arc arcs_6_1[1] = { - {54, 2}, -}; -static const arc arcs_6_2[1] = { - {0, 2}, -}; -static state states_6[3] = { - {1, arcs_6_0}, - {1, arcs_6_1}, - {1, arcs_6_2}, -}; -static const arc arcs_7_0[1] = { - {19, 1}, -}; -static const arc arcs_7_1[1] = { - {40, 2}, -}; -static const arc arcs_7_2[1] = { - {55, 3}, -}; -static const arc arcs_7_3[2] = { - {56, 4}, - {57, 5}, -}; -static const arc arcs_7_4[1] = { - {58, 6}, -}; -static const arc arcs_7_5[2] = { - {59, 7}, - {60, 8}, -}; -static const arc arcs_7_6[1] = { - {57, 5}, -}; -static const arc arcs_7_7[1] = { - {60, 8}, -}; -static const arc arcs_7_8[1] = { - {0, 8}, -}; -static state states_7[9] = { - {1, arcs_7_0}, - {1, arcs_7_1}, - {1, arcs_7_2}, - {2, arcs_7_3}, - {1, arcs_7_4}, - {2, arcs_7_5}, - {1, arcs_7_6}, - {1, arcs_7_7}, - {1, arcs_7_8}, -}; -static const arc arcs_8_0[1] = { - {5, 1}, -}; -static const arc arcs_8_1[2] = { - {61, 2}, - {62, 3}, -}; -static const arc arcs_8_2[1] = { - {0, 2}, -}; -static const arc arcs_8_3[1] = { - {61, 2}, -}; -static state states_8[4] = { - {1, arcs_8_0}, - {2, arcs_8_1}, - {1, arcs_8_2}, - {1, arcs_8_3}, -}; -static const arc arcs_9_0[3] = { - {6, 1}, - {63, 2}, - {64, 3}, -}; -static const arc arcs_9_1[4] = { - {65, 4}, - {59, 5}, - {64, 6}, - {0, 1}, -}; -static const arc arcs_9_2[1] = { - {64, 7}, -}; -static const arc arcs_9_3[4] = { - {65, 8}, - {66, 9}, - {59, 5}, - {0, 3}, -}; -static const arc arcs_9_4[4] = { - {63, 2}, - {59, 10}, - {64, 11}, - {0, 4}, -}; -static const arc arcs_9_5[1] = { - {0, 5}, -}; -static const arc arcs_9_6[3] = { - {65, 4}, - {59, 5}, - {0, 6}, -}; -static const arc arcs_9_7[3] = { - {65, 12}, - {59, 5}, - {0, 7}, -}; -static const arc arcs_9_8[6] = { - {6, 13}, - {63, 2}, - {67, 14}, - {59, 15}, - {64, 3}, - {0, 8}, -}; -static const arc arcs_9_9[1] = { - {58, 16}, -}; -static const arc arcs_9_10[3] = { - {63, 2}, - {64, 11}, - {0, 10}, -}; -static const arc arcs_9_11[4] = { - {65, 4}, - {66, 17}, - {59, 5}, - {0, 11}, -}; -static const arc arcs_9_12[2] = { - {59, 5}, - {0, 12}, -}; -static const arc arcs_9_13[4] = { - {65, 18}, - {59, 5}, - {64, 19}, - {0, 13}, -}; -static const arc arcs_9_14[2] = { - {65, 20}, - {0, 14}, -}; -static const arc arcs_9_15[5] = { - {6, 13}, - {63, 2}, - {67, 14}, - {64, 3}, - {0, 15}, -}; -static const arc arcs_9_16[3] = { - {65, 8}, - {59, 5}, - {0, 16}, -}; -static const arc arcs_9_17[1] = { - {58, 6}, -}; -static const arc arcs_9_18[4] = { - {63, 2}, - {59, 21}, - {64, 22}, - {0, 18}, -}; -static const arc arcs_9_19[3] = { - {65, 18}, - {59, 5}, - {0, 19}, -}; -static const arc arcs_9_20[5] = { - {6, 23}, - {63, 2}, - {59, 24}, - {64, 25}, - {0, 20}, -}; -static const arc arcs_9_21[3] = { - {63, 2}, - {64, 22}, - {0, 21}, -}; -static const arc arcs_9_22[4] = { - {65, 18}, - {66, 26}, - {59, 5}, - {0, 22}, -}; -static const arc arcs_9_23[4] = { - {65, 27}, - {59, 5}, - {64, 28}, - {0, 23}, -}; -static const arc arcs_9_24[1] = { - {64, 25}, -}; -static const arc arcs_9_25[4] = { - {65, 29}, - {66, 30}, - {59, 5}, - {0, 25}, -}; -static const arc arcs_9_26[1] = { - {58, 19}, -}; -static const arc arcs_9_27[4] = { - {63, 2}, - {59, 31}, - {64, 32}, - {0, 27}, -}; -static const arc arcs_9_28[3] = { - {65, 27}, - {59, 5}, - {0, 28}, -}; -static const arc arcs_9_29[5] = { - {6, 33}, - {63, 2}, - {59, 34}, - {64, 25}, - {0, 29}, -}; -static const arc arcs_9_30[1] = { - {58, 35}, -}; -static const arc arcs_9_31[3] = { - {63, 2}, - {64, 32}, - {0, 31}, -}; -static const arc arcs_9_32[4] = { - {65, 27}, - {66, 36}, - {59, 5}, - {0, 32}, -}; -static const arc arcs_9_33[4] = { - {65, 37}, - {59, 5}, - {64, 38}, - {0, 33}, -}; -static const arc arcs_9_34[4] = { - {6, 33}, - {63, 2}, - {64, 25}, - {0, 34}, -}; -static const arc arcs_9_35[3] = { - {65, 29}, - {59, 5}, - {0, 35}, -}; -static const arc arcs_9_36[1] = { - {58, 28}, -}; -static const arc arcs_9_37[4] = { - {63, 2}, - {59, 39}, - {64, 40}, - {0, 37}, -}; -static const arc arcs_9_38[3] = { - {65, 37}, - {59, 5}, - {0, 38}, -}; -static const arc arcs_9_39[3] = { - {63, 2}, - {64, 40}, - {0, 39}, -}; -static const arc arcs_9_40[4] = { - {65, 37}, - {66, 41}, - {59, 5}, - {0, 40}, -}; -static const arc arcs_9_41[1] = { - {58, 38}, -}; -static state states_9[42] = { - {3, arcs_9_0}, - {4, arcs_9_1}, - {1, arcs_9_2}, - {4, arcs_9_3}, - {4, arcs_9_4}, - {1, arcs_9_5}, - {3, arcs_9_6}, - {3, arcs_9_7}, - {6, arcs_9_8}, - {1, arcs_9_9}, - {3, arcs_9_10}, - {4, arcs_9_11}, - {2, arcs_9_12}, - {4, arcs_9_13}, - {2, arcs_9_14}, - {5, arcs_9_15}, - {3, arcs_9_16}, - {1, arcs_9_17}, - {4, arcs_9_18}, - {3, arcs_9_19}, - {5, arcs_9_20}, - {3, arcs_9_21}, - {4, arcs_9_22}, - {4, arcs_9_23}, - {1, arcs_9_24}, - {4, arcs_9_25}, - {1, arcs_9_26}, - {4, arcs_9_27}, - {3, arcs_9_28}, - {5, arcs_9_29}, - {1, arcs_9_30}, - {3, arcs_9_31}, - {4, arcs_9_32}, - {4, arcs_9_33}, - {4, arcs_9_34}, - {3, arcs_9_35}, - {1, arcs_9_36}, - {4, arcs_9_37}, - {3, arcs_9_38}, - {3, arcs_9_39}, - {4, arcs_9_40}, - {1, arcs_9_41}, -}; -static const arc arcs_10_0[1] = { - {40, 1}, -}; -static const arc arcs_10_1[2] = { - {57, 2}, - {0, 1}, -}; -static const arc arcs_10_2[1] = { - {58, 3}, -}; -static const arc arcs_10_3[1] = { - {0, 3}, -}; -static state states_10[4] = { - {1, arcs_10_0}, - {2, arcs_10_1}, - {1, arcs_10_2}, - {1, arcs_10_3}, -}; -static const arc arcs_11_0[3] = { - {6, 1}, - {63, 2}, - {69, 3}, -}; -static const arc arcs_11_1[3] = { - {65, 4}, - {69, 5}, - {0, 1}, -}; -static const arc arcs_11_2[1] = { - {69, 6}, -}; -static const arc arcs_11_3[3] = { - {65, 7}, - {66, 8}, - {0, 3}, -}; -static const arc arcs_11_4[3] = { - {63, 2}, - {69, 9}, - {0, 4}, -}; -static const arc arcs_11_5[2] = { - {65, 4}, - {0, 5}, -}; -static const arc arcs_11_6[2] = { - {65, 10}, - {0, 6}, -}; -static const arc arcs_11_7[5] = { - {6, 11}, - {63, 2}, - {67, 12}, - {69, 3}, - {0, 7}, -}; -static const arc arcs_11_8[1] = { - {58, 13}, -}; -static const arc arcs_11_9[3] = { - {65, 4}, - {66, 14}, - {0, 9}, -}; -static const arc arcs_11_10[1] = { - {0, 10}, -}; -static const arc arcs_11_11[3] = { - {65, 15}, - {69, 16}, - {0, 11}, -}; -static const arc arcs_11_12[2] = { - {65, 17}, - {0, 12}, -}; -static const arc arcs_11_13[2] = { - {65, 7}, - {0, 13}, -}; -static const arc arcs_11_14[1] = { - {58, 5}, -}; -static const arc arcs_11_15[3] = { - {63, 2}, - {69, 18}, - {0, 15}, -}; -static const arc arcs_11_16[2] = { - {65, 15}, - {0, 16}, -}; -static const arc arcs_11_17[4] = { - {6, 19}, - {63, 2}, - {69, 20}, - {0, 17}, -}; -static const arc arcs_11_18[3] = { - {65, 15}, - {66, 21}, - {0, 18}, -}; -static const arc arcs_11_19[3] = { - {65, 22}, - {69, 23}, - {0, 19}, -}; -static const arc arcs_11_20[3] = { - {65, 24}, - {66, 25}, - {0, 20}, -}; -static const arc arcs_11_21[1] = { - {58, 16}, -}; -static const arc arcs_11_22[3] = { - {63, 2}, - {69, 26}, - {0, 22}, -}; -static const arc arcs_11_23[2] = { - {65, 22}, - {0, 23}, -}; -static const arc arcs_11_24[4] = { - {6, 27}, - {63, 2}, - {69, 20}, - {0, 24}, -}; -static const arc arcs_11_25[1] = { - {58, 28}, -}; -static const arc arcs_11_26[3] = { - {65, 22}, - {66, 29}, - {0, 26}, -}; -static const arc arcs_11_27[3] = { - {65, 30}, - {69, 31}, - {0, 27}, -}; -static const arc arcs_11_28[2] = { - {65, 24}, - {0, 28}, -}; -static const arc arcs_11_29[1] = { - {58, 23}, -}; -static const arc arcs_11_30[3] = { - {63, 2}, - {69, 32}, - {0, 30}, -}; -static const arc arcs_11_31[2] = { - {65, 30}, - {0, 31}, -}; -static const arc arcs_11_32[3] = { - {65, 30}, - {66, 33}, - {0, 32}, -}; -static const arc arcs_11_33[1] = { - {58, 31}, -}; -static state states_11[34] = { - {3, arcs_11_0}, - {3, arcs_11_1}, - {1, arcs_11_2}, - {3, arcs_11_3}, - {3, arcs_11_4}, - {2, arcs_11_5}, - {2, arcs_11_6}, - {5, arcs_11_7}, - {1, arcs_11_8}, - {3, arcs_11_9}, - {1, arcs_11_10}, - {3, arcs_11_11}, - {2, arcs_11_12}, - {2, arcs_11_13}, - {1, arcs_11_14}, - {3, arcs_11_15}, - {2, arcs_11_16}, - {4, arcs_11_17}, - {3, arcs_11_18}, - {3, arcs_11_19}, - {3, arcs_11_20}, - {1, arcs_11_21}, - {3, arcs_11_22}, - {2, arcs_11_23}, - {4, arcs_11_24}, - {1, arcs_11_25}, - {3, arcs_11_26}, - {3, arcs_11_27}, - {2, arcs_11_28}, - {1, arcs_11_29}, - {3, arcs_11_30}, - {2, arcs_11_31}, - {3, arcs_11_32}, - {1, arcs_11_33}, -}; -static const arc arcs_12_0[1] = { - {40, 1}, -}; -static const arc arcs_12_1[1] = { - {0, 1}, -}; -static state states_12[2] = { - {1, arcs_12_0}, - {1, arcs_12_1}, -}; -static const arc arcs_13_0[2] = { - {3, 1}, - {4, 1}, -}; -static const arc arcs_13_1[1] = { - {0, 1}, -}; -static state states_13[2] = { - {2, arcs_13_0}, - {1, arcs_13_1}, -}; -static const arc arcs_14_0[1] = { - {70, 1}, -}; -static const arc arcs_14_1[2] = { - {71, 2}, - {2, 3}, -}; -static const arc arcs_14_2[2] = { - {2, 3}, - {70, 1}, -}; -static const arc arcs_14_3[1] = { - {0, 3}, -}; -static state states_14[4] = { - {1, arcs_14_0}, - {2, arcs_14_1}, - {2, arcs_14_2}, - {1, arcs_14_3}, -}; -static const arc arcs_15_0[8] = { - {72, 1}, - {73, 1}, - {74, 1}, - {75, 1}, - {76, 1}, - {77, 1}, - {78, 1}, - {79, 1}, -}; -static const arc arcs_15_1[1] = { - {0, 1}, -}; -static state states_15[2] = { - {8, arcs_15_0}, - {1, arcs_15_1}, -}; -static const arc arcs_16_0[1] = { - {80, 1}, -}; -static const arc arcs_16_1[4] = { - {66, 2}, - {81, 3}, - {82, 4}, - {0, 1}, -}; -static const arc arcs_16_2[2] = { - {80, 5}, - {83, 5}, -}; -static const arc arcs_16_3[1] = { - {0, 3}, -}; -static const arc arcs_16_4[2] = { - {47, 3}, - {83, 3}, -}; -static const arc arcs_16_5[3] = { - {66, 2}, - {59, 3}, - {0, 5}, -}; -static state states_16[6] = { - {1, arcs_16_0}, - {4, arcs_16_1}, - {2, arcs_16_2}, - {1, arcs_16_3}, - {2, arcs_16_4}, - {3, arcs_16_5}, -}; -static const arc arcs_17_0[1] = { - {57, 1}, -}; -static const arc arcs_17_1[1] = { - {58, 2}, -}; -static const arc arcs_17_2[2] = { - {66, 3}, - {0, 2}, -}; -static const arc arcs_17_3[2] = { - {80, 4}, - {83, 4}, -}; -static const arc arcs_17_4[1] = { - {0, 4}, -}; -static state states_17[5] = { - {1, arcs_17_0}, - {1, arcs_17_1}, - {2, arcs_17_2}, - {2, arcs_17_3}, - {1, arcs_17_4}, -}; -static const arc arcs_18_0[2] = { - {84, 1}, - {58, 1}, -}; -static const arc arcs_18_1[2] = { - {65, 2}, - {0, 1}, -}; -static const arc arcs_18_2[3] = { - {84, 1}, - {58, 1}, - {0, 2}, -}; -static state states_18[3] = { - {2, arcs_18_0}, - {2, arcs_18_1}, - {3, arcs_18_2}, -}; -static const arc arcs_19_0[13] = { - {85, 1}, - {86, 1}, - {87, 1}, - {88, 1}, - {89, 1}, - {90, 1}, - {91, 1}, - {92, 1}, - {93, 1}, - {94, 1}, - {95, 1}, - {96, 1}, - {97, 1}, -}; -static const arc arcs_19_1[1] = { - {0, 1}, -}; -static state states_19[2] = { - {13, arcs_19_0}, - {1, arcs_19_1}, -}; -static const arc arcs_20_0[1] = { - {20, 1}, -}; -static const arc arcs_20_1[1] = { - {98, 2}, -}; -static const arc arcs_20_2[1] = { - {0, 2}, -}; -static state states_20[3] = { - {1, arcs_20_0}, - {1, arcs_20_1}, - {1, arcs_20_2}, -}; -static const arc arcs_21_0[1] = { - {29, 1}, -}; -static const arc arcs_21_1[1] = { - {0, 1}, -}; -static state states_21[2] = { - {1, arcs_21_0}, - {1, arcs_21_1}, -}; -static const arc arcs_22_0[5] = { - {99, 1}, - {100, 1}, - {101, 1}, - {102, 1}, - {103, 1}, -}; -static const arc arcs_22_1[1] = { - {0, 1}, -}; -static state states_22[2] = { - {5, arcs_22_0}, - {1, arcs_22_1}, -}; -static const arc arcs_23_0[1] = { - {16, 1}, -}; -static const arc arcs_23_1[1] = { - {0, 1}, -}; -static state states_23[2] = { - {1, arcs_23_0}, - {1, arcs_23_1}, -}; -static const arc arcs_24_0[1] = { - {18, 1}, -}; -static const arc arcs_24_1[1] = { - {0, 1}, -}; -static state states_24[2] = { - {1, arcs_24_0}, - {1, arcs_24_1}, -}; -static const arc arcs_25_0[1] = { - {31, 1}, -}; -static const arc arcs_25_1[2] = { - {80, 2}, - {0, 1}, -}; -static const arc arcs_25_2[1] = { - {0, 2}, -}; -static state states_25[3] = { - {1, arcs_25_0}, - {2, arcs_25_1}, - {1, arcs_25_2}, -}; -static const arc arcs_26_0[1] = { - {83, 1}, -}; -static const arc arcs_26_1[1] = { - {0, 1}, -}; -static state states_26[2] = { - {1, arcs_26_0}, - {1, arcs_26_1}, -}; -static const arc arcs_27_0[1] = { - {30, 1}, -}; -static const arc arcs_27_1[2] = { - {58, 2}, - {0, 1}, -}; -static const arc arcs_27_2[2] = { - {22, 3}, - {0, 2}, -}; -static const arc arcs_27_3[1] = { - {58, 4}, -}; -static const arc arcs_27_4[1] = { - {0, 4}, -}; -static state states_27[5] = { - {1, arcs_27_0}, - {2, arcs_27_1}, - {2, arcs_27_2}, - {1, arcs_27_3}, - {1, arcs_27_4}, -}; -static const arc arcs_28_0[2] = { - {104, 1}, - {105, 1}, -}; -static const arc arcs_28_1[1] = { - {0, 1}, -}; -static state states_28[2] = { - {2, arcs_28_0}, - {1, arcs_28_1}, -}; -static const arc arcs_29_0[1] = { - {25, 1}, -}; -static const arc arcs_29_1[1] = { - {106, 2}, -}; -static const arc arcs_29_2[1] = { - {0, 2}, -}; -static state states_29[3] = { - {1, arcs_29_0}, - {1, arcs_29_1}, - {1, arcs_29_2}, -}; -static const arc arcs_30_0[1] = { - {22, 1}, -}; -static const arc arcs_30_1[3] = { - {107, 2}, - {9, 2}, - {108, 3}, -}; -static const arc arcs_30_2[4] = { - {107, 2}, - {9, 2}, - {25, 4}, - {108, 3}, -}; -static const arc arcs_30_3[1] = { - {25, 4}, -}; -static const arc arcs_30_4[3] = { - {5, 5}, - {6, 6}, - {109, 6}, -}; -static const arc arcs_30_5[1] = { - {109, 7}, -}; -static const arc arcs_30_6[1] = { - {0, 6}, -}; -static const arc arcs_30_7[1] = { - {61, 6}, -}; -static state states_30[8] = { - {1, arcs_30_0}, - {3, arcs_30_1}, - {4, arcs_30_2}, - {1, arcs_30_3}, - {3, arcs_30_4}, - {1, arcs_30_5}, - {1, arcs_30_6}, - {1, arcs_30_7}, -}; -static const arc arcs_31_0[1] = { - {40, 1}, -}; -static const arc arcs_31_1[2] = { - {111, 2}, - {0, 1}, -}; -static const arc arcs_31_2[1] = { - {40, 3}, -}; -static const arc arcs_31_3[1] = { - {0, 3}, -}; -static state states_31[4] = { - {1, arcs_31_0}, - {2, arcs_31_1}, - {1, arcs_31_2}, - {1, arcs_31_3}, -}; -static const arc arcs_32_0[1] = { - {108, 1}, -}; -static const arc arcs_32_1[2] = { - {111, 2}, - {0, 1}, -}; -static const arc arcs_32_2[1] = { - {40, 3}, -}; -static const arc arcs_32_3[1] = { - {0, 3}, -}; -static state states_32[4] = { - {1, arcs_32_0}, - {2, arcs_32_1}, - {1, arcs_32_2}, - {1, arcs_32_3}, -}; -static const arc arcs_33_0[1] = { - {110, 1}, -}; -static const arc arcs_33_1[2] = { - {65, 2}, - {0, 1}, -}; -static const arc arcs_33_2[2] = { - {110, 1}, - {0, 2}, -}; -static state states_33[3] = { - {1, arcs_33_0}, - {2, arcs_33_1}, - {2, arcs_33_2}, -}; -static const arc arcs_34_0[1] = { - {112, 1}, -}; -static const arc arcs_34_1[2] = { - {65, 0}, - {0, 1}, -}; -static state states_34[2] = { - {1, arcs_34_0}, - {2, arcs_34_1}, -}; -static const arc arcs_35_0[1] = { - {40, 1}, -}; -static const arc arcs_35_1[2] = { - {107, 0}, - {0, 1}, -}; -static state states_35[2] = { - {1, arcs_35_0}, - {2, arcs_35_1}, -}; -static const arc arcs_36_0[1] = { - {23, 1}, -}; -static const arc arcs_36_1[1] = { - {40, 2}, -}; -static const arc arcs_36_2[2] = { - {65, 1}, - {0, 2}, -}; -static state states_36[3] = { - {1, arcs_36_0}, - {1, arcs_36_1}, - {2, arcs_36_2}, -}; -static const arc arcs_37_0[1] = { - {27, 1}, -}; -static const arc arcs_37_1[1] = { - {40, 2}, -}; -static const arc arcs_37_2[2] = { - {65, 1}, - {0, 2}, -}; -static state states_37[3] = { - {1, arcs_37_0}, - {1, arcs_37_1}, - {2, arcs_37_2}, -}; -static const arc arcs_38_0[1] = { - {15, 1}, -}; -static const arc arcs_38_1[1] = { - {58, 2}, -}; -static const arc arcs_38_2[2] = { - {65, 3}, - {0, 2}, -}; -static const arc arcs_38_3[1] = { - {58, 4}, -}; -static const arc arcs_38_4[1] = { - {0, 4}, -}; -static state states_38[5] = { - {1, arcs_38_0}, - {1, arcs_38_1}, - {2, arcs_38_2}, - {1, arcs_38_3}, - {1, arcs_38_4}, -}; -static const arc arcs_39_0[9] = { - {113, 1}, - {53, 1}, - {51, 1}, - {114, 1}, - {54, 1}, - {115, 1}, - {116, 1}, - {117, 1}, - {118, 1}, -}; -static const arc arcs_39_1[1] = { - {0, 1}, -}; -static state states_39[2] = { - {9, arcs_39_0}, - {1, arcs_39_1}, -}; -static const arc arcs_40_0[1] = { - {38, 1}, -}; -static const arc arcs_40_1[3] = { - {114, 2}, - {54, 2}, - {118, 2}, -}; -static const arc arcs_40_2[1] = { - {0, 2}, -}; -static state states_40[3] = { - {1, arcs_40_0}, - {3, arcs_40_1}, - {1, arcs_40_2}, -}; -static const arc arcs_41_0[1] = { - {24, 1}, -}; -static const arc arcs_41_1[1] = { - {49, 2}, -}; -static const arc arcs_41_2[1] = { - {57, 3}, -}; -static const arc arcs_41_3[1] = { - {119, 4}, -}; -static const arc arcs_41_4[3] = { - {120, 1}, - {121, 5}, - {0, 4}, -}; -static const arc arcs_41_5[1] = { - {57, 6}, -}; -static const arc arcs_41_6[1] = { - {119, 7}, -}; -static const arc arcs_41_7[1] = { - {0, 7}, -}; -static state states_41[8] = { - {1, arcs_41_0}, - {1, arcs_41_1}, - {1, arcs_41_2}, - {1, arcs_41_3}, - {3, arcs_41_4}, - {1, arcs_41_5}, - {1, arcs_41_6}, - {1, arcs_41_7}, -}; -static const arc arcs_42_0[1] = { - {33, 1}, -}; -static const arc arcs_42_1[1] = { - {49, 2}, -}; -static const arc arcs_42_2[1] = { - {57, 3}, -}; -static const arc arcs_42_3[1] = { - {119, 4}, -}; -static const arc arcs_42_4[2] = { - {121, 5}, - {0, 4}, -}; -static const arc arcs_42_5[1] = { - {57, 6}, -}; -static const arc arcs_42_6[1] = { - {119, 7}, -}; -static const arc arcs_42_7[1] = { - {0, 7}, -}; -static state states_42[8] = { - {1, arcs_42_0}, - {1, arcs_42_1}, - {1, arcs_42_2}, - {1, arcs_42_3}, - {2, arcs_42_4}, - {1, arcs_42_5}, - {1, arcs_42_6}, - {1, arcs_42_7}, -}; -static const arc arcs_43_0[1] = { - {21, 1}, -}; -static const arc arcs_43_1[1] = { - {98, 2}, -}; -static const arc arcs_43_2[1] = { - {122, 3}, -}; -static const arc arcs_43_3[1] = { - {47, 4}, -}; -static const arc arcs_43_4[1] = { - {57, 5}, -}; -static const arc arcs_43_5[2] = { - {59, 6}, - {119, 7}, -}; -static const arc arcs_43_6[1] = { - {119, 7}, -}; -static const arc arcs_43_7[2] = { - {121, 8}, - {0, 7}, -}; -static const arc arcs_43_8[1] = { - {57, 9}, -}; -static const arc arcs_43_9[1] = { - {119, 10}, -}; -static const arc arcs_43_10[1] = { - {0, 10}, -}; -static state states_43[11] = { - {1, arcs_43_0}, - {1, arcs_43_1}, - {1, arcs_43_2}, - {1, arcs_43_3}, - {1, arcs_43_4}, - {2, arcs_43_5}, - {1, arcs_43_6}, - {2, arcs_43_7}, - {1, arcs_43_8}, - {1, arcs_43_9}, - {1, arcs_43_10}, -}; -static const arc arcs_44_0[1] = { - {32, 1}, -}; -static const arc arcs_44_1[1] = { - {57, 2}, -}; -static const arc arcs_44_2[1] = { - {119, 3}, -}; -static const arc arcs_44_3[2] = { - {123, 4}, - {124, 5}, -}; -static const arc arcs_44_4[1] = { - {57, 6}, -}; -static const arc arcs_44_5[1] = { - {57, 7}, -}; -static const arc arcs_44_6[1] = { - {119, 8}, -}; -static const arc arcs_44_7[1] = { - {119, 9}, -}; -static const arc arcs_44_8[1] = { - {0, 8}, -}; -static const arc arcs_44_9[4] = { - {121, 10}, - {123, 4}, - {124, 5}, - {0, 9}, -}; -static const arc arcs_44_10[1] = { - {57, 11}, -}; -static const arc arcs_44_11[1] = { - {119, 12}, -}; -static const arc arcs_44_12[2] = { - {123, 4}, - {0, 12}, -}; -static state states_44[13] = { - {1, arcs_44_0}, - {1, arcs_44_1}, - {1, arcs_44_2}, - {2, arcs_44_3}, - {1, arcs_44_4}, - {1, arcs_44_5}, - {1, arcs_44_6}, - {1, arcs_44_7}, - {1, arcs_44_8}, - {4, arcs_44_9}, - {1, arcs_44_10}, - {1, arcs_44_11}, - {2, arcs_44_12}, -}; -static const arc arcs_45_0[1] = { - {34, 1}, -}; -static const arc arcs_45_1[1] = { - {125, 2}, -}; -static const arc arcs_45_2[2] = { - {65, 1}, - {57, 3}, -}; -static const arc arcs_45_3[2] = { - {59, 4}, - {119, 5}, -}; -static const arc arcs_45_4[1] = { - {119, 5}, -}; -static const arc arcs_45_5[1] = { - {0, 5}, -}; -static state states_45[6] = { - {1, arcs_45_0}, - {1, arcs_45_1}, - {2, arcs_45_2}, - {2, arcs_45_3}, - {1, arcs_45_4}, - {1, arcs_45_5}, -}; -static const arc arcs_46_0[1] = { - {58, 1}, -}; -static const arc arcs_46_1[2] = { - {111, 2}, - {0, 1}, -}; -static const arc arcs_46_2[1] = { - {126, 3}, -}; -static const arc arcs_46_3[1] = { - {0, 3}, -}; -static state states_46[4] = { - {1, arcs_46_0}, - {2, arcs_46_1}, - {1, arcs_46_2}, - {1, arcs_46_3}, -}; -static const arc arcs_47_0[1] = { - {127, 1}, -}; -static const arc arcs_47_1[2] = { - {58, 2}, - {0, 1}, -}; -static const arc arcs_47_2[2] = { - {111, 3}, - {0, 2}, -}; -static const arc arcs_47_3[1] = { - {40, 4}, -}; -static const arc arcs_47_4[1] = { - {0, 4}, -}; -static state states_47[5] = { - {1, arcs_47_0}, - {2, arcs_47_1}, - {2, arcs_47_2}, - {1, arcs_47_3}, - {1, arcs_47_4}, -}; -static const arc arcs_48_0[2] = { - {2, 1}, - {4, 2}, -}; -static const arc arcs_48_1[1] = { - {128, 3}, -}; -static const arc arcs_48_2[1] = { - {0, 2}, -}; -static const arc arcs_48_3[1] = { - {45, 4}, -}; -static const arc arcs_48_4[2] = { - {129, 2}, - {45, 4}, -}; -static state states_48[5] = { - {2, arcs_48_0}, - {1, arcs_48_1}, - {1, arcs_48_2}, - {1, arcs_48_3}, - {2, arcs_48_4}, -}; -static const arc arcs_49_0[1] = { - {58, 1}, -}; -static const arc arcs_49_1[2] = { - {130, 2}, - {0, 1}, -}; -static const arc arcs_49_2[1] = { - {58, 3}, -}; -static const arc arcs_49_3[1] = { - {0, 3}, -}; -static state states_49[4] = { - {1, arcs_49_0}, - {2, arcs_49_1}, - {1, arcs_49_2}, - {1, arcs_49_3}, -}; -static const arc arcs_50_0[2] = { - {131, 1}, - {132, 2}, -}; -static const arc arcs_50_1[1] = { - {0, 1}, -}; -static const arc arcs_50_2[2] = { - {24, 3}, - {0, 2}, -}; -static const arc arcs_50_3[1] = { - {132, 4}, -}; -static const arc arcs_50_4[1] = { - {121, 5}, -}; -static const arc arcs_50_5[1] = { - {58, 1}, -}; -static state states_50[6] = { - {2, arcs_50_0}, - {1, arcs_50_1}, - {2, arcs_50_2}, - {1, arcs_50_3}, - {1, arcs_50_4}, - {1, arcs_50_5}, -}; -static const arc arcs_51_0[2] = { - {134, 1}, - {132, 1}, -}; -static const arc arcs_51_1[1] = { - {0, 1}, -}; -static state states_51[2] = { - {2, arcs_51_0}, - {1, arcs_51_1}, -}; -static const arc arcs_52_0[1] = { - {26, 1}, -}; -static const arc arcs_52_1[2] = { - {57, 2}, - {68, 3}, -}; -static const arc arcs_52_2[1] = { - {58, 4}, -}; -static const arc arcs_52_3[1] = { - {57, 2}, -}; -static const arc arcs_52_4[1] = { - {0, 4}, -}; -static state states_52[5] = { - {1, arcs_52_0}, - {2, arcs_52_1}, - {1, arcs_52_2}, - {1, arcs_52_3}, - {1, arcs_52_4}, -}; -static const arc arcs_53_0[1] = { - {26, 1}, -}; -static const arc arcs_53_1[2] = { - {57, 2}, - {68, 3}, -}; -static const arc arcs_53_2[1] = { - {133, 4}, -}; -static const arc arcs_53_3[1] = { - {57, 2}, -}; -static const arc arcs_53_4[1] = { - {0, 4}, -}; -static state states_53[5] = { - {1, arcs_53_0}, - {2, arcs_53_1}, - {1, arcs_53_2}, - {1, arcs_53_3}, - {1, arcs_53_4}, -}; -static const arc arcs_54_0[1] = { - {135, 1}, -}; -static const arc arcs_54_1[2] = { - {136, 0}, - {0, 1}, -}; -static state states_54[2] = { - {1, arcs_54_0}, - {2, arcs_54_1}, -}; -static const arc arcs_55_0[1] = { - {137, 1}, -}; -static const arc arcs_55_1[2] = { - {138, 0}, - {0, 1}, -}; -static state states_55[2] = { - {1, arcs_55_0}, - {2, arcs_55_1}, -}; -static const arc arcs_56_0[2] = { - {28, 1}, - {139, 2}, -}; -static const arc arcs_56_1[1] = { - {137, 2}, -}; -static const arc arcs_56_2[1] = { - {0, 2}, -}; -static state states_56[3] = { - {2, arcs_56_0}, - {1, arcs_56_1}, - {1, arcs_56_2}, -}; -static const arc arcs_57_0[1] = { - {126, 1}, -}; -static const arc arcs_57_1[2] = { - {140, 0}, - {0, 1}, -}; -static state states_57[2] = { - {1, arcs_57_0}, - {2, arcs_57_1}, -}; -static const arc arcs_58_0[10] = { - {141, 1}, - {142, 1}, - {143, 1}, - {141, 1}, - {144, 1}, - {145, 1}, - {146, 1}, - {122, 1}, - {147, 2}, - {28, 3}, -}; -static const arc arcs_58_1[1] = { - {0, 1}, -}; -static const arc arcs_58_2[2] = { - {28, 1}, - {0, 2}, -}; -static const arc arcs_58_3[1] = { - {122, 1}, -}; -static state states_58[4] = { - {10, arcs_58_0}, - {1, arcs_58_1}, - {2, arcs_58_2}, - {1, arcs_58_3}, -}; -static const arc arcs_59_0[1] = { - {6, 1}, -}; -static const arc arcs_59_1[1] = { - {126, 2}, -}; -static const arc arcs_59_2[1] = { - {0, 2}, -}; -static state states_59[3] = { - {1, arcs_59_0}, - {1, arcs_59_1}, - {1, arcs_59_2}, -}; -static const arc arcs_60_0[1] = { - {148, 1}, -}; -static const arc arcs_60_1[2] = { - {149, 0}, - {0, 1}, -}; -static state states_60[2] = { - {1, arcs_60_0}, - {2, arcs_60_1}, -}; -static const arc arcs_61_0[1] = { - {150, 1}, -}; -static const arc arcs_61_1[2] = { - {151, 0}, - {0, 1}, -}; -static state states_61[2] = { - {1, arcs_61_0}, - {2, arcs_61_1}, -}; -static const arc arcs_62_0[1] = { - {152, 1}, -}; -static const arc arcs_62_1[2] = { - {153, 0}, - {0, 1}, -}; -static state states_62[2] = { - {1, arcs_62_0}, - {2, arcs_62_1}, -}; -static const arc arcs_63_0[1] = { - {154, 1}, -}; -static const arc arcs_63_1[3] = { - {155, 0}, - {156, 0}, - {0, 1}, -}; -static state states_63[2] = { - {1, arcs_63_0}, - {3, arcs_63_1}, -}; -static const arc arcs_64_0[1] = { - {157, 1}, -}; -static const arc arcs_64_1[3] = { - {7, 0}, - {8, 0}, - {0, 1}, -}; -static state states_64[2] = { - {1, arcs_64_0}, - {3, arcs_64_1}, -}; -static const arc arcs_65_0[1] = { - {158, 1}, -}; -static const arc arcs_65_1[6] = { - {159, 0}, - {6, 0}, - {67, 0}, - {160, 0}, - {10, 0}, - {0, 1}, -}; -static state states_65[2] = { - {1, arcs_65_0}, - {6, arcs_65_1}, -}; -static const arc arcs_66_0[4] = { - {7, 1}, - {8, 1}, - {37, 1}, - {161, 2}, -}; -static const arc arcs_66_1[1] = { - {158, 2}, -}; -static const arc arcs_66_2[1] = { - {0, 2}, -}; -static state states_66[3] = { - {4, arcs_66_0}, - {1, arcs_66_1}, - {1, arcs_66_2}, -}; -static const arc arcs_67_0[1] = { - {162, 1}, -}; -static const arc arcs_67_1[2] = { - {63, 2}, - {0, 1}, -}; -static const arc arcs_67_2[1] = { - {158, 3}, -}; -static const arc arcs_67_3[1] = { - {0, 3}, -}; -static state states_67[4] = { - {1, arcs_67_0}, - {2, arcs_67_1}, - {1, arcs_67_2}, - {1, arcs_67_3}, -}; -static const arc arcs_68_0[2] = { - {39, 1}, - {163, 2}, -}; -static const arc arcs_68_1[1] = { - {163, 2}, -}; -static const arc arcs_68_2[2] = { - {164, 2}, - {0, 2}, -}; -static state states_68[3] = { - {2, arcs_68_0}, - {1, arcs_68_1}, - {2, arcs_68_2}, -}; -static const arc arcs_69_0[10] = { - {5, 1}, - {9, 2}, - {11, 2}, - {12, 2}, - {13, 2}, - {14, 3}, - {36, 4}, - {40, 2}, - {41, 2}, - {42, 5}, -}; -static const arc arcs_69_1[3] = { - {61, 2}, - {165, 6}, - {83, 6}, -}; -static const arc arcs_69_2[1] = { - {0, 2}, -}; -static const arc arcs_69_3[2] = { - {166, 2}, - {165, 7}, -}; -static const arc arcs_69_4[2] = { - {167, 2}, - {168, 8}, -}; -static const arc arcs_69_5[2] = { - {42, 5}, - {0, 5}, -}; -static const arc arcs_69_6[1] = { - {61, 2}, -}; -static const arc arcs_69_7[1] = { - {166, 2}, -}; -static const arc arcs_69_8[1] = { - {167, 2}, -}; -static state states_69[9] = { - {10, arcs_69_0}, - {3, arcs_69_1}, - {1, arcs_69_2}, - {2, arcs_69_3}, - {2, arcs_69_4}, - {2, arcs_69_5}, - {1, arcs_69_6}, - {1, arcs_69_7}, - {1, arcs_69_8}, -}; -static const arc arcs_70_0[2] = { - {49, 1}, - {84, 1}, -}; -static const arc arcs_70_1[3] = { - {65, 2}, - {169, 3}, - {0, 1}, -}; -static const arc arcs_70_2[3] = { - {49, 4}, - {84, 4}, - {0, 2}, -}; -static const arc arcs_70_3[1] = { - {0, 3}, -}; -static const arc arcs_70_4[2] = { - {65, 2}, - {0, 4}, -}; -static state states_70[5] = { - {2, arcs_70_0}, - {3, arcs_70_1}, - {3, arcs_70_2}, - {1, arcs_70_3}, - {2, arcs_70_4}, -}; -static const arc arcs_71_0[3] = { - {5, 1}, - {107, 2}, - {14, 3}, -}; -static const arc arcs_71_1[2] = { - {61, 4}, - {170, 5}, -}; -static const arc arcs_71_2[1] = { - {40, 4}, -}; -static const arc arcs_71_3[1] = { - {171, 6}, -}; -static const arc arcs_71_4[1] = { - {0, 4}, -}; -static const arc arcs_71_5[1] = { - {61, 4}, -}; -static const arc arcs_71_6[1] = { - {166, 4}, -}; -static state states_71[7] = { - {3, arcs_71_0}, - {2, arcs_71_1}, - {1, arcs_71_2}, - {1, arcs_71_3}, - {1, arcs_71_4}, - {1, arcs_71_5}, - {1, arcs_71_6}, -}; -static const arc arcs_72_0[1] = { - {172, 1}, -}; -static const arc arcs_72_1[2] = { - {65, 2}, - {0, 1}, -}; -static const arc arcs_72_2[2] = { - {172, 1}, - {0, 2}, -}; -static state states_72[3] = { - {1, arcs_72_0}, - {2, arcs_72_1}, - {2, arcs_72_2}, -}; -static const arc arcs_73_0[2] = { - {57, 1}, - {58, 2}, -}; -static const arc arcs_73_1[3] = { - {173, 3}, - {58, 4}, - {0, 1}, -}; -static const arc arcs_73_2[2] = { - {57, 1}, - {0, 2}, -}; -static const arc arcs_73_3[1] = { - {0, 3}, -}; -static const arc arcs_73_4[2] = { - {173, 3}, - {0, 4}, -}; -static state states_73[5] = { - {2, arcs_73_0}, - {3, arcs_73_1}, - {2, arcs_73_2}, - {1, arcs_73_3}, - {2, arcs_73_4}, -}; -static const arc arcs_74_0[1] = { - {57, 1}, -}; -static const arc arcs_74_1[2] = { - {58, 2}, - {0, 1}, -}; -static const arc arcs_74_2[1] = { - {0, 2}, -}; -static state states_74[3] = { - {1, arcs_74_0}, - {2, arcs_74_1}, - {1, arcs_74_2}, -}; -static const arc arcs_75_0[2] = { - {126, 1}, - {84, 1}, -}; -static const arc arcs_75_1[2] = { - {65, 2}, - {0, 1}, -}; -static const arc arcs_75_2[3] = { - {126, 1}, - {84, 1}, - {0, 2}, -}; -static state states_75[3] = { - {2, arcs_75_0}, - {2, arcs_75_1}, - {3, arcs_75_2}, -}; -static const arc arcs_76_0[1] = { - {58, 1}, -}; -static const arc arcs_76_1[2] = { - {65, 2}, - {0, 1}, -}; -static const arc arcs_76_2[2] = { - {58, 1}, - {0, 2}, -}; -static state states_76[3] = { - {1, arcs_76_0}, - {2, arcs_76_1}, - {2, arcs_76_2}, -}; -static const arc arcs_77_0[3] = { - {63, 1}, - {84, 2}, - {58, 3}, -}; -static const arc arcs_77_1[1] = { - {126, 4}, -}; -static const arc arcs_77_2[3] = { - {65, 5}, - {169, 6}, - {0, 2}, -}; -static const arc arcs_77_3[4] = { - {65, 5}, - {57, 7}, - {169, 6}, - {0, 3}, -}; -static const arc arcs_77_4[3] = { - {65, 8}, - {169, 6}, - {0, 4}, -}; -static const arc arcs_77_5[3] = { - {84, 9}, - {58, 9}, - {0, 5}, -}; -static const arc arcs_77_6[1] = { - {0, 6}, -}; -static const arc arcs_77_7[1] = { - {58, 4}, -}; -static const arc arcs_77_8[3] = { - {63, 10}, - {58, 11}, - {0, 8}, -}; -static const arc arcs_77_9[2] = { - {65, 5}, - {0, 9}, -}; -static const arc arcs_77_10[1] = { - {126, 12}, -}; -static const arc arcs_77_11[1] = { - {57, 13}, -}; -static const arc arcs_77_12[2] = { - {65, 8}, - {0, 12}, -}; -static const arc arcs_77_13[1] = { - {58, 12}, -}; -static state states_77[14] = { - {3, arcs_77_0}, - {1, arcs_77_1}, - {3, arcs_77_2}, - {4, arcs_77_3}, - {3, arcs_77_4}, - {3, arcs_77_5}, - {1, arcs_77_6}, - {1, arcs_77_7}, - {3, arcs_77_8}, - {2, arcs_77_9}, - {1, arcs_77_10}, - {1, arcs_77_11}, - {2, arcs_77_12}, - {1, arcs_77_13}, -}; -static const arc arcs_78_0[1] = { - {17, 1}, -}; -static const arc arcs_78_1[1] = { - {40, 2}, -}; -static const arc arcs_78_2[2] = { - {5, 3}, - {57, 4}, -}; -static const arc arcs_78_3[2] = { - {61, 5}, - {170, 6}, -}; -static const arc arcs_78_4[1] = { - {119, 7}, -}; -static const arc arcs_78_5[1] = { - {57, 4}, -}; -static const arc arcs_78_6[1] = { - {61, 5}, -}; -static const arc arcs_78_7[1] = { - {0, 7}, -}; -static state states_78[8] = { - {1, arcs_78_0}, - {1, arcs_78_1}, - {2, arcs_78_2}, - {2, arcs_78_3}, - {1, arcs_78_4}, - {1, arcs_78_5}, - {1, arcs_78_6}, - {1, arcs_78_7}, -}; -static const arc arcs_79_0[1] = { - {174, 1}, -}; -static const arc arcs_79_1[2] = { - {65, 2}, - {0, 1}, -}; -static const arc arcs_79_2[2] = { - {174, 1}, - {0, 2}, -}; -static state states_79[3] = { - {1, arcs_79_0}, - {2, arcs_79_1}, - {2, arcs_79_2}, -}; -static const arc arcs_80_0[3] = { - {6, 1}, - {63, 1}, - {58, 2}, -}; -static const arc arcs_80_1[1] = { - {58, 3}, -}; -static const arc arcs_80_2[4] = { - {130, 1}, - {66, 1}, - {169, 3}, - {0, 2}, -}; -static const arc arcs_80_3[1] = { - {0, 3}, -}; -static state states_80[4] = { - {3, arcs_80_0}, - {1, arcs_80_1}, - {4, arcs_80_2}, - {1, arcs_80_3}, -}; -static const arc arcs_81_0[2] = { - {169, 1}, - {176, 1}, -}; -static const arc arcs_81_1[1] = { - {0, 1}, -}; -static state states_81[2] = { - {2, arcs_81_0}, - {1, arcs_81_1}, -}; -static const arc arcs_82_0[1] = { - {21, 1}, -}; -static const arc arcs_82_1[1] = { - {98, 2}, -}; -static const arc arcs_82_2[1] = { - {122, 3}, -}; -static const arc arcs_82_3[1] = { - {132, 4}, -}; -static const arc arcs_82_4[2] = { - {175, 5}, - {0, 4}, -}; -static const arc arcs_82_5[1] = { - {0, 5}, -}; -static state states_82[6] = { - {1, arcs_82_0}, - {1, arcs_82_1}, - {1, arcs_82_2}, - {1, arcs_82_3}, - {2, arcs_82_4}, - {1, arcs_82_5}, -}; -static const arc arcs_83_0[2] = { - {38, 1}, - {177, 2}, -}; -static const arc arcs_83_1[1] = { - {177, 2}, -}; -static const arc arcs_83_2[1] = { - {0, 2}, -}; -static state states_83[3] = { - {2, arcs_83_0}, - {1, arcs_83_1}, - {1, arcs_83_2}, -}; -static const arc arcs_84_0[1] = { - {24, 1}, -}; -static const arc arcs_84_1[1] = { - {133, 2}, -}; -static const arc arcs_84_2[2] = { - {175, 3}, - {0, 2}, -}; -static const arc arcs_84_3[1] = { - {0, 3}, -}; -static state states_84[4] = { - {1, arcs_84_0}, - {1, arcs_84_1}, - {2, arcs_84_2}, - {1, arcs_84_3}, -}; -static const arc arcs_85_0[1] = { - {40, 1}, -}; -static const arc arcs_85_1[1] = { - {0, 1}, -}; -static state states_85[2] = { - {1, arcs_85_0}, - {1, arcs_85_1}, -}; -static const arc arcs_86_0[1] = { - {35, 1}, -}; -static const arc arcs_86_1[2] = { - {179, 2}, - {0, 1}, -}; -static const arc arcs_86_2[1] = { - {0, 2}, -}; -static state states_86[3] = { - {1, arcs_86_0}, - {2, arcs_86_1}, - {1, arcs_86_2}, -}; -static const arc arcs_87_0[2] = { - {22, 1}, - {80, 2}, -}; -static const arc arcs_87_1[1] = { - {58, 2}, -}; -static const arc arcs_87_2[1] = { - {0, 2}, -}; -static state states_87[3] = { - {2, arcs_87_0}, - {1, arcs_87_1}, - {1, arcs_87_2}, -}; -static const arc arcs_88_0[2] = { - {2, 1}, - {4, 2}, -}; -static const arc arcs_88_1[2] = { - {128, 3}, - {59, 4}, -}; -static const arc arcs_88_2[1] = { - {0, 2}, -}; -static const arc arcs_88_3[1] = { - {45, 5}, -}; -static const arc arcs_88_4[1] = { - {2, 6}, -}; -static const arc arcs_88_5[2] = { - {129, 2}, - {45, 5}, -}; -static const arc arcs_88_6[1] = { - {128, 3}, -}; -static state states_88[7] = { - {2, arcs_88_0}, - {2, arcs_88_1}, - {1, arcs_88_2}, - {1, arcs_88_3}, - {1, arcs_88_4}, - {2, arcs_88_5}, - {1, arcs_88_6}, -}; -static const arc arcs_89_0[1] = { - {181, 1}, -}; -static const arc arcs_89_1[2] = { - {44, 2}, - {2, 1}, -}; -static const arc arcs_89_2[1] = { - {0, 2}, -}; -static state states_89[3] = { - {1, arcs_89_0}, - {2, arcs_89_1}, - {1, arcs_89_2}, -}; -static const arc arcs_90_0[1] = { - {5, 1}, -}; -static const arc arcs_90_1[2] = { - {61, 2}, - {182, 3}, -}; -static const arc arcs_90_2[1] = { - {56, 4}, -}; -static const arc arcs_90_3[1] = { - {61, 2}, -}; -static const arc arcs_90_4[1] = { - {58, 5}, -}; -static const arc arcs_90_5[1] = { - {0, 5}, -}; -static state states_90[6] = { - {1, arcs_90_0}, - {2, arcs_90_1}, - {1, arcs_90_2}, - {1, arcs_90_3}, - {1, arcs_90_4}, - {1, arcs_90_5}, -}; -static const arc arcs_91_0[3] = { - {6, 1}, - {63, 2}, - {58, 3}, -}; -static const arc arcs_91_1[3] = { - {65, 4}, - {58, 5}, - {0, 1}, -}; -static const arc arcs_91_2[1] = { - {58, 6}, -}; -static const arc arcs_91_3[2] = { - {65, 7}, - {0, 3}, -}; -static const arc arcs_91_4[2] = { - {63, 2}, - {58, 5}, -}; -static const arc arcs_91_5[2] = { - {65, 4}, - {0, 5}, -}; -static const arc arcs_91_6[1] = { - {0, 6}, -}; -static const arc arcs_91_7[4] = { - {6, 8}, - {63, 2}, - {58, 3}, - {0, 7}, -}; -static const arc arcs_91_8[3] = { - {65, 9}, - {58, 10}, - {0, 8}, -}; -static const arc arcs_91_9[2] = { - {63, 2}, - {58, 10}, -}; -static const arc arcs_91_10[2] = { - {65, 9}, - {0, 10}, -}; -static state states_91[11] = { - {3, arcs_91_0}, - {3, arcs_91_1}, - {1, arcs_91_2}, - {2, arcs_91_3}, - {2, arcs_91_4}, - {2, arcs_91_5}, - {1, arcs_91_6}, - {4, arcs_91_7}, - {3, arcs_91_8}, - {2, arcs_91_9}, - {2, arcs_91_10}, -}; -static const dfa dfas[92] = { - {256, "single_input", 3, states_0, - "\344\377\377\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {257, "file_input", 2, states_1, - "\344\377\377\377\377\027\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {258, "eval_input", 3, states_2, - "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {259, "decorator", 4, states_3, - "\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {260, "decorators", 2, states_4, - "\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {261, "decorated", 3, states_5, - "\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {262, "async_funcdef", 3, states_6, - "\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {263, "funcdef", 9, states_7, - "\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {264, "parameters", 4, states_8, - "\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {265, "typedargslist", 42, states_9, - "\100\000\000\000\000\001\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {266, "tfpdef", 4, states_10, - "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {267, "varargslist", 34, states_11, - "\100\000\000\000\000\001\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {268, "vfpdef", 2, states_12, - "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {269, "stmt", 2, states_13, - "\340\377\377\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {270, "simple_stmt", 4, states_14, - "\340\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {271, "small_stmt", 2, states_15, - "\340\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {272, "expr_stmt", 6, states_16, - "\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {273, "annassign", 5, states_17, - "\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {274, "testlist_star_expr", 3, states_18, - "\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {275, "augassign", 2, states_19, - "\000\000\000\000\000\000\000\000\000\000\340\377\003\000\000\000\000\000\000\000\000\000\000"}, - {276, "del_stmt", 3, states_20, - "\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {277, "pass_stmt", 2, states_21, - "\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {278, "flow_stmt", 2, states_22, - "\000\000\005\300\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {279, "break_stmt", 2, states_23, - "\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {280, "continue_stmt", 2, states_24, - "\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {281, "return_stmt", 3, states_25, - "\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {282, "yield_stmt", 2, states_26, - "\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {283, "raise_stmt", 5, states_27, - "\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {284, "import_stmt", 2, states_28, - "\000\000\100\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {285, "import_name", 3, states_29, - "\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {286, "import_from", 8, states_30, - "\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {287, "import_as_name", 4, states_31, - "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {288, "dotted_as_name", 4, states_32, - "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {289, "import_as_names", 3, states_33, - "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {290, "dotted_as_names", 2, states_34, - "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {291, "dotted_name", 2, states_35, - "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {292, "global_stmt", 3, states_36, - "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {293, "nonlocal_stmt", 3, states_37, - "\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {294, "assert_stmt", 5, states_38, - "\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {295, "compound_stmt", 2, states_39, - "\000\004\052\001\107\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {296, "async_stmt", 3, states_40, - "\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {297, "if_stmt", 8, states_41, - "\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {298, "while_stmt", 8, states_42, - "\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {299, "for_stmt", 11, states_43, - "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {300, "try_stmt", 13, states_44, - "\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {301, "with_stmt", 6, states_45, - "\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {302, "with_item", 4, states_46, - "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {303, "except_clause", 5, states_47, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000"}, - {304, "suite", 5, states_48, - "\344\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {305, "namedexpr_test", 4, states_49, - "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {306, "test", 6, states_50, - "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {307, "test_nocond", 2, states_51, - "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {308, "lambdef", 5, states_52, - "\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {309, "lambdef_nocond", 5, states_53, - "\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {310, "or_test", 2, states_54, - "\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {311, "and_test", 2, states_55, - "\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {312, "not_test", 3, states_56, - "\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {313, "comparison", 2, states_57, - "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {314, "comp_op", 4, states_58, - "\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\004\000\340\017\000\000\000\000"}, - {315, "star_expr", 3, states_59, - "\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {316, "expr", 2, states_60, - "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {317, "xor_expr", 2, states_61, - "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {318, "and_expr", 2, states_62, - "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {319, "shift_expr", 2, states_63, - "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {320, "arith_expr", 2, states_64, - "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {321, "term", 2, states_65, - "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {322, "factor", 3, states_66, - "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {323, "power", 4, states_67, - "\040\172\000\000\220\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {324, "atom_expr", 3, states_68, - "\040\172\000\000\220\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {325, "atom", 9, states_69, - "\040\172\000\000\020\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {326, "testlist_comp", 5, states_70, - "\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {327, "trailer", 7, states_71, - "\040\100\000\000\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000"}, - {328, "subscriptlist", 3, states_72, - "\240\173\000\024\260\007\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {329, "subscript", 5, states_73, - "\240\173\000\024\260\007\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {330, "sliceop", 3, states_74, - "\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {331, "exprlist", 3, states_75, - "\340\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {332, "testlist", 3, states_76, - "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {333, "dictorsetmaker", 14, states_77, - "\340\173\000\024\260\007\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {334, "classdef", 8, states_78, - "\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {335, "arglist", 3, states_79, - "\340\173\000\024\260\007\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {336, "argument", 4, states_80, - "\340\173\000\024\260\007\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {337, "comp_iter", 2, states_81, - "\000\000\040\001\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {338, "sync_comp_for", 6, states_82, - "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {339, "comp_for", 3, states_83, - "\000\000\040\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {340, "comp_if", 4, states_84, - "\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {341, "encoding_decl", 2, states_85, - "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {342, "yield_expr", 3, states_86, - "\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {343, "yield_arg", 3, states_87, - "\340\173\100\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {344, "func_body_suite", 7, states_88, - "\344\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {345, "func_type_input", 3, states_89, - "\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {346, "func_type", 6, states_90, - "\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {347, "typelist", 11, states_91, - "\340\173\000\024\260\007\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, -}; -static const label labels[183] = { - {0, "EMPTY"}, - {256, 0}, - {4, 0}, - {295, 0}, - {270, 0}, - {7, 0}, - {16, 0}, - {14, 0}, - {15, 0}, - {52, 0}, - {49, 0}, - {1, "False"}, - {1, "None"}, - {1, "True"}, - {9, 0}, - {1, "assert"}, - {1, "break"}, - {1, "class"}, - {1, "continue"}, - {1, "def"}, - {1, "del"}, - {1, "for"}, - {1, "from"}, - {1, "global"}, - {1, "if"}, - {1, "import"}, - {1, "lambda"}, - {1, "nonlocal"}, - {1, "not"}, - {1, "pass"}, - {1, "raise"}, - {1, "return"}, - {1, "try"}, - {1, "while"}, - {1, "with"}, - {1, "yield"}, - {25, 0}, - {31, 0}, - {56, 0}, - {55, 0}, - {1, 0}, - {2, 0}, - {3, 0}, - {257, 0}, - {0, 0}, - {269, 0}, - {258, 0}, - {332, 0}, - {259, 0}, - {305, 0}, - {260, 0}, - {261, 0}, - {262, 0}, - {334, 0}, - {263, 0}, - {264, 0}, - {51, 0}, - {11, 0}, - {306, 0}, - {58, 0}, - {344, 0}, - {8, 0}, - {265, 0}, - {35, 0}, - {266, 0}, - {12, 0}, - {22, 0}, - {17, 0}, - {267, 0}, - {268, 0}, - {271, 0}, - {13, 0}, - {294, 0}, - {276, 0}, - {272, 0}, - {278, 0}, - {292, 0}, - {284, 0}, - {293, 0}, - {277, 0}, - {274, 0}, - {273, 0}, - {275, 0}, - {342, 0}, - {315, 0}, - {40, 0}, - {41, 0}, - {46, 0}, - {38, 0}, - {36, 0}, - {37, 0}, - {48, 0}, - {39, 0}, - {44, 0}, - {45, 0}, - {50, 0}, - {43, 0}, - {42, 0}, - {331, 0}, - {279, 0}, - {280, 0}, - {283, 0}, - {281, 0}, - {282, 0}, - {286, 0}, - {285, 0}, - {290, 0}, - {23, 0}, - {291, 0}, - {289, 0}, - {287, 0}, - {1, "as"}, - {288, 0}, - {296, 0}, - {299, 0}, - {297, 0}, - {300, 0}, - {298, 0}, - {301, 0}, - {304, 0}, - {1, "elif"}, - {1, "else"}, - {1, "in"}, - {1, "finally"}, - {303, 0}, - {302, 0}, - {316, 0}, - {1, "except"}, - {5, 0}, - {6, 0}, - {53, 0}, - {308, 0}, - {310, 0}, - {307, 0}, - {309, 0}, - {311, 0}, - {1, "or"}, - {312, 0}, - {1, "and"}, - {313, 0}, - {314, 0}, - {28, 0}, - {20, 0}, - {29, 0}, - {27, 0}, - {21, 0}, - {30, 0}, - {1, "is"}, - {317, 0}, - {18, 0}, - {318, 0}, - {32, 0}, - {319, 0}, - {19, 0}, - {320, 0}, - {33, 0}, - {34, 0}, - {321, 0}, - {322, 0}, - {24, 0}, - {47, 0}, - {323, 0}, - {324, 0}, - {325, 0}, - {327, 0}, - {326, 0}, - {10, 0}, - {26, 0}, - {333, 0}, - {339, 0}, - {335, 0}, - {328, 0}, - {329, 0}, - {330, 0}, - {336, 0}, - {337, 0}, - {340, 0}, - {338, 0}, - {341, 0}, - {343, 0}, - {345, 0}, - {346, 0}, - {347, 0}, -}; -Py_EXPORTED_SYMBOL grammar _PyParser_Grammar = { - 92, - dfas, - {183, labels}, - 256 -}; diff --git a/Python/hamt.c b/Python/hamt.c index 8801c5ea418..e272e8808fd 100644 --- a/Python/hamt.c +++ b/Python/hamt.c @@ -1,5 +1,6 @@ #include "Python.h" +#include "pycore_bitutils.h" // _Py_popcount32 #include "pycore_hamt.h" #include "pycore_object.h" // _PyObject_GC_TRACK() #include // offsetof() @@ -433,30 +434,10 @@ hamt_bitpos(int32_t hash, uint32_t shift) return (uint32_t)1 << hamt_mask(hash, shift); } -static inline uint32_t -hamt_bitcount(uint32_t i) -{ - /* We could use native popcount instruction but that would - require to either add configure flags to enable SSE4.2 - support or to detect it dynamically. Otherwise, we have - a risk of CPython not working properly on older hardware. - - In practice, there's no observable difference in - performance between using a popcount instruction or the - following fallback code. - - The algorithm is copied from: - https://graphics.stanford.edu/~seander/bithacks.html - */ - i = i - ((i >> 1) & 0x55555555); - i = (i & 0x33333333) + ((i >> 2) & 0x33333333); - return (((i + (i >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; -} - static inline uint32_t hamt_bitindex(uint32_t bitmap, uint32_t bit) { - return hamt_bitcount(bitmap & (bit - 1)); + return (uint32_t)_Py_popcount32(bitmap & (bit - 1)); } @@ -820,7 +801,7 @@ hamt_node_bitmap_assoc(PyHamtNode_Bitmap *self, else { /* There was no key before with the same (shift,hash). */ - uint32_t n = hamt_bitcount(self->b_bitmap); + uint32_t n = (uint32_t)_Py_popcount32(self->b_bitmap); if (n >= 16) { /* When we have a situation where we want to store more diff --git a/Python/hashtable.c b/Python/hashtable.c index b92e8ca08c7..09501de199b 100644 --- a/Python/hashtable.c +++ b/Python/hashtable.c @@ -133,7 +133,7 @@ _Py_hashtable_get_entry_generic(_Py_hashtable_t *ht, const void *key) { Py_uhash_t key_hash = ht->hash_func(key); size_t index = key_hash & (ht->nbuckets - 1); - _Py_hashtable_entry_t *entry = entry = TABLE_HEAD(ht, index); + _Py_hashtable_entry_t *entry = TABLE_HEAD(ht, index); while (1) { if (entry == NULL) { return NULL; @@ -155,7 +155,7 @@ _Py_hashtable_get_entry_ptr(_Py_hashtable_t *ht, const void *key) { Py_uhash_t key_hash = _Py_hashtable_hash_ptr(key); size_t index = key_hash & (ht->nbuckets - 1); - _Py_hashtable_entry_t *entry = entry = TABLE_HEAD(ht, index); + _Py_hashtable_entry_t *entry = TABLE_HEAD(ht, index); while (1) { if (entry == NULL) { return NULL; diff --git a/Python/import.c b/Python/import.c index 0e2e7c37086..505688400ef 100644 --- a/Python/import.c +++ b/Python/import.c @@ -148,7 +148,7 @@ _PyImportZip_Init(PyThreadState *tstate) in different threads to return with a partially loaded module. These calls are serialized by the global interpreter lock. */ -static PyThread_type_lock import_lock = 0; +static PyThread_type_lock import_lock = NULL; static unsigned long import_lock_thread = PYTHREAD_INVALID_THREAD_ID; static int import_lock_level = 0; @@ -171,7 +171,7 @@ _PyImport_AcquireLock(void) !PyThread_acquire_lock(import_lock, 0)) { PyThreadState *tstate = PyEval_SaveThread(); - PyThread_acquire_lock(import_lock, 1); + PyThread_acquire_lock(import_lock, WAIT_LOCK); PyEval_RestoreThread(tstate); } assert(import_lock_level == 0); @@ -197,33 +197,30 @@ _PyImport_ReleaseLock(void) } #ifdef HAVE_FORK -/* This function is called from PyOS_AfterFork_Child to ensure that newly +/* This function is called from PyOS_AfterFork_Child() to ensure that newly created child processes do not share locks with the parent. We now acquire the import lock around fork() calls but on some platforms (Solaris 9 and earlier? see isue7242) that still left us with problems. */ - -void +PyStatus _PyImport_ReInitLock(void) { if (import_lock != NULL) { if (_PyThread_at_fork_reinit(&import_lock) < 0) { - _Py_FatalErrorFunc(__func__, "failed to create a new lock"); + return _PyStatus_ERR("failed to create a new lock"); } } + if (import_lock_level > 1) { /* Forked as a side effect of import */ unsigned long me = PyThread_get_thread_ident(); - /* The following could fail if the lock is already held, but forking as - a side-effect of an import is a) rare, b) nuts, and c) difficult to - do thanks to the lock only being held when doing individual module - locks per import. */ - PyThread_acquire_lock(import_lock, NOWAIT_LOCK); + PyThread_acquire_lock(import_lock, WAIT_LOCK); import_lock_thread = me; import_lock_level--; } else { import_lock_thread = PYTHREAD_INVALID_THREAD_ID; import_lock_level = 0; } + return _PyStatus_OK(); } #endif diff --git a/Python/importlib.h b/Python/importlib.h index 59e0272b61d..1fb877a7534 100644 --- a/Python/importlib.h +++ b/Python/importlib.h @@ -1594,219 +1594,219 @@ const unsigned char _Py_M__importlib_bootstrap[] = { 0,218,1,120,90,5,119,104,101,114,101,90,9,102,114,111, 109,95,110,97,109,101,90,3,101,120,99,114,10,0,0,0, 114,10,0,0,0,114,11,0,0,0,114,215,0,0,0,9, - 4,0,0,115,52,0,0,0,0,10,8,1,10,1,4,1, - 12,2,4,1,4,1,2,255,4,1,8,255,10,2,8,1, - 14,1,10,1,2,255,8,2,10,1,14,1,2,1,14,1, - 14,4,10,1,16,255,2,2,12,1,26,1,114,215,0,0, - 0,99,1,0,0,0,0,0,0,0,0,0,0,0,3,0, - 0,0,6,0,0,0,67,0,0,0,115,146,0,0,0,124, - 0,160,0,100,1,161,1,125,1,124,0,160,0,100,2,161, - 1,125,2,124,1,100,3,117,1,114,82,124,2,100,3,117, - 1,114,78,124,1,124,2,106,1,107,3,114,78,116,2,106, - 3,100,4,124,1,155,2,100,5,124,2,106,1,155,2,100, - 6,157,5,116,4,100,7,100,8,141,3,1,0,124,1,83, - 0,124,2,100,3,117,1,114,96,124,2,106,1,83,0,116, - 2,106,3,100,9,116,4,100,7,100,8,141,3,1,0,124, - 0,100,10,25,0,125,1,100,11,124,0,118,1,114,142,124, - 1,160,5,100,12,161,1,100,13,25,0,125,1,124,1,83, - 0,41,14,122,167,67,97,108,99,117,108,97,116,101,32,119, - 104,97,116,32,95,95,112,97,99,107,97,103,101,95,95,32, - 115,104,111,117,108,100,32,98,101,46,10,10,32,32,32,32, - 95,95,112,97,99,107,97,103,101,95,95,32,105,115,32,110, - 111,116,32,103,117,97,114,97,110,116,101,101,100,32,116,111, - 32,98,101,32,100,101,102,105,110,101,100,32,111,114,32,99, - 111,117,108,100,32,98,101,32,115,101,116,32,116,111,32,78, - 111,110,101,10,32,32,32,32,116,111,32,114,101,112,114,101, - 115,101,110,116,32,116,104,97,116,32,105,116,115,32,112,114, - 111,112,101,114,32,118,97,108,117,101,32,105,115,32,117,110, - 107,110,111,119,110,46,10,10,32,32,32,32,114,146,0,0, - 0,114,106,0,0,0,78,122,32,95,95,112,97,99,107,97, - 103,101,95,95,32,33,61,32,95,95,115,112,101,99,95,95, - 46,112,97,114,101,110,116,32,40,122,4,32,33,61,32,250, - 1,41,233,3,0,0,0,41,1,90,10,115,116,97,99,107, - 108,101,118,101,108,122,89,99,97,110,39,116,32,114,101,115, - 111,108,118,101,32,112,97,99,107,97,103,101,32,102,114,111, - 109,32,95,95,115,112,101,99,95,95,32,111,114,32,95,95, - 112,97,99,107,97,103,101,95,95,44,32,102,97,108,108,105, - 110,103,32,98,97,99,107,32,111,110,32,95,95,110,97,109, - 101,95,95,32,97,110,100,32,95,95,112,97,116,104,95,95, - 114,1,0,0,0,114,142,0,0,0,114,129,0,0,0,114, - 22,0,0,0,41,6,114,35,0,0,0,114,131,0,0,0, - 114,193,0,0,0,114,194,0,0,0,114,195,0,0,0,114, - 130,0,0,0,41,3,218,7,103,108,111,98,97,108,115,114, - 187,0,0,0,114,96,0,0,0,114,10,0,0,0,114,10, - 0,0,0,114,11,0,0,0,218,17,95,99,97,108,99,95, - 95,95,112,97,99,107,97,103,101,95,95,46,4,0,0,115, - 42,0,0,0,0,7,10,1,10,1,8,1,18,1,6,1, - 2,255,4,1,4,255,6,2,4,254,6,3,4,1,8,1, - 6,2,6,2,4,254,6,3,8,1,8,1,14,1,114,221, - 0,0,0,114,10,0,0,0,99,5,0,0,0,0,0,0, - 0,0,0,0,0,9,0,0,0,5,0,0,0,67,0,0, - 0,115,180,0,0,0,124,4,100,1,107,2,114,18,116,0, - 124,0,131,1,125,5,110,36,124,1,100,2,117,1,114,30, - 124,1,110,2,105,0,125,6,116,1,124,6,131,1,125,7, - 116,0,124,0,124,7,124,4,131,3,125,5,124,3,115,150, - 124,4,100,1,107,2,114,84,116,0,124,0,160,2,100,3, - 161,1,100,1,25,0,131,1,83,0,124,0,115,92,124,5, - 83,0,116,3,124,0,131,1,116,3,124,0,160,2,100,3, - 161,1,100,1,25,0,131,1,24,0,125,8,116,4,106,5, - 124,5,106,6,100,2,116,3,124,5,106,6,131,1,124,8, - 24,0,133,2,25,0,25,0,83,0,110,26,116,7,124,5, - 100,4,131,2,114,172,116,8,124,5,124,3,116,0,131,3, - 83,0,124,5,83,0,100,2,83,0,41,5,97,215,1,0, - 0,73,109,112,111,114,116,32,97,32,109,111,100,117,108,101, - 46,10,10,32,32,32,32,84,104,101,32,39,103,108,111,98, - 97,108,115,39,32,97,114,103,117,109,101,110,116,32,105,115, - 32,117,115,101,100,32,116,111,32,105,110,102,101,114,32,119, - 104,101,114,101,32,116,104,101,32,105,109,112,111,114,116,32, - 105,115,32,111,99,99,117,114,114,105,110,103,32,102,114,111, - 109,10,32,32,32,32,116,111,32,104,97,110,100,108,101,32, - 114,101,108,97,116,105,118,101,32,105,109,112,111,114,116,115, - 46,32,84,104,101,32,39,108,111,99,97,108,115,39,32,97, - 114,103,117,109,101,110,116,32,105,115,32,105,103,110,111,114, - 101,100,46,32,84,104,101,10,32,32,32,32,39,102,114,111, - 109,108,105,115,116,39,32,97,114,103,117,109,101,110,116,32, - 115,112,101,99,105,102,105,101,115,32,119,104,97,116,32,115, - 104,111,117,108,100,32,101,120,105,115,116,32,97,115,32,97, - 116,116,114,105,98,117,116,101,115,32,111,110,32,116,104,101, - 32,109,111,100,117,108,101,10,32,32,32,32,98,101,105,110, - 103,32,105,109,112,111,114,116,101,100,32,40,101,46,103,46, - 32,96,96,102,114,111,109,32,109,111,100,117,108,101,32,105, - 109,112,111,114,116,32,60,102,114,111,109,108,105,115,116,62, - 96,96,41,46,32,32,84,104,101,32,39,108,101,118,101,108, - 39,10,32,32,32,32,97,114,103,117,109,101,110,116,32,114, - 101,112,114,101,115,101,110,116,115,32,116,104,101,32,112,97, - 99,107,97,103,101,32,108,111,99,97,116,105,111,110,32,116, - 111,32,105,109,112,111,114,116,32,102,114,111,109,32,105,110, - 32,97,32,114,101,108,97,116,105,118,101,10,32,32,32,32, - 105,109,112,111,114,116,32,40,101,46,103,46,32,96,96,102, - 114,111,109,32,46,46,112,107,103,32,105,109,112,111,114,116, - 32,109,111,100,96,96,32,119,111,117,108,100,32,104,97,118, - 101,32,97,32,39,108,101,118,101,108,39,32,111,102,32,50, - 41,46,10,10,32,32,32,32,114,22,0,0,0,78,114,129, - 0,0,0,114,142,0,0,0,41,9,114,210,0,0,0,114, - 221,0,0,0,218,9,112,97,114,116,105,116,105,111,110,114, - 186,0,0,0,114,15,0,0,0,114,93,0,0,0,114,1, - 0,0,0,114,4,0,0,0,114,215,0,0,0,41,9,114, - 17,0,0,0,114,220,0,0,0,218,6,108,111,99,97,108, - 115,114,216,0,0,0,114,188,0,0,0,114,97,0,0,0, - 90,8,103,108,111,98,97,108,115,95,114,187,0,0,0,90, - 7,99,117,116,95,111,102,102,114,10,0,0,0,114,10,0, - 0,0,114,11,0,0,0,218,10,95,95,105,109,112,111,114, - 116,95,95,73,4,0,0,115,30,0,0,0,0,11,8,1, - 10,2,16,1,8,1,12,1,4,3,8,1,18,1,4,1, - 4,4,26,3,32,1,10,1,12,2,114,224,0,0,0,99, - 1,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, - 3,0,0,0,67,0,0,0,115,38,0,0,0,116,0,160, - 1,124,0,161,1,125,1,124,1,100,0,117,0,114,30,116, - 2,100,1,124,0,23,0,131,1,130,1,116,3,124,1,131, - 1,83,0,41,2,78,122,25,110,111,32,98,117,105,108,116, - 45,105,110,32,109,111,100,117,108,101,32,110,97,109,101,100, - 32,41,4,114,161,0,0,0,114,168,0,0,0,114,80,0, - 0,0,114,160,0,0,0,41,2,114,17,0,0,0,114,96, - 0,0,0,114,10,0,0,0,114,10,0,0,0,114,11,0, - 0,0,218,18,95,98,117,105,108,116,105,110,95,102,114,111, - 109,95,110,97,109,101,110,4,0,0,115,8,0,0,0,0, - 1,10,1,8,1,12,1,114,225,0,0,0,99,2,0,0, - 0,0,0,0,0,0,0,0,0,10,0,0,0,5,0,0, - 0,67,0,0,0,115,166,0,0,0,124,1,97,0,124,0, - 97,1,116,2,116,1,131,1,125,2,116,1,106,3,160,4, - 161,0,68,0,93,72,92,2,125,3,125,4,116,5,124,4, - 124,2,131,2,114,26,124,3,116,1,106,6,118,0,114,60, - 116,7,125,5,110,18,116,0,160,8,124,3,161,1,114,26, - 116,9,125,5,110,2,113,26,116,10,124,4,124,5,131,2, - 125,6,116,11,124,6,124,4,131,2,1,0,113,26,116,1, - 106,3,116,12,25,0,125,7,100,1,68,0,93,46,125,8, - 124,8,116,1,106,3,118,1,114,138,116,13,124,8,131,1, - 125,9,110,10,116,1,106,3,124,8,25,0,125,9,116,14, - 124,7,124,8,124,9,131,3,1,0,113,114,100,2,83,0, - 41,3,122,250,83,101,116,117,112,32,105,109,112,111,114,116, - 108,105,98,32,98,121,32,105,109,112,111,114,116,105,110,103, - 32,110,101,101,100,101,100,32,98,117,105,108,116,45,105,110, - 32,109,111,100,117,108,101,115,32,97,110,100,32,105,110,106, - 101,99,116,105,110,103,32,116,104,101,109,10,32,32,32,32, - 105,110,116,111,32,116,104,101,32,103,108,111,98,97,108,32, - 110,97,109,101,115,112,97,99,101,46,10,10,32,32,32,32, - 65,115,32,115,121,115,32,105,115,32,110,101,101,100,101,100, - 32,102,111,114,32,115,121,115,46,109,111,100,117,108,101,115, - 32,97,99,99,101,115,115,32,97,110,100,32,95,105,109,112, - 32,105,115,32,110,101,101,100,101,100,32,116,111,32,108,111, - 97,100,32,98,117,105,108,116,45,105,110,10,32,32,32,32, - 109,111,100,117,108,101,115,44,32,116,104,111,115,101,32,116, - 119,111,32,109,111,100,117,108,101,115,32,109,117,115,116,32, - 98,101,32,101,120,112,108,105,99,105,116,108,121,32,112,97, - 115,115,101,100,32,105,110,46,10,10,32,32,32,32,41,3, - 114,23,0,0,0,114,193,0,0,0,114,65,0,0,0,78, - 41,15,114,58,0,0,0,114,15,0,0,0,114,14,0,0, - 0,114,93,0,0,0,218,5,105,116,101,109,115,114,197,0, - 0,0,114,79,0,0,0,114,161,0,0,0,114,89,0,0, - 0,114,175,0,0,0,114,143,0,0,0,114,149,0,0,0, - 114,1,0,0,0,114,225,0,0,0,114,5,0,0,0,41, - 10,218,10,115,121,115,95,109,111,100,117,108,101,218,11,95, - 105,109,112,95,109,111,100,117,108,101,90,11,109,111,100,117, - 108,101,95,116,121,112,101,114,17,0,0,0,114,97,0,0, - 0,114,110,0,0,0,114,96,0,0,0,90,11,115,101,108, - 102,95,109,111,100,117,108,101,90,12,98,117,105,108,116,105, - 110,95,110,97,109,101,90,14,98,117,105,108,116,105,110,95, - 109,111,100,117,108,101,114,10,0,0,0,114,10,0,0,0, - 114,11,0,0,0,218,6,95,115,101,116,117,112,117,4,0, - 0,115,36,0,0,0,0,9,4,1,4,3,8,1,18,1, - 10,1,10,1,6,1,10,1,6,2,2,1,10,1,12,3, - 10,1,8,1,10,1,10,2,10,1,114,229,0,0,0,99, - 2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, - 3,0,0,0,67,0,0,0,115,38,0,0,0,116,0,124, - 0,124,1,131,2,1,0,116,1,106,2,160,3,116,4,161, - 1,1,0,116,1,106,2,160,3,116,5,161,1,1,0,100, - 1,83,0,41,2,122,48,73,110,115,116,97,108,108,32,105, - 109,112,111,114,116,101,114,115,32,102,111,114,32,98,117,105, - 108,116,105,110,32,97,110,100,32,102,114,111,122,101,110,32, - 109,111,100,117,108,101,115,78,41,6,114,229,0,0,0,114, - 15,0,0,0,114,192,0,0,0,114,120,0,0,0,114,161, - 0,0,0,114,175,0,0,0,41,2,114,227,0,0,0,114, - 228,0,0,0,114,10,0,0,0,114,10,0,0,0,114,11, - 0,0,0,218,8,95,105,110,115,116,97,108,108,152,4,0, - 0,115,6,0,0,0,0,2,10,2,12,1,114,230,0,0, - 0,99,0,0,0,0,0,0,0,0,0,0,0,0,1,0, - 0,0,4,0,0,0,67,0,0,0,115,32,0,0,0,100, - 1,100,2,108,0,125,0,124,0,97,1,124,0,160,2,116, - 3,106,4,116,5,25,0,161,1,1,0,100,2,83,0,41, - 3,122,57,73,110,115,116,97,108,108,32,105,109,112,111,114, - 116,101,114,115,32,116,104,97,116,32,114,101,113,117,105,114, - 101,32,101,120,116,101,114,110,97,108,32,102,105,108,101,115, - 121,115,116,101,109,32,97,99,99,101,115,115,114,22,0,0, - 0,78,41,6,218,26,95,102,114,111,122,101,110,95,105,109, - 112,111,114,116,108,105,98,95,101,120,116,101,114,110,97,108, - 114,127,0,0,0,114,230,0,0,0,114,15,0,0,0,114, - 93,0,0,0,114,1,0,0,0,41,1,114,231,0,0,0, + 4,0,0,115,48,0,0,0,0,10,8,1,10,1,4,1, + 12,2,4,1,10,1,8,255,10,2,8,1,14,1,10,1, + 2,255,8,2,10,1,14,1,2,1,14,1,14,4,10,1, + 16,255,2,2,12,1,26,1,114,215,0,0,0,99,1,0, + 0,0,0,0,0,0,0,0,0,0,3,0,0,0,6,0, + 0,0,67,0,0,0,115,146,0,0,0,124,0,160,0,100, + 1,161,1,125,1,124,0,160,0,100,2,161,1,125,2,124, + 1,100,3,117,1,114,82,124,2,100,3,117,1,114,78,124, + 1,124,2,106,1,107,3,114,78,116,2,106,3,100,4,124, + 1,155,2,100,5,124,2,106,1,155,2,100,6,157,5,116, + 4,100,7,100,8,141,3,1,0,124,1,83,0,124,2,100, + 3,117,1,114,96,124,2,106,1,83,0,116,2,106,3,100, + 9,116,4,100,7,100,8,141,3,1,0,124,0,100,10,25, + 0,125,1,100,11,124,0,118,1,114,142,124,1,160,5,100, + 12,161,1,100,13,25,0,125,1,124,1,83,0,41,14,122, + 167,67,97,108,99,117,108,97,116,101,32,119,104,97,116,32, + 95,95,112,97,99,107,97,103,101,95,95,32,115,104,111,117, + 108,100,32,98,101,46,10,10,32,32,32,32,95,95,112,97, + 99,107,97,103,101,95,95,32,105,115,32,110,111,116,32,103, + 117,97,114,97,110,116,101,101,100,32,116,111,32,98,101,32, + 100,101,102,105,110,101,100,32,111,114,32,99,111,117,108,100, + 32,98,101,32,115,101,116,32,116,111,32,78,111,110,101,10, + 32,32,32,32,116,111,32,114,101,112,114,101,115,101,110,116, + 32,116,104,97,116,32,105,116,115,32,112,114,111,112,101,114, + 32,118,97,108,117,101,32,105,115,32,117,110,107,110,111,119, + 110,46,10,10,32,32,32,32,114,146,0,0,0,114,106,0, + 0,0,78,122,32,95,95,112,97,99,107,97,103,101,95,95, + 32,33,61,32,95,95,115,112,101,99,95,95,46,112,97,114, + 101,110,116,32,40,122,4,32,33,61,32,250,1,41,233,3, + 0,0,0,41,1,90,10,115,116,97,99,107,108,101,118,101, + 108,122,89,99,97,110,39,116,32,114,101,115,111,108,118,101, + 32,112,97,99,107,97,103,101,32,102,114,111,109,32,95,95, + 115,112,101,99,95,95,32,111,114,32,95,95,112,97,99,107, + 97,103,101,95,95,44,32,102,97,108,108,105,110,103,32,98, + 97,99,107,32,111,110,32,95,95,110,97,109,101,95,95,32, + 97,110,100,32,95,95,112,97,116,104,95,95,114,1,0,0, + 0,114,142,0,0,0,114,129,0,0,0,114,22,0,0,0, + 41,6,114,35,0,0,0,114,131,0,0,0,114,193,0,0, + 0,114,194,0,0,0,114,195,0,0,0,114,130,0,0,0, + 41,3,218,7,103,108,111,98,97,108,115,114,187,0,0,0, + 114,96,0,0,0,114,10,0,0,0,114,10,0,0,0,114, + 11,0,0,0,218,17,95,99,97,108,99,95,95,95,112,97, + 99,107,97,103,101,95,95,46,4,0,0,115,42,0,0,0, + 0,7,10,1,10,1,8,1,18,1,6,1,2,255,4,1, + 4,255,6,2,4,254,6,3,4,1,8,1,6,2,6,2, + 4,254,6,3,8,1,8,1,14,1,114,221,0,0,0,114, + 10,0,0,0,99,5,0,0,0,0,0,0,0,0,0,0, + 0,9,0,0,0,5,0,0,0,67,0,0,0,115,180,0, + 0,0,124,4,100,1,107,2,114,18,116,0,124,0,131,1, + 125,5,110,36,124,1,100,2,117,1,114,30,124,1,110,2, + 105,0,125,6,116,1,124,6,131,1,125,7,116,0,124,0, + 124,7,124,4,131,3,125,5,124,3,115,150,124,4,100,1, + 107,2,114,84,116,0,124,0,160,2,100,3,161,1,100,1, + 25,0,131,1,83,0,124,0,115,92,124,5,83,0,116,3, + 124,0,131,1,116,3,124,0,160,2,100,3,161,1,100,1, + 25,0,131,1,24,0,125,8,116,4,106,5,124,5,106,6, + 100,2,116,3,124,5,106,6,131,1,124,8,24,0,133,2, + 25,0,25,0,83,0,110,26,116,7,124,5,100,4,131,2, + 114,172,116,8,124,5,124,3,116,0,131,3,83,0,124,5, + 83,0,100,2,83,0,41,5,97,215,1,0,0,73,109,112, + 111,114,116,32,97,32,109,111,100,117,108,101,46,10,10,32, + 32,32,32,84,104,101,32,39,103,108,111,98,97,108,115,39, + 32,97,114,103,117,109,101,110,116,32,105,115,32,117,115,101, + 100,32,116,111,32,105,110,102,101,114,32,119,104,101,114,101, + 32,116,104,101,32,105,109,112,111,114,116,32,105,115,32,111, + 99,99,117,114,114,105,110,103,32,102,114,111,109,10,32,32, + 32,32,116,111,32,104,97,110,100,108,101,32,114,101,108,97, + 116,105,118,101,32,105,109,112,111,114,116,115,46,32,84,104, + 101,32,39,108,111,99,97,108,115,39,32,97,114,103,117,109, + 101,110,116,32,105,115,32,105,103,110,111,114,101,100,46,32, + 84,104,101,10,32,32,32,32,39,102,114,111,109,108,105,115, + 116,39,32,97,114,103,117,109,101,110,116,32,115,112,101,99, + 105,102,105,101,115,32,119,104,97,116,32,115,104,111,117,108, + 100,32,101,120,105,115,116,32,97,115,32,97,116,116,114,105, + 98,117,116,101,115,32,111,110,32,116,104,101,32,109,111,100, + 117,108,101,10,32,32,32,32,98,101,105,110,103,32,105,109, + 112,111,114,116,101,100,32,40,101,46,103,46,32,96,96,102, + 114,111,109,32,109,111,100,117,108,101,32,105,109,112,111,114, + 116,32,60,102,114,111,109,108,105,115,116,62,96,96,41,46, + 32,32,84,104,101,32,39,108,101,118,101,108,39,10,32,32, + 32,32,97,114,103,117,109,101,110,116,32,114,101,112,114,101, + 115,101,110,116,115,32,116,104,101,32,112,97,99,107,97,103, + 101,32,108,111,99,97,116,105,111,110,32,116,111,32,105,109, + 112,111,114,116,32,102,114,111,109,32,105,110,32,97,32,114, + 101,108,97,116,105,118,101,10,32,32,32,32,105,109,112,111, + 114,116,32,40,101,46,103,46,32,96,96,102,114,111,109,32, + 46,46,112,107,103,32,105,109,112,111,114,116,32,109,111,100, + 96,96,32,119,111,117,108,100,32,104,97,118,101,32,97,32, + 39,108,101,118,101,108,39,32,111,102,32,50,41,46,10,10, + 32,32,32,32,114,22,0,0,0,78,114,129,0,0,0,114, + 142,0,0,0,41,9,114,210,0,0,0,114,221,0,0,0, + 218,9,112,97,114,116,105,116,105,111,110,114,186,0,0,0, + 114,15,0,0,0,114,93,0,0,0,114,1,0,0,0,114, + 4,0,0,0,114,215,0,0,0,41,9,114,17,0,0,0, + 114,220,0,0,0,218,6,108,111,99,97,108,115,114,216,0, + 0,0,114,188,0,0,0,114,97,0,0,0,90,8,103,108, + 111,98,97,108,115,95,114,187,0,0,0,90,7,99,117,116, + 95,111,102,102,114,10,0,0,0,114,10,0,0,0,114,11, + 0,0,0,218,10,95,95,105,109,112,111,114,116,95,95,73, + 4,0,0,115,30,0,0,0,0,11,8,1,10,2,16,1, + 8,1,12,1,4,3,8,1,18,1,4,1,4,4,26,3, + 32,1,10,1,12,2,114,224,0,0,0,99,1,0,0,0, + 0,0,0,0,0,0,0,0,2,0,0,0,3,0,0,0, + 67,0,0,0,115,38,0,0,0,116,0,160,1,124,0,161, + 1,125,1,124,1,100,0,117,0,114,30,116,2,100,1,124, + 0,23,0,131,1,130,1,116,3,124,1,131,1,83,0,41, + 2,78,122,25,110,111,32,98,117,105,108,116,45,105,110,32, + 109,111,100,117,108,101,32,110,97,109,101,100,32,41,4,114, + 161,0,0,0,114,168,0,0,0,114,80,0,0,0,114,160, + 0,0,0,41,2,114,17,0,0,0,114,96,0,0,0,114, + 10,0,0,0,114,10,0,0,0,114,11,0,0,0,218,18, + 95,98,117,105,108,116,105,110,95,102,114,111,109,95,110,97, + 109,101,110,4,0,0,115,8,0,0,0,0,1,10,1,8, + 1,12,1,114,225,0,0,0,99,2,0,0,0,0,0,0, + 0,0,0,0,0,10,0,0,0,5,0,0,0,67,0,0, + 0,115,166,0,0,0,124,1,97,0,124,0,97,1,116,2, + 116,1,131,1,125,2,116,1,106,3,160,4,161,0,68,0, + 93,72,92,2,125,3,125,4,116,5,124,4,124,2,131,2, + 114,26,124,3,116,1,106,6,118,0,114,60,116,7,125,5, + 110,18,116,0,160,8,124,3,161,1,114,26,116,9,125,5, + 110,2,113,26,116,10,124,4,124,5,131,2,125,6,116,11, + 124,6,124,4,131,2,1,0,113,26,116,1,106,3,116,12, + 25,0,125,7,100,1,68,0,93,46,125,8,124,8,116,1, + 106,3,118,1,114,138,116,13,124,8,131,1,125,9,110,10, + 116,1,106,3,124,8,25,0,125,9,116,14,124,7,124,8, + 124,9,131,3,1,0,113,114,100,2,83,0,41,3,122,250, + 83,101,116,117,112,32,105,109,112,111,114,116,108,105,98,32, + 98,121,32,105,109,112,111,114,116,105,110,103,32,110,101,101, + 100,101,100,32,98,117,105,108,116,45,105,110,32,109,111,100, + 117,108,101,115,32,97,110,100,32,105,110,106,101,99,116,105, + 110,103,32,116,104,101,109,10,32,32,32,32,105,110,116,111, + 32,116,104,101,32,103,108,111,98,97,108,32,110,97,109,101, + 115,112,97,99,101,46,10,10,32,32,32,32,65,115,32,115, + 121,115,32,105,115,32,110,101,101,100,101,100,32,102,111,114, + 32,115,121,115,46,109,111,100,117,108,101,115,32,97,99,99, + 101,115,115,32,97,110,100,32,95,105,109,112,32,105,115,32, + 110,101,101,100,101,100,32,116,111,32,108,111,97,100,32,98, + 117,105,108,116,45,105,110,10,32,32,32,32,109,111,100,117, + 108,101,115,44,32,116,104,111,115,101,32,116,119,111,32,109, + 111,100,117,108,101,115,32,109,117,115,116,32,98,101,32,101, + 120,112,108,105,99,105,116,108,121,32,112,97,115,115,101,100, + 32,105,110,46,10,10,32,32,32,32,41,3,114,23,0,0, + 0,114,193,0,0,0,114,65,0,0,0,78,41,15,114,58, + 0,0,0,114,15,0,0,0,114,14,0,0,0,114,93,0, + 0,0,218,5,105,116,101,109,115,114,197,0,0,0,114,79, + 0,0,0,114,161,0,0,0,114,89,0,0,0,114,175,0, + 0,0,114,143,0,0,0,114,149,0,0,0,114,1,0,0, + 0,114,225,0,0,0,114,5,0,0,0,41,10,218,10,115, + 121,115,95,109,111,100,117,108,101,218,11,95,105,109,112,95, + 109,111,100,117,108,101,90,11,109,111,100,117,108,101,95,116, + 121,112,101,114,17,0,0,0,114,97,0,0,0,114,110,0, + 0,0,114,96,0,0,0,90,11,115,101,108,102,95,109,111, + 100,117,108,101,90,12,98,117,105,108,116,105,110,95,110,97, + 109,101,90,14,98,117,105,108,116,105,110,95,109,111,100,117, + 108,101,114,10,0,0,0,114,10,0,0,0,114,11,0,0, + 0,218,6,95,115,101,116,117,112,117,4,0,0,115,36,0, + 0,0,0,9,4,1,4,3,8,1,18,1,10,1,10,1, + 6,1,10,1,6,2,2,1,10,1,12,3,10,1,8,1, + 10,1,10,2,10,1,114,229,0,0,0,99,2,0,0,0, + 0,0,0,0,0,0,0,0,2,0,0,0,3,0,0,0, + 67,0,0,0,115,38,0,0,0,116,0,124,0,124,1,131, + 2,1,0,116,1,106,2,160,3,116,4,161,1,1,0,116, + 1,106,2,160,3,116,5,161,1,1,0,100,1,83,0,41, + 2,122,48,73,110,115,116,97,108,108,32,105,109,112,111,114, + 116,101,114,115,32,102,111,114,32,98,117,105,108,116,105,110, + 32,97,110,100,32,102,114,111,122,101,110,32,109,111,100,117, + 108,101,115,78,41,6,114,229,0,0,0,114,15,0,0,0, + 114,192,0,0,0,114,120,0,0,0,114,161,0,0,0,114, + 175,0,0,0,41,2,114,227,0,0,0,114,228,0,0,0, 114,10,0,0,0,114,10,0,0,0,114,11,0,0,0,218, - 27,95,105,110,115,116,97,108,108,95,101,120,116,101,114,110, - 97,108,95,105,109,112,111,114,116,101,114,115,160,4,0,0, - 115,6,0,0,0,0,3,8,1,4,1,114,232,0,0,0, - 41,2,78,78,41,1,78,41,2,78,114,22,0,0,0,41, - 4,78,78,114,10,0,0,0,114,22,0,0,0,41,50,114, - 3,0,0,0,114,127,0,0,0,114,12,0,0,0,114,18, - 0,0,0,114,60,0,0,0,114,34,0,0,0,114,44,0, - 0,0,114,19,0,0,0,114,20,0,0,0,114,50,0,0, - 0,114,51,0,0,0,114,54,0,0,0,114,66,0,0,0, - 114,68,0,0,0,114,77,0,0,0,114,87,0,0,0,114, - 91,0,0,0,114,98,0,0,0,114,112,0,0,0,114,113, - 0,0,0,114,92,0,0,0,114,143,0,0,0,114,149,0, - 0,0,114,153,0,0,0,114,108,0,0,0,114,94,0,0, - 0,114,159,0,0,0,114,160,0,0,0,114,95,0,0,0, - 114,161,0,0,0,114,175,0,0,0,114,180,0,0,0,114, - 189,0,0,0,114,191,0,0,0,114,196,0,0,0,114,202, - 0,0,0,90,15,95,69,82,82,95,77,83,71,95,80,82, - 69,70,73,88,114,204,0,0,0,114,207,0,0,0,218,6, - 111,98,106,101,99,116,114,208,0,0,0,114,209,0,0,0, - 114,210,0,0,0,114,215,0,0,0,114,221,0,0,0,114, - 224,0,0,0,114,225,0,0,0,114,229,0,0,0,114,230, - 0,0,0,114,232,0,0,0,114,10,0,0,0,114,10,0, - 0,0,114,10,0,0,0,114,11,0,0,0,218,8,60,109, - 111,100,117,108,101,62,1,0,0,0,115,94,0,0,0,4, - 24,4,2,8,8,8,8,4,2,4,3,16,4,14,77,14, - 21,14,16,8,37,8,17,8,11,14,8,8,11,8,12,8, - 16,8,36,14,101,16,26,10,45,14,72,8,17,8,17,8, - 30,8,37,8,42,8,15,14,75,14,79,14,13,8,9,8, - 9,10,47,8,16,4,1,8,2,8,32,6,3,8,16,10, - 15,14,37,8,27,10,37,8,7,8,35,8,8, + 8,95,105,110,115,116,97,108,108,152,4,0,0,115,6,0, + 0,0,0,2,10,2,12,1,114,230,0,0,0,99,0,0, + 0,0,0,0,0,0,0,0,0,0,1,0,0,0,4,0, + 0,0,67,0,0,0,115,32,0,0,0,100,1,100,2,108, + 0,125,0,124,0,97,1,124,0,160,2,116,3,106,4,116, + 5,25,0,161,1,1,0,100,2,83,0,41,3,122,57,73, + 110,115,116,97,108,108,32,105,109,112,111,114,116,101,114,115, + 32,116,104,97,116,32,114,101,113,117,105,114,101,32,101,120, + 116,101,114,110,97,108,32,102,105,108,101,115,121,115,116,101, + 109,32,97,99,99,101,115,115,114,22,0,0,0,78,41,6, + 218,26,95,102,114,111,122,101,110,95,105,109,112,111,114,116, + 108,105,98,95,101,120,116,101,114,110,97,108,114,127,0,0, + 0,114,230,0,0,0,114,15,0,0,0,114,93,0,0,0, + 114,1,0,0,0,41,1,114,231,0,0,0,114,10,0,0, + 0,114,10,0,0,0,114,11,0,0,0,218,27,95,105,110, + 115,116,97,108,108,95,101,120,116,101,114,110,97,108,95,105, + 109,112,111,114,116,101,114,115,160,4,0,0,115,6,0,0, + 0,0,3,8,1,4,1,114,232,0,0,0,41,2,78,78, + 41,1,78,41,2,78,114,22,0,0,0,41,4,78,78,114, + 10,0,0,0,114,22,0,0,0,41,50,114,3,0,0,0, + 114,127,0,0,0,114,12,0,0,0,114,18,0,0,0,114, + 60,0,0,0,114,34,0,0,0,114,44,0,0,0,114,19, + 0,0,0,114,20,0,0,0,114,50,0,0,0,114,51,0, + 0,0,114,54,0,0,0,114,66,0,0,0,114,68,0,0, + 0,114,77,0,0,0,114,87,0,0,0,114,91,0,0,0, + 114,98,0,0,0,114,112,0,0,0,114,113,0,0,0,114, + 92,0,0,0,114,143,0,0,0,114,149,0,0,0,114,153, + 0,0,0,114,108,0,0,0,114,94,0,0,0,114,159,0, + 0,0,114,160,0,0,0,114,95,0,0,0,114,161,0,0, + 0,114,175,0,0,0,114,180,0,0,0,114,189,0,0,0, + 114,191,0,0,0,114,196,0,0,0,114,202,0,0,0,90, + 15,95,69,82,82,95,77,83,71,95,80,82,69,70,73,88, + 114,204,0,0,0,114,207,0,0,0,218,6,111,98,106,101, + 99,116,114,208,0,0,0,114,209,0,0,0,114,210,0,0, + 0,114,215,0,0,0,114,221,0,0,0,114,224,0,0,0, + 114,225,0,0,0,114,229,0,0,0,114,230,0,0,0,114, + 232,0,0,0,114,10,0,0,0,114,10,0,0,0,114,10, + 0,0,0,114,11,0,0,0,218,8,60,109,111,100,117,108, + 101,62,1,0,0,0,115,94,0,0,0,4,24,4,2,8, + 8,8,8,4,2,4,3,16,4,14,77,14,21,14,16,8, + 37,8,17,8,11,14,8,8,11,8,12,8,16,8,36,14, + 101,16,26,10,45,14,72,8,17,8,17,8,30,8,37,8, + 42,8,15,14,75,14,79,14,13,8,9,8,9,10,47,8, + 16,4,1,8,2,8,32,6,3,8,16,10,15,14,37,8, + 27,10,37,8,7,8,35,8,8, }; diff --git a/Python/importlib_external.h b/Python/importlib_external.h index dd237428867..a5a7c383d78 100644 --- a/Python/importlib_external.h +++ b/Python/importlib_external.h @@ -481,2255 +481,2210 @@ const unsigned char _Py_M__importlib_bootstrap_external[] = { 108,101,118,101,108,90,13,98,97,115,101,95,102,105,108,101, 110,97,109,101,114,5,0,0,0,114,5,0,0,0,114,8, 0,0,0,218,17,115,111,117,114,99,101,95,102,114,111,109, - 95,99,97,99,104,101,116,1,0,0,115,68,0,0,0,0, + 95,99,97,99,104,101,116,1,0,0,115,60,0,0,0,0, 9,12,1,8,1,10,1,12,1,4,1,10,1,12,1,14, - 1,16,1,4,1,4,1,12,1,8,1,2,1,2,255,4, - 1,2,255,8,2,10,1,8,1,16,1,10,1,16,1,10, - 1,4,1,2,255,8,2,16,1,10,1,4,1,2,255,10, - 2,14,1,114,102,0,0,0,99,1,0,0,0,0,0,0, - 0,0,0,0,0,5,0,0,0,9,0,0,0,67,0,0, - 0,115,124,0,0,0,116,0,124,0,131,1,100,1,107,2, - 114,16,100,2,83,0,124,0,160,1,100,3,161,1,92,3, - 125,1,125,2,125,3,124,1,114,56,124,3,160,2,161,0, - 100,4,100,5,133,2,25,0,100,6,107,3,114,60,124,0, - 83,0,122,12,116,3,124,0,131,1,125,4,87,0,110,34, - 4,0,116,4,116,5,102,2,121,106,1,0,1,0,1,0, - 124,0,100,2,100,5,133,2,25,0,125,4,89,0,110,2, - 48,0,116,6,124,4,131,1,114,120,124,4,83,0,124,0, - 83,0,41,7,122,188,67,111,110,118,101,114,116,32,97,32, - 98,121,116,101,99,111,100,101,32,102,105,108,101,32,112,97, - 116,104,32,116,111,32,97,32,115,111,117,114,99,101,32,112, - 97,116,104,32,40,105,102,32,112,111,115,115,105,98,108,101, - 41,46,10,10,32,32,32,32,84,104,105,115,32,102,117,110, - 99,116,105,111,110,32,101,120,105,115,116,115,32,112,117,114, - 101,108,121,32,102,111,114,32,98,97,99,107,119,97,114,100, - 115,45,99,111,109,112,97,116,105,98,105,108,105,116,121,32, - 102,111,114,10,32,32,32,32,80,121,73,109,112,111,114,116, - 95,69,120,101,99,67,111,100,101,77,111,100,117,108,101,87, - 105,116,104,70,105,108,101,110,97,109,101,115,40,41,32,105, - 110,32,116,104,101,32,67,32,65,80,73,46,10,10,32,32, - 32,32,114,73,0,0,0,78,114,71,0,0,0,233,253,255, - 255,255,233,255,255,255,255,90,2,112,121,41,7,114,23,0, - 0,0,114,41,0,0,0,218,5,108,111,119,101,114,114,102, - 0,0,0,114,82,0,0,0,114,86,0,0,0,114,54,0, - 0,0,41,5,218,13,98,121,116,101,99,111,100,101,95,112, - 97,116,104,114,95,0,0,0,114,45,0,0,0,90,9,101, - 120,116,101,110,115,105,111,110,218,11,115,111,117,114,99,101, - 95,112,97,116,104,114,5,0,0,0,114,5,0,0,0,114, - 8,0,0,0,218,15,95,103,101,116,95,115,111,117,114,99, - 101,102,105,108,101,156,1,0,0,115,20,0,0,0,0,7, - 12,1,4,1,16,1,24,1,4,1,2,1,12,1,16,1, - 18,1,114,108,0,0,0,99,1,0,0,0,0,0,0,0, - 0,0,0,0,1,0,0,0,8,0,0,0,67,0,0,0, - 115,72,0,0,0,124,0,160,0,116,1,116,2,131,1,161, - 1,114,46,122,10,116,3,124,0,131,1,87,0,83,0,4, - 0,116,4,121,42,1,0,1,0,1,0,89,0,113,68,48, - 0,110,22,124,0,160,0,116,1,116,5,131,1,161,1,114, - 64,124,0,83,0,100,0,83,0,100,0,83,0,169,1,78, - 41,6,218,8,101,110,100,115,119,105,116,104,218,5,116,117, - 112,108,101,114,101,0,0,0,114,97,0,0,0,114,82,0, - 0,0,114,88,0,0,0,41,1,114,96,0,0,0,114,5, - 0,0,0,114,5,0,0,0,114,8,0,0,0,218,11,95, - 103,101,116,95,99,97,99,104,101,100,175,1,0,0,115,16, - 0,0,0,0,1,14,1,2,1,10,1,12,1,8,1,14, - 1,4,2,114,112,0,0,0,99,1,0,0,0,0,0,0, - 0,0,0,0,0,2,0,0,0,8,0,0,0,67,0,0, - 0,115,50,0,0,0,122,14,116,0,124,0,131,1,106,1, - 125,1,87,0,110,22,4,0,116,2,121,36,1,0,1,0, - 1,0,100,1,125,1,89,0,110,2,48,0,124,1,100,2, - 79,0,125,1,124,1,83,0,41,3,122,51,67,97,108,99, - 117,108,97,116,101,32,116,104,101,32,109,111,100,101,32,112, - 101,114,109,105,115,115,105,111,110,115,32,102,111,114,32,97, - 32,98,121,116,101,99,111,100,101,32,102,105,108,101,46,114, - 60,0,0,0,233,128,0,0,0,41,3,114,49,0,0,0, - 114,51,0,0,0,114,50,0,0,0,41,2,114,44,0,0, - 0,114,52,0,0,0,114,5,0,0,0,114,5,0,0,0, - 114,8,0,0,0,218,10,95,99,97,108,99,95,109,111,100, - 101,187,1,0,0,115,12,0,0,0,0,2,2,1,14,1, - 12,1,10,3,8,1,114,114,0,0,0,99,1,0,0,0, - 0,0,0,0,0,0,0,0,3,0,0,0,8,0,0,0, - 3,0,0,0,115,66,0,0,0,100,6,135,0,102,1,100, - 2,100,3,132,9,125,1,122,10,116,0,106,1,125,2,87, - 0,110,26,4,0,116,2,121,50,1,0,1,0,1,0,100, - 4,100,5,132,0,125,2,89,0,110,2,48,0,124,2,124, - 1,136,0,131,2,1,0,124,1,83,0,41,7,122,252,68, - 101,99,111,114,97,116,111,114,32,116,111,32,118,101,114,105, - 102,121,32,116,104,97,116,32,116,104,101,32,109,111,100,117, - 108,101,32,98,101,105,110,103,32,114,101,113,117,101,115,116, - 101,100,32,109,97,116,99,104,101,115,32,116,104,101,32,111, - 110,101,32,116,104,101,10,32,32,32,32,108,111,97,100,101, - 114,32,99,97,110,32,104,97,110,100,108,101,46,10,10,32, - 32,32,32,84,104,101,32,102,105,114,115,116,32,97,114,103, - 117,109,101,110,116,32,40,115,101,108,102,41,32,109,117,115, - 116,32,100,101,102,105,110,101,32,95,110,97,109,101,32,119, - 104,105,99,104,32,116,104,101,32,115,101,99,111,110,100,32, - 97,114,103,117,109,101,110,116,32,105,115,10,32,32,32,32, - 99,111,109,112,97,114,101,100,32,97,103,97,105,110,115,116, - 46,32,73,102,32,116,104,101,32,99,111,109,112,97,114,105, - 115,111,110,32,102,97,105,108,115,32,116,104,101,110,32,73, - 109,112,111,114,116,69,114,114,111,114,32,105,115,32,114,97, - 105,115,101,100,46,10,10,32,32,32,32,78,99,2,0,0, - 0,0,0,0,0,0,0,0,0,4,0,0,0,4,0,0, - 0,31,0,0,0,115,72,0,0,0,124,1,100,0,117,0, - 114,16,124,0,106,0,125,1,110,32,124,0,106,0,124,1, - 107,3,114,48,116,1,100,1,124,0,106,0,124,1,102,2, - 22,0,124,1,100,2,141,2,130,1,136,0,124,0,124,1, - 103,2,124,2,162,1,82,0,105,0,124,3,164,1,142,1, - 83,0,41,3,78,122,30,108,111,97,100,101,114,32,102,111, - 114,32,37,115,32,99,97,110,110,111,116,32,104,97,110,100, - 108,101,32,37,115,169,1,218,4,110,97,109,101,41,2,114, - 116,0,0,0,218,11,73,109,112,111,114,116,69,114,114,111, - 114,41,4,218,4,115,101,108,102,114,116,0,0,0,218,4, - 97,114,103,115,218,6,107,119,97,114,103,115,169,1,218,6, - 109,101,116,104,111,100,114,5,0,0,0,114,8,0,0,0, - 218,19,95,99,104,101,99,107,95,110,97,109,101,95,119,114, - 97,112,112,101,114,207,1,0,0,115,18,0,0,0,0,1, - 8,1,8,1,10,1,4,1,8,255,2,1,2,255,6,2, - 122,40,95,99,104,101,99,107,95,110,97,109,101,46,60,108, - 111,99,97,108,115,62,46,95,99,104,101,99,107,95,110,97, - 109,101,95,119,114,97,112,112,101,114,99,2,0,0,0,0, - 0,0,0,0,0,0,0,3,0,0,0,7,0,0,0,83, - 0,0,0,115,56,0,0,0,100,1,68,0,93,32,125,2, - 116,0,124,1,124,2,131,2,114,4,116,1,124,0,124,2, - 116,2,124,1,124,2,131,2,131,3,1,0,113,4,124,0, - 106,3,160,4,124,1,106,3,161,1,1,0,100,0,83,0, - 41,2,78,41,4,218,10,95,95,109,111,100,117,108,101,95, - 95,218,8,95,95,110,97,109,101,95,95,218,12,95,95,113, - 117,97,108,110,97,109,101,95,95,218,7,95,95,100,111,99, - 95,95,41,5,218,7,104,97,115,97,116,116,114,218,7,115, - 101,116,97,116,116,114,218,7,103,101,116,97,116,116,114,218, - 8,95,95,100,105,99,116,95,95,218,6,117,112,100,97,116, - 101,41,3,90,3,110,101,119,90,3,111,108,100,114,67,0, - 0,0,114,5,0,0,0,114,5,0,0,0,114,8,0,0, - 0,218,5,95,119,114,97,112,218,1,0,0,115,8,0,0, - 0,0,1,8,1,10,1,20,1,122,26,95,99,104,101,99, - 107,95,110,97,109,101,46,60,108,111,99,97,108,115,62,46, - 95,119,114,97,112,41,1,78,41,3,218,10,95,98,111,111, - 116,115,116,114,97,112,114,133,0,0,0,218,9,78,97,109, - 101,69,114,114,111,114,41,3,114,122,0,0,0,114,123,0, - 0,0,114,133,0,0,0,114,5,0,0,0,114,121,0,0, - 0,114,8,0,0,0,218,11,95,99,104,101,99,107,95,110, - 97,109,101,199,1,0,0,115,14,0,0,0,0,8,14,7, - 2,1,10,1,12,2,14,5,10,1,114,136,0,0,0,99, - 2,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0, - 6,0,0,0,67,0,0,0,115,60,0,0,0,124,0,160, - 0,124,1,161,1,92,2,125,2,125,3,124,2,100,1,117, - 0,114,56,116,1,124,3,131,1,114,56,100,2,125,4,116, - 2,160,3,124,4,160,4,124,3,100,3,25,0,161,1,116, - 5,161,2,1,0,124,2,83,0,41,4,122,155,84,114,121, - 32,116,111,32,102,105,110,100,32,97,32,108,111,97,100,101, - 114,32,102,111,114,32,116,104,101,32,115,112,101,99,105,102, - 105,101,100,32,109,111,100,117,108,101,32,98,121,32,100,101, - 108,101,103,97,116,105,110,103,32,116,111,10,32,32,32,32, - 115,101,108,102,46,102,105,110,100,95,108,111,97,100,101,114, - 40,41,46,10,10,32,32,32,32,84,104,105,115,32,109,101, - 116,104,111,100,32,105,115,32,100,101,112,114,101,99,97,116, - 101,100,32,105,110,32,102,97,118,111,114,32,111,102,32,102, - 105,110,100,101,114,46,102,105,110,100,95,115,112,101,99,40, - 41,46,10,10,32,32,32,32,78,122,44,78,111,116,32,105, - 109,112,111,114,116,105,110,103,32,100,105,114,101,99,116,111, - 114,121,32,123,125,58,32,109,105,115,115,105,110,103,32,95, - 95,105,110,105,116,95,95,114,73,0,0,0,41,6,218,11, - 102,105,110,100,95,108,111,97,100,101,114,114,23,0,0,0, - 114,75,0,0,0,114,76,0,0,0,114,62,0,0,0,218, - 13,73,109,112,111,114,116,87,97,114,110,105,110,103,41,5, - 114,118,0,0,0,218,8,102,117,108,108,110,97,109,101,218, - 6,108,111,97,100,101,114,218,8,112,111,114,116,105,111,110, - 115,218,3,109,115,103,114,5,0,0,0,114,5,0,0,0, - 114,8,0,0,0,218,17,95,102,105,110,100,95,109,111,100, - 117,108,101,95,115,104,105,109,227,1,0,0,115,10,0,0, - 0,0,10,14,1,16,1,4,1,22,1,114,143,0,0,0, - 99,3,0,0,0,0,0,0,0,0,0,0,0,6,0,0, - 0,4,0,0,0,67,0,0,0,115,166,0,0,0,124,0, - 100,1,100,2,133,2,25,0,125,3,124,3,116,0,107,3, - 114,64,100,3,124,1,155,2,100,4,124,3,155,2,157,4, - 125,4,116,1,160,2,100,5,124,4,161,2,1,0,116,3, - 124,4,102,1,105,0,124,2,164,1,142,1,130,1,116,4, - 124,0,131,1,100,6,107,0,114,106,100,7,124,1,155,2, - 157,2,125,4,116,1,160,2,100,5,124,4,161,2,1,0, - 116,5,124,4,131,1,130,1,116,6,124,0,100,2,100,8, - 133,2,25,0,131,1,125,5,124,5,100,9,64,0,114,162, - 100,10,124,5,155,2,100,11,124,1,155,2,157,4,125,4, - 116,3,124,4,102,1,105,0,124,2,164,1,142,1,130,1, - 124,5,83,0,41,12,97,84,2,0,0,80,101,114,102,111, - 114,109,32,98,97,115,105,99,32,118,97,108,105,100,105,116, - 121,32,99,104,101,99,107,105,110,103,32,111,102,32,97,32, - 112,121,99,32,104,101,97,100,101,114,32,97,110,100,32,114, - 101,116,117,114,110,32,116,104,101,32,102,108,97,103,115,32, - 102,105,101,108,100,44,10,32,32,32,32,119,104,105,99,104, - 32,100,101,116,101,114,109,105,110,101,115,32,104,111,119,32, - 116,104,101,32,112,121,99,32,115,104,111,117,108,100,32,98, - 101,32,102,117,114,116,104,101,114,32,118,97,108,105,100,97, - 116,101,100,32,97,103,97,105,110,115,116,32,116,104,101,32, - 115,111,117,114,99,101,46,10,10,32,32,32,32,42,100,97, - 116,97,42,32,105,115,32,116,104,101,32,99,111,110,116,101, - 110,116,115,32,111,102,32,116,104,101,32,112,121,99,32,102, - 105,108,101,46,32,40,79,110,108,121,32,116,104,101,32,102, - 105,114,115,116,32,49,54,32,98,121,116,101,115,32,97,114, - 101,10,32,32,32,32,114,101,113,117,105,114,101,100,44,32, - 116,104,111,117,103,104,46,41,10,10,32,32,32,32,42,110, - 97,109,101,42,32,105,115,32,116,104,101,32,110,97,109,101, - 32,111,102,32,116,104,101,32,109,111,100,117,108,101,32,98, - 101,105,110,103,32,105,109,112,111,114,116,101,100,46,32,73, - 116,32,105,115,32,117,115,101,100,32,102,111,114,32,108,111, - 103,103,105,110,103,46,10,10,32,32,32,32,42,101,120,99, - 95,100,101,116,97,105,108,115,42,32,105,115,32,97,32,100, - 105,99,116,105,111,110,97,114,121,32,112,97,115,115,101,100, - 32,116,111,32,73,109,112,111,114,116,69,114,114,111,114,32, - 105,102,32,105,116,32,114,97,105,115,101,100,32,102,111,114, - 10,32,32,32,32,105,109,112,114,111,118,101,100,32,100,101, - 98,117,103,103,105,110,103,46,10,10,32,32,32,32,73,109, - 112,111,114,116,69,114,114,111,114,32,105,115,32,114,97,105, - 115,101,100,32,119,104,101,110,32,116,104,101,32,109,97,103, - 105,99,32,110,117,109,98,101,114,32,105,115,32,105,110,99, - 111,114,114,101,99,116,32,111,114,32,119,104,101,110,32,116, - 104,101,32,102,108,97,103,115,10,32,32,32,32,102,105,101, - 108,100,32,105,115,32,105,110,118,97,108,105,100,46,32,69, - 79,70,69,114,114,111,114,32,105,115,32,114,97,105,115,101, - 100,32,119,104,101,110,32,116,104,101,32,100,97,116,97,32, - 105,115,32,102,111,117,110,100,32,116,111,32,98,101,32,116, - 114,117,110,99,97,116,101,100,46,10,10,32,32,32,32,78, - 114,16,0,0,0,122,20,98,97,100,32,109,97,103,105,99, - 32,110,117,109,98,101,114,32,105,110,32,122,2,58,32,250, - 2,123,125,233,16,0,0,0,122,40,114,101,97,99,104,101, - 100,32,69,79,70,32,119,104,105,108,101,32,114,101,97,100, - 105,110,103,32,112,121,99,32,104,101,97,100,101,114,32,111, - 102,32,233,8,0,0,0,233,252,255,255,255,122,14,105,110, - 118,97,108,105,100,32,102,108,97,103,115,32,122,4,32,105, - 110,32,41,7,218,12,77,65,71,73,67,95,78,85,77,66, - 69,82,114,134,0,0,0,218,16,95,118,101,114,98,111,115, - 101,95,109,101,115,115,97,103,101,114,117,0,0,0,114,23, - 0,0,0,218,8,69,79,70,69,114,114,111,114,114,27,0, - 0,0,41,6,114,26,0,0,0,114,116,0,0,0,218,11, - 101,120,99,95,100,101,116,97,105,108,115,90,5,109,97,103, - 105,99,114,92,0,0,0,114,2,0,0,0,114,5,0,0, - 0,114,5,0,0,0,114,8,0,0,0,218,13,95,99,108, - 97,115,115,105,102,121,95,112,121,99,244,1,0,0,115,28, - 0,0,0,0,16,12,1,8,1,16,1,12,1,16,1,12, - 1,10,1,12,1,8,1,16,2,8,1,16,1,16,1,114, - 152,0,0,0,99,5,0,0,0,0,0,0,0,0,0,0, - 0,6,0,0,0,4,0,0,0,67,0,0,0,115,120,0, - 0,0,116,0,124,0,100,1,100,2,133,2,25,0,131,1, - 124,1,100,3,64,0,107,3,114,62,100,4,124,3,155,2, - 157,2,125,5,116,1,160,2,100,5,124,5,161,2,1,0, - 116,3,124,5,102,1,105,0,124,4,164,1,142,1,130,1, - 124,2,100,6,117,1,114,116,116,0,124,0,100,2,100,7, - 133,2,25,0,131,1,124,2,100,3,64,0,107,3,114,116, - 116,3,100,4,124,3,155,2,157,2,102,1,105,0,124,4, - 164,1,142,1,130,1,100,6,83,0,41,8,97,7,2,0, - 0,86,97,108,105,100,97,116,101,32,97,32,112,121,99,32, - 97,103,97,105,110,115,116,32,116,104,101,32,115,111,117,114, - 99,101,32,108,97,115,116,45,109,111,100,105,102,105,101,100, - 32,116,105,109,101,46,10,10,32,32,32,32,42,100,97,116, - 97,42,32,105,115,32,116,104,101,32,99,111,110,116,101,110, - 116,115,32,111,102,32,116,104,101,32,112,121,99,32,102,105, - 108,101,46,32,40,79,110,108,121,32,116,104,101,32,102,105, - 114,115,116,32,49,54,32,98,121,116,101,115,32,97,114,101, - 10,32,32,32,32,114,101,113,117,105,114,101,100,46,41,10, - 10,32,32,32,32,42,115,111,117,114,99,101,95,109,116,105, - 109,101,42,32,105,115,32,116,104,101,32,108,97,115,116,32, - 109,111,100,105,102,105,101,100,32,116,105,109,101,115,116,97, - 109,112,32,111,102,32,116,104,101,32,115,111,117,114,99,101, - 32,102,105,108,101,46,10,10,32,32,32,32,42,115,111,117, - 114,99,101,95,115,105,122,101,42,32,105,115,32,78,111,110, - 101,32,111,114,32,116,104,101,32,115,105,122,101,32,111,102, - 32,116,104,101,32,115,111,117,114,99,101,32,102,105,108,101, - 32,105,110,32,98,121,116,101,115,46,10,10,32,32,32,32, - 42,110,97,109,101,42,32,105,115,32,116,104,101,32,110,97, - 109,101,32,111,102,32,116,104,101,32,109,111,100,117,108,101, - 32,98,101,105,110,103,32,105,109,112,111,114,116,101,100,46, - 32,73,116,32,105,115,32,117,115,101,100,32,102,111,114,32, - 108,111,103,103,105,110,103,46,10,10,32,32,32,32,42,101, - 120,99,95,100,101,116,97,105,108,115,42,32,105,115,32,97, - 32,100,105,99,116,105,111,110,97,114,121,32,112,97,115,115, - 101,100,32,116,111,32,73,109,112,111,114,116,69,114,114,111, - 114,32,105,102,32,105,116,32,114,97,105,115,101,100,32,102, - 111,114,10,32,32,32,32,105,109,112,114,111,118,101,100,32, - 100,101,98,117,103,103,105,110,103,46,10,10,32,32,32,32, - 65,110,32,73,109,112,111,114,116,69,114,114,111,114,32,105, - 115,32,114,97,105,115,101,100,32,105,102,32,116,104,101,32, - 98,121,116,101,99,111,100,101,32,105,115,32,115,116,97,108, - 101,46,10,10,32,32,32,32,114,146,0,0,0,233,12,0, - 0,0,114,15,0,0,0,122,22,98,121,116,101,99,111,100, - 101,32,105,115,32,115,116,97,108,101,32,102,111,114,32,114, - 144,0,0,0,78,114,145,0,0,0,41,4,114,27,0,0, - 0,114,134,0,0,0,114,149,0,0,0,114,117,0,0,0, - 41,6,114,26,0,0,0,218,12,115,111,117,114,99,101,95, - 109,116,105,109,101,218,11,115,111,117,114,99,101,95,115,105, - 122,101,114,116,0,0,0,114,151,0,0,0,114,92,0,0, - 0,114,5,0,0,0,114,5,0,0,0,114,8,0,0,0, - 218,23,95,118,97,108,105,100,97,116,101,95,116,105,109,101, - 115,116,97,109,112,95,112,121,99,21,2,0,0,115,16,0, - 0,0,0,19,24,1,10,1,12,1,16,1,8,1,22,255, - 2,2,114,156,0,0,0,99,4,0,0,0,0,0,0,0, - 0,0,0,0,4,0,0,0,4,0,0,0,67,0,0,0, - 115,42,0,0,0,124,0,100,1,100,2,133,2,25,0,124, - 1,107,3,114,38,116,0,100,3,124,2,155,2,157,2,102, - 1,105,0,124,3,164,1,142,1,130,1,100,4,83,0,41, - 5,97,243,1,0,0,86,97,108,105,100,97,116,101,32,97, - 32,104,97,115,104,45,98,97,115,101,100,32,112,121,99,32, - 98,121,32,99,104,101,99,107,105,110,103,32,116,104,101,32, - 114,101,97,108,32,115,111,117,114,99,101,32,104,97,115,104, - 32,97,103,97,105,110,115,116,32,116,104,101,32,111,110,101, - 32,105,110,10,32,32,32,32,116,104,101,32,112,121,99,32, - 104,101,97,100,101,114,46,10,10,32,32,32,32,42,100,97, - 116,97,42,32,105,115,32,116,104,101,32,99,111,110,116,101, - 110,116,115,32,111,102,32,116,104,101,32,112,121,99,32,102, - 105,108,101,46,32,40,79,110,108,121,32,116,104,101,32,102, - 105,114,115,116,32,49,54,32,98,121,116,101,115,32,97,114, - 101,10,32,32,32,32,114,101,113,117,105,114,101,100,46,41, - 10,10,32,32,32,32,42,115,111,117,114,99,101,95,104,97, - 115,104,42,32,105,115,32,116,104,101,32,105,109,112,111,114, - 116,108,105,98,46,117,116,105,108,46,115,111,117,114,99,101, - 95,104,97,115,104,40,41,32,111,102,32,116,104,101,32,115, - 111,117,114,99,101,32,102,105,108,101,46,10,10,32,32,32, - 32,42,110,97,109,101,42,32,105,115,32,116,104,101,32,110, - 97,109,101,32,111,102,32,116,104,101,32,109,111,100,117,108, - 101,32,98,101,105,110,103,32,105,109,112,111,114,116,101,100, - 46,32,73,116,32,105,115,32,117,115,101,100,32,102,111,114, - 32,108,111,103,103,105,110,103,46,10,10,32,32,32,32,42, - 101,120,99,95,100,101,116,97,105,108,115,42,32,105,115,32, - 97,32,100,105,99,116,105,111,110,97,114,121,32,112,97,115, - 115,101,100,32,116,111,32,73,109,112,111,114,116,69,114,114, - 111,114,32,105,102,32,105,116,32,114,97,105,115,101,100,32, - 102,111,114,10,32,32,32,32,105,109,112,114,111,118,101,100, - 32,100,101,98,117,103,103,105,110,103,46,10,10,32,32,32, - 32,65,110,32,73,109,112,111,114,116,69,114,114,111,114,32, - 105,115,32,114,97,105,115,101,100,32,105,102,32,116,104,101, - 32,98,121,116,101,99,111,100,101,32,105,115,32,115,116,97, - 108,101,46,10,10,32,32,32,32,114,146,0,0,0,114,145, - 0,0,0,122,46,104,97,115,104,32,105,110,32,98,121,116, - 101,99,111,100,101,32,100,111,101,115,110,39,116,32,109,97, - 116,99,104,32,104,97,115,104,32,111,102,32,115,111,117,114, - 99,101,32,78,41,1,114,117,0,0,0,41,4,114,26,0, - 0,0,218,11,115,111,117,114,99,101,95,104,97,115,104,114, - 116,0,0,0,114,151,0,0,0,114,5,0,0,0,114,5, - 0,0,0,114,8,0,0,0,218,18,95,118,97,108,105,100, - 97,116,101,95,104,97,115,104,95,112,121,99,49,2,0,0, - 115,12,0,0,0,0,17,16,1,2,1,8,255,4,2,2, - 254,114,158,0,0,0,99,4,0,0,0,0,0,0,0,0, - 0,0,0,5,0,0,0,5,0,0,0,67,0,0,0,115, - 80,0,0,0,116,0,160,1,124,0,161,1,125,4,116,2, - 124,4,116,3,131,2,114,56,116,4,160,5,100,1,124,2, - 161,2,1,0,124,3,100,2,117,1,114,52,116,6,160,7, - 124,4,124,3,161,2,1,0,124,4,83,0,116,8,100,3, - 160,9,124,2,161,1,124,1,124,2,100,4,141,3,130,1, - 100,2,83,0,41,5,122,35,67,111,109,112,105,108,101,32, - 98,121,116,101,99,111,100,101,32,97,115,32,102,111,117,110, - 100,32,105,110,32,97,32,112,121,99,46,122,21,99,111,100, - 101,32,111,98,106,101,99,116,32,102,114,111,109,32,123,33, - 114,125,78,122,23,78,111,110,45,99,111,100,101,32,111,98, - 106,101,99,116,32,105,110,32,123,33,114,125,169,2,114,116, - 0,0,0,114,44,0,0,0,41,10,218,7,109,97,114,115, - 104,97,108,90,5,108,111,97,100,115,218,10,105,115,105,110, - 115,116,97,110,99,101,218,10,95,99,111,100,101,95,116,121, - 112,101,114,134,0,0,0,114,149,0,0,0,218,4,95,105, - 109,112,90,16,95,102,105,120,95,99,111,95,102,105,108,101, - 110,97,109,101,114,117,0,0,0,114,62,0,0,0,41,5, - 114,26,0,0,0,114,116,0,0,0,114,106,0,0,0,114, - 107,0,0,0,218,4,99,111,100,101,114,5,0,0,0,114, - 5,0,0,0,114,8,0,0,0,218,17,95,99,111,109,112, - 105,108,101,95,98,121,116,101,99,111,100,101,73,2,0,0, - 115,18,0,0,0,0,2,10,1,10,1,12,1,8,1,12, - 1,4,2,10,1,4,255,114,165,0,0,0,114,73,0,0, - 0,99,3,0,0,0,0,0,0,0,0,0,0,0,4,0, - 0,0,5,0,0,0,67,0,0,0,115,70,0,0,0,116, - 0,116,1,131,1,125,3,124,3,160,2,116,3,100,1,131, - 1,161,1,1,0,124,3,160,2,116,3,124,1,131,1,161, - 1,1,0,124,3,160,2,116,3,124,2,131,1,161,1,1, - 0,124,3,160,2,116,4,160,5,124,0,161,1,161,1,1, - 0,124,3,83,0,41,2,122,43,80,114,111,100,117,99,101, - 32,116,104,101,32,100,97,116,97,32,102,111,114,32,97,32, - 116,105,109,101,115,116,97,109,112,45,98,97,115,101,100,32, - 112,121,99,46,114,73,0,0,0,41,6,218,9,98,121,116, - 101,97,114,114,97,121,114,148,0,0,0,218,6,101,120,116, - 101,110,100,114,21,0,0,0,114,160,0,0,0,218,5,100, - 117,109,112,115,41,4,114,164,0,0,0,218,5,109,116,105, - 109,101,114,155,0,0,0,114,26,0,0,0,114,5,0,0, - 0,114,5,0,0,0,114,8,0,0,0,218,22,95,99,111, - 100,101,95,116,111,95,116,105,109,101,115,116,97,109,112,95, - 112,121,99,86,2,0,0,115,12,0,0,0,0,2,8,1, - 14,1,14,1,14,1,16,1,114,170,0,0,0,84,99,3, - 0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,5, - 0,0,0,67,0,0,0,115,80,0,0,0,116,0,116,1, - 131,1,125,3,100,1,124,2,100,1,62,0,66,0,125,4, - 124,3,160,2,116,3,124,4,131,1,161,1,1,0,116,4, - 124,1,131,1,100,2,107,2,115,50,74,0,130,1,124,3, - 160,2,124,1,161,1,1,0,124,3,160,2,116,5,160,6, - 124,0,161,1,161,1,1,0,124,3,83,0,41,3,122,38, - 80,114,111,100,117,99,101,32,116,104,101,32,100,97,116,97, - 32,102,111,114,32,97,32,104,97,115,104,45,98,97,115,101, - 100,32,112,121,99,46,114,39,0,0,0,114,146,0,0,0, - 41,7,114,166,0,0,0,114,148,0,0,0,114,167,0,0, - 0,114,21,0,0,0,114,23,0,0,0,114,160,0,0,0, - 114,168,0,0,0,41,5,114,164,0,0,0,114,157,0,0, - 0,90,7,99,104,101,99,107,101,100,114,26,0,0,0,114, + 1,16,1,4,1,4,1,12,1,8,1,8,1,2,255,8, + 2,10,1,8,1,16,1,10,1,16,1,10,1,4,1,2, + 255,8,2,16,1,10,1,16,2,14,1,114,102,0,0,0, + 99,1,0,0,0,0,0,0,0,0,0,0,0,5,0,0, + 0,9,0,0,0,67,0,0,0,115,124,0,0,0,116,0, + 124,0,131,1,100,1,107,2,114,16,100,2,83,0,124,0, + 160,1,100,3,161,1,92,3,125,1,125,2,125,3,124,1, + 114,56,124,3,160,2,161,0,100,4,100,5,133,2,25,0, + 100,6,107,3,114,60,124,0,83,0,122,12,116,3,124,0, + 131,1,125,4,87,0,110,34,4,0,116,4,116,5,102,2, + 121,106,1,0,1,0,1,0,124,0,100,2,100,5,133,2, + 25,0,125,4,89,0,110,2,48,0,116,6,124,4,131,1, + 114,120,124,4,83,0,124,0,83,0,41,7,122,188,67,111, + 110,118,101,114,116,32,97,32,98,121,116,101,99,111,100,101, + 32,102,105,108,101,32,112,97,116,104,32,116,111,32,97,32, + 115,111,117,114,99,101,32,112,97,116,104,32,40,105,102,32, + 112,111,115,115,105,98,108,101,41,46,10,10,32,32,32,32, + 84,104,105,115,32,102,117,110,99,116,105,111,110,32,101,120, + 105,115,116,115,32,112,117,114,101,108,121,32,102,111,114,32, + 98,97,99,107,119,97,114,100,115,45,99,111,109,112,97,116, + 105,98,105,108,105,116,121,32,102,111,114,10,32,32,32,32, + 80,121,73,109,112,111,114,116,95,69,120,101,99,67,111,100, + 101,77,111,100,117,108,101,87,105,116,104,70,105,108,101,110, + 97,109,101,115,40,41,32,105,110,32,116,104,101,32,67,32, + 65,80,73,46,10,10,32,32,32,32,114,73,0,0,0,78, + 114,71,0,0,0,233,253,255,255,255,233,255,255,255,255,90, + 2,112,121,41,7,114,23,0,0,0,114,41,0,0,0,218, + 5,108,111,119,101,114,114,102,0,0,0,114,82,0,0,0, + 114,86,0,0,0,114,54,0,0,0,41,5,218,13,98,121, + 116,101,99,111,100,101,95,112,97,116,104,114,95,0,0,0, + 114,45,0,0,0,90,9,101,120,116,101,110,115,105,111,110, + 218,11,115,111,117,114,99,101,95,112,97,116,104,114,5,0, + 0,0,114,5,0,0,0,114,8,0,0,0,218,15,95,103, + 101,116,95,115,111,117,114,99,101,102,105,108,101,156,1,0, + 0,115,20,0,0,0,0,7,12,1,4,1,16,1,24,1, + 4,1,2,1,12,1,16,1,18,1,114,108,0,0,0,99, + 1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, + 8,0,0,0,67,0,0,0,115,72,0,0,0,124,0,160, + 0,116,1,116,2,131,1,161,1,114,46,122,10,116,3,124, + 0,131,1,87,0,83,0,4,0,116,4,121,42,1,0,1, + 0,1,0,89,0,113,68,48,0,110,22,124,0,160,0,116, + 1,116,5,131,1,161,1,114,64,124,0,83,0,100,0,83, + 0,100,0,83,0,169,1,78,41,6,218,8,101,110,100,115, + 119,105,116,104,218,5,116,117,112,108,101,114,101,0,0,0, + 114,97,0,0,0,114,82,0,0,0,114,88,0,0,0,41, + 1,114,96,0,0,0,114,5,0,0,0,114,5,0,0,0, + 114,8,0,0,0,218,11,95,103,101,116,95,99,97,99,104, + 101,100,175,1,0,0,115,16,0,0,0,0,1,14,1,2, + 1,10,1,12,1,8,1,14,1,4,2,114,112,0,0,0, + 99,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0, + 0,8,0,0,0,67,0,0,0,115,50,0,0,0,122,14, + 116,0,124,0,131,1,106,1,125,1,87,0,110,22,4,0, + 116,2,121,36,1,0,1,0,1,0,100,1,125,1,89,0, + 110,2,48,0,124,1,100,2,79,0,125,1,124,1,83,0, + 41,3,122,51,67,97,108,99,117,108,97,116,101,32,116,104, + 101,32,109,111,100,101,32,112,101,114,109,105,115,115,105,111, + 110,115,32,102,111,114,32,97,32,98,121,116,101,99,111,100, + 101,32,102,105,108,101,46,114,60,0,0,0,233,128,0,0, + 0,41,3,114,49,0,0,0,114,51,0,0,0,114,50,0, + 0,0,41,2,114,44,0,0,0,114,52,0,0,0,114,5, + 0,0,0,114,5,0,0,0,114,8,0,0,0,218,10,95, + 99,97,108,99,95,109,111,100,101,187,1,0,0,115,12,0, + 0,0,0,2,2,1,14,1,12,1,10,3,8,1,114,114, + 0,0,0,99,1,0,0,0,0,0,0,0,0,0,0,0, + 3,0,0,0,8,0,0,0,3,0,0,0,115,66,0,0, + 0,100,6,135,0,102,1,100,2,100,3,132,9,125,1,122, + 10,116,0,106,1,125,2,87,0,110,26,4,0,116,2,121, + 50,1,0,1,0,1,0,100,4,100,5,132,0,125,2,89, + 0,110,2,48,0,124,2,124,1,136,0,131,2,1,0,124, + 1,83,0,41,7,122,252,68,101,99,111,114,97,116,111,114, + 32,116,111,32,118,101,114,105,102,121,32,116,104,97,116,32, + 116,104,101,32,109,111,100,117,108,101,32,98,101,105,110,103, + 32,114,101,113,117,101,115,116,101,100,32,109,97,116,99,104, + 101,115,32,116,104,101,32,111,110,101,32,116,104,101,10,32, + 32,32,32,108,111,97,100,101,114,32,99,97,110,32,104,97, + 110,100,108,101,46,10,10,32,32,32,32,84,104,101,32,102, + 105,114,115,116,32,97,114,103,117,109,101,110,116,32,40,115, + 101,108,102,41,32,109,117,115,116,32,100,101,102,105,110,101, + 32,95,110,97,109,101,32,119,104,105,99,104,32,116,104,101, + 32,115,101,99,111,110,100,32,97,114,103,117,109,101,110,116, + 32,105,115,10,32,32,32,32,99,111,109,112,97,114,101,100, + 32,97,103,97,105,110,115,116,46,32,73,102,32,116,104,101, + 32,99,111,109,112,97,114,105,115,111,110,32,102,97,105,108, + 115,32,116,104,101,110,32,73,109,112,111,114,116,69,114,114, + 111,114,32,105,115,32,114,97,105,115,101,100,46,10,10,32, + 32,32,32,78,99,2,0,0,0,0,0,0,0,0,0,0, + 0,4,0,0,0,4,0,0,0,31,0,0,0,115,72,0, + 0,0,124,1,100,0,117,0,114,16,124,0,106,0,125,1, + 110,32,124,0,106,0,124,1,107,3,114,48,116,1,100,1, + 124,0,106,0,124,1,102,2,22,0,124,1,100,2,141,2, + 130,1,136,0,124,0,124,1,103,2,124,2,162,1,82,0, + 105,0,124,3,164,1,142,1,83,0,41,3,78,122,30,108, + 111,97,100,101,114,32,102,111,114,32,37,115,32,99,97,110, + 110,111,116,32,104,97,110,100,108,101,32,37,115,169,1,218, + 4,110,97,109,101,41,2,114,116,0,0,0,218,11,73,109, + 112,111,114,116,69,114,114,111,114,41,4,218,4,115,101,108, + 102,114,116,0,0,0,218,4,97,114,103,115,218,6,107,119, + 97,114,103,115,169,1,218,6,109,101,116,104,111,100,114,5, + 0,0,0,114,8,0,0,0,218,19,95,99,104,101,99,107, + 95,110,97,109,101,95,119,114,97,112,112,101,114,207,1,0, + 0,115,18,0,0,0,0,1,8,1,8,1,10,1,4,1, + 8,255,2,1,2,255,6,2,122,40,95,99,104,101,99,107, + 95,110,97,109,101,46,60,108,111,99,97,108,115,62,46,95, + 99,104,101,99,107,95,110,97,109,101,95,119,114,97,112,112, + 101,114,99,2,0,0,0,0,0,0,0,0,0,0,0,3, + 0,0,0,7,0,0,0,83,0,0,0,115,56,0,0,0, + 100,1,68,0,93,32,125,2,116,0,124,1,124,2,131,2, + 114,4,116,1,124,0,124,2,116,2,124,1,124,2,131,2, + 131,3,1,0,113,4,124,0,106,3,160,4,124,1,106,3, + 161,1,1,0,100,0,83,0,41,2,78,41,4,218,10,95, + 95,109,111,100,117,108,101,95,95,218,8,95,95,110,97,109, + 101,95,95,218,12,95,95,113,117,97,108,110,97,109,101,95, + 95,218,7,95,95,100,111,99,95,95,41,5,218,7,104,97, + 115,97,116,116,114,218,7,115,101,116,97,116,116,114,218,7, + 103,101,116,97,116,116,114,218,8,95,95,100,105,99,116,95, + 95,218,6,117,112,100,97,116,101,41,3,90,3,110,101,119, + 90,3,111,108,100,114,67,0,0,0,114,5,0,0,0,114, + 5,0,0,0,114,8,0,0,0,218,5,95,119,114,97,112, + 218,1,0,0,115,8,0,0,0,0,1,8,1,10,1,20, + 1,122,26,95,99,104,101,99,107,95,110,97,109,101,46,60, + 108,111,99,97,108,115,62,46,95,119,114,97,112,41,1,78, + 41,3,218,10,95,98,111,111,116,115,116,114,97,112,114,133, + 0,0,0,218,9,78,97,109,101,69,114,114,111,114,41,3, + 114,122,0,0,0,114,123,0,0,0,114,133,0,0,0,114, + 5,0,0,0,114,121,0,0,0,114,8,0,0,0,218,11, + 95,99,104,101,99,107,95,110,97,109,101,199,1,0,0,115, + 14,0,0,0,0,8,14,7,2,1,10,1,12,2,14,5, + 10,1,114,136,0,0,0,99,2,0,0,0,0,0,0,0, + 0,0,0,0,5,0,0,0,6,0,0,0,67,0,0,0, + 115,60,0,0,0,124,0,160,0,124,1,161,1,92,2,125, + 2,125,3,124,2,100,1,117,0,114,56,116,1,124,3,131, + 1,114,56,100,2,125,4,116,2,160,3,124,4,160,4,124, + 3,100,3,25,0,161,1,116,5,161,2,1,0,124,2,83, + 0,41,4,122,155,84,114,121,32,116,111,32,102,105,110,100, + 32,97,32,108,111,97,100,101,114,32,102,111,114,32,116,104, + 101,32,115,112,101,99,105,102,105,101,100,32,109,111,100,117, + 108,101,32,98,121,32,100,101,108,101,103,97,116,105,110,103, + 32,116,111,10,32,32,32,32,115,101,108,102,46,102,105,110, + 100,95,108,111,97,100,101,114,40,41,46,10,10,32,32,32, + 32,84,104,105,115,32,109,101,116,104,111,100,32,105,115,32, + 100,101,112,114,101,99,97,116,101,100,32,105,110,32,102,97, + 118,111,114,32,111,102,32,102,105,110,100,101,114,46,102,105, + 110,100,95,115,112,101,99,40,41,46,10,10,32,32,32,32, + 78,122,44,78,111,116,32,105,109,112,111,114,116,105,110,103, + 32,100,105,114,101,99,116,111,114,121,32,123,125,58,32,109, + 105,115,115,105,110,103,32,95,95,105,110,105,116,95,95,114, + 73,0,0,0,41,6,218,11,102,105,110,100,95,108,111,97, + 100,101,114,114,23,0,0,0,114,75,0,0,0,114,76,0, + 0,0,114,62,0,0,0,218,13,73,109,112,111,114,116,87, + 97,114,110,105,110,103,41,5,114,118,0,0,0,218,8,102, + 117,108,108,110,97,109,101,218,6,108,111,97,100,101,114,218, + 8,112,111,114,116,105,111,110,115,218,3,109,115,103,114,5, + 0,0,0,114,5,0,0,0,114,8,0,0,0,218,17,95, + 102,105,110,100,95,109,111,100,117,108,101,95,115,104,105,109, + 227,1,0,0,115,10,0,0,0,0,10,14,1,16,1,4, + 1,22,1,114,143,0,0,0,99,3,0,0,0,0,0,0, + 0,0,0,0,0,6,0,0,0,4,0,0,0,67,0,0, + 0,115,166,0,0,0,124,0,100,1,100,2,133,2,25,0, + 125,3,124,3,116,0,107,3,114,64,100,3,124,1,155,2, + 100,4,124,3,155,2,157,4,125,4,116,1,160,2,100,5, + 124,4,161,2,1,0,116,3,124,4,102,1,105,0,124,2, + 164,1,142,1,130,1,116,4,124,0,131,1,100,6,107,0, + 114,106,100,7,124,1,155,2,157,2,125,4,116,1,160,2, + 100,5,124,4,161,2,1,0,116,5,124,4,131,1,130,1, + 116,6,124,0,100,2,100,8,133,2,25,0,131,1,125,5, + 124,5,100,9,64,0,114,162,100,10,124,5,155,2,100,11, + 124,1,155,2,157,4,125,4,116,3,124,4,102,1,105,0, + 124,2,164,1,142,1,130,1,124,5,83,0,41,12,97,84, + 2,0,0,80,101,114,102,111,114,109,32,98,97,115,105,99, + 32,118,97,108,105,100,105,116,121,32,99,104,101,99,107,105, + 110,103,32,111,102,32,97,32,112,121,99,32,104,101,97,100, + 101,114,32,97,110,100,32,114,101,116,117,114,110,32,116,104, + 101,32,102,108,97,103,115,32,102,105,101,108,100,44,10,32, + 32,32,32,119,104,105,99,104,32,100,101,116,101,114,109,105, + 110,101,115,32,104,111,119,32,116,104,101,32,112,121,99,32, + 115,104,111,117,108,100,32,98,101,32,102,117,114,116,104,101, + 114,32,118,97,108,105,100,97,116,101,100,32,97,103,97,105, + 110,115,116,32,116,104,101,32,115,111,117,114,99,101,46,10, + 10,32,32,32,32,42,100,97,116,97,42,32,105,115,32,116, + 104,101,32,99,111,110,116,101,110,116,115,32,111,102,32,116, + 104,101,32,112,121,99,32,102,105,108,101,46,32,40,79,110, + 108,121,32,116,104,101,32,102,105,114,115,116,32,49,54,32, + 98,121,116,101,115,32,97,114,101,10,32,32,32,32,114,101, + 113,117,105,114,101,100,44,32,116,104,111,117,103,104,46,41, + 10,10,32,32,32,32,42,110,97,109,101,42,32,105,115,32, + 116,104,101,32,110,97,109,101,32,111,102,32,116,104,101,32, + 109,111,100,117,108,101,32,98,101,105,110,103,32,105,109,112, + 111,114,116,101,100,46,32,73,116,32,105,115,32,117,115,101, + 100,32,102,111,114,32,108,111,103,103,105,110,103,46,10,10, + 32,32,32,32,42,101,120,99,95,100,101,116,97,105,108,115, + 42,32,105,115,32,97,32,100,105,99,116,105,111,110,97,114, + 121,32,112,97,115,115,101,100,32,116,111,32,73,109,112,111, + 114,116,69,114,114,111,114,32,105,102,32,105,116,32,114,97, + 105,115,101,100,32,102,111,114,10,32,32,32,32,105,109,112, + 114,111,118,101,100,32,100,101,98,117,103,103,105,110,103,46, + 10,10,32,32,32,32,73,109,112,111,114,116,69,114,114,111, + 114,32,105,115,32,114,97,105,115,101,100,32,119,104,101,110, + 32,116,104,101,32,109,97,103,105,99,32,110,117,109,98,101, + 114,32,105,115,32,105,110,99,111,114,114,101,99,116,32,111, + 114,32,119,104,101,110,32,116,104,101,32,102,108,97,103,115, + 10,32,32,32,32,102,105,101,108,100,32,105,115,32,105,110, + 118,97,108,105,100,46,32,69,79,70,69,114,114,111,114,32, + 105,115,32,114,97,105,115,101,100,32,119,104,101,110,32,116, + 104,101,32,100,97,116,97,32,105,115,32,102,111,117,110,100, + 32,116,111,32,98,101,32,116,114,117,110,99,97,116,101,100, + 46,10,10,32,32,32,32,78,114,16,0,0,0,122,20,98, + 97,100,32,109,97,103,105,99,32,110,117,109,98,101,114,32, + 105,110,32,122,2,58,32,250,2,123,125,233,16,0,0,0, + 122,40,114,101,97,99,104,101,100,32,69,79,70,32,119,104, + 105,108,101,32,114,101,97,100,105,110,103,32,112,121,99,32, + 104,101,97,100,101,114,32,111,102,32,233,8,0,0,0,233, + 252,255,255,255,122,14,105,110,118,97,108,105,100,32,102,108, + 97,103,115,32,122,4,32,105,110,32,41,7,218,12,77,65, + 71,73,67,95,78,85,77,66,69,82,114,134,0,0,0,218, + 16,95,118,101,114,98,111,115,101,95,109,101,115,115,97,103, + 101,114,117,0,0,0,114,23,0,0,0,218,8,69,79,70, + 69,114,114,111,114,114,27,0,0,0,41,6,114,26,0,0, + 0,114,116,0,0,0,218,11,101,120,99,95,100,101,116,97, + 105,108,115,90,5,109,97,103,105,99,114,92,0,0,0,114, 2,0,0,0,114,5,0,0,0,114,5,0,0,0,114,8, - 0,0,0,218,17,95,99,111,100,101,95,116,111,95,104,97, - 115,104,95,112,121,99,96,2,0,0,115,14,0,0,0,0, - 2,8,1,12,1,14,1,16,1,10,1,16,1,114,171,0, - 0,0,99,1,0,0,0,0,0,0,0,0,0,0,0,5, - 0,0,0,6,0,0,0,67,0,0,0,115,62,0,0,0, - 100,1,100,2,108,0,125,1,116,1,160,2,124,0,161,1, - 106,3,125,2,124,1,160,4,124,2,161,1,125,3,116,1, - 160,5,100,2,100,3,161,2,125,4,124,4,160,6,124,0, - 160,6,124,3,100,1,25,0,161,1,161,1,83,0,41,4, - 122,121,68,101,99,111,100,101,32,98,121,116,101,115,32,114, - 101,112,114,101,115,101,110,116,105,110,103,32,115,111,117,114, - 99,101,32,99,111,100,101,32,97,110,100,32,114,101,116,117, - 114,110,32,116,104,101,32,115,116,114,105,110,103,46,10,10, - 32,32,32,32,85,110,105,118,101,114,115,97,108,32,110,101, - 119,108,105,110,101,32,115,117,112,112,111,114,116,32,105,115, - 32,117,115,101,100,32,105,110,32,116,104,101,32,100,101,99, - 111,100,105,110,103,46,10,32,32,32,32,114,73,0,0,0, - 78,84,41,7,218,8,116,111,107,101,110,105,122,101,114,64, - 0,0,0,90,7,66,121,116,101,115,73,79,90,8,114,101, - 97,100,108,105,110,101,90,15,100,101,116,101,99,116,95,101, - 110,99,111,100,105,110,103,90,25,73,110,99,114,101,109,101, - 110,116,97,108,78,101,119,108,105,110,101,68,101,99,111,100, - 101,114,218,6,100,101,99,111,100,101,41,5,218,12,115,111, - 117,114,99,101,95,98,121,116,101,115,114,172,0,0,0,90, - 21,115,111,117,114,99,101,95,98,121,116,101,115,95,114,101, - 97,100,108,105,110,101,218,8,101,110,99,111,100,105,110,103, - 90,15,110,101,119,108,105,110,101,95,100,101,99,111,100,101, - 114,114,5,0,0,0,114,5,0,0,0,114,8,0,0,0, - 218,13,100,101,99,111,100,101,95,115,111,117,114,99,101,107, - 2,0,0,115,10,0,0,0,0,5,8,1,12,1,10,1, - 12,1,114,176,0,0,0,169,2,114,140,0,0,0,218,26, - 115,117,98,109,111,100,117,108,101,95,115,101,97,114,99,104, - 95,108,111,99,97,116,105,111,110,115,99,2,0,0,0,0, - 0,0,0,2,0,0,0,9,0,0,0,8,0,0,0,67, - 0,0,0,115,12,1,0,0,124,1,100,1,117,0,114,58, - 100,2,125,1,116,0,124,2,100,3,131,2,114,68,122,14, - 124,2,160,1,124,0,161,1,125,1,87,0,113,68,4,0, - 116,2,121,54,1,0,1,0,1,0,89,0,113,68,48,0, - 110,10,116,3,160,4,124,1,161,1,125,1,116,5,106,6, - 124,0,124,2,124,1,100,4,141,3,125,4,100,5,124,4, - 95,7,124,2,100,1,117,0,114,152,116,8,131,0,68,0, - 93,42,92,2,125,5,125,6,124,1,160,9,116,10,124,6, - 131,1,161,1,114,104,124,5,124,0,124,1,131,2,125,2, - 124,2,124,4,95,11,1,0,113,152,113,104,100,1,83,0, - 124,3,116,12,117,0,114,216,116,0,124,2,100,6,131,2, - 114,222,122,14,124,2,160,13,124,0,161,1,125,7,87,0, - 110,18,4,0,116,2,121,202,1,0,1,0,1,0,89,0, - 113,222,48,0,124,7,114,222,103,0,124,4,95,14,110,6, - 124,3,124,4,95,14,124,4,106,14,103,0,107,2,144,1, - 114,8,124,1,144,1,114,8,116,15,124,1,131,1,100,7, - 25,0,125,8,124,4,106,14,160,16,124,8,161,1,1,0, - 124,4,83,0,41,8,97,61,1,0,0,82,101,116,117,114, - 110,32,97,32,109,111,100,117,108,101,32,115,112,101,99,32, - 98,97,115,101,100,32,111,110,32,97,32,102,105,108,101,32, - 108,111,99,97,116,105,111,110,46,10,10,32,32,32,32,84, - 111,32,105,110,100,105,99,97,116,101,32,116,104,97,116,32, - 116,104,101,32,109,111,100,117,108,101,32,105,115,32,97,32, - 112,97,99,107,97,103,101,44,32,115,101,116,10,32,32,32, - 32,115,117,98,109,111,100,117,108,101,95,115,101,97,114,99, - 104,95,108,111,99,97,116,105,111,110,115,32,116,111,32,97, - 32,108,105,115,116,32,111,102,32,100,105,114,101,99,116,111, - 114,121,32,112,97,116,104,115,46,32,32,65,110,10,32,32, - 32,32,101,109,112,116,121,32,108,105,115,116,32,105,115,32, - 115,117,102,102,105,99,105,101,110,116,44,32,116,104,111,117, - 103,104,32,105,116,115,32,110,111,116,32,111,116,104,101,114, - 119,105,115,101,32,117,115,101,102,117,108,32,116,111,32,116, - 104,101,10,32,32,32,32,105,109,112,111,114,116,32,115,121, - 115,116,101,109,46,10,10,32,32,32,32,84,104,101,32,108, - 111,97,100,101,114,32,109,117,115,116,32,116,97,107,101,32, - 97,32,115,112,101,99,32,97,115,32,105,116,115,32,111,110, - 108,121,32,95,95,105,110,105,116,95,95,40,41,32,97,114, - 103,46,10,10,32,32,32,32,78,122,9,60,117,110,107,110, - 111,119,110,62,218,12,103,101,116,95,102,105,108,101,110,97, - 109,101,169,1,218,6,111,114,105,103,105,110,84,218,10,105, - 115,95,112,97,99,107,97,103,101,114,73,0,0,0,41,17, - 114,128,0,0,0,114,179,0,0,0,114,117,0,0,0,114, - 4,0,0,0,114,79,0,0,0,114,134,0,0,0,218,10, - 77,111,100,117,108,101,83,112,101,99,90,13,95,115,101,116, - 95,102,105,108,101,97,116,116,114,218,27,95,103,101,116,95, - 115,117,112,112,111,114,116,101,100,95,102,105,108,101,95,108, - 111,97,100,101,114,115,114,110,0,0,0,114,111,0,0,0, - 114,140,0,0,0,218,9,95,80,79,80,85,76,65,84,69, - 114,182,0,0,0,114,178,0,0,0,114,47,0,0,0,218, - 6,97,112,112,101,110,100,41,9,114,116,0,0,0,90,8, - 108,111,99,97,116,105,111,110,114,140,0,0,0,114,178,0, - 0,0,218,4,115,112,101,99,218,12,108,111,97,100,101,114, - 95,99,108,97,115,115,218,8,115,117,102,102,105,120,101,115, - 114,182,0,0,0,90,7,100,105,114,110,97,109,101,114,5, - 0,0,0,114,5,0,0,0,114,8,0,0,0,218,23,115, - 112,101,99,95,102,114,111,109,95,102,105,108,101,95,108,111, - 99,97,116,105,111,110,124,2,0,0,115,62,0,0,0,0, - 12,8,4,4,1,10,2,2,1,14,1,12,1,8,2,10, - 8,16,1,6,3,8,1,14,1,14,1,10,1,6,1,6, - 2,4,3,8,2,10,1,2,1,14,1,12,1,6,2,4, - 1,8,2,6,1,12,1,6,1,12,1,12,2,114,190,0, + 0,0,0,218,13,95,99,108,97,115,115,105,102,121,95,112, + 121,99,244,1,0,0,115,28,0,0,0,0,16,12,1,8, + 1,16,1,12,1,16,1,12,1,10,1,12,1,8,1,16, + 2,8,1,16,1,16,1,114,152,0,0,0,99,5,0,0, + 0,0,0,0,0,0,0,0,0,6,0,0,0,4,0,0, + 0,67,0,0,0,115,120,0,0,0,116,0,124,0,100,1, + 100,2,133,2,25,0,131,1,124,1,100,3,64,0,107,3, + 114,62,100,4,124,3,155,2,157,2,125,5,116,1,160,2, + 100,5,124,5,161,2,1,0,116,3,124,5,102,1,105,0, + 124,4,164,1,142,1,130,1,124,2,100,6,117,1,114,116, + 116,0,124,0,100,2,100,7,133,2,25,0,131,1,124,2, + 100,3,64,0,107,3,114,116,116,3,100,4,124,3,155,2, + 157,2,102,1,105,0,124,4,164,1,142,1,130,1,100,6, + 83,0,41,8,97,7,2,0,0,86,97,108,105,100,97,116, + 101,32,97,32,112,121,99,32,97,103,97,105,110,115,116,32, + 116,104,101,32,115,111,117,114,99,101,32,108,97,115,116,45, + 109,111,100,105,102,105,101,100,32,116,105,109,101,46,10,10, + 32,32,32,32,42,100,97,116,97,42,32,105,115,32,116,104, + 101,32,99,111,110,116,101,110,116,115,32,111,102,32,116,104, + 101,32,112,121,99,32,102,105,108,101,46,32,40,79,110,108, + 121,32,116,104,101,32,102,105,114,115,116,32,49,54,32,98, + 121,116,101,115,32,97,114,101,10,32,32,32,32,114,101,113, + 117,105,114,101,100,46,41,10,10,32,32,32,32,42,115,111, + 117,114,99,101,95,109,116,105,109,101,42,32,105,115,32,116, + 104,101,32,108,97,115,116,32,109,111,100,105,102,105,101,100, + 32,116,105,109,101,115,116,97,109,112,32,111,102,32,116,104, + 101,32,115,111,117,114,99,101,32,102,105,108,101,46,10,10, + 32,32,32,32,42,115,111,117,114,99,101,95,115,105,122,101, + 42,32,105,115,32,78,111,110,101,32,111,114,32,116,104,101, + 32,115,105,122,101,32,111,102,32,116,104,101,32,115,111,117, + 114,99,101,32,102,105,108,101,32,105,110,32,98,121,116,101, + 115,46,10,10,32,32,32,32,42,110,97,109,101,42,32,105, + 115,32,116,104,101,32,110,97,109,101,32,111,102,32,116,104, + 101,32,109,111,100,117,108,101,32,98,101,105,110,103,32,105, + 109,112,111,114,116,101,100,46,32,73,116,32,105,115,32,117, + 115,101,100,32,102,111,114,32,108,111,103,103,105,110,103,46, + 10,10,32,32,32,32,42,101,120,99,95,100,101,116,97,105, + 108,115,42,32,105,115,32,97,32,100,105,99,116,105,111,110, + 97,114,121,32,112,97,115,115,101,100,32,116,111,32,73,109, + 112,111,114,116,69,114,114,111,114,32,105,102,32,105,116,32, + 114,97,105,115,101,100,32,102,111,114,10,32,32,32,32,105, + 109,112,114,111,118,101,100,32,100,101,98,117,103,103,105,110, + 103,46,10,10,32,32,32,32,65,110,32,73,109,112,111,114, + 116,69,114,114,111,114,32,105,115,32,114,97,105,115,101,100, + 32,105,102,32,116,104,101,32,98,121,116,101,99,111,100,101, + 32,105,115,32,115,116,97,108,101,46,10,10,32,32,32,32, + 114,146,0,0,0,233,12,0,0,0,114,15,0,0,0,122, + 22,98,121,116,101,99,111,100,101,32,105,115,32,115,116,97, + 108,101,32,102,111,114,32,114,144,0,0,0,78,114,145,0, + 0,0,41,4,114,27,0,0,0,114,134,0,0,0,114,149, + 0,0,0,114,117,0,0,0,41,6,114,26,0,0,0,218, + 12,115,111,117,114,99,101,95,109,116,105,109,101,218,11,115, + 111,117,114,99,101,95,115,105,122,101,114,116,0,0,0,114, + 151,0,0,0,114,92,0,0,0,114,5,0,0,0,114,5, + 0,0,0,114,8,0,0,0,218,23,95,118,97,108,105,100, + 97,116,101,95,116,105,109,101,115,116,97,109,112,95,112,121, + 99,21,2,0,0,115,16,0,0,0,0,19,24,1,10,1, + 12,1,16,1,8,1,22,255,2,2,114,156,0,0,0,99, + 4,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0, + 4,0,0,0,67,0,0,0,115,42,0,0,0,124,0,100, + 1,100,2,133,2,25,0,124,1,107,3,114,38,116,0,100, + 3,124,2,155,2,157,2,102,1,105,0,124,3,164,1,142, + 1,130,1,100,4,83,0,41,5,97,243,1,0,0,86,97, + 108,105,100,97,116,101,32,97,32,104,97,115,104,45,98,97, + 115,101,100,32,112,121,99,32,98,121,32,99,104,101,99,107, + 105,110,103,32,116,104,101,32,114,101,97,108,32,115,111,117, + 114,99,101,32,104,97,115,104,32,97,103,97,105,110,115,116, + 32,116,104,101,32,111,110,101,32,105,110,10,32,32,32,32, + 116,104,101,32,112,121,99,32,104,101,97,100,101,114,46,10, + 10,32,32,32,32,42,100,97,116,97,42,32,105,115,32,116, + 104,101,32,99,111,110,116,101,110,116,115,32,111,102,32,116, + 104,101,32,112,121,99,32,102,105,108,101,46,32,40,79,110, + 108,121,32,116,104,101,32,102,105,114,115,116,32,49,54,32, + 98,121,116,101,115,32,97,114,101,10,32,32,32,32,114,101, + 113,117,105,114,101,100,46,41,10,10,32,32,32,32,42,115, + 111,117,114,99,101,95,104,97,115,104,42,32,105,115,32,116, + 104,101,32,105,109,112,111,114,116,108,105,98,46,117,116,105, + 108,46,115,111,117,114,99,101,95,104,97,115,104,40,41,32, + 111,102,32,116,104,101,32,115,111,117,114,99,101,32,102,105, + 108,101,46,10,10,32,32,32,32,42,110,97,109,101,42,32, + 105,115,32,116,104,101,32,110,97,109,101,32,111,102,32,116, + 104,101,32,109,111,100,117,108,101,32,98,101,105,110,103,32, + 105,109,112,111,114,116,101,100,46,32,73,116,32,105,115,32, + 117,115,101,100,32,102,111,114,32,108,111,103,103,105,110,103, + 46,10,10,32,32,32,32,42,101,120,99,95,100,101,116,97, + 105,108,115,42,32,105,115,32,97,32,100,105,99,116,105,111, + 110,97,114,121,32,112,97,115,115,101,100,32,116,111,32,73, + 109,112,111,114,116,69,114,114,111,114,32,105,102,32,105,116, + 32,114,97,105,115,101,100,32,102,111,114,10,32,32,32,32, + 105,109,112,114,111,118,101,100,32,100,101,98,117,103,103,105, + 110,103,46,10,10,32,32,32,32,65,110,32,73,109,112,111, + 114,116,69,114,114,111,114,32,105,115,32,114,97,105,115,101, + 100,32,105,102,32,116,104,101,32,98,121,116,101,99,111,100, + 101,32,105,115,32,115,116,97,108,101,46,10,10,32,32,32, + 32,114,146,0,0,0,114,145,0,0,0,122,46,104,97,115, + 104,32,105,110,32,98,121,116,101,99,111,100,101,32,100,111, + 101,115,110,39,116,32,109,97,116,99,104,32,104,97,115,104, + 32,111,102,32,115,111,117,114,99,101,32,78,41,1,114,117, + 0,0,0,41,4,114,26,0,0,0,218,11,115,111,117,114, + 99,101,95,104,97,115,104,114,116,0,0,0,114,151,0,0, + 0,114,5,0,0,0,114,5,0,0,0,114,8,0,0,0, + 218,18,95,118,97,108,105,100,97,116,101,95,104,97,115,104, + 95,112,121,99,49,2,0,0,115,12,0,0,0,0,17,16, + 1,2,1,8,255,4,2,2,254,114,158,0,0,0,99,4, + 0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,5, + 0,0,0,67,0,0,0,115,80,0,0,0,116,0,160,1, + 124,0,161,1,125,4,116,2,124,4,116,3,131,2,114,56, + 116,4,160,5,100,1,124,2,161,2,1,0,124,3,100,2, + 117,1,114,52,116,6,160,7,124,4,124,3,161,2,1,0, + 124,4,83,0,116,8,100,3,160,9,124,2,161,1,124,1, + 124,2,100,4,141,3,130,1,100,2,83,0,41,5,122,35, + 67,111,109,112,105,108,101,32,98,121,116,101,99,111,100,101, + 32,97,115,32,102,111,117,110,100,32,105,110,32,97,32,112, + 121,99,46,122,21,99,111,100,101,32,111,98,106,101,99,116, + 32,102,114,111,109,32,123,33,114,125,78,122,23,78,111,110, + 45,99,111,100,101,32,111,98,106,101,99,116,32,105,110,32, + 123,33,114,125,169,2,114,116,0,0,0,114,44,0,0,0, + 41,10,218,7,109,97,114,115,104,97,108,90,5,108,111,97, + 100,115,218,10,105,115,105,110,115,116,97,110,99,101,218,10, + 95,99,111,100,101,95,116,121,112,101,114,134,0,0,0,114, + 149,0,0,0,218,4,95,105,109,112,90,16,95,102,105,120, + 95,99,111,95,102,105,108,101,110,97,109,101,114,117,0,0, + 0,114,62,0,0,0,41,5,114,26,0,0,0,114,116,0, + 0,0,114,106,0,0,0,114,107,0,0,0,218,4,99,111, + 100,101,114,5,0,0,0,114,5,0,0,0,114,8,0,0, + 0,218,17,95,99,111,109,112,105,108,101,95,98,121,116,101, + 99,111,100,101,73,2,0,0,115,18,0,0,0,0,2,10, + 1,10,1,12,1,8,1,12,1,4,2,10,1,4,255,114, + 165,0,0,0,114,73,0,0,0,99,3,0,0,0,0,0, + 0,0,0,0,0,0,4,0,0,0,5,0,0,0,67,0, + 0,0,115,70,0,0,0,116,0,116,1,131,1,125,3,124, + 3,160,2,116,3,100,1,131,1,161,1,1,0,124,3,160, + 2,116,3,124,1,131,1,161,1,1,0,124,3,160,2,116, + 3,124,2,131,1,161,1,1,0,124,3,160,2,116,4,160, + 5,124,0,161,1,161,1,1,0,124,3,83,0,41,2,122, + 43,80,114,111,100,117,99,101,32,116,104,101,32,100,97,116, + 97,32,102,111,114,32,97,32,116,105,109,101,115,116,97,109, + 112,45,98,97,115,101,100,32,112,121,99,46,114,73,0,0, + 0,41,6,218,9,98,121,116,101,97,114,114,97,121,114,148, + 0,0,0,218,6,101,120,116,101,110,100,114,21,0,0,0, + 114,160,0,0,0,218,5,100,117,109,112,115,41,4,114,164, + 0,0,0,218,5,109,116,105,109,101,114,155,0,0,0,114, + 26,0,0,0,114,5,0,0,0,114,5,0,0,0,114,8, + 0,0,0,218,22,95,99,111,100,101,95,116,111,95,116,105, + 109,101,115,116,97,109,112,95,112,121,99,86,2,0,0,115, + 12,0,0,0,0,2,8,1,14,1,14,1,14,1,16,1, + 114,170,0,0,0,84,99,3,0,0,0,0,0,0,0,0, + 0,0,0,5,0,0,0,5,0,0,0,67,0,0,0,115, + 80,0,0,0,116,0,116,1,131,1,125,3,100,1,124,2, + 100,1,62,0,66,0,125,4,124,3,160,2,116,3,124,4, + 131,1,161,1,1,0,116,4,124,1,131,1,100,2,107,2, + 115,50,74,0,130,1,124,3,160,2,124,1,161,1,1,0, + 124,3,160,2,116,5,160,6,124,0,161,1,161,1,1,0, + 124,3,83,0,41,3,122,38,80,114,111,100,117,99,101,32, + 116,104,101,32,100,97,116,97,32,102,111,114,32,97,32,104, + 97,115,104,45,98,97,115,101,100,32,112,121,99,46,114,39, + 0,0,0,114,146,0,0,0,41,7,114,166,0,0,0,114, + 148,0,0,0,114,167,0,0,0,114,21,0,0,0,114,23, + 0,0,0,114,160,0,0,0,114,168,0,0,0,41,5,114, + 164,0,0,0,114,157,0,0,0,90,7,99,104,101,99,107, + 101,100,114,26,0,0,0,114,2,0,0,0,114,5,0,0, + 0,114,5,0,0,0,114,8,0,0,0,218,17,95,99,111, + 100,101,95,116,111,95,104,97,115,104,95,112,121,99,96,2, + 0,0,115,14,0,0,0,0,2,8,1,12,1,14,1,16, + 1,10,1,16,1,114,171,0,0,0,99,1,0,0,0,0, + 0,0,0,0,0,0,0,5,0,0,0,6,0,0,0,67, + 0,0,0,115,62,0,0,0,100,1,100,2,108,0,125,1, + 116,1,160,2,124,0,161,1,106,3,125,2,124,1,160,4, + 124,2,161,1,125,3,116,1,160,5,100,2,100,3,161,2, + 125,4,124,4,160,6,124,0,160,6,124,3,100,1,25,0, + 161,1,161,1,83,0,41,4,122,121,68,101,99,111,100,101, + 32,98,121,116,101,115,32,114,101,112,114,101,115,101,110,116, + 105,110,103,32,115,111,117,114,99,101,32,99,111,100,101,32, + 97,110,100,32,114,101,116,117,114,110,32,116,104,101,32,115, + 116,114,105,110,103,46,10,10,32,32,32,32,85,110,105,118, + 101,114,115,97,108,32,110,101,119,108,105,110,101,32,115,117, + 112,112,111,114,116,32,105,115,32,117,115,101,100,32,105,110, + 32,116,104,101,32,100,101,99,111,100,105,110,103,46,10,32, + 32,32,32,114,73,0,0,0,78,84,41,7,218,8,116,111, + 107,101,110,105,122,101,114,64,0,0,0,90,7,66,121,116, + 101,115,73,79,90,8,114,101,97,100,108,105,110,101,90,15, + 100,101,116,101,99,116,95,101,110,99,111,100,105,110,103,90, + 25,73,110,99,114,101,109,101,110,116,97,108,78,101,119,108, + 105,110,101,68,101,99,111,100,101,114,218,6,100,101,99,111, + 100,101,41,5,218,12,115,111,117,114,99,101,95,98,121,116, + 101,115,114,172,0,0,0,90,21,115,111,117,114,99,101,95, + 98,121,116,101,115,95,114,101,97,100,108,105,110,101,218,8, + 101,110,99,111,100,105,110,103,90,15,110,101,119,108,105,110, + 101,95,100,101,99,111,100,101,114,114,5,0,0,0,114,5, + 0,0,0,114,8,0,0,0,218,13,100,101,99,111,100,101, + 95,115,111,117,114,99,101,107,2,0,0,115,10,0,0,0, + 0,5,8,1,12,1,10,1,12,1,114,176,0,0,0,169, + 2,114,140,0,0,0,218,26,115,117,98,109,111,100,117,108, + 101,95,115,101,97,114,99,104,95,108,111,99,97,116,105,111, + 110,115,99,2,0,0,0,0,0,0,0,2,0,0,0,9, + 0,0,0,8,0,0,0,67,0,0,0,115,12,1,0,0, + 124,1,100,1,117,0,114,58,100,2,125,1,116,0,124,2, + 100,3,131,2,114,68,122,14,124,2,160,1,124,0,161,1, + 125,1,87,0,113,68,4,0,116,2,121,54,1,0,1,0, + 1,0,89,0,113,68,48,0,110,10,116,3,160,4,124,1, + 161,1,125,1,116,5,106,6,124,0,124,2,124,1,100,4, + 141,3,125,4,100,5,124,4,95,7,124,2,100,1,117,0, + 114,152,116,8,131,0,68,0,93,42,92,2,125,5,125,6, + 124,1,160,9,116,10,124,6,131,1,161,1,114,104,124,5, + 124,0,124,1,131,2,125,2,124,2,124,4,95,11,1,0, + 113,152,113,104,100,1,83,0,124,3,116,12,117,0,114,216, + 116,0,124,2,100,6,131,2,114,222,122,14,124,2,160,13, + 124,0,161,1,125,7,87,0,110,18,4,0,116,2,121,202, + 1,0,1,0,1,0,89,0,113,222,48,0,124,7,114,222, + 103,0,124,4,95,14,110,6,124,3,124,4,95,14,124,4, + 106,14,103,0,107,2,144,1,114,8,124,1,144,1,114,8, + 116,15,124,1,131,1,100,7,25,0,125,8,124,4,106,14, + 160,16,124,8,161,1,1,0,124,4,83,0,41,8,97,61, + 1,0,0,82,101,116,117,114,110,32,97,32,109,111,100,117, + 108,101,32,115,112,101,99,32,98,97,115,101,100,32,111,110, + 32,97,32,102,105,108,101,32,108,111,99,97,116,105,111,110, + 46,10,10,32,32,32,32,84,111,32,105,110,100,105,99,97, + 116,101,32,116,104,97,116,32,116,104,101,32,109,111,100,117, + 108,101,32,105,115,32,97,32,112,97,99,107,97,103,101,44, + 32,115,101,116,10,32,32,32,32,115,117,98,109,111,100,117, + 108,101,95,115,101,97,114,99,104,95,108,111,99,97,116,105, + 111,110,115,32,116,111,32,97,32,108,105,115,116,32,111,102, + 32,100,105,114,101,99,116,111,114,121,32,112,97,116,104,115, + 46,32,32,65,110,10,32,32,32,32,101,109,112,116,121,32, + 108,105,115,116,32,105,115,32,115,117,102,102,105,99,105,101, + 110,116,44,32,116,104,111,117,103,104,32,105,116,115,32,110, + 111,116,32,111,116,104,101,114,119,105,115,101,32,117,115,101, + 102,117,108,32,116,111,32,116,104,101,10,32,32,32,32,105, + 109,112,111,114,116,32,115,121,115,116,101,109,46,10,10,32, + 32,32,32,84,104,101,32,108,111,97,100,101,114,32,109,117, + 115,116,32,116,97,107,101,32,97,32,115,112,101,99,32,97, + 115,32,105,116,115,32,111,110,108,121,32,95,95,105,110,105, + 116,95,95,40,41,32,97,114,103,46,10,10,32,32,32,32, + 78,122,9,60,117,110,107,110,111,119,110,62,218,12,103,101, + 116,95,102,105,108,101,110,97,109,101,169,1,218,6,111,114, + 105,103,105,110,84,218,10,105,115,95,112,97,99,107,97,103, + 101,114,73,0,0,0,41,17,114,128,0,0,0,114,179,0, + 0,0,114,117,0,0,0,114,4,0,0,0,114,79,0,0, + 0,114,134,0,0,0,218,10,77,111,100,117,108,101,83,112, + 101,99,90,13,95,115,101,116,95,102,105,108,101,97,116,116, + 114,218,27,95,103,101,116,95,115,117,112,112,111,114,116,101, + 100,95,102,105,108,101,95,108,111,97,100,101,114,115,114,110, + 0,0,0,114,111,0,0,0,114,140,0,0,0,218,9,95, + 80,79,80,85,76,65,84,69,114,182,0,0,0,114,178,0, + 0,0,114,47,0,0,0,218,6,97,112,112,101,110,100,41, + 9,114,116,0,0,0,90,8,108,111,99,97,116,105,111,110, + 114,140,0,0,0,114,178,0,0,0,218,4,115,112,101,99, + 218,12,108,111,97,100,101,114,95,99,108,97,115,115,218,8, + 115,117,102,102,105,120,101,115,114,182,0,0,0,90,7,100, + 105,114,110,97,109,101,114,5,0,0,0,114,5,0,0,0, + 114,8,0,0,0,218,23,115,112,101,99,95,102,114,111,109, + 95,102,105,108,101,95,108,111,99,97,116,105,111,110,124,2, + 0,0,115,62,0,0,0,0,12,8,4,4,1,10,2,2, + 1,14,1,12,1,8,2,10,8,16,1,6,3,8,1,14, + 1,14,1,10,1,6,1,6,2,4,3,8,2,10,1,2, + 1,14,1,12,1,6,2,4,1,8,2,6,1,12,1,6, + 1,12,1,12,2,114,190,0,0,0,99,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,64, + 0,0,0,115,80,0,0,0,101,0,90,1,100,0,90,2, + 100,1,90,3,100,2,90,4,100,3,90,5,100,4,90,6, + 101,7,100,5,100,6,132,0,131,1,90,8,101,7,100,7, + 100,8,132,0,131,1,90,9,101,7,100,14,100,10,100,11, + 132,1,131,1,90,10,101,7,100,15,100,12,100,13,132,1, + 131,1,90,11,100,9,83,0,41,16,218,21,87,105,110,100, + 111,119,115,82,101,103,105,115,116,114,121,70,105,110,100,101, + 114,122,62,77,101,116,97,32,112,97,116,104,32,102,105,110, + 100,101,114,32,102,111,114,32,109,111,100,117,108,101,115,32, + 100,101,99,108,97,114,101,100,32,105,110,32,116,104,101,32, + 87,105,110,100,111,119,115,32,114,101,103,105,115,116,114,121, + 46,122,59,83,111,102,116,119,97,114,101,92,80,121,116,104, + 111,110,92,80,121,116,104,111,110,67,111,114,101,92,123,115, + 121,115,95,118,101,114,115,105,111,110,125,92,77,111,100,117, + 108,101,115,92,123,102,117,108,108,110,97,109,101,125,122,65, + 83,111,102,116,119,97,114,101,92,80,121,116,104,111,110,92, + 80,121,116,104,111,110,67,111,114,101,92,123,115,121,115,95, + 118,101,114,115,105,111,110,125,92,77,111,100,117,108,101,115, + 92,123,102,117,108,108,110,97,109,101,125,92,68,101,98,117, + 103,70,99,2,0,0,0,0,0,0,0,0,0,0,0,2, + 0,0,0,8,0,0,0,67,0,0,0,115,54,0,0,0, + 122,16,116,0,160,1,116,0,106,2,124,1,161,2,87,0, + 83,0,4,0,116,3,121,48,1,0,1,0,1,0,116,0, + 160,1,116,0,106,4,124,1,161,2,6,0,89,0,83,0, + 48,0,100,0,83,0,114,109,0,0,0,41,5,218,6,119, + 105,110,114,101,103,90,7,79,112,101,110,75,101,121,90,17, + 72,75,69,89,95,67,85,82,82,69,78,84,95,85,83,69, + 82,114,50,0,0,0,90,18,72,75,69,89,95,76,79,67, + 65,76,95,77,65,67,72,73,78,69,41,2,218,3,99,108, + 115,114,7,0,0,0,114,5,0,0,0,114,5,0,0,0, + 114,8,0,0,0,218,14,95,111,112,101,110,95,114,101,103, + 105,115,116,114,121,204,2,0,0,115,8,0,0,0,0,2, + 2,1,16,1,12,1,122,36,87,105,110,100,111,119,115,82, + 101,103,105,115,116,114,121,70,105,110,100,101,114,46,95,111, + 112,101,110,95,114,101,103,105,115,116,114,121,99,2,0,0, + 0,0,0,0,0,0,0,0,0,6,0,0,0,8,0,0, + 0,67,0,0,0,115,132,0,0,0,124,0,106,0,114,14, + 124,0,106,1,125,2,110,6,124,0,106,2,125,2,124,2, + 106,3,124,1,100,1,116,4,106,5,100,0,100,2,133,2, + 25,0,22,0,100,3,141,2,125,3,122,58,124,0,160,6, + 124,3,161,1,143,28,125,4,116,7,160,8,124,4,100,4, + 161,2,125,5,87,0,100,0,4,0,4,0,131,3,1,0, + 110,16,49,0,115,94,48,0,1,0,1,0,1,0,89,0, + 1,0,87,0,110,20,4,0,116,9,121,126,1,0,1,0, + 1,0,89,0,100,0,83,0,48,0,124,5,83,0,41,5, + 78,122,5,37,100,46,37,100,114,28,0,0,0,41,2,114, + 139,0,0,0,90,11,115,121,115,95,118,101,114,115,105,111, + 110,114,40,0,0,0,41,10,218,11,68,69,66,85,71,95, + 66,85,73,76,68,218,18,82,69,71,73,83,84,82,89,95, + 75,69,89,95,68,69,66,85,71,218,12,82,69,71,73,83, + 84,82,89,95,75,69,89,114,62,0,0,0,114,1,0,0, + 0,218,12,118,101,114,115,105,111,110,95,105,110,102,111,114, + 194,0,0,0,114,192,0,0,0,90,10,81,117,101,114,121, + 86,97,108,117,101,114,50,0,0,0,41,6,114,193,0,0, + 0,114,139,0,0,0,90,12,114,101,103,105,115,116,114,121, + 95,107,101,121,114,7,0,0,0,90,4,104,107,101,121,218, + 8,102,105,108,101,112,97,116,104,114,5,0,0,0,114,5, + 0,0,0,114,8,0,0,0,218,16,95,115,101,97,114,99, + 104,95,114,101,103,105,115,116,114,121,211,2,0,0,115,24, + 0,0,0,0,2,6,1,8,2,6,1,6,1,16,255,6, + 2,2,1,12,1,46,1,12,1,8,1,122,38,87,105,110, + 100,111,119,115,82,101,103,105,115,116,114,121,70,105,110,100, + 101,114,46,95,115,101,97,114,99,104,95,114,101,103,105,115, + 116,114,121,78,99,4,0,0,0,0,0,0,0,0,0,0, + 0,8,0,0,0,8,0,0,0,67,0,0,0,115,120,0, + 0,0,124,0,160,0,124,1,161,1,125,4,124,4,100,0, + 117,0,114,22,100,0,83,0,122,12,116,1,124,4,131,1, + 1,0,87,0,110,20,4,0,116,2,121,54,1,0,1,0, + 1,0,89,0,100,0,83,0,48,0,116,3,131,0,68,0, + 93,52,92,2,125,5,125,6,124,4,160,4,116,5,124,6, + 131,1,161,1,114,62,116,6,106,7,124,1,124,5,124,1, + 124,4,131,2,124,4,100,1,141,3,125,7,124,7,2,0, + 1,0,83,0,113,62,100,0,83,0,41,2,78,114,180,0, + 0,0,41,8,114,200,0,0,0,114,49,0,0,0,114,50, + 0,0,0,114,184,0,0,0,114,110,0,0,0,114,111,0, + 0,0,114,134,0,0,0,218,16,115,112,101,99,95,102,114, + 111,109,95,108,111,97,100,101,114,41,8,114,193,0,0,0, + 114,139,0,0,0,114,44,0,0,0,218,6,116,97,114,103, + 101,116,114,199,0,0,0,114,140,0,0,0,114,189,0,0, + 0,114,187,0,0,0,114,5,0,0,0,114,5,0,0,0, + 114,8,0,0,0,218,9,102,105,110,100,95,115,112,101,99, + 226,2,0,0,115,28,0,0,0,0,2,10,1,8,1,4, + 1,2,1,12,1,12,1,8,1,14,1,14,1,6,1,8, + 1,2,254,6,3,122,31,87,105,110,100,111,119,115,82,101, + 103,105,115,116,114,121,70,105,110,100,101,114,46,102,105,110, + 100,95,115,112,101,99,99,3,0,0,0,0,0,0,0,0, + 0,0,0,4,0,0,0,4,0,0,0,67,0,0,0,115, + 34,0,0,0,124,0,160,0,124,1,124,2,161,2,125,3, + 124,3,100,1,117,1,114,26,124,3,106,1,83,0,100,1, + 83,0,100,1,83,0,41,2,122,108,70,105,110,100,32,109, + 111,100,117,108,101,32,110,97,109,101,100,32,105,110,32,116, + 104,101,32,114,101,103,105,115,116,114,121,46,10,10,32,32, + 32,32,32,32,32,32,84,104,105,115,32,109,101,116,104,111, + 100,32,105,115,32,100,101,112,114,101,99,97,116,101,100,46, + 32,32,85,115,101,32,101,120,101,99,95,109,111,100,117,108, + 101,40,41,32,105,110,115,116,101,97,100,46,10,10,32,32, + 32,32,32,32,32,32,78,169,2,114,203,0,0,0,114,140, + 0,0,0,169,4,114,193,0,0,0,114,139,0,0,0,114, + 44,0,0,0,114,187,0,0,0,114,5,0,0,0,114,5, + 0,0,0,114,8,0,0,0,218,11,102,105,110,100,95,109, + 111,100,117,108,101,242,2,0,0,115,8,0,0,0,0,7, + 12,1,8,1,6,2,122,33,87,105,110,100,111,119,115,82, + 101,103,105,115,116,114,121,70,105,110,100,101,114,46,102,105, + 110,100,95,109,111,100,117,108,101,41,2,78,78,41,1,78, + 41,12,114,125,0,0,0,114,124,0,0,0,114,126,0,0, + 0,114,127,0,0,0,114,197,0,0,0,114,196,0,0,0, + 114,195,0,0,0,218,11,99,108,97,115,115,109,101,116,104, + 111,100,114,194,0,0,0,114,200,0,0,0,114,203,0,0, + 0,114,206,0,0,0,114,5,0,0,0,114,5,0,0,0, + 114,5,0,0,0,114,8,0,0,0,114,191,0,0,0,192, + 2,0,0,115,28,0,0,0,8,2,4,3,2,255,2,4, + 2,255,2,3,4,2,2,1,10,6,2,1,10,14,2,1, + 12,15,2,1,114,191,0,0,0,99,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,2,0,0,0,64,0, + 0,0,115,48,0,0,0,101,0,90,1,100,0,90,2,100, + 1,90,3,100,2,100,3,132,0,90,4,100,4,100,5,132, + 0,90,5,100,6,100,7,132,0,90,6,100,8,100,9,132, + 0,90,7,100,10,83,0,41,11,218,13,95,76,111,97,100, + 101,114,66,97,115,105,99,115,122,83,66,97,115,101,32,99, + 108,97,115,115,32,111,102,32,99,111,109,109,111,110,32,99, + 111,100,101,32,110,101,101,100,101,100,32,98,121,32,98,111, + 116,104,32,83,111,117,114,99,101,76,111,97,100,101,114,32, + 97,110,100,10,32,32,32,32,83,111,117,114,99,101,108,101, + 115,115,70,105,108,101,76,111,97,100,101,114,46,99,2,0, + 0,0,0,0,0,0,0,0,0,0,5,0,0,0,4,0, + 0,0,67,0,0,0,115,64,0,0,0,116,0,124,0,160, + 1,124,1,161,1,131,1,100,1,25,0,125,2,124,2,160, + 2,100,2,100,1,161,2,100,3,25,0,125,3,124,1,160, + 3,100,2,161,1,100,4,25,0,125,4,124,3,100,5,107, + 2,111,62,124,4,100,5,107,3,83,0,41,6,122,141,67, + 111,110,99,114,101,116,101,32,105,109,112,108,101,109,101,110, + 116,97,116,105,111,110,32,111,102,32,73,110,115,112,101,99, + 116,76,111,97,100,101,114,46,105,115,95,112,97,99,107,97, + 103,101,32,98,121,32,99,104,101,99,107,105,110,103,32,105, + 102,10,32,32,32,32,32,32,32,32,116,104,101,32,112,97, + 116,104,32,114,101,116,117,114,110,101,100,32,98,121,32,103, + 101,116,95,102,105,108,101,110,97,109,101,32,104,97,115,32, + 97,32,102,105,108,101,110,97,109,101,32,111,102,32,39,95, + 95,105,110,105,116,95,95,46,112,121,39,46,114,39,0,0, + 0,114,71,0,0,0,114,73,0,0,0,114,28,0,0,0, + 218,8,95,95,105,110,105,116,95,95,41,4,114,47,0,0, + 0,114,179,0,0,0,114,43,0,0,0,114,41,0,0,0, + 41,5,114,118,0,0,0,114,139,0,0,0,114,96,0,0, + 0,90,13,102,105,108,101,110,97,109,101,95,98,97,115,101, + 90,9,116,97,105,108,95,110,97,109,101,114,5,0,0,0, + 114,5,0,0,0,114,8,0,0,0,114,182,0,0,0,5, + 3,0,0,115,8,0,0,0,0,3,18,1,16,1,14,1, + 122,24,95,76,111,97,100,101,114,66,97,115,105,99,115,46, + 105,115,95,112,97,99,107,97,103,101,99,2,0,0,0,0, + 0,0,0,0,0,0,0,2,0,0,0,1,0,0,0,67, + 0,0,0,115,4,0,0,0,100,1,83,0,169,2,122,42, + 85,115,101,32,100,101,102,97,117,108,116,32,115,101,109,97, + 110,116,105,99,115,32,102,111,114,32,109,111,100,117,108,101, + 32,99,114,101,97,116,105,111,110,46,78,114,5,0,0,0, + 169,2,114,118,0,0,0,114,187,0,0,0,114,5,0,0, + 0,114,5,0,0,0,114,8,0,0,0,218,13,99,114,101, + 97,116,101,95,109,111,100,117,108,101,13,3,0,0,115,2, + 0,0,0,0,1,122,27,95,76,111,97,100,101,114,66,97, + 115,105,99,115,46,99,114,101,97,116,101,95,109,111,100,117, + 108,101,99,2,0,0,0,0,0,0,0,0,0,0,0,3, + 0,0,0,5,0,0,0,67,0,0,0,115,56,0,0,0, + 124,0,160,0,124,1,106,1,161,1,125,2,124,2,100,1, + 117,0,114,36,116,2,100,2,160,3,124,1,106,1,161,1, + 131,1,130,1,116,4,160,5,116,6,124,2,124,1,106,7, + 161,3,1,0,100,1,83,0,41,3,122,19,69,120,101,99, + 117,116,101,32,116,104,101,32,109,111,100,117,108,101,46,78, + 122,52,99,97,110,110,111,116,32,108,111,97,100,32,109,111, + 100,117,108,101,32,123,33,114,125,32,119,104,101,110,32,103, + 101,116,95,99,111,100,101,40,41,32,114,101,116,117,114,110, + 115,32,78,111,110,101,41,8,218,8,103,101,116,95,99,111, + 100,101,114,125,0,0,0,114,117,0,0,0,114,62,0,0, + 0,114,134,0,0,0,218,25,95,99,97,108,108,95,119,105, + 116,104,95,102,114,97,109,101,115,95,114,101,109,111,118,101, + 100,218,4,101,120,101,99,114,131,0,0,0,41,3,114,118, + 0,0,0,218,6,109,111,100,117,108,101,114,164,0,0,0, + 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,218, + 11,101,120,101,99,95,109,111,100,117,108,101,16,3,0,0, + 115,12,0,0,0,0,2,12,1,8,1,6,1,4,255,6, + 2,122,25,95,76,111,97,100,101,114,66,97,115,105,99,115, + 46,101,120,101,99,95,109,111,100,117,108,101,99,2,0,0, + 0,0,0,0,0,0,0,0,0,2,0,0,0,4,0,0, + 0,67,0,0,0,115,12,0,0,0,116,0,160,1,124,0, + 124,1,161,2,83,0,41,1,122,26,84,104,105,115,32,109, + 111,100,117,108,101,32,105,115,32,100,101,112,114,101,99,97, + 116,101,100,46,41,2,114,134,0,0,0,218,17,95,108,111, + 97,100,95,109,111,100,117,108,101,95,115,104,105,109,169,2, + 114,118,0,0,0,114,139,0,0,0,114,5,0,0,0,114, + 5,0,0,0,114,8,0,0,0,218,11,108,111,97,100,95, + 109,111,100,117,108,101,24,3,0,0,115,2,0,0,0,0, + 2,122,25,95,76,111,97,100,101,114,66,97,115,105,99,115, + 46,108,111,97,100,95,109,111,100,117,108,101,78,41,8,114, + 125,0,0,0,114,124,0,0,0,114,126,0,0,0,114,127, + 0,0,0,114,182,0,0,0,114,212,0,0,0,114,217,0, + 0,0,114,220,0,0,0,114,5,0,0,0,114,5,0,0, + 0,114,5,0,0,0,114,8,0,0,0,114,208,0,0,0, + 0,3,0,0,115,10,0,0,0,8,2,4,3,8,8,8, + 3,8,8,114,208,0,0,0,99,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,3,0,0,0,64,0,0, + 0,115,74,0,0,0,101,0,90,1,100,0,90,2,100,1, + 100,2,132,0,90,3,100,3,100,4,132,0,90,4,100,5, + 100,6,132,0,90,5,100,7,100,8,132,0,90,6,100,9, + 100,10,132,0,90,7,100,11,100,12,156,1,100,13,100,14, + 132,2,90,8,100,15,100,16,132,0,90,9,100,17,83,0, + 41,18,218,12,83,111,117,114,99,101,76,111,97,100,101,114, + 99,2,0,0,0,0,0,0,0,0,0,0,0,2,0,0, + 0,1,0,0,0,67,0,0,0,115,8,0,0,0,116,0, + 130,1,100,1,83,0,41,2,122,165,79,112,116,105,111,110, + 97,108,32,109,101,116,104,111,100,32,116,104,97,116,32,114, + 101,116,117,114,110,115,32,116,104,101,32,109,111,100,105,102, + 105,99,97,116,105,111,110,32,116,105,109,101,32,40,97,110, + 32,105,110,116,41,32,102,111,114,32,116,104,101,10,32,32, + 32,32,32,32,32,32,115,112,101,99,105,102,105,101,100,32, + 112,97,116,104,32,40,97,32,115,116,114,41,46,10,10,32, + 32,32,32,32,32,32,32,82,97,105,115,101,115,32,79,83, + 69,114,114,111,114,32,119,104,101,110,32,116,104,101,32,112, + 97,116,104,32,99,97,110,110,111,116,32,98,101,32,104,97, + 110,100,108,101,100,46,10,32,32,32,32,32,32,32,32,78, + 41,1,114,50,0,0,0,169,2,114,118,0,0,0,114,44, + 0,0,0,114,5,0,0,0,114,5,0,0,0,114,8,0, + 0,0,218,10,112,97,116,104,95,109,116,105,109,101,31,3, + 0,0,115,2,0,0,0,0,6,122,23,83,111,117,114,99, + 101,76,111,97,100,101,114,46,112,97,116,104,95,109,116,105, + 109,101,99,2,0,0,0,0,0,0,0,0,0,0,0,2, + 0,0,0,4,0,0,0,67,0,0,0,115,14,0,0,0, + 100,1,124,0,160,0,124,1,161,1,105,1,83,0,41,2, + 97,158,1,0,0,79,112,116,105,111,110,97,108,32,109,101, + 116,104,111,100,32,114,101,116,117,114,110,105,110,103,32,97, + 32,109,101,116,97,100,97,116,97,32,100,105,99,116,32,102, + 111,114,32,116,104,101,32,115,112,101,99,105,102,105,101,100, + 10,32,32,32,32,32,32,32,32,112,97,116,104,32,40,97, + 32,115,116,114,41,46,10,10,32,32,32,32,32,32,32,32, + 80,111,115,115,105,98,108,101,32,107,101,121,115,58,10,32, + 32,32,32,32,32,32,32,45,32,39,109,116,105,109,101,39, + 32,40,109,97,110,100,97,116,111,114,121,41,32,105,115,32, + 116,104,101,32,110,117,109,101,114,105,99,32,116,105,109,101, + 115,116,97,109,112,32,111,102,32,108,97,115,116,32,115,111, + 117,114,99,101,10,32,32,32,32,32,32,32,32,32,32,99, + 111,100,101,32,109,111,100,105,102,105,99,97,116,105,111,110, + 59,10,32,32,32,32,32,32,32,32,45,32,39,115,105,122, + 101,39,32,40,111,112,116,105,111,110,97,108,41,32,105,115, + 32,116,104,101,32,115,105,122,101,32,105,110,32,98,121,116, + 101,115,32,111,102,32,116,104,101,32,115,111,117,114,99,101, + 32,99,111,100,101,46,10,10,32,32,32,32,32,32,32,32, + 73,109,112,108,101,109,101,110,116,105,110,103,32,116,104,105, + 115,32,109,101,116,104,111,100,32,97,108,108,111,119,115,32, + 116,104,101,32,108,111,97,100,101,114,32,116,111,32,114,101, + 97,100,32,98,121,116,101,99,111,100,101,32,102,105,108,101, + 115,46,10,32,32,32,32,32,32,32,32,82,97,105,115,101, + 115,32,79,83,69,114,114,111,114,32,119,104,101,110,32,116, + 104,101,32,112,97,116,104,32,99,97,110,110,111,116,32,98, + 101,32,104,97,110,100,108,101,100,46,10,32,32,32,32,32, + 32,32,32,114,169,0,0,0,41,1,114,223,0,0,0,114, + 222,0,0,0,114,5,0,0,0,114,5,0,0,0,114,8, + 0,0,0,218,10,112,97,116,104,95,115,116,97,116,115,39, + 3,0,0,115,2,0,0,0,0,12,122,23,83,111,117,114, + 99,101,76,111,97,100,101,114,46,112,97,116,104,95,115,116, + 97,116,115,99,4,0,0,0,0,0,0,0,0,0,0,0, + 4,0,0,0,4,0,0,0,67,0,0,0,115,12,0,0, + 0,124,0,160,0,124,2,124,3,161,2,83,0,41,1,122, + 228,79,112,116,105,111,110,97,108,32,109,101,116,104,111,100, + 32,119,104,105,99,104,32,119,114,105,116,101,115,32,100,97, + 116,97,32,40,98,121,116,101,115,41,32,116,111,32,97,32, + 102,105,108,101,32,112,97,116,104,32,40,97,32,115,116,114, + 41,46,10,10,32,32,32,32,32,32,32,32,73,109,112,108, + 101,109,101,110,116,105,110,103,32,116,104,105,115,32,109,101, + 116,104,111,100,32,97,108,108,111,119,115,32,102,111,114,32, + 116,104,101,32,119,114,105,116,105,110,103,32,111,102,32,98, + 121,116,101,99,111,100,101,32,102,105,108,101,115,46,10,10, + 32,32,32,32,32,32,32,32,84,104,101,32,115,111,117,114, + 99,101,32,112,97,116,104,32,105,115,32,110,101,101,100,101, + 100,32,105,110,32,111,114,100,101,114,32,116,111,32,99,111, + 114,114,101,99,116,108,121,32,116,114,97,110,115,102,101,114, + 32,112,101,114,109,105,115,115,105,111,110,115,10,32,32,32, + 32,32,32,32,32,41,1,218,8,115,101,116,95,100,97,116, + 97,41,4,114,118,0,0,0,114,107,0,0,0,90,10,99, + 97,99,104,101,95,112,97,116,104,114,26,0,0,0,114,5, + 0,0,0,114,5,0,0,0,114,8,0,0,0,218,15,95, + 99,97,99,104,101,95,98,121,116,101,99,111,100,101,53,3, + 0,0,115,2,0,0,0,0,8,122,28,83,111,117,114,99, + 101,76,111,97,100,101,114,46,95,99,97,99,104,101,95,98, + 121,116,101,99,111,100,101,99,3,0,0,0,0,0,0,0, + 0,0,0,0,3,0,0,0,1,0,0,0,67,0,0,0, + 115,4,0,0,0,100,1,83,0,41,2,122,150,79,112,116, + 105,111,110,97,108,32,109,101,116,104,111,100,32,119,104,105, + 99,104,32,119,114,105,116,101,115,32,100,97,116,97,32,40, + 98,121,116,101,115,41,32,116,111,32,97,32,102,105,108,101, + 32,112,97,116,104,32,40,97,32,115,116,114,41,46,10,10, + 32,32,32,32,32,32,32,32,73,109,112,108,101,109,101,110, + 116,105,110,103,32,116,104,105,115,32,109,101,116,104,111,100, + 32,97,108,108,111,119,115,32,102,111,114,32,116,104,101,32, + 119,114,105,116,105,110,103,32,111,102,32,98,121,116,101,99, + 111,100,101,32,102,105,108,101,115,46,10,32,32,32,32,32, + 32,32,32,78,114,5,0,0,0,41,3,114,118,0,0,0, + 114,44,0,0,0,114,26,0,0,0,114,5,0,0,0,114, + 5,0,0,0,114,8,0,0,0,114,225,0,0,0,63,3, + 0,0,115,2,0,0,0,0,1,122,21,83,111,117,114,99, + 101,76,111,97,100,101,114,46,115,101,116,95,100,97,116,97, + 99,2,0,0,0,0,0,0,0,0,0,0,0,5,0,0, + 0,10,0,0,0,67,0,0,0,115,84,0,0,0,124,0, + 160,0,124,1,161,1,125,2,122,14,124,0,160,1,124,2, + 161,1,125,3,87,0,110,50,4,0,116,2,121,74,1,0, + 125,4,1,0,122,26,116,3,100,1,124,1,100,2,141,2, + 124,4,130,2,87,0,89,0,100,3,125,4,126,4,110,10, + 100,3,125,4,126,4,48,0,48,0,116,4,124,3,131,1, + 83,0,41,4,122,52,67,111,110,99,114,101,116,101,32,105, + 109,112,108,101,109,101,110,116,97,116,105,111,110,32,111,102, + 32,73,110,115,112,101,99,116,76,111,97,100,101,114,46,103, + 101,116,95,115,111,117,114,99,101,46,122,39,115,111,117,114, + 99,101,32,110,111,116,32,97,118,97,105,108,97,98,108,101, + 32,116,104,114,111,117,103,104,32,103,101,116,95,100,97,116, + 97,40,41,114,115,0,0,0,78,41,5,114,179,0,0,0, + 218,8,103,101,116,95,100,97,116,97,114,50,0,0,0,114, + 117,0,0,0,114,176,0,0,0,41,5,114,118,0,0,0, + 114,139,0,0,0,114,44,0,0,0,114,174,0,0,0,218, + 3,101,120,99,114,5,0,0,0,114,5,0,0,0,114,8, + 0,0,0,218,10,103,101,116,95,115,111,117,114,99,101,70, + 3,0,0,115,20,0,0,0,0,2,10,1,2,1,14,1, + 14,1,4,1,2,255,4,1,2,255,24,2,122,23,83,111, + 117,114,99,101,76,111,97,100,101,114,46,103,101,116,95,115, + 111,117,114,99,101,114,104,0,0,0,41,1,218,9,95,111, + 112,116,105,109,105,122,101,99,3,0,0,0,0,0,0,0, + 1,0,0,0,4,0,0,0,8,0,0,0,67,0,0,0, + 115,22,0,0,0,116,0,106,1,116,2,124,1,124,2,100, + 1,100,2,124,3,100,3,141,6,83,0,41,4,122,130,82, + 101,116,117,114,110,32,116,104,101,32,99,111,100,101,32,111, + 98,106,101,99,116,32,99,111,109,112,105,108,101,100,32,102, + 114,111,109,32,115,111,117,114,99,101,46,10,10,32,32,32, + 32,32,32,32,32,84,104,101,32,39,100,97,116,97,39,32, + 97,114,103,117,109,101,110,116,32,99,97,110,32,98,101,32, + 97,110,121,32,111,98,106,101,99,116,32,116,121,112,101,32, + 116,104,97,116,32,99,111,109,112,105,108,101,40,41,32,115, + 117,112,112,111,114,116,115,46,10,32,32,32,32,32,32,32, + 32,114,215,0,0,0,84,41,2,218,12,100,111,110,116,95, + 105,110,104,101,114,105,116,114,83,0,0,0,41,3,114,134, + 0,0,0,114,214,0,0,0,218,7,99,111,109,112,105,108, + 101,41,4,114,118,0,0,0,114,26,0,0,0,114,44,0, + 0,0,114,230,0,0,0,114,5,0,0,0,114,5,0,0, + 0,114,8,0,0,0,218,14,115,111,117,114,99,101,95,116, + 111,95,99,111,100,101,80,3,0,0,115,6,0,0,0,0, + 5,12,1,4,255,122,27,83,111,117,114,99,101,76,111,97, + 100,101,114,46,115,111,117,114,99,101,95,116,111,95,99,111, + 100,101,99,2,0,0,0,0,0,0,0,0,0,0,0,15, + 0,0,0,9,0,0,0,67,0,0,0,115,24,2,0,0, + 124,0,160,0,124,1,161,1,125,2,100,1,125,3,100,1, + 125,4,100,1,125,5,100,2,125,6,100,3,125,7,122,12, + 116,1,124,2,131,1,125,8,87,0,110,24,4,0,116,2, + 121,66,1,0,1,0,1,0,100,1,125,8,89,0,144,1, + 110,42,48,0,122,14,124,0,160,3,124,2,161,1,125,9, + 87,0,110,20,4,0,116,4,121,102,1,0,1,0,1,0, + 89,0,144,1,110,6,48,0,116,5,124,9,100,4,25,0, + 131,1,125,3,122,14,124,0,160,6,124,8,161,1,125,10, + 87,0,110,18,4,0,116,4,121,148,1,0,1,0,1,0, + 89,0,110,216,48,0,124,1,124,8,100,5,156,2,125,11, + 122,148,116,7,124,10,124,1,124,11,131,3,125,12,116,8, + 124,10,131,1,100,6,100,1,133,2,25,0,125,13,124,12, + 100,7,64,0,100,8,107,3,125,6,124,6,144,1,114,30, + 124,12,100,9,64,0,100,8,107,3,125,7,116,9,106,10, + 100,10,107,3,144,1,114,50,124,7,115,248,116,9,106,10, + 100,11,107,2,144,1,114,50,124,0,160,6,124,2,161,1, + 125,4,116,9,160,11,116,12,124,4,161,2,125,5,116,13, + 124,10,124,5,124,1,124,11,131,4,1,0,110,20,116,14, + 124,10,124,3,124,9,100,12,25,0,124,1,124,11,131,5, + 1,0,87,0,110,24,4,0,116,15,116,16,102,2,144,1, + 121,76,1,0,1,0,1,0,89,0,110,32,48,0,116,17, + 160,18,100,13,124,8,124,2,161,3,1,0,116,19,124,13, + 124,1,124,8,124,2,100,14,141,4,83,0,124,4,100,1, + 117,0,144,1,114,128,124,0,160,6,124,2,161,1,125,4, + 124,0,160,20,124,4,124,2,161,2,125,14,116,17,160,18, + 100,15,124,2,161,2,1,0,116,21,106,22,144,2,115,20, + 124,8,100,1,117,1,144,2,114,20,124,3,100,1,117,1, + 144,2,114,20,124,6,144,1,114,220,124,5,100,1,117,0, + 144,1,114,206,116,9,160,11,124,4,161,1,125,5,116,23, + 124,14,124,5,124,7,131,3,125,10,110,16,116,24,124,14, + 124,3,116,25,124,4,131,1,131,3,125,10,122,18,124,0, + 160,26,124,2,124,8,124,10,161,3,1,0,87,0,110,20, + 4,0,116,2,144,2,121,18,1,0,1,0,1,0,89,0, + 110,2,48,0,124,14,83,0,41,16,122,190,67,111,110,99, + 114,101,116,101,32,105,109,112,108,101,109,101,110,116,97,116, + 105,111,110,32,111,102,32,73,110,115,112,101,99,116,76,111, + 97,100,101,114,46,103,101,116,95,99,111,100,101,46,10,10, + 32,32,32,32,32,32,32,32,82,101,97,100,105,110,103,32, + 111,102,32,98,121,116,101,99,111,100,101,32,114,101,113,117, + 105,114,101,115,32,112,97,116,104,95,115,116,97,116,115,32, + 116,111,32,98,101,32,105,109,112,108,101,109,101,110,116,101, + 100,46,32,84,111,32,119,114,105,116,101,10,32,32,32,32, + 32,32,32,32,98,121,116,101,99,111,100,101,44,32,115,101, + 116,95,100,97,116,97,32,109,117,115,116,32,97,108,115,111, + 32,98,101,32,105,109,112,108,101,109,101,110,116,101,100,46, + 10,10,32,32,32,32,32,32,32,32,78,70,84,114,169,0, + 0,0,114,159,0,0,0,114,145,0,0,0,114,39,0,0, + 0,114,73,0,0,0,114,28,0,0,0,90,5,110,101,118, + 101,114,90,6,97,108,119,97,121,115,218,4,115,105,122,101, + 122,13,123,125,32,109,97,116,99,104,101,115,32,123,125,41, + 3,114,116,0,0,0,114,106,0,0,0,114,107,0,0,0, + 122,19,99,111,100,101,32,111,98,106,101,99,116,32,102,114, + 111,109,32,123,125,41,27,114,179,0,0,0,114,97,0,0, + 0,114,82,0,0,0,114,224,0,0,0,114,50,0,0,0, + 114,18,0,0,0,114,227,0,0,0,114,152,0,0,0,218, + 10,109,101,109,111,114,121,118,105,101,119,114,163,0,0,0, + 90,21,99,104,101,99,107,95,104,97,115,104,95,98,97,115, + 101,100,95,112,121,99,115,114,157,0,0,0,218,17,95,82, + 65,87,95,77,65,71,73,67,95,78,85,77,66,69,82,114, + 158,0,0,0,114,156,0,0,0,114,117,0,0,0,114,150, + 0,0,0,114,134,0,0,0,114,149,0,0,0,114,165,0, + 0,0,114,233,0,0,0,114,1,0,0,0,218,19,100,111, + 110,116,95,119,114,105,116,101,95,98,121,116,101,99,111,100, + 101,114,171,0,0,0,114,170,0,0,0,114,23,0,0,0, + 114,226,0,0,0,41,15,114,118,0,0,0,114,139,0,0, + 0,114,107,0,0,0,114,154,0,0,0,114,174,0,0,0, + 114,157,0,0,0,90,10,104,97,115,104,95,98,97,115,101, + 100,90,12,99,104,101,99,107,95,115,111,117,114,99,101,114, + 106,0,0,0,218,2,115,116,114,26,0,0,0,114,151,0, + 0,0,114,2,0,0,0,90,10,98,121,116,101,115,95,100, + 97,116,97,90,11,99,111,100,101,95,111,98,106,101,99,116, + 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,114, + 213,0,0,0,88,3,0,0,115,152,0,0,0,0,7,10, + 1,4,1,4,1,4,1,4,1,4,1,2,1,12,1,12, + 1,12,2,2,1,14,1,12,1,8,2,12,1,2,1,14, + 1,12,1,6,3,2,1,2,254,6,4,2,1,12,1,16, + 1,12,1,6,1,12,1,12,1,2,255,2,2,8,254,4, + 3,10,1,4,1,2,1,2,254,4,4,8,1,2,255,6, + 3,2,1,2,1,2,1,6,1,2,1,2,251,8,7,18, + 1,6,2,8,1,2,255,4,2,6,1,2,1,2,254,6, + 3,10,1,10,1,12,1,12,1,18,1,6,255,4,2,6, + 1,10,1,10,1,14,2,6,1,6,255,4,2,2,1,18, + 1,14,1,6,1,122,21,83,111,117,114,99,101,76,111,97, + 100,101,114,46,103,101,116,95,99,111,100,101,78,41,10,114, + 125,0,0,0,114,124,0,0,0,114,126,0,0,0,114,223, + 0,0,0,114,224,0,0,0,114,226,0,0,0,114,225,0, + 0,0,114,229,0,0,0,114,233,0,0,0,114,213,0,0, + 0,114,5,0,0,0,114,5,0,0,0,114,5,0,0,0, + 114,8,0,0,0,114,221,0,0,0,29,3,0,0,115,14, + 0,0,0,8,2,8,8,8,14,8,10,8,7,8,10,14, + 8,114,221,0,0,0,99,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,115, + 92,0,0,0,101,0,90,1,100,0,90,2,100,1,90,3, + 100,2,100,3,132,0,90,4,100,4,100,5,132,0,90,5, + 100,6,100,7,132,0,90,6,101,7,135,0,102,1,100,8, + 100,9,132,8,131,1,90,8,101,7,100,10,100,11,132,0, + 131,1,90,9,100,12,100,13,132,0,90,10,101,7,100,14, + 100,15,132,0,131,1,90,11,135,0,4,0,90,12,83,0, + 41,16,218,10,70,105,108,101,76,111,97,100,101,114,122,103, + 66,97,115,101,32,102,105,108,101,32,108,111,97,100,101,114, + 32,99,108,97,115,115,32,119,104,105,99,104,32,105,109,112, + 108,101,109,101,110,116,115,32,116,104,101,32,108,111,97,100, + 101,114,32,112,114,111,116,111,99,111,108,32,109,101,116,104, + 111,100,115,32,116,104,97,116,10,32,32,32,32,114,101,113, + 117,105,114,101,32,102,105,108,101,32,115,121,115,116,101,109, + 32,117,115,97,103,101,46,99,3,0,0,0,0,0,0,0, + 0,0,0,0,3,0,0,0,2,0,0,0,67,0,0,0, + 115,16,0,0,0,124,1,124,0,95,0,124,2,124,0,95, + 1,100,1,83,0,41,2,122,75,67,97,99,104,101,32,116, + 104,101,32,109,111,100,117,108,101,32,110,97,109,101,32,97, + 110,100,32,116,104,101,32,112,97,116,104,32,116,111,32,116, + 104,101,32,102,105,108,101,32,102,111,117,110,100,32,98,121, + 32,116,104,101,10,32,32,32,32,32,32,32,32,102,105,110, + 100,101,114,46,78,114,159,0,0,0,41,3,114,118,0,0, + 0,114,139,0,0,0,114,44,0,0,0,114,5,0,0,0, + 114,5,0,0,0,114,8,0,0,0,114,209,0,0,0,178, + 3,0,0,115,4,0,0,0,0,3,6,1,122,19,70,105, + 108,101,76,111,97,100,101,114,46,95,95,105,110,105,116,95, + 95,99,2,0,0,0,0,0,0,0,0,0,0,0,2,0, + 0,0,2,0,0,0,67,0,0,0,115,24,0,0,0,124, + 0,106,0,124,1,106,0,107,2,111,22,124,0,106,1,124, + 1,106,1,107,2,83,0,114,109,0,0,0,169,2,218,9, + 95,95,99,108,97,115,115,95,95,114,131,0,0,0,169,2, + 114,118,0,0,0,90,5,111,116,104,101,114,114,5,0,0, + 0,114,5,0,0,0,114,8,0,0,0,218,6,95,95,101, + 113,95,95,184,3,0,0,115,6,0,0,0,0,1,12,1, + 10,255,122,17,70,105,108,101,76,111,97,100,101,114,46,95, + 95,101,113,95,95,99,1,0,0,0,0,0,0,0,0,0, + 0,0,1,0,0,0,3,0,0,0,67,0,0,0,115,20, + 0,0,0,116,0,124,0,106,1,131,1,116,0,124,0,106, + 2,131,1,65,0,83,0,114,109,0,0,0,169,3,218,4, + 104,97,115,104,114,116,0,0,0,114,44,0,0,0,169,1, + 114,118,0,0,0,114,5,0,0,0,114,5,0,0,0,114, + 8,0,0,0,218,8,95,95,104,97,115,104,95,95,188,3, + 0,0,115,2,0,0,0,0,1,122,19,70,105,108,101,76, + 111,97,100,101,114,46,95,95,104,97,115,104,95,95,99,2, + 0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,3, + 0,0,0,3,0,0,0,115,16,0,0,0,116,0,116,1, + 124,0,131,2,160,2,124,1,161,1,83,0,41,1,122,100, + 76,111,97,100,32,97,32,109,111,100,117,108,101,32,102,114, + 111,109,32,97,32,102,105,108,101,46,10,10,32,32,32,32, + 32,32,32,32,84,104,105,115,32,109,101,116,104,111,100,32, + 105,115,32,100,101,112,114,101,99,97,116,101,100,46,32,32, + 85,115,101,32,101,120,101,99,95,109,111,100,117,108,101,40, + 41,32,105,110,115,116,101,97,100,46,10,10,32,32,32,32, + 32,32,32,32,41,3,218,5,115,117,112,101,114,114,239,0, + 0,0,114,220,0,0,0,114,219,0,0,0,169,1,114,241, + 0,0,0,114,5,0,0,0,114,8,0,0,0,114,220,0, + 0,0,191,3,0,0,115,2,0,0,0,0,10,122,22,70, + 105,108,101,76,111,97,100,101,114,46,108,111,97,100,95,109, + 111,100,117,108,101,99,2,0,0,0,0,0,0,0,0,0, + 0,0,2,0,0,0,1,0,0,0,67,0,0,0,115,6, + 0,0,0,124,0,106,0,83,0,169,1,122,58,82,101,116, + 117,114,110,32,116,104,101,32,112,97,116,104,32,116,111,32, + 116,104,101,32,115,111,117,114,99,101,32,102,105,108,101,32, + 97,115,32,102,111,117,110,100,32,98,121,32,116,104,101,32, + 102,105,110,100,101,114,46,114,48,0,0,0,114,219,0,0, + 0,114,5,0,0,0,114,5,0,0,0,114,8,0,0,0, + 114,179,0,0,0,203,3,0,0,115,2,0,0,0,0,3, + 122,23,70,105,108,101,76,111,97,100,101,114,46,103,101,116, + 95,102,105,108,101,110,97,109,101,99,2,0,0,0,0,0, + 0,0,0,0,0,0,3,0,0,0,8,0,0,0,67,0, + 0,0,115,126,0,0,0,116,0,124,0,116,1,116,2,102, + 2,131,2,114,70,116,3,160,4,116,5,124,1,131,1,161, + 1,143,24,125,2,124,2,160,6,161,0,87,0,2,0,100, + 1,4,0,4,0,131,3,1,0,83,0,49,0,115,58,48, + 0,1,0,1,0,1,0,89,0,1,0,110,52,116,3,160, + 7,124,1,100,2,161,2,143,24,125,2,124,2,160,6,161, + 0,87,0,2,0,100,1,4,0,4,0,131,3,1,0,83, + 0,49,0,115,112,48,0,1,0,1,0,1,0,89,0,1, + 0,100,1,83,0,41,3,122,39,82,101,116,117,114,110,32, + 116,104,101,32,100,97,116,97,32,102,114,111,109,32,112,97, + 116,104,32,97,115,32,114,97,119,32,98,121,116,101,115,46, + 78,218,1,114,41,8,114,161,0,0,0,114,221,0,0,0, + 218,19,69,120,116,101,110,115,105,111,110,70,105,108,101,76, + 111,97,100,101,114,114,64,0,0,0,90,9,111,112,101,110, + 95,99,111,100,101,114,84,0,0,0,90,4,114,101,97,100, + 114,65,0,0,0,41,3,114,118,0,0,0,114,44,0,0, + 0,114,68,0,0,0,114,5,0,0,0,114,5,0,0,0, + 114,8,0,0,0,114,227,0,0,0,208,3,0,0,115,10, + 0,0,0,0,2,14,1,16,1,40,2,14,1,122,19,70, + 105,108,101,76,111,97,100,101,114,46,103,101,116,95,100,97, + 116,97,99,2,0,0,0,0,0,0,0,0,0,0,0,3, + 0,0,0,2,0,0,0,67,0,0,0,115,20,0,0,0, + 100,1,100,2,108,0,109,1,125,2,1,0,124,2,124,0, + 131,1,83,0,41,3,78,114,73,0,0,0,41,1,218,10, + 70,105,108,101,82,101,97,100,101,114,41,2,90,17,105,109, + 112,111,114,116,108,105,98,46,114,101,97,100,101,114,115,114, + 253,0,0,0,41,3,114,118,0,0,0,114,216,0,0,0, + 114,253,0,0,0,114,5,0,0,0,114,5,0,0,0,114, + 8,0,0,0,218,19,103,101,116,95,114,101,115,111,117,114, + 99,101,95,114,101,97,100,101,114,217,3,0,0,115,4,0, + 0,0,0,2,12,1,122,30,70,105,108,101,76,111,97,100, + 101,114,46,103,101,116,95,114,101,115,111,117,114,99,101,95, + 114,101,97,100,101,114,41,13,114,125,0,0,0,114,124,0, + 0,0,114,126,0,0,0,114,127,0,0,0,114,209,0,0, + 0,114,243,0,0,0,114,247,0,0,0,114,136,0,0,0, + 114,220,0,0,0,114,179,0,0,0,114,227,0,0,0,114, + 254,0,0,0,90,13,95,95,99,108,97,115,115,99,101,108, + 108,95,95,114,5,0,0,0,114,5,0,0,0,114,249,0, + 0,0,114,8,0,0,0,114,239,0,0,0,173,3,0,0, + 115,22,0,0,0,8,2,4,3,8,6,8,4,8,3,2, + 1,14,11,2,1,10,4,8,9,2,1,114,239,0,0,0, + 99,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,3,0,0,0,64,0,0,0,115,46,0,0,0,101,0, + 90,1,100,0,90,2,100,1,90,3,100,2,100,3,132,0, + 90,4,100,4,100,5,132,0,90,5,100,6,100,7,156,1, + 100,8,100,9,132,2,90,6,100,10,83,0,41,11,218,16, + 83,111,117,114,99,101,70,105,108,101,76,111,97,100,101,114, + 122,62,67,111,110,99,114,101,116,101,32,105,109,112,108,101, + 109,101,110,116,97,116,105,111,110,32,111,102,32,83,111,117, + 114,99,101,76,111,97,100,101,114,32,117,115,105,110,103,32, + 116,104,101,32,102,105,108,101,32,115,121,115,116,101,109,46, + 99,2,0,0,0,0,0,0,0,0,0,0,0,3,0,0, + 0,3,0,0,0,67,0,0,0,115,22,0,0,0,116,0, + 124,1,131,1,125,2,124,2,106,1,124,2,106,2,100,1, + 156,2,83,0,41,2,122,33,82,101,116,117,114,110,32,116, + 104,101,32,109,101,116,97,100,97,116,97,32,102,111,114,32, + 116,104,101,32,112,97,116,104,46,41,2,114,169,0,0,0, + 114,234,0,0,0,41,3,114,49,0,0,0,218,8,115,116, + 95,109,116,105,109,101,90,7,115,116,95,115,105,122,101,41, + 3,114,118,0,0,0,114,44,0,0,0,114,238,0,0,0, + 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,114, + 224,0,0,0,227,3,0,0,115,4,0,0,0,0,2,8, + 1,122,27,83,111,117,114,99,101,70,105,108,101,76,111,97, + 100,101,114,46,112,97,116,104,95,115,116,97,116,115,99,4, + 0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,5, + 0,0,0,67,0,0,0,115,24,0,0,0,116,0,124,1, + 131,1,125,4,124,0,106,1,124,2,124,3,124,4,100,1, + 141,3,83,0,41,2,78,169,1,218,5,95,109,111,100,101, + 41,2,114,114,0,0,0,114,225,0,0,0,41,5,114,118, + 0,0,0,114,107,0,0,0,114,106,0,0,0,114,26,0, + 0,0,114,52,0,0,0,114,5,0,0,0,114,5,0,0, + 0,114,8,0,0,0,114,226,0,0,0,232,3,0,0,115, + 4,0,0,0,0,2,8,1,122,32,83,111,117,114,99,101, + 70,105,108,101,76,111,97,100,101,114,46,95,99,97,99,104, + 101,95,98,121,116,101,99,111,100,101,114,60,0,0,0,114, + 1,1,0,0,99,3,0,0,0,0,0,0,0,1,0,0, + 0,9,0,0,0,11,0,0,0,67,0,0,0,115,252,0, + 0,0,116,0,124,1,131,1,92,2,125,4,125,5,103,0, + 125,6,124,4,114,52,116,1,124,4,131,1,115,52,116,0, + 124,4,131,1,92,2,125,4,125,7,124,6,160,2,124,7, + 161,1,1,0,113,16,116,3,124,6,131,1,68,0,93,104, + 125,7,116,4,124,4,124,7,131,2,125,4,122,14,116,5, + 160,6,124,4,161,1,1,0,87,0,113,60,4,0,116,7, + 121,110,1,0,1,0,1,0,89,0,113,60,89,0,113,60, + 4,0,116,8,121,162,1,0,125,8,1,0,122,30,116,9, + 160,10,100,1,124,4,124,8,161,3,1,0,87,0,89,0, + 100,2,125,8,126,8,1,0,100,2,83,0,100,2,125,8, + 126,8,48,0,48,0,113,60,122,28,116,11,124,1,124,2, + 124,3,131,3,1,0,116,9,160,10,100,3,124,1,161,2, + 1,0,87,0,110,52,4,0,116,8,144,0,121,246,1,0, + 125,8,1,0,122,26,116,9,160,10,100,1,124,1,124,8, + 161,3,1,0,87,0,89,0,100,2,125,8,126,8,110,10, + 100,2,125,8,126,8,48,0,48,0,100,2,83,0,41,4, + 122,27,87,114,105,116,101,32,98,121,116,101,115,32,100,97, + 116,97,32,116,111,32,97,32,102,105,108,101,46,122,27,99, + 111,117,108,100,32,110,111,116,32,99,114,101,97,116,101,32, + 123,33,114,125,58,32,123,33,114,125,78,122,12,99,114,101, + 97,116,101,100,32,123,33,114,125,41,12,114,47,0,0,0, + 114,56,0,0,0,114,186,0,0,0,114,42,0,0,0,114, + 38,0,0,0,114,4,0,0,0,90,5,109,107,100,105,114, + 218,15,70,105,108,101,69,120,105,115,116,115,69,114,114,111, + 114,114,50,0,0,0,114,134,0,0,0,114,149,0,0,0, + 114,69,0,0,0,41,9,114,118,0,0,0,114,44,0,0, + 0,114,26,0,0,0,114,2,1,0,0,218,6,112,97,114, + 101,110,116,114,96,0,0,0,114,37,0,0,0,114,33,0, + 0,0,114,228,0,0,0,114,5,0,0,0,114,5,0,0, + 0,114,8,0,0,0,114,225,0,0,0,237,3,0,0,115, + 46,0,0,0,0,2,12,1,4,2,12,1,12,1,12,2, + 12,1,10,1,2,1,14,1,12,2,8,1,14,3,6,1, + 4,255,4,2,28,1,2,1,12,1,16,1,16,2,8,1, + 2,255,122,25,83,111,117,114,99,101,70,105,108,101,76,111, + 97,100,101,114,46,115,101,116,95,100,97,116,97,78,41,7, + 114,125,0,0,0,114,124,0,0,0,114,126,0,0,0,114, + 127,0,0,0,114,224,0,0,0,114,226,0,0,0,114,225, + 0,0,0,114,5,0,0,0,114,5,0,0,0,114,5,0, + 0,0,114,8,0,0,0,114,255,0,0,0,223,3,0,0, + 115,8,0,0,0,8,2,4,2,8,5,8,5,114,255,0, 0,0,99,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,4,0,0,0,64,0,0,0,115,80,0,0,0, - 101,0,90,1,100,0,90,2,100,1,90,3,100,2,90,4, - 100,3,90,5,100,4,90,6,101,7,100,5,100,6,132,0, - 131,1,90,8,101,7,100,7,100,8,132,0,131,1,90,9, - 101,7,100,14,100,10,100,11,132,1,131,1,90,10,101,7, - 100,15,100,12,100,13,132,1,131,1,90,11,100,9,83,0, - 41,16,218,21,87,105,110,100,111,119,115,82,101,103,105,115, - 116,114,121,70,105,110,100,101,114,122,62,77,101,116,97,32, - 112,97,116,104,32,102,105,110,100,101,114,32,102,111,114,32, - 109,111,100,117,108,101,115,32,100,101,99,108,97,114,101,100, - 32,105,110,32,116,104,101,32,87,105,110,100,111,119,115,32, - 114,101,103,105,115,116,114,121,46,122,59,83,111,102,116,119, - 97,114,101,92,80,121,116,104,111,110,92,80,121,116,104,111, - 110,67,111,114,101,92,123,115,121,115,95,118,101,114,115,105, - 111,110,125,92,77,111,100,117,108,101,115,92,123,102,117,108, - 108,110,97,109,101,125,122,65,83,111,102,116,119,97,114,101, - 92,80,121,116,104,111,110,92,80,121,116,104,111,110,67,111, - 114,101,92,123,115,121,115,95,118,101,114,115,105,111,110,125, - 92,77,111,100,117,108,101,115,92,123,102,117,108,108,110,97, - 109,101,125,92,68,101,98,117,103,70,99,2,0,0,0,0, - 0,0,0,0,0,0,0,2,0,0,0,8,0,0,0,67, - 0,0,0,115,54,0,0,0,122,16,116,0,160,1,116,0, - 106,2,124,1,161,2,87,0,83,0,4,0,116,3,121,48, - 1,0,1,0,1,0,116,0,160,1,116,0,106,4,124,1, - 161,2,6,0,89,0,83,0,48,0,100,0,83,0,114,109, - 0,0,0,41,5,218,6,119,105,110,114,101,103,90,7,79, - 112,101,110,75,101,121,90,17,72,75,69,89,95,67,85,82, - 82,69,78,84,95,85,83,69,82,114,50,0,0,0,90,18, - 72,75,69,89,95,76,79,67,65,76,95,77,65,67,72,73, - 78,69,41,2,218,3,99,108,115,114,7,0,0,0,114,5, - 0,0,0,114,5,0,0,0,114,8,0,0,0,218,14,95, - 111,112,101,110,95,114,101,103,105,115,116,114,121,204,2,0, - 0,115,8,0,0,0,0,2,2,1,16,1,12,1,122,36, - 87,105,110,100,111,119,115,82,101,103,105,115,116,114,121,70, - 105,110,100,101,114,46,95,111,112,101,110,95,114,101,103,105, - 115,116,114,121,99,2,0,0,0,0,0,0,0,0,0,0, - 0,6,0,0,0,8,0,0,0,67,0,0,0,115,132,0, - 0,0,124,0,106,0,114,14,124,0,106,1,125,2,110,6, - 124,0,106,2,125,2,124,2,106,3,124,1,100,1,116,4, - 106,5,100,0,100,2,133,2,25,0,22,0,100,3,141,2, - 125,3,122,58,124,0,160,6,124,3,161,1,143,28,125,4, - 116,7,160,8,124,4,100,4,161,2,125,5,87,0,100,0, - 4,0,4,0,131,3,1,0,110,16,49,0,115,94,48,0, - 1,0,1,0,1,0,89,0,1,0,87,0,110,20,4,0, - 116,9,121,126,1,0,1,0,1,0,89,0,100,0,83,0, - 48,0,124,5,83,0,41,5,78,122,5,37,100,46,37,100, - 114,28,0,0,0,41,2,114,139,0,0,0,90,11,115,121, - 115,95,118,101,114,115,105,111,110,114,40,0,0,0,41,10, - 218,11,68,69,66,85,71,95,66,85,73,76,68,218,18,82, - 69,71,73,83,84,82,89,95,75,69,89,95,68,69,66,85, - 71,218,12,82,69,71,73,83,84,82,89,95,75,69,89,114, - 62,0,0,0,114,1,0,0,0,218,12,118,101,114,115,105, - 111,110,95,105,110,102,111,114,194,0,0,0,114,192,0,0, - 0,90,10,81,117,101,114,121,86,97,108,117,101,114,50,0, - 0,0,41,6,114,193,0,0,0,114,139,0,0,0,90,12, - 114,101,103,105,115,116,114,121,95,107,101,121,114,7,0,0, - 0,90,4,104,107,101,121,218,8,102,105,108,101,112,97,116, - 104,114,5,0,0,0,114,5,0,0,0,114,8,0,0,0, - 218,16,95,115,101,97,114,99,104,95,114,101,103,105,115,116, - 114,121,211,2,0,0,115,24,0,0,0,0,2,6,1,8, - 2,6,1,6,1,16,255,6,2,2,1,12,1,46,1,12, - 1,8,1,122,38,87,105,110,100,111,119,115,82,101,103,105, - 115,116,114,121,70,105,110,100,101,114,46,95,115,101,97,114, - 99,104,95,114,101,103,105,115,116,114,121,78,99,4,0,0, - 0,0,0,0,0,0,0,0,0,8,0,0,0,8,0,0, - 0,67,0,0,0,115,120,0,0,0,124,0,160,0,124,1, - 161,1,125,4,124,4,100,0,117,0,114,22,100,0,83,0, - 122,12,116,1,124,4,131,1,1,0,87,0,110,20,4,0, - 116,2,121,54,1,0,1,0,1,0,89,0,100,0,83,0, - 48,0,116,3,131,0,68,0,93,52,92,2,125,5,125,6, - 124,4,160,4,116,5,124,6,131,1,161,1,114,62,116,6, - 106,7,124,1,124,5,124,1,124,4,131,2,124,4,100,1, - 141,3,125,7,124,7,2,0,1,0,83,0,113,62,100,0, - 83,0,41,2,78,114,180,0,0,0,41,8,114,200,0,0, - 0,114,49,0,0,0,114,50,0,0,0,114,184,0,0,0, - 114,110,0,0,0,114,111,0,0,0,114,134,0,0,0,218, - 16,115,112,101,99,95,102,114,111,109,95,108,111,97,100,101, - 114,41,8,114,193,0,0,0,114,139,0,0,0,114,44,0, - 0,0,218,6,116,97,114,103,101,116,114,199,0,0,0,114, - 140,0,0,0,114,189,0,0,0,114,187,0,0,0,114,5, - 0,0,0,114,5,0,0,0,114,8,0,0,0,218,9,102, - 105,110,100,95,115,112,101,99,226,2,0,0,115,28,0,0, - 0,0,2,10,1,8,1,4,1,2,1,12,1,12,1,8, - 1,14,1,14,1,6,1,8,1,2,254,6,3,122,31,87, - 105,110,100,111,119,115,82,101,103,105,115,116,114,121,70,105, - 110,100,101,114,46,102,105,110,100,95,115,112,101,99,99,3, - 0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,4, - 0,0,0,67,0,0,0,115,34,0,0,0,124,0,160,0, - 124,1,124,2,161,2,125,3,124,3,100,1,117,1,114,26, - 124,3,106,1,83,0,100,1,83,0,100,1,83,0,41,2, - 122,108,70,105,110,100,32,109,111,100,117,108,101,32,110,97, - 109,101,100,32,105,110,32,116,104,101,32,114,101,103,105,115, - 116,114,121,46,10,10,32,32,32,32,32,32,32,32,84,104, + 0,0,0,2,0,0,0,64,0,0,0,115,32,0,0,0, + 101,0,90,1,100,0,90,2,100,1,90,3,100,2,100,3, + 132,0,90,4,100,4,100,5,132,0,90,5,100,6,83,0, + 41,7,218,20,83,111,117,114,99,101,108,101,115,115,70,105, + 108,101,76,111,97,100,101,114,122,45,76,111,97,100,101,114, + 32,119,104,105,99,104,32,104,97,110,100,108,101,115,32,115, + 111,117,114,99,101,108,101,115,115,32,102,105,108,101,32,105, + 109,112,111,114,116,115,46,99,2,0,0,0,0,0,0,0, + 0,0,0,0,5,0,0,0,5,0,0,0,67,0,0,0, + 115,68,0,0,0,124,0,160,0,124,1,161,1,125,2,124, + 0,160,1,124,2,161,1,125,3,124,1,124,2,100,1,156, + 2,125,4,116,2,124,3,124,1,124,4,131,3,1,0,116, + 3,116,4,124,3,131,1,100,2,100,0,133,2,25,0,124, + 1,124,2,100,3,141,3,83,0,41,4,78,114,159,0,0, + 0,114,145,0,0,0,41,2,114,116,0,0,0,114,106,0, + 0,0,41,5,114,179,0,0,0,114,227,0,0,0,114,152, + 0,0,0,114,165,0,0,0,114,235,0,0,0,41,5,114, + 118,0,0,0,114,139,0,0,0,114,44,0,0,0,114,26, + 0,0,0,114,151,0,0,0,114,5,0,0,0,114,5,0, + 0,0,114,8,0,0,0,114,213,0,0,0,16,4,0,0, + 115,22,0,0,0,0,1,10,1,10,4,2,1,2,254,6, + 4,12,1,2,1,14,1,2,1,2,253,122,29,83,111,117, + 114,99,101,108,101,115,115,70,105,108,101,76,111,97,100,101, + 114,46,103,101,116,95,99,111,100,101,99,2,0,0,0,0, + 0,0,0,0,0,0,0,2,0,0,0,1,0,0,0,67, + 0,0,0,115,4,0,0,0,100,1,83,0,41,2,122,39, + 82,101,116,117,114,110,32,78,111,110,101,32,97,115,32,116, + 104,101,114,101,32,105,115,32,110,111,32,115,111,117,114,99, + 101,32,99,111,100,101,46,78,114,5,0,0,0,114,219,0, + 0,0,114,5,0,0,0,114,5,0,0,0,114,8,0,0, + 0,114,229,0,0,0,32,4,0,0,115,2,0,0,0,0, + 2,122,31,83,111,117,114,99,101,108,101,115,115,70,105,108, + 101,76,111,97,100,101,114,46,103,101,116,95,115,111,117,114, + 99,101,78,41,6,114,125,0,0,0,114,124,0,0,0,114, + 126,0,0,0,114,127,0,0,0,114,213,0,0,0,114,229, + 0,0,0,114,5,0,0,0,114,5,0,0,0,114,5,0, + 0,0,114,8,0,0,0,114,5,1,0,0,12,4,0,0, + 115,6,0,0,0,8,2,4,2,8,16,114,5,1,0,0, + 99,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,3,0,0,0,64,0,0,0,115,92,0,0,0,101,0, + 90,1,100,0,90,2,100,1,90,3,100,2,100,3,132,0, + 90,4,100,4,100,5,132,0,90,5,100,6,100,7,132,0, + 90,6,100,8,100,9,132,0,90,7,100,10,100,11,132,0, + 90,8,100,12,100,13,132,0,90,9,100,14,100,15,132,0, + 90,10,100,16,100,17,132,0,90,11,101,12,100,18,100,19, + 132,0,131,1,90,13,100,20,83,0,41,21,114,252,0,0, + 0,122,93,76,111,97,100,101,114,32,102,111,114,32,101,120, + 116,101,110,115,105,111,110,32,109,111,100,117,108,101,115,46, + 10,10,32,32,32,32,84,104,101,32,99,111,110,115,116,114, + 117,99,116,111,114,32,105,115,32,100,101,115,105,103,110,101, + 100,32,116,111,32,119,111,114,107,32,119,105,116,104,32,70, + 105,108,101,70,105,110,100,101,114,46,10,10,32,32,32,32, + 99,3,0,0,0,0,0,0,0,0,0,0,0,3,0,0, + 0,2,0,0,0,67,0,0,0,115,16,0,0,0,124,1, + 124,0,95,0,124,2,124,0,95,1,100,0,83,0,114,109, + 0,0,0,114,159,0,0,0,41,3,114,118,0,0,0,114, + 116,0,0,0,114,44,0,0,0,114,5,0,0,0,114,5, + 0,0,0,114,8,0,0,0,114,209,0,0,0,49,4,0, + 0,115,4,0,0,0,0,1,6,1,122,28,69,120,116,101, + 110,115,105,111,110,70,105,108,101,76,111,97,100,101,114,46, + 95,95,105,110,105,116,95,95,99,2,0,0,0,0,0,0, + 0,0,0,0,0,2,0,0,0,2,0,0,0,67,0,0, + 0,115,24,0,0,0,124,0,106,0,124,1,106,0,107,2, + 111,22,124,0,106,1,124,1,106,1,107,2,83,0,114,109, + 0,0,0,114,240,0,0,0,114,242,0,0,0,114,5,0, + 0,0,114,5,0,0,0,114,8,0,0,0,114,243,0,0, + 0,53,4,0,0,115,6,0,0,0,0,1,12,1,10,255, + 122,26,69,120,116,101,110,115,105,111,110,70,105,108,101,76, + 111,97,100,101,114,46,95,95,101,113,95,95,99,1,0,0, + 0,0,0,0,0,0,0,0,0,1,0,0,0,3,0,0, + 0,67,0,0,0,115,20,0,0,0,116,0,124,0,106,1, + 131,1,116,0,124,0,106,2,131,1,65,0,83,0,114,109, + 0,0,0,114,244,0,0,0,114,246,0,0,0,114,5,0, + 0,0,114,5,0,0,0,114,8,0,0,0,114,247,0,0, + 0,57,4,0,0,115,2,0,0,0,0,1,122,28,69,120, + 116,101,110,115,105,111,110,70,105,108,101,76,111,97,100,101, + 114,46,95,95,104,97,115,104,95,95,99,2,0,0,0,0, + 0,0,0,0,0,0,0,3,0,0,0,5,0,0,0,67, + 0,0,0,115,36,0,0,0,116,0,160,1,116,2,106,3, + 124,1,161,2,125,2,116,0,160,4,100,1,124,1,106,5, + 124,0,106,6,161,3,1,0,124,2,83,0,41,2,122,38, + 67,114,101,97,116,101,32,97,110,32,117,110,105,116,105,97, + 108,105,122,101,100,32,101,120,116,101,110,115,105,111,110,32, + 109,111,100,117,108,101,122,38,101,120,116,101,110,115,105,111, + 110,32,109,111,100,117,108,101,32,123,33,114,125,32,108,111, + 97,100,101,100,32,102,114,111,109,32,123,33,114,125,41,7, + 114,134,0,0,0,114,214,0,0,0,114,163,0,0,0,90, + 14,99,114,101,97,116,101,95,100,121,110,97,109,105,99,114, + 149,0,0,0,114,116,0,0,0,114,44,0,0,0,41,3, + 114,118,0,0,0,114,187,0,0,0,114,216,0,0,0,114, + 5,0,0,0,114,5,0,0,0,114,8,0,0,0,114,212, + 0,0,0,60,4,0,0,115,14,0,0,0,0,2,4,1, + 6,255,4,2,6,1,8,255,4,2,122,33,69,120,116,101, + 110,115,105,111,110,70,105,108,101,76,111,97,100,101,114,46, + 99,114,101,97,116,101,95,109,111,100,117,108,101,99,2,0, + 0,0,0,0,0,0,0,0,0,0,2,0,0,0,5,0, + 0,0,67,0,0,0,115,36,0,0,0,116,0,160,1,116, + 2,106,3,124,1,161,2,1,0,116,0,160,4,100,1,124, + 0,106,5,124,0,106,6,161,3,1,0,100,2,83,0,41, + 3,122,30,73,110,105,116,105,97,108,105,122,101,32,97,110, + 32,101,120,116,101,110,115,105,111,110,32,109,111,100,117,108, + 101,122,40,101,120,116,101,110,115,105,111,110,32,109,111,100, + 117,108,101,32,123,33,114,125,32,101,120,101,99,117,116,101, + 100,32,102,114,111,109,32,123,33,114,125,78,41,7,114,134, + 0,0,0,114,214,0,0,0,114,163,0,0,0,90,12,101, + 120,101,99,95,100,121,110,97,109,105,99,114,149,0,0,0, + 114,116,0,0,0,114,44,0,0,0,169,2,114,118,0,0, + 0,114,216,0,0,0,114,5,0,0,0,114,5,0,0,0, + 114,8,0,0,0,114,217,0,0,0,68,4,0,0,115,8, + 0,0,0,0,2,14,1,6,1,8,255,122,31,69,120,116, + 101,110,115,105,111,110,70,105,108,101,76,111,97,100,101,114, + 46,101,120,101,99,95,109,111,100,117,108,101,99,2,0,0, + 0,0,0,0,0,0,0,0,0,2,0,0,0,4,0,0, + 0,3,0,0,0,115,36,0,0,0,116,0,124,0,106,1, + 131,1,100,1,25,0,137,0,116,2,135,0,102,1,100,2, + 100,3,132,8,116,3,68,0,131,1,131,1,83,0,41,4, + 122,49,82,101,116,117,114,110,32,84,114,117,101,32,105,102, + 32,116,104,101,32,101,120,116,101,110,115,105,111,110,32,109, + 111,100,117,108,101,32,105,115,32,97,32,112,97,99,107,97, + 103,101,46,114,39,0,0,0,99,1,0,0,0,0,0,0, + 0,0,0,0,0,2,0,0,0,4,0,0,0,51,0,0, + 0,115,26,0,0,0,124,0,93,18,125,1,136,0,100,0, + 124,1,23,0,107,2,86,0,1,0,113,2,100,1,83,0, + 41,2,114,209,0,0,0,78,114,5,0,0,0,169,2,114, + 32,0,0,0,218,6,115,117,102,102,105,120,169,1,90,9, + 102,105,108,101,95,110,97,109,101,114,5,0,0,0,114,8, + 0,0,0,218,9,60,103,101,110,101,120,112,114,62,77,4, + 0,0,115,4,0,0,0,4,1,2,255,122,49,69,120,116, + 101,110,115,105,111,110,70,105,108,101,76,111,97,100,101,114, + 46,105,115,95,112,97,99,107,97,103,101,46,60,108,111,99, + 97,108,115,62,46,60,103,101,110,101,120,112,114,62,41,4, + 114,47,0,0,0,114,44,0,0,0,218,3,97,110,121,218, + 18,69,88,84,69,78,83,73,79,78,95,83,85,70,70,73, + 88,69,83,114,219,0,0,0,114,5,0,0,0,114,9,1, + 0,0,114,8,0,0,0,114,182,0,0,0,74,4,0,0, + 115,8,0,0,0,0,2,14,1,12,1,2,255,122,30,69, + 120,116,101,110,115,105,111,110,70,105,108,101,76,111,97,100, + 101,114,46,105,115,95,112,97,99,107,97,103,101,99,2,0, + 0,0,0,0,0,0,0,0,0,0,2,0,0,0,1,0, + 0,0,67,0,0,0,115,4,0,0,0,100,1,83,0,41, + 2,122,63,82,101,116,117,114,110,32,78,111,110,101,32,97, + 115,32,97,110,32,101,120,116,101,110,115,105,111,110,32,109, + 111,100,117,108,101,32,99,97,110,110,111,116,32,99,114,101, + 97,116,101,32,97,32,99,111,100,101,32,111,98,106,101,99, + 116,46,78,114,5,0,0,0,114,219,0,0,0,114,5,0, + 0,0,114,5,0,0,0,114,8,0,0,0,114,213,0,0, + 0,80,4,0,0,115,2,0,0,0,0,2,122,28,69,120, + 116,101,110,115,105,111,110,70,105,108,101,76,111,97,100,101, + 114,46,103,101,116,95,99,111,100,101,99,2,0,0,0,0, + 0,0,0,0,0,0,0,2,0,0,0,1,0,0,0,67, + 0,0,0,115,4,0,0,0,100,1,83,0,41,2,122,53, + 82,101,116,117,114,110,32,78,111,110,101,32,97,115,32,101, + 120,116,101,110,115,105,111,110,32,109,111,100,117,108,101,115, + 32,104,97,118,101,32,110,111,32,115,111,117,114,99,101,32, + 99,111,100,101,46,78,114,5,0,0,0,114,219,0,0,0, + 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,114, + 229,0,0,0,84,4,0,0,115,2,0,0,0,0,2,122, + 30,69,120,116,101,110,115,105,111,110,70,105,108,101,76,111, + 97,100,101,114,46,103,101,116,95,115,111,117,114,99,101,99, + 2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, + 1,0,0,0,67,0,0,0,115,6,0,0,0,124,0,106, + 0,83,0,114,250,0,0,0,114,48,0,0,0,114,219,0, + 0,0,114,5,0,0,0,114,5,0,0,0,114,8,0,0, + 0,114,179,0,0,0,88,4,0,0,115,2,0,0,0,0, + 3,122,32,69,120,116,101,110,115,105,111,110,70,105,108,101, + 76,111,97,100,101,114,46,103,101,116,95,102,105,108,101,110, + 97,109,101,78,41,14,114,125,0,0,0,114,124,0,0,0, + 114,126,0,0,0,114,127,0,0,0,114,209,0,0,0,114, + 243,0,0,0,114,247,0,0,0,114,212,0,0,0,114,217, + 0,0,0,114,182,0,0,0,114,213,0,0,0,114,229,0, + 0,0,114,136,0,0,0,114,179,0,0,0,114,5,0,0, + 0,114,5,0,0,0,114,5,0,0,0,114,8,0,0,0, + 114,252,0,0,0,41,4,0,0,115,22,0,0,0,8,2, + 4,6,8,4,8,4,8,3,8,8,8,6,8,6,8,4, + 8,4,2,1,114,252,0,0,0,99,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,2,0,0,0,64,0, + 0,0,115,104,0,0,0,101,0,90,1,100,0,90,2,100, + 1,90,3,100,2,100,3,132,0,90,4,100,4,100,5,132, + 0,90,5,100,6,100,7,132,0,90,6,100,8,100,9,132, + 0,90,7,100,10,100,11,132,0,90,8,100,12,100,13,132, + 0,90,9,100,14,100,15,132,0,90,10,100,16,100,17,132, + 0,90,11,100,18,100,19,132,0,90,12,100,20,100,21,132, + 0,90,13,100,22,100,23,132,0,90,14,100,24,83,0,41, + 25,218,14,95,78,97,109,101,115,112,97,99,101,80,97,116, + 104,97,38,1,0,0,82,101,112,114,101,115,101,110,116,115, + 32,97,32,110,97,109,101,115,112,97,99,101,32,112,97,99, + 107,97,103,101,39,115,32,112,97,116,104,46,32,32,73,116, + 32,117,115,101,115,32,116,104,101,32,109,111,100,117,108,101, + 32,110,97,109,101,10,32,32,32,32,116,111,32,102,105,110, + 100,32,105,116,115,32,112,97,114,101,110,116,32,109,111,100, + 117,108,101,44,32,97,110,100,32,102,114,111,109,32,116,104, + 101,114,101,32,105,116,32,108,111,111,107,115,32,117,112,32, + 116,104,101,32,112,97,114,101,110,116,39,115,10,32,32,32, + 32,95,95,112,97,116,104,95,95,46,32,32,87,104,101,110, + 32,116,104,105,115,32,99,104,97,110,103,101,115,44,32,116, + 104,101,32,109,111,100,117,108,101,39,115,32,111,119,110,32, + 112,97,116,104,32,105,115,32,114,101,99,111,109,112,117,116, + 101,100,44,10,32,32,32,32,117,115,105,110,103,32,112,97, + 116,104,95,102,105,110,100,101,114,46,32,32,70,111,114,32, + 116,111,112,45,108,101,118,101,108,32,109,111,100,117,108,101, + 115,44,32,116,104,101,32,112,97,114,101,110,116,32,109,111, + 100,117,108,101,39,115,32,112,97,116,104,10,32,32,32,32, + 105,115,32,115,121,115,46,112,97,116,104,46,99,4,0,0, + 0,0,0,0,0,0,0,0,0,4,0,0,0,3,0,0, + 0,67,0,0,0,115,36,0,0,0,124,1,124,0,95,0, + 124,2,124,0,95,1,116,2,124,0,160,3,161,0,131,1, + 124,0,95,4,124,3,124,0,95,5,100,0,83,0,114,109, + 0,0,0,41,6,218,5,95,110,97,109,101,218,5,95,112, + 97,116,104,114,111,0,0,0,218,16,95,103,101,116,95,112, + 97,114,101,110,116,95,112,97,116,104,218,17,95,108,97,115, + 116,95,112,97,114,101,110,116,95,112,97,116,104,218,12,95, + 112,97,116,104,95,102,105,110,100,101,114,169,4,114,118,0, + 0,0,114,116,0,0,0,114,44,0,0,0,90,11,112,97, + 116,104,95,102,105,110,100,101,114,114,5,0,0,0,114,5, + 0,0,0,114,8,0,0,0,114,209,0,0,0,101,4,0, + 0,115,8,0,0,0,0,1,6,1,6,1,14,1,122,23, + 95,78,97,109,101,115,112,97,99,101,80,97,116,104,46,95, + 95,105,110,105,116,95,95,99,1,0,0,0,0,0,0,0, + 0,0,0,0,4,0,0,0,3,0,0,0,67,0,0,0, + 115,38,0,0,0,124,0,106,0,160,1,100,1,161,1,92, + 3,125,1,125,2,125,3,124,2,100,2,107,2,114,30,100, + 3,83,0,124,1,100,4,102,2,83,0,41,5,122,62,82, + 101,116,117,114,110,115,32,97,32,116,117,112,108,101,32,111, + 102,32,40,112,97,114,101,110,116,45,109,111,100,117,108,101, + 45,110,97,109,101,44,32,112,97,114,101,110,116,45,112,97, + 116,104,45,97,116,116,114,45,110,97,109,101,41,114,71,0, + 0,0,114,40,0,0,0,41,2,114,1,0,0,0,114,44, + 0,0,0,90,8,95,95,112,97,116,104,95,95,41,2,114, + 14,1,0,0,114,41,0,0,0,41,4,114,118,0,0,0, + 114,4,1,0,0,218,3,100,111,116,90,2,109,101,114,5, + 0,0,0,114,5,0,0,0,114,8,0,0,0,218,23,95, + 102,105,110,100,95,112,97,114,101,110,116,95,112,97,116,104, + 95,110,97,109,101,115,107,4,0,0,115,8,0,0,0,0, + 2,18,1,8,2,4,3,122,38,95,78,97,109,101,115,112, + 97,99,101,80,97,116,104,46,95,102,105,110,100,95,112,97, + 114,101,110,116,95,112,97,116,104,95,110,97,109,101,115,99, + 1,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0, + 3,0,0,0,67,0,0,0,115,28,0,0,0,124,0,160, + 0,161,0,92,2,125,1,125,2,116,1,116,2,106,3,124, + 1,25,0,124,2,131,2,83,0,114,109,0,0,0,41,4, + 114,21,1,0,0,114,130,0,0,0,114,1,0,0,0,218, + 7,109,111,100,117,108,101,115,41,3,114,118,0,0,0,90, + 18,112,97,114,101,110,116,95,109,111,100,117,108,101,95,110, + 97,109,101,90,14,112,97,116,104,95,97,116,116,114,95,110, + 97,109,101,114,5,0,0,0,114,5,0,0,0,114,8,0, + 0,0,114,16,1,0,0,117,4,0,0,115,4,0,0,0, + 0,1,12,1,122,31,95,78,97,109,101,115,112,97,99,101, + 80,97,116,104,46,95,103,101,116,95,112,97,114,101,110,116, + 95,112,97,116,104,99,1,0,0,0,0,0,0,0,0,0, + 0,0,3,0,0,0,4,0,0,0,67,0,0,0,115,80, + 0,0,0,116,0,124,0,160,1,161,0,131,1,125,1,124, + 1,124,0,106,2,107,3,114,74,124,0,160,3,124,0,106, + 4,124,1,161,2,125,2,124,2,100,0,117,1,114,68,124, + 2,106,5,100,0,117,0,114,68,124,2,106,6,114,68,124, + 2,106,6,124,0,95,7,124,1,124,0,95,2,124,0,106, + 7,83,0,114,109,0,0,0,41,8,114,111,0,0,0,114, + 16,1,0,0,114,17,1,0,0,114,18,1,0,0,114,14, + 1,0,0,114,140,0,0,0,114,178,0,0,0,114,15,1, + 0,0,41,3,114,118,0,0,0,90,11,112,97,114,101,110, + 116,95,112,97,116,104,114,187,0,0,0,114,5,0,0,0, + 114,5,0,0,0,114,8,0,0,0,218,12,95,114,101,99, + 97,108,99,117,108,97,116,101,121,4,0,0,115,16,0,0, + 0,0,2,12,1,10,1,14,3,18,1,6,1,8,1,6, + 1,122,27,95,78,97,109,101,115,112,97,99,101,80,97,116, + 104,46,95,114,101,99,97,108,99,117,108,97,116,101,99,1, + 0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,3, + 0,0,0,67,0,0,0,115,12,0,0,0,116,0,124,0, + 160,1,161,0,131,1,83,0,114,109,0,0,0,41,2,218, + 4,105,116,101,114,114,23,1,0,0,114,246,0,0,0,114, + 5,0,0,0,114,5,0,0,0,114,8,0,0,0,218,8, + 95,95,105,116,101,114,95,95,134,4,0,0,115,2,0,0, + 0,0,1,122,23,95,78,97,109,101,115,112,97,99,101,80, + 97,116,104,46,95,95,105,116,101,114,95,95,99,2,0,0, + 0,0,0,0,0,0,0,0,0,2,0,0,0,2,0,0, + 0,67,0,0,0,115,12,0,0,0,124,0,160,0,161,0, + 124,1,25,0,83,0,114,109,0,0,0,169,1,114,23,1, + 0,0,41,2,114,118,0,0,0,218,5,105,110,100,101,120, + 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,218, + 11,95,95,103,101,116,105,116,101,109,95,95,137,4,0,0, + 115,2,0,0,0,0,1,122,26,95,78,97,109,101,115,112, + 97,99,101,80,97,116,104,46,95,95,103,101,116,105,116,101, + 109,95,95,99,3,0,0,0,0,0,0,0,0,0,0,0, + 3,0,0,0,3,0,0,0,67,0,0,0,115,14,0,0, + 0,124,2,124,0,106,0,124,1,60,0,100,0,83,0,114, + 109,0,0,0,41,1,114,15,1,0,0,41,3,114,118,0, + 0,0,114,27,1,0,0,114,44,0,0,0,114,5,0,0, + 0,114,5,0,0,0,114,8,0,0,0,218,11,95,95,115, + 101,116,105,116,101,109,95,95,140,4,0,0,115,2,0,0, + 0,0,1,122,26,95,78,97,109,101,115,112,97,99,101,80, + 97,116,104,46,95,95,115,101,116,105,116,101,109,95,95,99, + 1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, + 3,0,0,0,67,0,0,0,115,12,0,0,0,116,0,124, + 0,160,1,161,0,131,1,83,0,114,109,0,0,0,41,2, + 114,23,0,0,0,114,23,1,0,0,114,246,0,0,0,114, + 5,0,0,0,114,5,0,0,0,114,8,0,0,0,218,7, + 95,95,108,101,110,95,95,143,4,0,0,115,2,0,0,0, + 0,1,122,22,95,78,97,109,101,115,112,97,99,101,80,97, + 116,104,46,95,95,108,101,110,95,95,99,1,0,0,0,0, + 0,0,0,0,0,0,0,1,0,0,0,3,0,0,0,67, + 0,0,0,115,12,0,0,0,100,1,160,0,124,0,106,1, + 161,1,83,0,41,2,78,122,20,95,78,97,109,101,115,112, + 97,99,101,80,97,116,104,40,123,33,114,125,41,41,2,114, + 62,0,0,0,114,15,1,0,0,114,246,0,0,0,114,5, + 0,0,0,114,5,0,0,0,114,8,0,0,0,218,8,95, + 95,114,101,112,114,95,95,146,4,0,0,115,2,0,0,0, + 0,1,122,23,95,78,97,109,101,115,112,97,99,101,80,97, + 116,104,46,95,95,114,101,112,114,95,95,99,2,0,0,0, + 0,0,0,0,0,0,0,0,2,0,0,0,3,0,0,0, + 67,0,0,0,115,12,0,0,0,124,1,124,0,160,0,161, + 0,118,0,83,0,114,109,0,0,0,114,26,1,0,0,169, + 2,114,118,0,0,0,218,4,105,116,101,109,114,5,0,0, + 0,114,5,0,0,0,114,8,0,0,0,218,12,95,95,99, + 111,110,116,97,105,110,115,95,95,149,4,0,0,115,2,0, + 0,0,0,1,122,27,95,78,97,109,101,115,112,97,99,101, + 80,97,116,104,46,95,95,99,111,110,116,97,105,110,115,95, + 95,99,2,0,0,0,0,0,0,0,0,0,0,0,2,0, + 0,0,3,0,0,0,67,0,0,0,115,16,0,0,0,124, + 0,106,0,160,1,124,1,161,1,1,0,100,0,83,0,114, + 109,0,0,0,41,2,114,15,1,0,0,114,186,0,0,0, + 114,32,1,0,0,114,5,0,0,0,114,5,0,0,0,114, + 8,0,0,0,114,186,0,0,0,152,4,0,0,115,2,0, + 0,0,0,1,122,21,95,78,97,109,101,115,112,97,99,101, + 80,97,116,104,46,97,112,112,101,110,100,78,41,15,114,125, + 0,0,0,114,124,0,0,0,114,126,0,0,0,114,127,0, + 0,0,114,209,0,0,0,114,21,1,0,0,114,16,1,0, + 0,114,23,1,0,0,114,25,1,0,0,114,28,1,0,0, + 114,29,1,0,0,114,30,1,0,0,114,31,1,0,0,114, + 34,1,0,0,114,186,0,0,0,114,5,0,0,0,114,5, + 0,0,0,114,5,0,0,0,114,8,0,0,0,114,13,1, + 0,0,94,4,0,0,115,24,0,0,0,8,1,4,6,8, + 6,8,10,8,4,8,13,8,3,8,3,8,3,8,3,8, + 3,8,3,114,13,1,0,0,99,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,3,0,0,0,64,0,0, + 0,115,80,0,0,0,101,0,90,1,100,0,90,2,100,1, + 100,2,132,0,90,3,101,4,100,3,100,4,132,0,131,1, + 90,5,100,5,100,6,132,0,90,6,100,7,100,8,132,0, + 90,7,100,9,100,10,132,0,90,8,100,11,100,12,132,0, + 90,9,100,13,100,14,132,0,90,10,100,15,100,16,132,0, + 90,11,100,17,83,0,41,18,218,16,95,78,97,109,101,115, + 112,97,99,101,76,111,97,100,101,114,99,4,0,0,0,0, + 0,0,0,0,0,0,0,4,0,0,0,4,0,0,0,67, + 0,0,0,115,18,0,0,0,116,0,124,1,124,2,124,3, + 131,3,124,0,95,1,100,0,83,0,114,109,0,0,0,41, + 2,114,13,1,0,0,114,15,1,0,0,114,19,1,0,0, + 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,114, + 209,0,0,0,158,4,0,0,115,2,0,0,0,0,1,122, + 25,95,78,97,109,101,115,112,97,99,101,76,111,97,100,101, + 114,46,95,95,105,110,105,116,95,95,99,2,0,0,0,0, + 0,0,0,0,0,0,0,2,0,0,0,3,0,0,0,67, + 0,0,0,115,12,0,0,0,100,1,160,0,124,1,106,1, + 161,1,83,0,41,2,122,115,82,101,116,117,114,110,32,114, + 101,112,114,32,102,111,114,32,116,104,101,32,109,111,100,117, + 108,101,46,10,10,32,32,32,32,32,32,32,32,84,104,101, + 32,109,101,116,104,111,100,32,105,115,32,100,101,112,114,101, + 99,97,116,101,100,46,32,32,84,104,101,32,105,109,112,111, + 114,116,32,109,97,99,104,105,110,101,114,121,32,100,111,101, + 115,32,116,104,101,32,106,111,98,32,105,116,115,101,108,102, + 46,10,10,32,32,32,32,32,32,32,32,122,25,60,109,111, + 100,117,108,101,32,123,33,114,125,32,40,110,97,109,101,115, + 112,97,99,101,41,62,41,2,114,62,0,0,0,114,125,0, + 0,0,41,2,114,193,0,0,0,114,216,0,0,0,114,5, + 0,0,0,114,5,0,0,0,114,8,0,0,0,218,11,109, + 111,100,117,108,101,95,114,101,112,114,161,4,0,0,115,2, + 0,0,0,0,7,122,28,95,78,97,109,101,115,112,97,99, + 101,76,111,97,100,101,114,46,109,111,100,117,108,101,95,114, + 101,112,114,99,2,0,0,0,0,0,0,0,0,0,0,0, + 2,0,0,0,1,0,0,0,67,0,0,0,115,4,0,0, + 0,100,1,83,0,41,2,78,84,114,5,0,0,0,114,219, + 0,0,0,114,5,0,0,0,114,5,0,0,0,114,8,0, + 0,0,114,182,0,0,0,170,4,0,0,115,2,0,0,0, + 0,1,122,27,95,78,97,109,101,115,112,97,99,101,76,111, + 97,100,101,114,46,105,115,95,112,97,99,107,97,103,101,99, + 2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, + 1,0,0,0,67,0,0,0,115,4,0,0,0,100,1,83, + 0,41,2,78,114,40,0,0,0,114,5,0,0,0,114,219, + 0,0,0,114,5,0,0,0,114,5,0,0,0,114,8,0, + 0,0,114,229,0,0,0,173,4,0,0,115,2,0,0,0, + 0,1,122,27,95,78,97,109,101,115,112,97,99,101,76,111, + 97,100,101,114,46,103,101,116,95,115,111,117,114,99,101,99, + 2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, + 6,0,0,0,67,0,0,0,115,16,0,0,0,116,0,100, + 1,100,2,100,3,100,4,100,5,141,4,83,0,41,6,78, + 114,40,0,0,0,122,8,60,115,116,114,105,110,103,62,114, + 215,0,0,0,84,41,1,114,231,0,0,0,41,1,114,232, + 0,0,0,114,219,0,0,0,114,5,0,0,0,114,5,0, + 0,0,114,8,0,0,0,114,213,0,0,0,176,4,0,0, + 115,2,0,0,0,0,1,122,25,95,78,97,109,101,115,112, + 97,99,101,76,111,97,100,101,114,46,103,101,116,95,99,111, + 100,101,99,2,0,0,0,0,0,0,0,0,0,0,0,2, + 0,0,0,1,0,0,0,67,0,0,0,115,4,0,0,0, + 100,1,83,0,114,210,0,0,0,114,5,0,0,0,114,211, + 0,0,0,114,5,0,0,0,114,5,0,0,0,114,8,0, + 0,0,114,212,0,0,0,179,4,0,0,115,2,0,0,0, + 0,1,122,30,95,78,97,109,101,115,112,97,99,101,76,111, + 97,100,101,114,46,99,114,101,97,116,101,95,109,111,100,117, + 108,101,99,2,0,0,0,0,0,0,0,0,0,0,0,2, + 0,0,0,1,0,0,0,67,0,0,0,115,4,0,0,0, + 100,0,83,0,114,109,0,0,0,114,5,0,0,0,114,6, + 1,0,0,114,5,0,0,0,114,5,0,0,0,114,8,0, + 0,0,114,217,0,0,0,182,4,0,0,115,2,0,0,0, + 0,1,122,28,95,78,97,109,101,115,112,97,99,101,76,111, + 97,100,101,114,46,101,120,101,99,95,109,111,100,117,108,101, + 99,2,0,0,0,0,0,0,0,0,0,0,0,2,0,0, + 0,4,0,0,0,67,0,0,0,115,26,0,0,0,116,0, + 160,1,100,1,124,0,106,2,161,2,1,0,116,0,160,3, + 124,0,124,1,161,2,83,0,41,2,122,98,76,111,97,100, + 32,97,32,110,97,109,101,115,112,97,99,101,32,109,111,100, + 117,108,101,46,10,10,32,32,32,32,32,32,32,32,84,104, 105,115,32,109,101,116,104,111,100,32,105,115,32,100,101,112, 114,101,99,97,116,101,100,46,32,32,85,115,101,32,101,120, 101,99,95,109,111,100,117,108,101,40,41,32,105,110,115,116, - 101,97,100,46,10,10,32,32,32,32,32,32,32,32,78,169, - 2,114,203,0,0,0,114,140,0,0,0,169,4,114,193,0, - 0,0,114,139,0,0,0,114,44,0,0,0,114,187,0,0, + 101,97,100,46,10,10,32,32,32,32,32,32,32,32,122,38, + 110,97,109,101,115,112,97,99,101,32,109,111,100,117,108,101, + 32,108,111,97,100,101,100,32,119,105,116,104,32,112,97,116, + 104,32,123,33,114,125,41,4,114,134,0,0,0,114,149,0, + 0,0,114,15,1,0,0,114,218,0,0,0,114,219,0,0, 0,114,5,0,0,0,114,5,0,0,0,114,8,0,0,0, - 218,11,102,105,110,100,95,109,111,100,117,108,101,242,2,0, - 0,115,8,0,0,0,0,7,12,1,8,1,6,2,122,33, - 87,105,110,100,111,119,115,82,101,103,105,115,116,114,121,70, - 105,110,100,101,114,46,102,105,110,100,95,109,111,100,117,108, - 101,41,2,78,78,41,1,78,41,12,114,125,0,0,0,114, - 124,0,0,0,114,126,0,0,0,114,127,0,0,0,114,197, - 0,0,0,114,196,0,0,0,114,195,0,0,0,218,11,99, - 108,97,115,115,109,101,116,104,111,100,114,194,0,0,0,114, - 200,0,0,0,114,203,0,0,0,114,206,0,0,0,114,5, - 0,0,0,114,5,0,0,0,114,5,0,0,0,114,8,0, - 0,0,114,191,0,0,0,192,2,0,0,115,28,0,0,0, - 8,2,4,3,2,255,2,4,2,255,2,3,4,2,2,1, - 10,6,2,1,10,14,2,1,12,15,2,1,114,191,0,0, - 0,99,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,2,0,0,0,64,0,0,0,115,48,0,0,0,101, - 0,90,1,100,0,90,2,100,1,90,3,100,2,100,3,132, - 0,90,4,100,4,100,5,132,0,90,5,100,6,100,7,132, - 0,90,6,100,8,100,9,132,0,90,7,100,10,83,0,41, - 11,218,13,95,76,111,97,100,101,114,66,97,115,105,99,115, - 122,83,66,97,115,101,32,99,108,97,115,115,32,111,102,32, - 99,111,109,109,111,110,32,99,111,100,101,32,110,101,101,100, - 101,100,32,98,121,32,98,111,116,104,32,83,111,117,114,99, - 101,76,111,97,100,101,114,32,97,110,100,10,32,32,32,32, - 83,111,117,114,99,101,108,101,115,115,70,105,108,101,76,111, - 97,100,101,114,46,99,2,0,0,0,0,0,0,0,0,0, - 0,0,5,0,0,0,4,0,0,0,67,0,0,0,115,64, - 0,0,0,116,0,124,0,160,1,124,1,161,1,131,1,100, - 1,25,0,125,2,124,2,160,2,100,2,100,1,161,2,100, - 3,25,0,125,3,124,1,160,3,100,2,161,1,100,4,25, - 0,125,4,124,3,100,5,107,2,111,62,124,4,100,5,107, - 3,83,0,41,6,122,141,67,111,110,99,114,101,116,101,32, - 105,109,112,108,101,109,101,110,116,97,116,105,111,110,32,111, - 102,32,73,110,115,112,101,99,116,76,111,97,100,101,114,46, - 105,115,95,112,97,99,107,97,103,101,32,98,121,32,99,104, - 101,99,107,105,110,103,32,105,102,10,32,32,32,32,32,32, - 32,32,116,104,101,32,112,97,116,104,32,114,101,116,117,114, - 110,101,100,32,98,121,32,103,101,116,95,102,105,108,101,110, - 97,109,101,32,104,97,115,32,97,32,102,105,108,101,110,97, - 109,101,32,111,102,32,39,95,95,105,110,105,116,95,95,46, - 112,121,39,46,114,39,0,0,0,114,71,0,0,0,114,73, - 0,0,0,114,28,0,0,0,218,8,95,95,105,110,105,116, - 95,95,41,4,114,47,0,0,0,114,179,0,0,0,114,43, - 0,0,0,114,41,0,0,0,41,5,114,118,0,0,0,114, - 139,0,0,0,114,96,0,0,0,90,13,102,105,108,101,110, - 97,109,101,95,98,97,115,101,90,9,116,97,105,108,95,110, - 97,109,101,114,5,0,0,0,114,5,0,0,0,114,8,0, - 0,0,114,182,0,0,0,5,3,0,0,115,8,0,0,0, - 0,3,18,1,16,1,14,1,122,24,95,76,111,97,100,101, - 114,66,97,115,105,99,115,46,105,115,95,112,97,99,107,97, - 103,101,99,2,0,0,0,0,0,0,0,0,0,0,0,2, - 0,0,0,1,0,0,0,67,0,0,0,115,4,0,0,0, - 100,1,83,0,169,2,122,42,85,115,101,32,100,101,102,97, - 117,108,116,32,115,101,109,97,110,116,105,99,115,32,102,111, - 114,32,109,111,100,117,108,101,32,99,114,101,97,116,105,111, - 110,46,78,114,5,0,0,0,169,2,114,118,0,0,0,114, - 187,0,0,0,114,5,0,0,0,114,5,0,0,0,114,8, - 0,0,0,218,13,99,114,101,97,116,101,95,109,111,100,117, - 108,101,13,3,0,0,115,2,0,0,0,0,1,122,27,95, - 76,111,97,100,101,114,66,97,115,105,99,115,46,99,114,101, - 97,116,101,95,109,111,100,117,108,101,99,2,0,0,0,0, - 0,0,0,0,0,0,0,3,0,0,0,5,0,0,0,67, - 0,0,0,115,56,0,0,0,124,0,160,0,124,1,106,1, - 161,1,125,2,124,2,100,1,117,0,114,36,116,2,100,2, - 160,3,124,1,106,1,161,1,131,1,130,1,116,4,160,5, - 116,6,124,2,124,1,106,7,161,3,1,0,100,1,83,0, - 41,3,122,19,69,120,101,99,117,116,101,32,116,104,101,32, - 109,111,100,117,108,101,46,78,122,52,99,97,110,110,111,116, - 32,108,111,97,100,32,109,111,100,117,108,101,32,123,33,114, - 125,32,119,104,101,110,32,103,101,116,95,99,111,100,101,40, - 41,32,114,101,116,117,114,110,115,32,78,111,110,101,41,8, - 218,8,103,101,116,95,99,111,100,101,114,125,0,0,0,114, - 117,0,0,0,114,62,0,0,0,114,134,0,0,0,218,25, - 95,99,97,108,108,95,119,105,116,104,95,102,114,97,109,101, - 115,95,114,101,109,111,118,101,100,218,4,101,120,101,99,114, - 131,0,0,0,41,3,114,118,0,0,0,218,6,109,111,100, - 117,108,101,114,164,0,0,0,114,5,0,0,0,114,5,0, - 0,0,114,8,0,0,0,218,11,101,120,101,99,95,109,111, - 100,117,108,101,16,3,0,0,115,12,0,0,0,0,2,12, - 1,8,1,6,1,4,255,6,2,122,25,95,76,111,97,100, - 101,114,66,97,115,105,99,115,46,101,120,101,99,95,109,111, - 100,117,108,101,99,2,0,0,0,0,0,0,0,0,0,0, - 0,2,0,0,0,4,0,0,0,67,0,0,0,115,12,0, - 0,0,116,0,160,1,124,0,124,1,161,2,83,0,41,1, - 122,26,84,104,105,115,32,109,111,100,117,108,101,32,105,115, - 32,100,101,112,114,101,99,97,116,101,100,46,41,2,114,134, - 0,0,0,218,17,95,108,111,97,100,95,109,111,100,117,108, - 101,95,115,104,105,109,169,2,114,118,0,0,0,114,139,0, - 0,0,114,5,0,0,0,114,5,0,0,0,114,8,0,0, - 0,218,11,108,111,97,100,95,109,111,100,117,108,101,24,3, - 0,0,115,2,0,0,0,0,2,122,25,95,76,111,97,100, - 101,114,66,97,115,105,99,115,46,108,111,97,100,95,109,111, - 100,117,108,101,78,41,8,114,125,0,0,0,114,124,0,0, - 0,114,126,0,0,0,114,127,0,0,0,114,182,0,0,0, - 114,212,0,0,0,114,217,0,0,0,114,220,0,0,0,114, - 5,0,0,0,114,5,0,0,0,114,5,0,0,0,114,8, - 0,0,0,114,208,0,0,0,0,3,0,0,115,10,0,0, - 0,8,2,4,3,8,8,8,3,8,8,114,208,0,0,0, - 99,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,3,0,0,0,64,0,0,0,115,74,0,0,0,101,0, - 90,1,100,0,90,2,100,1,100,2,132,0,90,3,100,3, - 100,4,132,0,90,4,100,5,100,6,132,0,90,5,100,7, - 100,8,132,0,90,6,100,9,100,10,132,0,90,7,100,11, - 100,12,156,1,100,13,100,14,132,2,90,8,100,15,100,16, - 132,0,90,9,100,17,83,0,41,18,218,12,83,111,117,114, - 99,101,76,111,97,100,101,114,99,2,0,0,0,0,0,0, - 0,0,0,0,0,2,0,0,0,1,0,0,0,67,0,0, - 0,115,8,0,0,0,116,0,130,1,100,1,83,0,41,2, - 122,165,79,112,116,105,111,110,97,108,32,109,101,116,104,111, - 100,32,116,104,97,116,32,114,101,116,117,114,110,115,32,116, - 104,101,32,109,111,100,105,102,105,99,97,116,105,111,110,32, - 116,105,109,101,32,40,97,110,32,105,110,116,41,32,102,111, - 114,32,116,104,101,10,32,32,32,32,32,32,32,32,115,112, - 101,99,105,102,105,101,100,32,112,97,116,104,32,40,97,32, - 115,116,114,41,46,10,10,32,32,32,32,32,32,32,32,82, - 97,105,115,101,115,32,79,83,69,114,114,111,114,32,119,104, - 101,110,32,116,104,101,32,112,97,116,104,32,99,97,110,110, - 111,116,32,98,101,32,104,97,110,100,108,101,100,46,10,32, - 32,32,32,32,32,32,32,78,41,1,114,50,0,0,0,169, - 2,114,118,0,0,0,114,44,0,0,0,114,5,0,0,0, - 114,5,0,0,0,114,8,0,0,0,218,10,112,97,116,104, - 95,109,116,105,109,101,31,3,0,0,115,2,0,0,0,0, - 6,122,23,83,111,117,114,99,101,76,111,97,100,101,114,46, - 112,97,116,104,95,109,116,105,109,101,99,2,0,0,0,0, - 0,0,0,0,0,0,0,2,0,0,0,4,0,0,0,67, - 0,0,0,115,14,0,0,0,100,1,124,0,160,0,124,1, - 161,1,105,1,83,0,41,2,97,158,1,0,0,79,112,116, - 105,111,110,97,108,32,109,101,116,104,111,100,32,114,101,116, - 117,114,110,105,110,103,32,97,32,109,101,116,97,100,97,116, - 97,32,100,105,99,116,32,102,111,114,32,116,104,101,32,115, - 112,101,99,105,102,105,101,100,10,32,32,32,32,32,32,32, - 32,112,97,116,104,32,40,97,32,115,116,114,41,46,10,10, - 32,32,32,32,32,32,32,32,80,111,115,115,105,98,108,101, - 32,107,101,121,115,58,10,32,32,32,32,32,32,32,32,45, - 32,39,109,116,105,109,101,39,32,40,109,97,110,100,97,116, - 111,114,121,41,32,105,115,32,116,104,101,32,110,117,109,101, - 114,105,99,32,116,105,109,101,115,116,97,109,112,32,111,102, - 32,108,97,115,116,32,115,111,117,114,99,101,10,32,32,32, - 32,32,32,32,32,32,32,99,111,100,101,32,109,111,100,105, - 102,105,99,97,116,105,111,110,59,10,32,32,32,32,32,32, - 32,32,45,32,39,115,105,122,101,39,32,40,111,112,116,105, - 111,110,97,108,41,32,105,115,32,116,104,101,32,115,105,122, - 101,32,105,110,32,98,121,116,101,115,32,111,102,32,116,104, - 101,32,115,111,117,114,99,101,32,99,111,100,101,46,10,10, - 32,32,32,32,32,32,32,32,73,109,112,108,101,109,101,110, - 116,105,110,103,32,116,104,105,115,32,109,101,116,104,111,100, - 32,97,108,108,111,119,115,32,116,104,101,32,108,111,97,100, - 101,114,32,116,111,32,114,101,97,100,32,98,121,116,101,99, - 111,100,101,32,102,105,108,101,115,46,10,32,32,32,32,32, - 32,32,32,82,97,105,115,101,115,32,79,83,69,114,114,111, - 114,32,119,104,101,110,32,116,104,101,32,112,97,116,104,32, - 99,97,110,110,111,116,32,98,101,32,104,97,110,100,108,101, - 100,46,10,32,32,32,32,32,32,32,32,114,169,0,0,0, - 41,1,114,223,0,0,0,114,222,0,0,0,114,5,0,0, - 0,114,5,0,0,0,114,8,0,0,0,218,10,112,97,116, - 104,95,115,116,97,116,115,39,3,0,0,115,2,0,0,0, - 0,12,122,23,83,111,117,114,99,101,76,111,97,100,101,114, - 46,112,97,116,104,95,115,116,97,116,115,99,4,0,0,0, - 0,0,0,0,0,0,0,0,4,0,0,0,4,0,0,0, - 67,0,0,0,115,12,0,0,0,124,0,160,0,124,2,124, - 3,161,2,83,0,41,1,122,228,79,112,116,105,111,110,97, - 108,32,109,101,116,104,111,100,32,119,104,105,99,104,32,119, - 114,105,116,101,115,32,100,97,116,97,32,40,98,121,116,101, - 115,41,32,116,111,32,97,32,102,105,108,101,32,112,97,116, - 104,32,40,97,32,115,116,114,41,46,10,10,32,32,32,32, - 32,32,32,32,73,109,112,108,101,109,101,110,116,105,110,103, - 32,116,104,105,115,32,109,101,116,104,111,100,32,97,108,108, - 111,119,115,32,102,111,114,32,116,104,101,32,119,114,105,116, - 105,110,103,32,111,102,32,98,121,116,101,99,111,100,101,32, - 102,105,108,101,115,46,10,10,32,32,32,32,32,32,32,32, - 84,104,101,32,115,111,117,114,99,101,32,112,97,116,104,32, - 105,115,32,110,101,101,100,101,100,32,105,110,32,111,114,100, - 101,114,32,116,111,32,99,111,114,114,101,99,116,108,121,32, - 116,114,97,110,115,102,101,114,32,112,101,114,109,105,115,115, - 105,111,110,115,10,32,32,32,32,32,32,32,32,41,1,218, - 8,115,101,116,95,100,97,116,97,41,4,114,118,0,0,0, - 114,107,0,0,0,90,10,99,97,99,104,101,95,112,97,116, - 104,114,26,0,0,0,114,5,0,0,0,114,5,0,0,0, - 114,8,0,0,0,218,15,95,99,97,99,104,101,95,98,121, - 116,101,99,111,100,101,53,3,0,0,115,2,0,0,0,0, - 8,122,28,83,111,117,114,99,101,76,111,97,100,101,114,46, - 95,99,97,99,104,101,95,98,121,116,101,99,111,100,101,99, - 3,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0, - 1,0,0,0,67,0,0,0,115,4,0,0,0,100,1,83, - 0,41,2,122,150,79,112,116,105,111,110,97,108,32,109,101, - 116,104,111,100,32,119,104,105,99,104,32,119,114,105,116,101, - 115,32,100,97,116,97,32,40,98,121,116,101,115,41,32,116, - 111,32,97,32,102,105,108,101,32,112,97,116,104,32,40,97, - 32,115,116,114,41,46,10,10,32,32,32,32,32,32,32,32, - 73,109,112,108,101,109,101,110,116,105,110,103,32,116,104,105, - 115,32,109,101,116,104,111,100,32,97,108,108,111,119,115,32, - 102,111,114,32,116,104,101,32,119,114,105,116,105,110,103,32, - 111,102,32,98,121,116,101,99,111,100,101,32,102,105,108,101, - 115,46,10,32,32,32,32,32,32,32,32,78,114,5,0,0, - 0,41,3,114,118,0,0,0,114,44,0,0,0,114,26,0, - 0,0,114,5,0,0,0,114,5,0,0,0,114,8,0,0, - 0,114,225,0,0,0,63,3,0,0,115,2,0,0,0,0, - 1,122,21,83,111,117,114,99,101,76,111,97,100,101,114,46, - 115,101,116,95,100,97,116,97,99,2,0,0,0,0,0,0, - 0,0,0,0,0,5,0,0,0,10,0,0,0,67,0,0, - 0,115,84,0,0,0,124,0,160,0,124,1,161,1,125,2, - 122,14,124,0,160,1,124,2,161,1,125,3,87,0,110,50, - 4,0,116,2,121,74,1,0,125,4,1,0,122,26,116,3, - 100,1,124,1,100,2,141,2,124,4,130,2,87,0,89,0, - 100,3,125,4,126,4,110,10,100,3,125,4,126,4,48,0, - 48,0,116,4,124,3,131,1,83,0,41,4,122,52,67,111, - 110,99,114,101,116,101,32,105,109,112,108,101,109,101,110,116, - 97,116,105,111,110,32,111,102,32,73,110,115,112,101,99,116, - 76,111,97,100,101,114,46,103,101,116,95,115,111,117,114,99, - 101,46,122,39,115,111,117,114,99,101,32,110,111,116,32,97, - 118,97,105,108,97,98,108,101,32,116,104,114,111,117,103,104, - 32,103,101,116,95,100,97,116,97,40,41,114,115,0,0,0, - 78,41,5,114,179,0,0,0,218,8,103,101,116,95,100,97, - 116,97,114,50,0,0,0,114,117,0,0,0,114,176,0,0, - 0,41,5,114,118,0,0,0,114,139,0,0,0,114,44,0, - 0,0,114,174,0,0,0,218,3,101,120,99,114,5,0,0, - 0,114,5,0,0,0,114,8,0,0,0,218,10,103,101,116, - 95,115,111,117,114,99,101,70,3,0,0,115,20,0,0,0, - 0,2,10,1,2,1,14,1,14,1,4,1,2,255,4,1, - 2,255,24,2,122,23,83,111,117,114,99,101,76,111,97,100, - 101,114,46,103,101,116,95,115,111,117,114,99,101,114,104,0, - 0,0,41,1,218,9,95,111,112,116,105,109,105,122,101,99, - 3,0,0,0,0,0,0,0,1,0,0,0,4,0,0,0, - 8,0,0,0,67,0,0,0,115,22,0,0,0,116,0,106, - 1,116,2,124,1,124,2,100,1,100,2,124,3,100,3,141, - 6,83,0,41,4,122,130,82,101,116,117,114,110,32,116,104, - 101,32,99,111,100,101,32,111,98,106,101,99,116,32,99,111, - 109,112,105,108,101,100,32,102,114,111,109,32,115,111,117,114, - 99,101,46,10,10,32,32,32,32,32,32,32,32,84,104,101, - 32,39,100,97,116,97,39,32,97,114,103,117,109,101,110,116, - 32,99,97,110,32,98,101,32,97,110,121,32,111,98,106,101, - 99,116,32,116,121,112,101,32,116,104,97,116,32,99,111,109, - 112,105,108,101,40,41,32,115,117,112,112,111,114,116,115,46, - 10,32,32,32,32,32,32,32,32,114,215,0,0,0,84,41, - 2,218,12,100,111,110,116,95,105,110,104,101,114,105,116,114, - 83,0,0,0,41,3,114,134,0,0,0,114,214,0,0,0, - 218,7,99,111,109,112,105,108,101,41,4,114,118,0,0,0, - 114,26,0,0,0,114,44,0,0,0,114,230,0,0,0,114, - 5,0,0,0,114,5,0,0,0,114,8,0,0,0,218,14, - 115,111,117,114,99,101,95,116,111,95,99,111,100,101,80,3, - 0,0,115,6,0,0,0,0,5,12,1,4,255,122,27,83, - 111,117,114,99,101,76,111,97,100,101,114,46,115,111,117,114, - 99,101,95,116,111,95,99,111,100,101,99,2,0,0,0,0, - 0,0,0,0,0,0,0,15,0,0,0,9,0,0,0,67, - 0,0,0,115,24,2,0,0,124,0,160,0,124,1,161,1, - 125,2,100,1,125,3,100,1,125,4,100,1,125,5,100,2, - 125,6,100,3,125,7,122,12,116,1,124,2,131,1,125,8, - 87,0,110,24,4,0,116,2,121,66,1,0,1,0,1,0, - 100,1,125,8,89,0,144,1,110,42,48,0,122,14,124,0, - 160,3,124,2,161,1,125,9,87,0,110,20,4,0,116,4, - 121,102,1,0,1,0,1,0,89,0,144,1,110,6,48,0, - 116,5,124,9,100,4,25,0,131,1,125,3,122,14,124,0, - 160,6,124,8,161,1,125,10,87,0,110,18,4,0,116,4, - 121,148,1,0,1,0,1,0,89,0,110,216,48,0,124,1, - 124,8,100,5,156,2,125,11,122,148,116,7,124,10,124,1, - 124,11,131,3,125,12,116,8,124,10,131,1,100,6,100,1, - 133,2,25,0,125,13,124,12,100,7,64,0,100,8,107,3, - 125,6,124,6,144,1,114,30,124,12,100,9,64,0,100,8, - 107,3,125,7,116,9,106,10,100,10,107,3,144,1,114,50, - 124,7,115,248,116,9,106,10,100,11,107,2,144,1,114,50, - 124,0,160,6,124,2,161,1,125,4,116,9,160,11,116,12, - 124,4,161,2,125,5,116,13,124,10,124,5,124,1,124,11, - 131,4,1,0,110,20,116,14,124,10,124,3,124,9,100,12, - 25,0,124,1,124,11,131,5,1,0,87,0,110,24,4,0, - 116,15,116,16,102,2,144,1,121,76,1,0,1,0,1,0, - 89,0,110,32,48,0,116,17,160,18,100,13,124,8,124,2, - 161,3,1,0,116,19,124,13,124,1,124,8,124,2,100,14, - 141,4,83,0,124,4,100,1,117,0,144,1,114,128,124,0, - 160,6,124,2,161,1,125,4,124,0,160,20,124,4,124,2, - 161,2,125,14,116,17,160,18,100,15,124,2,161,2,1,0, - 116,21,106,22,144,2,115,20,124,8,100,1,117,1,144,2, - 114,20,124,3,100,1,117,1,144,2,114,20,124,6,144,1, - 114,220,124,5,100,1,117,0,144,1,114,206,116,9,160,11, - 124,4,161,1,125,5,116,23,124,14,124,5,124,7,131,3, - 125,10,110,16,116,24,124,14,124,3,116,25,124,4,131,1, - 131,3,125,10,122,18,124,0,160,26,124,2,124,8,124,10, - 161,3,1,0,87,0,110,20,4,0,116,2,144,2,121,18, - 1,0,1,0,1,0,89,0,110,2,48,0,124,14,83,0, - 41,16,122,190,67,111,110,99,114,101,116,101,32,105,109,112, - 108,101,109,101,110,116,97,116,105,111,110,32,111,102,32,73, - 110,115,112,101,99,116,76,111,97,100,101,114,46,103,101,116, - 95,99,111,100,101,46,10,10,32,32,32,32,32,32,32,32, - 82,101,97,100,105,110,103,32,111,102,32,98,121,116,101,99, - 111,100,101,32,114,101,113,117,105,114,101,115,32,112,97,116, - 104,95,115,116,97,116,115,32,116,111,32,98,101,32,105,109, - 112,108,101,109,101,110,116,101,100,46,32,84,111,32,119,114, - 105,116,101,10,32,32,32,32,32,32,32,32,98,121,116,101, - 99,111,100,101,44,32,115,101,116,95,100,97,116,97,32,109, - 117,115,116,32,97,108,115,111,32,98,101,32,105,109,112,108, - 101,109,101,110,116,101,100,46,10,10,32,32,32,32,32,32, - 32,32,78,70,84,114,169,0,0,0,114,159,0,0,0,114, - 145,0,0,0,114,39,0,0,0,114,73,0,0,0,114,28, - 0,0,0,90,5,110,101,118,101,114,90,6,97,108,119,97, - 121,115,218,4,115,105,122,101,122,13,123,125,32,109,97,116, - 99,104,101,115,32,123,125,41,3,114,116,0,0,0,114,106, - 0,0,0,114,107,0,0,0,122,19,99,111,100,101,32,111, - 98,106,101,99,116,32,102,114,111,109,32,123,125,41,27,114, - 179,0,0,0,114,97,0,0,0,114,82,0,0,0,114,224, - 0,0,0,114,50,0,0,0,114,18,0,0,0,114,227,0, - 0,0,114,152,0,0,0,218,10,109,101,109,111,114,121,118, - 105,101,119,114,163,0,0,0,90,21,99,104,101,99,107,95, - 104,97,115,104,95,98,97,115,101,100,95,112,121,99,115,114, - 157,0,0,0,218,17,95,82,65,87,95,77,65,71,73,67, - 95,78,85,77,66,69,82,114,158,0,0,0,114,156,0,0, - 0,114,117,0,0,0,114,150,0,0,0,114,134,0,0,0, - 114,149,0,0,0,114,165,0,0,0,114,233,0,0,0,114, - 1,0,0,0,218,19,100,111,110,116,95,119,114,105,116,101, - 95,98,121,116,101,99,111,100,101,114,171,0,0,0,114,170, - 0,0,0,114,23,0,0,0,114,226,0,0,0,41,15,114, - 118,0,0,0,114,139,0,0,0,114,107,0,0,0,114,154, - 0,0,0,114,174,0,0,0,114,157,0,0,0,90,10,104, - 97,115,104,95,98,97,115,101,100,90,12,99,104,101,99,107, - 95,115,111,117,114,99,101,114,106,0,0,0,218,2,115,116, - 114,26,0,0,0,114,151,0,0,0,114,2,0,0,0,90, - 10,98,121,116,101,115,95,100,97,116,97,90,11,99,111,100, - 101,95,111,98,106,101,99,116,114,5,0,0,0,114,5,0, - 0,0,114,8,0,0,0,114,213,0,0,0,88,3,0,0, - 115,152,0,0,0,0,7,10,1,4,1,4,1,4,1,4, - 1,4,1,2,1,12,1,12,1,12,2,2,1,14,1,12, - 1,8,2,12,1,2,1,14,1,12,1,6,3,2,1,2, - 254,6,4,2,1,12,1,16,1,12,1,6,1,12,1,12, - 1,2,255,2,2,8,254,4,3,10,1,4,1,2,1,2, - 254,4,4,8,1,2,255,6,3,2,1,2,1,2,1,6, - 1,2,1,2,251,8,7,18,1,6,2,8,1,2,255,4, - 2,6,1,2,1,2,254,6,3,10,1,10,1,12,1,12, - 1,18,1,6,255,4,2,6,1,10,1,10,1,14,2,6, - 1,6,255,4,2,2,1,18,1,14,1,6,1,122,21,83, - 111,117,114,99,101,76,111,97,100,101,114,46,103,101,116,95, - 99,111,100,101,78,41,10,114,125,0,0,0,114,124,0,0, - 0,114,126,0,0,0,114,223,0,0,0,114,224,0,0,0, - 114,226,0,0,0,114,225,0,0,0,114,229,0,0,0,114, - 233,0,0,0,114,213,0,0,0,114,5,0,0,0,114,5, - 0,0,0,114,5,0,0,0,114,8,0,0,0,114,221,0, - 0,0,29,3,0,0,115,14,0,0,0,8,2,8,8,8, - 14,8,10,8,7,8,10,14,8,114,221,0,0,0,99,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, - 0,0,0,0,0,0,0,115,124,0,0,0,101,0,90,1, - 100,0,90,2,100,1,90,3,100,2,100,3,132,0,90,4, - 100,4,100,5,132,0,90,5,100,6,100,7,132,0,90,6, - 101,7,135,0,102,1,100,8,100,9,132,8,131,1,90,8, - 101,7,100,10,100,11,132,0,131,1,90,9,100,12,100,13, - 132,0,90,10,101,7,100,14,100,15,132,0,131,1,90,11, - 100,16,100,17,132,0,90,12,100,18,100,19,132,0,90,13, - 100,20,100,21,132,0,90,14,100,22,100,23,132,0,90,15, - 135,0,4,0,90,16,83,0,41,24,218,10,70,105,108,101, - 76,111,97,100,101,114,122,103,66,97,115,101,32,102,105,108, - 101,32,108,111,97,100,101,114,32,99,108,97,115,115,32,119, - 104,105,99,104,32,105,109,112,108,101,109,101,110,116,115,32, - 116,104,101,32,108,111,97,100,101,114,32,112,114,111,116,111, - 99,111,108,32,109,101,116,104,111,100,115,32,116,104,97,116, - 10,32,32,32,32,114,101,113,117,105,114,101,32,102,105,108, - 101,32,115,121,115,116,101,109,32,117,115,97,103,101,46,99, - 3,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0, - 2,0,0,0,67,0,0,0,115,16,0,0,0,124,1,124, - 0,95,0,124,2,124,0,95,1,100,1,83,0,41,2,122, - 75,67,97,99,104,101,32,116,104,101,32,109,111,100,117,108, - 101,32,110,97,109,101,32,97,110,100,32,116,104,101,32,112, - 97,116,104,32,116,111,32,116,104,101,32,102,105,108,101,32, - 102,111,117,110,100,32,98,121,32,116,104,101,10,32,32,32, - 32,32,32,32,32,102,105,110,100,101,114,46,78,114,159,0, - 0,0,41,3,114,118,0,0,0,114,139,0,0,0,114,44, - 0,0,0,114,5,0,0,0,114,5,0,0,0,114,8,0, - 0,0,114,209,0,0,0,178,3,0,0,115,4,0,0,0, - 0,3,6,1,122,19,70,105,108,101,76,111,97,100,101,114, - 46,95,95,105,110,105,116,95,95,99,2,0,0,0,0,0, - 0,0,0,0,0,0,2,0,0,0,2,0,0,0,67,0, - 0,0,115,24,0,0,0,124,0,106,0,124,1,106,0,107, - 2,111,22,124,0,106,1,124,1,106,1,107,2,83,0,114, - 109,0,0,0,169,2,218,9,95,95,99,108,97,115,115,95, - 95,114,131,0,0,0,169,2,114,118,0,0,0,90,5,111, - 116,104,101,114,114,5,0,0,0,114,5,0,0,0,114,8, - 0,0,0,218,6,95,95,101,113,95,95,184,3,0,0,115, - 6,0,0,0,0,1,12,1,10,255,122,17,70,105,108,101, - 76,111,97,100,101,114,46,95,95,101,113,95,95,99,1,0, - 0,0,0,0,0,0,0,0,0,0,1,0,0,0,3,0, - 0,0,67,0,0,0,115,20,0,0,0,116,0,124,0,106, - 1,131,1,116,0,124,0,106,2,131,1,65,0,83,0,114, - 109,0,0,0,169,3,218,4,104,97,115,104,114,116,0,0, - 0,114,44,0,0,0,169,1,114,118,0,0,0,114,5,0, - 0,0,114,5,0,0,0,114,8,0,0,0,218,8,95,95, - 104,97,115,104,95,95,188,3,0,0,115,2,0,0,0,0, - 1,122,19,70,105,108,101,76,111,97,100,101,114,46,95,95, - 104,97,115,104,95,95,99,2,0,0,0,0,0,0,0,0, - 0,0,0,2,0,0,0,3,0,0,0,3,0,0,0,115, - 16,0,0,0,116,0,116,1,124,0,131,2,160,2,124,1, - 161,1,83,0,41,1,122,100,76,111,97,100,32,97,32,109, - 111,100,117,108,101,32,102,114,111,109,32,97,32,102,105,108, - 101,46,10,10,32,32,32,32,32,32,32,32,84,104,105,115, - 32,109,101,116,104,111,100,32,105,115,32,100,101,112,114,101, - 99,97,116,101,100,46,32,32,85,115,101,32,101,120,101,99, - 95,109,111,100,117,108,101,40,41,32,105,110,115,116,101,97, - 100,46,10,10,32,32,32,32,32,32,32,32,41,3,218,5, - 115,117,112,101,114,114,239,0,0,0,114,220,0,0,0,114, - 219,0,0,0,169,1,114,241,0,0,0,114,5,0,0,0, - 114,8,0,0,0,114,220,0,0,0,191,3,0,0,115,2, - 0,0,0,0,10,122,22,70,105,108,101,76,111,97,100,101, - 114,46,108,111,97,100,95,109,111,100,117,108,101,99,2,0, - 0,0,0,0,0,0,0,0,0,0,2,0,0,0,1,0, - 0,0,67,0,0,0,115,6,0,0,0,124,0,106,0,83, - 0,169,1,122,58,82,101,116,117,114,110,32,116,104,101,32, - 112,97,116,104,32,116,111,32,116,104,101,32,115,111,117,114, - 99,101,32,102,105,108,101,32,97,115,32,102,111,117,110,100, - 32,98,121,32,116,104,101,32,102,105,110,100,101,114,46,114, - 48,0,0,0,114,219,0,0,0,114,5,0,0,0,114,5, - 0,0,0,114,8,0,0,0,114,179,0,0,0,203,3,0, - 0,115,2,0,0,0,0,3,122,23,70,105,108,101,76,111, - 97,100,101,114,46,103,101,116,95,102,105,108,101,110,97,109, - 101,99,2,0,0,0,0,0,0,0,0,0,0,0,3,0, - 0,0,8,0,0,0,67,0,0,0,115,126,0,0,0,116, - 0,124,0,116,1,116,2,102,2,131,2,114,70,116,3,160, - 4,116,5,124,1,131,1,161,1,143,24,125,2,124,2,160, - 6,161,0,87,0,2,0,100,1,4,0,4,0,131,3,1, - 0,83,0,49,0,115,58,48,0,1,0,1,0,1,0,89, - 0,1,0,110,52,116,3,160,7,124,1,100,2,161,2,143, - 24,125,2,124,2,160,6,161,0,87,0,2,0,100,1,4, - 0,4,0,131,3,1,0,83,0,49,0,115,112,48,0,1, - 0,1,0,1,0,89,0,1,0,100,1,83,0,41,3,122, - 39,82,101,116,117,114,110,32,116,104,101,32,100,97,116,97, - 32,102,114,111,109,32,112,97,116,104,32,97,115,32,114,97, - 119,32,98,121,116,101,115,46,78,218,1,114,41,8,114,161, - 0,0,0,114,221,0,0,0,218,19,69,120,116,101,110,115, - 105,111,110,70,105,108,101,76,111,97,100,101,114,114,64,0, - 0,0,90,9,111,112,101,110,95,99,111,100,101,114,84,0, - 0,0,90,4,114,101,97,100,114,65,0,0,0,41,3,114, - 118,0,0,0,114,44,0,0,0,114,68,0,0,0,114,5, - 0,0,0,114,5,0,0,0,114,8,0,0,0,114,227,0, - 0,0,208,3,0,0,115,10,0,0,0,0,2,14,1,16, - 1,40,2,14,1,122,19,70,105,108,101,76,111,97,100,101, - 114,46,103,101,116,95,100,97,116,97,99,2,0,0,0,0, - 0,0,0,0,0,0,0,2,0,0,0,3,0,0,0,67, - 0,0,0,115,18,0,0,0,124,0,160,0,124,1,161,1, - 114,14,124,0,83,0,100,0,83,0,114,109,0,0,0,41, - 1,114,182,0,0,0,169,2,114,118,0,0,0,114,216,0, - 0,0,114,5,0,0,0,114,5,0,0,0,114,8,0,0, - 0,218,19,103,101,116,95,114,101,115,111,117,114,99,101,95, - 114,101,97,100,101,114,219,3,0,0,115,6,0,0,0,0, - 2,10,1,4,1,122,30,70,105,108,101,76,111,97,100,101, - 114,46,103,101,116,95,114,101,115,111,117,114,99,101,95,114, - 101,97,100,101,114,99,2,0,0,0,0,0,0,0,0,0, - 0,0,3,0,0,0,4,0,0,0,67,0,0,0,115,32, - 0,0,0,116,0,116,1,124,0,106,2,131,1,100,1,25, - 0,124,1,131,2,125,2,116,3,160,4,124,2,100,2,161, - 2,83,0,41,3,78,114,73,0,0,0,114,251,0,0,0, - 41,5,114,38,0,0,0,114,47,0,0,0,114,44,0,0, - 0,114,64,0,0,0,114,65,0,0,0,169,3,114,118,0, - 0,0,90,8,114,101,115,111,117,114,99,101,114,44,0,0, - 0,114,5,0,0,0,114,5,0,0,0,114,8,0,0,0, - 218,13,111,112,101,110,95,114,101,115,111,117,114,99,101,225, - 3,0,0,115,4,0,0,0,0,1,20,1,122,24,70,105, - 108,101,76,111,97,100,101,114,46,111,112,101,110,95,114,101, - 115,111,117,114,99,101,99,2,0,0,0,0,0,0,0,0, - 0,0,0,3,0,0,0,3,0,0,0,67,0,0,0,115, - 38,0,0,0,124,0,160,0,124,1,161,1,115,14,116,1, - 130,1,116,2,116,3,124,0,106,4,131,1,100,1,25,0, - 124,1,131,2,125,2,124,2,83,0,169,2,78,114,73,0, - 0,0,41,5,218,11,105,115,95,114,101,115,111,117,114,99, - 101,218,17,70,105,108,101,78,111,116,70,111,117,110,100,69, - 114,114,111,114,114,38,0,0,0,114,47,0,0,0,114,44, - 0,0,0,114,255,0,0,0,114,5,0,0,0,114,5,0, - 0,0,114,8,0,0,0,218,13,114,101,115,111,117,114,99, - 101,95,112,97,116,104,229,3,0,0,115,8,0,0,0,0, - 1,10,1,4,1,20,1,122,24,70,105,108,101,76,111,97, - 100,101,114,46,114,101,115,111,117,114,99,101,95,112,97,116, - 104,99,2,0,0,0,0,0,0,0,0,0,0,0,3,0, - 0,0,3,0,0,0,67,0,0,0,115,40,0,0,0,116, - 0,124,1,118,0,114,12,100,1,83,0,116,1,116,2,124, - 0,106,3,131,1,100,2,25,0,124,1,131,2,125,2,116, - 4,124,2,131,1,83,0,41,3,78,70,114,73,0,0,0, - 41,5,114,35,0,0,0,114,38,0,0,0,114,47,0,0, - 0,114,44,0,0,0,114,54,0,0,0,169,3,114,118,0, - 0,0,114,116,0,0,0,114,44,0,0,0,114,5,0,0, - 0,114,5,0,0,0,114,8,0,0,0,114,2,1,0,0, - 235,3,0,0,115,8,0,0,0,0,1,8,1,4,1,20, - 1,122,22,70,105,108,101,76,111,97,100,101,114,46,105,115, - 95,114,101,115,111,117,114,99,101,99,1,0,0,0,0,0, - 0,0,0,0,0,0,1,0,0,0,5,0,0,0,67,0, - 0,0,115,24,0,0,0,116,0,116,1,160,2,116,3,124, - 0,106,4,131,1,100,1,25,0,161,1,131,1,83,0,114, - 1,1,0,0,41,5,218,4,105,116,101,114,114,4,0,0, - 0,218,7,108,105,115,116,100,105,114,114,47,0,0,0,114, - 44,0,0,0,114,246,0,0,0,114,5,0,0,0,114,5, - 0,0,0,114,8,0,0,0,218,8,99,111,110,116,101,110, - 116,115,241,3,0,0,115,2,0,0,0,0,1,122,19,70, - 105,108,101,76,111,97,100,101,114,46,99,111,110,116,101,110, - 116,115,41,17,114,125,0,0,0,114,124,0,0,0,114,126, - 0,0,0,114,127,0,0,0,114,209,0,0,0,114,243,0, - 0,0,114,247,0,0,0,114,136,0,0,0,114,220,0,0, - 0,114,179,0,0,0,114,227,0,0,0,114,254,0,0,0, - 114,0,1,0,0,114,4,1,0,0,114,2,1,0,0,114, - 8,1,0,0,90,13,95,95,99,108,97,115,115,99,101,108, - 108,95,95,114,5,0,0,0,114,5,0,0,0,114,249,0, - 0,0,114,8,0,0,0,114,239,0,0,0,173,3,0,0, - 115,30,0,0,0,8,2,4,3,8,6,8,4,8,3,2, - 1,14,11,2,1,10,4,8,11,2,1,10,5,8,4,8, - 6,8,6,114,239,0,0,0,99,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,3,0,0,0,64,0,0, - 0,115,46,0,0,0,101,0,90,1,100,0,90,2,100,1, - 90,3,100,2,100,3,132,0,90,4,100,4,100,5,132,0, - 90,5,100,6,100,7,156,1,100,8,100,9,132,2,90,6, - 100,10,83,0,41,11,218,16,83,111,117,114,99,101,70,105, - 108,101,76,111,97,100,101,114,122,62,67,111,110,99,114,101, - 116,101,32,105,109,112,108,101,109,101,110,116,97,116,105,111, - 110,32,111,102,32,83,111,117,114,99,101,76,111,97,100,101, - 114,32,117,115,105,110,103,32,116,104,101,32,102,105,108,101, - 32,115,121,115,116,101,109,46,99,2,0,0,0,0,0,0, - 0,0,0,0,0,3,0,0,0,3,0,0,0,67,0,0, - 0,115,22,0,0,0,116,0,124,1,131,1,125,2,124,2, - 106,1,124,2,106,2,100,1,156,2,83,0,41,2,122,33, - 82,101,116,117,114,110,32,116,104,101,32,109,101,116,97,100, - 97,116,97,32,102,111,114,32,116,104,101,32,112,97,116,104, - 46,41,2,114,169,0,0,0,114,234,0,0,0,41,3,114, - 49,0,0,0,218,8,115,116,95,109,116,105,109,101,90,7, - 115,116,95,115,105,122,101,41,3,114,118,0,0,0,114,44, - 0,0,0,114,238,0,0,0,114,5,0,0,0,114,5,0, - 0,0,114,8,0,0,0,114,224,0,0,0,249,3,0,0, - 115,4,0,0,0,0,2,8,1,122,27,83,111,117,114,99, - 101,70,105,108,101,76,111,97,100,101,114,46,112,97,116,104, - 95,115,116,97,116,115,99,4,0,0,0,0,0,0,0,0, - 0,0,0,5,0,0,0,5,0,0,0,67,0,0,0,115, - 24,0,0,0,116,0,124,1,131,1,125,4,124,0,106,1, - 124,2,124,3,124,4,100,1,141,3,83,0,41,2,78,169, - 1,218,5,95,109,111,100,101,41,2,114,114,0,0,0,114, - 225,0,0,0,41,5,114,118,0,0,0,114,107,0,0,0, - 114,106,0,0,0,114,26,0,0,0,114,52,0,0,0,114, - 5,0,0,0,114,5,0,0,0,114,8,0,0,0,114,226, - 0,0,0,254,3,0,0,115,4,0,0,0,0,2,8,1, - 122,32,83,111,117,114,99,101,70,105,108,101,76,111,97,100, - 101,114,46,95,99,97,99,104,101,95,98,121,116,101,99,111, - 100,101,114,60,0,0,0,114,11,1,0,0,99,3,0,0, - 0,0,0,0,0,1,0,0,0,9,0,0,0,11,0,0, - 0,67,0,0,0,115,252,0,0,0,116,0,124,1,131,1, - 92,2,125,4,125,5,103,0,125,6,124,4,114,52,116,1, - 124,4,131,1,115,52,116,0,124,4,131,1,92,2,125,4, - 125,7,124,6,160,2,124,7,161,1,1,0,113,16,116,3, - 124,6,131,1,68,0,93,104,125,7,116,4,124,4,124,7, - 131,2,125,4,122,14,116,5,160,6,124,4,161,1,1,0, - 87,0,113,60,4,0,116,7,121,110,1,0,1,0,1,0, - 89,0,113,60,89,0,113,60,4,0,116,8,121,162,1,0, - 125,8,1,0,122,30,116,9,160,10,100,1,124,4,124,8, - 161,3,1,0,87,0,89,0,100,2,125,8,126,8,1,0, - 100,2,83,0,100,2,125,8,126,8,48,0,48,0,113,60, - 122,28,116,11,124,1,124,2,124,3,131,3,1,0,116,9, - 160,10,100,3,124,1,161,2,1,0,87,0,110,52,4,0, - 116,8,144,0,121,246,1,0,125,8,1,0,122,26,116,9, - 160,10,100,1,124,1,124,8,161,3,1,0,87,0,89,0, - 100,2,125,8,126,8,110,10,100,2,125,8,126,8,48,0, - 48,0,100,2,83,0,41,4,122,27,87,114,105,116,101,32, - 98,121,116,101,115,32,100,97,116,97,32,116,111,32,97,32, - 102,105,108,101,46,122,27,99,111,117,108,100,32,110,111,116, - 32,99,114,101,97,116,101,32,123,33,114,125,58,32,123,33, - 114,125,78,122,12,99,114,101,97,116,101,100,32,123,33,114, - 125,41,12,114,47,0,0,0,114,56,0,0,0,114,186,0, - 0,0,114,42,0,0,0,114,38,0,0,0,114,4,0,0, - 0,90,5,109,107,100,105,114,218,15,70,105,108,101,69,120, - 105,115,116,115,69,114,114,111,114,114,50,0,0,0,114,134, - 0,0,0,114,149,0,0,0,114,69,0,0,0,41,9,114, - 118,0,0,0,114,44,0,0,0,114,26,0,0,0,114,12, - 1,0,0,218,6,112,97,114,101,110,116,114,96,0,0,0, - 114,37,0,0,0,114,33,0,0,0,114,228,0,0,0,114, - 5,0,0,0,114,5,0,0,0,114,8,0,0,0,114,225, - 0,0,0,3,4,0,0,115,46,0,0,0,0,2,12,1, - 4,2,12,1,12,1,12,2,12,1,10,1,2,1,14,1, - 12,2,8,1,14,3,6,1,4,255,4,2,28,1,2,1, - 12,1,16,1,16,2,8,1,2,255,122,25,83,111,117,114, - 99,101,70,105,108,101,76,111,97,100,101,114,46,115,101,116, - 95,100,97,116,97,78,41,7,114,125,0,0,0,114,124,0, - 0,0,114,126,0,0,0,114,127,0,0,0,114,224,0,0, - 0,114,226,0,0,0,114,225,0,0,0,114,5,0,0,0, - 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,114, - 9,1,0,0,245,3,0,0,115,8,0,0,0,8,2,4, - 2,8,5,8,5,114,9,1,0,0,99,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,64, - 0,0,0,115,32,0,0,0,101,0,90,1,100,0,90,2, - 100,1,90,3,100,2,100,3,132,0,90,4,100,4,100,5, - 132,0,90,5,100,6,83,0,41,7,218,20,83,111,117,114, - 99,101,108,101,115,115,70,105,108,101,76,111,97,100,101,114, - 122,45,76,111,97,100,101,114,32,119,104,105,99,104,32,104, - 97,110,100,108,101,115,32,115,111,117,114,99,101,108,101,115, - 115,32,102,105,108,101,32,105,109,112,111,114,116,115,46,99, - 2,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0, - 5,0,0,0,67,0,0,0,115,68,0,0,0,124,0,160, - 0,124,1,161,1,125,2,124,0,160,1,124,2,161,1,125, - 3,124,1,124,2,100,1,156,2,125,4,116,2,124,3,124, - 1,124,4,131,3,1,0,116,3,116,4,124,3,131,1,100, - 2,100,0,133,2,25,0,124,1,124,2,100,3,141,3,83, - 0,41,4,78,114,159,0,0,0,114,145,0,0,0,41,2, - 114,116,0,0,0,114,106,0,0,0,41,5,114,179,0,0, - 0,114,227,0,0,0,114,152,0,0,0,114,165,0,0,0, - 114,235,0,0,0,41,5,114,118,0,0,0,114,139,0,0, - 0,114,44,0,0,0,114,26,0,0,0,114,151,0,0,0, - 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,114, - 213,0,0,0,38,4,0,0,115,22,0,0,0,0,1,10, - 1,10,4,2,1,2,254,6,4,12,1,2,1,14,1,2, - 1,2,253,122,29,83,111,117,114,99,101,108,101,115,115,70, - 105,108,101,76,111,97,100,101,114,46,103,101,116,95,99,111, - 100,101,99,2,0,0,0,0,0,0,0,0,0,0,0,2, - 0,0,0,1,0,0,0,67,0,0,0,115,4,0,0,0, - 100,1,83,0,41,2,122,39,82,101,116,117,114,110,32,78, - 111,110,101,32,97,115,32,116,104,101,114,101,32,105,115,32, - 110,111,32,115,111,117,114,99,101,32,99,111,100,101,46,78, - 114,5,0,0,0,114,219,0,0,0,114,5,0,0,0,114, - 5,0,0,0,114,8,0,0,0,114,229,0,0,0,54,4, - 0,0,115,2,0,0,0,0,2,122,31,83,111,117,114,99, - 101,108,101,115,115,70,105,108,101,76,111,97,100,101,114,46, - 103,101,116,95,115,111,117,114,99,101,78,41,6,114,125,0, - 0,0,114,124,0,0,0,114,126,0,0,0,114,127,0,0, - 0,114,213,0,0,0,114,229,0,0,0,114,5,0,0,0, - 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,114, - 15,1,0,0,34,4,0,0,115,6,0,0,0,8,2,4, - 2,8,16,114,15,1,0,0,99,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,3,0,0,0,64,0,0, - 0,115,92,0,0,0,101,0,90,1,100,0,90,2,100,1, - 90,3,100,2,100,3,132,0,90,4,100,4,100,5,132,0, - 90,5,100,6,100,7,132,0,90,6,100,8,100,9,132,0, - 90,7,100,10,100,11,132,0,90,8,100,12,100,13,132,0, - 90,9,100,14,100,15,132,0,90,10,100,16,100,17,132,0, - 90,11,101,12,100,18,100,19,132,0,131,1,90,13,100,20, - 83,0,41,21,114,252,0,0,0,122,93,76,111,97,100,101, - 114,32,102,111,114,32,101,120,116,101,110,115,105,111,110,32, - 109,111,100,117,108,101,115,46,10,10,32,32,32,32,84,104, - 101,32,99,111,110,115,116,114,117,99,116,111,114,32,105,115, - 32,100,101,115,105,103,110,101,100,32,116,111,32,119,111,114, - 107,32,119,105,116,104,32,70,105,108,101,70,105,110,100,101, - 114,46,10,10,32,32,32,32,99,3,0,0,0,0,0,0, - 0,0,0,0,0,3,0,0,0,2,0,0,0,67,0,0, - 0,115,16,0,0,0,124,1,124,0,95,0,124,2,124,0, - 95,1,100,0,83,0,114,109,0,0,0,114,159,0,0,0, - 114,5,1,0,0,114,5,0,0,0,114,5,0,0,0,114, - 8,0,0,0,114,209,0,0,0,71,4,0,0,115,4,0, - 0,0,0,1,6,1,122,28,69,120,116,101,110,115,105,111, - 110,70,105,108,101,76,111,97,100,101,114,46,95,95,105,110, - 105,116,95,95,99,2,0,0,0,0,0,0,0,0,0,0, - 0,2,0,0,0,2,0,0,0,67,0,0,0,115,24,0, - 0,0,124,0,106,0,124,1,106,0,107,2,111,22,124,0, - 106,1,124,1,106,1,107,2,83,0,114,109,0,0,0,114, - 240,0,0,0,114,242,0,0,0,114,5,0,0,0,114,5, - 0,0,0,114,8,0,0,0,114,243,0,0,0,75,4,0, - 0,115,6,0,0,0,0,1,12,1,10,255,122,26,69,120, - 116,101,110,115,105,111,110,70,105,108,101,76,111,97,100,101, - 114,46,95,95,101,113,95,95,99,1,0,0,0,0,0,0, - 0,0,0,0,0,1,0,0,0,3,0,0,0,67,0,0, - 0,115,20,0,0,0,116,0,124,0,106,1,131,1,116,0, - 124,0,106,2,131,1,65,0,83,0,114,109,0,0,0,114, - 244,0,0,0,114,246,0,0,0,114,5,0,0,0,114,5, - 0,0,0,114,8,0,0,0,114,247,0,0,0,79,4,0, - 0,115,2,0,0,0,0,1,122,28,69,120,116,101,110,115, - 105,111,110,70,105,108,101,76,111,97,100,101,114,46,95,95, - 104,97,115,104,95,95,99,2,0,0,0,0,0,0,0,0, - 0,0,0,3,0,0,0,5,0,0,0,67,0,0,0,115, - 36,0,0,0,116,0,160,1,116,2,106,3,124,1,161,2, - 125,2,116,0,160,4,100,1,124,1,106,5,124,0,106,6, - 161,3,1,0,124,2,83,0,41,2,122,38,67,114,101,97, - 116,101,32,97,110,32,117,110,105,116,105,97,108,105,122,101, - 100,32,101,120,116,101,110,115,105,111,110,32,109,111,100,117, - 108,101,122,38,101,120,116,101,110,115,105,111,110,32,109,111, - 100,117,108,101,32,123,33,114,125,32,108,111,97,100,101,100, - 32,102,114,111,109,32,123,33,114,125,41,7,114,134,0,0, - 0,114,214,0,0,0,114,163,0,0,0,90,14,99,114,101, - 97,116,101,95,100,121,110,97,109,105,99,114,149,0,0,0, - 114,116,0,0,0,114,44,0,0,0,41,3,114,118,0,0, - 0,114,187,0,0,0,114,216,0,0,0,114,5,0,0,0, - 114,5,0,0,0,114,8,0,0,0,114,212,0,0,0,82, - 4,0,0,115,14,0,0,0,0,2,4,1,6,255,4,2, - 6,1,8,255,4,2,122,33,69,120,116,101,110,115,105,111, - 110,70,105,108,101,76,111,97,100,101,114,46,99,114,101,97, - 116,101,95,109,111,100,117,108,101,99,2,0,0,0,0,0, - 0,0,0,0,0,0,2,0,0,0,5,0,0,0,67,0, - 0,0,115,36,0,0,0,116,0,160,1,116,2,106,3,124, - 1,161,2,1,0,116,0,160,4,100,1,124,0,106,5,124, - 0,106,6,161,3,1,0,100,2,83,0,41,3,122,30,73, - 110,105,116,105,97,108,105,122,101,32,97,110,32,101,120,116, - 101,110,115,105,111,110,32,109,111,100,117,108,101,122,40,101, - 120,116,101,110,115,105,111,110,32,109,111,100,117,108,101,32, - 123,33,114,125,32,101,120,101,99,117,116,101,100,32,102,114, - 111,109,32,123,33,114,125,78,41,7,114,134,0,0,0,114, - 214,0,0,0,114,163,0,0,0,90,12,101,120,101,99,95, - 100,121,110,97,109,105,99,114,149,0,0,0,114,116,0,0, - 0,114,44,0,0,0,114,253,0,0,0,114,5,0,0,0, - 114,5,0,0,0,114,8,0,0,0,114,217,0,0,0,90, - 4,0,0,115,8,0,0,0,0,2,14,1,6,1,8,255, - 122,31,69,120,116,101,110,115,105,111,110,70,105,108,101,76, - 111,97,100,101,114,46,101,120,101,99,95,109,111,100,117,108, - 101,99,2,0,0,0,0,0,0,0,0,0,0,0,2,0, - 0,0,4,0,0,0,3,0,0,0,115,36,0,0,0,116, - 0,124,0,106,1,131,1,100,1,25,0,137,0,116,2,135, - 0,102,1,100,2,100,3,132,8,116,3,68,0,131,1,131, - 1,83,0,41,4,122,49,82,101,116,117,114,110,32,84,114, - 117,101,32,105,102,32,116,104,101,32,101,120,116,101,110,115, - 105,111,110,32,109,111,100,117,108,101,32,105,115,32,97,32, - 112,97,99,107,97,103,101,46,114,39,0,0,0,99,1,0, - 0,0,0,0,0,0,0,0,0,0,2,0,0,0,4,0, - 0,0,51,0,0,0,115,26,0,0,0,124,0,93,18,125, - 1,136,0,100,0,124,1,23,0,107,2,86,0,1,0,113, - 2,100,1,83,0,41,2,114,209,0,0,0,78,114,5,0, - 0,0,169,2,114,32,0,0,0,218,6,115,117,102,102,105, - 120,169,1,90,9,102,105,108,101,95,110,97,109,101,114,5, - 0,0,0,114,8,0,0,0,218,9,60,103,101,110,101,120, - 112,114,62,99,4,0,0,115,4,0,0,0,4,1,2,255, - 122,49,69,120,116,101,110,115,105,111,110,70,105,108,101,76, - 111,97,100,101,114,46,105,115,95,112,97,99,107,97,103,101, - 46,60,108,111,99,97,108,115,62,46,60,103,101,110,101,120, - 112,114,62,41,4,114,47,0,0,0,114,44,0,0,0,218, - 3,97,110,121,218,18,69,88,84,69,78,83,73,79,78,95, - 83,85,70,70,73,88,69,83,114,219,0,0,0,114,5,0, - 0,0,114,18,1,0,0,114,8,0,0,0,114,182,0,0, - 0,96,4,0,0,115,8,0,0,0,0,2,14,1,12,1, - 2,255,122,30,69,120,116,101,110,115,105,111,110,70,105,108, - 101,76,111,97,100,101,114,46,105,115,95,112,97,99,107,97, - 103,101,99,2,0,0,0,0,0,0,0,0,0,0,0,2, - 0,0,0,1,0,0,0,67,0,0,0,115,4,0,0,0, - 100,1,83,0,41,2,122,63,82,101,116,117,114,110,32,78, - 111,110,101,32,97,115,32,97,110,32,101,120,116,101,110,115, - 105,111,110,32,109,111,100,117,108,101,32,99,97,110,110,111, - 116,32,99,114,101,97,116,101,32,97,32,99,111,100,101,32, - 111,98,106,101,99,116,46,78,114,5,0,0,0,114,219,0, - 0,0,114,5,0,0,0,114,5,0,0,0,114,8,0,0, - 0,114,213,0,0,0,102,4,0,0,115,2,0,0,0,0, - 2,122,28,69,120,116,101,110,115,105,111,110,70,105,108,101, - 76,111,97,100,101,114,46,103,101,116,95,99,111,100,101,99, - 2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, - 1,0,0,0,67,0,0,0,115,4,0,0,0,100,1,83, - 0,41,2,122,53,82,101,116,117,114,110,32,78,111,110,101, - 32,97,115,32,101,120,116,101,110,115,105,111,110,32,109,111, - 100,117,108,101,115,32,104,97,118,101,32,110,111,32,115,111, - 117,114,99,101,32,99,111,100,101,46,78,114,5,0,0,0, - 114,219,0,0,0,114,5,0,0,0,114,5,0,0,0,114, - 8,0,0,0,114,229,0,0,0,106,4,0,0,115,2,0, - 0,0,0,2,122,30,69,120,116,101,110,115,105,111,110,70, - 105,108,101,76,111,97,100,101,114,46,103,101,116,95,115,111, - 117,114,99,101,99,2,0,0,0,0,0,0,0,0,0,0, - 0,2,0,0,0,1,0,0,0,67,0,0,0,115,6,0, - 0,0,124,0,106,0,83,0,114,250,0,0,0,114,48,0, - 0,0,114,219,0,0,0,114,5,0,0,0,114,5,0,0, - 0,114,8,0,0,0,114,179,0,0,0,110,4,0,0,115, - 2,0,0,0,0,3,122,32,69,120,116,101,110,115,105,111, - 110,70,105,108,101,76,111,97,100,101,114,46,103,101,116,95, - 102,105,108,101,110,97,109,101,78,41,14,114,125,0,0,0, - 114,124,0,0,0,114,126,0,0,0,114,127,0,0,0,114, - 209,0,0,0,114,243,0,0,0,114,247,0,0,0,114,212, - 0,0,0,114,217,0,0,0,114,182,0,0,0,114,213,0, - 0,0,114,229,0,0,0,114,136,0,0,0,114,179,0,0, - 0,114,5,0,0,0,114,5,0,0,0,114,5,0,0,0, - 114,8,0,0,0,114,252,0,0,0,63,4,0,0,115,22, - 0,0,0,8,2,4,6,8,4,8,4,8,3,8,8,8, - 6,8,6,8,4,8,4,2,1,114,252,0,0,0,99,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2, - 0,0,0,64,0,0,0,115,104,0,0,0,101,0,90,1, - 100,0,90,2,100,1,90,3,100,2,100,3,132,0,90,4, - 100,4,100,5,132,0,90,5,100,6,100,7,132,0,90,6, - 100,8,100,9,132,0,90,7,100,10,100,11,132,0,90,8, - 100,12,100,13,132,0,90,9,100,14,100,15,132,0,90,10, - 100,16,100,17,132,0,90,11,100,18,100,19,132,0,90,12, - 100,20,100,21,132,0,90,13,100,22,100,23,132,0,90,14, - 100,24,83,0,41,25,218,14,95,78,97,109,101,115,112,97, - 99,101,80,97,116,104,97,38,1,0,0,82,101,112,114,101, - 115,101,110,116,115,32,97,32,110,97,109,101,115,112,97,99, - 101,32,112,97,99,107,97,103,101,39,115,32,112,97,116,104, - 46,32,32,73,116,32,117,115,101,115,32,116,104,101,32,109, - 111,100,117,108,101,32,110,97,109,101,10,32,32,32,32,116, - 111,32,102,105,110,100,32,105,116,115,32,112,97,114,101,110, - 116,32,109,111,100,117,108,101,44,32,97,110,100,32,102,114, - 111,109,32,116,104,101,114,101,32,105,116,32,108,111,111,107, - 115,32,117,112,32,116,104,101,32,112,97,114,101,110,116,39, - 115,10,32,32,32,32,95,95,112,97,116,104,95,95,46,32, - 32,87,104,101,110,32,116,104,105,115,32,99,104,97,110,103, - 101,115,44,32,116,104,101,32,109,111,100,117,108,101,39,115, - 32,111,119,110,32,112,97,116,104,32,105,115,32,114,101,99, - 111,109,112,117,116,101,100,44,10,32,32,32,32,117,115,105, - 110,103,32,112,97,116,104,95,102,105,110,100,101,114,46,32, - 32,70,111,114,32,116,111,112,45,108,101,118,101,108,32,109, - 111,100,117,108,101,115,44,32,116,104,101,32,112,97,114,101, - 110,116,32,109,111,100,117,108,101,39,115,32,112,97,116,104, - 10,32,32,32,32,105,115,32,115,121,115,46,112,97,116,104, - 46,99,4,0,0,0,0,0,0,0,0,0,0,0,4,0, - 0,0,3,0,0,0,67,0,0,0,115,36,0,0,0,124, - 1,124,0,95,0,124,2,124,0,95,1,116,2,124,0,160, - 3,161,0,131,1,124,0,95,4,124,3,124,0,95,5,100, - 0,83,0,114,109,0,0,0,41,6,218,5,95,110,97,109, - 101,218,5,95,112,97,116,104,114,111,0,0,0,218,16,95, - 103,101,116,95,112,97,114,101,110,116,95,112,97,116,104,218, - 17,95,108,97,115,116,95,112,97,114,101,110,116,95,112,97, - 116,104,218,12,95,112,97,116,104,95,102,105,110,100,101,114, - 169,4,114,118,0,0,0,114,116,0,0,0,114,44,0,0, - 0,90,11,112,97,116,104,95,102,105,110,100,101,114,114,5, - 0,0,0,114,5,0,0,0,114,8,0,0,0,114,209,0, - 0,0,123,4,0,0,115,8,0,0,0,0,1,6,1,6, - 1,14,1,122,23,95,78,97,109,101,115,112,97,99,101,80, - 97,116,104,46,95,95,105,110,105,116,95,95,99,1,0,0, - 0,0,0,0,0,0,0,0,0,4,0,0,0,3,0,0, - 0,67,0,0,0,115,38,0,0,0,124,0,106,0,160,1, - 100,1,161,1,92,3,125,1,125,2,125,3,124,2,100,2, - 107,2,114,30,100,3,83,0,124,1,100,4,102,2,83,0, - 41,5,122,62,82,101,116,117,114,110,115,32,97,32,116,117, - 112,108,101,32,111,102,32,40,112,97,114,101,110,116,45,109, - 111,100,117,108,101,45,110,97,109,101,44,32,112,97,114,101, - 110,116,45,112,97,116,104,45,97,116,116,114,45,110,97,109, - 101,41,114,71,0,0,0,114,40,0,0,0,41,2,114,1, - 0,0,0,114,44,0,0,0,90,8,95,95,112,97,116,104, - 95,95,41,2,114,23,1,0,0,114,41,0,0,0,41,4, - 114,118,0,0,0,114,14,1,0,0,218,3,100,111,116,90, - 2,109,101,114,5,0,0,0,114,5,0,0,0,114,8,0, - 0,0,218,23,95,102,105,110,100,95,112,97,114,101,110,116, - 95,112,97,116,104,95,110,97,109,101,115,129,4,0,0,115, - 8,0,0,0,0,2,18,1,8,2,4,3,122,38,95,78, - 97,109,101,115,112,97,99,101,80,97,116,104,46,95,102,105, - 110,100,95,112,97,114,101,110,116,95,112,97,116,104,95,110, - 97,109,101,115,99,1,0,0,0,0,0,0,0,0,0,0, - 0,3,0,0,0,3,0,0,0,67,0,0,0,115,28,0, - 0,0,124,0,160,0,161,0,92,2,125,1,125,2,116,1, - 116,2,106,3,124,1,25,0,124,2,131,2,83,0,114,109, - 0,0,0,41,4,114,30,1,0,0,114,130,0,0,0,114, - 1,0,0,0,218,7,109,111,100,117,108,101,115,41,3,114, - 118,0,0,0,90,18,112,97,114,101,110,116,95,109,111,100, - 117,108,101,95,110,97,109,101,90,14,112,97,116,104,95,97, - 116,116,114,95,110,97,109,101,114,5,0,0,0,114,5,0, - 0,0,114,8,0,0,0,114,25,1,0,0,139,4,0,0, - 115,4,0,0,0,0,1,12,1,122,31,95,78,97,109,101, - 115,112,97,99,101,80,97,116,104,46,95,103,101,116,95,112, - 97,114,101,110,116,95,112,97,116,104,99,1,0,0,0,0, - 0,0,0,0,0,0,0,3,0,0,0,4,0,0,0,67, - 0,0,0,115,80,0,0,0,116,0,124,0,160,1,161,0, - 131,1,125,1,124,1,124,0,106,2,107,3,114,74,124,0, - 160,3,124,0,106,4,124,1,161,2,125,2,124,2,100,0, - 117,1,114,68,124,2,106,5,100,0,117,0,114,68,124,2, - 106,6,114,68,124,2,106,6,124,0,95,7,124,1,124,0, - 95,2,124,0,106,7,83,0,114,109,0,0,0,41,8,114, - 111,0,0,0,114,25,1,0,0,114,26,1,0,0,114,27, - 1,0,0,114,23,1,0,0,114,140,0,0,0,114,178,0, - 0,0,114,24,1,0,0,41,3,114,118,0,0,0,90,11, - 112,97,114,101,110,116,95,112,97,116,104,114,187,0,0,0, - 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,218, - 12,95,114,101,99,97,108,99,117,108,97,116,101,143,4,0, - 0,115,16,0,0,0,0,2,12,1,10,1,14,3,18,1, - 6,1,8,1,6,1,122,27,95,78,97,109,101,115,112,97, - 99,101,80,97,116,104,46,95,114,101,99,97,108,99,117,108, - 97,116,101,99,1,0,0,0,0,0,0,0,0,0,0,0, - 1,0,0,0,3,0,0,0,67,0,0,0,115,12,0,0, - 0,116,0,124,0,160,1,161,0,131,1,83,0,114,109,0, - 0,0,41,2,114,6,1,0,0,114,32,1,0,0,114,246, - 0,0,0,114,5,0,0,0,114,5,0,0,0,114,8,0, - 0,0,218,8,95,95,105,116,101,114,95,95,156,4,0,0, - 115,2,0,0,0,0,1,122,23,95,78,97,109,101,115,112, - 97,99,101,80,97,116,104,46,95,95,105,116,101,114,95,95, - 99,2,0,0,0,0,0,0,0,0,0,0,0,2,0,0, - 0,2,0,0,0,67,0,0,0,115,12,0,0,0,124,0, - 160,0,161,0,124,1,25,0,83,0,114,109,0,0,0,169, - 1,114,32,1,0,0,41,2,114,118,0,0,0,218,5,105, - 110,100,101,120,114,5,0,0,0,114,5,0,0,0,114,8, - 0,0,0,218,11,95,95,103,101,116,105,116,101,109,95,95, - 159,4,0,0,115,2,0,0,0,0,1,122,26,95,78,97, - 109,101,115,112,97,99,101,80,97,116,104,46,95,95,103,101, - 116,105,116,101,109,95,95,99,3,0,0,0,0,0,0,0, - 0,0,0,0,3,0,0,0,3,0,0,0,67,0,0,0, - 115,14,0,0,0,124,2,124,0,106,0,124,1,60,0,100, - 0,83,0,114,109,0,0,0,41,1,114,24,1,0,0,41, - 3,114,118,0,0,0,114,35,1,0,0,114,44,0,0,0, - 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,218, - 11,95,95,115,101,116,105,116,101,109,95,95,162,4,0,0, - 115,2,0,0,0,0,1,122,26,95,78,97,109,101,115,112, - 97,99,101,80,97,116,104,46,95,95,115,101,116,105,116,101, - 109,95,95,99,1,0,0,0,0,0,0,0,0,0,0,0, - 1,0,0,0,3,0,0,0,67,0,0,0,115,12,0,0, - 0,116,0,124,0,160,1,161,0,131,1,83,0,114,109,0, - 0,0,41,2,114,23,0,0,0,114,32,1,0,0,114,246, - 0,0,0,114,5,0,0,0,114,5,0,0,0,114,8,0, - 0,0,218,7,95,95,108,101,110,95,95,165,4,0,0,115, - 2,0,0,0,0,1,122,22,95,78,97,109,101,115,112,97, - 99,101,80,97,116,104,46,95,95,108,101,110,95,95,99,1, - 0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,3, - 0,0,0,67,0,0,0,115,12,0,0,0,100,1,160,0, - 124,0,106,1,161,1,83,0,41,2,78,122,20,95,78,97, - 109,101,115,112,97,99,101,80,97,116,104,40,123,33,114,125, - 41,41,2,114,62,0,0,0,114,24,1,0,0,114,246,0, - 0,0,114,5,0,0,0,114,5,0,0,0,114,8,0,0, - 0,218,8,95,95,114,101,112,114,95,95,168,4,0,0,115, - 2,0,0,0,0,1,122,23,95,78,97,109,101,115,112,97, - 99,101,80,97,116,104,46,95,95,114,101,112,114,95,95,99, - 2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, - 3,0,0,0,67,0,0,0,115,12,0,0,0,124,1,124, - 0,160,0,161,0,118,0,83,0,114,109,0,0,0,114,34, - 1,0,0,169,2,114,118,0,0,0,218,4,105,116,101,109, - 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,218, - 12,95,95,99,111,110,116,97,105,110,115,95,95,171,4,0, - 0,115,2,0,0,0,0,1,122,27,95,78,97,109,101,115, - 112,97,99,101,80,97,116,104,46,95,95,99,111,110,116,97, - 105,110,115,95,95,99,2,0,0,0,0,0,0,0,0,0, - 0,0,2,0,0,0,3,0,0,0,67,0,0,0,115,16, - 0,0,0,124,0,106,0,160,1,124,1,161,1,1,0,100, - 0,83,0,114,109,0,0,0,41,2,114,24,1,0,0,114, - 186,0,0,0,114,40,1,0,0,114,5,0,0,0,114,5, - 0,0,0,114,8,0,0,0,114,186,0,0,0,174,4,0, - 0,115,2,0,0,0,0,1,122,21,95,78,97,109,101,115, - 112,97,99,101,80,97,116,104,46,97,112,112,101,110,100,78, - 41,15,114,125,0,0,0,114,124,0,0,0,114,126,0,0, - 0,114,127,0,0,0,114,209,0,0,0,114,30,1,0,0, - 114,25,1,0,0,114,32,1,0,0,114,33,1,0,0,114, - 36,1,0,0,114,37,1,0,0,114,38,1,0,0,114,39, - 1,0,0,114,42,1,0,0,114,186,0,0,0,114,5,0, - 0,0,114,5,0,0,0,114,5,0,0,0,114,8,0,0, - 0,114,22,1,0,0,116,4,0,0,115,24,0,0,0,8, - 1,4,6,8,6,8,10,8,4,8,13,8,3,8,3,8, - 3,8,3,8,3,8,3,114,22,1,0,0,99,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0, - 0,64,0,0,0,115,80,0,0,0,101,0,90,1,100,0, - 90,2,100,1,100,2,132,0,90,3,101,4,100,3,100,4, - 132,0,131,1,90,5,100,5,100,6,132,0,90,6,100,7, - 100,8,132,0,90,7,100,9,100,10,132,0,90,8,100,11, - 100,12,132,0,90,9,100,13,100,14,132,0,90,10,100,15, - 100,16,132,0,90,11,100,17,83,0,41,18,218,16,95,78, - 97,109,101,115,112,97,99,101,76,111,97,100,101,114,99,4, - 0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,4, - 0,0,0,67,0,0,0,115,18,0,0,0,116,0,124,1, - 124,2,124,3,131,3,124,0,95,1,100,0,83,0,114,109, - 0,0,0,41,2,114,22,1,0,0,114,24,1,0,0,114, - 28,1,0,0,114,5,0,0,0,114,5,0,0,0,114,8, - 0,0,0,114,209,0,0,0,180,4,0,0,115,2,0,0, - 0,0,1,122,25,95,78,97,109,101,115,112,97,99,101,76, - 111,97,100,101,114,46,95,95,105,110,105,116,95,95,99,2, - 0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,3, - 0,0,0,67,0,0,0,115,12,0,0,0,100,1,160,0, - 124,1,106,1,161,1,83,0,41,2,122,115,82,101,116,117, - 114,110,32,114,101,112,114,32,102,111,114,32,116,104,101,32, - 109,111,100,117,108,101,46,10,10,32,32,32,32,32,32,32, - 32,84,104,101,32,109,101,116,104,111,100,32,105,115,32,100, - 101,112,114,101,99,97,116,101,100,46,32,32,84,104,101,32, - 105,109,112,111,114,116,32,109,97,99,104,105,110,101,114,121, - 32,100,111,101,115,32,116,104,101,32,106,111,98,32,105,116, - 115,101,108,102,46,10,10,32,32,32,32,32,32,32,32,122, - 25,60,109,111,100,117,108,101,32,123,33,114,125,32,40,110, - 97,109,101,115,112,97,99,101,41,62,41,2,114,62,0,0, - 0,114,125,0,0,0,41,2,114,193,0,0,0,114,216,0, - 0,0,114,5,0,0,0,114,5,0,0,0,114,8,0,0, - 0,218,11,109,111,100,117,108,101,95,114,101,112,114,183,4, - 0,0,115,2,0,0,0,0,7,122,28,95,78,97,109,101, - 115,112,97,99,101,76,111,97,100,101,114,46,109,111,100,117, - 108,101,95,114,101,112,114,99,2,0,0,0,0,0,0,0, - 0,0,0,0,2,0,0,0,1,0,0,0,67,0,0,0, - 115,4,0,0,0,100,1,83,0,41,2,78,84,114,5,0, - 0,0,114,219,0,0,0,114,5,0,0,0,114,5,0,0, - 0,114,8,0,0,0,114,182,0,0,0,192,4,0,0,115, - 2,0,0,0,0,1,122,27,95,78,97,109,101,115,112,97, - 99,101,76,111,97,100,101,114,46,105,115,95,112,97,99,107, - 97,103,101,99,2,0,0,0,0,0,0,0,0,0,0,0, - 2,0,0,0,1,0,0,0,67,0,0,0,115,4,0,0, - 0,100,1,83,0,41,2,78,114,40,0,0,0,114,5,0, - 0,0,114,219,0,0,0,114,5,0,0,0,114,5,0,0, - 0,114,8,0,0,0,114,229,0,0,0,195,4,0,0,115, - 2,0,0,0,0,1,122,27,95,78,97,109,101,115,112,97, - 99,101,76,111,97,100,101,114,46,103,101,116,95,115,111,117, - 114,99,101,99,2,0,0,0,0,0,0,0,0,0,0,0, - 2,0,0,0,6,0,0,0,67,0,0,0,115,16,0,0, - 0,116,0,100,1,100,2,100,3,100,4,100,5,141,4,83, - 0,41,6,78,114,40,0,0,0,122,8,60,115,116,114,105, - 110,103,62,114,215,0,0,0,84,41,1,114,231,0,0,0, - 41,1,114,232,0,0,0,114,219,0,0,0,114,5,0,0, - 0,114,5,0,0,0,114,8,0,0,0,114,213,0,0,0, - 198,4,0,0,115,2,0,0,0,0,1,122,25,95,78,97, - 109,101,115,112,97,99,101,76,111,97,100,101,114,46,103,101, - 116,95,99,111,100,101,99,2,0,0,0,0,0,0,0,0, - 0,0,0,2,0,0,0,1,0,0,0,67,0,0,0,115, - 4,0,0,0,100,1,83,0,114,210,0,0,0,114,5,0, - 0,0,114,211,0,0,0,114,5,0,0,0,114,5,0,0, - 0,114,8,0,0,0,114,212,0,0,0,201,4,0,0,115, - 2,0,0,0,0,1,122,30,95,78,97,109,101,115,112,97, - 99,101,76,111,97,100,101,114,46,99,114,101,97,116,101,95, - 109,111,100,117,108,101,99,2,0,0,0,0,0,0,0,0, - 0,0,0,2,0,0,0,1,0,0,0,67,0,0,0,115, - 4,0,0,0,100,0,83,0,114,109,0,0,0,114,5,0, - 0,0,114,253,0,0,0,114,5,0,0,0,114,5,0,0, - 0,114,8,0,0,0,114,217,0,0,0,204,4,0,0,115, - 2,0,0,0,0,1,122,28,95,78,97,109,101,115,112,97, - 99,101,76,111,97,100,101,114,46,101,120,101,99,95,109,111, - 100,117,108,101,99,2,0,0,0,0,0,0,0,0,0,0, - 0,2,0,0,0,4,0,0,0,67,0,0,0,115,26,0, - 0,0,116,0,160,1,100,1,124,0,106,2,161,2,1,0, - 116,0,160,3,124,0,124,1,161,2,83,0,41,2,122,98, - 76,111,97,100,32,97,32,110,97,109,101,115,112,97,99,101, - 32,109,111,100,117,108,101,46,10,10,32,32,32,32,32,32, - 32,32,84,104,105,115,32,109,101,116,104,111,100,32,105,115, - 32,100,101,112,114,101,99,97,116,101,100,46,32,32,85,115, - 101,32,101,120,101,99,95,109,111,100,117,108,101,40,41,32, - 105,110,115,116,101,97,100,46,10,10,32,32,32,32,32,32, - 32,32,122,38,110,97,109,101,115,112,97,99,101,32,109,111, - 100,117,108,101,32,108,111,97,100,101,100,32,119,105,116,104, - 32,112,97,116,104,32,123,33,114,125,41,4,114,134,0,0, - 0,114,149,0,0,0,114,24,1,0,0,114,218,0,0,0, - 114,219,0,0,0,114,5,0,0,0,114,5,0,0,0,114, - 8,0,0,0,114,220,0,0,0,207,4,0,0,115,8,0, - 0,0,0,7,6,1,4,255,4,2,122,28,95,78,97,109, - 101,115,112,97,99,101,76,111,97,100,101,114,46,108,111,97, - 100,95,109,111,100,117,108,101,78,41,12,114,125,0,0,0, - 114,124,0,0,0,114,126,0,0,0,114,209,0,0,0,114, - 207,0,0,0,114,44,1,0,0,114,182,0,0,0,114,229, - 0,0,0,114,213,0,0,0,114,212,0,0,0,114,217,0, - 0,0,114,220,0,0,0,114,5,0,0,0,114,5,0,0, - 0,114,5,0,0,0,114,8,0,0,0,114,43,1,0,0, - 179,4,0,0,115,18,0,0,0,8,1,8,3,2,1,10, - 8,8,3,8,3,8,3,8,3,8,3,114,43,1,0,0, - 99,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,4,0,0,0,64,0,0,0,115,118,0,0,0,101,0, - 90,1,100,0,90,2,100,1,90,3,101,4,100,2,100,3, - 132,0,131,1,90,5,101,4,100,4,100,5,132,0,131,1, - 90,6,101,4,100,6,100,7,132,0,131,1,90,7,101,4, - 100,8,100,9,132,0,131,1,90,8,101,4,100,19,100,11, - 100,12,132,1,131,1,90,9,101,4,100,20,100,13,100,14, - 132,1,131,1,90,10,101,4,100,21,100,15,100,16,132,1, - 131,1,90,11,101,4,100,17,100,18,132,0,131,1,90,12, - 100,10,83,0,41,22,218,10,80,97,116,104,70,105,110,100, - 101,114,122,62,77,101,116,97,32,112,97,116,104,32,102,105, - 110,100,101,114,32,102,111,114,32,115,121,115,46,112,97,116, - 104,32,97,110,100,32,112,97,99,107,97,103,101,32,95,95, - 112,97,116,104,95,95,32,97,116,116,114,105,98,117,116,101, - 115,46,99,1,0,0,0,0,0,0,0,0,0,0,0,3, - 0,0,0,4,0,0,0,67,0,0,0,115,64,0,0,0, - 116,0,116,1,106,2,160,3,161,0,131,1,68,0,93,44, - 92,2,125,1,125,2,124,2,100,1,117,0,114,40,116,1, - 106,2,124,1,61,0,113,14,116,4,124,2,100,2,131,2, - 114,14,124,2,160,5,161,0,1,0,113,14,100,1,83,0, - 41,3,122,125,67,97,108,108,32,116,104,101,32,105,110,118, - 97,108,105,100,97,116,101,95,99,97,99,104,101,115,40,41, - 32,109,101,116,104,111,100,32,111,110,32,97,108,108,32,112, - 97,116,104,32,101,110,116,114,121,32,102,105,110,100,101,114, - 115,10,32,32,32,32,32,32,32,32,115,116,111,114,101,100, - 32,105,110,32,115,121,115,46,112,97,116,104,95,105,109,112, - 111,114,116,101,114,95,99,97,99,104,101,115,32,40,119,104, - 101,114,101,32,105,109,112,108,101,109,101,110,116,101,100,41, - 46,78,218,17,105,110,118,97,108,105,100,97,116,101,95,99, - 97,99,104,101,115,41,6,218,4,108,105,115,116,114,1,0, - 0,0,218,19,112,97,116,104,95,105,109,112,111,114,116,101, - 114,95,99,97,99,104,101,218,5,105,116,101,109,115,114,128, - 0,0,0,114,46,1,0,0,41,3,114,193,0,0,0,114, - 116,0,0,0,218,6,102,105,110,100,101,114,114,5,0,0, - 0,114,5,0,0,0,114,8,0,0,0,114,46,1,0,0, - 225,4,0,0,115,10,0,0,0,0,4,22,1,8,1,10, - 1,10,1,122,28,80,97,116,104,70,105,110,100,101,114,46, - 105,110,118,97,108,105,100,97,116,101,95,99,97,99,104,101, - 115,99,2,0,0,0,0,0,0,0,0,0,0,0,3,0, - 0,0,9,0,0,0,67,0,0,0,115,82,0,0,0,116, - 0,106,1,100,1,117,1,114,28,116,0,106,1,115,28,116, - 2,160,3,100,2,116,4,161,2,1,0,116,0,106,1,68, - 0,93,42,125,2,122,14,124,2,124,1,131,1,87,0,2, - 0,1,0,83,0,4,0,116,5,121,74,1,0,1,0,1, - 0,89,0,113,34,89,0,113,34,48,0,113,34,100,1,83, - 0,41,3,122,46,83,101,97,114,99,104,32,115,121,115,46, - 112,97,116,104,95,104,111,111,107,115,32,102,111,114,32,97, - 32,102,105,110,100,101,114,32,102,111,114,32,39,112,97,116, - 104,39,46,78,122,23,115,121,115,46,112,97,116,104,95,104, - 111,111,107,115,32,105,115,32,101,109,112,116,121,41,6,114, - 1,0,0,0,218,10,112,97,116,104,95,104,111,111,107,115, - 114,75,0,0,0,114,76,0,0,0,114,138,0,0,0,114, - 117,0,0,0,41,3,114,193,0,0,0,114,44,0,0,0, - 90,4,104,111,111,107,114,5,0,0,0,114,5,0,0,0, - 114,8,0,0,0,218,11,95,112,97,116,104,95,104,111,111, - 107,115,235,4,0,0,115,16,0,0,0,0,3,16,1,12, - 1,10,1,2,1,14,1,12,1,12,2,122,22,80,97,116, - 104,70,105,110,100,101,114,46,95,112,97,116,104,95,104,111, - 111,107,115,99,2,0,0,0,0,0,0,0,0,0,0,0, - 3,0,0,0,8,0,0,0,67,0,0,0,115,100,0,0, - 0,124,1,100,1,107,2,114,42,122,12,116,0,160,1,161, - 0,125,1,87,0,110,20,4,0,116,2,121,40,1,0,1, - 0,1,0,89,0,100,2,83,0,48,0,122,14,116,3,106, - 4,124,1,25,0,125,2,87,0,110,38,4,0,116,5,121, - 94,1,0,1,0,1,0,124,0,160,6,124,1,161,1,125, - 2,124,2,116,3,106,4,124,1,60,0,89,0,110,2,48, - 0,124,2,83,0,41,3,122,210,71,101,116,32,116,104,101, - 32,102,105,110,100,101,114,32,102,111,114,32,116,104,101,32, - 112,97,116,104,32,101,110,116,114,121,32,102,114,111,109,32, + 114,220,0,0,0,185,4,0,0,115,8,0,0,0,0,7, + 6,1,4,255,4,2,122,28,95,78,97,109,101,115,112,97, + 99,101,76,111,97,100,101,114,46,108,111,97,100,95,109,111, + 100,117,108,101,78,41,12,114,125,0,0,0,114,124,0,0, + 0,114,126,0,0,0,114,209,0,0,0,114,207,0,0,0, + 114,36,1,0,0,114,182,0,0,0,114,229,0,0,0,114, + 213,0,0,0,114,212,0,0,0,114,217,0,0,0,114,220, + 0,0,0,114,5,0,0,0,114,5,0,0,0,114,5,0, + 0,0,114,8,0,0,0,114,35,1,0,0,157,4,0,0, + 115,18,0,0,0,8,1,8,3,2,1,10,8,8,3,8, + 3,8,3,8,3,8,3,114,35,1,0,0,99,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0, + 0,64,0,0,0,115,118,0,0,0,101,0,90,1,100,0, + 90,2,100,1,90,3,101,4,100,2,100,3,132,0,131,1, + 90,5,101,4,100,4,100,5,132,0,131,1,90,6,101,4, + 100,6,100,7,132,0,131,1,90,7,101,4,100,8,100,9, + 132,0,131,1,90,8,101,4,100,19,100,11,100,12,132,1, + 131,1,90,9,101,4,100,20,100,13,100,14,132,1,131,1, + 90,10,101,4,100,21,100,15,100,16,132,1,131,1,90,11, + 101,4,100,17,100,18,132,0,131,1,90,12,100,10,83,0, + 41,22,218,10,80,97,116,104,70,105,110,100,101,114,122,62, + 77,101,116,97,32,112,97,116,104,32,102,105,110,100,101,114, + 32,102,111,114,32,115,121,115,46,112,97,116,104,32,97,110, + 100,32,112,97,99,107,97,103,101,32,95,95,112,97,116,104, + 95,95,32,97,116,116,114,105,98,117,116,101,115,46,99,1, + 0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,4, + 0,0,0,67,0,0,0,115,64,0,0,0,116,0,116,1, + 106,2,160,3,161,0,131,1,68,0,93,44,92,2,125,1, + 125,2,124,2,100,1,117,0,114,40,116,1,106,2,124,1, + 61,0,113,14,116,4,124,2,100,2,131,2,114,14,124,2, + 160,5,161,0,1,0,113,14,100,1,83,0,41,3,122,125, + 67,97,108,108,32,116,104,101,32,105,110,118,97,108,105,100, + 97,116,101,95,99,97,99,104,101,115,40,41,32,109,101,116, + 104,111,100,32,111,110,32,97,108,108,32,112,97,116,104,32, + 101,110,116,114,121,32,102,105,110,100,101,114,115,10,32,32, + 32,32,32,32,32,32,115,116,111,114,101,100,32,105,110,32, 115,121,115,46,112,97,116,104,95,105,109,112,111,114,116,101, - 114,95,99,97,99,104,101,46,10,10,32,32,32,32,32,32, - 32,32,73,102,32,116,104,101,32,112,97,116,104,32,101,110, - 116,114,121,32,105,115,32,110,111,116,32,105,110,32,116,104, - 101,32,99,97,99,104,101,44,32,102,105,110,100,32,116,104, - 101,32,97,112,112,114,111,112,114,105,97,116,101,32,102,105, - 110,100,101,114,10,32,32,32,32,32,32,32,32,97,110,100, - 32,99,97,99,104,101,32,105,116,46,32,73,102,32,110,111, - 32,102,105,110,100,101,114,32,105,115,32,97,118,97,105,108, - 97,98,108,101,44,32,115,116,111,114,101,32,78,111,110,101, - 46,10,10,32,32,32,32,32,32,32,32,114,40,0,0,0, - 78,41,7,114,4,0,0,0,114,55,0,0,0,114,3,1, - 0,0,114,1,0,0,0,114,48,1,0,0,218,8,75,101, - 121,69,114,114,111,114,114,52,1,0,0,41,3,114,193,0, - 0,0,114,44,0,0,0,114,50,1,0,0,114,5,0,0, - 0,114,5,0,0,0,114,8,0,0,0,218,20,95,112,97, - 116,104,95,105,109,112,111,114,116,101,114,95,99,97,99,104, - 101,248,4,0,0,115,22,0,0,0,0,8,8,1,2,1, - 12,1,12,3,8,1,2,1,14,1,12,1,10,1,16,1, - 122,31,80,97,116,104,70,105,110,100,101,114,46,95,112,97, - 116,104,95,105,109,112,111,114,116,101,114,95,99,97,99,104, - 101,99,3,0,0,0,0,0,0,0,0,0,0,0,6,0, - 0,0,4,0,0,0,67,0,0,0,115,82,0,0,0,116, - 0,124,2,100,1,131,2,114,26,124,2,160,1,124,1,161, - 1,92,2,125,3,125,4,110,14,124,2,160,2,124,1,161, - 1,125,3,103,0,125,4,124,3,100,0,117,1,114,60,116, - 3,160,4,124,1,124,3,161,2,83,0,116,3,160,5,124, - 1,100,0,161,2,125,5,124,4,124,5,95,6,124,5,83, - 0,41,2,78,114,137,0,0,0,41,7,114,128,0,0,0, - 114,137,0,0,0,114,206,0,0,0,114,134,0,0,0,114, - 201,0,0,0,114,183,0,0,0,114,178,0,0,0,41,6, - 114,193,0,0,0,114,139,0,0,0,114,50,1,0,0,114, - 140,0,0,0,114,141,0,0,0,114,187,0,0,0,114,5, - 0,0,0,114,5,0,0,0,114,8,0,0,0,218,16,95, - 108,101,103,97,99,121,95,103,101,116,95,115,112,101,99,14, - 5,0,0,115,18,0,0,0,0,4,10,1,16,2,10,1, - 4,1,8,1,12,1,12,1,6,1,122,27,80,97,116,104, - 70,105,110,100,101,114,46,95,108,101,103,97,99,121,95,103, - 101,116,95,115,112,101,99,78,99,4,0,0,0,0,0,0, - 0,0,0,0,0,9,0,0,0,5,0,0,0,67,0,0, - 0,115,166,0,0,0,103,0,125,4,124,2,68,0,93,134, - 125,5,116,0,124,5,116,1,116,2,102,2,131,2,115,28, - 113,8,124,0,160,3,124,5,161,1,125,6,124,6,100,1, - 117,1,114,8,116,4,124,6,100,2,131,2,114,70,124,6, - 160,5,124,1,124,3,161,2,125,7,110,12,124,0,160,6, - 124,1,124,6,161,2,125,7,124,7,100,1,117,0,114,92, - 113,8,124,7,106,7,100,1,117,1,114,110,124,7,2,0, - 1,0,83,0,124,7,106,8,125,8,124,8,100,1,117,0, - 114,132,116,9,100,3,131,1,130,1,124,4,160,10,124,8, - 161,1,1,0,113,8,116,11,160,12,124,1,100,1,161,2, - 125,7,124,4,124,7,95,8,124,7,83,0,41,4,122,63, - 70,105,110,100,32,116,104,101,32,108,111,97,100,101,114,32, - 111,114,32,110,97,109,101,115,112,97,99,101,95,112,97,116, - 104,32,102,111,114,32,116,104,105,115,32,109,111,100,117,108, - 101,47,112,97,99,107,97,103,101,32,110,97,109,101,46,78, - 114,203,0,0,0,122,19,115,112,101,99,32,109,105,115,115, - 105,110,103,32,108,111,97,100,101,114,41,13,114,161,0,0, - 0,114,84,0,0,0,218,5,98,121,116,101,115,114,54,1, - 0,0,114,128,0,0,0,114,203,0,0,0,114,55,1,0, - 0,114,140,0,0,0,114,178,0,0,0,114,117,0,0,0, - 114,167,0,0,0,114,134,0,0,0,114,183,0,0,0,41, - 9,114,193,0,0,0,114,139,0,0,0,114,44,0,0,0, - 114,202,0,0,0,218,14,110,97,109,101,115,112,97,99,101, - 95,112,97,116,104,90,5,101,110,116,114,121,114,50,1,0, - 0,114,187,0,0,0,114,141,0,0,0,114,5,0,0,0, - 114,5,0,0,0,114,8,0,0,0,218,9,95,103,101,116, - 95,115,112,101,99,29,5,0,0,115,40,0,0,0,0,5, - 4,1,8,1,14,1,2,1,10,1,8,1,10,1,14,2, - 12,1,8,1,2,1,10,1,8,1,6,1,8,1,8,5, - 12,2,12,1,6,1,122,20,80,97,116,104,70,105,110,100, - 101,114,46,95,103,101,116,95,115,112,101,99,99,4,0,0, - 0,0,0,0,0,0,0,0,0,6,0,0,0,5,0,0, - 0,67,0,0,0,115,100,0,0,0,124,2,100,1,117,0, - 114,14,116,0,106,1,125,2,124,0,160,2,124,1,124,2, - 124,3,161,3,125,4,124,4,100,1,117,0,114,40,100,1, - 83,0,124,4,106,3,100,1,117,0,114,92,124,4,106,4, - 125,5,124,5,114,86,100,1,124,4,95,5,116,6,124,1, - 124,5,124,0,106,2,131,3,124,4,95,4,124,4,83,0, - 100,1,83,0,110,4,124,4,83,0,100,1,83,0,41,2, - 122,141,84,114,121,32,116,111,32,102,105,110,100,32,97,32, - 115,112,101,99,32,102,111,114,32,39,102,117,108,108,110,97, - 109,101,39,32,111,110,32,115,121,115,46,112,97,116,104,32, - 111,114,32,39,112,97,116,104,39,46,10,10,32,32,32,32, - 32,32,32,32,84,104,101,32,115,101,97,114,99,104,32,105, - 115,32,98,97,115,101,100,32,111,110,32,115,121,115,46,112, - 97,116,104,95,104,111,111,107,115,32,97,110,100,32,115,121, - 115,46,112,97,116,104,95,105,109,112,111,114,116,101,114,95, - 99,97,99,104,101,46,10,32,32,32,32,32,32,32,32,78, - 41,7,114,1,0,0,0,114,44,0,0,0,114,58,1,0, - 0,114,140,0,0,0,114,178,0,0,0,114,181,0,0,0, - 114,22,1,0,0,41,6,114,193,0,0,0,114,139,0,0, - 0,114,44,0,0,0,114,202,0,0,0,114,187,0,0,0, - 114,57,1,0,0,114,5,0,0,0,114,5,0,0,0,114, - 8,0,0,0,114,203,0,0,0,61,5,0,0,115,26,0, - 0,0,0,6,8,1,6,1,14,1,8,1,4,1,10,1, - 6,1,4,3,6,1,16,1,4,2,6,2,122,20,80,97, - 116,104,70,105,110,100,101,114,46,102,105,110,100,95,115,112, - 101,99,99,3,0,0,0,0,0,0,0,0,0,0,0,4, - 0,0,0,4,0,0,0,67,0,0,0,115,30,0,0,0, - 124,0,160,0,124,1,124,2,161,2,125,3,124,3,100,1, - 117,0,114,24,100,1,83,0,124,3,106,1,83,0,41,2, - 122,170,102,105,110,100,32,116,104,101,32,109,111,100,117,108, - 101,32,111,110,32,115,121,115,46,112,97,116,104,32,111,114, - 32,39,112,97,116,104,39,32,98,97,115,101,100,32,111,110, - 32,115,121,115,46,112,97,116,104,95,104,111,111,107,115,32, - 97,110,100,10,32,32,32,32,32,32,32,32,115,121,115,46, + 114,95,99,97,99,104,101,115,32,40,119,104,101,114,101,32, + 105,109,112,108,101,109,101,110,116,101,100,41,46,78,218,17, + 105,110,118,97,108,105,100,97,116,101,95,99,97,99,104,101, + 115,41,6,218,4,108,105,115,116,114,1,0,0,0,218,19, 112,97,116,104,95,105,109,112,111,114,116,101,114,95,99,97, - 99,104,101,46,10,10,32,32,32,32,32,32,32,32,84,104, - 105,115,32,109,101,116,104,111,100,32,105,115,32,100,101,112, - 114,101,99,97,116,101,100,46,32,32,85,115,101,32,102,105, - 110,100,95,115,112,101,99,40,41,32,105,110,115,116,101,97, - 100,46,10,10,32,32,32,32,32,32,32,32,78,114,204,0, - 0,0,114,205,0,0,0,114,5,0,0,0,114,5,0,0, - 0,114,8,0,0,0,114,206,0,0,0,85,5,0,0,115, - 8,0,0,0,0,8,12,1,8,1,4,1,122,22,80,97, - 116,104,70,105,110,100,101,114,46,102,105,110,100,95,109,111, - 100,117,108,101,99,1,0,0,0,0,0,0,0,0,0,0, - 0,4,0,0,0,4,0,0,0,79,0,0,0,115,28,0, - 0,0,100,1,100,2,108,0,109,1,125,3,1,0,124,3, - 106,2,124,1,105,0,124,2,164,1,142,1,83,0,41,3, - 97,32,1,0,0,10,32,32,32,32,32,32,32,32,70,105, - 110,100,32,100,105,115,116,114,105,98,117,116,105,111,110,115, - 46,10,10,32,32,32,32,32,32,32,32,82,101,116,117,114, - 110,32,97,110,32,105,116,101,114,97,98,108,101,32,111,102, - 32,97,108,108,32,68,105,115,116,114,105,98,117,116,105,111, - 110,32,105,110,115,116,97,110,99,101,115,32,99,97,112,97, - 98,108,101,32,111,102,10,32,32,32,32,32,32,32,32,108, - 111,97,100,105,110,103,32,116,104,101,32,109,101,116,97,100, - 97,116,97,32,102,111,114,32,112,97,99,107,97,103,101,115, - 32,109,97,116,99,104,105,110,103,32,96,96,99,111,110,116, - 101,120,116,46,110,97,109,101,96,96,10,32,32,32,32,32, - 32,32,32,40,111,114,32,97,108,108,32,110,97,109,101,115, - 32,105,102,32,96,96,78,111,110,101,96,96,32,105,110,100, - 105,99,97,116,101,100,41,32,97,108,111,110,103,32,116,104, - 101,32,112,97,116,104,115,32,105,110,32,116,104,101,32,108, - 105,115,116,10,32,32,32,32,32,32,32,32,111,102,32,100, - 105,114,101,99,116,111,114,105,101,115,32,96,96,99,111,110, - 116,101,120,116,46,112,97,116,104,96,96,46,10,32,32,32, - 32,32,32,32,32,114,73,0,0,0,41,1,218,18,77,101, - 116,97,100,97,116,97,80,97,116,104,70,105,110,100,101,114, - 41,3,90,18,105,109,112,111,114,116,108,105,98,46,109,101, - 116,97,100,97,116,97,114,59,1,0,0,218,18,102,105,110, - 100,95,100,105,115,116,114,105,98,117,116,105,111,110,115,41, - 4,114,193,0,0,0,114,119,0,0,0,114,120,0,0,0, - 114,59,1,0,0,114,5,0,0,0,114,5,0,0,0,114, - 8,0,0,0,114,60,1,0,0,98,5,0,0,115,4,0, - 0,0,0,10,12,1,122,29,80,97,116,104,70,105,110,100, - 101,114,46,102,105,110,100,95,100,105,115,116,114,105,98,117, - 116,105,111,110,115,41,1,78,41,2,78,78,41,1,78,41, - 13,114,125,0,0,0,114,124,0,0,0,114,126,0,0,0, - 114,127,0,0,0,114,207,0,0,0,114,46,1,0,0,114, - 52,1,0,0,114,54,1,0,0,114,55,1,0,0,114,58, - 1,0,0,114,203,0,0,0,114,206,0,0,0,114,60,1, - 0,0,114,5,0,0,0,114,5,0,0,0,114,5,0,0, - 0,114,8,0,0,0,114,45,1,0,0,221,4,0,0,115, - 34,0,0,0,8,2,4,2,2,1,10,9,2,1,10,12, - 2,1,10,21,2,1,10,14,2,1,12,31,2,1,12,23, - 2,1,12,12,2,1,114,45,1,0,0,99,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0, - 64,0,0,0,115,90,0,0,0,101,0,90,1,100,0,90, - 2,100,1,90,3,100,2,100,3,132,0,90,4,100,4,100, - 5,132,0,90,5,101,6,90,7,100,6,100,7,132,0,90, - 8,100,8,100,9,132,0,90,9,100,19,100,11,100,12,132, - 1,90,10,100,13,100,14,132,0,90,11,101,12,100,15,100, - 16,132,0,131,1,90,13,100,17,100,18,132,0,90,14,100, - 10,83,0,41,20,218,10,70,105,108,101,70,105,110,100,101, - 114,122,172,70,105,108,101,45,98,97,115,101,100,32,102,105, - 110,100,101,114,46,10,10,32,32,32,32,73,110,116,101,114, - 97,99,116,105,111,110,115,32,119,105,116,104,32,116,104,101, - 32,102,105,108,101,32,115,121,115,116,101,109,32,97,114,101, - 32,99,97,99,104,101,100,32,102,111,114,32,112,101,114,102, - 111,114,109,97,110,99,101,44,32,98,101,105,110,103,10,32, - 32,32,32,114,101,102,114,101,115,104,101,100,32,119,104,101, - 110,32,116,104,101,32,100,105,114,101,99,116,111,114,121,32, - 116,104,101,32,102,105,110,100,101,114,32,105,115,32,104,97, - 110,100,108,105,110,103,32,104,97,115,32,98,101,101,110,32, - 109,111,100,105,102,105,101,100,46,10,10,32,32,32,32,99, - 2,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0, - 6,0,0,0,7,0,0,0,115,84,0,0,0,103,0,125, - 3,124,2,68,0,93,32,92,2,137,0,125,4,124,3,160, - 0,135,0,102,1,100,1,100,2,132,8,124,4,68,0,131, - 1,161,1,1,0,113,8,124,3,124,0,95,1,124,1,112, - 54,100,3,124,0,95,2,100,4,124,0,95,3,116,4,131, - 0,124,0,95,5,116,4,131,0,124,0,95,6,100,5,83, - 0,41,6,122,154,73,110,105,116,105,97,108,105,122,101,32, - 119,105,116,104,32,116,104,101,32,112,97,116,104,32,116,111, - 32,115,101,97,114,99,104,32,111,110,32,97,110,100,32,97, - 32,118,97,114,105,97,98,108,101,32,110,117,109,98,101,114, - 32,111,102,10,32,32,32,32,32,32,32,32,50,45,116,117, - 112,108,101,115,32,99,111,110,116,97,105,110,105,110,103,32, - 116,104,101,32,108,111,97,100,101,114,32,97,110,100,32,116, - 104,101,32,102,105,108,101,32,115,117,102,102,105,120,101,115, - 32,116,104,101,32,108,111,97,100,101,114,10,32,32,32,32, - 32,32,32,32,114,101,99,111,103,110,105,122,101,115,46,99, - 1,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, - 3,0,0,0,51,0,0,0,115,22,0,0,0,124,0,93, - 14,125,1,124,1,136,0,102,2,86,0,1,0,113,2,100, - 0,83,0,114,109,0,0,0,114,5,0,0,0,114,16,1, - 0,0,169,1,114,140,0,0,0,114,5,0,0,0,114,8, - 0,0,0,114,19,1,0,0,127,5,0,0,243,0,0,0, - 0,122,38,70,105,108,101,70,105,110,100,101,114,46,95,95, - 105,110,105,116,95,95,46,60,108,111,99,97,108,115,62,46, - 60,103,101,110,101,120,112,114,62,114,71,0,0,0,114,104, - 0,0,0,78,41,7,114,167,0,0,0,218,8,95,108,111, - 97,100,101,114,115,114,44,0,0,0,218,11,95,112,97,116, - 104,95,109,116,105,109,101,218,3,115,101,116,218,11,95,112, - 97,116,104,95,99,97,99,104,101,218,19,95,114,101,108,97, - 120,101,100,95,112,97,116,104,95,99,97,99,104,101,41,5, - 114,118,0,0,0,114,44,0,0,0,218,14,108,111,97,100, - 101,114,95,100,101,116,97,105,108,115,90,7,108,111,97,100, - 101,114,115,114,189,0,0,0,114,5,0,0,0,114,62,1, - 0,0,114,8,0,0,0,114,209,0,0,0,121,5,0,0, - 115,16,0,0,0,0,4,4,1,12,1,26,1,6,2,10, - 1,6,1,8,1,122,19,70,105,108,101,70,105,110,100,101, - 114,46,95,95,105,110,105,116,95,95,99,1,0,0,0,0, - 0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,67, - 0,0,0,115,10,0,0,0,100,1,124,0,95,0,100,2, - 83,0,41,3,122,31,73,110,118,97,108,105,100,97,116,101, - 32,116,104,101,32,100,105,114,101,99,116,111,114,121,32,109, - 116,105,109,101,46,114,104,0,0,0,78,41,1,114,65,1, - 0,0,114,246,0,0,0,114,5,0,0,0,114,5,0,0, - 0,114,8,0,0,0,114,46,1,0,0,135,5,0,0,115, - 2,0,0,0,0,2,122,28,70,105,108,101,70,105,110,100, - 101,114,46,105,110,118,97,108,105,100,97,116,101,95,99,97, - 99,104,101,115,99,2,0,0,0,0,0,0,0,0,0,0, - 0,3,0,0,0,3,0,0,0,67,0,0,0,115,42,0, - 0,0,124,0,160,0,124,1,161,1,125,2,124,2,100,1, - 117,0,114,26,100,1,103,0,102,2,83,0,124,2,106,1, - 124,2,106,2,112,38,103,0,102,2,83,0,41,2,122,197, - 84,114,121,32,116,111,32,102,105,110,100,32,97,32,108,111, - 97,100,101,114,32,102,111,114,32,116,104,101,32,115,112,101, - 99,105,102,105,101,100,32,109,111,100,117,108,101,44,32,111, - 114,32,116,104,101,32,110,97,109,101,115,112,97,99,101,10, - 32,32,32,32,32,32,32,32,112,97,99,107,97,103,101,32, - 112,111,114,116,105,111,110,115,46,32,82,101,116,117,114,110, - 115,32,40,108,111,97,100,101,114,44,32,108,105,115,116,45, - 111,102,45,112,111,114,116,105,111,110,115,41,46,10,10,32, - 32,32,32,32,32,32,32,84,104,105,115,32,109,101,116,104, - 111,100,32,105,115,32,100,101,112,114,101,99,97,116,101,100, - 46,32,32,85,115,101,32,102,105,110,100,95,115,112,101,99, - 40,41,32,105,110,115,116,101,97,100,46,10,10,32,32,32, - 32,32,32,32,32,78,41,3,114,203,0,0,0,114,140,0, - 0,0,114,178,0,0,0,41,3,114,118,0,0,0,114,139, + 99,104,101,218,5,105,116,101,109,115,114,128,0,0,0,114, + 38,1,0,0,41,3,114,193,0,0,0,114,116,0,0,0, + 218,6,102,105,110,100,101,114,114,5,0,0,0,114,5,0, + 0,0,114,8,0,0,0,114,38,1,0,0,203,4,0,0, + 115,10,0,0,0,0,4,22,1,8,1,10,1,10,1,122, + 28,80,97,116,104,70,105,110,100,101,114,46,105,110,118,97, + 108,105,100,97,116,101,95,99,97,99,104,101,115,99,2,0, + 0,0,0,0,0,0,0,0,0,0,3,0,0,0,9,0, + 0,0,67,0,0,0,115,82,0,0,0,116,0,106,1,100, + 1,117,1,114,28,116,0,106,1,115,28,116,2,160,3,100, + 2,116,4,161,2,1,0,116,0,106,1,68,0,93,42,125, + 2,122,14,124,2,124,1,131,1,87,0,2,0,1,0,83, + 0,4,0,116,5,121,74,1,0,1,0,1,0,89,0,113, + 34,89,0,113,34,48,0,113,34,100,1,83,0,41,3,122, + 46,83,101,97,114,99,104,32,115,121,115,46,112,97,116,104, + 95,104,111,111,107,115,32,102,111,114,32,97,32,102,105,110, + 100,101,114,32,102,111,114,32,39,112,97,116,104,39,46,78, + 122,23,115,121,115,46,112,97,116,104,95,104,111,111,107,115, + 32,105,115,32,101,109,112,116,121,41,6,114,1,0,0,0, + 218,10,112,97,116,104,95,104,111,111,107,115,114,75,0,0, + 0,114,76,0,0,0,114,138,0,0,0,114,117,0,0,0, + 41,3,114,193,0,0,0,114,44,0,0,0,90,4,104,111, + 111,107,114,5,0,0,0,114,5,0,0,0,114,8,0,0, + 0,218,11,95,112,97,116,104,95,104,111,111,107,115,213,4, + 0,0,115,16,0,0,0,0,3,16,1,12,1,10,1,2, + 1,14,1,12,1,12,2,122,22,80,97,116,104,70,105,110, + 100,101,114,46,95,112,97,116,104,95,104,111,111,107,115,99, + 2,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0, + 8,0,0,0,67,0,0,0,115,100,0,0,0,124,1,100, + 1,107,2,114,42,122,12,116,0,160,1,161,0,125,1,87, + 0,110,20,4,0,116,2,121,40,1,0,1,0,1,0,89, + 0,100,2,83,0,48,0,122,14,116,3,106,4,124,1,25, + 0,125,2,87,0,110,38,4,0,116,5,121,94,1,0,1, + 0,1,0,124,0,160,6,124,1,161,1,125,2,124,2,116, + 3,106,4,124,1,60,0,89,0,110,2,48,0,124,2,83, + 0,41,3,122,210,71,101,116,32,116,104,101,32,102,105,110, + 100,101,114,32,102,111,114,32,116,104,101,32,112,97,116,104, + 32,101,110,116,114,121,32,102,114,111,109,32,115,121,115,46, + 112,97,116,104,95,105,109,112,111,114,116,101,114,95,99,97, + 99,104,101,46,10,10,32,32,32,32,32,32,32,32,73,102, + 32,116,104,101,32,112,97,116,104,32,101,110,116,114,121,32, + 105,115,32,110,111,116,32,105,110,32,116,104,101,32,99,97, + 99,104,101,44,32,102,105,110,100,32,116,104,101,32,97,112, + 112,114,111,112,114,105,97,116,101,32,102,105,110,100,101,114, + 10,32,32,32,32,32,32,32,32,97,110,100,32,99,97,99, + 104,101,32,105,116,46,32,73,102,32,110,111,32,102,105,110, + 100,101,114,32,105,115,32,97,118,97,105,108,97,98,108,101, + 44,32,115,116,111,114,101,32,78,111,110,101,46,10,10,32, + 32,32,32,32,32,32,32,114,40,0,0,0,78,41,7,114, + 4,0,0,0,114,55,0,0,0,218,17,70,105,108,101,78, + 111,116,70,111,117,110,100,69,114,114,111,114,114,1,0,0, + 0,114,40,1,0,0,218,8,75,101,121,69,114,114,111,114, + 114,44,1,0,0,41,3,114,193,0,0,0,114,44,0,0, + 0,114,42,1,0,0,114,5,0,0,0,114,5,0,0,0, + 114,8,0,0,0,218,20,95,112,97,116,104,95,105,109,112, + 111,114,116,101,114,95,99,97,99,104,101,226,4,0,0,115, + 22,0,0,0,0,8,8,1,2,1,12,1,12,3,8,1, + 2,1,14,1,12,1,10,1,16,1,122,31,80,97,116,104, + 70,105,110,100,101,114,46,95,112,97,116,104,95,105,109,112, + 111,114,116,101,114,95,99,97,99,104,101,99,3,0,0,0, + 0,0,0,0,0,0,0,0,6,0,0,0,4,0,0,0, + 67,0,0,0,115,82,0,0,0,116,0,124,2,100,1,131, + 2,114,26,124,2,160,1,124,1,161,1,92,2,125,3,125, + 4,110,14,124,2,160,2,124,1,161,1,125,3,103,0,125, + 4,124,3,100,0,117,1,114,60,116,3,160,4,124,1,124, + 3,161,2,83,0,116,3,160,5,124,1,100,0,161,2,125, + 5,124,4,124,5,95,6,124,5,83,0,41,2,78,114,137, + 0,0,0,41,7,114,128,0,0,0,114,137,0,0,0,114, + 206,0,0,0,114,134,0,0,0,114,201,0,0,0,114,183, + 0,0,0,114,178,0,0,0,41,6,114,193,0,0,0,114, + 139,0,0,0,114,42,1,0,0,114,140,0,0,0,114,141, 0,0,0,114,187,0,0,0,114,5,0,0,0,114,5,0, - 0,0,114,8,0,0,0,114,137,0,0,0,141,5,0,0, - 115,8,0,0,0,0,7,10,1,8,1,8,1,122,22,70, - 105,108,101,70,105,110,100,101,114,46,102,105,110,100,95,108, - 111,97,100,101,114,99,6,0,0,0,0,0,0,0,0,0, - 0,0,7,0,0,0,6,0,0,0,67,0,0,0,115,26, - 0,0,0,124,1,124,2,124,3,131,2,125,6,116,0,124, - 2,124,3,124,6,124,4,100,1,141,4,83,0,41,2,78, - 114,177,0,0,0,41,1,114,190,0,0,0,41,7,114,118, - 0,0,0,114,188,0,0,0,114,139,0,0,0,114,44,0, - 0,0,90,4,115,109,115,108,114,202,0,0,0,114,140,0, - 0,0,114,5,0,0,0,114,5,0,0,0,114,8,0,0, - 0,114,58,1,0,0,153,5,0,0,115,8,0,0,0,0, - 1,10,1,8,1,2,255,122,20,70,105,108,101,70,105,110, - 100,101,114,46,95,103,101,116,95,115,112,101,99,78,99,3, - 0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,8, - 0,0,0,67,0,0,0,115,96,1,0,0,100,1,125,3, - 124,1,160,0,100,2,161,1,100,3,25,0,125,4,122,24, - 116,1,124,0,106,2,112,34,116,3,160,4,161,0,131,1, - 106,5,125,5,87,0,110,22,4,0,116,6,121,64,1,0, - 1,0,1,0,100,4,125,5,89,0,110,2,48,0,124,5, - 124,0,106,7,107,3,114,90,124,0,160,8,161,0,1,0, - 124,5,124,0,95,7,116,9,131,0,114,112,124,0,106,10, - 125,6,124,4,160,11,161,0,125,7,110,10,124,0,106,12, - 125,6,124,4,125,7,124,7,124,6,118,0,114,216,116,13, - 124,0,106,2,124,4,131,2,125,8,124,0,106,14,68,0, - 93,58,92,2,125,9,125,10,100,5,124,9,23,0,125,11, - 116,13,124,8,124,11,131,2,125,12,116,15,124,12,131,1, - 114,148,124,0,160,16,124,10,124,1,124,12,124,8,103,1, - 124,2,161,5,2,0,1,0,83,0,113,148,116,17,124,8, - 131,1,125,3,124,0,106,14,68,0,93,82,92,2,125,9, - 125,10,116,13,124,0,106,2,124,4,124,9,23,0,131,2, - 125,12,116,18,106,19,100,6,124,12,100,3,100,7,141,3, - 1,0,124,7,124,9,23,0,124,6,118,0,114,222,116,15, - 124,12,131,1,114,222,124,0,160,16,124,10,124,1,124,12, - 100,8,124,2,161,5,2,0,1,0,83,0,113,222,124,3, - 144,1,114,92,116,18,160,19,100,9,124,8,161,2,1,0, - 116,18,160,20,124,1,100,8,161,2,125,13,124,8,103,1, - 124,13,95,21,124,13,83,0,100,8,83,0,41,10,122,111, - 84,114,121,32,116,111,32,102,105,110,100,32,97,32,115,112, - 101,99,32,102,111,114,32,116,104,101,32,115,112,101,99,105, - 102,105,101,100,32,109,111,100,117,108,101,46,10,10,32,32, - 32,32,32,32,32,32,82,101,116,117,114,110,115,32,116,104, - 101,32,109,97,116,99,104,105,110,103,32,115,112,101,99,44, - 32,111,114,32,78,111,110,101,32,105,102,32,110,111,116,32, - 102,111,117,110,100,46,10,32,32,32,32,32,32,32,32,70, - 114,71,0,0,0,114,28,0,0,0,114,104,0,0,0,114, - 209,0,0,0,122,9,116,114,121,105,110,103,32,123,125,41, - 1,90,9,118,101,114,98,111,115,105,116,121,78,122,25,112, - 111,115,115,105,98,108,101,32,110,97,109,101,115,112,97,99, - 101,32,102,111,114,32,123,125,41,22,114,41,0,0,0,114, - 49,0,0,0,114,44,0,0,0,114,4,0,0,0,114,55, - 0,0,0,114,10,1,0,0,114,50,0,0,0,114,65,1, - 0,0,218,11,95,102,105,108,108,95,99,97,99,104,101,114, - 9,0,0,0,114,68,1,0,0,114,105,0,0,0,114,67, - 1,0,0,114,38,0,0,0,114,64,1,0,0,114,54,0, - 0,0,114,58,1,0,0,114,56,0,0,0,114,134,0,0, - 0,114,149,0,0,0,114,183,0,0,0,114,178,0,0,0, - 41,14,114,118,0,0,0,114,139,0,0,0,114,202,0,0, - 0,90,12,105,115,95,110,97,109,101,115,112,97,99,101,90, - 11,116,97,105,108,95,109,111,100,117,108,101,114,169,0,0, - 0,90,5,99,97,99,104,101,90,12,99,97,99,104,101,95, - 109,111,100,117,108,101,90,9,98,97,115,101,95,112,97,116, - 104,114,17,1,0,0,114,188,0,0,0,90,13,105,110,105, - 116,95,102,105,108,101,110,97,109,101,90,9,102,117,108,108, - 95,112,97,116,104,114,187,0,0,0,114,5,0,0,0,114, - 5,0,0,0,114,8,0,0,0,114,203,0,0,0,158,5, - 0,0,115,72,0,0,0,0,5,4,1,14,1,2,1,24, - 1,12,1,10,1,10,1,8,1,6,2,6,1,6,1,10, - 2,6,1,4,2,8,1,12,1,14,1,8,1,10,1,8, - 1,26,4,8,2,14,1,16,1,16,1,12,1,8,1,10, - 1,4,255,10,2,6,1,12,1,12,1,8,1,4,1,122, - 20,70,105,108,101,70,105,110,100,101,114,46,102,105,110,100, - 95,115,112,101,99,99,1,0,0,0,0,0,0,0,0,0, - 0,0,9,0,0,0,10,0,0,0,67,0,0,0,115,188, - 0,0,0,124,0,106,0,125,1,122,22,116,1,160,2,124, - 1,112,22,116,1,160,3,161,0,161,1,125,2,87,0,110, - 28,4,0,116,4,116,5,116,6,102,3,121,56,1,0,1, - 0,1,0,103,0,125,2,89,0,110,2,48,0,116,7,106, - 8,160,9,100,1,161,1,115,82,116,10,124,2,131,1,124, - 0,95,11,110,74,116,10,131,0,125,3,124,2,68,0,93, - 56,125,4,124,4,160,12,100,2,161,1,92,3,125,5,125, - 6,125,7,124,6,114,134,100,3,160,13,124,5,124,7,160, - 14,161,0,161,2,125,8,110,4,124,5,125,8,124,3,160, - 15,124,8,161,1,1,0,113,92,124,3,124,0,95,11,116, - 7,106,8,160,9,116,16,161,1,114,184,100,4,100,5,132, - 0,124,2,68,0,131,1,124,0,95,17,100,6,83,0,41, - 7,122,68,70,105,108,108,32,116,104,101,32,99,97,99,104, - 101,32,111,102,32,112,111,116,101,110,116,105,97,108,32,109, - 111,100,117,108,101,115,32,97,110,100,32,112,97,99,107,97, - 103,101,115,32,102,111,114,32,116,104,105,115,32,100,105,114, - 101,99,116,111,114,121,46,114,0,0,0,0,114,71,0,0, - 0,114,61,0,0,0,99,1,0,0,0,0,0,0,0,0, - 0,0,0,2,0,0,0,4,0,0,0,83,0,0,0,115, - 20,0,0,0,104,0,124,0,93,12,125,1,124,1,160,0, - 161,0,146,2,113,4,83,0,114,5,0,0,0,41,1,114, - 105,0,0,0,41,2,114,32,0,0,0,90,2,102,110,114, - 5,0,0,0,114,5,0,0,0,114,8,0,0,0,218,9, - 60,115,101,116,99,111,109,112,62,235,5,0,0,114,63,1, - 0,0,122,41,70,105,108,101,70,105,110,100,101,114,46,95, - 102,105,108,108,95,99,97,99,104,101,46,60,108,111,99,97, - 108,115,62,46,60,115,101,116,99,111,109,112,62,78,41,18, - 114,44,0,0,0,114,4,0,0,0,114,7,1,0,0,114, - 55,0,0,0,114,3,1,0,0,218,15,80,101,114,109,105, - 115,115,105,111,110,69,114,114,111,114,218,18,78,111,116,65, - 68,105,114,101,99,116,111,114,121,69,114,114,111,114,114,1, - 0,0,0,114,10,0,0,0,114,11,0,0,0,114,66,1, - 0,0,114,67,1,0,0,114,100,0,0,0,114,62,0,0, - 0,114,105,0,0,0,218,3,97,100,100,114,12,0,0,0, - 114,68,1,0,0,41,9,114,118,0,0,0,114,44,0,0, - 0,114,8,1,0,0,90,21,108,111,119,101,114,95,115,117, - 102,102,105,120,95,99,111,110,116,101,110,116,115,114,41,1, - 0,0,114,116,0,0,0,114,29,1,0,0,114,17,1,0, - 0,90,8,110,101,119,95,110,97,109,101,114,5,0,0,0, - 114,5,0,0,0,114,8,0,0,0,114,70,1,0,0,206, - 5,0,0,115,34,0,0,0,0,2,6,1,2,1,22,1, - 18,3,10,3,12,1,12,7,6,1,8,1,16,1,4,1, - 18,2,4,1,12,1,6,1,12,1,122,22,70,105,108,101, - 70,105,110,100,101,114,46,95,102,105,108,108,95,99,97,99, - 104,101,99,1,0,0,0,0,0,0,0,0,0,0,0,3, - 0,0,0,3,0,0,0,7,0,0,0,115,18,0,0,0, - 135,0,135,1,102,2,100,1,100,2,132,8,125,2,124,2, - 83,0,41,3,97,20,1,0,0,65,32,99,108,97,115,115, - 32,109,101,116,104,111,100,32,119,104,105,99,104,32,114,101, - 116,117,114,110,115,32,97,32,99,108,111,115,117,114,101,32, - 116,111,32,117,115,101,32,111,110,32,115,121,115,46,112,97, - 116,104,95,104,111,111,107,10,32,32,32,32,32,32,32,32, - 119,104,105,99,104,32,119,105,108,108,32,114,101,116,117,114, - 110,32,97,110,32,105,110,115,116,97,110,99,101,32,117,115, - 105,110,103,32,116,104,101,32,115,112,101,99,105,102,105,101, - 100,32,108,111,97,100,101,114,115,32,97,110,100,32,116,104, - 101,32,112,97,116,104,10,32,32,32,32,32,32,32,32,99, - 97,108,108,101,100,32,111,110,32,116,104,101,32,99,108,111, - 115,117,114,101,46,10,10,32,32,32,32,32,32,32,32,73, - 102,32,116,104,101,32,112,97,116,104,32,99,97,108,108,101, - 100,32,111,110,32,116,104,101,32,99,108,111,115,117,114,101, - 32,105,115,32,110,111,116,32,97,32,100,105,114,101,99,116, - 111,114,121,44,32,73,109,112,111,114,116,69,114,114,111,114, - 32,105,115,10,32,32,32,32,32,32,32,32,114,97,105,115, - 101,100,46,10,10,32,32,32,32,32,32,32,32,99,1,0, - 0,0,0,0,0,0,0,0,0,0,1,0,0,0,4,0, - 0,0,19,0,0,0,115,36,0,0,0,116,0,124,0,131, - 1,115,20,116,1,100,1,124,0,100,2,141,2,130,1,136, - 0,124,0,103,1,136,1,162,1,82,0,142,0,83,0,41, - 3,122,45,80,97,116,104,32,104,111,111,107,32,102,111,114, - 32,105,109,112,111,114,116,108,105,98,46,109,97,99,104,105, - 110,101,114,121,46,70,105,108,101,70,105,110,100,101,114,46, - 122,30,111,110,108,121,32,100,105,114,101,99,116,111,114,105, - 101,115,32,97,114,101,32,115,117,112,112,111,114,116,101,100, - 114,48,0,0,0,41,2,114,56,0,0,0,114,117,0,0, - 0,114,48,0,0,0,169,2,114,193,0,0,0,114,69,1, - 0,0,114,5,0,0,0,114,8,0,0,0,218,24,112,97, - 116,104,95,104,111,111,107,95,102,111,114,95,70,105,108,101, - 70,105,110,100,101,114,247,5,0,0,115,6,0,0,0,0, - 2,8,1,12,1,122,54,70,105,108,101,70,105,110,100,101, - 114,46,112,97,116,104,95,104,111,111,107,46,60,108,111,99, - 97,108,115,62,46,112,97,116,104,95,104,111,111,107,95,102, - 111,114,95,70,105,108,101,70,105,110,100,101,114,114,5,0, - 0,0,41,3,114,193,0,0,0,114,69,1,0,0,114,76, - 1,0,0,114,5,0,0,0,114,75,1,0,0,114,8,0, - 0,0,218,9,112,97,116,104,95,104,111,111,107,237,5,0, - 0,115,4,0,0,0,0,10,14,6,122,20,70,105,108,101, - 70,105,110,100,101,114,46,112,97,116,104,95,104,111,111,107, - 99,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0, - 0,3,0,0,0,67,0,0,0,115,12,0,0,0,100,1, - 160,0,124,0,106,1,161,1,83,0,41,2,78,122,16,70, - 105,108,101,70,105,110,100,101,114,40,123,33,114,125,41,41, - 2,114,62,0,0,0,114,44,0,0,0,114,246,0,0,0, - 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,114, - 39,1,0,0,255,5,0,0,115,2,0,0,0,0,1,122, - 19,70,105,108,101,70,105,110,100,101,114,46,95,95,114,101, - 112,114,95,95,41,1,78,41,15,114,125,0,0,0,114,124, - 0,0,0,114,126,0,0,0,114,127,0,0,0,114,209,0, - 0,0,114,46,1,0,0,114,143,0,0,0,114,206,0,0, - 0,114,137,0,0,0,114,58,1,0,0,114,203,0,0,0, - 114,70,1,0,0,114,207,0,0,0,114,77,1,0,0,114, - 39,1,0,0,114,5,0,0,0,114,5,0,0,0,114,5, - 0,0,0,114,8,0,0,0,114,61,1,0,0,112,5,0, - 0,115,22,0,0,0,8,2,4,7,8,14,8,4,4,2, - 8,12,8,5,10,48,8,31,2,1,10,17,114,61,1,0, - 0,99,4,0,0,0,0,0,0,0,0,0,0,0,6,0, - 0,0,8,0,0,0,67,0,0,0,115,144,0,0,0,124, - 0,160,0,100,1,161,1,125,4,124,0,160,0,100,2,161, - 1,125,5,124,4,115,66,124,5,114,36,124,5,106,1,125, - 4,110,30,124,2,124,3,107,2,114,56,116,2,124,1,124, - 2,131,2,125,4,110,10,116,3,124,1,124,2,131,2,125, - 4,124,5,115,84,116,4,124,1,124,2,124,4,100,3,141, - 3,125,5,122,36,124,5,124,0,100,2,60,0,124,4,124, - 0,100,1,60,0,124,2,124,0,100,4,60,0,124,3,124, - 0,100,5,60,0,87,0,110,18,4,0,116,5,121,138,1, - 0,1,0,1,0,89,0,110,2,48,0,100,0,83,0,41, - 6,78,218,10,95,95,108,111,97,100,101,114,95,95,218,8, - 95,95,115,112,101,99,95,95,114,62,1,0,0,90,8,95, - 95,102,105,108,101,95,95,90,10,95,95,99,97,99,104,101, - 100,95,95,41,6,218,3,103,101,116,114,140,0,0,0,114, - 15,1,0,0,114,9,1,0,0,114,190,0,0,0,218,9, - 69,120,99,101,112,116,105,111,110,41,6,90,2,110,115,114, - 116,0,0,0,90,8,112,97,116,104,110,97,109,101,90,9, - 99,112,97,116,104,110,97,109,101,114,140,0,0,0,114,187, - 0,0,0,114,5,0,0,0,114,5,0,0,0,114,8,0, - 0,0,218,14,95,102,105,120,95,117,112,95,109,111,100,117, - 108,101,5,6,0,0,115,34,0,0,0,0,2,10,1,10, - 1,4,1,4,1,8,1,8,1,12,2,10,1,4,1,14, - 1,2,1,8,1,8,1,8,1,12,1,12,2,114,82,1, - 0,0,99,0,0,0,0,0,0,0,0,0,0,0,0,3, - 0,0,0,3,0,0,0,67,0,0,0,115,38,0,0,0, - 116,0,116,1,160,2,161,0,102,2,125,0,116,3,116,4, - 102,2,125,1,116,5,116,6,102,2,125,2,124,0,124,1, - 124,2,103,3,83,0,41,1,122,95,82,101,116,117,114,110, - 115,32,97,32,108,105,115,116,32,111,102,32,102,105,108,101, - 45,98,97,115,101,100,32,109,111,100,117,108,101,32,108,111, - 97,100,101,114,115,46,10,10,32,32,32,32,69,97,99,104, - 32,105,116,101,109,32,105,115,32,97,32,116,117,112,108,101, - 32,40,108,111,97,100,101,114,44,32,115,117,102,102,105,120, - 101,115,41,46,10,32,32,32,32,41,7,114,252,0,0,0, - 114,163,0,0,0,218,18,101,120,116,101,110,115,105,111,110, - 95,115,117,102,102,105,120,101,115,114,9,1,0,0,114,101, - 0,0,0,114,15,1,0,0,114,88,0,0,0,41,3,90, - 10,101,120,116,101,110,115,105,111,110,115,90,6,115,111,117, - 114,99,101,90,8,98,121,116,101,99,111,100,101,114,5,0, - 0,0,114,5,0,0,0,114,8,0,0,0,114,184,0,0, - 0,28,6,0,0,115,8,0,0,0,0,5,12,1,8,1, - 8,1,114,184,0,0,0,99,1,0,0,0,0,0,0,0, - 0,0,0,0,10,0,0,0,9,0,0,0,67,0,0,0, - 115,132,1,0,0,124,0,97,0,116,0,106,1,97,1,116, - 0,106,2,97,2,116,1,106,3,116,4,25,0,125,1,100, - 1,100,2,103,1,102,2,100,3,100,4,100,2,103,2,102, - 2,102,2,125,2,124,2,68,0,93,108,92,2,125,3,125, - 4,116,5,100,5,100,6,132,0,124,4,68,0,131,1,131, - 1,115,82,74,0,130,1,124,4,100,7,25,0,125,5,124, - 3,116,1,106,3,118,0,114,116,116,1,106,3,124,3,25, - 0,125,6,1,0,113,170,113,52,122,20,116,0,160,6,124, - 3,161,1,125,6,87,0,1,0,113,170,87,0,113,52,4, - 0,116,7,121,158,1,0,1,0,1,0,89,0,113,52,89, - 0,113,52,48,0,113,52,116,7,100,8,131,1,130,1,116, - 8,124,1,100,9,124,6,131,3,1,0,116,8,124,1,100, - 10,124,5,131,3,1,0,116,8,124,1,100,11,100,12,160, - 9,124,4,161,1,131,3,1,0,116,8,124,1,100,13,100, - 14,100,15,132,0,124,4,68,0,131,1,131,3,1,0,103, - 0,100,16,162,1,125,7,124,3,100,3,107,2,144,1,114, - 6,124,7,160,10,100,17,161,1,1,0,124,7,68,0,93, - 52,125,8,124,8,116,1,106,3,118,1,144,1,114,38,116, - 0,160,6,124,8,161,1,125,9,110,10,116,1,106,3,124, - 8,25,0,125,9,116,8,124,1,124,8,124,9,131,3,1, - 0,144,1,113,10,116,8,124,1,100,18,116,11,131,0,131, - 3,1,0,116,12,160,13,116,2,160,14,161,0,161,1,1, - 0,124,3,100,3,107,2,144,1,114,128,116,15,160,10,100, - 19,161,1,1,0,100,20,116,12,118,0,144,1,114,128,100, - 21,116,16,95,17,100,22,83,0,41,23,122,205,83,101,116, - 117,112,32,116,104,101,32,112,97,116,104,45,98,97,115,101, - 100,32,105,109,112,111,114,116,101,114,115,32,102,111,114,32, - 105,109,112,111,114,116,108,105,98,32,98,121,32,105,109,112, - 111,114,116,105,110,103,32,110,101,101,100,101,100,10,32,32, - 32,32,98,117,105,108,116,45,105,110,32,109,111,100,117,108, - 101,115,32,97,110,100,32,105,110,106,101,99,116,105,110,103, - 32,116,104,101,109,32,105,110,116,111,32,116,104,101,32,103, - 108,111,98,97,108,32,110,97,109,101,115,112,97,99,101,46, - 10,10,32,32,32,32,79,116,104,101,114,32,99,111,109,112, - 111,110,101,110,116,115,32,97,114,101,32,101,120,116,114,97, - 99,116,101,100,32,102,114,111,109,32,116,104,101,32,99,111, - 114,101,32,98,111,111,116,115,116,114,97,112,32,109,111,100, - 117,108,101,46,10,10,32,32,32,32,90,5,112,111,115,105, - 120,250,1,47,90,2,110,116,250,1,92,99,1,0,0,0, - 0,0,0,0,0,0,0,0,2,0,0,0,3,0,0,0, - 115,0,0,0,115,26,0,0,0,124,0,93,18,125,1,116, - 0,124,1,131,1,100,0,107,2,86,0,1,0,113,2,100, - 1,83,0,41,2,114,39,0,0,0,78,41,1,114,23,0, - 0,0,41,2,114,32,0,0,0,114,94,0,0,0,114,5, - 0,0,0,114,5,0,0,0,114,8,0,0,0,114,19,1, - 0,0,57,6,0,0,114,63,1,0,0,122,25,95,115,101, - 116,117,112,46,60,108,111,99,97,108,115,62,46,60,103,101, - 110,101,120,112,114,62,114,73,0,0,0,122,30,105,109,112, - 111,114,116,108,105,98,32,114,101,113,117,105,114,101,115,32, - 112,111,115,105,120,32,111,114,32,110,116,114,4,0,0,0, - 114,35,0,0,0,114,31,0,0,0,114,40,0,0,0,114, - 58,0,0,0,99,1,0,0,0,0,0,0,0,0,0,0, - 0,2,0,0,0,4,0,0,0,83,0,0,0,115,22,0, - 0,0,104,0,124,0,93,14,125,1,100,0,124,1,155,0, - 157,2,146,2,113,4,83,0,41,1,114,74,0,0,0,114, - 5,0,0,0,41,2,114,32,0,0,0,218,1,115,114,5, - 0,0,0,114,5,0,0,0,114,8,0,0,0,114,71,1, - 0,0,74,6,0,0,114,63,1,0,0,122,25,95,115,101, - 116,117,112,46,60,108,111,99,97,108,115,62,46,60,115,101, - 116,99,111,109,112,62,41,3,114,64,0,0,0,114,75,0, - 0,0,114,160,0,0,0,114,192,0,0,0,114,9,0,0, - 0,122,4,46,112,121,119,122,6,95,100,46,112,121,100,84, - 78,41,18,114,134,0,0,0,114,1,0,0,0,114,163,0, - 0,0,114,31,1,0,0,114,125,0,0,0,218,3,97,108, - 108,90,18,95,98,117,105,108,116,105,110,95,102,114,111,109, - 95,110,97,109,101,114,117,0,0,0,114,129,0,0,0,114, - 36,0,0,0,114,186,0,0,0,114,14,0,0,0,114,21, - 1,0,0,114,167,0,0,0,114,83,1,0,0,114,101,0, - 0,0,114,191,0,0,0,114,195,0,0,0,41,10,218,17, - 95,98,111,111,116,115,116,114,97,112,95,109,111,100,117,108, - 101,90,11,115,101,108,102,95,109,111,100,117,108,101,90,10, - 111,115,95,100,101,116,97,105,108,115,90,10,98,117,105,108, - 116,105,110,95,111,115,114,31,0,0,0,114,35,0,0,0, - 90,9,111,115,95,109,111,100,117,108,101,90,13,98,117,105, - 108,116,105,110,95,110,97,109,101,115,90,12,98,117,105,108, - 116,105,110,95,110,97,109,101,90,14,98,117,105,108,116,105, - 110,95,109,111,100,117,108,101,114,5,0,0,0,114,5,0, - 0,0,114,8,0,0,0,218,6,95,115,101,116,117,112,39, - 6,0,0,115,70,0,0,0,0,8,4,1,6,1,6,2, - 10,3,22,1,12,2,22,1,8,1,10,1,10,1,6,2, - 2,1,10,1,10,1,12,1,12,2,8,2,12,1,12,1, - 18,1,22,3,8,1,10,1,10,1,8,1,12,1,12,2, - 10,1,16,3,14,1,14,1,10,1,10,1,10,1,114,89, - 1,0,0,99,1,0,0,0,0,0,0,0,0,0,0,0, - 2,0,0,0,4,0,0,0,67,0,0,0,115,50,0,0, - 0,116,0,124,0,131,1,1,0,116,1,131,0,125,1,116, - 2,106,3,160,4,116,5,106,6,124,1,142,0,103,1,161, - 1,1,0,116,2,106,7,160,8,116,9,161,1,1,0,100, - 1,83,0,41,2,122,41,73,110,115,116,97,108,108,32,116, - 104,101,32,112,97,116,104,45,98,97,115,101,100,32,105,109, - 112,111,114,116,32,99,111,109,112,111,110,101,110,116,115,46, - 78,41,10,114,89,1,0,0,114,184,0,0,0,114,1,0, - 0,0,114,51,1,0,0,114,167,0,0,0,114,61,1,0, - 0,114,77,1,0,0,218,9,109,101,116,97,95,112,97,116, - 104,114,186,0,0,0,114,45,1,0,0,41,2,114,88,1, - 0,0,90,17,115,117,112,112,111,114,116,101,100,95,108,111, - 97,100,101,114,115,114,5,0,0,0,114,5,0,0,0,114, - 8,0,0,0,218,8,95,105,110,115,116,97,108,108,96,6, - 0,0,115,8,0,0,0,0,2,8,1,6,1,20,1,114, - 91,1,0,0,41,1,114,60,0,0,0,41,1,78,41,3, - 78,78,78,41,2,114,73,0,0,0,114,73,0,0,0,41, - 1,84,41,1,78,41,1,78,41,63,114,127,0,0,0,114, - 13,0,0,0,90,37,95,67,65,83,69,95,73,78,83,69, - 78,83,73,84,73,86,69,95,80,76,65,84,70,79,82,77, - 83,95,66,89,84,69,83,95,75,69,89,114,12,0,0,0, - 114,14,0,0,0,114,21,0,0,0,114,27,0,0,0,114, - 29,0,0,0,114,38,0,0,0,114,47,0,0,0,114,49, - 0,0,0,114,53,0,0,0,114,54,0,0,0,114,56,0, - 0,0,114,59,0,0,0,114,69,0,0,0,218,4,116,121, - 112,101,218,8,95,95,99,111,100,101,95,95,114,162,0,0, - 0,114,19,0,0,0,114,148,0,0,0,114,18,0,0,0, - 114,24,0,0,0,114,236,0,0,0,114,91,0,0,0,114, - 87,0,0,0,114,101,0,0,0,114,88,0,0,0,90,23, - 68,69,66,85,71,95,66,89,84,69,67,79,68,69,95,83, - 85,70,70,73,88,69,83,90,27,79,80,84,73,77,73,90, - 69,68,95,66,89,84,69,67,79,68,69,95,83,85,70,70, - 73,88,69,83,114,97,0,0,0,114,102,0,0,0,114,108, - 0,0,0,114,112,0,0,0,114,114,0,0,0,114,136,0, - 0,0,114,143,0,0,0,114,152,0,0,0,114,156,0,0, - 0,114,158,0,0,0,114,165,0,0,0,114,170,0,0,0, - 114,171,0,0,0,114,176,0,0,0,218,6,111,98,106,101, - 99,116,114,185,0,0,0,114,190,0,0,0,114,191,0,0, - 0,114,208,0,0,0,114,221,0,0,0,114,239,0,0,0, - 114,9,1,0,0,114,15,1,0,0,114,21,1,0,0,114, - 252,0,0,0,114,22,1,0,0,114,43,1,0,0,114,45, - 1,0,0,114,61,1,0,0,114,82,1,0,0,114,184,0, - 0,0,114,89,1,0,0,114,91,1,0,0,114,5,0,0, + 0,0,114,8,0,0,0,218,16,95,108,101,103,97,99,121, + 95,103,101,116,95,115,112,101,99,248,4,0,0,115,18,0, + 0,0,0,4,10,1,16,2,10,1,4,1,8,1,12,1, + 12,1,6,1,122,27,80,97,116,104,70,105,110,100,101,114, + 46,95,108,101,103,97,99,121,95,103,101,116,95,115,112,101, + 99,78,99,4,0,0,0,0,0,0,0,0,0,0,0,9, + 0,0,0,5,0,0,0,67,0,0,0,115,166,0,0,0, + 103,0,125,4,124,2,68,0,93,134,125,5,116,0,124,5, + 116,1,116,2,102,2,131,2,115,28,113,8,124,0,160,3, + 124,5,161,1,125,6,124,6,100,1,117,1,114,8,116,4, + 124,6,100,2,131,2,114,70,124,6,160,5,124,1,124,3, + 161,2,125,7,110,12,124,0,160,6,124,1,124,6,161,2, + 125,7,124,7,100,1,117,0,114,92,113,8,124,7,106,7, + 100,1,117,1,114,110,124,7,2,0,1,0,83,0,124,7, + 106,8,125,8,124,8,100,1,117,0,114,132,116,9,100,3, + 131,1,130,1,124,4,160,10,124,8,161,1,1,0,113,8, + 116,11,160,12,124,1,100,1,161,2,125,7,124,4,124,7, + 95,8,124,7,83,0,41,4,122,63,70,105,110,100,32,116, + 104,101,32,108,111,97,100,101,114,32,111,114,32,110,97,109, + 101,115,112,97,99,101,95,112,97,116,104,32,102,111,114,32, + 116,104,105,115,32,109,111,100,117,108,101,47,112,97,99,107, + 97,103,101,32,110,97,109,101,46,78,114,203,0,0,0,122, + 19,115,112,101,99,32,109,105,115,115,105,110,103,32,108,111, + 97,100,101,114,41,13,114,161,0,0,0,114,84,0,0,0, + 218,5,98,121,116,101,115,114,47,1,0,0,114,128,0,0, + 0,114,203,0,0,0,114,48,1,0,0,114,140,0,0,0, + 114,178,0,0,0,114,117,0,0,0,114,167,0,0,0,114, + 134,0,0,0,114,183,0,0,0,41,9,114,193,0,0,0, + 114,139,0,0,0,114,44,0,0,0,114,202,0,0,0,218, + 14,110,97,109,101,115,112,97,99,101,95,112,97,116,104,90, + 5,101,110,116,114,121,114,42,1,0,0,114,187,0,0,0, + 114,141,0,0,0,114,5,0,0,0,114,5,0,0,0,114, + 8,0,0,0,218,9,95,103,101,116,95,115,112,101,99,7, + 5,0,0,115,40,0,0,0,0,5,4,1,8,1,14,1, + 2,1,10,1,8,1,10,1,14,2,12,1,8,1,2,1, + 10,1,8,1,6,1,8,1,8,5,12,2,12,1,6,1, + 122,20,80,97,116,104,70,105,110,100,101,114,46,95,103,101, + 116,95,115,112,101,99,99,4,0,0,0,0,0,0,0,0, + 0,0,0,6,0,0,0,5,0,0,0,67,0,0,0,115, + 100,0,0,0,124,2,100,1,117,0,114,14,116,0,106,1, + 125,2,124,0,160,2,124,1,124,2,124,3,161,3,125,4, + 124,4,100,1,117,0,114,40,100,1,83,0,124,4,106,3, + 100,1,117,0,114,92,124,4,106,4,125,5,124,5,114,86, + 100,1,124,4,95,5,116,6,124,1,124,5,124,0,106,2, + 131,3,124,4,95,4,124,4,83,0,100,1,83,0,110,4, + 124,4,83,0,100,1,83,0,41,2,122,141,84,114,121,32, + 116,111,32,102,105,110,100,32,97,32,115,112,101,99,32,102, + 111,114,32,39,102,117,108,108,110,97,109,101,39,32,111,110, + 32,115,121,115,46,112,97,116,104,32,111,114,32,39,112,97, + 116,104,39,46,10,10,32,32,32,32,32,32,32,32,84,104, + 101,32,115,101,97,114,99,104,32,105,115,32,98,97,115,101, + 100,32,111,110,32,115,121,115,46,112,97,116,104,95,104,111, + 111,107,115,32,97,110,100,32,115,121,115,46,112,97,116,104, + 95,105,109,112,111,114,116,101,114,95,99,97,99,104,101,46, + 10,32,32,32,32,32,32,32,32,78,41,7,114,1,0,0, + 0,114,44,0,0,0,114,51,1,0,0,114,140,0,0,0, + 114,178,0,0,0,114,181,0,0,0,114,13,1,0,0,41, + 6,114,193,0,0,0,114,139,0,0,0,114,44,0,0,0, + 114,202,0,0,0,114,187,0,0,0,114,50,1,0,0,114, + 5,0,0,0,114,5,0,0,0,114,8,0,0,0,114,203, + 0,0,0,39,5,0,0,115,26,0,0,0,0,6,8,1, + 6,1,14,1,8,1,4,1,10,1,6,1,4,3,6,1, + 16,1,4,2,6,2,122,20,80,97,116,104,70,105,110,100, + 101,114,46,102,105,110,100,95,115,112,101,99,99,3,0,0, + 0,0,0,0,0,0,0,0,0,4,0,0,0,4,0,0, + 0,67,0,0,0,115,30,0,0,0,124,0,160,0,124,1, + 124,2,161,2,125,3,124,3,100,1,117,0,114,24,100,1, + 83,0,124,3,106,1,83,0,41,2,122,170,102,105,110,100, + 32,116,104,101,32,109,111,100,117,108,101,32,111,110,32,115, + 121,115,46,112,97,116,104,32,111,114,32,39,112,97,116,104, + 39,32,98,97,115,101,100,32,111,110,32,115,121,115,46,112, + 97,116,104,95,104,111,111,107,115,32,97,110,100,10,32,32, + 32,32,32,32,32,32,115,121,115,46,112,97,116,104,95,105, + 109,112,111,114,116,101,114,95,99,97,99,104,101,46,10,10, + 32,32,32,32,32,32,32,32,84,104,105,115,32,109,101,116, + 104,111,100,32,105,115,32,100,101,112,114,101,99,97,116,101, + 100,46,32,32,85,115,101,32,102,105,110,100,95,115,112,101, + 99,40,41,32,105,110,115,116,101,97,100,46,10,10,32,32, + 32,32,32,32,32,32,78,114,204,0,0,0,114,205,0,0, 0,114,5,0,0,0,114,5,0,0,0,114,8,0,0,0, - 218,8,60,109,111,100,117,108,101,62,1,0,0,0,115,126, - 0,0,0,4,22,4,1,4,1,2,1,2,255,4,4,8, - 17,8,5,8,5,8,6,8,6,8,12,8,10,8,9,8, - 5,8,7,8,9,10,22,10,127,0,20,16,1,12,2,4, - 1,4,2,6,2,6,2,8,2,16,71,8,40,8,19,8, - 12,8,12,8,28,8,17,8,33,8,28,8,24,10,13,10, - 10,10,11,8,14,6,3,4,1,2,255,12,68,14,64,14, - 29,16,127,0,17,14,72,18,45,18,26,4,3,18,53,14, - 63,14,42,14,127,0,20,14,127,0,22,10,23,8,11,8, - 57, + 114,206,0,0,0,63,5,0,0,115,8,0,0,0,0,8, + 12,1,8,1,4,1,122,22,80,97,116,104,70,105,110,100, + 101,114,46,102,105,110,100,95,109,111,100,117,108,101,99,1, + 0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,4, + 0,0,0,79,0,0,0,115,28,0,0,0,100,1,100,2, + 108,0,109,1,125,3,1,0,124,3,106,2,124,1,105,0, + 124,2,164,1,142,1,83,0,41,3,97,32,1,0,0,10, + 32,32,32,32,32,32,32,32,70,105,110,100,32,100,105,115, + 116,114,105,98,117,116,105,111,110,115,46,10,10,32,32,32, + 32,32,32,32,32,82,101,116,117,114,110,32,97,110,32,105, + 116,101,114,97,98,108,101,32,111,102,32,97,108,108,32,68, + 105,115,116,114,105,98,117,116,105,111,110,32,105,110,115,116, + 97,110,99,101,115,32,99,97,112,97,98,108,101,32,111,102, + 10,32,32,32,32,32,32,32,32,108,111,97,100,105,110,103, + 32,116,104,101,32,109,101,116,97,100,97,116,97,32,102,111, + 114,32,112,97,99,107,97,103,101,115,32,109,97,116,99,104, + 105,110,103,32,96,96,99,111,110,116,101,120,116,46,110,97, + 109,101,96,96,10,32,32,32,32,32,32,32,32,40,111,114, + 32,97,108,108,32,110,97,109,101,115,32,105,102,32,96,96, + 78,111,110,101,96,96,32,105,110,100,105,99,97,116,101,100, + 41,32,97,108,111,110,103,32,116,104,101,32,112,97,116,104, + 115,32,105,110,32,116,104,101,32,108,105,115,116,10,32,32, + 32,32,32,32,32,32,111,102,32,100,105,114,101,99,116,111, + 114,105,101,115,32,96,96,99,111,110,116,101,120,116,46,112, + 97,116,104,96,96,46,10,32,32,32,32,32,32,32,32,114, + 73,0,0,0,41,1,218,18,77,101,116,97,100,97,116,97, + 80,97,116,104,70,105,110,100,101,114,41,3,90,18,105,109, + 112,111,114,116,108,105,98,46,109,101,116,97,100,97,116,97, + 114,52,1,0,0,218,18,102,105,110,100,95,100,105,115,116, + 114,105,98,117,116,105,111,110,115,41,4,114,193,0,0,0, + 114,119,0,0,0,114,120,0,0,0,114,52,1,0,0,114, + 5,0,0,0,114,5,0,0,0,114,8,0,0,0,114,53, + 1,0,0,76,5,0,0,115,4,0,0,0,0,10,12,1, + 122,29,80,97,116,104,70,105,110,100,101,114,46,102,105,110, + 100,95,100,105,115,116,114,105,98,117,116,105,111,110,115,41, + 1,78,41,2,78,78,41,1,78,41,13,114,125,0,0,0, + 114,124,0,0,0,114,126,0,0,0,114,127,0,0,0,114, + 207,0,0,0,114,38,1,0,0,114,44,1,0,0,114,47, + 1,0,0,114,48,1,0,0,114,51,1,0,0,114,203,0, + 0,0,114,206,0,0,0,114,53,1,0,0,114,5,0,0, + 0,114,5,0,0,0,114,5,0,0,0,114,8,0,0,0, + 114,37,1,0,0,199,4,0,0,115,34,0,0,0,8,2, + 4,2,2,1,10,9,2,1,10,12,2,1,10,21,2,1, + 10,14,2,1,12,31,2,1,12,23,2,1,12,12,2,1, + 114,37,1,0,0,99,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,3,0,0,0,64,0,0,0,115,90, + 0,0,0,101,0,90,1,100,0,90,2,100,1,90,3,100, + 2,100,3,132,0,90,4,100,4,100,5,132,0,90,5,101, + 6,90,7,100,6,100,7,132,0,90,8,100,8,100,9,132, + 0,90,9,100,19,100,11,100,12,132,1,90,10,100,13,100, + 14,132,0,90,11,101,12,100,15,100,16,132,0,131,1,90, + 13,100,17,100,18,132,0,90,14,100,10,83,0,41,20,218, + 10,70,105,108,101,70,105,110,100,101,114,122,172,70,105,108, + 101,45,98,97,115,101,100,32,102,105,110,100,101,114,46,10, + 10,32,32,32,32,73,110,116,101,114,97,99,116,105,111,110, + 115,32,119,105,116,104,32,116,104,101,32,102,105,108,101,32, + 115,121,115,116,101,109,32,97,114,101,32,99,97,99,104,101, + 100,32,102,111,114,32,112,101,114,102,111,114,109,97,110,99, + 101,44,32,98,101,105,110,103,10,32,32,32,32,114,101,102, + 114,101,115,104,101,100,32,119,104,101,110,32,116,104,101,32, + 100,105,114,101,99,116,111,114,121,32,116,104,101,32,102,105, + 110,100,101,114,32,105,115,32,104,97,110,100,108,105,110,103, + 32,104,97,115,32,98,101,101,110,32,109,111,100,105,102,105, + 101,100,46,10,10,32,32,32,32,99,2,0,0,0,0,0, + 0,0,0,0,0,0,5,0,0,0,6,0,0,0,7,0, + 0,0,115,84,0,0,0,103,0,125,3,124,2,68,0,93, + 32,92,2,137,0,125,4,124,3,160,0,135,0,102,1,100, + 1,100,2,132,8,124,4,68,0,131,1,161,1,1,0,113, + 8,124,3,124,0,95,1,124,1,112,54,100,3,124,0,95, + 2,100,4,124,0,95,3,116,4,131,0,124,0,95,5,116, + 4,131,0,124,0,95,6,100,5,83,0,41,6,122,154,73, + 110,105,116,105,97,108,105,122,101,32,119,105,116,104,32,116, + 104,101,32,112,97,116,104,32,116,111,32,115,101,97,114,99, + 104,32,111,110,32,97,110,100,32,97,32,118,97,114,105,97, + 98,108,101,32,110,117,109,98,101,114,32,111,102,10,32,32, + 32,32,32,32,32,32,50,45,116,117,112,108,101,115,32,99, + 111,110,116,97,105,110,105,110,103,32,116,104,101,32,108,111, + 97,100,101,114,32,97,110,100,32,116,104,101,32,102,105,108, + 101,32,115,117,102,102,105,120,101,115,32,116,104,101,32,108, + 111,97,100,101,114,10,32,32,32,32,32,32,32,32,114,101, + 99,111,103,110,105,122,101,115,46,99,1,0,0,0,0,0, + 0,0,0,0,0,0,2,0,0,0,3,0,0,0,51,0, + 0,0,115,22,0,0,0,124,0,93,14,125,1,124,1,136, + 0,102,2,86,0,1,0,113,2,100,0,83,0,114,109,0, + 0,0,114,5,0,0,0,114,7,1,0,0,169,1,114,140, + 0,0,0,114,5,0,0,0,114,8,0,0,0,114,10,1, + 0,0,105,5,0,0,243,0,0,0,0,122,38,70,105,108, + 101,70,105,110,100,101,114,46,95,95,105,110,105,116,95,95, + 46,60,108,111,99,97,108,115,62,46,60,103,101,110,101,120, + 112,114,62,114,71,0,0,0,114,104,0,0,0,78,41,7, + 114,167,0,0,0,218,8,95,108,111,97,100,101,114,115,114, + 44,0,0,0,218,11,95,112,97,116,104,95,109,116,105,109, + 101,218,3,115,101,116,218,11,95,112,97,116,104,95,99,97, + 99,104,101,218,19,95,114,101,108,97,120,101,100,95,112,97, + 116,104,95,99,97,99,104,101,41,5,114,118,0,0,0,114, + 44,0,0,0,218,14,108,111,97,100,101,114,95,100,101,116, + 97,105,108,115,90,7,108,111,97,100,101,114,115,114,189,0, + 0,0,114,5,0,0,0,114,55,1,0,0,114,8,0,0, + 0,114,209,0,0,0,99,5,0,0,115,16,0,0,0,0, + 4,4,1,12,1,26,1,6,2,10,1,6,1,8,1,122, + 19,70,105,108,101,70,105,110,100,101,114,46,95,95,105,110, + 105,116,95,95,99,1,0,0,0,0,0,0,0,0,0,0, + 0,1,0,0,0,2,0,0,0,67,0,0,0,115,10,0, + 0,0,100,1,124,0,95,0,100,2,83,0,41,3,122,31, + 73,110,118,97,108,105,100,97,116,101,32,116,104,101,32,100, + 105,114,101,99,116,111,114,121,32,109,116,105,109,101,46,114, + 104,0,0,0,78,41,1,114,58,1,0,0,114,246,0,0, + 0,114,5,0,0,0,114,5,0,0,0,114,8,0,0,0, + 114,38,1,0,0,113,5,0,0,115,2,0,0,0,0,2, + 122,28,70,105,108,101,70,105,110,100,101,114,46,105,110,118, + 97,108,105,100,97,116,101,95,99,97,99,104,101,115,99,2, + 0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,3, + 0,0,0,67,0,0,0,115,42,0,0,0,124,0,160,0, + 124,1,161,1,125,2,124,2,100,1,117,0,114,26,100,1, + 103,0,102,2,83,0,124,2,106,1,124,2,106,2,112,38, + 103,0,102,2,83,0,41,2,122,197,84,114,121,32,116,111, + 32,102,105,110,100,32,97,32,108,111,97,100,101,114,32,102, + 111,114,32,116,104,101,32,115,112,101,99,105,102,105,101,100, + 32,109,111,100,117,108,101,44,32,111,114,32,116,104,101,32, + 110,97,109,101,115,112,97,99,101,10,32,32,32,32,32,32, + 32,32,112,97,99,107,97,103,101,32,112,111,114,116,105,111, + 110,115,46,32,82,101,116,117,114,110,115,32,40,108,111,97, + 100,101,114,44,32,108,105,115,116,45,111,102,45,112,111,114, + 116,105,111,110,115,41,46,10,10,32,32,32,32,32,32,32, + 32,84,104,105,115,32,109,101,116,104,111,100,32,105,115,32, + 100,101,112,114,101,99,97,116,101,100,46,32,32,85,115,101, + 32,102,105,110,100,95,115,112,101,99,40,41,32,105,110,115, + 116,101,97,100,46,10,10,32,32,32,32,32,32,32,32,78, + 41,3,114,203,0,0,0,114,140,0,0,0,114,178,0,0, + 0,41,3,114,118,0,0,0,114,139,0,0,0,114,187,0, + 0,0,114,5,0,0,0,114,5,0,0,0,114,8,0,0, + 0,114,137,0,0,0,119,5,0,0,115,8,0,0,0,0, + 7,10,1,8,1,8,1,122,22,70,105,108,101,70,105,110, + 100,101,114,46,102,105,110,100,95,108,111,97,100,101,114,99, + 6,0,0,0,0,0,0,0,0,0,0,0,7,0,0,0, + 6,0,0,0,67,0,0,0,115,26,0,0,0,124,1,124, + 2,124,3,131,2,125,6,116,0,124,2,124,3,124,6,124, + 4,100,1,141,4,83,0,41,2,78,114,177,0,0,0,41, + 1,114,190,0,0,0,41,7,114,118,0,0,0,114,188,0, + 0,0,114,139,0,0,0,114,44,0,0,0,90,4,115,109, + 115,108,114,202,0,0,0,114,140,0,0,0,114,5,0,0, + 0,114,5,0,0,0,114,8,0,0,0,114,51,1,0,0, + 131,5,0,0,115,8,0,0,0,0,1,10,1,8,1,2, + 255,122,20,70,105,108,101,70,105,110,100,101,114,46,95,103, + 101,116,95,115,112,101,99,78,99,3,0,0,0,0,0,0, + 0,0,0,0,0,14,0,0,0,8,0,0,0,67,0,0, + 0,115,96,1,0,0,100,1,125,3,124,1,160,0,100,2, + 161,1,100,3,25,0,125,4,122,24,116,1,124,0,106,2, + 112,34,116,3,160,4,161,0,131,1,106,5,125,5,87,0, + 110,22,4,0,116,6,121,64,1,0,1,0,1,0,100,4, + 125,5,89,0,110,2,48,0,124,5,124,0,106,7,107,3, + 114,90,124,0,160,8,161,0,1,0,124,5,124,0,95,7, + 116,9,131,0,114,112,124,0,106,10,125,6,124,4,160,11, + 161,0,125,7,110,10,124,0,106,12,125,6,124,4,125,7, + 124,7,124,6,118,0,114,216,116,13,124,0,106,2,124,4, + 131,2,125,8,124,0,106,14,68,0,93,58,92,2,125,9, + 125,10,100,5,124,9,23,0,125,11,116,13,124,8,124,11, + 131,2,125,12,116,15,124,12,131,1,114,148,124,0,160,16, + 124,10,124,1,124,12,124,8,103,1,124,2,161,5,2,0, + 1,0,83,0,113,148,116,17,124,8,131,1,125,3,124,0, + 106,14,68,0,93,82,92,2,125,9,125,10,116,13,124,0, + 106,2,124,4,124,9,23,0,131,2,125,12,116,18,106,19, + 100,6,124,12,100,3,100,7,141,3,1,0,124,7,124,9, + 23,0,124,6,118,0,114,222,116,15,124,12,131,1,114,222, + 124,0,160,16,124,10,124,1,124,12,100,8,124,2,161,5, + 2,0,1,0,83,0,113,222,124,3,144,1,114,92,116,18, + 160,19,100,9,124,8,161,2,1,0,116,18,160,20,124,1, + 100,8,161,2,125,13,124,8,103,1,124,13,95,21,124,13, + 83,0,100,8,83,0,41,10,122,111,84,114,121,32,116,111, + 32,102,105,110,100,32,97,32,115,112,101,99,32,102,111,114, + 32,116,104,101,32,115,112,101,99,105,102,105,101,100,32,109, + 111,100,117,108,101,46,10,10,32,32,32,32,32,32,32,32, + 82,101,116,117,114,110,115,32,116,104,101,32,109,97,116,99, + 104,105,110,103,32,115,112,101,99,44,32,111,114,32,78,111, + 110,101,32,105,102,32,110,111,116,32,102,111,117,110,100,46, + 10,32,32,32,32,32,32,32,32,70,114,71,0,0,0,114, + 28,0,0,0,114,104,0,0,0,114,209,0,0,0,122,9, + 116,114,121,105,110,103,32,123,125,41,1,90,9,118,101,114, + 98,111,115,105,116,121,78,122,25,112,111,115,115,105,98,108, + 101,32,110,97,109,101,115,112,97,99,101,32,102,111,114,32, + 123,125,41,22,114,41,0,0,0,114,49,0,0,0,114,44, + 0,0,0,114,4,0,0,0,114,55,0,0,0,114,0,1, + 0,0,114,50,0,0,0,114,58,1,0,0,218,11,95,102, + 105,108,108,95,99,97,99,104,101,114,9,0,0,0,114,61, + 1,0,0,114,105,0,0,0,114,60,1,0,0,114,38,0, + 0,0,114,57,1,0,0,114,54,0,0,0,114,51,1,0, + 0,114,56,0,0,0,114,134,0,0,0,114,149,0,0,0, + 114,183,0,0,0,114,178,0,0,0,41,14,114,118,0,0, + 0,114,139,0,0,0,114,202,0,0,0,90,12,105,115,95, + 110,97,109,101,115,112,97,99,101,90,11,116,97,105,108,95, + 109,111,100,117,108,101,114,169,0,0,0,90,5,99,97,99, + 104,101,90,12,99,97,99,104,101,95,109,111,100,117,108,101, + 90,9,98,97,115,101,95,112,97,116,104,114,8,1,0,0, + 114,188,0,0,0,90,13,105,110,105,116,95,102,105,108,101, + 110,97,109,101,90,9,102,117,108,108,95,112,97,116,104,114, + 187,0,0,0,114,5,0,0,0,114,5,0,0,0,114,8, + 0,0,0,114,203,0,0,0,136,5,0,0,115,72,0,0, + 0,0,5,4,1,14,1,2,1,24,1,12,1,10,1,10, + 1,8,1,6,2,6,1,6,1,10,2,6,1,4,2,8, + 1,12,1,14,1,8,1,10,1,8,1,26,4,8,2,14, + 1,16,1,16,1,12,1,8,1,10,1,4,255,10,2,6, + 1,12,1,12,1,8,1,4,1,122,20,70,105,108,101,70, + 105,110,100,101,114,46,102,105,110,100,95,115,112,101,99,99, + 1,0,0,0,0,0,0,0,0,0,0,0,9,0,0,0, + 10,0,0,0,67,0,0,0,115,188,0,0,0,124,0,106, + 0,125,1,122,22,116,1,160,2,124,1,112,22,116,1,160, + 3,161,0,161,1,125,2,87,0,110,28,4,0,116,4,116, + 5,116,6,102,3,121,56,1,0,1,0,1,0,103,0,125, + 2,89,0,110,2,48,0,116,7,106,8,160,9,100,1,161, + 1,115,82,116,10,124,2,131,1,124,0,95,11,110,74,116, + 10,131,0,125,3,124,2,68,0,93,56,125,4,124,4,160, + 12,100,2,161,1,92,3,125,5,125,6,125,7,124,6,114, + 134,100,3,160,13,124,5,124,7,160,14,161,0,161,2,125, + 8,110,4,124,5,125,8,124,3,160,15,124,8,161,1,1, + 0,113,92,124,3,124,0,95,11,116,7,106,8,160,9,116, + 16,161,1,114,184,100,4,100,5,132,0,124,2,68,0,131, + 1,124,0,95,17,100,6,83,0,41,7,122,68,70,105,108, + 108,32,116,104,101,32,99,97,99,104,101,32,111,102,32,112, + 111,116,101,110,116,105,97,108,32,109,111,100,117,108,101,115, + 32,97,110,100,32,112,97,99,107,97,103,101,115,32,102,111, + 114,32,116,104,105,115,32,100,105,114,101,99,116,111,114,121, + 46,114,0,0,0,0,114,71,0,0,0,114,61,0,0,0, + 99,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0, + 0,4,0,0,0,83,0,0,0,115,20,0,0,0,104,0, + 124,0,93,12,125,1,124,1,160,0,161,0,146,2,113,4, + 83,0,114,5,0,0,0,41,1,114,105,0,0,0,41,2, + 114,32,0,0,0,90,2,102,110,114,5,0,0,0,114,5, + 0,0,0,114,8,0,0,0,218,9,60,115,101,116,99,111, + 109,112,62,213,5,0,0,114,56,1,0,0,122,41,70,105, + 108,101,70,105,110,100,101,114,46,95,102,105,108,108,95,99, + 97,99,104,101,46,60,108,111,99,97,108,115,62,46,60,115, + 101,116,99,111,109,112,62,78,41,18,114,44,0,0,0,114, + 4,0,0,0,90,7,108,105,115,116,100,105,114,114,55,0, + 0,0,114,45,1,0,0,218,15,80,101,114,109,105,115,115, + 105,111,110,69,114,114,111,114,218,18,78,111,116,65,68,105, + 114,101,99,116,111,114,121,69,114,114,111,114,114,1,0,0, + 0,114,10,0,0,0,114,11,0,0,0,114,59,1,0,0, + 114,60,1,0,0,114,100,0,0,0,114,62,0,0,0,114, + 105,0,0,0,218,3,97,100,100,114,12,0,0,0,114,61, + 1,0,0,41,9,114,118,0,0,0,114,44,0,0,0,90, + 8,99,111,110,116,101,110,116,115,90,21,108,111,119,101,114, + 95,115,117,102,102,105,120,95,99,111,110,116,101,110,116,115, + 114,33,1,0,0,114,116,0,0,0,114,20,1,0,0,114, + 8,1,0,0,90,8,110,101,119,95,110,97,109,101,114,5, + 0,0,0,114,5,0,0,0,114,8,0,0,0,114,63,1, + 0,0,184,5,0,0,115,34,0,0,0,0,2,6,1,2, + 1,22,1,18,3,10,3,12,1,12,7,6,1,8,1,16, + 1,4,1,18,2,4,1,12,1,6,1,12,1,122,22,70, + 105,108,101,70,105,110,100,101,114,46,95,102,105,108,108,95, + 99,97,99,104,101,99,1,0,0,0,0,0,0,0,0,0, + 0,0,3,0,0,0,3,0,0,0,7,0,0,0,115,18, + 0,0,0,135,0,135,1,102,2,100,1,100,2,132,8,125, + 2,124,2,83,0,41,3,97,20,1,0,0,65,32,99,108, + 97,115,115,32,109,101,116,104,111,100,32,119,104,105,99,104, + 32,114,101,116,117,114,110,115,32,97,32,99,108,111,115,117, + 114,101,32,116,111,32,117,115,101,32,111,110,32,115,121,115, + 46,112,97,116,104,95,104,111,111,107,10,32,32,32,32,32, + 32,32,32,119,104,105,99,104,32,119,105,108,108,32,114,101, + 116,117,114,110,32,97,110,32,105,110,115,116,97,110,99,101, + 32,117,115,105,110,103,32,116,104,101,32,115,112,101,99,105, + 102,105,101,100,32,108,111,97,100,101,114,115,32,97,110,100, + 32,116,104,101,32,112,97,116,104,10,32,32,32,32,32,32, + 32,32,99,97,108,108,101,100,32,111,110,32,116,104,101,32, + 99,108,111,115,117,114,101,46,10,10,32,32,32,32,32,32, + 32,32,73,102,32,116,104,101,32,112,97,116,104,32,99,97, + 108,108,101,100,32,111,110,32,116,104,101,32,99,108,111,115, + 117,114,101,32,105,115,32,110,111,116,32,97,32,100,105,114, + 101,99,116,111,114,121,44,32,73,109,112,111,114,116,69,114, + 114,111,114,32,105,115,10,32,32,32,32,32,32,32,32,114, + 97,105,115,101,100,46,10,10,32,32,32,32,32,32,32,32, + 99,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0, + 0,4,0,0,0,19,0,0,0,115,36,0,0,0,116,0, + 124,0,131,1,115,20,116,1,100,1,124,0,100,2,141,2, + 130,1,136,0,124,0,103,1,136,1,162,1,82,0,142,0, + 83,0,41,3,122,45,80,97,116,104,32,104,111,111,107,32, + 102,111,114,32,105,109,112,111,114,116,108,105,98,46,109,97, + 99,104,105,110,101,114,121,46,70,105,108,101,70,105,110,100, + 101,114,46,122,30,111,110,108,121,32,100,105,114,101,99,116, + 111,114,105,101,115,32,97,114,101,32,115,117,112,112,111,114, + 116,101,100,114,48,0,0,0,41,2,114,56,0,0,0,114, + 117,0,0,0,114,48,0,0,0,169,2,114,193,0,0,0, + 114,62,1,0,0,114,5,0,0,0,114,8,0,0,0,218, + 24,112,97,116,104,95,104,111,111,107,95,102,111,114,95,70, + 105,108,101,70,105,110,100,101,114,225,5,0,0,115,6,0, + 0,0,0,2,8,1,12,1,122,54,70,105,108,101,70,105, + 110,100,101,114,46,112,97,116,104,95,104,111,111,107,46,60, + 108,111,99,97,108,115,62,46,112,97,116,104,95,104,111,111, + 107,95,102,111,114,95,70,105,108,101,70,105,110,100,101,114, + 114,5,0,0,0,41,3,114,193,0,0,0,114,62,1,0, + 0,114,69,1,0,0,114,5,0,0,0,114,68,1,0,0, + 114,8,0,0,0,218,9,112,97,116,104,95,104,111,111,107, + 215,5,0,0,115,4,0,0,0,0,10,14,6,122,20,70, + 105,108,101,70,105,110,100,101,114,46,112,97,116,104,95,104, + 111,111,107,99,1,0,0,0,0,0,0,0,0,0,0,0, + 1,0,0,0,3,0,0,0,67,0,0,0,115,12,0,0, + 0,100,1,160,0,124,0,106,1,161,1,83,0,41,2,78, + 122,16,70,105,108,101,70,105,110,100,101,114,40,123,33,114, + 125,41,41,2,114,62,0,0,0,114,44,0,0,0,114,246, + 0,0,0,114,5,0,0,0,114,5,0,0,0,114,8,0, + 0,0,114,31,1,0,0,233,5,0,0,115,2,0,0,0, + 0,1,122,19,70,105,108,101,70,105,110,100,101,114,46,95, + 95,114,101,112,114,95,95,41,1,78,41,15,114,125,0,0, + 0,114,124,0,0,0,114,126,0,0,0,114,127,0,0,0, + 114,209,0,0,0,114,38,1,0,0,114,143,0,0,0,114, + 206,0,0,0,114,137,0,0,0,114,51,1,0,0,114,203, + 0,0,0,114,63,1,0,0,114,207,0,0,0,114,70,1, + 0,0,114,31,1,0,0,114,5,0,0,0,114,5,0,0, + 0,114,5,0,0,0,114,8,0,0,0,114,54,1,0,0, + 90,5,0,0,115,22,0,0,0,8,2,4,7,8,14,8, + 4,4,2,8,12,8,5,10,48,8,31,2,1,10,17,114, + 54,1,0,0,99,4,0,0,0,0,0,0,0,0,0,0, + 0,6,0,0,0,8,0,0,0,67,0,0,0,115,144,0, + 0,0,124,0,160,0,100,1,161,1,125,4,124,0,160,0, + 100,2,161,1,125,5,124,4,115,66,124,5,114,36,124,5, + 106,1,125,4,110,30,124,2,124,3,107,2,114,56,116,2, + 124,1,124,2,131,2,125,4,110,10,116,3,124,1,124,2, + 131,2,125,4,124,5,115,84,116,4,124,1,124,2,124,4, + 100,3,141,3,125,5,122,36,124,5,124,0,100,2,60,0, + 124,4,124,0,100,1,60,0,124,2,124,0,100,4,60,0, + 124,3,124,0,100,5,60,0,87,0,110,18,4,0,116,5, + 121,138,1,0,1,0,1,0,89,0,110,2,48,0,100,0, + 83,0,41,6,78,218,10,95,95,108,111,97,100,101,114,95, + 95,218,8,95,95,115,112,101,99,95,95,114,55,1,0,0, + 90,8,95,95,102,105,108,101,95,95,90,10,95,95,99,97, + 99,104,101,100,95,95,41,6,218,3,103,101,116,114,140,0, + 0,0,114,5,1,0,0,114,255,0,0,0,114,190,0,0, + 0,218,9,69,120,99,101,112,116,105,111,110,41,6,90,2, + 110,115,114,116,0,0,0,90,8,112,97,116,104,110,97,109, + 101,90,9,99,112,97,116,104,110,97,109,101,114,140,0,0, + 0,114,187,0,0,0,114,5,0,0,0,114,5,0,0,0, + 114,8,0,0,0,218,14,95,102,105,120,95,117,112,95,109, + 111,100,117,108,101,239,5,0,0,115,34,0,0,0,0,2, + 10,1,10,1,4,1,4,1,8,1,8,1,12,2,10,1, + 4,1,14,1,2,1,8,1,8,1,8,1,12,1,12,2, + 114,75,1,0,0,99,0,0,0,0,0,0,0,0,0,0, + 0,0,3,0,0,0,3,0,0,0,67,0,0,0,115,38, + 0,0,0,116,0,116,1,160,2,161,0,102,2,125,0,116, + 3,116,4,102,2,125,1,116,5,116,6,102,2,125,2,124, + 0,124,1,124,2,103,3,83,0,41,1,122,95,82,101,116, + 117,114,110,115,32,97,32,108,105,115,116,32,111,102,32,102, + 105,108,101,45,98,97,115,101,100,32,109,111,100,117,108,101, + 32,108,111,97,100,101,114,115,46,10,10,32,32,32,32,69, + 97,99,104,32,105,116,101,109,32,105,115,32,97,32,116,117, + 112,108,101,32,40,108,111,97,100,101,114,44,32,115,117,102, + 102,105,120,101,115,41,46,10,32,32,32,32,41,7,114,252, + 0,0,0,114,163,0,0,0,218,18,101,120,116,101,110,115, + 105,111,110,95,115,117,102,102,105,120,101,115,114,255,0,0, + 0,114,101,0,0,0,114,5,1,0,0,114,88,0,0,0, + 41,3,90,10,101,120,116,101,110,115,105,111,110,115,90,6, + 115,111,117,114,99,101,90,8,98,121,116,101,99,111,100,101, + 114,5,0,0,0,114,5,0,0,0,114,8,0,0,0,114, + 184,0,0,0,6,6,0,0,115,8,0,0,0,0,5,12, + 1,8,1,8,1,114,184,0,0,0,99,1,0,0,0,0, + 0,0,0,0,0,0,0,10,0,0,0,9,0,0,0,67, + 0,0,0,115,132,1,0,0,124,0,97,0,116,0,106,1, + 97,1,116,0,106,2,97,2,116,1,106,3,116,4,25,0, + 125,1,100,1,100,2,103,1,102,2,100,3,100,4,100,2, + 103,2,102,2,102,2,125,2,124,2,68,0,93,108,92,2, + 125,3,125,4,116,5,100,5,100,6,132,0,124,4,68,0, + 131,1,131,1,115,82,74,0,130,1,124,4,100,7,25,0, + 125,5,124,3,116,1,106,3,118,0,114,116,116,1,106,3, + 124,3,25,0,125,6,1,0,113,170,113,52,122,20,116,0, + 160,6,124,3,161,1,125,6,87,0,1,0,113,170,87,0, + 113,52,4,0,116,7,121,158,1,0,1,0,1,0,89,0, + 113,52,89,0,113,52,48,0,113,52,116,7,100,8,131,1, + 130,1,116,8,124,1,100,9,124,6,131,3,1,0,116,8, + 124,1,100,10,124,5,131,3,1,0,116,8,124,1,100,11, + 100,12,160,9,124,4,161,1,131,3,1,0,116,8,124,1, + 100,13,100,14,100,15,132,0,124,4,68,0,131,1,131,3, + 1,0,103,0,100,16,162,1,125,7,124,3,100,3,107,2, + 144,1,114,6,124,7,160,10,100,17,161,1,1,0,124,7, + 68,0,93,52,125,8,124,8,116,1,106,3,118,1,144,1, + 114,38,116,0,160,6,124,8,161,1,125,9,110,10,116,1, + 106,3,124,8,25,0,125,9,116,8,124,1,124,8,124,9, + 131,3,1,0,144,1,113,10,116,8,124,1,100,18,116,11, + 131,0,131,3,1,0,116,12,160,13,116,2,160,14,161,0, + 161,1,1,0,124,3,100,3,107,2,144,1,114,128,116,15, + 160,10,100,19,161,1,1,0,100,20,116,12,118,0,144,1, + 114,128,100,21,116,16,95,17,100,22,83,0,41,23,122,205, + 83,101,116,117,112,32,116,104,101,32,112,97,116,104,45,98, + 97,115,101,100,32,105,109,112,111,114,116,101,114,115,32,102, + 111,114,32,105,109,112,111,114,116,108,105,98,32,98,121,32, + 105,109,112,111,114,116,105,110,103,32,110,101,101,100,101,100, + 10,32,32,32,32,98,117,105,108,116,45,105,110,32,109,111, + 100,117,108,101,115,32,97,110,100,32,105,110,106,101,99,116, + 105,110,103,32,116,104,101,109,32,105,110,116,111,32,116,104, + 101,32,103,108,111,98,97,108,32,110,97,109,101,115,112,97, + 99,101,46,10,10,32,32,32,32,79,116,104,101,114,32,99, + 111,109,112,111,110,101,110,116,115,32,97,114,101,32,101,120, + 116,114,97,99,116,101,100,32,102,114,111,109,32,116,104,101, + 32,99,111,114,101,32,98,111,111,116,115,116,114,97,112,32, + 109,111,100,117,108,101,46,10,10,32,32,32,32,90,5,112, + 111,115,105,120,250,1,47,90,2,110,116,250,1,92,99,1, + 0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,3, + 0,0,0,115,0,0,0,115,26,0,0,0,124,0,93,18, + 125,1,116,0,124,1,131,1,100,0,107,2,86,0,1,0, + 113,2,100,1,83,0,41,2,114,39,0,0,0,78,41,1, + 114,23,0,0,0,41,2,114,32,0,0,0,114,94,0,0, + 0,114,5,0,0,0,114,5,0,0,0,114,8,0,0,0, + 114,10,1,0,0,35,6,0,0,114,56,1,0,0,122,25, + 95,115,101,116,117,112,46,60,108,111,99,97,108,115,62,46, + 60,103,101,110,101,120,112,114,62,114,73,0,0,0,122,30, + 105,109,112,111,114,116,108,105,98,32,114,101,113,117,105,114, + 101,115,32,112,111,115,105,120,32,111,114,32,110,116,114,4, + 0,0,0,114,35,0,0,0,114,31,0,0,0,114,40,0, + 0,0,114,58,0,0,0,99,1,0,0,0,0,0,0,0, + 0,0,0,0,2,0,0,0,4,0,0,0,83,0,0,0, + 115,22,0,0,0,104,0,124,0,93,14,125,1,100,0,124, + 1,155,0,157,2,146,2,113,4,83,0,41,1,114,74,0, + 0,0,114,5,0,0,0,41,2,114,32,0,0,0,218,1, + 115,114,5,0,0,0,114,5,0,0,0,114,8,0,0,0, + 114,64,1,0,0,52,6,0,0,114,56,1,0,0,122,25, + 95,115,101,116,117,112,46,60,108,111,99,97,108,115,62,46, + 60,115,101,116,99,111,109,112,62,41,3,114,64,0,0,0, + 114,75,0,0,0,114,160,0,0,0,114,192,0,0,0,114, + 9,0,0,0,122,4,46,112,121,119,122,6,95,100,46,112, + 121,100,84,78,41,18,114,134,0,0,0,114,1,0,0,0, + 114,163,0,0,0,114,22,1,0,0,114,125,0,0,0,218, + 3,97,108,108,90,18,95,98,117,105,108,116,105,110,95,102, + 114,111,109,95,110,97,109,101,114,117,0,0,0,114,129,0, + 0,0,114,36,0,0,0,114,186,0,0,0,114,14,0,0, + 0,114,12,1,0,0,114,167,0,0,0,114,76,1,0,0, + 114,101,0,0,0,114,191,0,0,0,114,195,0,0,0,41, + 10,218,17,95,98,111,111,116,115,116,114,97,112,95,109,111, + 100,117,108,101,90,11,115,101,108,102,95,109,111,100,117,108, + 101,90,10,111,115,95,100,101,116,97,105,108,115,90,10,98, + 117,105,108,116,105,110,95,111,115,114,31,0,0,0,114,35, + 0,0,0,90,9,111,115,95,109,111,100,117,108,101,90,13, + 98,117,105,108,116,105,110,95,110,97,109,101,115,90,12,98, + 117,105,108,116,105,110,95,110,97,109,101,90,14,98,117,105, + 108,116,105,110,95,109,111,100,117,108,101,114,5,0,0,0, + 114,5,0,0,0,114,8,0,0,0,218,6,95,115,101,116, + 117,112,17,6,0,0,115,70,0,0,0,0,8,4,1,6, + 1,6,2,10,3,22,1,12,2,22,1,8,1,10,1,10, + 1,6,2,2,1,10,1,10,1,12,1,12,2,8,2,12, + 1,12,1,18,1,22,3,8,1,10,1,10,1,8,1,12, + 1,12,2,10,1,16,3,14,1,14,1,10,1,10,1,10, + 1,114,82,1,0,0,99,1,0,0,0,0,0,0,0,0, + 0,0,0,2,0,0,0,4,0,0,0,67,0,0,0,115, + 50,0,0,0,116,0,124,0,131,1,1,0,116,1,131,0, + 125,1,116,2,106,3,160,4,116,5,106,6,124,1,142,0, + 103,1,161,1,1,0,116,2,106,7,160,8,116,9,161,1, + 1,0,100,1,83,0,41,2,122,41,73,110,115,116,97,108, + 108,32,116,104,101,32,112,97,116,104,45,98,97,115,101,100, + 32,105,109,112,111,114,116,32,99,111,109,112,111,110,101,110, + 116,115,46,78,41,10,114,82,1,0,0,114,184,0,0,0, + 114,1,0,0,0,114,43,1,0,0,114,167,0,0,0,114, + 54,1,0,0,114,70,1,0,0,218,9,109,101,116,97,95, + 112,97,116,104,114,186,0,0,0,114,37,1,0,0,41,2, + 114,81,1,0,0,90,17,115,117,112,112,111,114,116,101,100, + 95,108,111,97,100,101,114,115,114,5,0,0,0,114,5,0, + 0,0,114,8,0,0,0,218,8,95,105,110,115,116,97,108, + 108,74,6,0,0,115,8,0,0,0,0,2,8,1,6,1, + 20,1,114,84,1,0,0,41,1,114,60,0,0,0,41,1, + 78,41,3,78,78,78,41,2,114,73,0,0,0,114,73,0, + 0,0,41,1,84,41,1,78,41,1,78,41,63,114,127,0, + 0,0,114,13,0,0,0,90,37,95,67,65,83,69,95,73, + 78,83,69,78,83,73,84,73,86,69,95,80,76,65,84,70, + 79,82,77,83,95,66,89,84,69,83,95,75,69,89,114,12, + 0,0,0,114,14,0,0,0,114,21,0,0,0,114,27,0, + 0,0,114,29,0,0,0,114,38,0,0,0,114,47,0,0, + 0,114,49,0,0,0,114,53,0,0,0,114,54,0,0,0, + 114,56,0,0,0,114,59,0,0,0,114,69,0,0,0,218, + 4,116,121,112,101,218,8,95,95,99,111,100,101,95,95,114, + 162,0,0,0,114,19,0,0,0,114,148,0,0,0,114,18, + 0,0,0,114,24,0,0,0,114,236,0,0,0,114,91,0, + 0,0,114,87,0,0,0,114,101,0,0,0,114,88,0,0, + 0,90,23,68,69,66,85,71,95,66,89,84,69,67,79,68, + 69,95,83,85,70,70,73,88,69,83,90,27,79,80,84,73, + 77,73,90,69,68,95,66,89,84,69,67,79,68,69,95,83, + 85,70,70,73,88,69,83,114,97,0,0,0,114,102,0,0, + 0,114,108,0,0,0,114,112,0,0,0,114,114,0,0,0, + 114,136,0,0,0,114,143,0,0,0,114,152,0,0,0,114, + 156,0,0,0,114,158,0,0,0,114,165,0,0,0,114,170, + 0,0,0,114,171,0,0,0,114,176,0,0,0,218,6,111, + 98,106,101,99,116,114,185,0,0,0,114,190,0,0,0,114, + 191,0,0,0,114,208,0,0,0,114,221,0,0,0,114,239, + 0,0,0,114,255,0,0,0,114,5,1,0,0,114,12,1, + 0,0,114,252,0,0,0,114,13,1,0,0,114,35,1,0, + 0,114,37,1,0,0,114,54,1,0,0,114,75,1,0,0, + 114,184,0,0,0,114,82,1,0,0,114,84,1,0,0,114, + 5,0,0,0,114,5,0,0,0,114,5,0,0,0,114,8, + 0,0,0,218,8,60,109,111,100,117,108,101,62,1,0,0, + 0,115,126,0,0,0,4,22,4,1,4,1,2,1,2,255, + 4,4,8,17,8,5,8,5,8,6,8,6,8,12,8,10, + 8,9,8,5,8,7,8,9,10,22,10,127,0,20,16,1, + 12,2,4,1,4,2,6,2,6,2,8,2,16,71,8,40, + 8,19,8,12,8,12,8,28,8,17,8,33,8,28,8,24, + 10,13,10,10,10,11,8,14,6,3,4,1,2,255,12,68, + 14,64,14,29,16,127,0,17,14,50,18,45,18,26,4,3, + 18,53,14,63,14,42,14,127,0,20,14,127,0,22,10,23, + 8,11,8,57, }; diff --git a/Python/importlib_zipimport.h b/Python/importlib_zipimport.h index 373b1366bde..be7d24fe1df 100644 --- a/Python/importlib_zipimport.h +++ b/Python/importlib_zipimport.h @@ -1,7 +1,7 @@ /* Auto-generated by Programs/_freeze_importlib.c */ const unsigned char _Py_M__zipimport[] = { 99,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,4,0,0,0,64,0,0,0,115,82,1,0,0,100,0, + 0,4,0,0,0,64,0,0,0,115,68,1,0,0,100,0, 90,0,100,1,100,2,108,1,90,2,100,1,100,3,108,1, 109,3,90,3,109,4,90,4,1,0,100,1,100,2,108,5, 90,6,100,1,100,2,108,7,90,7,100,1,100,2,108,8, @@ -21,1059 +21,941 @@ const unsigned char _Py_M__zipimport[] = { 132,0,90,35,101,19,101,35,106,36,131,1,90,37,100,35, 100,36,132,0,90,38,100,37,100,38,132,0,90,39,100,39, 100,40,132,0,90,40,100,41,100,42,132,0,90,41,100,43, - 100,44,132,0,90,42,100,45,100,46,132,0,90,43,71,0, - 100,47,100,48,132,0,100,48,131,2,90,44,100,2,83,0, - 41,49,97,80,2,0,0,122,105,112,105,109,112,111,114,116, - 32,112,114,111,118,105,100,101,115,32,115,117,112,112,111,114, - 116,32,102,111,114,32,105,109,112,111,114,116,105,110,103,32, - 80,121,116,104,111,110,32,109,111,100,117,108,101,115,32,102, - 114,111,109,32,90,105,112,32,97,114,99,104,105,118,101,115, - 46,10,10,84,104,105,115,32,109,111,100,117,108,101,32,101, - 120,112,111,114,116,115,32,116,104,114,101,101,32,111,98,106, - 101,99,116,115,58,10,45,32,122,105,112,105,109,112,111,114, - 116,101,114,58,32,97,32,99,108,97,115,115,59,32,105,116, - 115,32,99,111,110,115,116,114,117,99,116,111,114,32,116,97, - 107,101,115,32,97,32,112,97,116,104,32,116,111,32,97,32, - 90,105,112,32,97,114,99,104,105,118,101,46,10,45,32,90, - 105,112,73,109,112,111,114,116,69,114,114,111,114,58,32,101, - 120,99,101,112,116,105,111,110,32,114,97,105,115,101,100,32, - 98,121,32,122,105,112,105,109,112,111,114,116,101,114,32,111, - 98,106,101,99,116,115,46,32,73,116,39,115,32,97,10,32, - 32,115,117,98,99,108,97,115,115,32,111,102,32,73,109,112, - 111,114,116,69,114,114,111,114,44,32,115,111,32,105,116,32, - 99,97,110,32,98,101,32,99,97,117,103,104,116,32,97,115, - 32,73,109,112,111,114,116,69,114,114,111,114,44,32,116,111, - 111,46,10,45,32,95,122,105,112,95,100,105,114,101,99,116, - 111,114,121,95,99,97,99,104,101,58,32,97,32,100,105,99, - 116,44,32,109,97,112,112,105,110,103,32,97,114,99,104,105, - 118,101,32,112,97,116,104,115,32,116,111,32,122,105,112,32, - 100,105,114,101,99,116,111,114,121,10,32,32,105,110,102,111, - 32,100,105,99,116,115,44,32,97,115,32,117,115,101,100,32, - 105,110,32,122,105,112,105,109,112,111,114,116,101,114,46,95, - 102,105,108,101,115,46,10,10,73,116,32,105,115,32,117,115, - 117,97,108,108,121,32,110,111,116,32,110,101,101,100,101,100, - 32,116,111,32,117,115,101,32,116,104,101,32,122,105,112,105, - 109,112,111,114,116,32,109,111,100,117,108,101,32,101,120,112, - 108,105,99,105,116,108,121,59,32,105,116,32,105,115,10,117, - 115,101,100,32,98,121,32,116,104,101,32,98,117,105,108,116, - 105,110,32,105,109,112,111,114,116,32,109,101,99,104,97,110, - 105,115,109,32,102,111,114,32,115,121,115,46,112,97,116,104, - 32,105,116,101,109,115,32,116,104,97,116,32,97,114,101,32, - 112,97,116,104,115,10,116,111,32,90,105,112,32,97,114,99, - 104,105,118,101,115,46,10,233,0,0,0,0,78,41,2,218, - 14,95,117,110,112,97,99,107,95,117,105,110,116,49,54,218, - 14,95,117,110,112,97,99,107,95,117,105,110,116,51,50,218, - 14,90,105,112,73,109,112,111,114,116,69,114,114,111,114,218, - 11,122,105,112,105,109,112,111,114,116,101,114,233,1,0,0, - 0,99,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,1,0,0,0,64,0,0,0,115,12,0,0,0,101, - 0,90,1,100,0,90,2,100,1,83,0,41,2,114,3,0, - 0,0,78,41,3,218,8,95,95,110,97,109,101,95,95,218, - 10,95,95,109,111,100,117,108,101,95,95,218,12,95,95,113, - 117,97,108,110,97,109,101,95,95,169,0,114,9,0,0,0, - 114,9,0,0,0,250,18,60,102,114,111,122,101,110,32,122, - 105,112,105,109,112,111,114,116,62,114,3,0,0,0,33,0, - 0,0,115,2,0,0,0,8,1,233,22,0,0,0,115,4, - 0,0,0,80,75,5,6,105,255,255,0,0,99,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0, - 0,64,0,0,0,115,108,0,0,0,101,0,90,1,100,0, - 90,2,100,1,90,3,100,2,100,3,132,0,90,4,100,25, - 100,5,100,6,132,1,90,5,100,26,100,7,100,8,132,1, - 90,6,100,9,100,10,132,0,90,7,100,11,100,12,132,0, - 90,8,100,13,100,14,132,0,90,9,100,15,100,16,132,0, - 90,10,100,17,100,18,132,0,90,11,100,19,100,20,132,0, - 90,12,100,21,100,22,132,0,90,13,100,23,100,24,132,0, - 90,14,100,4,83,0,41,27,114,4,0,0,0,97,255,1, - 0,0,122,105,112,105,109,112,111,114,116,101,114,40,97,114, - 99,104,105,118,101,112,97,116,104,41,32,45,62,32,122,105, - 112,105,109,112,111,114,116,101,114,32,111,98,106,101,99,116, - 10,10,32,32,32,32,67,114,101,97,116,101,32,97,32,110, - 101,119,32,122,105,112,105,109,112,111,114,116,101,114,32,105, - 110,115,116,97,110,99,101,46,32,39,97,114,99,104,105,118, - 101,112,97,116,104,39,32,109,117,115,116,32,98,101,32,97, - 32,112,97,116,104,32,116,111,10,32,32,32,32,97,32,122, - 105,112,102,105,108,101,44,32,111,114,32,116,111,32,97,32, - 115,112,101,99,105,102,105,99,32,112,97,116,104,32,105,110, - 115,105,100,101,32,97,32,122,105,112,102,105,108,101,46,32, - 70,111,114,32,101,120,97,109,112,108,101,44,32,105,116,32, - 99,97,110,32,98,101,10,32,32,32,32,39,47,116,109,112, - 47,109,121,105,109,112,111,114,116,46,122,105,112,39,44,32, - 111,114,32,39,47,116,109,112,47,109,121,105,109,112,111,114, - 116,46,122,105,112,47,109,121,100,105,114,101,99,116,111,114, - 121,39,44,32,105,102,32,109,121,100,105,114,101,99,116,111, - 114,121,32,105,115,32,97,10,32,32,32,32,118,97,108,105, - 100,32,100,105,114,101,99,116,111,114,121,32,105,110,115,105, - 100,101,32,116,104,101,32,97,114,99,104,105,118,101,46,10, - 10,32,32,32,32,39,90,105,112,73,109,112,111,114,116,69, - 114,114,111,114,32,105,115,32,114,97,105,115,101,100,32,105, - 102,32,39,97,114,99,104,105,118,101,112,97,116,104,39,32, - 100,111,101,115,110,39,116,32,112,111,105,110,116,32,116,111, - 32,97,32,118,97,108,105,100,32,90,105,112,10,32,32,32, - 32,97,114,99,104,105,118,101,46,10,10,32,32,32,32,84, - 104,101,32,39,97,114,99,104,105,118,101,39,32,97,116,116, - 114,105,98,117,116,101,32,111,102,32,122,105,112,105,109,112, - 111,114,116,101,114,32,111,98,106,101,99,116,115,32,99,111, - 110,116,97,105,110,115,32,116,104,101,32,110,97,109,101,32, - 111,102,32,116,104,101,10,32,32,32,32,122,105,112,102,105, - 108,101,32,116,97,114,103,101,116,101,100,46,10,32,32,32, - 32,99,2,0,0,0,0,0,0,0,0,0,0,0,8,0, - 0,0,9,0,0,0,67,0,0,0,115,32,1,0,0,116, - 0,124,1,116,1,131,2,115,28,100,1,100,0,108,2,125, - 2,124,2,160,3,124,1,161,1,125,1,124,1,115,44,116, - 4,100,2,124,1,100,3,141,2,130,1,116,5,114,60,124, - 1,160,6,116,5,116,7,161,2,125,1,103,0,125,3,122, - 14,116,8,160,9,124,1,161,1,125,4,87,0,110,70,4, - 0,116,10,116,11,102,2,121,148,1,0,1,0,1,0,116, - 8,160,12,124,1,161,1,92,2,125,5,125,6,124,5,124, - 1,107,2,114,130,116,4,100,4,124,1,100,3,141,2,130, - 1,124,5,125,1,124,3,160,13,124,6,161,1,1,0,89, - 0,113,64,48,0,124,4,106,14,100,5,64,0,100,6,107, - 3,114,180,116,4,100,4,124,1,100,3,141,2,130,1,113, - 180,113,64,122,12,116,15,124,1,25,0,125,7,87,0,110, - 34,4,0,116,16,121,226,1,0,1,0,1,0,116,17,124, - 1,131,1,125,7,124,7,116,15,124,1,60,0,89,0,110, - 2,48,0,124,7,124,0,95,18,124,1,124,0,95,19,116, - 8,106,20,124,3,100,0,100,0,100,7,133,3,25,0,142, - 0,124,0,95,21,124,0,106,21,144,1,114,28,124,0,4, - 0,106,21,116,7,55,0,2,0,95,21,100,0,83,0,41, - 8,78,114,0,0,0,0,122,21,97,114,99,104,105,118,101, - 32,112,97,116,104,32,105,115,32,101,109,112,116,121,169,1, - 218,4,112,97,116,104,122,14,110,111,116,32,97,32,90,105, - 112,32,102,105,108,101,105,0,240,0,0,105,0,128,0,0, - 233,255,255,255,255,41,22,218,10,105,115,105,110,115,116,97, - 110,99,101,218,3,115,116,114,218,2,111,115,90,8,102,115, - 100,101,99,111,100,101,114,3,0,0,0,218,12,97,108,116, - 95,112,97,116,104,95,115,101,112,218,7,114,101,112,108,97, - 99,101,218,8,112,97,116,104,95,115,101,112,218,19,95,98, - 111,111,116,115,116,114,97,112,95,101,120,116,101,114,110,97, - 108,90,10,95,112,97,116,104,95,115,116,97,116,218,7,79, - 83,69,114,114,111,114,218,10,86,97,108,117,101,69,114,114, - 111,114,90,11,95,112,97,116,104,95,115,112,108,105,116,218, - 6,97,112,112,101,110,100,90,7,115,116,95,109,111,100,101, - 218,20,95,122,105,112,95,100,105,114,101,99,116,111,114,121, - 95,99,97,99,104,101,218,8,75,101,121,69,114,114,111,114, - 218,15,95,114,101,97,100,95,100,105,114,101,99,116,111,114, - 121,218,6,95,102,105,108,101,115,218,7,97,114,99,104,105, - 118,101,218,10,95,112,97,116,104,95,106,111,105,110,218,6, - 112,114,101,102,105,120,41,8,218,4,115,101,108,102,114,13, - 0,0,0,114,17,0,0,0,114,31,0,0,0,90,2,115, - 116,90,7,100,105,114,110,97,109,101,90,8,98,97,115,101, - 110,97,109,101,218,5,102,105,108,101,115,114,9,0,0,0, - 114,9,0,0,0,114,10,0,0,0,218,8,95,95,105,110, - 105,116,95,95,63,0,0,0,115,58,0,0,0,0,1,10, - 1,8,1,10,1,4,1,12,1,4,1,12,2,4,2,2, - 1,14,1,16,3,14,1,8,1,12,1,4,1,16,3,14, - 2,12,1,4,2,2,1,12,1,12,1,8,1,14,1,6, - 1,6,2,22,1,8,1,122,20,122,105,112,105,109,112,111, - 114,116,101,114,46,95,95,105,110,105,116,95,95,78,99,3, - 0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,4, - 0,0,0,67,0,0,0,115,78,0,0,0,116,0,124,0, - 124,1,131,2,125,3,124,3,100,1,117,1,114,26,124,0, - 103,0,102,2,83,0,116,1,124,0,124,1,131,2,125,4, - 116,2,124,0,124,4,131,2,114,70,100,1,124,0,106,3, - 155,0,116,4,155,0,124,4,155,0,157,3,103,1,102,2, - 83,0,100,1,103,0,102,2,83,0,41,2,97,239,1,0, - 0,102,105,110,100,95,108,111,97,100,101,114,40,102,117,108, - 108,110,97,109,101,44,32,112,97,116,104,61,78,111,110,101, - 41,32,45,62,32,115,101,108,102,44,32,115,116,114,32,111, - 114,32,78,111,110,101,46,10,10,32,32,32,32,32,32,32, - 32,83,101,97,114,99,104,32,102,111,114,32,97,32,109,111, - 100,117,108,101,32,115,112,101,99,105,102,105,101,100,32,98, - 121,32,39,102,117,108,108,110,97,109,101,39,46,32,39,102, - 117,108,108,110,97,109,101,39,32,109,117,115,116,32,98,101, - 32,116,104,101,10,32,32,32,32,32,32,32,32,102,117,108, - 108,121,32,113,117,97,108,105,102,105,101,100,32,40,100,111, - 116,116,101,100,41,32,109,111,100,117,108,101,32,110,97,109, - 101,46,32,73,116,32,114,101,116,117,114,110,115,32,116,104, - 101,32,122,105,112,105,109,112,111,114,116,101,114,10,32,32, - 32,32,32,32,32,32,105,110,115,116,97,110,99,101,32,105, - 116,115,101,108,102,32,105,102,32,116,104,101,32,109,111,100, - 117,108,101,32,119,97,115,32,102,111,117,110,100,44,32,97, - 32,115,116,114,105,110,103,32,99,111,110,116,97,105,110,105, - 110,103,32,116,104,101,10,32,32,32,32,32,32,32,32,102, - 117,108,108,32,112,97,116,104,32,110,97,109,101,32,105,102, - 32,105,116,39,115,32,112,111,115,115,105,98,108,121,32,97, - 32,112,111,114,116,105,111,110,32,111,102,32,97,32,110,97, - 109,101,115,112,97,99,101,32,112,97,99,107,97,103,101,44, - 10,32,32,32,32,32,32,32,32,111,114,32,78,111,110,101, - 32,111,116,104,101,114,119,105,115,101,46,32,84,104,101,32, - 111,112,116,105,111,110,97,108,32,39,112,97,116,104,39,32, - 97,114,103,117,109,101,110,116,32,105,115,32,105,103,110,111, - 114,101,100,32,45,45,32,105,116,39,115,10,32,32,32,32, - 32,32,32,32,116,104,101,114,101,32,102,111,114,32,99,111, - 109,112,97,116,105,98,105,108,105,116,121,32,119,105,116,104, - 32,116,104,101,32,105,109,112,111,114,116,101,114,32,112,114, - 111,116,111,99,111,108,46,10,32,32,32,32,32,32,32,32, - 78,41,5,218,16,95,103,101,116,95,109,111,100,117,108,101, - 95,105,110,102,111,218,16,95,103,101,116,95,109,111,100,117, - 108,101,95,112,97,116,104,218,7,95,105,115,95,100,105,114, - 114,29,0,0,0,114,20,0,0,0,41,5,114,32,0,0, - 0,218,8,102,117,108,108,110,97,109,101,114,13,0,0,0, - 218,2,109,105,218,7,109,111,100,112,97,116,104,114,9,0, - 0,0,114,9,0,0,0,114,10,0,0,0,218,11,102,105, - 110,100,95,108,111,97,100,101,114,109,0,0,0,115,14,0, - 0,0,0,10,10,1,8,2,8,7,10,1,10,4,24,2, - 122,23,122,105,112,105,109,112,111,114,116,101,114,46,102,105, - 110,100,95,108,111,97,100,101,114,99,3,0,0,0,0,0, - 0,0,0,0,0,0,3,0,0,0,4,0,0,0,67,0, - 0,0,115,16,0,0,0,124,0,160,0,124,1,124,2,161, - 2,100,1,25,0,83,0,41,2,97,139,1,0,0,102,105, - 110,100,95,109,111,100,117,108,101,40,102,117,108,108,110,97, - 109,101,44,32,112,97,116,104,61,78,111,110,101,41,32,45, - 62,32,115,101,108,102,32,111,114,32,78,111,110,101,46,10, - 10,32,32,32,32,32,32,32,32,83,101,97,114,99,104,32, - 102,111,114,32,97,32,109,111,100,117,108,101,32,115,112,101, - 99,105,102,105,101,100,32,98,121,32,39,102,117,108,108,110, - 97,109,101,39,46,32,39,102,117,108,108,110,97,109,101,39, - 32,109,117,115,116,32,98,101,32,116,104,101,10,32,32,32, - 32,32,32,32,32,102,117,108,108,121,32,113,117,97,108,105, - 102,105,101,100,32,40,100,111,116,116,101,100,41,32,109,111, - 100,117,108,101,32,110,97,109,101,46,32,73,116,32,114,101, - 116,117,114,110,115,32,116,104,101,32,122,105,112,105,109,112, - 111,114,116,101,114,10,32,32,32,32,32,32,32,32,105,110, - 115,116,97,110,99,101,32,105,116,115,101,108,102,32,105,102, - 32,116,104,101,32,109,111,100,117,108,101,32,119,97,115,32, - 102,111,117,110,100,44,32,111,114,32,78,111,110,101,32,105, - 102,32,105,116,32,119,97,115,110,39,116,46,10,32,32,32, - 32,32,32,32,32,84,104,101,32,111,112,116,105,111,110,97, - 108,32,39,112,97,116,104,39,32,97,114,103,117,109,101,110, - 116,32,105,115,32,105,103,110,111,114,101,100,32,45,45,32, - 105,116,39,115,32,116,104,101,114,101,32,102,111,114,32,99, - 111,109,112,97,116,105,98,105,108,105,116,121,10,32,32,32, - 32,32,32,32,32,119,105,116,104,32,116,104,101,32,105,109, - 112,111,114,116,101,114,32,112,114,111,116,111,99,111,108,46, - 10,32,32,32,32,32,32,32,32,114,0,0,0,0,41,1, - 114,41,0,0,0,41,3,114,32,0,0,0,114,38,0,0, - 0,114,13,0,0,0,114,9,0,0,0,114,9,0,0,0, - 114,10,0,0,0,218,11,102,105,110,100,95,109,111,100,117, - 108,101,141,0,0,0,115,2,0,0,0,0,9,122,23,122, - 105,112,105,109,112,111,114,116,101,114,46,102,105,110,100,95, - 109,111,100,117,108,101,99,2,0,0,0,0,0,0,0,0, - 0,0,0,5,0,0,0,3,0,0,0,67,0,0,0,115, - 20,0,0,0,116,0,124,0,124,1,131,2,92,3,125,2, - 125,3,125,4,124,2,83,0,41,1,122,163,103,101,116,95, - 99,111,100,101,40,102,117,108,108,110,97,109,101,41,32,45, - 62,32,99,111,100,101,32,111,98,106,101,99,116,46,10,10, - 32,32,32,32,32,32,32,32,82,101,116,117,114,110,32,116, - 104,101,32,99,111,100,101,32,111,98,106,101,99,116,32,102, - 111,114,32,116,104,101,32,115,112,101,99,105,102,105,101,100, - 32,109,111,100,117,108,101,46,32,82,97,105,115,101,32,90, - 105,112,73,109,112,111,114,116,69,114,114,111,114,10,32,32, - 32,32,32,32,32,32,105,102,32,116,104,101,32,109,111,100, - 117,108,101,32,99,111,117,108,100,110,39,116,32,98,101,32, - 102,111,117,110,100,46,10,32,32,32,32,32,32,32,32,169, - 1,218,16,95,103,101,116,95,109,111,100,117,108,101,95,99, - 111,100,101,169,5,114,32,0,0,0,114,38,0,0,0,218, - 4,99,111,100,101,218,9,105,115,112,97,99,107,97,103,101, - 114,40,0,0,0,114,9,0,0,0,114,9,0,0,0,114, - 10,0,0,0,218,8,103,101,116,95,99,111,100,101,153,0, - 0,0,115,4,0,0,0,0,6,16,1,122,20,122,105,112, - 105,109,112,111,114,116,101,114,46,103,101,116,95,99,111,100, - 101,99,2,0,0,0,0,0,0,0,0,0,0,0,4,0, - 0,0,8,0,0,0,67,0,0,0,115,116,0,0,0,116, - 0,114,16,124,1,160,1,116,0,116,2,161,2,125,1,124, - 1,125,2,124,1,160,3,124,0,106,4,116,2,23,0,161, - 1,114,58,124,1,116,5,124,0,106,4,116,2,23,0,131, - 1,100,1,133,2,25,0,125,2,122,14,124,0,106,6,124, - 2,25,0,125,3,87,0,110,30,4,0,116,7,121,102,1, - 0,1,0,1,0,116,8,100,2,100,3,124,2,131,3,130, - 1,89,0,110,2,48,0,116,9,124,0,106,4,124,3,131, - 2,83,0,41,4,122,154,103,101,116,95,100,97,116,97,40, - 112,97,116,104,110,97,109,101,41,32,45,62,32,115,116,114, - 105,110,103,32,119,105,116,104,32,102,105,108,101,32,100,97, - 116,97,46,10,10,32,32,32,32,32,32,32,32,82,101,116, - 117,114,110,32,116,104,101,32,100,97,116,97,32,97,115,115, - 111,99,105,97,116,101,100,32,119,105,116,104,32,39,112,97, - 116,104,110,97,109,101,39,46,32,82,97,105,115,101,32,79, - 83,69,114,114,111,114,32,105,102,10,32,32,32,32,32,32, - 32,32,116,104,101,32,102,105,108,101,32,119,97,115,110,39, - 116,32,102,111,117,110,100,46,10,32,32,32,32,32,32,32, - 32,78,114,0,0,0,0,218,0,41,10,114,18,0,0,0, - 114,19,0,0,0,114,20,0,0,0,218,10,115,116,97,114, - 116,115,119,105,116,104,114,29,0,0,0,218,3,108,101,110, - 114,28,0,0,0,114,26,0,0,0,114,22,0,0,0,218, - 9,95,103,101,116,95,100,97,116,97,41,4,114,32,0,0, - 0,218,8,112,97,116,104,110,97,109,101,90,3,107,101,121, - 218,9,116,111,99,95,101,110,116,114,121,114,9,0,0,0, - 114,9,0,0,0,114,10,0,0,0,218,8,103,101,116,95, - 100,97,116,97,163,0,0,0,115,20,0,0,0,0,6,4, - 1,12,2,4,1,16,1,22,2,2,1,14,1,12,1,18, - 1,122,20,122,105,112,105,109,112,111,114,116,101,114,46,103, - 101,116,95,100,97,116,97,99,2,0,0,0,0,0,0,0, - 0,0,0,0,5,0,0,0,3,0,0,0,67,0,0,0, - 115,20,0,0,0,116,0,124,0,124,1,131,2,92,3,125, - 2,125,3,125,4,124,4,83,0,41,1,122,106,103,101,116, - 95,102,105,108,101,110,97,109,101,40,102,117,108,108,110,97, - 109,101,41,32,45,62,32,102,105,108,101,110,97,109,101,32, - 115,116,114,105,110,103,46,10,10,32,32,32,32,32,32,32, - 32,82,101,116,117,114,110,32,116,104,101,32,102,105,108,101, - 110,97,109,101,32,102,111,114,32,116,104,101,32,115,112,101, - 99,105,102,105,101,100,32,109,111,100,117,108,101,46,10,32, - 32,32,32,32,32,32,32,114,43,0,0,0,114,45,0,0, - 0,114,9,0,0,0,114,9,0,0,0,114,10,0,0,0, - 218,12,103,101,116,95,102,105,108,101,110,97,109,101,184,0, - 0,0,115,4,0,0,0,0,7,16,1,122,24,122,105,112, - 105,109,112,111,114,116,101,114,46,103,101,116,95,102,105,108, - 101,110,97,109,101,99,2,0,0,0,0,0,0,0,0,0, - 0,0,6,0,0,0,8,0,0,0,67,0,0,0,115,126, - 0,0,0,116,0,124,0,124,1,131,2,125,2,124,2,100, - 1,117,0,114,36,116,1,100,2,124,1,155,2,157,2,124, - 1,100,3,141,2,130,1,116,2,124,0,124,1,131,2,125, - 3,124,2,114,64,116,3,160,4,124,3,100,4,161,2,125, - 4,110,10,124,3,155,0,100,5,157,2,125,4,122,14,124, - 0,106,5,124,4,25,0,125,5,87,0,110,20,4,0,116, - 6,121,108,1,0,1,0,1,0,89,0,100,1,83,0,48, - 0,116,7,124,0,106,8,124,5,131,2,160,9,161,0,83, - 0,41,6,122,253,103,101,116,95,115,111,117,114,99,101,40, - 102,117,108,108,110,97,109,101,41,32,45,62,32,115,111,117, - 114,99,101,32,115,116,114,105,110,103,46,10,10,32,32,32, - 32,32,32,32,32,82,101,116,117,114,110,32,116,104,101,32, - 115,111,117,114,99,101,32,99,111,100,101,32,102,111,114,32, - 116,104,101,32,115,112,101,99,105,102,105,101,100,32,109,111, - 100,117,108,101,46,32,82,97,105,115,101,32,90,105,112,73, - 109,112,111,114,116,69,114,114,111,114,10,32,32,32,32,32, - 32,32,32,105,102,32,116,104,101,32,109,111,100,117,108,101, - 32,99,111,117,108,100,110,39,116,32,98,101,32,102,111,117, - 110,100,44,32,114,101,116,117,114,110,32,78,111,110,101,32, - 105,102,32,116,104,101,32,97,114,99,104,105,118,101,32,100, - 111,101,115,10,32,32,32,32,32,32,32,32,99,111,110,116, - 97,105,110,32,116,104,101,32,109,111,100,117,108,101,44,32, - 98,117,116,32,104,97,115,32,110,111,32,115,111,117,114,99, - 101,32,102,111,114,32,105,116,46,10,32,32,32,32,32,32, - 32,32,78,250,18,99,97,110,39,116,32,102,105,110,100,32, - 109,111,100,117,108,101,32,169,1,218,4,110,97,109,101,250, - 11,95,95,105,110,105,116,95,95,46,112,121,250,3,46,112, - 121,41,10,114,35,0,0,0,114,3,0,0,0,114,36,0, - 0,0,114,21,0,0,0,114,30,0,0,0,114,28,0,0, - 0,114,26,0,0,0,114,52,0,0,0,114,29,0,0,0, - 218,6,100,101,99,111,100,101,41,6,114,32,0,0,0,114, - 38,0,0,0,114,39,0,0,0,114,13,0,0,0,218,8, - 102,117,108,108,112,97,116,104,114,54,0,0,0,114,9,0, - 0,0,114,9,0,0,0,114,10,0,0,0,218,10,103,101, - 116,95,115,111,117,114,99,101,195,0,0,0,115,24,0,0, - 0,0,7,10,1,8,1,18,2,10,1,4,1,14,2,10, - 2,2,1,14,1,12,2,8,1,122,22,122,105,112,105,109, - 112,111,114,116,101,114,46,103,101,116,95,115,111,117,114,99, - 101,99,2,0,0,0,0,0,0,0,0,0,0,0,3,0, - 0,0,4,0,0,0,67,0,0,0,115,40,0,0,0,116, - 0,124,0,124,1,131,2,125,2,124,2,100,1,117,0,114, - 36,116,1,100,2,124,1,155,2,157,2,124,1,100,3,141, - 2,130,1,124,2,83,0,41,4,122,171,105,115,95,112,97, - 99,107,97,103,101,40,102,117,108,108,110,97,109,101,41,32, - 45,62,32,98,111,111,108,46,10,10,32,32,32,32,32,32, - 32,32,82,101,116,117,114,110,32,84,114,117,101,32,105,102, - 32,116,104,101,32,109,111,100,117,108,101,32,115,112,101,99, - 105,102,105,101,100,32,98,121,32,102,117,108,108,110,97,109, - 101,32,105,115,32,97,32,112,97,99,107,97,103,101,46,10, - 32,32,32,32,32,32,32,32,82,97,105,115,101,32,90,105, - 112,73,109,112,111,114,116,69,114,114,111,114,32,105,102,32, - 116,104,101,32,109,111,100,117,108,101,32,99,111,117,108,100, - 110,39,116,32,98,101,32,102,111,117,110,100,46,10,32,32, - 32,32,32,32,32,32,78,114,57,0,0,0,114,58,0,0, - 0,41,2,114,35,0,0,0,114,3,0,0,0,41,3,114, - 32,0,0,0,114,38,0,0,0,114,39,0,0,0,114,9, - 0,0,0,114,9,0,0,0,114,10,0,0,0,218,10,105, - 115,95,112,97,99,107,97,103,101,221,0,0,0,115,8,0, - 0,0,0,6,10,1,8,1,18,1,122,22,122,105,112,105, - 109,112,111,114,116,101,114,46,105,115,95,112,97,99,107,97, - 103,101,99,2,0,0,0,0,0,0,0,0,0,0,0,8, - 0,0,0,8,0,0,0,67,0,0,0,115,246,0,0,0, - 116,0,124,0,124,1,131,2,92,3,125,2,125,3,125,4, - 116,1,106,2,160,3,124,1,161,1,125,5,124,5,100,1, - 117,0,115,46,116,4,124,5,116,5,131,2,115,64,116,5, - 124,1,131,1,125,5,124,5,116,1,106,2,124,1,60,0, - 124,0,124,5,95,6,122,84,124,3,114,108,116,7,124,0, - 124,1,131,2,125,6,116,8,160,9,124,0,106,10,124,6, - 161,2,125,7,124,7,103,1,124,5,95,11,116,12,124,5, - 100,2,131,2,115,124,116,13,124,5,95,13,116,8,160,14, - 124,5,106,15,124,1,124,4,161,3,1,0,116,16,124,2, - 124,5,106,15,131,2,1,0,87,0,110,22,1,0,1,0, - 1,0,116,1,106,2,124,1,61,0,130,0,89,0,110,2, - 48,0,122,14,116,1,106,2,124,1,25,0,125,5,87,0, - 110,34,4,0,116,17,121,226,1,0,1,0,1,0,116,18, - 100,3,124,1,155,2,100,4,157,3,131,1,130,1,89,0, - 110,2,48,0,116,19,160,20,100,5,124,1,124,4,161,3, - 1,0,124,5,83,0,41,6,122,245,108,111,97,100,95,109, - 111,100,117,108,101,40,102,117,108,108,110,97,109,101,41,32, - 45,62,32,109,111,100,117,108,101,46,10,10,32,32,32,32, - 32,32,32,32,76,111,97,100,32,116,104,101,32,109,111,100, - 117,108,101,32,115,112,101,99,105,102,105,101,100,32,98,121, - 32,39,102,117,108,108,110,97,109,101,39,46,32,39,102,117, - 108,108,110,97,109,101,39,32,109,117,115,116,32,98,101,32, - 116,104,101,10,32,32,32,32,32,32,32,32,102,117,108,108, - 121,32,113,117,97,108,105,102,105,101,100,32,40,100,111,116, - 116,101,100,41,32,109,111,100,117,108,101,32,110,97,109,101, - 46,32,73,116,32,114,101,116,117,114,110,115,32,116,104,101, - 32,105,109,112,111,114,116,101,100,10,32,32,32,32,32,32, - 32,32,109,111,100,117,108,101,44,32,111,114,32,114,97,105, - 115,101,115,32,90,105,112,73,109,112,111,114,116,69,114,114, - 111,114,32,105,102,32,105,116,32,119,97,115,110,39,116,32, - 102,111,117,110,100,46,10,32,32,32,32,32,32,32,32,78, - 218,12,95,95,98,117,105,108,116,105,110,115,95,95,122,14, - 76,111,97,100,101,100,32,109,111,100,117,108,101,32,122,25, - 32,110,111,116,32,102,111,117,110,100,32,105,110,32,115,121, - 115,46,109,111,100,117,108,101,115,122,30,105,109,112,111,114, - 116,32,123,125,32,35,32,108,111,97,100,101,100,32,102,114, - 111,109,32,90,105,112,32,123,125,41,21,114,44,0,0,0, - 218,3,115,121,115,218,7,109,111,100,117,108,101,115,218,3, - 103,101,116,114,15,0,0,0,218,12,95,109,111,100,117,108, - 101,95,116,121,112,101,218,10,95,95,108,111,97,100,101,114, - 95,95,114,36,0,0,0,114,21,0,0,0,114,30,0,0, - 0,114,29,0,0,0,90,8,95,95,112,97,116,104,95,95, - 218,7,104,97,115,97,116,116,114,114,66,0,0,0,90,14, - 95,102,105,120,95,117,112,95,109,111,100,117,108,101,218,8, - 95,95,100,105,99,116,95,95,218,4,101,120,101,99,114,26, - 0,0,0,218,11,73,109,112,111,114,116,69,114,114,111,114, - 218,10,95,98,111,111,116,115,116,114,97,112,218,16,95,118, - 101,114,98,111,115,101,95,109,101,115,115,97,103,101,41,8, - 114,32,0,0,0,114,38,0,0,0,114,46,0,0,0,114, - 47,0,0,0,114,40,0,0,0,90,3,109,111,100,114,13, - 0,0,0,114,63,0,0,0,114,9,0,0,0,114,9,0, - 0,0,114,10,0,0,0,218,11,108,111,97,100,95,109,111, - 100,117,108,101,234,0,0,0,115,48,0,0,0,0,7,16, - 1,12,1,18,1,8,1,10,1,6,2,2,1,4,3,10, - 1,14,1,8,2,10,1,6,1,16,1,16,1,6,1,8, - 1,8,2,2,1,14,1,12,1,22,1,14,1,122,23,122, - 105,112,105,109,112,111,114,116,101,114,46,108,111,97,100,95, - 109,111,100,117,108,101,99,2,0,0,0,0,0,0,0,0, - 0,0,0,3,0,0,0,8,0,0,0,67,0,0,0,115, - 86,0,0,0,122,20,124,0,160,0,124,1,161,1,115,18, - 87,0,100,1,83,0,87,0,110,20,4,0,116,1,121,40, - 1,0,1,0,1,0,89,0,100,1,83,0,48,0,116,2, - 106,3,115,76,100,2,100,3,108,4,109,5,125,2,1,0, - 124,2,160,6,116,2,161,1,1,0,100,4,116,2,95,3, - 116,2,124,0,124,1,131,2,83,0,41,5,122,204,82,101, - 116,117,114,110,32,116,104,101,32,82,101,115,111,117,114,99, - 101,82,101,97,100,101,114,32,102,111,114,32,97,32,112,97, - 99,107,97,103,101,32,105,110,32,97,32,122,105,112,32,102, - 105,108,101,46,10,10,32,32,32,32,32,32,32,32,73,102, - 32,39,102,117,108,108,110,97,109,101,39,32,105,115,32,97, - 32,112,97,99,107,97,103,101,32,119,105,116,104,105,110,32, - 116,104,101,32,122,105,112,32,102,105,108,101,44,32,114,101, - 116,117,114,110,32,116,104,101,10,32,32,32,32,32,32,32, - 32,39,82,101,115,111,117,114,99,101,82,101,97,100,101,114, - 39,32,111,98,106,101,99,116,32,102,111,114,32,116,104,101, - 32,112,97,99,107,97,103,101,46,32,32,79,116,104,101,114, - 119,105,115,101,32,114,101,116,117,114,110,32,78,111,110,101, - 46,10,32,32,32,32,32,32,32,32,78,114,0,0,0,0, - 41,1,218,14,82,101,115,111,117,114,99,101,82,101,97,100, - 101,114,84,41,7,114,65,0,0,0,114,3,0,0,0,218, - 24,95,90,105,112,73,109,112,111,114,116,82,101,115,111,117, - 114,99,101,82,101,97,100,101,114,218,11,95,114,101,103,105, - 115,116,101,114,101,100,90,13,105,109,112,111,114,116,108,105, - 98,46,97,98,99,114,79,0,0,0,90,8,114,101,103,105, - 115,116,101,114,41,3,114,32,0,0,0,114,38,0,0,0, - 114,79,0,0,0,114,9,0,0,0,114,9,0,0,0,114, - 10,0,0,0,218,19,103,101,116,95,114,101,115,111,117,114, - 99,101,95,114,101,97,100,101,114,16,1,0,0,115,20,0, - 0,0,0,6,2,1,10,1,10,1,12,1,8,1,6,1, - 12,1,10,1,6,1,122,31,122,105,112,105,109,112,111,114, - 116,101,114,46,103,101,116,95,114,101,115,111,117,114,99,101, - 95,114,101,97,100,101,114,99,1,0,0,0,0,0,0,0, - 0,0,0,0,1,0,0,0,5,0,0,0,67,0,0,0, - 115,24,0,0,0,100,1,124,0,106,0,155,0,116,1,155, - 0,124,0,106,2,155,0,100,2,157,5,83,0,41,3,78, - 122,21,60,122,105,112,105,109,112,111,114,116,101,114,32,111, - 98,106,101,99,116,32,34,122,2,34,62,41,3,114,29,0, - 0,0,114,20,0,0,0,114,31,0,0,0,41,1,114,32, + 100,44,132,0,90,42,100,45,100,46,132,0,90,43,100,2, + 83,0,41,47,97,80,2,0,0,122,105,112,105,109,112,111, + 114,116,32,112,114,111,118,105,100,101,115,32,115,117,112,112, + 111,114,116,32,102,111,114,32,105,109,112,111,114,116,105,110, + 103,32,80,121,116,104,111,110,32,109,111,100,117,108,101,115, + 32,102,114,111,109,32,90,105,112,32,97,114,99,104,105,118, + 101,115,46,10,10,84,104,105,115,32,109,111,100,117,108,101, + 32,101,120,112,111,114,116,115,32,116,104,114,101,101,32,111, + 98,106,101,99,116,115,58,10,45,32,122,105,112,105,109,112, + 111,114,116,101,114,58,32,97,32,99,108,97,115,115,59,32, + 105,116,115,32,99,111,110,115,116,114,117,99,116,111,114,32, + 116,97,107,101,115,32,97,32,112,97,116,104,32,116,111,32, + 97,32,90,105,112,32,97,114,99,104,105,118,101,46,10,45, + 32,90,105,112,73,109,112,111,114,116,69,114,114,111,114,58, + 32,101,120,99,101,112,116,105,111,110,32,114,97,105,115,101, + 100,32,98,121,32,122,105,112,105,109,112,111,114,116,101,114, + 32,111,98,106,101,99,116,115,46,32,73,116,39,115,32,97, + 10,32,32,115,117,98,99,108,97,115,115,32,111,102,32,73, + 109,112,111,114,116,69,114,114,111,114,44,32,115,111,32,105, + 116,32,99,97,110,32,98,101,32,99,97,117,103,104,116,32, + 97,115,32,73,109,112,111,114,116,69,114,114,111,114,44,32, + 116,111,111,46,10,45,32,95,122,105,112,95,100,105,114,101, + 99,116,111,114,121,95,99,97,99,104,101,58,32,97,32,100, + 105,99,116,44,32,109,97,112,112,105,110,103,32,97,114,99, + 104,105,118,101,32,112,97,116,104,115,32,116,111,32,122,105, + 112,32,100,105,114,101,99,116,111,114,121,10,32,32,105,110, + 102,111,32,100,105,99,116,115,44,32,97,115,32,117,115,101, + 100,32,105,110,32,122,105,112,105,109,112,111,114,116,101,114, + 46,95,102,105,108,101,115,46,10,10,73,116,32,105,115,32, + 117,115,117,97,108,108,121,32,110,111,116,32,110,101,101,100, + 101,100,32,116,111,32,117,115,101,32,116,104,101,32,122,105, + 112,105,109,112,111,114,116,32,109,111,100,117,108,101,32,101, + 120,112,108,105,99,105,116,108,121,59,32,105,116,32,105,115, + 10,117,115,101,100,32,98,121,32,116,104,101,32,98,117,105, + 108,116,105,110,32,105,109,112,111,114,116,32,109,101,99,104, + 97,110,105,115,109,32,102,111,114,32,115,121,115,46,112,97, + 116,104,32,105,116,101,109,115,32,116,104,97,116,32,97,114, + 101,32,112,97,116,104,115,10,116,111,32,90,105,112,32,97, + 114,99,104,105,118,101,115,46,10,233,0,0,0,0,78,41, + 2,218,14,95,117,110,112,97,99,107,95,117,105,110,116,49, + 54,218,14,95,117,110,112,97,99,107,95,117,105,110,116,51, + 50,218,14,90,105,112,73,109,112,111,114,116,69,114,114,111, + 114,218,11,122,105,112,105,109,112,111,114,116,101,114,233,1, + 0,0,0,99,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,1,0,0,0,64,0,0,0,115,12,0,0, + 0,101,0,90,1,100,0,90,2,100,1,83,0,41,2,114, + 3,0,0,0,78,41,3,218,8,95,95,110,97,109,101,95, + 95,218,10,95,95,109,111,100,117,108,101,95,95,218,12,95, + 95,113,117,97,108,110,97,109,101,95,95,169,0,114,9,0, + 0,0,114,9,0,0,0,250,18,60,102,114,111,122,101,110, + 32,122,105,112,105,109,112,111,114,116,62,114,3,0,0,0, + 33,0,0,0,115,2,0,0,0,8,1,233,22,0,0,0, + 115,4,0,0,0,80,75,5,6,105,255,255,0,0,99,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3, + 0,0,0,64,0,0,0,115,108,0,0,0,101,0,90,1, + 100,0,90,2,100,1,90,3,100,2,100,3,132,0,90,4, + 100,25,100,5,100,6,132,1,90,5,100,26,100,7,100,8, + 132,1,90,6,100,9,100,10,132,0,90,7,100,11,100,12, + 132,0,90,8,100,13,100,14,132,0,90,9,100,15,100,16, + 132,0,90,10,100,17,100,18,132,0,90,11,100,19,100,20, + 132,0,90,12,100,21,100,22,132,0,90,13,100,23,100,24, + 132,0,90,14,100,4,83,0,41,27,114,4,0,0,0,97, + 255,1,0,0,122,105,112,105,109,112,111,114,116,101,114,40, + 97,114,99,104,105,118,101,112,97,116,104,41,32,45,62,32, + 122,105,112,105,109,112,111,114,116,101,114,32,111,98,106,101, + 99,116,10,10,32,32,32,32,67,114,101,97,116,101,32,97, + 32,110,101,119,32,122,105,112,105,109,112,111,114,116,101,114, + 32,105,110,115,116,97,110,99,101,46,32,39,97,114,99,104, + 105,118,101,112,97,116,104,39,32,109,117,115,116,32,98,101, + 32,97,32,112,97,116,104,32,116,111,10,32,32,32,32,97, + 32,122,105,112,102,105,108,101,44,32,111,114,32,116,111,32, + 97,32,115,112,101,99,105,102,105,99,32,112,97,116,104,32, + 105,110,115,105,100,101,32,97,32,122,105,112,102,105,108,101, + 46,32,70,111,114,32,101,120,97,109,112,108,101,44,32,105, + 116,32,99,97,110,32,98,101,10,32,32,32,32,39,47,116, + 109,112,47,109,121,105,109,112,111,114,116,46,122,105,112,39, + 44,32,111,114,32,39,47,116,109,112,47,109,121,105,109,112, + 111,114,116,46,122,105,112,47,109,121,100,105,114,101,99,116, + 111,114,121,39,44,32,105,102,32,109,121,100,105,114,101,99, + 116,111,114,121,32,105,115,32,97,10,32,32,32,32,118,97, + 108,105,100,32,100,105,114,101,99,116,111,114,121,32,105,110, + 115,105,100,101,32,116,104,101,32,97,114,99,104,105,118,101, + 46,10,10,32,32,32,32,39,90,105,112,73,109,112,111,114, + 116,69,114,114,111,114,32,105,115,32,114,97,105,115,101,100, + 32,105,102,32,39,97,114,99,104,105,118,101,112,97,116,104, + 39,32,100,111,101,115,110,39,116,32,112,111,105,110,116,32, + 116,111,32,97,32,118,97,108,105,100,32,90,105,112,10,32, + 32,32,32,97,114,99,104,105,118,101,46,10,10,32,32,32, + 32,84,104,101,32,39,97,114,99,104,105,118,101,39,32,97, + 116,116,114,105,98,117,116,101,32,111,102,32,122,105,112,105, + 109,112,111,114,116,101,114,32,111,98,106,101,99,116,115,32, + 99,111,110,116,97,105,110,115,32,116,104,101,32,110,97,109, + 101,32,111,102,32,116,104,101,10,32,32,32,32,122,105,112, + 102,105,108,101,32,116,97,114,103,101,116,101,100,46,10,32, + 32,32,32,99,2,0,0,0,0,0,0,0,0,0,0,0, + 8,0,0,0,9,0,0,0,67,0,0,0,115,32,1,0, + 0,116,0,124,1,116,1,131,2,115,28,100,1,100,0,108, + 2,125,2,124,2,160,3,124,1,161,1,125,1,124,1,115, + 44,116,4,100,2,124,1,100,3,141,2,130,1,116,5,114, + 60,124,1,160,6,116,5,116,7,161,2,125,1,103,0,125, + 3,122,14,116,8,160,9,124,1,161,1,125,4,87,0,110, + 70,4,0,116,10,116,11,102,2,121,148,1,0,1,0,1, + 0,116,8,160,12,124,1,161,1,92,2,125,5,125,6,124, + 5,124,1,107,2,114,130,116,4,100,4,124,1,100,3,141, + 2,130,1,124,5,125,1,124,3,160,13,124,6,161,1,1, + 0,89,0,113,64,48,0,124,4,106,14,100,5,64,0,100, + 6,107,3,114,180,116,4,100,4,124,1,100,3,141,2,130, + 1,113,180,113,64,122,12,116,15,124,1,25,0,125,7,87, + 0,110,34,4,0,116,16,121,226,1,0,1,0,1,0,116, + 17,124,1,131,1,125,7,124,7,116,15,124,1,60,0,89, + 0,110,2,48,0,124,7,124,0,95,18,124,1,124,0,95, + 19,116,8,106,20,124,3,100,0,100,0,100,7,133,3,25, + 0,142,0,124,0,95,21,124,0,106,21,144,1,114,28,124, + 0,4,0,106,21,116,7,55,0,2,0,95,21,100,0,83, + 0,41,8,78,114,0,0,0,0,122,21,97,114,99,104,105, + 118,101,32,112,97,116,104,32,105,115,32,101,109,112,116,121, + 169,1,218,4,112,97,116,104,122,14,110,111,116,32,97,32, + 90,105,112,32,102,105,108,101,105,0,240,0,0,105,0,128, + 0,0,233,255,255,255,255,41,22,218,10,105,115,105,110,115, + 116,97,110,99,101,218,3,115,116,114,218,2,111,115,90,8, + 102,115,100,101,99,111,100,101,114,3,0,0,0,218,12,97, + 108,116,95,112,97,116,104,95,115,101,112,218,7,114,101,112, + 108,97,99,101,218,8,112,97,116,104,95,115,101,112,218,19, + 95,98,111,111,116,115,116,114,97,112,95,101,120,116,101,114, + 110,97,108,90,10,95,112,97,116,104,95,115,116,97,116,218, + 7,79,83,69,114,114,111,114,218,10,86,97,108,117,101,69, + 114,114,111,114,90,11,95,112,97,116,104,95,115,112,108,105, + 116,218,6,97,112,112,101,110,100,90,7,115,116,95,109,111, + 100,101,218,20,95,122,105,112,95,100,105,114,101,99,116,111, + 114,121,95,99,97,99,104,101,218,8,75,101,121,69,114,114, + 111,114,218,15,95,114,101,97,100,95,100,105,114,101,99,116, + 111,114,121,218,6,95,102,105,108,101,115,218,7,97,114,99, + 104,105,118,101,218,10,95,112,97,116,104,95,106,111,105,110, + 218,6,112,114,101,102,105,120,41,8,218,4,115,101,108,102, + 114,13,0,0,0,114,17,0,0,0,114,31,0,0,0,90, + 2,115,116,90,7,100,105,114,110,97,109,101,90,8,98,97, + 115,101,110,97,109,101,218,5,102,105,108,101,115,114,9,0, + 0,0,114,9,0,0,0,114,10,0,0,0,218,8,95,95, + 105,110,105,116,95,95,63,0,0,0,115,58,0,0,0,0, + 1,10,1,8,1,10,1,4,1,12,1,4,1,12,2,4, + 2,2,1,14,1,16,3,14,1,8,1,12,1,4,1,16, + 3,14,2,12,1,4,2,2,1,12,1,12,1,8,1,14, + 1,6,1,6,2,22,1,8,1,122,20,122,105,112,105,109, + 112,111,114,116,101,114,46,95,95,105,110,105,116,95,95,78, + 99,3,0,0,0,0,0,0,0,0,0,0,0,5,0,0, + 0,4,0,0,0,67,0,0,0,115,78,0,0,0,116,0, + 124,0,124,1,131,2,125,3,124,3,100,1,117,1,114,26, + 124,0,103,0,102,2,83,0,116,1,124,0,124,1,131,2, + 125,4,116,2,124,0,124,4,131,2,114,70,100,1,124,0, + 106,3,155,0,116,4,155,0,124,4,155,0,157,3,103,1, + 102,2,83,0,100,1,103,0,102,2,83,0,41,2,97,239, + 1,0,0,102,105,110,100,95,108,111,97,100,101,114,40,102, + 117,108,108,110,97,109,101,44,32,112,97,116,104,61,78,111, + 110,101,41,32,45,62,32,115,101,108,102,44,32,115,116,114, + 32,111,114,32,78,111,110,101,46,10,10,32,32,32,32,32, + 32,32,32,83,101,97,114,99,104,32,102,111,114,32,97,32, + 109,111,100,117,108,101,32,115,112,101,99,105,102,105,101,100, + 32,98,121,32,39,102,117,108,108,110,97,109,101,39,46,32, + 39,102,117,108,108,110,97,109,101,39,32,109,117,115,116,32, + 98,101,32,116,104,101,10,32,32,32,32,32,32,32,32,102, + 117,108,108,121,32,113,117,97,108,105,102,105,101,100,32,40, + 100,111,116,116,101,100,41,32,109,111,100,117,108,101,32,110, + 97,109,101,46,32,73,116,32,114,101,116,117,114,110,115,32, + 116,104,101,32,122,105,112,105,109,112,111,114,116,101,114,10, + 32,32,32,32,32,32,32,32,105,110,115,116,97,110,99,101, + 32,105,116,115,101,108,102,32,105,102,32,116,104,101,32,109, + 111,100,117,108,101,32,119,97,115,32,102,111,117,110,100,44, + 32,97,32,115,116,114,105,110,103,32,99,111,110,116,97,105, + 110,105,110,103,32,116,104,101,10,32,32,32,32,32,32,32, + 32,102,117,108,108,32,112,97,116,104,32,110,97,109,101,32, + 105,102,32,105,116,39,115,32,112,111,115,115,105,98,108,121, + 32,97,32,112,111,114,116,105,111,110,32,111,102,32,97,32, + 110,97,109,101,115,112,97,99,101,32,112,97,99,107,97,103, + 101,44,10,32,32,32,32,32,32,32,32,111,114,32,78,111, + 110,101,32,111,116,104,101,114,119,105,115,101,46,32,84,104, + 101,32,111,112,116,105,111,110,97,108,32,39,112,97,116,104, + 39,32,97,114,103,117,109,101,110,116,32,105,115,32,105,103, + 110,111,114,101,100,32,45,45,32,105,116,39,115,10,32,32, + 32,32,32,32,32,32,116,104,101,114,101,32,102,111,114,32, + 99,111,109,112,97,116,105,98,105,108,105,116,121,32,119,105, + 116,104,32,116,104,101,32,105,109,112,111,114,116,101,114,32, + 112,114,111,116,111,99,111,108,46,10,32,32,32,32,32,32, + 32,32,78,41,5,218,16,95,103,101,116,95,109,111,100,117, + 108,101,95,105,110,102,111,218,16,95,103,101,116,95,109,111, + 100,117,108,101,95,112,97,116,104,218,7,95,105,115,95,100, + 105,114,114,29,0,0,0,114,20,0,0,0,41,5,114,32, + 0,0,0,218,8,102,117,108,108,110,97,109,101,114,13,0, + 0,0,218,2,109,105,218,7,109,111,100,112,97,116,104,114, + 9,0,0,0,114,9,0,0,0,114,10,0,0,0,218,11, + 102,105,110,100,95,108,111,97,100,101,114,109,0,0,0,115, + 14,0,0,0,0,10,10,1,8,2,8,7,10,1,10,4, + 24,2,122,23,122,105,112,105,109,112,111,114,116,101,114,46, + 102,105,110,100,95,108,111,97,100,101,114,99,3,0,0,0, + 0,0,0,0,0,0,0,0,3,0,0,0,4,0,0,0, + 67,0,0,0,115,16,0,0,0,124,0,160,0,124,1,124, + 2,161,2,100,1,25,0,83,0,41,2,97,139,1,0,0, + 102,105,110,100,95,109,111,100,117,108,101,40,102,117,108,108, + 110,97,109,101,44,32,112,97,116,104,61,78,111,110,101,41, + 32,45,62,32,115,101,108,102,32,111,114,32,78,111,110,101, + 46,10,10,32,32,32,32,32,32,32,32,83,101,97,114,99, + 104,32,102,111,114,32,97,32,109,111,100,117,108,101,32,115, + 112,101,99,105,102,105,101,100,32,98,121,32,39,102,117,108, + 108,110,97,109,101,39,46,32,39,102,117,108,108,110,97,109, + 101,39,32,109,117,115,116,32,98,101,32,116,104,101,10,32, + 32,32,32,32,32,32,32,102,117,108,108,121,32,113,117,97, + 108,105,102,105,101,100,32,40,100,111,116,116,101,100,41,32, + 109,111,100,117,108,101,32,110,97,109,101,46,32,73,116,32, + 114,101,116,117,114,110,115,32,116,104,101,32,122,105,112,105, + 109,112,111,114,116,101,114,10,32,32,32,32,32,32,32,32, + 105,110,115,116,97,110,99,101,32,105,116,115,101,108,102,32, + 105,102,32,116,104,101,32,109,111,100,117,108,101,32,119,97, + 115,32,102,111,117,110,100,44,32,111,114,32,78,111,110,101, + 32,105,102,32,105,116,32,119,97,115,110,39,116,46,10,32, + 32,32,32,32,32,32,32,84,104,101,32,111,112,116,105,111, + 110,97,108,32,39,112,97,116,104,39,32,97,114,103,117,109, + 101,110,116,32,105,115,32,105,103,110,111,114,101,100,32,45, + 45,32,105,116,39,115,32,116,104,101,114,101,32,102,111,114, + 32,99,111,109,112,97,116,105,98,105,108,105,116,121,10,32, + 32,32,32,32,32,32,32,119,105,116,104,32,116,104,101,32, + 105,109,112,111,114,116,101,114,32,112,114,111,116,111,99,111, + 108,46,10,32,32,32,32,32,32,32,32,114,0,0,0,0, + 41,1,114,41,0,0,0,41,3,114,32,0,0,0,114,38, + 0,0,0,114,13,0,0,0,114,9,0,0,0,114,9,0, + 0,0,114,10,0,0,0,218,11,102,105,110,100,95,109,111, + 100,117,108,101,141,0,0,0,115,2,0,0,0,0,9,122, + 23,122,105,112,105,109,112,111,114,116,101,114,46,102,105,110, + 100,95,109,111,100,117,108,101,99,2,0,0,0,0,0,0, + 0,0,0,0,0,5,0,0,0,3,0,0,0,67,0,0, + 0,115,20,0,0,0,116,0,124,0,124,1,131,2,92,3, + 125,2,125,3,125,4,124,2,83,0,41,1,122,163,103,101, + 116,95,99,111,100,101,40,102,117,108,108,110,97,109,101,41, + 32,45,62,32,99,111,100,101,32,111,98,106,101,99,116,46, + 10,10,32,32,32,32,32,32,32,32,82,101,116,117,114,110, + 32,116,104,101,32,99,111,100,101,32,111,98,106,101,99,116, + 32,102,111,114,32,116,104,101,32,115,112,101,99,105,102,105, + 101,100,32,109,111,100,117,108,101,46,32,82,97,105,115,101, + 32,90,105,112,73,109,112,111,114,116,69,114,114,111,114,10, + 32,32,32,32,32,32,32,32,105,102,32,116,104,101,32,109, + 111,100,117,108,101,32,99,111,117,108,100,110,39,116,32,98, + 101,32,102,111,117,110,100,46,10,32,32,32,32,32,32,32, + 32,169,1,218,16,95,103,101,116,95,109,111,100,117,108,101, + 95,99,111,100,101,169,5,114,32,0,0,0,114,38,0,0, + 0,218,4,99,111,100,101,218,9,105,115,112,97,99,107,97, + 103,101,114,40,0,0,0,114,9,0,0,0,114,9,0,0, + 0,114,10,0,0,0,218,8,103,101,116,95,99,111,100,101, + 153,0,0,0,115,4,0,0,0,0,6,16,1,122,20,122, + 105,112,105,109,112,111,114,116,101,114,46,103,101,116,95,99, + 111,100,101,99,2,0,0,0,0,0,0,0,0,0,0,0, + 4,0,0,0,8,0,0,0,67,0,0,0,115,116,0,0, + 0,116,0,114,16,124,1,160,1,116,0,116,2,161,2,125, + 1,124,1,125,2,124,1,160,3,124,0,106,4,116,2,23, + 0,161,1,114,58,124,1,116,5,124,0,106,4,116,2,23, + 0,131,1,100,1,133,2,25,0,125,2,122,14,124,0,106, + 6,124,2,25,0,125,3,87,0,110,30,4,0,116,7,121, + 102,1,0,1,0,1,0,116,8,100,2,100,3,124,2,131, + 3,130,1,89,0,110,2,48,0,116,9,124,0,106,4,124, + 3,131,2,83,0,41,4,122,154,103,101,116,95,100,97,116, + 97,40,112,97,116,104,110,97,109,101,41,32,45,62,32,115, + 116,114,105,110,103,32,119,105,116,104,32,102,105,108,101,32, + 100,97,116,97,46,10,10,32,32,32,32,32,32,32,32,82, + 101,116,117,114,110,32,116,104,101,32,100,97,116,97,32,97, + 115,115,111,99,105,97,116,101,100,32,119,105,116,104,32,39, + 112,97,116,104,110,97,109,101,39,46,32,82,97,105,115,101, + 32,79,83,69,114,114,111,114,32,105,102,10,32,32,32,32, + 32,32,32,32,116,104,101,32,102,105,108,101,32,119,97,115, + 110,39,116,32,102,111,117,110,100,46,10,32,32,32,32,32, + 32,32,32,78,114,0,0,0,0,218,0,41,10,114,18,0, + 0,0,114,19,0,0,0,114,20,0,0,0,218,10,115,116, + 97,114,116,115,119,105,116,104,114,29,0,0,0,218,3,108, + 101,110,114,28,0,0,0,114,26,0,0,0,114,22,0,0, + 0,218,9,95,103,101,116,95,100,97,116,97,41,4,114,32, + 0,0,0,218,8,112,97,116,104,110,97,109,101,90,3,107, + 101,121,218,9,116,111,99,95,101,110,116,114,121,114,9,0, + 0,0,114,9,0,0,0,114,10,0,0,0,218,8,103,101, + 116,95,100,97,116,97,163,0,0,0,115,20,0,0,0,0, + 6,4,1,12,2,4,1,16,1,22,2,2,1,14,1,12, + 1,18,1,122,20,122,105,112,105,109,112,111,114,116,101,114, + 46,103,101,116,95,100,97,116,97,99,2,0,0,0,0,0, + 0,0,0,0,0,0,5,0,0,0,3,0,0,0,67,0, + 0,0,115,20,0,0,0,116,0,124,0,124,1,131,2,92, + 3,125,2,125,3,125,4,124,4,83,0,41,1,122,106,103, + 101,116,95,102,105,108,101,110,97,109,101,40,102,117,108,108, + 110,97,109,101,41,32,45,62,32,102,105,108,101,110,97,109, + 101,32,115,116,114,105,110,103,46,10,10,32,32,32,32,32, + 32,32,32,82,101,116,117,114,110,32,116,104,101,32,102,105, + 108,101,110,97,109,101,32,102,111,114,32,116,104,101,32,115, + 112,101,99,105,102,105,101,100,32,109,111,100,117,108,101,46, + 10,32,32,32,32,32,32,32,32,114,43,0,0,0,114,45, 0,0,0,114,9,0,0,0,114,9,0,0,0,114,10,0, - 0,0,218,8,95,95,114,101,112,114,95,95,34,1,0,0, - 115,2,0,0,0,0,1,122,20,122,105,112,105,109,112,111, - 114,116,101,114,46,95,95,114,101,112,114,95,95,41,1,78, - 41,1,78,41,15,114,6,0,0,0,114,7,0,0,0,114, - 8,0,0,0,218,7,95,95,100,111,99,95,95,114,34,0, - 0,0,114,41,0,0,0,114,42,0,0,0,114,48,0,0, - 0,114,55,0,0,0,114,56,0,0,0,114,64,0,0,0, - 114,65,0,0,0,114,78,0,0,0,114,82,0,0,0,114, - 83,0,0,0,114,9,0,0,0,114,9,0,0,0,114,9, - 0,0,0,114,10,0,0,0,114,4,0,0,0,45,0,0, - 0,115,24,0,0,0,8,1,4,17,8,46,10,32,10,12, - 8,10,8,21,8,11,8,26,8,13,8,38,8,18,122,12, - 95,95,105,110,105,116,95,95,46,112,121,99,84,114,60,0, - 0,0,70,41,3,122,4,46,112,121,99,84,70,41,3,114, - 61,0,0,0,70,70,99,2,0,0,0,0,0,0,0,0, - 0,0,0,2,0,0,0,4,0,0,0,67,0,0,0,115, - 20,0,0,0,124,0,106,0,124,1,160,1,100,1,161,1, - 100,2,25,0,23,0,83,0,41,3,78,218,1,46,233,2, - 0,0,0,41,2,114,31,0,0,0,218,10,114,112,97,114, - 116,105,116,105,111,110,41,2,114,32,0,0,0,114,38,0, - 0,0,114,9,0,0,0,114,9,0,0,0,114,10,0,0, - 0,114,36,0,0,0,52,1,0,0,115,2,0,0,0,0, - 1,114,36,0,0,0,99,2,0,0,0,0,0,0,0,0, - 0,0,0,3,0,0,0,2,0,0,0,67,0,0,0,115, - 18,0,0,0,124,1,116,0,23,0,125,2,124,2,124,0, - 106,1,118,0,83,0,169,1,78,41,2,114,20,0,0,0, - 114,28,0,0,0,41,3,114,32,0,0,0,114,13,0,0, - 0,90,7,100,105,114,112,97,116,104,114,9,0,0,0,114, - 9,0,0,0,114,10,0,0,0,114,37,0,0,0,56,1, - 0,0,115,4,0,0,0,0,4,8,2,114,37,0,0,0, - 99,2,0,0,0,0,0,0,0,0,0,0,0,7,0,0, - 0,4,0,0,0,67,0,0,0,115,56,0,0,0,116,0, - 124,0,124,1,131,2,125,2,116,1,68,0,93,36,92,3, - 125,3,125,4,125,5,124,2,124,3,23,0,125,6,124,6, - 124,0,106,2,118,0,114,14,124,5,2,0,1,0,83,0, - 113,14,100,0,83,0,114,88,0,0,0,41,3,114,36,0, - 0,0,218,16,95,122,105,112,95,115,101,97,114,99,104,111, - 114,100,101,114,114,28,0,0,0,41,7,114,32,0,0,0, - 114,38,0,0,0,114,13,0,0,0,218,6,115,117,102,102, - 105,120,218,10,105,115,98,121,116,101,99,111,100,101,114,47, - 0,0,0,114,63,0,0,0,114,9,0,0,0,114,9,0, - 0,0,114,10,0,0,0,114,35,0,0,0,65,1,0,0, - 115,12,0,0,0,0,1,10,1,14,1,8,1,10,1,10, - 1,114,35,0,0,0,99,1,0,0,0,0,0,0,0,0, - 0,0,0,26,0,0,0,9,0,0,0,67,0,0,0,115, - 2,5,0,0,122,14,116,0,160,1,124,0,161,1,125,1, - 87,0,110,36,4,0,116,2,121,50,1,0,1,0,1,0, - 116,3,100,1,124,0,155,2,157,2,124,0,100,2,141,2, - 130,1,89,0,110,2,48,0,124,1,144,4,143,164,1,0, - 122,36,124,1,160,4,116,5,11,0,100,3,161,2,1,0, - 124,1,160,6,161,0,125,2,124,1,160,7,116,5,161,1, - 125,3,87,0,110,36,4,0,116,2,121,132,1,0,1,0, - 1,0,116,3,100,4,124,0,155,2,157,2,124,0,100,2, - 141,2,130,1,89,0,110,2,48,0,116,8,124,3,131,1, - 116,5,107,3,114,164,116,3,100,4,124,0,155,2,157,2, - 124,0,100,2,141,2,130,1,124,3,100,0,100,5,133,2, - 25,0,116,9,107,3,144,1,114,170,122,24,124,1,160,4, - 100,6,100,3,161,2,1,0,124,1,160,6,161,0,125,4, - 87,0,110,36,4,0,116,2,121,242,1,0,1,0,1,0, - 116,3,100,4,124,0,155,2,157,2,124,0,100,2,141,2, - 130,1,89,0,110,2,48,0,116,10,124,4,116,11,24,0, - 116,5,24,0,100,6,131,2,125,5,122,22,124,1,160,4, - 124,5,161,1,1,0,124,1,160,7,161,0,125,6,87,0, - 110,38,4,0,116,2,144,1,121,66,1,0,1,0,1,0, - 116,3,100,4,124,0,155,2,157,2,124,0,100,2,141,2, - 130,1,89,0,110,2,48,0,124,6,160,12,116,9,161,1, - 125,7,124,7,100,6,107,0,144,1,114,106,116,3,100,7, - 124,0,155,2,157,2,124,0,100,2,141,2,130,1,124,6, - 124,7,124,7,116,5,23,0,133,2,25,0,125,3,116,8, - 124,3,131,1,116,5,107,3,144,1,114,154,116,3,100,8, - 124,0,155,2,157,2,124,0,100,2,141,2,130,1,124,4, - 116,8,124,6,131,1,24,0,124,7,23,0,125,2,116,13, - 124,3,100,9,100,10,133,2,25,0,131,1,125,8,116,13, - 124,3,100,10,100,11,133,2,25,0,131,1,125,9,124,2, - 124,8,107,0,144,1,114,230,116,3,100,12,124,0,155,2, - 157,2,124,0,100,2,141,2,130,1,124,2,124,9,107,0, - 144,2,114,2,116,3,100,13,124,0,155,2,157,2,124,0, - 100,2,141,2,130,1,124,2,124,8,56,0,125,2,124,2, - 124,9,24,0,125,10,124,10,100,6,107,0,144,2,114,46, - 116,3,100,14,124,0,155,2,157,2,124,0,100,2,141,2, - 130,1,105,0,125,11,100,6,125,12,122,14,124,1,160,4, - 124,2,161,1,1,0,87,0,110,38,4,0,116,2,144,2, - 121,106,1,0,1,0,1,0,116,3,100,4,124,0,155,2, - 157,2,124,0,100,2,141,2,130,1,89,0,110,2,48,0, - 124,1,160,7,100,15,161,1,125,3,116,8,124,3,131,1, - 100,5,107,0,144,2,114,140,116,14,100,16,131,1,130,1, - 124,3,100,0,100,5,133,2,25,0,100,17,107,3,144,2, - 114,162,144,4,113,208,116,8,124,3,131,1,100,15,107,3, - 144,2,114,184,116,14,100,16,131,1,130,1,116,15,124,3, - 100,18,100,19,133,2,25,0,131,1,125,13,116,15,124,3, - 100,19,100,9,133,2,25,0,131,1,125,14,116,15,124,3, - 100,9,100,20,133,2,25,0,131,1,125,15,116,15,124,3, - 100,20,100,10,133,2,25,0,131,1,125,16,116,13,124,3, - 100,10,100,11,133,2,25,0,131,1,125,17,116,13,124,3, - 100,11,100,21,133,2,25,0,131,1,125,18,116,13,124,3, - 100,21,100,22,133,2,25,0,131,1,125,4,116,15,124,3, - 100,22,100,23,133,2,25,0,131,1,125,19,116,15,124,3, - 100,23,100,24,133,2,25,0,131,1,125,20,116,15,124,3, - 100,24,100,25,133,2,25,0,131,1,125,21,116,13,124,3, - 100,26,100,15,133,2,25,0,131,1,125,22,124,19,124,20, - 23,0,124,21,23,0,125,8,124,22,124,9,107,4,144,3, - 114,144,116,3,100,27,124,0,155,2,157,2,124,0,100,2, - 141,2,130,1,124,22,124,10,55,0,125,22,122,14,124,1, - 160,7,124,19,161,1,125,23,87,0,110,38,4,0,116,2, - 144,3,121,204,1,0,1,0,1,0,116,3,100,4,124,0, - 155,2,157,2,124,0,100,2,141,2,130,1,89,0,110,2, - 48,0,116,8,124,23,131,1,124,19,107,3,144,3,114,238, - 116,3,100,4,124,0,155,2,157,2,124,0,100,2,141,2, - 130,1,122,50,116,8,124,1,160,7,124,8,124,19,24,0, - 161,1,131,1,124,8,124,19,24,0,107,3,144,4,114,30, - 116,3,100,4,124,0,155,2,157,2,124,0,100,2,141,2, - 130,1,87,0,110,38,4,0,116,2,144,4,121,70,1,0, - 1,0,1,0,116,3,100,4,124,0,155,2,157,2,124,0, - 100,2,141,2,130,1,89,0,110,2,48,0,124,13,100,28, - 64,0,144,4,114,92,124,23,160,16,161,0,125,23,110,52, - 122,14,124,23,160,16,100,29,161,1,125,23,87,0,110,36, - 4,0,116,17,144,4,121,142,1,0,1,0,1,0,124,23, - 160,16,100,30,161,1,160,18,116,19,161,1,125,23,89,0, - 110,2,48,0,124,23,160,20,100,31,116,21,161,2,125,23, - 116,22,160,23,124,0,124,23,161,2,125,24,124,24,124,14, - 124,18,124,4,124,22,124,15,124,16,124,17,102,8,125,25, - 124,25,124,11,124,23,60,0,124,12,100,32,55,0,125,12, - 144,2,113,108,87,0,100,0,4,0,4,0,131,3,1,0, - 110,18,49,0,144,4,115,230,48,0,1,0,1,0,1,0, - 89,0,1,0,116,24,160,25,100,33,124,12,124,0,161,3, - 1,0,124,11,83,0,41,34,78,122,21,99,97,110,39,116, - 32,111,112,101,110,32,90,105,112,32,102,105,108,101,58,32, - 114,12,0,0,0,114,86,0,0,0,250,21,99,97,110,39, - 116,32,114,101,97,100,32,90,105,112,32,102,105,108,101,58, - 32,233,4,0,0,0,114,0,0,0,0,122,16,110,111,116, - 32,97,32,90,105,112,32,102,105,108,101,58,32,122,18,99, - 111,114,114,117,112,116,32,90,105,112,32,102,105,108,101,58, - 32,233,12,0,0,0,233,16,0,0,0,233,20,0,0,0, - 122,28,98,97,100,32,99,101,110,116,114,97,108,32,100,105, - 114,101,99,116,111,114,121,32,115,105,122,101,58,32,122,30, - 98,97,100,32,99,101,110,116,114,97,108,32,100,105,114,101, - 99,116,111,114,121,32,111,102,102,115,101,116,58,32,122,38, - 98,97,100,32,99,101,110,116,114,97,108,32,100,105,114,101, - 99,116,111,114,121,32,115,105,122,101,32,111,114,32,111,102, - 102,115,101,116,58,32,233,46,0,0,0,250,27,69,79,70, - 32,114,101,97,100,32,119,104,101,114,101,32,110,111,116,32, - 101,120,112,101,99,116,101,100,115,4,0,0,0,80,75,1, - 2,233,8,0,0,0,233,10,0,0,0,233,14,0,0,0, - 233,24,0,0,0,233,28,0,0,0,233,30,0,0,0,233, - 32,0,0,0,233,34,0,0,0,233,42,0,0,0,122,25, - 98,97,100,32,108,111,99,97,108,32,104,101,97,100,101,114, - 32,111,102,102,115,101,116,58,32,105,0,8,0,0,218,5, - 97,115,99,105,105,90,6,108,97,116,105,110,49,250,1,47, - 114,5,0,0,0,122,33,122,105,112,105,109,112,111,114,116, - 58,32,102,111,117,110,100,32,123,125,32,110,97,109,101,115, - 32,105,110,32,123,33,114,125,41,26,218,3,95,105,111,218, - 9,111,112,101,110,95,99,111,100,101,114,22,0,0,0,114, - 3,0,0,0,218,4,115,101,101,107,218,20,69,78,68,95, - 67,69,78,84,82,65,76,95,68,73,82,95,83,73,90,69, - 90,4,116,101,108,108,218,4,114,101,97,100,114,51,0,0, - 0,218,18,83,84,82,73,78,71,95,69,78,68,95,65,82, - 67,72,73,86,69,218,3,109,97,120,218,15,77,65,88,95, - 67,79,77,77,69,78,84,95,76,69,78,218,5,114,102,105, - 110,100,114,2,0,0,0,218,8,69,79,70,69,114,114,111, - 114,114,1,0,0,0,114,62,0,0,0,218,18,85,110,105, - 99,111,100,101,68,101,99,111,100,101,69,114,114,111,114,218, - 9,116,114,97,110,115,108,97,116,101,218,11,99,112,52,51, - 55,95,116,97,98,108,101,114,19,0,0,0,114,20,0,0, - 0,114,21,0,0,0,114,30,0,0,0,114,76,0,0,0, - 114,77,0,0,0,41,26,114,29,0,0,0,218,2,102,112, - 90,15,104,101,97,100,101,114,95,112,111,115,105,116,105,111, - 110,218,6,98,117,102,102,101,114,218,9,102,105,108,101,95, - 115,105,122,101,90,17,109,97,120,95,99,111,109,109,101,110, - 116,95,115,116,97,114,116,218,4,100,97,116,97,90,3,112, - 111,115,218,11,104,101,97,100,101,114,95,115,105,122,101,90, - 13,104,101,97,100,101,114,95,111,102,102,115,101,116,90,10, - 97,114,99,95,111,102,102,115,101,116,114,33,0,0,0,218, - 5,99,111,117,110,116,218,5,102,108,97,103,115,218,8,99, - 111,109,112,114,101,115,115,218,4,116,105,109,101,218,4,100, - 97,116,101,218,3,99,114,99,218,9,100,97,116,97,95,115, - 105,122,101,218,9,110,97,109,101,95,115,105,122,101,218,10, - 101,120,116,114,97,95,115,105,122,101,90,12,99,111,109,109, - 101,110,116,95,115,105,122,101,218,11,102,105,108,101,95,111, - 102,102,115,101,116,114,59,0,0,0,114,13,0,0,0,218, - 1,116,114,9,0,0,0,114,9,0,0,0,114,10,0,0, - 0,114,27,0,0,0,96,1,0,0,115,212,0,0,0,0, - 1,2,1,14,1,12,1,24,2,8,1,2,1,14,1,8, - 1,14,1,12,1,24,1,12,1,18,1,18,3,2,1,12, - 1,12,1,12,1,10,1,2,255,12,2,8,1,2,255,2, - 1,2,255,4,2,2,1,10,1,12,1,14,1,10,1,2, - 255,12,2,10,1,10,1,10,1,2,255,6,2,16,1,14, - 1,10,1,2,255,6,2,16,2,16,1,16,1,10,1,18, - 1,10,1,18,1,8,1,8,1,10,1,18,2,4,2,4, - 1,2,1,14,1,14,1,24,2,10,1,14,1,8,2,18, - 1,4,1,14,1,8,1,16,1,16,1,16,1,16,1,16, - 1,16,1,16,1,16,1,16,1,16,1,16,1,12,1,10, - 1,18,1,8,2,2,1,14,1,14,1,24,1,14,1,18, - 4,2,1,28,1,22,1,14,1,24,2,10,2,10,3,2, - 1,14,1,14,1,22,2,12,1,12,1,20,1,8,1,44, - 1,14,1,114,27,0,0,0,117,190,1,0,0,0,1,2, - 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18, - 19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34, - 35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50, - 51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66, - 67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82, - 83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98, - 99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114, - 115,116,117,118,119,120,121,122,123,124,125,126,127,195,135,195, - 188,195,169,195,162,195,164,195,160,195,165,195,167,195,170,195, - 171,195,168,195,175,195,174,195,172,195,132,195,133,195,137,195, - 166,195,134,195,180,195,182,195,178,195,187,195,185,195,191,195, - 150,195,156,194,162,194,163,194,165,226,130,167,198,146,195,161, - 195,173,195,179,195,186,195,177,195,145,194,170,194,186,194,191, - 226,140,144,194,172,194,189,194,188,194,161,194,171,194,187,226, - 150,145,226,150,146,226,150,147,226,148,130,226,148,164,226,149, - 161,226,149,162,226,149,150,226,149,149,226,149,163,226,149,145, - 226,149,151,226,149,157,226,149,156,226,149,155,226,148,144,226, - 148,148,226,148,180,226,148,172,226,148,156,226,148,128,226,148, - 188,226,149,158,226,149,159,226,149,154,226,149,148,226,149,169, - 226,149,166,226,149,160,226,149,144,226,149,172,226,149,167,226, - 149,168,226,149,164,226,149,165,226,149,153,226,149,152,226,149, - 146,226,149,147,226,149,171,226,149,170,226,148,152,226,148,140, - 226,150,136,226,150,132,226,150,140,226,150,144,226,150,128,206, - 177,195,159,206,147,207,128,206,163,207,131,194,181,207,132,206, - 166,206,152,206,169,206,180,226,136,158,207,134,206,181,226,136, - 169,226,137,161,194,177,226,137,165,226,137,164,226,140,160,226, - 140,161,195,183,226,137,136,194,176,226,136,153,194,183,226,136, - 154,226,129,191,194,178,226,150,160,194,160,99,0,0,0,0, - 0,0,0,0,0,0,0,0,1,0,0,0,8,0,0,0, - 67,0,0,0,115,110,0,0,0,116,0,114,22,116,1,160, - 2,100,1,161,1,1,0,116,3,100,2,131,1,130,1,100, - 3,97,0,122,62,122,16,100,4,100,5,108,4,109,5,125, - 0,1,0,87,0,110,36,4,0,116,6,121,80,1,0,1, - 0,1,0,116,1,160,2,100,1,161,1,1,0,116,3,100, - 2,131,1,130,1,89,0,110,2,48,0,87,0,100,6,97, - 0,110,6,100,6,97,0,48,0,116,1,160,2,100,7,161, - 1,1,0,124,0,83,0,41,8,78,122,27,122,105,112,105, - 109,112,111,114,116,58,32,122,108,105,98,32,85,78,65,86, - 65,73,76,65,66,76,69,250,41,99,97,110,39,116,32,100, - 101,99,111,109,112,114,101,115,115,32,100,97,116,97,59,32, - 122,108,105,98,32,110,111,116,32,97,118,97,105,108,97,98, - 108,101,84,114,0,0,0,0,169,1,218,10,100,101,99,111, - 109,112,114,101,115,115,70,122,25,122,105,112,105,109,112,111, - 114,116,58,32,122,108,105,98,32,97,118,97,105,108,97,98, - 108,101,41,7,218,15,95,105,109,112,111,114,116,105,110,103, - 95,122,108,105,98,114,76,0,0,0,114,77,0,0,0,114, - 3,0,0,0,90,4,122,108,105,98,114,141,0,0,0,218, - 9,69,120,99,101,112,116,105,111,110,114,140,0,0,0,114, - 9,0,0,0,114,9,0,0,0,114,10,0,0,0,218,20, - 95,103,101,116,95,100,101,99,111,109,112,114,101,115,115,95, - 102,117,110,99,254,1,0,0,115,24,0,0,0,0,2,4, - 3,10,1,8,2,4,1,4,1,16,1,12,1,10,1,16, - 2,12,2,10,1,114,144,0,0,0,99,2,0,0,0,0, - 0,0,0,0,0,0,0,17,0,0,0,9,0,0,0,67, - 0,0,0,115,144,1,0,0,124,1,92,8,125,2,125,3, - 125,4,125,5,125,6,125,7,125,8,125,9,124,4,100,1, - 107,0,114,36,116,0,100,2,131,1,130,1,116,1,160,2, - 124,0,161,1,144,1,143,14,125,10,122,14,124,10,160,3, - 124,6,161,1,1,0,87,0,110,36,4,0,116,4,121,100, - 1,0,1,0,1,0,116,0,100,3,124,0,155,2,157,2, - 124,0,100,4,141,2,130,1,89,0,110,2,48,0,124,10, - 160,5,100,5,161,1,125,11,116,6,124,11,131,1,100,5, - 107,3,114,132,116,7,100,6,131,1,130,1,124,11,100,0, - 100,7,133,2,25,0,100,8,107,3,114,166,116,0,100,9, - 124,0,155,2,157,2,124,0,100,4,141,2,130,1,116,8, - 124,11,100,10,100,11,133,2,25,0,131,1,125,12,116,8, - 124,11,100,11,100,5,133,2,25,0,131,1,125,13,100,5, - 124,12,23,0,124,13,23,0,125,14,124,6,124,14,55,0, - 125,6,122,14,124,10,160,3,124,6,161,1,1,0,87,0, - 110,38,4,0,116,4,144,1,121,14,1,0,1,0,1,0, - 116,0,100,3,124,0,155,2,157,2,124,0,100,4,141,2, - 130,1,89,0,110,2,48,0,124,10,160,5,124,4,161,1, - 125,15,116,6,124,15,131,1,124,4,107,3,144,1,114,48, - 116,4,100,12,131,1,130,1,87,0,100,0,4,0,4,0, - 131,3,1,0,110,18,49,0,144,1,115,70,48,0,1,0, - 1,0,1,0,89,0,1,0,124,3,100,1,107,2,144,1, - 114,94,124,15,83,0,122,10,116,9,131,0,125,16,87,0, - 110,28,4,0,116,10,144,1,121,132,1,0,1,0,1,0, - 116,0,100,13,131,1,130,1,89,0,110,2,48,0,124,16, - 124,15,100,14,131,2,83,0,41,15,78,114,0,0,0,0, - 122,18,110,101,103,97,116,105,118,101,32,100,97,116,97,32, - 115,105,122,101,114,92,0,0,0,114,12,0,0,0,114,104, - 0,0,0,114,98,0,0,0,114,93,0,0,0,115,4,0, - 0,0,80,75,3,4,122,23,98,97,100,32,108,111,99,97, - 108,32,102,105,108,101,32,104,101,97,100,101,114,58,32,233, - 26,0,0,0,114,103,0,0,0,122,26,122,105,112,105,109, - 112,111,114,116,58,32,99,97,110,39,116,32,114,101,97,100, - 32,100,97,116,97,114,139,0,0,0,105,241,255,255,255,41, - 11,114,3,0,0,0,114,110,0,0,0,114,111,0,0,0, - 114,112,0,0,0,114,22,0,0,0,114,114,0,0,0,114, - 51,0,0,0,114,119,0,0,0,114,1,0,0,0,114,144, - 0,0,0,114,143,0,0,0,41,17,114,29,0,0,0,114, - 54,0,0,0,90,8,100,97,116,97,112,97,116,104,114,130, - 0,0,0,114,134,0,0,0,114,125,0,0,0,114,137,0, - 0,0,114,131,0,0,0,114,132,0,0,0,114,133,0,0, - 0,114,123,0,0,0,114,124,0,0,0,114,135,0,0,0, - 114,136,0,0,0,114,127,0,0,0,90,8,114,97,119,95, - 100,97,116,97,114,141,0,0,0,114,9,0,0,0,114,9, - 0,0,0,114,10,0,0,0,114,52,0,0,0,19,2,0, - 0,115,62,0,0,0,0,1,20,1,8,1,8,2,14,2, - 2,1,14,1,12,1,24,1,10,1,12,1,8,2,16,2, - 18,2,16,1,16,1,12,1,8,1,2,1,14,1,14,1, - 24,1,10,1,14,1,40,2,10,2,4,3,2,1,10,1, - 14,1,14,1,114,52,0,0,0,99,2,0,0,0,0,0, - 0,0,0,0,0,0,2,0,0,0,3,0,0,0,67,0, - 0,0,115,16,0,0,0,116,0,124,0,124,1,24,0,131, - 1,100,1,107,1,83,0,41,2,78,114,5,0,0,0,41, - 1,218,3,97,98,115,41,2,90,2,116,49,90,2,116,50, - 114,9,0,0,0,114,9,0,0,0,114,10,0,0,0,218, - 9,95,101,113,95,109,116,105,109,101,65,2,0,0,115,2, - 0,0,0,0,2,114,147,0,0,0,99,5,0,0,0,0, - 0,0,0,0,0,0,0,14,0,0,0,8,0,0,0,67, - 0,0,0,115,56,1,0,0,124,3,124,2,100,1,156,2, - 125,5,122,18,116,0,160,1,124,4,124,3,124,5,161,3, - 125,6,87,0,110,20,4,0,116,2,121,48,1,0,1,0, - 1,0,89,0,100,0,83,0,48,0,124,6,100,2,64,0, - 100,3,107,3,125,7,124,7,114,178,124,6,100,4,64,0, - 100,3,107,3,125,8,116,3,106,4,100,5,107,3,114,176, - 124,8,115,102,116,3,106,4,100,6,107,2,114,176,116,5, - 124,0,124,2,131,2,125,9,124,9,100,0,117,1,114,176, - 116,3,160,6,116,0,106,7,124,9,161,2,125,10,122,20, - 116,0,160,8,124,4,124,10,124,3,124,5,161,4,1,0, - 87,0,110,20,4,0,116,2,121,174,1,0,1,0,1,0, - 89,0,100,0,83,0,48,0,110,84,116,9,124,0,124,2, - 131,2,92,2,125,11,125,12,124,11,144,1,114,6,116,10, - 116,11,124,4,100,7,100,8,133,2,25,0,131,1,124,11, - 131,2,114,242,116,11,124,4,100,8,100,9,133,2,25,0, - 131,1,124,12,107,3,144,1,114,6,116,12,160,13,100,10, - 124,3,155,2,157,2,161,1,1,0,100,0,83,0,116,14, - 160,15,124,4,100,9,100,0,133,2,25,0,161,1,125,13, - 116,16,124,13,116,17,131,2,144,1,115,52,116,18,100,11, - 124,1,155,2,100,12,157,3,131,1,130,1,124,13,83,0, - 41,13,78,41,2,114,59,0,0,0,114,13,0,0,0,114, - 5,0,0,0,114,0,0,0,0,114,86,0,0,0,90,5, - 110,101,118,101,114,90,6,97,108,119,97,121,115,114,99,0, - 0,0,114,94,0,0,0,114,95,0,0,0,122,22,98,121, - 116,101,99,111,100,101,32,105,115,32,115,116,97,108,101,32, - 102,111,114,32,122,16,99,111,109,112,105,108,101,100,32,109, - 111,100,117,108,101,32,122,21,32,105,115,32,110,111,116,32, - 97,32,99,111,100,101,32,111,98,106,101,99,116,41,19,114, - 21,0,0,0,90,13,95,99,108,97,115,115,105,102,121,95, - 112,121,99,114,75,0,0,0,218,4,95,105,109,112,90,21, - 99,104,101,99,107,95,104,97,115,104,95,98,97,115,101,100, - 95,112,121,99,115,218,15,95,103,101,116,95,112,121,99,95, - 115,111,117,114,99,101,218,11,115,111,117,114,99,101,95,104, - 97,115,104,90,17,95,82,65,87,95,77,65,71,73,67,95, - 78,85,77,66,69,82,90,18,95,118,97,108,105,100,97,116, - 101,95,104,97,115,104,95,112,121,99,218,29,95,103,101,116, - 95,109,116,105,109,101,95,97,110,100,95,115,105,122,101,95, - 111,102,95,115,111,117,114,99,101,114,147,0,0,0,114,2, - 0,0,0,114,76,0,0,0,114,77,0,0,0,218,7,109, - 97,114,115,104,97,108,90,5,108,111,97,100,115,114,15,0, - 0,0,218,10,95,99,111,100,101,95,116,121,112,101,218,9, - 84,121,112,101,69,114,114,111,114,41,14,114,32,0,0,0, - 114,53,0,0,0,114,63,0,0,0,114,38,0,0,0,114, - 126,0,0,0,90,11,101,120,99,95,100,101,116,97,105,108, - 115,114,129,0,0,0,90,10,104,97,115,104,95,98,97,115, - 101,100,90,12,99,104,101,99,107,95,115,111,117,114,99,101, - 90,12,115,111,117,114,99,101,95,98,121,116,101,115,114,150, - 0,0,0,90,12,115,111,117,114,99,101,95,109,116,105,109, - 101,90,11,115,111,117,114,99,101,95,115,105,122,101,114,46, - 0,0,0,114,9,0,0,0,114,9,0,0,0,114,10,0, - 0,0,218,15,95,117,110,109,97,114,115,104,97,108,95,99, - 111,100,101,75,2,0,0,115,82,0,0,0,0,2,2,1, - 2,254,6,5,2,1,18,1,12,1,8,2,12,1,4,1, - 12,1,10,1,2,255,2,1,8,255,2,2,10,1,8,1, - 4,1,4,1,2,254,4,5,2,1,4,1,8,255,8,2, - 12,1,10,3,8,255,6,3,6,3,22,1,18,255,4,2, - 4,1,8,255,4,2,4,2,18,1,12,1,16,1,114,155, - 0,0,0,99,1,0,0,0,0,0,0,0,0,0,0,0, - 1,0,0,0,4,0,0,0,67,0,0,0,115,28,0,0, - 0,124,0,160,0,100,1,100,2,161,2,125,0,124,0,160, - 0,100,3,100,2,161,2,125,0,124,0,83,0,41,4,78, - 115,2,0,0,0,13,10,243,1,0,0,0,10,243,1,0, - 0,0,13,41,1,114,19,0,0,0,41,1,218,6,115,111, - 117,114,99,101,114,9,0,0,0,114,9,0,0,0,114,10, - 0,0,0,218,23,95,110,111,114,109,97,108,105,122,101,95, - 108,105,110,101,95,101,110,100,105,110,103,115,126,2,0,0, - 115,6,0,0,0,0,1,12,1,12,1,114,159,0,0,0, - 99,2,0,0,0,0,0,0,0,0,0,0,0,2,0,0, - 0,6,0,0,0,67,0,0,0,115,24,0,0,0,116,0, - 124,1,131,1,125,1,116,1,124,1,124,0,100,1,100,2, - 100,3,141,4,83,0,41,4,78,114,74,0,0,0,84,41, - 1,90,12,100,111,110,116,95,105,110,104,101,114,105,116,41, - 2,114,159,0,0,0,218,7,99,111,109,112,105,108,101,41, - 2,114,53,0,0,0,114,158,0,0,0,114,9,0,0,0, - 114,9,0,0,0,114,10,0,0,0,218,15,95,99,111,109, - 112,105,108,101,95,115,111,117,114,99,101,133,2,0,0,115, - 4,0,0,0,0,1,8,1,114,161,0,0,0,99,2,0, - 0,0,0,0,0,0,0,0,0,0,2,0,0,0,11,0, - 0,0,67,0,0,0,115,68,0,0,0,116,0,160,1,124, - 0,100,1,63,0,100,2,23,0,124,0,100,3,63,0,100, - 4,64,0,124,0,100,5,64,0,124,1,100,6,63,0,124, - 1,100,3,63,0,100,7,64,0,124,1,100,5,64,0,100, - 8,20,0,100,9,100,9,100,9,102,9,161,1,83,0,41, - 10,78,233,9,0,0,0,105,188,7,0,0,233,5,0,0, - 0,233,15,0,0,0,233,31,0,0,0,233,11,0,0,0, - 233,63,0,0,0,114,86,0,0,0,114,14,0,0,0,41, - 2,114,131,0,0,0,90,6,109,107,116,105,109,101,41,2, - 218,1,100,114,138,0,0,0,114,9,0,0,0,114,9,0, - 0,0,114,10,0,0,0,218,14,95,112,97,114,115,101,95, - 100,111,115,116,105,109,101,139,2,0,0,115,18,0,0,0, - 0,1,4,1,10,1,10,1,6,1,6,1,10,1,10,1, - 6,249,114,169,0,0,0,99,2,0,0,0,0,0,0,0, - 0,0,0,0,6,0,0,0,10,0,0,0,67,0,0,0, - 115,114,0,0,0,122,82,124,1,100,1,100,0,133,2,25, - 0,100,2,118,0,115,22,74,0,130,1,124,1,100,0,100, - 1,133,2,25,0,125,1,124,0,106,0,124,1,25,0,125, - 2,124,2,100,3,25,0,125,3,124,2,100,4,25,0,125, - 4,124,2,100,5,25,0,125,5,116,1,124,4,124,3,131, - 2,124,5,102,2,87,0,83,0,4,0,116,2,116,3,116, - 4,102,3,121,108,1,0,1,0,1,0,89,0,100,6,83, - 0,48,0,100,0,83,0,41,7,78,114,14,0,0,0,169, - 2,218,1,99,218,1,111,114,163,0,0,0,233,6,0,0, - 0,233,3,0,0,0,41,2,114,0,0,0,0,114,0,0, - 0,0,41,5,114,28,0,0,0,114,169,0,0,0,114,26, - 0,0,0,218,10,73,110,100,101,120,69,114,114,111,114,114, - 154,0,0,0,41,6,114,32,0,0,0,114,13,0,0,0, - 114,54,0,0,0,114,131,0,0,0,114,132,0,0,0,90, - 17,117,110,99,111,109,112,114,101,115,115,101,100,95,115,105, - 122,101,114,9,0,0,0,114,9,0,0,0,114,10,0,0, - 0,114,151,0,0,0,152,2,0,0,115,20,0,0,0,0, - 1,2,2,20,1,12,1,10,3,8,1,8,1,8,1,16, - 1,18,1,114,151,0,0,0,99,2,0,0,0,0,0,0, - 0,0,0,0,0,3,0,0,0,8,0,0,0,67,0,0, - 0,115,84,0,0,0,124,1,100,1,100,0,133,2,25,0, - 100,2,118,0,115,20,74,0,130,1,124,1,100,0,100,1, - 133,2,25,0,125,1,122,14,124,0,106,0,124,1,25,0, - 125,2,87,0,110,20,4,0,116,1,121,66,1,0,1,0, - 1,0,89,0,100,0,83,0,48,0,116,2,124,0,106,3, - 124,2,131,2,83,0,100,0,83,0,41,3,78,114,14,0, - 0,0,114,170,0,0,0,41,4,114,28,0,0,0,114,26, - 0,0,0,114,52,0,0,0,114,29,0,0,0,41,3,114, - 32,0,0,0,114,13,0,0,0,114,54,0,0,0,114,9, - 0,0,0,114,9,0,0,0,114,10,0,0,0,114,149,0, - 0,0,171,2,0,0,115,14,0,0,0,0,2,20,1,12, - 2,2,1,14,1,12,1,8,2,114,149,0,0,0,99,2, - 0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,9, - 0,0,0,67,0,0,0,115,196,0,0,0,116,0,124,0, - 124,1,131,2,125,2,116,1,68,0,93,158,92,3,125,3, - 125,4,125,5,124,2,124,3,23,0,125,6,116,2,106,3, - 100,1,124,0,106,4,116,5,124,6,100,2,100,3,141,5, - 1,0,122,14,124,0,106,6,124,6,25,0,125,7,87,0, - 110,18,4,0,116,7,121,86,1,0,1,0,1,0,89,0, - 113,14,48,0,124,7,100,4,25,0,125,8,116,8,124,0, - 106,4,124,7,131,2,125,9,124,4,114,130,116,9,124,0, - 124,8,124,6,124,1,124,9,131,5,125,10,110,10,116,10, - 124,8,124,9,131,2,125,10,124,10,100,0,117,0,114,150, - 113,14,124,7,100,4,25,0,125,8,124,10,124,5,124,8, - 102,3,2,0,1,0,83,0,113,14,116,11,100,5,124,1, - 155,2,157,2,124,1,100,6,141,2,130,1,100,0,83,0, - 41,7,78,122,13,116,114,121,105,110,103,32,123,125,123,125, - 123,125,114,86,0,0,0,41,1,90,9,118,101,114,98,111, - 115,105,116,121,114,0,0,0,0,114,57,0,0,0,114,58, - 0,0,0,41,12,114,36,0,0,0,114,89,0,0,0,114, - 76,0,0,0,114,77,0,0,0,114,29,0,0,0,114,20, - 0,0,0,114,28,0,0,0,114,26,0,0,0,114,52,0, - 0,0,114,155,0,0,0,114,161,0,0,0,114,3,0,0, - 0,41,11,114,32,0,0,0,114,38,0,0,0,114,13,0, - 0,0,114,90,0,0,0,114,91,0,0,0,114,47,0,0, - 0,114,63,0,0,0,114,54,0,0,0,114,40,0,0,0, - 114,126,0,0,0,114,46,0,0,0,114,9,0,0,0,114, - 9,0,0,0,114,10,0,0,0,114,44,0,0,0,186,2, - 0,0,115,36,0,0,0,0,1,10,1,14,1,8,1,22, - 1,2,1,14,1,12,1,6,2,8,1,12,1,4,1,18, - 2,10,1,8,3,2,1,8,1,16,2,114,44,0,0,0, - 99,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,2,0,0,0,64,0,0,0,115,60,0,0,0,101,0, - 90,1,100,0,90,2,100,1,90,3,100,2,90,4,100,3, - 100,4,132,0,90,5,100,5,100,6,132,0,90,6,100,7, - 100,8,132,0,90,7,100,9,100,10,132,0,90,8,100,11, - 100,12,132,0,90,9,100,13,83,0,41,14,114,80,0,0, - 0,122,165,80,114,105,118,97,116,101,32,99,108,97,115,115, - 32,117,115,101,100,32,116,111,32,115,117,112,112,111,114,116, - 32,90,105,112,73,109,112,111,114,116,46,103,101,116,95,114, - 101,115,111,117,114,99,101,95,114,101,97,100,101,114,40,41, - 46,10,10,32,32,32,32,84,104,105,115,32,99,108,97,115, - 115,32,105,115,32,97,108,108,111,119,101,100,32,116,111,32, - 114,101,102,101,114,101,110,99,101,32,97,108,108,32,116,104, - 101,32,105,110,110,97,114,100,115,32,97,110,100,32,112,114, - 105,118,97,116,101,32,112,97,114,116,115,32,111,102,10,32, - 32,32,32,116,104,101,32,122,105,112,105,109,112,111,114,116, - 101,114,46,10,32,32,32,32,70,99,3,0,0,0,0,0, - 0,0,0,0,0,0,3,0,0,0,2,0,0,0,67,0, - 0,0,115,16,0,0,0,124,1,124,0,95,0,124,2,124, - 0,95,1,100,0,83,0,114,88,0,0,0,41,2,114,4, - 0,0,0,114,38,0,0,0,41,3,114,32,0,0,0,114, - 4,0,0,0,114,38,0,0,0,114,9,0,0,0,114,9, - 0,0,0,114,10,0,0,0,114,34,0,0,0,220,2,0, - 0,115,4,0,0,0,0,1,6,1,122,33,95,90,105,112, - 73,109,112,111,114,116,82,101,115,111,117,114,99,101,82,101, - 97,100,101,114,46,95,95,105,110,105,116,95,95,99,2,0, - 0,0,0,0,0,0,0,0,0,0,5,0,0,0,8,0, - 0,0,67,0,0,0,115,90,0,0,0,124,0,106,0,160, - 1,100,1,100,2,161,2,125,2,124,2,155,0,100,2,124, - 1,155,0,157,3,125,3,100,3,100,4,108,2,109,3,125, - 4,1,0,122,18,124,4,124,0,106,4,160,5,124,3,161, - 1,131,1,87,0,83,0,4,0,116,6,121,84,1,0,1, - 0,1,0,116,7,124,3,131,1,130,1,89,0,110,2,48, - 0,100,0,83,0,41,5,78,114,85,0,0,0,114,109,0, - 0,0,114,0,0,0,0,41,1,218,7,66,121,116,101,115, - 73,79,41,8,114,38,0,0,0,114,19,0,0,0,90,2, - 105,111,114,176,0,0,0,114,4,0,0,0,114,55,0,0, - 0,114,22,0,0,0,218,17,70,105,108,101,78,111,116,70, - 111,117,110,100,69,114,114,111,114,41,5,114,32,0,0,0, - 218,8,114,101,115,111,117,114,99,101,218,16,102,117,108,108, - 110,97,109,101,95,97,115,95,112,97,116,104,114,13,0,0, - 0,114,176,0,0,0,114,9,0,0,0,114,9,0,0,0, - 114,10,0,0,0,218,13,111,112,101,110,95,114,101,115,111, - 117,114,99,101,224,2,0,0,115,14,0,0,0,0,1,14, - 1,14,1,12,1,2,1,18,1,12,1,122,38,95,90,105, - 112,73,109,112,111,114,116,82,101,115,111,117,114,99,101,82, - 101,97,100,101,114,46,111,112,101,110,95,114,101,115,111,117, + 0,0,218,12,103,101,116,95,102,105,108,101,110,97,109,101, + 184,0,0,0,115,4,0,0,0,0,7,16,1,122,24,122, + 105,112,105,109,112,111,114,116,101,114,46,103,101,116,95,102, + 105,108,101,110,97,109,101,99,2,0,0,0,0,0,0,0, + 0,0,0,0,6,0,0,0,8,0,0,0,67,0,0,0, + 115,126,0,0,0,116,0,124,0,124,1,131,2,125,2,124, + 2,100,1,117,0,114,36,116,1,100,2,124,1,155,2,157, + 2,124,1,100,3,141,2,130,1,116,2,124,0,124,1,131, + 2,125,3,124,2,114,64,116,3,160,4,124,3,100,4,161, + 2,125,4,110,10,124,3,155,0,100,5,157,2,125,4,122, + 14,124,0,106,5,124,4,25,0,125,5,87,0,110,20,4, + 0,116,6,121,108,1,0,1,0,1,0,89,0,100,1,83, + 0,48,0,116,7,124,0,106,8,124,5,131,2,160,9,161, + 0,83,0,41,6,122,253,103,101,116,95,115,111,117,114,99, + 101,40,102,117,108,108,110,97,109,101,41,32,45,62,32,115, + 111,117,114,99,101,32,115,116,114,105,110,103,46,10,10,32, + 32,32,32,32,32,32,32,82,101,116,117,114,110,32,116,104, + 101,32,115,111,117,114,99,101,32,99,111,100,101,32,102,111, + 114,32,116,104,101,32,115,112,101,99,105,102,105,101,100,32, + 109,111,100,117,108,101,46,32,82,97,105,115,101,32,90,105, + 112,73,109,112,111,114,116,69,114,114,111,114,10,32,32,32, + 32,32,32,32,32,105,102,32,116,104,101,32,109,111,100,117, + 108,101,32,99,111,117,108,100,110,39,116,32,98,101,32,102, + 111,117,110,100,44,32,114,101,116,117,114,110,32,78,111,110, + 101,32,105,102,32,116,104,101,32,97,114,99,104,105,118,101, + 32,100,111,101,115,10,32,32,32,32,32,32,32,32,99,111, + 110,116,97,105,110,32,116,104,101,32,109,111,100,117,108,101, + 44,32,98,117,116,32,104,97,115,32,110,111,32,115,111,117, + 114,99,101,32,102,111,114,32,105,116,46,10,32,32,32,32, + 32,32,32,32,78,250,18,99,97,110,39,116,32,102,105,110, + 100,32,109,111,100,117,108,101,32,169,1,218,4,110,97,109, + 101,250,11,95,95,105,110,105,116,95,95,46,112,121,250,3, + 46,112,121,41,10,114,35,0,0,0,114,3,0,0,0,114, + 36,0,0,0,114,21,0,0,0,114,30,0,0,0,114,28, + 0,0,0,114,26,0,0,0,114,52,0,0,0,114,29,0, + 0,0,218,6,100,101,99,111,100,101,41,6,114,32,0,0, + 0,114,38,0,0,0,114,39,0,0,0,114,13,0,0,0, + 218,8,102,117,108,108,112,97,116,104,114,54,0,0,0,114, + 9,0,0,0,114,9,0,0,0,114,10,0,0,0,218,10, + 103,101,116,95,115,111,117,114,99,101,195,0,0,0,115,24, + 0,0,0,0,7,10,1,8,1,18,2,10,1,4,1,14, + 2,10,2,2,1,14,1,12,2,8,1,122,22,122,105,112, + 105,109,112,111,114,116,101,114,46,103,101,116,95,115,111,117, 114,99,101,99,2,0,0,0,0,0,0,0,0,0,0,0, - 2,0,0,0,1,0,0,0,67,0,0,0,115,8,0,0, - 0,116,0,130,1,100,0,83,0,114,88,0,0,0,41,1, - 114,177,0,0,0,41,2,114,32,0,0,0,114,178,0,0, + 3,0,0,0,4,0,0,0,67,0,0,0,115,40,0,0, + 0,116,0,124,0,124,1,131,2,125,2,124,2,100,1,117, + 0,114,36,116,1,100,2,124,1,155,2,157,2,124,1,100, + 3,141,2,130,1,124,2,83,0,41,4,122,171,105,115,95, + 112,97,99,107,97,103,101,40,102,117,108,108,110,97,109,101, + 41,32,45,62,32,98,111,111,108,46,10,10,32,32,32,32, + 32,32,32,32,82,101,116,117,114,110,32,84,114,117,101,32, + 105,102,32,116,104,101,32,109,111,100,117,108,101,32,115,112, + 101,99,105,102,105,101,100,32,98,121,32,102,117,108,108,110, + 97,109,101,32,105,115,32,97,32,112,97,99,107,97,103,101, + 46,10,32,32,32,32,32,32,32,32,82,97,105,115,101,32, + 90,105,112,73,109,112,111,114,116,69,114,114,111,114,32,105, + 102,32,116,104,101,32,109,111,100,117,108,101,32,99,111,117, + 108,100,110,39,116,32,98,101,32,102,111,117,110,100,46,10, + 32,32,32,32,32,32,32,32,78,114,57,0,0,0,114,58, + 0,0,0,41,2,114,35,0,0,0,114,3,0,0,0,41, + 3,114,32,0,0,0,114,38,0,0,0,114,39,0,0,0, + 114,9,0,0,0,114,9,0,0,0,114,10,0,0,0,218, + 10,105,115,95,112,97,99,107,97,103,101,221,0,0,0,115, + 8,0,0,0,0,6,10,1,8,1,18,1,122,22,122,105, + 112,105,109,112,111,114,116,101,114,46,105,115,95,112,97,99, + 107,97,103,101,99,2,0,0,0,0,0,0,0,0,0,0, + 0,8,0,0,0,8,0,0,0,67,0,0,0,115,246,0, + 0,0,116,0,124,0,124,1,131,2,92,3,125,2,125,3, + 125,4,116,1,106,2,160,3,124,1,161,1,125,5,124,5, + 100,1,117,0,115,46,116,4,124,5,116,5,131,2,115,64, + 116,5,124,1,131,1,125,5,124,5,116,1,106,2,124,1, + 60,0,124,0,124,5,95,6,122,84,124,3,114,108,116,7, + 124,0,124,1,131,2,125,6,116,8,160,9,124,0,106,10, + 124,6,161,2,125,7,124,7,103,1,124,5,95,11,116,12, + 124,5,100,2,131,2,115,124,116,13,124,5,95,13,116,8, + 160,14,124,5,106,15,124,1,124,4,161,3,1,0,116,16, + 124,2,124,5,106,15,131,2,1,0,87,0,110,22,1,0, + 1,0,1,0,116,1,106,2,124,1,61,0,130,0,89,0, + 110,2,48,0,122,14,116,1,106,2,124,1,25,0,125,5, + 87,0,110,34,4,0,116,17,121,226,1,0,1,0,1,0, + 116,18,100,3,124,1,155,2,100,4,157,3,131,1,130,1, + 89,0,110,2,48,0,116,19,160,20,100,5,124,1,124,4, + 161,3,1,0,124,5,83,0,41,6,122,245,108,111,97,100, + 95,109,111,100,117,108,101,40,102,117,108,108,110,97,109,101, + 41,32,45,62,32,109,111,100,117,108,101,46,10,10,32,32, + 32,32,32,32,32,32,76,111,97,100,32,116,104,101,32,109, + 111,100,117,108,101,32,115,112,101,99,105,102,105,101,100,32, + 98,121,32,39,102,117,108,108,110,97,109,101,39,46,32,39, + 102,117,108,108,110,97,109,101,39,32,109,117,115,116,32,98, + 101,32,116,104,101,10,32,32,32,32,32,32,32,32,102,117, + 108,108,121,32,113,117,97,108,105,102,105,101,100,32,40,100, + 111,116,116,101,100,41,32,109,111,100,117,108,101,32,110,97, + 109,101,46,32,73,116,32,114,101,116,117,114,110,115,32,116, + 104,101,32,105,109,112,111,114,116,101,100,10,32,32,32,32, + 32,32,32,32,109,111,100,117,108,101,44,32,111,114,32,114, + 97,105,115,101,115,32,90,105,112,73,109,112,111,114,116,69, + 114,114,111,114,32,105,102,32,105,116,32,119,97,115,110,39, + 116,32,102,111,117,110,100,46,10,32,32,32,32,32,32,32, + 32,78,218,12,95,95,98,117,105,108,116,105,110,115,95,95, + 122,14,76,111,97,100,101,100,32,109,111,100,117,108,101,32, + 122,25,32,110,111,116,32,102,111,117,110,100,32,105,110,32, + 115,121,115,46,109,111,100,117,108,101,115,122,30,105,109,112, + 111,114,116,32,123,125,32,35,32,108,111,97,100,101,100,32, + 102,114,111,109,32,90,105,112,32,123,125,41,21,114,44,0, + 0,0,218,3,115,121,115,218,7,109,111,100,117,108,101,115, + 218,3,103,101,116,114,15,0,0,0,218,12,95,109,111,100, + 117,108,101,95,116,121,112,101,218,10,95,95,108,111,97,100, + 101,114,95,95,114,36,0,0,0,114,21,0,0,0,114,30, + 0,0,0,114,29,0,0,0,90,8,95,95,112,97,116,104, + 95,95,218,7,104,97,115,97,116,116,114,114,66,0,0,0, + 90,14,95,102,105,120,95,117,112,95,109,111,100,117,108,101, + 218,8,95,95,100,105,99,116,95,95,218,4,101,120,101,99, + 114,26,0,0,0,218,11,73,109,112,111,114,116,69,114,114, + 111,114,218,10,95,98,111,111,116,115,116,114,97,112,218,16, + 95,118,101,114,98,111,115,101,95,109,101,115,115,97,103,101, + 41,8,114,32,0,0,0,114,38,0,0,0,114,46,0,0, + 0,114,47,0,0,0,114,40,0,0,0,90,3,109,111,100, + 114,13,0,0,0,114,63,0,0,0,114,9,0,0,0,114, + 9,0,0,0,114,10,0,0,0,218,11,108,111,97,100,95, + 109,111,100,117,108,101,234,0,0,0,115,48,0,0,0,0, + 7,16,1,12,1,18,1,8,1,10,1,6,2,2,1,4, + 3,10,1,14,1,8,2,10,1,6,1,16,1,16,1,6, + 1,8,1,8,2,2,1,14,1,12,1,22,1,14,1,122, + 23,122,105,112,105,109,112,111,114,116,101,114,46,108,111,97, + 100,95,109,111,100,117,108,101,99,2,0,0,0,0,0,0, + 0,0,0,0,0,3,0,0,0,8,0,0,0,67,0,0, + 0,115,64,0,0,0,122,20,124,0,160,0,124,1,161,1, + 115,18,87,0,100,1,83,0,87,0,110,20,4,0,116,1, + 121,40,1,0,1,0,1,0,89,0,100,1,83,0,48,0, + 100,2,100,3,108,2,109,3,125,2,1,0,124,2,124,0, + 124,1,131,2,83,0,41,4,122,204,82,101,116,117,114,110, + 32,116,104,101,32,82,101,115,111,117,114,99,101,82,101,97, + 100,101,114,32,102,111,114,32,97,32,112,97,99,107,97,103, + 101,32,105,110,32,97,32,122,105,112,32,102,105,108,101,46, + 10,10,32,32,32,32,32,32,32,32,73,102,32,39,102,117, + 108,108,110,97,109,101,39,32,105,115,32,97,32,112,97,99, + 107,97,103,101,32,119,105,116,104,105,110,32,116,104,101,32, + 122,105,112,32,102,105,108,101,44,32,114,101,116,117,114,110, + 32,116,104,101,10,32,32,32,32,32,32,32,32,39,82,101, + 115,111,117,114,99,101,82,101,97,100,101,114,39,32,111,98, + 106,101,99,116,32,102,111,114,32,116,104,101,32,112,97,99, + 107,97,103,101,46,32,32,79,116,104,101,114,119,105,115,101, + 32,114,101,116,117,114,110,32,78,111,110,101,46,10,32,32, + 32,32,32,32,32,32,78,114,0,0,0,0,41,1,218,9, + 90,105,112,82,101,97,100,101,114,41,4,114,65,0,0,0, + 114,3,0,0,0,90,17,105,109,112,111,114,116,108,105,98, + 46,114,101,97,100,101,114,115,114,79,0,0,0,41,3,114, + 32,0,0,0,114,38,0,0,0,114,79,0,0,0,114,9, + 0,0,0,114,9,0,0,0,114,10,0,0,0,218,19,103, + 101,116,95,114,101,115,111,117,114,99,101,95,114,101,97,100, + 101,114,16,1,0,0,115,14,0,0,0,0,6,2,1,10, + 1,10,1,12,1,8,1,12,1,122,31,122,105,112,105,109, + 112,111,114,116,101,114,46,103,101,116,95,114,101,115,111,117, + 114,99,101,95,114,101,97,100,101,114,99,1,0,0,0,0, + 0,0,0,0,0,0,0,1,0,0,0,5,0,0,0,67, + 0,0,0,115,24,0,0,0,100,1,124,0,106,0,155,0, + 116,1,155,0,124,0,106,2,155,0,100,2,157,5,83,0, + 41,3,78,122,21,60,122,105,112,105,109,112,111,114,116,101, + 114,32,111,98,106,101,99,116,32,34,122,2,34,62,41,3, + 114,29,0,0,0,114,20,0,0,0,114,31,0,0,0,41, + 1,114,32,0,0,0,114,9,0,0,0,114,9,0,0,0, + 114,10,0,0,0,218,8,95,95,114,101,112,114,95,95,31, + 1,0,0,115,2,0,0,0,0,1,122,20,122,105,112,105, + 109,112,111,114,116,101,114,46,95,95,114,101,112,114,95,95, + 41,1,78,41,1,78,41,15,114,6,0,0,0,114,7,0, + 0,0,114,8,0,0,0,218,7,95,95,100,111,99,95,95, + 114,34,0,0,0,114,41,0,0,0,114,42,0,0,0,114, + 48,0,0,0,114,55,0,0,0,114,56,0,0,0,114,64, + 0,0,0,114,65,0,0,0,114,78,0,0,0,114,80,0, + 0,0,114,81,0,0,0,114,9,0,0,0,114,9,0,0, + 0,114,9,0,0,0,114,10,0,0,0,114,4,0,0,0, + 45,0,0,0,115,24,0,0,0,8,1,4,17,8,46,10, + 32,10,12,8,10,8,21,8,11,8,26,8,13,8,38,8, + 15,122,12,95,95,105,110,105,116,95,95,46,112,121,99,84, + 114,60,0,0,0,70,41,3,122,4,46,112,121,99,84,70, + 41,3,114,61,0,0,0,70,70,99,2,0,0,0,0,0, + 0,0,0,0,0,0,2,0,0,0,4,0,0,0,67,0, + 0,0,115,20,0,0,0,124,0,106,0,124,1,160,1,100, + 1,161,1,100,2,25,0,23,0,83,0,41,3,78,218,1, + 46,233,2,0,0,0,41,2,114,31,0,0,0,218,10,114, + 112,97,114,116,105,116,105,111,110,41,2,114,32,0,0,0, + 114,38,0,0,0,114,9,0,0,0,114,9,0,0,0,114, + 10,0,0,0,114,36,0,0,0,49,1,0,0,115,2,0, + 0,0,0,1,114,36,0,0,0,99,2,0,0,0,0,0, + 0,0,0,0,0,0,3,0,0,0,2,0,0,0,67,0, + 0,0,115,18,0,0,0,124,1,116,0,23,0,125,2,124, + 2,124,0,106,1,118,0,83,0,169,1,78,41,2,114,20, + 0,0,0,114,28,0,0,0,41,3,114,32,0,0,0,114, + 13,0,0,0,90,7,100,105,114,112,97,116,104,114,9,0, + 0,0,114,9,0,0,0,114,10,0,0,0,114,37,0,0, + 0,53,1,0,0,115,4,0,0,0,0,4,8,2,114,37, + 0,0,0,99,2,0,0,0,0,0,0,0,0,0,0,0, + 7,0,0,0,4,0,0,0,67,0,0,0,115,56,0,0, + 0,116,0,124,0,124,1,131,2,125,2,116,1,68,0,93, + 36,92,3,125,3,125,4,125,5,124,2,124,3,23,0,125, + 6,124,6,124,0,106,2,118,0,114,14,124,5,2,0,1, + 0,83,0,113,14,100,0,83,0,114,86,0,0,0,41,3, + 114,36,0,0,0,218,16,95,122,105,112,95,115,101,97,114, + 99,104,111,114,100,101,114,114,28,0,0,0,41,7,114,32, + 0,0,0,114,38,0,0,0,114,13,0,0,0,218,6,115, + 117,102,102,105,120,218,10,105,115,98,121,116,101,99,111,100, + 101,114,47,0,0,0,114,63,0,0,0,114,9,0,0,0, + 114,9,0,0,0,114,10,0,0,0,114,35,0,0,0,62, + 1,0,0,115,12,0,0,0,0,1,10,1,14,1,8,1, + 10,1,10,1,114,35,0,0,0,99,1,0,0,0,0,0, + 0,0,0,0,0,0,26,0,0,0,9,0,0,0,67,0, + 0,0,115,2,5,0,0,122,14,116,0,160,1,124,0,161, + 1,125,1,87,0,110,36,4,0,116,2,121,50,1,0,1, + 0,1,0,116,3,100,1,124,0,155,2,157,2,124,0,100, + 2,141,2,130,1,89,0,110,2,48,0,124,1,144,4,143, + 164,1,0,122,36,124,1,160,4,116,5,11,0,100,3,161, + 2,1,0,124,1,160,6,161,0,125,2,124,1,160,7,116, + 5,161,1,125,3,87,0,110,36,4,0,116,2,121,132,1, + 0,1,0,1,0,116,3,100,4,124,0,155,2,157,2,124, + 0,100,2,141,2,130,1,89,0,110,2,48,0,116,8,124, + 3,131,1,116,5,107,3,114,164,116,3,100,4,124,0,155, + 2,157,2,124,0,100,2,141,2,130,1,124,3,100,0,100, + 5,133,2,25,0,116,9,107,3,144,1,114,170,122,24,124, + 1,160,4,100,6,100,3,161,2,1,0,124,1,160,6,161, + 0,125,4,87,0,110,36,4,0,116,2,121,242,1,0,1, + 0,1,0,116,3,100,4,124,0,155,2,157,2,124,0,100, + 2,141,2,130,1,89,0,110,2,48,0,116,10,124,4,116, + 11,24,0,116,5,24,0,100,6,131,2,125,5,122,22,124, + 1,160,4,124,5,161,1,1,0,124,1,160,7,161,0,125, + 6,87,0,110,38,4,0,116,2,144,1,121,66,1,0,1, + 0,1,0,116,3,100,4,124,0,155,2,157,2,124,0,100, + 2,141,2,130,1,89,0,110,2,48,0,124,6,160,12,116, + 9,161,1,125,7,124,7,100,6,107,0,144,1,114,106,116, + 3,100,7,124,0,155,2,157,2,124,0,100,2,141,2,130, + 1,124,6,124,7,124,7,116,5,23,0,133,2,25,0,125, + 3,116,8,124,3,131,1,116,5,107,3,144,1,114,154,116, + 3,100,8,124,0,155,2,157,2,124,0,100,2,141,2,130, + 1,124,4,116,8,124,6,131,1,24,0,124,7,23,0,125, + 2,116,13,124,3,100,9,100,10,133,2,25,0,131,1,125, + 8,116,13,124,3,100,10,100,11,133,2,25,0,131,1,125, + 9,124,2,124,8,107,0,144,1,114,230,116,3,100,12,124, + 0,155,2,157,2,124,0,100,2,141,2,130,1,124,2,124, + 9,107,0,144,2,114,2,116,3,100,13,124,0,155,2,157, + 2,124,0,100,2,141,2,130,1,124,2,124,8,56,0,125, + 2,124,2,124,9,24,0,125,10,124,10,100,6,107,0,144, + 2,114,46,116,3,100,14,124,0,155,2,157,2,124,0,100, + 2,141,2,130,1,105,0,125,11,100,6,125,12,122,14,124, + 1,160,4,124,2,161,1,1,0,87,0,110,38,4,0,116, + 2,144,2,121,106,1,0,1,0,1,0,116,3,100,4,124, + 0,155,2,157,2,124,0,100,2,141,2,130,1,89,0,110, + 2,48,0,124,1,160,7,100,15,161,1,125,3,116,8,124, + 3,131,1,100,5,107,0,144,2,114,140,116,14,100,16,131, + 1,130,1,124,3,100,0,100,5,133,2,25,0,100,17,107, + 3,144,2,114,162,144,4,113,208,116,8,124,3,131,1,100, + 15,107,3,144,2,114,184,116,14,100,16,131,1,130,1,116, + 15,124,3,100,18,100,19,133,2,25,0,131,1,125,13,116, + 15,124,3,100,19,100,9,133,2,25,0,131,1,125,14,116, + 15,124,3,100,9,100,20,133,2,25,0,131,1,125,15,116, + 15,124,3,100,20,100,10,133,2,25,0,131,1,125,16,116, + 13,124,3,100,10,100,11,133,2,25,0,131,1,125,17,116, + 13,124,3,100,11,100,21,133,2,25,0,131,1,125,18,116, + 13,124,3,100,21,100,22,133,2,25,0,131,1,125,4,116, + 15,124,3,100,22,100,23,133,2,25,0,131,1,125,19,116, + 15,124,3,100,23,100,24,133,2,25,0,131,1,125,20,116, + 15,124,3,100,24,100,25,133,2,25,0,131,1,125,21,116, + 13,124,3,100,26,100,15,133,2,25,0,131,1,125,22,124, + 19,124,20,23,0,124,21,23,0,125,8,124,22,124,9,107, + 4,144,3,114,144,116,3,100,27,124,0,155,2,157,2,124, + 0,100,2,141,2,130,1,124,22,124,10,55,0,125,22,122, + 14,124,1,160,7,124,19,161,1,125,23,87,0,110,38,4, + 0,116,2,144,3,121,204,1,0,1,0,1,0,116,3,100, + 4,124,0,155,2,157,2,124,0,100,2,141,2,130,1,89, + 0,110,2,48,0,116,8,124,23,131,1,124,19,107,3,144, + 3,114,238,116,3,100,4,124,0,155,2,157,2,124,0,100, + 2,141,2,130,1,122,50,116,8,124,1,160,7,124,8,124, + 19,24,0,161,1,131,1,124,8,124,19,24,0,107,3,144, + 4,114,30,116,3,100,4,124,0,155,2,157,2,124,0,100, + 2,141,2,130,1,87,0,110,38,4,0,116,2,144,4,121, + 70,1,0,1,0,1,0,116,3,100,4,124,0,155,2,157, + 2,124,0,100,2,141,2,130,1,89,0,110,2,48,0,124, + 13,100,28,64,0,144,4,114,92,124,23,160,16,161,0,125, + 23,110,52,122,14,124,23,160,16,100,29,161,1,125,23,87, + 0,110,36,4,0,116,17,144,4,121,142,1,0,1,0,1, + 0,124,23,160,16,100,30,161,1,160,18,116,19,161,1,125, + 23,89,0,110,2,48,0,124,23,160,20,100,31,116,21,161, + 2,125,23,116,22,160,23,124,0,124,23,161,2,125,24,124, + 24,124,14,124,18,124,4,124,22,124,15,124,16,124,17,102, + 8,125,25,124,25,124,11,124,23,60,0,124,12,100,32,55, + 0,125,12,144,2,113,108,87,0,100,0,4,0,4,0,131, + 3,1,0,110,18,49,0,144,4,115,230,48,0,1,0,1, + 0,1,0,89,0,1,0,116,24,160,25,100,33,124,12,124, + 0,161,3,1,0,124,11,83,0,41,34,78,122,21,99,97, + 110,39,116,32,111,112,101,110,32,90,105,112,32,102,105,108, + 101,58,32,114,12,0,0,0,114,84,0,0,0,250,21,99, + 97,110,39,116,32,114,101,97,100,32,90,105,112,32,102,105, + 108,101,58,32,233,4,0,0,0,114,0,0,0,0,122,16, + 110,111,116,32,97,32,90,105,112,32,102,105,108,101,58,32, + 122,18,99,111,114,114,117,112,116,32,90,105,112,32,102,105, + 108,101,58,32,233,12,0,0,0,233,16,0,0,0,233,20, + 0,0,0,122,28,98,97,100,32,99,101,110,116,114,97,108, + 32,100,105,114,101,99,116,111,114,121,32,115,105,122,101,58, + 32,122,30,98,97,100,32,99,101,110,116,114,97,108,32,100, + 105,114,101,99,116,111,114,121,32,111,102,102,115,101,116,58, + 32,122,38,98,97,100,32,99,101,110,116,114,97,108,32,100, + 105,114,101,99,116,111,114,121,32,115,105,122,101,32,111,114, + 32,111,102,102,115,101,116,58,32,233,46,0,0,0,250,27, + 69,79,70,32,114,101,97,100,32,119,104,101,114,101,32,110, + 111,116,32,101,120,112,101,99,116,101,100,115,4,0,0,0, + 80,75,1,2,233,8,0,0,0,233,10,0,0,0,233,14, + 0,0,0,233,24,0,0,0,233,28,0,0,0,233,30,0, + 0,0,233,32,0,0,0,233,34,0,0,0,233,42,0,0, + 0,122,25,98,97,100,32,108,111,99,97,108,32,104,101,97, + 100,101,114,32,111,102,102,115,101,116,58,32,105,0,8,0, + 0,218,5,97,115,99,105,105,90,6,108,97,116,105,110,49, + 250,1,47,114,5,0,0,0,122,33,122,105,112,105,109,112, + 111,114,116,58,32,102,111,117,110,100,32,123,125,32,110,97, + 109,101,115,32,105,110,32,123,33,114,125,41,26,218,3,95, + 105,111,218,9,111,112,101,110,95,99,111,100,101,114,22,0, + 0,0,114,3,0,0,0,218,4,115,101,101,107,218,20,69, + 78,68,95,67,69,78,84,82,65,76,95,68,73,82,95,83, + 73,90,69,90,4,116,101,108,108,218,4,114,101,97,100,114, + 51,0,0,0,218,18,83,84,82,73,78,71,95,69,78,68, + 95,65,82,67,72,73,86,69,218,3,109,97,120,218,15,77, + 65,88,95,67,79,77,77,69,78,84,95,76,69,78,218,5, + 114,102,105,110,100,114,2,0,0,0,218,8,69,79,70,69, + 114,114,111,114,114,1,0,0,0,114,62,0,0,0,218,18, + 85,110,105,99,111,100,101,68,101,99,111,100,101,69,114,114, + 111,114,218,9,116,114,97,110,115,108,97,116,101,218,11,99, + 112,52,51,55,95,116,97,98,108,101,114,19,0,0,0,114, + 20,0,0,0,114,21,0,0,0,114,30,0,0,0,114,76, + 0,0,0,114,77,0,0,0,41,26,114,29,0,0,0,218, + 2,102,112,90,15,104,101,97,100,101,114,95,112,111,115,105, + 116,105,111,110,218,6,98,117,102,102,101,114,218,9,102,105, + 108,101,95,115,105,122,101,90,17,109,97,120,95,99,111,109, + 109,101,110,116,95,115,116,97,114,116,218,4,100,97,116,97, + 90,3,112,111,115,218,11,104,101,97,100,101,114,95,115,105, + 122,101,90,13,104,101,97,100,101,114,95,111,102,102,115,101, + 116,90,10,97,114,99,95,111,102,102,115,101,116,114,33,0, + 0,0,218,5,99,111,117,110,116,218,5,102,108,97,103,115, + 218,8,99,111,109,112,114,101,115,115,218,4,116,105,109,101, + 218,4,100,97,116,101,218,3,99,114,99,218,9,100,97,116, + 97,95,115,105,122,101,218,9,110,97,109,101,95,115,105,122, + 101,218,10,101,120,116,114,97,95,115,105,122,101,90,12,99, + 111,109,109,101,110,116,95,115,105,122,101,218,11,102,105,108, + 101,95,111,102,102,115,101,116,114,59,0,0,0,114,13,0, + 0,0,218,1,116,114,9,0,0,0,114,9,0,0,0,114, + 10,0,0,0,114,27,0,0,0,93,1,0,0,115,212,0, + 0,0,0,1,2,1,14,1,12,1,24,2,8,1,2,1, + 14,1,8,1,14,1,12,1,24,1,12,1,18,1,18,3, + 2,1,12,1,12,1,12,1,10,1,2,255,12,2,8,1, + 2,255,2,1,2,255,4,2,2,1,10,1,12,1,14,1, + 10,1,2,255,12,2,10,1,10,1,10,1,2,255,6,2, + 16,1,14,1,10,1,2,255,6,2,16,2,16,1,16,1, + 10,1,18,1,10,1,18,1,8,1,8,1,10,1,18,2, + 4,2,4,1,2,1,14,1,14,1,24,2,10,1,14,1, + 8,2,18,1,4,1,14,1,8,1,16,1,16,1,16,1, + 16,1,16,1,16,1,16,1,16,1,16,1,16,1,16,1, + 12,1,10,1,18,1,8,2,2,1,14,1,14,1,24,1, + 14,1,18,4,2,1,28,1,22,1,14,1,24,2,10,2, + 10,3,2,1,14,1,14,1,22,2,12,1,12,1,20,1, + 8,1,44,1,14,1,114,27,0,0,0,117,190,1,0,0, + 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, + 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, + 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, + 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, + 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79, + 80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95, + 96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111, + 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, + 195,135,195,188,195,169,195,162,195,164,195,160,195,165,195,167, + 195,170,195,171,195,168,195,175,195,174,195,172,195,132,195,133, + 195,137,195,166,195,134,195,180,195,182,195,178,195,187,195,185, + 195,191,195,150,195,156,194,162,194,163,194,165,226,130,167,198, + 146,195,161,195,173,195,179,195,186,195,177,195,145,194,170,194, + 186,194,191,226,140,144,194,172,194,189,194,188,194,161,194,171, + 194,187,226,150,145,226,150,146,226,150,147,226,148,130,226,148, + 164,226,149,161,226,149,162,226,149,150,226,149,149,226,149,163, + 226,149,145,226,149,151,226,149,157,226,149,156,226,149,155,226, + 148,144,226,148,148,226,148,180,226,148,172,226,148,156,226,148, + 128,226,148,188,226,149,158,226,149,159,226,149,154,226,149,148, + 226,149,169,226,149,166,226,149,160,226,149,144,226,149,172,226, + 149,167,226,149,168,226,149,164,226,149,165,226,149,153,226,149, + 152,226,149,146,226,149,147,226,149,171,226,149,170,226,148,152, + 226,148,140,226,150,136,226,150,132,226,150,140,226,150,144,226, + 150,128,206,177,195,159,206,147,207,128,206,163,207,131,194,181, + 207,132,206,166,206,152,206,169,206,180,226,136,158,207,134,206, + 181,226,136,169,226,137,161,194,177,226,137,165,226,137,164,226, + 140,160,226,140,161,195,183,226,137,136,194,176,226,136,153,194, + 183,226,136,154,226,129,191,194,178,226,150,160,194,160,99,0, + 0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,8, + 0,0,0,67,0,0,0,115,110,0,0,0,116,0,114,22, + 116,1,160,2,100,1,161,1,1,0,116,3,100,2,131,1, + 130,1,100,3,97,0,122,62,122,16,100,4,100,5,108,4, + 109,5,125,0,1,0,87,0,110,36,4,0,116,6,121,80, + 1,0,1,0,1,0,116,1,160,2,100,1,161,1,1,0, + 116,3,100,2,131,1,130,1,89,0,110,2,48,0,87,0, + 100,6,97,0,110,6,100,6,97,0,48,0,116,1,160,2, + 100,7,161,1,1,0,124,0,83,0,41,8,78,122,27,122, + 105,112,105,109,112,111,114,116,58,32,122,108,105,98,32,85, + 78,65,86,65,73,76,65,66,76,69,250,41,99,97,110,39, + 116,32,100,101,99,111,109,112,114,101,115,115,32,100,97,116, + 97,59,32,122,108,105,98,32,110,111,116,32,97,118,97,105, + 108,97,98,108,101,84,114,0,0,0,0,169,1,218,10,100, + 101,99,111,109,112,114,101,115,115,70,122,25,122,105,112,105, + 109,112,111,114,116,58,32,122,108,105,98,32,97,118,97,105, + 108,97,98,108,101,41,7,218,15,95,105,109,112,111,114,116, + 105,110,103,95,122,108,105,98,114,76,0,0,0,114,77,0, + 0,0,114,3,0,0,0,90,4,122,108,105,98,114,139,0, + 0,0,218,9,69,120,99,101,112,116,105,111,110,114,138,0, + 0,0,114,9,0,0,0,114,9,0,0,0,114,10,0,0, + 0,218,20,95,103,101,116,95,100,101,99,111,109,112,114,101, + 115,115,95,102,117,110,99,251,1,0,0,115,24,0,0,0, + 0,2,4,3,10,1,8,2,4,1,4,1,16,1,12,1, + 10,1,16,2,12,2,10,1,114,142,0,0,0,99,2,0, + 0,0,0,0,0,0,0,0,0,0,17,0,0,0,9,0, + 0,0,67,0,0,0,115,144,1,0,0,124,1,92,8,125, + 2,125,3,125,4,125,5,125,6,125,7,125,8,125,9,124, + 4,100,1,107,0,114,36,116,0,100,2,131,1,130,1,116, + 1,160,2,124,0,161,1,144,1,143,14,125,10,122,14,124, + 10,160,3,124,6,161,1,1,0,87,0,110,36,4,0,116, + 4,121,100,1,0,1,0,1,0,116,0,100,3,124,0,155, + 2,157,2,124,0,100,4,141,2,130,1,89,0,110,2,48, + 0,124,10,160,5,100,5,161,1,125,11,116,6,124,11,131, + 1,100,5,107,3,114,132,116,7,100,6,131,1,130,1,124, + 11,100,0,100,7,133,2,25,0,100,8,107,3,114,166,116, + 0,100,9,124,0,155,2,157,2,124,0,100,4,141,2,130, + 1,116,8,124,11,100,10,100,11,133,2,25,0,131,1,125, + 12,116,8,124,11,100,11,100,5,133,2,25,0,131,1,125, + 13,100,5,124,12,23,0,124,13,23,0,125,14,124,6,124, + 14,55,0,125,6,122,14,124,10,160,3,124,6,161,1,1, + 0,87,0,110,38,4,0,116,4,144,1,121,14,1,0,1, + 0,1,0,116,0,100,3,124,0,155,2,157,2,124,0,100, + 4,141,2,130,1,89,0,110,2,48,0,124,10,160,5,124, + 4,161,1,125,15,116,6,124,15,131,1,124,4,107,3,144, + 1,114,48,116,4,100,12,131,1,130,1,87,0,100,0,4, + 0,4,0,131,3,1,0,110,18,49,0,144,1,115,70,48, + 0,1,0,1,0,1,0,89,0,1,0,124,3,100,1,107, + 2,144,1,114,94,124,15,83,0,122,10,116,9,131,0,125, + 16,87,0,110,28,4,0,116,10,144,1,121,132,1,0,1, + 0,1,0,116,0,100,13,131,1,130,1,89,0,110,2,48, + 0,124,16,124,15,100,14,131,2,83,0,41,15,78,114,0, + 0,0,0,122,18,110,101,103,97,116,105,118,101,32,100,97, + 116,97,32,115,105,122,101,114,90,0,0,0,114,12,0,0, + 0,114,102,0,0,0,114,96,0,0,0,114,91,0,0,0, + 115,4,0,0,0,80,75,3,4,122,23,98,97,100,32,108, + 111,99,97,108,32,102,105,108,101,32,104,101,97,100,101,114, + 58,32,233,26,0,0,0,114,101,0,0,0,122,26,122,105, + 112,105,109,112,111,114,116,58,32,99,97,110,39,116,32,114, + 101,97,100,32,100,97,116,97,114,137,0,0,0,105,241,255, + 255,255,41,11,114,3,0,0,0,114,108,0,0,0,114,109, + 0,0,0,114,110,0,0,0,114,22,0,0,0,114,112,0, + 0,0,114,51,0,0,0,114,117,0,0,0,114,1,0,0, + 0,114,142,0,0,0,114,141,0,0,0,41,17,114,29,0, + 0,0,114,54,0,0,0,90,8,100,97,116,97,112,97,116, + 104,114,128,0,0,0,114,132,0,0,0,114,123,0,0,0, + 114,135,0,0,0,114,129,0,0,0,114,130,0,0,0,114, + 131,0,0,0,114,121,0,0,0,114,122,0,0,0,114,133, + 0,0,0,114,134,0,0,0,114,125,0,0,0,90,8,114, + 97,119,95,100,97,116,97,114,139,0,0,0,114,9,0,0, + 0,114,9,0,0,0,114,10,0,0,0,114,52,0,0,0, + 16,2,0,0,115,62,0,0,0,0,1,20,1,8,1,8, + 2,14,2,2,1,14,1,12,1,24,1,10,1,12,1,8, + 2,16,2,18,2,16,1,16,1,12,1,8,1,2,1,14, + 1,14,1,24,1,10,1,14,1,40,2,10,2,4,3,2, + 1,10,1,14,1,14,1,114,52,0,0,0,99,2,0,0, + 0,0,0,0,0,0,0,0,0,2,0,0,0,3,0,0, + 0,67,0,0,0,115,16,0,0,0,116,0,124,0,124,1, + 24,0,131,1,100,1,107,1,83,0,41,2,78,114,5,0, + 0,0,41,1,218,3,97,98,115,41,2,90,2,116,49,90, + 2,116,50,114,9,0,0,0,114,9,0,0,0,114,10,0, + 0,0,218,9,95,101,113,95,109,116,105,109,101,62,2,0, + 0,115,2,0,0,0,0,2,114,145,0,0,0,99,5,0, + 0,0,0,0,0,0,0,0,0,0,14,0,0,0,8,0, + 0,0,67,0,0,0,115,56,1,0,0,124,3,124,2,100, + 1,156,2,125,5,122,18,116,0,160,1,124,4,124,3,124, + 5,161,3,125,6,87,0,110,20,4,0,116,2,121,48,1, + 0,1,0,1,0,89,0,100,0,83,0,48,0,124,6,100, + 2,64,0,100,3,107,3,125,7,124,7,114,178,124,6,100, + 4,64,0,100,3,107,3,125,8,116,3,106,4,100,5,107, + 3,114,176,124,8,115,102,116,3,106,4,100,6,107,2,114, + 176,116,5,124,0,124,2,131,2,125,9,124,9,100,0,117, + 1,114,176,116,3,160,6,116,0,106,7,124,9,161,2,125, + 10,122,20,116,0,160,8,124,4,124,10,124,3,124,5,161, + 4,1,0,87,0,110,20,4,0,116,2,121,174,1,0,1, + 0,1,0,89,0,100,0,83,0,48,0,110,84,116,9,124, + 0,124,2,131,2,92,2,125,11,125,12,124,11,144,1,114, + 6,116,10,116,11,124,4,100,7,100,8,133,2,25,0,131, + 1,124,11,131,2,114,242,116,11,124,4,100,8,100,9,133, + 2,25,0,131,1,124,12,107,3,144,1,114,6,116,12,160, + 13,100,10,124,3,155,2,157,2,161,1,1,0,100,0,83, + 0,116,14,160,15,124,4,100,9,100,0,133,2,25,0,161, + 1,125,13,116,16,124,13,116,17,131,2,144,1,115,52,116, + 18,100,11,124,1,155,2,100,12,157,3,131,1,130,1,124, + 13,83,0,41,13,78,41,2,114,59,0,0,0,114,13,0, + 0,0,114,5,0,0,0,114,0,0,0,0,114,84,0,0, + 0,90,5,110,101,118,101,114,90,6,97,108,119,97,121,115, + 114,97,0,0,0,114,92,0,0,0,114,93,0,0,0,122, + 22,98,121,116,101,99,111,100,101,32,105,115,32,115,116,97, + 108,101,32,102,111,114,32,122,16,99,111,109,112,105,108,101, + 100,32,109,111,100,117,108,101,32,122,21,32,105,115,32,110, + 111,116,32,97,32,99,111,100,101,32,111,98,106,101,99,116, + 41,19,114,21,0,0,0,90,13,95,99,108,97,115,115,105, + 102,121,95,112,121,99,114,75,0,0,0,218,4,95,105,109, + 112,90,21,99,104,101,99,107,95,104,97,115,104,95,98,97, + 115,101,100,95,112,121,99,115,218,15,95,103,101,116,95,112, + 121,99,95,115,111,117,114,99,101,218,11,115,111,117,114,99, + 101,95,104,97,115,104,90,17,95,82,65,87,95,77,65,71, + 73,67,95,78,85,77,66,69,82,90,18,95,118,97,108,105, + 100,97,116,101,95,104,97,115,104,95,112,121,99,218,29,95, + 103,101,116,95,109,116,105,109,101,95,97,110,100,95,115,105, + 122,101,95,111,102,95,115,111,117,114,99,101,114,145,0,0, + 0,114,2,0,0,0,114,76,0,0,0,114,77,0,0,0, + 218,7,109,97,114,115,104,97,108,90,5,108,111,97,100,115, + 114,15,0,0,0,218,10,95,99,111,100,101,95,116,121,112, + 101,218,9,84,121,112,101,69,114,114,111,114,41,14,114,32, + 0,0,0,114,53,0,0,0,114,63,0,0,0,114,38,0, + 0,0,114,124,0,0,0,90,11,101,120,99,95,100,101,116, + 97,105,108,115,114,127,0,0,0,90,10,104,97,115,104,95, + 98,97,115,101,100,90,12,99,104,101,99,107,95,115,111,117, + 114,99,101,90,12,115,111,117,114,99,101,95,98,121,116,101, + 115,114,148,0,0,0,90,12,115,111,117,114,99,101,95,109, + 116,105,109,101,90,11,115,111,117,114,99,101,95,115,105,122, + 101,114,46,0,0,0,114,9,0,0,0,114,9,0,0,0, + 114,10,0,0,0,218,15,95,117,110,109,97,114,115,104,97, + 108,95,99,111,100,101,72,2,0,0,115,82,0,0,0,0, + 2,2,1,2,254,6,5,2,1,18,1,12,1,8,2,12, + 1,4,1,12,1,10,1,2,255,2,1,8,255,2,2,10, + 1,8,1,4,1,4,1,2,254,4,5,2,1,4,1,8, + 255,8,2,12,1,10,3,8,255,6,3,6,3,22,1,18, + 255,4,2,4,1,8,255,4,2,4,2,18,1,12,1,16, + 1,114,153,0,0,0,99,1,0,0,0,0,0,0,0,0, + 0,0,0,1,0,0,0,4,0,0,0,67,0,0,0,115, + 28,0,0,0,124,0,160,0,100,1,100,2,161,2,125,0, + 124,0,160,0,100,3,100,2,161,2,125,0,124,0,83,0, + 41,4,78,115,2,0,0,0,13,10,243,1,0,0,0,10, + 243,1,0,0,0,13,41,1,114,19,0,0,0,41,1,218, + 6,115,111,117,114,99,101,114,9,0,0,0,114,9,0,0, + 0,114,10,0,0,0,218,23,95,110,111,114,109,97,108,105, + 122,101,95,108,105,110,101,95,101,110,100,105,110,103,115,123, + 2,0,0,115,6,0,0,0,0,1,12,1,12,1,114,157, + 0,0,0,99,2,0,0,0,0,0,0,0,0,0,0,0, + 2,0,0,0,6,0,0,0,67,0,0,0,115,24,0,0, + 0,116,0,124,1,131,1,125,1,116,1,124,1,124,0,100, + 1,100,2,100,3,141,4,83,0,41,4,78,114,74,0,0, + 0,84,41,1,90,12,100,111,110,116,95,105,110,104,101,114, + 105,116,41,2,114,157,0,0,0,218,7,99,111,109,112,105, + 108,101,41,2,114,53,0,0,0,114,156,0,0,0,114,9, + 0,0,0,114,9,0,0,0,114,10,0,0,0,218,15,95, + 99,111,109,112,105,108,101,95,115,111,117,114,99,101,130,2, + 0,0,115,4,0,0,0,0,1,8,1,114,159,0,0,0, + 99,2,0,0,0,0,0,0,0,0,0,0,0,2,0,0, + 0,11,0,0,0,67,0,0,0,115,68,0,0,0,116,0, + 160,1,124,0,100,1,63,0,100,2,23,0,124,0,100,3, + 63,0,100,4,64,0,124,0,100,5,64,0,124,1,100,6, + 63,0,124,1,100,3,63,0,100,7,64,0,124,1,100,5, + 64,0,100,8,20,0,100,9,100,9,100,9,102,9,161,1, + 83,0,41,10,78,233,9,0,0,0,105,188,7,0,0,233, + 5,0,0,0,233,15,0,0,0,233,31,0,0,0,233,11, + 0,0,0,233,63,0,0,0,114,84,0,0,0,114,14,0, + 0,0,41,2,114,129,0,0,0,90,6,109,107,116,105,109, + 101,41,2,218,1,100,114,136,0,0,0,114,9,0,0,0, + 114,9,0,0,0,114,10,0,0,0,218,14,95,112,97,114, + 115,101,95,100,111,115,116,105,109,101,136,2,0,0,115,18, + 0,0,0,0,1,4,1,10,1,10,1,6,1,6,1,10, + 1,10,1,6,249,114,167,0,0,0,99,2,0,0,0,0, + 0,0,0,0,0,0,0,6,0,0,0,10,0,0,0,67, + 0,0,0,115,114,0,0,0,122,82,124,1,100,1,100,0, + 133,2,25,0,100,2,118,0,115,22,74,0,130,1,124,1, + 100,0,100,1,133,2,25,0,125,1,124,0,106,0,124,1, + 25,0,125,2,124,2,100,3,25,0,125,3,124,2,100,4, + 25,0,125,4,124,2,100,5,25,0,125,5,116,1,124,4, + 124,3,131,2,124,5,102,2,87,0,83,0,4,0,116,2, + 116,3,116,4,102,3,121,108,1,0,1,0,1,0,89,0, + 100,6,83,0,48,0,100,0,83,0,41,7,78,114,14,0, + 0,0,169,2,218,1,99,218,1,111,114,161,0,0,0,233, + 6,0,0,0,233,3,0,0,0,41,2,114,0,0,0,0, + 114,0,0,0,0,41,5,114,28,0,0,0,114,167,0,0, + 0,114,26,0,0,0,218,10,73,110,100,101,120,69,114,114, + 111,114,114,152,0,0,0,41,6,114,32,0,0,0,114,13, + 0,0,0,114,54,0,0,0,114,129,0,0,0,114,130,0, + 0,0,90,17,117,110,99,111,109,112,114,101,115,115,101,100, + 95,115,105,122,101,114,9,0,0,0,114,9,0,0,0,114, + 10,0,0,0,114,149,0,0,0,149,2,0,0,115,20,0, + 0,0,0,1,2,2,20,1,12,1,10,3,8,1,8,1, + 8,1,16,1,18,1,114,149,0,0,0,99,2,0,0,0, + 0,0,0,0,0,0,0,0,3,0,0,0,8,0,0,0, + 67,0,0,0,115,84,0,0,0,124,1,100,1,100,0,133, + 2,25,0,100,2,118,0,115,20,74,0,130,1,124,1,100, + 0,100,1,133,2,25,0,125,1,122,14,124,0,106,0,124, + 1,25,0,125,2,87,0,110,20,4,0,116,1,121,66,1, + 0,1,0,1,0,89,0,100,0,83,0,48,0,116,2,124, + 0,106,3,124,2,131,2,83,0,100,0,83,0,41,3,78, + 114,14,0,0,0,114,168,0,0,0,41,4,114,28,0,0, + 0,114,26,0,0,0,114,52,0,0,0,114,29,0,0,0, + 41,3,114,32,0,0,0,114,13,0,0,0,114,54,0,0, 0,114,9,0,0,0,114,9,0,0,0,114,10,0,0,0, - 218,13,114,101,115,111,117,114,99,101,95,112,97,116,104,233, - 2,0,0,115,2,0,0,0,0,4,122,38,95,90,105,112, - 73,109,112,111,114,116,82,101,115,111,117,114,99,101,82,101, - 97,100,101,114,46,114,101,115,111,117,114,99,101,95,112,97, - 116,104,99,2,0,0,0,0,0,0,0,0,0,0,0,4, - 0,0,0,8,0,0,0,67,0,0,0,115,70,0,0,0, - 124,0,106,0,160,1,100,1,100,2,161,2,125,2,124,2, - 155,0,100,2,124,1,155,0,157,3,125,3,122,16,124,0, - 106,2,160,3,124,3,161,1,1,0,87,0,110,20,4,0, - 116,4,121,64,1,0,1,0,1,0,89,0,100,3,83,0, - 48,0,100,4,83,0,41,5,78,114,85,0,0,0,114,109, - 0,0,0,70,84,41,5,114,38,0,0,0,114,19,0,0, - 0,114,4,0,0,0,114,55,0,0,0,114,22,0,0,0, - 41,4,114,32,0,0,0,114,59,0,0,0,114,179,0,0, - 0,114,13,0,0,0,114,9,0,0,0,114,9,0,0,0, - 114,10,0,0,0,218,11,105,115,95,114,101,115,111,117,114, - 99,101,239,2,0,0,115,14,0,0,0,0,3,14,1,14, - 1,2,1,16,1,12,1,8,1,122,36,95,90,105,112,73, - 109,112,111,114,116,82,101,115,111,117,114,99,101,82,101,97, - 100,101,114,46,105,115,95,114,101,115,111,117,114,99,101,99, - 1,0,0,0,0,0,0,0,0,0,0,0,9,0,0,0, - 9,0,0,0,99,0,0,0,115,184,0,0,0,100,1,100, - 2,108,0,109,1,125,1,1,0,124,1,124,0,106,2,160, - 3,124,0,106,4,161,1,131,1,125,2,124,2,160,5,124, - 0,106,2,106,6,161,1,125,3,124,3,106,7,100,3,107, - 2,115,58,74,0,130,1,124,3,106,8,125,4,116,9,131, - 0,125,5,124,0,106,2,106,10,68,0,93,100,125,6,122, - 18,124,1,124,6,131,1,160,5,124,4,161,1,125,7,87, - 0,110,22,4,0,116,11,121,122,1,0,1,0,1,0,89, - 0,113,78,89,0,110,2,48,0,124,7,106,8,106,7,125, - 8,116,12,124,8,131,1,100,1,107,2,114,154,124,7,106, - 7,86,0,1,0,113,78,124,8,124,5,118,1,114,78,124, - 5,160,13,124,8,161,1,1,0,124,8,86,0,1,0,113, - 78,100,0,83,0,41,4,78,114,0,0,0,0,41,1,218, - 4,80,97,116,104,114,60,0,0,0,41,14,90,7,112,97, - 116,104,108,105,98,114,183,0,0,0,114,4,0,0,0,114, - 56,0,0,0,114,38,0,0,0,90,11,114,101,108,97,116, - 105,118,101,95,116,111,114,29,0,0,0,114,59,0,0,0, - 90,6,112,97,114,101,110,116,218,3,115,101,116,114,28,0, - 0,0,114,23,0,0,0,114,51,0,0,0,218,3,97,100, - 100,41,9,114,32,0,0,0,114,183,0,0,0,90,13,102, - 117,108,108,110,97,109,101,95,112,97,116,104,90,13,114,101, - 108,97,116,105,118,101,95,112,97,116,104,90,12,112,97,99, - 107,97,103,101,95,112,97,116,104,90,12,115,117,98,100,105, - 114,115,95,115,101,101,110,218,8,102,105,108,101,110,97,109, - 101,90,8,114,101,108,97,116,105,118,101,90,11,112,97,114, - 101,110,116,95,110,97,109,101,114,9,0,0,0,114,9,0, - 0,0,114,10,0,0,0,218,8,99,111,110,116,101,110,116, - 115,250,2,0,0,115,34,0,0,0,0,8,12,1,18,1, - 14,3,14,1,6,1,6,1,12,1,2,1,18,1,12,1, - 10,5,8,1,12,1,10,1,8,1,10,1,122,33,95,90, - 105,112,73,109,112,111,114,116,82,101,115,111,117,114,99,101, - 82,101,97,100,101,114,46,99,111,110,116,101,110,116,115,78, - 41,10,114,6,0,0,0,114,7,0,0,0,114,8,0,0, - 0,114,84,0,0,0,114,81,0,0,0,114,34,0,0,0, - 114,180,0,0,0,114,181,0,0,0,114,182,0,0,0,114, - 187,0,0,0,114,9,0,0,0,114,9,0,0,0,114,9, - 0,0,0,114,10,0,0,0,114,80,0,0,0,212,2,0, - 0,115,14,0,0,0,8,1,4,5,4,2,8,4,8,9, - 8,6,8,11,114,80,0,0,0,41,45,114,84,0,0,0, - 90,26,95,102,114,111,122,101,110,95,105,109,112,111,114,116, - 108,105,98,95,101,120,116,101,114,110,97,108,114,21,0,0, - 0,114,1,0,0,0,114,2,0,0,0,90,17,95,102,114, - 111,122,101,110,95,105,109,112,111,114,116,108,105,98,114,76, - 0,0,0,114,148,0,0,0,114,110,0,0,0,114,152,0, - 0,0,114,67,0,0,0,114,131,0,0,0,90,7,95,95, - 97,108,108,95,95,114,20,0,0,0,90,15,112,97,116,104, - 95,115,101,112,97,114,97,116,111,114,115,114,18,0,0,0, - 114,75,0,0,0,114,3,0,0,0,114,25,0,0,0,218, - 4,116,121,112,101,114,70,0,0,0,114,113,0,0,0,114, - 115,0,0,0,114,117,0,0,0,114,4,0,0,0,114,89, - 0,0,0,114,36,0,0,0,114,37,0,0,0,114,35,0, - 0,0,114,27,0,0,0,114,122,0,0,0,114,142,0,0, - 0,114,144,0,0,0,114,52,0,0,0,114,147,0,0,0, - 114,155,0,0,0,218,8,95,95,99,111,100,101,95,95,114, - 153,0,0,0,114,159,0,0,0,114,161,0,0,0,114,169, - 0,0,0,114,151,0,0,0,114,149,0,0,0,114,44,0, - 0,0,114,80,0,0,0,114,9,0,0,0,114,9,0,0, - 0,114,9,0,0,0,114,10,0,0,0,218,8,60,109,111, - 100,117,108,101,62,1,0,0,0,115,88,0,0,0,4,16, - 8,1,16,1,8,1,8,1,8,1,8,1,8,1,8,2, - 8,3,6,1,14,3,16,4,4,2,8,2,4,1,4,1, - 4,2,14,127,0,127,0,1,12,1,12,1,2,1,2,252, - 4,9,8,4,8,9,8,31,8,126,2,254,2,29,4,5, - 8,21,8,46,8,10,8,46,10,5,8,7,8,6,8,13, - 8,19,8,15,8,26, + 114,147,0,0,0,168,2,0,0,115,14,0,0,0,0,2, + 20,1,12,2,2,1,14,1,12,1,8,2,114,147,0,0, + 0,99,2,0,0,0,0,0,0,0,0,0,0,0,11,0, + 0,0,9,0,0,0,67,0,0,0,115,196,0,0,0,116, + 0,124,0,124,1,131,2,125,2,116,1,68,0,93,158,92, + 3,125,3,125,4,125,5,124,2,124,3,23,0,125,6,116, + 2,106,3,100,1,124,0,106,4,116,5,124,6,100,2,100, + 3,141,5,1,0,122,14,124,0,106,6,124,6,25,0,125, + 7,87,0,110,18,4,0,116,7,121,86,1,0,1,0,1, + 0,89,0,113,14,48,0,124,7,100,4,25,0,125,8,116, + 8,124,0,106,4,124,7,131,2,125,9,124,4,114,130,116, + 9,124,0,124,8,124,6,124,1,124,9,131,5,125,10,110, + 10,116,10,124,8,124,9,131,2,125,10,124,10,100,0,117, + 0,114,150,113,14,124,7,100,4,25,0,125,8,124,10,124, + 5,124,8,102,3,2,0,1,0,83,0,113,14,116,11,100, + 5,124,1,155,2,157,2,124,1,100,6,141,2,130,1,100, + 0,83,0,41,7,78,122,13,116,114,121,105,110,103,32,123, + 125,123,125,123,125,114,84,0,0,0,41,1,90,9,118,101, + 114,98,111,115,105,116,121,114,0,0,0,0,114,57,0,0, + 0,114,58,0,0,0,41,12,114,36,0,0,0,114,87,0, + 0,0,114,76,0,0,0,114,77,0,0,0,114,29,0,0, + 0,114,20,0,0,0,114,28,0,0,0,114,26,0,0,0, + 114,52,0,0,0,114,153,0,0,0,114,159,0,0,0,114, + 3,0,0,0,41,11,114,32,0,0,0,114,38,0,0,0, + 114,13,0,0,0,114,88,0,0,0,114,89,0,0,0,114, + 47,0,0,0,114,63,0,0,0,114,54,0,0,0,114,40, + 0,0,0,114,124,0,0,0,114,46,0,0,0,114,9,0, + 0,0,114,9,0,0,0,114,10,0,0,0,114,44,0,0, + 0,183,2,0,0,115,36,0,0,0,0,1,10,1,14,1, + 8,1,22,1,2,1,14,1,12,1,6,2,8,1,12,1, + 4,1,18,2,10,1,8,3,2,1,8,1,16,2,114,44, + 0,0,0,41,44,114,82,0,0,0,90,26,95,102,114,111, + 122,101,110,95,105,109,112,111,114,116,108,105,98,95,101,120, + 116,101,114,110,97,108,114,21,0,0,0,114,1,0,0,0, + 114,2,0,0,0,90,17,95,102,114,111,122,101,110,95,105, + 109,112,111,114,116,108,105,98,114,76,0,0,0,114,146,0, + 0,0,114,108,0,0,0,114,150,0,0,0,114,67,0,0, + 0,114,129,0,0,0,90,7,95,95,97,108,108,95,95,114, + 20,0,0,0,90,15,112,97,116,104,95,115,101,112,97,114, + 97,116,111,114,115,114,18,0,0,0,114,75,0,0,0,114, + 3,0,0,0,114,25,0,0,0,218,4,116,121,112,101,114, + 70,0,0,0,114,111,0,0,0,114,113,0,0,0,114,115, + 0,0,0,114,4,0,0,0,114,87,0,0,0,114,36,0, + 0,0,114,37,0,0,0,114,35,0,0,0,114,27,0,0, + 0,114,120,0,0,0,114,140,0,0,0,114,142,0,0,0, + 114,52,0,0,0,114,145,0,0,0,114,153,0,0,0,218, + 8,95,95,99,111,100,101,95,95,114,151,0,0,0,114,157, + 0,0,0,114,159,0,0,0,114,167,0,0,0,114,149,0, + 0,0,114,147,0,0,0,114,44,0,0,0,114,9,0,0, + 0,114,9,0,0,0,114,9,0,0,0,114,10,0,0,0, + 218,8,60,109,111,100,117,108,101,62,1,0,0,0,115,84, + 0,0,0,4,16,8,1,16,1,8,1,8,1,8,1,8, + 1,8,1,8,2,8,3,6,1,14,3,16,4,4,2,8, + 2,4,1,4,1,4,2,14,127,0,125,12,1,12,1,2, + 1,2,252,4,9,8,4,8,9,8,31,8,126,2,254,2, + 29,4,5,8,21,8,46,8,10,8,46,10,5,8,7,8, + 6,8,13,8,19,8,15, }; diff --git a/Python/initconfig.c b/Python/initconfig.c index 185935c05fb..86285c77e23 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -24,6 +24,10 @@ # endif #endif +#ifndef PLATLIBDIR +# error "PLATLIBDIR macro must be defined" +#endif + /* --- Command line options --------------------------------------- */ @@ -68,7 +72,6 @@ static const char usage_3[] = "\ -X opt : set implementation-specific option. The following options are available:\n\ \n\ -X faulthandler: enable faulthandler\n\ - -X oldparser: enable the traditional LL(1) parser; also PYTHONOLDPARSER\n\ -X showrefcount: output the total reference count and number of used\n\ memory blocks when the program finishes or after each statement in the\n\ interactive interpreter. This only works on debug builds\n\ @@ -110,6 +113,7 @@ PYTHONPATH : '%lc'-separated list of directories prefixed to the\n\ static const char usage_5[] = "PYTHONHOME : alternate directory (or %lc).\n" " The default module search path uses %s.\n" +"PYTHONPLATLIBDIR : override sys.platlibdir.\n" "PYTHONCASEOK : ignore case in 'import' statements (Windows).\n" "PYTHONUTF8: if set to 1, enable the UTF-8 mode.\n" "PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n" @@ -543,8 +547,6 @@ _Py_SetArgcArgv(Py_ssize_t argc, wchar_t * const *argv) } -/* Make the *original* argc/argv available to other modules. - This is rare, but it is needed by the secureware extension. */ void Py_GetArgcArgv(int *argc, wchar_t ***argv) { @@ -588,6 +590,7 @@ PyConfig_Clear(PyConfig *config) CLEAR(config->base_prefix); CLEAR(config->exec_prefix); CLEAR(config->base_exec_prefix); + CLEAR(config->platlibdir); CLEAR(config->filesystem_encoding); CLEAR(config->filesystem_errors); @@ -597,6 +600,8 @@ PyConfig_Clear(PyConfig *config) CLEAR(config->run_module); CLEAR(config->run_filename); CLEAR(config->check_hash_pycs_mode); + + _PyWideStringList_Clear(&config->orig_argv); #undef CLEAR } @@ -636,7 +641,6 @@ _PyConfig_InitCompatConfig(PyConfig *config) #ifdef MS_WINDOWS config->legacy_windows_stdio = -1; #endif - config->_use_peg_parser = 1; } @@ -794,7 +798,6 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2) COPY_ATTR(isolated); COPY_ATTR(use_environment); COPY_ATTR(dev_mode); - COPY_ATTR(_use_peg_parser); COPY_ATTR(install_signal_handlers); COPY_ATTR(use_hash_seed); COPY_ATTR(hash_seed); @@ -824,6 +827,7 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2) COPY_WSTR_ATTR(base_prefix); COPY_WSTR_ATTR(exec_prefix); COPY_WSTR_ATTR(base_exec_prefix); + COPY_WSTR_ATTR(platlibdir); COPY_ATTR(site_import); COPY_ATTR(bytes_warning); @@ -852,6 +856,7 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2) COPY_ATTR(pathconfig_warnings); COPY_ATTR(_init_main); COPY_ATTR(_isolated_interpreter); + COPY_WSTRLIST(orig_argv); #undef COPY_ATTR #undef COPY_WSTR_ATTR @@ -899,7 +904,6 @@ config_as_dict(const PyConfig *config) SET_ITEM_INT(isolated); SET_ITEM_INT(use_environment); SET_ITEM_INT(dev_mode); - SET_ITEM_INT(_use_peg_parser); SET_ITEM_INT(install_signal_handlers); SET_ITEM_INT(use_hash_seed); SET_ITEM_UINT(hash_seed); @@ -926,6 +930,7 @@ config_as_dict(const PyConfig *config) SET_ITEM_WSTR(base_prefix); SET_ITEM_WSTR(exec_prefix); SET_ITEM_WSTR(base_exec_prefix); + SET_ITEM_WSTR(platlibdir); SET_ITEM_INT(site_import); SET_ITEM_INT(bytes_warning); SET_ITEM_INT(inspect); @@ -952,6 +957,7 @@ config_as_dict(const PyConfig *config) SET_ITEM_INT(pathconfig_warnings); SET_ITEM_INT(_init_main); SET_ITEM_INT(_isolated_interpreter); + SET_ITEM_WSTRLIST(orig_argv); return dict; @@ -1336,6 +1342,14 @@ config_read_env_vars(PyConfig *config) } } + if(config->platlibdir == NULL) { + status = CONFIG_GET_ENV_DUP(config, &config->platlibdir, + L"PYTHONPLATLIBDIR", "PYTHONPLATLIBDIR"); + if (_PyStatus_EXCEPTION(status)) { + return status; + } + } + if (config->use_hash_seed < 0) { status = config_init_hash_seed(config); if (_PyStatus_EXCEPTION(status)) { @@ -1435,11 +1449,6 @@ config_read_complex_options(PyConfig *config) config->import_time = 1; } - if (config_get_env(config, "PYTHONOLDPARSER") - || config_get_xoption(config, L"oldparser")) { - config->_use_peg_parser = 0; - } - PyStatus status; if (config->tracemalloc < 0) { status = config_init_tracemalloc(config); @@ -1731,6 +1740,14 @@ config_read(PyConfig *config) } } + if(config->platlibdir == NULL) { + status = CONFIG_SET_BYTES_STR(config, &config->platlibdir, PLATLIBDIR, + "PLATLIBDIR macro"); + if (_PyStatus_EXCEPTION(status)) { + return status; + } + } + if (config->_install_importlib) { status = _PyConfig_InitPathConfig(config); if (_PyStatus_EXCEPTION(status)) { @@ -1832,7 +1849,7 @@ config_init_stdio(const PyConfig *config) - set Py_xxx global configuration variables - initialize C standard streams (stdin, stdout, stderr) */ -void +PyStatus _PyConfig_Write(const PyConfig *config, _PyRuntimeState *runtime) { config_set_global_vars(config); @@ -1846,6 +1863,13 @@ _PyConfig_Write(const PyConfig *config, _PyRuntimeState *runtime) preconfig->isolated = config->isolated; preconfig->use_environment = config->use_environment; preconfig->dev_mode = config->dev_mode; + + if (_Py_SetArgcArgv(config->orig_argv.length, + config->orig_argv.items) < 0) + { + return _PyStatus_NO_MEMORY(); + } + return _PyStatus_OK(); } @@ -2469,7 +2493,6 @@ PyStatus PyConfig_Read(PyConfig *config) { PyStatus status; - PyWideStringList orig_argv = _PyWideStringList_INIT; status = _Py_PreInitializeFromConfig(config, NULL); if (_PyStatus_EXCEPTION(status)) { @@ -2478,8 +2501,13 @@ PyConfig_Read(PyConfig *config) config_get_global_vars(config); - if (_PyWideStringList_Copy(&orig_argv, &config->argv) < 0) { - return _PyStatus_NO_MEMORY(); + if (config->orig_argv.length == 0 + && !(config->argv.length == 1 + && wcscmp(config->argv.items[0], L"") == 0)) + { + if (_PyWideStringList_Copy(&config->orig_argv, &config->argv) < 0) { + return _PyStatus_NO_MEMORY(); + } } _PyPreCmdline precmdline = _PyPreCmdline_INIT; @@ -2510,16 +2538,10 @@ PyConfig_Read(PyConfig *config) goto done; } - if (_Py_SetArgcArgv(orig_argv.length, orig_argv.items) < 0) { - status = _PyStatus_NO_MEMORY(); - goto done; - } - /* Check config consistency */ assert(config->isolated >= 0); assert(config->use_environment >= 0); assert(config->dev_mode >= 0); - assert(config->_use_peg_parser >= 0); assert(config->install_signal_handlers >= 0); assert(config->use_hash_seed >= 0); assert(config->faulthandler >= 0); @@ -2554,6 +2576,7 @@ PyConfig_Read(PyConfig *config) assert(config->exec_prefix != NULL); assert(config->base_exec_prefix != NULL); } + assert(config->platlibdir != NULL); assert(config->filesystem_encoding != NULL); assert(config->filesystem_errors != NULL); assert(config->stdio_encoding != NULL); @@ -2566,11 +2589,11 @@ PyConfig_Read(PyConfig *config) assert(config->check_hash_pycs_mode != NULL); assert(config->_install_importlib >= 0); assert(config->pathconfig_warnings >= 0); + assert(_PyWideStringList_CheckConsistency(&config->orig_argv)); status = _PyStatus_OK(); done: - _PyWideStringList_Clear(&orig_argv); _PyPreCmdline_Clear(&precmdline); return status; } @@ -2704,6 +2727,7 @@ _Py_DumpPathConfig(PyThreadState *tstate) DUMP_SYS(_base_executable); DUMP_SYS(base_prefix); DUMP_SYS(base_exec_prefix); + DUMP_SYS(platlibdir); DUMP_SYS(executable); DUMP_SYS(prefix); DUMP_SYS(exec_prefix); diff --git a/Python/marshal.c b/Python/marshal.c index a0f6b981260..c4538bd373a 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -1371,6 +1371,12 @@ r_object(RFILE *p) if (lnotab == NULL) goto code_error; + if (PySys_Audit("code.__new__", "OOOiiiiii", + code, filename, name, argcount, posonlyargcount, + kwonlyargcount, nlocals, stacksize, flags) < 0) { + goto code_error; + } + v = (PyObject *) PyCode_NewWithPosOnlyArgs( argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize, flags, diff --git a/Python/modsupport.c b/Python/modsupport.c index 845bdcb2b6f..2637039d4a1 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -283,6 +283,13 @@ do_mktuple(const char **p_format, va_list *p_va, char endchar, Py_ssize_t n, int static PyObject * do_mkvalue(const char **p_format, va_list *p_va, int flags) { +#define ERROR_NEED_PY_SSIZE_T_CLEAN \ + { \ + PyErr_SetString(PyExc_SystemError, \ + "PY_SSIZE_T_CLEAN macro must be defined for '#' formats"); \ + return NULL; \ + } + for (;;) { switch (*(*p_format)++) { case '(': @@ -341,14 +348,12 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags) Py_ssize_t n; if (**p_format == '#') { ++*p_format; - if (flags & FLAG_SIZE_T) + if (flags & FLAG_SIZE_T) { n = va_arg(*p_va, Py_ssize_t); + } else { n = va_arg(*p_va, int); - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) { - return NULL; - } + ERROR_NEED_PY_SSIZE_T_CLEAN; } } else @@ -394,14 +399,12 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags) Py_ssize_t n; if (**p_format == '#') { ++*p_format; - if (flags & FLAG_SIZE_T) + if (flags & FLAG_SIZE_T) { n = va_arg(*p_va, Py_ssize_t); + } else { n = va_arg(*p_va, int); - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) { - return NULL; - } + ERROR_NEED_PY_SSIZE_T_CLEAN; } } else @@ -432,14 +435,12 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags) Py_ssize_t n; if (**p_format == '#') { ++*p_format; - if (flags & FLAG_SIZE_T) + if (flags & FLAG_SIZE_T) { n = va_arg(*p_va, Py_ssize_t); + } else { n = va_arg(*p_va, int); - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) { - return NULL; - } + ERROR_NEED_PY_SSIZE_T_CLEAN; } } else @@ -507,6 +508,8 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags) } } + +#undef ERROR_NEED_PY_SSIZE_T_CLEAN } diff --git a/Python/mysnprintf.c b/Python/mysnprintf.c index 945a81abb01..cd69198011e 100644 --- a/Python/mysnprintf.c +++ b/Python/mysnprintf.c @@ -1,6 +1,8 @@ #include "Python.h" -/* snprintf() wrappers. If the platform has vsnprintf, we use it, else we +/* snprintf() and vsnprintf() wrappers. + + If the platform has vsnprintf, we use it, else we emulate it in a half-hearted way. Even if the platform has it, we wrap it because platforms differ in what vsnprintf does in case the buffer is too small: C99 behavior is to return the number of characters that @@ -13,10 +15,6 @@ PyOS_snprintf and PyOS_vsnprintf never write more than size bytes (including the trailing '\0') into str. - If the platform doesn't have vsnprintf, and the buffer size needed to - avoid truncation exceeds size by more than 512, Python aborts with a - Py_FatalError. - Return value (rv): When 0 <= rv < size, the output conversion was unexceptional, and @@ -35,6 +33,7 @@ PyMem_Malloc couldn't obtain space for a temp buffer. CAUTION: Unlike C99, str != NULL and size > 0 are required. + Also, size must be smaller than INT_MAX. */ int @@ -52,53 +51,29 @@ PyOS_snprintf(char *str, size_t size, const char *format, ...) int PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va) { - int len; /* # bytes written, excluding \0 */ -#ifdef HAVE_SNPRINTF -#define _PyOS_vsnprintf_EXTRA_SPACE 1 -#else -#define _PyOS_vsnprintf_EXTRA_SPACE 512 - char *buffer; -#endif assert(str != NULL); assert(size > 0); + assert(size <= (INT_MAX - 1)); assert(format != NULL); + + int len; /* # bytes written, excluding \0 */ /* We take a size_t as input but return an int. Sanity check * our input so that it won't cause an overflow in the - * vsnprintf return value or the buffer malloc size. */ - if (size > INT_MAX - _PyOS_vsnprintf_EXTRA_SPACE) { + * vsnprintf return value. */ + if (size > INT_MAX - 1) { len = -666; goto Done; } -#ifdef HAVE_SNPRINTF - len = vsnprintf(str, size, format, va); +#if defined(_MSC_VER) + len = _vsnprintf(str, size, format, va); #else - /* Emulate it. */ - buffer = PyMem_MALLOC(size + _PyOS_vsnprintf_EXTRA_SPACE); - if (buffer == NULL) { - len = -666; - goto Done; - } - - len = vsprintf(buffer, format, va); - if (len < 0) { - /* ignore the error */; - } - else if ((size_t)len >= size + _PyOS_vsnprintf_EXTRA_SPACE) { - _Py_FatalErrorFunc(__func__, "Buffer overflow"); - } - else { - const size_t to_copy = (size_t)len < size ? - (size_t)len : size - 1; - assert(to_copy < size); - memcpy(str, buffer, to_copy); - str[to_copy] = '\0'; - } - PyMem_FREE(buffer); + len = vsnprintf(str, size, format, va); #endif + Done: - if (size > 0) + if (size > 0) { str[size-1] = '\0'; + } return len; -#undef _PyOS_vsnprintf_EXTRA_SPACE } diff --git a/Python/pathconfig.c b/Python/pathconfig.c index fe3ac3ee3d8..9a302213e77 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -17,9 +17,6 @@ extern "C" { _PyPathConfig _Py_path_config = _PyPathConfig_INIT; -#ifdef MS_WINDOWS -wchar_t *_Py_dll_path = NULL; -#endif static int @@ -107,10 +104,6 @@ _PyPathConfig_ClearGlobal(void) _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); pathconfig_clear(&_Py_path_config); -#ifdef MS_WINDOWS - PyMem_RawFree(_Py_dll_path); - _Py_dll_path = NULL; -#endif PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); } @@ -147,31 +140,6 @@ _PyWideStringList_Join(const PyWideStringList *list, wchar_t sep) } -#ifdef MS_WINDOWS -/* Initialize _Py_dll_path on Windows. Do nothing on other platforms. */ -static PyStatus -_PyPathConfig_InitDLLPath(void) -{ - if (_Py_dll_path != NULL) { - /* Already set: nothing to do */ - return _PyStatus_OK(); - } - - PyMemAllocatorEx old_alloc; - _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - - _Py_dll_path = _Py_GetDLLPath(); - - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - - if (_Py_dll_path == NULL) { - return _PyStatus_NO_MEMORY(); - } - return _PyStatus_OK(); -} -#endif - - static PyStatus pathconfig_set_from_config(_PyPathConfig *pathconfig, const PyConfig *config) { @@ -222,13 +190,6 @@ done: PyStatus _PyConfig_WritePathConfig(const PyConfig *config) { -#ifdef MS_WINDOWS - PyStatus status = _PyPathConfig_InitDLLPath(); - if (_PyStatus_EXCEPTION(status)) { - return status; - } -#endif - return pathconfig_set_from_config(&_Py_path_config, config); } @@ -455,13 +416,6 @@ pathconfig_global_init(void) { PyStatus status; -#ifdef MS_WINDOWS - status = _PyPathConfig_InitDLLPath(); - if (_PyStatus_EXCEPTION(status)) { - Py_ExitStatusException(status); - } -#endif - if (_Py_path_config.module_search_path == NULL) { status = pathconfig_global_read(&_Py_path_config); if (_PyStatus_EXCEPTION(status)) { @@ -686,6 +640,7 @@ _PyPathConfig_ComputeSysPath0(const PyWideStringList *argv, PyObject **path0_p) #ifdef HAVE_READLINK wchar_t link[MAXPATHLEN + 1]; int nr = 0; + wchar_t path0copy[2 * MAXPATHLEN + 1]; if (have_script_arg) { nr = _Py_wreadlink(path0, link, Py_ARRAY_LENGTH(link)); @@ -708,7 +663,6 @@ _PyPathConfig_ComputeSysPath0(const PyWideStringList *argv, PyObject **path0_p) } else { /* Must make a copy, path0copy has room for 2 * MAXPATHLEN */ - wchar_t path0copy[2 * MAXPATHLEN + 1]; wcsncpy(path0copy, path0, MAXPATHLEN); q = wcsrchr(path0copy, SEP); wcsncpy(q+1, link, MAXPATHLEN); diff --git a/Python/peephole.c b/Python/peephole.c index 84de1abc175..fe67de42227 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -3,7 +3,6 @@ #include "Python.h" #include "Python-ast.h" -#include "node.h" #include "ast.h" #include "code.h" #include "symtable.h" diff --git a/Python/preconfig.c b/Python/preconfig.c index fd94d7dda1c..149afcd99ab 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -829,13 +829,6 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args) int init_legacy_encoding = Py_LegacyWindowsFSEncodingFlag; #endif - if (args) { - status = _PyPreCmdline_SetArgv(&cmdline, args); - if (_PyStatus_EXCEPTION(status)) { - goto done; - } - } - int locale_coerced = 0; int loops = 0; @@ -846,7 +839,7 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args) loops++; if (loops == 3) { status = _PyStatus_ERR("Encoding changed twice while " - "reading the configuration"); + "reading the configuration"); goto done; } @@ -857,6 +850,15 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args) Py_LegacyWindowsFSEncodingFlag = config->legacy_windows_fs_encoding; #endif + if (args) { + // Set command line arguments at each iteration. If they are bytes + // strings, they are decoded from the new encoding. + status = _PyPreCmdline_SetArgv(&cmdline, args); + if (_PyStatus_EXCEPTION(status)) { + goto done; + } + } + status = preconfig_read(config, &cmdline); if (_PyStatus_EXCEPTION(status)) { goto done; @@ -896,7 +898,7 @@ _PyPreConfig_Read(PyPreConfig *config, const _PyArgv *args) } /* Reset the configuration before reading again the configuration, - just keep UTF-8 Mode value. */ + just keep UTF-8 Mode and coerce C locale value. */ int new_utf8_mode = config->utf8_mode; int new_coerce_c_locale = config->coerce_c_locale; preconfig_copy(config, &save_config); diff --git a/Python/pyhash.c b/Python/pyhash.c index 3843079fbbc..3b6c34eefd5 100644 --- a/Python/pyhash.c +++ b/Python/pyhash.c @@ -200,18 +200,14 @@ void _PyHash_Fini(void) { #ifdef Py_HASH_STATS - int i; - Py_ssize_t total = 0; - const char *fmt = "%2i %8" PY_FORMAT_SIZE_T "d %8" PY_FORMAT_SIZE_T "d\n"; - fprintf(stderr, "len calls total\n"); - for (i = 1; i <= Py_HASH_STATS_MAX; i++) { + Py_ssize_t total = 0; + for (int i = 1; i <= Py_HASH_STATS_MAX; i++) { total += hashstats[i]; - fprintf(stderr, fmt, i, hashstats[i], total); + fprintf(stderr, "%2i %8zd %8zd\n", i, hashstats[i], total); } total += hashstats[0]; - fprintf(stderr, "> %8" PY_FORMAT_SIZE_T "d %8" PY_FORMAT_SIZE_T "d\n", - hashstats[0], total); + fprintf(stderr, "> %8zd %8zd\n", hashstats[0], total); #endif } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index da66a82ada7..2d219a4a3a8 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -18,7 +18,6 @@ #include "pycore_sysmodule.h" // _PySys_ClearAuditHooks() #include "pycore_traceback.h" // _Py_DumpTracebackThreads() -#include "grammar.h" // PyGrammar_RemoveAccelerators() #include // setlocale() #ifdef HAVE_SIGNAL_H @@ -50,7 +49,6 @@ _Py_IDENTIFIER(threading); extern "C" { #endif -extern grammar _PyParser_Grammar; /* From graminit.c */ /* Forward declarations */ static PyStatus add_main_module(PyInterpreterState *interp); @@ -460,7 +458,10 @@ pyinit_core_reconfigure(_PyRuntimeState *runtime, return _PyStatus_ERR("can't make main interpreter"); } - _PyConfig_Write(config, runtime); + status = _PyConfig_Write(config, runtime); + if (_PyStatus_EXCEPTION(status)) { + return status; + } status = _PyInterpreterState_SetConfig(interp, config); if (_PyStatus_EXCEPTION(status)) { @@ -486,7 +487,10 @@ pycore_init_runtime(_PyRuntimeState *runtime, return _PyStatus_ERR("main interpreter already initialized"); } - _PyConfig_Write(config, runtime); + PyStatus status = _PyConfig_Write(config, runtime); + if (_PyStatus_EXCEPTION(status)) { + return status; + } /* Py_Finalize leaves _Py_Finalizing set in order to help daemon * threads behave a little more gracefully at interpreter shutdown. @@ -499,7 +503,7 @@ pycore_init_runtime(_PyRuntimeState *runtime, */ _PyRuntimeState_SetFinalizing(runtime, NULL); - PyStatus status = _Py_HashRandomization_Init(config); + status = _Py_HashRandomization_Init(config); if (_PyStatus_EXCEPTION(status)) { return status; } @@ -579,6 +583,14 @@ pycore_init_types(PyThreadState *tstate) return status; } + // Create the empty tuple singleton. It must be created before the first + // PyType_Ready() call since PyType_Ready() creates tuples, for tp_bases + // for example. + status = _PyTuple_Init(tstate); + if (_PyStatus_EXCEPTION(status)) { + return status; + } + if (is_main_interp) { status = _PyTypes_Init(); if (_PyStatus_EXCEPTION(status)) { @@ -586,19 +598,21 @@ pycore_init_types(PyThreadState *tstate) } } - if (!_PyLong_Init(tstate)) { return _PyStatus_ERR("can't init longs"); } - if (is_main_interp) { - status = _PyUnicode_Init(); - if (_PyStatus_EXCEPTION(status)) { - return status; - } + status = _PyUnicode_Init(tstate); + if (_PyStatus_EXCEPTION(status)) { + return status; } - status = _PyExc_Init(); + status = _PyBytes_Init(tstate); + if (_PyStatus_EXCEPTION(status)) { + return status; + } + + status = _PyExc_Init(tstate); if (_PyStatus_EXCEPTION(status)) { return status; } @@ -681,24 +695,22 @@ pycore_init_import_warnings(PyThreadState *tstate, PyObject *sysmod) return status; } - const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp); - if (_Py_IsMainInterpreter(tstate)) { - /* Initialize _warnings. */ - status = _PyWarnings_InitState(tstate); - if (_PyStatus_EXCEPTION(status)) { - return status; - } + /* Initialize _warnings. */ + status = _PyWarnings_InitState(tstate); + if (_PyStatus_EXCEPTION(status)) { + return status; + } - if (config->_install_importlib) { + const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp); + if (config->_install_importlib) { + if (_Py_IsMainInterpreter(tstate)) { status = _PyConfig_WritePathConfig(config); if (_PyStatus_EXCEPTION(status)) { return status; } } - } - /* This call sets up builtin and frozen import support */ - if (config->_install_importlib) { + /* This call sets up builtin and frozen import support */ status = init_importlib(tstate, sysmod); if (_PyStatus_EXCEPTION(status)) { return status; @@ -746,8 +758,6 @@ pyinit_config(_PyRuntimeState *runtime, PyThreadState **tstate_p, const PyConfig *config) { - _PyConfig_Write(config, runtime); - PyStatus status = pycore_init_runtime(runtime, config); if (_PyStatus_EXCEPTION(status)) { return status; @@ -1247,40 +1257,24 @@ flush_std_files(void) static void -finalize_interp_types(PyThreadState *tstate, int is_main_interp) +finalize_interp_types(PyThreadState *tstate) { - if (is_main_interp) { - /* Sundry finalizers */ - _PyFrame_Fini(); - _PyTuple_Fini(); - _PyList_Fini(); - _PySet_Fini(); - _PyBytes_Fini(); - } + _PyExc_Fini(tstate); + _PyFrame_Fini(tstate); + _PyAsyncGen_Fini(tstate); + _PyContext_Fini(tstate); + _PyUnicode_ClearInterned(tstate); - _PyLong_Fini(tstate); + _PyDict_Fini(tstate); + _PyList_Fini(tstate); + _PyTuple_Fini(tstate); - if (is_main_interp) { - _PyFloat_Fini(); - _PyDict_Fini(); - _PySlice_Fini(); - } + _PySlice_Fini(tstate); - _PyWarnings_Fini(tstate->interp); - - if (is_main_interp) { - _Py_HashRandomization_Fini(); - _PyArg_Fini(); - _PyAsyncGen_Fini(); - _PyContext_Fini(); - } - - /* Cleanup Unicode implementation */ + _PyBytes_Fini(tstate); _PyUnicode_Fini(tstate); - - if (is_main_interp) { - _Py_ClearFileSystemEncoding(); - } + _PyFloat_Fini(tstate); + _PyLong_Fini(tstate); } @@ -1297,21 +1291,24 @@ finalize_interp_clear(PyThreadState *tstate) _PyGC_CollectNoFail(); } - finalize_interp_types(tstate, is_main_interp); - + /* Clear all loghooks */ + /* Both _PySys_Audit function and users still need PyObject, such as tuple. + Call _PySys_ClearAuditHooks when PyObject available. */ if (is_main_interp) { - /* XXX Still allocated: - - various static ad-hoc pointers to interned strings - - int and float free list blocks - - whatever various modules and libraries allocate - */ - - PyGrammar_RemoveAccelerators(&_PyParser_Grammar); - - _PyExc_Fini(); + _PySys_ClearAuditHooks(tstate); } _PyGC_Fini(tstate); + + if (is_main_interp) { + _Py_HashRandomization_Fini(); + _PyArg_Fini(); + _Py_ClearFileSystemEncoding(); + } + + _PyWarnings_Fini(tstate->interp); + + finalize_interp_types(tstate); } @@ -1415,9 +1412,6 @@ Py_FinalizeEx(void) */ _PyGC_CollectIfEnabled(); - /* Clear all loghooks */ - _PySys_ClearAuditHooks(tstate); - /* Destroy all modules */ _PyImport_Cleanup(tstate); @@ -1948,7 +1942,6 @@ static PyStatus init_sys_streams(PyThreadState *tstate) { PyObject *iomod = NULL; - PyObject *m; PyObject *std = NULL; int fd; PyObject * encoding_attr; @@ -1968,18 +1961,6 @@ init_sys_streams(PyThreadState *tstate) } #endif - /* Hack to avoid a nasty recursion issue when Python is invoked - in verbose mode: pre-import the Latin-1 and UTF-8 codecs */ - if ((m = PyImport_ImportModule("encodings.utf_8")) == NULL) { - goto error; - } - Py_DECREF(m); - - if (!(m = PyImport_ImportModule("encodings.latin_1"))) { - goto error; - } - Py_DECREF(m); - if (!(iomod = PyImport_ImportModule("io"))) { goto error; } diff --git a/Python/pymath.c b/Python/pymath.c index a08a0e79615..24b804223ee 100644 --- a/Python/pymath.c +++ b/Python/pymath.c @@ -79,18 +79,3 @@ round(double x) return copysign(y, x); } #endif /* HAVE_ROUND */ - -static const unsigned int BitLengthTable[32] = { - 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 -}; - -unsigned int _Py_bit_length(unsigned long d) { - unsigned int d_bits = 0; - while (d >= 32) { - d_bits += 6; - d >>= 6; - } - d_bits += BitLengthTable[d]; - return d_bits; -} diff --git a/Python/pystate.c b/Python/pystate.c index 119fe31a84b..d0cbf5cb836 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -39,16 +39,6 @@ extern "C" { _Py_atomic_store_relaxed(&(gilstate)->tstate_current, \ (uintptr_t)(value)) -static void -ensure_tstate_not_null(const char *func, PyThreadState *tstate) -{ - if (tstate == NULL) { - _Py_FatalErrorFunc(func, - "current thread state is NULL (released GIL?)"); - } -} - - /* Forward declarations */ static PyThreadState *_PyGILState_GetThisThreadState(struct _gilstate_runtime_state *gilstate); static void _PyThreadState_Delete(PyThreadState *tstate, int check_current); @@ -134,10 +124,8 @@ _PyRuntimeState_Fini(_PyRuntimeState *runtime) #ifdef HAVE_FORK /* This function is called from PyOS_AfterFork_Child to ensure that - * newly created child processes do not share locks with the parent. - */ - -void + newly created child processes do not share locks with the parent. */ +PyStatus _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime) { // This was initially set in _PyRuntimeState_Init(). @@ -148,23 +136,20 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime) PyMemAllocatorEx old_alloc; _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - int interp_mutex = _PyThread_at_fork_reinit(&runtime->interpreters.mutex); - int main_interp_id_mutex = _PyThread_at_fork_reinit(&runtime->interpreters.main->id_mutex); - int xidregistry_mutex = _PyThread_at_fork_reinit(&runtime->xidregistry.mutex); + int reinit_interp = _PyThread_at_fork_reinit(&runtime->interpreters.mutex); + int reinit_main_id = _PyThread_at_fork_reinit(&runtime->interpreters.main->id_mutex); + int reinit_xidregistry = _PyThread_at_fork_reinit(&runtime->xidregistry.mutex); PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - if (interp_mutex < 0) { - Py_FatalError("Can't initialize lock for runtime interpreters"); - } + if (reinit_interp < 0 + || reinit_main_id < 0 + || reinit_xidregistry < 0) + { + return _PyStatus_ERR("Failed to reinitialize runtime locks"); - if (main_interp_id_mutex < 0) { - Py_FatalError("Can't initialize ID lock for main interpreter"); - } - - if (xidregistry_mutex < 0) { - Py_FatalError("Can't initialize lock for cross-interpreter data registry"); } + return _PyStatus_OK(); } #endif @@ -383,11 +368,12 @@ PyInterpreterState_Delete(PyInterpreterState *interp) } +#ifdef HAVE_FORK /* * Delete all interpreter states except the main interpreter. If there * is a current interpreter state, it *must* be the main interpreter. */ -void +PyStatus _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime) { struct _gilstate_runtime_state *gilstate = &runtime->gilstate; @@ -395,7 +381,7 @@ _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime) PyThreadState *tstate = _PyThreadState_Swap(gilstate, NULL); if (tstate != NULL && tstate->interp != interpreters->main) { - Py_FatalError("not main interpreter"); + return _PyStatus_ERR("not main interpreter"); } HEAD_LOCK(runtime); @@ -421,17 +407,19 @@ _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime) HEAD_UNLOCK(runtime); if (interpreters->head == NULL) { - Py_FatalError("missing main interpreter"); + return _PyStatus_ERR("missing main interpreter"); } _PyThreadState_Swap(gilstate, tstate); + return _PyStatus_OK(); } +#endif PyInterpreterState * PyInterpreterState_Get(void) { PyThreadState *tstate = _PyThreadState_GET(); - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); PyInterpreterState *interp = tstate->interp; if (interp == NULL) { Py_FatalError("no current interpreter"); @@ -846,7 +834,7 @@ static void tstate_delete_common(PyThreadState *tstate, struct _gilstate_runtime_state *gilstate) { - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); PyInterpreterState *interp = tstate->interp; if (interp == NULL) { Py_FatalError("NULL interpreter"); @@ -897,7 +885,7 @@ PyThreadState_Delete(PyThreadState *tstate) void _PyThreadState_DeleteCurrent(PyThreadState *tstate) { - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate; tstate_delete_common(tstate, gilstate); _PyRuntimeGILState_SetThreadState(gilstate, NULL); @@ -975,7 +963,7 @@ PyThreadState * PyThreadState_Get(void) { PyThreadState *tstate = _PyThreadState_GET(); - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); return tstate; } @@ -1269,11 +1257,12 @@ _PyGILState_Fini(PyThreadState *tstate) gilstate->autoInterpreterState = NULL; } +#ifdef HAVE_FORK /* Reset the TSS key - called by PyOS_AfterFork_Child(). * This should not be necessary, but some - buggy - pthread implementations * don't reset TSS upon fork(), see issue #10517. */ -void +PyStatus _PyGILState_Reinit(_PyRuntimeState *runtime) { struct _gilstate_runtime_state *gilstate = &runtime->gilstate; @@ -1281,7 +1270,7 @@ _PyGILState_Reinit(_PyRuntimeState *runtime) PyThread_tss_delete(&gilstate->autoTSSkey); if (PyThread_tss_create(&gilstate->autoTSSkey) != 0) { - Py_FatalError("Could not allocate TSS entry"); + return _PyStatus_NO_MEMORY(); } /* If the thread had an associated auto thread state, reassociate it with @@ -1289,9 +1278,11 @@ _PyGILState_Reinit(_PyRuntimeState *runtime) if (tstate && PyThread_tss_set(&gilstate->autoTSSkey, (void *)tstate) != 0) { - Py_FatalError("Couldn't create autoTSSkey mapping"); + return _PyStatus_ERR("failed to set autoTSSkey"); } + return _PyStatus_OK(); } +#endif /* When a thread state is created for a thread by some mechanism other than PyGILState_Ensure, it's important that the GILState machinery knows about @@ -1735,7 +1726,7 @@ _str_shared(PyObject *obj, _PyCrossInterpreterData *data) struct _shared_str_data *shared = PyMem_NEW(struct _shared_str_data, 1); shared->kind = PyUnicode_KIND(obj); shared->buffer = PyUnicode_DATA(obj); - shared->len = PyUnicode_GET_LENGTH(obj) - 1; + shared->len = PyUnicode_GET_LENGTH(obj); data->data = (void *)shared; Py_INCREF(obj); data->obj = obj; // Will be "released" (decref'ed) when data released. diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 160f44d38e2..ff80103050e 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -20,16 +20,13 @@ #include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_sysmodule.h" // _PySys_Audit() -#include "node.h" // node #include "token.h" // INDENT -#include "parsetok.h" // perrdetail #include "errcode.h" // E_EOF #include "code.h" // PyCodeObject #include "symtable.h" // PySymtable_BuildObject() -#include "ast.h" // PyAST_FromNodeObject() #include "marshal.h" // PyMarshal_ReadLongFromFile() -#include "pegen_interface.h" // PyPegen_ASTFrom* +#include "parser_interface.h" // PyParser_ASTFrom* #ifdef MS_WINDOWS # include "malloc.h" // alloca() @@ -58,16 +55,12 @@ _Py_static_string(PyId_string, ""); extern "C" { #endif -extern Py_EXPORTED_SYMBOL grammar _PyParser_Grammar; /* From graminit.c */ - /* Forward */ static void flush_io(void); static PyObject *run_mod(mod_ty, PyObject *, PyObject *, PyObject *, PyCompilerFlags *, PyArena *); static PyObject *run_pyc_file(FILE *, const char *, PyObject *, PyObject *, PyCompilerFlags *); -static void err_input(perrdetail *); -static void err_free(perrdetail *); static int PyRun_InteractiveOneObjectEx(FILE *, PyObject *, PyCompilerFlags *); /* Parse input from a file and execute it */ @@ -148,32 +141,6 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename_str, PyCompilerFlags * return err; } -/* compute parser flags based on compiler flags */ -static int PARSER_FLAGS(PyCompilerFlags *flags) -{ - int parser_flags = 0; - if (!flags) - return 0; - if (flags->cf_flags & PyCF_DONT_IMPLY_DEDENT) - parser_flags |= PyPARSE_DONT_IMPLY_DEDENT; - if (flags->cf_flags & PyCF_IGNORE_COOKIE) - parser_flags |= PyPARSE_IGNORE_COOKIE; - if (flags->cf_flags & CO_FUTURE_BARRY_AS_BDFL) - parser_flags |= PyPARSE_BARRY_AS_BDFL; - if (flags->cf_flags & PyCF_TYPE_COMMENTS) - parser_flags |= PyPARSE_TYPE_COMMENTS; - return parser_flags; -} - -#if 0 -/* Keep an example of flags with future keyword support. */ -#define PARSER_FLAGS(flags) \ - ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \ - PyPARSE_DONT_IMPLY_DEDENT : 0) \ - | ((flags)->cf_flags & CO_FUTURE_WITH_STATEMENT ? \ - PyPARSE_WITH_IS_KEYWORD : 0)) : 0) -#endif - /* A PyRun_InteractiveOneObject() auxiliary function that does not print the * error on failure. */ static int @@ -185,7 +152,6 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename, PyArena *arena; const char *ps1 = "", *ps2 = "", *enc = NULL; int errcode = 0; - int use_peg = _PyInterpreterState_GET()->config._use_peg_parser; _Py_IDENTIFIER(encoding); _Py_IDENTIFIER(__main__); @@ -239,15 +205,8 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename, return -1; } - if (use_peg) { - mod = PyPegen_ASTFromFileObject(fp, filename, Py_single_input, - enc, ps1, ps2, flags, &errcode, arena); - } - else { - mod = PyParser_ASTFromFileObject(fp, filename, enc, - Py_single_input, ps1, ps2, - flags, &errcode, arena); - } + mod = PyParser_ASTFromFileObject(fp, filename, enc, Py_single_input, + ps1, ps2, flags, &errcode, arena); Py_XDECREF(v); Py_XDECREF(w); @@ -478,9 +437,9 @@ PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags) static int parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, - int *lineno, int *offset, PyObject **text) + Py_ssize_t *lineno, Py_ssize_t *offset, PyObject **text) { - int hold; + Py_ssize_t hold; PyObject *v; _Py_IDENTIFIER(msg); _Py_IDENTIFIER(filename); @@ -513,7 +472,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, v = _PyObject_GetAttrId(err, &PyId_lineno); if (!v) goto finally; - hold = _PyLong_AsInt(v); + hold = PyLong_AsSsize_t(v); Py_DECREF(v); if (hold < 0 && PyErr_Occurred()) goto finally; @@ -526,7 +485,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, *offset = -1; Py_DECREF(v); } else { - hold = _PyLong_AsInt(v); + hold = PyLong_AsSsize_t(v); Py_DECREF(v); if (hold < 0 && PyErr_Occurred()) goto finally; @@ -552,7 +511,7 @@ finally: } static void -print_error_text(PyObject *f, int offset, PyObject *text_obj) +print_error_text(PyObject *f, Py_ssize_t offset, PyObject *text_obj) { /* Convert text to a char pointer; return if error */ const char *text = PyUnicode_AsUTF8(text_obj); @@ -586,7 +545,7 @@ print_error_text(PyObject *f, int offset, PyObject *text_obj) break; } Py_ssize_t inl = nl - text; - if (inl >= (Py_ssize_t)offset) { + if (inl >= offset) { break; } inl += 1; @@ -833,7 +792,7 @@ print_exception(PyObject *f, PyObject *value) _PyObject_HasAttrId(value, &PyId_print_file_and_line)) { PyObject *message, *filename, *text; - int lineno, offset; + Py_ssize_t lineno, offset; if (!parse_syntax_error(value, &message, &filename, &lineno, &offset, &text)) PyErr_Clear(); @@ -843,7 +802,7 @@ print_exception(PyObject *f, PyObject *value) Py_DECREF(value); value = message; - line = PyUnicode_FromFormat(" File \"%S\", line %d\n", + line = PyUnicode_FromFormat(" File \"%S\", line %zd\n", filename, lineno); Py_DECREF(filename); if (line != NULL) { @@ -1058,7 +1017,6 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals, mod_ty mod; PyArena *arena; PyObject *filename; - int use_peg = _PyInterpreterState_GET()->config._use_peg_parser; filename = _PyUnicode_FromId(&PyId_string); /* borrowed */ if (filename == NULL) @@ -1068,12 +1026,7 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals, if (arena == NULL) return NULL; - if (use_peg) { - mod = PyPegen_ASTFromStringObject(str, filename, start, flags, arena); - } - else { - mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena); - } + mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena); if (mod != NULL) ret = run_mod(mod, filename, globals, locals, flags, arena); @@ -1089,7 +1042,6 @@ PyRun_FileExFlags(FILE *fp, const char *filename_str, int start, PyObject *globa mod_ty mod; PyArena *arena = NULL; PyObject *filename; - int use_peg = _PyInterpreterState_GET()->config._use_peg_parser; filename = PyUnicode_DecodeFSDefault(filename_str); if (filename == NULL) @@ -1099,14 +1051,8 @@ PyRun_FileExFlags(FILE *fp, const char *filename_str, int start, PyObject *globa if (arena == NULL) goto exit; - if (use_peg) { - mod = PyPegen_ASTFromFileObject(fp, filename, start, NULL, NULL, NULL, - flags, NULL, arena); - } - else { - mod = PyParser_ASTFromFileObject(fp, filename, NULL, start, 0, 0, - flags, NULL, arena); - } + mod = PyParser_ASTFromFileObject(fp, filename, NULL, start, NULL, NULL, + flags, NULL, arena); if (closeit) fclose(fp); @@ -1250,17 +1196,11 @@ Py_CompileStringObject(const char *str, PyObject *filename, int start, { PyCodeObject *co; mod_ty mod; - int use_peg = _PyInterpreterState_GET()->config._use_peg_parser; PyArena *arena = PyArena_New(); if (arena == NULL) return NULL; - if (use_peg) { - mod = PyPegen_ASTFromStringObject(str, filename, start, flags, arena); - } - else { - mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena); - } + mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena); if (mod == NULL) { PyArena_Free(arena); return NULL; @@ -1357,19 +1297,13 @@ _Py_SymtableStringObjectFlags(const char *str, PyObject *filename, int start, Py { struct symtable *st; mod_ty mod; - int use_peg = _PyInterpreterState_GET()->config._use_peg_parser; PyArena *arena; arena = PyArena_New(); if (arena == NULL) return NULL; - if (use_peg) { - mod = PyPegen_ASTFromStringObject(str, filename, start, flags, arena); - } - else { - mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena); - } + mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena); if (mod == NULL) { PyArena_Free(arena); return NULL; @@ -1393,291 +1327,6 @@ Py_SymtableString(const char *str, const char *filename_str, int start) return st; } -/* Preferred access to parser is through AST. */ -mod_ty -PyParser_ASTFromStringObject(const char *s, PyObject *filename, int start, - PyCompilerFlags *flags, PyArena *arena) -{ - mod_ty mod; - PyCompilerFlags localflags = _PyCompilerFlags_INIT; - perrdetail err; - int iflags = PARSER_FLAGS(flags); - if (flags && flags->cf_feature_version < 7) - iflags |= PyPARSE_ASYNC_HACKS; - - node *n = PyParser_ParseStringObject(s, filename, - &_PyParser_Grammar, start, &err, - &iflags); - if (flags == NULL) { - flags = &localflags; - } - if (n) { - flags->cf_flags |= iflags & PyCF_MASK; - mod = PyAST_FromNodeObject(n, flags, filename, arena); - PyNode_Free(n); - } - else { - err_input(&err); - mod = NULL; - } - err_free(&err); - return mod; -} - -mod_ty -PyParser_ASTFromString(const char *s, const char *filename_str, int start, - PyCompilerFlags *flags, PyArena *arena) -{ - PyObject *filename; - mod_ty mod; - filename = PyUnicode_DecodeFSDefault(filename_str); - if (filename == NULL) - return NULL; - mod = PyParser_ASTFromStringObject(s, filename, start, flags, arena); - Py_DECREF(filename); - return mod; -} - -mod_ty -PyParser_ASTFromFileObject(FILE *fp, PyObject *filename, const char* enc, - int start, const char *ps1, - const char *ps2, PyCompilerFlags *flags, int *errcode, - PyArena *arena) -{ - mod_ty mod; - PyCompilerFlags localflags = _PyCompilerFlags_INIT; - perrdetail err; - int iflags = PARSER_FLAGS(flags); - - node *n = PyParser_ParseFileObject(fp, filename, enc, - &_PyParser_Grammar, - start, ps1, ps2, &err, &iflags); - if (flags == NULL) { - flags = &localflags; - } - if (n) { - flags->cf_flags |= iflags & PyCF_MASK; - mod = PyAST_FromNodeObject(n, flags, filename, arena); - PyNode_Free(n); - } - else { - err_input(&err); - if (errcode) - *errcode = err.error; - mod = NULL; - } - err_free(&err); - return mod; -} - -mod_ty -PyParser_ASTFromFile(FILE *fp, const char *filename_str, const char* enc, - int start, const char *ps1, - const char *ps2, PyCompilerFlags *flags, int *errcode, - PyArena *arena) -{ - mod_ty mod; - PyObject *filename; - filename = PyUnicode_DecodeFSDefault(filename_str); - if (filename == NULL) - return NULL; - mod = PyParser_ASTFromFileObject(fp, filename, enc, start, ps1, ps2, - flags, errcode, arena); - Py_DECREF(filename); - return mod; -} - -/* Simplified interface to parsefile -- return node or set exception */ - -node * -PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int flags) -{ - perrdetail err; - node *n = PyParser_ParseFileFlags(fp, filename, NULL, - &_PyParser_Grammar, - start, NULL, NULL, &err, flags); - if (n == NULL) - err_input(&err); - err_free(&err); - - return n; -} - -/* Simplified interface to parsestring -- return node or set exception */ - -node * -PyParser_SimpleParseStringFlags(const char *str, int start, int flags) -{ - perrdetail err; - node *n = PyParser_ParseStringFlags(str, &_PyParser_Grammar, - start, &err, flags); - if (n == NULL) - err_input(&err); - err_free(&err); - return n; -} - -node * -PyParser_SimpleParseStringFlagsFilename(const char *str, const char *filename, - int start, int flags) -{ - perrdetail err; - node *n = PyParser_ParseStringFlagsFilename(str, filename, - &_PyParser_Grammar, start, &err, flags); - if (n == NULL) - err_input(&err); - err_free(&err); - return n; -} - -/* May want to move a more generalized form of this to parsetok.c or - even parser modules. */ - -void -PyParser_ClearError(perrdetail *err) -{ - err_free(err); -} - -void -PyParser_SetError(perrdetail *err) -{ - err_input(err); -} - -static void -err_free(perrdetail *err) -{ - Py_CLEAR(err->filename); -} - -/* Set the error appropriate to the given input error code (see errcode.h) */ - -static void -err_input(perrdetail *err) -{ - PyObject *v, *w, *errtype, *errtext; - PyObject *msg_obj = NULL; - const char *msg = NULL; - int offset = err->offset; - - errtype = PyExc_SyntaxError; - switch (err->error) { - case E_ERROR: - goto cleanup; - case E_SYNTAX: - errtype = PyExc_IndentationError; - if (err->expected == INDENT) - msg = "expected an indented block"; - else if (err->token == INDENT) - msg = "unexpected indent"; - else if (err->token == DEDENT) - msg = "unexpected unindent"; - else if (err->expected == NOTEQUAL) { - errtype = PyExc_SyntaxError; - msg = "with Barry as BDFL, use '<>' instead of '!='"; - } - else { - errtype = PyExc_SyntaxError; - msg = "invalid syntax"; - } - break; - case E_TOKEN: - msg = "invalid token"; - break; - case E_EOFS: - msg = "EOF while scanning triple-quoted string literal"; - break; - case E_EOLS: - msg = "EOL while scanning string literal"; - break; - case E_INTR: - if (!PyErr_Occurred()) - PyErr_SetNone(PyExc_KeyboardInterrupt); - goto cleanup; - case E_NOMEM: - PyErr_NoMemory(); - goto cleanup; - case E_EOF: - msg = "unexpected EOF while parsing"; - break; - case E_TABSPACE: - errtype = PyExc_TabError; - msg = "inconsistent use of tabs and spaces in indentation"; - break; - case E_OVERFLOW: - msg = "expression too long"; - break; - case E_DEDENT: - errtype = PyExc_IndentationError; - msg = "unindent does not match any outer indentation level"; - break; - case E_TOODEEP: - errtype = PyExc_IndentationError; - msg = "too many levels of indentation"; - break; - case E_DECODE: { - PyObject *type, *value, *tb; - PyErr_Fetch(&type, &value, &tb); - msg = "unknown decode error"; - if (value != NULL) - msg_obj = PyObject_Str(value); - Py_XDECREF(type); - Py_XDECREF(value); - Py_XDECREF(tb); - break; - } - case E_LINECONT: - msg = "unexpected character after line continuation character"; - break; - - case E_BADSINGLE: - msg = "multiple statements found while compiling a single statement"; - break; - default: - fprintf(stderr, "error=%d\n", err->error); - msg = "unknown parsing error"; - break; - } - /* err->text may not be UTF-8 in case of decoding errors. - Explicitly convert to an object. */ - if (!err->text) { - errtext = Py_None; - Py_INCREF(Py_None); - } else { - errtext = PyUnicode_DecodeUTF8(err->text, err->offset, - "replace"); - if (errtext != NULL) { - Py_ssize_t len = strlen(err->text); - offset = (int)PyUnicode_GET_LENGTH(errtext); - if (len != err->offset) { - Py_DECREF(errtext); - errtext = PyUnicode_DecodeUTF8(err->text, len, - "replace"); - } - } - } - v = Py_BuildValue("(OiiN)", err->filename, - err->lineno, offset, errtext); - if (v != NULL) { - if (msg_obj) - w = Py_BuildValue("(OO)", msg_obj, v); - else - w = Py_BuildValue("(sO)", msg, v); - } else - w = NULL; - Py_XDECREF(v); - PyErr_SetObject(errtype, w); - Py_XDECREF(w); -cleanup: - Py_XDECREF(msg_obj); - if (err->text != NULL) { - PyObject_FREE(err->text); - err->text = NULL; - } -} - - #if defined(USE_STACKCHECK) #if defined(WIN32) && defined(_MSC_VER) @@ -1715,123 +1364,6 @@ PyOS_CheckStack(void) #endif /* USE_STACKCHECK */ -/* Deprecated C API functions still provided for binary compatibility */ - -#undef PyParser_SimpleParseFile -PyAPI_FUNC(node *) -PyParser_SimpleParseFile(FILE *fp, const char *filename, int start) -{ - return PyParser_SimpleParseFileFlags(fp, filename, start, 0); -} - -#undef PyParser_SimpleParseString -PyAPI_FUNC(node *) -PyParser_SimpleParseString(const char *str, int start) -{ - return PyParser_SimpleParseStringFlags(str, start, 0); -} - -#undef PyRun_AnyFile -PyAPI_FUNC(int) -PyRun_AnyFile(FILE *fp, const char *name) -{ - return PyRun_AnyFileExFlags(fp, name, 0, NULL); -} - -#undef PyRun_AnyFileEx -PyAPI_FUNC(int) -PyRun_AnyFileEx(FILE *fp, const char *name, int closeit) -{ - return PyRun_AnyFileExFlags(fp, name, closeit, NULL); -} - -#undef PyRun_AnyFileFlags -PyAPI_FUNC(int) -PyRun_AnyFileFlags(FILE *fp, const char *name, PyCompilerFlags *flags) -{ - return PyRun_AnyFileExFlags(fp, name, 0, flags); -} - -#undef PyRun_File -PyAPI_FUNC(PyObject *) -PyRun_File(FILE *fp, const char *p, int s, PyObject *g, PyObject *l) -{ - return PyRun_FileExFlags(fp, p, s, g, l, 0, NULL); -} - -#undef PyRun_FileEx -PyAPI_FUNC(PyObject *) -PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, int c) -{ - return PyRun_FileExFlags(fp, p, s, g, l, c, NULL); -} - -#undef PyRun_FileFlags -PyAPI_FUNC(PyObject *) -PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, - PyCompilerFlags *flags) -{ - return PyRun_FileExFlags(fp, p, s, g, l, 0, flags); -} - -#undef PyRun_SimpleFile -PyAPI_FUNC(int) -PyRun_SimpleFile(FILE *f, const char *p) -{ - return PyRun_SimpleFileExFlags(f, p, 0, NULL); -} - -#undef PyRun_SimpleFileEx -PyAPI_FUNC(int) -PyRun_SimpleFileEx(FILE *f, const char *p, int c) -{ - return PyRun_SimpleFileExFlags(f, p, c, NULL); -} - - -#undef PyRun_String -PyAPI_FUNC(PyObject *) -PyRun_String(const char *str, int s, PyObject *g, PyObject *l) -{ - return PyRun_StringFlags(str, s, g, l, NULL); -} - -#undef PyRun_SimpleString -PyAPI_FUNC(int) -PyRun_SimpleString(const char *s) -{ - return PyRun_SimpleStringFlags(s, NULL); -} - -#undef Py_CompileString -PyAPI_FUNC(PyObject *) -Py_CompileString(const char *str, const char *p, int s) -{ - return Py_CompileStringExFlags(str, p, s, NULL, -1); -} - -#undef Py_CompileStringFlags -PyAPI_FUNC(PyObject *) -Py_CompileStringFlags(const char *str, const char *p, int s, - PyCompilerFlags *flags) -{ - return Py_CompileStringExFlags(str, p, s, flags, -1); -} - -#undef PyRun_InteractiveOne -PyAPI_FUNC(int) -PyRun_InteractiveOne(FILE *f, const char *p) -{ - return PyRun_InteractiveOneFlags(f, p, NULL); -} - -#undef PyRun_InteractiveLoop -PyAPI_FUNC(int) -PyRun_InteractiveLoop(FILE *f, const char *p) -{ - return PyRun_InteractiveLoopFlags(f, p, NULL); -} - #ifdef __cplusplus } #endif diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 914beb7e127..9fcdb5dbc49 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -15,18 +15,18 @@ Data members: */ #include "Python.h" -#include "code.h" -#include "frameobject.h" // PyFrame_GetBack() #include "pycore_ceval.h" // _Py_RecursionLimitLowerWaterMark() -#include "pycore_initconfig.h" -#include "pycore_object.h" -#include "pycore_pathconfig.h" -#include "pycore_pyerrors.h" -#include "pycore_pylifecycle.h" +#include "pycore_initconfig.h" // _PyStatus_EXCEPTION() +#include "pycore_object.h" // _PyObject_IS_GC() +#include "pycore_pathconfig.h" // _PyPathConfig_ComputeSysPath0() +#include "pycore_pyerrors.h" // _PyErr_Fetch() +#include "pycore_pylifecycle.h" // _PyErr_WriteUnraisableDefaultHook() #include "pycore_pymem.h" // _PyMem_SetDefaultAllocator() #include "pycore_pystate.h" // _PyThreadState_GET() -#include "pycore_tupleobject.h" +#include "pycore_tuple.h" // _PyTuple_FromArray() +#include "code.h" +#include "frameobject.h" // PyFrame_GetBack() #include "pydtrace.h" #include "osdefs.h" // DELIM #include @@ -457,7 +457,7 @@ static PyObject * sys_audit(PyObject *self, PyObject *const *args, Py_ssize_t argc) { PyThreadState *tstate = _PyThreadState_GET(); - assert(tstate != NULL); + _Py_EnsureTstateNotNULL(tstate); if (argc == 0) { _PyErr_SetString(tstate, PyExc_TypeError, @@ -2922,13 +2922,7 @@ _PySys_InitMain(PyThreadState *tstate) SET_SYS_FROM_WSTR("base_prefix", config->base_prefix); SET_SYS_FROM_WSTR("exec_prefix", config->exec_prefix); SET_SYS_FROM_WSTR("base_exec_prefix", config->base_exec_prefix); - { - PyObject *str = PyUnicode_FromString(PLATLIBDIR); - if (str == NULL) { - return -1; - } - SET_SYS_FROM_STRING("platlibdir", str); - } + SET_SYS_FROM_WSTR("platlibdir", config->platlibdir); if (config->pycache_prefix != NULL) { SET_SYS_FROM_WSTR("pycache_prefix", config->pycache_prefix); @@ -2937,6 +2931,7 @@ _PySys_InitMain(PyThreadState *tstate) } COPY_LIST("argv", config->argv); + COPY_LIST("orig_argv", config->orig_argv); COPY_LIST("warnoptions", config->warnoptions); PyObject *xoptions = sys_create_xoptions_dict(config); diff --git a/Tools/c-analyzer/c_analyzer/common/files.py b/Tools/c-analyzer/c_analyzer/common/files.py index ab551a84bad..f630afe6259 100644 --- a/Tools/c-analyzer/c_analyzer/common/files.py +++ b/Tools/c-analyzer/c_analyzer/common/files.py @@ -41,6 +41,8 @@ def walk_tree(root, *, def glob_tree(root, *, suffix=None, _glob=glob.iglob, + _escape=glob.escape, + _join=os.path.join, ): """Yield each file in the tree under the given directory name. @@ -51,9 +53,9 @@ def glob_tree(root, *, if not isinstance(suffix, str): raise ValueError('suffix must be a string') - for filename in _glob(f'{root}/*{suffix}'): + for filename in _glob(_join(_escape(root), f'*{suffix}')): yield filename - for filename in _glob(f'{root}/**/*{suffix}'): + for filename in _glob(_join(_escape(root), f'**/*{suffix}')): yield filename diff --git a/Tools/c-analyzer/check-c-globals.py b/Tools/c-analyzer/check-c-globals.py index e68ed9271fe..1371f927423 100644 --- a/Tools/c-analyzer/check-c-globals.py +++ b/Tools/c-analyzer/check-c-globals.py @@ -37,7 +37,9 @@ IGNORED_VARS = { def find_capi_vars(root): capi_vars = {} for dirname in SOURCE_DIRS: - for filename in glob.glob(os.path.join(ROOT_DIR, dirname, '**/*.[hc]'), + for filename in glob.glob(os.path.join( + glob.escape(os.path.join(ROOT_DIR, dirname)), + '**/*.[hc]'), recursive=True): with open(filename) as file: for name in _find_capi_vars(file): diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 0f40e0679f0..92334d9195f 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -3062,7 +3062,7 @@ class Py_ssize_t_converter(CConverter): return """ {{{{ Py_ssize_t ival = -1; - PyObject *iobj = PyNumber_Index({argname}); + PyObject *iobj = _PyNumber_Index({argname}); if (iobj != NULL) {{{{ ival = PyLong_AsSsize_t(iobj); Py_DECREF(iobj); @@ -3374,20 +3374,75 @@ class unicode_converter(CConverter): displayname=displayname) return super().parse_arg(argname, displayname) +@add_legacy_c_converter('u') @add_legacy_c_converter('u#', zeroes=True) @add_legacy_c_converter('Z', accept={str, NoneType}) @add_legacy_c_converter('Z#', accept={str, NoneType}, zeroes=True) class Py_UNICODE_converter(CConverter): type = 'const Py_UNICODE *' default_type = (str, Null, NoneType) - format_unit = 'u' def converter_init(self, *, accept={str}, zeroes=False): format_unit = 'Z' if accept=={str, NoneType} else 'u' if zeroes: format_unit += '#' self.length = True - self.format_unit = format_unit + self.format_unit = format_unit + else: + self.accept = accept + if accept == {str}: + self.converter = '_PyUnicode_WideCharString_Converter' + elif accept == {str, NoneType}: + self.converter = '_PyUnicode_WideCharString_Opt_Converter' + else: + fail("Py_UNICODE_converter: illegal 'accept' argument " + repr(accept)) + + def cleanup(self): + if not self.length: + return """\ +#if !USE_UNICODE_WCHAR_CACHE +PyMem_Free((void *){name}); +#endif /* USE_UNICODE_WCHAR_CACHE */ +""".format(name=self.name) + + def parse_arg(self, argname, argnum): + if not self.length: + if self.accept == {str}: + return """ + if (!PyUnicode_Check({argname})) {{{{ + _PyArg_BadArgument("{{name}}", {argnum}, "str", {argname}); + goto exit; + }}}} + #if USE_UNICODE_WCHAR_CACHE + {paramname} = _PyUnicode_AsUnicode({argname}); + #else /* USE_UNICODE_WCHAR_CACHE */ + {paramname} = PyUnicode_AsWideCharString({argname}, NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if ({paramname} == NULL) {{{{ + goto exit; + }}}} + """.format(argname=argname, paramname=self.name, argnum=argnum) + elif self.accept == {str, NoneType}: + return """ + if ({argname} == Py_None) {{{{ + {paramname} = NULL; + }}}} + else if (PyUnicode_Check({argname})) {{{{ + #if USE_UNICODE_WCHAR_CACHE + {paramname} = _PyUnicode_AsUnicode({argname}); + #else /* USE_UNICODE_WCHAR_CACHE */ + {paramname} = PyUnicode_AsWideCharString({argname}, NULL); + #endif /* USE_UNICODE_WCHAR_CACHE */ + if ({paramname} == NULL) {{{{ + goto exit; + }}}} + }}}} + else {{{{ + _PyArg_BadArgument("{{name}}", {argnum}, "str or None", {argname}); + goto exit; + }}}} + """.format(argname=argname, paramname=self.name, argnum=argnum) + return super().parse_arg(argname, argnum) @add_legacy_c_converter('s*', accept={str, buffer}) @add_legacy_c_converter('z*', accept={str, buffer, NoneType}) diff --git a/Tools/msi/bundle/bootstrap/pythonba.vcxproj b/Tools/msi/bundle/bootstrap/pythonba.vcxproj index 75aad442a44..ef71fe7da08 100644 --- a/Tools/msi/bundle/bootstrap/pythonba.vcxproj +++ b/Tools/msi/bundle/bootstrap/pythonba.vcxproj @@ -21,6 +21,9 @@ Release Win32 + v142 + v141 + v140 v140 v120 {7A09B132-B3EE-499B-A700-A4B2157FEA3D} @@ -47,6 +50,8 @@ comctl32.lib;gdiplus.lib;msimg32.lib;shlwapi.lib;wininet.lib;dutil.lib;balutil.lib;version.lib;uxtheme.lib;%(AdditionalDependencies) + $(WixInstallPath)sdk\vs2017\lib\x86 + $(WixInstallPath)sdk\vs2017\lib\x86 $(WixInstallPath)sdk\vs2015\lib\x86 $(WixInstallPath)sdk\vs2013\lib\x86 pythonba.def diff --git a/Tools/peg_generator/Makefile b/Tools/peg_generator/Makefile index e7a190c1bcd..6ad9c91b985 100644 --- a/Tools/peg_generator/Makefile +++ b/Tools/peg_generator/Makefile @@ -22,7 +22,7 @@ data/xxl.py: build: peg_extension/parse.c -peg_extension/parse.c: $(GRAMMAR) $(TOKENS) pegen/*.py peg_extension/peg_extension.c ../../Parser/pegen/pegen.c ../../Parser/pegen/parse_string.c ../../Parser/pegen/*.h pegen/grammar_parser.py +peg_extension/parse.c: $(GRAMMAR) $(TOKENS) pegen/*.py peg_extension/peg_extension.c ../../Parser/pegen.c ../../Parser/string_parser.c ../../Parser/*.h pegen/grammar_parser.py $(PYTHON) -m pegen -q c $(GRAMMAR) $(TOKENS) -o peg_extension/parse.c --compile-extension clean: @@ -70,23 +70,13 @@ stats: peg_extension/parse.c data/xxl.py time: time_compile time_compile: venv data/xxl.py - $(VENVPYTHON) scripts/benchmark.py --parser=pegen --target=xxl compile + $(VENVPYTHON) scripts/benchmark.py --target=xxl compile time_parse: venv data/xxl.py - $(VENVPYTHON) scripts/benchmark.py --parser=pegen --target=xxl parse - -time_old: time_old_compile - -time_old_compile: venv data/xxl.py - $(VENVPYTHON) scripts/benchmark.py --parser=cpython --target=xxl compile - -time_old_parse: venv data/xxl.py - $(VENVPYTHON) scripts/benchmark.py --parser=cpython --target=xxl parse + $(VENVPYTHON) scripts/benchmark.py --target=xxl parse time_peg_dir: venv $(VENVPYTHON) scripts/test_parse_directory.py \ - --grammar-file $(GRAMMAR) \ - --tokens-file $(TOKENS) \ -d $(TESTDIR) \ $(TESTFLAGS) \ --exclude "*/failset/*" \ @@ -95,12 +85,8 @@ time_peg_dir: venv time_stdlib: $(CPYTHON) venv $(VENVPYTHON) scripts/test_parse_directory.py \ - --grammar-file $(GRAMMAR) \ - --tokens-file $(TOKENS) \ -d $(CPYTHON) \ $(TESTFLAGS) \ - --exclude "*/test2to3/*" \ - --exclude "*/test2to3/**/*" \ --exclude "*/bad*" \ --exclude "*/lib2to3/tests/data/*" diff --git a/Tools/peg_generator/pegen/build.py b/Tools/peg_generator/pegen/build.py index 931ffc78752..9edde372e8d 100644 --- a/Tools/peg_generator/pegen/build.py +++ b/Tools/peg_generator/pegen/build.py @@ -66,15 +66,14 @@ def compile_c_extension( str(MOD_DIR.parent.parent.parent / "Python" / "Python-ast.c"), str(MOD_DIR.parent.parent.parent / "Python" / "asdl.c"), str(MOD_DIR.parent.parent.parent / "Parser" / "tokenizer.c"), - str(MOD_DIR.parent.parent.parent / "Parser" / "pegen" / "pegen.c"), - str(MOD_DIR.parent.parent.parent / "Parser" / "pegen" / "parse_string.c"), + str(MOD_DIR.parent.parent.parent / "Parser" / "pegen.c"), + str(MOD_DIR.parent.parent.parent / "Parser" / "string_parser.c"), str(MOD_DIR.parent / "peg_extension" / "peg_extension.c"), generated_source_path, ], include_dirs=[ str(MOD_DIR.parent.parent.parent / "Include" / "internal"), str(MOD_DIR.parent.parent.parent / "Parser"), - str(MOD_DIR.parent.parent.parent / "Parser" / "pegen"), ], extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py index 885ff05858f..aee668c3f32 100644 --- a/Tools/peg_generator/pegen/c_generator.py +++ b/Tools/peg_generator/pegen/c_generator.py @@ -58,7 +58,8 @@ class NodeTypes(Enum): STRING_TOKEN = 2 GENERIC_TOKEN = 3 KEYWORD = 4 - CUT_OPERATOR = 5 + SOFT_KEYWORD = 5 + CUT_OPERATOR = 6 BASE_NODETYPES = { @@ -104,6 +105,7 @@ class CCallMakerVisitor(GrammarVisitor): self.non_exact_tokens = non_exact_tokens self.cache: Dict[Any, FunctionCall] = {} self.keyword_cache: Dict[str, int] = {} + self.soft_keywords: Set[str] = set() def keyword_helper(self, keyword: str) -> FunctionCall: if keyword not in self.keyword_cache: @@ -118,12 +120,13 @@ class CCallMakerVisitor(GrammarVisitor): ) def soft_keyword_helper(self, value: str) -> FunctionCall: + self.soft_keywords.add(value.replace('"', "")) return FunctionCall( assigned_variable="_keyword", function="_PyPegen_expect_soft_keyword", arguments=["p", value], return_type="expr_ty", - nodetype=NodeTypes.NAME_TOKEN, + nodetype=NodeTypes.SOFT_KEYWORD, comment=f"soft_keyword='{value}'", ) @@ -217,6 +220,12 @@ class CCallMakerVisitor(GrammarVisitor): arguments=[positive, call.function, *call.arguments], return_type="int", ) + elif call.nodetype == NodeTypes.SOFT_KEYWORD: + return FunctionCall( + function=f"_PyPegen_lookahead_with_string", + arguments=[positive, call.function, *call.arguments], + return_type="int", + ) elif call.nodetype in {NodeTypes.GENERIC_TOKEN, NodeTypes.KEYWORD}: return FunctionCall( function=f"_PyPegen_lookahead_with_int", @@ -431,7 +440,7 @@ class CParserGenerator(ParserGenerator, GrammarVisitor): num_groups = max(groups) + 1 if groups else 1 for keywords_length in range(num_groups): if keywords_length not in groups.keys(): - self.print("NULL,") + self.print("(KeywordToken[]) {{NULL, -1}},") else: self.print("(KeywordToken[]) {") with self.indent(): diff --git a/Tools/peg_generator/pegen/keywordgen.py b/Tools/peg_generator/pegen/keywordgen.py new file mode 100644 index 00000000000..53638b17e61 --- /dev/null +++ b/Tools/peg_generator/pegen/keywordgen.py @@ -0,0 +1,76 @@ +"""Generate Lib/keyword.py from the Grammar and Tokens files using pgen""" + +import argparse + +from .build import build_parser, generate_token_definitions +from .c_generator import CParserGenerator + +TEMPLATE = r''' +"""Keywords (from "Grammar/python.gram") + +This file is automatically generated; please don't muck it up! + +To update the symbols in this file, 'cd' to the top directory of +the python source tree and run: + + PYTHONPATH=Tools/peg_generator python3 -m pegen.keywordgen \ + Grammar/Grammar \ + Grammar/Tokens \ + Lib/keyword.py + +Alternatively, you can run 'make regen-keyword'. +""" + +__all__ = ["iskeyword", "issoftkeyword", "kwlist", "softkwlist"] + +kwlist = [ +{keywords} +] + +softkwlist = [ +{soft_keywords} +] + +iskeyword = frozenset(kwlist).__contains__ +issoftkeyword = frozenset(softkwlist).__contains__ +'''.lstrip() + +EXTRA_KEYWORDS = ["async", "await"] + + +def main(): + parser = argparse.ArgumentParser( + description="Generate the Lib/keywords.py file from the grammar." + ) + parser.add_argument( + "grammar", type=str, help="The file with the grammar definition in PEG format" + ) + parser.add_argument( + "tokens_file", type=argparse.FileType("r"), help="The file with the token definitions" + ) + parser.add_argument( + "keyword_file", + type=argparse.FileType("w"), + help="The path to write the keyword definitions", + ) + args = parser.parse_args() + + grammar, _, _ = build_parser(args.grammar) + with args.tokens_file as tok_file: + all_tokens, exact_tok, non_exact_tok = generate_token_definitions(tok_file) + gen: ParserGenerator = CParserGenerator( + grammar, all_tokens, exact_tok, non_exact_tok, file=None + ) + gen.collect_todo() + + with args.keyword_file as thefile: + all_keywords = sorted(list(gen.callmakervisitor.keyword_cache.keys()) + EXTRA_KEYWORDS) + all_soft_keywords = sorted(gen.callmakervisitor.soft_keywords) + + keywords = "" if not all_keywords else " " + ",\n ".join(map(repr, all_keywords)) + soft_keywords = "" if not all_soft_keywords else " " + ",\n ".join(map(repr, all_soft_keywords)) + thefile.write(TEMPLATE.format(keywords=keywords, soft_keywords=soft_keywords)) + + +if __name__ == "__main__": + main() diff --git a/Tools/peg_generator/pegen/python_generator.py b/Tools/peg_generator/pegen/python_generator.py index 64336552f24..45a75975dbf 100644 --- a/Tools/peg_generator/pegen/python_generator.py +++ b/Tools/peg_generator/pegen/python_generator.py @@ -93,7 +93,13 @@ class PythonCallMakerVisitor(GrammarVisitor): def visit_Opt(self, node: Opt) -> Tuple[str, str]: name, call = self.visit(node.node) - return "opt", f"{call}," # Note trailing comma! + # Note trailing comma (the call may already have one comma + # at the end, for example when rules have both repeat0 and optional + # markers, e.g: [rule*]) + if call.endswith(","): + return "opt", call + else: + return "opt", f"{call}," def visit_Repeat0(self, node: Repeat0) -> Tuple[str, str]: if node in self.cache: diff --git a/Tools/peg_generator/scripts/benchmark.py b/Tools/peg_generator/scripts/benchmark.py index 71512c22a35..5fbedaa3b0e 100644 --- a/Tools/peg_generator/scripts/benchmark.py +++ b/Tools/peg_generator/scripts/benchmark.py @@ -6,13 +6,13 @@ import sys import os from time import time -import _peg_parser - try: import memory_profiler except ModuleNotFoundError: - print("Please run `make venv` to create a virtual environment and install" - " all the dependencies, before running this script.") + print( + "Please run `make venv` to create a virtual environment and install" + " all the dependencies, before running this script." + ) sys.exit(1) sys.path.insert(0, os.getcwd()) @@ -21,13 +21,6 @@ from scripts.test_parse_directory import parse_directory argparser = argparse.ArgumentParser( prog="benchmark", description="Reproduce the various pegen benchmarks" ) -argparser.add_argument( - "--parser", - action="store", - choices=["pegen", "cpython"], - default="pegen", - help="Which parser to benchmark (default is pegen)", -) argparser.add_argument( "--target", action="store", @@ -61,51 +54,37 @@ def benchmark(func): @benchmark -def time_compile(source, parser): - if parser == "cpython": - return _peg_parser.compile_string( - source, - oldparser=True, - ) - else: - return _peg_parser.compile_string(source) +def time_compile(source): + return compile(source, "", "exec") @benchmark -def time_parse(source, parser): - if parser == "cpython": - return _peg_parser.parse_string(source, oldparser=True) - else: - return _peg_parser.parse_string(source) +def time_parse(source): + return ast.parse(source) -def run_benchmark_xxl(subcommand, parser, source): +def run_benchmark_xxl(subcommand, source): if subcommand == "compile": - time_compile(source, parser) + time_compile(source) elif subcommand == "parse": - time_parse(source, parser) + time_parse(source) -def run_benchmark_stdlib(subcommand, parser): +def run_benchmark_stdlib(subcommand): + modes = {"compile": 2, "parse": 1} for _ in range(3): parse_directory( "../../Lib", - "../../Grammar/python.gram", - "../../Grammar/Tokens", verbose=False, excluded_files=["*/bad*", "*/lib2to3/tests/data/*",], - skip_actions=False, - tree_arg=0, short=True, - mode=2 if subcommand == "compile" else 1, - parser=parser, + mode=modes[subcommand], ) def main(): args = argparser.parse_args() subcommand = args.subcommand - parser = args.parser target = args.target if subcommand is None: @@ -114,9 +93,9 @@ def main(): if target == "xxl": with open(os.path.join("data", "xxl.py"), "r") as f: source = f.read() - run_benchmark_xxl(subcommand, parser, source) + run_benchmark_xxl(subcommand, source) elif target == "stdlib": - run_benchmark_stdlib(subcommand, parser) + run_benchmark_stdlib(subcommand) if __name__ == "__main__": diff --git a/Tools/peg_generator/scripts/find_max_nesting.py b/Tools/peg_generator/scripts/find_max_nesting.py index f2fdd00bfb7..92045c93ff7 100755 --- a/Tools/peg_generator/scripts/find_max_nesting.py +++ b/Tools/peg_generator/scripts/find_max_nesting.py @@ -14,8 +14,7 @@ INITIAL_NESTING_DEPTH, or NESTED_INCR_AMT variables. Usage: python -m scripts.find_max_nesting """ import sys - -from _peg_parser import parse_string +import ast GRAMMAR_FILE = "data/python.gram" INITIAL_NESTING_DEPTH = 10 @@ -28,9 +27,8 @@ ENDC = "\033[0m" def check_nested_expr(nesting_depth: int) -> bool: expr = f"{'(' * nesting_depth}0{')' * nesting_depth}" - try: - parse_string(expr) + ast.parse(expr) print(f"Nesting depth of {nesting_depth} is successful") return True except Exception as err: diff --git a/Tools/peg_generator/scripts/grammar_grapher.py b/Tools/peg_generator/scripts/grammar_grapher.py index 3aa25466c70..4afdbce8f96 100755 --- a/Tools/peg_generator/scripts/grammar_grapher.py +++ b/Tools/peg_generator/scripts/grammar_grapher.py @@ -42,6 +42,13 @@ from pegen.grammar import ( ) argparser = argparse.ArgumentParser(prog="graph_grammar", description="Graph a grammar tree",) +argparser.add_argument( + "-s", + "--start", + choices=["exec", "eval", "single"], + default="exec", + help="Choose the grammar's start rule (exec, eval or single)", +) argparser.add_argument("grammar_file", help="The grammar file to graph") @@ -91,19 +98,15 @@ def main() -> None: references[name] = set(references_for_item(rule)) # Flatten the start node if has only a single reference - root_node = "start" - if start := references["start"]: - if len(start) == 1: - root_node = list(start)[0] - del references["start"] + root_node = {"exec": "file", "eval": "eval", "single": "interactive"}[args.start] print("digraph g1 {") print('\toverlap="scale";') # Force twopi to scale the graph to avoid overlaps print(f'\troot="{root_node}";') - print(f"\t{root_node} [color=green, shape=circle]") + print(f"\t{root_node} [color=green, shape=circle];") for name, refs in references.items(): - if refs: # Ignore empty sets - print(f"\t{name} -> {','.join(refs)};") + for ref in refs: + print(f"\t{name} -> {ref};") print("}") diff --git a/Tools/peg_generator/scripts/show_parse.py b/Tools/peg_generator/scripts/show_parse.py deleted file mode 100755 index 1c1996f40f7..00000000000 --- a/Tools/peg_generator/scripts/show_parse.py +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env python3.8 - -"""Show the parse tree for a given program, nicely formatted. - -Example: - -$ scripts/show_parse.py a+b -Module( - body=[ - Expr( - value=BinOp( - left=Name(id="a", ctx=Load()), op=Add(), right=Name(id="b", ctx=Load()) - ) - ) - ], - type_ignores=[], -) -$ - -Use -v to show line numbers and column offsets. - -The formatting is done using black. You can also import this module -and call one of its functions. -""" - -import argparse -import ast -import difflib -import os -import sys -import tempfile - -import _peg_parser - -from typing import List - -sys.path.insert(0, os.getcwd()) -from pegen.ast_dump import ast_dump - -parser = argparse.ArgumentParser() -parser.add_argument( - "-d", "--diff", action="store_true", help="show diff between grammar and ast (requires -g)" -) -parser.add_argument("-g", "--grammar-file", help="grammar to use (default: use the ast module)") -parser.add_argument( - "-m", - "--multiline", - action="store_true", - help="concatenate program arguments using newline instead of space", -) -parser.add_argument("-v", "--verbose", action="store_true", help="show line/column numbers") -parser.add_argument("program", nargs="+", help="program to parse (will be concatenated)") - - -def format_tree(tree: ast.AST, verbose: bool = False) -> str: - with tempfile.NamedTemporaryFile("w+") as tf: - tf.write(ast_dump(tree, include_attributes=verbose)) - tf.write("\n") - tf.flush() - cmd = f"black -q {tf.name}" - sts = os.system(cmd) - if sts: - raise RuntimeError(f"Command {cmd!r} failed with status 0x{sts:x}") - tf.seek(0) - return tf.read() - - -def diff_trees(a: ast.AST, b: ast.AST, verbose: bool = False) -> List[str]: - sa = format_tree(a, verbose) - sb = format_tree(b, verbose) - la = sa.splitlines() - lb = sb.splitlines() - return list(difflib.unified_diff(la, lb, "a", "b", lineterm="")) - - -def show_parse(source: str, verbose: bool = False) -> str: - tree = _peg_parser.parse_string(source, oldparser=True) - return format_tree(tree, verbose).rstrip("\n") - - -def print_parse(source: str, verbose: bool = False) -> None: - print(show_parse(source, verbose)) - - -def main() -> None: - args = parser.parse_args() - if args.diff and not args.grammar_file: - parser.error("-d/--diff requires -g/--grammar-file") - if args.multiline: - sep = "\n" - else: - sep = " " - program = sep.join(args.program) - if args.grammar_file: - tree = _peg_parser.parse_string(program) - - if args.diff: - a = tree - b = _peg_parser.parse_string(program, oldparser=True) - diff = diff_trees(a, b, args.verbose) - if diff: - for line in diff: - print(line) - else: - print("# Trees are the same") - else: - print(f"# Parsed using {args.grammar_file}") - print(format_tree(tree, args.verbose)) - else: - tree = _peg_parser.parse_string(program, oldparser=True) - print("# Parse using the old parser") - print(format_tree(tree, args.verbose)) - - -if __name__ == "__main__": - main() diff --git a/Tools/peg_generator/scripts/test_parse_directory.py b/Tools/peg_generator/scripts/test_parse_directory.py index e88afe1539c..a5e26f0a0fe 100755 --- a/Tools/peg_generator/scripts/test_parse_directory.py +++ b/Tools/peg_generator/scripts/test_parse_directory.py @@ -7,28 +7,28 @@ import sys import time import traceback import tokenize -import _peg_parser -from glob import glob +from glob import glob, escape from pathlib import PurePath -from typing import List, Optional, Any +from typing import List, Optional, Any, Tuple sys.path.insert(0, os.getcwd()) from pegen.ast_dump import ast_dump from pegen.testutil import print_memstats -from scripts import show_parse SUCCESS = "\033[92m" FAIL = "\033[91m" ENDC = "\033[0m" +COMPILE = 2 +PARSE = 1 +NOTREE = 0 + argparser = argparse.ArgumentParser( prog="test_parse_directory", description="Helper program to test directories or files for pegen", ) argparser.add_argument("-d", "--directory", help="Directory path containing files to test") -argparser.add_argument("--grammar-file", help="Grammar file path") -argparser.add_argument("--tokens-file", help="Tokens file path") argparser.add_argument( "-e", "--exclude", action="append", default=[], help="Glob(s) for matching files to exclude" ) @@ -38,12 +38,6 @@ argparser.add_argument( argparser.add_argument( "-v", "--verbose", action="store_true", help="Display detailed errors for failures" ) -argparser.add_argument( - "--skip-actions", action="store_true", help="Suppress code emission for rule actions", -) -argparser.add_argument( - "-t", "--tree", action="count", help="Compare parse tree to official AST", default=0 -) def report_status( @@ -80,125 +74,15 @@ def report_status( print(f" {str(error.__class__.__name__)}: {error}") -def compare_trees( - actual_tree: ast.AST, file: str, verbose: bool, include_attributes: bool = False, -) -> int: - with open(file) as f: - expected_tree = _peg_parser.parse_string(f.read(), oldparser=True) - - expected_text = ast_dump(expected_tree, include_attributes=include_attributes) - actual_text = ast_dump(actual_tree, include_attributes=include_attributes) - if actual_text == expected_text: - if verbose: - print("Tree for {file}:") - print(show_parse.format_tree(actual_tree, include_attributes)) - return 0 - - print(f"Diffing ASTs for {file} ...") - - expected = show_parse.format_tree(expected_tree, include_attributes) - actual = show_parse.format_tree(actual_tree, include_attributes) - - if verbose: - print("Expected for {file}:") - print(expected) - print("Actual for {file}:") - print(actual) - print(f"Diff for {file}:") - - diff = show_parse.diff_trees(expected_tree, actual_tree, include_attributes) - for line in diff: - print(line) - - return 1 - - -def parse_directory( - directory: str, - grammar_file: str, - tokens_file: str, - verbose: bool, - excluded_files: List[str], - skip_actions: bool, - tree_arg: int, - short: bool, - mode: int, - parser: str, -) -> int: - if parser == "cpython" and (tree_arg or mode == 0): - print("Cannot specify tree argument or mode=0 with the cpython parser.", file=sys.stderr) - return 1 - - if not directory: - print("You must specify a directory of files to test.", file=sys.stderr) - return 1 - - if grammar_file and tokens_file: - if not os.path.exists(grammar_file): - print(f"The specified grammar file, {grammar_file}, does not exist.", file=sys.stderr) - return 1 - else: - print( - "A grammar file or a tokens file was not provided - attempting to use existing parser from stdlib...\n" - ) - - if tree_arg: - assert mode == 1, "Mode should be 1 (parse), when comparing the generated trees" - - # For a given directory, traverse files and attempt to parse each one - # - Output success/failure for each file - errors = 0 - files = [] - trees = {} # Trees to compare (after everything else is done) - total_seconds = 0 - - for file in sorted(glob(f"{directory}/**/*.py", recursive=True)): - # Only attempt to parse Python files and files that are not excluded - should_exclude_file = False - for pattern in excluded_files: - if PurePath(file).match(pattern): - should_exclude_file = True - break - - if not should_exclude_file: - with tokenize.open(file) as f: - source = f.read() - try: - t0 = time.time() - if mode == 2: - result = _peg_parser.compile_string( - source, - filename=file, - oldparser=parser == "cpython", - ) - else: - result = _peg_parser.parse_string( - source, - filename=file, - oldparser=parser == "cpython" - ) - t1 = time.time() - total_seconds += (t1 - t0) - if tree_arg: - trees[file] = result - if not short: - report_status(succeeded=True, file=file, verbose=verbose) - except Exception as error: - try: - _peg_parser.parse_string(source, mode="exec", oldparser=True) - except Exception: - if not short: - print(f"File {file} cannot be parsed by either pegen or the ast module.") - else: - report_status( - succeeded=False, file=file, verbose=verbose, error=error, short=short - ) - errors += 1 - files.append(file) +def parse_file(source: str, file: str) -> Tuple[Any, float]: + t0 = time.time() + result = ast.parse(source, filename=file) t1 = time.time() + return result, t1 - t0 + +def generate_time_stats(files, total_seconds) -> None: total_files = len(files) - total_bytes = 0 total_lines = 0 for file in files: @@ -217,21 +101,37 @@ def parse_directory( f"or {total_bytes / total_seconds :,.0f} bytes/sec.", ) + +def parse_directory(directory: str, verbose: bool, excluded_files: List[str], short: bool) -> int: + # For a given directory, traverse files and attempt to parse each one + # - Output success/failure for each file + errors = 0 + files = [] + total_seconds = 0 + + for file in sorted(glob(os.path.join(escape(directory), f"**/*.py"), recursive=True)): + # Only attempt to parse Python files and files that are not excluded + if any(PurePath(file).match(pattern) for pattern in excluded_files): + continue + + with tokenize.open(file) as f: + source = f.read() + + try: + result, dt = parse_file(source, file) + total_seconds += dt + report_status(succeeded=True, file=file, verbose=verbose, short=short) + except SyntaxError as error: + report_status(succeeded=False, file=file, verbose=verbose, error=error, short=short) + errors += 1 + files.append(file) + + generate_time_stats(files, total_seconds) if short: print_memstats() if errors: print(f"Encountered {errors} failures.", file=sys.stderr) - - # Compare trees (the dict is empty unless -t is given) - compare_trees_errors = 0 - for file, tree in trees.items(): - if not short: - print("Comparing ASTs for", file) - if compare_trees(tree, file, verbose, tree_arg >= 2) == 1: - compare_trees_errors += 1 - - if errors or compare_trees_errors: return 1 return 0 @@ -240,28 +140,10 @@ def parse_directory( def main() -> None: args = argparser.parse_args() directory = args.directory - grammar_file = args.grammar_file - tokens_file = args.tokens_file verbose = args.verbose excluded_files = args.exclude - skip_actions = args.skip_actions - tree = args.tree short = args.short - mode = 1 if args.tree else 2 - sys.exit( - parse_directory( - directory, - grammar_file, - tokens_file, - verbose, - excluded_files, - skip_actions, - tree, - short, - mode, - "pegen", - ) - ) + sys.exit(parse_directory(directory, verbose, excluded_files, short)) if __name__ == "__main__": diff --git a/Tools/peg_generator/scripts/test_pypi_packages.py b/Tools/peg_generator/scripts/test_pypi_packages.py index 98f77785cdd..f014753b3cd 100755 --- a/Tools/peg_generator/scripts/test_pypi_packages.py +++ b/Tools/peg_generator/scripts/test_pypi_packages.py @@ -57,22 +57,11 @@ def find_dirname(package_name: str) -> str: def run_tests(dirname: str, tree: int) -> int: return test_parse_directory.parse_directory( dirname, - HERE / ".." / ".." / ".." / "Grammar" / "python.gram", - HERE / ".." / ".." / ".." / "Grammar" / "Tokens", verbose=False, - excluded_files=[ - "*/failset/*", - "*/failset/**", - "*/failset/**/*", - "*/test2to3/*", - "*/test2to3/**/*", - "*/bad*", - "*/lib2to3/tests/data/*", - ], - skip_actions=False, + excluded_files=[], tree_arg=tree, short=True, - mode=1, + mode=1 if tree else 0, parser="pegen", ) diff --git a/Tools/scripts/generate_symbol_py.py b/Tools/scripts/generate_symbol_py.py deleted file mode 100755 index 9219b096e4d..00000000000 --- a/Tools/scripts/generate_symbol_py.py +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env python3 -# This script generates the symbol.py source file. - -import sys -import re - -def main(inFileName="Include/graminit.h", outFileName="Lib/symbol.py"): - try: - fp = open(inFileName) - except OSError as err: - sys.stderr.write("I/O error: %s\n" % str(err)) - sys.exit(1) - with fp: - lines = fp.read().split("\n") - prog = re.compile( - "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)", - re.IGNORECASE) - tokens = {} - for line in lines: - match = prog.match(line) - if match: - name, val = match.group(1, 2) - val = int(val) - tokens[val] = name # reverse so we can sort them... - keys = sorted(tokens.keys()) - # load the output skeleton from the target: - try: - fp = open(outFileName) - except OSError as err: - sys.stderr.write("I/O error: %s\n" % str(err)) - sys.exit(2) - with fp: - format = fp.read().split("\n") - try: - start = format.index("#--start constants--") + 1 - end = format.index("#--end constants--") - except ValueError: - sys.stderr.write("target does not contain format markers") - sys.exit(3) - lines = [] - for val in keys: - lines.append("%s = %d" % (tokens[val], val)) - format[start:end] = lines - try: - fp = open(outFileName, 'w') - except OSError as err: - sys.stderr.write("I/O error: %s\n" % str(err)) - sys.exit(4) - with fp: - fp.write("\n".join(format)) - -if __name__ == '__main__': - main(*sys.argv[1:]) diff --git a/Tools/scripts/run_tests.py b/Tools/scripts/run_tests.py index bcfa5e943b3..48feb3f778e 100644 --- a/Tools/scripts/run_tests.py +++ b/Tools/scripts/run_tests.py @@ -25,9 +25,8 @@ def main(regrtest_args): '-u', # Unbuffered stdout and stderr '-W', 'default', # Warnings set to 'default' '-bb', # Warnings about bytes/bytearray + '-E', # Ignore environment variables ] - if 'PYTHONOLDPARSER' not in os.environ: - args.append('-E') # Ignore environment variables # Allow user-specified interpreter options to override our defaults. args.extend(test.support.args_from_interpreter_flags()) diff --git a/Tools/ssl/make_ssl_data.py b/Tools/ssl/make_ssl_data.py index a29c04ab571..1dc234f5232 100755 --- a/Tools/ssl/make_ssl_data.py +++ b/Tools/ssl/make_ssl_data.py @@ -39,7 +39,7 @@ if __name__ == "__main__": f = sys.stdout if use_stdout else open(outfile, "w") # mnemonic -> (library code, error prefix, header file) error_libraries = {} - for error_header in glob.glob(os.path.join(openssl_inc, 'include/openssl/*err.h')): + for error_header in glob.glob(os.path.join(glob.escape(openssl_inc), 'include/openssl/*err.h')): base = os.path.basename(error_header) if base in ('buffererr.h', 'objectserr.h', 'storeerr.h'): # Deprecated in 3.0. diff --git a/Tools/ssl/multissltests.py b/Tools/ssl/multissltests.py index 12af98d12c4..3818165a836 100755 --- a/Tools/ssl/multissltests.py +++ b/Tools/ssl/multissltests.py @@ -314,6 +314,7 @@ class AbstractBuilder(object): "shared", "--debug", "--prefix={}".format(self.install_dir) ] + # cmd.extend(["no-deprecated", "--api=1.1.0"]) env = os.environ.copy() # set rpath env["LD_RUN_PATH"] = self.lib_dir diff --git a/configure b/configure index 1124412dce4..5024860ca43 100755 --- a/configure +++ b/configure @@ -632,6 +632,7 @@ THREADHEADERS LIBPL PY_ENABLE_SHARED PLATLIBDIR +BINLIBDEST LIBPYTHON EXT_SUFFIX ALT_SOABI @@ -2738,7 +2739,7 @@ if test "$srcdir" != . -a "$srcdir" != "$(pwd)"; then # If we're building out-of-tree, we need to make sure the following # resources get picked up before their $srcdir counterparts. # Objects/ -> typeslots.inc - # Include/ -> Python-ast.h, graminit.h + # Include/ -> Python-ast.h # Python/ -> importlib.h # (A side effect of this is that these resources will automatically be # regenerated when building out-of-tree, regardless of whether or not @@ -3425,7 +3426,7 @@ $as_echo "#define _BSD_SOURCE 1" >>confdefs.h # has no effect, don't bother defining them Darwin/[6789].*) define_xopen_source=no;; - Darwin/1[0-9].*) + Darwin/[12][0-9].*) define_xopen_source=no;; # On AIX 4 and 5.1, mbstate_t is defined only when _XOPEN_SOURCE == 500 but # used in wcsnrtombs() and mbsnrtowcs() even if _XOPEN_SOURCE is not defined @@ -15334,7 +15335,11 @@ else fi -# Check for --with-libdir-name + +BINLIBDEST='$(LIBDIR)/python$(VERSION)' + + +# Check for --with-platlibdir # /usr/$LIDIRNAME/python$VERSION PLATLIBDIR="lib" @@ -15353,6 +15358,7 @@ then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } PLATLIBDIR="$withval" + BINLIBDEST='${exec_prefix}/${PLATLIBDIR}/python$(VERSION)' else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } @@ -16800,7 +16806,7 @@ do done -SRCDIRS="Parser Parser/pegen Objects Python Modules Modules/_io Programs" +SRCDIRS="Parser Objects Python Modules Modules/_io Programs" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for build directories" >&5 $as_echo_n "checking for build directories... " >&6; } for dir in $SRCDIRS; do diff --git a/configure.ac b/configure.ac index 84d1f00983f..5a3e340aa3e 100644 --- a/configure.ac +++ b/configure.ac @@ -16,7 +16,7 @@ if test "$srcdir" != . -a "$srcdir" != "$(pwd)"; then # If we're building out-of-tree, we need to make sure the following # resources get picked up before their $srcdir counterparts. # Objects/ -> typeslots.inc - # Include/ -> Python-ast.h, graminit.h + # Include/ -> Python-ast.h # Python/ -> importlib.h # (A side effect of this is that these resources will automatically be # regenerated when building out-of-tree, regardless of whether or not @@ -510,7 +510,7 @@ case $ac_sys_system/$ac_sys_release in # has no effect, don't bother defining them Darwin/@<:@6789@:>@.*) define_xopen_source=no;; - Darwin/1@<:@0-9@:>@.*) + Darwin/@<:@[12]@:>@@<:@0-9@:>@.*) define_xopen_source=no;; # On AIX 4 and 5.1, mbstate_t is defined only when _XOPEN_SOURCE == 500 but # used in wcsnrtombs() and mbsnrtowcs() even if _XOPEN_SOURCE is not defined @@ -4770,7 +4770,11 @@ else fi -# Check for --with-libdir-name +AC_SUBST(BINLIBDEST) +BINLIBDEST='$(LIBDIR)/python$(VERSION)' + + +# Check for --with-platlibdir # /usr/$LIDIRNAME/python$VERSION AC_SUBST(PLATLIBDIR) PLATLIBDIR="lib" @@ -4787,6 +4791,7 @@ if test -n "$withval" -a "$withval" != yes -a "$withval" != no then AC_MSG_RESULT(yes) PLATLIBDIR="$withval" + BINLIBDEST='${exec_prefix}/${PLATLIBDIR}/python$(VERSION)' else AC_MSG_RESULT(no) fi], @@ -5433,7 +5438,7 @@ do done AC_SUBST(SRCDIRS) -SRCDIRS="Parser Parser/pegen Objects Python Modules Modules/_io Programs" +SRCDIRS="Parser Objects Python Modules Modules/_io Programs" AC_MSG_CHECKING(for build directories) for dir in $SRCDIRS; do if test ! -d $dir; then diff --git a/setup.py b/setup.py index a220f366e25..21a5a58981f 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ import os import re import sys import sysconfig -from glob import glob +from glob import glob, escape try: @@ -401,7 +401,7 @@ class PyBuildExt(build_ext): # Python header files headers = [sysconfig.get_config_h_filename()] - headers += glob(os.path.join(sysconfig.get_path('include'), "*.h")) + headers += glob(os.path.join(escape(sysconfig.get_path('include')), "*.h")) for ext in self.extensions: ext.sources = [ find_module_file(filename, moddirlist) @@ -853,7 +853,8 @@ class PyBuildExt(build_ext): # libm is needed by delta_new() that uses round() and by accum() that # uses modf(). self.add(Extension('_datetime', ['_datetimemodule.c'], - libraries=['m'])) + libraries=['m'], + extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) # zoneinfo module self.add(Extension('_zoneinfo', ['_zoneinfo.c'])), # random number generator implemented in C @@ -862,7 +863,8 @@ class PyBuildExt(build_ext): # bisect self.add(Extension("_bisect", ["_bisectmodule.c"])) # heapq - self.add(Extension("_heapq", ["_heapqmodule.c"])) + self.add(Extension("_heapq", ["_heapqmodule.c"], + extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) # C-optimized pickle replacement self.add(Extension("_pickle", ["_pickle.c"], extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) @@ -917,9 +919,6 @@ class PyBuildExt(build_ext): # select(2); not on ancient System V self.add(Extension('select', ['selectmodule.c'])) - # Fred Drake's interface to the Python parser - self.add(Extension('parser', ['parsermodule.c'])) - # Memory-mapped files (also works on Win32). self.add(Extension('mmap', ['mmapmodule.c'])) @@ -2433,7 +2432,7 @@ class PyBuildExt(build_ext): if "blake2" in configured: blake2_deps = glob( - os.path.join(self.srcdir, 'Modules/_blake2/impl/*') + os.path.join(escape(self.srcdir), 'Modules/_blake2/impl/*') ) blake2_deps.append('hashlib.h') self.add(Extension( @@ -2448,7 +2447,7 @@ class PyBuildExt(build_ext): if "sha3" in configured: sha3_deps = glob( - os.path.join(self.srcdir, 'Modules/_sha3/kcp/*') + os.path.join(escape(self.srcdir), 'Modules/_sha3/kcp/*') ) sha3_deps.append('hashlib.h') self.add(Extension(