diff options
author | Yingchi Long <i@lyc.dev> | 2023-07-03 16:02:54 +0800 |
---|---|---|
committer | Yingchi Long <i@lyc.dev> | 2023-07-03 16:05:43 +0800 |
commit | 3c90340fe64fb18e66f02a648ebce8ad629482a5 (patch) | |
tree | f843f180f20cdb60651c5a6dad1f3c26c77080af | |
parent | 7b39a388b382e7912de3c5951faad42fe2d72f48 (diff) |
libexpr: use `thread_local` to make the parser thread-safe
If we call `adjustLoc`, the global variable `prev_yylloc` is shared
between threads and racy.
Currently, nix itself does not concurrently parsing files, but this is
helpful for libexpr users. (The parser is thread-safe except this.)
-rw-r--r-- | src/libexpr/lexer.l | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index 462b3b602..a3a8608d9 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -36,7 +36,7 @@ static inline PosIdx makeCurPos(const YYLTYPE & loc, ParseData * data) #define CUR_POS makeCurPos(*yylloc, data) // backup to recover from yyless(0) -YYLTYPE prev_yylloc; +thread_local YYLTYPE prev_yylloc; static void initLoc(YYLTYPE * loc) { |