summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
AgeCommit message (Collapse)AuthorLines
2022-02-14bpo-46541: Discover the global strings. (gh-31346)Eric Snow-0/+2
Instead of manually enumerating the global strings in generate_global_objects.py, we extrapolate the list from usage of _Py_ID() and _Py_STR() in the source files. This is partly inspired by gh-31261. https://bugs.python.org/issue46541
2022-02-08bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow-78/+45
global objects. (gh-30928) We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code. It is still used in a number of non-builtin stdlib modules. The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime. A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings). https://bugs.python.org/issue46541#msg411799 explains the rationale for this change. The core of the change is in: * (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros * Include/internal/pycore_runtime_init.h - added the static initializers for the global strings * Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState * Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings. That check is added to the PR CI config. The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()). This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *. The following are not changed (yet): * stop using _Py_IDENTIFIER() in the stdlib modules * (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API * (maybe) intern the strings during runtime init https://bugs.python.org/issue46541
2021-12-16bpo-45635: Do not suppress errors in functions called from _PyErr_Display ↵Irit Katriel-113/+157
(GH-30073) Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
2021-12-10bpo-45635: refactor print_exception_recursive into smaller functions to ↵Irit Katriel-148/+186
standardize error handling (GH-30015) Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
2021-12-09bpo-45635: continue refactor of print_exception() to standardize error ↵Irit Katriel-78/+105
handling (GH-29996) Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
2021-12-08bpo-45635: refactor print_exception() into smaller functions (GH-29981)Irit Katriel-87/+139
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
2021-12-03bpo-45607: Make it possible to enrich exception displays via setting their ↵Irit Katriel-0/+35
__note__ field (GH-29880)
2021-11-27bpo-45614: Fix traceback display for exceptions with invalid module name ↵Irit Katriel-1/+1
(GH-29726)
2021-11-05bpo-45292: [PEP 654] Update traceback display code to work with exception ↵Irit Katriel-47/+270
groups (GH-29207)
2021-10-06Fix typos in the Python directory (GH-28767)Christian Clauss-2/+2
2021-09-05bpo-41031: Match C and Python code formatting of unprintable exceptions and ↵Irit Katriel-1/+3
exceptions in the __main__ module. (GH-28139)
2021-09-03bpo-45083: Include the exception class qualname when formatting an exception ↵Irit Katriel-18/+19
(GH-28119) Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
2021-04-23bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)Pablo Galindo-6/+67
To improve the user experience understanding what part of the error messages associated with SyntaxErrors is wrong, we can highlight the whole error range and not only place the caret at the first character. In this way: >>> foo(x, z for z in range(10), t, w) File "<stdin>", line 1 foo(x, z for z in range(10), t, w) ^ SyntaxError: Generator expression must be parenthesized becomes >>> foo(x, z for z in range(10), t, w) File "<stdin>", line 1 foo(x, z for z in range(10), t, w) ^^^^^^^^^^^^^^^^^^^^ SyntaxError: Generator expression must be parenthesized
2021-04-19bpo-25460: Surround suggestions by quotes (GH-25473)Pablo Galindo-2/+2
2021-04-14bpo-38530: Make sure that failing to generate suggestions on failure will ↵Pablo Galindo-0/+2
not propagate exceptions (GH-25408)
2021-04-14bpo-38530: Offer suggestions on AttributeError (#16856)Pablo Galindo-1/+11
When printing AttributeError, PyErr_Display will offer suggestions of similar attribute names in the object that the exception was raised from: >>> collections.namedtoplo Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'collections' has no attribute 'namedtoplo'. Did you mean: namedtuple?
2021-04-07bpo-43244: Remove Yield macro from pycore_ast.h (GH-25243)Victor Stinner-2/+0
* pycore_ast.h no longer defines the Yield macro. * Fix a compiler warning on Windows: "warning C4005: 'Yield': macro redefinition". * Python-ast.c now defines directly functions with their real _Py_xxx() name, rather than xxx(). * Remove "#undef Yield" in C files including pycore_ast.h.
2021-03-29bpo-43660: Fix crash when displaying exceptions with custom values for ↵Pablo Galindo-1/+2
sys.stderr (GH-25075)
2021-03-24bpo-43244: Remove the pyarena.h header (GH-25007)Victor Stinner-12/+12
Remove the pyarena.h header file with functions: * PyArena_New() * PyArena_Free() * PyArena_Malloc() * PyArena_AddPyObject() These functions were undocumented, excluded from the limited C API, and were only used internally by the compiler. Add pycore_pyarena.h header. Rename functions: * PyArena_New() => _PyArena_New() * PyArena_Free() => _PyArena_Free() * PyArena_Malloc() => _PyArena_Malloc() * PyArena_AddPyObject() => _PyArena_AddPyObject()
2021-03-24bpo-43244: Remove parser_interface.h header file (GH-25001)Victor Stinner-6/+7
Remove parser functions using the "struct _mod" type, because the AST C API was removed: * PyParser_ASTFromFile() * PyParser_ASTFromFileObject() * PyParser_ASTFromFilename() * PyParser_ASTFromString() * PyParser_ASTFromStringObject() These functions were undocumented and excluded from the limited C API. Add pycore_parser.h internal header file. Rename functions: * PyParser_ASTFromFileObject() => _PyParser_ASTFromFile() * PyParser_ASTFromStringObject() => _PyParser_ASTFromString() These functions are no longer exported (replace PyAPI_FUNC() with extern). Remove also _PyPegen_run_parser_from_file() function. Update test_peg_generator to use _PyPegen_run_parser_from_file_pointer() instead.
2021-03-24bpo-43244: Add pycore_compile.h header file (GH-25000)Victor Stinner-2/+3
Remove the compiler functions using "struct _mod" type, because the public AST C API was removed: * PyAST_Compile() * PyAST_CompileEx() * PyAST_CompileObject() * PyFuture_FromAST() * PyFuture_FromASTObject() These functions were undocumented and excluded from the limited C API. Rename functions: * PyAST_CompileObject() => _PyAST_Compile() * PyFuture_FromASTObject() => _PyFuture_FromAST() Moreover, _PyFuture_FromAST() is no longer exported (replace PyAPI_FUNC() with extern). _PyAST_Compile() remains exported for test_peg_generator. Remove also compatibility functions: * PyAST_Compile() * PyAST_CompileEx() * PyFuture_FromAST()
2021-03-23bpo-43244: Remove ast.h, asdl.h, Python-ast.h headers (GH-24933)Victor Stinner-1/+1
These functions were undocumented and excluded from the limited C API. Most names defined by these header files were not prefixed by "Py" and so could create names conflicts. For example, Python-ast.h defined a "Yield" macro which was conflict with the "Yield" name used by the Windows <winbase.h> header. Use the Python ast module instead. * Move Include/asdl.h to Include/internal/pycore_asdl.h. * Move Include/Python-ast.h to Include/internal/pycore_ast.h. * Remove ast.h header file. * pycore_symtable.h no longer includes Python-ast.h.
2021-03-19bpo-43244: Remove symtable.h header file (GH-24910)Victor Stinner-43/+0
Rename Include/symtable.h to to Include/internal/pycore_symtable.h, don't export symbols anymore (replace PyAPI_FUNC and PyAPI_DATA with extern) and rename functions: * PyST_GetScope() to _PyST_GetScope() * PySymtable_BuildObject() to _PySymtable_Build() * PySymtable_Free() to _PySymtable_Free() Remove PySymtable_Build(), Py_SymtableString() and Py_SymtableStringObject() functions. The Py_SymtableString() function was part the stable ABI by mistake but it could not be used, since the symtable.h header file was excluded from the limited C API. The Python symtable module remains available and is unchanged.
2021-02-19bpo-35134: Move non-limited C API files to Include/cpython/ (GH-24561)Nicholas Sim-2/+0
Include/{odictobject.h,parser_interface.h,picklebufobject.h,pydebug.h,pyfpe.h} into Include/cpython/. Parser: peg_api: include Python.h instead of parser_interface.h.
2020-12-09bpo-32381: Add _PyRun_AnyFileObject() (GH-23723)Victor Stinner-26/+73
pymain_run_file() no longer encodes the filename: pass the filename as an object to the new _PyRun_AnyFileObject() function. Add new private functions: * _PyRun_AnyFileObject() * _PyRun_InteractiveLoopObject() * _Py_FdIsInteractive()
2020-12-09bpo-32381: Add _PyRun_SimpleFileObject() (GH-23709)Victor Stinner-4/+4
pymain_run_startup() now pass the filename as a Python object to _PyRun_SimpleFileObject().
2020-12-08bpo-32381: Fix PyRun_SimpleFileExFlags() encoding (GH-23642)Victor Stinner-92/+132
Fix encoding name when running a ".pyc" file on Windows: PyRun_SimpleFileExFlags() now uses the correct encoding to decode the filename. * Add pyrun_file() subfunction. * Add pyrun_simple_file() subfunction. * PyRun_SimpleFileExFlags() now calls _Py_fopen_obj() rather than _Py_fopen().
2020-12-02bpo-40939: Restore some stable API functions incorrectly deleted (GH-23606)Pablo Galindo-8/+103
2020-10-26bpo-42006: Stop using PyDict_GetItem, PyDict_GetItemString and ↵Serhiy Storchaka-4/+9
_PyDict_GetItemId. (GH-22648) These functions are considered not safe because they suppress all internal errors and can return wrong result. PyDict_GetItemString and _PyDict_GetItemId can also silence current exception in rare cases. Remove no longer used _PyDict_GetItemId. Add _PyDict_ContainsId and rename _PyDict_Contains into _PyDict_Contains_KnownHash.
2020-10-10bpo-41991: Remove _PyObject_HasAttrId (GH-22629)Serhiy Storchaka-2/+4
It can silence arbitrary exceptions.
2020-06-22bpo-40939: Rename PyPegen* functions to PyParser* (GH-21016)Lysandros Nikolaou-8/+8
Rename PyPegen* functions to PyParser*, so that we can remove the old set of PyParser* functions that were using the old parser.
2020-06-20bpo-40939: Remove the old parser (Part 2) (GH-21005)Lysandros Nikolaou-3/+0
Remove some remaining files and Makefile targets for the old parser
2020-06-11bpo-40939: Remove the old parser (GH-20768)Pablo Galindo-471/+6
This commit removes the old parser, the deprecated parser module, the old parser compatibility flags and environment variables and all associated support code and documentation.
2020-06-02Fix MSVC warnings in pythonrun.c (#GH-0587)Ammar Askar-8/+8
2020-05-14bpo-40612: Fix SyntaxError edge cases in traceback formatting (GH-20072)Guido van Rossum-19/+47
This fixes both the traceback.py module and the C code for formatting syntax errors (in Python/pythonrun.c). They now both consistently do the following: - Suppress caret if it points left of text - Allow caret pointing just past end of line - If caret points past end of line, clip to *just* past end of line The syntax error formatting code in traceback.py was mostly rewritten; small, subtle changes were applied to the C code in pythonrun.c. There's still a difference when the text contains embedded newlines. Neither handles these very well, and I don't think the case occurs in practice. Automerge-Triggered-By: @gvanrossum
2020-05-12bpo-40593: Improve syntax errors for invalid characters in source code. ↵Serhiy Storchaka-3/+0
(GH-20033)
2020-05-04bpo-40246: Revert reporting of invalid string prefixes (GH-19888)Lysandros Nikolaou-3/+0
Due to backwards compatibility concerns regarding keywords immediately followed by a string without whitespace between them (like in `bg="#d00" if clear else"#fca"`) will fail to parse, commit 41d5b94af44e34ac05d4cd57460ed104ccf96628 has to be reverted.
2020-04-27bpo-40334: Support CO_FUTURE_BARRY_AS_BDFL in the new parser (GH-19721)Pablo Galindo-2/+2
This commit also allows to pass flags to the new parser in all interfaces and fixes a bug in the parser generator that was causing to inline rules with actions, making them disappear.
2020-04-23bpo-40334: Improve various PEG-Parser related stuff (GH-19669)Lysandros Nikolaou-1/+1
The changes in this commit are all related to @vstinner's original review comments of the initial PEP 617 implementation PR.
2020-04-23bpo-40334: Rename PyConfig.use_peg to _use_peg_parser (GH-19670)Victor Stinner-5/+5
* Rename PyConfig.use_peg to _use_peg_parser * Document PyConfig._use_peg_parser and mark it a deprecated * Mark -X oldparser option and PYTHONOLDPARSER env var as deprecated in the documentation. * Add use_old_parser() and skip_if_new_parser() to test.support * Remove sys.flags.use_peg: use_old_parser() uses _testinternalcapi.get_configs() instead. * Enhance test_embed tests * subprocess._args_from_interpreter_flags() copies -X oldparser
2020-04-22bpo-40334: PEP 617 implementation: New PEG parser for CPython (GH-19503)Pablo Galindo-8/+46
Co-authored-by: Guido van Rossum <guido@python.org> Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
2020-04-15bpo-40268: Remove unused imports in pylifecycle.c (GH-19533)Victor Stinner-20/+17
Remove unused imports in files: * initconfig.c * main.c * preconfig.h * pylifecycle.c * python.c * pythonrun.c
2020-04-15bpo-40268: Remove unused osdefs.h includes (GH-19532)Victor Stinner-1/+0
When the include is needed, add required symbol in a comment.
2020-04-14bpo-40268: Remove a few pycore_pystate.h includes (GH-19510)Victor Stinner-1/+2
2020-04-14bpo-40268: Rename _PyInterpreterState_GET_UNSAFE() (GH-19509)Victor Stinner-1/+1
Rename _PyInterpreterState_GET_UNSAFE() to _PyInterpreterState_GET() for consistency with _PyThreadState_GET() and to have a shorter name (help to fit into 80 columns). Add also "assert(tstate != NULL);" to the function.
2020-04-13bpo-40268: Add _PyInterpreterState_GetConfig() (GH-19492)Victor Stinner-2/+2
Don't access PyInterpreterState.config member directly anymore, but use new functions: * _PyInterpreterState_GetConfig() * _PyInterpreterState_SetConfig() * _Py_GetConfig()
2020-04-12bpo-40246: Report a better error message for invalid string prefixes (GH-19476)Lysandros Nikolaou-0/+3
2020-03-27bpo-38644: Use _PySys_Audit(): pass tstate explicitly (GH-19183)Victor Stinner-12/+13
Add the dependency to tstate more explicit.
2020-03-13bpo-39947: Use _PyInterpreterState_GET_UNSAFE() (GH-18978)Victor Stinner-3/+3
Replace _PyInterpreterState_Get() function call with _PyInterpreterState_GET_UNSAFE() macro which is more efficient but don't check if tstate or interp is NULL. _Py_GetConfigsAsDict() now uses _PyThreadState_GET().
2020-02-03bpo-39542: Move object.h debug functions to internal C API (GH-18331)Victor Stinner-0/+1
Move the following functions from the public C API to the internal C API: * _PyDebug_PrintTotalRefs(), * _Py_PrintReferenceAddresses() * _Py_PrintReferences()