Improve default temp allocator; Fix filepath.abs behaviour on Windows

This commit is contained in:
gingerBill
2020-10-13 14:40:13 +01:00
parent 1b4bccbc94
commit fa33476438
5 changed files with 59 additions and 38 deletions
+23 -19
View File
@@ -2,15 +2,16 @@ package sys_windows
import "core:c"
c_char :: c.char;
c_int :: c.int;
c_uint :: c.uint;
c_long :: c.long;
c_char :: c.char;
c_int :: c.int;
c_uint :: c.uint;
c_long :: c.long;
c_longlong :: c.longlong;
c_ulong :: c.ulong;
c_ushort :: c.ushort;
size_t :: c.size_t;
wchar_t :: c.wchar_t;
c_ulong :: c.ulong;
c_short :: c.short;
c_ushort :: c.ushort;
size_t :: c.size_t;
wchar_t :: c.wchar_t;
DWORD :: c_ulong;
HANDLE :: distinct LPVOID;
@@ -36,6 +37,9 @@ DWORD_PTR :: ULONG_PTR;
ULONG :: c_ulong;
UCHAR :: BYTE;
PDWORD_PTR :: ^DWORD_PTR;
ATOM :: distinct WORD;
wstring :: ^WCHAR;
LPBOOL :: ^BOOL;
@@ -717,15 +721,15 @@ SYSTEM_INFO :: struct {
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_osversioninfoexw
OSVERSIONINFOEXW :: struct {
os_version_info_size: ULONG,
major_version: ULONG,
minor_version: ULONG,
build_number: ULONG,
platform_id : ULONG,
service_pack_string: [128]WCHAR,
service_pack_major: USHORT,
service_pack_minor: USHORT,
suite_mask: USHORT,
product_type: UCHAR,
reserved: UCHAR,
os_version_info_size: ULONG,
major_version: ULONG,
minor_version: ULONG,
build_number: ULONG,
platform_id : ULONG,
service_pack_string: [128]WCHAR,
service_pack_major: USHORT,
service_pack_minor: USHORT,
suite_mask: USHORT,
product_type: UCHAR,
reserved: UCHAR,
}
+14 -5
View File
@@ -1,12 +1,20 @@
package sys_windows
LOWORD :: inline proc "contextless" (x: DWORD) -> WORD {
return WORD(x & 0xffff);
}
HIWORD :: inline proc "contextless" (x: DWORD) -> WORD {
return WORD(x >> 16);
}
utf8_to_utf16 :: proc(s: string, allocator := context.temp_allocator) -> []u16 {
if len(s) < 1 {
return nil;
}
b := transmute([]byte)s;
cstr := &b[0];
cstr := raw_data(b);
n := MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, cstr, i32(len(s)), nil, 0);
if n == 0 {
return nil;
@@ -14,7 +22,7 @@ utf8_to_utf16 :: proc(s: string, allocator := context.temp_allocator) -> []u16 {
text := make([]u16, n+1, allocator);
n1 := MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, cstr, i32(len(s)), wstring(&text[0]), i32(n));
n1 := MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, cstr, i32(len(s)), raw_data(text), i32(n));
if n1 == 0 {
delete(text, allocator);
return nil;
@@ -34,7 +42,7 @@ utf8_to_wstring :: proc(s: string, allocator := context.temp_allocator) -> wstri
}
wstring_to_utf8 :: proc(s: wstring, N: int, allocator := context.temp_allocator) -> string {
if N == 0 {
if N <= 0 {
return "";
}
@@ -50,7 +58,8 @@ wstring_to_utf8 :: proc(s: wstring, N: int, allocator := context.temp_allocator)
// will not be null terminated, we therefore have to force it to be null terminated manually.
text := make([]byte, n+1 if N != -1 else n, allocator);
if n1 := WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, s, i32(N), &text[0], n, nil, nil); n1 == 0 {
n1 := WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, s, i32(N), raw_data(text), n, nil, nil);
if n1 == 0 {
delete(text, allocator);
return "";
}
@@ -69,6 +78,6 @@ utf16_to_utf8 :: proc(s: []u16, allocator := context.temp_allocator) -> string {
if len(s) == 0 {
return "";
}
return wstring_to_utf8(cast(wstring)&s[0], len(s), allocator);
return wstring_to_utf8(raw_data(s), len(s), allocator);
}