summaryrefslogtreecommitdiffstats
path: root/Modules/_asynciomodule.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-126405: fix use-after-free in `_asyncio.Future.remove_done_callback` ↵Kumar Aditya2024-11-121-0/+2
| | | | (#126733)
* remove minor redundant code from `_asyncio` (#126578)Kumar Aditya2024-11-081-3/+1
|
* GH-107803: use circular double linked list for tasks in `_asyncio` (#126577)Kumar Aditya2024-11-081-52/+21
|
* gh-126138: Fix use-after-free in `_asyncio.Task` by evil `__getattribute__` ↵Nico-Posada2024-11-021-2/+20
| | | | | (#126305) Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
* gh-126080: fix UAF on `task->task_context` in `task_call_step_soon` due to ↵Bénédikt Tran2024-10-311-1/+5
| | | | an evil `loop.__getattribute__` (#126120)
* gh-126083: Fix a reference leak in `asyncio.Task` when reinitializing with ↵Nico-Posada2024-10-311-1/+1
| | | | new non-`None` context (#126103)
* gh-125966: fix use-after-free on `fut->fut_callback0` due to an evil ↵Bénédikt Tran2024-10-271-1/+6
| | | | callback's `__eq__` in asyncio (#125967)
* gh-125984: fix use-after-free on `fut->fut_{callback,context}0` due to an ↵Bénédikt Tran2024-10-271-6/+13
| | | | evil `loop.__getattribute__` (#126003)
* gh-125969: fix OOB in `future_schedule_callbacks` due to an evil `call_soon` ↵Bénédikt Tran2024-10-251-17/+12
| | | | | (#125970) Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
* GH-125789: fix `fut._callbacks` to always return a copy of callbacks (#125922)Kumar Aditya2024-10-251-28/+25
| | | Fix `asyncio.Future._callbacks` to always return a copy of the internal list of callbacks to avoid mutation from user code affecting the internal state.
* GH-125174: Make immortal objects more robust, following design from PEP 683 ↵Mark Shannon2024-10-101-1/+1
| | | | (GH-125251)
* gh-123091: Use more _Py_IsImmortalLoose() (GH-123602)Petr Viktorin2024-09-021-1/+1
| | | | | | | Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...) The remaining calls to _Py_IsImmortal are in free-threaded-only code, initialization of core objects, tests, and guards that fall back to code that works with mortal objects.
* GH-120974: make `_asyncio.all_tasks` thread safe (#122801)Kumar Aditya2024-08-111-7/+15
| | | Make `_asyncio.all_tasks` thread safe, also changes state lock to use critical section.
* gh-120974: Make asyncio `swap_current_task` safe in free-threaded build ↵Sam Gross2024-08-021-14/+23
| | | | | (#122317) * gh-120974: Make asyncio `swap_current_task` safe in free-threaded build
* gh-122332: Fix missing `NULL` check in `asyncio.Task.get_coro` (#122338)Peter Bierma2024-07-271-1/+5
|
* gh-120974: Make _asyncio._leave_task atomic in the free-threaded build (#122139)Sam Gross2024-07-231-18/+24
| | | | | | | * gh-120974: Make _asyncio._leave_task atomic in the free-threaded build Update `_PyDict_DelItemIf` to allow for an argument to be passed to the predicate.
* gh-120974: Use common freelist code in asyncio (#122132)Sam Gross2024-07-231-69/+4
| | | | | This refactors asyncio to use the common freelist helper functions and macros. As a side effect, the freelist for _asyncio.Future is now re-enabled in the free-threaded build.
* gh-120974: Make _asyncio._enter_task atomic in the free-threaded build (#122138)Sam Gross2024-07-231-10/+5
| | | | Use `PyDict_SetDefaultRef` to set the current task in a single operation under the dictionary's lock.
* gh-121621: Disable asyncio freelist in free-threaded build (#122046)Sam Gross2024-07-191-5/+17
| | | | The futureobj freelist isn't thread-safe. We intend to re-enable the freelist in a thread-safe way for 3.14 (but not 3.13).
* gh-121621: Move asyncio_running_loop to private struct (#121939)Sam Gross2024-07-171-4/+4
| | | | This avoids changing the ABI and keeps the field in the private struct.
* gh-121621: Move asyncio running loop to thread state (GH-121695)Ken Jin2024-07-161-104/+12
|
* fix outdated comments in asyncio (#121783)Kumar Aditya2024-07-151-1/+1
|
* gh-121621: Use PyMutex for writes to asyncio state (#121622)Ken Jin2024-07-141-1/+29
| | | Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* Update retroactive comments from GH-117741 (segfault in ↵Savannah Ostrowski2024-07-121-3/+0
| | | | | `FutureIter_dealloc`) (GH-121638) Address comments
* gh-107803: fix thread safety issue in double linked list implementation ↵Kumar Aditya2024-06-261-2/+7
| | | | (#121007)
* GH-107803: double linked list implementation for asyncio tasks (GH-107804)Kumar Aditya2024-06-221-83/+281
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * linked list * add tail optmiization to linked list * wip * wip * wip * more fixes * finally it works * add tests * remove weakreflist * add some comments * reduce code duplication in _asynciomodule.c * address some review comments * add invariants about the state of the linked list * add better explanation * clinic regen * reorder branches for better branch prediction * Update Modules/_asynciomodule.c * Apply suggestions from code review Co-authored-by: Itamar Oren <itamarost@gmail.com> * fix capturing of eager tasks * add comment to task finalization * fix tests and couple c implmentation to c task improved linked-list logic and more comments * fix test --------- Co-authored-by: Itamar Oren <itamarost@gmail.com>
* gh-116322: Add Py_mod_gil module slot (#116882)Brett Simmers2024-05-031-0/+1
| | | | | | | | | | | | | | This PR adds the ability to enable the GIL if it was disabled at interpreter startup, and modifies the multi-phase module initialization path to enable the GIL when loading a module, unless that module's spec includes a slot indicating it can run safely without the GIL. PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148. A warning will be issued up to once per interpreter for the first GIL-using module that is loaded. If `-v` is given, a shorter message will be printed to stderr every time a GIL-using module is loaded (including the first one that issues a warning).
* GH-115874: Fix segfault in FutureIter_dealloc (GH-117741)Savannah Ostrowski2024-04-191-2/+16
|
* gh-116720: Fix corner cases of taskgroups (#117407)Guido van Rossum2024-04-091-0/+3
| | | | | | | | | | This prevents external cancellations of a task group's parent task to be dropped when an internal cancellation happens at the same time. Also strengthen the semantics of uncancel() to clear self._must_cancel when the cancellation count reaches zero. Co-Authored-By: Tin Tvrtković <tinchester@gmail.com> Co-Authored-By: Arthur Tacca
* gh-116437: Use new C API PyDict_Pop() to simplify the code (GH-116438)Serhiy Storchaka2024-03-071-14/+14
|
* gh-112182: Replace StopIteration with RuntimeError for future (#113220)Jamie Phan2024-01-101-5/+20
| | | | | | When an `StopIteration` raises into `asyncio.Future`, this will cause a thread to hang. This commit address this by not raising an exception and silently transforming the `StopIteration` with a `RuntimeError`, which the caller can reconstruct from `fut.exception().__cause__`
* gh-113848: Use PyErr_GivenExceptionMatches() for check for CancelledError ↵Serhiy Storchaka2024-01-091-15/+1
| | | | (GH-113849)
* gh-111789: Use PyDict_GetItemRef() in Modules/_asynciomodule.c (GH-112072)Serhiy Storchaka2023-11-151-6/+2
|
* gh-110964: Remove private _PyArg functions (#110966)Victor Stinner2023-10-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Move the following private functions and structures to pycore_modsupport.h internal C API: * _PyArg_BadArgument() * _PyArg_CheckPositional() * _PyArg_NoKeywords() * _PyArg_NoPositional() * _PyArg_ParseStack() * _PyArg_ParseStackAndKeywords() * _PyArg_Parser structure * _PyArg_UnpackKeywords() * _PyArg_UnpackKeywordsWithVararg() * _PyArg_UnpackStack() * _Py_ANY_VARARGS() Changes: * Python/getargs.h now includes pycore_modsupport.h to export functions. * clinic.py now adds pycore_modsupport.h when one of these functions is used. * Add pycore_modsupport.h includes when a C extension uses one of these functions. * Define Py_BUILD_CORE_MODULE in C extensions which now include directly or indirectly (via code generated by Argument Clinic) pycore_modsupport.h: * _csv * _curses_panel * _dbm * _gdbm * _multiprocessing.posixshmem * _sqlite.row * _statistics * grp * resource * syslog * _testcapi: bad_get() no longer uses METH_FASTCALL calling convention but METH_VARARGS. Replace _PyArg_UnpackStack() with PyArg_ParseTuple(). * _testcapi: add PYTESTCAPI_NEED_INTERNAL_API macro which is defined by _testcapi sub-modules which need the internal C API (pycore_modsupport.h): exceptions.c, float.c, vectorcall.c, watchers.c. * Remove Include/cpython/modsupport.h header file. Include/modsupport.h no longer includes the removed header file. * Fix mypy clinic.py
* gh-107073: Make PyObject_VisitManagedDict() public (#108763)Victor Stinner2023-10-021-3/+3
| | | | | | | | Make PyObject_VisitManagedDict() and PyObject_ClearManagedDict() functions public in Python 3.13 C API. * Rename _PyObject_VisitManagedDict() to PyObject_VisitManagedDict(). * Rename _PyObject_ClearManagedDict() to PyObject_ClearManagedDict(). * Document these functions.
* gh-106320: Remove private _PyDict functions (#108449)Victor Stinner2023-08-241-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Move private functions to the internal C API (pycore_dict.h): * _PyDictView_Intersect() * _PyDictView_New() * _PyDict_ContainsId() * _PyDict_DelItemId() * _PyDict_DelItem_KnownHash() * _PyDict_GetItemIdWithError() * _PyDict_GetItem_KnownHash() * _PyDict_HasSplitTable() * _PyDict_NewPresized() * _PyDict_Next() * _PyDict_Pop() * _PyDict_SetItemId() * _PyDict_SetItem_KnownHash() * _PyDict_SizeOf() No longer export most of these functions. Move also the _PyDictViewObject structure to the internal C API. Move dict_getitem_knownhash() function from _testcapi to the _testinternalcapi extension. Update test_capi.test_dict for this change.
* gh-108014: Add Py_IsFinalizing() function (#108032)Victor Stinner2023-08-181-1/+1
| | | Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* GH-84436: Skip refcounting for known immortals (GH-107605)Brandt Bucher2023-08-041-1/+2
|
* gh-106869: Use new PyMemberDef constant names (#106871)Victor Stinner2023-07-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Remove '#include "structmember.h"'. * If needed, add <stddef.h> to get offsetof() function. * Update Parser/asdl_c.py to regenerate Python/Python-ast.c. * Replace: * T_SHORT => Py_T_SHORT * T_INT => Py_T_INT * T_LONG => Py_T_LONG * T_FLOAT => Py_T_FLOAT * T_DOUBLE => Py_T_DOUBLE * T_STRING => Py_T_STRING * T_OBJECT => _Py_T_OBJECT * T_CHAR => Py_T_CHAR * T_BYTE => Py_T_BYTE * T_UBYTE => Py_T_UBYTE * T_USHORT => Py_T_USHORT * T_UINT => Py_T_UINT * T_ULONG => Py_T_ULONG * T_STRING_INPLACE => Py_T_STRING_INPLACE * T_BOOL => Py_T_BOOL * T_OBJECT_EX => Py_T_OBJECT_EX * T_LONGLONG => Py_T_LONGLONG * T_ULONGLONG => Py_T_ULONGLONG * T_PYSSIZET => Py_T_PYSSIZET * T_NONE => _Py_T_NONE * READONLY => Py_READONLY * PY_AUDIT_READ => Py_AUDIT_READ * READ_RESTRICTED => Py_AUDIT_READ * PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED * RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
* gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)Serhiy Storchaka2023-07-121-2/+2
|
* GH-104787: use managed weakrefs in `_asyncio` (#106516)Kumar Aditya2023-07-101-21/+6
|
* gh-106320: Remove private pylifecycle.h functions (#106400)Victor Stinner2023-07-041-1/+2
| | | | | | | Remove private pylifecycle.h functions: move them to the internal C API ( pycore_atexit.h, pycore_pylifecycle.h and pycore_signal.h). No longer export most of these functions. Move _testcapi.test_atexit() to _testinternalcapi.
* gh-106320: Use _PyInterpreterState_GET() (#106336)Victor Stinner2023-07-021-1/+1
| | | | Replace PyInterpreterState_Get() with inlined _PyInterpreterState_GET().
* gh-105987: Fix reference counting issue in `_asyncio._swap_current_task` ↵chgnrdv2023-06-241-4/+7
| | | | (#105989)
* GH-104787: use bitfields in `_asyncio` (#104788)Kumar Aditya2023-06-131-7/+10
|
* GH-104787: use managed dict in `_asyncio` (#104795)Kumar Aditya2023-05-261-9/+5
|
* gh-104341: Adjust tstate_must_exit() to Respect Interpreter Finalization ↵Eric Snow2023-05-151-1/+1
| | | | | (gh-104437) With the move to a per-interpreter GIL, this check slipped through the cracks.
* gh-97696: Use `PyObject_CallMethodNoArgs` and inline is_loop_running check ↵Itamar Ostricher2023-05-071-18/+5
| | | | in `_asyncio` (#104255)
* gh-97696: Remove redundant #include (#104216)Jacob Bower2023-05-051-1/+0
| | | | | Remove "#include cpython/context.h"` from `_asynciomodule.c`. It's already included in `Python.h`.
* gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205)Eric Snow2023-05-051-0/+1
| | | Here we are doing no more than adding the value for Py_mod_multiple_interpreters and using it for stdlib modules. We will start checking for it in gh-104206 (once PyInterpreterState.ceval.own_gil is added in gh-104204).