aboutsummaryrefslogtreecommitdiff
path: root/core/strings/intern.odin
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2026-01-31 10:50:42 +0100
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2026-01-31 10:50:42 +0100
commit2b539bfcd5e540ae4bbddd43c39b8d261f80484c (patch)
treeba469e6bde1dc1b5ada42e621ae92826e8ac1800 /core/strings/intern.odin
parentb1122284f1930b49d7a079c55344888fd0935626 (diff)
Fix #6198
Diffstat (limited to 'core/strings/intern.odin')
-rw-r--r--core/strings/intern.odin11
1 files changed, 7 insertions, 4 deletions
diff --git a/core/strings/intern.odin b/core/strings/intern.odin
index 0b8ed173e..909510c7c 100644
--- a/core/strings/intern.odin
+++ b/core/strings/intern.odin
@@ -30,6 +30,7 @@ Inputs:
- m: A pointer to the Intern struct to be initialized
- allocator: The allocator for the Intern_Entry strings (Default: context.allocator)
- map_allocator: The allocator for the map of entries (Default: context.allocator)
+- loc: The caller location for debugging purposes (default: `#caller_location`)
Returns:
- err: An allocator error if one occured, `nil` otherwise
@@ -78,6 +79,7 @@ Returns an interned copy of the given text as a cstring, adding it to the map if
Inputs:
- m: A pointer to the Intern struct
- text: The string to be interned
+- loc: The caller location for debugging purposes (default: `#caller_location`)
NOTE: The returned cstring lives as long as the map entry lives
@@ -85,8 +87,8 @@ Returns:
- str: The interned cstring
- err: An allocator error if one occured, `nil` otherwise
*/
-intern_get_cstring :: proc(m: ^Intern, text: string) -> (str: cstring, err: runtime.Allocator_Error) {
- entry := _intern_get_entry(m, text) or_return
+intern_get_cstring :: proc(m: ^Intern, text: string, loc := #caller_location) -> (str: cstring, err: runtime.Allocator_Error) {
+ entry := _intern_get_entry(m, text, loc) or_return
return cstring(&entry.str[0]), nil
}
@@ -99,12 +101,13 @@ Sets and allocates the entry if it wasn't set yet
Inputs:
- m: A pointer to the Intern struct
- text: The string to be looked up or interned
+- loc: The caller location for debugging purposes (default: `#caller_location`)
Returns:
- new_entry: The interned cstring
- err: An allocator error if one occured, `nil` otherwise
*/
-_intern_get_entry :: proc(m: ^Intern, text: string) -> (new_entry: ^Intern_Entry, err: runtime.Allocator_Error) #no_bounds_check {
+_intern_get_entry :: proc(m: ^Intern, text: string, loc := #caller_location) -> (new_entry: ^Intern_Entry, err: runtime.Allocator_Error) #no_bounds_check {
if m.allocator.procedure == nil {
m.allocator = context.allocator
}
@@ -115,7 +118,7 @@ _intern_get_entry :: proc(m: ^Intern, text: string) -> (new_entry: ^Intern_Entry
}
entry_size := int(offset_of(Intern_Entry, str)) + len(text) + 1
- bytes := runtime.mem_alloc(entry_size, align_of(Intern_Entry), m.allocator) or_return
+ bytes := runtime.mem_alloc(entry_size, align_of(Intern_Entry), m.allocator, loc) or_return
new_entry = (^Intern_Entry)(raw_data(bytes))
new_entry.len = len(text)