mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-06 02:34:05 +00:00
Merge pull request #3508 from Feoramund/fmt-alloc-print-reqres
Require results for non-buffered `print` procs
This commit is contained in:
@@ -120,11 +120,11 @@ register_user_formatter :: proc(id: typeid, formatter: User_Formatter) -> Regist
|
||||
//
|
||||
// Returns: A formatted string.
|
||||
//
|
||||
@(require_results)
|
||||
aprint :: proc(args: ..any, sep := " ", allocator := context.allocator) -> string {
|
||||
str: strings.Builder
|
||||
strings.builder_init(&str, allocator)
|
||||
sbprint(&str, ..args, sep=sep)
|
||||
return strings.to_string(str)
|
||||
return sbprint(&str, ..args, sep=sep)
|
||||
}
|
||||
// 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.
|
||||
//
|
||||
@(require_results)
|
||||
aprintln :: proc(args: ..any, sep := " ", allocator := context.allocator) -> string {
|
||||
str: strings.Builder
|
||||
strings.builder_init(&str, allocator)
|
||||
sbprintln(&str, ..args, sep=sep)
|
||||
return strings.to_string(str)
|
||||
return sbprintln(&str, ..args, sep=sep)
|
||||
}
|
||||
// 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.
|
||||
//
|
||||
@(require_results)
|
||||
aprintf :: proc(fmt: string, args: ..any, allocator := context.allocator, newline := false) -> string {
|
||||
str: strings.Builder
|
||||
strings.builder_init(&str, allocator)
|
||||
sbprintf(&str, fmt, ..args, newline=newline)
|
||||
return strings.to_string(str)
|
||||
return sbprintf(&str, fmt, ..args, newline=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.
|
||||
//
|
||||
@(require_results)
|
||||
aprintfln :: proc(fmt: string, args: ..any, allocator := context.allocator) -> string {
|
||||
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.
|
||||
//
|
||||
@(require_results)
|
||||
tprint :: proc(args: ..any, sep := " ") -> string {
|
||||
str: strings.Builder
|
||||
strings.builder_init(&str, context.temp_allocator)
|
||||
sbprint(&str, ..args, sep=sep)
|
||||
return strings.to_string(str)
|
||||
return sbprint(&str, ..args, sep=sep)
|
||||
}
|
||||
// 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.
|
||||
//
|
||||
@(require_results)
|
||||
tprintln :: proc(args: ..any, sep := " ") -> string {
|
||||
str: strings.Builder
|
||||
strings.builder_init(&str, context.temp_allocator)
|
||||
sbprintln(&str, ..args, sep=sep)
|
||||
return strings.to_string(str)
|
||||
return sbprintln(&str, ..args, sep=sep)
|
||||
}
|
||||
// Creates a formatted string using a format string and arguments
|
||||
//
|
||||
@@ -215,11 +216,11 @@ tprintln :: proc(args: ..any, sep := " ") -> string {
|
||||
//
|
||||
// Returns: A formatted string.
|
||||
//
|
||||
@(require_results)
|
||||
tprintf :: proc(fmt: string, args: ..any, newline := false) -> string {
|
||||
str: strings.Builder
|
||||
strings.builder_init(&str, context.temp_allocator)
|
||||
sbprintf(&str, fmt, ..args, newline=newline)
|
||||
return strings.to_string(str)
|
||||
return sbprintf(&str, fmt, ..args, newline=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.
|
||||
//
|
||||
@(require_results)
|
||||
tprintfln :: proc(fmt: string, args: ..any) -> string {
|
||||
return tprintf(fmt, ..args, newline=true)
|
||||
}
|
||||
@@ -339,6 +341,7 @@ panicf :: proc(fmt: string, args: ..any, loc := #caller_location) -> ! {
|
||||
//
|
||||
// Returns: A formatted C string
|
||||
//
|
||||
@(require_results)
|
||||
caprintf :: proc(format: string, args: ..any, newline := false) -> cstring {
|
||||
str: strings.Builder
|
||||
strings.builder_init(&str)
|
||||
@@ -357,6 +360,7 @@ caprintf :: proc(format: string, args: ..any, newline := false) -> cstring {
|
||||
//
|
||||
// Returns: A formatted C string
|
||||
//
|
||||
@(require_results)
|
||||
caprintfln :: proc(format: string, args: ..any) -> cstring {
|
||||
return caprintf(format, ..args, newline=true)
|
||||
}
|
||||
@@ -371,6 +375,7 @@ caprintfln :: proc(format: string, args: ..any) -> cstring {
|
||||
//
|
||||
// Returns: A formatted C string
|
||||
//
|
||||
@(require_results)
|
||||
ctprintf :: proc(format: string, args: ..any, newline := false) -> cstring {
|
||||
str: strings.Builder
|
||||
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
|
||||
//
|
||||
@(require_results)
|
||||
ctprintfln :: proc(format: string, args: ..any) -> cstring {
|
||||
return ctprintf(format, ..args, newline=true)
|
||||
}
|
||||
|
||||
@@ -2385,7 +2385,7 @@ matrix_type :: proc() {
|
||||
|
||||
c := a * b
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user