mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Convert all uses of *_from_slice to *_from_bytes where appropriate
This commit is contained in:
@@ -16,7 +16,8 @@ clone_safe :: proc(s: []byte, allocator := context.allocator, loc := #caller_loc
|
|||||||
return c[:len(s)], nil
|
return c[:len(s)], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr_from_slice :: proc(str: []byte) -> ^byte {
|
ptr_from_slice :: ptr_from_bytes
|
||||||
|
ptr_from_bytes :: proc(str: []byte) -> ^byte {
|
||||||
d := transmute(mem.Raw_String)str
|
d := transmute(mem.Raw_String)str
|
||||||
return d.data
|
return d.data
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -119,17 +119,17 @@ tprintf :: proc(fmt: string, args: ..any) -> string {
|
|||||||
|
|
||||||
// bprint procedures return a string using a buffer from an array
|
// bprint procedures return a string using a buffer from an array
|
||||||
bprint :: proc(buf: []byte, args: ..any, sep := " ") -> string {
|
bprint :: proc(buf: []byte, args: ..any, sep := " ") -> string {
|
||||||
sb := strings.builder_from_slice(buf[0:len(buf)])
|
sb := strings.builder_from_bytes(buf[0:len(buf)])
|
||||||
return sbprint(buf=&sb, args=args, sep=sep)
|
return sbprint(buf=&sb, args=args, sep=sep)
|
||||||
}
|
}
|
||||||
// bprintln procedures return a string using a buffer from an array
|
// bprintln procedures return a string using a buffer from an array
|
||||||
bprintln :: proc(buf: []byte, args: ..any, sep := " ") -> string {
|
bprintln :: proc(buf: []byte, args: ..any, sep := " ") -> string {
|
||||||
sb := strings.builder_from_slice(buf[0:len(buf)])
|
sb := strings.builder_from_bytes(buf[0:len(buf)])
|
||||||
return sbprintln(buf=&sb, args=args, sep=sep)
|
return sbprintln(buf=&sb, args=args, sep=sep)
|
||||||
}
|
}
|
||||||
// bprintf procedures return a string using a buffer from an array
|
// bprintf procedures return a string using a buffer from an array
|
||||||
bprintf :: proc(buf: []byte, fmt: string, args: ..any) -> string {
|
bprintf :: proc(buf: []byte, fmt: string, args: ..any) -> string {
|
||||||
sb := strings.builder_from_slice(buf[0:len(buf)])
|
sb := strings.builder_from_bytes(buf[0:len(buf)])
|
||||||
return sbprintf(&sb, fmt, ..args)
|
return sbprintf(&sb, fmt, ..args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ file_console_logger_proc :: proc(logger_data: rawptr, level: Level, text: string
|
|||||||
h = data.file_handle
|
h = data.file_handle
|
||||||
}
|
}
|
||||||
backing: [1024]byte //NOTE(Hoej): 1024 might be too much for a header backing, unless somebody has really long paths.
|
backing: [1024]byte //NOTE(Hoej): 1024 might be too much for a header backing, unless somebody has really long paths.
|
||||||
buf := strings.builder_from_slice(backing[:])
|
buf := strings.builder_from_bytes(backing[:])
|
||||||
|
|
||||||
do_level_header(options, level, &buf)
|
do_level_header(options, level, &buf)
|
||||||
|
|
||||||
|
|||||||
+12
-9
@@ -34,17 +34,20 @@ File_Flag :: enum {
|
|||||||
Trunc,
|
Trunc,
|
||||||
Sparse,
|
Sparse,
|
||||||
Close_On_Exec,
|
Close_On_Exec,
|
||||||
|
|
||||||
|
Unbuffered_IO,
|
||||||
}
|
}
|
||||||
|
|
||||||
O_RDONLY :: File_Flags{.Read}
|
O_RDONLY :: File_Flags{.Read}
|
||||||
O_WRONLY :: File_Flags{.Write}
|
O_WRONLY :: File_Flags{.Write}
|
||||||
O_RDWR :: File_Flags{.Read, .Write}
|
O_RDWR :: File_Flags{.Read, .Write}
|
||||||
O_APPEND :: File_Flags{.Append}
|
O_APPEND :: File_Flags{.Append}
|
||||||
O_CREATE :: File_Flags{.Create}
|
O_CREATE :: File_Flags{.Create}
|
||||||
O_EXCL :: File_Flags{.Excl}
|
O_EXCL :: File_Flags{.Excl}
|
||||||
O_SYNC :: File_Flags{.Sync}
|
O_SYNC :: File_Flags{.Sync}
|
||||||
O_TRUNC :: File_Flags{.Trunc}
|
O_TRUNC :: File_Flags{.Trunc}
|
||||||
O_SPARSE :: File_Flags{.Sparse}
|
O_SPARSE :: File_Flags{.Sparse}
|
||||||
|
O_CLOEXEC :: File_Flags{.Close_On_Exec}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -124,11 +124,11 @@ reset_builder :: proc(b: ^Builder) {
|
|||||||
used in `fmt.bprint*`
|
used in `fmt.bprint*`
|
||||||
|
|
||||||
bytes: [8]byte // <-- gets filled
|
bytes: [8]byte // <-- gets filled
|
||||||
builder := strings.builder_from_slice(bytes[:])
|
builder := strings.builder_from_bytes(bytes[:])
|
||||||
strings.write_byte(&builder, 'a') -> "a"
|
strings.write_byte(&builder, 'a') -> "a"
|
||||||
strings.write_byte(&builder, 'b') -> "ab"
|
strings.write_byte(&builder, 'b') -> "ab"
|
||||||
*/
|
*/
|
||||||
builder_from_slice :: proc(backing: []byte) -> Builder {
|
builder_from_bytes :: proc(backing: []byte) -> Builder {
|
||||||
s := transmute(mem.Raw_Slice)backing
|
s := transmute(mem.Raw_Slice)backing
|
||||||
d := mem.Raw_Dynamic_Array{
|
d := mem.Raw_Dynamic_Array{
|
||||||
data = s.data,
|
data = s.data,
|
||||||
@@ -140,6 +140,7 @@ builder_from_slice :: proc(backing: []byte) -> Builder {
|
|||||||
buf = transmute([dynamic]byte)d,
|
buf = transmute([dynamic]byte)d,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
builder_from_slice :: builder_from_bytes
|
||||||
|
|
||||||
// cast the builder byte buffer to a string and return it
|
// cast the builder byte buffer to a string and return it
|
||||||
to_string :: proc(b: Builder) -> string {
|
to_string :: proc(b: Builder) -> string {
|
||||||
|
|||||||
@@ -402,7 +402,7 @@ syscall_openat :: #force_inline proc(fd: int, path: cstring, oflag: u32, mode: u
|
|||||||
return cast(c.int)intrinsics.syscall(unix_offset_syscall(.openat), uintptr(fd), transmute(uintptr)path, uintptr(oflag), uintptr(mode))
|
return cast(c.int)intrinsics.syscall(unix_offset_syscall(.openat), uintptr(fd), transmute(uintptr)path, uintptr(oflag), uintptr(mode))
|
||||||
}
|
}
|
||||||
|
|
||||||
syscall_getentropy :: #force_inline proc(buf: ^u8, buflen: u64) -> c.int {
|
syscall_getentropy :: #force_inline proc(buf: [^]u8, buflen: u64) -> c.int {
|
||||||
return cast(c.int)intrinsics.syscall(unix_offset_syscall(.getentropy), uintptr(buf), uintptr(buflen))
|
return cast(c.int)intrinsics.syscall(unix_offset_syscall(.getentropy), uintptr(buf), uintptr(buflen))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1522,6 +1522,6 @@ sys_gettid :: proc "contextless" () -> int {
|
|||||||
return cast(int)intrinsics.syscall(SYS_gettid)
|
return cast(int)intrinsics.syscall(SYS_gettid)
|
||||||
}
|
}
|
||||||
|
|
||||||
sys_getrandom :: proc "contextless" (buf: ^byte, buflen: int, flags: uint) -> int {
|
sys_getrandom :: proc "contextless" (buf: [^]byte, buflen: int, flags: uint) -> int {
|
||||||
return cast(int)intrinsics.syscall(SYS_getrandom, buf, cast(uintptr)(buflen), cast(uintptr)(flags))
|
return cast(int)intrinsics.syscall(SYS_getrandom, buf, cast(uintptr)(buflen), cast(uintptr)(flags))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ BCRYPT_USE_SYSTEM_PREFERRED_RNG: DWORD : 0x00000002
|
|||||||
|
|
||||||
@(default_calling_convention="stdcall")
|
@(default_calling_convention="stdcall")
|
||||||
foreign bcrypt {
|
foreign bcrypt {
|
||||||
BCryptGenRandom :: proc(hAlgorithm: LPVOID, pBuffer: ^u8, cbBuffer: ULONG, dwFlags: ULONG) -> LONG ---
|
BCryptGenRandom :: proc(hAlgorithm: LPVOID, pBuffer: [^]u8, cbBuffer: ULONG, dwFlags: ULONG) -> LONG ---
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import "core:os"
|
|||||||
import "core:strings"
|
import "core:strings"
|
||||||
import "core:bytes"
|
import "core:bytes"
|
||||||
|
|
||||||
parse_mo_from_slice :: proc(data: []u8, options := DEFAULT_PARSE_OPTIONS, pluralizer: proc(int) -> int = nil, allocator := context.allocator) -> (translation: ^Translation, err: Error) {
|
parse_mo_from_bytes :: proc(data: []byte, options := DEFAULT_PARSE_OPTIONS, pluralizer: proc(int) -> int = nil, allocator := context.allocator) -> (translation: ^Translation, err: Error) {
|
||||||
context.allocator = allocator
|
context.allocator = allocator
|
||||||
/*
|
/*
|
||||||
An MO file should have at least a 4-byte magic, 2 x 2 byte version info,
|
An MO file should have at least a 4-byte magic, 2 x 2 byte version info,
|
||||||
@@ -126,10 +126,10 @@ parse_mo_file :: proc(filename: string, options := DEFAULT_PARSE_OPTIONS, plural
|
|||||||
|
|
||||||
if !data_ok { return {}, .File_Error }
|
if !data_ok { return {}, .File_Error }
|
||||||
|
|
||||||
return parse_mo_from_slice(data, options, pluralizer, allocator)
|
return parse_mo_from_bytes(data, options, pluralizer, allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_mo :: proc { parse_mo_file, parse_mo_from_slice }
|
parse_mo :: proc { parse_mo_file, parse_mo_from_bytes }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Helpers.
|
Helpers.
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ TS_XML_Options := xml.Options{
|
|||||||
expected_doctype = "TS",
|
expected_doctype = "TS",
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_qt_linguist_from_slice :: proc(data: []u8, options := DEFAULT_PARSE_OPTIONS, pluralizer: proc(int) -> int = nil, allocator := context.allocator) -> (translation: ^Translation, err: Error) {
|
parse_qt_linguist_from_bytes :: proc(data: []byte, options := DEFAULT_PARSE_OPTIONS, pluralizer: proc(int) -> int = nil, allocator := context.allocator) -> (translation: ^Translation, err: Error) {
|
||||||
context.allocator = allocator
|
context.allocator = allocator
|
||||||
|
|
||||||
ts, xml_err := xml.parse(data, TS_XML_Options)
|
ts, xml_err := xml.parse(data, TS_XML_Options)
|
||||||
@@ -150,7 +150,7 @@ parse_qt_linguist_file :: proc(filename: string, options := DEFAULT_PARSE_OPTION
|
|||||||
|
|
||||||
if !data_ok { return {}, .File_Error }
|
if !data_ok { return {}, .File_Error }
|
||||||
|
|
||||||
return parse_qt_linguist_from_slice(data, options, pluralizer, allocator)
|
return parse_qt_linguist_from_bytes(data, options, pluralizer, allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_qt :: proc { parse_qt_linguist_file, parse_qt_linguist_from_slice }
|
parse_qt :: proc { parse_qt_linguist_file, parse_qt_linguist_from_bytes }
|
||||||
Vendored
+1
-1
@@ -309,7 +309,7 @@ init :: proc(ctx: ^Context) {
|
|||||||
ctx.draw_frame = default_draw_frame
|
ctx.draw_frame = default_draw_frame
|
||||||
ctx._style = default_style
|
ctx._style = default_style
|
||||||
ctx.style = &ctx._style
|
ctx.style = &ctx._style
|
||||||
ctx.text_input = strings.builder_from_slice(ctx._text_store[:])
|
ctx.text_input = strings.builder_from_bytes(ctx._text_store[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
begin :: proc(ctx: ^Context) {
|
begin :: proc(ctx: ^Context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user