Imply #no_capture to all variadic parameters

This commit is contained in:
gingerBill
2024-07-14 12:19:47 +01:00
parent 891cf54b5c
commit 8642d719f0
25 changed files with 125 additions and 117 deletions
+29 -29
View File
@@ -125,7 +125,7 @@ register_user_formatter :: proc(id: typeid, formatter: User_Formatter) -> Regist
// Returns: A formatted string.
//
@(require_results)
aprint :: proc(#no_capture args: ..any, sep := " ", allocator := context.allocator) -> string {
aprint :: proc(args: ..any, sep := " ", allocator := context.allocator) -> string {
str: strings.Builder
strings.builder_init(&str, allocator)
return sbprint(&str, ..args, sep=sep)
@@ -141,7 +141,7 @@ aprint :: proc(#no_capture args: ..any, sep := " ", allocator := context.allocat
// Returns: A formatted string with a newline character at the end.
//
@(require_results)
aprintln :: proc(#no_capture args: ..any, sep := " ", allocator := context.allocator) -> string {
aprintln :: proc(args: ..any, sep := " ", allocator := context.allocator) -> string {
str: strings.Builder
strings.builder_init(&str, allocator)
return sbprintln(&str, ..args, sep=sep)
@@ -158,7 +158,7 @@ aprintln :: proc(#no_capture args: ..any, sep := " ", allocator := context.alloc
// Returns: A formatted string. The returned string must be freed accordingly.
//
@(require_results)
aprintf :: proc(fmt: string, #no_capture args: ..any, allocator := context.allocator, newline := false) -> string {
aprintf :: proc(fmt: string, args: ..any, allocator := context.allocator, newline := false) -> string {
str: strings.Builder
strings.builder_init(&str, allocator)
return sbprintf(&str, fmt, ..args, newline=newline)
@@ -174,7 +174,7 @@ aprintf :: proc(fmt: string, #no_capture args: ..any, allocator := context.alloc
// Returns: A formatted string. The returned string must be freed accordingly.
//
@(require_results)
aprintfln :: proc(fmt: string, #no_capture args: ..any, allocator := context.allocator) -> string {
aprintfln :: proc(fmt: string, args: ..any, allocator := context.allocator) -> string {
return aprintf(fmt, ..args, allocator=allocator, newline=true)
}
// Creates a formatted string
@@ -188,7 +188,7 @@ aprintfln :: proc(fmt: string, #no_capture args: ..any, allocator := context.all
// Returns: A formatted string.
//
@(require_results)
tprint :: proc(#no_capture args: ..any, sep := " ") -> string {
tprint :: proc(args: ..any, sep := " ") -> string {
str: strings.Builder
strings.builder_init(&str, context.temp_allocator)
return sbprint(&str, ..args, sep=sep)
@@ -204,7 +204,7 @@ tprint :: proc(#no_capture args: ..any, sep := " ") -> string {
// Returns: A formatted string with a newline character at the end.
//
@(require_results)
tprintln :: proc(#no_capture args: ..any, sep := " ") -> string {
tprintln :: proc(args: ..any, sep := " ") -> string {
str: strings.Builder
strings.builder_init(&str, context.temp_allocator)
return sbprintln(&str, ..args, sep=sep)
@@ -221,7 +221,7 @@ tprintln :: proc(#no_capture args: ..any, sep := " ") -> string {
// Returns: A formatted string.
//
@(require_results)
tprintf :: proc(fmt: string, #no_capture args: ..any, newline := false) -> string {
tprintf :: proc(fmt: string, args: ..any, newline := false) -> string {
str: strings.Builder
strings.builder_init(&str, context.temp_allocator)
return sbprintf(&str, fmt, ..args, newline=newline)
@@ -237,7 +237,7 @@ tprintf :: proc(fmt: string, #no_capture args: ..any, newline := false) -> strin
// Returns: A formatted string.
//
@(require_results)
tprintfln :: proc(fmt: string, #no_capture args: ..any) -> string {
tprintfln :: proc(fmt: string, args: ..any) -> string {
return tprintf(fmt, ..args, newline=true)
}
// Creates a formatted string using a supplied buffer as the backing array. Writes into the buffer.
@@ -249,7 +249,7 @@ tprintfln :: proc(fmt: string, #no_capture args: ..any) -> string {
//
// Returns: A formatted string
//
bprint :: proc(buf: []byte, #no_capture args: ..any, sep := " ") -> string {
bprint :: proc(buf: []byte, args: ..any, sep := " ") -> string {
sb := strings.builder_from_bytes(buf)
return sbprint(&sb, ..args, sep=sep)
}
@@ -262,7 +262,7 @@ bprint :: proc(buf: []byte, #no_capture args: ..any, sep := " ") -> string {
//
// Returns: A formatted string with a newline character at the end
//
bprintln :: proc(buf: []byte, #no_capture args: ..any, sep := " ") -> string {
bprintln :: proc(buf: []byte, args: ..any, sep := " ") -> string {
sb := strings.builder_from_bytes(buf)
return sbprintln(&sb, ..args, sep=sep)
}
@@ -276,7 +276,7 @@ bprintln :: proc(buf: []byte, #no_capture args: ..any, sep := " ") -> string {
//
// Returns: A formatted string
//
bprintf :: proc(buf: []byte, fmt: string, #no_capture args: ..any, newline := false) -> string {
bprintf :: proc(buf: []byte, fmt: string, args: ..any, newline := false) -> string {
sb := strings.builder_from_bytes(buf)
return sbprintf(&sb, fmt, ..args, newline=newline)
}
@@ -289,7 +289,7 @@ bprintf :: proc(buf: []byte, fmt: string, #no_capture args: ..any, newline := fa
//
// Returns: A formatted string
//
bprintfln :: proc(buf: []byte, fmt: string, #no_capture args: ..any) -> string {
bprintfln :: proc(buf: []byte, fmt: string, args: ..any) -> string {
return bprintf(buf, fmt, ..args, newline=true)
}
// Runtime assertion with a formatted message
@@ -301,14 +301,14 @@ bprintfln :: proc(buf: []byte, fmt: string, #no_capture args: ..any) -> string {
// - loc: The location of the caller
//
@(disabled=ODIN_DISABLE_ASSERT)
assertf :: proc(condition: bool, fmt: string, #no_capture args: ..any, loc := #caller_location) {
assertf :: proc(condition: bool, fmt: string, args: ..any, loc := #caller_location) {
if !condition {
// NOTE(dragos): We are using the same trick as in builtin.assert
// to improve performance to make the CPU not
// execute speculatively, making it about an order of
// magnitude faster
@(cold)
internal :: proc(loc: runtime.Source_Code_Location, fmt: string, #no_capture args: ..any) {
internal :: proc(loc: runtime.Source_Code_Location, fmt: string, args: ..any) {
p := context.assertion_failure_proc
if p == nil {
p = runtime.default_assertion_failure_proc
@@ -326,7 +326,7 @@ assertf :: proc(condition: bool, fmt: string, #no_capture args: ..any, loc := #c
// - args: A variadic list of arguments to be formatted
// - loc: The location of the caller
//
panicf :: proc(fmt: string, #no_capture args: ..any, loc := #caller_location) -> ! {
panicf :: proc(fmt: string, args: ..any, loc := #caller_location) -> ! {
p := context.assertion_failure_proc
if p == nil {
p = runtime.default_assertion_failure_proc
@@ -346,7 +346,7 @@ panicf :: proc(fmt: string, #no_capture args: ..any, loc := #caller_location) ->
// Returns: A formatted C string
//
@(require_results)
caprintf :: proc(format: string, #no_capture args: ..any, newline := false) -> cstring {
caprintf :: proc(format: string, args: ..any, newline := false) -> cstring {
str: strings.Builder
strings.builder_init(&str)
sbprintf(&str, format, ..args, newline=newline)
@@ -365,7 +365,7 @@ caprintf :: proc(format: string, #no_capture args: ..any, newline := false) -> c
// Returns: A formatted C string
//
@(require_results)
caprintfln :: proc(format: string, #no_capture args: ..any) -> cstring {
caprintfln :: proc(format: string, args: ..any) -> cstring {
return caprintf(format, ..args, newline=true)
}
// Creates a formatted C string
@@ -379,7 +379,7 @@ caprintfln :: proc(format: string, #no_capture args: ..any) -> cstring {
// Returns: A formatted C string.
//
@(require_results)
ctprint :: proc(#no_capture args: ..any, sep := " ") -> cstring {
ctprint :: proc(args: ..any, sep := " ") -> cstring {
str: strings.Builder
strings.builder_init(&str, context.temp_allocator)
sbprint(&str, ..args, sep=sep)
@@ -399,7 +399,7 @@ ctprint :: proc(#no_capture args: ..any, sep := " ") -> cstring {
// Returns: A formatted C string
//
@(require_results)
ctprintf :: proc(format: string, #no_capture args: ..any, newline := false) -> cstring {
ctprintf :: proc(format: string, args: ..any, newline := false) -> cstring {
str: strings.Builder
strings.builder_init(&str, context.temp_allocator)
sbprintf(&str, format, ..args, newline=newline)
@@ -418,7 +418,7 @@ ctprintf :: proc(format: string, #no_capture args: ..any, newline := false) -> c
// Returns: A formatted C string
//
@(require_results)
ctprintfln :: proc(format: string, #no_capture args: ..any) -> cstring {
ctprintfln :: proc(format: string, args: ..any) -> cstring {
return ctprintf(format, ..args, newline=true)
}
// Formats using the default print settings and writes to the given strings.Builder
@@ -430,7 +430,7 @@ ctprintfln :: proc(format: string, #no_capture args: ..any) -> cstring {
//
// Returns: A formatted string
//
sbprint :: proc(buf: ^strings.Builder, #no_capture args: ..any, sep := " ") -> string {
sbprint :: proc(buf: ^strings.Builder, args: ..any, sep := " ") -> string {
wprint(strings.to_writer(buf), ..args, sep=sep, flush=true)
return strings.to_string(buf^)
}
@@ -443,7 +443,7 @@ sbprint :: proc(buf: ^strings.Builder, #no_capture args: ..any, sep := " ") -> s
//
// Returns: The resulting formatted string
//
sbprintln :: proc(buf: ^strings.Builder, #no_capture args: ..any, sep := " ") -> string {
sbprintln :: proc(buf: ^strings.Builder, args: ..any, sep := " ") -> string {
wprintln(strings.to_writer(buf), ..args, sep=sep, flush=true)
return strings.to_string(buf^)
}
@@ -457,7 +457,7 @@ sbprintln :: proc(buf: ^strings.Builder, #no_capture args: ..any, sep := " ") ->
//
// Returns: The resulting formatted string
//
sbprintf :: proc(buf: ^strings.Builder, fmt: string, #no_capture args: ..any, newline := false) -> string {
sbprintf :: proc(buf: ^strings.Builder, fmt: string, args: ..any, newline := false) -> string {
wprintf(strings.to_writer(buf), fmt, ..args, flush=true, newline=newline)
return strings.to_string(buf^)
}
@@ -469,7 +469,7 @@ sbprintf :: proc(buf: ^strings.Builder, fmt: string, #no_capture args: ..any, ne
//
// Returns: A formatted string
//
sbprintfln :: proc(buf: ^strings.Builder, format: string, #no_capture args: ..any) -> string {
sbprintfln :: proc(buf: ^strings.Builder, format: string, args: ..any) -> string {
return sbprintf(buf, format, ..args, newline=true)
}
// Formats and writes to an io.Writer using the default print settings
@@ -481,7 +481,7 @@ sbprintfln :: proc(buf: ^strings.Builder, format: string, #no_capture args: ..an
//
// Returns: The number of bytes written
//
wprint :: proc(w: io.Writer, #no_capture args: ..any, sep := " ", flush := true) -> int {
wprint :: proc(w: io.Writer, args: ..any, sep := " ", flush := true) -> int {
fi: Info
fi.writer = w
@@ -522,7 +522,7 @@ wprint :: proc(w: io.Writer, #no_capture args: ..any, sep := " ", flush := true)
//
// Returns: The number of bytes written
//
wprintln :: proc(w: io.Writer, #no_capture args: ..any, sep := " ", flush := true) -> int {
wprintln :: proc(w: io.Writer, args: ..any, sep := " ", flush := true) -> int {
fi: Info
fi.writer = w
@@ -549,11 +549,11 @@ wprintln :: proc(w: io.Writer, #no_capture args: ..any, sep := " ", flush := tru
//
// Returns: The number of bytes written
//
wprintf :: proc(w: io.Writer, fmt: string, #no_capture args: ..any, flush := true, newline := false) -> int {
wprintf :: proc(w: io.Writer, fmt: string, args: ..any, flush := true, newline := false) -> int {
MAX_CHECKED_ARGS :: 64
assert(len(args) <= MAX_CHECKED_ARGS, "number of args > 64 is unsupported")
parse_options :: proc(fi: ^Info, fmt: string, index, end: int, unused_args: ^bit_set[0 ..< MAX_CHECKED_ARGS], #no_capture args: ..any) -> int {
parse_options :: proc(fi: ^Info, fmt: string, index, end: int, unused_args: ^bit_set[0 ..< MAX_CHECKED_ARGS], args: ..any) -> int {
i := index
// Prefix
@@ -809,7 +809,7 @@ wprintf :: proc(w: io.Writer, fmt: string, #no_capture args: ..any, flush := tru
//
// Returns: The number of bytes written.
//
wprintfln :: proc(w: io.Writer, format: string, #no_capture args: ..any, flush := true) -> int {
wprintfln :: proc(w: io.Writer, format: string, args: ..any, flush := true) -> int {
return wprintf(w, format, ..args, flush=flush, newline=true)
}
// Writes a ^runtime.Type_Info value to an io.Writer
+12 -12
View File
@@ -43,7 +43,7 @@ fd_to_writer :: proc(fd: os.Handle, loc := #caller_location) -> io.Writer {
}
// fprint formats using the default print settings and writes to fd
fprint :: proc(fd: os.Handle, #no_capture args: ..any, sep := " ", flush := true, loc := #caller_location) -> int {
fprint :: proc(fd: os.Handle, args: ..any, sep := " ", flush := true, loc := #caller_location) -> int {
buf: [1024]byte
b: bufio.Writer
defer bufio.writer_flush(&b)
@@ -54,7 +54,7 @@ fprint :: proc(fd: os.Handle, #no_capture args: ..any, sep := " ", flush := true
}
// fprintln formats using the default print settings and writes to fd
fprintln :: proc(fd: os.Handle, #no_capture args: ..any, sep := " ", flush := true, loc := #caller_location) -> int {
fprintln :: proc(fd: os.Handle, args: ..any, sep := " ", flush := true, loc := #caller_location) -> int {
buf: [1024]byte
b: bufio.Writer
defer bufio.writer_flush(&b)
@@ -66,7 +66,7 @@ fprintln :: proc(fd: os.Handle, #no_capture args: ..any, sep := " ", flush := tr
}
// fprintf formats according to the specified format string and writes to fd
fprintf :: proc(fd: os.Handle, fmt: string, #no_capture args: ..any, flush := true, newline := false, loc := #caller_location) -> int {
fprintf :: proc(fd: os.Handle, fmt: string, args: ..any, flush := true, newline := false, loc := #caller_location) -> int {
buf: [1024]byte
b: bufio.Writer
defer bufio.writer_flush(&b)
@@ -78,24 +78,24 @@ fprintf :: proc(fd: os.Handle, fmt: string, #no_capture args: ..any, flush := tr
}
// fprintfln formats according to the specified format string and writes to fd, followed by a newline.
fprintfln :: proc(fd: os.Handle, fmt: string, #no_capture args: ..any, flush := true, loc := #caller_location) -> int {
fprintfln :: proc(fd: os.Handle, fmt: string, args: ..any, flush := true, loc := #caller_location) -> int {
return fprintf(fd, fmt, ..args, flush=flush, newline=true, loc=loc)
}
// print formats using the default print settings and writes to stdout
print :: proc(#no_capture args: ..any, sep := " ", flush := true) -> int { return wprint(w=stdout, args=args, sep=sep, flush=flush) }
print :: proc(args: ..any, sep := " ", flush := true) -> int { return wprint(w=stdout, args=args, sep=sep, flush=flush) }
// println formats using the default print settings and writes to stdout
println :: proc(#no_capture args: ..any, sep := " ", flush := true) -> int { return wprintln(w=stdout, args=args, sep=sep, flush=flush) }
println :: proc(args: ..any, sep := " ", flush := true) -> int { return wprintln(w=stdout, args=args, sep=sep, flush=flush) }
// printf formats according to the specififed format string and writes to stdout
printf :: proc(fmt: string, #no_capture args: ..any, flush := true) -> int { return wprintf(stdout, fmt, ..args, flush=flush) }
printf :: proc(fmt: string, args: ..any, flush := true) -> int { return wprintf(stdout, fmt, ..args, flush=flush) }
// printfln formats according to the specified format string and writes to stdout, followed by a newline.
printfln :: proc(fmt: string, #no_capture args: ..any, flush := true) -> int { return wprintf(stdout, fmt, ..args, flush=flush, newline=true) }
printfln :: proc(fmt: string, args: ..any, flush := true) -> int { return wprintf(stdout, fmt, ..args, flush=flush, newline=true) }
// eprint formats using the default print settings and writes to stderr
eprint :: proc(#no_capture args: ..any, sep := " ", flush := true) -> int { return wprint(w=stderr, args=args, sep=sep, flush=flush) }
eprint :: proc(args: ..any, sep := " ", flush := true) -> int { return wprint(w=stderr, args=args, sep=sep, flush=flush) }
// eprintln formats using the default print settings and writes to stderr
eprintln :: proc(#no_capture args: ..any, sep := " ", flush := true) -> int { return wprintln(w=stderr, args=args, sep=sep, flush=flush) }
eprintln :: proc(args: ..any, sep := " ", flush := true) -> int { return wprintln(w=stderr, args=args, sep=sep, flush=flush) }
// eprintf formats according to the specififed format string and writes to stderr
eprintf :: proc(fmt: string, #no_capture args: ..any, flush := true) -> int { return wprintf(stderr, fmt, ..args, flush=flush) }
eprintf :: proc(fmt: string, args: ..any, flush := true) -> int { return wprintf(stderr, fmt, ..args, flush=flush) }
// eprintfln formats according to the specified format string and writes to stderr, followed by a newline.
eprintfln :: proc(fmt: string, #no_capture args: ..any, flush := true) -> int { return wprintf(stdout, fmt, ..args, flush=flush, newline=true) }
eprintfln :: proc(fmt: string, args: ..any, flush := true) -> int { return wprintf(stdout, fmt, ..args, flush=flush, newline=true) }
+12 -12
View File
@@ -9,7 +9,7 @@ import "core:io"
import "core:bufio"
// fprint formats using the default print settings and writes to fd
fprint :: proc(fd: os.Handle, #no_capture args: ..any, sep := " ", flush := true) -> int {
fprint :: proc(fd: os.Handle, args: ..any, sep := " ", flush := true) -> int {
buf: [1024]byte
b: bufio.Writer
defer bufio.writer_flush(&b)
@@ -20,7 +20,7 @@ fprint :: proc(fd: os.Handle, #no_capture args: ..any, sep := " ", flush := true
}
// fprintln formats using the default print settings and writes to fd
fprintln :: proc(fd: os.Handle, #no_capture args: ..any, sep := " ", flush := true) -> int {
fprintln :: proc(fd: os.Handle, args: ..any, sep := " ", flush := true) -> int {
buf: [1024]byte
b: bufio.Writer
defer bufio.writer_flush(&b)
@@ -31,7 +31,7 @@ fprintln :: proc(fd: os.Handle, #no_capture args: ..any, sep := " ", flush := tr
return wprintln(w, ..args, sep=sep, flush=flush)
}
// fprintf formats according to the specified format string and writes to fd
fprintf :: proc(fd: os.Handle, fmt: string, #no_capture args: ..any, flush := true, newline := false) -> int {
fprintf :: proc(fd: os.Handle, fmt: string, args: ..any, flush := true, newline := false) -> int {
buf: [1024]byte
b: bufio.Writer
defer bufio.writer_flush(&b)
@@ -42,7 +42,7 @@ fprintf :: proc(fd: os.Handle, fmt: string, #no_capture args: ..any, flush := tr
return wprintf(w, fmt, ..args, flush=flush, newline=newline)
}
// fprintfln formats according to the specified format string and writes to fd, followed by a newline.
fprintfln :: proc(fd: os.Handle, fmt: string, #no_capture args: ..any, flush := true) -> int {
fprintfln :: proc(fd: os.Handle, fmt: string, args: ..any, flush := true) -> int {
return fprintf(fd, fmt, ..args, flush=flush, newline=true)
}
fprint_type :: proc(fd: os.Handle, info: ^runtime.Type_Info, flush := true) -> (n: int, err: io.Error) {
@@ -67,19 +67,19 @@ fprint_typeid :: proc(fd: os.Handle, id: typeid, flush := true) -> (n: int, err:
}
// print formats using the default print settings and writes to os.stdout
print :: proc(#no_capture args: ..any, sep := " ", flush := true) -> int { return fprint(os.stdout, ..args, sep=sep, flush=flush) }
print :: proc(args: ..any, sep := " ", flush := true) -> int { return fprint(os.stdout, ..args, sep=sep, flush=flush) }
// println formats using the default print settings and writes to os.stdout
println :: proc(#no_capture args: ..any, sep := " ", flush := true) -> int { return fprintln(os.stdout, ..args, sep=sep, flush=flush) }
println :: proc(args: ..any, sep := " ", flush := true) -> int { return fprintln(os.stdout, ..args, sep=sep, flush=flush) }
// printf formats according to the specified format string and writes to os.stdout
printf :: proc(fmt: string, #no_capture args: ..any, flush := true) -> int { return fprintf(os.stdout, fmt, ..args, flush=flush) }
printf :: proc(fmt: string, args: ..any, flush := true) -> int { return fprintf(os.stdout, fmt, ..args, flush=flush) }
// printfln formats according to the specified format string and writes to os.stdout, followed by a newline.
printfln :: proc(fmt: string, #no_capture args: ..any, flush := true) -> int { return fprintf(os.stdout, fmt, ..args, flush=flush, newline=true) }
printfln :: proc(fmt: string, args: ..any, flush := true) -> int { return fprintf(os.stdout, fmt, ..args, flush=flush, newline=true) }
// eprint formats using the default print settings and writes to os.stderr
eprint :: proc(#no_capture args: ..any, sep := " ", flush := true) -> int { return fprint(os.stderr, ..args, sep=sep, flush=flush) }
eprint :: proc(args: ..any, sep := " ", flush := true) -> int { return fprint(os.stderr, ..args, sep=sep, flush=flush) }
// eprintln formats using the default print settings and writes to os.stderr
eprintln :: proc(#no_capture args: ..any, sep := " ", flush := true) -> int { return fprintln(os.stderr, ..args, sep=sep, flush=flush) }
eprintln :: proc(args: ..any, sep := " ", flush := true) -> int { return fprintln(os.stderr, ..args, sep=sep, flush=flush) }
// eprintf formats according to the specified format string and writes to os.stderr
eprintf :: proc(fmt: string, #no_capture args: ..any, flush := true) -> int { return fprintf(os.stderr, fmt, ..args, flush=flush) }
eprintf :: proc(fmt: string, args: ..any, flush := true) -> int { return fprintf(os.stderr, fmt, ..args, flush=flush) }
// eprintfln formats according to the specified format string and writes to os.stderr, followed by a newline.
eprintfln :: proc(fmt: string, #no_capture args: ..any, flush := true) -> int { return fprintf(os.stderr, fmt, ..args, flush=flush, newline=true) }
eprintfln :: proc(fmt: string, args: ..any, flush := true) -> int { return fprintf(os.stderr, fmt, ..args, flush=flush, newline=true) }