From 01bbd981adccc63e9934a2ad7760985d029d6807 Mon Sep 17 00:00:00 2001 From: samwega Date: Fri, 3 Oct 2025 20:54:18 +0300 Subject: [PATCH 1/6] short C names deprecated (itoa, ftoa), C reimplementations of atoi and atof deprecated as parse_int() and parse_f64() are preferable --- core/strconv/deprecated.odin | 24 +++++++++++++++ core/strconv/strconv.odin | 60 ++++-------------------------------- 2 files changed, 30 insertions(+), 54 deletions(-) diff --git a/core/strconv/deprecated.odin b/core/strconv/deprecated.odin index 883822e4b..20cd2642e 100644 --- a/core/strconv/deprecated.odin +++ b/core/strconv/deprecated.odin @@ -36,3 +36,27 @@ append_u128 :: proc(buf: []byte, u: u128, base: int) -> string { append_float :: proc(buf: []byte, f: f64, fmt: byte, prec, bit_size: int) -> string { return write_float(buf, f, fmt, prec, bit_size) } + +// 2025-10-03 Deprecated C short names and implementations + +@(deprecated="Use int_to_string instead") +itoa :: proc(buf: []byte, i: int) -> string { + return write_int(buf, i64(i), 10) +} + +@(deprecated="Use strconv.parse_int() instead") +atoi :: proc(s: string) -> int { + v, _ := parse_int(s) + return v +} + +@(deprecated="Use parse_f64() instead") +atof :: proc(s: string) -> f64 { + v, _ := parse_f64(s) + return v +} + +@(deprecated="Use write_float instead") +ftoa :: proc(buf: []byte, f: f64, fmt: byte, prec, bit_size: int) -> string { + return string(generic_ftoa(buf, f, fmt, prec, bit_size)) +} \ No newline at end of file diff --git a/core/strconv/strconv.odin b/core/strconv/strconv.odin index 652da1adb..e7de67c42 100644 --- a/core/strconv/strconv.odin +++ b/core/strconv/strconv.odin @@ -1547,6 +1547,8 @@ write_u128 :: proc(buf: []byte, u: u128, base: int) -> string { } /* +`itoa` C name deprecated, use `int_to_string` instead (same procedure) + Converts an integer value to a string and stores it in the given buffer **Inputs** @@ -1557,9 +1559,9 @@ Example: import "core:fmt" import "core:strconv" - itoa_example :: proc() { + int_to_string_example :: proc() { buf: [4]byte - result := strconv.itoa(buf[:], 42) + result := strconv.int_to_string(buf[:], 42) fmt.println(result, buf) // "42" } @@ -1570,62 +1572,12 @@ Output: **Returns** - The resulting string after converting the integer value */ -itoa :: proc(buf: []byte, i: int) -> string { +int_to_string :: proc(buf: []byte, i: int) -> string { return write_int(buf, i64(i), 10) } /* -Converts a string to an integer value +`ftoa` C name deprecated, use `int_to_string` instead (same procedure) -**Inputs** -- s: The string to be converted - -Example: - - import "core:fmt" - import "core:strconv" - atoi_example :: proc() { - fmt.println(strconv.atoi("42")) - } - -Output: - - 42 - -**Returns** -- The resulting integer value -*/ -atoi :: proc(s: string) -> int { - v, _ := parse_int(s) - return v -} -/* -Converts a string to a float64 value - -**Inputs** -- s: The string to be converted - -Example: - - import "core:fmt" - import "core:strconv" - atof_example :: proc() { - fmt.printfln("%.3f", strconv.atof("3.14")) - } - -Output: - - 3.140 - -**Returns** -- The resulting float64 value after converting the string -*/ -atof :: proc(s: string) -> f64 { - v, _ := parse_f64(s) - return v -} -// Alias to `write_float` -ftoa :: write_float -/* Writes a float64 value as a string to the given buffer with the specified format and precision **Inputs** From 2af3f280bf232274d8f5aa32b7f3ded53e0b5061 Mon Sep 17 00:00:00 2001 From: samwega Date: Fri, 3 Oct 2025 21:14:00 +0300 Subject: [PATCH 2/6] Tetralux asked for int_tostring() to also be deprecated, use write_int() instead. --- core/strconv/deprecated.odin | 6 +++--- core/strconv/strconv.odin | 29 ----------------------------- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/core/strconv/deprecated.odin b/core/strconv/deprecated.odin index 20cd2642e..c644d331e 100644 --- a/core/strconv/deprecated.odin +++ b/core/strconv/deprecated.odin @@ -39,7 +39,7 @@ append_float :: proc(buf: []byte, f: f64, fmt: byte, prec, bit_size: int) -> str // 2025-10-03 Deprecated C short names and implementations -@(deprecated="Use int_to_string instead") +@(deprecated="Use strconv.write_int() instead") itoa :: proc(buf: []byte, i: int) -> string { return write_int(buf, i64(i), 10) } @@ -50,13 +50,13 @@ atoi :: proc(s: string) -> int { return v } -@(deprecated="Use parse_f64() instead") +@(deprecated="Use strconv.parse_f64() instead") atof :: proc(s: string) -> f64 { v, _ := parse_f64(s) return v } -@(deprecated="Use write_float instead") +@(deprecated="Use strconv.write_float() instead") ftoa :: proc(buf: []byte, f: f64, fmt: byte, prec, bit_size: int) -> string { return string(generic_ftoa(buf, f, fmt, prec, bit_size)) } \ No newline at end of file diff --git a/core/strconv/strconv.odin b/core/strconv/strconv.odin index e7de67c42..8680542ee 100644 --- a/core/strconv/strconv.odin +++ b/core/strconv/strconv.odin @@ -1546,35 +1546,6 @@ write_u128 :: proc(buf: []byte, u: u128, base: int) -> string { return write_bits_128(buf, u, base, false, 8*size_of(uint), digits, nil) } -/* -`itoa` C name deprecated, use `int_to_string` instead (same procedure) - -Converts an integer value to a string and stores it in the given buffer - -**Inputs** -- buf: The buffer to store the resulting string -- i: The integer value to be converted - -Example: - - import "core:fmt" - import "core:strconv" - int_to_string_example :: proc() { - buf: [4]byte - result := strconv.int_to_string(buf[:], 42) - fmt.println(result, buf) // "42" - } - -Output: - - 42 [52, 50, 0, 0] - -**Returns** -- The resulting string after converting the integer value -*/ -int_to_string :: proc(buf: []byte, i: int) -> string { - return write_int(buf, i64(i), 10) -} /* `ftoa` C name deprecated, use `int_to_string` instead (same procedure) From bbf297f2653cc565da932277b99c929e1e399faf Mon Sep 17 00:00:00 2001 From: samwega Date: Fri, 3 Oct 2025 21:18:38 +0300 Subject: [PATCH 3/6] fix: copy/paste error --- core/strconv/strconv.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/strconv/strconv.odin b/core/strconv/strconv.odin index 8680542ee..7fcb578f7 100644 --- a/core/strconv/strconv.odin +++ b/core/strconv/strconv.odin @@ -1547,7 +1547,7 @@ write_u128 :: proc(buf: []byte, u: u128, base: int) -> string { } /* -`ftoa` C name deprecated, use `int_to_string` instead (same procedure) +`ftoa` C name deprecated, use `write_float` instead (same procedure) Writes a float64 value as a string to the given buffer with the specified format and precision From 83d36451a334f500a15eb6e8b55a810fbd5681d3 Mon Sep 17 00:00:00 2001 From: samwega Date: Fri, 3 Oct 2025 22:13:03 +0300 Subject: [PATCH 4/6] os_linux.odin was using itoa, changed to use write_int() --- core/os/os_linux.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin index 15d230820..1b53183c2 100644 --- a/core/os/os_linux.odin +++ b/core/os/os_linux.odin @@ -908,7 +908,7 @@ _dup :: proc(fd: Handle) -> (Handle, Error) { @(require_results) absolute_path_from_handle :: proc(fd: Handle) -> (string, Error) { buf : [256]byte - fd_str := strconv.itoa( buf[:], cast(int)fd ) + fd_str := strconv.write_int( buf[:], cast(int)fd, 10 ) procfs_path := strings.concatenate( []string{ "/proc/self/fd/", fd_str } ) defer delete(procfs_path) From 9e9d41ddfd30257006f66709f2ba0222381c615d Mon Sep 17 00:00:00 2001 From: samwega Date: Fri, 3 Oct 2025 22:17:25 +0300 Subject: [PATCH 5/6] fix: cars i64 instead of int --- core/os/os_linux.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin index 1b53183c2..f0f9b401c 100644 --- a/core/os/os_linux.odin +++ b/core/os/os_linux.odin @@ -908,7 +908,7 @@ _dup :: proc(fd: Handle) -> (Handle, Error) { @(require_results) absolute_path_from_handle :: proc(fd: Handle) -> (string, Error) { buf : [256]byte - fd_str := strconv.write_int( buf[:], cast(int)fd, 10 ) + fd_str := strconv.write_int( buf[:], cast(i64)fd, 10 ) procfs_path := strings.concatenate( []string{ "/proc/self/fd/", fd_str } ) defer delete(procfs_path) From 9da10dece2da04ab47771fa66e2f4e355573d891 Mon Sep 17 00:00:00 2001 From: samwega Date: Fri, 3 Oct 2025 22:26:24 +0300 Subject: [PATCH 6/6] fix: another itoa() used in path_linux.odin had to be replaced with write_int() --- core/os/os2/path_linux.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/os/os2/path_linux.odin b/core/os/os2/path_linux.odin index 8b185f419..1c9927843 100644 --- a/core/os/os2/path_linux.odin +++ b/core/os/os2/path_linux.odin @@ -199,7 +199,7 @@ _get_full_path :: proc(fd: linux.Fd, allocator: runtime.Allocator) -> (fullpath: buf: [32]u8 copy(buf[:], PROC_FD_PATH) - strconv.itoa(buf[len(PROC_FD_PATH):], int(fd)) + strconv.write_int(buf[len(PROC_FD_PATH):], i64(fd), 10) if fullpath, err = _read_link_cstr(cstring(&buf[0]), allocator); err != nil || fullpath[0] != '/' { delete(fullpath, allocator)