aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-01-16 18:31:40 +0000
committergingerBill <bill@gingerbill.org>2023-01-16 18:31:40 +0000
commitedb23db2ae519627e0d67d482764b01488e78b4e (patch)
treea2f78ad992d09da571bd42586340bd1039b14904 /src/parser.cpp
parent0b01cfd85300e1c37579dcd5c7787bdf57757a36 (diff)
Fix potential race condition when determining the package name
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index b364d01cf..0d9fad8c7 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -4949,7 +4949,7 @@ gb_internal void parser_add_foreign_file_to_process(Parser *p, AstPackage *pkg,
// NOTE(bill): Returns true if it's added
-gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, String const &rel_path, TokenPos pos, PackageKind kind = Package_Normal) {
+gb_internal AstPackage *try_add_import_path(Parser *p, String path, String const &rel_path, TokenPos pos, PackageKind kind = Package_Normal) {
String const FILE_EXT = str_lit(".odin");
MUTEX_GUARD_BLOCK(&p->imported_files_mutex) {
@@ -4958,6 +4958,8 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, Strin
}
}
+ path = copy_string(permanent_allocator(), path);
+
AstPackage *pkg = gb_alloc_item(permanent_allocator(), AstPackage);
pkg->kind = kind;
pkg->fullpath = path;
@@ -5715,6 +5717,7 @@ gb_internal ParseFileError process_imported_file(Parser *p, ImportedFile importe
array_add(&pkg->files, file);
}
+ mutex_lock(&pkg->name_mutex);
if (pkg->name.len == 0) {
pkg->name = file->package_name;
} else if (pkg->name != file->package_name) {
@@ -5726,6 +5729,7 @@ gb_internal ParseFileError process_imported_file(Parser *p, ImportedFile importe
syntax_error(tok, "Different package name, expected '%.*s', got '%.*s'", LIT(pkg->name), LIT(file->package_name));
}
}
+ mutex_unlock(&pkg->name_mutex);
p->total_line_count.fetch_add(file->tokenizer.line_count);
p->total_token_count.fetch_add(file->tokens.count);