There was an error while loading. Please reload this page.
1 parent c3b6dbf commit 900dd6aCopy full SHA for 900dd6a
1 file changed
Python/Python-tokenize.c
@@ -1,5 +1,6 @@
1
#include "Python.h"
2
#include "errcode.h"
3
+#include "internal/pycore_lock.h" // PyMutex
4
#include "../Parser/lexer/state.h"
5
#include "../Parser/lexer/lexer.h"
6
#include "../Parser/tokenizer/tokenizer.h"
@@ -37,6 +38,10 @@ typedef struct
37
38
PyObject *last_line;
39
Py_ssize_t last_lineno;
40
Py_ssize_t byte_col_offset_diff;
41
+
42
+#ifdef Py_GIL_DISABLED
43
+ PyMutex mutex;
44
+#endif
45
} tokenizeriterobject;
46
47
/*[clinic input]
@@ -74,6 +79,10 @@ tokenizeriter_new_impl(PyTypeObject *type, PyObject *readline,
74
79
}
75
80
self->done = 0;
76
81
82
83
+ self->mutex = (PyMutex) {_Py_UNLOCKED};
84
85
77
86
self->last_line = NULL;
78
87
self->byte_col_offset_diff = 0;
88
self->last_lineno = 0;
@@ -182,7 +191,14 @@ tokenizeriter_next(tokenizeriterobject *it)
182
191
struct token token;
183
192
_PyToken_Init(&token);
184
193
194
195
+ PyMutex_Lock(&it->mutex);
196
185
197
int type = _PyTokenizer_Get(it->tok, &token);
198
199
+ PyMutex_Unlock(&it->mutex);
200
201
186
202
if (type == ERRORTOKEN) {
187
203
if(!PyErr_Occurred()) {
188
204
_tokenizer_error(it->tok);
0 commit comments