Browse Source

Remove `strings` dependency from `core:sys/windows`

gingerBill 3 years ago
parent
commit
fb49841b1d

+ 1 - 1
core/mem/mem.odin

@@ -152,7 +152,7 @@ slice_ptr :: proc "contextless" (ptr: ^$T, len: int) -> []T {
 	return ([^]T)(ptr)[:len]
 	return ([^]T)(ptr)[:len]
 }
 }
 
 
-byte_slice :: #force_inline proc "contextless" (data: rawptr, len: int) -> []byte {
+byte_slice :: #force_inline proc "contextless" (data: rawptr, #any_int len: int) -> []byte {
 	return ([^]u8)(data)[:max(len, 0)]
 	return ([^]u8)(data)[:max(len, 0)]
 }
 }
 
 

+ 1 - 3
core/slice/map.odin

@@ -2,11 +2,9 @@ package slice
 
 
 import "core:intrinsics"
 import "core:intrinsics"
 import "core:runtime"
 import "core:runtime"
-import "core:mem"
 
 
 _ :: intrinsics
 _ :: intrinsics
 _ :: runtime
 _ :: runtime
-_ :: mem
 
 
 map_keys :: proc(m: $M/map[$K]$V, allocator := context.allocator) -> (keys: []K) {
 map_keys :: proc(m: $M/map[$K]$V, allocator := context.allocator) -> (keys: []K) {
 	keys = make(type_of(keys), len(m), allocator)
 	keys = make(type_of(keys), len(m), allocator)
@@ -52,7 +50,7 @@ map_entries :: proc(m: $M/map[$K]$V, allocator := context.allocator) -> (entries
 
 
 map_entry_infos :: proc(m: $M/map[$K]$V, allocator := context.allocator) -> (entries: []Map_Entry_Info(K, V)) #no_bounds_check {
 map_entry_infos :: proc(m: $M/map[$K]$V, allocator := context.allocator) -> (entries: []Map_Entry_Info(K, V)) #no_bounds_check {
 	m := m
 	m := m
-	rm := (^mem.Raw_Map)(&m)
+	rm := (^runtime.Raw_Map)(&m)
 
 
 	info := runtime.type_info_base(type_info_of(M)).variant.(runtime.Type_Info_Map)
 	info := runtime.type_info_base(type_info_of(M)).variant.(runtime.Type_Info_Map)
 	gs := runtime.type_info_base(info.generated_struct).variant.(runtime.Type_Info_Struct)
 	gs := runtime.type_info_base(info.generated_struct).variant.(runtime.Type_Info_Struct)

+ 6 - 6
core/strings/builder.odin

@@ -1,6 +1,6 @@
 package strings
 package strings
 
 
-import "core:mem"
+import "core:runtime"
 import "core:unicode/utf8"
 import "core:unicode/utf8"
 import "core:strconv"
 import "core:strconv"
 import "core:io"
 import "core:io"
@@ -129,12 +129,12 @@ reset_builder :: proc(b: ^Builder) {
 	strings.write_byte(&builder, 'b') -> "ab"
 	strings.write_byte(&builder, 'b') -> "ab"
 */
 */
 builder_from_bytes :: proc(backing: []byte) -> Builder {
 builder_from_bytes :: proc(backing: []byte) -> Builder {
-	s := transmute(mem.Raw_Slice)backing
-	d := mem.Raw_Dynamic_Array{
+	s := transmute(runtime.Raw_Slice)backing
+	d := runtime.Raw_Dynamic_Array{
 		data = s.data,
 		data = s.data,
 		len  = 0,
 		len  = 0,
 		cap  = s.len,
 		cap  = s.len,
-		allocator = mem.nil_allocator(),
+		allocator = runtime.nil_allocator(),
 	}
 	}
 	return Builder{
 	return Builder{
 		buf = transmute([dynamic]byte)d,
 		buf = transmute([dynamic]byte)d,
@@ -276,7 +276,7 @@ pop_byte :: proc(b: ^Builder) -> (r: byte) {
 	}
 	}
 
 
 	r = b.buf[len(b.buf)-1]
 	r = b.buf[len(b.buf)-1]
-	d := cast(^mem.Raw_Dynamic_Array)&b.buf
+	d := cast(^runtime.Raw_Dynamic_Array)&b.buf
 	d.len = max(d.len-1, 0)
 	d.len = max(d.len-1, 0)
 	return
 	return
 }
 }
@@ -289,7 +289,7 @@ pop_rune :: proc(b: ^Builder) -> (r: rune, width: int) {
 	}
 	}
 
 
 	r, width = utf8.decode_last_rune(b.buf[:])
 	r, width = utf8.decode_last_rune(b.buf[:])
-	d := cast(^mem.Raw_Dynamic_Array)&b.buf
+	d := cast(^runtime.Raw_Dynamic_Array)&b.buf
 	d.len = max(d.len-width, 0)
 	d.len = max(d.len-width, 0)
 	return
 	return
 }
 }

+ 4 - 3
core/strings/intern.odin

@@ -1,6 +1,6 @@
 package strings
 package strings
 
 
-import "core:mem"
+import "core:runtime"
 
 
 // custom string entry struct
 // custom string entry struct
 Intern_Entry :: struct {
 Intern_Entry :: struct {
@@ -11,7 +11,7 @@ Intern_Entry :: struct {
 // "intern" is a more memory efficient string map
 // "intern" is a more memory efficient string map
 // `allocator` is used to allocate the actual `Intern_Entry` strings
 // `allocator` is used to allocate the actual `Intern_Entry` strings
 Intern :: struct {
 Intern :: struct {
-	allocator: mem.Allocator,
+	allocator: runtime.Allocator,
 	entries: map[string]^Intern_Entry,
 	entries: map[string]^Intern_Entry,
 }
 }
 
 
@@ -54,7 +54,8 @@ _intern_get_entry :: proc(m: ^Intern, text: string) -> ^Intern_Entry #no_bounds_
 	}
 	}
 
 
 	entry_size := int(offset_of(Intern_Entry, str)) + len(text) + 1
 	entry_size := int(offset_of(Intern_Entry, str)) + len(text) + 1
-	new_entry := (^Intern_Entry)(mem.alloc(entry_size, align_of(Intern_Entry), m.allocator))
+	ptr, _ := runtime.mem_alloc(entry_size, align_of(Intern_Entry), m.allocator)
+	new_entry := (^Intern_Entry)(ptr)
 
 
 	new_entry.len = len(text)
 	new_entry.len = len(text)
 	copy(new_entry.str[:new_entry.len], text)
 	copy(new_entry.str[:new_entry.len], text)

+ 4 - 1
core/sys/windows/comdlg32.odin

@@ -2,7 +2,6 @@
 package sys_windows
 package sys_windows
 
 
 foreign import "system:Comdlg32.lib"
 foreign import "system:Comdlg32.lib"
-import "core:strings"
 
 
 LPOFNHOOKPROC :: #type proc "stdcall" (hdlg: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> UINT_PTR
 LPOFNHOOKPROC :: #type proc "stdcall" (hdlg: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> UINT_PTR
 
 
@@ -49,6 +48,9 @@ SAVE_TITLE :: "Select file to save"
 SAVE_FLAGS :: u32(OFN_OVERWRITEPROMPT | OFN_EXPLORER)
 SAVE_FLAGS :: u32(OFN_OVERWRITEPROMPT | OFN_EXPLORER)
 SAVE_EXT   :: "txt"
 SAVE_EXT   :: "txt"
 
 
+/*
+import "core:strings"
+
 Open_Save_Mode :: enum {
 Open_Save_Mode :: enum {
 	Open = 0,
 	Open = 0,
 	Save = 1,
 	Save = 1,
@@ -121,6 +123,7 @@ select_file_to_save :: proc(title := SAVE_TITLE, dir := ".",
 	path, ok = _open_file_dialog(title, dir, filters, default_filter, flags, default_ext, Open_Save_Mode.Save, allocator)
 	path, ok = _open_file_dialog(title, dir, filters, default_filter, flags, default_ext, Open_Save_Mode.Save, allocator)
 	return
 	return
 }
 }
+*/
 
 
 // TODO: Implement convenience function for select_file_to_open with ALLOW_MULTI_SELECT that takes
 // TODO: Implement convenience function for select_file_to_open with ALLOW_MULTI_SELECT that takes
 //       it output of the form "path\u0000\file1u\0000file2" and turns it into []string with the path + file pre-concatenated for you.
 //       it output of the form "path\u0000\file1u\0000file2" and turns it into []string with the path + file pre-concatenated for you.

+ 15 - 2
core/sys/windows/util.odin

@@ -1,7 +1,6 @@
 // +build windows
 // +build windows
 package sys_windows
 package sys_windows
 
 
-import "core:strings"
 import "core:runtime"
 import "core:runtime"
 import "core:intrinsics"
 import "core:intrinsics"
 
 
@@ -100,6 +99,20 @@ utf16_to_utf8 :: proc(s: []u16, allocator := context.temp_allocator) -> (res: st
 // AdvAPI32, NetAPI32 and UserENV helpers.
 // AdvAPI32, NetAPI32 and UserENV helpers.
 
 
 allowed_username :: proc(username: string) -> bool {
 allowed_username :: proc(username: string) -> bool {
+	contains_any :: proc(s, chars: string) -> bool {
+		if chars == "" {
+			return false
+		}
+		for c in transmute([]byte)s {
+			for b in transmute([]byte)chars {
+				if c == b {
+					return true
+				}
+			}
+		}
+		return false
+	}
+
 /*
 /*
 	User account names are limited to 20 characters and group names are limited to 256 characters.
 	User account names are limited to 20 characters and group names are limited to 256 characters.
 	In addition, account names cannot be terminated by a period and they cannot include commas or any of the following printable characters:
 	In addition, account names cannot be terminated by a period and they cannot include commas or any of the following printable characters:
@@ -120,7 +133,7 @@ allowed_username :: proc(username: string) -> bool {
 			return false
 			return false
 		}
 		}
 	}
 	}
-	if strings.contains_any(username, _DISALLOWED) {
+	if contains_any(username, _DISALLOWED) {
 		return false
 		return false
 	}
 	}
 
 

+ 4 - 4
core/time/perf.odin

@@ -1,6 +1,6 @@
 package time
 package time
 
 
-import "core:mem"
+import "core:runtime"
 
 
 Tick :: struct {
 Tick :: struct {
 	_nsec: i64, // relative amount
 	_nsec: i64, // relative amount
@@ -50,9 +50,9 @@ Benchmark_Error :: enum {
 }
 }
 
 
 Benchmark_Options :: struct {
 Benchmark_Options :: struct {
-	setup:     #type proc(options: ^Benchmark_Options, allocator: mem.Allocator) -> (err: Benchmark_Error),
-	bench:     #type proc(options: ^Benchmark_Options, allocator: mem.Allocator) -> (err: Benchmark_Error),
-	teardown:  #type proc(options: ^Benchmark_Options, allocator: mem.Allocator) -> (err: Benchmark_Error),
+	setup:     #type proc(options: ^Benchmark_Options, allocator: runtime.Allocator) -> (err: Benchmark_Error),
+	bench:     #type proc(options: ^Benchmark_Options, allocator: runtime.Allocator) -> (err: Benchmark_Error),
+	teardown:  #type proc(options: ^Benchmark_Options, allocator: runtime.Allocator) -> (err: Benchmark_Error),
 
 
 	rounds:    int,
 	rounds:    int,
 	bytes:     int,
 	bytes:     int,