cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-120317: Lock around global state in the tokenize module

Open lysnikolaou opened this issue 1 year ago • 8 comments

  • Issue: gh-120317

lysnikolaou avatar Jun 10 '24 13:06 lysnikolaou

This LGTM. Can you add the reproducer to test.test_free_threading please? I'll approve after!

Fidget-Spinner avatar Jun 10 '24 14:06 Fidget-Spinner

@Fidget-Spinner I added more locking around global state. Reviewing each commit seprately might make it easier.

lysnikolaou avatar Jun 10 '24 15:06 lysnikolaou

Feedback addressed.

@Fidget-Spinner I used _Py_atomic_store_int instead of the macro. Is that okay?

lysnikolaou avatar Jun 10 '24 16:06 lysnikolaou

All feedback addressed. Thanks a lot for the reviews and the help @Fidget-Spinner and @erlend-aasland!

lysnikolaou avatar Jun 10 '24 16:06 lysnikolaou

Actually, one question here: shouldn't we be protecting all reads of the it structure that are not under critical sections? Otherwise we are getting some partial reads no? I am missing something?

pablogsal avatar Jun 11 '24 17:06 pablogsal

For example, this read is not protected, no?:

    Py_ssize_t lineno = ISSTRINGLIT(type) ? it->tok->first_lineno : it->tok->lineno;
     Py_ssize_t end_lineno = it->tok->lineno;

pablogsal avatar Jun 11 '24 17:06 pablogsal

After some offline discussion with @pablogsal, we decided it makes more sense to just lock around all of tokenizeriter_next.

lysnikolaou avatar Jun 11 '24 20:06 lysnikolaou

@pablogsal Can you do a final review here when you have some spare cycles?

lysnikolaou avatar Jul 01 '24 12:07 lysnikolaou

Thanks @lysnikolaou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. 🐍🍒⛏🤖

miss-islington-app[bot] avatar Jul 16 '24 09:07 miss-islington-app[bot]

GH-121841 is a backport of this pull request to the 3.13 branch.

bedevere-app[bot] avatar Jul 16 '24 09:07 bedevere-app[bot]