mirror of
https://github.com/odin-lang/Odin.git
synced 2026-08-03 04:38:54 +00:00
use win32.wstring_to_utf8, default to temp_allocator, guarantees proper null termination
This commit is contained in:
@@ -162,7 +162,7 @@ If thread is nil the procedure will get the name of the calling thread.
|
||||
|
||||
allocates memory for the returned string using provided allocator.
|
||||
*/
|
||||
get_name :: proc(thread: ^Thread, allocator := context.allocator, loc := #caller_location) -> (string, runtime.Allocator_Error) {
|
||||
get_name :: proc(thread: ^Thread, allocator := context.temp_allocator, loc := #caller_location) -> (string, runtime.Allocator_Error) {
|
||||
return _get_name(thread, allocator, loc)
|
||||
}
|
||||
|
||||
|
||||
@@ -163,15 +163,9 @@ _get_name :: proc(thread: ^Thread, allocator: runtime.Allocator, loc: runtime.So
|
||||
t_handle = thread.win32_thread
|
||||
}
|
||||
|
||||
buf_8: [_THREAD_DESCRIPTION_LENGTH * 2]u8
|
||||
buf_16: [_THREAD_DESCRIPTION_LENGTH]u16
|
||||
win32.GetThreadDescription(t_handle, raw_data(buf_16[:]))
|
||||
n := utf16.decode_to_utf8(buf_8[:], buf_16[:])
|
||||
buf := make([]u8, n, allocator, loc)
|
||||
|
||||
copy(buf[:], buf_8[:])
|
||||
|
||||
name = transmute(string)buf
|
||||
buf_16: win32.PWSTR
|
||||
win32.GetThreadDescription(t_handle, &buf_16)
|
||||
name = win32.wstring_to_utf8(buf_16, -1, allocator) or_return
|
||||
|
||||
return
|
||||
}
|
||||
@@ -185,9 +179,8 @@ _set_name :: proc(thread: ^Thread, name: string) {
|
||||
}
|
||||
|
||||
buf: [_THREAD_DESCRIPTION_LENGTH]u16
|
||||
utf16.encode_string(buf[:], name)
|
||||
// _THREAD_DESCRIPTION_LENGTH includes terminating null
|
||||
buf[len(buf) - 1] = 0
|
||||
utf16.encode_string(buf[:len(buf) - 1], name)
|
||||
win32.SetThreadDescription(t_handle, raw_data(buf[:]))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user