From 60ef4fda4dd71e5474bb2598c4e0d18c58924e99 Mon Sep 17 00:00:00 2001 From: joakin Date: Wed, 3 Apr 2024 14:03:56 +0200 Subject: [PATCH 1/7] Recognize dynamic library names like libraylib.so.5.0.0 --- src/linker.cpp | 2 +- src/parser.cpp | 2 +- src/string.cpp | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/linker.cpp b/src/linker.cpp index 498a96c5f..245275bd3 100644 --- a/src/linker.cpp +++ b/src/linker.cpp @@ -432,7 +432,7 @@ gb_internal i32 linker_stage(LinkerData *gen) { if (string_ends_with(lib, str_lit(".a")) || string_ends_with(lib, str_lit(".o"))) { // static libs and object files, absolute full path relative to the file in which the lib was imported from lib_str = gb_string_append_fmt(lib_str, " -l:\"%.*s\" ", LIT(lib)); - } else if (string_ends_with(lib, str_lit(".so"))) { + } else if (string_ends_with(lib, str_lit(".so")) || string_contains_string(lib, str_lit(".so."))) { // dynamic lib, relative path to executable // NOTE(vassvik): it is the user's responsibility to make sure the shared library files are visible // at runtime to the executable diff --git a/src/parser.cpp b/src/parser.cpp index f4d3dc48d..2bf25c768 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -5710,7 +5710,7 @@ gb_internal bool determine_path_from_string(BlockingMutex *file_mutex, Ast *node // working directory of the exe to the library search paths. // Static libraries can be linked directly with the full pathname // - if (node->kind == Ast_ForeignImportDecl && string_ends_with(file_str, str_lit(".so"))) { + if (node->kind == Ast_ForeignImportDecl && (string_ends_with(file_str, str_lit(".so")) || string_contains_string(file_str, str_lit(".so.")))) { *path = file_str; return true; } diff --git a/src/string.cpp b/src/string.cpp index 3747f4564..a68cf315f 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -323,6 +323,25 @@ gb_internal bool string_contains_char(String const &s, u8 c) { return false; } +gb_internal bool string_contains_string(String const &haystack, String const &needle) { + if (needle.len == 0) return true; + if (needle.len > haystack.len) return false; + + for (isize i = 0; i <= haystack.len - needle.len; i++) { + bool found = true; + for (isize j = 0; j < needle.len; j++) { + if (haystack[i + j] != needle[j]) { + found = false; + break; + } + } + if (found) { + return true; + } + } + return false; +} + gb_internal String filename_from_path(String s) { isize i = string_extension_position(s); if (i >= 0) { From 67b786c7388db140e80653f2d6c4027e272257b2 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Wed, 1 May 2024 16:41:02 -0400 Subject: [PATCH 2/7] Fix more race conditions in error reporting --- src/error.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/error.cpp b/src/error.cpp index 1b091f88e..1ad757964 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -452,11 +452,11 @@ gb_internal void error_line_va(char const *fmt, va_list va) { gb_internal void error_no_newline_va(TokenPos const &pos, char const *fmt, va_list va) { global_error_collector.count.fetch_add(1); + mutex_lock(&global_error_collector.mutex); if (global_error_collector.count.load() > MAX_ERROR_COLLECTOR_COUNT()) { print_all_errors(); gb_exit(1); } - mutex_lock(&global_error_collector.mutex); push_error_value(pos, ErrorValue_Error); @@ -485,11 +485,11 @@ gb_internal void error_no_newline_va(TokenPos const &pos, char const *fmt, va_li gb_internal void syntax_error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { global_error_collector.count.fetch_add(1); + mutex_lock(&global_error_collector.mutex); if (global_error_collector.count > MAX_ERROR_COLLECTOR_COUNT()) { print_all_errors(); gb_exit(1); } - mutex_lock(&global_error_collector.mutex); push_error_value(pos, ErrorValue_Warning); @@ -518,11 +518,11 @@ gb_internal void syntax_error_va(TokenPos const &pos, TokenPos end, char const * gb_internal void syntax_error_with_verbose_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { global_error_collector.count.fetch_add(1); + mutex_lock(&global_error_collector.mutex); if (global_error_collector.count > MAX_ERROR_COLLECTOR_COUNT()) { print_all_errors(); gb_exit(1); } - mutex_lock(&global_error_collector.mutex); push_error_value(pos, ErrorValue_Warning); From 8506e643451edd0a474e7e368afb7db6c71f8ea8 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Thu, 2 May 2024 20:49:29 +0200 Subject: [PATCH 3/7] sync: fix deadlock in one shot event --- core/sync/extended.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/sync/extended.odin b/core/sync/extended.odin index 76b7686fe..781ed816e 100644 --- a/core/sync/extended.odin +++ b/core/sync/extended.odin @@ -433,7 +433,7 @@ One_Shot_Event :: struct #no_copy { // Blocks the current thread until the event is made available with `one_shot_event_signal`. one_shot_event_wait :: proc "contextless" (e: ^One_Shot_Event) { for atomic_load_explicit(&e.state, .Acquire) == 0 { - futex_wait(&e.state, 1) + futex_wait(&e.state, 0) } } From 8aab395c7028136137385b9ac38512773580a454 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Thu, 2 May 2024 20:49:54 +0200 Subject: [PATCH 4/7] darwin: fix minimum os version check not being inclusive --- core/sys/darwin/sync.odin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/sys/darwin/sync.odin b/core/sys/darwin/sync.odin index c76b30d6b..361b4b8b4 100644 --- a/core/sys/darwin/sync.odin +++ b/core/sys/darwin/sync.odin @@ -5,9 +5,9 @@ foreign import system "system:System.framework" // #define OS_WAIT_ON_ADDR_AVAILABILITY \ // __API_AVAILABLE(macos(14.4), ios(17.4), tvos(17.4), watchos(10.4)) when ODIN_OS == .Darwin { - when ODIN_PLATFORM_SUBTARGET == .iOS && ODIN_MINIMUM_OS_VERSION > 17_04_00 { + when ODIN_PLATFORM_SUBTARGET == .iOS && ODIN_MINIMUM_OS_VERSION >= 17_04_00 { WAIT_ON_ADDRESS_AVAILABLE :: true - } else when ODIN_MINIMUM_OS_VERSION > 14_04_00 { + } else when ODIN_MINIMUM_OS_VERSION >= 14_04_00 { WAIT_ON_ADDRESS_AVAILABLE :: true } else { WAIT_ON_ADDRESS_AVAILABLE :: false From 242307dd4466389e971b6273c1267708777b50dd Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 3 May 2024 12:34:12 +0100 Subject: [PATCH 5/7] Revert to old `StringMap` internal layout --- src/string_map.cpp | 292 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 292 insertions(+) diff --git a/src/string_map.cpp b/src/string_map.cpp index 4de88bbf9..802bf5853 100644 --- a/src/string_map.cpp +++ b/src/string_map.cpp @@ -24,6 +24,296 @@ gb_internal gb_inline StringHashKey string_hash_string(String const &s) { return hash_key; } + +#if 1 /* old string map */ + +template +struct StringMapEntry { + String key; + u32 hash; + MapIndex next; + T value; +}; + +template +struct StringMap { + MapIndex * hashes; + usize hashes_count; + StringMapEntry *entries; + u32 count; + u32 entries_capacity; +}; + + +template gb_internal void string_map_init (StringMap *h, usize capacity = 16); +template gb_internal void string_map_destroy (StringMap *h); + +template gb_internal T * string_map_get (StringMap *h, char const *key); +template gb_internal T * string_map_get (StringMap *h, String const &key); +template gb_internal T * string_map_get (StringMap *h, StringHashKey const &key); + +template gb_internal T & string_map_must_get(StringMap *h, char const *key); +template gb_internal T & string_map_must_get(StringMap *h, String const &key); +template gb_internal T & string_map_must_get(StringMap *h, StringHashKey const &key); + +template gb_internal void string_map_set (StringMap *h, char const *key, T const &value); +template gb_internal void string_map_set (StringMap *h, String const &key, T const &value); +template gb_internal void string_map_set (StringMap *h, StringHashKey const &key, T const &value); + +// template gb_internal void string_map_remove (StringMap *h, StringHashKey const &key); +template gb_internal void string_map_clear (StringMap *h); +template gb_internal void string_map_grow (StringMap *h); +template gb_internal void string_map_reserve (StringMap *h, usize new_count); + +gb_internal gbAllocator string_map_allocator(void) { + return heap_allocator(); +} + +template +gb_internal gb_inline void string_map_init(StringMap *h, usize capacity) { + capacity = next_pow2_isize(capacity); + string_map_reserve(h, capacity); +} + +template +gb_internal gb_inline void string_map_destroy(StringMap *h) { + gb_free(string_map_allocator(), h->hashes); + gb_free(string_map_allocator(), h->entries); +} + + +template +gb_internal void string_map__resize_hashes(StringMap *h, usize count) { + h->hashes_count = cast(u32)resize_array_raw(&h->hashes, string_map_allocator(), h->hashes_count, count, MAP_CACHE_LINE_SIZE); +} + + +template +gb_internal void string_map__reserve_entries(StringMap *h, usize capacity) { + h->entries_capacity = cast(u32)resize_array_raw(&h->entries, string_map_allocator(), h->entries_capacity, capacity, MAP_CACHE_LINE_SIZE); +} + + +template +gb_internal MapIndex string_map__add_entry(StringMap *h, u32 hash, String const &key) { + StringMapEntry e = {}; + e.key = key; + e.hash = hash; + e.next = MAP_SENTINEL; + if (h->count+1 >= h->entries_capacity) { + string_map__reserve_entries(h, gb_max(h->entries_capacity*2, 4)); + } + h->entries[h->count++] = e; + return cast(MapIndex)(h->count-1); +} + +template +gb_internal MapFindResult string_map__find(StringMap *h, u32 hash, String const &key) { + MapFindResult fr = {MAP_SENTINEL, MAP_SENTINEL, MAP_SENTINEL}; + if (h->hashes_count != 0) { + fr.hash_index = cast(MapIndex)(hash & (h->hashes_count-1)); + fr.entry_index = h->hashes[fr.hash_index]; + while (fr.entry_index != MAP_SENTINEL) { + auto *entry = &h->entries[fr.entry_index]; + if (entry->hash == hash && entry->key == key) { + return fr; + } + fr.entry_prev = fr.entry_index; + fr.entry_index = entry->next; + } + } + return fr; +} + +template +gb_internal MapFindResult string_map__find_from_entry(StringMap *h, StringMapEntry *e) { + MapFindResult fr = {MAP_SENTINEL, MAP_SENTINEL, MAP_SENTINEL}; + if (h->hashes_count != 0) { + fr.hash_index = cast(MapIndex)(e->hash & (h->hashes_count-1)); + fr.entry_index = h->hashes[fr.hash_index]; + while (fr.entry_index != MAP_SENTINEL) { + auto *entry = &h->entries[fr.entry_index]; + if (entry == e) { + return fr; + } + fr.entry_prev = fr.entry_index; + fr.entry_index = entry->next; + } + } + return fr; +} + +template +gb_internal b32 string_map__full(StringMap *h) { + return 0.75f * h->hashes_count <= h->count; +} + +template +gb_inline void string_map_grow(StringMap *h) { + isize new_count = gb_max(h->hashes_count<<1, 16); + string_map_reserve(h, new_count); +} + + +template +gb_internal void string_map_reset_entries(StringMap *h) { + for (u32 i = 0; i < h->hashes_count; i++) { + h->hashes[i] = MAP_SENTINEL; + } + for (isize i = 0; i < h->count; i++) { + MapFindResult fr; + StringMapEntry *e = &h->entries[i]; + e->next = MAP_SENTINEL; + fr = string_map__find_from_entry(h, e); + if (fr.entry_prev == MAP_SENTINEL) { + h->hashes[fr.hash_index] = cast(MapIndex)i; + } else { + h->entries[fr.entry_prev].next = cast(MapIndex)i; + } + } +} + +template +gb_internal void string_map_reserve(StringMap *h, usize cap) { + if (h->count*2 < h->hashes_count) { + return; + } + string_map__reserve_entries(h, cap); + string_map__resize_hashes(h, cap*2); + string_map_reset_entries(h); +} + +template +gb_internal T *string_map_get(StringMap *h, u32 hash, String const &key) { + MapFindResult fr = {MAP_SENTINEL, MAP_SENTINEL, MAP_SENTINEL}; + if (h->hashes_count != 0) { + fr.hash_index = cast(MapIndex)(hash & (h->hashes_count-1)); + fr.entry_index = h->hashes[fr.hash_index]; + while (fr.entry_index != MAP_SENTINEL) { + auto *entry = &h->entries[fr.entry_index]; + if (entry->hash == hash && entry->key == key) { + return &entry->value; + } + fr.entry_prev = fr.entry_index; + fr.entry_index = entry->next; + } + } + return nullptr; +} + + +template +gb_internal gb_inline T *string_map_get(StringMap *h, StringHashKey const &key) { + return string_map_get(h, key.hash, key.string); +} + +template +gb_internal gb_inline T *string_map_get(StringMap *h, String const &key) { + return string_map_get(h, string_hash(key), key); +} + +template +gb_internal gb_inline T *string_map_get(StringMap *h, char const *key) { + String k = make_string_c(key); + return string_map_get(h, string_hash(k), k); +} + +template +gb_internal T &string_map_must_get(StringMap *h, u32 hash, String const &key) { + isize index = string_map__find(h, hash, key).entry_index; + GB_ASSERT(index != MAP_SENTINEL); + return h->entries[index].value; +} + +template +gb_internal T &string_map_must_get(StringMap *h, StringHashKey const &key) { + return string_map_must_get(h, key.hash, key.string); +} + +template +gb_internal gb_inline T &string_map_must_get(StringMap *h, String const &key) { + return string_map_must_get(h, string_hash(key), key); +} + +template +gb_internal gb_inline T &string_map_must_get(StringMap *h, char const *key) { + String k = make_string_c(key); + return string_map_must_get(h, string_hash(k), k); +} + +template +gb_internal void string_map_set(StringMap *h, u32 hash, String const &key, T const &value) { + MapIndex index; + MapFindResult fr; + if (h->hashes_count == 0) { + string_map_grow(h); + } + fr = string_map__find(h, hash, key); + if (fr.entry_index != MAP_SENTINEL) { + index = fr.entry_index; + } else { + index = string_map__add_entry(h, hash, key); + if (fr.entry_prev != MAP_SENTINEL) { + h->entries[fr.entry_prev].next = index; + } else { + h->hashes[fr.hash_index] = index; + } + } + h->entries[index].value = value; + + if (string_map__full(h)) { + string_map_grow(h); + } +} + +template +gb_internal gb_inline void string_map_set(StringMap *h, String const &key, T const &value) { + string_map_set(h, string_hash_string(key), value); +} + +template +gb_internal gb_inline void string_map_set(StringMap *h, char const *key, T const &value) { + string_map_set(h, string_hash_string(make_string_c(key)), value); +} + +template +gb_internal gb_inline void string_map_set(StringMap *h, StringHashKey const &key, T const &value) { + string_map_set(h, key.hash, key.string, value); +} + + +template +gb_internal gb_inline void string_map_clear(StringMap *h) { + h->count = 0; + for (u32 i = 0; i < h->hashes_count; i++) { + h->hashes[i] = MAP_SENTINEL; + } +} + + + +template +gb_internal StringMapEntry *begin(StringMap &m) noexcept { + return m.entries; +} +template +gb_internal StringMapEntry const *begin(StringMap const &m) noexcept { + return m.entries; +} + + +template +gb_internal StringMapEntry *end(StringMap &m) noexcept { + return m.entries + m.count; +} + +template +gb_internal StringMapEntry const *end(StringMap const &m) noexcept { + return m.entries + m.count; +} + +#else /* new string map */ + template struct StringMapEntry { String key; @@ -305,3 +595,5 @@ gb_internal StringMapIterator const begin(StringMap const &m) noexcept { } return StringMapIterator{&m, index}; } + +#endif \ No newline at end of file From f2505b096d7367e4a6aa66475cda81e9f9bc0dae Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 3 May 2024 14:22:30 +0100 Subject: [PATCH 6/7] Improve error message's suggestion for `if !integer` --- src/check_expr.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 06d0a8b12..83706112b 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -1802,11 +1802,13 @@ gb_internal bool check_unary_op(CheckerContext *c, Operand *o, Token op) { case Token_Not: if (!is_type_boolean(type) || is_type_array_like(o->type)) { ERROR_BLOCK(); - str = expr_to_string(o->expr); error(op, "Operator '%.*s' is only allowed on boolean expressions", LIT(op.string)); - gb_string_free(str); if (is_type_integer(type)) { - error_line("\tSuggestion: Did you mean to use the bitwise not operator '~'?\n"); + str = expr_to_string(o->expr); + error_line("\tSuggestion: Did you mean to do one of the following?\n"); + error_line("\t\t'%s == 0'?\n", str); + error_line("\t\tUse of the bitwise not operator '~'?\n"); + gb_string_free(str); } } else { o->type = t_untyped_bool; From 2201f365a1676f966fff5b9a79f0f56b5c1cf7ee Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 3 May 2024 14:51:02 +0100 Subject: [PATCH 7/7] Allow `#no_alias` on multi-pointers --- src/check_type.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/check_type.cpp b/src/check_type.cpp index ab8c0b057..61c502a68 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -2017,8 +2017,8 @@ gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_para } if (p->flags&FieldFlag_no_alias) { - if (!is_type_pointer(type)) { - error(name, "'#no_alias' can only be applied pointer typed parameters"); + if (!is_type_pointer(type) && !is_type_multi_pointer(type)) { + error(name, "'#no_alias' can only be applied pointer or multi-pointer typed parameters"); p->flags &= ~FieldFlag_no_alias; // Remove the flag } }