python / cpython

The Python programming language
https://www.python.org
Other
62.52k stars 30.01k forks source link

Advanced Debugger Support C-API is useless without HEAD_LOCK()/HEAD_UNLOCK() #85234

Open ba9228e2-9454-44a8-98af-f771e548a6cc opened 4 years ago

ba9228e2-9454-44a8-98af-f771e548a6cc commented 4 years ago
BPO 41062
Nosy @vstinner, @AndreiPashkin

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['expert-C-API', 'type-feature', '3.11'] title = 'Advanced Debugger Support C-API is useless without HEAD_LOCK()/HEAD_UNLOCK()' updated_at = user = 'https://github.com/AndreiPashkin' ``` bugs.python.org fields: ```python activity = actor = 'iritkatriel' assignee = 'none' closed = False closed_date = None closer = None components = ['C API'] creation = creator = 'pashkin' dependencies = [] files = [] hgrepos = [] issue_num = 41062 keywords = [] message_count = 2.0 messages = ['371988', '371989'] nosy_count = 2.0 nosy_names = ['vstinner', 'pashkin'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue41062' versions = ['Python 3.11'] ```

ba9228e2-9454-44a8-98af-f771e548a6cc commented 4 years ago

To me it seems like Advanced Debugger Support C-API doesn't make sense without HEAD_LOCK() and HEAD_UNLOCK() which are private right now.

When researching how C-API works I've found this comment in the source code: https://github.com/python/cpython/blob/e838a9324c1719bb917ca81ede8d766b5cb551f4/Python/pystate.c#L1176

It says that the lists of interpreter-state and thread-state objects (that Adv. Debugger Support API operates on) could be mutated even when GIL is held so there is need to acquire head mutex when accessing them. But there is no way to acquire head mutex using public C-API.

Am I right? If yes - it seems like HEAD_(UN)LOCK() should be made public.

ba9228e2-9454-44a8-98af-f771e548a6cc commented 4 years ago

Here is what I mean by "Advanced Debugger Support" API: https://docs.python.org/dev/c-api/init.html#advanced-debugger-support