aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-08-22 12:54:04 +0100
committergingerBill <bill@gingerbill.org>2021-08-22 12:54:04 +0100
commit445ed9be2b526de355d7fac550747b25c8fd7f20 (patch)
tree2196b5c25f947a322752ae42e971b1d771353cb0 /core
parent8694a0f68a2b5c18ea19e1b8a526aacfd51fc85b (diff)
Use multi-pointers when appropriate
Diffstat (limited to 'core')
-rw-r--r--core/mem/mem.odin7
-rw-r--r--core/os/env_windows.odin11
-rw-r--r--core/runtime/core_builtin.odin8
-rw-r--r--core/sys/windows/types.odin2
4 files changed, 12 insertions, 16 deletions
diff --git a/core/mem/mem.odin b/core/mem/mem.odin
index 4c6d33a00..fddb1dd72 100644
--- a/core/mem/mem.odin
+++ b/core/mem/mem.odin
@@ -135,16 +135,15 @@ ptr_sub :: proc(a, b: $P/^$T) -> int {
}
slice_ptr :: proc(ptr: ^$T, len: int) -> []T {
- assert(len >= 0);
- return transmute([]T)Raw_Slice{data = ptr, len = len};
+ return ([^]T)(ptr)[:len];
}
byte_slice :: #force_inline proc "contextless" (data: rawptr, len: int) -> []byte {
- return transmute([]u8)Raw_Slice{data=data, len=max(len, 0)};
+ return ([^]u8)(data)[:max(len, 0)];
}
@(deprecated="use byte_slice")
slice_ptr_to_bytes :: proc(data: rawptr, len: int) -> []byte {
- return transmute([]u8)Raw_Slice{data=data, len=max(len, 0)};
+ return ([^]u8)(data)[:max(len, 0)];
}
diff --git a/core/os/env_windows.odin b/core/os/env_windows.odin
index 8a4cee967..5eb827e16 100644
--- a/core/os/env_windows.odin
+++ b/core/os/env_windows.odin
@@ -65,22 +65,19 @@ unset_env :: proc(key: string) -> Errno {
// environ returns a copy of strings representing the environment, in the form "key=value"
// NOTE: the slice of strings and the strings with be allocated using the supplied allocator
environ :: proc(allocator := context.allocator) -> []string {
- envs := win32.GetEnvironmentStringsW();
+ envs := cast([^]win32.WCHAR)(win32.GetEnvironmentStringsW());
if envs == nil {
return nil;
}
defer win32.FreeEnvironmentStringsW(envs);
r := make([dynamic]string, 0, 50, allocator);
- for from, i, p := 0, 0, envs; true; i += 1 {
- c := (^u16)(uintptr(p) + uintptr(i*2))^;
- if c == 0 {
+ for from, i := 0, 0; true; i += 1 {
+ if c := envs[i]; c == 0 {
if i <= from {
break;
}
- w := mem.slice_ptr(mem.ptr_offset(p, from), i-from);
-
- append(&r, win32.utf16_to_utf8(w, allocator));
+ append(&r, win32.utf16_to_utf8(envs[from:i], allocator));
from = i + 1;
}
}
diff --git a/core/runtime/core_builtin.odin b/core/runtime/core_builtin.odin
index f4dc6aebe..0fc72fd69 100644
--- a/core/runtime/core_builtin.odin
+++ b/core/runtime/core_builtin.odin
@@ -303,9 +303,9 @@ append_elem :: proc(array: ^$T/[dynamic]$E, arg: E, loc := #caller_location) {
if cap(array)-len(array) > 0 {
a := (^Raw_Dynamic_Array)(array);
when size_of(E) != 0 {
- data := (^E)(a.data);
+ data := ([^]E)(a.data);
assert(condition=data != nil, loc=loc);
- intrinsics.ptr_offset(data, a.len)^ = arg;
+ data[a.len] = arg;
}
a.len += 1;
}
@@ -331,9 +331,9 @@ append_elems :: proc(array: ^$T/[dynamic]$E, args: ..E, loc := #caller_location)
if arg_len > 0 {
a := (^Raw_Dynamic_Array)(array);
when size_of(E) != 0 {
- data := (^E)(a.data);
+ data := ([^]E)(a.data);
assert(condition=data != nil, loc=loc);
- intrinsics.mem_copy(intrinsics.ptr_offset(data, a.len), &args[0], size_of(E) * arg_len);
+ intrinsics.mem_copy(&data[a.len], raw_data(args), size_of(E) * arg_len);
}
a.len += arg_len;
}
diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin
index bb60ae193..9e55a463d 100644
--- a/core/sys/windows/types.odin
+++ b/core/sys/windows/types.odin
@@ -63,7 +63,7 @@ LONG64 :: i64;
PDWORD_PTR :: ^DWORD_PTR;
ATOM :: distinct WORD;
-wstring :: ^WCHAR;
+wstring :: [^]WCHAR;
PBYTE :: ^BYTE;
LPBYTE :: ^BYTE;