mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Fix potential race condition when determining the package name
This commit is contained in:
+5
-1
@@ -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
|
// 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");
|
String const FILE_EXT = str_lit(".odin");
|
||||||
|
|
||||||
MUTEX_GUARD_BLOCK(&p->imported_files_mutex) {
|
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);
|
AstPackage *pkg = gb_alloc_item(permanent_allocator(), AstPackage);
|
||||||
pkg->kind = kind;
|
pkg->kind = kind;
|
||||||
pkg->fullpath = path;
|
pkg->fullpath = path;
|
||||||
@@ -5715,6 +5717,7 @@ gb_internal ParseFileError process_imported_file(Parser *p, ImportedFile importe
|
|||||||
array_add(&pkg->files, file);
|
array_add(&pkg->files, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutex_lock(&pkg->name_mutex);
|
||||||
if (pkg->name.len == 0) {
|
if (pkg->name.len == 0) {
|
||||||
pkg->name = file->package_name;
|
pkg->name = file->package_name;
|
||||||
} else if (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));
|
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_line_count.fetch_add(file->tokenizer.line_count);
|
||||||
p->total_token_count.fetch_add(file->tokens.count);
|
p->total_token_count.fetch_add(file->tokens.count);
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ struct AstPackage {
|
|||||||
BlockingMutex files_mutex;
|
BlockingMutex files_mutex;
|
||||||
BlockingMutex foreign_files_mutex;
|
BlockingMutex foreign_files_mutex;
|
||||||
BlockingMutex type_and_value_mutex;
|
BlockingMutex type_and_value_mutex;
|
||||||
|
BlockingMutex name_mutex;
|
||||||
|
|
||||||
// NOTE(bill): This must be a MPMCQueue
|
// NOTE(bill): This must be a MPMCQueue
|
||||||
MPMCQueue<AstPackageExportedEntity> exported_entity_queue;
|
MPMCQueue<AstPackageExportedEntity> exported_entity_queue;
|
||||||
|
|||||||
Reference in New Issue
Block a user