mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Correct context.allocator usage
This commit is contained in:
@@ -5,12 +5,14 @@ import win32 "core:sys/windows"
|
|||||||
|
|
||||||
@(private)
|
@(private)
|
||||||
full_path_from_name :: proc(name: string, allocator := context.allocator) -> (path: string, err: Errno) {
|
full_path_from_name :: proc(name: string, allocator := context.allocator) -> (path: string, err: Errno) {
|
||||||
|
context.allocator = allocator
|
||||||
|
|
||||||
name := name
|
name := name
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = "."
|
name = "."
|
||||||
}
|
}
|
||||||
p := win32.utf8_to_utf16(name, context.temp_allocator)
|
p := win32.utf8_to_utf16(name, context.temp_allocator)
|
||||||
buf := make([dynamic]u16, 100, allocator)
|
buf := make([dynamic]u16, 100)
|
||||||
defer delete(buf)
|
defer delete(buf)
|
||||||
for {
|
for {
|
||||||
n := win32.GetFullPathNameW(raw_data(p), u32(len(buf)), raw_data(buf), nil)
|
n := win32.GetFullPathNameW(raw_data(p), u32(len(buf)), raw_data(buf), nil)
|
||||||
|
|||||||
@@ -91,13 +91,15 @@ abs :: proc(path: string, allocator := context.allocator) -> (string, bool) {
|
|||||||
join :: proc(elems: ..string, allocator := context.allocator) -> string {
|
join :: proc(elems: ..string, allocator := context.allocator) -> string {
|
||||||
for e, i in elems {
|
for e, i in elems {
|
||||||
if e != "" {
|
if e != "" {
|
||||||
return join_non_empty(elems[i:])
|
return join_non_empty(elems[i:], allocator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
join_non_empty :: proc(elems: []string) -> string {
|
join_non_empty :: proc(elems: []string, allocator := context.allocator) -> string {
|
||||||
|
context.allocator = allocator
|
||||||
|
|
||||||
if len(elems[0]) == 2 && elems[0][1] == ':' {
|
if len(elems[0]) == 2 && elems[0][1] == ':' {
|
||||||
i := 1
|
i := 1
|
||||||
for ; i < len(elems); i += 1 {
|
for ; i < len(elems); i += 1 {
|
||||||
@@ -110,8 +112,7 @@ join_non_empty :: proc(elems: []string) -> string {
|
|||||||
return clean(s)
|
return clean(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := strings.join(elems, SEPARATOR_STRING, context.temp_allocator)
|
p := clean(strings.join(elems, SEPARATOR_STRING, context.temp_allocator))
|
||||||
p := clean(s)
|
|
||||||
if !is_UNC(p) {
|
if !is_UNC(p) {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -681,9 +681,10 @@ unquote_string :: proc(lit: string, allocator := context.allocator) -> (res: str
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.allocator = allocator
|
||||||
|
|
||||||
buf_len := 3*len(s) / 2
|
buf_len := 3*len(s) / 2
|
||||||
buf := make([]byte, buf_len, allocator)
|
buf := make([]byte, buf_len)
|
||||||
offset := 0
|
offset := 0
|
||||||
for len(s) > 0 {
|
for len(s) > 0 {
|
||||||
r, multiple_bytes, tail_string, ok := unquote_char(s, byte(quote))
|
r, multiple_bytes, tail_string, ok := unquote_char(s, byte(quote))
|
||||||
|
|||||||
@@ -84,7 +84,11 @@ _open_file_dialog :: proc(title: string, dir: string,
|
|||||||
filters: []string, default_filter: u32,
|
filters: []string, default_filter: u32,
|
||||||
flags: u32, default_ext: string,
|
flags: u32, default_ext: string,
|
||||||
mode: Open_Save_Mode, allocator := context.temp_allocator) -> (path: string, ok: bool = true) {
|
mode: Open_Save_Mode, allocator := context.temp_allocator) -> (path: string, ok: bool = true) {
|
||||||
file_buf := make([]u16, MAX_PATH_WIDE, allocator)
|
context.allocator = allocator
|
||||||
|
file_buf := make([]u16, MAX_PATH_WIDE)
|
||||||
|
defer if !ok {
|
||||||
|
delete(file_buf)
|
||||||
|
}
|
||||||
|
|
||||||
// Filters need to be passed as a pair of strings (title, filter)
|
// Filters need to be passed as a pair of strings (title, filter)
|
||||||
filter_len := u32(len(filters))
|
filter_len := u32(len(filters))
|
||||||
@@ -118,10 +122,10 @@ _open_file_dialog :: proc(title: string, dir: string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
delete(file_buf)
|
return
|
||||||
return "", false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
file_name := utf16_to_utf8(file_buf[:], allocator)
|
file_name := utf16_to_utf8(file_buf[:], allocator)
|
||||||
path = strings.trim_right_null(file_name)
|
path = strings.trim_right_null(file_name)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user