Merge pull request #3508 from Feoramund/fmt-alloc-print-reqres

Require results for non-buffered `print` procs
This commit is contained in:
gingerBill
2024-04-29 12:04:58 +01:00
committed by GitHub
2 changed files with 19 additions and 13 deletions
+18 -12
View File
@@ -120,11 +120,11 @@ register_user_formatter :: proc(id: typeid, formatter: User_Formatter) -> Regist
// //
// Returns: A formatted string. // Returns: A formatted string.
// //
@(require_results)
aprint :: proc(args: ..any, sep := " ", allocator := context.allocator) -> string { aprint :: proc(args: ..any, sep := " ", allocator := context.allocator) -> string {
str: strings.Builder str: strings.Builder
strings.builder_init(&str, allocator) strings.builder_init(&str, allocator)
sbprint(&str, ..args, sep=sep) return sbprint(&str, ..args, sep=sep)
return strings.to_string(str)
} }
// Creates a formatted string with a newline character at the end // Creates a formatted string with a newline character at the end
// //
@@ -136,11 +136,11 @@ aprint :: proc(args: ..any, sep := " ", allocator := context.allocator) -> strin
// //
// Returns: A formatted string with a newline character at the end. // Returns: A formatted string with a newline character at the end.
// //
@(require_results)
aprintln :: proc(args: ..any, sep := " ", allocator := context.allocator) -> string { aprintln :: proc(args: ..any, sep := " ", allocator := context.allocator) -> string {
str: strings.Builder str: strings.Builder
strings.builder_init(&str, allocator) strings.builder_init(&str, allocator)
sbprintln(&str, ..args, sep=sep) return sbprintln(&str, ..args, sep=sep)
return strings.to_string(str)
} }
// Creates a formatted string using a format string and arguments // Creates a formatted string using a format string and arguments
// //
@@ -153,11 +153,11 @@ aprintln :: proc(args: ..any, sep := " ", allocator := context.allocator) -> str
// //
// Returns: A formatted string. The returned string must be freed accordingly. // Returns: A formatted string. The returned string must be freed accordingly.
// //
@(require_results)
aprintf :: proc(fmt: string, args: ..any, allocator := context.allocator, newline := false) -> string { aprintf :: proc(fmt: string, args: ..any, allocator := context.allocator, newline := false) -> string {
str: strings.Builder str: strings.Builder
strings.builder_init(&str, allocator) strings.builder_init(&str, allocator)
sbprintf(&str, fmt, ..args, newline=newline) return sbprintf(&str, fmt, ..args, newline=newline)
return strings.to_string(str)
} }
// Creates a formatted string using a format string and arguments, followed by a newline. // Creates a formatted string using a format string and arguments, followed by a newline.
// //
@@ -169,6 +169,7 @@ aprintf :: proc(fmt: string, args: ..any, allocator := context.allocator, newlin
// //
// Returns: A formatted string. The returned string must be freed accordingly. // Returns: A formatted string. The returned string must be freed accordingly.
// //
@(require_results)
aprintfln :: proc(fmt: string, args: ..any, allocator := context.allocator) -> string { aprintfln :: proc(fmt: string, args: ..any, allocator := context.allocator) -> string {
return aprintf(fmt, ..args, allocator=allocator, newline=true) return aprintf(fmt, ..args, allocator=allocator, newline=true)
} }
@@ -182,11 +183,11 @@ aprintfln :: proc(fmt: string, args: ..any, allocator := context.allocator) -> s
// //
// Returns: A formatted string. // Returns: A formatted string.
// //
@(require_results)
tprint :: proc(args: ..any, sep := " ") -> string { tprint :: proc(args: ..any, sep := " ") -> string {
str: strings.Builder str: strings.Builder
strings.builder_init(&str, context.temp_allocator) strings.builder_init(&str, context.temp_allocator)
sbprint(&str, ..args, sep=sep) return sbprint(&str, ..args, sep=sep)
return strings.to_string(str)
} }
// Creates a formatted string with a newline character at the end // Creates a formatted string with a newline character at the end
// //
@@ -198,11 +199,11 @@ tprint :: proc(args: ..any, sep := " ") -> string {
// //
// Returns: A formatted string with a newline character at the end. // Returns: A formatted string with a newline character at the end.
// //
@(require_results)
tprintln :: proc(args: ..any, sep := " ") -> string { tprintln :: proc(args: ..any, sep := " ") -> string {
str: strings.Builder str: strings.Builder
strings.builder_init(&str, context.temp_allocator) strings.builder_init(&str, context.temp_allocator)
sbprintln(&str, ..args, sep=sep) return sbprintln(&str, ..args, sep=sep)
return strings.to_string(str)
} }
// Creates a formatted string using a format string and arguments // Creates a formatted string using a format string and arguments
// //
@@ -215,11 +216,11 @@ tprintln :: proc(args: ..any, sep := " ") -> string {
// //
// Returns: A formatted string. // Returns: A formatted string.
// //
@(require_results)
tprintf :: proc(fmt: string, args: ..any, newline := false) -> string { tprintf :: proc(fmt: string, args: ..any, newline := false) -> string {
str: strings.Builder str: strings.Builder
strings.builder_init(&str, context.temp_allocator) strings.builder_init(&str, context.temp_allocator)
sbprintf(&str, fmt, ..args, newline=newline) return sbprintf(&str, fmt, ..args, newline=newline)
return strings.to_string(str)
} }
// Creates a formatted string using a format string and arguments, followed by a newline. // Creates a formatted string using a format string and arguments, followed by a newline.
// //
@@ -231,6 +232,7 @@ tprintf :: proc(fmt: string, args: ..any, newline := false) -> string {
// //
// Returns: A formatted string. // Returns: A formatted string.
// //
@(require_results)
tprintfln :: proc(fmt: string, args: ..any) -> string { tprintfln :: proc(fmt: string, args: ..any) -> string {
return tprintf(fmt, ..args, newline=true) return tprintf(fmt, ..args, newline=true)
} }
@@ -339,6 +341,7 @@ panicf :: proc(fmt: string, args: ..any, loc := #caller_location) -> ! {
// //
// Returns: A formatted C string // Returns: A formatted C string
// //
@(require_results)
caprintf :: proc(format: string, args: ..any, newline := false) -> cstring { caprintf :: proc(format: string, args: ..any, newline := false) -> cstring {
str: strings.Builder str: strings.Builder
strings.builder_init(&str) strings.builder_init(&str)
@@ -357,6 +360,7 @@ caprintf :: proc(format: string, args: ..any, newline := false) -> cstring {
// //
// Returns: A formatted C string // Returns: A formatted C string
// //
@(require_results)
caprintfln :: proc(format: string, args: ..any) -> cstring { caprintfln :: proc(format: string, args: ..any) -> cstring {
return caprintf(format, ..args, newline=true) return caprintf(format, ..args, newline=true)
} }
@@ -371,6 +375,7 @@ caprintfln :: proc(format: string, args: ..any) -> cstring {
// //
// Returns: A formatted C string // Returns: A formatted C string
// //
@(require_results)
ctprintf :: proc(format: string, args: ..any, newline := false) -> cstring { ctprintf :: proc(format: string, args: ..any, newline := false) -> cstring {
str: strings.Builder str: strings.Builder
strings.builder_init(&str, context.temp_allocator) strings.builder_init(&str, context.temp_allocator)
@@ -389,6 +394,7 @@ ctprintf :: proc(format: string, args: ..any, newline := false) -> cstring {
// //
// Returns: A formatted C string // Returns: A formatted C string
// //
@(require_results)
ctprintfln :: proc(format: string, args: ..any) -> cstring { ctprintfln :: proc(format: string, args: ..any) -> cstring {
return ctprintf(format, ..args, newline=true) return ctprintf(format, ..args, newline=true)
} }
+1 -1
View File
@@ -2385,7 +2385,7 @@ matrix_type :: proc() {
c := a * b c := a * b
#assert(type_of(c) == matrix[2, 2]f32) #assert(type_of(c) == matrix[2, 2]f32)
fmt.tprintln("c = a * b", c) fmt.println("c = a * b", c)
} }
{ // Matrices support multiplication between matrices and arrays { // Matrices support multiplication between matrices and arrays