Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Python/Python-tokenize.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Python.h"
#include "errcode.h"
#include "internal/pycore_lock.h" // PyMutex
#include "../Parser/lexer/state.h"
#include "../Parser/lexer/lexer.h"
#include "../Parser/tokenizer/tokenizer.h"
Expand Down Expand Up @@ -37,6 +38,10 @@ typedef struct
PyObject *last_line;
Py_ssize_t last_lineno;
Py_ssize_t byte_col_offset_diff;

#ifdef Py_GIL_DISABLED
PyMutex mutex;
#endif
} tokenizeriterobject;

/*[clinic input]
Expand Down Expand Up @@ -74,6 +79,10 @@ tokenizeriter_new_impl(PyTypeObject *type, PyObject *readline,
}
self->done = 0;

#ifdef Py_GIL_DISABLED
self->mutex = (PyMutex) {_Py_UNLOCKED};
#endif

self->last_line = NULL;
self->byte_col_offset_diff = 0;
self->last_lineno = 0;
Expand Down Expand Up @@ -182,7 +191,14 @@ tokenizeriter_next(tokenizeriterobject *it)
struct token token;
_PyToken_Init(&token);

#ifdef Py_GIL_DISABLED
PyMutex_Lock(&it->mutex);
#endif
int type = _PyTokenizer_Get(it->tok, &token);
#ifdef Py_GIL_DISABLED
PyMutex_Unlock(&it->mutex);
#endif

if (type == ERRORTOKEN) {
if(!PyErr_Occurred()) {
_tokenizer_error(it->tok);
Expand Down