summaryrefslogtreecommitdiffstats
path: root/Python
Commit message (Collapse)AuthorAgeFilesLines
...
* gh-109039: Branch prediction for Tier 2 interpreter (#109038)Guido van Rossum2023-09-115-32/+125
| | | | | | | | | | | This adds a 16-bit inline cache entry to the conditional branch instructions POP_JUMP_IF_{FALSE,TRUE,NONE,NOT_NONE} and their instrumented variants, which is used to keep track of the branch direction. Each time we encounter these instructions we shift the cache entry left by one and set the bottom bit to whether we jumped. Then when it's time to translate such a branch to Tier 2 uops, we use the bit count from the cache entry to decided whether to continue translating the "didn't jump" branch or the "jumped" branch. The counter is initialized to a pattern of alternating ones and zeros to avoid bias. The .pyc file magic number is updated. There's a new test, some fixes for existing tests, and a few miscellaneous cleanups.
* gh-109179: Fix traceback display for SyntaxErrors with notes (#109197)Irit Katriel2023-09-111-13/+11
|
* gh-108987: Fix _thread.start_new_thread() race condition (#109135)Victor Stinner2023-09-112-25/+32
| | | | | | | | | | | | | Fix _thread.start_new_thread() race condition. If a thread is created during Python finalization, the newly spawned thread now exits immediately instead of trying to access freed memory and lead to a crash. thread_run() calls PyEval_AcquireThread() which checks if the thread must exit. The problem was that tstate was dereferenced earlier in _PyThreadState_Bind() which leads to a crash most of the time. Move _PyThreadState_CheckConsistency() from thread_run() to _PyThreadState_Bind().
* GH-108976. Keep monitoring data structures valid during de-optimization ↵Mark Shannon2023-09-111-55/+51
| | | | during callback. (GH-109131)
* gh-109207: Fix SystemError when printing symtable entry object. (GH-109225)云line2023-09-101-3/+2
|
* gh-109118: Fix runtime crash when NameError happens in PEP 695 function ↵Jelle Zijlstra2023-09-094-54/+109
| | | | (#109123)
* Check the result of PySet_Contains() for error in Python/symtable.c (GH-109146)Serhiy Storchaka2023-09-081-15/+57
|
* GH-108614: Unbreak emscripten build (GH-109132)Mark Shannon2023-09-084-10/+10
|
* gh-106922: Fix error location for constructs with spaces and parentheses ↵Pablo Galindo Salgado2023-09-081-0/+17
| | | | (#108959)
* gh-104690: thread_run() checks for tstate dangling pointer (#109056)Victor Stinner2023-09-082-18/+26
| | | | | | | | thread_run() of _threadmodule.c now calls _PyThreadState_CheckConsistency() to check if tstate is a dangling pointer when Python is built in debug mode. Rename ceval_gil.c is_tstate_valid() to _PyThreadState_CheckConsistency() to reuse it in _threadmodule.c.
* GH-91079: Rename C_RECURSION_LIMIT to Py_C_RECURSION_LIMIT (#108507)Victor Stinner2023-09-085-9/+9
| | | | | | | Symbols of the C API should be prefixed by "Py_" to avoid conflict with existing names in 3rd party C extensions on "#include <Python.h>". test.pythoninfo now logs Py_C_RECURSION_LIMIT constant and other _testcapi and _testinternalcapi constants.
* GH-108716: Turn off deep-freezing of code objects. (GH-108722)Mark Shannon2023-09-084-47/+31
|
* gh-109094: remove unnecessary updates of frame->prev_instr in ↵Irit Katriel2023-09-071-6/+2
| | | | instrumentation functions (#109076)
* GH-108614: Add `RESUME_CHECK` instruction (GH-108630)Mark Shannon2023-09-077-40/+58
|
* gh-108753: _Py_PrintSpecializationStats() uses Py_hexdigits (#109040)Victor Stinner2023-09-071-2/+2
|
* gh-107265: Remove all ENTER_EXECUTOR when execute _Py_Instrument (gh-108539)Dong-hee Na2023-09-071-32/+11
|
* GH-104584: Restore frame->stacktop on optimizer error (GH-108953)Brandt Bucher2023-09-061-0/+1
|
* gh-108753: Enhance pystats (#108754)Victor Stinner2023-09-066-55/+136
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Statistics gathering is now off by default. Use the "-X pystats" command line option or set the new PYTHONSTATS environment variable to 1 to turn statistics gathering on at Python startup. Statistics are no longer dumped at exit if statistics gathering was off or statistics have been cleared. Changes: * Add PYTHONSTATS environment variable. * sys._stats_dump() now returns False if statistics are not dumped because they are all equal to zero. * Add PyConfig._pystats member. * Add tests on sys functions and on setting PyConfig._pystats to 1. * Add Include/cpython/pystats.h and Include/internal/pycore_pystats.h header files. * Rename '_py_stats' variable to '_Py_stats'. * Exclude Include/cpython/pystats.h from the Py_LIMITED_API. * Move pystats.h include from object.h to Python.h. * Add _Py_StatsOn() and _Py_StatsOff() functions. Remove '_py_stats_struct' variable from the API: make it static in specialize.c. * Document API in Include/pystats.h and Include/cpython/pystats.h. * Complete pystats documentation in Doc/using/configure.rst. * Don't write "all zeros" stats: if _stats_off() and _stats_clear() or _stats_dump() were called. * _PyEval_Fini() now always call _Py_PrintSpecializationStats() which does nothing if stats are all zeros. Co-authored-by: Michael Droettboom <mdboom@gmail.com>
* gh-108765: Cleanup #include in Python/*.c files (#108977)Victor Stinner2023-09-0617-48/+55
| | | Mention one symbol imported by each #include.
* GH-108390: Prevent non-local events being set with ↵Mark Shannon2023-09-052-61/+101
| | | | `sys.monitoring.set_local_events()` (GH-108420)
* gh-106320: Remove private _PyErr_WriteUnraisableMsg() (#108863)Victor Stinner2023-09-042-0/+2
| | | | | | Move the private _PyErr_WriteUnraisableMsg() functions to the internal C API (pycore_pyerrors.h). Move write_unraisable_exc() from _testcapi to _testinternalcapi.
* GH-108614: Remove `TIER_ONE` and `TIER_TWO` from `_PUSH_FRAME` (GH-108725)Mark Shannon2023-09-044-37/+44
|
* gh-108765: Python.h no longer includes <ctype.h> (#108831)Victor Stinner2023-09-037-21/+13
| | | | | | | | | | | | | | | | | | | | | | | Remove <ctype.h> in C files which don't use it; only sre.c and _decimal.c still use it. Remove _PY_PORT_CTYPE_UTF8_ISSUE code from pyport.h: * Code added by commit b5047fd01948ab108edcc1b3c2c901d915814cfd in 2004 for MacOSX and FreeBSD. * Test removed by commit 52ddaefb6bab1a74ecffe8519c02735794ebfbe1 in 2007, since Python str type now uses locale independent functions like Py_ISALPHA() and Py_TOLOWER() and the Unicode database. Modules/_sre/sre.c replaces _PY_PORT_CTYPE_UTF8_ISSUE with new functions: sre_isalnum(), sre_tolower(), sre_toupper(). Remove unused includes: * _localemodule.c: remove <stdio.h>. * getargs.c: remove <float.h>. * dynload_win.c: remove <direct.h>, it no longer calls _getcwd() since commit fb1f68ed7cc1536482d1debd70a53c5442135fe2 (in 2001).
* gh-108765: pystrhex: Replace stdlib.h abs() with Py_ABS() (#108830)Victor Stinner2023-09-021-2/+1
|
* gh-108765: Python.h no longer includes <sys/time.h> (#108775)Victor Stinner2023-09-021-0/+5
| | | | | | | | | Python.h no longer includes <time.h>, <sys/select.h> and <sys/time.h> standard header files. * Add <time.h> include to xxsubtype.c. * Add <sys/time.h> include to posixmodule.c and semaphore.c. * readline.c includes <sys/select.h> instead of <sys/time.h>. * resource.c no longer includes <time.h> and <sys/time.h>.
* gh-108765: Python.h no longer includes <unistd.h> (#108783)Victor Stinner2023-09-022-5/+5
|
* gh-108767: Replace ctype.h functions with pyctype.h functions (#108772)Victor Stinner2023-09-011-4/+4
| | | | | | | | | | | | | | Replace <ctype.h> locale dependent functions with Python "pyctype.h" locale independent functions: * Replace isalpha() with Py_ISALPHA(). * Replace isdigit() with Py_ISDIGIT(). * Replace isxdigit() with Py_ISXDIGIT(). * Replace tolower() with Py_TOLOWER(). Leave Modules/_sre/sre.c unchanged, it uses locale dependent functions on purpose. Include explicitly <ctype.h> in _decimal.c to get isascii().
* gh-108634: PyInterpreterState_New() no longer calls Py_FatalError() (#108748)Victor Stinner2023-09-013-45/+87
| | | | | | | | | | | | pycore_create_interpreter() now returns a status, rather than calling Py_FatalError(). * PyInterpreterState_New() now calls Py_ExitStatusException() instead of calling Py_FatalError() directly. * Replace Py_FatalError() with PyStatus in init_interpreter() and _PyObject_InitState(). * _PyErr_SetFromPyStatus() now raises RuntimeError, instead of ValueError. It can now call PyErr_NoMemory(), raise MemoryError, if it detects _PyStatus_NO_MEMORY() error message.
* gh-108727: Fix segfault due to missing tp_dealloc definition for ↵Irit Katriel2023-09-011-0/+1
| | | | CounterOptimizer_Type (GH-108734)
* gh-107603: Argument Clinic: Only include pycore_gc.h if needed (#108726)Victor Stinner2023-08-319-46/+22
| | | | | | | | | | | | | | | | | | | | Argument Clinic now only includes pycore_gc.h if PyGC_Head is needed, and only includes pycore_runtime.h if _Py_ID() is needed. * Add 'condition' optional argument to Clinic.add_include(). * deprecate_keyword_use() includes pycore_runtime.h when using the _PyID() function. * Fix rendering of includes: comments start at the column 35. * Mark PC/clinic/_wmimodule.cpp.h and "Objects/stringlib/clinic/*.h.h" header files as generated in .gitattributes. Effects: * 42 header files generated by AC no longer include the internal C API, instead of 4 header files before. For example, Modules/clinic/_abc.c.h no longer includes the internal C API. * Fix _testclinic_depr.c.h: it now always includes pycore_runtime.h to get _Py_ID().
* gh-108634: Py_TRACE_REFS uses a hash table (#108663)Victor Stinner2023-08-314-15/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Python built with "configure --with-trace-refs" (tracing references) is now ABI compatible with Python release build and debug build. Moreover, it now also supports the Limited API. Change Py_TRACE_REFS build: * Remove _PyObject_EXTRA_INIT macro. * The PyObject structure no longer has two extra members (_ob_prev and _ob_next). * Use a hash table (_Py_hashtable_t) to trace references (all objects): PyInterpreterState.object_state.refchain. * Py_TRACE_REFS build is now ABI compatible with release build and debug build. * Limited C API extensions can now be built with Py_TRACE_REFS: xxlimited, xxlimited_35, _testclinic_limited. * No longer rename PyModule_Create2() and PyModule_FromDefAndSpec2() functions to PyModule_Create2TraceRefs() and PyModule_FromDefAndSpec2TraceRefs(). * _Py_PrintReferenceAddresses() is now called before finalize_interp_delete() which deletes the refchain hash table. * test_tracemalloc find_trace() now also filters by size to ignore the memory allocated by _PyRefchain_Trace(). Test changes for Py_TRACE_REFS: * Add test.support.Py_TRACE_REFS constant. * Add test_sys.test_getobjects() to test sys.getobjects() function. * test_exceptions skips test_recursion_normalizing_with_no_memory() and test_memory_error_in_PyErr_PrintEx() if Python is built with Py_TRACE_REFS. * test_repl skips test_no_memory(). * test_capi skisp test_set_nomemory().
* GH-108614: Remove non-debug uses of `#if TIER_ONE` and `#if TIER_TWO` from ↵Mark Shannon2023-08-316-64/+121
| | | | `_POP_FRAME` op. (GH-108685)
* gh-107149: Make PyUnstable_ExecutableKinds public (#108440)Victor Stinner2023-08-311-6/+6
| | | | | | Move PyUnstable_ExecutableKinds and associated macros from the internal C API to the public C API. Rename constants: replace "PY_" prefix with "PyUnstable_" prefix.
* gh-108654: restore comprehension locals before handling exception (#108659)Carl Meyer2023-08-301-14/+53
| | | Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
* gh-108488: Initialize JUMP_BACKWARD cache to 0, not 17 (#108591)Guido van Rossum2023-08-291-1/+3
| | | This mis-initialization caused the executor optimization to kick in sooner than intended. It also set the lower 4 bits of the counter to `1` -- those bits are supposed to be reserved (the actual counter is in the upper 12 bits).
* gh-107557: Remove unnecessary SAVE_IP instructions (#108583)Guido van Rossum2023-08-291-24/+116
| | | | | Also remove NOP instructions. The "stubs" are not optimized in this fashion (their SAVE_IP should always be preserved since it's where to jump next, and they don't contain NOPs by their nature).
* gh-106320: Remove private pythonrun API (#108599)Victor Stinner2023-08-292-0/+2
| | | | | | | | | | | Remove these private functions from the public C API: * _PyRun_AnyFileObject() * _PyRun_InteractiveLoopObject() * _PyRun_SimpleFileObject() * _Py_SourceAsString() Move them to the internal C API: add a new pycore_pythonrun.h header file. No longer export these functions.
* gh-107149: Rename _PyUnstable_GetUnaryIntrinsicName() function (#108441)Victor Stinner2023-08-281-2/+2
| | | | | | * Rename _PyUnstable_GetUnaryIntrinsicName() to PyUnstable_GetUnaryIntrinsicName() * Rename _PyUnstable_GetBinaryIntrinsicName() to PyUnstable_GetBinaryIntrinsicName().
* gh-108487: Move assert(self != NULL) down beyond DEOPT_IF() (#108510)Guido van Rossum2023-08-282-2/+2
|
* gh-107265: Fix initialize/remove_tools for ENTER_EXECUTOR case (gh-108482)Dong-hee Na2023-08-271-4/+32
|
* gh-107913: Fix possible losses of OSError error codes (GH-107930)Serhiy Storchaka2023-08-261-1/+3
| | | | | | Functions like PyErr_SetFromErrno() and SetFromWindowsErr() should be called immediately after using the C API which sets errno or the Windows error code.
* gh-106320: Remove private AC converter functions (#108505)Victor Stinner2023-08-262-1/+3
| | | | | | | | | | | | | | Move these private functions to the internal C API (pycore_abstract.h): * _Py_convert_optional_to_ssize_t() * _PyNumber_Index() Argument Clinic now emits #include "pycore_abstract.h" when these functions are used. The parser of the c-analyzer tool now uses a list of files which use the limited C API, rather than a list of files using the internal C API.
* GH-106581: Fix instrumentation in tier 2 (GH-108493)Brandt Bucher2023-08-253-12/+18
|
* gh-107265: Revert "Ensure _PyCode_Quicken does not handle ENTER_EXECUTOR" ↵Dong-hee Na2023-08-251-2/+0
| | | | | | | (#108485) This reverts commit d6ac5c7b105fe57266bd71248e3ada41fedb5ba9. Reason: the assert we just added could be triggered (see issue).
* gh-108444: Remove _PyLong_AsInt() function (#108461)Victor Stinner2023-08-251-1/+1
| | | | * Update Parser/asdl_c.py to regenerate Python/Python-ast.c. * Remove _PyLong_AsInt() alias to PyLong_AsInt().
* gh-106581: Split CALL_BOUND_METHOD_EXACT_ARGS into uops (#108462)Guido van Rossum2023-08-254-20/+143
| | | Instead of using `GO_TO_INSTRUCTION(CALL_PY_EXACT_ARGS)` we just add the macro elements of the latter to the macro for the former. This requires lengthening the uops array in struct opcode_macro_expansion. (It also required changes to stacking.py that were merged already.)
* gh-106320: Remove private _PyTraceback functions (#108453)Victor Stinner2023-08-241-3/+2
| | | | | | Move private functions to the internal C API (pycore_traceback.h): * _Py_DisplaySourceLine() * _PyTraceback_Add()
* gh-107265: Ensure _PyCode_Quicken does not handle ENTER_EXECUTOR (gh-108460)Dong-hee Na2023-08-241-0/+2
|
* gh-108444: Replace _PyLong_AsInt() with PyLong_AsInt() (#108459)Victor Stinner2023-08-245-10/+10
| | | | | | Change generated by the command: sed -i -e 's!_PyLong_AsInt!PyLong_AsInt!g' \ $(find -name "*.c" -o -name "*.h")
* gh-108444: Argument Clinic uses PyLong_AsInt() (#108458)Victor Stinner2023-08-247-37/+37
| | | | Argument Clinic now uses the new public PyLong_AsInt(), rather than the old name _PyLong_AsInt().