diff --git a/GNUmakefile b/GNUmakefile index 55a8c5b69a..07183111b8 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -258,7 +258,9 @@ BOOTSTRAP_VFLAGS := $(BOOTSTRAP_CCOMPILER_VFLAG) $(if $(strip $(BOOTSTRAP_CFLAGS all: latest_vc latest_tcc latest_legacy ifdef WIN32 - $(CC) $(CPPFLAGS) $(BOOTSTRAP_VC_CC_CFLAGS) $(VC_BOOTSTRAP_DEFINE) -std=c99 -municode -w -o v1$(EXE_EXT) $(VC)/$(VCFILE) $(LDFLAGS) -lws2_32 -lbcrypt || cmd/tools/cc_compilation_failed_windows.sh + powershell -NoProfile -ExecutionPolicy Bypass -File "$(VROOT)/cmd/tools/vc_compat_uint.ps1" -Source "$(VC)/$(VCFILE)" -Destination "$(VC)/v_win_compat.c" + $(CC) $(CPPFLAGS) $(BOOTSTRAP_VC_CC_CFLAGS) $(VC_BOOTSTRAP_DEFINE) -std=c99 -municode -w -o v1$(EXE_EXT) "$(VC)/v_win_compat.c" $(LDFLAGS) -lws2_32 -lbcrypt || cmd/tools/cc_compilation_failed_windows.sh + $(RM) "$(VC)/v_win_compat.c" ./v1$(EXE_EXT) -no-parallel -o v2$(EXE_EXT) $(BOOTSTRAP_GC_VFLAG) $(VFLAGS) $(BOOTSTRAP_VC_VFLAGS) cmd/v ./v2$(EXE_EXT) -o $(VEXE)$(EXE_EXT) $(BOOTSTRAP_GC_VFLAG) $(VFLAGS) $(BOOTSTRAP_VFLAGS) cmd/v $(RM) v1$(EXE_EXT) diff --git a/README.md b/README.md index 49c4265206..4186c386bc 100644 --- a/README.md +++ b/README.md @@ -98,10 +98,12 @@ That should be it, and you should find your V executable at `[path to V repo]/v` On Unix-like systems, `make` and the `v self` bootstrap fallback stream compatibility fixes for older `vc/v.c` snapshots to the C compiler. These match the peak RSS helper's return type -to `i64` and guard Linux-only `prctl` code. The snapshot stays unchanged on disk. +to `i64`, guard Linux-only `prctl` code, and teach pre-`uint` compilers the new integer +spelling and allocator signatures. The snapshot stays unchanged on disk. The compatibility filter uses the system `sh`; Bash is not required. -On Windows, `makev.bat` generates the first compiler stage as C and links it directly. +On Windows, builds use PowerShell to prepare a temporary snapshot with the same integer +compatibility fixes. `makev.bat` generates the first compiler stage as C and links it directly. This also works with older bootstrap snapshots whose process-spawn code is broken. Direct TCC links add the installed bundle's `thirdparty\tcc\lib\openlibm.o`, when present, for C99 math functions such as `remainder`. Each bundle ships this object for its own compiler, diff --git a/cmd/tools/makev_test.py b/cmd/tools/makev_test.py index 20b52aa6fa..73d227ba3d 100644 --- a/cmd/tools/makev_test.py +++ b/cmd/tools/makev_test.py @@ -29,6 +29,15 @@ def routine(name: str) -> str: class BootstrapConfigurationTests(unittest.TestCase): + def test_bootstrap_prepares_a_temporary_uint_compatible_snapshot(self): + build = routine("build") + self.assertIn('vc_compat_uint.ps1" -Source "%V_C_FILE%"', build) + self.assertIn('if !ERRORLEVEL! NEQ 0 goto :error', build) + self.assertLess(build.index("vc_compat_uint.ps1"), build.index("echo Building V...")) + self.assertIn('set "V_C_FILE=%vc_dir%\\v_win_compat.c"', build) + for name in ("success", "error"): + self.assertIn('call :try_delete "%vc_dir%\\v_win_compat.c"', routine(name)) + def test_all_portable_bootstraps_select_v1(self): self.assertIn( "set VC_BOOTSTRAP_DEFINE=-DCUSTOM_DEFINE_v1_fallback\n", SOURCE diff --git a/cmd/tools/vc_compat.awk b/cmd/tools/vc_compat.awk index 2a77f7bfb4..784e06a198 100644 --- a/cmd/tools/vc_compat.awk +++ b/cmd/tools/vc_compat.awk @@ -1,4 +1,30 @@ # Keep the downloaded snapshot intact and stream compatibility fixes to the C compiler. +# Only the pre-uint compiler needs its primitive spelling updated. Check the +# compiler's type-ID declaration, not arbitrary strings or C qualifier IDs. +BEGIN { + while ((getline line < ARGV[1]) > 0) { + if (line ~ /^u32 flat__source_type_usize;$/) legacy_uint = 1 + if (line ~ /^u32 flat__source_type_uint;$/) native_uint = 1 + if (line ~ /^_SL\([^,]+, "(u8\* malloc_noscan\(ptrdiff_t n\);|void\* memdup\(void\* src, ptrdiff_t sz\);|void\* memdup_align\(void\* src, ptrdiff_t sz, ptrdiff_t alignment\);)",/) { + id = line + sub(/^_SL\(/, "", id) + sub(/,.*/, "", id) + allocator_prototypes[id] = 1 + } + } + close(ARGV[1]) +} + +legacy_uint && !native_uint { + gsub(/"usize", 5/, "\"uint\", 4") + # The migrated allocator declarations use int. Rewrite their codegen calls + # using the selected target type, without changing the snapshot's own ABI. + for (id in allocator_prototypes) { + sub("c__FlatGen__writeln\\(g, " id "\\);", + "c__FlatGen__writeln(g, string__replace(" id ", (string){(u8*)\"ptrdiff_t\", 9, 1}, g->int_ct));") + } +} + # Older portable snapshots return long long here but declare the function as i64. # On Linux, i64 is int64_t (long), which conflicts even though both types are 64-bit. /^(V_PEAK_RSS_SCOPE|static|static inline) long long v3_bench_peak_rss_kb\(void\)[ \t]*\{/ { diff --git a/cmd/tools/vc_compat_test.v b/cmd/tools/vc_compat_test.v index c42e137e00..ebe8dfa897 100644 --- a/cmd/tools/vc_compat_test.v +++ b/cmd/tools/vc_compat_test.v @@ -190,3 +190,43 @@ fn test_vc_compat_links_libraries_after_the_streamed_source() ! { ran := os.exec([executable]) assert ran.exit_code == 0, ran.output } + +fn test_vc_compat_bridges_only_snapshots_without_native_uint() ! { + root := os.join_path(os.vtmp_dir(), 'vc_compat_uint_${os.getpid()}') + os.mkdir_all(root)! + defer { os.rmdir_all(root) or {} } + source := os.join_path(root, 'snapshot with spaces.c') + output := os.join_path(root, 'filtered.c') + // C qualifier metadata already mentioned uint in old snapshots. It does + // not mean the compiler recognizes it as a V primitive. + legacy := 'u32 flat__source_type_usize;\nu32 types__qualify_source_type_uint;\n_SL(name, "usize", 5);\nconst string casts[] = {(string){"usize", 5, 1}};\nu8* malloc_noscan(ptrdiff_t n);\n_SL(alloc, "u8* malloc_noscan(ptrdiff_t n);", 31);\n_SL(copy, "void* memdup(void* src, ptrdiff_t sz);", 38);\n_SL(align, "void* memdup_align(void* src, ptrdiff_t sz, ptrdiff_t alignment);", 65);\nc__FlatGen__writeln(g, alloc);\nc__FlatGen__writeln(g, copy);\nc__FlatGen__writeln(g, align);\nconst char* embedded = "\\\"usize\\\", 5";\n' + bytes := [u8(0xff), u8(0xfe)].bytestr() + for declarations in ['', 'u32 flat__source_type_uint;\n'] { + original := declarations + legacy + 'const char* binary = "${bytes}";\n' + os.write_file(source, original)! + mut filtered := '' + $if windows { + checked := os.exec(['powershell', '-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', + os.join_path(@VEXEROOT, 'cmd', 'tools', 'vc_compat_uint.ps1'), '-Source', source, + '-Destination', output]) + assert checked.exit_code == 0, checked.output + filtered = os.read_file(output)! + } $else { + _ = output + checked := os.exec(['env', 'LC_ALL=C', 'awk', '-f', + os.join_path(@VEXEROOT, 'cmd', 'tools', 'vc_compat.awk'), source]) + assert checked.exit_code == 0, checked.output + filtered = checked.output + } + expected := if declarations == '' { + original.replace('"usize", 5', '"uint", 4') + .replace('c__FlatGen__writeln(g, alloc);', 'c__FlatGen__writeln(g, string__replace(alloc, (string){(u8*)"ptrdiff_t", 9, 1}, g->int_ct));') + .replace('c__FlatGen__writeln(g, copy);', 'c__FlatGen__writeln(g, string__replace(copy, (string){(u8*)"ptrdiff_t", 9, 1}, g->int_ct));') + .replace('c__FlatGen__writeln(g, align);', 'c__FlatGen__writeln(g, string__replace(align, (string){(u8*)"ptrdiff_t", 9, 1}, g->int_ct));') + } else { + original + } + assert filtered == expected + assert os.read_file(source)! == original + } +} diff --git a/cmd/tools/vc_compat_uint.ps1 b/cmd/tools/vc_compat_uint.ps1 new file mode 100644 index 0000000000..8aa71e2a7e --- /dev/null +++ b/cmd/tools/vc_compat_uint.ps1 @@ -0,0 +1,21 @@ +# Keep downloaded snapshots intact, including string literals with non-UTF-8 bytes. +param( + [Parameter(Mandatory = $true)][string]$Source, + [Parameter(Mandatory = $true)][string]$Destination +) +$ErrorActionPreference = 'Stop' +$encoding = [Text.Encoding]::GetEncoding(28591) +$text = [IO.File]::ReadAllText($Source, $encoding) +if ($text -match '(?m)^u32 flat__source_type_usize;\r?$' -and + $text -notmatch '(?m)^u32 flat__source_type_uint;\r?$') { + $text = $text.Replace('"usize", 5', '"uint", 4') + # Rewrite codegen calls using the selected target's integer type. The + # snapshot's interned strings and its own allocator ABI remain unchanged. + $prototypes = '(?m)^_SL\(([^,]+), "(?:u8\* malloc_noscan\(ptrdiff_t n\);|void\* memdup\(void\* src, ptrdiff_t sz\);|void\* memdup_align\(void\* src, ptrdiff_t sz, ptrdiff_t alignment\);)",' + foreach ($match in [regex]::Matches($text, $prototypes)) { + $id = $match.Groups[1].Value + $text = $text.Replace("c__FlatGen__writeln(g, $id);", + ('c__FlatGen__writeln(g, string__replace(' + $id + ', (string){(u8*)"ptrdiff_t", 9, 1}, g->int_ct));')) + } +} +[IO.File]::WriteAllText($Destination, $text, $encoding) diff --git a/cmd/tools/vcover/write_tests.v b/cmd/tools/vcover/write_tests.v index cb0287bf1d..0f1a596132 100644 --- a/cmd/tools/vcover/write_tests.v +++ b/cmd/tools/vcover/write_tests.v @@ -44,7 +44,7 @@ fn test_file_for(source string) string { fn zero_value_for(typ string) ?string { t := typ.trim_space() if t in ['int', 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'byte', 'rune', 'isize', - 'usize'] { + 'uint', 'usize'] { return '0' } if t in ['f32', 'f64'] { diff --git a/cmd/tools/vfmt_test.v b/cmd/tools/vfmt_test.v index b01b37bb3b..a19248da71 100644 --- a/cmd/tools/vfmt_test.v +++ b/cmd/tools/vfmt_test.v @@ -1214,11 +1214,11 @@ fn test_fmt_preserves_legacy_dollar_builtins_with_v3() { } fn test_fmt_preserves_bodyless_function_prefixes_with_v3() { - source := 'fn plain(value usize) usize\nfn C.c_call(value int) int\nfn JS.js_call(value int) int\n' + source := 'fn plain(value uint) uint\nfn C.c_call(value int) int\nfn JS.js_call(value int) int\n' res, formatted := run_vfmt_write('bodyless_function_prefixes', source, '') assert res.exit_code == 0, res.output - assert formatted.contains('fn plain(value usize) usize'), formatted + assert formatted.contains('fn plain(value uint) uint'), formatted assert formatted.contains('fn C.c_call(value int) int'), formatted assert formatted.contains('fn JS.js_call(value int) int'), formatted assert !formatted.contains('fn C.plain'), formatted diff --git a/cmd/tools/vpbgen/namer.v b/cmd/tools/vpbgen/namer.v index f2a0b1ce06..4364a400a0 100644 --- a/cmd/tools/vpbgen/namer.v +++ b/cmd/tools/vpbgen/namer.v @@ -226,7 +226,7 @@ pub fn map_entry_read_fn_name(v_name string, field string) string { pub fn zero_value(v_type string) string { return match v_type { 'i8', 'i16', 'int', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'isize', - 'usize', 'rune' { + 'uint', 'usize', 'rune' { '${v_type}(0)' } 'f32' { 'f32(0)' } diff --git a/cmd/tools/vpbgen/namer_test.v b/cmd/tools/vpbgen/namer_test.v index 4fbeaf1a7d..b8d5d37c38 100644 --- a/cmd/tools/vpbgen/namer_test.v +++ b/cmd/tools/vpbgen/namer_test.v @@ -106,7 +106,7 @@ fn test_zero_value() { assert zero_value('int') == 'int(0)' assert zero_value('i32') == 'i32(0)' assert zero_value('u64') == 'u64(0)' - assert zero_value('usize') == 'usize(0)' + assert zero_value('uint') == 'uint(0)' assert zero_value('rune') == 'rune(0)' assert zero_value('f32') == 'f32(0)' assert zero_value('f64') == 'f64(0)' diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index a71bb8c480..7ccff83e6f 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -641,8 +641,8 @@ fn repl_literal_is_negated(line string, start int) bool { // repl_literal_carries_its_type reports whether the literal is already the argument of a // conversion, since the type that conversion names is the one that governs. fn repl_literal_carries_its_type(line string, start int) bool { - names := ['u8', 'u16', 'u32', 'u64', 'u128', 'i8', 'i16', 'i32', 'i64', 'i128', 'int', 'usize', - 'isize', 'rune', 'char', 'f32', 'f64'] + names := ['u8', 'u16', 'u32', 'u64', 'u128', 'i8', 'i16', 'i32', 'i64', 'i128', 'int', 'uint', + 'usize', 'isize', 'rune', 'char', 'f32', 'f64'] mut k := start - 1 for k >= 0 && line[k] == ` ` { k-- diff --git a/cmd/tools/vself.v b/cmd/tools/vself.v index 3d083da84f..e911595ab0 100644 --- a/cmd/tools/vself.v +++ b/cmd/tools/vself.v @@ -707,10 +707,25 @@ fn bootstrap_self_build(vroot string, args []string, final_binary string) ! { os.rm(bootstrap_v1) or {} os.rm(bootstrap_v2) or {} } - vc_source := os.join_path(vroot, 'vc', if os.user_os() == 'windows' { 'v_win.c' } else { 'v.c' }) + mut vc_source := os.join_path(vroot, 'vc', if os.user_os() == 'windows' { + 'v_win.c' + } else { + 'v.c' + }) if !os.exists(vc_source) { return error('bootstrap fallback failed: `${vc_source}` is missing') } + compat_source := os.join_path(vroot, 'vc', 'v_self_compat.c') + defer { + if os.user_os() == 'windows' { + os.rm(compat_source) or {} + } + } + if os.user_os() == 'windows' { + filter := os.join_path(vroot, 'cmd', 'tools', 'vc_compat_uint.ps1') + run_cmd('powershell -NoProfile -ExecutionPolicy Bypass -File ${os.quoted_path(filter)} -Source ${os.quoted_path(vc_source)} -Destination ${os.quoted_path(compat_source)}')! + vc_source = compat_source + } cc := os.getenv_opt('CC') or { if os.user_os() == 'windows' { 'gcc' } else { 'cc' } } diff --git a/doc/c_and_v_type_interoperability.md b/doc/c_and_v_type_interoperability.md index b0e4a202ef..f61abb7af5 100644 --- a/doc/c_and_v_type_interoperability.md +++ b/doc/c_and_v_type_interoperability.md @@ -22,18 +22,17 @@ V `char`, `&char`, or `charptr` when you need to match C `char`, `char*`, or `char**`. -* A V `isize` is equivalent to C `ssize_t`. -It is a signed integer, and `isize` is guaranteed to be at least 16 bits. -It is 32 bit on 32 bit platforms, and 64 bits on 64 bit ones. +* A V `int` is a platform-width signed integer: 32 bits on 32-bit targets and +64 bits on 64-bit targets. -* A V `usize` is equivalent to C `size_t`. -It is an unsigned integer, and `usize` is guaranteed to be at least 16 bits. -It is 32 bit on 32 bit platforms, and 64 bits on 64 bit ones. +* A V `uint` is a platform-width unsigned integer, equivalent to C `size_t` or `uintptr_t`. +It is 32 bits on 32-bit targets and 64 bits on 64-bit targets. -* A V `int` is currently equivalent to C `int`, or `int64_t`. -There are plans to make it equivalent to `isize`, so if you want to write C -library wrappers, it is better to describe your `fn C.` parameters using `i32` -instead of using `int`. +`isize` and `usize` are deprecated. Use `int` and `uint`, respectively. +For C library wrappers, use `i32` for C `int` parameters, fields, and return values. +Plain `int` in a `fn C.` signature retains the C `int` ABI for compatibility. +Use `C.ptrdiff_t` for signed pointer-width parameters and return values, including C +`intptr_t`, `ptrdiff_t`, and `ssize_t`. It is an alias of V `int` that preserves the C ABI. ## Representing pointers in C and V: @@ -49,7 +48,7 @@ unsigned char func_name(int * p, index int); ... then you can represent its function signature in V like this: ```v ignore -fn C.func_name(p &int, index i32) u8 +fn C.func_name(p &i32, index i32) u8 ``` For a C output parameter, pass the address of the variable or struct field that C should update. @@ -71,7 +70,7 @@ in a `.c.v` file, and mark a C typedef with `@[typedef]`. For example, ```v ignore @[typedef] struct C.Foo { - x int + x i32 } ``` diff --git a/doc/c_backend_headers.md b/doc/c_backend_headers.md index bc02bea138..8fcb799426 100644 --- a/doc/c_backend_headers.md +++ b/doc/c_backend_headers.md @@ -13,7 +13,7 @@ runtime even for literal output. Native execution must be validated on each platform; generating C for a target alone does not verify its runtime ABI. The compiler's string literals can contain the text of includes for other generated programs. The C backend emits libc prototypes from bodyless V declarations such as -`fn C.strlen(const_s &char) usize`. Without system headers, this includes the bindings that a +`fn C.strlen(const_s &char) uint`. Without system headers, this includes the bindings that a program declares itself, such as `fn C.getpgrp() int` or a Win32 function in Windows C, which nothing else would declare. Runtime bindings are marked used so cached modules retain their prototypes. Native backends retain C declarations without rooting same-named diff --git a/doc/docs.md b/doc/docs.md index 1e2c58bd76..4ab481e602 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -718,15 +718,15 @@ bool string -i8 i16 int i64 i128 +i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 +int, uint // platform-width signed and unsigned integers + rune // represents a Unicode code point f32 f64 -isize, usize // platform-dependent, the size is how many bytes it takes to reference any location in memory - voidptr // this one is mostly used for [C interoperability](#v-and-c) ``` @@ -734,6 +734,11 @@ voidptr // this one is mostly used for [C interoperability](#v-and-c) > `int` is a platform-width signed integer: 64 bits on 64-bit targets and 32 bits on 32-bit > targets. Use `i32` or `i64` when you need a fixed width. > Integer literal casts to `int` are checked against the target platform's width. +> `uint` has the same width and is unsigned. + +`isize` and `usize` are deprecated. Replace `isize` with `int` and `usize` with `uint`. +Use `uint` for pointer addresses and C `size_t` values to preserve +the full unsigned range. Existing spellings still compile with deprecation warnings. ### 128-bit integers @@ -5037,7 +5042,7 @@ They are just a convenient way to write `i.some_function()` instead of a convenience for writing `s.xyz()` instead of `xyz(s)`. An immediate read-only interface method call on a smart-casted value can return -a scalar, including `char`, `rune`, `isize`, `usize`, or an enum. +a scalar, including `char`, `rune`, `int`, `uint`, or an enum. Receiver methods are also available through embedded interfaces. A mutable receiver method updates the underlying concrete object's mutable fields, including when called through an @@ -9367,7 +9372,7 @@ V supports the following compile time types: - `$enum` => matches [Enums](#enums). - `$float` => matches `f32`, `f64` and float literals. - `$function` => matches [Function Types](#function-types). -- `$int` => matches `int`, `i8`, `i16`, `i32`, `i64`, `u8`, `u16`, `u32`, `u64`, `isize`, `usize` +- `$int` => matches `int`, `i8`, `i16`, `i32`, `i64`, `u8`, `u16`, `u32`, `u64`, `uint` and integer literals. - `$interface` => matches [Interfaces](#interfaces). - `$map` => matches [Maps](#maps). @@ -11233,7 +11238,7 @@ pub struct C.SomeCStruct { // union { // struct { data voidptr - size usize + size uint // } view C.DataView // } diff --git a/doc/language/c2v-scalar-expressions.md b/doc/language/c2v-scalar-expressions.md index ed32875730..779a244c68 100644 --- a/doc/language/c2v-scalar-expressions.md +++ b/doc/language/c2v-scalar-expressions.md @@ -2,7 +2,7 @@ In `@[translated]` files, boolean values can index arrays and pointers. Boolean, character, and enum values can offset pointers in arithmetic and compound assignments. -Subtracting two pointers produces a pointer-width `isize` difference. +Subtracting two pointers produces a pointer-width `int` difference. Mixed boolean and numeric conditional branches retain the numeric branch type. Narrow integer shifts use C's minimum 32-bit operand width. Shifts of translated `int` values use C's 32-bit `int` width. diff --git a/editors/vim/syntax/v.vim b/editors/vim/syntax/v.vim index 57b2a96009..2579d4a506 100644 --- a/editors/vim/syntax/v.vim +++ b/editors/vim/syntax/v.vim @@ -31,7 +31,7 @@ syn match vNumber /\v<\d[\d_]*([eE][+-]?\d[\d_]*)?>/ syn keyword vBoolean true false syn keyword vConstant none nil syn keyword vKeyword as asm assert atomic break const continue defer else enum false for fn __global go goto if import in interface is match module mut shared lock rlock none nil return select sizeof isreftype _likely_ _unlikely_ __offsetof struct true type typeof dump or union pub static volatile unsafe spawn implements like ilike -syn keyword vType bool string rune i8 i16 int i64 i128 isize u8 u16 u32 u64 u128 usize f32 f64 char map chan any voidptr byteptr charptr +syn keyword vType bool string rune i8 i16 i32 int i64 i128 isize u8 u16 u32 u64 u128 uint usize f32 f64 char map chan any voidptr byteptr charptr syn match vComptime /\$[A-Za-z_][A-Za-z0-9_]*/ syn match vComptime /@[A-Z_][A-Z0-9_]*/ diff --git a/examples/1brc/solution/main.v b/examples/1brc/solution/main.v index b6de680feb..0ef09aa88d 100644 --- a/examples/1brc/solution/main.v +++ b/examples/1brc/solution/main.v @@ -5,11 +5,11 @@ import os #include -fn C.mmap(addr voidptr, len usize, prot i32, flags i32, fd i32, offset i64) voidptr -fn C.munmap(addr voidptr, len usize) i32 +fn C.mmap(addr voidptr, len uint, prot i32, flags i32, fd i32, offset i64) voidptr +fn C.munmap(addr voidptr, len uint) i32 struct MemoryMappedFile { - size usize + size uint mut: data &u8 file os.File @@ -18,7 +18,7 @@ mut: fn mmap_file(path string) MemoryMappedFile { mut mf := MemoryMappedFile{ file: os.open_file(path, 'r', 0) or { panic('fail') } - size: usize(os.file_size(path)) + size: uint(os.file_size(path)) data: unsafe { nil } } diff --git a/examples/c_interop_wkhtmltopdf.v b/examples/c_interop_wkhtmltopdf.v index 618c301faa..352857cfd9 100644 --- a/examples/c_interop_wkhtmltopdf.v +++ b/examples/c_interop_wkhtmltopdf.v @@ -48,7 +48,7 @@ fn C.wkhtmltopdf_convert(converter &C.wkhtmltopdf_converter) i32 fn C.wkhtmltopdf_http_error_code(converter &C.wkhtmltopdf_converter) i32 -fn C.wkhtmltopdf_get_output(converter &C.wkhtmltopdf_converter, const_data &&u8) isize +fn C.wkhtmltopdf_get_output(converter &C.wkhtmltopdf_converter, const_data &&u8) C.ptrdiff_t fn main() { // init diff --git a/examples/gg/multiwindow_services.v b/examples/gg/multiwindow_services.v index 2d0952b87c..d26b0fb4bf 100644 --- a/examples/gg/multiwindow_services.v +++ b/examples/gg/multiwindow_services.v @@ -186,22 +186,22 @@ fn inspect_native_window(mut app gg.App, window gg.WindowId) ! { match backend { .win32 { lease.with_win32(fn (hwnd voidptr) ! { - println('borrowed HWND=${usize(hwnd):x}') + println('borrowed HWND=${uint(hwnd):x}') })! } .appkit { lease.with_appkit(fn (ns_window voidptr) ! { - println('borrowed NSWindow=${usize(ns_window):x}') + println('borrowed NSWindow=${uint(ns_window):x}') })! } .x11 { lease.with_x11(fn (display voidptr, xwindow u64) ! { - println('borrowed Display=${usize(display):x} Window=${xwindow:x}') + println('borrowed Display=${uint(display):x} Window=${xwindow:x}') })! } .wayland { lease.with_wayland(fn (display voidptr, surface voidptr) ! { - println('borrowed wl_display=${usize(display):x} wl_surface=${usize(surface):x}') + println('borrowed wl_display=${uint(display):x} wl_surface=${uint(surface):x}') })! } .auto, .mock {} diff --git a/examples/sokol/01_cubes/cube.v b/examples/sokol/01_cubes/cube.v index bb1fc98583..3eba52da9d 100644 --- a/examples/sokol/01_cubes/cube.v +++ b/examples/sokol/01_cubes/cube.v @@ -42,7 +42,7 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) { // comment, if .dynamic is enabled img_desc.data.subimage[0][0] = gfx.Range{ ptr: buf - size: usize(sz) + size: uint(sz) } sg_img := gfx.make_image(&img_desc) diff --git a/examples/sokol/02_cubes_glsl/cube_glsl.v b/examples/sokol/02_cubes_glsl/cube_glsl.v index 9c7555fc9f..2f145d4ea2 100644 --- a/examples/sokol/02_cubes_glsl/cube_glsl.v +++ b/examples/sokol/02_cubes_glsl/cube_glsl.v @@ -66,7 +66,7 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) { // comment if .dynamic is enabled img_desc.data.subimage[0][0] = gfx.Range{ ptr: buf - size: usize(sz) + size: uint(sz) } sg_img := gfx.make_image(&img_desc) @@ -287,10 +287,10 @@ fn init_cube_glsl(mut app App) { } unsafe { vmemset(&vert_buffer_desc, 0, int(sizeof(vert_buffer_desc))) } - vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t))) + vert_buffer_desc.size = uint(vertices.len * int(sizeof(Vertex_t))) vert_buffer_desc.data = gfx.Range{ ptr: vertices.data - size: usize(vertices.len * int(sizeof(Vertex_t))) + size: uint(vertices.len * int(sizeof(Vertex_t))) } vert_buffer_desc.type = .vertexbuffer @@ -314,10 +314,10 @@ fn init_cube_glsl(mut app App) { } unsafe { vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc))) } - index_buffer_desc.size = usize(indices.len * int(sizeof(u16))) + index_buffer_desc.size = uint(indices.len * int(sizeof(u16))) index_buffer_desc.data = gfx.Range{ ptr: indices.data - size: usize(indices.len * int(sizeof(u16))) + size: uint(indices.len * int(sizeof(u16))) } index_buffer_desc.type = .indexbuffer @@ -393,7 +393,7 @@ fn draw_cube_glsl(app App) { // res is a 4x4 matrix of f32 thus: 4*16 byte of size vs_uniforms_range := gfx.Range{ ptr: unsafe { &tr_matrix } - size: usize(4 * 16) + size: uint(4 * 16) } gfx.apply_uniforms(.vs, C.SLOT_vs_params, &vs_uniforms_range) @@ -407,7 +407,7 @@ fn draw_cube_glsl(app App) { ]! fs_uniforms_range := gfx.Range{ ptr: unsafe { &text_res } - size: usize(4 * 4) + size: uint(4 * 4) } gfx.apply_uniforms(.fs, C.SLOT_fs_params, &fs_uniforms_range) diff --git a/examples/sokol/03_march_tracing_glsl/rt_glsl.v b/examples/sokol/03_march_tracing_glsl/rt_glsl.v index b397bdb59d..38a3b4a158 100644 --- a/examples/sokol/03_march_tracing_glsl/rt_glsl.v +++ b/examples/sokol/03_march_tracing_glsl/rt_glsl.v @@ -69,7 +69,7 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) { // comment if .dynamic is enabled img_desc.data.subimage[0][0] = gfx.Range{ ptr: buf - size: usize(sz) + size: uint(sz) } sg_img := gfx.make_image(&img_desc) @@ -154,10 +154,10 @@ fn init_cube_glsl(mut app App) { } unsafe { vmemset(&vert_buffer_desc, 0, int(sizeof(vert_buffer_desc))) } - vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t))) + vert_buffer_desc.size = uint(vertices.len * int(sizeof(Vertex_t))) vert_buffer_desc.data = gfx.Range{ ptr: vertices.data - size: usize(vertices.len * int(sizeof(Vertex_t))) + size: uint(vertices.len * int(sizeof(Vertex_t))) } vert_buffer_desc.type = .vertexbuffer @@ -180,10 +180,10 @@ fn init_cube_glsl(mut app App) { } unsafe { vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc))) } - index_buffer_desc.size = usize(indices.len * int(sizeof(u16))) + index_buffer_desc.size = uint(indices.len * int(sizeof(u16))) index_buffer_desc.data = gfx.Range{ ptr: indices.data - size: usize(indices.len * int(sizeof(u16))) + size: uint(indices.len * int(sizeof(u16))) } index_buffer_desc.type = .indexbuffer @@ -269,7 +269,7 @@ fn draw_cube_glsl(app App) { // res is a 4x4 matrix of f32 thus: 4*16 byte of size vs_uniforms_range := gfx.Range{ ptr: unsafe { &tr_matrix } - size: usize(4 * 16) + size: uint(4 * 16) } gfx.apply_uniforms(.vs, C.SLOT_vs_params, &vs_uniforms_range) @@ -287,7 +287,7 @@ fn draw_cube_glsl(app App) { ]! fs_uniforms_range := gfx.Range{ ptr: unsafe { &tmp_fs_params } - size: usize(sizeof(tmp_fs_params)) + size: uint(sizeof(tmp_fs_params)) } gfx.apply_uniforms(.fs, C.SLOT_fs_params, &fs_uniforms_range) diff --git a/examples/sokol/04_multi_shader_glsl/rt_glsl.v b/examples/sokol/04_multi_shader_glsl/rt_glsl.v index 8ada2dc36d..8150e5a302 100644 --- a/examples/sokol/04_multi_shader_glsl/rt_glsl.v +++ b/examples/sokol/04_multi_shader_glsl/rt_glsl.v @@ -53,7 +53,7 @@ fn create_texture(w int, h int, buf byteptr) (gfx.Image, gfx.Sampler) { } img_desc.data.subimage[0][0] = gfx.Range{ ptr: buf - size: usize(sz) + size: uint(sz) } sg_img := gfx.make_image(&img_desc) mut smp_desc := gfx.SamplerDesc{ @@ -111,7 +111,7 @@ fn (mut app App) init_glsl_shader(shader_name string, shader_desc &gfx.ShaderDes mut vert_buffer_desc := gfx.BufferDesc{} unsafe { vmemset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) } vert_buffer_desc.label = c'cube-vertices' - vert_buffer_desc.size = usize(vertices.len) * sizeof(Vertex_t) + vert_buffer_desc.size = uint(vertices.len) * sizeof(Vertex_t) vert_buffer_desc.data = gfx.Range{ ptr: vertices.data size: vert_buffer_desc.size @@ -122,7 +122,7 @@ fn (mut app App) init_glsl_shader(shader_name string, shader_desc &gfx.ShaderDes mut index_buffer_desc := gfx.BufferDesc{} unsafe { vmemset(&index_buffer_desc, 0, sizeof(index_buffer_desc)) } index_buffer_desc.label = c'cube-indices' - index_buffer_desc.size = usize(indices.len) * sizeof(u16) + index_buffer_desc.size = uint(indices.len) * sizeof(u16) index_buffer_desc.data = gfx.Range{ ptr: indices.data size: index_buffer_desc.size @@ -196,7 +196,7 @@ fn (app &App) draw_glsl_shader(shader_name string) { // res is a 4x4 matrix of f32 thus: 4*16 byte of size vs_uniforms_range := gfx.Range{ ptr: unsafe { &tr_matrix } - size: usize(4 * 16) + size: uint(4 * 16) } gfx.apply_uniforms(.vs, C.SLOT_vs_params_m, &vs_uniforms_range) @@ -216,7 +216,7 @@ fn (app &App) draw_glsl_shader(shader_name string) { ]! fs_uniforms_range := gfx.Range{ ptr: unsafe { &tmp_fs_params } - size: usize(sizeof(tmp_fs_params)) + size: uint(sizeof(tmp_fs_params)) } gfx.apply_uniforms(.fs, C.SLOT_fs_params_p, &fs_uniforms_range) diff --git a/examples/sokol/05_instancing_glsl/rt_glsl.v b/examples/sokol/05_instancing_glsl/rt_glsl.v index 89867a6617..28a16292c0 100644 --- a/examples/sokol/05_instancing_glsl/rt_glsl.v +++ b/examples/sokol/05_instancing_glsl/rt_glsl.v @@ -81,7 +81,7 @@ fn create_texture(w int, h int, buf byteptr) (gfx.Image, gfx.Sampler) { // comment if .dynamic is enabled img_desc.data.subimage[0][0] = gfx.Range{ ptr: buf - size: usize(sz) + size: uint(sz) } sg_img := gfx.make_image(&img_desc) @@ -166,10 +166,10 @@ fn init_cube_glsl_i(mut app App) { label: c'cube-vertices' } unsafe { vmemset(&vert_buffer_desc, 0, int(sizeof(vert_buffer_desc))) } - vert_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t))) + vert_buffer_desc.size = uint(vertices.len * int(sizeof(Vertex_t))) vert_buffer_desc.data = gfx.Range{ ptr: vertices.data - size: usize(vertices.len * int(sizeof(Vertex_t))) + size: uint(vertices.len * int(sizeof(Vertex_t))) } vert_buffer_desc.type = .vertexbuffer vbuf := gfx.make_buffer(&vert_buffer_desc) @@ -180,7 +180,7 @@ fn init_cube_glsl_i(mut app App) { } unsafe { vmemset(&inst_buffer_desc, 0, int(sizeof(inst_buffer_desc))) } - inst_buffer_desc.size = usize(num_inst * int(sizeof(m4.Vec4))) + inst_buffer_desc.size = uint(num_inst * int(sizeof(m4.Vec4))) inst_buffer_desc.type = .vertexbuffer inst_buffer_desc.usage = .stream inst_buf := gfx.make_buffer(&inst_buffer_desc) @@ -201,10 +201,10 @@ fn init_cube_glsl_i(mut app App) { label: c'cube-indices' } unsafe { vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc))) } - index_buffer_desc.size = usize(indices.len * int(sizeof(u16))) + index_buffer_desc.size = uint(indices.len * int(sizeof(u16))) index_buffer_desc.data = gfx.Range{ ptr: indices.data - size: usize(indices.len * int(sizeof(u16))) + size: uint(indices.len * int(sizeof(u16))) } index_buffer_desc.type = .indexbuffer ibuf := gfx.make_buffer(&index_buffer_desc) @@ -316,7 +316,7 @@ fn draw_cube_glsl_i(mut app App) { } range := gfx.Range{ ptr: unsafe { &app.inst_pos } - size: usize(num_inst * int(sizeof(m4.Vec4))) + size: uint(num_inst * int(sizeof(m4.Vec4))) } gfx.update_buffer(app.bind['inst'].vertex_buffers[1], &range) @@ -326,7 +326,7 @@ fn draw_cube_glsl_i(mut app App) { // res is a 4x4 matrix of f32 thus: 4*16 byte of size vs_uniforms_range := gfx.Range{ ptr: unsafe { &tr_matrix } - size: usize(4 * 16) + size: uint(4 * 16) } gfx.apply_uniforms(.vs, C.SLOT_vs_params_i, &vs_uniforms_range) @@ -346,7 +346,7 @@ fn draw_cube_glsl_i(mut app App) { // vfmt on fs_uniforms_range := gfx.Range{ ptr: unsafe { &tmp_fs_params } - size: usize(sizeof(tmp_fs_params)) + size: uint(sizeof(tmp_fs_params)) } gfx.apply_uniforms(.fs, C.SLOT_fs_params, &fs_uniforms_range) */ diff --git a/examples/sokol/06_obj_viewer/obj/rend.v b/examples/sokol/06_obj_viewer/obj/rend.v index f2cdd9ac0e..0d964d6d69 100644 --- a/examples/sokol/06_obj_viewer/obj/rend.v +++ b/examples/sokol/06_obj_viewer/obj/rend.v @@ -35,7 +35,7 @@ pub fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) { // comment if .dynamic is enabled img_desc.data.subimage[0][0] = gfx.Range{ ptr: buf - size: usize(sz) + size: uint(sz) } sg_img := gfx.make_image(&img_desc) @@ -80,10 +80,10 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader, mut vert_buffer_desc := gfx.BufferDesc{} unsafe { vmemset(&vert_buffer_desc, 0, int(sizeof(vert_buffer_desc))) } - vert_buffer_desc.size = usize(obj_buf.vbuf.len * int(sizeof(Vertex_pnct))) + vert_buffer_desc.size = uint(obj_buf.vbuf.len * int(sizeof(Vertex_pnct))) vert_buffer_desc.data = gfx.Range{ ptr: obj_buf.vbuf.data - size: usize(obj_buf.vbuf.len * int(sizeof(Vertex_pnct))) + size: uint(obj_buf.vbuf.len * int(sizeof(Vertex_pnct))) } vert_buffer_desc.type = .vertexbuffer @@ -94,10 +94,10 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader, mut index_buffer_desc := gfx.BufferDesc{} unsafe { vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc))) } - index_buffer_desc.size = usize(obj_buf.ibuf.len * int(sizeof(u32))) + index_buffer_desc.size = uint(obj_buf.ibuf.len * int(sizeof(u32))) index_buffer_desc.data = gfx.Range{ ptr: obj_buf.ibuf.data - size: usize(obj_buf.ibuf.len * int(sizeof(u32))) + size: uint(obj_buf.ibuf.len * int(sizeof(u32))) } index_buffer_desc.type = .indexbuffer @@ -244,11 +244,11 @@ pub fn (obj_part ObjPart) bind_and_draw(rend_data_index int, in_data Shader_data vs_uniforms_range := gfx.Range{ ptr: in_data.vs_data - size: usize(in_data.vs_len) + size: uint(in_data.vs_len) } fs_uniforms_range := gfx.Range{ ptr: unsafe { &tmp_fs_params } - size: usize(in_data.fs_len) + size: uint(in_data.fs_len) } gfx.apply_uniforms(.vs, C.SLOT_vs_params, &vs_uniforms_range) diff --git a/examples/sokol/07_simple_shader_glsl/simple_shader.v b/examples/sokol/07_simple_shader_glsl/simple_shader.v index 19a45d9b39..fe7c605062 100644 --- a/examples/sokol/07_simple_shader_glsl/simple_shader.v +++ b/examples/sokol/07_simple_shader_glsl/simple_shader.v @@ -98,7 +98,7 @@ fn init(user_data voidptr) { } unsafe { vmemset(&vertex_buffer_desc, 0, int(sizeof(vertex_buffer_desc))) } - vertex_buffer_desc.size = usize(vertices.len * int(sizeof(Vertex_t))) + vertex_buffer_desc.size = uint(vertices.len * int(sizeof(Vertex_t))) vertex_buffer_desc.data = gfx.Range{ ptr: vertices.data size: vertex_buffer_desc.size diff --git a/examples/viewer/main.v b/examples/viewer/main.v index b250f0d196..81b1b74e01 100644 --- a/examples/viewer/main.v +++ b/examples/viewer/main.v @@ -169,7 +169,7 @@ fn make_rgba_texture(w int, h int, rgba []u8) gfx.Image { } desc.data.subimage[0][0] = gfx.Range{ ptr: rgba.data - size: usize(w * h * 4) + size: uint(w * h * 4) } return gfx.make_image(&desc) } diff --git a/makev.bat b/makev.bat index 3921aba4e1..8071a47906 100644 --- a/makev.bat +++ b/makev.bat @@ -171,6 +171,11 @@ if !flag_local! NEQ 1 ( echo. ) +REM Teach pre-uint snapshots the new spelling without changing the download. +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0cmd\tools\vc_compat_uint.ps1" -Source "%V_C_FILE%" -Destination "%vc_dir%\v_win_compat.c" +if !ERRORLEVEL! NEQ 0 goto :error +set "V_C_FILE=%vc_dir%\v_win_compat.c" + echo Building V... if not [!compiler!] == [] goto :!compiler!_strap @@ -385,12 +390,14 @@ echo Backend compiler error goto :error :error +call :try_delete "%vc_dir%\v_win_compat.c" echo. echo Exiting from error echo ERROR: please follow the instructions in https://github.com/vlang/v/wiki/Installing-a-C-compiler-on-Windows exit /b 1 :success +call :try_delete "%vc_dir%\v_win_compat.c" "%V_EXE%" run cmd/tools/detect_tcc.v if !ERRORLEVEL! NEQ 0 exit /b !ERRORLEVEL! echo ^> V built successfully! diff --git a/vlib/arena/arena.c.v b/vlib/arena/arena.c.v index 10da60550e..ab3f734150 100644 --- a/vlib/arena/arena.c.v +++ b/vlib/arena/arena.c.v @@ -39,7 +39,7 @@ pub fn new(config Config) Arena { $compile_error('module `arena` supports `-gc none` and the default Boehm GC, not `-gc vgc`') } return Arena{ - handle: unsafe { v_arena_new(isize(config.chunk_size)) } + handle: unsafe { v_arena_new(int(config.chunk_size)) } } } @@ -79,13 +79,13 @@ pub fn (mut a Arena) free() { // used returns the number of bytes allocated in `a` since it was created or // last reset. -pub fn (a &Arena) used() isize { +pub fn (a &Arena) used() int { used, _ := v_arena_stats(a.handle) return used } // capacity returns the number of bytes in the chunks that `a` holds. -pub fn (a &Arena) capacity() isize { +pub fn (a &Arena) capacity() int { _, capacity := v_arena_stats(a.handle) return capacity } diff --git a/vlib/arena/arena_test.v b/vlib/arena/arena_test.v index 532efaa30a..f397e0c7b2 100644 --- a/vlib/arena/arena_test.v +++ b/vlib/arena/arena_test.v @@ -363,7 +363,7 @@ fn test_arena_memory_is_reused_in_loops() { defer { a.free() } - mut warm_capacity := isize(0) + mut warm_capacity := int(0) for i in 0 .. 2000 { a.push() mut sb := strings.new_builder(64) diff --git a/vlib/arrays/arrays.v b/vlib/arrays/arrays.v index 233956598a..83529963b5 100644 --- a/vlib/arrays/arrays.v +++ b/vlib/arrays/arrays.v @@ -560,7 +560,7 @@ pub fn rotate_left[T](mut array []T, mid int) { k := array.len - mid p := unsafe { &T(array.data) } unsafe { - ptr_rotate[T](mid, &T(usize(voidptr(p)) + usize(sizeof(T)) * usize(mid)), k) + ptr_rotate[T](mid, &T(uint(voidptr(p)) + uint(sizeof(T)) * uint(mid)), k) } } @@ -579,24 +579,24 @@ pub fn rotate_right[T](mut array []T, k int) { mid := array.len - k p := unsafe { &T(array.data) } unsafe { - ptr_rotate[T](mid, &T(usize(voidptr(p)) + usize(sizeof(T)) * usize(mid)), k) + ptr_rotate[T](mid, &T(uint(voidptr(p)) + uint(sizeof(T)) * uint(mid)), k) } } @[unsafe] fn ptr_rotate[T](left_ int, mid &T, right_ int) { - sz := usize(sizeof(T)) - mut left := usize(left_) - mut right := usize(right_) + sz := uint(sizeof(T)) + mut left := uint(left_) + mut right := uint(right_) limit := raw_array_cap[T]() for { delta := if left < right { left } else { right } - if delta <= usize(limit) { + if delta <= uint(limit) { break } unsafe { - swap_nonoverlapping[T](&T(usize(voidptr(mid)) - left * sz), &T(usize(voidptr(mid)) + - usize(right - delta) * sz), int(delta)) + swap_nonoverlapping[T](&T(uint(voidptr(mid)) - left * sz), &T(uint(voidptr(mid)) + + uint(right - delta) * sz), int(delta)) } if left <= right { right -= delta @@ -609,15 +609,15 @@ fn ptr_rotate[T](left_ int, mid &T, right_ int) { defer { free(rawarray) } - dim := &T(usize(voidptr(mid)) - left * sz + right * sz) + dim := &T(uint(voidptr(mid)) - left * sz + right * sz) if left <= right { - vmemcpy(rawarray, voidptr(usize(voidptr(mid)) - left * sz), isize(left * sz)) - vmemmove(voidptr(usize(voidptr(mid)) - left * sz), voidptr(mid), isize(right * sz)) - vmemcpy(voidptr(dim), rawarray, isize(left * sz)) + vmemcpy(rawarray, voidptr(uint(voidptr(mid)) - left * sz), int(left * sz)) + vmemmove(voidptr(uint(voidptr(mid)) - left * sz), voidptr(mid), int(right * sz)) + vmemcpy(voidptr(dim), rawarray, int(left * sz)) } else { - vmemcpy(rawarray, voidptr(mid), isize(right * sz)) - vmemmove(voidptr(dim), voidptr(usize(voidptr(mid)) - left * sz), isize(left * sz)) - vmemcpy(voidptr(usize(voidptr(mid)) - left * sz), rawarray, isize(right * sz)) + vmemcpy(rawarray, voidptr(mid), int(right * sz)) + vmemmove(voidptr(dim), voidptr(uint(voidptr(mid)) - left * sz), int(left * sz)) + vmemcpy(voidptr(uint(voidptr(mid)) - left * sz), rawarray, int(right * sz)) } } } @@ -638,10 +638,10 @@ mut: w u64 } -const extra_size = 32 * isize(sizeof(usize)) +const extra_size = 32 * int(sizeof(uint)) -fn raw_array_cap[T]() isize { - size := isize(sizeof(T)) +fn raw_array_cap[T]() int { + size := int(sizeof(T)) if size > extra_size { return 1 } else { @@ -649,8 +649,8 @@ fn raw_array_cap[T]() isize { } } -fn raw_array_malloc_size[T]() isize { - size := isize(sizeof(T)) +fn raw_array_malloc_size[T]() int { + size := int(sizeof(T)) if size > extra_size { return size * 2 } else { @@ -659,29 +659,29 @@ fn raw_array_malloc_size[T]() isize { } @[unsafe] -fn memswap(x voidptr, y voidptr, len usize) { - block_size := isize(sizeof(Block)) +fn memswap(x voidptr, y voidptr, len uint) { + block_size := int(sizeof(Block)) - mut i := usize(0) - for i + usize(block_size) <= len { + mut i := uint(0) + for i + uint(block_size) <= len { mut t_ := Block{} t := voidptr(&t_) - xi := usize(x) + i - yi := usize(y) + i + xi := uint(x) + i + yi := uint(y) + i unsafe { vmemcpy(t, voidptr(xi), block_size) vmemcpy(voidptr(xi), voidptr(yi), block_size) vmemcpy(voidptr(yi), t, block_size) } - i += usize(block_size) + i += uint(block_size) } if i < len { mut t_ := UnalignedBlock{} t := voidptr(&t_) - rem := isize(len - i) - xi := usize(x) + i - yi := usize(y) + i + rem := int(len - i) + xi := uint(x) + i + yi := uint(y) + i unsafe { vmemcpy(t, voidptr(xi), rem) vmemcpy(voidptr(xi), voidptr(yi), rem) @@ -695,7 +695,7 @@ fn swap_nonoverlapping[T](x_ &T, y_ &T, count int) { x := voidptr(x_) y := voidptr(y_) - len := usize(sizeof(T)) * usize(count) + len := uint(sizeof(T)) * uint(count) unsafe { memswap(x, y, len) } @@ -711,12 +711,12 @@ pub fn copy[T](mut dst []T, src []T) int { return 0 } if can_copy_bits[T]() { - blen := min_len * isize(sizeof(T)) + blen := min_len * int(sizeof(T)) unsafe { vmemmove(&T(dst.data), src.data, blen) } } else { - dst_start := unsafe { usize(dst.data) } - src_start := unsafe { usize(src.data) } - copy_bytes := usize(min_len) * usize(sizeof(T)) + dst_start := unsafe { uint(dst.data) } + src_start := unsafe { uint(src.data) } + copy_bytes := uint(min_len) * uint(sizeof(T)) if dst_start > src_start && dst_start - src_start < copy_bytes { for i := min_len - 1; i >= 0; i-- { dst[i] = src[i] @@ -746,7 +746,7 @@ fn can_copy_bits[T]() bool { @[unsafe] pub fn carray_to_varray[T](c_array_data voidptr, items int) []T { mut v_array := []T{len: items} - total_size := items * isize(sizeof(T)) + total_size := items * int(sizeof(T)) unsafe { vmemcpy(v_array.data, c_array_data, total_size) } return v_array } diff --git a/vlib/builtin/README.md b/vlib/builtin/README.md index 774088c57a..82cd32be09 100644 --- a/vlib/builtin/README.md +++ b/vlib/builtin/README.md @@ -3,6 +3,9 @@ `builtin` is a module that is implicitly imported by every V program. It implements the builtin V types `array`, `string`, `map`. +`int` and `uint` use the pointer width of the target. The old `isize` and `usize` +names are deprecated in favor of `int` and `uint`. For signed pointer-width C +parameters and return values, `C.ptrdiff_t` aliases `int` and preserves the C ABI. With bounds checking enabled, `first()` and `last()` on an empty dynamic array panic with `array.first: array is empty` and `array.last: array is empty`, respectively. This also applies when writing through the returned element, such as `cells.last().field = value`. @@ -101,7 +104,7 @@ ensure no allocation from a rewound or freed scope remains in use. `prealloc_scope_allocated_size(scope)` reports the bytes in all allocation blocks owned by a scope, excluding allocator metadata and address gaps between blocks. It returns zero for a nil -scope and saturates at `usize`'s maximum on overflow. This query is unsafe: no thread may add or +scope and saturates at `uint`'s maximum on overflow. This query is unsafe: no thread may add or remove blocks while it runs. `string.replace_each(pairs)` ignores pairs with an empty search string. An empty replacement diff --git a/vlib/builtin/allocation.c.v b/vlib/builtin/allocation.c.v index d9d7076497..a27893f417 100644 --- a/vlib/builtin/allocation.c.v +++ b/vlib/builtin/allocation.c.v @@ -10,7 +10,7 @@ module builtin __global v_memory_panic = false @[noreturn] -fn _memory_panic(fname string, size isize) { +fn _memory_panic(fname string, size int) { v_memory_panic = true // Note: do not use string interpolation here at all, since string interpolation itself allocates eprint(fname) @@ -46,7 +46,7 @@ fn C.vheap_alloc(p voidptr, n u64) fn C.vheap_free(p voidptr) @[if track_heap ?] -fn _ht_alloc(p &u8, n isize) { +fn _ht_alloc(p &u8, n int) { C.vheap_alloc(p, u64(n)) } @@ -59,7 +59,7 @@ fn _ht_free(p voidptr) { // malloc returns a `byteptr` pointing to the memory address of the allocated space. // unlike the `calloc` family of functions - malloc will not zero the memory block. @[inline; unsafe] -pub fn malloc(n isize) &u8 { +pub fn malloc(n int) &u8 { $if trace_malloc ? { total_m += n C.fprintf(C.stderr, c'_v_malloc %6d total %10d\n', n, total_m) @@ -85,7 +85,7 @@ pub fn malloc(n isize) &u8 { return unsafe { prealloc_malloc(n) } } $else $if vgc ? { unsafe { - res = &u8(vgc_malloc(usize(n))) + res = &u8(vgc_malloc(uint(n))) } } $else $if gcboehm ? { unsafe { @@ -94,7 +94,7 @@ pub fn malloc(n isize) &u8 { } $else $if freestanding { // todo: is this safe to call malloc there? We export __malloc as malloc and it uses dlmalloc behind the scenes // so theoretically it is safe - res = unsafe { __malloc(usize(n)) } + res = unsafe { __malloc(uint(n)) } } $else { $if windows { // Warning! On windows, we always use _aligned_malloc to allocate memory. @@ -120,7 +120,7 @@ pub fn malloc(n isize) &u8 { // malloc_noscan allocates n bytes that do not contain garbage-collected pointers. @[inline; unsafe] -pub fn malloc_noscan(n isize) &u8 { +pub fn malloc_noscan(n int) &u8 { $if trace_malloc ? { total_m += n C.fprintf(C.stderr, c'malloc_noscan %6d total %10d\n', n, total_m) @@ -142,7 +142,7 @@ pub fn malloc_noscan(n isize) &u8 { return unsafe { prealloc_malloc(n) } } $else $if vgc ? { unsafe { - res = &u8(vgc_malloc_noscan(usize(n))) + res = &u8(vgc_malloc_noscan(uint(n))) } } $else $if gcboehm ? { $if gcboehm_opt ? { @@ -155,7 +155,7 @@ pub fn malloc_noscan(n isize) &u8 { } } } $else $if freestanding { - res = unsafe { __malloc(usize(n)) } + res = unsafe { __malloc(uint(n)) } } $else { $if windows { // Warning! On windows, we always use _aligned_malloc to allocate memory. @@ -182,7 +182,7 @@ pub fn malloc_noscan(n isize) &u8 { // String contents contain bytes only, including when a string view starts at an // unaligned offset. Keep normal allocator hooks and tracing on their existing path. @[inline; unsafe] -fn malloc_string_buffer(n isize) &u8 { +fn malloc_string_buffer(n int) &u8 { $if prealloc && !builtin_arena ?&& !trace_malloc ? { if n < 0 { _memory_panic('malloc_noscan', n) @@ -193,27 +193,27 @@ fn malloc_string_buffer(n isize) &u8 { } @[inline; unsafe] -fn malloc_uninit(n isize) &u8 { +fn malloc_uninit(n int) &u8 { if n < 0 { _memory_panic(@FN, n) } else if n == 0 { return &u8(unsafe { nil }) } $if vgc ? { - return unsafe { &u8(vgc_malloc_typed_opts(usize(n), 0, 0, false)) } + return unsafe { &u8(vgc_malloc_typed_opts(uint(n), 0, 0, false)) } } return malloc(n) } @[inline; unsafe] -fn malloc_noscan_uninit(n isize) &u8 { +fn malloc_noscan_uninit(n int) &u8 { if n < 0 { _memory_panic(@FN, n) } else if n == 0 { return &u8(unsafe { nil }) } $if vgc ? { - return unsafe { &u8(vgc_malloc_noscan_opts(usize(n), false)) } + return unsafe { &u8(vgc_malloc_noscan_opts(uint(n), false)) } } return malloc_noscan(n) } @@ -231,7 +231,7 @@ fn __at_least_one(how_many u64) u64 { // malloc_uncollectable dynamically allocates a `n` bytes block of memory // on the heap, which will NOT be garbage-collected (but its contents will). @[unsafe] -pub fn malloc_uncollectable(n isize) &u8 { +pub fn malloc_uncollectable(n int) &u8 { $if trace_malloc ? { total_m += n C.fprintf(C.stderr, c'malloc_uncollectable %6d total %10d\n', n, total_m) @@ -255,14 +255,14 @@ pub fn malloc_uncollectable(n isize) &u8 { return unsafe { prealloc_malloc(n) } } $else $if vgc ? { unsafe { - res = &u8(vgc_malloc(usize(n))) + res = &u8(vgc_malloc(uint(n))) } } $else $if gcboehm ? { unsafe { res = C.GC_MALLOC_UNCOLLECTABLE(n) } } $else $if freestanding { - res = unsafe { __malloc(usize(n)) } + res = unsafe { __malloc(uint(n)) } } $else { $if windows { // Warning! On windows, we always use _aligned_malloc to allocate memory. @@ -291,7 +291,7 @@ pub fn malloc_uncollectable(n isize) &u8 { // previously allocated with `malloc` or `vcalloc`. // Please, see also realloc_data, and use it instead if possible. @[unsafe] -pub fn v_realloc(b &u8, n isize) &u8 { +pub fn v_realloc(b &u8, n int) &u8 { $if trace_realloc ? { C.fprintf(C.stderr, c'v_realloc %6d\n', n) } @@ -312,7 +312,7 @@ pub fn v_realloc(b &u8, n isize) &u8 { } return new_ptr } $else $if vgc ? { - new_ptr = unsafe { &u8(vgc_realloc(b, usize(n))) } + new_ptr = unsafe { &u8(vgc_realloc(b, uint(n))) } } $else $if gcboehm ? { new_ptr = unsafe { C.GC_REALLOC(b, n) } } $else { @@ -384,7 +384,7 @@ pub fn realloc_data(old_data &u8, old_size int, new_size int) &u8 { } mut nptr := &u8(unsafe { nil }) $if vgc ? { - nptr = unsafe { &u8(vgc_realloc(old_data, usize(new_size))) } + nptr = unsafe { &u8(vgc_realloc(old_data, uint(new_size))) } } $else $if gcboehm ? { nptr = unsafe { C.GC_REALLOC(old_data, new_size) } } $else { @@ -399,13 +399,13 @@ pub fn realloc_data(old_data &u8, old_size int, new_size int) &u8 { } } if nptr == 0 { - _memory_panic(@FN, isize(new_size)) + _memory_panic(@FN, int(new_size)) } // realloc(nil, …) means "allocate"; don't report a free with no prior block. if old_data != unsafe { nil } { _ht_free(old_data) } - _ht_alloc(nptr, isize(new_size)) + _ht_alloc(nptr, int(new_size)) return nptr } @@ -413,7 +413,7 @@ pub fn realloc_data(old_data &u8, old_size int, new_size int) &u8 { // vcalloc returns a `byteptr` pointing to the memory address of the allocated space. // vcalloc checks for negative values given in `n`. @[inline] -pub fn vcalloc(n isize) &u8 { +pub fn vcalloc(n int) &u8 { $if trace_vcalloc ? { total_m += n C.fprintf(C.stderr, c'vcalloc %6d total %10d\n', n, total_m) @@ -436,7 +436,7 @@ pub fn vcalloc(n isize) &u8 { $if prealloc { return unsafe { prealloc_calloc(n) } } $else $if vgc ? { - return unsafe { &u8(vgc_calloc(usize(n))) } + return unsafe { &u8(vgc_calloc(uint(n))) } } $else $if gcboehm ? { return unsafe { &u8(C.GC_MALLOC(n)) } } $else { @@ -463,7 +463,7 @@ pub fn vcalloc(n isize) &u8 { // special versions of the above that allocate memory which is not scanned // for pointers (but is collected) when the Boehm garbage collection is used @[inline] -pub fn vcalloc_noscan(n isize) &u8 { +pub fn vcalloc_noscan(n int) &u8 { $if trace_vcalloc ? { total_m += n C.fprintf(C.stderr, c'vcalloc_noscan %6d total %10d\n', n, total_m) @@ -474,7 +474,7 @@ pub fn vcalloc_noscan(n isize) &u8 { if n < 0 { _memory_panic(@FN, n) } - return unsafe { &u8(vgc_calloc(usize(n))) } + return unsafe { &u8(vgc_calloc(uint(n))) } } $else $if gcboehm ? { if n < 0 { _memory_panic(@FN, n) @@ -599,7 +599,7 @@ fn free_unaliased(ptr voidptr) { // memdup then copies the contents of `src` into the allocated space and // returns a pointer to the newly allocated space. @[inline; unsafe] -pub fn memdup(src voidptr, sz isize) voidptr { +pub fn memdup(src voidptr, sz int) voidptr { $if trace_memdup ? { C.fprintf(C.stderr, c'memdup size: %10d\n', sz) } @@ -617,7 +617,7 @@ pub fn memdup(src voidptr, sz isize) voidptr { // memdup_noscan copies `sz` bytes into newly allocated pointer-free storage. @[inline; unsafe] -pub fn memdup_noscan(src voidptr, sz isize) voidptr { +pub fn memdup_noscan(src voidptr, sz int) voidptr { $if trace_memdup ? { C.fprintf(C.stderr, c'memdup_noscan size: %10d\n', sz) } @@ -638,7 +638,7 @@ pub fn memdup_noscan(src voidptr, sz isize) voidptr { // memdup_uncollectable then copies the contents of `src` into the allocated // space and returns a pointer to the newly allocated space. @[unsafe] -pub fn memdup_uncollectable(src voidptr, sz isize) voidptr { +pub fn memdup_uncollectable(src voidptr, sz int) voidptr { $if trace_memdup ? { C.fprintf(C.stderr, c'memdup_uncollectable size: %10d\n', sz) } @@ -659,7 +659,7 @@ pub fn memdup_uncollectable(src voidptr, sz isize) voidptr { // - `sz` must be non-negative // - The memory regions should not overlap @[unsafe] -pub fn memdup_align(src voidptr, sz isize, align isize) voidptr { +pub fn memdup_align(src voidptr, sz int, align int) voidptr { $if trace_memdup ? { C.fprintf(C.stderr, c'memdup_align size: %10d align: %10d\n', sz, align) } @@ -688,10 +688,10 @@ pub fn memdup_align(src voidptr, sz isize, align isize) voidptr { res = prealloc_malloc_align(n, align) } $else $if vgc ? { // VGC traces and frees interior pointers within the scanned allocation. - alignment := usize(align) - base := vgc_malloc(usize(n) + alignment - 1) + alignment := uint(align) + base := vgc_malloc(uint(n) + alignment - 1) if base != unsafe { nil } { - res = unsafe { &u8((usize(base) + alignment - 1) & ~(alignment - 1)) } + res = unsafe { &u8((uint(base) + alignment - 1) & ~(alignment - 1)) } } } $else $if gcboehm ? { unsafe { @@ -705,7 +705,7 @@ pub fn memdup_align(src voidptr, sz isize, align isize) voidptr { // todo: is this safe to call malloc there? We export __malloc as malloc and it uses dlmalloc behind the scenes // so theoretically it is safe panic('memdup_align is not implemented with -freestanding') - res = unsafe { __malloc(usize(n)) } + res = unsafe { __malloc(uint(n)) } } $else { $if windows { // Warning! On windows, we always use _aligned_malloc to allocate memory. @@ -736,11 +736,11 @@ pub fn memdup_align(src voidptr, sz isize, align isize) voidptr { // the same with `-gc boehm` and `-gc vgc`; they are 0 with `-gc none`. pub struct GCHeapUsage { pub: - heap_size usize // the heap memory obtained from the OS, without the part returned to it - free_bytes usize // the part of heap_size in free blocks - total_bytes usize // the bytes allocated since the program started - unmapped_bytes usize // free heap memory that was returned to the OS - bytes_since_gc usize // the bytes allocated since the last collection + heap_size uint // the heap memory obtained from the OS, without the part returned to it + free_bytes uint // the part of heap_size in free blocks + total_bytes uint // the bytes allocated since the program started + unmapped_bytes uint // free heap memory that was returned to the OS + bytes_since_gc uint // the bytes allocated since the last collection } // gc_heap_usage returns the info about heap usage. @@ -766,7 +766,7 @@ pub fn gc_heap_usage() GCHeapUsage { // gc_memory_use returns the total memory use in bytes by all allocated blocks: the heap_size // of gc_heap_usage() without its free_bytes. -pub fn gc_memory_use() usize { +pub fn gc_memory_use() uint { $if vgc ? { return vgc_memory_use() } $else $if gcboehm ? { diff --git a/vlib/builtin/arena_d_builtin_arena.c.v b/vlib/builtin/arena_d_builtin_arena.c.v index 06813b0195..cbd36a324a 100644 --- a/vlib/builtin/arena_d_builtin_arena.c.v +++ b/vlib/builtin/arena_d_builtin_arena.c.v @@ -21,8 +21,8 @@ module builtin // never call into this file. const arena_magic = u32(0x41524e41) -const arena_default_chunk_size = isize(64 * 1024) -const arena_max_chunk_size = isize(4 * 1024 * 1024) +const arena_default_chunk_size = int(64 * 1024) +const arena_max_chunk_size = int(4 * 1024 * 1024) // VArenaChunk is the header at the start of each arena chunk. struct VArenaChunk { @@ -44,14 +44,14 @@ mut: chunk &VArenaChunk = unsafe { nil } // serves new allocations last &u8 = unsafe { nil } // the most recent allocation below &VArena = unsafe { nil } // next arena down the thread's stack - chunk_size isize // size of the next regular chunk - max_chunk_size isize + chunk_size int // size of the next regular chunk + max_chunk_size int } struct VArenaRange { mut: - start usize - stop usize + start uint + stop uint owner &VArena = unsafe { nil } } @@ -73,8 +73,8 @@ fn C.atomic_store_ptr(voidptr, voidptr) // and nothing clears. Publishing g_arena_hooks_ready after installation makes // all three immutable hooks visible together to allocation entry points. __global g_arena_hooks_ready u32 -__global g_arena_alloc_hook fn (n isize, align isize) &u8 -__global g_arena_realloc_hook fn (old_data &u8, old_size isize, new_size isize) &u8 +__global g_arena_alloc_hook fn (n int, align int) &u8 +__global g_arena_realloc_hook fn (old_data &u8, old_size int, new_size int) &u8 __global g_arena_owns_hook fn (ptr voidptr) bool // g_arena_top is the innermost arena pushed on the current thread. It is // thread-local (see `is_builtin_arena_top` in the C backend), so spawned @@ -92,14 +92,14 @@ __global g_arena_ranges_len u32 // arena_align is the alignment of arena allocations without an explicit one: // that of malloc, which is 16 bytes on 32-bit targets too. @[inline] -fn arena_align() isize { +fn arena_align() int { return 16 } @[inline] -fn arena_chunk_header_size() isize { +fn arena_chunk_header_size() int { align := arena_align() - return (isize(sizeof(VArenaChunk)) + align - 1) / align * align + return (int(sizeof(VArenaChunk)) + align - 1) / align * align } @[inline] @@ -131,13 +131,13 @@ fn arena_registry_end_write() { } @[inline; unsafe] -fn arena_range_start(r &VArenaRange) usize { - return usize(C.atomic_load_ptr(&r.start)) +fn arena_range_start(r &VArenaRange) uint { + return uint(C.atomic_load_ptr(&r.start)) } @[inline; unsafe] -fn arena_range_stop(r &VArenaRange) usize { - return usize(C.atomic_load_ptr(&r.stop)) +fn arena_range_stop(r &VArenaRange) uint { + return uint(C.atomic_load_ptr(&r.stop)) } @[inline; unsafe] @@ -150,7 +150,7 @@ fn arena_range_set(mut r VArenaRange, value VArenaRange) { // arena_registry_upper returns the index of the first of the `len` ranges of // `reg` that starts after `addr`. @[direct_array_access; unsafe] -fn arena_registry_upper(reg &VArenaRegistry, len int, addr usize) int { +fn arena_registry_upper(reg &VArenaRegistry, len int, addr uint) int { mut lo := 0 mut hi := len for lo < hi { @@ -172,26 +172,26 @@ fn arena_registry_add(owner &VArena, chunk &VArenaChunk) { mut reg := g_arena_registry if reg == nil || len == reg.cap { new_cap := if reg == nil { 16 } else { reg.cap * 2 } - bytes := sizeof(VArenaRegistry) + usize(new_cap) * sizeof(VArenaRange) + bytes := sizeof(VArenaRegistry) + uint(new_cap) * sizeof(VArenaRange) mut grown := &VArenaRegistry(C.malloc(bytes)) - vmemory_abort_on_nil(grown, isize(bytes)) + vmemory_abort_on_nil(grown, int(bytes)) grown.cap = new_cap grown.ranges = &VArenaRange(&u8(grown) + sizeof(VArenaRegistry)) if len > 0 { - C.memcpy(grown.ranges, reg.ranges, usize(len) * sizeof(VArenaRange)) + C.memcpy(grown.ranges, reg.ranges, uint(len) * sizeof(VArenaRange)) } // The old registry is left allocated (see VArenaRegistry). C.atomic_store_ptr(&g_arena_registry, grown) reg = grown } - start := usize(chunk.start) + start := uint(chunk.start) i := arena_registry_upper(reg, len, start) for j := len; j > i; j-- { arena_range_set(mut reg.ranges[j], reg.ranges[j - 1]) } arena_range_set(mut reg.ranges[i], VArenaRange{ start: start - stop: usize(chunk.stop) + stop: uint(chunk.stop) owner: owner }) C.atomic_store_u32(&g_arena_ranges_len, u32(len + 1)) @@ -205,7 +205,7 @@ fn arena_registry_remove(chunk &VArenaChunk) { unsafe { reg := g_arena_registry len := int(g_arena_ranges_len) - start := usize(chunk.start) + start := uint(chunk.start) i := arena_registry_upper(reg, len, start) - 1 if i >= 0 && reg.ranges[i].start == start { for j in i .. len - 1 { @@ -223,7 +223,7 @@ fn arena_registry_remove(chunk &VArenaChunk) { // of the registry is repeated. Its loads stay inside the registry it searches, // whatever a writer does meanwhile. @[direct_array_access; unsafe] -fn arena_registry_find(addr usize) (&VArena, usize) { +fn arena_registry_find(addr uint) (&VArena, uint) { for { seq := C.atomic_load_u32(&g_arena_seq) if seq & 1 != 0 { @@ -231,7 +231,7 @@ fn arena_registry_find(addr usize) (&VArena, usize) { } reg := &VArenaRegistry(C.atomic_load_ptr(&g_arena_registry)) mut owner := &VArena(nil) - mut stop := usize(0) + mut stop := uint(0) if reg != nil { mut len := int(C.atomic_load_u32(&g_arena_ranges_len)) if len > reg.cap { @@ -257,8 +257,8 @@ fn arena_registry_find(addr usize) (&VArena, usize) { // arena_owner returns the arena that owns `ptr` (nil for any other memory) and // the end of the chunk that contains it. @[unsafe] -fn arena_owner(ptr voidptr) (&VArena, usize) { - addr := usize(ptr) +fn arena_owner(ptr voidptr) (&VArena, uint) { + addr := uint(ptr) unsafe { // Only this thread changes the arenas on its own stack, so they can be // searched without the registry. They own most memory freed in a scope. @@ -266,8 +266,8 @@ fn arena_owner(ptr voidptr) (&VArena, usize) { for a != nil { mut c := a.chunk for c != nil { - if addr >= usize(c.start) && addr < usize(c.stop) { - return a, usize(c.stop) + if addr >= uint(c.start) && addr < uint(c.stop) { + return a, uint(c.stop) } c = c.prev } @@ -301,7 +301,7 @@ fn arena_chunk_release(chunk &VArenaChunk) { // arena_grow adds a chunk with room for at least `need` bytes. @[noinline; unsafe] -fn arena_grow(mut a VArena, need isize) &VArenaChunk { +fn arena_grow(mut a VArena, need int) &VArenaChunk { mut size := a.chunk_size if need > size { size = need @@ -317,9 +317,9 @@ fn arena_grow(mut a VArena, need isize) &VArenaChunk { $if gcboehm ? { // Uncollectable chunks are still scanned, so GC objects that are only // referenced from arena memory stay alive. - mem = C.GC_MALLOC_UNCOLLECTABLE(usize(total)) + mem = C.GC_MALLOC_UNCOLLECTABLE(uint(total)) } $else { - mem = C.malloc(usize(total)) + mem = C.malloc(uint(total)) } vmemory_abort_on_nil(mem, total) unsafe { @@ -335,12 +335,12 @@ fn arena_grow(mut a VArena, need isize) &VArenaChunk { } @[unsafe] -fn arena_alloc(mut a VArena, n isize, align isize) &u8 { +fn arena_alloc(mut a VArena, n int, align int) &u8 { default_align := arena_align() fixed_align := if align > default_align { align } else { default_align } // Like malloc, fail for a size that no chunk can hold, before computing the // size of that chunk overflows. - if usize(n) > (~usize(0) >> 1) - usize(fixed_align + arena_chunk_header_size()) { + if uint(n) > (~uint(0) >> 1) - uint(fixed_align + arena_chunk_header_size()) { _memory_panic(@FN, n) } unsafe { @@ -361,7 +361,7 @@ fn arena_alloc(mut a VArena, n isize, align isize) &u8 { // arena_alloc_current returns `n` bytes from the current thread's arena, or // nil when no arena is active. -fn arena_alloc_current(n isize, align isize) &u8 { +fn arena_alloc_current(n int, align int) &u8 { mut a := g_arena_top if a == unsafe { nil } { return unsafe { nil } @@ -374,7 +374,7 @@ fn arena_alloc_current(n isize, align isize) &u8 { // of the current arena grows in place; other arena memory is copied to the // current allocator and left in its arena. realloc(nil, n) allocates from the // current arena. -fn arena_realloc(old_data &u8, old_size isize, new_size isize) &u8 { +fn arena_realloc(old_data &u8, old_size int, new_size int) &u8 { unsafe { if old_data == nil { if new_size <= 0 { @@ -403,16 +403,16 @@ fn arena_realloc(old_data &u8, old_size isize, new_size isize) &u8 { n = old_size } // Without the old size, copy what the chunk holds: it is mapped memory. - available := isize(chunk_stop - usize(old_data)) + available := int(chunk_stop - uint(old_data)) if available < n { n = available } // A new block in the same chunk starts at or after the end of the old // one, so the bytes before it hold all of the old block. - if usize(new_ptr) > usize(old_data) && usize(new_ptr) - usize(old_data) < usize(n) { - n = isize(usize(new_ptr) - usize(old_data)) + if uint(new_ptr) > uint(old_data) && uint(new_ptr) - uint(old_data) < uint(n) { + n = int(uint(new_ptr) - uint(old_data)) } - C.memcpy(new_ptr, old_data, usize(n)) + C.memcpy(new_ptr, old_data, uint(n)) return new_ptr } } @@ -446,7 +446,7 @@ fn arena_release_chunks(mut a VArena, keep_one bool) { if keep != nil { $if gcboehm ? { // Stale pointers in reused memory would keep GC objects alive. - C.memset(keep.start, 0, usize(i64(keep.cursor) - i64(keep.start))) + C.memset(keep.start, 0, uint(i64(keep.cursor) - i64(keep.start))) } keep.prev = nil keep.cursor = keep.start @@ -470,12 +470,12 @@ fn arena_checked(handle voidptr) &VArena { // v_arena_new creates an arena whose first chunk holds `chunk_size` bytes (0 // selects 64KB). It is the low-level hook behind `arena.new()`; use that. @[unsafe] -pub fn v_arena_new(chunk_size isize) voidptr { +pub fn v_arena_new(chunk_size int) voidptr { $if prealloc || vgc ?|| freestanding || vinix { panic('arena: scoped arenas are not supported with -prealloc, -gc vgc, -freestanding or on Vinix') } mut a := unsafe { &VArena(C.calloc(1, sizeof(VArena))) } - vmemory_abort_on_nil(a, isize(sizeof(VArena))) + vmemory_abort_on_nil(a, int(sizeof(VArena))) a.magic = arena_magic a.chunk_size = if chunk_size > 0 { chunk_size } else { arena_default_chunk_size } a.max_chunk_size = if a.chunk_size > arena_max_chunk_size { @@ -562,7 +562,7 @@ pub fn v_arena_current() voidptr { // v_arena_stats returns the bytes handed out by an arena since its last // reset, and the bytes of its chunks. -pub fn v_arena_stats(handle voidptr) (isize, isize) { +pub fn v_arena_stats(handle voidptr) (int, int) { a := arena_checked(handle) mut used := i64(0) mut capacity := i64(0) @@ -572,16 +572,16 @@ pub fn v_arena_stats(handle voidptr) (isize, isize) { capacity += i64(c.stop) - i64(c.start) c = c.prev } - return isize(used), isize(capacity) + return int(used), int(capacity) } // v_arena_owns reports whether `ptr` points into the memory of an arena. pub fn v_arena_owns(handle voidptr, ptr voidptr) bool { a := arena_checked(handle) - addr := usize(ptr) + addr := uint(ptr) mut c := a.chunk for c != unsafe { nil } { - if addr >= usize(c.start) && addr < usize(c.stop) { + if addr >= uint(c.start) && addr < uint(c.stop) { return true } c = c.prev diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 16bb60b37b..7e88f8b558 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -12,7 +12,7 @@ import strings pub struct array { pub mut: data voidptr - offset int // in bytes (should be `usize`), to avoid copying data while making slices, unless it starts changing + offset int // in bytes (should be `uint`), to avoid copying data while making slices, unless it starts changing len int // length of the array in elements. cap int // capacity of the array in elements. flags ArrayFlags @@ -59,7 +59,7 @@ fn array_data_allocation_size(total_size u64) u64 { @[inline] fn init_array_data(raw voidptr) voidptr { // At most 15 bytes of padding keep both the header and element storage aligned. - padding := (16 - (usize(raw) + usize(array_data_header_size())) % 16) % 16 + padding := (16 - (uint(raw) + uint(array_data_header_size())) % 16) % 16 unsafe { data := &u8(raw) + array_data_header_size() + padding header := &ArrayDataHeader(data - array_data_header_size()) @@ -462,7 +462,7 @@ pub fn (mut a array) ensure_cap(required int) { if a.flags.has(.noslices) && !a.flags.has(.is_slice) && !a.buffer_has_slices() { unsafe { $if prealloc { - prealloc_discard_pages(a.data, usize(a.cap) * usize(a.element_size)) + prealloc_discard_pages(a.data, uint(a.cap) * uint(a.element_size)) } if a.flags.has(.managed) { free_unaliased(a.data_header().allocation) @@ -1199,9 +1199,9 @@ fn (mut a array) set(i int, val voidptr) { // with indexes it has already bounded, so it skips the per-element range checks // of `array.set`. @[inline; markused; unsafe] -fn array_sort_move(dst voidptr, di int, src voidptr, si int, count int, element_size usize) { - vmemcpy(&u8(dst) + usize(di) * element_size, &u8(src) + usize(si) * element_size, - isize(usize(count) * element_size)) +fn array_sort_move(dst voidptr, di int, src voidptr, si int, count int, element_size uint) { + vmemcpy(&u8(dst) + uint(di) * element_size, &u8(src) + uint(si) * element_size, + int(uint(count) * element_size)) } $if !v3_backend ? { @@ -1391,7 +1391,7 @@ pub fn (a array) reverse() array { pub fn (a &array) free() { $if prealloc { if !a.flags.has(.is_slice) && !a.flags.has(.nofree) && !a.buffer_has_retained_fixed_views() { - unsafe { prealloc_discard_pages(a.data, usize(a.cap) * usize(a.element_size)) } + unsafe { prealloc_discard_pages(a.data, uint(a.cap) * uint(a.element_size)) } } return } @@ -1406,7 +1406,7 @@ pub fn (a &array) free() { if a.flags.has(.nofree) || a.buffer_has_retained_fixed_views() { return } - mblock_ptr := &u8(usize(a.data) - usize(a.offset)) + mblock_ptr := &u8(uint(a.data) - uint(a.offset)) if mblock_ptr != unsafe { nil } { unsafe { allocation := if a.flags.has(.managed) { @@ -1547,7 +1547,7 @@ pub fn (mut a array) sort_with_compare(callback FnSortCB) { $if freestanding { panic('sort_with_compare does not work with -freestanding') } $else { - unsafe { vqsort(a.data, usize(a.len), usize(a.element_size), callback) } + unsafe { vqsort(a.data, uint(a.len), uint(a.element_size), callback) } } } @@ -1557,7 +1557,7 @@ pub fn (mut a array) sort_with_compare(callback FnSortCB) { // Equal elements keep their original relative order. pub fn (a &array) sorted_with_compare(callback FnSortCB) array { mut r := a.clone() - unsafe { vqsort(r.data, usize(r.len), usize(r.element_size), callback) } + unsafe { vqsort(r.data, uint(r.len), uint(r.element_size), callback) } return r } @@ -1640,7 +1640,7 @@ pub fn (b []u8) hex() string { pub fn copy(mut dst []u8, src []u8) int { min := if dst.len < src.len { dst.len } else { src.len } if min > 0 { - unsafe { vmemmove(dst.data, src.data, isize(min) * isize(dst.element_size)) } + unsafe { vmemmove(dst.data, src.data, int(min) * int(dst.element_size)) } } return min } diff --git a/vlib/builtin/array_alignment.v b/vlib/builtin/array_alignment.v index 77beb38c0c..266404f429 100644 --- a/vlib/builtin/array_alignment.v +++ b/vlib/builtin/array_alignment.v @@ -4,12 +4,12 @@ const array_alignment_shift = sizeof(ArrayFlags) * 8 - 8 const array_alignment_mask = u32(63) << array_alignment_shift @[inline] -fn (a &array) data_alignment() usize { +fn (a &array) data_alignment() uint { exponent := (u32(a.flags) & array_alignment_mask) >> array_alignment_shift - return if exponent == 0 { usize(16) } else { usize(1) << exponent } + return if exponent == 0 { uint(16) } else { uint(1) << exponent } } -fn data_alignment_exponent(alignment usize) u8 { +fn data_alignment_exponent(alignment uint) u8 { if alignment <= 16 { return 0 } @@ -22,7 +22,7 @@ fn data_alignment_exponent(alignment usize) u8 { return exponent } -fn (mut a array) set_data_alignment(alignment usize) { +fn (mut a array) set_data_alignment(alignment uint) { exponent := u32(data_alignment_exponent(alignment)) bits := u32(a.flags) & ~array_alignment_mask a.flags = unsafe { ArrayFlags(bits | (exponent << array_alignment_shift)) } @@ -38,7 +38,7 @@ fn (a &array) storage_flags(noscan bool) ArrayFlags { return unsafe { ArrayFlags(flags) } } -fn alloc_array_data_aligned(total_size u64, alignment usize, zero bool) voidptr { +fn alloc_array_data_aligned(total_size u64, alignment uint, zero bool) voidptr { size := u64(array_data_header_size()) + u64(alignment - 1) allocation_size := size + __at_least_one(total_size) raw := if zero { @@ -46,8 +46,8 @@ fn alloc_array_data_aligned(total_size u64, alignment usize, zero bool) voidptr } else { unsafe { malloc_uninit(allocation_size) } } - header_size := usize(array_data_header_size()) - padding := (alignment - (usize(raw) + header_size) % alignment) % alignment + header_size := uint(array_data_header_size()) + padding := (alignment - (uint(raw) + header_size) % alignment) % alignment unsafe { data := &u8(raw) + header_size + padding header := &ArrayDataHeader(data - header_size) @@ -58,7 +58,7 @@ fn alloc_array_data_aligned(total_size u64, alignment usize, zero bool) voidptr } } -fn __new_array_aligned(mylen int, capacity int, element_size int, alignment usize) array { +fn __new_array_aligned(mylen int, capacity int, element_size int, alignment uint) array { if alignment <= 16 { return __new_array(mylen, capacity, element_size) } @@ -78,7 +78,7 @@ fn __new_array_aligned(mylen int, capacity int, element_size int, alignment usiz return result } -fn new_array_from_c_array_aligned(length int, capacity int, element_size int, source voidptr, alignment usize) array { +fn new_array_from_c_array_aligned(length int, capacity int, element_size int, source voidptr, alignment uint) array { panic_on_negative_len(length) panic_on_negative_cap(capacity) mut result := __new_array_aligned(0, if capacity < length { length } else { capacity }, @@ -90,7 +90,7 @@ fn new_array_from_c_array_aligned(length int, capacity int, element_size int, so return result } -fn new_array_from_c_array_no_alloc_aligned(length int, capacity int, element_size int, source voidptr, alignment usize) array { +fn new_array_from_c_array_no_alloc_aligned(length int, capacity int, element_size int, source voidptr, alignment uint) array { mut result := new_array_from_c_array_no_alloc(length, capacity, element_size, source) result.set_data_alignment(alignment) return result diff --git a/vlib/builtin/array_alignment_test.v b/vlib/builtin/array_alignment_test.v index 6ee5dfb92e..b15b6e83a4 100644 --- a/vlib/builtin/array_alignment_test.v +++ b/vlib/builtin/array_alignment_test.v @@ -1,7 +1,7 @@ module builtin fn test_array_alignment_does_not_overlap_retained_storage_flags() { - for alignment in [usize(16), 32, 64, 128, 4096] { + for alignment in [uint(16), 32, 64, 128, 4096] { mut value := array{} value.set_data_alignment(alignment) value.mark_aligned_fixed_array_buffer() @@ -15,7 +15,7 @@ fn test_array_alignment_does_not_overlap_retained_storage_flags() { fn test_aligned_array_header_initializes_retained_views() { mut value := __new_array_aligned(0, 4, int(sizeof(u64)), 64) - assert usize(value.data) % 64 == 0 + assert uint(value.data) % 64 == 0 assert !value.buffer_has_retained_fixed_views() assert !value.buffer_has_slices() unsafe { value.free() } diff --git a/vlib/builtin/array_managed_alignment_test.v b/vlib/builtin/array_managed_alignment_test.v index 0b6ef606da..072bc859b5 100644 --- a/vlib/builtin/array_managed_alignment_test.v +++ b/vlib/builtin/array_managed_alignment_test.v @@ -1,15 +1,15 @@ module builtin fn test_managed_array_alignment_does_not_depend_on_allocation_alignment() { - assert sizeof(ArrayDataHeader) <= usize(array_data_header_size()) + assert sizeof(ArrayDataHeader) <= uint(array_data_header_size()) // Model allocators with weaker alignment by testing every possible low nibble. allocation := unsafe { malloc(128) } for offset in 0 .. 16 { raw := unsafe { allocation + offset } data := init_array_data(raw) - assert usize(data) % 16 == 0 - assert usize(data) - usize(raw) >= usize(array_data_header_size()) - assert usize(data) - usize(raw) <= usize(array_data_header_size()) + 15 + assert uint(data) % 16 == 0 + assert uint(data) - uint(raw) >= uint(array_data_header_size()) + assert uint(data) - uint(raw) <= uint(array_data_header_size()) + 15 a := array{ data: data len: 1 @@ -38,7 +38,7 @@ fn test_managed_array_header_survives_slice_offsets() { assert owner[1] == 1 view << u64(99) assert view.data != owner.data - assert usize(view.data) % 16 == 0 + assert uint(view.data) % 16 == 0 assert unsafe { view.data_header().allocation } != allocation assert view == [u64(1), 2, 3, 4, 99] assert owner[5] == 5 @@ -56,7 +56,7 @@ fn test_managed_array_offset_and_noslices_growth_free_original_allocation() { assert unsafe { values.data_header() } == header for n in 2 .. 128 { values << u64(n) - assert usize(values.data) % 16 == 0 + assert uint(values.data) % 16 == 0 } assert values[0] == 1 assert values.last() == 127 @@ -74,7 +74,7 @@ fn test_noscan_array_allocations_use_the_same_alignment_and_ownership() { } else { alloc_array_data_noscan_uninit(32) } - assert usize(data) % 16 == 0 + assert uint(data) % 16 == 0 mut values := array{ data: data len: 2 @@ -86,7 +86,7 @@ fn test_noscan_array_allocations_use_the_same_alignment_and_ownership() { assert header.allocation != unsafe { nil } assert !header.has_slices values.ensure_cap_noscan(128) - assert usize(values.data) % 16 == 0 + assert uint(values.data) % 16 == 0 assert values.flags.has(.noscan_data) assert !values.buffer_has_slices() unsafe { values.free() } diff --git a/vlib/builtin/backtraces_nix.c.v b/vlib/builtin/backtraces_nix.c.v index 773dcd1470..e8241e4d59 100644 --- a/vlib/builtin/backtraces_nix.c.v +++ b/vlib/builtin/backtraces_nix.c.v @@ -36,7 +36,7 @@ fn backtrace_exec_capture(args []string) (string, int) { mut output := '' mut buf := [4096]u8{} for { - n := C.read(fd, &buf[0], usize(buf.len)) + n := C.read(fd, &buf[0], uint(buf.len)) if n > 0 { // read returned n initialized bytes in the stack buffer. output += unsafe { tos(&buf[0], int(n)) } diff --git a/vlib/builtin/builtin_d_gcboehm.c.v b/vlib/builtin/builtin_d_gcboehm.c.v index 42e54c714d..df4c23c1bd 100644 --- a/vlib/builtin/builtin_d_gcboehm.c.v +++ b/vlib/builtin/builtin_d_gcboehm.c.v @@ -214,17 +214,17 @@ $if gcboehm_leak ? { // Do not use them manually. They are automatically chosen when // compiled with `-gc boehm` or `-gc boehm_leak`. @[c: 'v_gc_malloc'] -fn C.GC_MALLOC(n usize) voidptr +fn C.GC_MALLOC(n uint) voidptr @[c: 'v_gc_malloc_atomic'] -fn C.GC_MALLOC_ATOMIC(n usize) voidptr +fn C.GC_MALLOC_ATOMIC(n uint) voidptr @[c: 'v_gc_malloc_uncollectable'] @[markused] -fn C.GC_MALLOC_UNCOLLECTABLE(n usize) voidptr +fn C.GC_MALLOC_UNCOLLECTABLE(n uint) voidptr @[c: 'v_gc_realloc'] -fn C.GC_REALLOC(ptr voidptr, n usize) voidptr +fn C.GC_REALLOC(ptr voidptr, n uint) voidptr @[c: 'v_gc_free'] @[markused] @@ -247,7 +247,7 @@ $if !windows { fn C.v_gc_dlopen(const_path &char, mode i32) voidptr } -fn C.GC_memalign(align usize, size usize) voidptr +fn C.GC_memalign(align uint, size uint) voidptr // explicitly perform garbage collection now! Garbage collections // are done automatically when needed, so this function is hardly needed @@ -304,9 +304,9 @@ pub fn gc_check_leaks() { } } -fn C.GC_get_heap_usage_safe(pheap_size &usize, pfree_bytes &usize, punmapped_bytes &usize, pbytes_since_gc &usize, - ptotal_bytes &usize) -fn C.GC_get_memory_use() usize +fn C.GC_get_heap_usage_safe(pheap_size &uint, pfree_bytes &uint, punmapped_bytes &uint, pbytes_since_gc &uint, + ptotal_bytes &uint) +fn C.GC_get_memory_use() uint pub struct C.GC_stack_base { mem_base voidptr @@ -337,7 +337,7 @@ fn C.GC_set_sp_corrector(fn (voidptr, voidptr)) // FnGC_WarnCB is the type of the callback, that you have to define, if you want to redirect GC warnings and handle them. // Note: GC warnings are silenced by default. Use gc_set_warn_proc/1 to set your own handler for them. -pub type FnGC_WarnCB = fn (const_msg &char, arg usize) +pub type FnGC_WarnCB = fn (const_msg &char, arg uint) fn C.v_gc_get_warn_proc() voidptr fn C.v_gc_set_warn_proc(cb FnGC_WarnCB) @@ -345,7 +345,7 @@ fn C.v_gc_set_warn_proc(cb FnGC_WarnCB) // GC_REGISTER_DISPLACEMENT is `GC_debug_register_displacement` when `GC_DEBUG` is set // (`-gc boehm_leak`), and `GC_register_displacement` otherwise. @[c: 'v_gc_register_displacement'] -fn C.GC_REGISTER_DISPLACEMENT(offset usize) +fn C.GC_REGISTER_DISPLACEMENT(offset uint) // FnGC_AbortCB is the type of Boehm's fatal error handler (`GC_abort_func`). // `const_msg` is nil when Boehm calls it right before `exit(1)`. @@ -371,7 +371,7 @@ pub fn gc_set_warn_proc(cb FnGC_WarnCB) { } // used by builtin_init: -fn internal_gc_warn_proc_none(const_msg &char, arg usize) {} +fn internal_gc_warn_proc_none(const_msg &char, arg uint) {} // gc_report_fatal_errors_on_stderr replaces Boehm's abort handler. On Windows the // default one shows a modal message box and waits for someone to dismiss it, so a diff --git a/vlib/builtin/builtin_d_use_libbacktrace.c.v b/vlib/builtin/builtin_d_use_libbacktrace.c.v index d742ac0435..ec379f02e9 100644 --- a/vlib/builtin/builtin_d_use_libbacktrace.c.v +++ b/vlib/builtin/builtin_d_use_libbacktrace.c.v @@ -24,7 +24,7 @@ $if openbsd { type BacktraceErrorCallback = fn (data voidptr, const_msg &char, errnum i32) - type BacktraceFullCallback = fn (data voidptr, pc usize, const_filename &char, lineno i32, const_func &char) i32 + type BacktraceFullCallback = fn (data voidptr, pc uint, const_filename &char, lineno i32, const_func &char) i32 fn C.backtrace_create_state(filename &char, threaded i32, error_callback BacktraceErrorCallback, data voidptr) &C.backtrace_state fn C.backtrace_full(state &C.backtrace_state, skip i32, cb BacktraceFullCallback, err_cb BacktraceErrorCallback, @@ -47,7 +47,7 @@ $if openbsd { stdin bool = true } - fn bt_print_callback(data_ptr voidptr, pc usize, filename_ptr &char, line i32, fn_name_ptr &char) i32 { + fn bt_print_callback(data_ptr voidptr, pc uint, filename_ptr &char, line i32, fn_name_ptr &char) i32 { data := unsafe { &BacktraceOptions(data_ptr) } filename := if filename_ptr == unsafe { nil } { '???' diff --git a/vlib/builtin/builtin_notd_gcboehm.c.v b/vlib/builtin/builtin_notd_gcboehm.c.v index 2ffe932f1e..43dba12a6e 100644 --- a/vlib/builtin/builtin_notd_gcboehm.c.v +++ b/vlib/builtin/builtin_notd_gcboehm.c.v @@ -4,22 +4,22 @@ module builtin // Note: they will NOT be used, since calls to them are wrapped with `$if gcboehm ? { }` -fn C.GC_MALLOC(n usize) voidptr +fn C.GC_MALLOC(n uint) voidptr -fn C.GC_MALLOC_ATOMIC(n usize) voidptr +fn C.GC_MALLOC_ATOMIC(n uint) voidptr -fn C.GC_MALLOC_UNCOLLECTABLE(n usize) voidptr +fn C.GC_MALLOC_UNCOLLECTABLE(n uint) voidptr -fn C.GC_REALLOC(ptr voidptr, n usize) voidptr +fn C.GC_REALLOC(ptr voidptr, n uint) voidptr fn C.GC_FREE(ptr voidptr) -fn C.GC_memalign(align usize, size usize) voidptr +fn C.GC_memalign(align uint, size uint) voidptr -fn C.GC_get_heap_usage_safe(pheap_size &usize, pfree_bytes &usize, punmapped_bytes &usize, pbytes_since_gc &usize, - ptotal_bytes &usize) +fn C.GC_get_heap_usage_safe(pheap_size &uint, pfree_bytes &uint, punmapped_bytes &uint, pbytes_since_gc &uint, + ptotal_bytes &uint) -fn C.GC_get_memory_use() usize +fn C.GC_get_memory_use() uint fn C.GC_gcollect() @@ -67,7 +67,7 @@ pub fn gc_collect() { } } -pub type FnGC_WarnCB = fn (msg &char, arg usize) +pub type FnGC_WarnCB = fn (msg &char, arg uint) fn C.GC_get_warn_proc() FnGC_WarnCB fn C.GC_set_warn_proc(cb FnGC_WarnCB) @@ -81,4 +81,4 @@ pub fn gc_get_warn_proc() {} pub fn gc_set_warn_proc(cb FnGC_WarnCB) {} // used by builtin_init -fn internal_gc_warn_proc_none(msg &char, arg usize) {} +fn internal_gc_warn_proc_none(msg &char, arg uint) {} diff --git a/vlib/builtin/builtin_windows.c.v b/vlib/builtin/builtin_windows.c.v index 76de469926..56b3c98301 100644 --- a/vlib/builtin/builtin_windows.c.v +++ b/vlib/builtin/builtin_windows.c.v @@ -57,9 +57,9 @@ fn C.WriteConsoleW(voidptr, &u16, C.DWORD, &C.DWORD, voidptr) bool fn C.WriteFile(voidptr, &u8, C.DWORD, &C.DWORD, voidptr) bool fn C.ExitProcess(u32) fn C.GetProcessHeap() voidptr -fn C.HeapAlloc(voidptr, u32, usize) voidptr +fn C.HeapAlloc(voidptr, u32, uint) voidptr fn C.HeapFree(voidptr, u32, voidptr) bool -fn C.CreateThread(attributes voidptr, stack_size usize, start_routine voidptr, arg voidptr, flags u32, thread_id &u32) voidptr +fn C.CreateThread(attributes voidptr, stack_size uint, start_routine voidptr, arg voidptr, flags u32, thread_id &u32) voidptr fn C.v_builtin_windows_stream(index u32) voidptr fn C._setmode(int, int) int @@ -176,7 +176,7 @@ fn write_buf_to_console_kernel32(fd int, buf &u8, buf_len int) bool { if isnil(heap) { return false } - wide_size := usize((wide_len + 1) * int(sizeof(u16))) + wide_size := uint((wide_len + 1) * int(sizeof(u16))) mut wide_buf := &u16(C.HeapAlloc(heap, 0, wide_size)) if isnil(wide_buf) { return false @@ -259,7 +259,7 @@ fn write_buf_to_fd_windows_non_minimal(fd int, buf &u8, buf_len int) { return } mut ptr := unsafe { buf } - mut remaining_bytes := isize(buf_len) + mut remaining_bytes := int(buf_len) if write_buf_to_console(fd, ptr, int(remaining_bytes)) { return } @@ -267,10 +267,10 @@ fn write_buf_to_fd_windows_non_minimal(fd int, buf &u8, buf_len int) { if fd == 2 { stream = voidptr(C.stderr) } - mut x := isize(0) + mut x := int(0) unsafe { for remaining_bytes > 0 { - x = isize(C.fwrite(ptr, 1, remaining_bytes, stream)) + x = int(C.fwrite(ptr, 1, remaining_bytes, stream)) if x <= 0 { // GUI programs on Windows may not have a writable stdout/stderr stream. break @@ -390,7 +390,7 @@ struct C.MEMORY_BASIC_INFORMATION { AllocationBase voidptr } -fn C.VirtualQuery(address voidptr, buffer &C.MEMORY_BASIC_INFORMATION, length usize) usize +fn C.VirtualQuery(address voidptr, buffer &C.MEMORY_BASIC_INFORMATION, length uint) uint fn C.GetModuleHandleW(name &u16) voidptr diff --git a/vlib/builtin/cfns.c.v b/vlib/builtin/cfns.c.v index b99210b861..695edcb2fc 100644 --- a/vlib/builtin/cfns.c.v +++ b/vlib/builtin/cfns.c.v @@ -6,6 +6,10 @@ pub struct C.FILE {} @[typedef] pub struct C.qsort_callback_func {} +// C.ptrdiff_t is the signed pointer-width integer used by C interfaces. +@[typedef] +pub type C.ptrdiff_t = int + // Virtual C globals that are available through libc or generated C headers. __global C.errno int __global C.stdin &C.FILE @@ -16,74 +20,74 @@ __global C._wyp &u64 // @[markused; noalloc] -fn C.memcpy(dest voidptr, const_src voidptr, n usize) voidptr +fn C.memcpy(dest voidptr, const_src voidptr, n uint) voidptr @[markused; noalloc] -fn C.memcmp(const_s1 voidptr, const_s2 voidptr, n usize) i32 +fn C.memcmp(const_s1 voidptr, const_s2 voidptr, n uint) i32 @[markused; noalloc] -fn C.memmove(dest voidptr, const_src voidptr, n usize) voidptr +fn C.memmove(dest voidptr, const_src voidptr, n uint) voidptr @[markused; noalloc] -fn C.memset(str voidptr, c i32, n usize) voidptr +fn C.memset(str voidptr, c i32, n uint) voidptr @[noalloc] -fn C.memchr(str voidptr, c i32, n usize) voidptr +fn C.memchr(str voidptr, c i32, n uint) voidptr @[noalloc] -fn C.memmem(haystack voidptr, haystacklen usize, needle voidptr, needlelen usize) voidptr +fn C.memmem(haystack voidptr, haystacklen uint, needle voidptr, needlelen uint) voidptr @[noalloc] -fn C.mempcpy(dest voidptr, src voidptr, n usize) voidptr +fn C.mempcpy(dest voidptr, src voidptr, n uint) voidptr @[markused; trusted] -fn C.calloc(usize, usize) voidptr +fn C.calloc(uint, uint) voidptr fn C.atoi(&char) i32 @[markused] -fn C.malloc(usize) voidptr +fn C.malloc(uint) voidptr @[markused] -fn C.realloc(a voidptr, b usize) voidptr +fn C.realloc(a voidptr, b uint) voidptr @[markused; noalloc] fn C.free(ptr voidptr) @[markused] -fn C.mmap(addr_length voidptr, length usize, prot i32, flags i32, fd i32, offset isize) voidptr +fn C.mmap(addr_length voidptr, length uint, prot i32, flags i32, fd i32, offset C.ptrdiff_t) voidptr // C.munmap releases a memory mapping created by C.mmap. -fn C.munmap(addr_length voidptr, len usize) i32 +fn C.munmap(addr_length voidptr, len uint) i32 @[markused] -fn C.mprotect(addr_length voidptr, len usize, prot i32) i32 +fn C.mprotect(addr_length voidptr, len uint, prot i32) i32 @[markused] -fn C.aligned_alloc(align usize, size usize) voidptr +fn C.aligned_alloc(align uint, size uint) voidptr // windows aligned memory functions -fn C._aligned_malloc(size usize, align usize) voidptr +fn C._aligned_malloc(size uint, align uint) voidptr fn C._aligned_free(voidptr) -fn C._aligned_realloc(voidptr, size usize, align usize) voidptr -fn C._aligned_offset_malloc(size usize, align usize, offset usize) voidptr -fn C._aligned_offset_realloc(voidptr, size usize, align usize, offset usize) voidptr -fn C._aligned_msize(voidptr, align usize, offset usize) usize -fn C._aligned_recalloc(voidptr, num usize, size usize, align usize) voidptr +fn C._aligned_realloc(voidptr, size uint, align uint) voidptr +fn C._aligned_offset_malloc(size uint, align uint, offset uint) voidptr +fn C._aligned_offset_realloc(voidptr, size uint, align uint, offset uint) voidptr +fn C._aligned_msize(voidptr, align uint, offset uint) uint +fn C._aligned_recalloc(voidptr, num uint, size uint, align uint) voidptr $if windows { - fn C.VirtualAlloc(voidptr, isize, u32, u32) voidptr - fn C.VirtualProtect(voidptr, isize, C.DWORD, &C.DWORD) bool + fn C.VirtualAlloc(voidptr, C.ptrdiff_t, u32, u32) voidptr + fn C.VirtualProtect(voidptr, C.ptrdiff_t, C.DWORD, &C.DWORD) bool } @[markused; noreturn; trusted] fn C.exit(code i32) @[markused] -fn C.qsort(base voidptr, items usize, item_size usize, cb C.qsort_callback_func) +fn C.qsort(base voidptr, items uint, item_size uint, cb C.qsort_callback_func) @[markused; noalloc] -fn C.strlen(const_s &char) usize +fn C.strlen(const_s &char) uint @[trusted] fn C.isdigit(c i32) bool @@ -110,7 +114,7 @@ fn C.fprintf(fstream &C.FILE, const_format &char, opt ...voidptr) i32 fn C.sprintf(str &char, const_format &char, opt ...voidptr) i32 @[markused] -fn C.snprintf(str &char, size usize, const_format &char, opt ...voidptr) i32 +fn C.snprintf(str &char, size uint, const_format &char, opt ...voidptr) i32 fn C.wprintf(const_format &u16, opt ...voidptr) i32 @@ -134,7 +138,7 @@ fn C.fflush(fstream &C.FILE) i32 $if windows { fn C.fseek(stream &C.FILE, offset i32, whence i32) i32 } $else { - fn C.fseek(stream &C.FILE, offset isize, whence i32) i32 + fn C.fseek(stream &C.FILE, offset C.ptrdiff_t, whence i32) i32 } // Coverage and profiling writers call these without a V AST reference. @@ -143,10 +147,10 @@ fn C.fopen(filename &char, mode &char) &C.FILE fn C.fileno(&C.FILE) i32 -fn C.fread(ptr voidptr, item_size usize, items usize, stream &C.FILE) usize +fn C.fread(ptr voidptr, item_size uint, items uint, stream &C.FILE) uint @[markused] -fn C.fwrite(const_ptr voidptr, item_size usize, items usize, stream &C.FILE) usize +fn C.fwrite(const_ptr voidptr, item_size uint, items uint, stream &C.FILE) uint @[markused] fn C.fclose(stream &C.FILE) i32 @@ -225,7 +229,7 @@ fn C.chdir(path &char) i32 fn C.rewind(stream &C.FILE) i32 -fn C.ftell(&C.FILE) isize +fn C.ftell(&C.FILE) C.ptrdiff_t fn C.stat(&char, voidptr) i32 @@ -246,7 +250,7 @@ fn C.fgetpos(&C.FILE, voidptr) i32 @[trusted] fn C.sigemptyset() i32 -fn C.getcwd(buf &char, size usize) &char +fn C.getcwd(buf &char, size uint) &char @[trusted] fn C.mktime() i32 @@ -304,7 +308,7 @@ fn C.strncasecmp(s &char, s2 &char, n i32) i32 fn C.strcasecmp(s &char, s2 &char) i32 -fn C.strncmp(s &char, s2 &char, n usize) i32 +fn C.strncmp(s &char, s2 &char, n uint) i32 @[trusted] fn C.strerror(i32) &char @@ -326,7 +330,7 @@ fn C.isatty(fd i32) i32 fn C.syscall(number i32, va ...voidptr) i32 -fn C.sysctl(name &i32, namelen u32, oldp voidptr, oldlenp voidptr, newp voidptr, newlen usize) i32 +fn C.sysctl(name &i32, namelen u32, oldp voidptr, oldlenp voidptr, newp voidptr, newlen uint) i32 @[trusted] fn C._fileno(&C.FILE) i32 @@ -367,9 +371,9 @@ fn C.GetComputerNameW(&u16, &u32) bool fn C.GetUserNameW(&u16, &u32) bool @[trusted] -fn C.SendMessageTimeout() isize +fn C.SendMessageTimeout() C.ptrdiff_t -fn C.SendMessageTimeoutW(hWnd voidptr, msg u32, wParam &u16, lParam &u32, fuFlags u32, uTimeout u32, lpdwResult &u64) isize +fn C.SendMessageTimeoutW(hWnd voidptr, msg u32, wParam &u16, lParam &u32, fuFlags u32, uTimeout u32, lpdwResult &u64) C.ptrdiff_t fn C.CreateProcessW(lpApplicationName &u16, lpCommandLine &u16, lpProcessAttributes voidptr, lpThreadAttributes voidptr, bInheritHandles bool, dwCreationFlags u32, lpEnvironment voidptr, lpCurrentDirectory &u16, lpStartupInfo voidptr, @@ -411,7 +415,7 @@ fn C.SymCleanup(hProcess voidptr) fn C.MultiByteToWideChar(codePage u32, dwFlags u32, lpMultiMyteStr &char, cbMultiByte i32, lpWideCharStr &u16, cchWideChar i32) i32 -fn C.wcslen(str voidptr) usize +fn C.wcslen(str voidptr) uint fn C.WideCharToMultiByte(codePage u32, dwFlags u32, lpWideCharStr &u16, cchWideChar i32, lpMultiByteStr &char, cbMultiByte i32, lpDefaultChar &char, lpUsedDefaultChar &int) i32 @@ -533,7 +537,7 @@ $if macos { fn C.pthread_self() voidptr } $else { @[markused] - fn C.pthread_self() usize + fn C.pthread_self() uint } @[markused] @@ -546,7 +550,7 @@ fn C.pthread_join(thread voidptr, retval voidptr) i32 fn C.pthread_attr_init(attr voidptr) i32 @[markused] -fn C.pthread_attr_setstacksize(attr voidptr, stacksize usize) i32 +fn C.pthread_attr_setstacksize(attr voidptr, stacksize uint) i32 @[markused] fn C.pthread_attr_destroy(attr voidptr) i32 @@ -618,12 +622,12 @@ fn C.dispatch_time(u64, i64) u64 fn C.dispatch_release(voidptr) // file descriptor based reading/writing -fn C.read(fd i32, buf voidptr, count usize) i32 +fn C.read(fd i32, buf voidptr, count uint) i32 $if windows { fn C.write(fd i32, const_buf voidptr, count u32) i32 } $else { - fn C.write(fd i32, const_buf voidptr, count usize) isize + fn C.write(fd i32, const_buf voidptr, count uint) C.ptrdiff_t } fn C.close(fd i32) i32 @@ -735,13 +739,13 @@ fn C.__get_errno_ptr() &i32 fn C.pthread_equal(t1 voidptr, t2 voidptr) i32 @[markused] -fn C.pthread_key_create(key &usize, destructor voidptr) i32 +fn C.pthread_key_create(key &uint, destructor voidptr) i32 @[markused] -fn C.pthread_getspecific(key usize) voidptr +fn C.pthread_getspecific(key uint) voidptr @[markused] -fn C.pthread_setspecific(key usize, value voidptr) i32 +fn C.pthread_setspecific(key uint, value voidptr) i32 @[markused] fn C.pthread_once(control voidptr, init_routine voidptr) i32 diff --git a/vlib/builtin/cfns_wrapper.c.v b/vlib/builtin/cfns_wrapper.c.v index a5d4cc0c98..2bf29c0545 100644 --- a/vlib/builtin/cfns_wrapper.c.v +++ b/vlib/builtin/cfns_wrapper.c.v @@ -39,11 +39,11 @@ fn string_index_byte(data &u8, size int, needle u8) int { } } } - found := unsafe { C.memchr(data, i32(needle), usize(size)) } + found := unsafe { C.memchr(data, i32(needle), uint(size)) } if isnil(found) { return -1 } - return int(usize(found) - usize(data)) + return int(uint(found) - uint(data)) } } @@ -122,7 +122,7 @@ fn string_bytes_equal(a &u8, b &u8, size int) bool { return unsafe { ((a[0] ^ b[0]) | (a[size >> 1] ^ b[size >> 1]) | (a[size - 1] ^ b[size - 1])) == 0 } } } - return unsafe { C.memcmp(a, b, usize(size)) == 0 } + return unsafe { C.memcmp(a, b, uint(size)) == 0 } } // string_content_equal preserves vmemcmp's guarded and traced string comparison. @@ -131,7 +131,7 @@ fn string_content_equal(a &u8, b &u8, size int) bool { $if trace_vmemcmp ? { return unsafe { vmemcmp(a, b, size) == 0 } } - if size == 0 || usize(a) <= 0xFFFF || usize(b) <= 0xFFFF { + if size == 0 || uint(a) <= 0xFFFF || uint(b) <= 0xFFFF { return true } return string_bytes_equal(a, b, size) @@ -155,7 +155,7 @@ pub fn vstrlen_char(s &char) int { // The memory areas *MUST NOT OVERLAP*. Use vmemmove, if the memory // areas do overlap. vmemcpy returns a pointer to `dest`. @[inline; unsafe] -pub fn vmemcpy(dest voidptr, const_src voidptr, n isize) voidptr { +pub fn vmemcpy(dest voidptr, const_src voidptr, n int) voidptr { $if trace_vmemcpy ? { C.fprintf(C.stderr, c'vmemcpy dest: %p src: %p n: %6ld\n', dest, const_src, n) } @@ -166,7 +166,7 @@ pub fn vmemcpy(dest voidptr, const_src voidptr, n isize) voidptr { print_backtrace() } } - if n == 0 || usize(dest) <= 0xFFFF || usize(const_src) <= 0xFFFF { + if n == 0 || uint(dest) <= 0xFFFF || uint(const_src) <= 0xFFFF { return dest } $if prod && !tinyc && !msvc && !native { @@ -208,11 +208,11 @@ pub fn vmemcpy(dest voidptr, const_src voidptr, n isize) voidptr { // `src` or `dest`, and the bytes are then copied from the temporary array // to `dest`. vmemmove returns a pointer to `dest`. @[inline; unsafe] -pub fn vmemmove(dest voidptr, const_src voidptr, n isize) voidptr { +pub fn vmemmove(dest voidptr, const_src voidptr, n int) voidptr { $if trace_vmemmove ? { C.fprintf(C.stderr, c'vmemmove dest: %p src: %p n: %6ld\n', dest, const_src, n) } - if n == 0 || usize(dest) <= 0xFFFF || usize(const_src) <= 0xFFFF { + if n == 0 || uint(dest) <= 0xFFFF || uint(const_src) <= 0xFFFF { return dest } $if prod && !tinyc && !msvc && !native { @@ -279,11 +279,11 @@ pub fn vmemmove(dest voidptr, const_src voidptr, n isize) voidptr { // You should use a function that performs comparisons in constant time for // this. @[inline; unsafe] -pub fn vmemcmp(const_s1 voidptr, const_s2 voidptr, n isize) int { +pub fn vmemcmp(const_s1 voidptr, const_s2 voidptr, n int) int { $if trace_vmemcmp ? { C.fprintf(C.stderr, c'vmemcmp s1: %p s2: %p n: %6ld\n', const_s1, const_s2, n) } - if n == 0 || usize(const_s1) <= 0xFFFF || usize(const_s2) <= 0xFFFF { + if n == 0 || uint(const_s1) <= 0xFFFF || uint(const_s2) <= 0xFFFF { return 0 } unsafe { @@ -294,7 +294,7 @@ pub fn vmemcmp(const_s1 voidptr, const_s2 voidptr, n isize) int { // vmemset fills the first `n` bytes of the memory area pointed to by `s`, // with the constant byte `c`. It returns a pointer to the memory area `s`. @[inline; unsafe] -pub fn vmemset(s voidptr, c int, n isize) voidptr { +pub fn vmemset(s voidptr, c int, n int) voidptr { $if trace_vmemset ? { C.fprintf(C.stderr, c'vmemset s: %p c: %d n: %6ld\n', s, c, n) } @@ -304,7 +304,7 @@ pub fn vmemset(s voidptr, c int, n isize) voidptr { print_backtrace() } } - if n == 0 || usize(s) <= 0xFFFF { + if n == 0 || uint(s) <= 0xFFFF { return s } unsafe { @@ -315,12 +315,12 @@ pub fn vmemset(s voidptr, c int, n isize) voidptr { type FnSortCB = fn (const_a voidptr, const_b voidptr) int @[inline; unsafe] -fn vsort_ptr_at(base voidptr, index usize, size usize) voidptr { +fn vsort_ptr_at(base voidptr, index uint, size uint) voidptr { return unsafe { voidptr(&u8(base) + index * size) } } @[unsafe] -fn vstable_sort_merge(source voidptr, dest voidptr, left usize, mid usize, right usize, size usize, sort_cb FnSortCB) { +fn vstable_sort_merge(source voidptr, dest voidptr, left uint, mid uint, right uint, size uint, sort_cb FnSortCB) { mut left_index := left mut right_index := mid mut dest_index := left @@ -328,26 +328,26 @@ fn vstable_sort_merge(source voidptr, dest voidptr, left usize, mid usize, right left_ptr := vsort_ptr_at(source, left_index, size) right_ptr := vsort_ptr_at(source, right_index, size) if sort_cb(left_ptr, right_ptr) <= 0 { - vmemcpy(vsort_ptr_at(dest, dest_index, size), left_ptr, isize(size)) + vmemcpy(vsort_ptr_at(dest, dest_index, size), left_ptr, int(size)) left_index++ } else { - vmemcpy(vsort_ptr_at(dest, dest_index, size), right_ptr, isize(size)) + vmemcpy(vsort_ptr_at(dest, dest_index, size), right_ptr, int(size)) right_index++ } dest_index++ } if left_index < mid { vmemcpy(vsort_ptr_at(dest, dest_index, size), vsort_ptr_at(source, left_index, size), - isize((mid - left_index) * size)) + int((mid - left_index) * size)) } if right_index < right { vmemcpy(vsort_ptr_at(dest, dest_index, size), vsort_ptr_at(source, right_index, size), - isize((right - right_index) * size)) + int((right - right_index) * size)) } } @[inline; unsafe] -fn vqsort(base voidptr, nmemb usize, size usize, sort_cb FnSortCB) { +fn vqsort(base voidptr, nmemb uint, size uint, sort_cb FnSortCB) { $if trace_vqsort ? { C.fprintf(C.stderr, c'vqsort base: %p, nmemb: %6uld, size: %6uld, sort_cb: %p\n', base, nmemb, size, sort_cb) @@ -363,16 +363,16 @@ fn vqsort(base voidptr, nmemb usize, size usize, sort_cb FnSortCB) { print_backtrace() } } - total_size := isize(nmemb * size) + total_size := int(nmemb * size) buffer := malloc(total_size) defer { free(buffer) } mut source := base mut dest := voidptr(buffer) - mut width := usize(1) + mut width := uint(1) for width < nmemb { - mut left := usize(0) + mut left := uint(0) for left < nmemb { mid := if left + width < nmemb { left + width } else { nmemb } right := if left + width + width < nmemb { left + width + width } else { nmemb } diff --git a/vlib/builtin/closure/closure.c.v b/vlib/builtin/closure/closure.c.v index 062a7da45a..b7fa0e71eb 100644 --- a/vlib/builtin/closure/closure.c.v +++ b/vlib/builtin/closure/closure.c.v @@ -347,7 +347,7 @@ fn closure_slot_meta(exec_ptr voidptr) &voidptr { fn closure_register_page(exec_page_start voidptr) { unsafe { - node := &ClosurePage(malloc(sizeof(ClosurePage))) + node := &ClosurePage(malloc(int(sizeof(ClosurePage)))) *node = ClosurePage{ next: g_closure.pages exec_page_start: exec_page_start @@ -360,13 +360,13 @@ fn closure_is_managed(exec_ptr voidptr) bool { if isnil(exec_ptr) { return false } - exec_addr := unsafe { usize(exec_ptr) } + exec_addr := unsafe { uint(exec_ptr) } mut page := g_closure.pages for page != unsafe { nil } { - page_addr := unsafe { usize(page.exec_page_start) } - if exec_addr >= page_addr && exec_addr < page_addr + usize(g_closure.v_page_size) { + page_addr := unsafe { uint(page.exec_page_start) } + if exec_addr >= page_addr && exec_addr < page_addr + uint(g_closure.v_page_size) { slot_offset := exec_addr - page_addr - return slot_offset >= usize(closure_size) && slot_offset % usize(closure_size) == 0 + return slot_offset >= uint(closure_size) && slot_offset % uint(closure_size) == 0 } page = page.next } @@ -398,7 +398,7 @@ fn new_closure_lifetime_state_no_lock() &ClosureLifetimeState { g_closure.free_lifetime_states = state.next_free } else { unsafe { - state = &ClosureLifetimeState(malloc(sizeof(ClosureLifetimeState))) + state = &ClosureLifetimeState(malloc(int(sizeof(ClosureLifetimeState)))) } g_closure.lifetime_state_allocs++ } diff --git a/vlib/builtin/closure/closure_nix.c.v b/vlib/builtin/closure/closure_nix.c.v index acf4365dfd..7a4138d340 100644 --- a/vlib/builtin/closure/closure_nix.c.v +++ b/vlib/builtin/closure/closure_nix.c.v @@ -47,7 +47,7 @@ fn closure_alloc_platform() &u8 { } @[inline] -fn closure_memory_protect_platform(ptr voidptr, size isize, attr MemoryProtectAtrr) { +fn closure_memory_protect_platform(ptr voidptr, size int, attr MemoryProtectAtrr) { $if freestanding { // No memory protection in freestanding mode } $else { diff --git a/vlib/builtin/closure/closure_windows.c.v b/vlib/builtin/closure/closure_windows.c.v index 2bb6d32025..e52c216ac7 100644 --- a/vlib/builtin/closure/closure_windows.c.v +++ b/vlib/builtin/closure/closure_windows.c.v @@ -29,7 +29,7 @@ fn closure_alloc_platform() &u8 { } @[inline] -fn closure_memory_protect_platform(ptr voidptr, size isize, attr MemoryProtectAtrr) { +fn closure_memory_protect_platform(ptr voidptr, size int, attr MemoryProtectAtrr) { mut tmp := C.DWORD(0) match attr { .read_exec { diff --git a/vlib/builtin/gc_collect_vgc_test.v b/vlib/builtin/gc_collect_vgc_test.v index 4e2ce8fa35..dd011412da 100644 --- a/vlib/builtin/gc_collect_vgc_test.v +++ b/vlib/builtin/gc_collect_vgc_test.v @@ -75,7 +75,7 @@ fn test_threads_that_exited_are_not_scanned() { @[noinline] fn vgc_test_garbage(n int, size int) { for _ in 0 .. n { - _ = vgc_malloc_noscan(usize(size)) + _ = vgc_malloc_noscan(uint(size)) } } @@ -227,7 +227,7 @@ fn test_the_heap_stays_bounded_with_a_bounded_live_set() { gc_collect() base := vgc_memory_use() mut ring := []string{len: 4096} - mut peak := usize(0) + mut peak := uint(0) // About 100 MB of strings in total, of which about 1 MB stays live. for i in 0 .. 400_000 { ring[i % ring.len] = 'bounded live set '.repeat(1 + i % 30) diff --git a/vlib/builtin/gc_heap_usage_vgc_test.v b/vlib/builtin/gc_heap_usage_vgc_test.v index 85fbe31f33..0b0dca0781 100644 --- a/vlib/builtin/gc_heap_usage_vgc_test.v +++ b/vlib/builtin/gc_heap_usage_vgc_test.v @@ -9,7 +9,7 @@ // - total_bytes: the bytes allocated since the program started; // - gc_memory_use(): the heap memory in use, heap_size - free_bytes. // The test passes with `-gc boehm` as well. -const mb = usize(1024 * 1024) +const mb = uint(1024 * 1024) // has_collector reports whether a collector manages the heap: with `-gc none`, all the values // are 0. @@ -37,19 +37,19 @@ fn allocate_garbage(n int) int { // clear_dead_stack overwrites the stack below the caller, where dead frames can still hold // pointers that a conservative collector would take for live ones. @[noinline] -fn clear_dead_stack() usize { - buf := [4096]usize{} +fn clear_dead_stack() uint { + buf := [4096]uint{} return buf[0] + buf[4095] } // memory_use_with_a_large_object allocates a large object, and returns the memory in use while // the object is live. The object is garbage after the return. @[noinline] -fn memory_use_with_a_large_object(size int) usize { +fn memory_use_with_a_large_object(size int) uint { mut big := []u8{len: size} big[0] = 1 big[size - 1] = 2 - return gc_memory_use() + usize(big[0] + big[size - 1] - 3) + return gc_memory_use() + uint(big[0] + big[size - 1] - 3) } fn test_bytes_since_gc_and_total_bytes_count_the_allocations() { diff --git a/vlib/builtin/gc_roots_vgc_test.v b/vlib/builtin/gc_roots_vgc_test.v index aaa5edee2c..8bd1ab4eec 100644 --- a/vlib/builtin/gc_roots_vgc_test.v +++ b/vlib/builtin/gc_roots_vgc_test.v @@ -24,7 +24,7 @@ fn vgc_test_is_marked(p voidptr) bool { if span == unsafe { nil } || span.mark_bits == unsafe { nil } { return false } - index := u32((usize(p) - span.base) / usize(span.elem_size)) + index := u32((uint(p) - span.base) / uint(span.elem_size)) return C.vgc_bitmap_get(span.mark_bits, index) != 0 } @@ -44,8 +44,8 @@ fn test_the_globals_of_vgc_are_not_roots() { // The cache slot of a thread that does not exist. slot := vgc_max_threads - 1 assert !vgc_heap.caches[slot].registered - vgc_heap.caches[slot].stack_base = usize(p) - vgc_heap.caches[slot].stack_hi = usize(p) + vgc_heap.caches[slot].stack_base = uint(p) + vgc_heap.caches[slot].stack_hi = uint(p) marked := vgc_test_marked_from_data(p) vgc_heap.caches[slot].stack_base = 0 vgc_heap.caches[slot].stack_hi = 0 @@ -61,7 +61,7 @@ fn test_the_tiny_block_of_a_thread_is_a_root() { idx := C.vgc_get_cache_idx() tiny := vgc_heap.caches[idx].tiny assert tiny != 0 - assert usize(p) >= tiny && usize(p) < tiny + vgc_tiny_size + assert uint(p) >= tiny && uint(p) < tiny + vgc_tiny_size // Mark from all the roots, without this thread's stack. lo := vgc_heap.caches[idx].stack_lo hi := vgc_heap.caches[idx].stack_hi @@ -82,7 +82,7 @@ fn test_the_heap_is_far_from_small_numbers() { // Windows hands out the lowest free addresses first: with TinyCC, whose executables // start at 4 MB, the heap started at about 9 MB, where words in the data segment // that hold numbers like 0x2000537 point. The arenas come from the top now. - assert vgc_arena_lo > usize(1) << 32 + assert vgc_arena_lo > uint(1) << 32 } } } diff --git a/vlib/builtin/gc_startup_d_gcboehm.c.v b/vlib/builtin/gc_startup_d_gcboehm.c.v index fbd84d898b..b6b5a3b214 100644 --- a/vlib/builtin/gc_startup_d_gcboehm.c.v +++ b/vlib/builtin/gc_startup_d_gcboehm.c.v @@ -20,7 +20,7 @@ fn C.GC_set_all_interior_pointers(int) fn C.GC_set_pages_executable(int) @[c_extern] -fn C.GC_set_free_space_divisor(usize) +fn C.GC_set_free_space_divisor(uint) @[c_extern] fn C.GC_enable_incremental() diff --git a/vlib/builtin/global_aligned_array_vgc_test.v b/vlib/builtin/global_aligned_array_vgc_test.v index ab65489f26..e700e5bdc8 100644 --- a/vlib/builtin/global_aligned_array_vgc_test.v +++ b/vlib/builtin/global_aligned_array_vgc_test.v @@ -14,7 +14,7 @@ __global vgc_global_aligned_cells = &[1]VgcGlobalAlignedCell{init: VgcGlobalAlig fn test_global_aligned_array_is_scanned_by_vgc() { $if vgc ? { - assert usize(voidptr(vgc_global_aligned_cells)) % 512 == 0 + assert uint(voidptr(vgc_global_aligned_cells)) % 512 == 0 span := vgc_find_span(voidptr(vgc_global_aligned_cells)) assert span != unsafe { nil } assert !span.noscan @@ -43,7 +43,7 @@ fn vgc_test_object_is_marked(value voidptr) bool { if span == unsafe { nil } || span.mark_bits == unsafe { nil } { return false } - index := (usize(value) - span.base) / usize(span.elem_size) + index := (uint(value) - span.base) / uint(span.elem_size) return unsafe { span.mark_bits[index / 8] } & u8(1 << (index % 8)) != 0 } return false diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index 193ed47c2c..a9e67f5b5c 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -9,17 +9,18 @@ pub struct VContext { // ptr_str returns a string with the address of `ptr`. pub fn ptr_str(ptr voidptr) string { - buf1 := u64_to_hex_no_leading_zeros(u64(usize(ptr)), 16) + buf1 := u64_to_hex_no_leading_zeros(u64(uint(ptr)), 16) return buf1 } +// The legacy receiver keeps existing isize method calls working during migration. // str returns the string equivalent of x. pub fn (x isize) str() string { return i64(x).str() } // str returns the string equivalent of x. -pub fn (x usize) str() string { +pub fn (x uint) str() string { return u64(x).str() } diff --git a/vlib/builtin/large_heap_vgc_test.v b/vlib/builtin/large_heap_vgc_test.v index de61b5eec6..eca755e75b 100644 --- a/vlib/builtin/large_heap_vgc_test.v +++ b/vlib/builtin/large_heap_vgc_test.v @@ -7,7 +7,7 @@ module builtin // A page more than an arena: every such object takes an arena of its own. -const vgc_test_big_size = usize(vgc_arena_size + vgc_page_size) +const vgc_test_big_size = uint(vgc_arena_size + vgc_page_size) // vgc_test_big_heap_enabled reports whether the test that needs more than 4 GB of address space // runs. Its objects are never written, so on Linux, macOS and the BSDs they take address space, @@ -38,14 +38,14 @@ fn vgc_test_allocate_big(n int) []voidptr { objs << p } for p in objs { - last := voidptr(usize(p) + vgc_test_big_size - 1) + last := voidptr(uint(p) + vgc_test_big_size - 1) unsafe { *(&u8(p)) = 1 *(&u8(last)) = 2 } span := vgc_find_span(p) assert span != unsafe { nil } - assert span.base == usize(p) + assert span.base == uint(p) assert vgc_find_span(last) == span } return objs @@ -54,8 +54,8 @@ fn vgc_test_allocate_big(n int) []voidptr { // vgc_test_clear_dead_stack overwrites the stack below the caller, where dead frames can still // hold pointers that the conservative stack scan would take for live ones. @[noinline] -fn vgc_test_clear_dead_stack() usize { - buf := [4096]usize{} +fn vgc_test_clear_dead_stack() uint { + buf := [4096]uint{} return buf[0] + buf[4095] } @@ -79,13 +79,13 @@ fn vgc_test_drop(mut objs []voidptr) { fn test_a_pointer_past_the_first_64_mb_of_an_object_is_found() { $if vgc ? { - size := usize(96 * 1024 * 1024) + size := uint(96 * 1024 * 1024) p := vgc_malloc_noscan_opts(size, false) assert p != unsafe { nil } span := vgc_find_span(p) assert span != unsafe { nil } - assert vgc_find_span(voidptr(usize(p) + 80 * 1024 * 1024)) == span - assert vgc_find_span(voidptr(usize(p) + size - 1)) == span + assert vgc_find_span(voidptr(uint(p) + 80 * 1024 * 1024)) == span + assert vgc_find_span(voidptr(uint(p) + size - 1)) == span } } diff --git a/vlib/builtin/linux_bare/libc_impl.v b/vlib/builtin/linux_bare/libc_impl.v index c36dc67d67..6a303bb13b 100644 --- a/vlib/builtin/linux_bare/libc_impl.v +++ b/vlib/builtin/linux_bare/libc_impl.v @@ -5,9 +5,10 @@ import dlmalloc __global global_allocator dlmalloc.Dlmalloc __global global_allocator_ready bool +// memcpy copies n bytes from const_src to dest. @[export: 'memcpy'] @[unsafe] -pub fn memcpy(dest voidptr, const_src voidptr, n usize) voidptr { +pub fn memcpy(dest voidptr, const_src voidptr, n uint) voidptr { dest_ := unsafe { &u8(dest) } src_ := unsafe { &u8(const_src) } unsafe { @@ -22,7 +23,7 @@ pub fn memcpy(dest voidptr, const_src voidptr, n usize) voidptr { // initializes already allocate, so it cannot wait for any of them. @[export: 'malloc'] @[unsafe] -fn __malloc(n usize) voidptr { +fn __malloc(n uint) voidptr { if !global_allocator_ready { init_global_allocator() } @@ -31,21 +32,21 @@ fn __malloc(n usize) voidptr { @[export: 'strlen'] @[unsafe] -fn strlen(const_s voidptr) usize { +fn strlen(const_s voidptr) uint { s := unsafe { &u8(const_s) } mut i := 0 for ; unsafe { s[i] } != 0; i++ { } - return usize(i) + return uint(i) } @[export: 'realloc'] @[unsafe] -fn realloc(old_area voidptr, new_size usize) voidptr { +fn realloc(old_area voidptr, new_size uint) voidptr { if old_area == 0 { return unsafe { __malloc(new_size) } } - if new_size == usize(0) { + if new_size == uint(0) { unsafe { __free(old_area) } return 0 } @@ -54,7 +55,7 @@ fn realloc(old_area voidptr, new_size usize) voidptr { @[export: 'memset'] @[unsafe] -fn memset(s voidptr, c int, n usize) voidptr { +fn memset(s voidptr, c int, n uint) voidptr { mut s_ := unsafe { &char(s) } for i in 0 .. int(n) { unsafe { @@ -68,10 +69,10 @@ fn memset(s voidptr, c int, n usize) voidptr { // needs no temporary buffer. @[export: 'memmove'] @[unsafe] -fn memmove(dest voidptr, const_src voidptr, n usize) voidptr { +fn memmove(dest voidptr, const_src voidptr, n uint) voidptr { dest_ := unsafe { &u8(dest) } src_ := unsafe { &u8(const_src) } - if usize(dest_) <= usize(src_) || usize(dest_) >= usize(src_) + n { + if uint(dest_) <= uint(src_) || uint(dest_) >= uint(src_) + n { for i in 0 .. int(n) { unsafe { dest_[i] = src_[i] @@ -89,7 +90,7 @@ fn memmove(dest voidptr, const_src voidptr, n usize) voidptr { @[export: 'calloc'] @[unsafe] -fn __calloc(nmemb usize, size usize) voidptr { +fn __calloc(nmemb uint, size uint) voidptr { new_area := unsafe { __malloc(nmemb * size) } if new_area != 0 { unsafe { memset(new_area, 0, nmemb * size) } @@ -104,7 +105,7 @@ fn getchar() int { } @[export: 'memcmp'] -fn memcmp(const_a voidptr, const_b voidptr, n usize) int { +fn memcmp(const_a voidptr, const_b voidptr, n uint) int { a_ := unsafe { &u8(const_a) } b_ := unsafe { &u8(const_b) } for i in 0 .. int(n) { @@ -132,7 +133,7 @@ fn vsprintf(str &char, format &char, ap &u8) int { panic('vsprintf(): string interpolation is not supported in `-freestanding`') } -fn vsnprintf(str &char, size usize, format &char, ap &u8) int { +fn vsnprintf(str &char, size uint, format &char, ap &u8) int { panic('vsnprintf(): string interpolation is not supported in `-freestanding`') } @@ -172,7 +173,7 @@ fn __exit(code int) { // __qsort takes the C callback type: a V `FnSortCB` returns a 64-bit `int`. @[export: 'qsort'] -fn __qsort(base voidptr, nmemb usize, size usize, sort_cb C.qsort_callback_func) { +fn __qsort(base voidptr, nmemb uint, size uint, sort_cb C.qsort_callback_func) { panic('qsort() is not yet implemented in `-freestanding`') } diff --git a/vlib/builtin/linux_bare/linux_syscalls.i386.v b/vlib/builtin/linux_bare/linux_syscalls.i386.v index 01912d0180..f6d2cf5b75 100644 --- a/vlib/builtin/linux_bare/linux_syscalls.i386.v +++ b/vlib/builtin/linux_bare/linux_syscalls.i386.v @@ -1,16 +1,16 @@ module builtin struct LinuxMmapArgs { - addr usize - len usize - prot usize - flags usize - fd usize - offset usize + addr uint + len uint + prot uint + flags uint + fd uint + offset uint } -fn split_int_errno(rc_in usize) (i64, Errno) { - rc := isize(rc_in) +fn split_int_errno(rc_in uint) (i64, Errno) { + rc := int(rc_in) if rc < 0 { return i64(-1), unsafe { Errno(-rc) } } @@ -19,64 +19,64 @@ fn split_int_errno(rc_in usize) (i64, Errno) { // 3 sys_read fn sys_read(fd i64, buf &u8, count u64) (i64, Errno) { - return split_int_errno(sys_call3(3, usize(fd), usize(buf), usize(count))) + return split_int_errno(sys_call3(3, uint(fd), uint(buf), uint(count))) } // 4 sys_write. pub fn sys_write(fd i64, buf &u8, count u64) (i64, Errno) { - return split_int_errno(sys_call3(4, usize(fd), usize(buf), usize(count))) + return split_int_errno(sys_call3(4, uint(fd), uint(buf), uint(count))) } // 5 sys_open fn sys_open(filename &u8, flags i64, mode int) (i64, Errno) { - return split_int_errno(sys_call3(5, usize(filename), usize(flags), usize(mode))) + return split_int_errno(sys_call3(5, uint(filename), uint(flags), uint(mode))) } // 6 sys_close fn sys_close(fd i64) Errno { - return unsafe { Errno(-isize(sys_call1(6, usize(fd)))) } + return unsafe { Errno(-int(sys_call1(6, uint(fd)))) } } // 90 sys_mmap fn sys_mmap(addr &u8, len u64, prot MemProt, flags MapFlags, fildes i64, off u64) (&u8, Errno) { args := LinuxMmapArgs{ - addr: usize(addr) - len: usize(len) - prot: usize(prot) - flags: usize(flags) - fd: usize(fildes) - offset: usize(off) + addr: uint(addr) + len: uint(len) + prot: uint(prot) + flags: uint(flags) + fd: uint(fildes) + offset: uint(off) } - rc := sys_call1(90, usize(&args)) + rc := sys_call1(90, uint(&args)) a, e := split_int_errno(rc) - return unsafe { &u8(usize(a)) }, e + return unsafe { &u8(uint(a)) }, e } // 91 sys_munmap fn sys_munmap(addr voidptr, len u64) Errno { - return unsafe { Errno(-isize(sys_call2(91, usize(addr), usize(len)))) } + return unsafe { Errno(-int(sys_call2(91, uint(addr), uint(len)))) } } // 163 sys_mremap fn sys_mremap(old_addr voidptr, old_len u64, new_len u64, flags u64) (&u8, Errno) { - rc := sys_call4(163, usize(old_addr), usize(old_len), usize(new_len), usize(flags)) + rc := sys_call4(163, uint(old_addr), uint(old_len), uint(new_len), uint(flags)) a, e := split_int_errno(rc) - return unsafe { &u8(usize(a)) }, e + return unsafe { &u8(uint(a)) }, e } // 42 sys_pipe fn sys_pipe(filedes &int) Errno { - return unsafe { Errno(isize(sys_call1(42, usize(filedes)))) } + return unsafe { Errno(int(sys_call1(42, uint(filedes)))) } } // 158 sys_sched_yield fn sys_sched_yield() Errno { - return unsafe { Errno(isize(sys_call0(158))) } + return unsafe { Errno(int(sys_call0(158))) } } // 219 sys_madvise fn sys_madvise(addr voidptr, len u64, advice int) Errno { - return unsafe { Errno(isize(sys_call3(219, usize(addr), usize(len), usize(advice)))) } + return unsafe { Errno(int(sys_call3(219, uint(addr), uint(len), uint(advice)))) } } // 20 sys_getpid @@ -96,18 +96,18 @@ fn sys_vfork() int { // 63 sys_dup2 fn sys_dup2(oldfd int, newfd int) (i64, Errno) { - return split_int_errno(sys_call2(63, usize(oldfd), usize(newfd))) + return split_int_errno(sys_call2(63, uint(oldfd), uint(newfd))) } // 11 sys_execve fn sys_execve(filename &u8, argv []&u8, envp []&u8) int { - return int(sys_call3(11, usize(filename), usize(argv.data), usize(envp.data))) + return int(sys_call3(11, uint(filename), uint(argv.data), uint(envp.data))) } // 1 sys_exit @[noreturn] fn sys_exit(ec int) { - sys_call1(1, usize(ec)) + sys_call1(1, uint(ec)) for {} } @@ -119,13 +119,13 @@ fn sys_getuid() int { // 284 sys_waitid fn sys_waitid(which WiWhich, pid int, infop &int, options int, ru voidptr) Errno { return unsafe { - Errno(isize(sys_call5(284, usize(which), usize(pid), usize(infop), usize(options), - usize(ru)))) + Errno(int(sys_call5(284, uint(which), uint(pid), uint(infop), uint(options), + uint(ru)))) } } -fn sys_call0(scn usize) usize { - mut res := usize(0) +fn sys_call0(scn uint) uint { + mut res := uint(0) asm volatile i386 { mov eax, scn int 0x80 @@ -138,8 +138,8 @@ fn sys_call0(scn usize) usize { return res } -fn sys_call1(scn usize, arg1 usize) usize { - mut res := usize(0) +fn sys_call1(scn uint, arg1 uint) uint { + mut res := uint(0) asm volatile i386 { mov eax, scn mov ebx, arg1 @@ -155,8 +155,8 @@ fn sys_call1(scn usize, arg1 usize) usize { return res } -fn sys_call2(scn usize, arg1 usize, arg2 usize) usize { - mut res := usize(0) +fn sys_call2(scn uint, arg1 uint, arg2 uint) uint { + mut res := uint(0) asm volatile i386 { mov eax, scn mov ebx, arg1 @@ -175,8 +175,8 @@ fn sys_call2(scn usize, arg1 usize, arg2 usize) usize { return res } -fn sys_call3(scn usize, arg1 usize, arg2 usize, arg3 usize) usize { - mut res := usize(0) +fn sys_call3(scn uint, arg1 uint, arg2 uint, arg3 uint) uint { + mut res := uint(0) asm volatile i386 { mov eax, scn mov ebx, arg1 @@ -198,8 +198,8 @@ fn sys_call3(scn usize, arg1 usize, arg2 usize, arg3 usize) usize { return res } -fn sys_call4(scn usize, arg1 usize, arg2 usize, arg3 usize, arg4 usize) usize { - mut res := usize(0) +fn sys_call4(scn uint, arg1 uint, arg2 uint, arg3 uint, arg4 uint) uint { + mut res := uint(0) asm volatile i386 { mov eax, scn mov ebx, arg1 @@ -224,8 +224,8 @@ fn sys_call4(scn usize, arg1 usize, arg2 usize, arg3 usize, arg4 usize) usize { return res } -fn sys_call5(scn usize, arg1 usize, arg2 usize, arg3 usize, arg4 usize, arg5 usize) usize { - mut res := usize(0) +fn sys_call5(scn uint, arg1 uint, arg2 uint, arg3 uint, arg4 uint, arg5 uint) uint { + mut res := uint(0) asm volatile i386 { mov eax, scn mov ebx, arg1 diff --git a/vlib/builtin/linux_bare/memory_managment.v b/vlib/builtin/linux_bare/memory_managment.v index 95221f2e7e..ede7743765 100644 --- a/vlib/builtin/linux_bare/memory_managment.v +++ b/vlib/builtin/linux_bare/memory_managment.v @@ -30,7 +30,7 @@ fn mm_free(addr &u8) Errno { } } -fn system_alloc(_ voidptr, size usize) (voidptr, usize, u32) { +fn system_alloc(_ voidptr, size uint) (voidptr, uint, u32) { // BEGIN CONSTS // the constants need to be here, since the initialization of other constants, // which happen before these ones would, require malloc @@ -46,21 +46,21 @@ fn system_alloc(_ voidptr, size usize) (voidptr, usize, u32) { return unsafe { nil }, 0, 0 } -fn system_remap(_ voidptr, ptr voidptr, oldsize usize, newsize usize, can_move bool) voidptr { +fn system_remap(_ voidptr, ptr voidptr, oldsize uint, newsize uint, can_move bool) voidptr { return unsafe { nil } } -fn system_free_part(_ voidptr, ptr voidptr, oldsize usize, newsize usize) bool { +fn system_free_part(_ voidptr, ptr voidptr, oldsize uint, newsize uint) bool { _, e := sys_mremap(ptr, u64(oldsize), u64(newsize), 0) if e == .enoerror { return true } - e2 := sys_munmap(voidptr(usize(ptr) + newsize), u64(oldsize - newsize)) + e2 := sys_munmap(voidptr(uint(ptr) + newsize), u64(oldsize - newsize)) return e2 == .enoerror } -fn system_free(_ voidptr, ptr voidptr, size usize) bool { +fn system_free(_ voidptr, ptr voidptr, size uint) bool { unsafe { return sys_munmap(ptr, u64(size)) == .enoerror } @@ -74,7 +74,7 @@ fn system_allocates_zeros(_ voidptr) bool { return true } -fn system_page_size(_ voidptr) usize { +fn system_page_size(_ voidptr) uint { return 4096 } diff --git a/vlib/builtin/linux_bare/old/mm_bare.v b/vlib/builtin/linux_bare/old/mm_bare.v index 53b02a1134..c59ecaf6f3 100644 --- a/vlib/builtin/linux_bare/old/mm_bare.v +++ b/vlib/builtin/linux_bare/old/mm_bare.v @@ -29,7 +29,8 @@ pub fn mm_free(addr &u8) Errno { return sys_munmap(ap, size) } -pub fn mem_copy(dest0 voidptr, src0 voidptr, n isize) voidptr { +// mem_copy copies n bytes from src0 to dest0. +pub fn mem_copy(dest0 voidptr, src0 voidptr, n int) voidptr { mut dest := &u8(dest0) src := &u8(src0) for i in 0 .. n { @@ -38,8 +39,9 @@ pub fn mem_copy(dest0 voidptr, src0 voidptr, n isize) voidptr { return dest0 } +// malloc allocates n bytes of memory. @[unsafe] -pub fn malloc(n isize) &u8 { +pub fn malloc(n int) &u8 { if n < 0 { panic('malloc(<0)') } diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index ff278ee744..462ec6852b 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -468,9 +468,9 @@ fn (m &map) key_to_index(pkey voidptr) (u32, u32) { if voidptr(m.hash_fn) == unsafe { nil } { unsafe { p := &u64(m) - prev2 := (&u64(usize(m) - usize(16)))[0] - prev1 := (&u64(usize(m) - usize(8)))[0] - panic('map.hash_fn is nil map_ptr=${usize(m)} key_bytes=${m.key_bytes} value_bytes=${m.value_bytes} even_index=${m.even_index} shift=${m.shift} metas=${usize(m.metas)} prev2=${prev2} prev1=${prev1} w0=${p[0]} w1=${p[1]} w2=${p[2]} w3=${p[3]} w4=${p[4]} w5=${p[5]} w6=${p[6]} w7=${p[7]} hash_fn=${usize(voidptr(m.hash_fn))}') + prev2 := (&u64(uint(m) - uint(16)))[0] + prev1 := (&u64(uint(m) - uint(8)))[0] + panic('map.hash_fn is nil map_ptr=${uint(m)} key_bytes=${m.key_bytes} value_bytes=${m.value_bytes} even_index=${m.even_index} shift=${m.shift} metas=${uint(m.metas)} prev2=${prev2} prev1=${prev1} w0=${p[0]} w1=${p[1]} w2=${p[2]} w3=${p[3]} w4=${p[4]} w5=${p[5]} w6=${p[6]} w7=${p[7]} hash_fn=${uint(voidptr(m.hash_fn))}') } } hash := if voidptr(m.hash_fn) == voidptr(map_hash_string) { diff --git a/vlib/builtin/map_clone_alignment_test.v b/vlib/builtin/map_clone_alignment_test.v index 2360f58d26..0876197124 100644 --- a/vlib/builtin/map_clone_alignment_test.v +++ b/vlib/builtin/map_clone_alignment_test.v @@ -7,7 +7,7 @@ struct AlignedCloneCell { fn clone_aligned_map_key(destination voidptr, source voidptr) { // The raw map callback copies the complete aligned key, including its padding. - unsafe { vmemcpy(destination, source, sizeof(AlignedCloneCell)) } + unsafe { vmemcpy(destination, source, int(sizeof(AlignedCloneCell))) } } fn assert_aligned_map_clone_storage(value &map) { @@ -16,25 +16,25 @@ fn assert_aligned_map_clone_storage(value &map) { if value.data.count == 0 { return } - assert usize(value.data.key_values.keys) % 64 == 0 - assert usize(value.data.key_values.values) % 64 == 0 + assert uint(value.data.key_values.keys) % 64 == 0 + assert uint(value.data.key_values.values) % 64 == 0 keys := value.keys() values := value.values() assert keys.data_alignment() == 64 assert values.data_alignment() == 64 - assert usize(keys.data) % 64 == 0 - assert usize(values.data) % 64 == 0 + assert uint(keys.data) % 64 == 0 + assert uint(values.data) % 64 == 0 for i in 0 .. keys.len { // Raw map exports have the same aligned element layout as the input cells. key := unsafe { &AlignedCloneCell(&u8(keys.data) + i * int(sizeof(AlignedCloneCell))) } item := unsafe { &AlignedCloneCell(&u8(values.data) + i * int(sizeof(AlignedCloneCell))) } - assert usize(key) % 64 == 0 - assert usize(item) % 64 == 0 + assert uint(key) % 64 == 0 + assert uint(item) % 64 == 0 assert key.value == u64(i + 1) assert item.value == key.value * 10 zero := AlignedCloneCell{} stored := unsafe { &AlignedCloneCell(value.get(key, &zero)) } - assert usize(stored) % 64 == 0 + assert uint(stored) % 64 == 0 assert stored.value == item.value } unsafe { @@ -87,13 +87,13 @@ fn test_sparse_typed_map_clone_keeps_aligned_values() { assert copied['only'].value == 42 // Inspect each map element's address before any subsequent map mutation. first_address := unsafe { voidptr(&copied['only']) } - assert usize(first_address) % 64 == 0 + assert uint(first_address) % 64 == 0 values := copied.values() - assert usize(values.data) % 64 == 0 + assert uint(values.data) % 64 == 0 assert values[0].value == 42 copied['next'] = AlignedCloneCell{ value: 99 } next_address := unsafe { voidptr(&copied['next']) } - assert usize(next_address) % 64 == 0 + assert uint(next_address) % 64 == 0 assert 'next' !in original unsafe { values.free() diff --git a/vlib/builtin/map_d_v3_backend.v b/vlib/builtin/map_d_v3_backend.v index 7f2b274037..706caa1ff2 100644 --- a/vlib/builtin/map_d_v3_backend.v +++ b/vlib/builtin/map_d_v3_backend.v @@ -408,7 +408,7 @@ fn new_map(key_bytes int, value_bytes int, hash_fn MapHashFn, key_eq_fn MapEqFn, } fn new_map_aligned(key_bytes int, value_bytes int, hash_fn MapHashFn, key_eq_fn MapEqFn, - clone_fn MapCloneFn, free_fn MapFreeFn, key_alignment usize, value_alignment usize) map { + clone_fn MapCloneFn, free_fn MapFreeFn, key_alignment uint, value_alignment uint) map { mut result := new_map(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn, free_fn) result.data.key_values.key_alignment = data_alignment_exponent(key_alignment) result.data.key_values.value_alignment = data_alignment_exponent(value_alignment) @@ -493,9 +493,9 @@ fn (mut m VMapData) clear() { fn (m &VMapData) panic_nil_map_hash_fn() { unsafe { p := &u64(m) - prev2 := (&u64(usize(m) - usize(16)))[0] - prev1 := (&u64(usize(m) - usize(8)))[0] - panic('map.hash_fn is nil map_ptr=${usize(m)} key_bytes=${m.key_bytes} value_bytes=${m.value_bytes} even_index=${m.even_index} shift=${m.shift} metas=${usize(m.metas)} prev2=${prev2} prev1=${prev1} w0=${p[0]} w1=${p[1]} w2=${p[2]} w3=${p[3]} w4=${p[4]} w5=${p[5]} w6=${p[6]} w7=${p[7]} hash_fn=${usize(voidptr(m.hash_fn))}') + prev2 := (&u64(uint(m) - uint(16)))[0] + prev1 := (&u64(uint(m) - uint(8)))[0] + panic('map.hash_fn is nil map_ptr=${uint(m)} key_bytes=${m.key_bytes} value_bytes=${m.value_bytes} even_index=${m.even_index} shift=${m.shift} metas=${uint(m.metas)} prev2=${prev2} prev1=${prev1} w0=${p[0]} w1=${p[1]} w2=${p[2]} w3=${p[3]} w4=${p[4]} w5=${p[5]} w6=${p[6]} w7=${p[7]} hash_fn=${uint(voidptr(m.hash_fn))}') } } @@ -760,7 +760,7 @@ fn (mut m VMapData) cached_rehash(old_cap u32) { m.meta_greater(index, meta, kv_index) } $if prealloc { - unsafe { prealloc_discard_pages(old_metas, usize(sizeof(u32)) * usize(old_cap + 2 + old_extra_metas)) } + unsafe { prealloc_discard_pages(old_metas, uint(sizeof(u32)) * uint(old_cap + 2 + old_extra_metas)) } } unsafe { free(old_metas) } } @@ -1083,7 +1083,7 @@ fn dense_array_allocate(size u64, alignment u8) &u8 { if alignment == 0 { return unsafe { malloc(__at_least_one(size)) } } - return alloc_array_data_aligned(size, usize(1) << alignment, false) + return alloc_array_data_aligned(size, uint(1) << alignment, false) } @[inline; unsafe] @@ -1125,7 +1125,7 @@ fn (m &VMapData) keys() array { mut keys := if alignment == 0 { __new_array(m.count, 0, m.key_bytes) } else { - __new_array_aligned(m.count, 0, m.key_bytes, usize(1) << alignment) + __new_array_aligned(m.count, 0, m.key_bytes, uint(1) << alignment) } mut item := unsafe { &u8(keys.data) } if m.key_values.deletes == 0 { @@ -1161,7 +1161,7 @@ fn (m &VMapData) values() array { mut values := if alignment == 0 { __new_array(m.count, 0, m.value_bytes) } else { - __new_array_aligned(m.count, 0, m.value_bytes, usize(1) << alignment) + __new_array_aligned(m.count, 0, m.value_bytes, uint(1) << alignment) } if m.count == 0 { return values @@ -1303,7 +1303,7 @@ pub fn (m &map) free() { @[unsafe] fn (m &VMapData) free() { $if prealloc { - unsafe { prealloc_discard_pages(m.metas, usize(sizeof(u32)) * usize(m.even_index + 2 + m.extra_metas)) } + unsafe { prealloc_discard_pages(m.metas, uint(sizeof(u32)) * uint(m.even_index + 2 + m.extra_metas)) } } unsafe { free(m.metas) } unsafe { @@ -1336,14 +1336,14 @@ fn (m &VMapData) free() { } if m.key_values.keys != nil { $if prealloc { - prealloc_discard_pages(m.key_values.keys, usize(m.key_values.cap) * usize(m.key_bytes)) + prealloc_discard_pages(m.key_values.keys, uint(m.key_values.cap) * uint(m.key_bytes)) } dense_array_free(m.key_values.keys, m.key_values.key_alignment) m.key_values.keys = nil } if m.key_values.values != nil { $if prealloc { - prealloc_discard_pages(m.key_values.values, usize(m.key_values.cap) * usize(m.value_bytes)) + prealloc_discard_pages(m.key_values.values, uint(m.key_values.cap) * uint(m.value_bytes)) } dense_array_free(m.key_values.values, m.key_values.value_alignment) m.key_values.values = nil diff --git a/vlib/builtin/map_empty_value_test.v b/vlib/builtin/map_empty_value_test.v index 58e5b9c6a5..64ffb73d30 100644 --- a/vlib/builtin/map_empty_value_test.v +++ b/vlib/builtin/map_empty_value_test.v @@ -44,7 +44,7 @@ fn test_dense_array_zero_value_size_with_every_c_compiler() { key_bytes: int(sizeof(int)) value_bytes: 0 cap: 8 - keys: unsafe { malloc(8 * isize(sizeof(int))) } + keys: unsafe { malloc(8 * int(sizeof(int))) } values: unsafe { malloc(1) } } // DenseArray stores raw key bytes; fill and inspect its integer slots directly. diff --git a/vlib/builtin/platform_uint_test.v b/vlib/builtin/platform_uint_test.v new file mode 100644 index 0000000000..63c6c90f64 --- /dev/null +++ b/vlib/builtin/platform_uint_test.v @@ -0,0 +1,29 @@ +module builtin + +fn test_platform_uint_preserves_unsigned_range() { + assert sizeof(uint) == sizeof(int) + assert sizeof(uint) == sizeof(voidptr) + maximum := ~uint(0) + assert maximum > uint(max_int) + assert maximum >> (sizeof(uint) * 8 - 1) == 1 + assert maximum + uint(1) == 0 + $if x64 || arm64 { + assert maximum.str() == '18446744073709551615' + assert uint(1) << 40 == u64(1099511627776) + } $else $if x32 || arm32 { + assert maximum.str() == '4294967295' + } + mut values := map[uint]int{} + values[maximum] = -1 + assert values[maximum] == -1 +} + +fn test_platform_uint_pointer_round_trip() { + value := 42 + address := uint(&value) + // Recover and dereference the pointer from its integer address. + unsafe { + assert &int(address) == &value + assert *(&int(address)) == value + } +} diff --git a/vlib/builtin/prealloc.c.v b/vlib/builtin/prealloc.c.v index 0ce2fd9636..d176bb5e38 100644 --- a/vlib/builtin/prealloc.c.v +++ b/vlib/builtin/prealloc.c.v @@ -15,14 +15,14 @@ fn C.v_prealloc_atomic_add_i64(ptr &i64, delta i64) i64 fn C.v_prealloc_atomic_load_i64(ptr &i64) i64 -fn C.madvise(addr voidptr, length usize, advice int) int +fn C.madvise(addr voidptr, length uint, advice int) int // prealloc_discard_pages releases physical backing for dead arena storage on // macOS and Linux. Only complete pages inside the range are discarded; their // addresses remain reserved and writable until the containing arena is freed. // No surviving value may depend on the contents of this range. @[unsafe] -pub fn prealloc_discard_pages(start voidptr, size usize) { +pub fn prealloc_discard_pages(start voidptr, size uint) { $if prealloc && !freestanding && !vinix && (macos || linux) { if size < 65_536 || start == unsafe { nil } { return @@ -31,9 +31,9 @@ pub fn prealloc_discard_pages(start voidptr, size usize) { if page_bytes <= 0 { return } - page_size := usize(page_bytes) - lo := (usize(start) + page_size - 1) / page_size * page_size - hi := (usize(start) + size) / page_size * page_size + page_size := uint(page_bytes) + lo := (uint(start) + page_size - 1) / page_size * page_size + hi := (uint(start) + size) / page_size * page_size if hi <= lo { return } @@ -82,8 +82,8 @@ __global g_prealloc_allocated_bytes i64 // prealloc_recyclable_block_size reports whether a block belongs to one of // the scope size classes (256K..1M, the geometric scope growth ladder) that // the per-thread recycle cache retains. -fn prealloc_recyclable_block_size(size isize) bool { - base := isize(prealloc_scope_block_size) +fn prealloc_recyclable_block_size(size int) bool { + base := int(prealloc_scope_block_size) return size == base || size == base * 2 || size == base * 4 } @@ -96,9 +96,9 @@ fn prealloc_recyclable_block_size(size isize) bool { struct VPreallocBlockCache { mut: count int - bytes isize + bytes int starts [prealloc_recycle_cache_slots]voidptr - sizes [prealloc_recycle_cache_slots]isize + sizes [prealloc_recycle_cache_slots]int } @[inline] @@ -139,7 +139,7 @@ mut: next &VMemoryBlock = 0 // 8 scope &VPreallocScope = 0 recycle_cache &VPreallocBlockCache = 0 - min_block_size isize + min_block_size int is_scope bool mmap_allocated bool id int // 4 @@ -149,8 +149,8 @@ mut: @[heap] struct VPreallocRange { mut: - start usize - stop usize + start uint + stop uint } @[heap] @@ -162,8 +162,8 @@ mut: // linked after it: a reentered parent scope keeps rewound blocks there. // Unlinking the scope restores them instead of dropping them from the chain. saved_next &VMemoryBlock = 0 - min_address usize - max_address usize + min_address uint + max_address uint ranges &VPreallocRange = 0 ranges_len int ranges_cap int @@ -184,13 +184,13 @@ fn prealloc_scope_add_block(scope &VPreallocScope, block &VMemoryBlock) { unsafe { if scope.ranges_len == scope.ranges_cap { new_cap := if scope.ranges_cap == 0 { 8 } else { scope.ranges_cap * 2 } - ranges := &VPreallocRange(C.realloc(scope.ranges, usize(new_cap) * sizeof(VPreallocRange))) - vmemory_abort_on_nil(ranges, isize(new_cap) * isize(sizeof(VPreallocRange))) + ranges := &VPreallocRange(C.realloc(scope.ranges, uint(new_cap) * sizeof(VPreallocRange))) + vmemory_abort_on_nil(ranges, int(new_cap) * int(sizeof(VPreallocRange))) scope.ranges = ranges scope.ranges_cap = new_cap } - start := usize(block.start) - stop := usize(block.stop) + start := uint(block.start) + stop := uint(block.stop) mut insert := scope.ranges_len for insert > 0 && scope.ranges[insert - 1].start > start { scope.ranges[insert] = scope.ranges[insert - 1] @@ -218,7 +218,7 @@ fn prealloc_scope_remove_block(scope &VPreallocScope, block &VMemoryBlock) { return } unsafe { - start := usize(block.start) + start := uint(block.start) for i in 0 .. scope.ranges_len { if scope.ranges[i].start == start { for j := i; j + 1 < scope.ranges_len; j++ { @@ -236,7 +236,7 @@ fn prealloc_scope_remove_block(scope &VPreallocScope, block &VMemoryBlock) { } } -fn vmemory_abort_on_nil(p voidptr, bytes isize) { +fn vmemory_abort_on_nil(p voidptr, bytes int) { if unsafe { p == 0 } { C.fprintf(C.stderr, c'could not allocate %td bytes\n', bytes) exit(1) @@ -244,8 +244,8 @@ fn vmemory_abort_on_nil(p voidptr, bytes isize) { } @[inline] -fn vmemory_effective_align(align isize) isize { - default_align := isize(prealloc_default_align) +fn vmemory_effective_align(align int) int { + default_align := int(prealloc_default_align) if align > default_align { return align } @@ -253,7 +253,7 @@ fn vmemory_effective_align(align isize) isize { } @[inline; unsafe] -fn vmemory_align_up(ptr &u8, align isize) &u8 { +fn vmemory_align_up(ptr &u8, align int) &u8 { if align <= 1 { return ptr } @@ -303,12 +303,12 @@ fn prealloc_trace_scope(action &char, scope &VPreallocScope) { } @[unsafe] -fn vmemory_block_new(prev &VMemoryBlock, at_least isize, align isize) &VMemoryBlock { - return unsafe { vmemory_block_new_sized(prev, at_least, align, isize(prealloc_block_size)) } +fn vmemory_block_new(prev &VMemoryBlock, at_least int, align int) &VMemoryBlock { + return unsafe { vmemory_block_new_sized(prev, at_least, align, int(prealloc_block_size)) } } @[unsafe] -fn vmemory_block_new_sized(prev &VMemoryBlock, at_least isize, align isize, min_block_size isize) &VMemoryBlock { +fn vmemory_block_new_sized(prev &VMemoryBlock, at_least int, align int, min_block_size int) &VMemoryBlock { vmem_block_size := sizeof(VMemoryBlock) mut v := unsafe { &VMemoryBlock(C.calloc(1, vmem_block_size)) } vmemory_abort_on_nil(v, vmem_block_size) @@ -325,7 +325,7 @@ fn vmemory_block_new_sized(prev &VMemoryBlock, at_least isize, align isize, min_ effective_min_block_size := if min_block_size > 0 { min_block_size } else { - isize(prealloc_block_size) + int(prealloc_block_size) } v.min_block_size = effective_min_block_size base_block_size := if at_least < effective_min_block_size { @@ -351,7 +351,7 @@ fn vmemory_block_new_sized(prev &VMemoryBlock, at_least isize, align isize, min_ v.start = unsafe { C._aligned_malloc(block_size, fixed_align) } } $else { $if !freestanding && !vinix { - if fixed_align <= isize(prealloc_default_align) { + if fixed_align <= int(prealloc_default_align) { $if !prealloc_no_recycle ? { if prealloc_recyclable_block_size(block_size) { unsafe { @@ -377,7 +377,7 @@ fn vmemory_block_new_sized(prev &VMemoryBlock, at_least isize, align isize, min_ } if unsafe { v.start == 0 } { mmap_ptr := unsafe { - C.mmap(0, usize(block_size), C.PROT_READ | C.PROT_WRITE, C.MAP_ANONYMOUS | C.MAP_PRIVATE, -1, 0) + C.mmap(0, uint(block_size), C.PROT_READ | C.PROT_WRITE, C.MAP_ANONYMOUS | C.MAP_PRIVATE, -1, 0) } if mmap_ptr != C.MAP_FAILED { v.start = &u8(mmap_ptr) @@ -426,7 +426,7 @@ fn vmemory_block_current_or_new() &VMemoryBlock { @[noinline; unsafe] fn vmemory_block_init_thread() &VMemoryBlock { unsafe { - mut mb := vmemory_block_new(nil, isize(prealloc_block_size), 0) + mut mb := vmemory_block_new(nil, int(prealloc_block_size), 0) mb.recycle_cache = &VPreallocBlockCache(C.calloc(1, sizeof(VPreallocBlockCache))) vmemory_abort_on_nil(mb.recycle_cache, sizeof(VPreallocBlockCache)) g_memory_block = mb @@ -435,7 +435,7 @@ fn vmemory_block_init_thread() &VMemoryBlock { } @[noinline; unsafe] -fn vmemory_block_grow(previous &VMemoryBlock, n isize, align isize) &VMemoryBlock { +fn vmemory_block_grow(previous &VMemoryBlock, n int, align int) &VMemoryBlock { unsafe { was_scope := previous.is_scope scope := previous.scope @@ -457,9 +457,9 @@ fn vmemory_block_grow(previous &VMemoryBlock, n isize, align isize) &VMemoryBloc mut min_block_size := if previous.min_block_size > 0 { previous.min_block_size } else { - isize(prealloc_block_size) + int(prealloc_block_size) } - if was_scope && min_block_size < isize(prealloc_scope_block_size) * 4 { + if was_scope && min_block_size < int(prealloc_scope_block_size) * 4 { // Scopes that outgrow one block tend to keep growing: doubling // the block size (256K..4M) turns a 100-block scope into ~10 // blocks, cutting refill and map/unmap churn per batch. @@ -482,13 +482,13 @@ fn vmemory_block_grow(previous &VMemoryBlock, n isize, align isize) &VMemoryBloc } @[inline; unsafe] -fn vmemory_block_malloc(n isize, align isize) &u8 { +fn vmemory_block_malloc(n int, align int) &u8 { return unsafe { vmemory_block_malloc_aligned(n, vmemory_effective_align(align)) } } // Byte buffers can use alignment 1; general allocations retain the default alignment. @[inline; unsafe] -fn vmemory_block_malloc_aligned(n isize, align isize) &u8 { +fn vmemory_block_malloc_aligned(n int, align int) &u8 { unsafe { // Read the thread-local block pointer ONCE per call: it only stores // which block is current, and the bump updates go through the block @@ -543,7 +543,7 @@ fn vmemory_block_free(mb &VMemoryBlock) { size := vmemory_block_size(mb) mut recycled := false $if !prealloc_no_recycle ? { - if prealloc_recyclable_block_size(isize(size)) { + if prealloc_recyclable_block_size(int(size)) { unsafe { mut cache := &VPreallocBlockCache(nil) if g_memory_block != 0 { @@ -551,10 +551,10 @@ fn vmemory_block_free(mb &VMemoryBlock) { } cache_limit := prealloc_recycle_cache_limit() if cache != 0 && cache.count < cache_limit - && cache.bytes + isize(size) <= isize(prealloc_scope_block_size) * cache_limit { + && cache.bytes + int(size) <= int(prealloc_scope_block_size) * cache_limit { cache.starts[cache.count] = voidptr(mb.start) - cache.sizes[cache.count] = isize(size) - cache.bytes += isize(size) + cache.sizes[cache.count] = int(size) + cache.bytes += int(size) cache.count++ recycled = true } @@ -565,7 +565,7 @@ fn vmemory_block_free(mb &VMemoryBlock) { $if prealloc_trace_recycle ? { C.fprintf(C.stderr, c'[recycle-miss] size=%lld\n', size) } - C.munmap(mb.start, usize(size)) + C.munmap(mb.start, uint(size)) } } else { C.free(mb.start) @@ -609,7 +609,7 @@ fn prealloc_recycle_cache_free(cache &VPreallocBlockCache) { $if !windows && !freestanding && !vinix { unsafe { for i in 0 .. cache.count { - C.munmap(cache.starts[i], usize(cache.sizes[i])) + C.munmap(cache.starts[i], uint(cache.sizes[i])) } } } @@ -644,7 +644,7 @@ fn prealloc_vinit() { C.fprintf(C.stderr, c'prealloc_vinit started\n') } unsafe { - mut root := vmemory_block_new(nil, isize(prealloc_block_size), 0) + mut root := vmemory_block_new(nil, int(prealloc_block_size), 0) root.recycle_cache = &VPreallocBlockCache(C.calloc(1, sizeof(VPreallocBlockCache))) vmemory_abort_on_nil(root.recycle_cache, sizeof(VPreallocBlockCache)) g_memory_block = root @@ -697,10 +697,10 @@ fn prealloc_vcleanup() { C.fprintf(C.stderr, c'prealloc_vcleanup dumping mb: %p, mb.id: %d, used: %10lld bytes\n', mb, mb.id, used) mut ptr := mb.start - mut remaining_bytes := isize(used) - mut x := isize(0) + mut remaining_bytes := int(used) + mut x := int(0) for remaining_bytes > 0 { - x = isize(C.fwrite(ptr, 1, remaining_bytes, stream)) + x = int(C.fwrite(ptr, 1, remaining_bytes, stream)) ptr += x remaining_bytes -= x } @@ -731,11 +731,11 @@ pub fn prealloc_scope_begin() voidptr { vmemory_abort_on_nil(scope, sizeof(VPreallocScope)) scope.previous = vmemory_block_current_or_new() scope.saved_next = scope.previous.next - scope.first = vmemory_block_new_sized(scope.previous, isize(prealloc_scope_block_size), 0, isize(prealloc_scope_block_size)) + scope.first = vmemory_block_new_sized(scope.previous, int(prealloc_scope_block_size), 0, int(prealloc_scope_block_size)) scope.first.is_scope = true scope.first.scope = scope - scope.min_address = usize(scope.first.start) - scope.max_address = usize(scope.first.stop) + scope.min_address = uint(scope.first.start) + scope.max_address = uint(scope.first.stop) prealloc_scope_add_block(scope, scope.first) g_memory_block = scope.first prealloc_trace_scope(c'begin', scope) @@ -933,7 +933,7 @@ pub fn prealloc_scope_leave(scope_ptr voidptr) { // leaving the scope untouched, when the scope is still current, retained by // another owner, or already being freed; the caller then starts a new scope. @[unsafe] -pub fn prealloc_scope_reenter(scope_ptr voidptr, keep_bytes isize) bool { +pub fn prealloc_scope_reenter(scope_ptr voidptr, keep_bytes int) bool { $if prealloc { if scope_ptr == unsafe { nil } { return false @@ -949,11 +949,11 @@ pub fn prealloc_scope_reenter(scope_ptr voidptr, keep_bytes isize) bool { } parent := vmemory_block_current_or_new() // Keep the first blocks, up to `keep_bytes`, for reuse; free the rest. - mut kept := isize(0) + mut kept := int(0) mut last_kept := &VMemoryBlock(nil) mut mb := scope.first for mb != 0 && mb.is_scope && mb.scope == scope { - size := isize(vmemory_block_size(mb)) + size := int(vmemory_block_size(mb)) if last_kept != 0 && kept + size > keep_bytes { break } @@ -1042,7 +1042,7 @@ pub fn prealloc_scope_owns(scope_ptr voidptr, ptr voidptr) bool { } unsafe { scope := &VPreallocScope(scope_ptr) - address := usize(ptr) + address := uint(ptr) if address < scope.min_address || address >= scope.max_address { return false } @@ -1069,7 +1069,7 @@ pub fn prealloc_scope_owns(scope_ptr voidptr, ptr voidptr) bool { // addresses of the blocks owned by scope_ptr, so callers probing many pointers // can reject most of them before the per-block search in prealloc_scope_owns. @[inline; unsafe] -pub fn prealloc_scope_address_range(scope_ptr voidptr) (usize, usize) { +pub fn prealloc_scope_address_range(scope_ptr voidptr) (uint, uint) { if scope_ptr == unsafe { nil } { return 0, 0 } @@ -1081,19 +1081,19 @@ pub fn prealloc_scope_address_range(scope_ptr voidptr) (usize, usize) { // prealloc_scope_allocated_size returns the total bytes in the allocation blocks // owned by scope_ptr. The scope must be settled: no thread may add or remove blocks -// during the query. A nil scope returns zero; size overflow saturates at usize's max. +// during the query. A nil scope returns zero; size overflow saturates at uint's max. @[unsafe] -pub fn prealloc_scope_allocated_size(scope_ptr voidptr) usize { +pub fn prealloc_scope_allocated_size(scope_ptr voidptr) uint { if scope_ptr == unsafe { nil } { return 0 } unsafe { scope := &VPreallocScope(scope_ptr) - mut total := usize(0) + mut total := uint(0) for i in 0 .. scope.ranges_len { bytes := scope.ranges[i].stop - scope.ranges[i].start - if bytes > ~usize(0) - total { - return ~usize(0) + if bytes > ~uint(0) - total { + return ~uint(0) } total += bytes } @@ -1133,12 +1133,12 @@ pub fn prealloc_scope_free_after(scope_ptr voidptr) { } @[inline; unsafe] -fn prealloc_malloc(n isize) &u8 { +fn prealloc_malloc(n int) &u8 { return unsafe { vmemory_block_malloc(n, 0) } } @[unsafe] -fn prealloc_realloc(old_data &u8, old_size isize, new_size isize) &u8 { +fn prealloc_realloc(old_data &u8, old_size int, new_size int) &u8 { unsafe { mut mb := g_memory_block if mb != nil && old_data != nil && old_size >= 0 && new_size >= 0 @@ -1168,19 +1168,19 @@ fn prealloc_realloc(old_data &u8, old_size isize, new_size isize) &u8 { } // realloc invalidates the old buffer once its contents have been copied. if old_size > 0 { - unsafe { prealloc_discard_pages(old_data, usize(old_size)) } + unsafe { prealloc_discard_pages(old_data, uint(old_size)) } } return new_ptr } @[inline; unsafe] -fn prealloc_calloc(n isize) &u8 { +fn prealloc_calloc(n int) &u8 { new_ptr := unsafe { vmemory_block_malloc(n, 0) } unsafe { C.memset(new_ptr, 0, n) } return new_ptr } @[unsafe] -fn prealloc_malloc_align(n isize, align isize) &u8 { +fn prealloc_malloc_align(n int, align int) &u8 { return unsafe { vmemory_block_malloc(n, align) } } diff --git a/vlib/builtin/prealloc_discard_test.v b/vlib/builtin/prealloc_discard_test.v index 6a54a15a22..880e8e18db 100644 --- a/vlib/builtin/prealloc_discard_test.v +++ b/vlib/builtin/prealloc_discard_test.v @@ -3,7 +3,7 @@ fn test_prealloc_discard_preserves_neighbors_and_writable_reservation() { start := 10_003 end := 210_017 $if prealloc { - unsafe { prealloc_discard_pages(&bytes[start], usize(end - start)) } + unsafe { prealloc_discard_pages(&bytes[start], uint(end - start)) } } for i in 0 .. start { assert bytes[i] == 0xa5 diff --git a/vlib/builtin/prealloc_scope_ownership_test.v b/vlib/builtin/prealloc_scope_ownership_test.v index 3b7ca00523..599e59e21c 100644 --- a/vlib/builtin/prealloc_scope_ownership_test.v +++ b/vlib/builtin/prealloc_scope_ownership_test.v @@ -76,10 +76,10 @@ fn test_prealloc_refills_preserve_aligned_allocations() { mut sizes := []int{cap: 64} for i in 0 .. 64 { size := 16_385 + i * 19 - alignment := isize(16 << (i % 5)) + alignment := int(16 << (i % 5)) source := []u8{len: size, init: u8(i)} - ptr := unsafe { &u8(memdup_align(source.data, isize(size), alignment)) } - assert usize(ptr) % usize(alignment) == 0 + ptr := unsafe { &u8(memdup_align(source.data, int(size), alignment)) } + assert uint(ptr) % uint(alignment) == 0 assert unsafe { prealloc_scope_owns(scope, ptr) } allocations << ptr sizes << size diff --git a/vlib/builtin/prealloc_scope_reenter_test.v b/vlib/builtin/prealloc_scope_reenter_test.v index 39c192435f..016d35e4fd 100644 --- a/vlib/builtin/prealloc_scope_reenter_test.v +++ b/vlib/builtin/prealloc_scope_reenter_test.v @@ -3,7 +3,7 @@ // Scope blocks are 256 KB, so every 200 KB allocation below starts a new block. const reenter_alloc_size = 200 * 1024 -const reenter_keep_all = isize(64 * 1024 * 1024) +const reenter_keep_all = int(64 * 1024 * 1024) fn test_prealloc_scope_reenter_reuses_rewound_blocks() { $if prealloc { diff --git a/vlib/builtin/prealloc_scope_size_test.v b/vlib/builtin/prealloc_scope_size_test.v index 1379587802..51722304f6 100644 --- a/vlib/builtin/prealloc_scope_size_test.v +++ b/vlib/builtin/prealloc_scope_size_test.v @@ -9,7 +9,7 @@ fn test_prealloc_scope_allocated_size_tracks_multiple_blocks() { first_size := unsafe { prealloc_scope_allocated_size(scope) } second := []u8{len: 512 * 1024} second_size := unsafe { prealloc_scope_allocated_size(scope) } - assert initial >= usize(prealloc_scope_block_size) + assert initial >= uint(prealloc_scope_block_size) assert first_size > initial assert second_size > first_size assert unsafe { prealloc_scope_owns(scope, first.data) } @@ -21,12 +21,12 @@ fn test_prealloc_scope_allocated_size_tracks_multiple_blocks() { } fn test_prealloc_scope_allocated_size_saturates_overflow() { - mut ranges := [VPreallocRange{ start: 1, stop: ~usize(0) }, VPreallocRange{ start: 5, stop: 6 }] + mut ranges := [VPreallocRange{ start: 1, stop: ~uint(0) }, VPreallocRange{ start: 5, stop: 6 }] scope := VPreallocScope{ ranges: unsafe { &ranges[0] } ranges_len: ranges.len } - assert unsafe { prealloc_scope_allocated_size(&scope) } == ~usize(0) + assert unsafe { prealloc_scope_allocated_size(&scope) } == ~uint(0) ranges[1].stop = 7 - assert unsafe { prealloc_scope_allocated_size(&scope) } == ~usize(0) + assert unsafe { prealloc_scope_allocated_size(&scope) } == ~uint(0) } diff --git a/vlib/builtin/prealloc_string_test.v b/vlib/builtin/prealloc_string_test.v index 859716f016..baade5dc1e 100644 --- a/vlib/builtin/prealloc_string_test.v +++ b/vlib/builtin/prealloc_string_test.v @@ -6,13 +6,13 @@ fn test_prealloc_string_buffers_pack_bytes_and_preserve_general_alignment() { first := 'ab'.clone() second := 'cdef'.clone() third := 'gh'.clone() - assert usize(second.str) == usize(first.str) + usize(first.len) + 1 - assert usize(third.str) == usize(second.str) + usize(second.len) + 1 + assert uint(second.str) == uint(first.str) + uint(first.len) + 1 + assert uint(third.str) == uint(second.str) + uint(second.len) + 1 assert first == 'ab' && second == 'cdef' && third == 'gh' assert unsafe { first.str[first.len] } == 0 assert unsafe { second.str[second.len] } == 0 general := unsafe { malloc(17) } - assert usize(general) % usize(prealloc_default_align) == 0 + assert uint(general) % uint(prealloc_default_align) == 0 assert unsafe { prealloc_scope_owns(scope, first.str) } assert unsafe { prealloc_scope_owns(scope, general) } unsafe { @@ -38,7 +38,7 @@ fn test_prealloc_string_buffers_grow_and_reenter_a_scope() { assert unsafe { joined.str[joined.len] } == 0 assert unsafe { prealloc_scope_owns(scope, joined.str) } general := unsafe { malloc(33) } - assert usize(general) % usize(prealloc_default_align) == 0 + assert uint(general) % uint(prealloc_default_align) == 0 unsafe { prealloc_scope_leave(scope) } } unsafe { prealloc_scope_free_after(scope) } diff --git a/vlib/builtin/printing.c.v b/vlib/builtin/printing.c.v index e8b891705f..4be2ea1dc1 100644 --- a/vlib/builtin/printing.c.v +++ b/vlib/builtin/printing.c.v @@ -1,12 +1,12 @@ module builtin -fn C.setvbuf(fstream &C.FILE, buffer &char, mode i32, size usize) i32 +fn C.setvbuf(fstream &C.FILE, buffer &char, mode i32, size uint) i32 // set_stream_unbuffered switches a stdio stream to unbuffered mode without using the // deprecated `setbuf` API on Windows toolchains. @[unsafe] fn set_stream_unbuffered(stream &C.FILE) { - C.setvbuf(stream, &char(nil), C._IONBF, usize(0)) + C.setvbuf(stream, &char(nil), C._IONBF, uint(0)) } // race_stdio_write marks a write to stdout or stderr in a race build (`v -race`), like @@ -219,8 +219,8 @@ fn _write_buf_to_fd(fd int, buf &u8, buf_len int) { } } $else { mut ptr := unsafe { buf } - mut remaining_bytes := isize(buf_len) - mut x := isize(0) + mut remaining_bytes := int(buf_len) + mut x := int(0) $if freestanding || vinix || builtin_write_buf_to_fd_should_use_c_write ? { // Flush any pending libc stdio output (from C.puts, C.putchar, etc.) // before writing directly via write() syscall to prevent output reordering. @@ -243,7 +243,7 @@ fn _write_buf_to_fd(fd int, buf &u8, buf_len int) { } unsafe { for remaining_bytes > 0 { - x = isize(C.fwrite(ptr, 1, remaining_bytes, stream)) + x = int(C.fwrite(ptr, 1, remaining_bytes, stream)) if x <= 0 { // GUI programs on Windows may not have a writable stdout/stderr stream. break diff --git a/vlib/builtin/race_d_race.c.v b/vlib/builtin/race_d_race.c.v index 9e780e1df0..c9d6a4e160 100644 --- a/vlib/builtin/race_d_race.c.v +++ b/vlib/builtin/race_d_race.c.v @@ -9,8 +9,8 @@ fn C.__tsan_acquire(addr voidptr) fn C.__tsan_release(addr voidptr) fn C.__tsan_read1(addr voidptr) fn C.__tsan_write1(addr voidptr) -fn C.__tsan_read_range(addr voidptr, size usize) -fn C.__tsan_write_range(addr voidptr, size usize) +fn C.__tsan_read_range(addr voidptr, size uint) +fn C.__tsan_write_range(addr voidptr, size uint) fn C.AnnotateIgnoreReadsBegin(file &char, line int) fn C.AnnotateIgnoreReadsEnd(file &char, line int) fn C.AnnotateIgnoreWritesBegin(file &char, line int) @@ -50,13 +50,13 @@ pub fn racewrite(addr voidptr) { // racereadrange tells the race detector that the calling thread reads `len` bytes at `addr`. pub fn racereadrange(addr voidptr, len int) { - C.__tsan_read_range(addr, usize(len)) + C.__tsan_read_range(addr, uint(len)) } // racewriterange tells the race detector that the calling thread writes `len` bytes at // `addr`. pub fn racewriterange(addr voidptr, len int) { - C.__tsan_write_range(addr, usize(len)) + C.__tsan_write_range(addr, uint(len)) } // race_io_sync stands for all file I/O, like `ioSync` in Go's syscall package. diff --git a/vlib/builtin/recover.c.v b/vlib/builtin/recover.c.v index 109db7684a..0ec3309af2 100644 --- a/vlib/builtin/recover.c.v +++ b/vlib/builtin/recover.c.v @@ -200,7 +200,7 @@ fn panic_unwind(msg string, debug PanicDebugInfo) { if g_panic_state.len == g_panic_state.cap { new_cap := if g_panic_state.cap == 0 { 4 } else { g_panic_state.cap * 2 } records := unsafe { - &PanicRecord(C.realloc(g_panic_state.records, usize(new_cap) * usize(sizeof(PanicRecord)))) + &PanicRecord(C.realloc(g_panic_state.records, uint(new_cap) * uint(sizeof(PanicRecord)))) } if records == unsafe { nil } { panic_frames_reset() @@ -209,13 +209,13 @@ fn panic_unwind(msg string, debug PanicDebugInfo) { g_panic_state.records = records g_panic_state.cap = new_cap } - msg_copy := unsafe { &u8(C.malloc(usize(msg.len + 1))) } + msg_copy := unsafe { &u8(C.malloc(uint(msg.len + 1))) } if msg_copy == unsafe { nil } { panic_frames_reset() panic(msg) } unsafe { - C.memcpy(msg_copy, msg.str, usize(msg.len)) + C.memcpy(msg_copy, msg.str, uint(msg.len)) msg_copy[msg.len] = 0 } mut rec := panic_record(g_panic_state.len) diff --git a/vlib/builtin/segfault_handler_nix.c.v b/vlib/builtin/segfault_handler_nix.c.v index 8971357ce0..36fe1dab7a 100644 --- a/vlib/builtin/segfault_handler_nix.c.v +++ b/vlib/builtin/segfault_handler_nix.c.v @@ -13,7 +13,7 @@ $if !native && !no_segfault_handler ?&& !freestanding && !vinix { fn C.v_install_segfault_handler(fallback voidptr, main_argv voidptr) @[markused] -fn C.v_thread_signal_stack_enter(stack_top voidptr, stack_size usize) voidptr +fn C.v_thread_signal_stack_enter(stack_top voidptr, stack_size uint) voidptr @[markused] fn C.v_thread_signal_stack_leave(alt_stack voidptr) diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 91aeddf7dc..85dc80749c 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -1512,7 +1512,7 @@ pub fn (s string) index_(p string) int { if p.len == 0 { return 0 } - if p.len > s.len || usize(s.str) <= 0xFFFF || usize(p.str) <= 0xFFFF { + if p.len > s.len || uint(s.str) <= 0xFFFF || uint(p.str) <= 0xFFFF { return -1 } if p.len == 1 { @@ -1818,7 +1818,7 @@ pub fn (s string) contains_any_substr(substrs []string) bool { // starts_with returns `true` if the string starts with `p`. @[direct_array_access; inline] pub fn (s string) starts_with(p string) bool { - if p.len > s.len || usize(s.str) <= 0xFFFF || usize(p.str) <= 0xFFFF { + if p.len > s.len || uint(s.str) <= 0xFFFF || uint(p.str) <= 0xFFFF { return false } return string_content_equal(s.str, p.str, p.len) @@ -1827,7 +1827,7 @@ pub fn (s string) starts_with(p string) bool { // ends_with returns `true` if the string ends with `p`. @[direct_array_access; inline] pub fn (s string) ends_with(p string) bool { - if p.len > s.len || usize(s.str) <= 0xFFFF || usize(p.str) <= 0xFFFF { + if p.len > s.len || uint(s.str) <= 0xFFFF || uint(p.str) <= 0xFFFF { return false } return string_content_equal(unsafe { s.str + s.len - p.len }, p.str, p.len) diff --git a/vlib/builtin/testdata/gc_misaligned_stack_pointer.c.v b/vlib/builtin/testdata/gc_misaligned_stack_pointer.c.v index b23c175ec8..0f28f5c3f3 100644 --- a/vlib/builtin/testdata/gc_misaligned_stack_pointer.c.v +++ b/vlib/builtin/testdata/gc_misaligned_stack_pointer.c.v @@ -22,7 +22,7 @@ mut: const words = ['alpha'.repeat(3), 'beta'.repeat(3), 'gamma'.repeat(3), 'delta'.repeat(3)] // GC_noop1 receives stack addresses, so the buffers behind them stay in memory. -fn C.GC_noop1(usize) +fn C.GC_noop1(uint) @[noinline] fn flags(a bool, b bool) int { @@ -73,7 +73,7 @@ fn churn() { fn scrub() { mut buf := [4096]u8{} unsafe { C.memset(&buf[0], 0, 4096) } - C.GC_noop1(usize(&buf[0])) + C.GC_noop1(uint(&buf[0])) } // copy_through_padding moves `h.f` into a local, clears the source and collects while @@ -106,7 +106,7 @@ fn misaligned_slot() bool { mut slot := [24]u8{} mut p := new_block() unsafe { C.memcpy(&slot[3], &p, sizeof(voidptr)) } - C.GC_noop1(usize(&slot[0])) + C.GC_noop1(uint(&slot[0])) p = unsafe { nil } gc_collect() churn() diff --git a/vlib/builtin/testdata/gc_prod_unmap.c.v b/vlib/builtin/testdata/gc_prod_unmap.c.v index 53824477ac..356fe347d4 100644 --- a/vlib/builtin/testdata/gc_prod_unmap.c.v +++ b/vlib/builtin/testdata/gc_prod_unmap.c.v @@ -1,6 +1,6 @@ module main -fn C.GC_expand_hp(usize) int +fn C.GC_expand_hp(uint) int fn C.GC_set_force_unmap_on_gcollect(int) fn main() { diff --git a/vlib/builtin/vgc_d_vgc.c.v b/vlib/builtin/vgc_d_vgc.c.v index 5ab1959518..c93ac80ac6 100644 --- a/vlib/builtin/vgc_d_vgc.c.v +++ b/vlib/builtin/vgc_d_vgc.c.v @@ -24,13 +24,13 @@ fn C.vgc_atomic_fence() fn C.vgc_counter_load(ptr &u64) u64 fn C.vgc_counter_add(ptr &u64, val u64) fn C.vgc_count_alloc(live &u64, allocated &u64, size u64, n u64) -fn C.vgc_os_alloc(size usize) voidptr -fn C.vgc_os_alloc_heap(size usize) voidptr -fn C.vgc_os_free(ptr voidptr, size usize) -fn C.vgc_os_decommit(ptr voidptr, size usize) -fn C.vgc_os_recommit(ptr voidptr, size usize) int +fn C.vgc_os_alloc(size uint) voidptr +fn C.vgc_os_alloc_heap(size uint) voidptr +fn C.vgc_os_free(ptr voidptr, size uint) +fn C.vgc_os_decommit(ptr voidptr, size uint) +fn C.vgc_os_recommit(ptr voidptr, size uint) int fn C.vgc_get_sp() voidptr -fn C.vgc_get_stack_bounds(lo &usize, hi &usize) int +fn C.vgc_get_stack_bounds(lo &uint, hi &uint) int fn C.vgc_bitmap_get(bits &u8, idx u32) int fn C.vgc_bitmap_set(bits &u8, idx u32) fn C.vgc_bitmap_clear(bits &u8, idx u32) @@ -60,7 +60,7 @@ const vgc_page_size = 8192 const vgc_max_small_size = u32(32768) // objects > this are "large" const vgc_num_classes = 68 const vgc_num_span_classes = 136 // 68 * 2 (scan + noscan variants) -// These MUST stay compile-time integer constants (no `usize()` cast, no division by +// These MUST stay compile-time integer constants (no `uint()` cast, no division by // another const). Otherwise V emits them as runtime globals initialized inside // `_vinit()`, and the allocations that run earlier in `_vinit()` (const strings, etc.) // see them as 0: arenas get sized to a single page instead of 64MB. @@ -97,14 +97,14 @@ const vgc_phase_sweep = u32(3) // Translated from Go's runtime.mspan. struct VGC_Span { mut: - base usize // start address of the span - npages u32 // number of pages in this span - elem_size u32 // size of each object in bytes - nelems u32 // number of elements (objects) in the span - class_idx u8 // size class index (0 for large objects) - noscan bool // true if objects contain no pointers (noscan variant) - in_use bool // true if span is allocated to a size class - has_ptrmap bool // true if ptrmap is valid (precise scanning available) + base uint // start address of the span + npages u32 // number of pages in this span + elem_size u32 // size of each object in bytes + nelems u32 // number of elements (objects) in the span + class_idx u8 // size class index (0 for large objects) + noscan bool // true if objects contain no pointers (noscan variant) + in_use bool // true if span is allocated to a size class + has_ptrmap bool // true if ptrmap is valid (precise scanning available) // Pointer bitmap: bit N = word offset N contains a pointer. // Covers objects up to 512 bytes (64 words on 64-bit). // For larger objects, falls back to conservative scanning. @@ -141,9 +141,9 @@ mut: alloc [136]&VGC_Span // one span per span class (68 scan + 68 noscan) // Tiny allocator for objects < 16 bytes without pointers // Translated from Go's mcache.tiny - tiny usize - tiny_offset usize - tiny_allocs usize + tiny uint + tiny_offset uint + tiny_allocs uint // What the threads that had this slot allocated: the bytes of the objects that they allocated // minus the ones that they freed, and the bytes that they asked for. The slot's thread adds to // them with C.vgc_count_alloc and C.vgc_counter_add, macros without a lock, an atomic @@ -153,9 +153,9 @@ mut: alloc_bytes u64 // Thread info registered bool - stack_base usize // fixed stack boundary for this thread - stack_lo usize // lowest stack address (for root scanning) - stack_hi usize // highest stack address + stack_base uint // fixed stack boundary for this thread + stack_lo uint // lowest stack address (for root scanning) + stack_hi uint // highest stack address thread_id u64 stopped u32 // 1 if stopped for GC } @@ -173,9 +173,9 @@ mut: // Translated from Go's heapArena concept. struct VGC_Arena { mut: - base usize - size usize - used usize + base uint + size uint + used uint // Map from page index to span (for finding which span owns an address): one entry for each // of the size / vgc_page_size pages, stored right after the arena. page_span &&VGC_Span = unsafe { nil } @@ -192,7 +192,7 @@ mut: struct VGC_WorkBuf { mut: nobj int - obj [256]usize // pointers to mark + obj [256]uint // pointers to mark next &VGC_WorkBuf = unsafe { nil } } @@ -216,8 +216,8 @@ mut: // Large object spans large_alloc &VGC_Span = unsafe { nil } // The rest of the current chunk for span metadata, and the bytes of all chunks - meta_next usize - meta_left usize + meta_next uint + meta_left uint meta_bytes u64 // Free spans (completely empty, reusable by page count) free_spans_lock u32 @@ -278,10 +278,10 @@ __global vgc_heap = VGC_Heap{} // these to 0 after the first arena has already been mapped during const init. @[cinit] -__global vgc_arena_lo = usize(0) +__global vgc_arena_lo = uint(0) @[cinit] -__global vgc_arena_hi = usize(0) +__global vgc_arena_hi = uint(0) // ============================================================ // Initialization @@ -327,13 +327,13 @@ fn vgc_register_thread() { C.vgc_set_cache_idx(idx) C.vgc_watch_thread_exit(idx) - sp := usize(C.vgc_get_sp()) - mut stack_lo := usize(0) - mut stack_hi := usize(0) - mut stack_base := if sp > usize(8) * 1024 * 1024 { - sp - usize(8) * 1024 * 1024 + sp := uint(C.vgc_get_sp()) + mut stack_lo := uint(0) + mut stack_hi := uint(0) + mut stack_base := if sp > uint(8) * 1024 * 1024 { + sp - uint(8) * 1024 * 1024 } else { - usize(0) + uint(0) } if C.vgc_get_stack_bounds(&stack_lo, &stack_hi) != 0 && stack_lo < stack_hi { dist_lo := if sp >= stack_lo { sp - stack_lo } else { stack_lo - sp } @@ -348,7 +348,7 @@ fn vgc_register_thread() { // vgc_on_thread_exit runs when a registered thread exits, with its cache index + 1. fn vgc_on_thread_exit(value voidptr) { - vgc_unregister_thread(int(isize(value)) - 1) + vgc_unregister_thread(int(int(value)) - 1) } // vgc_unregister_thread frees the slot of an exiting thread, so that the collector no longer @@ -442,7 +442,7 @@ fn vgc_enter() int { return C.vgc_get_cache_idx() } -fn vgc_refresh_stack_range_for_sp(cache_idx int, sp usize) { +fn vgc_refresh_stack_range_for_sp(cache_idx int, sp uint) { if cache_idx < 0 || cache_idx >= vgc_max_threads { return } @@ -472,7 +472,7 @@ fn vgc_get_free_span(npages u32, owner int) &VGC_Span { } // The pages of a free span were given back to the OS; Windows faults on them until they // are committed again. - if C.vgc_os_recommit(voidptr(span.base), usize(npages) * vgc_page_size) == 0 { + if C.vgc_os_recommit(voidptr(span.base), uint(npages) * vgc_page_size) == 0 { vgc_push_free_span(mut span) return unsafe { nil } } @@ -547,7 +547,7 @@ fn vgc_put_free_span(mut span VGC_Span) { span.ptrmap = 0 span.ptr_words = 0 // Decommit pages to return physical memory to OS - page_bytes := usize(npages) * vgc_page_size + page_bytes := uint(npages) * vgc_page_size C.vgc_os_decommit(voidptr(span.base), page_bytes) C.vgc_atomic_add_u64(&vgc_heap.unmapped_bytes, u64(page_bytes)) vgc_push_free_span(mut span) @@ -583,11 +583,11 @@ fn vgc_span_alloc(npages u32, owner int) &VGC_Span { return recycled } - nbytes := usize(npages) * vgc_page_size + nbytes := uint(npages) * vgc_page_size C.vgc_mutex_lock(&vgc_heap.lock) // Try to find space in existing arenas - mut base := usize(0) + mut base := uint(0) mut arena := unsafe { &VGC_Arena(nil) } for i in vgc_heap.arena_open .. vgc_heap.narenas { mut a := unsafe { vgc_heap.arenas[i] } @@ -633,7 +633,7 @@ fn vgc_span_alloc(npages u32, owner int) &VGC_Span { } // Register span in arena's page map page_start := (base - arena.base) / vgc_page_size - for p in 0 .. usize(npages) { + for p in 0 .. uint(npages) { unsafe { arena.page_span[page_start + p] = span } @@ -645,23 +645,23 @@ fn vgc_span_alloc(npages u32, owner int) &VGC_Span { // vgc_new_arena gets an arena for a span of nbytes from the OS: vgc_arena_size bytes, or // nbytes for a larger object. The caller holds vgc_heap.lock. -fn vgc_new_arena(nbytes usize) &VGC_Arena { +fn vgc_new_arena(nbytes uint) &VGC_Arena { if vgc_heap.narenas == vgc_heap.arenas_cap { new_cap := if vgc_heap.arenas_cap == 0 { 8 } else { vgc_heap.arenas_cap * 2 } - table := unsafe { &&VGC_Arena(C.vgc_os_alloc(usize(new_cap) * sizeof(voidptr))) } + table := unsafe { &&VGC_Arena(C.vgc_os_alloc(uint(new_cap) * sizeof(voidptr))) } if table == unsafe { nil } { return unsafe { nil } } if vgc_heap.arenas != unsafe { nil } { unsafe { - C.memcpy(table, vgc_heap.arenas, usize(vgc_heap.narenas) * sizeof(voidptr)) + C.memcpy(table, vgc_heap.arenas, uint(vgc_heap.narenas) * sizeof(voidptr)) } - C.vgc_os_free(vgc_heap.arenas, usize(vgc_heap.arenas_cap) * sizeof(voidptr)) + C.vgc_os_free(vgc_heap.arenas, uint(vgc_heap.arenas_cap) * sizeof(voidptr)) } vgc_heap.arenas = table vgc_heap.arenas_cap = new_cap } - asize := if nbytes > vgc_arena_size { nbytes } else { usize(vgc_arena_size) } + asize := if nbytes > vgc_arena_size { nbytes } else { uint(vgc_arena_size) } mem := C.vgc_os_alloc_heap(asize) if mem == unsafe { nil } { return unsafe { nil } @@ -674,9 +674,9 @@ fn vgc_new_arena(nbytes usize) &VGC_Arena { return unsafe { nil } } mut arena := unsafe { &VGC_Arena(desc) } - arena.base = usize(mem) + arena.base = uint(mem) arena.size = asize - arena.page_span = unsafe { &&VGC_Span(usize(desc) + sizeof(VGC_Arena)) } + arena.page_span = unsafe { &&VGC_Span(uint(desc) + sizeof(VGC_Arena)) } unsafe { vgc_heap.arenas[vgc_heap.narenas] = arena } @@ -730,15 +730,15 @@ fn vgc_arena_map_add(arena &VGC_Arena) bool { // freed, so the metadata comes from large chunks; a page of its own for each span (and one for // each of its two bitmaps) used more memory than the span's objects. The caller holds // vgc_heap.lock. -fn vgc_meta_alloc(size usize) voidptr { - n := (size + 15) & ~usize(15) +fn vgc_meta_alloc(size uint) voidptr { + n := (size + 15) & ~uint(15) if vgc_heap.meta_left < n { - chunk := C.vgc_os_alloc(usize(vgc_meta_chunk_size)) + chunk := C.vgc_os_alloc(uint(vgc_meta_chunk_size)) if chunk == unsafe { nil } { return unsafe { nil } } - vgc_heap.meta_next = usize(chunk) - vgc_heap.meta_left = usize(vgc_meta_chunk_size) + vgc_heap.meta_next = uint(chunk) + vgc_heap.meta_left = uint(vgc_meta_chunk_size) vgc_heap.meta_bytes += u64(vgc_meta_chunk_size) } p := vgc_heap.meta_next @@ -808,7 +808,7 @@ fn vgc_span_alloc_obj(mut span VGC_Span) voidptr { } span.alloc_count++ span.free_index = i + 1 - addr := span.base + usize(i) * usize(span.elem_size) + addr := span.base + uint(i) * uint(span.elem_size) return unsafe { voidptr(addr) } } } @@ -939,7 +939,7 @@ fn vgc_cache_get_span(cache_idx int, span_class int) &VGC_Span { // (translated from Go's runtime.mallocgc) // ============================================================ -fn vgc_malloc(n usize) voidptr { +fn vgc_malloc(n uint) voidptr { return vgc_malloc_typed_opts(n, 0, 0, true) } @@ -947,11 +947,11 @@ fn vgc_malloc(n usize) voidptr { // ptrmap: bitmap where bit N means word offset N is a pointer. // ptr_words: number of pointer words in the object. // If ptrmap==0 && ptr_words==0, falls back to conservative scanning. -fn vgc_malloc_typed(n usize, ptrmap u64, ptr_words u8) voidptr { +fn vgc_malloc_typed(n uint, ptrmap u64, ptr_words u8) voidptr { return vgc_malloc_typed_opts(n, ptrmap, ptr_words, true) } -fn vgc_malloc_typed_opts(n usize, ptrmap u64, ptr_words u8, zero_fill bool) voidptr { +fn vgc_malloc_typed_opts(n uint, ptrmap u64, ptr_words u8, zero_fill bool) voidptr { if n == 0 { return unsafe { nil } } @@ -959,7 +959,7 @@ fn vgc_malloc_typed_opts(n usize, ptrmap u64, ptr_words u8, zero_fill bool) void cache_idx := vgc_enter() // Large allocation (> 32KB) - get dedicated span - if n > usize(vgc_max_small_size) { + if n > uint(vgc_max_small_size) { vgc_maybe_gc() return vgc_alloc_large(n, false, zero_fill, cache_idx) } @@ -1016,18 +1016,18 @@ fn vgc_maybe_gc() { } } -fn vgc_malloc_noscan(n usize) voidptr { +fn vgc_malloc_noscan(n uint) voidptr { return vgc_malloc_noscan_opts(n, true) } -fn vgc_malloc_noscan_opts(n usize, zero_fill bool) voidptr { +fn vgc_malloc_noscan_opts(n uint, zero_fill bool) voidptr { if n == 0 { return unsafe { nil } } cache_idx := vgc_enter() - if n > usize(vgc_max_small_size) { + if n > uint(vgc_max_small_size) { vgc_maybe_gc() return vgc_alloc_large(n, true, zero_fill, cache_idx) } @@ -1045,11 +1045,11 @@ fn vgc_malloc_noscan_opts(n usize, zero_fill bool) voidptr { // Align up for the allocation mut off := cache.tiny_offset if n >= 8 { - off = (off + 7) & ~usize(7) + off = (off + 7) & ~uint(7) } else if n >= 4 { - off = (off + 3) & ~usize(3) + off = (off + 3) & ~uint(3) } else if n >= 2 { - off = (off + 1) & ~usize(1) + off = (off + 1) & ~uint(1) } if off + n <= vgc_tiny_size { ptr := unsafe { voidptr(cache.tiny + off) } @@ -1073,10 +1073,10 @@ fn vgc_malloc_noscan_opts(n usize, zero_fill bool) voidptr { ptr := unsafe { vgc_span_alloc_obj(mut span) } if ptr != unsafe { nil } { if zero_fill { - unsafe { C.memset(ptr, 0, usize(span.elem_size)) } + unsafe { C.memset(ptr, 0, uint(span.elem_size)) } } unsafe { - vgc_heap.caches[cache_idx].tiny = usize(ptr) + vgc_heap.caches[cache_idx].tiny = uint(ptr) vgc_heap.caches[cache_idx].tiny_offset = n vgc_heap.caches[cache_idx].tiny_allocs++ } @@ -1113,7 +1113,7 @@ fn vgc_malloc_noscan_opts(n usize, zero_fill bool) voidptr { } // Allocate a large object (> 32KB) with its own span -fn vgc_alloc_large(n usize, noscan bool, zero_fill bool, cache_idx int) voidptr { +fn vgc_alloc_large(n uint, noscan bool, zero_fill bool, cache_idx int) voidptr { npages := u32((n + vgc_page_size - 1) / vgc_page_size) span := vgc_span_alloc(npages, cache_idx + 1) if span == unsafe { nil } { @@ -1153,7 +1153,7 @@ fn vgc_alloc_large(n usize, noscan bool, zero_fill bool, cache_idx int) voidptr } // Realloc for VGC-managed memory -fn vgc_realloc(old_ptr voidptr, new_size usize) voidptr { +fn vgc_realloc(old_ptr voidptr, new_size uint) voidptr { if old_ptr == unsafe { nil } { return vgc_malloc(new_size) } @@ -1166,7 +1166,7 @@ fn vgc_realloc(old_ptr voidptr, new_size usize) voidptr { // Unknown object - just malloc new return vgc_malloc(new_size) } - old_size := usize(old_span.elem_size) + old_size := uint(old_span.elem_size) if new_size <= old_size { return old_ptr // fits in current allocation } @@ -1230,7 +1230,7 @@ fn vgc_free(ptr voidptr) { // vgc_free_obj frees the object at ptr for the thread with cache index cache_idx. fn vgc_free_obj(span &VGC_Span, ptr voidptr, cache_idx int) { - obj_idx := u32((usize(ptr) - span.base) / usize(span.elem_size)) + obj_idx := u32((uint(ptr) - span.base) / uint(span.elem_size)) if obj_idx < span.nelems && span.alloc_bits != unsafe { nil } { if C.vgc_bitmap_get(span.alloc_bits, obj_idx) != 0 { C.vgc_bitmap_clear(span.alloc_bits, obj_idx) @@ -1247,18 +1247,18 @@ fn vgc_free_obj(span &VGC_Span, ptr voidptr, cache_idx int) { } // Calloc (zero-initialized allocation) -fn vgc_calloc(n usize) voidptr { +fn vgc_calloc(n uint) voidptr { return vgc_malloc(n) // vgc_malloc already zeroes memory } // Typed memdup: allocate with pointer map and copy source data. // Used by HEAP_vgc() macro for struct allocations with known layout. @[markused] -fn vgc_memdup_typed(src voidptr, n isize, ptrmap u64, ptr_words u8) voidptr { +fn vgc_memdup_typed(src voidptr, n int, ptrmap u64, ptr_words u8) voidptr { if src == unsafe { nil } || n <= 0 { return unsafe { nil } } - mem := vgc_malloc_typed_opts(usize(n), ptrmap, ptr_words, false) + mem := vgc_malloc_typed_opts(uint(n), ptrmap, ptr_words, false) if mem != unsafe { nil } { unsafe { C.memcpy(mem, src, n) } } @@ -1267,11 +1267,11 @@ fn vgc_memdup_typed(src voidptr, n isize, ptrmap u64, ptr_words u8) voidptr { // Memdup variants that skip zero-fill when the destination will be overwritten. @[markused] -fn vgc_memdup(src voidptr, n isize) voidptr { +fn vgc_memdup(src voidptr, n int) voidptr { if src == unsafe { nil } || n <= 0 { return unsafe { nil } } - mem := vgc_malloc_typed_opts(usize(n), 0, 0, false) + mem := vgc_malloc_typed_opts(uint(n), 0, 0, false) if mem != unsafe { nil } { unsafe { C.memcpy(mem, src, n) } } @@ -1279,11 +1279,11 @@ fn vgc_memdup(src voidptr, n isize) voidptr { } @[markused] -fn vgc_memdup_noscan(src voidptr, n isize) voidptr { +fn vgc_memdup_noscan(src voidptr, n int) voidptr { if src == unsafe { nil } || n <= 0 { return unsafe { nil } } - mem := vgc_malloc_noscan_opts(usize(n), false) + mem := vgc_malloc_noscan_opts(uint(n), false) if mem != unsafe { nil } { unsafe { C.memcpy(mem, src, n) } } @@ -1299,7 +1299,7 @@ fn vgc_memdup_noscan(src voidptr, n isize) voidptr { // a recycled span keeps its page count, so the page map holds every span exactly once. The // position is returned rather than kept in an iterator, because the compiler may move a local // whose address is taken to the heap, and the collector must not allocate. -fn vgc_next_span(arena int, page usize) (&VGC_Span, int, usize) { +fn vgc_next_span(arena int, page uint) (&VGC_Span, int, uint) { mut ai := arena mut p := page for ai < vgc_heap.narenas { @@ -1311,7 +1311,7 @@ fn vgc_next_span(arena int, page usize) (&VGC_Span, int, usize) { p++ continue } - return span, ai, p + usize(span.npages) + return span, ai, p + uint(span.npages) } ai++ p = 0 @@ -1321,7 +1321,7 @@ fn vgc_next_span(arena int, page usize) (&VGC_Span, int, usize) { @[direct_array_access] fn vgc_find_span(ptr voidptr) &VGC_Span { - addr := usize(ptr) + addr := uint(ptr) // Fast reject: most probed words are not heap pointers at all. if addr < vgc_arena_lo || addr >= vgc_arena_hi { return unsafe { nil } @@ -1355,7 +1355,7 @@ fn vgc_find_span(ptr voidptr) &VGC_Span { // vgc_find_arena returns the arena that holds addr, or nil. @[direct_array_access] -fn vgc_find_arena(addr usize) &VGC_Arena { +fn vgc_find_arena(addr uint) &VGC_Arena { g := addr >> vgc_granule_shift if g < vgc_arena_map_granules { chunk := vgc_heap.arena_map[g >> vgc_arena_map_l2_bits] @@ -1386,16 +1386,16 @@ fn vgc_find_arena(addr usize) &VGC_Arena { } // Get the allocation size of an object -fn vgc_get_obj_size(ptr voidptr) usize { +fn vgc_get_obj_size(ptr voidptr) uint { span := vgc_find_span(ptr) if span == unsafe { nil } { return 0 } - return usize(span.elem_size) + return uint(span.elem_size) } // Check if an address is within the GC heap - O(1) with fast bounds reject -fn vgc_is_heap_ptr(addr usize) bool { +fn vgc_is_heap_ptr(addr uint) bool { // Fast reject: most words on the stack are NOT heap pointers if addr < vgc_arena_lo || addr >= vgc_arena_hi { return false @@ -1416,16 +1416,16 @@ fn vgc_safepoint() { fn vgc_safepoint_at(cache_idx int) { // Wait below a frame that holds this thread's callee-saved registers, so that the // collector's scan of this stack sees them. - C.vgc_call_with_registers_spilled(vgc_safepoint_wait, voidptr(isize(cache_idx))) + C.vgc_call_with_registers_spilled(vgc_safepoint_wait, voidptr(int(cache_idx))) } // vgc_safepoint_wait stops the thread with cache index arg while a collection runs. The // collector scans its stack from regs, where the thread's registers are saved, upwards: the // frames below are vgc's own. fn vgc_safepoint_wait(arg voidptr, regs voidptr) { - cache_idx := int(isize(arg)) + cache_idx := int(int(arg)) // Update the live stack range for root scanning. - vgc_refresh_stack_range_for_sp(cache_idx, usize(regs)) + vgc_refresh_stack_range_for_sp(cache_idx, uint(regs)) // Mark ourselves as stopped C.vgc_atomic_store_u32(&vgc_heap.caches[cache_idx].stopped, 1) C.vgc_atomic_add_u32(&vgc_heap.gc_stopped_count, 1) diff --git a/vlib/builtin/vgc_gc_d_vgc.c.v b/vlib/builtin/vgc_gc_d_vgc.c.v index 1a5bc677b3..997eb1789e 100644 --- a/vlib/builtin/vgc_gc_d_vgc.c.v +++ b/vlib/builtin/vgc_gc_d_vgc.c.v @@ -6,7 +6,7 @@ module builtin fn C.v3_vgc_mark_global_arrays() -fn C.vgc_data_ranges(lo &usize, hi &usize, max int) int +fn C.vgc_data_ranges(lo &uint, hi &uint, max int) int // ============================================================ // GC Orchestration (translated from Go's runtime.gcStart, gcMarkDone, gcMarkTermination) @@ -94,7 +94,7 @@ fn vgc_gc_run(_ voidptr, regs voidptr) { C.vgc_atomic_store_u32(&vgc_heap.wb_enabled, 1) // The thread starting GC does not pass through a safepoint. - vgc_refresh_stack_range_for_sp(self_idx, usize(regs)) + vgc_refresh_stack_range_for_sp(self_idx, uint(regs)) // Scan roots: stacks + globals (conservative scanning) vgc_mark_roots() @@ -147,7 +147,7 @@ fn vgc_clear_mark_bits() { // Keep the arena table still while walking it. C.vgc_mutex_lock(&vgc_heap.lock) mut arena := 0 - mut page := usize(0) + mut page := uint(0) for { span, next_arena, next_page := vgc_next_span(arena, page) if span == unsafe { nil } { @@ -195,19 +195,19 @@ fn vgc_mark_roots() { // and the spans that the caches allocate from, but no pointer that the program holds. The only // objects that they keep alive are the tiny blocks, which vgc_mark_roots marks itself. fn vgc_mark_data_segments() { - mut lo := [16]usize{} - mut hi := [16]usize{} + mut lo := [16]uint{} + mut hi := [16]uint{} n := C.vgc_data_ranges(&lo[0], &hi[0], 16) - skip_lo := [usize(&vgc_heap), usize(&vgc_arena_lo), usize(&vgc_arena_hi)]! - skip_hi := [usize(&vgc_heap) + sizeof(VGC_Heap), usize(&vgc_arena_lo) + sizeof(usize), - usize(&vgc_arena_hi) + sizeof(usize)]! + skip_lo := [uint(&vgc_heap), uint(&vgc_arena_lo), uint(&vgc_arena_hi)]! + skip_hi := [uint(&vgc_heap) + sizeof(VGC_Heap), uint(&vgc_arena_lo) + sizeof(uint), + uint(&vgc_arena_hi) + sizeof(uint)]! for i in 0 .. n { vgc_scan_range_skipping(lo[i], hi[i], &skip_lo[0], &skip_hi[0], skip_lo.len) } } // vgc_scan_range_skipping scans [lo, hi) without the nskip ranges [skip_lo[k], skip_hi[k]). -fn vgc_scan_range_skipping(lo usize, hi usize, skip_lo &usize, skip_hi &usize, nskip int) { +fn vgc_scan_range_skipping(lo uint, hi uint, skip_lo &uint, skip_hi &uint, nskip int) { if lo >= hi { return } @@ -230,22 +230,22 @@ fn vgc_scan_range_skipping(lo usize, hi usize, skip_lo &usize, skip_hi &usize, n // Scan a memory range conservatively, looking for pointers into the GC heap. // Each word-aligned value that looks like a heap pointer is treated as a root. // Translated from Go's scanblock() with conservative pointer finding. -fn vgc_scan_range(lo usize, hi usize) { +fn vgc_scan_range(lo uint, hi uint) { // Align to word boundaries - start := (lo + sizeof(usize) - 1) & ~(usize(sizeof(usize)) - 1) + start := (lo + sizeof(uint) - 1) & ~(uint(sizeof(uint)) - 1) mut addr := start - for addr + sizeof(usize) <= hi { - val := unsafe { *(&usize(voidptr(addr))) } + for addr + sizeof(uint) <= hi { + val := unsafe { *(&uint(voidptr(addr))) } if val != 0 { vgc_shade(val) } - addr += sizeof(usize) + addr += sizeof(uint) } } // Shade marks an object grey (discovered but not yet scanned). // Translated from Go's shade() in mgcmark.go. -fn vgc_shade(addr usize) { +fn vgc_shade(addr uint) { if addr < vgc_arena_lo || addr >= vgc_arena_hi { return } @@ -257,7 +257,7 @@ fn vgc_shade(addr usize) { return } // Find which object this address belongs to - obj_idx := u32((addr - span.base) / usize(span.elem_size)) + obj_idx := u32((addr - span.base) / uint(span.elem_size)) if obj_idx >= span.nelems { return } @@ -270,7 +270,7 @@ fn vgc_shade(addr usize) { if C.vgc_bitmap_test_and_set(span.mark_bits, obj_idx) == 0 { // Newly marked - add to work queue for scanning (only if it may contain pointers) if !span.noscan { - obj_addr := span.base + usize(obj_idx) * usize(span.elem_size) + obj_addr := span.base + uint(obj_idx) * uint(span.elem_size) vgc_work_put(obj_addr) } } @@ -310,7 +310,7 @@ fn vgc_drain_mark_work() { vgc_scan_precise(obj_addr, span.ptrmap, span.ptr_words) } else { // Conservative fallback: scan every word - obj_size := usize(span.elem_size) + obj_size := uint(span.elem_size) vgc_scan_range(obj_addr, obj_addr + obj_size) } } @@ -318,9 +318,9 @@ fn vgc_drain_mark_work() { // Precise pointer scanning: use the pointer bitmap to scan only // word offsets known to contain pointers. Much faster than conservative. -fn vgc_scan_precise(obj_addr usize, ptrmap u64, ptr_words u8) { +fn vgc_scan_precise(obj_addr uint, ptrmap u64, ptr_words u8) { mut mask := ptrmap - word_size := sizeof(usize) + word_size := sizeof(uint) for mask != 0 { // Find lowest set bit (next pointer offset) mut bit := u8(0) @@ -350,8 +350,8 @@ fn vgc_scan_precise(obj_addr usize, ptrmap u64, ptr_words u8) { bit += 1 } // Read the pointer at this offset - ptr_addr := obj_addr + usize(bit) * word_size - val := unsafe { *(&usize(voidptr(ptr_addr))) } + ptr_addr := obj_addr + uint(bit) * word_size + val := unsafe { *(&uint(voidptr(ptr_addr))) } if val != 0 { vgc_shade(val) } @@ -370,7 +370,7 @@ fn vgc_can_use_work_fastpath() bool { } // Add a pointer to the mark work queue -fn vgc_work_put(addr usize) { +fn vgc_work_put(addr uint) { if vgc_can_use_work_fastpath() { mut buf := vgc_heap.work_full if buf == unsafe { nil } || buf.nobj >= 256 { @@ -380,7 +380,7 @@ fn vgc_work_put(addr usize) { vgc_heap.work_empty = new_buf.next } } else { - new_buf = unsafe { &VGC_WorkBuf(C.vgc_os_alloc(usize(sizeof(VGC_WorkBuf)))) } + new_buf = unsafe { &VGC_WorkBuf(C.vgc_os_alloc(uint(sizeof(VGC_WorkBuf)))) } if new_buf == unsafe { nil } { return } @@ -411,7 +411,7 @@ fn vgc_work_put(addr usize) { vgc_heap.work_empty = new_buf.next } } else { - new_buf = unsafe { &VGC_WorkBuf(C.vgc_os_alloc(usize(sizeof(VGC_WorkBuf)))) } + new_buf = unsafe { &VGC_WorkBuf(C.vgc_os_alloc(uint(sizeof(VGC_WorkBuf)))) } if new_buf == unsafe { nil } { C.vgc_mutex_unlock(&vgc_heap.work_lock) return @@ -433,7 +433,7 @@ fn vgc_work_put(addr usize) { } // Get a pointer from the mark work queue -fn vgc_work_get() usize { +fn vgc_work_get() uint { if vgc_can_use_work_fastpath() { mut buf := vgc_heap.work_full if buf == unsafe { nil } || buf.nobj == 0 { @@ -489,7 +489,7 @@ fn vgc_write_barrier(new_val voidptr) { return } // Shade the new pointer (mark it grey) - vgc_shade(usize(new_val)) + vgc_shade(uint(new_val)) } // ============================================================ @@ -519,7 +519,7 @@ fn vgc_sweep_spans() { // Keep the arena table still while walking it. C.vgc_mutex_lock(&vgc_heap.lock) mut arena := 0 - mut page := usize(0) + mut page := uint(0) for { span, next_arena, next_page := vgc_next_span(arena, page) if span == unsafe { nil } { @@ -618,7 +618,7 @@ fn vgc_count_marked() u64 { mut total := u64(0) C.vgc_mutex_lock(&vgc_heap.lock) mut arena := 0 - mut page := usize(0) + mut page := uint(0) for { span, next_arena, next_page := vgc_next_span(arena, page) if span == unsafe { nil } { @@ -672,7 +672,7 @@ fn vgc_update_trigger() { // - total_bytes: the bytes allocated since the program started. // - unmapped_bytes: the pages of the free spans, which went back to the OS. // - bytes_since_gc: the bytes allocated since the last collection. -fn vgc_heap_usage() (usize, usize, usize, usize, usize) { +fn vgc_heap_usage() (uint, uint, uint, uint, uint) { obtained := C.vgc_atomic_load_u64(&vgc_heap.arena_bytes) used := C.vgc_atomic_load_u64(&vgc_heap.arena_used) unmapped := C.vgc_atomic_load_u64(&vgc_heap.unmapped_bytes) @@ -681,13 +681,13 @@ fn vgc_heap_usage() (usize, usize, usize, usize, usize) { heap_size := if obtained > unmapped { obtained - unmapped } else { u64(0) } free := if obtained > used { obtained - used } else { u64(0) } since_gc := if total > at_gc { total - at_gc } else { u64(0) } - return usize(heap_size), usize(free), usize(total), usize(unmapped), usize(since_gc) + return uint(heap_size), uint(free), uint(total), uint(unmapped), uint(since_gc) } // vgc_memory_use returns the heap memory in use: the pages of the spans that are not free, which // is heap_size - free_bytes, as with Boehm's GC_get_memory_use(). -fn vgc_memory_use() usize { +fn vgc_memory_use() uint { used := C.vgc_atomic_load_u64(&vgc_heap.arena_used) unmapped := C.vgc_atomic_load_u64(&vgc_heap.unmapped_bytes) - return if used > unmapped { usize(used - unmapped) } else { usize(0) } + return if used > unmapped { uint(used - unmapped) } else { uint(0) } } diff --git a/vlib/builtin/vgc_notd_vgc.c.v b/vlib/builtin/vgc_notd_vgc.c.v index bf42469baa..64bced2beb 100644 --- a/vlib/builtin/vgc_notd_vgc.c.v +++ b/vlib/builtin/vgc_notd_vgc.c.v @@ -4,46 +4,46 @@ module builtin // because of the missing definitions in $if vgc ? { } blocks. // Note: they will NOT be called, since calls to them are wrapped with `$if vgc ? { }`. -fn vgc_malloc(n usize) voidptr { +fn vgc_malloc(n uint) voidptr { return unsafe { nil } } -fn vgc_malloc_noscan(n usize) voidptr { +fn vgc_malloc_noscan(n uint) voidptr { return unsafe { nil } } -fn vgc_malloc_typed_opts(n usize, ptrmap u64, ptr_words u8, zero_fill bool) voidptr { +fn vgc_malloc_typed_opts(n uint, ptrmap u64, ptr_words u8, zero_fill bool) voidptr { return unsafe { nil } } -fn vgc_malloc_noscan_opts(n usize, zero_fill bool) voidptr { +fn vgc_malloc_noscan_opts(n uint, zero_fill bool) voidptr { return unsafe { nil } } -fn vgc_memdup(src voidptr, n isize) voidptr { +fn vgc_memdup(src voidptr, n int) voidptr { return unsafe { nil } } -fn vgc_memdup_noscan(src voidptr, n isize) voidptr { +fn vgc_memdup_noscan(src voidptr, n int) voidptr { return unsafe { nil } } -fn vgc_realloc(old_ptr voidptr, new_size usize) voidptr { +fn vgc_realloc(old_ptr voidptr, new_size uint) voidptr { return unsafe { nil } } -fn vgc_calloc(n usize) voidptr { +fn vgc_calloc(n uint) voidptr { return unsafe { nil } } fn vgc_free(ptr voidptr) { } -fn vgc_heap_usage() (usize, usize, usize, usize, usize) { +fn vgc_heap_usage() (uint, uint, uint, uint, uint) { return 0, 0, 0, 0, 0 } -fn vgc_memory_use() usize { +fn vgc_memory_use() uint { return 0 } diff --git a/vlib/builtin/wasm/alloc.v b/vlib/builtin/wasm/alloc.v index 4a9d3287fd..d2d8c35572 100644 --- a/vlib/builtin/wasm/alloc.v +++ b/vlib/builtin/wasm/alloc.v @@ -4,13 +4,13 @@ module builtin // Shitty `sbrk` basic `malloc` and `free` impl // TODO: implement pure V `walloc` later -__global g_heap_base = usize(vwasm_heap_base()) +__global g_heap_base = uint(vwasm_heap_base()) // malloc dynamically allocates a `n` bytes block of memory on the heap. // malloc returns a `byteptr` pointing to the memory address of the allocated space. // unlike the `calloc` family of functions - malloc will not zero the memory block. @[unsafe] -pub fn malloc(n isize) &u8 { +pub fn malloc(n int) &u8 { if n <= 0 { $if no_imports ? { return unsafe { nil } @@ -20,7 +20,7 @@ pub fn malloc(n isize) &u8 { } res := g_heap_base - g_heap_base += usize(n) + g_heap_base += uint(n) return &u8(res) } diff --git a/vlib/builtin/wasm/builtin.v b/vlib/builtin/wasm/builtin.v index 9c9942667a..f14b6b5fa5 100644 --- a/vlib/builtin/wasm/builtin.v +++ b/vlib/builtin/wasm/builtin.v @@ -41,7 +41,7 @@ pub fn vwasm_memory_grow(size int) int { // vcalloc returns a `byteptr` pointing to the memory address of the allocated space. // vcalloc checks for negative values given in `n`. @[unsafe] -pub fn vcalloc(n isize) &u8 { +pub fn vcalloc(n int) &u8 { if n <= 0 { $if no_imports ? { return unsafe { nil } @@ -73,7 +73,7 @@ pub fn isnil(v voidptr) bool { // vmemcpy copies n bytes from memory area src to memory area dest. // The memory areas **CAN** overlap. vmemcpy returns a pointer to `dest`. @[unsafe] -pub fn vmemcpy(dest voidptr, const_src voidptr, n isize) voidptr { +pub fn vmemcpy(dest voidptr, const_src voidptr, n int) voidptr { asm wasm { local.get dest local.get const_src @@ -89,7 +89,7 @@ pub fn vmemcpy(dest voidptr, const_src voidptr, n isize) voidptr { // vmemmove copies n bytes from memory area src to memory area dest. // The memory areas **CAN** overlap. vmemmove returns a pointer to `dest`. @[unsafe] -pub fn vmemmove(dest voidptr, const_src voidptr, n isize) voidptr { +pub fn vmemmove(dest voidptr, const_src voidptr, n int) voidptr { asm wasm { local.get dest local.get const_src @@ -105,7 +105,7 @@ pub fn vmemmove(dest voidptr, const_src voidptr, n isize) voidptr { // vmemset fills the first `n` bytes of the memory area pointed to by `s`, // with the constant byte `c`. It returns a pointer to the memory area `s`. @[unsafe] -pub fn vmemset(s voidptr, c int, n isize) voidptr { +pub fn vmemset(s voidptr, c int, n int) voidptr { asm wasm { local.get s local.get c diff --git a/vlib/builtin/wasm/wasi/builtin_notd_no_imports.v b/vlib/builtin/wasm/wasi/builtin_notd_no_imports.v index 7841f7ebc0..b55774c35f 100644 --- a/vlib/builtin/wasm/wasi/builtin_notd_no_imports.v +++ b/vlib/builtin/wasm/wasi/builtin_notd_no_imports.v @@ -4,7 +4,7 @@ module builtin pub fn print(s string) { elm := CIOVec{ buf: s.str - len: usize(s.len) + len: uint(s.len) } WASM.fd_write(1, &elm, 1, 0) @@ -14,7 +14,7 @@ pub fn print(s string) { pub fn println(s string) { elm := [CIOVec{ buf: s.str - len: usize(s.len) + len: uint(s.len) }, CIOVec{ buf: c'\n' len: 1 @@ -27,7 +27,7 @@ pub fn println(s string) { pub fn eprint(s string) { elm := CIOVec{ buf: s.str - len: usize(s.len) + len: uint(s.len) } WASM.fd_write(2, &elm, 1, 0) @@ -37,7 +37,7 @@ pub fn eprint(s string) { pub fn eprintln(s string) { elm := [CIOVec{ buf: s.str - len: usize(s.len) + len: uint(s.len) }, CIOVec{ buf: c'\n' len: 1 diff --git a/vlib/builtin/wasm/wasi/wasi_notd_no_imports.v b/vlib/builtin/wasm/wasi/wasi_notd_no_imports.v index d930a43731..3f4fbd1539 100644 --- a/vlib/builtin/wasm/wasi/wasi_notd_no_imports.v +++ b/vlib/builtin/wasm/wasi/wasi_notd_no_imports.v @@ -3,7 +3,7 @@ module builtin pub struct CIOVec { pub: buf &u8 - len usize + len uint } type Errno = u16 @@ -16,16 +16,16 @@ fn WASM.args_sizes_get(argc &u32, argc_buf_size &u32) Errno fn WASM.args_get(argv &&u8, argv_buf &u8) Errno @[wasm_import_namespace: 'wasi_snapshot_preview1'] -fn WASM.fd_write(fd FileDesc, iovs &CIOVec, iovs_len usize, retptr &usize) Errno +fn WASM.fd_write(fd FileDesc, iovs &CIOVec, iovs_len uint, retptr &uint) Errno @[wasm_import_namespace: 'wasi_snapshot_preview1'] -fn WASM.fd_read(fd FileDesc, iovs &CIOVec, iovs_len usize, nread &usize) Errno +fn WASM.fd_read(fd FileDesc, iovs &CIOVec, iovs_len uint, nread &uint) Errno @[wasm_import_namespace: 'wasi_snapshot_preview1'] fn WASM.fd_sync(fd FileDesc) Errno @[wasm_import_namespace: 'wasi_snapshot_preview1'] -fn WASM.random_get(buf &u8, buf_len usize) Errno +fn WASM.random_get(buf &u8, buf_len uint) Errno @[wasm_import_namespace: 'wasi_snapshot_preview1'] @[noreturn] diff --git a/vlib/builtin/wasm_bare/libc_impl.c.v b/vlib/builtin/wasm_bare/libc_impl.c.v index 793523353a..89252ff6d0 100644 --- a/vlib/builtin/wasm_bare/libc_impl.c.v +++ b/vlib/builtin/wasm_bare/libc_impl.c.v @@ -2,8 +2,9 @@ module builtin //__global global_allocator dlmalloc.Dlmalloc +// __malloc allocates size bytes of memory. @[unsafe] -pub fn __malloc(size usize) voidptr { +pub fn __malloc(size uint) voidptr { unsafe { $if windows { // Warning! On windows, we always use _aligned_malloc to allocate memory. @@ -18,8 +19,9 @@ pub fn __malloc(size usize) voidptr { return unsafe { nil } } +// memcpy copies n bytes from const_src to dest. @[unsafe] -pub fn memcpy(dest &C.void, const_src &C.void, n usize) &C.void { +pub fn memcpy(dest &C.void, const_src &C.void, n uint) &C.void { dest_ := unsafe { &u8(dest) } src_ := unsafe { &u8(const_src) } unsafe { @@ -31,20 +33,20 @@ pub fn memcpy(dest &C.void, const_src &C.void, n usize) &C.void { } @[unsafe] -fn strlen(const_s &char) usize { +fn strlen(const_s &char) uint { s := unsafe { &u8(const_s) } mut i := 0 for ; unsafe { s[i] } != 0; i++ { } - return usize(i) + return uint(i) } @[unsafe] -fn realloc(old_area &C.void, new_size usize) &C.void { +fn realloc(old_area &C.void, new_size uint) &C.void { if old_area == 0 { return unsafe { malloc(int(new_size)) } } - if new_size == usize(0) { + if new_size == uint(0) { unsafe { free(old_area) } return 0 } @@ -53,14 +55,14 @@ fn realloc(old_area &C.void, new_size usize) &C.void { return unsafe { old_area } } else { new_area := unsafe { malloc(int(new_size)) } - unsafe { memmove(new_area, old_area, usize(old_size)) } + unsafe { memmove(new_area, old_area, uint(old_size)) } unsafe { free(old_area) } return new_area } } @[unsafe] -fn memset(s &C.void, c int, n usize) &C.void { +fn memset(s &C.void, c int, n uint) &C.void { mut s_ := unsafe { &char(s) } for i in 0 .. int(n) { unsafe { @@ -71,7 +73,7 @@ fn memset(s &C.void, c int, n usize) &C.void { } @[unsafe] -fn memmove(dest &C.void, const_src &C.void, n usize) &C.void { +fn memmove(dest &C.void, const_src &C.void, n uint) &C.void { dest_ := unsafe { &u8(dest) } src_ := unsafe { &u8(const_src) } mut temp_buf := unsafe { malloc(int(n)) } @@ -92,7 +94,7 @@ fn memmove(dest &C.void, const_src &C.void, n usize) &C.void { @[export: 'calloc'] @[unsafe] -fn __calloc(nmemb usize, size usize) &C.void { +fn __calloc(nmemb uint, size uint) &C.void { new_area := unsafe { malloc(int(nmemb) * int(size)) } unsafe { memset(new_area, 0, nmemb * size) } return new_area @@ -102,7 +104,7 @@ fn getchar() int { return 0 } -fn memcmp(const_a &C.void, const_b &C.void, n usize) int { +fn memcmp(const_a &C.void, const_b &C.void, n uint) int { a_ := unsafe { &u8(const_a) } b_ := unsafe { &u8(const_b) } for i in 0 .. int(n) { @@ -119,7 +121,7 @@ fn vsprintf(str &char, format &char, ap &u8) int { panic('vsprintf(): string interpolation is not supported in `-freestanding`') } -fn vsnprintf(str &char, size usize, format &char, ap &u8) int { +fn vsnprintf(str &char, size uint, format &char, ap &u8) int { panic('vsnprintf(): string interpolation is not supported in `-freestanding`') } @@ -165,6 +167,6 @@ fn __exit(code int) { } @[export: 'qsort'] -fn __qsort(base voidptr, nmemb usize, size usize, sort_cb FnSortCB) { +fn __qsort(base voidptr, nmemb uint, size uint, sort_cb FnSortCB) { panic('qsort() is not yet implemented in `-freestanding`') } diff --git a/vlib/compress/brotli/brotli.c.v b/vlib/compress/brotli/brotli.c.v index 90a2d0f6a9..3e54377c64 100644 --- a/vlib/compress/brotli/brotli.c.v +++ b/vlib/compress/brotli/brotli.c.v @@ -12,7 +12,7 @@ $if linux { fn C.v_brotli_open(const_name &char) voidptr fn C.v_brotli_sym(handle voidptr, const_name &char) voidptr fn C.v_brotli_close(handle voidptr) int -fn C.v_brotli_msan_unpoison(ptr voidptr, len usize) +fn C.v_brotli_msan_unpoison(ptr voidptr, len uint) const min_quality = 0 const max_quality = 11 @@ -25,15 +25,15 @@ const decoder_result_success = 1 const decoder_result_needs_more_input = 2 const decoder_result_needs_more_output = 3 -type FNEncoderMaxCompressedSize = fn (usize) usize +type FNEncoderMaxCompressedSize = fn (uint) uint -type FNEncoderCompress = fn (int, int, int, usize, voidptr, &usize, voidptr) int +type FNEncoderCompress = fn (int, int, int, uint, voidptr, &uint, voidptr) int type FNDecoderCreateInstance = fn (voidptr, voidptr, voidptr) voidptr type FNDecoderDestroyInstance = fn (voidptr) -type FNDecoderDecompressStream = fn (voidptr, &usize, &&u8, &usize, &&u8, &usize) int +type FNDecoderDecompressStream = fn (voidptr, &uint, &&u8, &uint, &&u8, &uint) int type FNDecoderGetErrorCode = fn (voidptr) int @@ -179,7 +179,7 @@ pub fn compress(data []u8, params CompressParams) ![]u8 { max_compressed_size := FNEncoderMaxCompressedSize(library_symbol(enc, 'BrotliEncoderMaxCompressedSize', 'encoder')!) encoder_compress := FNEncoderCompress(library_symbol(enc, 'BrotliEncoderCompress', 'encoder')!) - dst_capacity := max_compressed_size(usize(data.len)) + dst_capacity := max_compressed_size(uint(data.len)) if dst_capacity == 0 { return error('brotli: input is too large') } @@ -191,7 +191,7 @@ pub fn compress(data []u8, params CompressParams) ![]u8 { } } mut encoded_size := dst_capacity - ok := encoder_compress(params.quality, params.lgwin, int(params.mode), usize(data.len), + ok := encoder_compress(params.quality, params.lgwin, int(params.mode), uint(data.len), data.data, &encoded_size, dst.data) if ok == 0 { return error('brotli: compression failed') @@ -235,17 +235,17 @@ pub fn decompress(data []u8, _ DecompressParams) ![]u8 { defer { unsafe { chunk.free() } } - mut available_in := usize(data.len) + mut available_in := uint(data.len) mut next_in := unsafe { &u8(data.data) } for { - mut available_out := usize(chunk.len) + mut available_out := uint(chunk.len) mut next_out := unsafe { &u8(chunk.data) } - mut total_out := usize(0) + mut total_out := uint(0) result := decoder_stream(state, &available_in, &next_in, &available_out, &next_out, &total_out) produced := chunk.len - int(available_out) if produced > 0 { - C.v_brotli_msan_unpoison(chunk.data, usize(produced)) + C.v_brotli_msan_unpoison(chunk.data, uint(produced)) out << chunk[..produced] } match result { diff --git a/vlib/compress/compress.c.v b/vlib/compress/compress.c.v index 940328403d..b9a580bf0a 100644 --- a/vlib/compress/compress.c.v +++ b/vlib/compress/compress.c.v @@ -10,8 +10,8 @@ module compress @[deprecated_after: '2026-07-31'] pub const max_size = u64(1 << 31) -fn C.tdefl_compress_mem_to_heap(source_buf voidptr, source_buf_len usize, out_len &usize, flags i32) voidptr -fn C.tinfl_decompress_mem_to_heap(source_buf voidptr, source_buf_len usize, out_len &usize, flags i32) voidptr +fn C.tdefl_compress_mem_to_heap(source_buf voidptr, source_buf_len uint, out_len &uint, flags i32) voidptr +fn C.tinfl_decompress_mem_to_heap(source_buf voidptr, source_buf_len uint, out_len &uint, flags i32) voidptr // compresses an array of bytes based on providing flags and returns the compressed bytes in a new array // NB: this is a low level api, a high level implementation like zlib/gzip should be preferred @@ -22,7 +22,7 @@ pub fn compress(data []u8, flags int) ![]u8 { if u64(data.len) > max_size { return error('data too large (${data.len} > ${max_size})') } - mut out_len := usize(0) + mut out_len := uint(0) address := C.tdefl_compress_mem_to_heap(data.data, data.len, &out_len, flags) if address == 0 { @@ -44,7 +44,7 @@ pub fn compress(data []u8, flags int) ![]u8 { @[deprecated_after: '2026-07-31'] @[manualfree] pub fn decompress(data []u8, flags int) ![]u8 { - mut out_len := usize(0) + mut out_len := uint(0) address := C.tinfl_decompress_mem_to_heap(data.data, data.len, &out_len, flags) if address == 0 { @@ -79,7 +79,7 @@ pub type ChunkCallback = fn (chunk []u8, userdata voidptr) int pub fn decompress_with_callback(data []u8, cb ChunkCallback, userdata voidptr, flags int) !u64 { cbdata := DecompressionCallBackData{ data: data.data - size: usize(data.len) + size: uint(data.len) cb: cb userdata: userdata } @@ -94,7 +94,7 @@ pub fn decompress_with_callback(data []u8, cb ChunkCallback, userdata voidptr, f struct DecompressionCallBackData { mut: data voidptr - size usize + size uint decompressed_size u64 userdata voidptr cb ChunkCallback = unsafe { nil } @@ -114,4 +114,4 @@ fn c_cb_for_decompress_mem(buf &char, len i32, pdcbd voidptr) i32 { type DecompressCallback = fn (const_buffer voidptr, len i32, userdata voidptr) i32 -fn C.tinfl_decompress_mem_to_callback(const_input_buffer voidptr, psize &usize, put_buf_cb DecompressCallback, userdata voidptr, flags i32) i32 +fn C.tinfl_decompress_mem_to_callback(const_input_buffer voidptr, psize &uint, put_buf_cb DecompressCallback, userdata voidptr, flags i32) i32 diff --git a/vlib/compress/deflate/deflate_test.v b/vlib/compress/deflate/deflate_test.v index 872f2501a0..514bb851a8 100644 --- a/vlib/compress/deflate/deflate_test.v +++ b/vlib/compress/deflate/deflate_test.v @@ -70,7 +70,7 @@ fn bit_flips(data []u8, start int) [][]u8 { return res } -// assert_checksum_errors checks that, with the payload intact, a wrong adler32, crc32 or isize +// assert_checksum_errors checks that, with the payload intact, a wrong adler32, crc32 or int // is reported as exactly that, by the one-shot and by the callback decoder. fn assert_checksum_errors(payload []u8, plain []u8) ! { z := zlib_stream(payload, plain) diff --git a/vlib/compress/gzip/gzip_test.v b/vlib/compress/gzip/gzip_test.v index cdcdfdac9f..42b7862c57 100644 --- a/vlib/compress/gzip/gzip_test.v +++ b/vlib/compress/gzip/gzip_test.v @@ -240,7 +240,7 @@ fn test_gzip_damaged_payload_is_reported_as_such_whatever_the_trailer() { 'invalid gzip stream: size mismatch'] assert callback_error(damaged) == payload_error // Nothing was decoded, so there is nothing to compare the trailer with: - // a wrong crc32 or isize on top of that does not change the error. + // a wrong crc32 or int on top of that does not change the error. for i in [damaged.len - 8, damaged.len - 4] { mut both := damaged.clone() both[i] ^= 0x01 diff --git a/vlib/compress/szip/szip.c.v b/vlib/compress/szip/szip.c.v index d7788ede7e..0daa525bcf 100644 --- a/vlib/compress/szip/szip.c.v +++ b/vlib/compress/szip/szip.c.v @@ -25,7 +25,7 @@ fn C.zip_close(&Zip) fn C.zip_entry_open(&Zip, &u8) i32 -fn C.zip_entry_openbyindex(&Zip, usize) i32 +fn C.zip_entry_openbyindex(&Zip, uint) i32 fn C.zip_entry_close(&Zip) i32 @@ -39,13 +39,13 @@ fn C.zip_entry_size(&Zip) u64 fn C.zip_entry_crc32(&Zip) u32 -fn C.zip_entry_write(&Zip, voidptr, usize) i32 +fn C.zip_entry_write(&Zip, voidptr, uint) i32 fn C.zip_entry_fwrite(&Zip, &char) i32 -fn C.zip_entry_read(&Zip, &voidptr, &usize) i32 +fn C.zip_entry_read(&Zip, &voidptr, &uint) i32 -fn C.zip_entry_noallocread(&Zip, voidptr, usize) i32 +fn C.zip_entry_noallocread(&Zip, voidptr, uint) i32 fn C.zip_entry_fread(&Zip, &char) i32 @@ -204,7 +204,7 @@ pub fn (mut zentry Zip) create_entry(name string) ! { // for large entries, please take a look at zip_entry_extract function. pub fn (mut zentry Zip) read_entry() !voidptr { mut buf := &u8(unsafe { nil }) - mut bsize := usize(0) + mut bsize := uint(0) res := C.zip_entry_read(zentry, unsafe { &voidptr(&buf) }, &bsize) if res == -1 { return error('szip: cannot read properly data from entry') @@ -214,7 +214,7 @@ pub fn (mut zentry Zip) read_entry() !voidptr { // read_entry_buf extracts the current zip entry into user specified buffer. pub fn (mut zentry Zip) read_entry_buf(buf voidptr, in_bsize int) !int { - bsize := usize(in_bsize) + bsize := uint(in_bsize) res := C.zip_entry_noallocread(zentry, buf, bsize) if res == -1 { return error('szip: cannot read properly data from entry') diff --git a/vlib/compress/zstd/zstd.c.v b/vlib/compress/zstd/zstd.c.v index 3118c318cb..0ac0fd10e5 100644 --- a/vlib/compress/zstd/zstd.c.v +++ b/vlib/compress/zstd/zstd.c.v @@ -28,22 +28,22 @@ const buf_out_size = 1024 * 1024 fn C.ZSTD_versionNumber() u32 fn C.ZSTD_versionString() charptr -fn C.ZSTD_compress(voidptr, usize, voidptr, usize, i32) usize -fn C.ZSTD_decompress(voidptr, usize, voidptr, usize) usize -fn C.ZSTD_getFrameContentSize(voidptr, usize) u64 -fn C.ZSTD_findFrameCompressedSize(voidptr, usize) usize -fn C.ZSTD_compressBound(usize) usize -fn C.ZSTD_isError(usize) u32 -fn C.ZSTD_getErrorName(usize) charptr +fn C.ZSTD_compress(voidptr, uint, voidptr, uint, i32) uint +fn C.ZSTD_decompress(voidptr, uint, voidptr, uint) uint +fn C.ZSTD_getFrameContentSize(voidptr, uint) u64 +fn C.ZSTD_findFrameCompressedSize(voidptr, uint) uint +fn C.ZSTD_compressBound(uint) uint +fn C.ZSTD_isError(uint) u32 +fn C.ZSTD_getErrorName(uint) charptr fn C.ZSTD_minCLevel() i32 fn C.ZSTD_maxCLevel() i32 fn C.ZSTD_defaultCLevel() i32 fn C.ZSTD_createCCtx() &C.ZSTD_CCtx_s -fn C.ZSTD_freeCCtx(voidptr) usize -fn C.ZSTD_compressCCtx(voidptr, voidptr, usize, voidptr, usize, i32) usize +fn C.ZSTD_freeCCtx(voidptr) uint +fn C.ZSTD_compressCCtx(voidptr, voidptr, uint, voidptr, uint, i32) uint fn C.ZSTD_createDCtx() &C.ZSTD_DCtx_s -fn C.ZSTD_freeDCtx(voidptr) usize -fn C.ZSTD_decompressDCtx(voidptr, voidptr, usize, voidptr, usize) usize +fn C.ZSTD_freeDCtx(voidptr) uint +fn C.ZSTD_decompressDCtx(voidptr, voidptr, uint, voidptr, uint) uint // note : new strategies _might_ be added in the future. Only the order (from fast to strong) is guaranteed pub enum Strategy { @@ -272,14 +272,14 @@ pub enum CParameter { pub struct Bounds { pub: - error usize + error uint lower_bound int upper_bound int } fn C.ZSTD_cParam_getBounds(CParameter) Bounds -fn C.ZSTD_CCtx_setParameter(voidptr, CParameter, i32) usize -fn C.ZSTD_CCtx_setPledgedSrcSize(voidptr, u64) usize +fn C.ZSTD_CCtx_setParameter(voidptr, CParameter, i32) uint +fn C.ZSTD_CCtx_setPledgedSrcSize(voidptr, u64) uint pub enum ResetDirective { session_only = 1 @@ -287,8 +287,8 @@ pub enum ResetDirective { session_and_parameters = 3 } -fn C.ZSTD_CCtx_reset(voidptr, ResetDirective) usize -fn C.ZSTD_compress2(voidptr, voidptr, usize, voidptr, usize) usize +fn C.ZSTD_CCtx_reset(voidptr, ResetDirective) uint +fn C.ZSTD_compress2(voidptr, voidptr, uint, voidptr, uint) uint pub enum DParameter { // Select a size limit (in power of 2) beyond which @@ -317,26 +317,26 @@ pub enum DParameter { } fn C.ZSTD_dParam_getBounds(DParameter) Bounds -fn C.ZSTD_DCtx_setParameter(voidptr, DParameter, i32) usize -fn C.ZSTD_DCtx_reset(voidptr, ResetDirective) usize +fn C.ZSTD_DCtx_setParameter(voidptr, DParameter, i32) uint +fn C.ZSTD_DCtx_reset(voidptr, ResetDirective) uint // streaming compression pub struct InBuffer { pub mut: src voidptr - size usize - pos usize + size uint + pos uint } pub struct OutBuffer { pub mut: dst voidptr - size usize - pos usize + size uint + pos uint } fn C.ZSTD_createCStream() voidptr -fn C.ZSTD_freeCStream(voidptr) usize +fn C.ZSTD_freeCStream(voidptr) uint pub enum EndDirective { // collect more data, encoder decides when to output compressed result, for optimal compression ratio @@ -354,21 +354,21 @@ pub enum EndDirective { end = 2 } -fn C.ZSTD_compressStream2(voidptr, &OutBuffer, &InBuffer, EndDirective) usize -fn C.ZSTD_CStreamInSize() usize -fn C.ZSTD_CStreamOutSize() usize -fn C.ZSTD_initCStream(voidptr, i32) usize -fn C.ZSTD_compressStream(voidptr, &OutBuffer, &InBuffer) usize -fn C.ZSTD_flushStream(voidptr, &OutBuffer) usize -fn C.ZSTD_endStream(voidptr, &OutBuffer) usize +fn C.ZSTD_compressStream2(voidptr, &OutBuffer, &InBuffer, EndDirective) uint +fn C.ZSTD_CStreamInSize() uint +fn C.ZSTD_CStreamOutSize() uint +fn C.ZSTD_initCStream(voidptr, i32) uint +fn C.ZSTD_compressStream(voidptr, &OutBuffer, &InBuffer) uint +fn C.ZSTD_flushStream(voidptr, &OutBuffer) uint +fn C.ZSTD_endStream(voidptr, &OutBuffer) uint // streaming decompression fn C.ZSTD_createDStream() voidptr -fn C.ZSTD_freeDStream(voidptr) usize -fn C.ZSTD_initDStream(voidptr) usize -fn C.ZSTD_decompressStream(voidptr, &OutBuffer, &InBuffer) usize -fn C.ZSTD_DStreamInSize() usize -fn C.ZSTD_DStreamOutSize() usize +fn C.ZSTD_freeDStream(voidptr) uint +fn C.ZSTD_initDStream(voidptr) uint +fn C.ZSTD_decompressStream(voidptr, &OutBuffer, &InBuffer) uint +fn C.ZSTD_DStreamInSize() uint +fn C.ZSTD_DStreamOutSize() uint // version_number returns runtime library version, the value is (MAJOR*100*100 + MINOR*100 + RELEASE). pub fn version_number() u32 { @@ -380,18 +380,18 @@ pub fn version_string() string { return unsafe { tos_clone(C.ZSTD_versionString()) } } -// is_error tells if a `usize` function result is an error code. -pub fn is_error(code usize) bool { +// is_error tells if a `uint` function result is an error code. +pub fn is_error(code uint) bool { return C.ZSTD_isError(code) == 1 } // get_error_name provides readable string from an error code. -pub fn get_error_name(code usize) string { +pub fn get_error_name(code uint) string { return unsafe { tos_clone(&u8(C.ZSTD_getErrorName(code))) } } // check_zstd checks the zstd error code, and return a error string. -pub fn check_error(code usize) ! { +pub fn check_error(code uint) ! { if is_error(code) { return error(get_error_name(code)) } @@ -496,14 +496,14 @@ pub fn (mut c CCtx) set(c_param CParameter, val int) ! { // .zstd_e_continue => continue stream compression. // .zstd_e_flush => flush data // .zstd_e_end => it is the last frame -pub fn (mut c CCtx) compress_stream2(output &OutBuffer, input &InBuffer, mode EndDirective) !usize { +pub fn (mut c CCtx) compress_stream2(output &OutBuffer, input &InBuffer, mode EndDirective) !uint { res := C.ZSTD_compressStream2(c.ctx, output, input, mode) check_error(res)! return res } // free_cctx free a compression context. -pub fn (mut c CCtx) free_cctx() usize { +pub fn (mut c CCtx) free_cctx() uint { return C.ZSTD_freeCCtx(c.ctx) } @@ -535,14 +535,14 @@ pub fn (mut d DCtx) set(d_param DParameter, val int) ! { // decompress_stream do stream decompress on `input`, and store decompressed data in `output`. // return remaining bytes in `input` stream -pub fn (mut d DCtx) decompress_stream(output &OutBuffer, input &InBuffer) !usize { +pub fn (mut d DCtx) decompress_stream(output &OutBuffer, input &InBuffer) !uint { res := C.ZSTD_decompressStream(d.ctx, output, input) check_error(res)! return res } // free_cctx free a compression context -pub fn (mut d DCtx) free_dctx() usize { +pub fn (mut d DCtx) free_dctx() uint { return C.ZSTD_freeDCtx(d.ctx) } @@ -587,7 +587,7 @@ pub fn store_array[T](fname string, array []T, params CompressParams) ! { fout.write(buf_out[..int(output.pos)])! // then, write the array.data to file input.src = array.data - input.size = usize(array.len * int(sizeof(T))) + input.size = uint(array.len * int(sizeof(T))) input.pos = 0 output.dst = buf_out.data output.size = buf_out_size @@ -618,29 +618,29 @@ pub fn load_array[T](fname string, params DecompressParams) ![]T { mut len_buf := []u8{len: 8} mut input := &InBuffer{} mut output := &OutBuffer{} - mut last_ret := usize(0) + mut last_ret := uint(0) mut last_chunk := false // first, read the array.len from file mut read_len := fin.read(mut buf_in)! last_chunk = read_len < buf_in.len input.src = buf_in.data - input.size = usize(read_len) + input.size = uint(read_len) input.pos = 0 output.dst = len_buf.data - output.size = usize(len_buf.len) + output.size = uint(len_buf.len) output.pos = 0 last_ret = dctx.decompress_stream(output, input)! len := binary.little_endian_u64(len_buf) // then, read the array.data from file mut result := []T{len: int(len)} output.dst = result.data - output.size = usize(result.len) * sizeof(T) + output.size = uint(result.len) * sizeof(T) output.pos = 0 last_ret = dctx.decompress_stream(output, input)! for !last_chunk { read_len = fin.read(mut buf_in)! last_chunk = read_len < buf_in.len - input.size = usize(read_len) + input.size = uint(read_len) input.pos = 0 for input.pos < input.size { last_ret = dctx.decompress_stream(output, input)! diff --git a/vlib/compress/zstd/zstd_test.v b/vlib/compress/zstd/zstd_test.v index b2c2a927de..96e55b391b 100644 --- a/vlib/compress/zstd/zstd_test.v +++ b/vlib/compress/zstd/zstd_test.v @@ -164,7 +164,7 @@ fn compress_file(fname string, oname string, params CompressParams) ! { mut finished := false input.src = buf_in.data - input.size = usize(read_len) + input.size = uint(read_len) input.pos = 0 for !finished { output.dst = buf_out.data @@ -208,11 +208,11 @@ fn decompress_file(fname string, oname string, params DecompressParams) ! { pos: 0 } - mut last_ret := usize(0) + mut last_ret := uint(0) for { read_len := fin.read(mut buf_in)! input.src = buf_in.data - input.size = usize(read_len) + input.size = uint(read_len) input.pos = 0 for input.pos < input.size { output.dst = buf_out.data diff --git a/vlib/crypto/ecdsa/ecdsa_d_use_openssl.c.v b/vlib/crypto/ecdsa/ecdsa_d_use_openssl.c.v index 0098be27de..b88c59b017 100644 --- a/vlib/crypto/ecdsa/ecdsa_d_use_openssl.c.v +++ b/vlib/crypto/ecdsa/ecdsa_d_use_openssl.c.v @@ -78,20 +78,20 @@ fn C.EVP_PKEY_public_check(ctx &C.EVP_PKEY_CTX) i32 fn C.EVP_PKEY_dup(key &C.EVP_PKEY) &C.EVP_PKEY fn C.EVP_PKEY_set_bn_param(pkey &C.EVP_PKEY, const_key_name &char, const_bn &C.BIGNUM) i32 -fn C.EVP_PKEY_get_group_name(pkey &C.EVP_PKEY, gname &u8, gname_sz u32, gname_len &usize) i32 -fn C.EVP_PKEY_get1_encoded_public_key(pkey &C.EVP_PKEY, ppub &&u8) usize +fn C.EVP_PKEY_get_group_name(pkey &C.EVP_PKEY, gname &u8, gname_sz u32, gname_len &uint) i32 +fn C.EVP_PKEY_get1_encoded_public_key(pkey &C.EVP_PKEY, ppub &&u8) uint fn C.EVP_PKEY_get_bn_param(pkey &C.EVP_PKEY, key_name &char, bn &&C.BIGNUM) i32 fn C.EVP_PKEY_fromdata_init(ctx &C.EVP_PKEY_CTX) i32 fn C.EVP_PKEY_fromdata(ctx &C.EVP_PKEY_CTX, ppkey &&C.EVP_PKEY, selection i32, params &C.OSSL_PARAM) i32 // no-prehash signing (verifying) -fn C.EVP_PKEY_sign(ctx &C.EVP_PKEY_CTX, sig &u8, siglen &usize, tbs &u8, tbslen usize) i32 +fn C.EVP_PKEY_sign(ctx &C.EVP_PKEY_CTX, sig &u8, siglen &uint, tbs &u8, tbslen uint) i32 fn C.EVP_PKEY_sign_init(ctx &C.EVP_PKEY_CTX) i32 fn C.EVP_PKEY_verify_init(ctx &C.EVP_PKEY_CTX) i32 -fn C.EVP_PKEY_verify(ctx &C.EVP_PKEY_CTX, sig &u8, siglen usize, tbs &u8, tbslen usize) i32 +fn C.EVP_PKEY_verify(ctx &C.EVP_PKEY_CTX, sig &u8, siglen uint, tbs &u8, tbslen uint) i32 // single shoot digest signing (verifying) routine -fn C.EVP_DigestSign(ctx &C.EVP_MD_CTX, sig &u8, siglen &usize, tbs &u8, tbslen i32) i32 +fn C.EVP_DigestSign(ctx &C.EVP_MD_CTX, sig &u8, siglen &uint, tbs &u8, tbslen i32) i32 fn C.EVP_DigestVerify(ctx &C.EVP_MD_CTX, sig &u8, siglen i32, tbs &u8, tbslen i32) i32 // Message digest routines @@ -102,7 +102,7 @@ fn C.EVP_DigestFinal(ctx &C.EVP_MD_CTX, md &u8, s &u32) i32 // Recommended hashed signing/verifying routines fn C.EVP_DigestSignInit(ctx &C.EVP_MD_CTX, pctx &&C.EVP_PKEY_CTX, tipe &C.EVP_MD, e &C.ENGINE, pkey &C.EVP_PKEY) i32 fn C.EVP_DigestSignUpdate(ctx &C.EVP_MD_CTX, d voidptr, cnt i32) i32 -fn C.EVP_DigestSignFinal(ctx &C.EVP_MD_CTX, sig &u8, siglen &usize) i32 +fn C.EVP_DigestSignFinal(ctx &C.EVP_MD_CTX, sig &u8, siglen &uint) i32 fn C.EVP_DigestVerifyInit(ctx &C.EVP_MD_CTX, pctx &&C.EVP_PKEY_CTX, tipe &C.EVP_MD, e &C.ENGINE, pkey &C.EVP_PKEY) i32 fn C.EVP_DigestVerifyUpdate(ctx &C.EVP_MD_CTX, d voidptr, cnt i32) i32 fn C.EVP_DigestVerifyFinal(ctx &C.EVP_MD_CTX, sig &u8, siglen i32) i32 @@ -122,7 +122,7 @@ fn C.EVP_PKEY_CTX_free(ctx &C.EVP_PKEY_CTX) // ECDH key agreement (used to derive TLS 1.3's P-256 ECDHE shared secret). fn C.EVP_PKEY_derive_init(ctx &C.EVP_PKEY_CTX) i32 fn C.EVP_PKEY_derive_set_peer(ctx &C.EVP_PKEY_CTX, peer &C.EVP_PKEY) i32 -fn C.EVP_PKEY_derive(ctx &C.EVP_PKEY_CTX, key &u8, keylen &usize) i32 +fn C.EVP_PKEY_derive(ctx &C.EVP_PKEY_CTX, key &u8, keylen &uint) i32 fn C.EVP_PKEY_get_bits(pkey &C.EVP_PKEY) i32 @@ -150,7 +150,7 @@ struct C.EC_POINT {} fn C.EC_POINT_new(group &C.EC_GROUP) &C.EC_POINT fn C.EC_POINT_mul(group &C.EC_GROUP, r &C.EC_POINT, n &C.BIGNUM, q &C.EC_POINT, m &C.BIGNUM, ctx &C.BN_CTX) i32 -fn C.EC_POINT_point2buf(group &C.EC_GROUP, point &C.EC_POINT, form i32, pbuf &&u8, ctx &C.BN_CTX) usize +fn C.EC_POINT_point2buf(group &C.EC_GROUP, point &C.EC_POINT, form i32, pbuf &&u8, ctx &C.BN_CTX) uint fn C.EC_POINT_free(point &C.EC_POINT) // Elliptic group (curve) related declarations. @@ -205,7 +205,7 @@ struct C.OSSL_PARAM_BLD {} fn C.OSSL_PARAM_free(params &C.OSSL_PARAM) fn C.OSSL_PARAM_BLD_free(param_bld &C.OSSL_PARAM_BLD) fn C.OSSL_PARAM_BLD_new() &C.OSSL_PARAM_BLD -fn C.OSSL_PARAM_BLD_push_utf8_string(bld &C.OSSL_PARAM_BLD, const_key &char, const_buf &char, bsize usize) i32 +fn C.OSSL_PARAM_BLD_push_utf8_string(bld &C.OSSL_PARAM_BLD, const_key &char, const_buf &char, bsize uint) i32 fn C.OSSL_PARAM_BLD_push_BN(bld &C.OSSL_PARAM_BLD, const_key &char, const_bn &C.BIGNUM) i32 -fn C.OSSL_PARAM_BLD_push_octet_string(bld &C.OSSL_PARAM_BLD, const_key &char, const_buf voidptr, bsize usize) i32 +fn C.OSSL_PARAM_BLD_push_octet_string(bld &C.OSSL_PARAM_BLD, const_key &char, const_buf voidptr, bsize uint) i32 fn C.OSSL_PARAM_BLD_to_param(bld &C.OSSL_PARAM_BLD) &C.OSSL_PARAM diff --git a/vlib/crypto/ecdsa/ecdsa_d_use_openssl.v b/vlib/crypto/ecdsa/ecdsa_d_use_openssl.v index 33b6026ec0..601119ba66 100644 --- a/vlib/crypto/ecdsa/ecdsa_d_use_openssl.v +++ b/vlib/crypto/ecdsa/ecdsa_d_use_openssl.v @@ -307,7 +307,7 @@ pub fn (pv PrivateKey) derive_shared_secret(peer PublicKey) ![]u8 { return error('EVP_PKEY_derive_set_peer failed (mismatched curve or invalid peer key?)') } // First call with a nil buffer to learn the required secret length. - mut secret_len := usize(0) + mut secret_len := uint(0) dlen := C.EVP_PKEY_derive(ctx, unsafe { nil }, &secret_len) if dlen <= 0 || secret_len == 0 { C.EVP_PKEY_CTX_free(ctx) @@ -393,7 +393,7 @@ pub fn PublicKey.from_uncompressed_bytes(bytes []u8, opt CurveOptions) !PublicKe return error('OSSL_PARAM_BLD_new failed') } n := C.OSSL_PARAM_BLD_push_utf8_string(param_bld, c'group', voidptr(opt.nid.str().str), 0) - o := C.OSSL_PARAM_BLD_push_octet_string(param_bld, c'pub', bytes.data, usize(bytes.len)) + o := C.OSSL_PARAM_BLD_push_octet_string(param_bld, c'pub', bytes.data, uint(bytes.len)) if n <= 0 || o <= 0 { C.OSSL_PARAM_BLD_free(param_bld) return error('OSSL_PARAM_BLD_push failed') @@ -481,7 +481,7 @@ fn sign_digest(key &C.EVP_PKEY, digest []u8) ![]u8 { } // siglen was used to store the size of the signature output. When EVP_PKEY_sign // was called with NULL signature buffer, siglen will tell maximum size of signature. - siglen := usize(C.EVP_PKEY_size(key)) + siglen := uint(C.EVP_PKEY_size(key)) sig := []u8{len: int(siglen)} // calls directly with sign @@ -604,7 +604,7 @@ fn evpkey_from_seed(seed []u8, opt CurveOptions) !&C.EVP_PKEY { // push the group, private and public key bytes infos into the builder n := C.OSSL_PARAM_BLD_push_utf8_string(param_bld, c'group', voidptr(opt.nid.str().str), 0) m := C.OSSL_PARAM_BLD_push_BN(param_bld, c'priv', bn) - o := C.OSSL_PARAM_BLD_push_octet_string(param_bld, c'pub', pub_bytes.data, usize(pub_bytes.len)) + o := C.OSSL_PARAM_BLD_push_octet_string(param_bld, c'pub', pub_bytes.data, uint(pub_bytes.len)) if n <= 0 || m <= 0 || o <= 0 { C.EC_POINT_free(point) C.BN_free(bn) diff --git a/vlib/crypto/ecdsa/ecdsa_notd_use_openssl.c.v b/vlib/crypto/ecdsa/ecdsa_notd_use_openssl.c.v index b5565f29f4..e6c8a38e5f 100644 --- a/vlib/crypto/ecdsa/ecdsa_notd_use_openssl.c.v +++ b/vlib/crypto/ecdsa/ecdsa_notd_use_openssl.c.v @@ -356,7 +356,7 @@ fn C.mbedtls_ecdsa_init(ctx &C.mbedtls_ecdsa_context) fn C.mbedtls_ecdsa_free(ctx &C.mbedtls_ecdsa_context) -fn C.mbedtls_ecdsa_genkey(ctx &C.mbedtls_ecdsa_context, gid int, f_rng fn (voidptr, &u8, usize) int, p_rng voidptr) int +fn C.mbedtls_ecdsa_genkey(ctx &C.mbedtls_ecdsa_context, gid int, f_rng fn (voidptr, &u8, uint) int, p_rng voidptr) int // mbedtls_ecdsa_write_signature/read_signature operate on a whole context // (not bare grp/d/Q like the lower-level mbedtls_ecdsa_sign/verify) and @@ -373,9 +373,9 @@ fn C.mbedtls_ecdsa_genkey(ctx &C.mbedtls_ecdsa_context, gid int, f_rng fn (voidp // fails -- which it always does for MBEDTLS_MD_NONE (0), since md.c's own // switch has no case for it. PrivateKey.sign() (ecdsa_notd_use_openssl.v) // relies on this: it never calls write_signature with md_alg 0. -fn C.mbedtls_ecdsa_write_signature(ctx &C.mbedtls_ecdsa_context, md_alg int, hash &u8, hlen usize, sig &u8, sig_size usize, slen &usize, f_rng fn (voidptr, &u8, usize) int, p_rng voidptr) int +fn C.mbedtls_ecdsa_write_signature(ctx &C.mbedtls_ecdsa_context, md_alg int, hash &u8, hlen uint, sig &u8, sig_size uint, slen &uint, f_rng fn (voidptr, &u8, uint) int, p_rng voidptr) int -fn C.mbedtls_ecdsa_read_signature(ctx &C.mbedtls_ecdsa_context, hash &u8, hlen usize, sig &u8, slen usize) int +fn C.mbedtls_ecdsa_read_signature(ctx &C.mbedtls_ecdsa_context, hash &u8, hlen uint, sig &u8, slen uint) int fn C.mbedtls_ecp_group_init(grp &C.mbedtls_ecp_group) @@ -387,9 +387,9 @@ fn C.mbedtls_ecp_point_init(pt &C.mbedtls_ecp_point) fn C.mbedtls_ecp_point_free(pt &C.mbedtls_ecp_point) -fn C.mbedtls_ecp_point_write_binary(grp &C.mbedtls_ecp_group, pt &C.mbedtls_ecp_point, format int, olen &usize, buf &u8, buflen usize) int +fn C.mbedtls_ecp_point_write_binary(grp &C.mbedtls_ecp_group, pt &C.mbedtls_ecp_point, format int, olen &uint, buf &u8, buflen uint) int -fn C.mbedtls_ecp_point_read_binary(grp &C.mbedtls_ecp_group, pt &C.mbedtls_ecp_point, buf &u8, ilen usize) int +fn C.mbedtls_ecp_point_read_binary(grp &C.mbedtls_ecp_group, pt &C.mbedtls_ecp_point, buf &u8, ilen uint) int fn C.mbedtls_ecp_point_cmp(p &C.mbedtls_ecp_point, q &C.mbedtls_ecp_point) int @@ -412,18 +412,18 @@ fn C.mbedtls_ecp_set_public_key(grp_id int, key &C.mbedtls_ecdsa_context, q &C.m // the big-endian private scalar `d`, then rejects it via // mbedtls_ecp_check_privkey unless it lies in `[1, curve_order-1]`. It does // NOT compute the public point -- call mbedtls_ecp_keypair_calc_public next. -fn C.mbedtls_ecp_read_key(grp_id int, key &C.mbedtls_ecdsa_context, buf &u8, buflen usize) int +fn C.mbedtls_ecp_read_key(grp_id int, key &C.mbedtls_ecdsa_context, buf &u8, buflen uint) int // mbedtls_ecp_keypair_calc_public computes and stores `Q = d * G` for a // keypair whose group and private scalar are already set. `f_rng` is // required (used for scalar-multiplication blinding, not for the key itself). -fn C.mbedtls_ecp_keypair_calc_public(key &C.mbedtls_ecdsa_context, f_rng fn (voidptr, &u8, usize) int, p_rng voidptr) int +fn C.mbedtls_ecp_keypair_calc_public(key &C.mbedtls_ecdsa_context, f_rng fn (voidptr, &u8, uint) int, p_rng voidptr) int fn C.mbedtls_mpi_init(x &C.mbedtls_mpi) fn C.mbedtls_mpi_free(x &C.mbedtls_mpi) -fn C.mbedtls_mpi_write_binary(x &C.mbedtls_mpi, buf &u8, buflen usize) int +fn C.mbedtls_mpi_write_binary(x &C.mbedtls_mpi, buf &u8, buflen uint) int fn C.mbedtls_mpi_cmp_mpi(x &C.mbedtls_mpi, y &C.mbedtls_mpi) int @@ -432,18 +432,18 @@ fn C.mbedtls_mpi_cmp_mpi(x &C.mbedtls_mpi, y &C.mbedtls_mpi) int // directly from bare grp/d/Q -- the lower-level API, not the stateful // mbedtls_ecdh_context one, since this module never needs to hold ECDH // state across calls the way a TLS handshake would. -fn C.mbedtls_ecdh_compute_shared(grp &C.mbedtls_ecp_group, z &C.mbedtls_mpi, q &C.mbedtls_ecp_point, d &C.mbedtls_mpi, f_rng fn (voidptr, &u8, usize) int, p_rng voidptr) int +fn C.mbedtls_ecdh_compute_shared(grp &C.mbedtls_ecp_group, z &C.mbedtls_mpi, q &C.mbedtls_ecp_point, d &C.mbedtls_mpi, f_rng fn (voidptr, &u8, uint) int, p_rng voidptr) int fn C.mbedtls_ctr_drbg_init(ctx &C.mbedtls_ctr_drbg_context) fn C.mbedtls_ctr_drbg_free(ctx &C.mbedtls_ctr_drbg_context) -fn C.mbedtls_ctr_drbg_seed(ctx &C.mbedtls_ctr_drbg_context, f_entropy fn (voidptr, &u8, usize) int, p_entropy voidptr, custom &u8, len usize) int +fn C.mbedtls_ctr_drbg_seed(ctx &C.mbedtls_ctr_drbg_context, f_entropy fn (voidptr, &u8, uint) int, p_entropy voidptr, custom &u8, len uint) int -fn C.mbedtls_ctr_drbg_random(p_rng voidptr, output &u8, output_len usize) int +fn C.mbedtls_ctr_drbg_random(p_rng voidptr, output &u8, output_len uint) int fn C.mbedtls_entropy_init(ctx &C.mbedtls_entropy_context) fn C.mbedtls_entropy_free(ctx &C.mbedtls_entropy_context) -fn C.mbedtls_entropy_func(data voidptr, output &u8, len usize) int +fn C.mbedtls_entropy_func(data voidptr, output &u8, len uint) int diff --git a/vlib/crypto/ecdsa/ecdsa_notd_use_openssl.v b/vlib/crypto/ecdsa/ecdsa_notd_use_openssl.v index eb8837b37b..997c1ef059 100644 --- a/vlib/crypto/ecdsa/ecdsa_notd_use_openssl.v +++ b/vlib/crypto/ecdsa/ecdsa_notd_use_openssl.v @@ -165,7 +165,7 @@ pub fn new_key_from_seed(seed []u8, opt CurveOptions) !PrivateKey { // read_key loads the group and the private scalar (range-checked), but // leaves the public point unset -- calc_public derives Q = d * G, which // sign()/public_key()/derive_shared_secret() all need present in the ctx. - rret := C.mbedtls_ecp_read_key(opt.nid.mbedtls_group_id(), ctx, seed.data, usize(seed.len)) + rret := C.mbedtls_ecp_read_key(opt.nid.mbedtls_group_id(), ctx, seed.data, uint(seed.len)) if rret != 0 { C.mbedtls_ecdsa_free(ctx) return error_with_code('crypto.ecdsa: mbedtls_ecp_read_key failed (seed is not a valid private scalar for the curve?)', rret) @@ -280,7 +280,7 @@ pub fn (pv PrivateKey) bytes() ![]u8 { } size := if pv.ks_flag == .flexible { pv.ks_size } else { pv.nid.byte_size() } mut buf := []u8{len: size} - wret := C.mbedtls_mpi_write_binary(&d, buf.data, usize(size)) + wret := C.mbedtls_mpi_write_binary(&d, buf.data, uint(size)) if wret != 0 { return error_with_code('crypto.ecdsa: mbedtls_mpi_write_binary failed', wret) } @@ -365,7 +365,7 @@ pub fn (pv PrivateKey) derive_shared_secret(peer PublicKey) ![]u8 { } size := pv.nid.byte_size() mut secret := []u8{len: size} - wret := C.mbedtls_mpi_write_binary(&z, secret.data, usize(size)) + wret := C.mbedtls_mpi_write_binary(&z, secret.data, uint(size)) if wret != 0 { return error_with_code('crypto.ecdsa: mbedtls_mpi_write_binary failed', wret) } @@ -417,7 +417,7 @@ pub fn (pb PublicKey) verify(message []u8, sig []u8, opt SignerOpts) !bool { // write_signature/sign) -- it verifies against whatever digest bytes are // given, algorithm-agnostic. _, digest := calc_digest(pb.nid, message, opt)! - ret := C.mbedtls_ecdsa_read_signature(pb.ctx, digest.data, usize(digest.len), sig.data, usize(sig.len)) + ret := C.mbedtls_ecdsa_read_signature(pb.ctx, digest.data, uint(digest.len), sig.data, uint(sig.len)) return ret == 0 } @@ -465,8 +465,8 @@ pub fn (pb PublicKey) uncompressed_bytes() ![]u8 { return error_with_code('crypto.ecdsa: mbedtls_ecp_export failed', eret) } mut buf := []u8{len: int(C.MBEDTLS_ECP_MAX_PT_LEN)} - mut olen := usize(0) - wret := C.mbedtls_ecp_point_write_binary(&grp, &q, C.MBEDTLS_ECP_PF_UNCOMPRESSED, &olen, buf.data, usize(buf.len)) + mut olen := uint(0) + wret := C.mbedtls_ecp_point_write_binary(&grp, &q, C.MBEDTLS_ECP_PF_UNCOMPRESSED, &olen, buf.data, uint(buf.len)) if wret != 0 { return error_with_code('crypto.ecdsa: mbedtls_ecp_point_write_binary failed', wret) } @@ -499,7 +499,7 @@ pub fn PublicKey.from_uncompressed_bytes(bytes []u8, opt CurveOptions) !PublicKe defer { C.mbedtls_ecp_point_free(&q) } - rret := C.mbedtls_ecp_point_read_binary(&grp, &q, bytes.data, usize(bytes.len)) + rret := C.mbedtls_ecp_point_read_binary(&grp, &q, bytes.data, uint(bytes.len)) if rret != 0 { return error_with_code('crypto.ecdsa: mbedtls_ecp_point_read_binary failed', rret) } @@ -616,8 +616,8 @@ fn sign_digest(ctx &C.mbedtls_ecdsa_context, md_alg int, digest []u8) ![]u8 { free_rng(mut ctr_drbg, mut entropy) } mut sig := []u8{len: int(C.MBEDTLS_ECDSA_MAX_LEN)} - mut slen := usize(0) - ret := C.mbedtls_ecdsa_write_signature(ctx, md_alg, digest.data, usize(digest.len), sig.data, usize(sig.len), &slen, C.mbedtls_ctr_drbg_random, voidptr(&ctr_drbg)) + mut slen := uint(0) + ret := C.mbedtls_ecdsa_write_signature(ctx, md_alg, digest.data, uint(digest.len), sig.data, uint(sig.len), &slen, C.mbedtls_ctr_drbg_random, voidptr(&ctr_drbg)) if ret != 0 { return error_with_code('crypto.ecdsa: mbedtls_ecdsa_write_signature failed', ret) } diff --git a/vlib/crypto/ecdsa/entropy_callback_notd_use_openssl_test.c.v b/vlib/crypto/ecdsa/entropy_callback_notd_use_openssl_test.c.v index 7a1c8ae11c..5cd85a2de7 100644 --- a/vlib/crypto/ecdsa/entropy_callback_notd_use_openssl_test.c.v +++ b/vlib/crypto/ecdsa/entropy_callback_notd_use_openssl_test.c.v @@ -6,11 +6,11 @@ fn test_entropy_callback_preserves_integer_result() { defer { C.mbedtls_entropy_free(&entropy) } mut output := [32]u8{} callback := C.mbedtls_entropy_func - status := callback(voidptr(&entropy), &output[0], usize(output.len)) + status := callback(voidptr(&entropy), &output[0], uint(output.len)) assert status == 0 } -fn reject_entropy(_ voidptr, _ &u8, _ usize) int { +fn reject_entropy(_ voidptr, _ &u8, _ uint) int { return -1 } diff --git a/vlib/crypto/ecdsa/util_d_use_openssl.v b/vlib/crypto/ecdsa/util_d_use_openssl.v index 408eaeefd2..f7a11ee8c8 100644 --- a/vlib/crypto/ecdsa/util_d_use_openssl.v +++ b/vlib/crypto/ecdsa/util_d_use_openssl.v @@ -235,7 +235,7 @@ const default_groupname_size = 25 // short name commonly only take 10-15 length // key_group_name returns underlying group name of the key as a string. fn key_group_name(key &C.EVP_PKEY) !string { gname := []u8{len: default_groupname_size} - gname_len := usize(0) + gname_len := uint(0) mut s := C.EVP_PKEY_get_group_name(key, gname.data, u32(gname.len), &gname_len) if s == 0 { unsafe { gname.free() } diff --git a/vlib/crypto/rand/internal/rand_darwin.c.v b/vlib/crypto/rand/internal/rand_darwin.c.v index 9d5ef823d3..16960e9a46 100644 --- a/vlib/crypto/rand/internal/rand_darwin.c.v +++ b/vlib/crypto/rand/internal/rand_darwin.c.v @@ -5,7 +5,7 @@ module internal #include -fn C.getentropy(buf voidptr, buflen usize) i32 +fn C.getentropy(buf voidptr, buflen uint) i32 const read_batch_size = 256 diff --git a/vlib/crypto/rand/internal/rand_freebsd.c.v b/vlib/crypto/rand/internal/rand_freebsd.c.v index 915940a29f..df4745b4bc 100644 --- a/vlib/crypto/rand/internal/rand_freebsd.c.v +++ b/vlib/crypto/rand/internal/rand_freebsd.c.v @@ -5,7 +5,7 @@ module internal #include -fn C.arc4random_buf(p &u8, n usize) +fn C.arc4random_buf(p &u8, n uint) // read fills `buffer` with random bytes from the OS. pub fn read(mut buffer []u8) ! { diff --git a/vlib/crypto/rand/internal/rand_linux.c.v b/vlib/crypto/rand/internal/rand_linux.c.v index 8c570acb3b..1953b9a3a7 100644 --- a/vlib/crypto/rand/internal/rand_linux.c.v +++ b/vlib/crypto/rand/internal/rand_linux.c.v @@ -14,9 +14,9 @@ $if macos || ios || openbsd { pub const C.SYS_getrandom int -fn C.getentropy(buf voidptr, buflen usize) i32 +fn C.getentropy(buf voidptr, buflen uint) i32 -fn C.v_crypto_getrandom(buf voidptr, n usize) i64 +fn C.v_crypto_getrandom(buf voidptr, n uint) i64 const read_batch_size = 256 @@ -45,11 +45,11 @@ fn getrandom(bytes_needed int, buffer voidptr) int { panic('getrandom() dont request more than ${read_batch_size} bytes at once.') } $if macos || ios || openbsd { - if C.getentropy(buffer, usize(bytes_needed)) != 0 { + if C.getentropy(buffer, uint(bytes_needed)) != 0 { return -1 } return bytes_needed } $else { - return int(C.v_crypto_getrandom(buffer, usize(bytes_needed))) + return int(C.v_crypto_getrandom(buffer, uint(bytes_needed))) } } diff --git a/vlib/crypto/rand/internal/rand_openbsd.c.v b/vlib/crypto/rand/internal/rand_openbsd.c.v index 915940a29f..df4745b4bc 100644 --- a/vlib/crypto/rand/internal/rand_openbsd.c.v +++ b/vlib/crypto/rand/internal/rand_openbsd.c.v @@ -5,7 +5,7 @@ module internal #include -fn C.arc4random_buf(p &u8, n usize) +fn C.arc4random_buf(p &u8, n uint) // read fills `buffer` with random bytes from the OS. pub fn read(mut buffer []u8) ! { diff --git a/vlib/crypto/rand/internal/rand_solaris.c.v b/vlib/crypto/rand/internal/rand_solaris.c.v index 255b71d700..75840f8973 100644 --- a/vlib/crypto/rand/internal/rand_solaris.c.v +++ b/vlib/crypto/rand/internal/rand_solaris.c.v @@ -5,7 +5,7 @@ module internal #include -fn C.getrandom(p &u8, n usize, flags u32) i32 +fn C.getrandom(p &u8, n uint, flags u32) i32 const read_batch_size = 256 diff --git a/vlib/db/mssql/_cdefs.c.v b/vlib/db/mssql/_cdefs.c.v index ecdbeda901..1a63d262bb 100644 --- a/vlib/db/mssql/_cdefs.c.v +++ b/vlib/db/mssql/_cdefs.c.v @@ -7,11 +7,11 @@ type C.SQLHANDLE = voidptr type C.SQLHSTMT = voidptr type C.SQLHWND = voidptr type C.SQLINTEGER = int -type C.SQLLEN = isize +type C.SQLLEN = C.ptrdiff_t type C.SQLPOINTER = voidptr type C.SQLRETURN = i16 type C.SQLSMALLINT = i16 -type C.SQLULEN = usize +type C.SQLULEN = uint type C.SQLUSMALLINT = u16 fn C.SQLAllocHandle(handle_type C.SQLSMALLINT, input_handle C.SQLHANDLE, output_handle &C.SQLHANDLE) C.SQLRETURN diff --git a/vlib/db/mssql/stmt_handle.c.v b/vlib/db/mssql/stmt_handle.c.v index 8f5bcbbb5b..90a317a471 100644 --- a/vlib/db/mssql/stmt_handle.c.v +++ b/vlib/db/mssql/stmt_handle.c.v @@ -13,7 +13,7 @@ mut: buffers [][]char // indicators for each column. Use a V pointer-sized integer to avoid arrays // of C typedefs in generated code while still matching SQLLEN width. - indicators []isize + indicators []int } // new_hstmt constructs a new statement handle @@ -95,7 +95,7 @@ fn (mut h HStmt) prepare_read() ! { h.column_count = column_count // remember the count because read will need it h.buffers = [][]char{len: h.column_count} - h.indicators = []isize{len: h.column_count} + h.indicators = []int{len: h.column_count} for i := 0; i < h.column_count; i++ { i_col := C.SQLUSMALLINT(i + 1) // col number starts with 1 diff --git a/vlib/db/mysql/orm.c.v b/vlib/db/mysql/orm.c.v index 41635e126b..2985a8deb0 100644 --- a/vlib/db/mysql/orm.c.v +++ b/vlib/db/mysql/orm.c.v @@ -42,7 +42,7 @@ pub fn (db DB) select(config orm.SelectConfig, data orm.QueryData, where orm.Que data_pointers << unsafe { malloc(8) } } .type_time, .type_date, .type_datetime, .type_time2, .type_datetime2, .type_timestamp { - data_pointers << unsafe { malloc(sizeof(C.MYSQL_TIME)) } + data_pointers << unsafe { malloc(int(sizeof(C.MYSQL_TIME))) } } .type_decimal, .type_newdecimal, .type_string, .type_var_string, .type_blob, .type_tiny_blob, .type_medium_blob, .type_long_blob { @@ -88,7 +88,7 @@ pub fn (db DB) select(config orm.SelectConfig, data orm.QueryData, where orm.Que .type_time, .type_date, .type_datetime, .type_timestamp { // FIXME: Allocate memory for blobs dynamically. mysql_bind.buffer_type = C.MYSQL_TYPE_BLOB - mysql_bind.buffer_length = usize(FieldType.type_blob.get_len()) + mysql_bind.buffer_length = uint(FieldType.type_blob.get_len()) } else {} } diff --git a/vlib/db/mysql/stmt.c.v b/vlib/db/mysql/stmt.c.v index 5f5bdc0cac..f2935eca8d 100644 --- a/vlib/db/mysql/stmt.c.v +++ b/vlib/db/mysql/stmt.c.v @@ -1,6 +1,6 @@ module mysql -type C.v_mysql_ulong = usize +type C.v_mysql_ulong = uint type C.v_mysql_bool = i8 @[typedef] @@ -297,7 +297,7 @@ pub fn (mut stmt Stmt) bind(typ int, buffer voidptr, buf_len u32) { stmt.binds << C.MYSQL_BIND{ buffer_type: typ buffer: buffer - buffer_length: usize(buf_len) + buffer_length: uint(buf_len) length: 0 is_null: 0 } diff --git a/vlib/db/pg/pg.c.v b/vlib/db/pg/pg.c.v index e5e5f07d3f..ab2447163d 100644 --- a/vlib/db/pg/pg.c.v +++ b/vlib/db/pg/pg.c.v @@ -293,7 +293,7 @@ fn C.PQconsumeInput(conn &C.PGconn) i32 fn C.PQsocket(conn &C.PGconn) i32 -fn C.PQescapeLiteral(conn &C.PGconn, str &char, length usize) &char +fn C.PQescapeLiteral(conn &C.PGconn, str &char, length uint) &char fn conninfo_needs_quotes(value string) bool { for ch in value { @@ -1031,7 +1031,7 @@ pub fn (mut c Conn) unlisten_all() ! { // a query. Prefer parameterized queries when they can express the operation. pub fn (mut c Conn) escape_literal(value string) !string { c.ensure_active()! - escaped := C.PQescapeLiteral(c.conn, &char(value.str), usize(value.len)) + escaped := C.PQescapeLiteral(c.conn, &char(value.str), uint(value.len)) if escaped == unsafe { nil } { e := unsafe { C.PQerrorMessage(c.conn).vstring() } return error('pg escape_literal error: "${e}"') diff --git a/vlib/db/redis/README.md b/vlib/db/redis/README.md index e018dd4e50..844b9897a4 100644 --- a/vlib/db/redis/README.md +++ b/vlib/db/redis/README.md @@ -103,7 +103,7 @@ part := db.getrange[string]('first', 0, 4)! missing key. The deprecated `getset` and `substr` commands are also available; `getset` stores the new value even when it returns `NilError` for a missing previous value. `mget[T]` and `hmget[T]` return nullable entries for strings, integers, or `[]u8`. -Scalar and multi-get unsigned reads preserve the full range of `u64` and `usize`. +Scalar and multi-get unsigned reads preserve the full range of `u64` and `uint`. `GetExOptions` selects one `mode`: `.none`, `.ex`, `.px`, `.exat`, `.pxat`, or `.persist`. The four expiration modes require a positive `value`; `.none` and `.persist` use zero. diff --git a/vlib/db/redis/commands.v b/vlib/db/redis/commands.v index 3fee2764e7..7b7aa5b35c 100644 --- a/vlib/db/redis/commands.v +++ b/vlib/db/redis/commands.v @@ -169,7 +169,7 @@ fn bulk_value[T](resp RedisValue, command string) !T { } $if T is string { return data - } $else $if T is u64 || T is usize { + } $else $if T is u64 || T is uint { return T(unsigned_value(data)) } $else $if T is $int { return T(data.i64()) diff --git a/vlib/db/redis/redis_test.v b/vlib/db/redis/redis_test.v index 3e7bb6c0ae..31c0a3930f 100644 --- a/vlib/db/redis/redis_test.v +++ b/vlib/db/redis/redis_test.v @@ -743,12 +743,12 @@ fn test_multi_key_values() ! { assert_command_value(unsigned_values[0], ~u64(0)) assert db.get[u64](keys[4])! == ~u64(0) assert db.mset({ - keys[4]: ~usize(0) + keys[4]: ~uint(0) })! == 'OK' - usize_values := db.mget[usize](keys[4])! + usize_values := db.mget[uint](keys[4])! assert usize_values.len == 1 - assert_command_value(usize_values[0], ~usize(0)) - assert db.get[usize](keys[4])! == ~usize(0) + assert_command_value(usize_values[0], ~uint(0)) + assert db.get[uint](keys[4])! == ~uint(0) assert !db.msetnx({ keys[2]: 'replacement' @@ -932,12 +932,12 @@ fn test_hash_commands() ! { assert_command_value(unsigned_values[0], ~u64(0)) assert db.hget[u64](keys[0], 'unsigned')! == ~u64(0) assert db.hset(keys[0], { - 'unsigned': ~usize(0) + 'unsigned': ~uint(0) })! == 0 - usize_values := db.hmget[usize](keys[0], 'unsigned')! + usize_values := db.hmget[uint](keys[0], 'unsigned')! assert usize_values.len == 1 - assert_command_value(usize_values[0], ~usize(0)) - assert db.hget[usize](keys[0], 'unsigned')! == ~usize(0) + assert_command_value(usize_values[0], ~uint(0)) + assert db.hget[uint](keys[0], 'unsigned')! == ~uint(0) assert db.hdel(keys[0], 'unsigned')! == 1 assert db.hincrbyfloat(keys[0], 'float', 1.25)! == 1.25 assert db.hincrbyfloat(keys[0], 'float', -0.5)! == 0.75 diff --git a/vlib/dlmalloc/dlmalloc.v b/vlib/dlmalloc/dlmalloc.v index 7943861258..fd3252d40a 100644 --- a/vlib/dlmalloc/dlmalloc.v +++ b/vlib/dlmalloc/dlmalloc.v @@ -21,9 +21,9 @@ $if debug ? { #include "valgrind.h" } -fn //C.VALGRIND_MALLOCLIKE_BLOCK(addr voidptr, size usize, rzb usize,is_zeroed bool) -fn //C.VALGRIND_FREELIKE_BLOCK(addr voidptr, rzB usize) -fn //C.VALGRIND_MAKE_MEM_UNDEFINED(addr voidptr, size usize) +fn //C.VALGRIND_MALLOCLIKE_BLOCK(addr voidptr, size uint, rzb uint,is_zeroed bool) +fn //C.VALGRIND_FREELIKE_BLOCK(addr voidptr, rzB uint) +fn //C.VALGRIND_MAKE_MEM_UNDEFINED(addr voidptr, size uint) */ pub const n_small_bins = 32 @@ -33,90 +33,90 @@ pub const tree_bin_shift = 8 pub const max_release_check_rate = 4095 -fn usize_leading_zeros(x usize) usize { - if sizeof(usize) == 8 { - return usize(bits.leading_zeros_64(u64(x))) +fn usize_leading_zeros(x uint) uint { + if sizeof(uint) == 8 { + return uint(bits.leading_zeros_64(u64(x))) } else { - return usize(bits.leading_zeros_32(u32(x))) + return uint(bits.leading_zeros_32(u32(x))) } } @[inline] -fn default_granularity() usize { +fn default_granularity() uint { return 64 * 1024 } @[inline] -fn default_trim_threshold() usize { +fn default_trim_threshold() uint { return 2 * 1024 * 1024 } @[inline] -fn malloc_alignment() usize { - return sizeof(usize) * 2 +fn malloc_alignment() uint { + return sizeof(uint) * 2 } @[inline] -fn chunk_overhead() usize { - return sizeof(usize) +fn chunk_overhead() uint { + return sizeof(uint) } @[inline] -fn min_large_size() usize { +fn min_large_size() uint { return 1 << tree_bin_shift } @[inline] -fn mmap_chunk_overhead() usize { - return 2 * sizeof(usize) +fn mmap_chunk_overhead() uint { + return 2 * sizeof(uint) } @[inline] -fn max_small_size() usize { +fn max_small_size() uint { return min_large_size() - 1 } @[inline] -fn max_small_request() usize { +fn max_small_request() uint { return max_small_size() - (malloc_alignment() - 1) - chunk_overhead() } @[inline] -fn min_chunk_size() usize { +fn min_chunk_size() uint { return align_up(sizeof(Chunk), malloc_alignment()) } @[inline] -fn chunk_mem_offset() usize { - return 2 * sizeof(usize) +fn chunk_mem_offset() uint { + return 2 * sizeof(uint) } @[inline] -fn min_request() usize { +fn min_request() uint { return min_chunk_size() - chunk_overhead() - 1 } @[inline] -fn top_foot_size() usize { +fn top_foot_size() uint { return align_offset_usize(chunk_mem_offset()) + pad_request(sizeof(Segment)) + min_chunk_size() } @[inline] -fn max_request() usize { +fn max_request() uint { return calc_max_request() } @[inline] -fn mmap_foot_pad() usize { - return 4 * sizeof(usize) +fn mmap_foot_pad() uint { + return 4 * sizeof(uint) } -fn min_sys_alloc_space() usize { +fn min_sys_alloc_space() uint { return ((~0 - (default_granularity() + top_foot_size() + malloc_alignment()) + 1) & ~malloc_alignment()) - chunk_overhead() + 1 } -fn calc_max_request() usize { +fn calc_max_request() uint { x := min_sys_alloc_space() y := (~min_chunk_size() + 1) << 2 @@ -127,31 +127,31 @@ fn calc_max_request() usize { } } -fn pad_request(amt usize) usize { +fn pad_request(amt uint) uint { return align_up(amt + chunk_overhead(), malloc_alignment()) } -fn align_offset_usize(addr usize) usize { +fn align_offset_usize(addr uint) uint { return align_up(addr, malloc_alignment()) - addr } -fn is_aligned(a usize) bool { +fn is_aligned(a uint) bool { return a & (malloc_alignment() - 1) == 0 } -fn is_small(s usize) bool { +fn is_small(s uint) bool { return s >> small_bin_shift < n_small_bins } -fn small_index2size(idx u32) usize { - return usize(idx) << small_bin_shift +fn small_index2size(idx u32) uint { + return uint(idx) << small_bin_shift } -fn small_index(size usize) u32 { +fn small_index(size uint) u32 { return u32(size >> small_bin_shift) } -fn align_up(a usize, alignment usize) usize { +fn align_up(a uint, alignment uint) uint { if a % alignment == 0 { return a } else { @@ -170,22 +170,22 @@ fn least_bit(x u32) u32 { } fn leftshift_for_tree_index(x u32) u32 { - y := usize(x) + y := uint(x) if y == n_tree_bins - 1 { return 0 } else { - return u32(sizeof(usize) * 8 - 1 - ((y >> 1) + tree_bin_shift - 2)) + return u32(sizeof(uint) * 8 - 1 - ((y >> 1) + tree_bin_shift - 2)) } } @[unsafe] fn align_as_chunk(ptr_ voidptr) &Chunk { - ptr := usize(ptr_) + ptr := uint(ptr_) chunk := ptr + chunk_mem_offset() return &Chunk(ptr + align_offset_usize(chunk)) } -fn request_2_size(req usize) usize { +fn request_2_size(req uint) uint { if req < min_request() { return min_chunk_size() } else { @@ -193,7 +193,7 @@ fn request_2_size(req usize) usize { } } -fn overhead_for(c &Chunk) usize { +fn overhead_for(c &Chunk) uint { if c.mmapped() { return mmap_chunk_overhead() } else { @@ -208,19 +208,19 @@ fn overhead_for(c &Chunk) usize { // Why not `interface?` Interfaces require memory allocation so it is simpler to pass a struct. pub struct Allocator { pub: - alloc fn (voidptr, usize) (voidptr, usize, u32) = unsafe { nil } - remap fn (voidptr, voidptr, usize, usize, bool) voidptr = unsafe { nil } - free_part fn (voidptr, voidptr, usize, usize) bool = unsafe { nil } - free_ fn (voidptr, voidptr, usize) bool = unsafe { nil } + alloc fn (voidptr, uint) (voidptr, uint, u32) = unsafe { nil } + remap fn (voidptr, voidptr, uint, uint, bool) voidptr = unsafe { nil } + free_part fn (voidptr, voidptr, uint, uint) bool = unsafe { nil } + free_ fn (voidptr, voidptr, uint) bool = unsafe { nil } can_release_part fn (voidptr, u32) bool = unsafe { nil } allocates_zeros fn (voidptr) bool = unsafe { nil } - page_size fn (voidptr) usize = unsafe { nil } // not a constant field because some platforms might have different page sizes depending on configs + page_size fn (voidptr) uint = unsafe { nil } // not a constant field because some platforms might have different page sizes depending on configs data voidptr } pub struct Dlmalloc { system_allocator Allocator - max_request usize = 4294901657 + max_request uint = 4294901657 mut: // bin maps smallmap u32 // bin map for small bins @@ -228,16 +228,16 @@ mut: smallbins [66]&Chunk // small bins, it is actually (n_small_bins + 1) * 2 treebins [n_tree_bins]&TreeChunk - dvsize usize - topsize usize + dvsize uint + topsize uint dv &Chunk = unsafe { nil } top &Chunk = unsafe { nil } - footprint usize - max_footprint usize + footprint uint + max_footprint uint seg Segment trim_check u32 least_addr voidptr - release_checks usize + release_checks uint } // new creates a new instance of `Dlmalloc` with the given system allocator. @@ -265,8 +265,8 @@ pub fn new(system_allocator Allocator) Dlmalloc { @[heap] struct Chunk { mut: - prev_foot usize - head usize + prev_foot uint + head uint prev &Chunk = unsafe { nil } next &Chunk = unsafe { nil } } @@ -275,7 +275,7 @@ mut: struct Segment { mut: base voidptr - size usize + size uint next &Segment = unsafe { nil } flags u32 } @@ -295,11 +295,11 @@ const flag4 = 1 << 2 const inuse = pinuse | cinuse const flag_bits = pinuse | cinuse | flag4 -fn fencepost_head() usize { - return inuse | sizeof(usize) +fn fencepost_head() uint { + return inuse | sizeof(uint) } -fn (c &Chunk) size() usize { +fn (c &Chunk) size() uint { return c.head & ~flag_bits } @@ -308,13 +308,13 @@ fn (c &Chunk) mmapped() bool { } fn (c &Chunk) next() &Chunk { - mut me := usize(c) + mut me := uint(c) me = me + c.size() return unsafe { &Chunk(me) } } fn (c &Chunk) prev() &Chunk { - mut me := usize(c) + mut me := uint(c) me = me - c.prev_foot return unsafe { &Chunk(me) } } @@ -335,52 +335,52 @@ fn (c &Chunk) inuse() bool { return c.head & inuse != pinuse } -fn (mut c Chunk) set_inuse(size usize) { +fn (mut c Chunk) set_inuse(size uint) { c.head = (c.head & pinuse) | size | cinuse mut next := c.plus_offset(size) next.head |= pinuse } -fn (mut c Chunk) set_inuse_and_pinuse(size usize) { +fn (mut c Chunk) set_inuse_and_pinuse(size uint) { c.head = pinuse | size | cinuse mut next := c.plus_offset(size) next.head |= pinuse } -fn (mut c Chunk) set_size_and_pinuse_of_inuse_chunk(size usize) { +fn (mut c Chunk) set_size_and_pinuse_of_inuse_chunk(size uint) { c.head = size | pinuse | cinuse } -fn (mut c Chunk) set_size_and_pinuse_of_free_chunk(size usize) { +fn (mut c Chunk) set_size_and_pinuse_of_free_chunk(size uint) { c.head = size | pinuse c.set_foot(size) } -fn (mut c Chunk) set_free_with_pinuse(size usize, n_ &Chunk) { +fn (mut c Chunk) set_free_with_pinuse(size uint, n_ &Chunk) { mut n := unsafe { n_ } n.clear_pinuse() c.set_size_and_pinuse_of_free_chunk(size) } -fn (c &Chunk) set_foot(size usize) { +fn (c &Chunk) set_foot(size uint) { mut next := c.plus_offset(size) next.prev_foot = size } -fn (c &Chunk) plus_offset(offset usize) &Chunk { - return unsafe { &Chunk((usize(c) + offset)) } +fn (c &Chunk) plus_offset(offset uint) &Chunk { + return unsafe { &Chunk((uint(c) + offset)) } } -fn (c &Chunk) minus_offset(offset usize) &Chunk { - return unsafe { &Chunk(usize(c) - offset) } +fn (c &Chunk) minus_offset(offset uint) &Chunk { + return unsafe { &Chunk(uint(c) - offset) } } fn (c &Chunk) to_mem() voidptr { - return voidptr(usize(c) + chunk_mem_offset()) + return voidptr(uint(c) + chunk_mem_offset()) } fn chunk_from_mem(mem_ voidptr) &Chunk { - mem := usize(mem_) + mem := uint(mem_) return unsafe { &Chunk((mem - chunk_mem_offset())) } } @@ -430,7 +430,7 @@ fn (seg &Segment) holds(addr voidptr) bool { } fn (seg &Segment) top() voidptr { - return voidptr(usize(seg.base) + seg.size) + return voidptr(uint(seg.base) + seg.size) } @[unsafe] @@ -451,20 +451,20 @@ fn (mut dl Dlmalloc) treebin_at(idx u32) &&TreeChunk { return &dl.treebins[idx] } -fn (dl &Dlmalloc) compute_tree_index(size usize) u32 { +fn (dl &Dlmalloc) compute_tree_index(size uint) u32 { x := size >> tree_bin_shift if x == 0 { return 0 } else if x > 0xffff { return n_tree_bins - 1 } else { - k := sizeof(usize) * 8 - 1 - usize_leading_zeros(x) + k := sizeof(uint) * 8 - 1 - usize_leading_zeros(x) return u32((k << 1) + ((size >> (k + tree_bin_shift - 1)) & 1)) } } @[unsafe] -fn (mut dl Dlmalloc) unlink_chunk(chunk &Chunk, size usize) { +fn (mut dl Dlmalloc) unlink_chunk(chunk &Chunk, size uint) { unsafe { if is_small(size) { dl.unlink_small_chunk(chunk, size) @@ -475,7 +475,7 @@ fn (mut dl Dlmalloc) unlink_chunk(chunk &Chunk, size usize) { } @[unsafe] -fn (mut dl Dlmalloc) unlink_small_chunk(chunk_ &Chunk, size usize) { +fn (mut dl Dlmalloc) unlink_small_chunk(chunk_ &Chunk, size uint) { mut chunk := unsafe { chunk_ } mut f := chunk.prev mut b := chunk.next @@ -574,7 +574,7 @@ fn (mut dl Dlmalloc) unlink_first_small_chunk(head_ &Chunk, next_ &Chunk, idx u3 // calloc is the same as `malloc`, except if the allocation succeeds it's guaranteed // to point to `size` bytes of zeros. @[unsafe] -pub fn (mut dl Dlmalloc) calloc(size usize) voidptr { +pub fn (mut dl Dlmalloc) calloc(size uint) voidptr { unsafe { ptr := dl.malloc(size) if !isnil(ptr) && dl.calloc_must_clear(ptr) { @@ -601,7 +601,7 @@ pub fn (mut dl Dlmalloc) free_(mem voidptr) { if p.mmapped() { psize += prevsize + mmap_foot_pad() if dl.system_allocator.free_(dl.system_allocator.data, - voidptr(usize(p) - prevsize), psize) + voidptr(uint(p) - prevsize), psize) { dl.footprint -= psize } @@ -674,19 +674,19 @@ pub fn (mut dl Dlmalloc) free_(mem voidptr) { } } -fn (dl &Dlmalloc) should_trim(size usize) bool { +fn (dl &Dlmalloc) should_trim(size uint) bool { return size > dl.trim_check } @[unsafe] -fn (mut dl Dlmalloc) sys_trim(pad_ usize) bool { +fn (mut dl Dlmalloc) sys_trim(pad_ uint) bool { unsafe { mut pad := pad_ - mut released := usize(0) + mut released := uint(0) if pad < dl.max_request && !isnil(dl.top) { pad += top_foot_size() if dl.topsize > pad { - unit := usize(default_granularity()) + unit := uint(default_granularity()) extra := ((dl.topsize - pad + unit - 1) / unit - 1) * unit mut sp := dl.segment_holding(dl.top) @@ -723,10 +723,10 @@ fn (mut dl Dlmalloc) sys_trim(pad_ usize) bool { } @[unsafe] -fn (mut dl Dlmalloc) release_unused_segments() usize { +fn (mut dl Dlmalloc) release_unused_segments() uint { unsafe { - mut released := usize(0) - mut nsegs := usize(0) + mut released := uint(0) + mut nsegs := uint(0) mut pred := &dl.seg mut sp := pred.next for !isnil(sp) { @@ -739,8 +739,8 @@ fn (mut dl Dlmalloc) release_unused_segments() usize { if sp.can_release_part(&dl.system_allocator) && !sp.is_extern() { mut p := align_as_chunk(base) psize := p.size() - chunk_top := voidptr(usize(p) + psize) - top := voidptr(usize(base) + (size - top_foot_size())) + chunk_top := voidptr(uint(p) + psize) + top := voidptr(uint(base) + (size - top_foot_size())) if !p.inuse() && chunk_top >= top { mut tp := &TreeChunk(p) if voidptr(p) == voidptr(dl.dv) { @@ -786,7 +786,7 @@ fn (dl &Dlmalloc) has_segment_link(ptr &Segment) bool { } @[unsafe] -fn (mut dl Dlmalloc) replace_dv(chunk &Chunk, size usize) { +fn (mut dl Dlmalloc) replace_dv(chunk &Chunk, size uint) { dvs := dl.dvsize if dvs != 0 { dv := dl.dv @@ -799,7 +799,7 @@ fn (mut dl Dlmalloc) replace_dv(chunk &Chunk, size usize) { } @[unsafe] -fn (mut dl Dlmalloc) insert_chunk(chunk &Chunk, size usize) { +fn (mut dl Dlmalloc) insert_chunk(chunk &Chunk, size uint) { unsafe { if is_small(size) { dl.insert_small_chunk(chunk, size) @@ -810,7 +810,7 @@ fn (mut dl Dlmalloc) insert_chunk(chunk &Chunk, size usize) { } @[unsafe] -fn (mut dl Dlmalloc) insert_small_chunk(chunk_ &Chunk, size usize) { +fn (mut dl Dlmalloc) insert_small_chunk(chunk_ &Chunk, size uint) { mut chunk := unsafe { chunk_ } idx := small_index(size) unsafe { @@ -832,7 +832,7 @@ fn (mut dl Dlmalloc) insert_small_chunk(chunk_ &Chunk, size usize) { } @[unsafe] -fn (mut dl Dlmalloc) insert_large_chunk(chunk_ &TreeChunk, size usize) { +fn (mut dl Dlmalloc) insert_large_chunk(chunk_ &TreeChunk, size uint) { unsafe { mut chunk := chunk_ idx := dl.compute_tree_index(size) @@ -855,7 +855,7 @@ fn (mut dl Dlmalloc) insert_large_chunk(chunk_ &TreeChunk, size usize) { mut k := size << leftshift_for_tree_index(idx) for { if t.chunk().size() != size { - c_ := &t.child[int((k >> (sizeof(usize) * 8 - 1)) & 1)] + c_ := &t.child[int((k >> (sizeof(uint) * 8 - 1)) & 1)] mut c := &&TreeChunk(c_) k <<= 1 if !isnil(*c) { @@ -914,7 +914,7 @@ fn (mut dl Dlmalloc) treemap_is_marked(idx u32) bool { } // malloc allocates a block of memory of the given size. -pub fn (mut dl Dlmalloc) malloc(size usize) voidptr { +pub fn (mut dl Dlmalloc) malloc(size uint) voidptr { unsafe { p := dl.malloc_real(size) if !isnil(p) { @@ -926,8 +926,8 @@ pub fn (mut dl Dlmalloc) malloc(size usize) voidptr { // malloc_real behaves as libc malloc, but operates within the given space @[unsafe] -fn (mut dl Dlmalloc) malloc_real(size usize) voidptr { - mut nb := usize(0) +fn (mut dl Dlmalloc) malloc_real(size uint) voidptr { + mut nb := uint(0) unsafe { if size <= max_small_request() { nb = request_2_size(size) @@ -961,7 +961,7 @@ fn (mut dl Dlmalloc) malloc_real(size usize) voidptr { dl.unlink_first_small_chunk(b, p, i) smallsize := small_index2size(i) rsize := smallsize - nb - if sizeof(usize) != 4 && rsize < min_chunk_size() { + if sizeof(uint) != 4 && rsize < min_chunk_size() { p.set_inuse_and_pinuse(smallsize) } else { p.set_size_and_pinuse_of_inuse_chunk(nb) @@ -1043,23 +1043,23 @@ fn (mut dl Dlmalloc) init_bins() { } @[unsafe] -fn (mut dl Dlmalloc) init_top(ptr &Chunk, size_ usize) { +fn (mut dl Dlmalloc) init_top(ptr &Chunk, size_ uint) { pmem := ptr.to_mem() - offset := align_offset_usize(usize(pmem)) + offset := align_offset_usize(uint(pmem)) mut p := ptr.plus_offset(offset) size := size_ - offset dl.top = p dl.topsize = size - // C.VALGRIND_MAKE_MEM_UNDEFINED(p.plus_offset(sizeof(usize)),sizeof(usize)) + // C.VALGRIND_MAKE_MEM_UNDEFINED(p.plus_offset(sizeof(uint)),sizeof(uint)) p.head = size | pinuse - // C.VALGRIND_MAKE_MEM_UNDEFINED(p.plus_offset(size + sizeof(usize)),sizeof(usize)) + // C.VALGRIND_MAKE_MEM_UNDEFINED(p.plus_offset(size + sizeof(uint)),sizeof(uint)) p.plus_offset(size).head = top_foot_size() dl.trim_check = u32(default_trim_threshold()) } @[unsafe] -fn (mut dl Dlmalloc) sys_alloc(size usize) voidptr { +fn (mut dl Dlmalloc) sys_alloc(size uint) voidptr { page_size := dl.system_allocator.page_size(dl.system_allocator.data) asize := align_up(align_up(size + top_foot_size() + malloc_alignment(), default_granularity()), page_size) @@ -1106,7 +1106,7 @@ fn (mut dl Dlmalloc) sys_alloc(size usize) voidptr { dl.least_addr = dl.least_addr } sp = &dl.seg - for !isnil(sp) && sp.base != voidptr(usize(tbase) + tsize) { + for !isnil(sp) && sp.base != voidptr(uint(tbase) + tsize) { sp = sp.next } @@ -1138,7 +1138,7 @@ fn (mut dl Dlmalloc) sys_alloc(size usize) voidptr { } @[unsafe] -fn (mut dl Dlmalloc) tmalloc_small(size usize) voidptr { +fn (mut dl Dlmalloc) tmalloc_small(size uint) voidptr { unsafe { leastbit := least_bit(dl.treemap) i := bits.trailing_zeros_32(leastbit) @@ -1175,7 +1175,7 @@ fn (mut dl Dlmalloc) tmalloc_small(size usize) voidptr { } @[unsafe] -fn (mut dl Dlmalloc) tmalloc_large(size usize) voidptr { +fn (mut dl Dlmalloc) tmalloc_large(size uint) voidptr { unsafe { mut v := &TreeChunk(nil) mut rsize := ~size + 1 @@ -1195,7 +1195,7 @@ fn (mut dl Dlmalloc) tmalloc_large(size usize) voidptr { } rt := t.child[1] - t = t.child[int((sizebits >> (sizeof(usize) * 8 - 1)) & 1)] + t = t.child[int((sizebits >> (sizeof(uint) * 8 - 1)) & 1)] if !isnil(rt) && voidptr(rt) != voidptr(t) { rst = rt } @@ -1245,14 +1245,14 @@ fn (mut dl Dlmalloc) tmalloc_large(size usize) voidptr { } @[unsafe] -fn (mut dl Dlmalloc) prepend_alloc(newbase voidptr, oldbase voidptr, size usize) voidptr { +fn (mut dl Dlmalloc) prepend_alloc(newbase voidptr, oldbase voidptr, size uint) voidptr { unsafe { mut p := align_as_chunk(newbase) mut oldfirst := align_as_chunk(oldbase) - psize := usize(oldfirst) - usize(p) + psize := uint(oldfirst) - uint(p) mut q := p.plus_offset(size) mut qsize := psize - size - // C.VALGRIND_MAKE_MEM_UNDEFINED(p.plus_offset(sizeof(usize)),size) + // C.VALGRIND_MAKE_MEM_UNDEFINED(p.plus_offset(sizeof(uint)),size) p.set_size_and_pinuse_of_inuse_chunk(size) if qsize >= sizeof(TreeChunk) { @@ -1260,7 +1260,7 @@ fn (mut dl Dlmalloc) prepend_alloc(newbase voidptr, oldbase voidptr, size usize) } else { // C.VALGRIND_MAKE_MEM_UNDEFINED(q,sizeof(Chunk)) } - // C.VALGRIND_MAKE_MEM_UNDEFINED(q.plus_offset(qsize),sizeof(usize)) + // C.VALGRIND_MAKE_MEM_UNDEFINED(q.plus_offset(qsize),sizeof(uint)) if voidptr(oldfirst) == voidptr(dl.top) { dl.topsize += qsize @@ -1289,19 +1289,19 @@ fn (mut dl Dlmalloc) prepend_alloc(newbase voidptr, oldbase voidptr, size usize) } @[unsafe] -fn (mut dl Dlmalloc) add_segment(tbase voidptr, tsize usize, flags u32) { +fn (mut dl Dlmalloc) add_segment(tbase voidptr, tsize uint, flags u32) { // TODO: what in the world is this function doing???? unsafe { old_top := dl.top mut oldsp := dl.segment_holding(old_top) old_end := oldsp.top() ssize := pad_request(sizeof(Segment)) - mut offset := ssize + sizeof(usize) * 4 + malloc_alignment() - 1 - rawsp := voidptr(usize(old_end) - offset) + mut offset := ssize + sizeof(uint) * 4 + malloc_alignment() - 1 + rawsp := voidptr(uint(old_end) - offset) pmem := (&Chunk(rawsp)).to_mem() - offset = align_offset_usize(usize(pmem)) - asp := voidptr(usize(rawsp) + offset) - csp := if asp < voidptr(usize(old_top) + min_chunk_size()) { old_top } else { asp } + offset = align_offset_usize(uint(pmem)) + asp := voidptr(uint(rawsp) + offset) + csp := if asp < voidptr(uint(old_top) + min_chunk_size()) { old_top } else { asp } mut sp := &Chunk(csp) mut ss := &Segment(sp.to_mem()) mut tnext := sp.plus_offset(ssize) @@ -1319,7 +1319,7 @@ fn (mut dl Dlmalloc) add_segment(tbase voidptr, tsize usize, flags u32) { dl.seg.next = ss for { - nextp := p.plus_offset(sizeof(usize)) + nextp := p.plus_offset(sizeof(uint)) p.head = fencepost_head() nfences += 1 if voidptr(&nextp.head) < old_end { @@ -1332,7 +1332,7 @@ fn (mut dl Dlmalloc) add_segment(tbase voidptr, tsize usize, flags u32) { assert nfences >= 2 if voidptr(csp) != voidptr(old_top) { mut q := &Chunk(old_top) - psize := usize(csp) - usize(old_top) + psize := uint(csp) - uint(old_top) tn := q.plus_offset(psize) q.set_free_with_pinuse(psize, tn) @@ -1355,7 +1355,7 @@ fn (mut dl Dlmalloc) segment_holding(ptr voidptr) &Segment { // realloc behaves as libc realloc, but operates within the given space @[unsafe] -pub fn (mut dl Dlmalloc) realloc(oldmem voidptr, bytes usize) voidptr { +pub fn (mut dl Dlmalloc) realloc(oldmem voidptr, bytes uint) voidptr { if bytes >= dl.max_request { return unsafe { nil } } @@ -1382,7 +1382,7 @@ pub fn (mut dl Dlmalloc) realloc(oldmem voidptr, bytes usize) voidptr { // memaligns allocates memory aligned to `alignment_`. Only call this with power-of-two alignment // and alignment > dlmalloc.malloc_alignment @[unsafe] -pub fn (mut dl Dlmalloc) memalign(alignment_ usize, bytes usize) voidptr { +pub fn (mut dl Dlmalloc) memalign(alignment_ uint, bytes uint) voidptr { mut alignment := alignment_ if alignment < min_chunk_size() { alignment = min_chunk_size() @@ -1400,23 +1400,23 @@ pub fn (mut dl Dlmalloc) memalign(alignment_ usize, bytes usize) voidptr { } mut p := chunk_from_mem(mem) - if usize(mem) & (alignment - 1) != 0 { + if uint(mem) & (alignment - 1) != 0 { // Here we find an aligned sopt inside the chunk. Since we need to // give back leading space in a chunk of at least `min_chunk_size`, // if the first calculation places us at a spot with less than // `min_chunk_size` leader we can move to the next aligned spot. // we've allocated enough total room so that this is always possible - br_ := (usize(mem) + alignment - 1) & (~alignment + 1) + br_ := (uint(mem) + alignment - 1) & (~alignment + 1) br := chunk_from_mem(voidptr(br_)) mut pos := voidptr(u64(0)) - if usize(br) - usize(p) > min_chunk_size() { + if uint(br) - uint(p) > min_chunk_size() { pos = voidptr(br) } else { - pos = voidptr(usize(br) + alignment) + pos = voidptr(uint(br) + alignment) } mut newp := &Chunk(pos) - leadsize := usize(pos) - usize(p) + leadsize := uint(pos) - uint(p) newsize := p.size() - leadsize if p.mmapped() { @@ -1447,7 +1447,7 @@ pub fn (mut dl Dlmalloc) memalign(alignment_ usize, bytes usize) voidptr { } @[unsafe] -fn (mut dl Dlmalloc) try_realloc_chunk(p_ &Chunk, nb usize, can_move bool) &Chunk { +fn (mut dl Dlmalloc) try_realloc_chunk(p_ &Chunk, nb uint, can_move bool) &Chunk { unsafe { mut p := p_ oldsize := p.size() @@ -1522,32 +1522,32 @@ fn (mut dl Dlmalloc) try_realloc_chunk(p_ &Chunk, nb usize, can_move bool) &Chun } @[unsafe] -fn (mut dl Dlmalloc) mmap_resize(oldp_ &Chunk, nb usize, can_move bool) &Chunk { +fn (mut dl Dlmalloc) mmap_resize(oldp_ &Chunk, nb uint, can_move bool) &Chunk { mut oldp := unsafe { oldp_ } oldsize := oldp.size() if is_small(nb) { return unsafe { nil } } // Keep the old chunk if it's big enough but not too big - if oldsize >= nb + sizeof(usize) && (oldsize - nb) <= (default_granularity() << 1) { + if oldsize >= nb + sizeof(uint) && (oldsize - nb) <= (default_granularity() << 1) { return oldp } offset := oldp.prev_foot oldmmsize := oldsize + offset + mmap_foot_pad() - newmmsize := dl.mmap_align(nb + 6 * sizeof(usize) + malloc_alignment() - 1) + newmmsize := dl.mmap_align(nb + 6 * sizeof(uint) + malloc_alignment() - 1) - ptr := dl.system_allocator.remap(dl.system_allocator.data, voidptr(usize(oldp) - offset), + ptr := dl.system_allocator.remap(dl.system_allocator.data, voidptr(uint(oldp) - offset), oldmmsize, newmmsize, can_move) if isnil(ptr) { return unsafe { nil } } - mut newp := unsafe { &Chunk(voidptr(usize(ptr) + offset)) } + mut newp := unsafe { &Chunk(voidptr(uint(ptr) + offset)) } psize := newmmsize - offset - mmap_foot_pad() newp.head = psize newp.plus_offset(psize).head = fencepost_head() - newp.plus_offset(psize + sizeof(usize)).head = 0 + newp.plus_offset(psize + sizeof(uint)).head = 0 if ptr < dl.least_addr { dl.least_addr = ptr } @@ -1558,12 +1558,12 @@ fn (mut dl Dlmalloc) mmap_resize(oldp_ &Chunk, nb usize, can_move bool) &Chunk { return newp } -fn (dl &Dlmalloc) mmap_align(a usize) usize { +fn (dl &Dlmalloc) mmap_align(a uint) uint { return align_up(a, dl.system_allocator.page_size(dl.system_allocator.data)) } @[unsafe] -fn (mut dl Dlmalloc) dispose_chunk(p_ &Chunk, psize_ usize) { +fn (mut dl Dlmalloc) dispose_chunk(p_ &Chunk, psize_ uint) { mut p := unsafe { p_ } mut psize := psize_ unsafe { @@ -1574,7 +1574,7 @@ fn (mut dl Dlmalloc) dispose_chunk(p_ &Chunk, psize_ usize) { psize += prevsize + mmap_foot_pad() if dl.system_allocator.free_(dl.system_allocator.data, - voidptr(usize(p) - prevsize), psize) + voidptr(uint(p) - prevsize), psize) { dl.footprint -= psize } diff --git a/vlib/dlmalloc/dlmalloc_sys_nix.c.v b/vlib/dlmalloc/dlmalloc_sys_nix.c.v index a7ab300090..21601a73de 100644 --- a/vlib/dlmalloc/dlmalloc_sys_nix.c.v +++ b/vlib/dlmalloc/dlmalloc_sys_nix.c.v @@ -5,8 +5,8 @@ $if !freestanding { #include } -fn C.munmap(ptr voidptr, size usize) i32 -fn C.mmap(base voidptr, len usize, prot i32, flags i32, fd i32, offset i64) voidptr +fn C.munmap(ptr voidptr, size uint) i32 +fn C.mmap(base voidptr, len uint, prot i32, flags i32, fd i32, offset i64) voidptr // Mm_prot and Map_flags hold the Linux values. `system_alloc` uses the C // constants of the target platform instead: `MAP_ANONYMOUS` differs between @@ -32,7 +32,7 @@ pub enum Map_flags { map_huge_mask = 0x3f } -fn system_alloc(_ voidptr, size usize) (voidptr, usize, u32) { +fn system_alloc(_ voidptr, size uint) (voidptr, uint, u32) { $if !freestanding { unsafe { addr := C.mmap(nil, size, C.PROT_READ | C.PROT_WRITE, C.MAP_PRIVATE | C.MAP_ANONYMOUS, @@ -50,22 +50,22 @@ fn system_alloc(_ voidptr, size usize) (voidptr, usize, u32) { return unsafe { nil }, 0, 0 } -fn system_remap(_ voidptr, ptr voidptr, oldsize usize, newsize usize, can_move bool) voidptr { +fn system_remap(_ voidptr, ptr voidptr, oldsize uint, newsize uint, can_move bool) voidptr { return unsafe { nil } } -fn system_free_part(_ voidptr, ptr voidptr, oldsize usize, newsize usize) bool { +fn system_free_part(_ voidptr, ptr voidptr, oldsize uint, newsize uint) bool { $if !freestanding { // Unmapping the tail shrinks the mapping in place, like `mremap` without // MREMAP_MAYMOVE would, but needs no GNU-only declaration. unsafe { - return C.munmap(voidptr(usize(ptr) + newsize), oldsize - newsize) == 0 + return C.munmap(voidptr(uint(ptr) + newsize), oldsize - newsize) == 0 } } return false } -fn system_free(_ voidptr, ptr voidptr, size usize) bool { +fn system_free(_ voidptr, ptr voidptr, size uint) bool { $if !freestanding { unsafe { return C.munmap(ptr, size) == 0 @@ -83,7 +83,7 @@ fn system_allocates_zeros(_ voidptr) bool { return true } -fn system_page_size(_ voidptr) usize { +fn system_page_size(_ voidptr) uint { return 4096 } diff --git a/vlib/dlmalloc/dlmalloc_sys_windows.c.v b/vlib/dlmalloc/dlmalloc_sys_windows.c.v index 637012b6ad..a7e708b077 100644 --- a/vlib/dlmalloc/dlmalloc_sys_windows.c.v +++ b/vlib/dlmalloc/dlmalloc_sys_windows.c.v @@ -1,18 +1,18 @@ module dlmalloc -fn system_alloc(_ voidptr, size usize) (voidptr, usize, u32) { +fn system_alloc(_ voidptr, size uint) (voidptr, uint, u32) { return unsafe { nil }, 0, 0 } -fn system_remap(_ voidptr, ptr voidptr, oldsize usize, newsize usize, can_move bool) voidptr { +fn system_remap(_ voidptr, ptr voidptr, oldsize uint, newsize uint, can_move bool) voidptr { return unsafe { nil } } -fn system_free_part(_ voidptr, ptr voidptr, oldsize usize, newsize usize) bool { +fn system_free_part(_ voidptr, ptr voidptr, oldsize uint, newsize uint) bool { return false } -fn system_free(_ voidptr, ptr voidptr, size usize) bool { +fn system_free(_ voidptr, ptr voidptr, size uint) bool { return false } @@ -24,7 +24,7 @@ fn system_allocates_zeros(_ voidptr) bool { return false } -fn system_page_size(_ voidptr) usize { +fn system_page_size(_ voidptr) uint { return 4096 } diff --git a/vlib/dlmalloc/dlmalloc_test.v b/vlib/dlmalloc/dlmalloc_test.v index 7f2e50c99d..d5c26cd09c 100644 --- a/vlib/dlmalloc/dlmalloc_test.v +++ b/vlib/dlmalloc/dlmalloc_test.v @@ -18,10 +18,10 @@ fn test_left_bits_sets_every_bit_above_the_given_one() { } fn test_chunk_prev_steps_back_by_prev_foot() { - mut buf := [8]usize{} + mut buf := [8]uint{} unsafe { mut c := &Chunk(&buf[4]) - c.prev_foot = 2 * sizeof(usize) + c.prev_foot = 2 * sizeof(uint) assert voidptr(c.prev()) == voidptr(&buf[2]) } } @@ -29,7 +29,7 @@ fn test_chunk_prev_steps_back_by_prev_foot() { fn test_tree_bins_keep_chunks_reachable_by_their_size_bits() { mut dl := new(get_system_allocator()) // All of these sizes share one tree bin (768..1023 bytes). - sizes := [usize(0x300), 0x3f0, 0x380, 0x340, 0x3c0, 0x310, 0x3a0, 0x3e0] + sizes := [uint(0x300), 0x3f0, 0x380, 0x340, 0x3c0, 0x310, 0x3a0, 0x3e0] mut chunks := []TreeChunk{len: sizes.len} idx := dl.compute_tree_index(sizes[0]) unsafe { @@ -43,7 +43,7 @@ fn test_tree_bins_keep_chunks_reachable_by_their_size_bits() { mut t := *dl.treebin_at(idx) mut size_bits := size << leftshift_for_tree_index(idx) for !isnil(t) && t.chunk().size() != size { - t = t.child[int((size_bits >> (sizeof(usize) * 8 - 1)) & 1)] + t = t.child[int((size_bits >> (sizeof(uint) * 8 - 1)) & 1)] size_bits <<= 1 } assert voidptr(t) == voidptr(&chunks[i]) @@ -66,7 +66,7 @@ fn test_global_allocator_round_trip() { unsafe { p := &u8(malloc(100)) assert !isnil(p) - assert usize(p) % malloc_alignment() == 0 + assert uint(p) % malloc_alignment() == 0 for i in 0 .. 100 { p[i] = u8(i) } @@ -82,7 +82,7 @@ fn test_global_allocator_round_trip() { } a := memalign(1000, 256) assert !isnil(a) - assert usize(a) % 256 == 0 + assert uint(a) % 256 == 0 free(a) free(z) free(q) @@ -115,7 +115,7 @@ fn test_realloc_releases_the_old_block_when_it_moves() { p := dl.malloc(20_000) blocker := dl.malloc(16) // On a fresh heap `blocker` directly follows `p`, so `p` cannot grow in place. - assert usize(blocker) == usize(p) + chunk_from_mem(p).size() + assert uint(blocker) == uint(p) + chunk_from_mem(p).size() q := dl.realloc(p, 40_000) assert !isnil(q) assert q != p @@ -130,7 +130,7 @@ fn test_realloc_releases_the_old_block_when_it_moves() { struct Block { mut: ptr &u8 = unsafe { nil } - size usize + size uint seed u8 } @@ -146,28 +146,28 @@ fn (mut r Rng) next() u32 { return r.state } -fn (mut r Rng) size(max_huge usize) usize { +fn (mut r Rng) size(max_huge uint) uint { kind := r.next() % 16 return if kind < 9 { // small bins, up to just above `max_small_request` - usize(1 + r.next() % 248) + uint(1 + r.next() % 248) } else if kind < 14 { // tree bins - usize(233 + r.next() % 16_000) + uint(233 + r.next() % 16_000) } else if kind < 15 { - usize(16_000 + r.next() % 200_000) + uint(16_000 + r.next() % 200_000) } else { - usize(1 + r.next() % u32(max_huge)) + uint(1 + r.next() % u32(max_huge)) } } -fn pattern(seed u8, i usize) u8 { - return u8(usize(seed) * 7 + i * 13 + (i >> 9)) +fn pattern(seed u8, i uint) u8 { + return u8(uint(seed) * 7 + i * 13 + (i >> 9)) } // next_sample visits every byte near the ends of a block, and one byte per KiB // in between, so that big blocks stay cheap to fill and check. -fn next_sample(i usize, n usize) usize { +fn next_sample(i uint, n uint) uint { if i < 64 || i + 64 >= n { return i + 1 } @@ -176,7 +176,7 @@ fn next_sample(i usize, n usize) usize { } fn fill(b Block) { - mut i := usize(0) + mut i := uint(0) for i < b.size { unsafe { b.ptr[i] = pattern(b.seed, i) @@ -186,8 +186,8 @@ fn fill(b Block) { } // check verifies the first `n` bytes of `b`, sampled as `fill` wrote them. -fn check(b Block, n usize) { - mut i := usize(0) +fn check(b Block, n uint) { + mut i := uint(0) for i < n { got := unsafe { b.ptr[i] } if got != pattern(b.seed, i) { @@ -197,25 +197,25 @@ fn check(b Block, n usize) { } } -fn check_new_block(blocks []Block, idx int, b Block, align usize) { +fn check_new_block(blocks []Block, idx int, b Block, align uint) { assert !isnil(b.ptr), 'allocation of ${b.size} bytes failed' - assert usize(b.ptr) % align == 0 + assert uint(b.ptr) % align == 0 c := chunk_from_mem(b.ptr) assert c.cinuse() assert c.size() >= b.size + chunk_overhead() assert c.next().pinuse() - lo := usize(b.ptr) + lo := uint(b.ptr) hi := lo + b.size for j, other in blocks { if j == idx || isnil(other.ptr) { continue } - olo := usize(other.ptr) + olo := uint(other.ptr) assert hi <= olo || olo + other.size <= lo, 'blocks overlap' } } -fn stress(mut dl Dlmalloc, rounds int, seed u32, max_huge usize) { +fn stress(mut dl Dlmalloc, rounds int, seed u32, max_huge uint) { mut rng := Rng{seed} mut blocks := []Block{len: 256} for round in 0 .. rounds { @@ -233,7 +233,7 @@ fn stress(mut dl Dlmalloc, rounds int, seed u32, max_huge usize) { assert b.ptr[i] == 0 } } else if op == 1 { - align = usize(32) << (rng.next() % 8) + align = uint(32) << (rng.next() % 8) b.ptr = dl.memalign(align, b.size) } else { b.ptr = dl.malloc(b.size) @@ -274,17 +274,17 @@ fn stress(mut dl Dlmalloc, rounds int, seed u32, max_huge usize) { struct TestArena { mut: buf []u8 - start usize - end usize - lo usize - hi usize + start uint + end uint + lo uint + hi uint calls int } -fn new_test_arena(size usize) &TestArena { +fn new_test_arena(size uint) &TestArena { buf := []u8{len: int(size)} - start := align_up(usize(buf.data), default_granularity()) - end := usize(buf.data) + size + start := align_up(uint(buf.data), default_granularity()) + end := uint(buf.data) + size middle := align_up(start + (end - start) / 2, default_granularity()) return &TestArena{ buf: buf @@ -316,10 +316,10 @@ fn (mut a TestArena) release() { unsafe { a.buf.free() } } -fn arena_alloc(data voidptr, size usize) (voidptr, usize, u32) { +fn arena_alloc(data voidptr, size uint) (voidptr, uint, u32) { mut a := unsafe { &TestArena(data) } a.calls++ - mut addr := usize(0) + mut addr := uint(0) match a.calls % 3 { 1 { // directly above the highest region @@ -347,12 +347,12 @@ fn arena_alloc(data voidptr, size usize) (voidptr, usize, u32) { // Released memory stays readable, so it is overwritten to make any later use // of it by the allocator visible. -fn arena_free(_ voidptr, ptr voidptr, size usize) bool { +fn arena_free(_ voidptr, ptr voidptr, size uint) bool { unsafe { vmemset(ptr, 0xa5, int(size)) } return true } -fn arena_free_part(_ voidptr, ptr voidptr, oldsize usize, newsize usize) bool { - unsafe { vmemset(voidptr(usize(ptr) + newsize), 0xa5, int(oldsize - newsize)) } +fn arena_free_part(_ voidptr, ptr voidptr, oldsize uint, newsize uint) bool { + unsafe { vmemset(voidptr(uint(ptr) + newsize), 0xa5, int(oldsize - newsize)) } return true } diff --git a/vlib/dlmalloc/global.v b/vlib/dlmalloc/global.v index 390d5f201f..a7317d8616 100644 --- a/vlib/dlmalloc/global.v +++ b/vlib/dlmalloc/global.v @@ -7,7 +7,7 @@ __global global = new(get_system_allocator()) // It returns a null pointer if allocation fails. // It returns a valid pointer otherwise. @[unsafe] -pub fn malloc(size usize) voidptr { +pub fn malloc(size uint) voidptr { unsafe { return global.malloc(size) } @@ -24,7 +24,7 @@ pub fn free(ptr voidptr) { // Same as `malloc`, except if the allocation succeeds it's guaranteed to // point to `size` bytes of zeros. @[unsafe] -pub fn calloc(size usize) voidptr { +pub fn calloc(size uint) voidptr { unsafe { return global.calloc(size) } @@ -38,7 +38,7 @@ pub fn calloc(size usize) voidptr { // is still valid. Returns a valid pointer and frees `ptr` if the request // is satisfied. @[unsafe] -pub fn realloc(ptr voidptr, oldsize usize, newsize usize) voidptr { +pub fn realloc(ptr voidptr, oldsize uint, newsize uint) voidptr { unsafe { _ := oldsize @@ -51,7 +51,7 @@ pub fn realloc(ptr voidptr, oldsize usize, newsize usize) voidptr { // // Returns a null pointer if allocation fails. Returns a valid pointer otherwise. @[unsafe] -pub fn memalign(size usize, align usize) voidptr { +pub fn memalign(size uint, align uint) voidptr { unsafe { if align <= malloc_alignment() { return global.malloc(size) diff --git a/vlib/encoding/binary/serialize.v b/vlib/encoding/binary/serialize.v index 0677ec7fa5..fb0e98197c 100644 --- a/vlib/encoding/binary/serialize.v +++ b/vlib/encoding/binary/serialize.v @@ -127,14 +127,8 @@ fn encode_primitive[T](mut s EncodeState, value T) ! { s.put_u8(u8(value)) } $else $if T is rune { s.put_u32(u32(value)) - } $else $if T is isize { - if sizeof(isize) == 4 { - s.put_u32(u32(value)) - } else { - s.put_u64(u64(value)) - } - } $else $if T is usize { - if sizeof(usize) == 4 { + } $else $if T is isize || T is uint { + if sizeof(T) == 4 { s.put_u32(u32(value)) } else { s.put_u64(u64(value)) @@ -313,14 +307,8 @@ fn decode_primitive[T](mut s DecodeState, value T) !T { return s.get_u8()! != 0 } $else $if T is rune { return T(s.get_u32()!) - } $else $if T is isize { - if sizeof(isize) == 4 { - return T(s.get_u32()!) - } else { - return T(s.get_u64()!) - } - } $else $if T is usize { - if sizeof(usize) == 4 { + } $else $if T is isize || T is uint { + if sizeof(T) == 4 { return T(s.get_u32()!) } else { return T(s.get_u64()!) @@ -375,27 +363,6 @@ fn decode_string(mut s DecodeState) !string { return str } -// `Any` is a sum type that lists the possible types to be decoded and used. -type Any = int - | bool - | f64 - | f32 - | i64 - | i32 - | i16 - | i8 - | map[string]Any - | map[int]Any - | string - | u64 - | u32 - | u16 - | u8 - | rune - | isize - | usize - | []Any - fn decode_map[K, V](mut s DecodeState, _ map[K]V) !map[K]V { len := int(s.get_u64()!) if len <= 0 || s.offset + len > s.b.len { @@ -407,7 +374,7 @@ fn decode_map[K, V](mut s DecodeState, _ map[K]V) !map[K]V { for _ in 0 .. len { // decode key first // Maps can have keys of type string, rune, integer, float or voidptr. - mut k := Any(0) + mut k := K{} $if K is $string { k = decode_string(mut s)! } $else { @@ -417,16 +384,16 @@ fn decode_map[K, V](mut s DecodeState, _ map[K]V) !map[K]V { // decode value $if V is $struct { v := decode_struct(mut s, V{})! - m[k as K] = v + m[k] = v } $else $if V is $map { v := decode_map(mut s, V{})! - m[k as K] = v + m[k] = v } $else $if V is $string { v := decode_string(mut s)! - m[k as K] = v + m[k] = v } $else { v := decode_primitive(mut s, unsafe { V(0) })! - m[k as K] = v + m[k] = v } } return m diff --git a/vlib/encoding/binary/serialize_test.v b/vlib/encoding/binary/serialize_test.v index 350859a9f7..7fc4376583 100644 --- a/vlib/encoding/binary/serialize_test.v +++ b/vlib/encoding/binary/serialize_test.v @@ -14,8 +14,8 @@ fn test_encode_decode_primitive_string() ! { a_f64 := f64(-32144.3133) a_bool := bool(true) a_rune := `♥` - a_isize := isize(-45433) - a_usize := usize(432211) + a_isize := int(-45433) + a_usize := uint(432211) a_string := '♥🖊dsser333100' b_u8 := encode_binary(a_u8)! @@ -48,8 +48,8 @@ fn test_encode_decode_primitive_string() ! { c_f64 := decode_binary[f64](b_f64)! c_bool := decode_binary[bool](b_bool)! c_rune := decode_binary[rune](b_rune)! - c_isize := decode_binary[isize](b_isize)! - c_usize := decode_binary[usize](b_usize)! + c_isize := decode_binary[int](b_isize)! + c_usize := decode_binary[uint](b_usize)! c_string := decode_binary[string](b_string)! assert a_u8 == c_u8 @@ -84,11 +84,10 @@ fn test_encode_decode_primitive_string() ! { assert b_rune == [u8(101), 38, 0, 0] assert b_string == [u8(18), 0, 0, 0, 0, 0, 0, 0, 226, 153, 165, 240, 159, 150, 138, 100, 115, 115, 101, 114, 51, 51, 51, 49, 48, 48] - $if x64 { - assert b_isize == [u8(135), 78, 255, 255, 255, 255, 255, 255] + assert b_isize == [u8(135), 78, 255, 255, 255, 255, 255, 255] + if sizeof(uint) == 8 { assert b_usize == [u8(83), 152, 6, 0, 0, 0, 0, 0] - } $else { - assert b_isize == [u8(135), 78, 255, 255] + } else { assert b_usize == [u8(83), 152, 6, 0] } } @@ -107,8 +106,8 @@ fn test_encode_decode_array() { a_f64 := [f64(-32144.3133), 432e-13] a_bool := [bool(true), false] a_rune := [`♥`, `🖊`] - a_isize := [isize(-45433), 24342] - a_usize := [usize(432211), 888533] + a_isize := [int(-45433), 24342] + a_usize := [uint(432211), 888533] a_string := ['♥', '🖊', 'dfd21'] b_u8 := encode_binary(a_u8)! @@ -141,8 +140,8 @@ fn test_encode_decode_array() { c_f64 := decode_binary[[]f64](b_f64)! c_bool := decode_binary[[]bool](b_bool)! c_rune := decode_binary[[]rune](b_rune)! - c_isize := decode_binary[[]isize](b_isize)! - c_usize := decode_binary[[]usize](b_usize)! + c_isize := decode_binary[[]int](b_isize)! + c_usize := decode_binary[[]uint](b_usize)! c_string := decode_binary[[]string](b_string)! assert a_u8 == c_u8 @@ -181,13 +180,12 @@ fn test_encode_decode_array() { assert b_rune == [u8(2), 0, 0, 0, 0, 0, 0, 0, 101, 38, 0, 0, 138, 245, 1, 0] assert b_string == [u8(3), 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 226, 153, 165, 4, 0, 0, 0, 0, 0, 0, 0, 240, 159, 150, 138, 5, 0, 0, 0, 0, 0, 0, 0, 100, 102, 100, 50, 49] - $if x64 { - assert b_isize == [u8(2), 0, 0, 0, 0, 0, 0, 0, 135, 78, 255, 255, 255, 255, 255, 255, 22, - 95, 0, 0, 0, 0, 0, 0] + assert b_isize == [u8(2), 0, 0, 0, 0, 0, 0, 0, 135, 78, 255, 255, 255, 255, 255, 255, 22, 95, + 0, 0, 0, 0, 0, 0] + if sizeof(uint) == 8 { assert b_usize == [u8(2), 0, 0, 0, 0, 0, 0, 0, 83, 152, 6, 0, 0, 0, 0, 0, 213, 142, 13, 0, 0, 0, 0, 0] - } $else { - assert b_isize == [u8(2), 0, 0, 0, 0, 0, 0, 0, 135, 78, 255, 255, 22, 95, 0, 0] + } else { assert b_usize == [u8(2), 0, 0, 0, 0, 0, 0, 0, 83, 152, 6, 0, 213, 142, 13, 0] } } @@ -240,10 +238,10 @@ fn test_encode_decode_map() { 'abc': `♥` } a_map_string_isize := { - 'abc': isize(-45433) + 'abc': int(-45433) } a_map_string_usize := { - 'abc': usize(432211) + 'abc': uint(432211) } a_map_string_struct := { @@ -282,8 +280,8 @@ fn test_encode_decode_map() { c_map_string_f64 := decode_binary[map[string]f64](b_map_string_f64)! c_map_string_bool := decode_binary[map[string]bool](b_map_string_bool)! c_map_string_rune := decode_binary[map[string]rune](b_map_string_rune)! - c_map_string_isize := decode_binary[map[string]isize](b_map_string_isize)! - c_map_string_usize := decode_binary[map[string]usize](b_map_string_usize)! + c_map_string_isize := decode_binary[map[string]int](b_map_string_isize)! + c_map_string_usize := decode_binary[map[string]uint](b_map_string_usize)! c_map_string_struct := decode_binary[map[string]St](b_map_string_struct)! assert a_map_string_string == c_map_string_string @@ -332,14 +330,12 @@ fn test_encode_decode_map() { 1] assert b_map_string_rune == [u8(1), 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 97, 98, 99, 101, 38, 0, 0] - $if x64 { - assert b_map_string_isize == [u8(1), 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 97, 98, - 99, 135, 78, 255, 255, 255, 255, 255, 255] + assert b_map_string_isize == [u8(1), 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 97, 98, 99, + 135, 78, 255, 255, 255, 255, 255, 255] + if sizeof(uint) == 8 { assert b_map_string_usize == [u8(1), 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 97, 98, 99, 83, 152, 6, 0, 0, 0, 0, 0] - } $else { - assert b_map_string_isize == [u8(1), 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 97, 98, - 99, 135, 78, 255, 255] + } else { assert b_map_string_usize == [u8(1), 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 97, 98, 99, 83, 152, 6, 0] } @@ -361,8 +357,8 @@ struct MyStruct { f_f64 f64 f_bool bool f_rune rune - f_isize isize - f_usize usize + f_isize int + f_usize uint f_string string f_array_u8 []u8 f_array_string []string @@ -383,8 +379,8 @@ fn test_encode_decode_struct() { f_f64: f64(22421.32) f_bool: bool(true) f_rune: rune(`♥`) - f_isize: isize(42323) - f_usize: usize(83842) + f_isize: int(42323) + f_usize: uint(83842) f_string: 'fds♥323s' f_array_u8: [u8(32), 22, 55, 72] f_array_string: ['dfdss', 'dfsd3', '54344'] @@ -411,8 +407,8 @@ mut: f_f64 f64 f_bool bool f_rune rune - f_isize isize - f_usize usize + f_isize int + f_usize uint f_string string f_array_u8 []u8 @[serialize: '-'] f_array_string []string @@ -433,8 +429,8 @@ fn test_encode_decode_struct_skip_fields() { f_f64: f64(22421.32) f_bool: bool(true) f_rune: rune(`♥`) - f_isize: isize(42323) - f_usize: usize(83842) + f_isize: int(42323) + f_usize: uint(83842) f_string: 'fds♥323s' f_array_u8: [u8(32), 22, 55, 72] f_array_string: ['dfdss', 'dfsd3', '54344'] @@ -480,8 +476,8 @@ fn test_encode_decode_complex() { f_f64: f64(22421.32) f_bool: bool(true) f_rune: rune(`♥`) - f_isize: isize(42323) - f_usize: usize(83842) + f_isize: int(42323) + f_usize: uint(83842) f_string: 'fds♥323s' f_array_u8: [u8(32), 22, 55, 72] f_array_string: ['dfdss', 'dfsd3', '54344'] @@ -500,8 +496,8 @@ fn test_encode_decode_complex() { f_f64: f64(32421.32) f_bool: bool(true) f_rune: rune(`♥`) - f_isize: isize(52323) - f_usize: usize(93842) + f_isize: int(52323) + f_usize: uint(93842) f_string: 'ads♥323s' f_array_u8: [u8(22), 22, 55, 72] f_array_string: ['dxfdss', 'dsefsd3', 'po54344'] @@ -558,3 +554,22 @@ fn test_skip_shared_field() { c: 200 }' } + +fn test_legacy_signed_encoding_preserves_wire_width() ! { + value := isize(-42) + for use_big_endian in [false, true] { + bytes := encode_binary(value, big_endian: use_big_endian)! + assert bytes.len == int(sizeof(isize)) + assert decode_binary[isize](bytes, big_endian: use_big_endian)! == value + values := [value, isize(123)] + assert decode_binary[[]isize](encode_binary(values, big_endian: use_big_endian)!, + big_endian: use_big_endian + )! == values + mapping := { + value: isize(123) + } + assert decode_binary[map[isize]isize](encode_binary(mapping, big_endian: use_big_endian)!, + big_endian: use_big_endian + )! == mapping + } +} diff --git a/vlib/encoding/csv/csv_reader_random_access.v b/vlib/encoding/csv/csv_reader_random_access.v index 71a1d9f9d8..517d5035ca 100644 --- a/vlib/encoding/csv/csv_reader_random_access.v +++ b/vlib/encoding/csv/csv_reader_random_access.v @@ -431,14 +431,14 @@ pub fn (mut cr RandomAccessReader) get_cell(cfg GetCellConfig) !string { } // create the string from the buffer - mut tmp_mem := malloc_noscan(isize(len + 1)) + mut tmp_mem := malloc_noscan(int(len + 1)) /* defer { free(tmp_mem) } */ mem_start := &u8(cr.mem_buf) + start - cr.start_index - vmemcpy(tmp_mem, mem_start, isize(len)) + vmemcpy(tmp_mem, mem_start, int(len)) tmp_mem[len] = 0 // 0 for C string compatibility ret_str := tos(tmp_mem, int(len)) return ret_str diff --git a/vlib/encoding/iconv/iconv_nix.c.v b/vlib/encoding/iconv/iconv_nix.c.v index 12b902acef..8d40cd2cb3 100644 --- a/vlib/encoding/iconv/iconv_nix.c.v +++ b/vlib/encoding/iconv/iconv_nix.c.v @@ -13,7 +13,7 @@ module iconv fn C.iconv_open(tocode charptr, fromcode charptr) voidptr fn C.iconv_close(cd voidptr) i32 -fn C.iconv(cd voidptr, inbuf &charptr, inbytesleft &usize, outbuf &charptr, outbytesleft &usize) usize +fn C.iconv(cd voidptr, inbuf &charptr, inbytesleft &uint, outbuf &charptr, outbytesleft &uint) uint // conv convert `fromcode` encoding string to `tocode` encoding string @[direct_array_access] @@ -43,7 +43,7 @@ fn conv(tocode string, fromcode string, src &u8, src_len int) ![]u8 { } mut cd := C.iconv_open(charptr(dst_encoding.str), charptr(src_encoding.str)) - if isize(cd) == -1 { + if int(cd) == -1 { return error("platform can't convert from ${src_encoding} to ${dst_encoding}") } defer { C.iconv_close(cd) } @@ -52,10 +52,10 @@ fn conv(tocode string, fromcode string, src &u8, src_len int) ![]u8 { mut src_ptr := charptr(src) mut dst_ptr := charptr(dst.data) - mut src_left := usize(src_len) - mut dst_left := usize(dst.len) + mut src_left := uint(src_len) + mut dst_left := uint(dst.len) res := C.iconv(cd, &src_ptr, &src_left, &dst_ptr, &dst_left) - if res == usize(-1) { + if res == uint(-1) { return error('convert encoding string fail, iconv return ${res}') } diff --git a/vlib/fasthttp/fasthttp.v b/vlib/fasthttp/fasthttp.v index 934625c007..f40b0df45b 100644 --- a/vlib/fasthttp/fasthttp.v +++ b/vlib/fasthttp/fasthttp.v @@ -41,7 +41,7 @@ pub mut: header_fields Slice body Slice client_conn_fd int - client_conn_handle usize + client_conn_handle uint user_data voidptr // User-defined context data (shared, set from ServerConfig.user_data) // worker_state is the value ServerConfig.make_state returned on THIS worker // thread (nil when no make_state is configured). It is thread-local by diff --git a/vlib/fasthttp/fasthttp_bsd.c.v b/vlib/fasthttp/fasthttp_bsd.c.v index 53d6a40730..c8d3a2213e 100644 --- a/vlib/fasthttp/fasthttp_bsd.c.v +++ b/vlib/fasthttp/fasthttp_bsd.c.v @@ -30,9 +30,9 @@ fn C.socket(domain i32, typ i32, protocol i32) i32 fn C.bind(sockfd i32, addr voidptr, addrlen u32) i32 -fn C.send(__fd i32, __buf voidptr, __n usize, __flags i32) i32 +fn C.send(__fd i32, __buf voidptr, __n uint, __flags i32) i32 -fn C.recv(__fd i32, __buf voidptr, __n usize, __flags i32) i32 +fn C.recv(__fd i32, __buf voidptr, __n uint, __flags i32) i32 fn C.setsockopt(__fd i32, __level i32, __optname i32, __optval voidptr, __optlen u32) i32 @@ -100,21 +100,21 @@ fn send_file_bytes(file_fd i32, sock_fd i32, offset i64, nbytes i64) (int, i64) if want > sendfile_fallback_buf_size { want = sendfile_fallback_buf_size } - nread := C.pread(file_fd, &buf[0], usize(want), offset) + nread := C.pread(file_fd, &buf[0], uint(want), offset) if nread <= 0 { // nread == 0 is EOF (shouldn't happen given write_pos < file_len // guards in send_pending, but treat it as an error to close the // connection); nread < 0 propagates errno for EAGAIN handling. return -1, i64(0) } - nsent := C.send(sock_fd, &buf[0], usize(nread), send_flags) + nsent := C.send(sock_fd, &buf[0], uint(nread), send_flags) if nsent < 0 { return -1, i64(0) } return 0, i64(nsent) } $else { mut sbytes := i64(0) - ret := C.sendfile(file_fd, sock_fd, offset, usize(nbytes), unsafe { nil }, &sbytes, 0) + ret := C.sendfile(file_fd, sock_fd, offset, uint(nbytes), unsafe { nil }, &sbytes, 0) return int(ret), sbytes } } @@ -125,11 +125,11 @@ $if macos { } $else $if openbsd { // ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset); - fn C.pread(fd i32, buf voidptr, nbyte usize, offset i64) isize + fn C.pread(fd i32, buf voidptr, nbyte uint, offset i64) C.ptrdiff_t } $else { // int sendfile(int fd, int s, off_t offset, size_t nbytes, struct sf_hdtr *hdtr, off_t *sbytes, int flags); - fn C.sendfile(fd i32, s i32, offset i64, nbytes usize, hdtr voidptr, sbytes &i64, flags i32) i32 + fn C.sendfile(fd i32, s i32, offset i64, nbytes uint, hdtr voidptr, sbytes &i64, flags i32) i32 } struct C.kevent { @@ -137,12 +137,12 @@ struct C.kevent { filter i16 flags u16 fflags u32 - data isize + data int udata voidptr } // Helper to set fields of a kevent struct. -fn ev_set(mut ev C.kevent, ident u64, filter i16, flags u16, fflags u32, data isize, udata voidptr) { +fn ev_set(mut ev C.kevent, ident u64, filter i16, flags u16, fflags u32, data int, udata voidptr) { ev.ident = ident ev.filter = filter ev.flags = flags @@ -289,13 +289,13 @@ fn set_nonblocking(fd int) { fn add_event(kq int, ident u64, filter i16, flags u16, udata voidptr) int { mut ev := C.kevent{} - ev_set(mut &ev, ident, filter, flags, u32(0), isize(0), udata) + ev_set(mut &ev, ident, filter, flags, u32(0), int(0), udata) return C.kevent(kq, &ev, 1, unsafe { nil }, 0, unsafe { nil }) } fn delete_event(kq int, ident u64, filter i16, udata voidptr) { mut ev := C.kevent{} - ev_set(mut &ev, ident, filter, u16(C.EV_DELETE), u32(0), isize(0), udata) + ev_set(mut &ev, ident, filter, u16(C.EV_DELETE), u32(0), int(0), udata) C.kevent(kq, &ev, 1, unsafe { nil }, 0, unsafe { nil }) } @@ -445,7 +445,7 @@ fn process_request(server &Server, kq int, c_ptr voidptr, frame_total int, mut c server.begin_request() c.request_active = true decoded.client_conn_fd = c.fd - decoded.client_conn_handle = usize(c.fd) + decoded.client_conn_handle = uint(c.fd) decoded.user_data = server.user_data decoded.worker_state = c.worker_state @@ -583,7 +583,7 @@ fn (mut c Conn) consume_read_prefix(full_data []u8, consumed int) { return } fixed_len := if leftover < buf_size { leftover } else { buf_size } - unsafe { C.memcpy(&c.read_buf[0], &full_data[consumed], usize(fixed_len)) } + unsafe { C.memcpy(&c.read_buf[0], &full_data[consumed], uint(fixed_len)) } c.read_len = fixed_len if leftover > fixed_len { c.read_extra << full_data[consumed + fixed_len..] diff --git a/vlib/fasthttp/fasthttp_linux.c.v b/vlib/fasthttp/fasthttp_linux.c.v index 4ec92d0ff1..a53f1867cb 100644 --- a/vlib/fasthttp/fasthttp_linux.c.v +++ b/vlib/fasthttp/fasthttp_linux.c.v @@ -22,9 +22,9 @@ fn C.socket(domain i32, typ i32, protocol i32) i32 fn C.bind(sockfd i32, addr voidptr, addrlen u32) i32 -fn C.send(__fd i32, __buf voidptr, __n usize, __flags i32) i32 +fn C.send(__fd i32, __buf voidptr, __n uint, __flags i32) i32 -fn C.recv(__fd i32, __buf voidptr, __n usize, __flags i32) i32 +fn C.recv(__fd i32, __buf voidptr, __n uint, __flags i32) i32 fn C.setsockopt(__fd i32, __level i32, __optname i32, __optval voidptr, __optlen u32) i32 @@ -46,7 +46,7 @@ fn C.epoll_ctl(__epfd i32, __op i32, __fd i32, __event &C.epoll_event) i32 fn C.epoll_wait(__epfd i32, __events &C.epoll_event, __maxevents i32, __timeout i32) i32 -fn C.sendfile(out_fd i32, in_fd i32, offset voidptr, count usize) i32 +fn C.sendfile(out_fd i32, in_fd i32, offset voidptr, count uint) i32 @[typedef] pub struct C.sigset_t {} @@ -64,7 +64,7 @@ fn C.pthread_sigmask(how i32, const_set voidptr, oldset voidptr) i32 fn C.sigtimedwait(const_set &C.sigset_t, info voidptr, const_timeout &C.timespec) i32 // sendfile_without_sigpipe confines SIGPIPE blocking to one sendfile call. -fn sendfile_without_sigpipe(out_fd i32, in_fd i32, offset &i64, count usize) i32 { +fn sendfile_without_sigpipe(out_fd i32, in_fd i32, offset &i64, count uint) i32 { mut sigpipe_set := C.sigset_t{} mut previous_mask := C.sigset_t{} C.sigemptyset(&sigpipe_set) @@ -107,7 +107,7 @@ fn C.fstat(fd i32, buf &C.stat) i32 fn C.open(pathname &char, flags i32, mode ...int) i32 -fn C.memmove(dest voidptr, src voidptr, n usize) voidptr +fn C.memmove(dest voidptr, src voidptr, n uint) voidptr @[typedef] union C.epoll_data_t { diff --git a/vlib/fasthttp/fasthttp_linux.v b/vlib/fasthttp/fasthttp_linux.v index fd43d9a09a..86c2fdf9c1 100644 --- a/vlib/fasthttp/fasthttp_linux.v +++ b/vlib/fasthttp/fasthttp_linux.v @@ -428,9 +428,9 @@ fn mark_read_deadline(mut w Worker, mut cs ConnState) { fn drain_file(fd int, mut cs ConnState) int { for cs.file_remaining > 0 { want := if cs.file_remaining > sendfile_chunk { - usize(sendfile_chunk) + uint(sendfile_chunk) } else { - usize(cs.file_remaining) + uint(cs.file_remaining) } sent := sendfile_without_sigpipe(fd, cs.file_fd, &cs.file_off, want) if sent > 0 { @@ -461,7 +461,7 @@ fn drain_file(fd int, mut cs ConnState) int { fn flush_batch(mut w Worker, fd int, mut cs ConnState) FlushResult { // Phase 1: the buffered response bytes (status lines, headers, small bodies). for cs.write_off < cs.write_buf.len { - n := C.send(fd, unsafe { &u8(cs.write_buf.data) + cs.write_off }, usize(cs.write_buf.len - cs.write_off), C.MSG_NOSIGNAL) + n := C.send(fd, unsafe { &u8(cs.write_buf.data) + cs.write_off }, uint(cs.write_buf.len - cs.write_off), C.MSG_NOSIGNAL) if n > 0 { cs.write_off += n continue @@ -565,7 +565,7 @@ fn compact_read_buf(mut cs ConnState, pos int) { return } if leftover > 0 { - unsafe { C.memmove(cs.read_buf.data, &u8(cs.read_buf.data) + pos, usize(leftover)) } + unsafe { C.memmove(cs.read_buf.data, &u8(cs.read_buf.data) + pos, uint(leftover)) } } unsafe { cs.read_buf.len = leftover @@ -658,7 +658,7 @@ fn drain_requests(mut w Worker, fd int, mut cs ConnState) bool { return flush_batch(mut w, fd, mut cs) != .closed } decoded.client_conn_fd = fd - decoded.client_conn_handle = usize(fd) + decoded.client_conn_handle = uint(fd) decoded.user_data = w.server.user_data decoded.worker_state = w.worker_state mut ctl := ResponseControl{} @@ -728,7 +728,7 @@ fn drain_requests(mut w Worker, fd int, mut cs ConnState) bool { return flush_batch(mut w, fd, mut cs) != .closed } decoded.client_conn_fd = fd - decoded.client_conn_handle = usize(fd) + decoded.client_conn_handle = uint(fd) decoded.user_data = w.server.user_data decoded.worker_state = w.worker_state mut resp := w.server.request_handler(decoded) or { @@ -859,7 +859,7 @@ fn serve_conn(mut w Worker, fd int, mut cs ConnState) { } } spare := cs.read_buf.cap - cs.read_buf.len - n := C.recv(fd, unsafe { &u8(cs.read_buf.data) + cs.read_buf.len }, usize(spare), 0) + n := C.recv(fd, unsafe { &u8(cs.read_buf.data) + cs.read_buf.len }, uint(spare), 0) if n < 0 { if C.errno == C.EAGAIN { break // socket drained diff --git a/vlib/fasthttp/fasthttp_test.v b/vlib/fasthttp/fasthttp_test.v index ff366f963e..375a37aa6b 100644 --- a/vlib/fasthttp/fasthttp_test.v +++ b/vlib/fasthttp/fasthttp_test.v @@ -218,7 +218,7 @@ fn reusable_takeover_handler(req HttpRequest) !HttpResponse { } } -fn send_raw_response(handle usize, response string) { +fn send_raw_response(handle uint, response string) { $if linux { C.send(int(handle), response.str, response.len, C.MSG_NOSIGNAL) } $else $if bsd { diff --git a/vlib/fasthttp/fasthttp_windows.c.v b/vlib/fasthttp/fasthttp_windows.c.v index 6f42e4afc6..d7b62d48aa 100644 --- a/vlib/fasthttp/fasthttp_windows.c.v +++ b/vlib/fasthttp/fasthttp_windows.c.v @@ -16,8 +16,8 @@ module fasthttp #define v_fasthttp_shutdown(s, how) shutdown((s), (how)) type C.DWORD = u32 -type C.ULONG_PTR = usize -type C.SOCKET = usize +type C.ULONG_PTR = uint +type C.SOCKET = uint const iocp_invalid_socket = C.SOCKET(C.INVALID_SOCKET) @@ -36,8 +36,8 @@ mut: @[typedef] struct C.OVERLAPPED { mut: - Internal usize - InternalHigh usize + Internal uint + InternalHigh uint Offset u32 OffsetHigh u32 hEvent voidptr diff --git a/vlib/fasthttp/fasthttp_windows.v b/vlib/fasthttp/fasthttp_windows.v index 40cc73ab98..db531285cd 100644 --- a/vlib/fasthttp/fasthttp_windows.v +++ b/vlib/fasthttp/fasthttp_windows.v @@ -578,7 +578,7 @@ fn process_request(mut conn IocpConn, frame_total int, worker_state voidptr) { } // Keep legacy int fd consumers working; client_conn_handle preserves the full SOCKET. decoded.client_conn_fd = int(conn.fd) - decoded.client_conn_handle = usize(conn.fd) + decoded.client_conn_handle = uint(conn.fd) decoded.user_data = conn.server.user_data decoded.worker_state = worker_state diff --git a/vlib/fasthttp/fasthttp_windows_regression_test.c.v b/vlib/fasthttp/fasthttp_windows_regression_test.c.v index 31b25331d3..4a289b94ab 100644 --- a/vlib/fasthttp/fasthttp_windows_regression_test.c.v +++ b/vlib/fasthttp/fasthttp_windows_regression_test.c.v @@ -15,7 +15,7 @@ fn C.v_fasthttp_test_cancel_io(s C.SOCKET, overlapped &C.OVERLAPPED) int fn test_accept_wrapper_preserves_pointer_sized_socket() { client_fd := C.v_fasthttp_accept(iocp_invalid_socket) assert sizeof(client_fd) == sizeof(C.SOCKET) - assert sizeof(client_fd) == sizeof(usize) + assert sizeof(client_fd) == sizeof(uint) } fn iocp_timeout_sweep_closes_connection(read_start u64, write_start u64, active bool) bool { diff --git a/vlib/fontstash/fontstash.c.v b/vlib/fontstash/fontstash.c.v index e397ce9697..b26647c1fd 100644 --- a/vlib/fontstash/fontstash.c.v +++ b/vlib/fontstash/fontstash.c.v @@ -21,7 +21,7 @@ $if gcboehm ? { #include "fontstash.h" #flag darwin -I/usr/local/Cellar/freetype/2.10.2/include/freetype2 -fn C.GC_MALLOC_ATOMIC(n usize) voidptr +fn C.GC_MALLOC_ATOMIC(n uint) voidptr $if windows { $if tinyc { @@ -112,9 +112,9 @@ pub fn (s &Context) add_font_mem(name string, data []u8, free_data bool) int { data_len := data.len mut owned := &u8(nil) $if gcboehm ? { - owned = &u8(C.GC_MALLOC_ATOMIC(usize(data_len))) + owned = &u8(C.GC_MALLOC_ATOMIC(uint(data_len))) } $else { - owned = &u8(C.malloc(usize(data_len))) + owned = &u8(C.malloc(uint(data_len))) } if data_len > 0 && owned == nil { data.free() diff --git a/vlib/fontstash/iterator_test.c.v b/vlib/fontstash/iterator_test.c.v new file mode 100644 index 0000000000..b8d1fd5361 --- /dev/null +++ b/vlib/fontstash/iterator_test.c.v @@ -0,0 +1,7 @@ +module fontstash + +fn test_iterator_preserves_c_field_names_when_formatted() { + iter := C.FONStextIter{} + assert iter.isize == 0 + assert iter.str().contains('isize: 0') +} diff --git a/vlib/gg/frame_pass_test.c.v b/vlib/gg/frame_pass_test.c.v index a85c5ce961..59a7027f84 100644 --- a/vlib/gg/frame_pass_test.c.v +++ b/vlib/gg/frame_pass_test.c.v @@ -7,8 +7,8 @@ import os import v.cmdexec $if gcboehm ? { - fn C.GC_get_total_bytes() usize - fn C.GC_get_gc_no() usize + fn C.GC_get_total_bytes() uint + fn C.GC_get_gc_no() uint } fn test_context_end_does_not_heap_copy_a_frame_local_pass() { diff --git a/vlib/gg/gg.c.v b/vlib/gg/gg.c.v index ed6b061a23..742226e52d 100644 --- a/vlib/gg/gg.c.v +++ b/vlib/gg/gg.c.v @@ -723,7 +723,7 @@ fn gg_resize_window(width int, height int) { u32(C.SWP_NOZORDER | C.SWP_NOACTIVATE)) } $else $if linux && !sokol_wayland ? { display := sapp.x11_get_display() - window := u64(usize(sapp.x11_get_window())) + window := u64(uint(sapp.x11_get_window())) if display == unsafe { nil } || window == 0 { return } diff --git a/vlib/gg/image.c.v b/vlib/gg/image.c.v index 48b41cd6dd..a241cadbdc 100644 --- a/vlib/gg/image.c.v +++ b/vlib/gg/image.c.v @@ -142,7 +142,7 @@ fn sokol_mipmap(mut simg_desc gfx.ImageDesc, max_mipmaps int) { src_width = target_width src_height = target_height simg_desc.data.subimage[0][level].ptr = target - simg_desc.data.subimage[0][level].size = usize(target_width * target_height * 4) + simg_desc.data.subimage[0][level].size = uint(target_width * target_height * 4) unsafe { target += target_width * target_height * 4 } @@ -164,7 +164,7 @@ pub fn (mut img Image) init_sokol_image() &Image { } // NOTE the following code, sometimes, result in hard-to-detect visual errors/bugs: - // img_size := usize(img.nr_channels * img.width * img.height) + // img_size := uint(img.nr_channels * img.width * img.height) // As an example see https://github.com/vlang/vab/issues/239 // The image will come out blank for some reason and no SOKOL_ASSERT // nor any CI check will/can currently catch this. @@ -174,7 +174,7 @@ pub fn (mut img Image) init_sokol_image() &Image { // 3 (or less) channels which stbi will correctly detect and set as `img.nr_channels` // but the current sokol_gl context setup expects 4. It *should* be the same with // all other stbi supported formats. - img_size := usize(4 * img.width * img.height) + img_size := uint(4 * img.width * img.height) img_desc.data.subimage[0][0] = gfx.Range{ ptr: img.data size: img_size @@ -232,7 +232,7 @@ pub fn (mut ctx Context) new_streaming_image(w int, h int, channels int, sicfg S // Sokol requires that streamed images have NO .ptr/.size initially: img_desc.data.subimage[0][0] = gfx.Range{ ptr: 0 - size: usize(0) + size: uint(0) } img.simg = gfx.make_image(&img_desc) @@ -262,7 +262,7 @@ pub fn (mut ctx Context) update_pixel_data(cached_image_idx int, buf &u8) { pub fn (mut img Image) update_pixel_data(buf &u8) { mut data := gfx.ImageData{} data.subimage[0][0].ptr = buf - data.subimage[0][0].size = usize(img.width * img.height * img.nr_channels) + data.subimage[0][0].size = uint(img.width * img.height * img.nr_channels) gfx.update_image(img.simg, &data) } diff --git a/vlib/gg/multiwindow_api_d_gg_multiwindow_test.v b/vlib/gg/multiwindow_api_d_gg_multiwindow_test.v index b77d73fda9..6b7571d400 100644 --- a/vlib/gg/multiwindow_api_d_gg_multiwindow_test.v +++ b/vlib/gg/multiwindow_api_d_gg_multiwindow_test.v @@ -1815,8 +1815,8 @@ fn test_multiwindow_mock_run_with_event_and_frame_rejects_before_callbacks() { } fn test_multiwindow_render_owner_guard_rejects_mixed_owners() { - legacy_token := voidptr(usize(0x1001)) - app_token := voidptr(usize(0x2002)) + legacy_token := voidptr(uint(0x1001)) + app_token := voidptr(uint(0x2002)) gg_release_gfx_render_owner(.legacy_context, legacy_token) gg_release_gfx_render_owner(.multiwindow_app, app_token) gg_claim_gfx_render_owner(.legacy_context, legacy_token)! @@ -1857,7 +1857,7 @@ fn test_multiwindow_same_app_can_reclaim_renderer_owner() { } fn test_multiwindow_release_render_owner_allows_other_owner_after_claim() { - legacy_token := voidptr(usize(0x5005)) + legacy_token := voidptr(uint(0x5005)) gg_release_gfx_render_owner(.legacy_context, legacy_token) mut app := new_app(backend: .mock)! @@ -1869,7 +1869,7 @@ fn test_multiwindow_release_render_owner_allows_other_owner_after_claim() { } fn test_multiwindow_foreign_thread_stop_does_not_release_render_owner() { - legacy_token := voidptr(usize(0x7007)) + legacy_token := voidptr(uint(0x7007)) gg_release_gfx_render_owner(.legacy_context, legacy_token) mut app := new_app(backend: .mock)! app.ensure_render_owner()! @@ -1922,7 +1922,7 @@ fn test_multiwindow_foreign_thread_stop_does_not_release_render_owner() { } fn test_multiwindow_legacy_then_app_ownership_is_rejected_without_window() { - legacy_token := voidptr(usize(0x3003)) + legacy_token := voidptr(uint(0x3003)) mut app := new_app(backend: .mock)! gg_claim_gfx_render_owner(.legacy_context, legacy_token)! @@ -1941,7 +1941,7 @@ fn test_multiwindow_legacy_then_app_ownership_is_rejected_without_window() { fn test_multiwindow_app_then_legacy_ownership_is_rejected_without_window() { mut app := new_app(backend: .mock)! - legacy_token := voidptr(usize(0x4004)) + legacy_token := voidptr(uint(0x4004)) app.ensure_render_owner()! mut claim_message := '' diff --git a/vlib/gg/multiwindow_buffer_cleanup_d_gg_multiwindow_test.v b/vlib/gg/multiwindow_buffer_cleanup_d_gg_multiwindow_test.v index c1d4412d85..6584cbe4a9 100644 --- a/vlib/gg/multiwindow_buffer_cleanup_d_gg_multiwindow_test.v +++ b/vlib/gg/multiwindow_buffer_cleanup_d_gg_multiwindow_test.v @@ -13,7 +13,7 @@ import x.multiwindow struct MultiWindowBufferSlotProof { status MultiWindowResourceStatus usage gfx.Usage - capacity usize + capacity uint last_mutation_batch u64 mutation_mode MultiWindowBufferMutationMode native_id u32 @@ -271,7 +271,7 @@ fn multiwindow_run_buffer_descriptor_init(mut resources AppResourceContext, mut bytes := [u8(1), 2, 3, 4] data := gfx.Range{ ptr: bytes.data - size: usize(bytes.len) + size: uint(bytes.len) } for desc in [ @@ -293,7 +293,7 @@ fn multiwindow_run_buffer_descriptor_init(mut resources AppResourceContext, mut usage: .stream }, gfx.BufferDesc{ - size: usize(0x80000000) + size: uint(0x80000000) usage: .dynamic }, ] { diff --git a/vlib/gg/multiwindow_render_fault_matrix_d_gg_multiwindow_test.v b/vlib/gg/multiwindow_render_fault_matrix_d_gg_multiwindow_test.v index c157ec2bce..13ca552dac 100644 --- a/vlib/gg/multiwindow_render_fault_matrix_d_gg_multiwindow_test.v +++ b/vlib/gg/multiwindow_render_fault_matrix_d_gg_multiwindow_test.v @@ -47,7 +47,7 @@ struct MultiWindowMatrixSlotState { dependents []string last_mutation_batch u64 buffer_mutation_mode MultiWindowBufferMutationMode - buffer_capacity usize + buffer_capacity uint buffer_usage gfx.Usage buffer_desc []u8 image_desc []u8 @@ -714,7 +714,7 @@ fn multiwindow_fault_matrix_make_image(mut resources AppResourceContext, mut pro } invalid_desc.data.subimage[0][0] = gfx.Range{ ptr: invalid_pixels.data - size: usize(invalid_pixels.len) + size: uint(invalid_pixels.len) } mut invalid_error := '' _ := resources.make_image(&invalid_desc) or { @@ -1067,7 +1067,7 @@ fn multiwindow_fault_matrix_update_buffer(mut resources AppResourceContext, mut bytes := [u8(1), 2, 3, 4] data := gfx.Range{ ptr: bytes.data - size: usize(bytes.len) + size: uint(bytes.len) } mut fault_error := '' resources.update_buffer(proof.update_buffer, &data) or { fault_error = err.msg() } @@ -1096,7 +1096,7 @@ fn multiwindow_fault_matrix_append_buffer(mut resources AppResourceContext, mut prime_bytes := []u8{len: 48, init: u8(index)} prime_data := gfx.Range{ ptr: prime_bytes.data - size: usize(prime_bytes.len) + size: uint(prime_bytes.len) } prime_offset := resources.append_buffer(proof.append_buffer, &prime_data)! assert prime_offset == 0 @@ -1114,7 +1114,7 @@ fn multiwindow_fault_matrix_append_buffer(mut resources AppResourceContext, mut overflow_bytes := []u8{len: 20, init: u8(index)} overflow_data := gfx.Range{ ptr: overflow_bytes.data - size: usize(overflow_bytes.len) + size: uint(overflow_bytes.len) } mut overflow_error := '' _ := resources.append_buffer(proof.append_buffer, &overflow_data) or { @@ -1127,7 +1127,7 @@ fn multiwindow_fault_matrix_append_buffer(mut resources AppResourceContext, mut bytes := [u8(5), 6, 7, 8] data := gfx.Range{ ptr: bytes.data - size: usize(bytes.len) + size: uint(bytes.len) } mut fault_error := '' _ := resources.append_buffer(proof.append_buffer, &data) or { @@ -1169,7 +1169,7 @@ fn multiwindow_fault_matrix_update_image(mut resources AppResourceContext, mut p mut data := gfx.ImageData{} data.subimage[0][0] = gfx.Range{ ptr: pixels.data - size: usize(pixels.len) + size: uint(pixels.len) } mut fault_error := '' resources.update_image(proof.update_image, &data) or { fault_error = err.msg() } @@ -1710,7 +1710,7 @@ fn multiwindow_assert_postcommit_replacement_destruction(before multiwindow_soko assert !before.overflow assert !after.overflow assert after.install_generation == before.install_generation - assert after.count >= before.count + usize(expected.len + 1) + assert after.count >= before.count + uint(expected.len + 1) for record in before.records { for item in expected { assert record.operation != item.operation || record.identity != item.identity @@ -1889,7 +1889,7 @@ fn multiwindow_assert_retirement_trace(before multiwindow_sokol_trace.TypedSnaps assert !after.overflow assert before.install_generation != 0 assert after.install_generation == before.install_generation - assert after.count == before.count + usize(expected.len + 3) + assert after.count == before.count + uint(expected.len + 3) anchor_begin := after.records[int(before.count)] anchor_end := after.records[int(before.count) + 1] commit := after.records[int(before.count) + 2] @@ -1974,7 +1974,7 @@ fn multiwindow_assert_exact_registry_delta(before MultiWindowMatrixRegistryState } } -fn multiwindow_assert_buffer_retry_slot(registry MultiWindowMatrixRegistryState, id WindowBufferId, native u32, capacity usize, usage gfx.Usage, mutation MultiWindowBufferMutationMode, mutation_batch u64) { +fn multiwindow_assert_buffer_retry_slot(registry MultiWindowMatrixRegistryState, id WindowBufferId, native u32, capacity uint, usage gfx.Usage, mutation MultiWindowBufferMutationMode, mutation_batch u64) { slot := multiwindow_fault_matrix_registry_slot(registry, multiwindow_fault_matrix_key(buffer_resource_key(id))) mut desc := gfx.BufferDesc{ @@ -2512,7 +2512,7 @@ fn multiwindow_fault_matrix_materializations(values map[string]MultiWindowSglMat fn multiwindow_fault_matrix_raw_bytes[T](value &T) []u8 { mut result := []u8{len: int(sizeof(T))} unsafe { - C.memcpy(result.data, value, usize(result.len)) + C.memcpy(result.data, value, uint(result.len)) } return result } @@ -2521,7 +2521,7 @@ fn multiwindow_assert_desc_semantically_equal[T](actual_bytes []u8, expected &T) assert actual_bytes.len == int(sizeof(T)) mut actual := T{} unsafe { - C.memcpy(&actual, actual_bytes.data, usize(actual_bytes.len)) + C.memcpy(&actual, actual_bytes.data, uint(actual_bytes.len)) } assert actual == *expected } @@ -2621,7 +2621,7 @@ fn multiwindow_assert_cleanup_error_trace(snapshot multiwindow_sokol_trace.Typed assert app_buffer != window_buffer assert snapshot.install_generation != 0 assert !snapshot.overflow - assert snapshot.count == usize(snapshot.records.len) + assert snapshot.count == uint(snapshot.records.len) assert snapshot.records.len > 0 assert snapshot.records[0].sequence != 0 for index in 1 .. snapshot.records.len { @@ -2731,7 +2731,7 @@ fn multiwindow_assert_shutdown_destruction_tail(before multiwindow_sokol_trace.T .destroy_shader, ] expected_tail := context_shutdown.len * 2 + global_shutdown.len - assert after.count == before.count + usize(expected_tail) + assert after.count == before.count + uint(expected_tail) assert after.records.len == int(after.count) for index, record in before.records { assert after.records[index] == record @@ -2780,7 +2780,7 @@ fn multiwindow_assert_trace_delta(before multiwindow_sokol_trace.TypedSnapshot, assert !after.overflow assert before.install_generation != 0 assert after.install_generation == before.install_generation - assert after.count == before.count + usize(expected.len) + assert after.count == before.count + uint(expected.len) for index, item in expected { record := after.records[int(before.count) + index] assert record.operation == item.operation diff --git a/vlib/gg/multiwindow_render_impl_d_gg_multiwindow.v b/vlib/gg/multiwindow_render_impl_d_gg_multiwindow.v index e87c12fcc9..704391a17f 100644 --- a/vlib/gg/multiwindow_render_impl_d_gg_multiwindow.v +++ b/vlib/gg/multiwindow_render_impl_d_gg_multiwindow.v @@ -8,8 +8,8 @@ $if linux { $if x_multiwindow_x11 ?|| sokol_wayland ? { #insert "@VMODROOT/vlib/gg/multiwindow_gl_readback_helpers.h" - fn C.v_gg_multiwindow_gl_readback_image_rgba8(image_id u32, image_height int, x int, y int, width int, height int, pixels &u8, pixels_len usize) int - fn C.v_gg_multiwindow_gl_readback_window_rgba8(framebuffer_height int, x int, y int, width int, height int, pixels &u8, pixels_len usize) int + fn C.v_gg_multiwindow_gl_readback_image_rgba8(image_id u32, image_height int, x int, y int, width int, height int, pixels &u8, pixels_len uint) int + fn C.v_gg_multiwindow_gl_readback_window_rgba8(framebuffer_height int, x int, y int, width int, height int, pixels &u8, pixels_len uint) int } } @@ -364,7 +364,7 @@ fn (mut app App) stage_managed_window_captures(id WindowId, target_submitted_fra mut pixels := []u8{len: capture.rect.width * capture.rect.height * 4} status := C.v_gg_multiwindow_gl_readback_window_rgba8(framebuffer_height, capture.rect.x, capture.rect.y, capture.rect.width, capture.rect.height, - pixels.data, usize(pixels.len)) + pixels.data, uint(pixels.len)) if status != 0 { app.core.service_fail_window_readback(capture.id, err_multiwindow_render_readback_unsupported)! @@ -841,7 +841,7 @@ fn (mut context WindowContext) request_image_readback_managed(id WindowImageId, width, height)! mut pixels := []u8{len: width * height * 4} status := C.v_gg_multiwindow_gl_readback_image_rgba8(snapshot.image.id, - snapshot.desc.height, x, y, width, height, pixels.data, usize(pixels.len)) + snapshot.desc.height, x, y, width, height, pixels.data, uint(pixels.len)) if status != 0 { app.core.service_rollback_window_readback_for_gg(readback) return error(err_multiwindow_render_readback_unsupported) @@ -987,7 +987,7 @@ fn (mut pass WindowPassContext) apply_bindings_managed(bindings WindowBindings) } buffer_slot := runtime.resources.slots[index] if buffer_slot.buffer_desc.type != .vertexbuffer - || usize(binding.offset) >= buffer_slot.buffer_capacity { + || uint(binding.offset) >= buffer_slot.buffer_capacity { runtime.mutex.unlock() return error(err_multiwindow_render_invalid_bindings) } @@ -1007,7 +1007,7 @@ fn (mut pass WindowPassContext) apply_bindings_managed(bindings WindowBindings) } buffer_slot := runtime.resources.slots[index] if buffer_slot.buffer_desc.type != .indexbuffer - || usize(index_binding.offset) >= buffer_slot.buffer_capacity { + || uint(index_binding.offset) >= buffer_slot.buffer_capacity { runtime.mutex.unlock() return error(err_multiwindow_render_invalid_bindings) } diff --git a/vlib/gg/multiwindow_resource_impl_d_gg_multiwindow.v b/vlib/gg/multiwindow_resource_impl_d_gg_multiwindow.v index 8a0aeaac77..2fc4c0dab5 100644 --- a/vlib/gg/multiwindow_resource_impl_d_gg_multiwindow.v +++ b/vlib/gg/multiwindow_resource_impl_d_gg_multiwindow.v @@ -751,13 +751,13 @@ fn copy_managed_buffer_desc(desc &gfx.BufferDesc) !ManagedBufferDescCopy { result.desc.label = &char(result.label.str) } if desc.data.size > 0 { - if desc.data.ptr == unsafe { nil } || desc.data.size > usize(0x7fffffff) { + if desc.data.ptr == unsafe { nil } || desc.data.size > uint(0x7fffffff) { return error(err_multiwindow_render_invalid_descriptor) } result.data = unsafe { desc.data.ptr.vbytes(int(desc.data.size)).clone() } result.desc.data = gfx.Range{ ptr: result.data.data - size: usize(result.data.len) + size: uint(result.data.len) } } else if desc.data.ptr != unsafe { nil } { return error(err_multiwindow_render_invalid_descriptor) @@ -769,7 +769,7 @@ fn validate_raw_buffer_desc(desc &gfx.BufferDesc) ! { if desc == unsafe { nil } { return error(err_multiwindow_render_invalid_descriptor) } - if desc.size > usize(0x7fffffff) || desc.data.size > usize(0x7fffffff) { + if desc.size > uint(0x7fffffff) || desc.data.size > uint(0x7fffffff) { return error(err_multiwindow_render_invalid_descriptor) } match desc.usage { @@ -793,7 +793,7 @@ fn validate_raw_buffer_desc(desc &gfx.BufferDesc) ! { } fn validate_effective_buffer_desc(desc gfx.BufferDesc) ! { - if desc.size == 0 || desc.size > usize(0x7fffffff) || desc.data.size > usize(0x7fffffff) { + if desc.size == 0 || desc.size > uint(0x7fffffff) || desc.data.size > uint(0x7fffffff) { return error(err_multiwindow_render_invalid_descriptor) } if desc.type != .vertexbuffer && desc.type != .indexbuffer && desc.type != .storagebuffer { @@ -845,14 +845,14 @@ fn copy_managed_image_desc(desc &gfx.ImageDesc) !ManagedImageDescCopy { } continue } - if range.ptr == unsafe { nil } || range.size > usize(0x7fffffff) { + if range.ptr == unsafe { nil } || range.size > uint(0x7fffffff) { return error(err_multiwindow_render_invalid_descriptor) } owned := unsafe { range.ptr.vbytes(int(range.size)).clone() } result.data << owned result.desc.data.subimage[face][mip] = gfx.Range{ ptr: result.data[result.data.len - 1].data - size: usize(owned.len) + size: uint(owned.len) } } } @@ -949,14 +949,14 @@ fn copy_managed_shader_stage(mut stage gfx.ShaderStageDesc, mut strings []string stage.entry = copy_managed_cstring(stage.entry, mut strings)! stage.d3d11_target = copy_managed_cstring(stage.d3d11_target, mut strings)! if stage.bytecode.size > 0 { - if stage.bytecode.ptr == unsafe { nil } || stage.bytecode.size > usize(0x7fffffff) { + if stage.bytecode.ptr == unsafe { nil } || stage.bytecode.size > uint(0x7fffffff) { return error(err_multiwindow_render_invalid_descriptor) } owned := unsafe { stage.bytecode.ptr.vbytes(int(stage.bytecode.size)).clone() } bytes << owned stage.bytecode = gfx.Range{ ptr: bytes[bytes.len - 1].data - size: usize(owned.len) + size: uint(owned.len) } } else if stage.bytecode.ptr != unsafe { nil } { return error(err_multiwindow_render_invalid_descriptor) diff --git a/vlib/gg/multiwindow_resource_state_d_gg_multiwindow.v b/vlib/gg/multiwindow_resource_state_d_gg_multiwindow.v index 321531ed5b..5231ebedb7 100644 --- a/vlib/gg/multiwindow_resource_state_d_gg_multiwindow.v +++ b/vlib/gg/multiwindow_resource_state_d_gg_multiwindow.v @@ -57,7 +57,7 @@ mut: dependents []MultiWindowResourceKey last_mutation_batch u64 buffer_mutation_mode MultiWindowBufferMutationMode - buffer_capacity usize + buffer_capacity uint buffer_usage gfx.Usage buffer_desc gfx.BufferDesc buffer gfx.Buffer @@ -227,7 +227,7 @@ fn (registry &MultiWindowResourceRegistry) validate_any(key MultiWindowResourceK return key.slot } -fn (registry &MultiWindowResourceRegistry) plan_buffer_mutation(key MultiWindowResourceKey, window WindowId, scope MultiWindowResourceScope, batch u64, mode MultiWindowBufferMutationMode, data_size usize) !MultiWindowBufferMutationPlan { +fn (registry &MultiWindowResourceRegistry) plan_buffer_mutation(key MultiWindowResourceKey, window WindowId, scope MultiWindowResourceScope, batch u64, mode MultiWindowBufferMutationMode, data_size uint) !MultiWindowBufferMutationPlan { index := registry.validate(key, .buffer, window, scope)! registry.validate_mutation_scope(index, scope)! if batch == 0 { diff --git a/vlib/gg/multiwindow_win32_public_services_contract_windows_test.v b/vlib/gg/multiwindow_win32_public_services_contract_windows_test.v index 38b2615fd1..f8e3ac4291 100644 --- a/vlib/gg/multiwindow_win32_public_services_contract_windows_test.v +++ b/vlib/gg/multiwindow_win32_public_services_contract_windows_test.v @@ -22,8 +22,8 @@ $if windows && gg_multiwindow ? { fn C.v_multiwindow_test_win32_monitor_enumeration_reset() fn C.v_multiwindow_test_win32_monitor_enumeration_empty_calls() int fn C.v_multiwindow_test_win32_monitor_enumeration_replay_calls() int - fn C.v_multiwindow_test_win32_clipboard_equals(expected &u16, expected_units usize) int - fn C.v_multiwindow_test_win32_set_clipboard(owner voidptr, text &u16, units usize) int + fn C.v_multiwindow_test_win32_clipboard_equals(expected &u16, expected_units uint) int + fn C.v_multiwindow_test_win32_set_clipboard(owner voidptr, text &u16, units uint) int fn C.SetForegroundWindow(hwnd voidptr) int fn C.GetForegroundWindow() voidptr fn C.SetFocus(hwnd voidptr) voidptr @@ -71,10 +71,10 @@ fn win32_public_hwnd(mut app App, window WindowId) !voidptr { return probe.hwnd } -fn win32_public_utf16_units(text string) usize { - mut units := usize(1) +fn win32_public_utf16_units(text string) uint { + mut units := uint(1) for codepoint in text.runes() { - units += if codepoint > 0xffff { usize(2) } else { usize(1) } + units += if codepoint > 0xffff { uint(2) } else { uint(1) } } return units } diff --git a/vlib/gg/testdata/multiwindow_dynamic_texture_consumer_probe.v b/vlib/gg/testdata/multiwindow_dynamic_texture_consumer_probe.v index 7dda49ba96..24ca690a4b 100644 --- a/vlib/gg/testdata/multiwindow_dynamic_texture_consumer_probe.v +++ b/vlib/gg/testdata/multiwindow_dynamic_texture_consumer_probe.v @@ -276,7 +276,7 @@ fn run_app_resource_only_identity_probe(backend gg.MultiWindowBackend, stale_ima mut data := gfx.ImageData{} data.subimage[0][0] = gfx.Range{ ptr: pixels.data - size: usize(pixels.len) + size: uint(pixels.len) } mut rejected := false resources.update_image(stale_image, &data) or { @@ -497,7 +497,7 @@ fn update_dynamic_texture(mut resources gg.AppResourceContext, mut state Dynamic mut data := gfx.ImageData{} data.subimage[0][0] = gfx.Range{ ptr: pixels.data - size: usize(pixels.len) + size: uint(pixels.len) } resources.update_image(state.texture, &data)! state.texture_updates++ diff --git a/vlib/gg/testdata/multiwindow_retained_ui_consumer_probe.v b/vlib/gg/testdata/multiwindow_retained_ui_consumer_probe.v index 4ca051d125..c0683824cc 100644 --- a/vlib/gg/testdata/multiwindow_retained_ui_consumer_probe.v +++ b/vlib/gg/testdata/multiwindow_retained_ui_consumer_probe.v @@ -341,7 +341,7 @@ fn draw_retained_ui_probe(mut context gg.WindowContext, accent gg.Color, frames data_bytes := [u8(1), 2, 3, 4] data := gfx.Range{ ptr: data_bytes.data - size: usize(data_bytes.len) + size: uint(data_bytes.len) } mut rejected := false resources.update_buffer(state.main_buffer, &data) or { diff --git a/vlib/gg/testdata/multiwindow_sokol_trace/shader_fixture.v b/vlib/gg/testdata/multiwindow_sokol_trace/shader_fixture.v index 89c23df2fd..06cf27dd0d 100644 --- a/vlib/gg/testdata/multiwindow_sokol_trace/shader_fixture.v +++ b/vlib/gg/testdata/multiwindow_sokol_trace/shader_fixture.v @@ -7,9 +7,9 @@ $if gg_multiwindow ? { #insert "@VMODROOT/vlib/gg/testdata/multiwindow_sokol_trace/shader_fixture_helpers.h" fn C.v_multiwindow_fixture_hlsl4_vs() voidptr -fn C.v_multiwindow_fixture_hlsl4_vs_size() usize +fn C.v_multiwindow_fixture_hlsl4_vs_size() uint fn C.v_multiwindow_fixture_hlsl4_fs() voidptr -fn C.v_multiwindow_fixture_hlsl4_fs_size() usize +fn C.v_multiwindow_fixture_hlsl4_fs_size() uint const fixture_gl_vs = '#version 330\nuniform vec4 vs_params[8];\nlayout(location=0) in vec4 position;\nlayout(location=1) in vec2 texcoord0;\nlayout(location=2) in vec4 color0;\nlayout(location=3) in float psize;\nout vec4 uv;\nout vec4 color;\nvoid main() { mat4 mvp = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]); mat4 tm = mat4(vs_params[4], vs_params[5], vs_params[6], vs_params[7]); gl_Position = mvp * position; gl_PointSize = psize; uv = tm * vec4(texcoord0, 0.0, 1.0); color = color0; }\n' const fixture_gl_fs = '#version 330\nuniform sampler2D tex_smp;\nin vec4 uv;\nin vec4 color;\nout vec4 frag_color;\nvoid main() { frag_color = texture(tex_smp, uv.xy) * color; }\n' diff --git a/vlib/gg/testdata/multiwindow_sokol_trace/trace.c.v b/vlib/gg/testdata/multiwindow_sokol_trace/trace.c.v index b6d47da1ca..a7c48720ae 100644 --- a/vlib/gg/testdata/multiwindow_sokol_trace/trace.c.v +++ b/vlib/gg/testdata/multiwindow_sokol_trace/trace.c.v @@ -11,19 +11,19 @@ fn C.v_multiwindow_trace_uninstall_owned(generation u64) int fn C.v_multiwindow_trace_logical_release_owned(generation u64) int fn C.v_multiwindow_trace_reset() fn C.v_multiwindow_trace_snapshot() &char -fn C.v_multiwindow_typed_trace_snapshot_count() usize +fn C.v_multiwindow_typed_trace_snapshot_count() uint fn C.v_multiwindow_typed_trace_snapshot_overflow() int fn C.v_multiwindow_trace_active_install_generation() u64 -fn C.v_multiwindow_typed_trace_snapshot_operation(index usize) int -fn C.v_multiwindow_typed_trace_snapshot_identity(index usize) u32 -fn C.v_multiwindow_typed_trace_snapshot_value(index usize) i64 -fn C.v_multiwindow_typed_trace_snapshot_sequence(index usize) u64 -fn C.v_multiwindow_typed_trace_snapshot_swapchain_identity(index usize) u64 -fn C.v_multiwindow_typed_trace_snapshot_width(index usize) int -fn C.v_multiwindow_typed_trace_snapshot_height(index usize) int -fn C.v_multiwindow_typed_trace_snapshot_sample_count(index usize) int -fn C.v_multiwindow_typed_trace_snapshot_color_format(index usize) int -fn C.v_multiwindow_typed_trace_snapshot_depth_format(index usize) int +fn C.v_multiwindow_typed_trace_snapshot_operation(index uint) int +fn C.v_multiwindow_typed_trace_snapshot_identity(index uint) u32 +fn C.v_multiwindow_typed_trace_snapshot_value(index uint) i64 +fn C.v_multiwindow_typed_trace_snapshot_sequence(index uint) u64 +fn C.v_multiwindow_typed_trace_snapshot_swapchain_identity(index uint) u64 +fn C.v_multiwindow_typed_trace_snapshot_width(index uint) int +fn C.v_multiwindow_typed_trace_snapshot_height(index uint) int +fn C.v_multiwindow_typed_trace_snapshot_sample_count(index uint) int +fn C.v_multiwindow_typed_trace_snapshot_color_format(index uint) int +fn C.v_multiwindow_typed_trace_snapshot_depth_format(index uint) int pub enum Operation { invalid @@ -65,7 +65,7 @@ pub: pub struct TypedSnapshot { pub: records []Record - count usize + count uint overflow bool install_generation u64 } diff --git a/vlib/gg/wayland_pipe_abi_test.c.v b/vlib/gg/wayland_pipe_abi_test.c.v index 4e0c090635..2dd1932700 100644 --- a/vlib/gg/wayland_pipe_abi_test.c.v +++ b/vlib/gg/wayland_pipe_abi_test.c.v @@ -48,15 +48,15 @@ fn test_wayland_pipe_bindings_and_native_descriptor_storage() { // A small payload fits in an empty pipe; close its writer before reading so // both the payload read and the EOF check are bounded without a compositor. payload := [u8(0), 0x7f, 0x80, 0xff, `V`, `\n`]! - assert C.write(probe.fds[1], &payload[0], usize(payload.len)) == isize(payload.len) + assert C.write(probe.fds[1], &payload[0], uint(payload.len)) == int(payload.len) assert C.close(probe.fds[1]) == 0 probe.fds[1] = -1 mut received := [16]u8{} - assert C.read(probe.fds[0], &received[0], usize(received.len)) == isize(payload.len) + assert C.read(probe.fds[0], &received[0], uint(received.len)) == int(payload.len) for i, expected_byte in payload { assert received[i] == expected_byte } - assert C.read(probe.fds[0], &received[0], usize(received.len)) == 0 + assert C.read(probe.fds[0], &received[0], uint(received.len)) == 0 assert probe.before == 0x13579bdf assert probe.after == 0x2468ace0 } diff --git a/vlib/goroutines/atomic_ops.c.v b/vlib/goroutines/atomic_ops.c.v index 0646cd9711..694a6b232f 100644 --- a/vlib/goroutines/atomic_ops.c.v +++ b/vlib/goroutines/atomic_ops.c.v @@ -28,8 +28,8 @@ fn C.goroutines_atomic_cas_ptr(ptr voidptr, expected voidptr, desired voidptr) b fn C.grt_spinlock_lock(lk &i32) fn C.grt_spinlock_unlock(lk &i32) -fn C.memcpy(dest voidptr, src voidptr, n usize) voidptr -fn C.memset(dest voidptr, ch int, n usize) voidptr +fn C.memcpy(dest voidptr, src voidptr, n uint) voidptr +fn C.memset(dest voidptr, ch int, n uint) voidptr fn C.rand() int // SpinLock - ucontext-safe lock (pthreads mutex breaks with swapcontext). diff --git a/vlib/goroutines/chan.v b/vlib/goroutines/chan.v index 14a5c81521..d3ff7ecd1f 100644 --- a/vlib/goroutines/chan.v +++ b/vlib/goroutines/chan.v @@ -265,7 +265,7 @@ fn recv_direct(ch &Chan, sg &Sudog, ep voidptr) { // chan_buf returns a pointer to the i-th slot in the buffer. // Translated from Go's chanbuf() in chan.go. fn chan_buf(c &Chan, i u32) voidptr { - return unsafe { voidptr(usize(c.buf) + usize(i) * usize(c.elemsize)) } + return unsafe { voidptr(uint(c.buf) + uint(i) * uint(c.elemsize)) } } // chan_len returns the number of elements in the channel buffer. diff --git a/vlib/goroutines/context_windows.c.v b/vlib/goroutines/context_windows.c.v index b202631ded..5ef376dd68 100644 --- a/vlib/goroutines/context_windows.c.v +++ b/vlib/goroutines/context_windows.c.v @@ -7,7 +7,7 @@ module goroutines #include -fn C.CreateFiber(dwStackSize usize, lpStartAddress voidptr, lpParameter voidptr) voidptr +fn C.CreateFiber(dwStackSize uint, lpStartAddress voidptr, lpParameter voidptr) voidptr fn C.ConvertThreadToFiber(lpParameter voidptr) voidptr fn C.SwitchToFiber(lpFiber voidptr) fn C.DeleteFiber(lpFiber voidptr) @@ -21,7 +21,7 @@ pub mut: pub fn context_init(mut ctx Context, stack voidptr, stack_size int, entry_fn fn (voidptr), arg voidptr) { // Windows fibers manage their own stack, so we ignore the stack param - ctx.uctx = C.CreateFiber(usize(stack_size), voidptr(entry_fn), arg) + ctx.uctx = C.CreateFiber(uint(stack_size), voidptr(entry_fn), arg) } pub fn context_switch(mut from Context, to &Context) { diff --git a/vlib/image/decoders/jpeg/jpeg.v b/vlib/image/decoders/jpeg/jpeg.v index 98814b1c6a..1107f4c92d 100644 --- a/vlib/image/decoders/jpeg/jpeg.v +++ b/vlib/image/decoders/jpeg/jpeg.v @@ -2255,7 +2255,7 @@ $if windows { // `&stack_local` into a spawn makes V heap-escape it with no way to // free; the main thread frees it right after barrier_wait returns. fn new_barrier_counter() &u64 { - return &u64(unsafe { vcalloc_noscan(sizeof(u64)) }) + return &u64(unsafe { vcalloc_noscan(int(sizeof(u64))) }) } fn free_barrier_counter(cnt &u64) { diff --git a/vlib/json2/decode.v b/vlib/json2/decode.v index e7ea30ac65..3d5a9238bb 100644 --- a/vlib/json2/decode.v +++ b/vlib/json2/decode.v @@ -520,7 +520,7 @@ fn (mut decoder Decoder) decode_new_pointer[P](_ P) !P { // new_pointer_to returns a new heap pointer to `value`: one more level of // indirection, for decoding `&&T`, `&&&T`, ... values. fn new_pointer_to[T](value T) &T { - mut ptr := unsafe { &T(vcalloc(sizeof(T))) } + mut ptr := unsafe { &T(vcalloc(int(sizeof(T)))) } unsafe { *ptr = value } @@ -1921,12 +1921,10 @@ fn parse_integer_number[T](str string) !T { return T(strconv.atou64(int_str)!) } $else $if T is int { return int(strconv.atoi64(int_str)!) - } $else $if T.unaliased_typ is int { + } $else $if T.unaliased_typ is int || T.unaliased_typ is isize { return T(int(strconv.atoi64(int_str)!)) - } $else $if T.unaliased_typ is isize { - return T(isize(strconv.atoi64(int_str)!)) - } $else $if T.unaliased_typ is usize { - return T(usize(strconv.atou64(int_str)!)) + } $else $if T.unaliased_typ is uint { + return T(uint(strconv.atou64(int_str)!)) } $else { return error('`parse_integer_number` cannot decode ${T.name} type') } @@ -1990,7 +1988,7 @@ fn (mut decoder Decoder) decode_number[T](val &T) ! { u64 { *val = parse_integer_number[T](str)! } int { *val = parse_int_number(str)! } isize { *val = parse_integer_number[T](str)! } - usize { *val = parse_integer_number[T](str)! } + uint { *val = parse_integer_number[T](str)! } f32 { *val = parse_float_number[T](str)! } f64 { *val = parse_float_number[T](str)! } $else { return error('`decode_number` can not decode ${T.name} type') } @@ -2025,11 +2023,9 @@ fn (mut decoder Decoder) decode_number_from_string[T]() !T { return parse_integer_number[T](str)! } $else $if T is int { return parse_int_number(str)! - } $else $if T.unaliased_typ is int { + } $else $if T.unaliased_typ is int || T.unaliased_typ is isize { return parse_integer_number[T](str)! - } $else $if T.unaliased_typ is isize { - return parse_integer_number[T](str)! - } $else $if T.unaliased_typ is usize { + } $else $if T.unaliased_typ is uint { return parse_integer_number[T](str)! } $else $if T.unaliased_typ is f32 { return parse_float_number[T](str)! diff --git a/vlib/json2/decoder2/decode.v b/vlib/json2/decoder2/decode.v index 06df479c8f..3f4e569559 100644 --- a/vlib/json2/decoder2/decode.v +++ b/vlib/json2/decoder2/decode.v @@ -984,18 +984,13 @@ fn parse_integer_value[T](value string) !T { return T(strconv.atou32(value)!) } $else $if T.unaliased_typ is u64 { return T(strconv.atou64(value)!) - } $else $if T.unaliased_typ is int { + } $else $if T.unaliased_typ is int || T.unaliased_typ is isize { if sizeof(int) == 4 { return T(strconv.atoi(value)!) } return T(strconv.atoi64(value)!) - } $else $if T.unaliased_typ is isize { - if sizeof(isize) == 4 { - return T(strconv.atoi32(value)!) - } - return T(strconv.atoi64(value)!) - } $else $if T.unaliased_typ is usize { - if sizeof(usize) == 4 { + } $else $if T.unaliased_typ is uint { + if sizeof(uint) == 4 { return T(strconv.atou32(value)!) } return T(strconv.atou64(value)!) diff --git a/vlib/json2/encode.v b/vlib/json2/encode.v index 0d4ee5a52a..444df6e792 100644 --- a/vlib/json2/encode.v +++ b/vlib/json2/encode.v @@ -104,10 +104,10 @@ fn (mut encoder Encoder) encode_value[T](val T) { encoder.encode_number(i32(val)) } $else $if T.unaliased_typ is i64 { encoder.encode_number(i64(val)) - } $else $if T.unaliased_typ is usize { - encoder.encode_number(usize(val)) } $else $if T.unaliased_typ is isize { - encoder.encode_number(isize(val)) + encoder.encode_number(i64(val)) + } $else $if T.unaliased_typ is uint { + encoder.encode_number(uint(val)) } $else $if T.unaliased_typ is f32 { encoder.encode_number(f32(val)) } $else $if T.unaliased_typ is f64 { @@ -363,7 +363,7 @@ fn (mut encoder Encoder) encode_boolean(val bool) { @[manualfree] fn (mut encoder Encoder) encode_number[T](val T) { $if T is $int { - $if T is u8 || T is u16 || T is u32 || T is u64 || T is usize { + $if T is u8 || T is u16 || T is u32 || T is u64 || T is uint { encoder.output.write_u_decimal(u64(val)) } $else { encoder.output.write_decimal(i64(val)) diff --git a/vlib/json2/legacy_integer_test.v b/vlib/json2/legacy_integer_test.v new file mode 100644 index 0000000000..f92b3f4b40 --- /dev/null +++ b/vlib/json2/legacy_integer_test.v @@ -0,0 +1,21 @@ +module json2 + +import json2.decoder2 + +type LegacySigned = isize + +struct LegacyInteger { + value isize +} + +fn test_legacy_integer_encoding_and_decoding() ! { + assert encode(isize(-42)) == '-42' + assert encode(LegacyInteger{-42}) == '{"value":-42}' + assert decode[isize]('-42')! == -42 + assert decode[LegacySigned]('-42')! == -42 + assert decode[LegacyInteger]('{"value":-42}')!.value == -42 + assert decode[LegacyInteger]('{"value":"-42"}')!.value == -42 + assert decoder2.decode[isize]('-42')! == -42 + assert decoder2.decode[LegacySigned]('-42')! == -42 + assert decoder2.decode[LegacyInteger]('{"value":-42}')!.value == -42 +} diff --git a/vlib/json2/tests/encode_struct_test.v b/vlib/json2/tests/encode_struct_test.v index e15194017e..71596aa672 100644 --- a/vlib/json2/tests/encode_struct_test.v +++ b/vlib/json2/tests/encode_struct_test.v @@ -22,8 +22,8 @@ type I16Alias = i16 type I32Alias = i32 type I64Alias = i64 type IntAlias = int -type UsizeAlias = usize -type IsizeAlias = isize +type UsizeAlias = uint +type IsizeAlias = int type F32Alias = f32 type F64Alias = f64 type TimeAlias = time.Time diff --git a/vlib/macos/macos.c.v b/vlib/macos/macos.c.v index 21d2648bff..fa891d68c7 100644 --- a/vlib/macos/macos.c.v +++ b/vlib/macos/macos.c.v @@ -35,11 +35,11 @@ pub mut: height f64 } -pub const assoc_assign = usize(0) -pub const assoc_retain_nonatomic = usize(1) -pub const assoc_copy_nonatomic = usize(3) -pub const assoc_retain = usize(0o1401) -pub const assoc_copy = usize(0o1403) +pub const assoc_assign = uint(0) +pub const assoc_retain_nonatomic = uint(1) +pub const assoc_copy_nonatomic = uint(3) +pub const assoc_retain = uint(0o1401) +pub const assoc_copy = uint(0o1403) pub const run_loop_default_mode = 'kCFRunLoopDefaultMode' fn C.macos_objc_msg_id0(obj Id, selector Sel) Id @@ -95,15 +95,15 @@ fn C.macos_objc_msg_f64(obj Id, selector Sel) f64 fn C.macos_objc_msg_rect(obj Id, selector Sel) Rect fn C.macos_objc_get_class(const_name &char) Class fn C.macos_sel_register_name(const_name &char) Sel -fn C.macos_objc_allocate_class_pair(superclass Class, const_name &char, extra_bytes usize) Class +fn C.macos_objc_allocate_class_pair(superclass Class, const_name &char, extra_bytes uint) Class fn C.macos_objc_register_class_pair(cls Class) fn C.macos_class_add_method(cls Class, name Sel, imp voidptr, const_types &char) bool -fn C.macos_class_add_ivar(cls Class, const_name &char, size usize, alignment u8, const_types &char) bool +fn C.macos_class_add_ivar(cls Class, const_name &char, size uint, alignment u8, const_types &char) bool fn C.macos_objc_get_protocol(const_name &char) Protocol fn C.macos_class_add_protocol(cls Class, protocol Protocol) bool fn C.macos_objc_set_ptr_ivar(obj Id, const_name &char, value voidptr) fn C.macos_objc_get_ptr_ivar(obj Id, const_name &char) voidptr -fn C.macos_set_associated_object(obj Id, const_key voidptr, value Id, policy usize) +fn C.macos_set_associated_object(obj Id, const_key voidptr, value Id, policy uint) fn C.macos_get_associated_object(obj Id, const_key voidptr) Id @[inline] @@ -491,8 +491,9 @@ pub fn autorelease_pool_new() Id { return new('NSAutoreleasePool') } +// set_associated_object associates value with obj and key using policy. @[inline] -pub fn set_associated_object(obj Id, key voidptr, value Id, policy usize) { +pub fn set_associated_object(obj Id, key voidptr, value Id, policy uint) { C.macos_set_associated_object(obj, key, value, policy) } diff --git a/vlib/math/math.v b/vlib/math/math.v index 368763a58c..720a85be49 100644 --- a/vlib/math/math.v +++ b/vlib/math/math.v @@ -67,7 +67,7 @@ pub: } // digits returns an array of the digits of `num` in the given optional `base`. -// The `num` argument accepts any integer type (i8|i16|int|isize|i64), and will be cast to i64 +// The `num` argument accepts any integer type (i8|i16|int|int|i64), and will be cast to i64 // The `base:` argument is optional, it will default to base: 10. // This function returns an array of the digits in reverse order i.e.: // Example: assert math.digits(12345, base: 10) == [5,4,3,2,1] @@ -111,7 +111,7 @@ pub fn digits(num i64, params DigitParams) []int { } // count_digits return the number of digits in the number passed. -// Number argument accepts any integer type (i8|i16|int|isize|i64) and will be cast to i64 +// Number argument accepts any integer type (i8|i16|int|int|i64) and will be cast to i64 pub fn count_digits(number i64) int { mut n := number if n == 0 { diff --git a/vlib/net/aasocket.c.v b/vlib/net/aasocket.c.v index a48c9d6fb0..0dc28f69e6 100644 --- a/vlib/net/aasocket.c.v +++ b/vlib/net/aasocket.c.v @@ -74,17 +74,17 @@ $if !windows { // fn C.connect(sockfd int, addr &C.sockaddr, addrlen C.socklen_t) int fn C.connect(sockfd i32, addr voidptr, addrlen u32) i32 -// fn C.send(sockfd int, buf voidptr, len usize, flags int) usize -fn C.send(sockfd i32, buf voidptr, len usize, flags i32) i32 +// fn C.send(sockfd int, buf voidptr, len uint, flags int) uint +fn C.send(sockfd i32, buf voidptr, len uint, flags i32) i32 -// fn C.sendto(sockfd int, buf voidptr, len usize, flags int, dest_add &C.sockaddr, addrlen C.socklen_t) usize -fn C.sendto(sockfd i32, buf voidptr, len usize, flags i32, dest_add voidptr, addrlen u32) i32 +// fn C.sendto(sockfd int, buf voidptr, len uint, flags int, dest_add &C.sockaddr, addrlen C.socklen_t) uint +fn C.sendto(sockfd i32, buf voidptr, len uint, flags i32, dest_add voidptr, addrlen u32) i32 -// fn C.recv(sockfd int, buf voidptr, len usize, flags int) usize -fn C.recv(sockfd i32, buf voidptr, len usize, flags i32) i32 +// fn C.recv(sockfd int, buf voidptr, len uint, flags int) uint +fn C.recv(sockfd i32, buf voidptr, len uint, flags i32) i32 -// fn C.recvfrom(sockfd int, buf voidptr, len usize, flags int, src_addr &C.sockaddr, addrlen &C.socklen_t) usize -fn C.recvfrom(sockfd i32, buf voidptr, len usize, flags i32, src_addr voidptr, addrlen &u32) i32 +// fn C.recvfrom(sockfd int, buf voidptr, len uint, flags int, src_addr &C.sockaddr, addrlen &C.socklen_t) uint +fn C.recvfrom(sockfd i32, buf voidptr, len uint, flags i32, src_addr voidptr, addrlen &u32) i32 fn C.shutdown(socket i32, how i32) i32 diff --git a/vlib/net/html/allocation_growth_test.v b/vlib/net/html/allocation_growth_test.v index 6312518e8e..666ae52961 100644 --- a/vlib/net/html/allocation_growth_test.v +++ b/vlib/net/html/allocation_growth_test.v @@ -19,7 +19,7 @@ fn test_tree_growth_keeps_parent_and_child_indices() { assert tree.get_parent() == 0 } -fn allocation_growth_bytes(fragment string, count int) usize { +fn allocation_growth_bytes(fragment string, count int) uint { page := fragment.repeat(count) before := gc_heap_usage().total_bytes doc := parse(page) diff --git a/vlib/net/http/backend_vschannel_windows.c.v b/vlib/net/http/backend_vschannel_windows.c.v index 334f458298..88299d4bd5 100644 --- a/vlib/net/http/backend_vschannel_windows.c.v +++ b/vlib/net/http/backend_vschannel_windows.c.v @@ -25,7 +25,7 @@ fn C.vschannel_request_on_open(&C.TlsContext, &u8, u32, &&char, fn (voidptr, i64 // Match the void-pointer allocator callback expected by SChannel. fn vschannel_realloc(buffer voidptr, new_size i64) voidptr { - return unsafe { v_realloc(&u8(buffer), isize(new_size)) } + return unsafe { v_realloc(&u8(buffer), int(new_size)) } } fn vschannel_ssl_do(req &Request, port int, method Method, host_name string, path string, data string, header Header) !Response { diff --git a/vlib/net/http/request.v b/vlib/net/http/request.v index 5a01f37794..7043067389 100644 --- a/vlib/net/http/request.v +++ b/vlib/net/http/request.v @@ -99,37 +99,37 @@ fn (mut req Request) free() { for i := 0; i < req.header.cur_pos; i++ { mut key := req.header.data[i].key mut value := req.header.data[i].value - key_ptr := u64(usize(key.str)) + key_ptr := u64(uint(key.str)) if key_ptr !in freed_ptrs { key.free() freed_ptrs[key_ptr] = true } - value_ptr := u64(usize(value.str)) + value_ptr := u64(uint(value.str)) if value_ptr !in freed_ptrs { value.free() freed_ptrs[value_ptr] = true } } mut host := req.host - host_ptr := u64(usize(host.str)) + host_ptr := u64(uint(host.str)) if host_ptr !in freed_ptrs { host.free() freed_ptrs[host_ptr] = true } mut data := req.data - data_ptr := u64(usize(data.str)) + data_ptr := u64(uint(data.str)) if data_ptr !in freed_ptrs { data.free() freed_ptrs[data_ptr] = true } mut url := req.url - url_ptr := u64(usize(url.str)) + url_ptr := u64(uint(url.str)) if url_ptr !in freed_ptrs { url.free() freed_ptrs[url_ptr] = true } mut user_agent := req.user_agent - user_agent_ptr := u64(usize(user_agent.str)) + user_agent_ptr := u64(uint(user_agent.str)) if user_agent_ptr !in freed_ptrs { user_agent.free() freed_ptrs[user_agent_ptr] = true @@ -139,25 +139,25 @@ fn (mut req Request) free() { // there is no port to strip. The freed_ptrs guard is what keeps that // from being a double free, here as for every other field. mut remote_addr := req.remote_addr - remote_addr_ptr := u64(usize(remote_addr.str)) + remote_addr_ptr := u64(uint(remote_addr.str)) if remote_addr_ptr !in freed_ptrs { remote_addr.free() freed_ptrs[remote_addr_ptr] = true } mut verify := req.verify - verify_ptr := u64(usize(verify.str)) + verify_ptr := u64(uint(verify.str)) if verify_ptr !in freed_ptrs { verify.free() freed_ptrs[verify_ptr] = true } mut cert := req.cert - cert_ptr := u64(usize(cert.str)) + cert_ptr := u64(uint(cert.str)) if cert_ptr !in freed_ptrs { cert.free() freed_ptrs[cert_ptr] = true } mut cert_key := req.cert_key - cert_key_ptr := u64(usize(cert_key.str)) + cert_key_ptr := u64(uint(cert_key.str)) if cert_key_ptr !in freed_ptrs { cert_key.free() freed_ptrs[cert_key_ptr] = true diff --git a/vlib/net/mbedtls/entropy_callback_test.c.v b/vlib/net/mbedtls/entropy_callback_test.c.v index e783beff68..0e1de3139d 100644 --- a/vlib/net/mbedtls/entropy_callback_test.c.v +++ b/vlib/net/mbedtls/entropy_callback_test.c.v @@ -6,11 +6,11 @@ fn test_entropy_callback_preserves_integer_result() { defer { C.mbedtls_entropy_free(&entropy) } mut output := [32]u8{} callback := C.mbedtls_entropy_func - status := callback(voidptr(&entropy), &output[0], usize(output.len)) + status := callback(voidptr(&entropy), &output[0], uint(output.len)) assert status == 0 } -fn reject_entropy(_ voidptr, _ &u8, _ usize) int { +fn reject_entropy(_ voidptr, _ &u8, _ uint) int { return -1 } diff --git a/vlib/net/mbedtls/mbedtls.c.v b/vlib/net/mbedtls/mbedtls.c.v index 7a176ce6c0..6d8f287270 100644 --- a/vlib/net/mbedtls/mbedtls.c.v +++ b/vlib/net/mbedtls/mbedtls.c.v @@ -195,51 +195,51 @@ pub struct C.mbedtls_x509_crl {} fn C.mbedtls_net_init(&C.mbedtls_net_context) fn C.mbedtls_net_connect(&C.mbedtls_net_context, &char, &char, i32) i32 fn C.mbedtls_net_bind(&C.mbedtls_net_context, &char, &char, i32) i32 -fn C.mbedtls_net_accept(&C.mbedtls_net_context, &C.mbedtls_net_context, voidptr, usize, &usize) i32 -fn C.mbedtls_net_recv(voidptr, &u8, usize) i32 -fn C.mbedtls_net_send(voidptr, &u8, usize) i32 -fn C.mbedtls_net_recv_timeout(voidptr, &u8, usize, u32) i32 +fn C.mbedtls_net_accept(&C.mbedtls_net_context, &C.mbedtls_net_context, voidptr, uint, &uint) i32 +fn C.mbedtls_net_recv(voidptr, &u8, uint) i32 +fn C.mbedtls_net_send(voidptr, &u8, uint) i32 +fn C.mbedtls_net_recv_timeout(voidptr, &u8, uint, u32) i32 fn C.mbedtls_net_free(&C.mbedtls_net_context) fn C.mbedtls_ssl_init(&C.mbedtls_ssl_context) fn C.mbedtls_ssl_setup(&C.mbedtls_ssl_context, &C.mbedtls_ssl_config) i32 fn C.mbedtls_ssl_session_reset(&C.mbedtls_ssl_context) fn C.mbedtls_ssl_conf_authmode(&C.mbedtls_ssl_config, i32) -fn C.mbedtls_ssl_conf_rng(&C.mbedtls_ssl_config, fn (voidptr, &u8, usize) int, voidptr) -fn C.mbedtls_ssl_set_bio(&C.mbedtls_ssl_context, &C.mbedtls_net_context, fn (voidptr, &u8, usize) i32, fn (voidptr, &u8, usize) i32, fn (voidptr, &u8, usize, u32) i32) +fn C.mbedtls_ssl_conf_rng(&C.mbedtls_ssl_config, fn (voidptr, &u8, uint) int, voidptr) +fn C.mbedtls_ssl_set_bio(&C.mbedtls_ssl_context, &C.mbedtls_net_context, fn (voidptr, &u8, uint) i32, fn (voidptr, &u8, uint) i32, fn (voidptr, &u8, uint, u32) i32) fn C.mbedtls_ssl_conf_own_cert(&C.mbedtls_ssl_config, &C.mbedtls_x509_crt, &C.mbedtls_pk_context) i32 fn C.mbedtls_ssl_conf_ca_chain(&C.mbedtls_ssl_config, &C.mbedtls_x509_crt, &C.mbedtls_x509_crl) fn C.mbedtls_ssl_set_hostname(&C.mbedtls_ssl_context, &char) i32 fn C.mbedtls_ssl_handshake(&C.mbedtls_ssl_context) i32 -fn C.mbedtls_ssl_read(&C.mbedtls_ssl_context, &u8, usize) i32 -fn C.mbedtls_ssl_write(&C.mbedtls_ssl_context, &u8, usize) i32 +fn C.mbedtls_ssl_read(&C.mbedtls_ssl_context, &u8, uint) i32 +fn C.mbedtls_ssl_write(&C.mbedtls_ssl_context, &u8, uint) i32 fn C.mbedtls_ssl_free(&C.mbedtls_ssl_context) fn C.mbedtls_ssl_config_init(&C.mbedtls_ssl_config) fn C.mbedtls_ssl_config_defaults(&C.mbedtls_ssl_config, i32, i32, i32) i32 fn C.mbedtls_ssl_config_free(&C.mbedtls_ssl_config) -fn C.mbedtls_ssl_conf_sni(&C.mbedtls_ssl_config, fn (voidptr, &C.mbedtls_ssl_context, &u8, usize) int, voidptr) +fn C.mbedtls_ssl_conf_sni(&C.mbedtls_ssl_config, fn (voidptr, &C.mbedtls_ssl_context, &u8, uint) int, voidptr) fn C.mbedtls_ssl_set_hs_ca_chain(&C.mbedtls_ssl_config, &C.mbedtls_x509_crt, &C.mbedtls_x509_crl) fn C.mbedtls_ssl_set_hs_own_cert(&C.mbedtls_ssl_context, &C.mbedtls_x509_crt, &C.mbedtls_pk_context) i32 fn C.mbedtls_ssl_set_hs_authmode(&C.mbedtls_ssl_context, i32) fn C.mbedtls_pk_init(&C.mbedtls_pk_context) fn C.mbedtls_pk_free(&C.mbedtls_pk_context) -fn C.mbedtls_pk_parse_key(&C.mbedtls_pk_context, &u8, usize, &u8, usize, fn (voidptr, &u8, usize) int, +fn C.mbedtls_pk_parse_key(&C.mbedtls_pk_context, &u8, uint, &u8, uint, fn (voidptr, &u8, uint) int, voidptr) i32 -fn C.mbedtls_pk_parse_keyfile(&C.mbedtls_pk_context, &char, &char, fn (voidptr, &u8, usize) int, voidptr) i32 +fn C.mbedtls_pk_parse_keyfile(&C.mbedtls_pk_context, &char, &char, fn (voidptr, &u8, uint) int, voidptr) i32 fn C.mbedtls_ctr_drbg_init(&C.mbedtls_ctr_drbg_context) -fn C.mbedtls_ctr_drbg_seed(&C.mbedtls_ctr_drbg_context, fn (voidptr, &u8, usize) int, voidptr, &u8, usize) i32 +fn C.mbedtls_ctr_drbg_seed(&C.mbedtls_ctr_drbg_context, fn (voidptr, &u8, uint) int, voidptr, &u8, uint) i32 fn C.mbedtls_ctr_drbg_free(&C.mbedtls_ctr_drbg_context) -fn C.mbedtls_ctr_drbg_random(voidptr, &u8, usize) i32 +fn C.mbedtls_ctr_drbg_random(voidptr, &u8, uint) i32 fn C.mbedtls_entropy_init(&C.mbedtls_entropy_context) fn C.mbedtls_entropy_free(&C.mbedtls_entropy_context) -fn C.mbedtls_entropy_func(voidptr, &u8, usize) int +fn C.mbedtls_entropy_func(voidptr, &u8, uint) int fn C.mbedtls_x509_crt_init(&C.mbedtls_x509_crt) fn C.mbedtls_x509_crt_free(&C.mbedtls_x509_crt) -fn C.mbedtls_x509_crt_parse(&C.mbedtls_x509_crt, &u8, usize) i32 +fn C.mbedtls_x509_crt_parse(&C.mbedtls_x509_crt, &u8, uint) i32 fn C.mbedtls_x509_crt_parse_file(&C.mbedtls_x509_crt, &char) i32 // mbedtls_x509_crt_verify validates a certificate chain against a trust anchor, @@ -248,7 +248,7 @@ fn C.mbedtls_x509_crt_parse_file(&C.mbedtls_x509_crt, &char) i32 // default checks only. fn C.mbedtls_x509_crt_verify(&C.mbedtls_x509_crt, &C.mbedtls_x509_crt, &C.mbedtls_x509_crl, &char, &u32, fn (voidptr, &C.mbedtls_x509_crt, i32, &u32) i32, voidptr) i32 -fn C.mbedtls_pk_verify(&C.mbedtls_pk_context, i32, &u8, usize, &u8, usize) i32 +fn C.mbedtls_pk_verify(&C.mbedtls_pk_context, i32, &u8, uint, &u8, uint) i32 // mbedtls_pk_rsassa_pss_options mirrors mbedTLS's own struct (pk.h) // field-for-field rather than being kept opaque like mbedtls_x509_crt/ @@ -266,7 +266,7 @@ mut: // type (inc. RSASSA-PSS) and optional type-specific options -- see // x509_standalone.c.v's verify_ecdsa_signature/verify_rsa_pss_signature for // the two call shapes this codebase actually uses. -fn C.mbedtls_pk_verify_ext(i32, voidptr, &C.mbedtls_pk_context, i32, &u8, usize, &u8, usize) i32 +fn C.mbedtls_pk_verify_ext(i32, voidptr, &C.mbedtls_pk_context, i32, &u8, uint, &u8, uint) i32 // mbedtls_pk_sign_ext is not called by any production code yet -- v1 is // client-only and never sends a client CertificateVerify (CertificateRequest @@ -276,7 +276,7 @@ fn C.mbedtls_pk_verify_ext(i32, voidptr, &C.mbedtls_pk_context, i32, &u8, usize, // x509_standalone_signature_test.v's round-trip test needs genuine RSA-PSS // signatures to validate verify_rsa_pss_signature against real cryptography, // not just reasoning about C-binding parameter marshaling. -fn C.mbedtls_pk_sign_ext(i32, &C.mbedtls_pk_context, i32, &u8, usize, &u8, usize, &usize, fn (voidptr, &u8, usize) int, voidptr) i32 +fn C.mbedtls_pk_sign_ext(i32, &C.mbedtls_pk_context, i32, &u8, uint, &u8, uint, &uint, fn (voidptr, &u8, uint) int, voidptr) i32 // v_mbedtls_x509_crt_get_pk extracts the public-key context embedded in a // parsed certificate -- see mbedtls_helpers.h for why this needs a C shim diff --git a/vlib/net/mbedtls/ssl_connection.c.v b/vlib/net/mbedtls/ssl_connection.c.v index accabfa22c..827b6bbf34 100644 --- a/vlib/net/mbedtls/ssl_connection.c.v +++ b/vlib/net/mbedtls/ssl_connection.c.v @@ -335,7 +335,7 @@ fn (mut l SSLListener) init() ! { // See the matching client-side logic in SSLConn.init for lifetime notes. if l.config.alpn_protocols.len > 0 { n := l.config.alpn_protocols.len - l.alpn_list = unsafe { &&char(C.malloc(isize((n + 1) * int(sizeof(voidptr))))) } + l.alpn_list = unsafe { &&char(C.malloc(int((n + 1) * int(sizeof(voidptr))))) } if l.alpn_list == unsafe { nil } { l.shutdown() or {} return error('net.mbedtls SSLListener.init, failed to allocate ALPN list') @@ -366,7 +366,7 @@ fn (mut l SSLListener) init() ! { } } -fn tls_listener_rng(p_rng voidptr, output &u8, output_len usize) int { +fn tls_listener_rng(p_rng voidptr, output &u8, output_len uint) int { mut listener := unsafe { &SSLListener(p_rng) } listener.rng_mutex.lock() defer { @@ -380,7 +380,7 @@ fn (mut l SSLListener) init_sni(get_cert_callback fn (mut SSLListener, string) ! $if trace_ssl ? { eprintln(@METHOD) } - C.mbedtls_ssl_conf_sni(&l.conf, fn [get_cert_callback, mut l] (p_info voidptr, ssl &C.mbedtls_ssl_context, name &u8, lng usize) int { + C.mbedtls_ssl_conf_sni(&l.conf, fn [get_cert_callback, mut l] (p_info voidptr, ssl &C.mbedtls_ssl_context, name &u8, lng uint) int { host := unsafe { name.vstring_literal_with_len(int(lng)) } if certs := get_cert_callback(mut l, host) { return C.mbedtls_ssl_set_hs_own_cert(ssl, &certs.client_cert, &certs.client_key) @@ -417,7 +417,7 @@ fn (mut l SSLListener) accept_tcp_connection() !&SSLConn { opened: true } ip := [16]u8{} - iplen := usize(0) + iplen := uint(0) ret := C.mbedtls_net_accept(&l.server_fd, &conn.server_fd, &ip, 16, &iplen) if ret != 0 { @@ -697,7 +697,7 @@ fn (mut s SSLConn) init() ! { // is allocated here and freed in shutdown(). if s.config.alpn_protocols.len > 0 { n := s.config.alpn_protocols.len - s.alpn_list = unsafe { &&char(C.malloc(isize((n + 1) * int(sizeof(voidptr))))) } + s.alpn_list = unsafe { &&char(C.malloc(int((n + 1) * int(sizeof(voidptr))))) } if s.alpn_list == unsafe { nil } { return error('net.mbedtls SSLConn.init, failed to allocate ALPN list') } diff --git a/vlib/net/mbedtls/x509_standalone.c.v b/vlib/net/mbedtls/x509_standalone.c.v index b44799fcba..6c4fe99390 100644 --- a/vlib/net/mbedtls/x509_standalone.c.v +++ b/vlib/net/mbedtls/x509_standalone.c.v @@ -60,7 +60,7 @@ pub fn build_certificate_chain(der_certs [][]u8) !&C.mbedtls_x509_crt { mut chain := &C.mbedtls_x509_crt{} C.mbedtls_x509_crt_init(chain) for i, der in der_certs { - ret := C.mbedtls_x509_crt_parse(chain, der.data, usize(der.len)) + ret := C.mbedtls_x509_crt_parse(chain, der.data, uint(der.len)) if ret != 0 { C.mbedtls_x509_crt_free(chain) return error_with_code('net.mbedtls: failed to parse certificate ${i} of ${der_certs.len} in the chain, mbedtls ret: ${ret}', @@ -144,7 +144,7 @@ pub fn public_key_curve_is_secp256r1(pk &C.mbedtls_pk_context) bool { // MBEDTLS_PK_ECKEY-typed key, not assumed from the type names alone. pub fn verify_ecdsa_signature(pk &C.mbedtls_pk_context, md_alg MbedtlsMdType, hash []u8, signature []u8) ! { ret := C.mbedtls_pk_verify_ext(pk_type_ecdsa, unsafe { nil }, pk, i32(md_alg), hash.data, - usize(hash.len), signature.data, usize(signature.len)) + uint(hash.len), signature.data, uint(signature.len)) if ret != 0 { return error_with_code('net.mbedtls: ECDSA signature verification failed, mbedtls ret: ${ret}', ret) @@ -174,7 +174,7 @@ pub fn verify_rsa_pss_signature(pk &C.mbedtls_pk_context, md_alg MbedtlsMdType, expected_salt_len: hash.len } ret := C.mbedtls_pk_verify_ext(pk_type_rsassa_pss, &opts, pk, i32(md_alg), hash.data, - usize(hash.len), signature.data, usize(signature.len)) + uint(hash.len), signature.data, uint(signature.len)) if ret != 0 { return error_with_code('net.mbedtls: RSA-PSS signature verification failed, mbedtls ret: ${ret}', ret) @@ -215,7 +215,7 @@ pub fn verify_certificate_chain(chain &C.mbedtls_x509_crt, ca_bundle_pem string, // PEM-parsing call site's own convention in this module // (new_sslcerts_in_memory_with_rng et al., which all pass `.str`). parse_ret := C.mbedtls_x509_crt_parse(&ca_chain, ca_bundle_pem.str, - usize(ca_bundle_pem.len + 1)) + uint(ca_bundle_pem.len + 1)) // != 0, not < 0: for a PEM bundle specifically (unlike the DER path in // build_certificate_chain), mbedtls_x509_crt_parse can return a // POSITIVE count of certificates it failed to parse when others in the diff --git a/vlib/net/mbedtls/x509_standalone_signature_test.v b/vlib/net/mbedtls/x509_standalone_signature_test.v index 12911174da..fe951d1997 100644 --- a/vlib/net/mbedtls/x509_standalone_signature_test.v +++ b/vlib/net/mbedtls/x509_standalone_signature_test.v @@ -58,9 +58,9 @@ fn sign_rsa_pss_for_test(md_alg MbedtlsMdType, hash []u8) ![]u8 { // (512-byte) modulus -- the largest signature mbedtls_pk_sign_ext could // possibly produce for it. mut sig := []u8{len: 600} - mut sig_len := usize(0) - ret := C.mbedtls_pk_sign_ext(pk_type_rsassa_pss, &pk, i32(md_alg), hash.data, usize(hash.len), - sig.data, usize(sig.len), &sig_len, C.mbedtls_ctr_drbg_random, &ctr_drbg) + mut sig_len := uint(0) + ret := C.mbedtls_pk_sign_ext(pk_type_rsassa_pss, &pk, i32(md_alg), hash.data, uint(hash.len), + sig.data, uint(sig.len), &sig_len, C.mbedtls_ctr_drbg_random, &ctr_drbg) if ret != 0 { return error_with_code('test: mbedtls_pk_sign_ext failed, mbedtls ret: ${ret}', ret) } diff --git a/vlib/net/mbedtls/x509_standalone_test.v b/vlib/net/mbedtls/x509_standalone_test.v index 62259d0d2e..3496f07100 100644 --- a/vlib/net/mbedtls/x509_standalone_test.v +++ b/vlib/net/mbedtls/x509_standalone_test.v @@ -28,7 +28,7 @@ fn test_x509_parse_and_verify_without_ssl_context() { // exactly .len bytes with no trailing NUL, so len+1 with that buffer // reads one byte past the allocation (confirmed via ASan: // heap-buffer-overflow in mbedtls_x509_crt_parse). - parse_res := C.mbedtls_x509_crt_parse(&crt, standalone_test_cert.str, usize(standalone_test_cert.len + 1)) + parse_res := C.mbedtls_x509_crt_parse(&crt, standalone_test_cert.str, uint(standalone_test_cert.len + 1)) assert parse_res == 0, 'mbedtls_x509_crt_parse failed standalone (no ssl_context in scope): ${parse_res}' // Verify the self-signed leaf cert against itself as the sole trust diff --git a/vlib/net/openssl/openssl.c.v b/vlib/net/openssl/openssl.c.v index 14dc2fb7e8..42002ed96f 100644 --- a/vlib/net/openssl/openssl.c.v +++ b/vlib/net/openssl/openssl.c.v @@ -118,13 +118,13 @@ fn C.SSL_CTX_use_certificate_chain_file(ctx &C.SSL_CTX, const_file &char) i32 fn C.SSL_CTX_use_PrivateKey_file(ctx &C.SSL_CTX, const_file &char, file_type i32) i32 -fn C.v_net_openssl_SSL_CTX_use_certificate_chain_memory(ctx &C.SSL_CTX, data &u8, len usize) i32 +fn C.v_net_openssl_SSL_CTX_use_certificate_chain_memory(ctx &C.SSL_CTX, data &u8, len uint) i32 fn C.v_net_openssl_SSL_CTX_extra_chain_certs_count(ctx &C.SSL_CTX) int -fn C.v_net_openssl_SSL_CTX_use_PrivateKey_memory(ctx &C.SSL_CTX, data &u8, len usize) i32 +fn C.v_net_openssl_SSL_CTX_use_PrivateKey_memory(ctx &C.SSL_CTX, data &u8, len uint) i32 -fn C.v_net_openssl_SSL_CTX_load_verify_memory(ctx &C.SSL_CTX, data &u8, len usize) i32 +fn C.v_net_openssl_SSL_CTX_load_verify_memory(ctx &C.SSL_CTX, data &u8, len uint) i32 fn C.v_net_openssl_SSL_CTX_load_client_CA_file(ctx &C.SSL_CTX, const_file &char) i32 @@ -146,7 +146,7 @@ fn C.v_net_openssl_has_x509_identity_checks() int fn C.X509_free(const_cert &C.X509) -fn C.v_net_openssl_x509_check_host(const_cert &C.X509, const_name &char, name_len usize, flags u32, peer_name &&char) int +fn C.v_net_openssl_x509_check_host(const_cert &C.X509, const_name &char, name_len uint, flags u32, peer_name &&char) int fn C.v_net_openssl_x509_check_ip_asc(const_cert &C.X509, const_ip_asc &char, flags u32) int @@ -154,7 +154,7 @@ fn C.ERR_clear_error() fn C.ERR_get_error() u64 -fn C.ERR_error_string_n(e u64, buf &char, len usize) +fn C.ERR_error_string_n(e u64, buf &char, len uint) fn C.SSL_get_error(ssl &C.SSL, ret i32) i32 @@ -215,7 +215,7 @@ fn ssl_get_error_queue() string { break } mut buf := [256]char{} - C.ERR_error_string_n(code, &buf[0], usize(buf.len)) + C.ERR_error_string_n(code, &buf[0], uint(buf.len)) reasons << unsafe { cstring_to_vstring(&buf[0]) } } return reasons.join('; ') diff --git a/vlib/net/openssl/ssl_connection.c.v b/vlib/net/openssl/ssl_connection.c.v index b2afdbee31..cad680cc4a 100644 --- a/vlib/net/openssl/ssl_connection.c.v +++ b/vlib/net/openssl/ssl_connection.c.v @@ -190,7 +190,7 @@ fn (mut s SSLConn) init() ! { C.SSL_CTX_set_default_verify_paths(s.sslctx) } else if s.config.in_memory_verification { C.v_net_openssl_SSL_CTX_load_verify_memory(s.sslctx, s.config.verify.str, - usize(s.config.verify.len)) + uint(s.config.verify.len)) } else { C.SSL_CTX_load_verify_locations(s.sslctx, &char(s.config.verify.str), unsafe { nil }) } @@ -206,7 +206,7 @@ fn (mut s SSLConn) init() ! { } certificate_result := if s.config.in_memory_verification { C.v_net_openssl_SSL_CTX_use_certificate_chain_memory(s.sslctx, s.config.cert.str, - usize(s.config.cert.len)) + uint(s.config.cert.len)) } else { C.SSL_CTX_use_certificate_chain_file(s.sslctx, &char(s.config.cert.str)) } @@ -215,7 +215,7 @@ fn (mut s SSLConn) init() ! { } key_result := if s.config.in_memory_verification { C.v_net_openssl_SSL_CTX_use_PrivateKey_memory(s.sslctx, s.config.cert_key.str, - usize(s.config.cert_key.len)) + uint(s.config.cert_key.len)) } else { C.SSL_CTX_use_PrivateKey_file(s.sslctx, &char(s.config.cert_key.str), C.SSL_FILETYPE_PEM) } @@ -315,7 +315,7 @@ fn (s &SSLConn) verify_hostname(hostname string) ! { } ip_result := C.v_net_openssl_x509_check_ip_asc(cert, &char(hostname.str), 0) verified := if ip_result == -2 { - C.v_net_openssl_x509_check_host(cert, &char(hostname.str), usize(hostname.len), 0, + C.v_net_openssl_x509_check_host(cert, &char(hostname.str), uint(hostname.len), 0, unsafe { nil }) == 1 } else { ip_result == 1 diff --git a/vlib/net/openssl/ssl_listener.c.v b/vlib/net/openssl/ssl_listener.c.v index 002b447225..e33e26131a 100644 --- a/vlib/net/openssl/ssl_listener.c.v +++ b/vlib/net/openssl/ssl_listener.c.v @@ -78,20 +78,20 @@ fn (mut l SSLListener) init() ! { if l.config.in_memory_verification { mut res := C.v_net_openssl_SSL_CTX_use_certificate_chain_memory(l.sslctx, - l.config.cert.str, usize(l.config.cert.len)) + l.config.cert.str, uint(l.config.cert.len)) if res != 1 { l.shutdown() or {} return error('net.openssl SSLListener.init, could not load certificate from memory') } res = C.v_net_openssl_SSL_CTX_use_PrivateKey_memory(l.sslctx, l.config.cert_key.str, - usize(l.config.cert_key.len)) + uint(l.config.cert_key.len)) if res != 1 { l.shutdown() or {} return error('net.openssl SSLListener.init, could not load private key from memory') } if l.config.validate { res = C.v_net_openssl_SSL_CTX_load_verify_memory(l.sslctx, l.config.verify.str, - usize(l.config.verify.len)) + uint(l.config.verify.len)) if res != 1 { l.shutdown() or {} return error('net.openssl SSLListener.init, could not load root CA from memory') diff --git a/vlib/net/quic/conn_test.v b/vlib/net/quic/conn_test.v index 87628a5e56..fabc94318b 100644 --- a/vlib/net/quic/conn_test.v +++ b/vlib/net/quic/conn_test.v @@ -58,8 +58,8 @@ fn conn_test_sign_certificate_verify(signed_content []u8) ![]u8 { } // pk_type 6 = MBEDTLS_PK_RSASSA_PSS, md_alg 9 = MBEDTLS_MD_SHA256. mut sig := []u8{len: 600} - mut sig_len := usize(0) - ret := C.mbedtls_pk_sign_ext(6, &pk, 9, hash.data, usize(hash.len), sig.data, usize(sig.len), &sig_len, C.mbedtls_ctr_drbg_random, &ctr_drbg) + mut sig_len := uint(0) + ret := C.mbedtls_pk_sign_ext(6, &pk, 9, hash.data, uint(hash.len), sig.data, uint(sig.len), &sig_len, C.mbedtls_ctr_drbg_random, &ctr_drbg) if ret != 0 { return error('test: mbedtls_pk_sign_ext failed, mbedtls ret: ${ret}') } diff --git a/vlib/net/quic/h3_conn_test.v b/vlib/net/quic/h3_conn_test.v index b8cd01f0e7..ea1e06b5ba 100644 --- a/vlib/net/quic/h3_conn_test.v +++ b/vlib/net/quic/h3_conn_test.v @@ -60,8 +60,8 @@ fn conn_test_sign_certificate_verify(signed_content []u8) ![]u8 { } // pk_type 6 = MBEDTLS_PK_RSASSA_PSS, md_alg 9 = MBEDTLS_MD_SHA256. mut sig := []u8{len: 600} - mut sig_len := usize(0) - ret := C.mbedtls_pk_sign_ext(6, &pk, 9, hash.data, usize(hash.len), sig.data, usize(sig.len), &sig_len, C.mbedtls_ctr_drbg_random, &ctr_drbg) + mut sig_len := uint(0) + ret := C.mbedtls_pk_sign_ext(6, &pk, 9, hash.data, uint(hash.len), sig.data, uint(sig.len), &sig_len, C.mbedtls_ctr_drbg_random, &ctr_drbg) if ret != 0 { return error('test: mbedtls_pk_sign_ext failed, mbedtls ret: ${ret}') } diff --git a/vlib/net/quic/tls13_handshake_test.v b/vlib/net/quic/tls13_handshake_test.v index 9e84c2bfbf..90f50d664f 100644 --- a/vlib/net/quic/tls13_handshake_test.v +++ b/vlib/net/quic/tls13_handshake_test.v @@ -64,8 +64,8 @@ fn fake_server_sign_certificate_verify(signed_content []u8) ![]u8 { // verify_rsa_pss_signature uses on the verify side (pk.h/md.h, // confirmed there, not re-derived here). mut sig := []u8{len: 600} - mut sig_len := usize(0) - ret := C.mbedtls_pk_sign_ext(6, &pk, 9, hash.data, usize(hash.len), sig.data, usize(sig.len), &sig_len, C.mbedtls_ctr_drbg_random, &ctr_drbg) + mut sig_len := uint(0) + ret := C.mbedtls_pk_sign_ext(6, &pk, 9, hash.data, uint(hash.len), sig.data, uint(sig.len), &sig_len, C.mbedtls_ctr_drbg_random, &ctr_drbg) if ret != 0 { return error('test: mbedtls_pk_sign_ext failed, mbedtls ret: ${ret}') } diff --git a/vlib/net/websocket/reactor_linux.c.v b/vlib/net/websocket/reactor_linux.c.v index b8d02614a8..e9a6a5dba9 100644 --- a/vlib/net/websocket/reactor_linux.c.v +++ b/vlib/net/websocket/reactor_linux.c.v @@ -30,7 +30,7 @@ fn C.epoll_create1(int) int fn C.epoll_ctl(int, int, int, &C.epoll_event) int fn C.epoll_wait(int, &C.epoll_event, int, int) int fn C.eventfd(u32, int) int -fn C.pthread_self() usize +fn C.pthread_self() uint // ReactorOptions configures an optional Linux plaintext server transport. // Callbacks run serially on the owning worker, must not block, and borrow each diff --git a/vlib/os/fd.c.v b/vlib/os/fd.c.v index 37780f85bd..57cab1175f 100644 --- a/vlib/os/fd.c.v +++ b/vlib/os/fd.c.v @@ -30,7 +30,7 @@ pub fn fd_write(fd int, s string) { return } remaining = remaining - written - sp = unsafe { voidptr(usize(sp) + usize(written)) } + sp = unsafe { voidptr(uint(sp) + uint(written)) } } } diff --git a/vlib/os/fifo_nix.c.v b/vlib/os/fifo_nix.c.v index a5cb8ec700..db52ca4d3d 100644 --- a/vlib/os/fifo_nix.c.v +++ b/vlib/os/fifo_nix.c.v @@ -41,7 +41,7 @@ fn fifo_read_nix(f File, mut buf []u8) !int { if !f.is_opened { return error_file_not_opened() } if buf.len == 0 { return Eof{} } for { - n := C.read(f.fd, buf.data, usize(buf.len)) + n := C.read(f.fd, buf.data, uint(buf.len)) if n < 0 { if C.errno == C.EINTR { continue } return error_posix() @@ -56,7 +56,7 @@ fn fifo_read_nix(f File, mut buf []u8) !int { fn fifo_write_nix(f File, buf []u8) !int { if !f.is_opened { return error_file_not_opened() } for { - n := C.write(f.fd, buf.data, usize(buf.len)) + n := C.write(f.fd, buf.data, uint(buf.len)) if n < 0 { if C.errno == C.EINTR { continue } return error_posix() diff --git a/vlib/os/file.c.v b/vlib/os/file.c.v index 6848208400..2e38be56d7 100644 --- a/vlib/os/file.c.v +++ b/vlib/os/file.c.v @@ -270,7 +270,7 @@ pub fn (mut f File) writeln(s string) !int { // write_string writes the string `s` into the file. // It returns how many bytes were actually written. pub fn (mut f File) write_string(s string) !int { - unsafe { f.write_full_buffer(s.str, usize(s.len))! } + unsafe { f.write_full_buffer(s.str, uint(s.len))! } return s.len } @@ -304,8 +304,8 @@ pub fn (mut f File) write_ptr(data voidptr, size int) int { // address in `buffer`, no matter how many tries/partial writes it would take. // The size in bytes, of the `buffer`, should be passed in `buffer_len`. @[unsafe] -pub fn (mut f File) write_full_buffer(buffer voidptr, buffer_len usize) ! { - if buffer_len <= usize(0) { +pub fn (mut f File) write_full_buffer(buffer voidptr, buffer_len uint) ! { + if buffer_len <= uint(0) { return } if !f.is_opened { @@ -610,7 +610,7 @@ pub fn (mut f File) write_struct_at[T](t &T, pos u64) ! { if !f.is_opened { return error_file_not_opened() } - tsize := usize(sizeof(T)) + tsize := uint(sizeof(T)) if tsize == 0 { return error_size_of_type_0() } @@ -627,7 +627,7 @@ pub fn (mut f File) write_raw[T](t &T) ! { if !f.is_opened { return error_file_not_opened() } - tsize := usize(sizeof(T)) + tsize := uint(sizeof(T)) if tsize == 0 { return error_size_of_type_0() } @@ -640,7 +640,7 @@ pub fn (mut f File) write_raw_at[T](t &T, pos u64) ! { if !f.is_opened { return error_file_not_opened() } - tsize := usize(sizeof(T)) + tsize := uint(sizeof(T)) if tsize == 0 { return error_size_of_type_0() } diff --git a/vlib/os/file.js.v b/vlib/os/file.js.v index 3c1790c0dc..807560f1c7 100644 --- a/vlib/os/file.js.v +++ b/vlib/os/file.js.v @@ -138,7 +138,8 @@ pub fn (mut f File) close() { #$fs.closeSync(f.valueOf().fd.valueOf()) } -pub fn (mut f File) write_full_buffer(s voidptr, buffer_len usize) ! {} +// write_full_buffer writes buffer_len bytes from s to the file. +pub fn (mut f File) write_full_buffer(s voidptr, buffer_len uint) ! {} pub fn (mut f File) write_array(buffer array) !int { if !f.is_opened { diff --git a/vlib/os/file_buffering.c.v b/vlib/os/file_buffering.c.v index 32d1cef871..d357c3b434 100644 --- a/vlib/os/file_buffering.c.v +++ b/vlib/os/file_buffering.c.v @@ -1,6 +1,6 @@ module os -fn C.setvbuf(stream &C.FILE, buffer &char, mode i32, size usize) i32 +fn C.setvbuf(stream &C.FILE, buffer &char, mode i32, size uint) i32 // FileBufferMode describes the available buffering modes for an os.File: unbuffered, line buffered and block/fully buffered. // Normally all files are block buffered. If a stream refers to a terminal (as stdout normally does), it is line buffered. @@ -18,7 +18,7 @@ pub enum FileBufferMode { // Note: make sure, that the space, that buffer points to (when != 0), still exists by the time the file stream is closed, which also happens at program termination. // Note: f.setvbuf() may be used only after opening a file stream, and before any other operations have been performed on it. @[unsafe] -pub fn (mut f File) setvbuf(buffer &char, mode FileBufferMode, size usize) int { +pub fn (mut f File) setvbuf(buffer &char, mode FileBufferMode, size uint) int { return C.setvbuf(f.cfile, buffer, int(mode), size) } @@ -26,17 +26,17 @@ pub fn (mut f File) setvbuf(buffer &char, mode FileBufferMode, size usize) int { // Unlike File.setvbuf, it allows you to pass an existing V []u8 array directly. // Note: f.set_buffer() may be used only after opening a file stream, and before any other operations have been performed on it. pub fn (mut f File) set_buffer(mut buffer []u8, mode FileBufferMode) int { - return unsafe { f.setvbuf(buffer.data, mode, usize(buffer.len)) } + return unsafe { f.setvbuf(buffer.data, mode, uint(buffer.len)) } } // set_line_buffered sets the file buffering mode to FileBufferMode.line_buffered. // Note: f.set_line_buffered() may be used only after opening a file stream, and before any other operations have been performed on it. pub fn (mut f File) set_line_buffered() { - unsafe { f.setvbuf(&char(nil), .line_buffered, usize(0)) } + unsafe { f.setvbuf(&char(nil), .line_buffered, uint(0)) } } // set_unbuffered sets the file buffering mode to FileBufferMode.not_buffered. // Note: f.set_unbuffered() may be used only after opening a file stream, and before any other operations have been performed on it. pub fn (mut f File) set_unbuffered() { - unsafe { f.setvbuf(&char(nil), .not_buffered, usize(0)) } + unsafe { f.setvbuf(&char(nil), .not_buffered, uint(0)) } } diff --git a/vlib/os/file_le_be.c.v b/vlib/os/file_le_be.c.v index 51e0ac411f..ed3c52d3db 100644 --- a/vlib/os/file_le_be.c.v +++ b/vlib/os/file_le_be.c.v @@ -134,7 +134,7 @@ fn swap_bytes[T](input T) T { } } -fn check_cf(x usize, label string) ! { +fn check_cf(x uint, label string) ! { if C.errno != 0 { return error(posix_get_error_msg(C.errno)) } @@ -143,10 +143,10 @@ fn check_cf(x usize, label string) ! { } } -fn check_fwrite(x usize) ! { +fn check_fwrite(x uint) ! { check_cf(x, 'fwrite')! } -fn check_fread(x usize) ! { +fn check_fread(x uint) ! { check_cf(x, 'fread')! } diff --git a/vlib/os/mmap.v b/vlib/os/mmap.v index f4f6fa4867..f70503a36d 100644 --- a/vlib/os/mmap.v +++ b/vlib/os/mmap.v @@ -106,7 +106,7 @@ pub fn (mut m Mmap) close() { // mmap_check_length rejects lengths that cannot be represented as V array lengths. fn mmap_check_length(len u64) ! { if len == 0 { return error('os.mmap_create: length must be positive') } - if len > u64(max_int) || len > u64(max_i64) || u64(usize(len)) != len { + if len > u64(max_int) || len > u64(max_i64) || u64(uint(len)) != len { return error('os.mmap: length exceeds the supported array size') } } diff --git a/vlib/os/mmap_nix.c.v b/vlib/os/mmap_nix.c.v index 63e31706ff..b0140a5cf5 100644 --- a/vlib/os/mmap_nix.c.v +++ b/vlib/os/mmap_nix.c.v @@ -2,7 +2,7 @@ module os #include -fn C.msync(addr voidptr, len usize, flags i32) i32 +fn C.msync(addr voidptr, len uint, flags i32) i32 // mmap_map_nix opens path, maps len bytes and closes the fd again (the // mapping survives a closed fd on POSIX). With create it creates/truncates @@ -24,7 +24,7 @@ fn mmap_map_nix(path string, len u64, write bool, create bool) !voidptr { } } prot := if write { C.PROT_READ | C.PROT_WRITE } else { C.PROT_READ } - addr := C.mmap(unsafe { nil }, usize(len), prot, C.MAP_SHARED, fd, 0) + addr := C.mmap(unsafe { nil }, uint(len), prot, C.MAP_SHARED, fd, 0) C.close(fd) if addr == voidptr(C.MAP_FAILED) { return error('os: mmap of `${path}` failed') @@ -34,12 +34,12 @@ fn mmap_map_nix(path string, len u64, write bool, create bool) !voidptr { // mmap_unmap_nix releases a mapping. fn mmap_unmap_nix(addr voidptr, len u64) { - C.munmap(addr, usize(len)) + C.munmap(addr, uint(len)) } // mmap_sync_nix flushes a mapping to the file. fn mmap_sync_nix(addr voidptr, len u64) ! { - if C.msync(addr, usize(len), C.MS_SYNC) != 0 { + if C.msync(addr, uint(len), C.MS_SYNC) != 0 { return error('os: msync failed') } } diff --git a/vlib/os/mmap_windows.c.v b/vlib/os/mmap_windows.c.v index d1c0ad0f31..d91559a346 100644 --- a/vlib/os/mmap_windows.c.v +++ b/vlib/os/mmap_windows.c.v @@ -2,9 +2,9 @@ module os fn C.CreateFileMappingW(h voidptr, attrs voidptr, protect u32, maxhi u32, maxlo u32, name &u16) voidptr fn C.FlushFileBuffers(h voidptr) bool -fn C.MapViewOfFile(h voidptr, access u32, offhi u32, offlo u32, nbytes usize) voidptr +fn C.MapViewOfFile(h voidptr, access u32, offhi u32, offlo u32, nbytes uint) voidptr fn C.UnmapViewOfFile(addr voidptr) i32 -fn C.FlushViewOfFile(addr voidptr, nbytes usize) i32 +fn C.FlushViewOfFile(addr voidptr, nbytes uint) i32 const mmap_generic_read = u32(0x80000000) const mmap_generic_write = u32(0x40000000) @@ -35,7 +35,7 @@ fn mmap_map_windows(path string, len u64, write bool, create bool) !(voidptr, vo return error('os: cannot create file mapping for `${path}`') } view_access := if write { mmap_map_read | mmap_map_write } else { mmap_map_read } - addr := C.MapViewOfFile(h_map, view_access, 0, 0, usize(len)) + addr := C.MapViewOfFile(h_map, view_access, 0, 0, uint(len)) if addr == unsafe { nil } { C.CloseHandle(h_map) C.CloseHandle(h_file) @@ -57,7 +57,7 @@ fn mmap_unmap_windows(addr voidptr, mapping voidptr, file_handle voidptr) { // mmap_sync_windows flushes the view to the file. fn mmap_sync_windows(addr voidptr, len u64, file_handle voidptr) ! { - if C.FlushViewOfFile(addr, usize(len)) == 0 { + if C.FlushViewOfFile(addr, uint(len)) == 0 { return error('os: FlushViewOfFile failed') } if !C.FlushFileBuffers(file_handle) { return error('os: FlushFileBuffers failed') } diff --git a/vlib/os/notify/backend_darwin.c.v b/vlib/os/notify/backend_darwin.c.v index 389c76178d..a41822c564 100644 --- a/vlib/os/notify/backend_darwin.c.v +++ b/vlib/os/notify/backend_darwin.c.v @@ -7,17 +7,17 @@ import os pub struct C.kevent { mut: - ident usize + ident uint filter i16 flags u16 fflags u32 - data isize + data int udata voidptr } fn C.kqueue() i32 fn C.__kevent__(i32, voidptr, i32, voidptr, i32, voidptr) i32 -fn C.EV_SET(voidptr, usize, i16, u16, u32, isize, voidptr) +fn C.EV_SET(voidptr, uint, i16, u16, u32, C.ptrdiff_t, voidptr) // KqueueNotifier provides methods that implement FdNotifier using the // kqueue I/O event notification facility (macos, freeBSD, xxxBSD...unix only) @@ -89,7 +89,7 @@ const kqueue_error = u16(C.EV_ERROR) // ctl is a helper method for add, modify, and remove fn (mut kn KqueueNotifier) ctl(fd int, filter i16, flags u16) ! { event := [1]C.kevent{} - C.EV_SET(&event[0], usize(fd), filter, flags, 0, 0, unsafe { nil }) + C.EV_SET(&event[0], uint(fd), filter, flags, 0, 0, unsafe { nil }) if C.__kevent__(kn.kqueue_fd, &event[0], 1, unsafe { nil }, 0, unsafe { nil }) == -1 { return error(os.posix_get_error_msg(C.errno)) } diff --git a/vlib/os/os.c.v b/vlib/os/os.c.v index 1486d21f82..362229b48d 100644 --- a/vlib/os/os.c.v +++ b/vlib/os/os.c.v @@ -19,7 +19,7 @@ pub const args = arguments() fn C.readdir(voidptr) &C.dirent -fn C.readlink(pathname &char, buf &char, bufsiz usize) i32 +fn C.readlink(pathname &char, buf &char, bufsiz uint) i32 fn C.getline(voidptr, voidptr, voidptr) i32 @@ -60,7 +60,7 @@ fn write_file_direct(path string, text string) ! { return error('0 bytes written') } remaining -= written - sp = unsafe { &u8(voidptr(usize(sp) + usize(written))) } + sp = unsafe { &u8(voidptr(uint(sp) + uint(written))) } } } @@ -730,7 +730,7 @@ pub fn get_raw_line() string { } } } $else { - max := usize(0) + max := uint(0) buf := &u8(unsafe { nil }) mut str := '' @@ -782,7 +782,7 @@ pub fn get_raw_stdin() []u8 { } } } $else { - max := usize(0) + max := uint(0) buf := &u8(unsafe { nil }) nr_chars := unsafe { C.getline(voidptr(&buf), &max, C.stdin) } $if race ? { @@ -881,7 +881,7 @@ pub fn executable() string { return unsafe { cstring_to_vstring(self_path) } } $if freebsd { - bufsize := usize(max_path_buffer_size) + bufsize := uint(max_path_buffer_size) mib := [sysctl_ctl_kern, freebsd_kern_proc, freebsd_kern_proc_pathname, -1]! // C `int` mib buffer unsafe { C.sysctl(&mib[0], mib.len, &result[0], &bufsize, 0, 0) } res := unsafe { tos_clone(&result[0]) } @@ -895,7 +895,7 @@ pub fn executable() string { // See also https://github.com/gpakosz/whereami/blob/master/src/whereami.c#L591 // and https://github.com/ziglang/zig/issues/6718#issuecomment-711134120 . mut pbuf := unsafe { &&u8(&result[0]) } - bufsize := usize(max_path_buffer_size) + bufsize := uint(max_path_buffer_size) pid := C.getpid() mib := [sysctl_ctl_kern, openbsd_kern_proc_args, pid, openbsd_kern_proc_argv]! // C `int` mib buffer if unsafe { C.sysctl(&mib[0], mib.len, nil, &bufsize, nil, 0) } == 0 { @@ -1041,13 +1041,13 @@ fn relative_path_from_cwd(fpath string, buf voidptr, size int) int { // both parts, the separator and the terminator was compared with `size` above. unsafe { mut dst := &u8(buf) - C.memcpy(dst, cwd, usize(cwd_len)) + C.memcpy(dst, cwd, uint(cwd_len)) mut n := cwd_len if cwd[cwd_len - 1] != `/` { dst[n] = `/` n++ } - C.memcpy(dst + n, fpath.str, usize(fpath.len)) + C.memcpy(dst + n, fpath.str, uint(fpath.len)) dst[n + fpath.len] = 0 } return cwd_len @@ -1372,7 +1372,7 @@ pub fn write_file_array(path string, buffer array) ! { defer { f.close() } - unsafe { f.write_full_buffer(buffer.data, usize(buffer.len * buffer.element_size))! } + unsafe { f.write_full_buffer(buffer.data, uint(buffer.len * buffer.element_size))! } } // glob function searches for all the pathnames matching patterns and returns a diff --git a/vlib/os/os.v b/vlib/os/os.v index 94aeaafc14..4a97ce0916 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -669,7 +669,7 @@ pub fn write_file(path string, text string) ! { defer { f.close() } - unsafe { f.write_full_buffer(text.str, usize(text.len))! } + unsafe { f.write_full_buffer(text.str, uint(text.len))! } } pub struct ExecutableNotFoundError { diff --git a/vlib/os/os_android_outside_termux.c.v b/vlib/os/os_android_outside_termux.c.v index 8740e2dc00..10c34e1ae5 100644 --- a/vlib/os/os_android_outside_termux.c.v +++ b/vlib/os/os_android_outside_termux.c.v @@ -71,11 +71,11 @@ pub fn (a &Asset) get_length_64() i64 { return C.AAsset_getLength64(a) } -fn C.AAsset_read(&C.AAsset, voidptr, usize) i32 +fn C.AAsset_read(&C.AAsset, voidptr, uint) i32 // read attempts to read 'count' bytes of data from the current offset. // read returns the number of bytes read, zero on EOF, or < 0 on error. -pub fn (a &Asset) read(buffer voidptr, count usize) int { +pub fn (a &Asset) read(buffer voidptr, count uint) int { return C.AAsset_read(a, buffer, count) } @@ -99,7 +99,7 @@ pub fn read_apk_asset(path string) ![]u8 { len := asset.get_length() buf := []u8{len: len} for { - if asset.read(buf.data, usize(len)) > 0 { + if asset.read(buf.data, uint(len)) > 0 { break } } diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index e210e64b0d..bf030af137 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -50,11 +50,11 @@ fn C.uname(name &C.utsname) i32 fn C.symlink(&char, &char) i32 -fn C.readlink(&char, &char, usize) i32 +fn C.readlink(&char, &char, uint) i32 fn C.link(&char, &char) i32 -fn C.gethostname(&char, usize) i32 +fn C.gethostname(&char, uint) i32 // Note: not available on Android fn C.getlogin_r(&char, int) int fn C.getlogin() &char @@ -632,10 +632,10 @@ pub fn page_size() int { } struct C.statvfs { - f_bsize usize - f_blocks usize - f_bfree usize - f_bavail usize + f_bsize uint + f_blocks uint + f_bfree uint + f_bavail uint } // disk_usage returns disk usage of `path`. diff --git a/vlib/os/process_nix.c.v b/vlib/os/process_nix.c.v index 5062f65657..d5648a8315 100644 --- a/vlib/os/process_nix.c.v +++ b/vlib/os/process_nix.c.v @@ -93,7 +93,7 @@ fn (p &Process) unix_prepare_spawn() UnixSpawnPlan { // It is used between fork() and execve(), so it must not allocate. fn unix_child_write(s string) { if s.len > 0 { - unsafe { C.write(2, s.str, usize(s.len)) } + unsafe { C.write(2, s.str, uint(s.len)) } } } @@ -136,7 +136,7 @@ fn unix_child_report_errno(prefix string) { } buf[n] = `\n` n++ - unsafe { C.write(2, &buf[0], usize(n)) } + unsafe { C.write(2, &buf[0], uint(n)) } } fn (mut p Process) unix_spawn_process() int { diff --git a/vlib/os/signal_default.c.v b/vlib/os/signal_default.c.v index c36b0c2231..6c0825c64a 100644 --- a/vlib/os/signal_default.c.v +++ b/vlib/os/signal_default.c.v @@ -3,7 +3,7 @@ module os #flag -lpthread -fn C.pthread_self() usize +fn C.pthread_self() uint // g_main_thread_id and is_main_thread can be used to determine if the current thread is the main thread. // if need to get the tid of the main thread, can use the global variable g_main_thread_id diff --git a/vlib/os/signal_linux.c.v b/vlib/os/signal_linux.c.v index be38acbc7f..a1ac822ff5 100644 --- a/vlib/os/signal_linux.c.v +++ b/vlib/os/signal_linux.c.v @@ -3,7 +3,7 @@ module os #flag -lpthread -fn C.pthread_self() usize +fn C.pthread_self() uint // g_main_thread_id and is_main_thread can be used to determine if the current thread is the main thread. // if need to get the tid of the main thread, can use the global variable g_main_thread_id diff --git a/vlib/picoev/loop_macos.c.v b/vlib/picoev/loop_macos.c.v index 7f1e93fa03..ff77f3b7c9 100644 --- a/vlib/picoev/loop_macos.c.v +++ b/vlib/picoev/loop_macos.c.v @@ -6,15 +6,15 @@ module picoev fn C.kevent(i32, changelist voidptr, nchanges i32, eventlist voidptr, nevents i32, timeout &C.timespec) i32 fn C.kqueue() i32 -fn C.EV_SET(kev voidptr, ident usize, filter i16, flags u16, fflags u32, data isize, udata voidptr) +fn C.EV_SET(kev voidptr, ident uint, filter i16, flags u16, fflags u32, data C.ptrdiff_t, udata voidptr) pub struct C.kevent { pub mut: - ident usize + ident uint filter i16 flags u16 fflags u32 - data isize + data int udata voidptr } @@ -58,7 +58,7 @@ pub fn (mut pv Picoev) ev_set(index int, operation int, events int) { } filter = i16(filter) - C.EV_SET(&pv.loop.changelist[index], usize(pv.loop.changed_fds), filter, operation, 0, 0, 0) + C.EV_SET(&pv.loop.changelist[index], uint(pv.loop.changed_fds), filter, operation, 0, 0, 0) } // backend_build uses the lower 8 bits to store the old events and the higher 8 diff --git a/vlib/picohttpparser/response.c.v b/vlib/picohttpparser/response.c.v index 39f617fcb9..0fade8f924 100644 --- a/vlib/picohttpparser/response.c.v +++ b/vlib/picohttpparser/response.c.v @@ -109,7 +109,7 @@ pub fn (mut r Response) raw(response string) { r.write_string(response) } -fn C.send(sockfd i32, buf voidptr, len usize, flags i32) i32 +fn C.send(sockfd i32, buf voidptr, len uint, flags i32) i32 // Use per-send protection where picoev cannot configure SO_NOSIGPIPE on the // socket. This also protects calls made on worker threads, where changing the diff --git a/vlib/runtime/free_memory_impl_darwin.c.v b/vlib/runtime/free_memory_impl_darwin.c.v index 5839edc441..12c7d51210 100644 --- a/vlib/runtime/free_memory_impl_darwin.c.v +++ b/vlib/runtime/free_memory_impl_darwin.c.v @@ -28,7 +28,7 @@ fn C.v_runtime_free_memory_darwin(bytes &u64, code &i32) i32 #flag @VEXEROOT/vlib/runtime/free_memory_darwin.o -fn free_memory_impl() !usize { +fn free_memory_impl() !uint { $if macos || ios { mut bytes := u64(0) mut code := i32(0) @@ -39,7 +39,7 @@ fn free_memory_impl() !usize { if stage == 2 { return error('free_memory: `C.host_page_size()` return = ${code}') } - return usize(bytes) + return uint(bytes) } return error('free_memory: not implemented') } diff --git a/vlib/runtime/free_memory_impl_default.c.v b/vlib/runtime/free_memory_impl_default.c.v index 83da715c4c..e089ed9274 100644 --- a/vlib/runtime/free_memory_impl_default.c.v +++ b/vlib/runtime/free_memory_impl_default.c.v @@ -1,5 +1,5 @@ module runtime -fn free_memory_impl() !usize { +fn free_memory_impl() !uint { return error('free_memory: not implemented') } diff --git a/vlib/runtime/free_memory_impl_freebsd.c.v b/vlib/runtime/free_memory_impl_freebsd.c.v index 641004926d..54600d2e82 100644 --- a/vlib/runtime/free_memory_impl_freebsd.c.v +++ b/vlib/runtime/free_memory_impl_freebsd.c.v @@ -1,20 +1,20 @@ module runtime -fn C.sysctlnametomib(name charptr, mib &i32, len &usize) i32 +fn C.sysctlnametomib(name charptr, mib &i32, len &uint) i32 -fn free_memory_impl() !usize { +fn free_memory_impl() !uint { $if cross ? { return error('free_memory: not implemented') } $if !cross ? { $if freebsd { - page_size := usize(C.sysconf(C._SC_PAGESIZE)) + page_size := uint(C.sysconf(C._SC_PAGESIZE)) c_errno_1 := C.errno - if page_size == usize(-1) { + if page_size == uint(-1) { return error('free_memory: `C.sysconf()` return error code = ${c_errno_1}') } mut mib := [4]i32{} // C `int` mib buffer (sysctl name array) - mut len := usize(4) + mut len := uint(4) retval_2 := unsafe { C.sysctlnametomib(c'vm.stats.vm.v_free_count', &mib[0], &len) } @@ -23,7 +23,7 @@ fn free_memory_impl() !usize { return error('free_memory: `C.sysctlnametomib()` return error code = ${c_errno_2}') } mut free_pages := i32(0) // sysctl writes a 4-byte C int (bufsize 4) - bufsize := usize(4) + bufsize := uint(4) retval_3 := unsafe { C.sysctl(&mib[0], mib.len, &free_pages, &bufsize, 0, 0) } @@ -31,7 +31,7 @@ fn free_memory_impl() !usize { if retval_3 == -1 { return error('free_memory: `C.sysctl()` return error code = ${c_errno_3}') } - return page_size * usize(free_pages) + return page_size * uint(free_pages) } } return error('free_memory: not implemented') diff --git a/vlib/runtime/free_memory_impl_linux.c.v b/vlib/runtime/free_memory_impl_linux.c.v index 057108b5d6..37561c4e22 100644 --- a/vlib/runtime/free_memory_impl_linux.c.v +++ b/vlib/runtime/free_memory_impl_linux.c.v @@ -1,19 +1,19 @@ module runtime -fn free_memory_impl() !usize { +fn free_memory_impl() !uint { $if cross ? { return error('free_memory: not implemented') } $if !cross ? { $if linux { - page_size := usize(C.sysconf(C._SC_PAGESIZE)) + page_size := uint(C.sysconf(C._SC_PAGESIZE)) c_errno_1 := C.errno - if page_size == usize(-1) { + if page_size == uint(-1) { return error('free_memory: `C.sysconf(C._SC_PAGESIZE)` return error code = ${c_errno_1}') } - av_phys_pages := usize(C.sysconf(C._SC_AVPHYS_PAGES)) + av_phys_pages := uint(C.sysconf(C._SC_AVPHYS_PAGES)) c_errno_2 := C.errno - if av_phys_pages == usize(-1) { + if av_phys_pages == uint(-1) { return error('free_memory: `C.sysconf(C._SC_AVPHYS_PAGES)` return error code = ${c_errno_2}') } return page_size * av_phys_pages diff --git a/vlib/runtime/free_memory_impl_openbsd.c.v b/vlib/runtime/free_memory_impl_openbsd.c.v index 408bd2fc9f..c5da73299b 100644 --- a/vlib/runtime/free_memory_impl_openbsd.c.v +++ b/vlib/runtime/free_memory_impl_openbsd.c.v @@ -2,15 +2,15 @@ module runtime #flag @VEXEROOT/vlib/runtime/free_memory_openbsd.o -fn C.v_runtime_openbsd_free_memory(&usize) int +fn C.v_runtime_openbsd_free_memory(&uint) int -fn free_memory_impl() !usize { +fn free_memory_impl() !uint { $if cross ? { return error('free_memory: not implemented') } $if !cross ? { $if openbsd { - mut free_bytes := usize(0) + mut free_bytes := uint(0) retval := C.v_runtime_openbsd_free_memory(&free_bytes) c_errno := C.errno if retval == -1 { diff --git a/vlib/runtime/runtime_nix.c.v b/vlib/runtime/runtime_nix.c.v index b5005bd10c..296ede6f2f 100644 --- a/vlib/runtime/runtime_nix.c.v +++ b/vlib/runtime/runtime_nix.c.v @@ -13,15 +13,15 @@ pub fn nr_cpus() int { } // total_memory returns total physical memory found on the system. -pub fn total_memory() !usize { - page_size := usize(C.sysconf(C._SC_PAGESIZE)) +pub fn total_memory() !uint { + page_size := uint(C.sysconf(C._SC_PAGESIZE)) c_errno_1 := C.errno - if page_size == usize(-1) { + if page_size == uint(-1) { return error('total_memory: `C.sysconf(C._SC_PAGESIZE)` return error code = ${c_errno_1}') } - phys_pages := usize(C.sysconf(C._SC_PHYS_PAGES)) + phys_pages := uint(C.sysconf(C._SC_PHYS_PAGES)) c_errno_2 := C.errno - if phys_pages == usize(-1) { + if phys_pages == uint(-1) { return error('total_memory: `C.sysconf(C._SC_PHYS_PAGES)` return error code = ${c_errno_2}') } return page_size * phys_pages @@ -30,6 +30,6 @@ pub fn total_memory() !usize { // free_memory returns free physical memory found on the system. // Note: implementation available only on Darwin, FreeBSD, Linux, OpenBSD and // Windows. Otherwise, returns 'free_memory: not implemented'. -pub fn free_memory() !usize { +pub fn free_memory() !uint { return free_memory_impl()! } diff --git a/vlib/runtime/runtime_windows.c.v b/vlib/runtime/runtime_windows.c.v index 5ef5f55a34..7fbb6ddc50 100644 --- a/vlib/runtime/runtime_windows.c.v +++ b/vlib/runtime/runtime_windows.c.v @@ -4,8 +4,8 @@ import os @[typedef] pub struct C.MEMORYSTATUS { - dwTotalPhys usize - dwAvailPhys usize + dwTotalPhys uint + dwAvailPhys uint } fn C.GlobalMemoryStatus(&C.MEMORYSTATUS) @@ -22,14 +22,14 @@ pub fn nr_cpus() int { } // total_memory returns total physical memory found on the system. -pub fn total_memory() !usize { +pub fn total_memory() !uint { memory_status := C.MEMORYSTATUS{} C.GlobalMemoryStatus(&memory_status) return memory_status.dwTotalPhys } // free_memory returns free physical memory found on the system. -pub fn free_memory() !usize { +pub fn free_memory() !uint { memory_status := C.MEMORYSTATUS{} C.GlobalMemoryStatus(&memory_status) return memory_status.dwAvailPhys diff --git a/vlib/runtime/used_memory_freebsd.c.v b/vlib/runtime/used_memory_freebsd.c.v index 74fe661e20..54d7dfe246 100644 --- a/vlib/runtime/used_memory_freebsd.c.v +++ b/vlib/runtime/used_memory_freebsd.c.v @@ -19,9 +19,9 @@ const rlimit_rss = i32(5) // used_memory retrieves the current physical memory usage of the process. // TinyCC and kernels without kern.proc.rlimit_usage report peak resident memory. pub fn used_memory() !u64 { - page_size := usize(C.sysconf(C._SC_PAGESIZE)) + page_size := uint(C.sysconf(C._SC_PAGESIZE)) c_errno_1 := C.errno - if page_size == usize(-1) { + if page_size == uint(-1) { return error('used_memory: C.sysconf() return error code = ${c_errno_1}') } $if tinyc { @@ -30,7 +30,7 @@ pub fn used_memory() !u64 { mib := [sysctl_ctl_kern, sysctl_kern_proc, sysctl_kern_proc_rlimit_usage, C.getpid(), rlimit_rss]! mut bytes := u64(0) - mut length := usize(sizeof(u64)) + mut length := uint(sizeof(u64)) result := unsafe { C.sysctl(&mib[0], mib.len, &bytes, &length, nil, 0) } c_errno_2 := C.errno if result == 0 && length == sizeof(u64) && bytes != u64(-1) { diff --git a/vlib/runtime/used_memory_openbsd.c.v b/vlib/runtime/used_memory_openbsd.c.v index 47b2f5ca9c..02526a5973 100644 --- a/vlib/runtime/used_memory_openbsd.c.v +++ b/vlib/runtime/used_memory_openbsd.c.v @@ -10,9 +10,9 @@ fn C.getrusage(who i32, usage &C.rusage) i32 // used_memory retrieves the current physical memory usage of the process. pub fn used_memory() !u64 { - page_size := usize(C.sysconf(C._SC_PAGESIZE)) + page_size := uint(C.sysconf(C._SC_PAGESIZE)) c_errno_1 := C.errno - if page_size == usize(-1) { + if page_size == uint(-1) { return error('used_memory: C.sysconf() return error code = ${c_errno_1}') } diff --git a/vlib/runtime/used_memory_windows.c.v b/vlib/runtime/used_memory_windows.c.v index 6f0581ce9a..ab8251ed78 100644 --- a/vlib/runtime/used_memory_windows.c.v +++ b/vlib/runtime/used_memory_windows.c.v @@ -9,14 +9,14 @@ module runtime struct C.PROCESS_MEMORY_COUNTERS { cb u32 PageFaultCount u32 - PeakWorkingSetSize usize - WorkingSetSize usize - QuotaPeakPagedPoolUsage usize - QuotaPagedPoolUsage usize - QuotaPeakNonPagedPoolUsage usize - QuotaNonPagedPoolUsage usize - PagefileUsage usize - PeakPagefileUsage usize + PeakWorkingSetSize uint + WorkingSetSize uint + QuotaPeakPagedPoolUsage uint + QuotaPagedPoolUsage uint + QuotaPeakNonPagedPoolUsage uint + QuotaNonPagedPoolUsage uint + PagefileUsage uint + PeakPagefileUsage uint } fn C.K32GetProcessMemoryInfo(voidptr, &C.PROCESS_MEMORY_COUNTERS, u32) bool diff --git a/vlib/sokol/gfx/gfx.c.v b/vlib/sokol/gfx/gfx.c.v index ab4e38401b..b76cabb669 100644 --- a/vlib/sokol/gfx/gfx.c.v +++ b/vlib/sokol/gfx/gfx.c.v @@ -146,8 +146,9 @@ pub fn query_buffer_overflow(buf Buffer) bool { return C.sg_query_buffer_overflow(buf) } +// query_buffer_will_overflow reports whether appending size bytes would overflow buf. @[inline] -pub fn query_buffer_will_overflow(buf Buffer, size usize) bool { +pub fn query_buffer_will_overflow(buf Buffer, size uint) bool { return C.sg_query_buffer_will_overflow(buf, size) } diff --git a/vlib/sokol/gfx/gfx_funcs.c.v b/vlib/sokol/gfx/gfx_funcs.c.v index 22b6b93477..466f7ce133 100644 --- a/vlib/sokol/gfx/gfx_funcs.c.v +++ b/vlib/sokol/gfx/gfx_funcs.c.v @@ -28,7 +28,7 @@ fn C.sg_update_buffer(buf C.sg_buffer, data &C.sg_range) fn C.sg_update_image(img C.sg_image, data &C.sg_image_data) fn C.sg_append_buffer(buf C.sg_buffer, data &C.sg_range) i32 fn C.sg_query_buffer_overflow(buf C.sg_buffer) bool -fn C.sg_query_buffer_will_overflow(buf C.sg_buffer, size usize) bool +fn C.sg_query_buffer_will_overflow(buf C.sg_buffer, size uint) bool // rendering functions fn C.sg_begin_pass(const_pass &C.sg_pass) diff --git a/vlib/sokol/gfx/gfx_structs.c.v b/vlib/sokol/gfx/gfx_structs.c.v index 2de14a3fe9..8d02891ac2 100644 --- a/vlib/sokol/gfx/gfx_structs.c.v +++ b/vlib/sokol/gfx/gfx_structs.c.v @@ -142,7 +142,7 @@ pub fn (mut b Bindings) set_frag_image(index int, img Image) { pub fn (b &Bindings) update_vert_buffer(index int, data voidptr, element_size int, element_count int) { range := Range{ ptr: data - size: usize(element_size * element_count) + size: uint(element_size * element_count) } C.sg_update_buffer(b.vertex_buffers[index], &range) } @@ -150,7 +150,7 @@ pub fn (b &Bindings) update_vert_buffer(index int, data voidptr, element_size in pub fn (b &Bindings) append_vert_buffer(index int, data voidptr, element_size int, element_count int) int { range := Range{ ptr: data - size: usize(element_size * element_count) + size: uint(element_size * element_count) } return C.sg_append_buffer(b.vertex_buffers[index], &range) } @@ -158,7 +158,7 @@ pub fn (b &Bindings) append_vert_buffer(index int, data voidptr, element_size in pub fn (b &Bindings) update_index_buffer(data voidptr, element_size int, element_count int) { range := Range{ ptr: data - size: usize(element_size * element_count) + size: uint(element_size * element_count) } C.sg_update_buffer(b.index_buffer, &range) } @@ -166,7 +166,7 @@ pub fn (b &Bindings) update_index_buffer(data voidptr, element_size int, element pub fn (b &Bindings) append_index_buffer(data voidptr, element_size int, element_count int) int { range := Range{ ptr: data - size: usize(element_size * element_count) + size: uint(element_size * element_count) } return C.sg_append_buffer(b.index_buffer, &range) } @@ -215,12 +215,14 @@ pub fn (mut desc C.sg_shader_desc) set_frag_image(index int, name string) &Shade return desc } -pub fn (mut desc C.sg_shader_desc) set_vert_uniform_block_size(block_index int, size usize) &ShaderDesc { +// set_vert_uniform_block_size sets the byte size of a vertex uniform block. +pub fn (mut desc C.sg_shader_desc) set_vert_uniform_block_size(block_index int, size uint) &ShaderDesc { desc.vs.uniform_blocks[block_index].size = size return desc } -pub fn (mut desc C.sg_shader_desc) set_frag_uniform_block_size(block_index int, size usize) &ShaderDesc { +// set_frag_uniform_block_size sets the byte size of a fragment uniform block. +pub fn (mut desc C.sg_shader_desc) set_frag_uniform_block_size(block_index int, size uint) &ShaderDesc { desc.fs.uniform_blocks[block_index].size = size return desc } @@ -277,7 +279,7 @@ pub fn (mut desc ShaderStageDesc) set_image(index int, name string) ShaderStageD pub struct C.sg_shader_uniform_block_desc { pub mut: - size usize + size uint layout UniformLayout uniforms [16]ShaderUniformDesc } @@ -340,7 +342,7 @@ pub type ShaderInfo = C.sg_shader_info pub struct C.sg_range { pub mut: ptr voidptr - size usize + size uint } pub type Range = C.sg_range @@ -643,7 +645,7 @@ pub type Pass = C.sg_pass pub struct C.sg_buffer_desc { pub mut: _start_canary u32 - size usize + size uint type BufferType usage Usage data Range diff --git a/vlib/sokol/memory/memory.c.v b/vlib/sokol/memory/memory.c.v index fc5fcf876f..3b8a9b1db1 100644 --- a/vlib/sokol/memory/memory.c.v +++ b/vlib/sokol/memory/memory.c.v @@ -1,13 +1,13 @@ module memory -pub type FnAllocatorAlloc = fn (size usize, user_data voidptr) voidptr +pub type FnAllocatorAlloc = fn (size uint, user_data voidptr) voidptr pub type FnAllocatorFree = fn (ptr voidptr, user_data voidptr) pub type FnLogCb = fn (const_tag &char, log_level u32, log_item_id u32, const_message_or_null &char, line_nr u32, const_filename_or_null &char, user_data voidptr) // salloc - used in the allocator structs, that the SOKOL libraries use, for allocating new memory blocks -pub fn salloc(size usize, user_data voidptr) voidptr { +pub fn salloc(size uint, user_data voidptr) voidptr { res := unsafe { malloc(int(size)) } $if trace_sokol_memory ? { eprintln('sokol.memory.salloc | user_data: ${user_data:x} | size: ${size:10} | res: ${res:x}') diff --git a/vlib/sokol/sapp/sapp_linux.c.v b/vlib/sokol/sapp/sapp_linux.c.v index e71c2505d4..ee60bb8ca1 100644 --- a/vlib/sokol/sapp/sapp_linux.c.v +++ b/vlib/sokol/sapp/sapp_linux.c.v @@ -60,8 +60,8 @@ $if sokol_wayland ? { pub struct C.wl_interface {} pub struct C.wl_array { - size usize - alloc usize + size uint + alloc uint data voidptr } @@ -284,7 +284,7 @@ $if sokol_wayland ? { fn C.xkb_state_new(keymap &C.xkb_keymap) &C.xkb_state fn C.xkb_state_unref(state &C.xkb_state) fn C.xkb_state_key_get_one_sym(state &C.xkb_state, key u32) Xkb_keysym_t - fn C.xkb_state_key_get_utf8(state &C.xkb_state, key u32, buf &char, size usize) int + fn C.xkb_state_key_get_utf8(state &C.xkb_state, key u32, buf &char, size uint) int fn C.xkb_state_update_mask(state &C.xkb_state, depressed u32, latched u32, locked u32, dep_group u32, lat_group u32, lock_group u32) int fn C.xkb_state_mod_name_is_active(state &C.xkb_state, name &char, @type int) int @@ -346,7 +346,7 @@ $if sokol_wayland ? { const wp_cursor_shape_device_v1_shape_not_allowed = u32(25) // MAP_FAILED - const map_failed = voidptr(usize(~u64(0))) + const map_failed = voidptr(uint(~u64(0))) // Linux input event codes (from linux/input-event-codes.h) const btn_left = 0x110 @@ -433,17 +433,17 @@ const gl_framebuffer_binding = u32(0x8CA6) // === Linux syscalls (shared) === -fn C.mmap(addr voidptr, length usize, prot int, flags int, fd int, offset i64) voidptr -fn C.munmap(addr voidptr, length usize) int +fn C.mmap(addr voidptr, length uint, prot int, flags int, fd int, offset i64) voidptr +fn C.munmap(addr voidptr, length uint) int fn C.close(fd int) int -fn C.read(fd int, buf voidptr, count usize) isize +fn C.read(fd int, buf voidptr, count uint) C.ptrdiff_t fn C.pipe(fds &i32) i32 fn C.strcmp(s1 &char, s2 &char) int -fn C.strncmp(s1 &char, s2 &char, n usize) int -fn C.strlen(s &char) usize +fn C.strncmp(s1 &char, s2 &char, n uint) int +fn C.strlen(s &char) uint fn C.strtok(str &char, delim &char) &char fn C.strtol(str &char, endptr &&char, base int) i64 -fn C.memset(s voidptr, c int, n usize) voidptr +fn C.memset(s voidptr, c int, n uint) voidptr fn C.atof(s &char) f64 // mmap constants @@ -941,7 +941,7 @@ fn C.poll(fds &C.pollfd, nfds u64, timeout int) int fn C.ConnectionNumber(display &C.Display) int fn C.atof(str &char) f64 -fn C.strncmp(s1 &char, s2 &char, n usize) int +fn C.strncmp(s1 &char, s2 &char, n uint) int // X11 constants const x_false = 0 diff --git a/vlib/sokol/sapp/sapp_state_linux.v b/vlib/sokol/sapp/sapp_state_linux.v index 95de3761b6..9f1ec63d2f 100644 --- a/vlib/sokol/sapp/sapp_state_linux.v +++ b/vlib/sokol/sapp/sapp_state_linux.v @@ -382,7 +382,7 @@ fn sapp_init_state(desc &Desc) { if g_sapp_state.clipboard.enabled { g_sapp_state.clipboard.buf_size = g_sapp_state.desc.clipboard_size g_sapp_state.clipboard.buffer = unsafe { - &char(C.calloc(1, usize(g_sapp_state.clipboard.buf_size))) + &char(C.calloc(1, uint(g_sapp_state.clipboard.buf_size))) } } g_sapp_state.drop.enabled = g_sapp_state.desc.enable_dragndrop @@ -390,7 +390,7 @@ fn sapp_init_state(desc &Desc) { g_sapp_state.drop.max_files = g_sapp_state.desc.max_dropped_files g_sapp_state.drop.max_path_length = g_sapp_state.desc.max_dropped_file_path_length g_sapp_state.drop.buf_size = g_sapp_state.drop.max_files * g_sapp_state.drop.max_path_length - g_sapp_state.drop.buffer = unsafe { &char(C.calloc(1, usize(g_sapp_state.drop.buf_size))) } + g_sapp_state.drop.buffer = unsafe { &char(C.calloc(1, uint(g_sapp_state.drop.buf_size))) } } // Copy window title if g_sapp_state.desc.window_title != unsafe { nil } diff --git a/vlib/sokol/sapp/sapp_structs.c.v b/vlib/sokol/sapp/sapp_structs.c.v index 7831ee74eb..dfa40401eb 100644 --- a/vlib/sokol/sapp/sapp_structs.c.v +++ b/vlib/sokol/sapp/sapp_structs.c.v @@ -31,7 +31,7 @@ pub type Logger = C.sapp_logger pub struct C.sapp_range { pub: ptr voidptr - size usize + size uint } pub type Range = C.sapp_range diff --git a/vlib/sokol/sapp/sapp_wayland_linux.v b/vlib/sokol/sapp/sapp_wayland_linux.v index b31ac7cc9f..a4641882ca 100644 --- a/vlib/sokol/sapp/sapp_wayland_linux.v +++ b/vlib/sokol/sapp/sapp_wayland_linux.v @@ -347,7 +347,7 @@ $if sokol_wayland ? { mut buf := [8]u8{} count := C.xkb_state_key_get_utf8(g_sapp_state.wl.xkb_state, - g_sapp_state.wl.key_repeat_keycode, &char(&buf[0]), usize(buf.len)) + g_sapp_state.wl.key_repeat_keycode, &char(&buf[0]), uint(buf.len)) if count > 0 && count < buf.len { codepoint := utf8_decode(&buf[0], count) if codepoint > 0 && codepoint < 0x110000 { @@ -368,7 +368,7 @@ $if sokol_wayland ? { C.close(fd) return } - map_str := C.mmap(unsafe { nil }, usize(size), prot_read, map_private, fd, 0) + map_str := C.mmap(unsafe { nil }, uint(size), prot_read, map_private, fd, 0) if map_str == map_failed { C.close(fd) return @@ -378,7 +378,7 @@ $if sokol_wayland ? { } g_sapp_state.wl.xkb_keymap = C.xkb_keymap_new_from_string(g_sapp_state.wl.xkb_context, map_str, xkb_keymap_format_text_v1, xkb_keymap_compile_no_flags) - C.munmap(map_str, usize(size)) + C.munmap(map_str, uint(size)) C.close(fd) if g_sapp_state.wl.xkb_keymap == unsafe { nil } { @@ -434,7 +434,7 @@ $if sokol_wayland ? { if state == wl_keyboard_key_state_pressed { mut buf := [8]u8{} count := C.xkb_state_key_get_utf8(g_sapp_state.wl.xkb_state, keycode, &char(&buf[0]), - usize(buf.len)) + uint(buf.len)) if count > 0 && count < buf.len { codepoint := utf8_decode(&buf[0], count) if codepoint > 0 && codepoint < 0x110000 { @@ -818,15 +818,15 @@ $if sokol_wayland ? { C.wl_display_flush(g_sapp_state.wl.display) mut buffer := [8192]u8{} - mut total_read := isize(0) + mut total_read := int(0) for { - n := C.read(fds[0], unsafe { &buffer[0] + total_read }, usize(buffer.len - + n := C.read(fds[0], unsafe { &buffer[0] + total_read }, uint(buffer.len - int(total_read) - 1)) if n <= 0 { break } total_read += n - if total_read >= isize(buffer.len - 1) { + if total_read >= int(buffer.len - 1) { break } } @@ -838,7 +838,7 @@ $if sokol_wayland ? { } // Clear drop buffer if g_sapp_state.drop.buffer != unsafe { nil } { - unsafe { C.memset(g_sapp_state.drop.buffer, 0, usize(g_sapp_state.drop.buf_size)) } + unsafe { C.memset(g_sapp_state.drop.buffer, 0, uint(g_sapp_state.drop.buf_size)) } } g_sapp_state.drop.num_files = 0 @@ -855,7 +855,7 @@ $if sokol_wayland ? { // URL decode into drop buffer mut dst := sapp_dropped_file_path_ptr(g_sapp_state.drop.num_files) dst_end := unsafe { dst + (g_sapp_state.drop.max_path_length - 1) } - mut i := usize(0) + mut i := uint(0) for unsafe { file_path[i] } != 0 && dst < dst_end { ch := unsafe { u8(file_path[i]) } if ch == `%` && unsafe { file_path[i + 1] } != 0 diff --git a/vlib/sokol/sapp/sapp_wayland_pipe_linux_test.c.v b/vlib/sokol/sapp/sapp_wayland_pipe_linux_test.c.v index 54e29228a4..343120fed4 100644 --- a/vlib/sokol/sapp/sapp_wayland_pipe_linux_test.c.v +++ b/vlib/sokol/sapp/sapp_wayland_pipe_linux_test.c.v @@ -31,7 +31,7 @@ fn test_wayland_drop_pipe_has_two_independent_descriptors() { } for i, fds in [first, second] { payload := [u8(41 + i)]! - assert C.write(fds[1], &payload[0], usize(payload.len)) == 1 + assert C.write(fds[1], &payload[0], uint(payload.len)) == 1 } for i, fds in [first, second] { mut byte := u8(0) @@ -47,14 +47,14 @@ fn test_wayland_drop_pipe_transfers_uri_list_and_reaches_eof() { } assert fds[0] >= 0 && fds[1] >= 0 && fds[0] != fds[1] payload := 'file:///tmp/drop%20path.v\r\nfile:///tmp/caf%C3%A9.v\r\n' - assert C.write(fds[1], payload.str, usize(payload.len)) == isize(payload.len) + assert C.write(fds[1], payload.str, uint(payload.len)) == int(payload.len) assert C.close(fds[1]) == 0 fds[1] = -1 mut buffer := [128]u8{} mut total := 0 for { assert total < buffer.len - n := C.read(fds[0], unsafe { &buffer[0] + total }, usize(buffer.len - total)) + n := C.read(fds[0], unsafe { &buffer[0] + total }, uint(buffer.len - total)) assert n >= 0 if n == 0 { break diff --git a/vlib/sokol/sapp/sapp_x11_linux.v b/vlib/sokol/sapp/sapp_x11_linux.v index 37c761125a..f9a74ffcfc 100644 --- a/vlib/sokol/sapp/sapp_x11_linux.v +++ b/vlib/sokol/sapp/sapp_x11_linux.v @@ -892,7 +892,7 @@ fn x11_init_keytable() { for km in keymap { if unsafe { C.strncmp(&char(&desc.names.keys[scancode].name[0]), &char(&km.name[0]), - usize(xkb_key_name_length)) + uint(xkb_key_name_length)) } == 0 { key = km.key break @@ -903,14 +903,14 @@ fn x11_init_keytable() { for i in 0 .. int(desc.names.num_key_aliases) { if unsafe { C.strncmp(&char(&desc.names.key_aliases[i].real[0]), - &char(&desc.names.keys[scancode].name[0]), usize(xkb_key_name_length)) + &char(&desc.names.keys[scancode].name[0]), uint(xkb_key_name_length)) } != 0 { continue } for km in keymap { if unsafe { C.strncmp(&char(&desc.names.key_aliases[i].alias[0]), &char(&km.name[0]), - usize(xkb_key_name_length)) + uint(xkb_key_name_length)) } == 0 { key = km.key break @@ -932,7 +932,7 @@ fn x11_init_keytable() { scancode_min + 1, &syms_per_code) for scancode in scancode_min .. scancode_max + 1 { if g_sapp_state.keycodes[scancode] == .invalid { - base := usize((scancode - scancode_min) * syms_per_code) + base := uint((scancode - scancode_min) * syms_per_code) g_sapp_state.keycodes[scancode] = x11_translate_keysyms(unsafe { keysyms + base }, syms_per_code) } @@ -1220,7 +1220,7 @@ fn x11_create_hidden_cursor() { } img.xhot = 0 img.yhot = 0 - unsafe { C.memset(img.pixels, 0, usize(16 * 16 * 4)) } + unsafe { C.memset(img.pixels, 0, uint(16 * 16 * 4)) } g_sapp_state.x11.hidden_cursor = C.XcursorImageLoadCursor(g_sapp_state.x11.display, img) C.XcursorImageDestroy(img) } @@ -1375,8 +1375,8 @@ fn x11_get_clipboard_string() &char { if data == nil { return nil } - item_size := usize(item_count) - if item_size >= usize(g_sapp_state.clipboard.buf_size) { + item_size := uint(item_count) + if item_size >= uint(g_sapp_state.clipboard.buf_size) { C.XFree(data) return nil } @@ -1532,14 +1532,14 @@ fn x11_keyrelease_repeat(keycode int) { // === Window property helpers === -fn x11_get_window_property(window Window, property Atom, req_type Atom, value &&u8) usize { +fn x11_get_window_property(window Window, property Atom, req_type Atom, value &&u8) uint { mut actual_type := Atom(0) mut actual_format := 0 mut item_count := XlibULong(0) mut bytes_after := XlibULong(0) C.XGetWindowProperty(g_sapp_state.x11.display, window, property, 0, 0x7fffffff, x_false, req_type, &actual_type, &actual_format, &item_count, &bytes_after, value) - return usize(item_count) + return uint(item_count) } fn x11_get_window_state() int { @@ -1564,7 +1564,7 @@ fn x11_parse_dropped_files_list(src &char) bool { return false } // Clear drop buffer - unsafe { C.memset(g_sapp_state.drop.buffer, 0, usize(g_sapp_state.drop.buf_size)) } + unsafe { C.memset(g_sapp_state.drop.buffer, 0, uint(g_sapp_state.drop.buf_size)) } g_sapp_state.drop.num_files = 0 mut err := false @@ -1612,7 +1612,7 @@ fn x11_parse_dropped_files_list(src &char) bool { digits[0] = u8(*p) digits[1] = u8(*(p + 1)) digits[2] = 0 - p = &char(usize(p) + 2) + p = &char(uint(p) + 2) dst_chr = u8(C.strtol(&char(&digits[0]), nil, 16)) } } @@ -1620,7 +1620,7 @@ fn x11_parse_dropped_files_list(src &char) bool { dst_chr = src_chr } if dst_chr != 0 { - if usize(dst_ptr) < usize(dst_end_ptr) { + if uint(dst_ptr) < uint(dst_end_ptr) { unsafe { *dst_ptr = char(dst_chr) dst_ptr++ @@ -1632,7 +1632,7 @@ fn x11_parse_dropped_files_list(src &char) bool { } } if err { - unsafe { C.memset(g_sapp_state.drop.buffer, 0, usize(g_sapp_state.drop.buf_size)) } + unsafe { C.memset(g_sapp_state.drop.buffer, 0, uint(g_sapp_state.drop.buf_size)) } g_sapp_state.drop.num_files = 0 return false } @@ -1883,7 +1883,7 @@ fn x11_on_clientmessage(event &C.XEvent) { if g_sapp_state.x11.xdnd.version > x11_xdnd_version { return } - mut count := usize(0) + mut count := uint(0) mut formats := &Atom(nil) if is_list { count = x11_get_window_property(g_sapp_state.x11.xdnd.source, diff --git a/vlib/stbi/stbi.c.v b/vlib/stbi/stbi.c.v index 19666eb9c0..667248df4a 100644 --- a/vlib/stbi/stbi.c.v +++ b/vlib/stbi/stbi.c.v @@ -12,15 +12,15 @@ fn trace_allocation(message string) { } @[export: 'stbi__callback_malloc'] -fn cb_malloc(s usize) voidptr { - res := unsafe { malloc(isize(s)) } +fn cb_malloc(s uint) voidptr { + res := unsafe { malloc(int(s)) } trace_allocation('> stbi__callback_malloc: ${s} => ${ptr_str(res)}') return res } @[export: 'stbi__callback_realloc'] -fn cb_realloc(p voidptr, s usize) voidptr { - res := unsafe { v_realloc(p, isize(s)) } +fn cb_realloc(p voidptr, s uint) voidptr { + res := unsafe { v_realloc(p, int(s)) } trace_allocation('> stbi__callback_realloc: ${ptr_str(p)} , ${s} => ${ptr_str(res)}') return res } @@ -202,7 +202,7 @@ pub fn resize_uint8(img &Image, output_w int, output_h int) !Image { original_nr_channels: img.original_nr_channels // preserve the metadata of the original, during resizes } - res.data = cb_malloc(usize(output_w * output_h * img.nr_channels)) + res.data = cb_malloc(uint(output_w * output_h * img.nr_channels)) if res.data == 0 { return error('stbi_image failed to resize file') } diff --git a/vlib/strconv/format_thousands.v b/vlib/strconv/format_thousands.v index aa46254c35..6de43e674f 100644 --- a/vlib/strconv/format_thousands.v +++ b/vlib/strconv/format_thousands.v @@ -17,10 +17,22 @@ pub: pub type SeparatorOptions = string | Separator // Numeric is the set of built-in numeric types accepted by `format_thousands`: -// `int`, `i8`, `i16`, `i32`, `i64`, `u8`, `u16`, `u32`, `u64`, `isize`, `usize`, +// `int`, `i8`, `i16`, `i32`, `i64`, `u8`, `u16`, `u32`, `u64`, `uint`, // `f32` and `f64`. Generic code that forwards a `T` to it can use -// `[T strconv.Numeric]` as its constraint. -pub type Numeric = int | i8 | i16 | i32 | i64 | u8 | u16 | u32 | u64 | isize | usize | f32 | f64 +// `[T strconv.Numeric]` as its constraint. The deprecated `isize` remains accepted. +pub type Numeric = isize + | int + | i8 + | i16 + | i32 + | i64 + | u8 + | u16 + | u32 + | u64 + | uint + | f32 + | f64 // is_all_digits reports whether every byte in `s` is an ASCII digit (`0`-`9`). // An empty string reports `true` (vacuously), matching how `insert_thousands_sep` diff --git a/vlib/strconv/format_thousands_test.v b/vlib/strconv/format_thousands_test.v index e8cbc0e907..fd4e4e12b6 100644 --- a/vlib/strconv/format_thousands_test.v +++ b/vlib/strconv/format_thousands_test.v @@ -55,8 +55,8 @@ fn test_format_thousands_int_types() { assert format_thousands(u16(65535), ',') == '65,535' assert format_thousands(u32(4294967295), ',') == '4,294,967,295' assert format_thousands(u64(18446744073709551615), ' ') == '18 446 744 073 709 551 615' - assert format_thousands(isize(-1234567), ',') == '-1,234,567' - assert format_thousands(usize(1234567), ',') == '1,234,567' + assert format_thousands(int(-1234567), ',') == '-1,234,567' + assert format_thousands(uint(1234567), ',') == '1,234,567' } fn grouped[T Numeric](x T) string { @@ -99,3 +99,7 @@ fn test_format_thousands_float_non_finite() { assert format_thousands(value, ',') == value.str() } } + +fn test_format_legacy_signed_integer() { + assert format_thousands(isize(-1234567), ',') == '-1,234,567' +} diff --git a/vlib/strings/strings.c.v b/vlib/strings/strings.c.v index 67cf37a00a..59b0b28a0f 100644 --- a/vlib/strings/strings.c.v +++ b/vlib/strings/strings.c.v @@ -8,7 +8,7 @@ pub fn repeat(c u8, n int) string { } mut bytes := unsafe { malloc_noscan(n + 1) } unsafe { - C.memset(bytes, c, usize(n)) + C.memset(bytes, c, uint(n)) bytes[n] = 0 } return unsafe { bytes.vstring_with_len(n) } diff --git a/vlib/sync/channels.c.v b/vlib/sync/channels.c.v index bfa93788f4..f5da4067cc 100644 --- a/vlib/sync/channels.c.v +++ b/vlib/sync/channels.c.v @@ -176,7 +176,7 @@ pub fn (mut ch Channel) close(errs ...IError) { } C.atomic_store_u16(&ch.closed, 1) mut nulladr := unsafe { nil } - for !C.atomic_compare_exchange_weak_ptr(voidptr(&ch.adr_written), voidptr(&nulladr), isize(-1)) { + for !C.atomic_compare_exchange_weak_ptr(voidptr(&ch.adr_written), voidptr(&nulladr), int(-1)) { nulladr = unsafe { nil } } ch.readsem_im.post() @@ -348,14 +348,14 @@ fn (mut ch Channel) try_push_impl(src voidptr, no_block bool) ChanState { mut wradr := C.atomic_load_ptr(unsafe { &voidptr(&ch.write_adr) }) for wradr != unsafe { nil } { if C.atomic_compare_exchange_strong_ptr(voidptr(&ch.write_adr), voidptr(&wradr), - isize(0)) + int(0)) { // there is a reader waiting for us race_sync_on(wradr) unsafe { C.memcpy(wradr, src, ch.objsize) } mut nulladr := unsafe { nil } for !C.atomic_compare_exchange_weak_ptr(voidptr(&ch.adr_written), - voidptr(&nulladr), isize(wradr)) { + voidptr(&nulladr), int(wradr)) { nulladr = unsafe { nil } } ch.readsem_im.post() @@ -394,7 +394,7 @@ fn (mut ch Channel) try_push_impl(src voidptr, no_block bool) ChanState { if wradr != unsafe { nil } { mut src2 := src if C.atomic_compare_exchange_strong_ptr(voidptr(&ch.read_adr), voidptr(&src2), - isize(0)) + int(0)) { ch.writesem.post() continue @@ -412,7 +412,7 @@ fn (mut ch Channel) try_push_impl(src voidptr, no_block bool) ChanState { mut src2 := src for sp := u32(0); sp < spinloops_ || read_in_progress; sp++ { if C.atomic_compare_exchange_strong_ptr(voidptr(&ch.adr_read), voidptr(&src2), - isize(0)) + int(0)) { have_swapped = true read_in_progress = true @@ -435,7 +435,7 @@ fn (mut ch Channel) try_push_impl(src voidptr, no_block bool) ChanState { } if C.atomic_load_u16(&ch.closed) != 0 { if have_swapped - || C.atomic_compare_exchange_strong_ptr(voidptr(&ch.adr_read), voidptr(&src2), isize(0)) { + || C.atomic_compare_exchange_strong_ptr(voidptr(&ch.adr_read), voidptr(&src2), int(0)) { ch.writesem.post() race_acquire_on(src) return .success @@ -444,7 +444,7 @@ fn (mut ch Channel) try_push_impl(src voidptr, no_block bool) ChanState { } } if have_swapped - || C.atomic_compare_exchange_strong_ptr(voidptr(&ch.adr_read), voidptr(&src2), isize(0)) { + || C.atomic_compare_exchange_strong_ptr(voidptr(&ch.adr_read), voidptr(&src2), int(0)) { ch.writesem.post() break } else { @@ -592,14 +592,14 @@ fn (mut ch Channel) try_pop_impl(dest voidptr, no_block bool) ChanState { mut rdadr := C.atomic_load_ptr(unsafe { &voidptr(&ch.read_adr) }) for rdadr != unsafe { nil } { if C.atomic_compare_exchange_strong_ptr(voidptr(&ch.read_adr), voidptr(&rdadr), - isize(0)) + int(0)) { // there is a writer waiting for us race_sync_on(rdadr) unsafe { C.memcpy(dest, rdadr, ch.objsize) } mut nulladr := unsafe { nil } for !C.atomic_compare_exchange_weak_ptr(voidptr(&ch.adr_read), - voidptr(&nulladr), isize(rdadr)) { + voidptr(&nulladr), int(rdadr)) { nulladr = unsafe { nil } } ch.writesem_im.post() @@ -692,7 +692,7 @@ fn (mut ch Channel) try_pop_impl(dest voidptr, no_block bool) ChanState { if rdadr != unsafe { nil } { mut dest2 := dest if C.atomic_compare_exchange_strong_ptr(voidptr(&ch.write_adr), voidptr(&dest2), - isize(0)) + int(0)) { ch.readsem.post() continue @@ -711,7 +711,7 @@ fn (mut ch Channel) try_pop_impl(dest voidptr, no_block bool) ChanState { mut dest2 := dest for sp := u32(0); sp < spinloops_ || write_in_progress; sp++ { if C.atomic_compare_exchange_strong_ptr(voidptr(&ch.adr_written), voidptr(&dest2), - isize(0)) + int(0)) { have_swapped = true break @@ -735,7 +735,7 @@ fn (mut ch Channel) try_pop_impl(dest voidptr, no_block bool) ChanState { ch.readsem_im.wait() } if have_swapped - || C.atomic_compare_exchange_strong_ptr(voidptr(&ch.adr_written), voidptr(&dest2), isize(0)) { + || C.atomic_compare_exchange_strong_ptr(voidptr(&ch.adr_written), voidptr(&dest2), int(0)) { ch.readsem.post() race_acquire_on(dest) break @@ -777,7 +777,7 @@ fn select_recheck_after_waiting(mut channels []&Channel, dir []Direction, state } for sub != unsafe { nil } { if sub.state != state && C.atomic_load_u32(sub.state) == select_state_waiting { - if usize(sub.state) < usize(state) { + if uint(sub.state) < uint(state) { sub.sem.post() sub_mtx.unlock() return false diff --git a/vlib/sync/concurrent_map.v b/vlib/sync/concurrent_map.v index 5af4fdb757..6129dbae3d 100644 --- a/vlib/sync/concurrent_map.v +++ b/vlib/sync/concurrent_map.v @@ -40,7 +40,7 @@ pub fn new_concurrent_map[K, V]() &ConcurrentMap[K, V] { // other scalar key types hash through their string form. fn (m &ConcurrentMap[K, V]) shard_for(key K) &ConcurrentShard[K, V] { $if K is $pointer { - address := u64(usize(key)) + address := u64(uint(key)) h := address ^ (address >> 5) ^ (address >> 17) return m.shards[h % u64(concurrent_map_shards)] } $else $if K is string { diff --git a/vlib/sync/stdatomic/1.declarations.c.v b/vlib/sync/stdatomic/1.declarations.c.v index 2b51d50145..b6e1c63659 100644 --- a/vlib/sync/stdatomic/1.declarations.c.v +++ b/vlib/sync/stdatomic/1.declarations.c.v @@ -92,8 +92,8 @@ $if linux { // The following functions are actually generic in C fn C.atomic_load_ptr(voidptr) voidptr fn C.atomic_store_ptr(voidptr, voidptr) -fn C.atomic_compare_exchange_weak_ptr(voidptr, voidptr, isize) bool -fn C.atomic_compare_exchange_strong_ptr(voidptr, voidptr, isize) bool +fn C.atomic_compare_exchange_weak_ptr(voidptr, voidptr, C.ptrdiff_t) bool +fn C.atomic_compare_exchange_strong_ptr(voidptr, voidptr, C.ptrdiff_t) bool fn C.atomic_exchange_ptr(voidptr, voidptr) voidptr fn C.atomic_fetch_add_ptr(voidptr, voidptr) voidptr fn C.atomic_fetch_sub_ptr(voidptr, voidptr) voidptr diff --git a/vlib/sync/stdatomic/atomic.c.v b/vlib/sync/stdatomic/atomic.c.v index 73b69ab6fc..e3f4227456 100644 --- a/vlib/sync/stdatomic/atomic.c.v +++ b/vlib/sync/stdatomic/atomic.c.v @@ -114,8 +114,8 @@ pub fn (mut a AtomicVal[T]) load() T { } else { return int(C.atomic_load_u64(voidptr(&a.val))) } - } $else $if T is isize || T is usize { - if sizeof(isize) == 4 { + } $else $if T is isize || T is uint { + if sizeof(int) == 4 { return T(C.atomic_load_u32(voidptr(&a.val))) } else { return T(C.atomic_load_u64(voidptr(&a.val))) @@ -150,8 +150,8 @@ pub fn (mut a AtomicVal[T]) store(val T) { } else { C.atomic_store_u64(voidptr(&a.val), u64(val)) } - } $else $if T is isize || T is usize { - if sizeof(isize) == 4 { + } $else $if T is isize || T is uint { + if sizeof(int) == 4 { C.atomic_store_u32(voidptr(&a.val), u32(val)) } else { C.atomic_store_u64(voidptr(&a.val), u64(val)) @@ -193,8 +193,8 @@ pub fn (mut a AtomicVal[T]) add(delta T) T { old := C.atomic_fetch_add_u64(voidptr(&a.val), u64(delta)) return T(old) } - } $else $if T is isize || T is usize { - if sizeof(isize) == 4 { + } $else $if T is isize || T is uint { + if sizeof(int) == 4 { old := C.atomic_fetch_add_u32(voidptr(&a.val), u32(delta)) return T(old) } else { @@ -232,8 +232,8 @@ pub fn (mut a AtomicVal[T]) sub(delta T) T { old := C.atomic_fetch_sub_u64(voidptr(&a.val), u64(delta)) return T(old) } - } $else $if T is isize || T is usize { - if sizeof(isize) == 4 { + } $else $if T is isize || T is uint { + if sizeof(int) == 4 { old := C.atomic_fetch_sub_u32(voidptr(&a.val), u32(delta)) return T(old) } else { @@ -270,8 +270,8 @@ pub fn (mut a AtomicVal[T]) swap(new T) T { old := C.atomic_exchange_u64(voidptr(&a.val), u64(new)) return T(old) } - } $else $if T is isize || T is usize { - if sizeof(isize) == 4 { + } $else $if T is isize || T is uint { + if sizeof(int) == 4 { old := C.atomic_exchange_u32(voidptr(&a.val), u32(new)) return T(old) } else { @@ -319,8 +319,8 @@ pub fn (mut a AtomicVal[T]) compare_and_swap(expected T, new T) bool { mut exp := u64(expected) return C.atomic_compare_exchange_strong_u64(voidptr(&a.val), &exp, u64(new)) } - } $else $if T is isize || T is usize { - if sizeof(isize) == 4 { + } $else $if T is isize || T is uint { + if sizeof(int) == 4 { mut exp := u32(expected) return C.atomic_compare_exchange_strong_u32(voidptr(&a.val), &exp, u32(new)) } else { diff --git a/vlib/sync/stdatomic/atomic_load_read_only_nix_test.v b/vlib/sync/stdatomic/atomic_load_read_only_nix_test.v index db1a64aab4..d2197a4177 100644 --- a/vlib/sync/stdatomic/atomic_load_read_only_nix_test.v +++ b/vlib/sync/stdatomic/atomic_load_read_only_nix_test.v @@ -22,17 +22,17 @@ const off_int = 40 const off_isize = 48 const off_usize = 56 -const ptr_value = voidptr(usize(0x1000)) +const ptr_value = voidptr(uint(0x1000)) fn at(base voidptr, offset int) voidptr { return unsafe { voidptr(&u8(base) + offset) } } // page_size returns the system page size, the unit that mmap and mprotect work in. -fn page_size() usize { +fn page_size() uint { size := unsafe { C.sysconf(C._SC_PAGESIZE) } assert size > 0 - return usize(size) + return uint(size) } // read_only_page returns a page that holds a known value of every width at the @@ -56,8 +56,8 @@ fn read_only_page() voidptr { *(&bool(at(base, off_bool))) = true *(&voidptr(at(base, off_ptr))) = ptr_value *(&int(at(base, off_int))) = -1234 - *(&isize(at(base, off_isize))) = -5678 - *(&usize(at(base, off_usize))) = 9876 + *(&int(at(base, off_isize))) = -5678 + *(&uint(at(base, off_usize))) = 9876 } assert unsafe { C.mprotect(base, size, C.PROT_READ) } == 0 return base @@ -105,9 +105,9 @@ fn test_atomic_val_load_of_every_width_from_read_only_memory() { assert a_ptr.load() == ptr_value mut a_int := unsafe { &stdatomic.AtomicVal[int](at(base, off_int)) } assert a_int.load() == -1234 - mut a_isize := unsafe { &stdatomic.AtomicVal[isize](at(base, off_isize)) } + mut a_isize := unsafe { &stdatomic.AtomicVal[int](at(base, off_isize)) } assert a_isize.load() == -5678 - mut a_usize := unsafe { &stdatomic.AtomicVal[usize](at(base, off_usize)) } + mut a_usize := unsafe { &stdatomic.AtomicVal[uint](at(base, off_usize)) } assert a_usize.load() == 9876 } diff --git a/vlib/sync/stdatomic/atomic_test.v b/vlib/sync/stdatomic/atomic_test.v index 93f7cae210..bedaa136c8 100644 --- a/vlib/sync/stdatomic/atomic_test.v +++ b/vlib/sync/stdatomic/atomic_test.v @@ -235,28 +235,28 @@ fn test_atomic_vals() { assert v_int.compare_and_swap(new_int, -40001) == true assert v_int.load() == -40001 - mut v_isize := stdatomic.new_atomic(isize(-55)) + mut v_isize := stdatomic.new_atomic(int(-55)) v_isize.store(-56) assert v_isize.load() == -56 assert v_isize.add(10) == -56 assert v_isize.load() == -46 assert v_isize.sub(7) == -46 assert v_isize.load() == -53 - mut new_isize := isize(-50000) + mut new_isize := int(-50000) assert v_isize.swap(new_isize) == -53 assert v_isize.swap(-53) == new_isize assert v_isize.compare_and_swap(-53, new_isize) == true assert v_isize.compare_and_swap(new_isize, -50001) == true assert v_isize.load() == -50001 - mut v_usize := stdatomic.new_atomic(usize(55)) + mut v_usize := stdatomic.new_atomic(uint(55)) v_usize.store(56) assert v_usize.load() == 56 assert v_usize.add(10) == 56 assert v_usize.load() == 66 assert v_usize.sub(7) == 66 assert v_usize.load() == 59 - mut new_usize := usize(50000) + mut new_usize := uint(50000) assert v_usize.swap(new_usize) == 59 assert v_usize.swap(59) == new_usize assert v_usize.compare_and_swap(59, new_usize) == true @@ -280,3 +280,15 @@ fn test_atomic_vals() { C.atomic_thread_fence(C.memory_order_relaxed) C.cpu_relax() } + +fn test_legacy_signed_atomic_operations() { + mut value := stdatomic.new_atomic(isize(-42)) + value.store(-50) + assert value.load() == -50 + assert value.add(8) == -50 + assert value.sub(2) == -42 + assert value.swap(-100) == -44 + assert !value.compare_and_swap(-42, -1) + assert value.compare_and_swap(-100, -1) + assert value.load() == -1 +} diff --git a/vlib/sync/stdatomic/stdatomic_include_after_compat_nix_test.v b/vlib/sync/stdatomic/stdatomic_include_after_compat_nix_test.v index 65dc6961a3..36e9a92f59 100644 --- a/vlib/sync/stdatomic/stdatomic_include_after_compat_nix_test.v +++ b/vlib/sync/stdatomic/stdatomic_include_after_compat_nix_test.v @@ -2,7 +2,7 @@ import sync.stdatomic as _ #include "@VEXEROOT/vlib/sync/stdatomic/stdatomic_include_after_compat.h" -fn C.v_test_atomic_after_compat_include() usize +fn C.v_test_atomic_after_compat_include() uint fn test_system_stdatomic_can_be_included_after_v_compat_header() { assert C.v_test_atomic_after_compat_include() == 7 diff --git a/vlib/sync/thread_default.c.v b/vlib/sync/thread_default.c.v index 03cbd2c5e8..781b127996 100644 --- a/vlib/sync/thread_default.c.v +++ b/vlib/sync/thread_default.c.v @@ -3,7 +3,7 @@ module sync $if macos { fn C.pthread_self() voidptr } $else { - fn C.pthread_self() usize + fn C.pthread_self() uint } // thread_id returns a unique identifier for the caller thread. diff --git a/vlib/sync/timer.c.v b/vlib/sync/timer.c.v index 66a3d791ff..741dc9b018 100644 --- a/vlib/sync/timer.c.v +++ b/vlib/sync/timer.c.v @@ -21,7 +21,7 @@ mut: fn new_timer_thread_args(duration time.Duration, output chan time.Time, stop chan chan bool, done chan bool) &TimerThreadArgs { // Keep the channels visible to tracing collectors until the detached worker finishes. - mut args := unsafe { &TimerThreadArgs(vcalloc(sizeof(TimerThreadArgs))) } + mut args := unsafe { &TimerThreadArgs(vcalloc(int(sizeof(TimerThreadArgs)))) } if args == unsafe { nil } { panic('could not allocate timer thread arguments') } diff --git a/vlib/sync/timer_nix.c.v b/vlib/sync/timer_nix.c.v index d68e970193..99fe2a02f1 100644 --- a/vlib/sync/timer_nix.c.v +++ b/vlib/sync/timer_nix.c.v @@ -20,7 +20,7 @@ fn timer_thread_entry(args_ptr voidptr) voidptr { fn start_timer(duration time.Duration, output chan time.Time, stop chan chan bool, done chan bool) { args := new_timer_thread_args(duration, output, stop, done) - result := C.v_sync_thread_create_detached_with_stack(voidptr(timer_thread_entry), voidptr(args), usize(C.V_THREAD_STACK_SIZE)) + result := C.v_sync_thread_create_detached_with_stack(voidptr(timer_thread_entry), voidptr(args), uint(C.V_THREAD_STACK_SIZE)) if result != 0 { free_timer_thread_args(args) panic('could not start timer: error ${result}') diff --git a/vlib/sync/tls.v b/vlib/sync/tls.v index ab151cd4c7..852b764659 100644 --- a/vlib/sync/tls.v +++ b/vlib/sync/tls.v @@ -22,8 +22,7 @@ mut: f_i64 i64 f_voidptr voidptr - f_isize isize - f_usize usize + f_usize uint f_int int f_f32 f32 f_f64 f64 @@ -53,8 +52,8 @@ fn convert_t_to_voidptr[T](value T) !voidptr { } $else $if T is $pointer { f.f_voidptr = voidptr(value) } $else $if T is isize { - f.f_isize = value - } $else $if T is usize { + f.f_int = int(value) + } $else $if T is uint { f.f_usize = value } $else $if T is int { f.f_int = value @@ -95,8 +94,8 @@ fn convert_voidptr_to_t[T](value voidptr) !T { } $else $if T is $pointer { return unsafe { f.f_voidptr } } $else $if T is isize { - return unsafe { f.f_isize } - } $else $if T is usize { + return T(unsafe { f.f_int }) + } $else $if T is uint { return unsafe { f.f_usize } } $else $if T is int { return unsafe { f.f_int } diff --git a/vlib/sync/tls_default.c.v b/vlib/sync/tls_default.c.v index 388428edd2..cae1dabcb1 100644 --- a/vlib/sync/tls_default.c.v +++ b/vlib/sync/tls_default.c.v @@ -8,7 +8,7 @@ fn C.pthread_getspecific(key u64) voidptr // new_tls creates new TLS storage initialized with the given `value` pub fn new_tls[T](value T) !ThreadLocalStorage[T] { - $if T !in [i8, i16, i32, i64, u8, u16, u32, u64, isize, usize, f32, f64, rune, int, voidptr, $pointer] { + $if T !in [i8, i16, i32, i64, u8, u16, u32, u64, int, uint, f32, f64, rune, isize, voidptr, $pointer] { return error('new_tls: invalid type ${T.name}') } mut key := u64(0) diff --git a/vlib/sync/tls_test.v b/vlib/sync/tls_test.v index 2472351e36..6cd69524a0 100644 --- a/vlib/sync/tls_test.v +++ b/vlib/sync/tls_test.v @@ -104,7 +104,7 @@ fn test_basic_tls() { } tls_u64.set(5900) or { assert err.msg().contains('already destroyed') } - mut tls_isize := sync.new_tls[isize](-57000)! + mut tls_isize := sync.new_tls[int](-57000)! assert tls_isize.get()! == -57000 tls_isize.set(-58000)! assert tls_isize.get()! == -58000 @@ -116,7 +116,7 @@ fn test_basic_tls() { } tls_isize.set(-59000) or { assert err.msg().contains('already destroyed') } - mut tls_usize := sync.new_tls[usize](57000)! + mut tls_usize := sync.new_tls[uint](57000)! assert tls_usize.get()! == 57000 tls_usize.set(58000)! assert tls_usize.get()! == 58000 @@ -282,3 +282,12 @@ fn test_cross_thread_type() { assert int_tls.get()! == 42 assert f64_tls.get()! == 1.5 } + +fn test_legacy_signed_tls() ! { + value := isize(-42) + mut tls := sync.new_tls(value)! + assert tls.get()! == value + tls.set(-123)! + assert tls.get()! == -123 + tls.destroy()! +} diff --git a/vlib/sync/tls_windows.c.v b/vlib/sync/tls_windows.c.v index 17382b5d37..edd05536e7 100644 --- a/vlib/sync/tls_windows.c.v +++ b/vlib/sync/tls_windows.c.v @@ -8,7 +8,7 @@ fn C.TlsFree(key u32) bool // new_tls creates new TLS storage initialized with the given `value` pub fn new_tls[T](value T) !ThreadLocalStorage[T] { - $if T !in [i8, i16, i32, i64, u8, u16, u32, u64, isize, usize, f32, f64, rune, int, voidptr, $pointer] { + $if T !in [i8, i16, i32, i64, u8, u16, u32, u64, int, uint, f32, f64, rune, isize, voidptr, $pointer] { return error('new_tls: invalid type ${T.name}') } diff --git a/vlib/sync/waitgroup.c.v b/vlib/sync/waitgroup.c.v index 3423db6033..17aa5b94ad 100644 --- a/vlib/sync/waitgroup.c.v +++ b/vlib/sync/waitgroup.c.v @@ -43,7 +43,7 @@ mut: fn new_waitgroup_thread_args(wg &WaitGroup, f fn ()) &WaitGroupThreadArgs { // Keep the wait group and captured callback context visible to tracing collectors. - mut args := unsafe { &WaitGroupThreadArgs(vcalloc(sizeof(WaitGroupThreadArgs))) } + mut args := unsafe { &WaitGroupThreadArgs(vcalloc(int(sizeof(WaitGroupThreadArgs)))) } if args == unsafe { nil } { panic('could not allocate waitgroup thread arguments') } diff --git a/vlib/sync/waitgroup_nix.c.v b/vlib/sync/waitgroup_nix.c.v index 929032297d..15c68e28d8 100644 --- a/vlib/sync/waitgroup_nix.c.v +++ b/vlib/sync/waitgroup_nix.c.v @@ -2,7 +2,7 @@ module sync #flag @VEXEROOT/vlib/sync/thread_helper.o -fn C.v_sync_thread_create_detached_with_stack(voidptr, voidptr, usize) int +fn C.v_sync_thread_create_detached_with_stack(voidptr, voidptr, uint) int fn waitgroup_thread_entry(args_ptr voidptr) voidptr { args := unsafe { &WaitGroupThreadArgs(args_ptr) } @@ -24,7 +24,7 @@ fn waitgroup_thread_entry(args_ptr voidptr) voidptr { fn start_waitgroup_thread(mut wg WaitGroup, f fn ()) { args := new_waitgroup_thread_args(&wg, f) - result := C.v_sync_thread_create_detached_with_stack(voidptr(waitgroup_thread_entry), voidptr(args), usize(C.V_THREAD_STACK_SIZE)) + result := C.v_sync_thread_create_detached_with_stack(voidptr(waitgroup_thread_entry), voidptr(args), uint(C.V_THREAD_STACK_SIZE)) if result != 0 { wg.done() free_waitgroup_thread_args(args) diff --git a/vlib/term/termios/termios_darwin.c.v b/vlib/term/termios/termios_darwin.c.v index cd91bd2d3c..23c523869e 100644 --- a/vlib/term/termios/termios_darwin.c.v +++ b/vlib/term/termios/termios_darwin.c.v @@ -11,8 +11,8 @@ module termios const cclen = 20 -type TcFlag = usize -type Speed = usize +type TcFlag = uint +type Speed = uint type Cc = u8 // Termios stores the terminal options @@ -37,14 +37,14 @@ fn C.ioctl(fd i32, request u64, args ...voidptr) i32 // for the underlying C.termios structure @[inline] pub fn flag(value int) TcFlag { - return usize(value) + return uint(value) } // invert is a platform dependant way to bitwise NOT (~) TcFlag // as its length varies across platforms @[inline] pub fn invert(value TcFlag) TcFlag { - return ~usize(value) + return ~uint(value) } pub struct Termios { @@ -90,5 +90,5 @@ pub fn set_state(fd int, new_state Termios) int { // disable_echo disables echoing characters as they are typed, when that Termios state is later set with termios.set_state(fd,t). pub fn (mut t Termios) disable_echo() { - t.c_lflag &= invert(usize(C.ECHO)) + t.c_lflag &= invert(uint(C.ECHO)) } diff --git a/vlib/time/time.c.v b/vlib/time/time.c.v index 91850f1526..7e3c570ce1 100644 --- a/vlib/time/time.c.v +++ b/vlib/time/time.c.v @@ -19,7 +19,7 @@ fn C.localtime(t &C.time_t) &C.tm fn C.localtime_r(t &C.time_t, tm &C.tm) fn C.gmtime(t &C.time_t) &C.tm fn C.gmtime_r(t &C.time_t, res &C.tm) &C.tm -fn C.strftime(buf &char, maxsize usize, const_format &char, const_tm &C.tm) usize +fn C.strftime(buf &char, maxsize uint, const_format &char, const_tm &C.tm) uint // now returns the current local time. pub fn now() Time { @@ -157,7 +157,7 @@ pub fn (t Time) strftime(fmt string) string { } mut buf := [1024]char{} fmt_c := unsafe { &char(strftime_fmt.str) } - C.strftime(&buf[0], usize(sizeof(buf)), fmt_c, tm) + C.strftime(&buf[0], uint(sizeof(buf)), fmt_c, tm) return unsafe { cstring_to_vstring(&buf[0]) } } diff --git a/vlib/time/zoneinfo_files_nix.c.v b/vlib/time/zoneinfo_files_nix.c.v index ef430957da..12ad4b5475 100644 --- a/vlib/time/zoneinfo_files_nix.c.v +++ b/vlib/time/zoneinfo_files_nix.c.v @@ -7,7 +7,7 @@ module time fn C.getenv(&char) &char -fn C.readlink(pathname &char, buf &char, bufsiz usize) i32 +fn C.readlink(pathname &char, buf &char, bufsiz uint) i32 @[typedef] struct C.pthread_mutex_t {} @@ -68,7 +68,7 @@ fn zoneinfo_is_file(path string) bool { // zoneinfo_readlink returns the target of the symbolic link `path`, when it is one. fn zoneinfo_readlink(path string) ?string { mut buf := [4096]u8{} - len := C.readlink(&char(path.str), &char(&buf[0]), usize(buf.len)) + len := C.readlink(&char(path.str), &char(&buf[0]), uint(buf.len)) if len <= 0 || len >= buf.len { return none } @@ -90,7 +90,7 @@ fn zoneinfo_read_file(path string) ![]u8 { mut data := []u8{} mut buf := [4096]u8{} for { - len := int(C.fread(&buf[0], 1, usize(buf.len), file)) + len := int(C.fread(&buf[0], 1, uint(buf.len), file)) if len <= 0 { break } diff --git a/vlib/toml/tests/integer_map_keys_test.v b/vlib/toml/tests/integer_map_keys_test.v index 0e76c62a3d..ca4a8de38a 100644 --- a/vlib/toml/tests/integer_map_keys_test.v +++ b/vlib/toml/tests/integer_map_keys_test.v @@ -42,9 +42,9 @@ fn test_signed_integer_key_widths() { i64(-9223372036854775807) - 1: 'min' i64(9223372036854775807): 'max' }) - check_keys[isize]('nums = { "-1" = "negative", 42 = "positive" }', { - isize(-1): 'negative' - isize(42): 'positive' + check_keys[int]('nums = { "-1" = "negative", 42 = "positive" }', { + int(-1): 'negative' + int(42): 'positive' }) } @@ -62,8 +62,8 @@ fn test_unsigned_integer_key_widths() { check_keys[u64]('nums = { 18446744073709551615 = "max", 18446744073709551616 = "skip" }', { u64(18446744073709551615): 'max' }) - check_keys[usize]('nums = { 42 = "value", "-1" = "skip" }', { - usize(42): 'value' + check_keys[uint]('nums = { 42 = "value", "-1" = "skip" }', { + uint(42): 'value' }) } diff --git a/vlib/toml/tests/narrow_int_test.v b/vlib/toml/tests/narrow_int_test.v index e0bf592a64..9ea4d93ece 100644 --- a/vlib/toml/tests/narrow_int_test.v +++ b/vlib/toml/tests/narrow_int_test.v @@ -127,35 +127,35 @@ fn test_decode_narrow_ints_in_collections_rejects_non_integers() { } struct OtherInts { - sizes []usize = [usize(7)] - isizes map[string]isize = { - 'a': isize(5) + sizes []uint = [uint(7)] + signed map[string]int = { + 'a': int(5) } runes []rune = [`x`] } fn test_decode_other_int_collections_keep_current() { - // Only u8, u16, u32, i8, i16 and i32 are decoded as narrow integers. Collections - // of the other integer types keep their current value, as before. - o := toml.decode[OtherInts]('sizes = [1]\nrunes = [1]\n\n[isizes]\nb = 2\n') or { + // Platform int maps are decoded normally; uint and rune collections keep their + // current value rather than being decoded as narrow integers. + o := toml.decode[OtherInts]('sizes = [1]\nrunes = [1]\n\n[signed]\nb = 2\n') or { panic(err) } - assert o.sizes == [usize(7)] - assert o.isizes == { - 'a': isize(5) + assert o.sizes == [uint(7)] + assert o.signed == { + 'b': int(2) } assert o.runes == [`x`] } struct WideInts { - u usize + u uint r rune } fn test_encode_other_ints() { - w := WideInts{~usize(0), `🚀`} + w := WideInts{~uint(0), `🚀`} encoded := toml.encode[WideInts](w) - // `usize` is not widened to `i64`, which would wrap its largest values. + // `uint` is not widened to `i64`, which would wrap its largest values. assert encoded.contains('${w.u}') // `rune` is still encoded as a string. assert encoded.contains('r = "🚀"') diff --git a/vlib/toml/toml.v b/vlib/toml/toml.v index 1adc3e8ea1..9f21c245d7 100644 --- a/vlib/toml/toml.v +++ b/vlib/toml/toml.v @@ -458,7 +458,7 @@ fn decode_map_key[K](text string) ?K { for digit in text[start..].bytes() { if digit < `0` || digit > `9` { return none } } - $if K is u8 || K is u16 || K is u32 || K is u64 || K is usize { + $if K is u8 || K is u16 || K is u32 || K is u64 || K is uint { if text.starts_with('-') { return none } unsigned_text := if text.starts_with('+') { text[1..] } else { text } n := strconv.common_parse_uint(unsigned_text, 10, int(sizeof(K) * 8), true, true) or { return none } diff --git a/vlib/v/checker/tests/disallow_pointer_arithmetic_err.out b/vlib/v/checker/tests/disallow_pointer_arithmetic_err.out index 1750884424..547ec06395 100644 --- a/vlib/v/checker/tests/disallow_pointer_arithmetic_err.out +++ b/vlib/v/checker/tests/disallow_pointer_arithmetic_err.out @@ -3,12 +3,12 @@ vlib/v/checker/tests/disallow_pointer_arithmetic_err.vv:7:7: warning: pointer ar 6 | _ := p * 2 // should be error 7 | _ := p + 5 // OK but only in unsafe block, r is *int | ~~~~~ - 8 | _ := p - p // OK even in safe code, but n should be isize + 8 | _ := p - p // OK even in safe code, but n should be int 9 | } vlib/v/checker/tests/disallow_pointer_arithmetic_err.vv:8:7: warning: pointer arithmetic is only allowed in `unsafe` blocks 6 | _ := p * 2 // should be error 7 | _ := p + 5 // OK but only in unsafe block, r is *int - 8 | _ := p - p // OK even in safe code, but n should be isize + 8 | _ := p - p // OK even in safe code, but n should be int | ~~~~~ 9 | } vlib/v/checker/tests/disallow_pointer_arithmetic_err.vv:4:7: error: invalid operator `+` to `&int` and `&int` @@ -38,11 +38,11 @@ vlib/v/checker/tests/disallow_pointer_arithmetic_err.vv:6:7: error: invalid oper 6 | _ := p * 2 // should be error | ~~~~~ 7 | _ := p + 5 // OK but only in unsafe block, r is *int - 8 | _ := p - p // OK even in safe code, but n should be isize + 8 | _ := p - p // OK even in safe code, but n should be int vlib/v/checker/tests/disallow_pointer_arithmetic_err.vv:6:7: error: infix `*` is not defined for pointer values 4 | _ := p + p // should be error 5 | _ := p * p // should be error 6 | _ := p * 2 // should be error | ~~~~~ 7 | _ := p + 5 // OK but only in unsafe block, r is *int - 8 | _ := p - p // OK even in safe code, but n should be isize + 8 | _ := p - p // OK even in safe code, but n should be int diff --git a/vlib/v/checker/tests/disallow_pointer_arithmetic_err.vv b/vlib/v/checker/tests/disallow_pointer_arithmetic_err.vv index 089163fabb..069254ba9c 100644 --- a/vlib/v/checker/tests/disallow_pointer_arithmetic_err.vv +++ b/vlib/v/checker/tests/disallow_pointer_arithmetic_err.vv @@ -5,5 +5,5 @@ fn main() { _ := p * p // should be error _ := p * 2 // should be error _ := p + 5 // OK but only in unsafe block, r is *int - _ := p - p // OK even in safe code, but n should be isize + _ := p - p // OK even in safe code, but n should be int } diff --git a/vlib/v/checker/tests/index_expr_implicit_int_downcast_err.js.out b/vlib/v/checker/tests/index_expr_implicit_int_downcast_err.js.out index e4983f4883..0902feeeee 100644 --- a/vlib/v/checker/tests/index_expr_implicit_int_downcast_err.js.out +++ b/vlib/v/checker/tests/index_expr_implicit_int_downcast_err.js.out @@ -12,7 +12,7 @@ vlib/v/checker/tests/index_expr_implicit_int_downcast_err.vv:11:12: error: canno | ~~~~~~~ 12 | println(a[idx_usize..]) 13 | } -vlib/v/checker/tests/index_expr_implicit_int_downcast_err.vv:12:12: error: cannot use `usize` as index type `int`, use an explicit cast like `int(expr)` +vlib/v/checker/tests/index_expr_implicit_int_downcast_err.vv:12:12: error: cannot use `uint` as index type `int`, use an explicit cast like `int(expr)` 10 | println(s[idx_u64]) 11 | println(a[idx_i64]) 12 | println(a[idx_usize..]) diff --git a/vlib/v/checker/tests/index_expr_implicit_int_downcast_err.vv b/vlib/v/checker/tests/index_expr_implicit_int_downcast_err.vv index 2708d9b79e..9656cc4907 100644 --- a/vlib/v/checker/tests/index_expr_implicit_int_downcast_err.vv +++ b/vlib/v/checker/tests/index_expr_implicit_int_downcast_err.vv @@ -4,7 +4,7 @@ fn main() { idx_u64 := u64(1) idx_u32 := u32(1) idx_i64 := i64(1) - idx_usize := usize(1) + idx_usize := uint(1) _ = s[int(idx_u64)] _ = a[idx_u32] println(s[idx_u64]) diff --git a/vlib/v/checker/tests/int_signess_call_arg_test.out b/vlib/v/checker/tests/int_signess_call_arg_test.out index 8147959028..16ed486940 100644 --- a/vlib/v/checker/tests/int_signess_call_arg_test.out +++ b/vlib/v/checker/tests/int_signess_call_arg_test.out @@ -26,7 +26,7 @@ vlib/v/checker/tests/int_signess_call_arg_test.vv:8:9: error: cannot use literal | ~~ 9 | ztest5(-1) 10 | } -vlib/v/checker/tests/int_signess_call_arg_test.vv:9:9: error: cannot use literal signed integer as `usize` in argument 1 to `ztest5` +vlib/v/checker/tests/int_signess_call_arg_test.vv:9:9: error: cannot use literal signed integer as `uint` in argument 1 to `ztest5` 7 | ztest3(-1) 8 | ztest4(-1) 9 | ztest5(-1) diff --git a/vlib/v/checker/tests/int_signess_call_arg_test.vv b/vlib/v/checker/tests/int_signess_call_arg_test.vv index 6689684a87..feda7592c7 100644 --- a/vlib/v/checker/tests/int_signess_call_arg_test.vv +++ b/vlib/v/checker/tests/int_signess_call_arg_test.vv @@ -25,6 +25,6 @@ fn ztest4(len u32) { println(len) } -fn ztest5(len usize) { +fn ztest5(len uint) { println(len) } diff --git a/vlib/v/checker/tests/modules/c_fn_import_marks_module_used/cmod/cmod.c.v b/vlib/v/checker/tests/modules/c_fn_import_marks_module_used/cmod/cmod.c.v index e3a1ff041d..bea49808b1 100644 --- a/vlib/v/checker/tests/modules/c_fn_import_marks_module_used/cmod/cmod.c.v +++ b/vlib/v/checker/tests/modules/c_fn_import_marks_module_used/cmod/cmod.c.v @@ -2,4 +2,4 @@ module cmod #include -fn C.strlen(s &char) usize +fn C.strlen(s &char) uint diff --git a/vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.out b/vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.out index 5d37338536..b5b57d389c 100644 --- a/vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.out +++ b/vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.out @@ -75,14 +75,14 @@ vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:64:8: war | ~~~~~~~~~~~~~~~~~~~~ 65 | f_isize(9223372036854775808) 66 | f_isize(-9223372036854775809) -vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:65:10: warning: value `9223372036854775808` is outside the range of `isize` in argument, this will be considered hard error soon +vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:65:10: warning: value `9223372036854775808` is outside the range of `int` in argument, this will be considered hard error soon 63 | f_i64(9223372036854775808) 64 | f_i64(-9223372036854775809) 65 | f_isize(9223372036854775808) | ~~~~~~~~~~~~~~~~~~~ 66 | f_isize(-9223372036854775809) 67 | -vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:66:10: warning: value `-9223372036854775809` is outside the range of `isize` in argument, this will be considered hard error soon +vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:66:10: warning: value `-9223372036854775809` is outside the range of `int` in argument, this will be considered hard error soon 64 | f_i64(-9223372036854775809) 65 | f_isize(9223372036854775808) 66 | f_isize(-9223372036854775809) @@ -145,14 +145,14 @@ vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:76:3: war | ~~~~~~~~~~~~~~~~~~~~~ 77 | isize_over_max: 9223372036854775808 78 | isize_under_min: -9223372036854775809 -vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:77:3: warning: value `9223372036854775808` is outside the range of `isize` in argument, this will be considered hard error soon +vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:77:3: warning: value `9223372036854775808` is outside the range of `int` in argument, this will be considered hard error soon 75 | i8_over_max: 128 76 | i8_under_min: -129 77 | isize_over_max: 9223372036854775808 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 78 | isize_under_min: -9223372036854775809 79 | u16_over_max: 65536 -vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:78:3: warning: value `-9223372036854775809` is outside the range of `isize` in argument, this will be considered hard error soon +vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:78:3: warning: value `-9223372036854775809` is outside the range of `int` in argument, this will be considered hard error soon 76 | i8_under_min: -129 77 | isize_over_max: 9223372036854775808 78 | isize_under_min: -9223372036854775809 @@ -249,26 +249,26 @@ vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:94:26: wa 94 | _ := GenericSample[i64]{9223372036854775808} | ~~~~~~~~~~~~~~~~~~~ 95 | _ := GenericSample[i64]{-9223372036854775809} - 96 | _ := GenericSample[isize]{9223372036854775808} + 96 | _ := GenericSample[int]{9223372036854775808} vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:95:26: warning: value `-9223372036854775809` is outside the range of `i64` in argument, this will be considered hard error soon 93 | _ := GenericSample[i32]{-2147483649} 94 | _ := GenericSample[i64]{9223372036854775808} 95 | _ := GenericSample[i64]{-9223372036854775809} | ~~~~~~~~~~~~~~~~~~~~ - 96 | _ := GenericSample[isize]{9223372036854775808} - 97 | _ := GenericSample[isize]{-9223372036854775809} -vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:96:28: warning: value `9223372036854775808` is outside the range of `isize` in argument, this will be considered hard error soon + 96 | _ := GenericSample[int]{9223372036854775808} + 97 | _ := GenericSample[int]{-9223372036854775809} +vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:96:26: warning: value `9223372036854775808` is outside the range of `int` in argument, this will be considered hard error soon 94 | _ := GenericSample[i64]{9223372036854775808} 95 | _ := GenericSample[i64]{-9223372036854775809} - 96 | _ := GenericSample[isize]{9223372036854775808} - | ~~~~~~~~~~~~~~~~~~~ - 97 | _ := GenericSample[isize]{-9223372036854775809} + 96 | _ := GenericSample[int]{9223372036854775808} + | ~~~~~~~~~~~~~~~~~~~ + 97 | _ := GenericSample[int]{-9223372036854775809} 98 | } -vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:97:28: warning: value `-9223372036854775809` is outside the range of `isize` in argument, this will be considered hard error soon +vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:97:26: warning: value `-9223372036854775809` is outside the range of `int` in argument, this will be considered hard error soon 95 | _ := GenericSample[i64]{-9223372036854775809} - 96 | _ := GenericSample[isize]{9223372036854775808} - 97 | _ := GenericSample[isize]{-9223372036854775809} - | ~~~~~~~~~~~~~~~~~~~~ + 96 | _ := GenericSample[int]{9223372036854775808} + 97 | _ := GenericSample[int]{-9223372036854775809} + | ~~~~~~~~~~~~~~~~~~~~ 98 | } vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:64:8: error: integer literal -9223372036854775809 overflows int 62 | f_i32(-2147483649) @@ -303,11 +303,11 @@ vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:95:26: er 94 | _ := GenericSample[i64]{9223372036854775808} 95 | _ := GenericSample[i64]{-9223372036854775809} | ~~~~~~~~~~~~~~~~~~~~ - 96 | _ := GenericSample[isize]{9223372036854775808} - 97 | _ := GenericSample[isize]{-9223372036854775809} -vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:97:28: error: integer literal -9223372036854775809 overflows int + 96 | _ := GenericSample[int]{9223372036854775808} + 97 | _ := GenericSample[int]{-9223372036854775809} +vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv:97:26: error: integer literal -9223372036854775809 overflows int 95 | _ := GenericSample[i64]{-9223372036854775809} - 96 | _ := GenericSample[isize]{9223372036854775808} - 97 | _ := GenericSample[isize]{-9223372036854775809} - | ~~~~~~~~~~~~~~~~~~~~ + 96 | _ := GenericSample[int]{9223372036854775808} + 97 | _ := GenericSample[int]{-9223372036854775809} + | ~~~~~~~~~~~~~~~~~~~~ 98 | } diff --git a/vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv b/vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv index 1b8e1b9009..c8791238b2 100644 --- a/vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv +++ b/vlib/v/checker/tests/number_literal_overflows_known_type_range_warn.vv @@ -26,7 +26,7 @@ fn f_i64(a i64) { _ = a } -fn f_isize(a isize) { +fn f_isize(a int) { _ = a } @@ -39,8 +39,8 @@ struct Sample { i64_under_min i64 i8_over_max i8 i8_under_min i8 - isize_over_max isize - isize_under_min isize + isize_over_max int + isize_under_min int u16_over_max u16 u32_over_max u32 u8_over_max u8 @@ -93,6 +93,6 @@ fn main() { _ := GenericSample[i32]{-2147483649} _ := GenericSample[i64]{9223372036854775808} _ := GenericSample[i64]{-9223372036854775809} - _ := GenericSample[isize]{9223372036854775808} - _ := GenericSample[isize]{-9223372036854775809} + _ := GenericSample[int]{9223372036854775808} + _ := GenericSample[int]{-9223372036854775809} } diff --git a/vlib/v/checker/tests/shift_ops_expressions.out b/vlib/v/checker/tests/shift_ops_expressions.out index 447106cc22..66894bfa60 100644 --- a/vlib/v/checker/tests/shift_ops_expressions.out +++ b/vlib/v/checker/tests/shift_ops_expressions.out @@ -1,5 +1,5 @@ -vlib/v/checker/tests/shift_ops_expressions.vv:4:2: notice: shifting a value from a signed type `int` can change the sign - 2 | mut a := 12 +vlib/v/checker/tests/shift_ops_expressions.vv:4:2: notice: shifting a value from a signed type `i32` can change the sign + 2 | mut a := i32(12) 3 | mut arr := []int{} 4 | a << 1 | ^ @@ -12,7 +12,7 @@ vlib/v/checker/tests/shift_ops_expressions.vv:5:5: notice: condition is always t | ~~~~ 6 | a << 2 7 | } -vlib/v/checker/tests/shift_ops_expressions.vv:6:3: notice: shifting a value from a signed type `int` can change the sign +vlib/v/checker/tests/shift_ops_expressions.vv:6:3: notice: shifting a value from a signed type `i32` can change the sign 4 | a << 1 5 | if true { 6 | a << 2 @@ -26,14 +26,14 @@ vlib/v/checker/tests/shift_ops_expressions.vv:8:10: notice: condition is always | ~~~~ 9 | println(c) 10 | a << 1 -vlib/v/checker/tests/shift_ops_expressions.vv:8:17: notice: shifting a value from a signed type `int` can change the sign +vlib/v/checker/tests/shift_ops_expressions.vv:8:17: notice: shifting a value from a signed type `i32` can change the sign 6 | a << 2 7 | } 8 | c := if true { a << 111 } else { a << 333 } | ^ 9 | println(c) 10 | a << 1 -vlib/v/checker/tests/shift_ops_expressions.vv:10:2: notice: shifting a value from a signed type `int` can change the sign +vlib/v/checker/tests/shift_ops_expressions.vv:10:2: notice: shifting a value from a signed type `i32` can change the sign 8 | c := if true { a << 111 } else { a << 333 } 9 | println(c) 10 | a << 1 @@ -61,14 +61,14 @@ vlib/v/checker/tests/shift_ops_expressions.vv:32:10: notice: condition is always | ~~~~ 33 | a << 1 34 | 999 -vlib/v/checker/tests/shift_ops_expressions.vv:33:3: notice: shifting a value from a signed type `int` can change the sign +vlib/v/checker/tests/shift_ops_expressions.vv:33:3: notice: shifting a value from a signed type `i32` can change the sign 31 | // 32 | x := if true { 33 | a << 1 | ^ 34 | 999 35 | } else { -vlib/v/checker/tests/shift_ops_expressions.vv:37:3: notice: shifting a value from a signed type `int` can change the sign +vlib/v/checker/tests/shift_ops_expressions.vv:37:3: notice: shifting a value from a signed type `i32` can change the sign 35 | } else { 36 | println('---') 37 | a << 9999 @@ -76,7 +76,7 @@ vlib/v/checker/tests/shift_ops_expressions.vv:37:3: notice: shifting a value fro 38 | println('---') 39 | 555 vlib/v/checker/tests/shift_ops_expressions.vv:47:5: notice: condition is always true - 45 | mut rr := 12 + 45 | mut rr := i32(12) 46 | rr >> 1 47 | if true { | ~~~~ @@ -97,7 +97,7 @@ vlib/v/checker/tests/shift_ops_expressions.vv:61:10: notice: condition is always 62 | rr >> 1 63 | 999 vlib/v/checker/tests/shift_ops_expressions.vv:4:2: error: unused expression - 2 | mut a := 12 + 2 | mut a := i32(12) 3 | mut arr := []int{} 4 | a << 1 | ~~~~~~ @@ -110,7 +110,7 @@ vlib/v/checker/tests/shift_ops_expressions.vv:6:3: error: unused expression | ~~~~~~ 7 | } 8 | c := if true { a << 111 } else { a << 333 } -vlib/v/checker/tests/shift_ops_expressions.vv:8:22: error: shift count for type `int` too large (maximum: 31 bits) +vlib/v/checker/tests/shift_ops_expressions.vv:8:22: error: shift count for type `i32` too large (maximum: 31 bits) 6 | a << 2 7 | } 8 | c := if true { a << 111 } else { a << 333 } @@ -145,7 +145,7 @@ vlib/v/checker/tests/shift_ops_expressions.vv:33:3: error: unused expression | ~~~~~~ 34 | 999 35 | } else { -vlib/v/checker/tests/shift_ops_expressions.vv:37:8: error: shift count for type `int` too large (maximum: 31 bits) +vlib/v/checker/tests/shift_ops_expressions.vv:37:8: error: shift count for type `i32` too large (maximum: 31 bits) 35 | } else { 36 | println('---') 37 | a << 9999 @@ -159,14 +159,14 @@ vlib/v/checker/tests/shift_ops_expressions.vv:37:3: error: unused expression | ~~~~~~~~~ 38 | println('---') 39 | 555 -vlib/v/checker/tests/shift_ops_expressions.vv:50:23: error: shift count for type `int` too large (maximum: 31 bits) +vlib/v/checker/tests/shift_ops_expressions.vv:50:23: error: shift count for type `i32` too large (maximum: 31 bits) 48 | rr >> 2 49 | } 50 | c := if true { rr >> 111 } else { rr >> 333 } | ~~~ 51 | println(c) 52 | rr >> 1 -vlib/v/checker/tests/shift_ops_expressions.vv:66:9: error: shift count for type `int` too large (maximum: 31 bits) +vlib/v/checker/tests/shift_ops_expressions.vv:66:9: error: shift count for type `i32` too large (maximum: 31 bits) 64 | } else { 65 | println('---') 66 | rr >> 9999 diff --git a/vlib/v/checker/tests/shift_ops_expressions.vv b/vlib/v/checker/tests/shift_ops_expressions.vv index 709aac155b..db13c1b4de 100644 --- a/vlib/v/checker/tests/shift_ops_expressions.vv +++ b/vlib/v/checker/tests/shift_ops_expressions.vv @@ -1,5 +1,5 @@ fn left_shifts() { - mut a := 12 + mut a := i32(12) mut arr := []int{} a << 1 if true { @@ -42,7 +42,7 @@ fn left_shifts() { } fn right_shifts() { - mut rr := 12 + mut rr := i32(12) rr >> 1 if true { rr >> 2 diff --git a/vlib/v/cmdexec/cmdexec_poll_test.v b/vlib/v/cmdexec/cmdexec_poll_test.v index b52d3b86a6..a4fb092a6c 100644 --- a/vlib/v/cmdexec/cmdexec_poll_test.v +++ b/vlib/v/cmdexec/cmdexec_poll_test.v @@ -29,7 +29,7 @@ fn test_cmdexec_owned_poll_can_coexist_with_application_poll_bindings() { defer { os.rmdir_all(root) or {} } // Unsuffixed source lets V supply the complete headerless C record layout. source := os.join_path(root, 'main.v') - os.write_file(source, '#flag -lc\nimport v.cmdexec\nstruct C.pollfd { fd i32 events i16 revents i16 }\n$if macos || ios || freebsd || openbsd || dragonfly || android || termux { fn C.poll(fds &C.pollfd, nfds u32, timeout i32) i32 } $else { fn C.poll(fds &C.pollfd, nfds usize, timeout i32) i32 }\nfn main() {\n mut descriptor := C.pollfd{fd: -1, events: 1}\n assert C.poll(&descriptor, 1, 0) == 0\n assert cmdexec.run_with_timeout("sh", ["-c", "sleep 0.01; echo OK"], 5000).exit_code == 0\n println("OK")\n}\n')! + os.write_file(source, '#flag -lc\nimport v.cmdexec\nstruct C.pollfd { fd i32 events i16 revents i16 }\n$if macos || ios || freebsd || openbsd || dragonfly || android || termux { fn C.poll(fds &C.pollfd, nfds u32, timeout i32) i32 } $else { fn C.poll(fds &C.pollfd, nfds uint, timeout i32) i32 }\nfn main() {\n mut descriptor := C.pollfd{fd: -1, events: 1}\n assert C.poll(&descriptor, 1, 0) == 0\n assert cmdexec.run_with_timeout("sh", ["-c", "sleep 0.01; echo OK"], 5000).exit_code == 0\n println("OK")\n}\n')! mut compilers := ['cc'] $if macos || linux { compilers << 'tcc' diff --git a/vlib/v/compiler_tests/array_data_pointer_arg_codegen_test.v b/vlib/v/compiler_tests/array_data_pointer_arg_codegen_test.v index 068783d85e..fbf071a39e 100644 --- a/vlib/v/compiler_tests/array_data_pointer_arg_codegen_test.v +++ b/vlib/v/compiler_tests/array_data_pointer_arg_codegen_test.v @@ -29,43 +29,43 @@ fn first(values &voidptr) voidptr { } fn set(value &voidptr) { - unsafe { *value = voidptr(usize(0x5678)) } + unsafe { *value = voidptr(uint(0x5678)) } } fn through_pointer(values &[]voidptr) { - assert first(values.data) == voidptr(usize(0x1234)) - assert first((values.data)) == voidptr(usize(0x1234)) - assert first(((values.data))) == voidptr(usize(0x1234)) + assert first(values.data) == voidptr(uint(0x1234)) + assert first((values.data)) == voidptr(uint(0x1234)) + assert first(((values.data))) == voidptr(uint(0x1234)) } fn through_mut(mut values []voidptr) { - assert first(values.data) == voidptr(usize(0x1234)) - assert first((values.data)) == voidptr(usize(0x1234)) - assert first(((values.data))) == voidptr(usize(0x1234)) + assert first(values.data) == voidptr(uint(0x1234)) + assert first((values.data)) == voidptr(uint(0x1234)) + assert first(((values.data))) == voidptr(uint(0x1234)) } fn through_alias(values &Values) { - assert first(values.data) == voidptr(usize(0x1234)) - assert first((values.data)) == voidptr(usize(0x1234)) - assert first(((values.data))) == voidptr(usize(0x1234)) + assert first(values.data) == voidptr(uint(0x1234)) + assert first((values.data)) == voidptr(uint(0x1234)) + assert first(((values.data))) == voidptr(uint(0x1234)) } fn main() { mut values := unsafe { []voidptr{len: 2} } - values[0] = voidptr(usize(0x1234)) - assert first(values.data) == voidptr(usize(0x1234)) - assert first((values.data)) == voidptr(usize(0x1234)) - assert first(((values.data))) == voidptr(usize(0x1234)) + values[0] = voidptr(uint(0x1234)) + assert first(values.data) == voidptr(uint(0x1234)) + assert first((values.data)) == voidptr(uint(0x1234)) + assert first(((values.data))) == voidptr(uint(0x1234)) through_pointer(&values) through_mut(mut values) aliased := Values(values) through_alias(&aliased) mut slot := Slot{} set(slot.data) - assert slot.data == voidptr(usize(0x5678)) + assert slot.data == voidptr(uint(0x5678)) slot.data = unsafe { nil } set((slot.data)) - assert slot.data == voidptr(usize(0x5678)) + assert slot.data == voidptr(uint(0x5678)) } ') or { panic(err) } bin := os.join_path(root, 'out${exe_suffix}') diff --git a/vlib/v/compiler_tests/borrowed_array_range_reference_test.v b/vlib/v/compiler_tests/borrowed_array_range_reference_test.v index f7598f2f86..a513d68aff 100644 --- a/vlib/v/compiler_tests/borrowed_array_range_reference_test.v +++ b/vlib/v/compiler_tests/borrowed_array_range_reference_test.v @@ -52,15 +52,15 @@ fn disturb_stack(seed int) int { fn main() { mut owner := Buffer{bytes: [u8(1), 2, 3, 4]} - address := unsafe { usize(owner.bytes.data) } + address := unsafe { uint(owner.bytes.data) } { mut first := owner.free_buffer(1) - assert unsafe { usize(first.data) == address + 1 } + assert unsafe { uint(first.data) == address + 1 } assert first.len == 3 assert disturb_stack(5) == 13 { mut second := owner.free_buffer(0) - assert unsafe { usize(second.data) == address } + assert unsafe { uint(second.data) == address } fill(mut second, 8) assert owner.bytes[0] == 8 assert second.len == 4 @@ -71,7 +71,7 @@ fn main() { assert first.len == 3 } assert owner.bytes == [u8(8), 9, 3, 4] - assert unsafe { usize(owner.bytes.data) == address } + assert unsafe { uint(owner.bytes.data) == address } { read := forwarded(owner, 1, 3) zero := owner.buffer(0, 2) @@ -80,23 +80,23 @@ fn main() { assert read.len == 2 assert zero.len == 2 assert empty.len == 0 - assert unsafe { usize(read.data) == address + 1 } - assert unsafe { usize(zero.data) == address } - assert unsafe { usize(empty.data) == address + 2 } + assert unsafe { uint(read.data) == address + 1 } + assert unsafe { uint(zero.data) == address } + assert unsafe { uint(empty.data) == address + 2 } assert unsafe { (*read)[0] == 9 } assert unsafe { (*zero)[0] == 8 } } assert owner.bytes == [u8(8), 9, 3, 4] - global_address := unsafe { usize(global_bytes.data) } + global_address := unsafe { uint(global_bytes.data) } global_range := global_view(1, 3) - assert unsafe { usize(global_range.data) == global_address + 1 } + assert unsafe { uint(global_range.data) == global_address + 1 } assert unsafe { (*global_range)[0] == 6 } heap_range := heap_view() assert disturb_stack(12) == 27 assert unsafe { (*heap_range)[0] == 5 } assert heap_range.len == 2 mut copied := owner.copy() - assert unsafe { usize(copied.data) != address + 1 } + assert unsafe { uint(copied.data) != address + 1 } copied[0] = 7 assert owner.bytes[1] == 9 assert copied[0] == 7 @@ -185,7 +185,7 @@ fn test_borrowed_string_range_headers_survive_returns_and_loop_iterations() { } fn main() { text := "abc\\nxyz".to_owned() - address := unsafe { usize(text.str) } + address := unsafe { uint(text.str) } { parts := split(text) first := view(text, 0, 4) @@ -195,18 +195,18 @@ fn test_borrowed_string_range_headers_survive_returns_and_loop_iterations() { assert disturb_stack(3) == 9 assert *parts[0] == "abc\\n" assert *parts[1] == "xyz" - assert unsafe { usize(parts[0].str) == address } - assert unsafe { usize(parts[1].str) == address + 4 } + assert unsafe { uint(parts[0].str) == address } + assert unsafe { uint(parts[1].str) == address + 4 } assert voidptr(parts[0]) != voidptr(parts[1]) assert *full == text - assert unsafe { usize(full.str) == address } + assert unsafe { uint(full.str) == address } assert *first == "abc\\n" assert *last == "xyz" assert empty.len == 0 - assert unsafe { usize(empty.str) == address + 2 } + assert unsafe { uint(empty.str) == address + 2 } } assert text == "abc\\nxyz" - assert unsafe { usize(text.str) == address } + assert unsafe { uint(text.str) == address } } ')! for mode in ['-no-parallel', ''] { diff --git a/vlib/v/compiler_tests/borrowed_container_param_annotation_test.v b/vlib/v/compiler_tests/borrowed_container_param_annotation_test.v index d7507ffea4..56488bb4e9 100644 --- a/vlib/v/compiler_tests/borrowed_container_param_annotation_test.v +++ b/vlib/v/compiler_tests/borrowed_container_param_annotation_test.v @@ -7,11 +7,11 @@ fn test_borrowed_array_parameter_indexing_survives_generic_annotation() { defer { os.rmdir_all(root) or {} } source := os.join_path(root, 'main.v') os.write_file(source, 'fn identity[T](value T) T { return value } -fn skip_table(literal &[]u8) []usize { - m := usize(literal.len) - mut skip := []usize{len: 256, init: m} +fn skip_table(literal &[]u8) []uint { + m := uint(literal.len) + mut skip := []uint{len: 256, init: m} for i := 0; i + 1 < literal.len; i++ { - skip[int(literal[i])] = m - 1 - usize(i) + skip[int(literal[i])] = m - 1 - uint(i) } return skip } diff --git a/vlib/v/compiler_tests/c_extern_fn_callback_arg_codegen_test.v b/vlib/v/compiler_tests/c_extern_fn_callback_arg_codegen_test.v index d6ad2c92c9..ae4b93c93e 100644 --- a/vlib/v/compiler_tests/c_extern_fn_callback_arg_codegen_test.v +++ b/vlib/v/compiler_tests/c_extern_fn_callback_arg_codegen_test.v @@ -53,8 +53,8 @@ static int native_register_const_int(int (*callback)(const unsigned char *, int) #insert "${header}" -fn C.native_send(voidptr, &u8, usize) i32 -fn C.native_register(fn (voidptr, &u8, usize) i32) i32 +fn C.native_send(voidptr, &u8, uint) i32 +fn C.native_register(fn (voidptr, &u8, uint) i32) i32 fn C.native_send_int(voidptr, &u8, int) i32 fn C.native_register_int(fn (voidptr, &u8, int) i32) i32 @@ -62,7 +62,7 @@ type NativeConstIntCallback = fn (const_buf &u8, len int) int fn C.native_register_const_int(NativeConstIntCallback) int -fn v_send(ctx voidptr, buf &u8, len usize) i32 { +fn v_send(ctx voidptr, buf &u8, len uint) i32 { return i32(len) + i32(unsafe { buf[0] }) + i32(ctx != unsafe { nil }) } diff --git a/vlib/v/compiler_tests/c_fn_redeclaration_and_empty_struct_test.v b/vlib/v/compiler_tests/c_fn_redeclaration_and_empty_struct_test.v index ef7d6af07c..0c359f2f9f 100644 --- a/vlib/v/compiler_tests/c_fn_redeclaration_and_empty_struct_test.v +++ b/vlib/v/compiler_tests/c_fn_redeclaration_and_empty_struct_test.v @@ -57,8 +57,8 @@ fn test_v3_c_fn_redeclarations_and_empty_struct_defaults() { compatible_root := write_c_fn_redecl_v3_project('c_fn_compatible', { 'v.mod': "Module { name: 'c_fn_compatible' }\n" - 'moda/moda.v': 'module moda\n\nstruct C.Display {}\nstruct C.Widget {\n\tvalue int\n}\n\nfn C.compat_probe(value int, data byteptr, display voidptr, mut state usize) int\nfn C.local_make() &C.Widget\n\npub fn touch() {\n\tmut state := usize(0)\n\tC.compat_probe(0, unsafe { nil }, unsafe { nil }, mut state)\n}\n\npub fn value() int {\n\treturn C.local_make().value\n}\n' - 'modb/modb.v': 'module modb\n\nstruct C.Display {}\nstruct C.Widget {\n\tvalue int\n}\n\ntype CInt = i32\n\nfn C.compat_probe(value CInt, data &u8, display &C.Display, state &usize) i32\nfn C.local_make() voidptr\n\npub fn touch() {\n\tmut state := usize(0)\n\tC.compat_probe(0, unsafe { nil }, unsafe { nil }, &state)\n}\n\npub fn make() voidptr {\n\treturn C.local_make()\n}\n' + 'moda/moda.v': 'module moda\n\nstruct C.Display {}\nstruct C.Widget {\n\tvalue int\n}\n\nfn C.compat_probe(value int, data byteptr, display voidptr, mut state uint) int\nfn C.local_make() &C.Widget\n\npub fn touch() {\n\tmut state := uint(0)\n\tC.compat_probe(0, unsafe { nil }, unsafe { nil }, mut state)\n}\n\npub fn value() int {\n\treturn C.local_make().value\n}\n' + 'modb/modb.v': 'module modb\n\nstruct C.Display {}\nstruct C.Widget {\n\tvalue int\n}\n\ntype CInt = i32\n\nfn C.compat_probe(value CInt, data &u8, display &C.Display, state &uint) i32\nfn C.local_make() voidptr\n\npub fn touch() {\n\tmut state := uint(0)\n\tC.compat_probe(0, unsafe { nil }, unsafe { nil }, &state)\n}\n\npub fn make() voidptr {\n\treturn C.local_make()\n}\n' 'main.v': 'module main\n\nimport moda as _\nimport modb as _\nimport net as _\n\nfn C.fcntl(fd int, cmd int, arg int) int\n\nfn main() {\n\targ := 0\n\t_ = C.fcntl(-1, 0, arg)\n}\n' })! defer { diff --git a/vlib/v/compiler_tests/c_global_static_codegen_test.v b/vlib/v/compiler_tests/c_global_static_codegen_test.v index e2a711a528..8b821a00ef 100644 --- a/vlib/v/compiler_tests/c_global_static_codegen_test.v +++ b/vlib/v/compiler_tests/c_global_static_codegen_test.v @@ -268,7 +268,7 @@ fn test_nil_pointer_global_initializer_is_emitted_at_file_scope() { c_code := gen_c_for_source('nil_pointer_global_static_initializer', '__global early_state = unsafe { nil } fn use_before_vinit() { - early_state = voidptr(usize(0x1000)) + early_state = voidptr(uint(0x1000)) } fn main() {} diff --git a/vlib/v/compiler_tests/c_struct_redeclaration_test.v b/vlib/v/compiler_tests/c_struct_redeclaration_test.v index 10df5e505b..0658e39cee 100644 --- a/vlib/v/compiler_tests/c_struct_redeclaration_test.v +++ b/vlib/v/compiler_tests/c_struct_redeclaration_test.v @@ -108,7 +108,7 @@ fn test_c_struct_redeclaration_checks_field_signature() { cached_termios_good := run_v3_project(v3_bin, 'module_cache_termios_shims', { 'v.mod': 'Module { name: "cached_termios_shims" }\n' 'term/term_cached.vh': 'module term\n\nstruct C.termios {\n\tc_iflag int\n}\n' - 'term/termios/termios.vh': 'module termios\n\nstruct C.termios {\n\tc_iflag usize\n\tc_ispeed usize\n}\n' + 'term/termios/termios.vh': 'module termios\n\nstruct C.termios {\n\tc_iflag uint\n\tc_ispeed uint\n}\n' 'main.v': 'module main\n\nimport term\nimport term.termios\n\nfn main() {}\n' }) assert cached_termios_good.exit_code == 0, cached_termios_good.output diff --git a/vlib/v/compiler_tests/default_clone_heap_receiver_test.v b/vlib/v/compiler_tests/default_clone_heap_receiver_test.v index 3bbc77d40a..bca98f0053 100644 --- a/vlib/v/compiler_tests/default_clone_heap_receiver_test.v +++ b/vlib/v/compiler_tests/default_clone_heap_receiver_test.v @@ -49,7 +49,7 @@ fn main() { value := HeapValue{bytes: [u8(1), 2], drops: &drops} mut cloned := value.clone() assert cloned.bytes == [u8(1), 2] - assert unsafe { usize(cloned.bytes.data) != usize(value.bytes.data) } + assert unsafe { uint(cloned.bytes.data) != uint(value.bytes.data) } cloned.bytes[0] = 3 assert value.bytes[0] == 1 } @@ -58,23 +58,23 @@ fn main() { mut value := HeapValue{bytes: [u8(4), 5], drops: &drops} first := (value).clone() assert first.bytes == [u8(4), 5] - assert unsafe { usize(first.bytes.data) != usize(value.bytes.data) } + assert unsafe { uint(first.bytes.data) != uint(value.bytes.data) } third := clone_mutable(mut value) assert third.bytes == [u8(4), 5] - assert unsafe { usize(third.bytes.data) != usize(value.bytes.data) } + assert unsafe { uint(third.bytes.data) != uint(value.bytes.data) } pointer := &value second := pointer.clone() assert second.bytes == [u8(4), 5] - assert unsafe { usize(second.bytes.data) != usize(value.bytes.data) } + assert unsafe { uint(second.bytes.data) != uint(value.bytes.data) } } assert drops == 6 { mut value := PromotedValue{bytes: [u8(6), 7], drops: &drops} pointer := value.reference() - assert unsafe { usize(pointer.bytes.data) == usize(value.bytes.data) } + assert unsafe { uint(pointer.bytes.data) == uint(value.bytes.data) } mut cloned := value.clone() assert cloned.bytes == [u8(6), 7] - assert unsafe { usize(cloned.bytes.data) != usize(value.bytes.data) } + assert unsafe { uint(cloned.bytes.data) != uint(value.bytes.data) } cloned.bytes[0] = 8 assert pointer.bytes[0] == 6 } diff --git a/vlib/v/compiler_tests/generic_constraint_operators_test.v b/vlib/v/compiler_tests/generic_constraint_operators_test.v index 0f60a1bc06..8bd22092b0 100644 --- a/vlib/v/compiler_tests/generic_constraint_operators_test.v +++ b/vlib/v/compiler_tests/generic_constraint_operators_test.v @@ -205,11 +205,10 @@ type AliasAdd = OpAdd // The types, each as a constraint of its own; `[T Named]` is the interface // constraint, the rest are sets of one type. -const operator_types = ['i8', 'i16', 'int', 'i64', 'u8', 'u16', 'u32', 'u64', 'isize', 'usize', - 'rune', 'f32', 'f64', 'string', 'bool', 'Color', 'Perm', 'User', 'Sum', 'IntArr', 'IntArr2', - 'StrMap', 'Fn0', 'MyInt', 'MyStr', 'MyFloat', 'Vec', 'Eq', 'OpAdd', 'OpSub', 'OpMul', 'OpDiv', - 'OpMod', 'OpPow', 'OpLt', 'OpLtEq', 'OpAll', 'OpIdx', 'OpIdxSet', 'Meters', 'AliasAdd', 'Named', - 'voidptr'] +const operator_types = ['i8', 'i16', 'int', 'i64', 'u8', 'u16', 'u32', 'u64', 'uint', 'rune', 'f32', + 'f64', 'string', 'bool', 'Color', 'Perm', 'User', 'Sum', 'IntArr', 'IntArr2', 'StrMap', 'Fn0', + 'MyInt', 'MyStr', 'MyFloat', 'Vec', 'Eq', 'OpAdd', 'OpSub', 'OpMul', 'OpDiv', 'OpMod', 'OpPow', + 'OpLt', 'OpLtEq', 'OpAll', 'OpIdx', 'OpIdxSet', 'Meters', 'AliasAdd', 'Named', 'voidptr'] // Pointers are left to the checker: an operator on them is not checked. const unchecked_types = ['voidptr'] diff --git a/vlib/v/compiler_tests/headerless_iconv_codegen_test.v b/vlib/v/compiler_tests/headerless_iconv_codegen_test.v index 4861f6dbdf..3506f94dd8 100644 --- a/vlib/v/compiler_tests/headerless_iconv_codegen_test.v +++ b/vlib/v/compiler_tests/headerless_iconv_codegen_test.v @@ -34,7 +34,7 @@ fn main() { to := "UTF-8" from := "UTF-8" cd := C.iconv_open(charptr(to.str), charptr(from.str)) - if isize(cd) != -1 { + if int(cd) != -1 { C.iconv_close(cd) } println("iconv-ok") diff --git a/vlib/v/compiler_tests/orm_null_text_codegen_test.v b/vlib/v/compiler_tests/orm_null_text_codegen_test.v index 55524c663d..736265b18a 100644 --- a/vlib/v/compiler_tests/orm_null_text_codegen_test.v +++ b/vlib/v/compiler_tests/orm_null_text_codegen_test.v @@ -245,8 +245,8 @@ struct Metric { wide_32 u32 wide_i i64 wide_u u64 - wide_is isize - wide_us usize + wide_is int + wide_us uint } fn main() { @@ -256,8 +256,8 @@ fn main() { wide_32: u32(1) << 31 wide_i: i64(1) << 40 wide_u: u64(1) << 40 - wide_is: isize(1) << 40 - wide_us: usize(1) << 40 + wide_is: int(1) << 40 + wide_us: uint(1) << 40 } sql db { insert metric into Metric @@ -282,11 +282,9 @@ fn main() { assert c_code.contains('orm__append_field_value_data_T_u32('), c_code assert c_code.contains('orm__append_field_value_data_T_i64('), c_code assert c_code.contains('orm__append_field_value_data_T_u64('), c_code - assert c_code.contains('orm__append_field_value_data_T_isize('), c_code - assert c_code.contains('orm__append_field_value_data_T_usize('), c_code + assert c_code.contains('orm__append_field_value_data_T_uint('), c_code assert c_code.contains('orm__primitive_from_field_value_T_u32('), c_code assert c_code.contains('orm__primitive_from_field_value_T_i64('), c_code assert c_code.contains('orm__primitive_from_field_value_T_u64('), c_code - assert c_code.contains('orm__primitive_from_field_value_T_isize('), c_code - assert c_code.contains('orm__primitive_from_field_value_T_usize('), c_code + assert c_code.contains('orm__primitive_from_field_value_T_uint('), c_code } diff --git a/vlib/v/compiler_tests/owned_map_or_value_codegen_test.v b/vlib/v/compiler_tests/owned_map_or_value_codegen_test.v index d8f07a606d..dad4a3dfef 100644 --- a/vlib/v/compiler_tests/owned_map_or_value_codegen_test.v +++ b/vlib/v/compiler_tests/owned_map_or_value_codegen_test.v @@ -69,9 +69,9 @@ fn byte_copy(entries &map[string][]u8) []u8 { fn move_indexed() string { mut entries := {"found": "moved".to_owned()} - address := unsafe { usize(entries["found"].str) } + address := unsafe { uint(entries["found"].str) } item := entries["found"] or { "fallback".to_owned() } - assert unsafe { usize(item.str) } == address + assert unsafe { uint(item.str) } == address return item } @@ -111,7 +111,7 @@ fn main() { assert copied[0].text == "first" assert copied[1].text == "second" assert copied[2].text == "third" - assert unsafe { usize(copied.data) != usize(builder.entries["found"].data) } + assert unsafe { uint(copied.data) != uint(builder.entries["found"].data) } copied[0].text = "changed".repeat(1) assert builder.entries["found"][0].text == "first" drop_owned(copied) @@ -122,7 +122,7 @@ fn main() { { bytes := {"found": [u8(1), 2, 3]} mut copied := byte_copy(&bytes) - assert unsafe { usize(copied.data) != usize(bytes["found"].data) } + assert unsafe { uint(copied.data) != uint(bytes["found"].data) } copied[0] = 4 assert bytes["found"] == [u8(1), 2, 3] } diff --git a/vlib/v/compiler_tests/ownership_signed_integer_parsing_test.v b/vlib/v/compiler_tests/ownership_signed_integer_parsing_test.v index dbadc33eb0..5774a6abc5 100644 --- a/vlib/v/compiler_tests/ownership_signed_integer_parsing_test.v +++ b/vlib/v/compiler_tests/ownership_signed_integer_parsing_test.v @@ -9,18 +9,18 @@ fn test_ownership_signed_integer_parsers_preserve_their_inputs() { fn main() { negative := "-12345".to_owned() - negative_address := unsafe { usize(negative.str) } + negative_address := unsafe { uint(negative.str) } assert negative.int() == -12345 assert negative.int() == -12345 assert strconv.parse_int(negative, 10, 64)! == -12345 assert negative == "-12345" - assert unsafe { usize(negative.str) == negative_address } + assert unsafe { uint(negative.str) == negative_address } positive := "+23456".to_owned() - positive_address := unsafe { usize(positive.str) } + positive_address := unsafe { uint(positive.str) } assert positive.int() == 23456 assert strconv.parse_int(positive, 10, 64)! == 23456 assert positive == "+23456" - assert unsafe { usize(positive.str) == positive_address } + assert unsafe { uint(positive.str) == positive_address } unsigned := "34567".to_owned() assert unsigned.int() == 34567 assert strconv.parse_int(unsigned, 10, 64)! == 34567 diff --git a/vlib/v/compiler_tests/ownership_storage_summary_test.v b/vlib/v/compiler_tests/ownership_storage_summary_test.v index a4bd4a1590..98ca8fbfa9 100644 --- a/vlib/v/compiler_tests/ownership_storage_summary_test.v +++ b/vlib/v/compiler_tests/ownership_storage_summary_test.v @@ -261,8 +261,8 @@ struct Scalars { flag bool fraction f64 letter rune - signed isize - unsigned usize + signed int + unsigned uint number Number state State values [2]int @@ -282,12 +282,12 @@ fn letter() rune { ptr := &local return ptr.letter } -fn signed() isize { +fn signed() int { local := Scalars{signed: -2} ptr := &local return ptr.signed } -fn unsigned() usize { +fn unsigned() uint { local := Scalars{unsigned: 3} ptr := &local return ptr.unsigned diff --git a/vlib/v/compiler_tests/pointer_voidptr_compat_test.v b/vlib/v/compiler_tests/pointer_voidptr_compat_test.v index 2e07d2683d..aeada563af 100644 --- a/vlib/v/compiler_tests/pointer_voidptr_compat_test.v +++ b/vlib/v/compiler_tests/pointer_voidptr_compat_test.v @@ -280,7 +280,7 @@ fn test_pointer_to_voidptr_return_keeps_pointer_value() { fn main() { unsafe { values := &voidptr(make_values()) - println(usize(values[1])) + println(uint(values[1])) free(values) } } diff --git a/vlib/v/compiler_tests/posix_wait_header_codegen_test.v b/vlib/v/compiler_tests/posix_wait_header_codegen_test.v index ac36ab26e2..4c4e1a2c78 100644 --- a/vlib/v/compiler_tests/posix_wait_header_codegen_test.v +++ b/vlib/v/compiler_tests/posix_wait_header_codegen_test.v @@ -518,7 +518,7 @@ fn test_unsuffixed_winapi_decls_use_wide_exports() { fn C.GetModuleFileName(voidptr, &u16, u32) u32 fn C.CreateFile(&u16, u32, u32, voidptr, u32, u32, voidptr) voidptr fn C.LoadLibrary(&u16) voidptr -fn C.DefWindowProc(voidptr, u32, usize, isize) isize +fn C.DefWindowProc(voidptr, u32, uint, C.ptrdiff_t) C.ptrdiff_t fn main() { path := &u16(unsafe { nil }) @@ -560,7 +560,7 @@ fn test_c_fn_value_keeps_its_prototype_in_serial_and_parallel_cgen() { v3_bin := wait_header_build_v3() source := 'module main -fn C.V3WaitHeaderCallback(voidptr, u32) isize +fn C.V3WaitHeaderCallback(voidptr, u32) C.ptrdiff_t fn main() { _ = voidptr(&C.V3WaitHeaderCallback) diff --git a/vlib/v/compiler_tests/post_merge_review_fixes_test.v b/vlib/v/compiler_tests/post_merge_review_fixes_test.v index f77efd3faf..109f607a9a 100644 --- a/vlib/v/compiler_tests/post_merge_review_fixes_test.v +++ b/vlib/v/compiler_tests/post_merge_review_fixes_test.v @@ -257,11 +257,11 @@ fn main() { } fn test_c_integer_parameters_accept_other_integer_variable_types() { - check_good('c_integer_variable_arguments', 'fn C.integer_probe(usize, isize, u64) int + check_good('c_integer_variable_arguments', 'fn C.integer_probe(uint, int, u64) int fn main() { - signed := isize(1) - unsigned := usize(2) + signed := int(1) + unsigned := uint(2) word := int(3) _ = C.integer_probe(signed, unsigned, word) } @@ -4245,7 +4245,7 @@ fn test_latest_pr_review_codegen_regressions() { ') assert small_int_comparison == 'true\ntrue' - c_strings := run_good(v3_bin, 'single_char_c_string_pointer_context', "fn C.strlen(charptr) usize + c_strings := run_good(v3_bin, 'single_char_c_string_pointer_context', "fn C.strlen(charptr) uint fn main() { println(C.strlen(c'\\n')) @@ -8042,7 +8042,7 @@ fn test_user_c_string_function_is_not_inferred_unsafe() { v3_bin := build_v3() src_path := '${tmp_test_path('user_c_strlen_not_unsafe')}.v' bin_path := tmp_test_path('user_c_strlen_not_unsafe') - os.write_file(src_path, "fn C.strlen(charptr) usize + os.write_file(src_path, "fn C.strlen(charptr) uint fn main() { println(C.strlen(c'x')) diff --git a/vlib/v/compiler_tests/review_transform_regressions_test.v b/vlib/v/compiler_tests/review_transform_regressions_test.v index c105972de8..5951bc4e41 100644 --- a/vlib/v/compiler_tests/review_transform_regressions_test.v +++ b/vlib/v/compiler_tests/review_transform_regressions_test.v @@ -2996,8 +2996,8 @@ fn test_immediately_invoked_closure_keeps_integer_encoded_capture_address_alive( v3_bin := build_v3_review_transform() source := 'fn main() { mut value := 41 - address := (fn [mut value] () usize { - return usize(voidptr(&value)) + address := (fn [mut value] () uint { + return uint(voidptr(&value)) })() p := unsafe { &int(voidptr(address)) } println(int_str(unsafe { *p + 1 })) @@ -3017,8 +3017,8 @@ fn test_immediately_invoked_closure_keeps_aliased_integer_capture_address_alive( v3_bin := build_v3_review_transform() source := 'fn main() { mut value := 41 - address := (fn [mut value] () usize { - encoded := usize(voidptr(&value)) + address := (fn [mut value] () uint { + encoded := uint(voidptr(&value)) return encoded })() p := unsafe { &int(voidptr(address)) } @@ -12711,7 +12711,7 @@ fn make_aligned_memdup() &int { fn make_builtin_memdup() &int { local := 44 - return unsafe { &int(memdup(&local, sizeof(int))) } + return unsafe { &int(memdup(&local, int(sizeof(int)))) } } fn main() { diff --git a/vlib/v/compiler_tests/source_integrity_test.v b/vlib/v/compiler_tests/source_integrity_test.v index bdf7f61d84..35d6f1e389 100644 --- a/vlib/v/compiler_tests/source_integrity_test.v +++ b/vlib/v/compiler_tests/source_integrity_test.v @@ -154,10 +154,10 @@ fn test_parser_canonicalizes_repeated_node_text() { prefs := pref.new_preferences() mut p := parser.Parser.new(prefs) p.parse_into(path) - mut pointers := []usize{} + mut pointers := []uint{} for idx in 0 .. p.a.nodes.len { if p.a.nodes[idx].value == 'repeated' { - pointers << usize(p.a.nodes[idx].value.str) + pointers << uint(p.a.nodes[idx].value.str) } } assert pointers.len >= 3 diff --git a/vlib/v/compiler_tests/testdata/format_thousands_28797.v b/vlib/v/compiler_tests/testdata/format_thousands_28797.v index efff8974de..3dc42f9e73 100644 --- a/vlib/v/compiler_tests/testdata/format_thousands_28797.v +++ b/vlib/v/compiler_tests/testdata/format_thousands_28797.v @@ -208,8 +208,7 @@ pub type Number = int | u16 | u32 | u64 - | isize - | usize + | uint | f32 | f64 @@ -217,7 +216,7 @@ pub type Number = int // a thousands separator every three digits. With a `Separator`, its `integer` // and `decimal` fields configure the output; a string uses that string for // grouping and `.` as the decimal separator. It accepts all built-in signed -// and unsigned integer types, `isize`, `usize`, `f32`, and `f64`. +// and unsigned integer types, `f32`, and `f64`. // // Example: // assert strconv.format_thousands(1234567, Separator{}) == '1 234 567' diff --git a/vlib/v/compiler_tests/wasm_codegen_test.v b/vlib/v/compiler_tests/wasm_codegen_test.v index aec8a1c0e8..16fbeaa4c7 100644 --- a/vlib/v/compiler_tests/wasm_codegen_test.v +++ b/vlib/v/compiler_tests/wasm_codegen_test.v @@ -466,7 +466,7 @@ fn test_wasm_control_flow_and_int_print() { fn test_wasm_lowered_integer_print_formats() { v3_bin := v3_binary() // Print lowering uses dotted numeric str methods, including u64's unsigned range. - src := 'fn main() {\n\tfor number in 1 .. 4 {\n\t\tprintln(number * number)\n\t}\n\tprintln(i8(-8))\n\tprintln(i16(-160))\n\tprintln(i32(-320))\n\tprintln(i64(-6400000000))\n\tprintln(isize(-32))\n\tprintln(u8(255).str())\n\tprintln(u16(65535).str())\n\tprintln(u32(4294967295).str())\n\tprintln(u64(18446744073709551615))\n\tprintln(usize(4294967295).str())\n}\n' + src := 'fn main() {\n\tfor number in 1 .. 4 {\n\t\tprintln(number * number)\n\t}\n\tprintln(i8(-8))\n\tprintln(i16(-160))\n\tprintln(i32(-320))\n\tprintln(i64(-6400000000))\n\tprintln(int(-32))\n\tprintln(u8(255).str())\n\tprintln(u16(65535).str())\n\tprintln(u32(4294967295).str())\n\tprintln(u64(18446744073709551615))\n\tprintln(uint(4294967295).str())\n}\n' wasm := compile_to_wasm(v3_bin, src, 'wasm_integer_print_formats') assert_valid_wasm(wasm) run_wasi_expect(wasm, ['1', '4', '9', '-8', '-160', '-320', '-6400000000', '-32', '255', '65535', diff --git a/vlib/v/compiler_tests/x11_source_abi_alias_codegen_test.v b/vlib/v/compiler_tests/x11_source_abi_alias_codegen_test.v index a99dd26ac3..0b211e290e 100644 --- a/vlib/v/compiler_tests/x11_source_abi_alias_codegen_test.v +++ b/vlib/v/compiler_tests/x11_source_abi_alias_codegen_test.v @@ -54,7 +54,7 @@ fn C.XSetWMProtocols(display &C.Display, window Window, protocols &Atom, count i fn C.XGetWindowProperty(display &C.Display, window Window, property Atom, offset i64, length i64, delete int, req_type Atom, actual &Atom, actual_format &int, count &NativeULong, bytes &NativeULong, prop &&u8) int fn C.take_time(value &C.NativeTime) -fn helper(display &C.Display, window Window, value &&u8) usize { +fn helper(display &C.Display, window Window, value &&u8) uint { mut actual_type := Atom(0) mut item_count := NativeULong(0) mut bytes_after := NativeULong(0) @@ -62,7 +62,7 @@ fn helper(display &C.Display, window Window, value &&u8) usize { property := Atom(0) C.XGetWindowProperty(display, window, property, 0, 1, 0, property, &actual_type, &actual_format, &item_count, &bytes_after, value) - return usize(item_count) + return uint(item_count) } fn main() { diff --git a/vlib/v/diagserver/diagserver_linux.c.v b/vlib/v/diagserver/diagserver_linux.c.v index 2a87e1093b..f22e0cacba 100644 --- a/vlib/v/diagserver/diagserver_linux.c.v +++ b/vlib/v/diagserver/diagserver_linux.c.v @@ -31,8 +31,8 @@ fn C.v3_linux_parent_death_signal(signal_number int) int fn C.v3_linux_memory_file(name &char) int fn C.lseek(fd int, offset i64, whence int) i64 fn C.flock(i32, i32) i32 -fn C.pread(fd int, buf voidptr, count usize, offset i64) isize -fn C.pwrite(fd int, buf voidptr, count usize, offset i64) isize +fn C.pread(fd int, buf voidptr, count uint, offset i64) C.ptrdiff_t +fn C.pwrite(fd int, buf voidptr, count uint, offset i64) C.ptrdiff_t // Request is what a child of the diagnostics server was made for: answering // `question`, the questions of a `query` line, or checking the program when it @@ -448,7 +448,7 @@ pub fn (r &Request) incremental_record() string { mut out := []u8{} mut chunk := []u8{len: 65536} for { - got := C.pread(r.record_fd, unsafe { &u8(chunk.data) }, usize(chunk.len), i64(out.len)) + got := C.pread(r.record_fd, unsafe { &u8(chunk.data) }, uint(chunk.len), i64(out.len)) if got < 0 && C.errno == C.EINTR { continue } @@ -472,7 +472,7 @@ pub fn (r &Request) keep_incremental_record(text string) { C.ftruncate(r.record_fd, u64(0)) mut written := 0 for written < text.len { - wrote := C.pwrite(r.record_fd, unsafe { text.str + written }, usize(text.len - written), + wrote := C.pwrite(r.record_fd, unsafe { text.str + written }, uint(text.len - written), i64(written)) if wrote < 0 && C.errno == C.EINTR { continue @@ -519,7 +519,7 @@ fn read_from_start(fd int) string { mut out := []u8{} mut chunk := []u8{len: 65536} for { - got := C.read(fd, unsafe { &u8(chunk.data) }, usize(chunk.len)) + got := C.read(fd, unsafe { &u8(chunk.data) }, uint(chunk.len)) if got < 0 && C.errno == C.EINTR { continue } @@ -966,7 +966,7 @@ fn read_into(path string, mut buffer []u8) ?int { } mut size := 0 for size < buffer.len { - got := C.read(fd, unsafe { &u8(buffer.data) + size }, usize(buffer.len - size)) + got := C.read(fd, unsafe { &u8(buffer.data) + size }, uint(buffer.len - size)) if got < 0 { if C.errno == C.EINTR { continue @@ -1039,7 +1039,7 @@ fn (mut r LineReader) read_line() ?string { } line << c } - got := C.read(r.fd, unsafe { &u8(r.chunk.data) }, usize(r.chunk.len)) + got := C.read(r.fd, unsafe { &u8(r.chunk.data) }, uint(r.chunk.len)) if got < 0 && C.errno == C.EINTR { continue } diff --git a/vlib/v/driver/c_compiler_flags_test.v b/vlib/v/driver/c_compiler_flags_test.v index 4ca4f7ee1e..22b363de7f 100644 --- a/vlib/v/driver/c_compiler_flags_test.v +++ b/vlib/v/driver/c_compiler_flags_test.v @@ -1291,7 +1291,7 @@ fn test_v3_bundled_tcc_native_object_build_is_cwd_independent() { v_source := os.join_path(root, 'main.v') output := os.join_path(root, 'main' + $if windows { '.exe' } $else { '' }) os.write_file(c_source, '#include \nsize_t v3_tcc_native_object_probe(void) { return sizeof(size_t); }\n')! - os.write_file(v_source, '#flag ${c_object}\n\nfn C.v3_tcc_native_object_probe() usize\n\nfn main() {\n\tassert C.v3_tcc_native_object_probe() > 0\n}\n')! + os.write_file(v_source, '#flag ${c_object}\n\nfn C.v3_tcc_native_object_probe() uint\n\nfn main() {\n\tassert C.v3_tcc_native_object_probe() > 0\n}\n')! build := cmdexec.run_in(v3_driver_test_executable(), ['-new-compiler', '-nocache', '-no-retry-compilation', '-cc', 'tcc', '-o', output, v_source], root) assert build.exit_code == 0, build.output @@ -1317,7 +1317,7 @@ fn test_v3_implicit_tcc_cpp_native_object_uses_platform_headers() { v_source := os.join_path(root, 'main.v') output := os.join_path(root, 'main') os.write_file(cpp_source, '#include \nextern "C" size_t v3_cpp_object_probe(void) { return sizeof(std::max_align_t); }\n')! - os.write_file(v_source, '#flag ${cpp_object}\n\nfn C.v3_cpp_object_probe() usize\n\nfn main() {\n\tassert C.v3_cpp_object_probe() > 0\n}\n')! + os.write_file(v_source, '#flag ${cpp_object}\n\nfn C.v3_cpp_object_probe() uint\n\nfn main() {\n\tassert C.v3_cpp_object_probe() > 0\n}\n')! old_vflags := os.getenv_opt('VFLAGS') os.unsetenv('VFLAGS') defer { diff --git a/vlib/v/driver/deprecated_integer_types.v b/vlib/v/driver/deprecated_integer_types.v new file mode 100644 index 0000000000..5fffa07678 --- /dev/null +++ b/vlib/v/driver/deprecated_integer_types.v @@ -0,0 +1,29 @@ +module driver + +import v.parser +import v.pref +import v.errors as compiler_errors + +fn report_deprecated_integer_types(paths []string, prefs &pref.Preferences, warns_are_errors bool) bool { + mut failed := false + mut diagnostics := compiler_errors.DiagnosticRun{} + for path in paths { + mut p := parser.Parser.new(prefs) + a := p.parse_file(path) + for diagnostic in p.diagnostics { + if diagnostic.severity != 'warning:' + || !diagnostic.message.starts_with('`isize` is deprecated;') + && !diagnostic.message.starts_with('`usize` is deprecated;') { + continue + } + severity := if warns_are_errors { 'error:' } else { 'warning:' } + if compiler_errors.json_output() { + eprintln(compiler_errors.json_parser_diagnostic(severity, diagnostic.message, []string{}, a, diagnostic.pos)) + } else { + eprintln(diagnostics.formatted_parser_diagnostic(severity, diagnostic.message, a, diagnostic.pos)) + } + failed = failed || warns_are_errors + } + } + return failed +} diff --git a/vlib/v/driver/deprecated_integer_types_test.v b/vlib/v/driver/deprecated_integer_types_test.v new file mode 100644 index 0000000000..ba57547a87 --- /dev/null +++ b/vlib/v/driver/deprecated_integer_types_test.v @@ -0,0 +1,113 @@ +module driver + +import os +import v.cmdexec + +fn test_platform_signed_c_binding_preserves_values_above_32_bits() { + $if !macos && !linux { + return + } + root := os.join_path(os.vtmp_dir(), 'platform_signed_c_${os.getpid()}') + os.mkdir_all(root) or { panic(err) } + defer { os.rmdir_all(root) or {} } + os.write_file(os.join_path(root, 'count.h'), 'static inline __PTRDIFF_TYPE__ platform_signed_count(__PTRDIFF_TYPE__ value) { return value; }\n') or { panic(err) } + os.write_file(os.join_path(root, 'main.v'), 'module main +#insert "count.h" +fn C.platform_signed_count(value C.ptrdiff_t) C.ptrdiff_t +fn main() { + value := if sizeof(int) == 8 { int(i64(1) << 40) } else { int(1234567) } + assert int(C.platform_signed_count(C.ptrdiff_t(value))) == value + assert int(C.platform_signed_count(C.ptrdiff_t(-value))) == -value +} +') or { panic(err) } + for backend in ['c', 'fastc'] { + program := os.join_path(root, backend) + built := cmdexec.run(@VEXE, ['-b', backend, '-o', program, root]) + assert built.exit_code == 0, built.output + ran := cmdexec.run(program, []) + assert ran.exit_code == 0, ran.output + } +} + +fn test_deprecated_integer_types_warn_and_respect_warnings_as_errors() { + root := os.join_path(os.vtmp_dir(), 'deprecated_integer_types_${os.getpid()}') + os.mkdir_all(root) or { panic(err) } + defer { os.rmdir_all(root) or {} } + source := os.join_path(root, 'main.v') + os.write_file(source, 'module main +fn main() { + x := isize(-1) + y := usize(1) + assert x < 0 + assert y > 0 + assert x.str() == "-1" + assert y.str() == "1" +} +') or { panic(err) } + for backend in ['c', 'fastc'] { + output := os.join_path(root, backend + '.c') + args := ['-b', backend, '-o', output, root] + built := cmdexec.run(@VEXE, args) + assert built.exit_code == 0, built.output + assert built.output.contains('`isize` is deprecated; use `int` instead'), built.output + assert built.output.contains('`usize` is deprecated; use `uint` instead'), built.output + assert built.output.contains('main.v:3:'), built.output + assert built.output.contains('main.v:4:'), built.output + $if macos || linux { + program := os.join_path(root, backend) + compiled := cmdexec.run(@VEXE, ['-b', backend, '-o', program, root]) + assert compiled.exit_code == 0, compiled.output + ran := cmdexec.run(program, []) + assert ran.exit_code == 0, ran.output + } + strict := cmdexec.run(@VEXE, ['-W', ...args]) + assert strict.exit_code != 0, strict.output + assert strict.output.contains('error: `isize` is deprecated; use `int` instead'), strict.output + assert strict.output.contains('error: `usize` is deprecated; use `uint` instead'), strict.output + } +} + +fn test_nested_explicit_generic_arguments_use_canonical_integer_names() { + root := os.join_path(os.vtmp_dir(), 'nested_legacy_integer_${os.getpid()}') + os.mkdir_all(root) or { panic(err) } + defer { os.rmdir_all(root) or {} } + os.write_file(os.join_path(root, 'main.v'), 'module main +struct Box[T] { value T } +fn identity[T](value T) T { return value } +fn main() { + box := identity[Box[usize]](Box[usize]{value: 123}) + assert box.value == 123 + nested := identity[Box[Box[usize]]](Box[Box[usize]]{value: Box[usize]{value: 456}}) + assert nested.value.value == 456 +} +') or { panic(err) } + program := os.join_path(root, 'program') + built := cmdexec.run(@VEXE, ['-o', program, root]) + assert built.exit_code == 0, built.output + ran := cmdexec.run(program, []) + assert ran.exit_code == 0, ran.output +} + +fn test_modern_integer_library_calls_do_not_emit_legacy_type_warnings() { + root := os.join_path(os.vtmp_dir(), 'modern_integer_libraries_${os.getpid()}') + os.mkdir_all(root) or { panic(err) } + defer { os.rmdir_all(root) or {} } + os.write_file(os.join_path(root, 'main.v'), 'module main +import strconv +import sync +import encoding.binary +fn main() { + assert strconv.format_thousands(1234567, ",") == "1,234,567" + mut local := sync.new_tls(int(-42))! + assert local.get()! == -42 + local.destroy()! + assert binary.encode_binary(int(-42))!.len == 8 +} +') or { panic(err) } + program := os.join_path(root, 'program') + built := cmdexec.run(@VEXE, ['-nocache', '-o', program, root]) + assert built.exit_code == 0, built.output + assert !built.output.contains('is deprecated; use'), built.output + ran := cmdexec.run(program, []) + assert ran.exit_code == 0, ran.output +} diff --git a/vlib/v/driver/driver.v b/vlib/v/driver/driver.v index bb114f3978..58b2d4567f 100644 --- a/vlib/v/driver/driver.v +++ b/vlib/v/driver/driver.v @@ -4355,7 +4355,7 @@ fn should_scope_prealloc_cgen() bool { return false } -fn transform_scope_size_is_bounded(size usize) bool { +fn transform_scope_size_is_bounded(size uint) bool { return size > 0 && size <= 64 * 1024 * 1024 } @@ -4372,7 +4372,7 @@ fn transform_scope_fits_retention_budget(scope voidptr) bool { fn transform_helper_scopes_fit_retention_budget(scopes []voidptr) bool { $if prealloc { if scopes.len == 0 { return false } - mut remaining := usize(256 * 1024 * 1024) + mut remaining := uint(256 * 1024 * 1024) for scope in scopes { size := unsafe { prealloc_scope_allocated_size(scope) } if size == 0 || size > remaining { return false } @@ -7679,7 +7679,7 @@ fn publish_transform_helper_scope_texts(mut a flat.FlatAst, scopes []voidptr) { // Only a few thousand nodes are flagged; jump between them. mut idx := 0 for idx < flags.len { - found := unsafe { &u8(C.memchr(&u8(flags.data) + idx, 1, usize(flags.len - idx))) } + found := unsafe { &u8(C.memchr(&u8(flags.data) + idx, 1, uint(flags.len - idx))) } if isnil(found) { break } @@ -7857,7 +7857,7 @@ fn clone_flat_ast_after_transform_from_scope(ast &flat.FlatAst, scope voidptr) & if ast.nodes.len > 0 { unsafe { nodes.grow_len(ast.nodes.len) - vmemcpy(nodes.data, ast.nodes.data, isize(ast.nodes.len) * isize(sizeof(flat.Node))) + vmemcpy(nodes.data, ast.nodes.data, int(ast.nodes.len) * int(sizeof(flat.Node))) } } for idx in 0 .. nodes.len { @@ -12349,6 +12349,10 @@ pub fn run(args []string) { if os.getenv('FASTC_BENCH_PHASES') != '' { eprintln('fastc-phase driver.generated ${driver_sw.elapsed().microseconds()}us') } + if report_deprecated_integer_types(fastc_generation.deprecated_integer_paths, prefs, + warns_are_errors) { + exit(1) + } fastc_artifact_path := canonical_v3_fastc_output_path(fastc_artifact_file) for source_path in fastc_generation.source_paths { if fastc_artifact_path != '' && fastc_artifact_path == source_path @@ -13044,6 +13048,7 @@ pub fn run(args []string) { exit(1) } mut printed_parser_diagnostic := false + mut parser_diagnostics := compiler_errors.DiagnosticRun{} if (!silent || !only_check_syntax) && (!parser_diagnostics_already_printed || parser_has_errors) { for diagnostic in p.diagnostics { @@ -13063,17 +13068,17 @@ pub fn run(args []string) { if compiler_errors.json_output() { mut details := diagnostic.details.clone() if diagnostic.detail_pos.is_valid() { - details << compiler_errors.formatted_parser_diagnostic('details:', + details << parser_diagnostics.formatted_parser_diagnostic('details:', diagnostic.detail_message, a, diagnostic.detail_pos) } eprintln(compiler_errors.json_parser_diagnostic(severity, diagnostic.message, details, a, diagnostic.pos)) } else { - eprintln(compiler_errors.formatted_parser_diagnostic(severity, diagnostic.message, a, diagnostic.pos)) + eprintln(parser_diagnostics.formatted_parser_diagnostic(severity, diagnostic.message, a, diagnostic.pos)) print_type_diagnostic_details(diagnostic.details) if diagnostic.detail_pos.is_valid() { eprintln('Details: ') - eprintln(compiler_errors.formatted_parser_diagnostic('details:', + eprintln(parser_diagnostics.formatted_parser_diagnostic('details:', diagnostic.detail_message, a, diagnostic.detail_pos)) } } @@ -21214,7 +21219,7 @@ fn wasm_supported_array_elem_bytes(type_name string) bool { return false } elem := type_name[2..] - return elem in ['int', 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'isize', 'usize', + return elem in ['int', 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'isize', 'uint', 'f32', 'f64', 'bool', 'char', 'rune'] } @@ -23535,7 +23540,7 @@ const implicit_type_prefixes = ['mut ', 'shared ', '&', '?', '!'] // leaves them. const implicit_number_types = [flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_isize, flat.source_type_u8, - flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, flat.source_type_usize, + flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, flat.source_type_uint, flat.source_type_f32, flat.source_type_f64] fn implicit_normalize_type(raw_id u32, index ImplicitFieldScanIndex) u32 { @@ -24038,7 +24043,7 @@ fn insert_synthetic_imports(mut a flat.FlatAst, insertions []SyntheticInsertion) // Move backwards by region: source and destination may overlap, and // earlier regions must remain intact until their own move. unsafe { - vmemmove(&a.nodes[insertion.pos + i + 1], &a.nodes[insertion.pos], isize(end - insertion.pos) * isize(sizeof(flat.Node))) + vmemmove(&a.nodes[insertion.pos + i + 1], &a.nodes[insertion.pos], int(end - insertion.pos) * int(sizeof(flat.Node))) } } a.nodes[insertion.pos + i] = imports[i] diff --git a/vlib/v/driver/environment_test.v b/vlib/v/driver/environment_test.v index bfe7f3bb83..229db2bb97 100644 --- a/vlib/v/driver/environment_test.v +++ b/vlib/v/driver/environment_test.v @@ -767,7 +767,7 @@ fn test_scoped_ast_storage_copy_preserves_persistent_text_and_promotes_retiring_ mut a := flat.FlatAst.new() _, canonical := a.intern_text('persistent value') a.add_node(flat.Node{ kind: .ident, value: canonical }) - persistent_ptr := usize(voidptr(a.nodes[0].value.str)) + persistent_ptr := uint(voidptr(a.nodes[0].value.str)) constraints := ['persistent constraint'.clone()] scope := prealloc_scope_begin_for_v3() value := 'retiring value'.clone() @@ -778,7 +778,7 @@ fn test_scoped_ast_storage_copy_preserves_persistent_text_and_promotes_retiring_ a.nodes << generated prealloc_scope_leave_for_v3(scope) cloned := clone_flat_ast_after_transform_from_scope(&a, scope) - assert usize(voidptr(cloned.nodes[0].value.str)) == persistent_ptr + assert uint(voidptr(cloned.nodes[0].value.str)) == persistent_ptr assert !scoped_value_owned(scope, cloned.nodes.data) assert !scoped_value_owned(scope, cloned.nodes[1].value.str) assert !scoped_value_owned(scope, cloned.nodes[1].typ_text().str) diff --git a/vlib/v/driver/gc_precision_test.v b/vlib/v/driver/gc_precision_test.v index bda47350e0..7afad4ae23 100644 --- a/vlib/v/driver/gc_precision_test.v +++ b/vlib/v/driver/gc_precision_test.v @@ -42,11 +42,11 @@ fn test_precise_boehm_counts_each_small_allocation_after_warmup() { os.write_file(source, 'module main #include struct C.GC_prof_stats_s { - bytes_allocd_since_gc usize - allocd_bytes_before_gc usize - gc_no usize + bytes_allocd_since_gc uint + allocd_bytes_before_gc uint + gc_no uint } -fn C.GC_get_prof_stats(&C.GC_prof_stats_s, usize) usize +fn C.GC_get_prof_stats(&C.GC_prof_stats_s, uint) uint fn allocated_bytes() u64 { mut stats := C.GC_prof_stats_s{} C.GC_get_prof_stats(&stats, sizeof(C.GC_prof_stats_s)) diff --git a/vlib/v/driver/instance_check_nix.c.v b/vlib/v/driver/instance_check_nix.c.v index 6424185485..68e462b5ba 100644 --- a/vlib/v/driver/instance_check_nix.c.v +++ b/vlib/v/driver/instance_check_nix.c.v @@ -77,7 +77,7 @@ fn (check ProgramInstanceCheck) finish() int { } mut buf := []u8{len: 65536} for { - n := C.read(check.output, buf.data, usize(buf.len)) + n := C.read(check.output, buf.data, uint(buf.len)) if n < 0 && C.errno == C.EINTR { continue } diff --git a/vlib/v/driver/transform_scope_retention_test.v b/vlib/v/driver/transform_scope_retention_test.v index 80d13fba7e..4480436bd3 100644 --- a/vlib/v/driver/transform_scope_retention_test.v +++ b/vlib/v/driver/transform_scope_retention_test.v @@ -1,12 +1,12 @@ module driver fn test_transform_scope_retention_budget_bounds_allocation_size() { - limit := usize(64 * 1024 * 1024) + limit := uint(64 * 1024 * 1024) assert !transform_scope_size_is_bounded(0) assert transform_scope_size_is_bounded(1) assert transform_scope_size_is_bounded(limit) assert !transform_scope_size_is_bounded(limit + 1) - assert !transform_scope_size_is_bounded(~usize(0)) + assert !transform_scope_size_is_bounded(~uint(0)) } fn test_transform_scope_retention_requires_an_actual_arena() { @@ -30,7 +30,7 @@ fn test_helper_scope_retention_checks_the_combined_budget() { assert text == 'borrowed helper text' // Repeating a real arena exercises accumulation without a large allocation. size := unsafe { prealloc_scope_allocated_size(first) } - count := int(usize(256 * 1024 * 1024) / size) + count := int(uint(256 * 1024 * 1024) / size) assert transform_helper_scopes_fit_retention_budget([]voidptr{len: count, init: first}) assert !transform_helper_scopes_fit_retention_budget([]voidptr{len: count + 1, init: first}) } diff --git a/vlib/v/driver/wasm_arrays_gate_test.v b/vlib/v/driver/wasm_arrays_gate_test.v index e086ec22b2..69f192e673 100644 --- a/vlib/v/driver/wasm_arrays_gate_test.v +++ b/vlib/v/driver/wasm_arrays_gate_test.v @@ -76,8 +76,8 @@ fn test_wasm_gate_rejects_maps_structs_fixed_nested() { } fn test_wasm_supported_array_elem() { - for t in ['int', 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'isize', 'usize', 'f32', - 'f64', 'bool', 'char', 'rune'] { + for t in ['int', 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'uint', 'f32', 'f64', + 'bool', 'char', 'rune'] { assert wasm_supported_array_elem(flat.source_type_id('[]' + t)), t } for t in ['', '[]', 'int', 'map[string]int', 'Point', '[2]int', '[][]int', '[]Point', '[]string'] { diff --git a/vlib/v/driver/windows_icon_windows.c.v b/vlib/v/driver/windows_icon_windows.c.v index b6ffdf4e65..bd0a8a57de 100644 --- a/vlib/v/driver/windows_icon_windows.c.v +++ b/vlib/v/driver/windows_icon_windows.c.v @@ -103,5 +103,5 @@ fn add_windows_long_path_manifest(exe_path string) !bool { } fn windows_resource_id(id int) voidptr { - return voidptr(usize(id)) + return voidptr(uint(id)) } diff --git a/vlib/v/embed_file/embed_file.c.v b/vlib/v/embed_file/embed_file.c.v index 4fe030f180..689ed60f8c 100644 --- a/vlib/v/embed_file/embed_file.c.v +++ b/vlib/v/embed_file/embed_file.c.v @@ -9,5 +9,5 @@ module embed_file // symbols outside a `.c.v` one. @[inline; unsafe] fn join_chunks_raw_alloc(size int) &u8 { - return unsafe { &u8(C.malloc(usize(size))) } + return unsafe { &u8(C.malloc(uint(size))) } } diff --git a/vlib/v/embed_file/embed_file.v b/vlib/v/embed_file/embed_file.v index a9419cd57c..fc363f31d9 100644 --- a/vlib/v/embed_file/embed_file.v +++ b/vlib/v/embed_file/embed_file.v @@ -32,7 +32,7 @@ fn join_chunks_buffer(size int) &u8 { return buffer } } $else { - return unsafe { &u8(malloc(isize(size))) } + return unsafe { &u8(malloc(int(size))) } } } @@ -62,7 +62,7 @@ pub fn join_chunks(chunks &EmbedFileChunk, len int) &u8 { if offset + n > len { n = len - offset } - vmemcpy(buffer + offset, chunk.data, isize(n)) + vmemcpy(buffer + offset, chunk.data, int(n)) offset += n chunk++ } diff --git a/vlib/v/errors/README.md b/vlib/v/errors/README.md index 00157105d2..354a376cb7 100644 --- a/vlib/v/errors/README.md +++ b/vlib/v/errors/README.md @@ -3,6 +3,7 @@ `v.errors` formats compiler diagnostics with source excerpts, source positions, and template call stacks. `DiagnosticRun` shares path resolution and the most recently read source file across a report, and finds a line in that file from the line it found before. Its -`formatted_error` method preserves the standalone formatter output. +`formatted_error` and `formatted_parser_diagnostic` methods preserve the standalone formatter +output. Reuse a run when reporting multiple checker or parser diagnostics. Use a fresh run for each report and keep the working directory, path display settings, and reported source files unchanged while it is in use. diff --git a/vlib/v/errors/format.v b/vlib/v/errors/format.v index 48e7e8f5ed..62227ce84e 100644 --- a/vlib/v/errors/format.v +++ b/vlib/v/errors/format.v @@ -74,8 +74,14 @@ pub fn formatted_parser_error(message string, a &flat.FlatAst, pos token.Pos) st // formatted_parser_diagnostic renders a colored parser diagnostic with template call-site context. pub fn formatted_parser_diagnostic(kind string, message string, a &flat.FlatAst, pos token.Pos) string { - file := a.source_files[pos.id] or { return formatted_message(kind, message) } mut run := DiagnosticRun{} + return run.formatted_parser_diagnostic(kind, message, a, pos) +} + +// formatted_parser_diagnostic renders a parser diagnostic, sharing source and path lookups +// with the other diagnostics in this run. +pub fn (mut run DiagnosticRun) formatted_parser_diagnostic(kind string, message string, a &flat.FlatAst, pos token.Pos) string { + file := a.source_files[pos.id] or { return formatted_message(kind, message) } result := run.formatted_source_error(kind, message, file, pos) return run.append_template_call_stack(result, kind, a, pos) } @@ -145,34 +151,45 @@ fn (mut run DiagnosticRun) formatted_source_error(kind string, message string, f if position.filename != file.name || position.line != physical_line { if position.filename != file.name { if source := run.read_source(position.filename) { - lines := run.source_lines_through(source, position.line - source_context_before, - position.line + source_context_after) - if position.line <= lines.len { + first := int_max(1, position.line - source_context_before) + lines := run.source_lines_for_excerpt(source, first, + position.line + source_context_after, true) + if position.line - first < lines.len { write_source_excerpt(mut result, kind, lines, position.line, span_start, - span_end) + span_end, first - 1) return result.str().trim_right('\n') } } } source := run.read_source(file.name) or { return result.str().trim_right('\n') } - lines := run.source_lines_through(source, physical_line, physical_line) - if physical_line <= lines.len { - write_source_line(mut result, kind, lines[physical_line - 1], position.line, true, + lines := run.source_lines_for_file(source, file, physical_line, physical_line) + if lines.len > 0 { + write_source_line(mut result, kind, lines[0], position.line, true, true, span_start, span_end) } return result.str().trim_right('\n') } } source := run.read_source(file.name) or { return result.str().trim_right('\n') } - lines := run.source_lines_through(source, position.line - source_context_before, - position.line + source_context_after) + first := int_max(1, position.line - source_context_before) + lines := run.source_lines_for_file(source, file, first, position.line + source_context_after) if lines.len == 0 { return result.str().trim_right('\n') } - write_source_excerpt(mut result, kind, lines, position.line, span_start, span_end) + write_source_excerpt(mut result, kind, lines, position.line, span_start, span_end, first - 1) return result.str().trim_right('\n') } +// Parsed files already index their line starts. Use that index instead of scanning +// the preceding source again when the first warning is near the end of a large file. +fn (mut run DiagnosticRun) source_lines_for_file(source string, file &token.File, first_line int, last_line int) []string { + if file.has_source_lines() && first_line >= 1 && first_line <= file.line_count() { + return source_lines_from(source, file.line_start(first_line), 1, 1, + last_line - first_line + 1) + } + return run.source_lines_for_excerpt(source, first_line, last_line, true) +} + // source_lines_through returns the lines `source.split_into_lines()` holds up to the 1-based // line `last_line`: all of them when the source is shorter, the first `last_line` otherwise. // Lines before `first_line` are left empty. A diagnostic prints a few lines around its @@ -220,10 +237,20 @@ fn source_lines_from(source string, start_offset int, start_line int, first_line // source_lines_through returns what the function of the same name does for the source // read last. The diagnostics of one file come in the order of their lines, so the search // for a line starts where the one before it was found rather than at the top of the file. -@[direct_array_access] fn (mut run DiagnosticRun) source_lines_through(source string, first_line int, last_line int) []string { + return run.source_lines_for_excerpt(source, first_line, last_line, false) +} + +// Compact excerpts contain only the displayed lines, avoiding an array of empty +// strings for every preceding line when a large legacy file has many warnings. +@[direct_array_access] +fn (mut run DiagnosticRun) source_lines_for_excerpt(source string, first_line int, last_line int, compact bool) []string { if !run.source_read || source.str != run.source.str || source.len != run.source.len { - return source_lines_through(source, first_line, last_line) + lines := source_lines_through(source, first_line, last_line) + if compact { + return lines[int_min(lines.len, int_max(0, first_line - 1))..] + } + return lines } target := int_min(int_max(1, first_line), int_max(1, last_line)) mut line := 1 @@ -249,20 +276,26 @@ fn (mut run DiagnosticRun) source_lines_through(source string, first_line int, l } if line < target { // The source ends before the first line asked for. + if compact { + return []string{} + } return []string{len: if line_start < source.len { line } else { line - 1 }} } run.cursor_line = line run.cursor_offset = line_start + if compact { + return source_lines_from(source, line_start, 1, first_line - line + 1, last_line - line + 1) + } return source_lines_from(source, line_start, line, first_line, last_line) } // write_source_excerpt writes the lines around `target_line` of `lines`, and highlights // the span `span_start..span_end` (byte offsets relative to the line start) on it. -fn write_source_excerpt(mut result strings.Builder, kind string, lines []string, target_line int, span_start int, span_end int) { +fn write_source_excerpt(mut result strings.Builder, kind string, lines []string, target_line int, span_start int, span_end int, line_base int) { first_line := int_max(1, target_line - source_context_before) - last_line := int_min(lines.len, target_line + source_context_after) + last_line := int_min(lines.len + line_base, target_line + source_context_after) for line_number := first_line; line_number <= last_line; line_number++ { - write_source_line(mut result, kind, lines[line_number - 1], line_number, + write_source_line(mut result, kind, lines[line_number - line_base - 1], line_number, line_number == target_line, line_number == last_line, span_start, span_end) } } diff --git a/vlib/v/errors/format_test.v b/vlib/v/errors/format_test.v index ef52d91ef8..3f86a8632a 100644 --- a/vlib/v/errors/format_test.v +++ b/vlib/v/errors/format_test.v @@ -71,6 +71,11 @@ fn test_template_call_stack_includes_every_parent() { 0 })) assert output.count('called from ') == 2, output + mut run := DiagnosticRun{} + for _ in 0 .. 2 { + assert run.formatted_parser_diagnostic('error:', 'undefined ident: `missing`', a, + token.new_pos(3, inner_source.index('missing') or { 0 })) == output + } assert output.contains('called from ${relative_error_path(outer_path)}:1:'), output assert output.contains('called from ${relative_error_path(main_path)}:2:'), output } @@ -120,6 +125,11 @@ fn test_diagnostic_run_finds_lines_in_any_order() { for request in requests { assert run.source_lines_through(source, request[0], request[1]) == source_lines_through(source, request[0], request[1]), '${source.bytes()} ${request}' + if request[0] >= 1 && request[1] >= request[0] { + expected := source_lines_through(source, request[0], request[1]) + assert run.source_lines_for_excerpt(source, request[0], request[1], true) == expected[int_min(expected.len, + request[0] - 1)..], '${source.bytes()} ${request}' + } } // another text of the same length is not the source the run has read other := source.clone() @@ -160,10 +170,13 @@ fn test_diagnostic_run_formats_like_separate_diagnostics() { token.new_pos(9, 0), ] mut run := DiagnosticRun{} + mut parser_run := DiagnosticRun{} for i, pos in reports { message := 'diagnostic ${i}' expected := formatted_error('notice:', message, a, flat.NodeId(-1), pos) assert run.formatted_error('notice:', message, a, flat.NodeId(-1), pos) == expected + assert parser_run.formatted_parser_diagnostic('warning:', message, a, pos) == formatted_parser_diagnostic('warning:', + message, a, pos) if pos.id != 9 { assert expected.contains(' | '), expected } diff --git a/vlib/v/eval/eval.v b/vlib/v/eval/eval.v index e258804510..d8dd29dccd 100644 --- a/vlib/v/eval/eval.v +++ b/vlib/v/eval/eval.v @@ -5004,7 +5004,7 @@ fn is_builtin_str_receiver_type_name(name_id u32) bool { return name_id in [flat.source_type_bool, flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_isize, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, - flat.source_type_usize, flat.source_type_f32, flat.source_type_f64, flat.source_type_rune, + flat.source_type_uint, flat.source_type_f32, flat.source_type_f64, flat.source_type_rune, flat.source_type_char, flat.source_type_string] } @@ -5639,7 +5639,7 @@ fn (mut e Eval) zero_value_for_type_name_in_module(type_name_id u32, module_name if name == flat.source_type_string { return Value('') } if name in [flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, - flat.source_type_u64, flat.source_type_isize, flat.source_type_usize, flat.source_type_rune, + flat.source_type_u64, flat.source_type_isize, flat.source_type_uint, flat.source_type_rune, flat.source_type_char] { return Value(i64(0)) } @@ -5890,7 +5890,7 @@ fn (e &Eval) cast_value_in_module(value Value, type_name_id u32, module_name str source := e.unwrap_sum_cast_value(value, target_name) if name in [flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, - flat.source_type_u64, flat.source_type_isize, flat.source_type_usize, flat.source_type_rune, + flat.source_type_u64, flat.source_type_isize, flat.source_type_uint, flat.source_type_rune, flat.source_type_char] { return Value(e.value_as_int(source)!) } @@ -5948,7 +5948,7 @@ fn (e &Eval) value_matches_type_name(value Value, target_name_id u32) bool { return name in [flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, flat.source_type_isize, - flat.source_type_usize, flat.source_type_rune, flat.source_type_char] + flat.source_type_uint, flat.source_type_rune, flat.source_type_char] } EnumValue { return e.type_name_matches(value.type_name, name) } f64 { return name in [flat.source_type_f32, flat.source_type_f64] } @@ -6790,7 +6790,7 @@ fn (e &Eval) qualify_type_name_bytes(module_name string, type_name string) strin fn is_builtin_type_name_bytes(name string) bool { return name in ['bool', 'int', 'i8', 'i16', 'i32', 'i64', 'isize', 'u8', 'u16', 'u32', 'u64', - 'usize', 'f32', 'f64', 'rune', 'char', 'string', 'void', 'voidptr', 'charptr', 'byteptr', + 'uint', 'f32', 'f64', 'rune', 'char', 'string', 'void', 'voidptr', 'charptr', 'byteptr', 'array'] } diff --git a/vlib/v/flat/flat.v b/vlib/v/flat/flat.v index d9a66d44ed..f5103ad9b7 100644 --- a/vlib/v/flat/flat.v +++ b/vlib/v/flat/flat.v @@ -24,7 +24,7 @@ const static_type_method_name_marker = '@static@' pub fn empty_node_ids(len int) []NodeId { mut ids := []NodeId{len: len} if len > 0 { - unsafe { C.memset(ids.data, 0xff, usize(len) * sizeof(NodeId)) } + unsafe { C.memset(ids.data, 0xff, uint(len) * sizeof(NodeId)) } } return ids } @@ -294,16 +294,16 @@ fn node_payload_with_types(generic_params []string, generic_constraints TypeText node_payload_unlock() panic('v3: too many node payloads (${idx})') } - mut chunk := payload_ptr_get(voidptr(table), usize(chunk_idx)) + mut chunk := payload_ptr_get(voidptr(table), uint(chunk_idx)) if isnil(chunk) { chunk = node_payload_new_chunk() - payload_ptr_set(voidptr(table), usize(chunk_idx), chunk) + payload_ptr_set(voidptr(table), uint(chunk_idx), chunk) if isnil(chunk) { node_payload_unlock() panic('v3: could not allocate a node payload chunk') } } - payload_ptr_set(chunk, usize(idx & node_payload_chunk_mask), voidptr(payload)) + payload_ptr_set(chunk, uint(idx & node_payload_chunk_mask), voidptr(payload)) node_payload_count_publish(table, u32(idx + 1)) node_payload_unlock() return u32(idx + 1) @@ -323,8 +323,8 @@ pub fn node_payload_at(id u32) &NodePayload { if isnil(table) || idx >= int(node_payload_count_load(table)) { return &NodePayload(unsafe { nil }) } - chunk := payload_ptr_get(voidptr(table), usize(idx >> node_payload_chunk_bits)) - return unsafe { &NodePayload(payload_ptr_get(chunk, usize(idx & node_payload_chunk_mask))) } + chunk := payload_ptr_get(voidptr(table), uint(idx >> node_payload_chunk_bits)) + return unsafe { &NodePayload(payload_ptr_get(chunk, uint(idx & node_payload_chunk_mask))) } } // node_flag_skip_ownership_drops marks a block/if/for/fn node whose scope must @@ -970,7 +970,7 @@ pub mut: // passed on by reference is allocated as well, after it is zeroed whole and // copied: this allocates it alone and clears no more than a pass reads. pub fn new_text_probe_cache() &TextProbeCache { - mut cache := unsafe { &TextProbeCache(malloc_noscan(sizeof(TextProbeCache))) } + mut cache := unsafe { &TextProbeCache(malloc_noscan(int(sizeof(TextProbeCache)))) } cache.reset() return cache } @@ -1027,8 +1027,8 @@ fn (mut a FlatAst) intern_node_texts_range_wide(start int, end int) { // A slot's text and identity are read only once its nonzero pointer key // matches, so the keys alone start out cleared. mut probe := WideTextProbe{ - ptrs: unsafe { &voidptr(vcalloc_noscan(isize(wide_text_probe_slots) * isize(sizeof(voidptr)))) } - vals: unsafe { &string(malloc_noscan(isize(wide_text_probe_slots) * isize(sizeof(string)))) } + ptrs: unsafe { &voidptr(vcalloc_noscan(int(wide_text_probe_slots) * int(sizeof(voidptr)))) } + vals: unsafe { &string(malloc_noscan(int(wide_text_probe_slots) * int(sizeof(string)))) } } defer { // These buffers borrow the AST's canonical text; release only the scratch storage. @@ -1363,7 +1363,7 @@ pub fn (mut a FlatAst) add_node(node Node) NodeId { mut stored := node if a.nodes.len < a.nodes.cap { unsafe { - mut slot := &Node(&u8(a.nodes.data) + usize(a.nodes.len) * sizeof(Node)) + mut slot := &Node(&u8(a.nodes.data) + uint(a.nodes.len) * sizeof(Node)) *slot = stored a.nodes.len++ } @@ -1390,7 +1390,7 @@ pub fn (mut a FlatAst) begin_children() int { pub fn (mut a FlatAst) add_child(id NodeId) { if a.children.len < a.children.cap { unsafe { - mut slot := &NodeId(&u8(a.children.data) + usize(a.children.len) * sizeof(NodeId)) + mut slot := &NodeId(&u8(a.children.data) + uint(a.children.len) * sizeof(NodeId)) *slot = id a.children.len++ } diff --git a/vlib/v/flat/flat_memory.c.v b/vlib/v/flat/flat_memory.c.v index d2f7a99322..c625f1c2d3 100644 --- a/vlib/v/flat/flat_memory.c.v +++ b/vlib/v/flat/flat_memory.c.v @@ -11,12 +11,12 @@ pub fn (a &FlatAst) discard_unused_capacity() { // array headers, and neighboring arena allocations remain untouched. if a.nodes.cap > a.nodes.len { unsafe { - prealloc_discard_pages(&u8(a.nodes.data) + usize(a.nodes.len) * sizeof(Node), usize(a.nodes.cap - a.nodes.len) * sizeof(Node)) + prealloc_discard_pages(&u8(a.nodes.data) + uint(a.nodes.len) * sizeof(Node), uint(a.nodes.cap - a.nodes.len) * sizeof(Node)) } } if a.children.cap > a.children.len { unsafe { - prealloc_discard_pages(&u8(a.children.data) + usize(a.children.len) * sizeof(NodeId), usize(a.children.cap - a.children.len) * sizeof(NodeId)) + prealloc_discard_pages(&u8(a.children.data) + uint(a.children.len) * sizeof(NodeId), uint(a.children.cap - a.children.len) * sizeof(NodeId)) } } } @@ -31,10 +31,10 @@ pub fn (a &FlatAst) discard_unused_capacity() { pub fn (a &FlatAst) discard_replaced_storage(old_nodes voidptr, old_nodes_cap int, old_children voidptr, old_children_cap int) { $if prealloc { if old_nodes != nil && old_nodes != a.nodes.data && old_nodes_cap > 0 { - unsafe { prealloc_discard_pages(old_nodes, usize(old_nodes_cap) * sizeof(Node)) } + unsafe { prealloc_discard_pages(old_nodes, uint(old_nodes_cap) * sizeof(Node)) } } if old_children != nil && old_children != a.children.data && old_children_cap > 0 { - unsafe { prealloc_discard_pages(old_children, usize(old_children_cap) * sizeof(NodeId)) } + unsafe { prealloc_discard_pages(old_children, uint(old_children_cap) * sizeof(NodeId)) } } } } diff --git a/vlib/v/flat/flat_payload.c.v b/vlib/v/flat/flat_payload.c.v index d7146b547e..54521c82dc 100644 --- a/vlib/v/flat/flat_payload.c.v +++ b/vlib/v/flat/flat_payload.c.v @@ -22,13 +22,13 @@ fn C.atomic_load_u64(voidptr) u64 fn C.cpu_relax() @[inline] -fn payload_ptr_get(base voidptr, index usize) voidptr { +fn payload_ptr_get(base voidptr, index uint) voidptr { // The payload chunks are arrays of pointers with validated indices. return unsafe { (&voidptr(base))[index] } } @[inline] -fn payload_ptr_set(base voidptr, index usize, value voidptr) { +fn payload_ptr_set(base voidptr, index uint, value voidptr) { // The caller owns the chunk and has reserved this index. unsafe { (&voidptr(base))[index] = value } } @@ -93,13 +93,13 @@ fn node_payload_unlock() { // no arena can release is right; otherwise the storage comes from // malloc_uncollectable, which a tracing GC scans but never reclaims, so the // payloads (and their generic_params arrays) stay reachable through it. -fn node_payload_alloc_zeroed(n usize) voidptr { +fn node_payload_alloc_zeroed(n uint) voidptr { $if prealloc { return unsafe { C.calloc(1, n) } } $else { - ptr := unsafe { malloc_uncollectable(isize(n)) } + ptr := unsafe { malloc_uncollectable(int(n)) } if !isnil(ptr) { - unsafe { vmemset(ptr, 0, isize(n)) } + unsafe { vmemset(ptr, 0, int(n)) } } return ptr } diff --git a/vlib/v/flat/source_types.c.v b/vlib/v/flat/source_types.c.v index 2d6cbc8a3d..e27fb99ab7 100644 --- a/vlib/v/flat/source_types.c.v +++ b/vlib/v/flat/source_types.c.v @@ -21,6 +21,7 @@ pub const source_type_char = source_type_id('char') pub const source_type_rune = source_type_id('rune') pub const source_type_isize = source_type_id('isize') pub const source_type_usize = source_type_id('usize') +pub const source_type_uint = source_type_id('uint') pub const source_type_voidptr = source_type_id('voidptr') pub const source_type_byteptr = source_type_id('byteptr') pub const source_type_charptr = source_type_id('charptr') @@ -112,7 +113,7 @@ fn source_type_spelling_shape(text string) SourceTypeShape { if text.contains('typeof') { shape.set(.typeof_name) } if text.len >= 8 && text.contains('typeof(') { shape.set(.typeof_expr) } if text in ['bool', 'string', 'void', 'int', 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', - 'u64', 'f32', 'f64', 'rune', 'isize', 'usize', 'voidptr', 'byteptr', 'charptr'] { + 'u64', 'f32', 'f64', 'rune', 'uint', 'isize', 'usize', 'voidptr', 'byteptr', 'charptr'] { shape.set(.builtin_alias) } if text == 'struct' || text.ends_with('.struct') { shape.set(.anonymous_struct) } @@ -297,7 +298,7 @@ fn source_type_index_publish(table &SourceTypeTable, index &SourceTypeIndex) { @[inline] fn source_type_entry(table &SourceTypeTable, id u32) &SourceTypeEntry { idx := id - 1 - chunk := payload_ptr_get(voidptr(table), usize(idx >> source_type_chunk_bits)) + chunk := payload_ptr_get(voidptr(table), uint(idx >> source_type_chunk_bits)) // Published IDs address immutable entries in nonmoving chunks. return unsafe { &SourceTypeEntry(chunk) + (idx & (source_type_chunk_size - 1)) } } @@ -458,15 +459,15 @@ fn source_type_id_uncached(text string) u32 { if chunk_idx >= source_type_chunk_count { panic('too many source type spellings') } - mut chunk := payload_ptr_get(voidptr(table), usize(chunk_idx)) + mut chunk := payload_ptr_get(voidptr(table), uint(chunk_idx)) if isnil(chunk) { chunk = node_payload_alloc_zeroed(source_type_chunk_size * sizeof(SourceTypeEntry)) if isnil(chunk) { panic('could not allocate a source type chunk') } - payload_ptr_set(voidptr(table), usize(chunk_idx), chunk) + payload_ptr_set(voidptr(table), uint(chunk_idx), chunk) } - bytes := node_payload_alloc_zeroed(usize(text.len) + 1) + bytes := node_payload_alloc_zeroed(uint(text.len) + 1) if isnil(bytes) { panic('could not allocate a source type spelling') } diff --git a/vlib/v/flat/type_texts.v b/vlib/v/flat/type_texts.v index 52ca85de7b..0a5f1b2791 100644 --- a/vlib/v/flat/type_texts.v +++ b/vlib/v/flat/type_texts.v @@ -17,7 +17,7 @@ pub fn (mut table TypeTextTable) intern(text string) u32 { } // Pointer reuse is safe: every hit compares the current bytes with the // immutable process-owned spelling, never with a borrowed input header. - slot := int((usize(text.str) >> 4 ^ usize(text.len)) & 127) + slot := int((uint(text.str) >> 4 ^ uint(text.len)) & 127) recent := table.recent[slot] if recent != 0 && table.recent_texts[slot] == text { return recent diff --git a/vlib/v/flat/type_texts_test.v b/vlib/v/flat/type_texts_test.v index a9d8a74587..956b7a1037 100644 --- a/vlib/v/flat/type_texts_test.v +++ b/vlib/v/flat/type_texts_test.v @@ -329,7 +329,7 @@ fn test_type_text_recent_headers_do_not_own_global_spelling_bytes() { mut texts := TypeTextTable{} input := 'type_texts.CachedHeader'.clone() id := texts.intern(input) - slot := int((usize(input.str) >> 4 ^ usize(input.len)) & 127) + slot := int((uint(input.str) >> 4 ^ uint(input.len)) & 127) canonical := source_type_name(id) assert texts.recent_texts[slot].str == canonical.str mut fork := texts.fork() @@ -356,7 +356,7 @@ fn test_type_text_recent_headers_survive_the_input_arena() { input := 'type_texts.DisposableInput'.clone() assert unsafe { prealloc_scope_owns(scope, input.str) } id := texts.intern(input) - slot := int((usize(input.str) >> 4 ^ usize(input.len)) & 127) + slot := int((uint(input.str) >> 4 ^ uint(input.len)) & 127) unsafe { prealloc_scope_leave(scope) } assert !unsafe { prealloc_scope_owns(scope, texts.recent_texts[slot].str) } mut fork := texts.fork() diff --git a/vlib/v/gen/arm64/native_allocation_test.v b/vlib/v/gen/arm64/native_allocation_test.v index a71c45fdd5..b4eb495668 100644 --- a/vlib/v/gen/arm64/native_allocation_test.v +++ b/vlib/v/gen/arm64/native_allocation_test.v @@ -20,7 +20,7 @@ fn main() { source[2] = 3 source[3] = 4 copy := &u8(v3_aligned_memdup(&source[0], 4, 64)) - if usize(copy) == 0 || usize(copy) % 64 != 0 { C.exit(1) } + if uint(copy) == 0 || uint(copy) % 64 != 0 { C.exit(1) } unsafe { if copy[0] != 1 || copy[1] != 2 || copy[2] != 3 || copy[3] != 4 { C.exit(2) } copy[1] = 9 @@ -28,10 +28,10 @@ fn main() { if source[1] != 2 { C.exit(3) } C.free(copy) small := v3_aligned_memdup(&source[0], 4, 1) - if usize(small) == 0 || usize(small) % 8 != 0 { C.exit(4) } + if uint(small) == 0 || uint(small) % 8 != 0 { C.exit(4) } C.free(small) invalid := v3_aligned_memdup(&source[0], 4, 24) - if usize(invalid) != 0 { C.exit(5) } + if uint(invalid) != 0 { C.exit(5) } } ', false) } @@ -71,7 +71,7 @@ fn main() { slots[0] = voidptr(11) slots[1] = voidptr(22) } - if usize(values[0]) != 11 || usize(values[1]) != 22 { C.exit(1) } + if uint(values[0]) != 11 || uint(values[1]) != 22 { C.exit(1) } } ', false) } diff --git a/vlib/v/gen/arm64/native_array_test.v b/vlib/v/gen/arm64/native_array_test.v index 8a08dac00c..339076126b 100644 --- a/vlib/v/gen/arm64/native_array_test.v +++ b/vlib/v/gen/arm64/native_array_test.v @@ -128,9 +128,9 @@ fn test_native_array_growth_handles_managed_storage_and_preserves_views() { $if macos && arm64 { run_native_array_fixture('managed', 'module main fn C.exit(int) -fn C.malloc(usize) voidptr +fn C.malloc(uint) voidptr fn C.free(voidptr) -fn C.memcpy(voidptr, voidptr, usize) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr struct NativeArray { data voidptr offset i32 @@ -169,7 +169,7 @@ fn main() { if old[0] != 11 { C.exit(5) } mut grown := NativeArray{} C.memcpy(&grown, &values, sizeof(NativeArray)) - if grown.offset != 0 || grown.flags != 16 || usize(grown.data) % 16 != 0 { C.exit(6) } + if grown.offset != 0 || grown.flags != 16 || uint(grown.data) % 16 != 0 { C.exit(6) } if grown.data == header.data { C.exit(7) } new_allocation := unsafe { *(&voidptr(&u8(grown.data) - 16)) } C.free(new_allocation) @@ -209,8 +209,8 @@ fn test_native_string_builder_growth_handles_managed_array_backing() { $if macos && arm64 { run_native_array_fixture('builder', 'module main fn C.exit(int) -fn C.malloc(usize) voidptr -fn C.memcpy(voidptr, voidptr, usize) voidptr +fn C.malloc(uint) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr type Builder = []u8 fn (mut b Builder) write_string(value string) {} fn (mut b Builder) write_byte(value u8) {} diff --git a/vlib/v/gen/arm64/native_closure_test.v b/vlib/v/gen/arm64/native_closure_test.v index 626e8fe909..051e233036 100644 --- a/vlib/v/gen/arm64/native_closure_test.v +++ b/vlib/v/gen/arm64/native_closure_test.v @@ -19,11 +19,11 @@ fn test_native_spawn_noreturn_worker_preserves_parent_execution() { os.write_file(path, 'module main fn C.exit(int) fn C.alarm(u32) u32 -fn C.malloc(usize) voidptr -fn C.memcpy(voidptr, voidptr, usize) voidptr -fn memdup(source voidptr, size isize) voidptr { - destination := C.malloc(usize(size)) - return C.memcpy(destination, source, usize(size)) +fn C.malloc(uint) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr +fn memdup(source voidptr, size int) voidptr { + destination := C.malloc(uint(size)) + return C.memcpy(destination, source, uint(size)) } @[noreturn] fn C.pthread_exit(voidptr) diff --git a/vlib/v/gen/arm64/native_constant_test.v b/vlib/v/gen/arm64/native_constant_test.v index 57417026ca..29251e8154 100644 --- a/vlib/v/gen/arm64/native_constant_test.v +++ b/vlib/v/gen/arm64/native_constant_test.v @@ -123,7 +123,7 @@ fn test_native_compiler_string_array_constants_reserve_full_headers_and_preserve import ssa import arm64 fn C.exit(int) -fn C.strlen(&u8) usize +fn C.strlen(&u8) uint __global canary = u64(305419896) const neighboring = ["first", "second", "third"] fn main() { diff --git a/vlib/v/gen/arm64/native_enum_flags_test.v b/vlib/v/gen/arm64/native_enum_flags_test.v index 59cb734eaf..82c3e488d6 100644 --- a/vlib/v/gen/arm64/native_enum_flags_test.v +++ b/vlib/v/gen/arm64/native_enum_flags_test.v @@ -31,7 +31,7 @@ fn (mut cache VarTypeIndexCache) clear() { C.exit(90) } r'module main import strings fn C.exit(int) -fn C.memcpy(voidptr, voidptr, usize) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr @[flag] enum Features { read write execute extra } type FeatureAlias = Features diff --git a/vlib/v/gen/arm64/native_fixed_array_test.v b/vlib/v/gen/arm64/native_fixed_array_test.v index a6b50a483a..dfca5ea8bd 100644 --- a/vlib/v/gen/arm64/native_fixed_array_test.v +++ b/vlib/v/gen/arm64/native_fixed_array_test.v @@ -16,10 +16,10 @@ fn test_native_returned_registration_fixed_array_fields_preserve_string_elements source := definitions.all_before('// new_type_reference').replace('module types', 'module main') + registration.replace('types.Type', 'Type') + r' fn C.exit(int) -fn C.malloc(usize) voidptr -fn C.memcpy(voidptr, voidptr, usize) voidptr -fn memdup(value voidptr, size isize) voidptr { - return C.memcpy(C.malloc(usize(size)), value, usize(size)) +fn C.malloc(uint) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr +fn memdup(value voidptr, size int) voidptr { + return C.memcpy(C.malloc(uint(size)), value, uint(size)) } fn make_registration() FnSignatureRegistration { mut aliases := [6]string{} diff --git a/vlib/v/gen/arm64/native_float_literal_test.v b/vlib/v/gen/arm64/native_float_literal_test.v index 7612ea41d4..21829430b3 100644 --- a/vlib/v/gen/arm64/native_float_literal_test.v +++ b/vlib/v/gen/arm64/native_float_literal_test.v @@ -33,10 +33,10 @@ fn test_native_real_float_unions_share_storage_before_and_after_transform() { source := r'module main import strconv fn C.exit(int) -fn C.malloc(usize) voidptr -fn C.memcpy(voidptr, voidptr, usize) voidptr -fn memdup(value voidptr, size isize) voidptr { - return C.memcpy(C.malloc(usize(size)), value, usize(size)) +fn C.malloc(uint) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr +fn memdup(value voidptr, size int) voidptr { + return C.memcpy(C.malloc(uint(size)), value, uint(size)) } fn bits64(value strconv.Float64u) u64 { return unsafe { value.u } } fn main() { diff --git a/vlib/v/gen/arm64/native_if_string_test.v b/vlib/v/gen/arm64/native_if_string_test.v index cca47d4220..df04cb373e 100644 --- a/vlib/v/gen/arm64/native_if_string_test.v +++ b/vlib/v/gen/arm64/native_if_string_test.v @@ -48,11 +48,11 @@ fn test_native_pointer_map_or_keeps_type_across_terminating_branches() { $if macos && arm64 { source := r'module main fn C.exit(int) -fn C.malloc(usize) voidptr -fn C.memcpy(voidptr, voidptr, usize) voidptr -fn memdup(source voidptr, size isize) voidptr { - result := C.malloc(usize(size)) - return C.memcpy(result, source, usize(size)) +fn C.malloc(uint) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr +fn memdup(source voidptr, size int) voidptr { + result := C.malloc(uint(size)) + return C.memcpy(result, source, uint(size)) } struct SourceFile { name string } fn find_continue(sources map[string]&SourceFile, names []string) string { diff --git a/vlib/v/gen/arm64/native_map_array_test.v b/vlib/v/gen/arm64/native_map_array_test.v index 2ad1b1fcce..dc72da392c 100644 --- a/vlib/v/gen/arm64/native_map_array_test.v +++ b/vlib/v/gen/arm64/native_map_array_test.v @@ -11,11 +11,11 @@ fn test_native_map_array_fields_keep_map_indexing_through_pointer_receivers() { $if macos && arm64 { source := r'module main fn C.exit(int) -fn C.malloc(usize) voidptr -fn C.memcpy(voidptr, voidptr, usize) voidptr -fn memdup(source voidptr, size isize) voidptr { - result := C.malloc(usize(size)) - return C.memcpy(result, source, usize(size)) +fn C.malloc(uint) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr +fn memdup(source voidptr, size int) voidptr { + result := C.malloc(uint(size)) + return C.memcpy(result, source, uint(size)) } fn array_new(element_size int, len int, cap int) []int { return []int{} } fn __new_array_noscan(len int, cap int, element_size int) []int { diff --git a/vlib/v/gen/arm64/native_map_index_test.v b/vlib/v/gen/arm64/native_map_index_test.v index 0e5a336d62..001e61af1d 100644 --- a/vlib/v/gen/arm64/native_map_index_test.v +++ b/vlib/v/gen/arm64/native_map_index_test.v @@ -11,7 +11,7 @@ fn test_native_map_index_handles_many_keys_updates_and_numeric_bits() { $if macos && arm64 { run_native_map_index_fixture('many_keys', r'module main fn C.exit(int) -fn C.memcpy(voidptr, voidptr, usize) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr fn println(s string) {} fn int_str(n i64) string { return "" } fn map__clone(m &map[int]int) map[int]int { return map[int]int{} } @@ -47,7 +47,7 @@ fn main() { C.exit(4) } mut state_pointer := voidptr(0) - C.memcpy(&state_pointer, &numbers, usize(8)) + C.memcpy(&state_pointer, &numbers, uint(8)) state := &NativeMapState(state_pointer) if state.hash_cap < 40000 || state.indexed_len != 20000 { C.exit(5) } slots := &i64(state.hash_slots) diff --git a/vlib/v/gen/arm64/native_optional_pointer_test.v b/vlib/v/gen/arm64/native_optional_pointer_test.v index b91a6e7bac..f12d8acc6e 100644 --- a/vlib/v/gen/arm64/native_optional_pointer_test.v +++ b/vlib/v/gen/arm64/native_optional_pointer_test.v @@ -12,11 +12,11 @@ fn test_native_optional_pointer_literals_and_thread_results_preserve_the_pointer source := r'module main import prepared fn C.exit(int) -fn C.malloc(usize) voidptr -fn C.memcpy(voidptr, voidptr, usize) voidptr -fn memdup(source voidptr, size isize) voidptr { - destination := C.malloc(usize(size)) - C.memcpy(destination, source, usize(size)) +fn C.malloc(uint) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr +fn memdup(source voidptr, size int) voidptr { + destination := C.malloc(uint(size)) + C.memcpy(destination, source, uint(size)) return destination } fn select_prepared(shared bool) &prepared.Prepared { diff --git a/vlib/v/gen/arm64/native_payload_table_test.v b/vlib/v/gen/arm64/native_payload_table_test.v index 77d87f6da4..9bf6dd5dea 100644 --- a/vlib/v/gen/arm64/native_payload_table_test.v +++ b/vlib/v/gen/arm64/native_payload_table_test.v @@ -18,9 +18,9 @@ fn test_native_payload_table_preserves_constant_array_layout_across_chunks() { table := flat_source.all_after('struct NodePayloadTable {').all_before('__global g_node_payload_table') new_table := allocator_source.all_after('fn node_payload_new_table()').all_before('// node_payload_new_chunk') new_chunk := allocator_source.all_after('fn node_payload_new_chunk()') - payload_source := 'module flat\nfn C.calloc(usize, usize) voidptr\nfn C.free(voidptr)\nfn C.v_flat_payload_ptr_get(voidptr, usize) voidptr\nfn C.v_flat_payload_ptr_set(voidptr, usize, voidptr)\nconst node_payload_chunk_bits =' + + payload_source := 'module flat\nfn C.calloc(uint, uint) voidptr\nfn C.free(voidptr)\nfn C.v_flat_payload_ptr_get(voidptr, uint) voidptr\nfn C.v_flat_payload_ptr_set(voidptr, uint, voidptr)\nconst node_payload_chunk_bits =' + constants + 'struct NodePayloadTable {' + table + - 'fn node_payload_alloc_zeroed(n usize) voidptr { return unsafe { C.calloc(1, n) } }\nfn node_payload_new_table()' + + 'fn node_payload_alloc_zeroed(n uint) voidptr { return unsafe { C.calloc(1, n) } }\nfn node_payload_new_table()' + new_table + 'fn node_payload_new_chunk()' + new_chunk + r' pub fn verify() int { if sizeof(NodePayloadTable) != 32776 { return 1 } @@ -30,12 +30,12 @@ pub fn verify() int { for index in 0 .. 4097 { payloads[index] = index + 1 chunk_index := int(table.count) >> node_payload_chunk_bits - mut chunk := C.v_flat_payload_ptr_get(voidptr(table), usize(chunk_index)) + mut chunk := C.v_flat_payload_ptr_get(voidptr(table), uint(chunk_index)) if chunk == voidptr(0) { chunk = node_payload_new_chunk() - C.v_flat_payload_ptr_set(voidptr(table), usize(chunk_index), chunk) + C.v_flat_payload_ptr_set(voidptr(table), uint(chunk_index), chunk) } - C.v_flat_payload_ptr_set(chunk, usize(int(table.count) & node_payload_chunk_mask), + C.v_flat_payload_ptr_set(chunk, uint(int(table.count) & node_payload_chunk_mask), unsafe { voidptr(&payloads[index]) }) table.count += 1 } diff --git a/vlib/v/gen/arm64/native_platform_test.v b/vlib/v/gen/arm64/native_platform_test.v index 99a190b45d..632ff5e30a 100644 --- a/vlib/v/gen/arm64/native_platform_test.v +++ b/vlib/v/gen/arm64/native_platform_test.v @@ -24,8 +24,8 @@ fn test_native_platform_file_flags_and_thread_local_errno() { __global C.errno int fn C.open(&char, int, ...int) int fn C.close(int) int -fn C.write(int, voidptr, usize) isize -fn C.read(int, voidptr, usize) isize +fn C.write(int, voidptr, uint) C.ptrdiff_t +fn C.read(int, voidptr, uint) C.ptrdiff_t fn C.unlink(&char) int fn C.v3_bench_peak_rss_kb() i64 fn C.exit(int) @@ -34,7 +34,7 @@ fn main() { text := "native file" fd := C.open(path.str, C.O_WRONLY | C.O_CREAT | C.O_TRUNC, 0o600) if fd < 0 { C.exit(1) } - if C.write(fd, text.str, usize(text.len)) != text.len { C.exit(2) } + if C.write(fd, text.str, uint(text.len)) != text.len { C.exit(2) } C.close(fd) input := C.open(path.str, C.O_RDONLY) mut buffer := [32]u8{} diff --git a/vlib/v/gen/arm64/native_pointer_array_test.v b/vlib/v/gen/arm64/native_pointer_array_test.v index 6e94f36812..fc534bff11 100644 --- a/vlib/v/gen/arm64/native_pointer_array_test.v +++ b/vlib/v/gen/arm64/native_pointer_array_test.v @@ -64,11 +64,11 @@ fn test_native_pointer_elements_and_nil_terminators_keep_their_storage_addresses $if macos && arm64 { source := 'module main fn C.exit(int) -fn C.malloc(usize) voidptr -fn C.memcpy(voidptr, voidptr, usize) voidptr -fn memdup(source voidptr, size isize) voidptr { - destination := C.malloc(usize(size)) - return C.memcpy(destination, source, usize(size)) +fn C.malloc(uint) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr +fn memdup(source voidptr, size int) voidptr { + destination := C.malloc(uint(size)) + return C.memcpy(destination, source, uint(size)) } fn main() { mut first := u8(65) diff --git a/vlib/v/gen/arm64/native_poll_sync_test.v b/vlib/v/gen/arm64/native_poll_sync_test.v index bb072496e1..4b7993a75c 100644 --- a/vlib/v/gen/arm64/native_poll_sync_test.v +++ b/vlib/v/gen/arm64/native_poll_sync_test.v @@ -14,7 +14,7 @@ fn C.exit(int) fn C.alarm(u32) u32 fn C.pipe(&i32) i32 fn C.close(i32) i32 -fn C.read(i32, voidptr, usize) isize +fn C.read(i32, voidptr, uint) C.ptrdiff_t struct C.pollfd { fd int events i16 revents i16 } fn C.poll(&C.pollfd, u64, int) int fn main() { @@ -63,11 +63,11 @@ import sync fn C.exit(int) fn C.alarm(u32) u32 fn C.usleep(u32) int -fn C.malloc(usize) voidptr -fn C.memcpy(voidptr, voidptr, usize) voidptr -fn memdup(source voidptr, size isize) voidptr { - result := C.malloc(usize(size)) - return C.memcpy(result, source, usize(size)) +fn C.malloc(uint) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr +fn memdup(source voidptr, size int) voidptr { + result := C.malloc(uint(size)) + return C.memcpy(result, source, uint(size)) } fn monitor(sem &sync.Semaphore) int { mut wake := unsafe { &sync.Semaphore(voidptr(sem)) } diff --git a/vlib/v/gen/arm64/native_process_test.v b/vlib/v/gen/arm64/native_process_test.v index 37668ff197..ee236775bb 100644 --- a/vlib/v/gen/arm64/native_process_test.v +++ b/vlib/v/gen/arm64/native_process_test.v @@ -82,21 +82,21 @@ fn C.exit(int) fn C.alarm(u32) u32 fn C.v_os_execute_capture_start(voidptr, &int, &int) int fn C.v_os_exec_capture_start(voidptr, &int, &int) int -fn C.read(i32, voidptr, usize) isize +fn C.read(i32, voidptr, uint) C.ptrdiff_t fn C.close(i32) i32 fn C.waitpid(i32, &i32, i32) i32 -fn C.memcmp(voidptr, voidptr, usize) i32 +fn C.memcmp(voidptr, voidptr, uint) i32 fn check_capture(pid int, fd int, expected string, code int) { mut buffer := [128]u8{} mut total := 0 for { - n := C.read(i32(fd), &buffer[total], usize(128 - total)) + n := C.read(i32(fd), &buffer[total], uint(128 - total)) if n < 0 { C.exit(1) } if n == 0 { break } total += int(n) } C.close(i32(fd)) - if total != expected.len || C.memcmp(&buffer[0], expected.str, usize(total)) != 0 { + if total != expected.len || C.memcmp(&buffer[0], expected.str, uint(total)) != 0 { C.exit(2) } mut status := i32(0) diff --git a/vlib/v/gen/arm64/native_runtime_test.v b/vlib/v/gen/arm64/native_runtime_test.v index 298aad78a8..4803971466 100644 --- a/vlib/v/gen/arm64/native_runtime_test.v +++ b/vlib/v/gen/arm64/native_runtime_test.v @@ -146,9 +146,9 @@ fn test_native_filelock_headers_preserve_modes_ranges_and_unlocking() { run_native_runtime_fixture('filelock', 'module main fn C.exit(int) fn C.alarm(u32) u32 -fn C.malloc(usize) voidptr +fn C.malloc(uint) voidptr fn C.free(voidptr) -fn C.memcpy(voidptr, voidptr, usize) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr fn C.mkstemp(voidptr) i32 fn C.unlink(voidptr) i32 fn C.close(i32) i32 @@ -164,7 +164,7 @@ fn main() { C.alarm(5) name := "/tmp/v-native-filelock-XXXXXX" path := C.malloc(128) - C.memcpy(path, name.str, usize(name.len + 1)) + C.memcpy(path, name.str, uint(name.len + 1)) fd := C.mkstemp(path) if fd < 0 { C.exit(1) } if C.v_filelock_lock(fd, 1, 1, 2, 3) != 0 { C.exit(2) } @@ -200,10 +200,10 @@ fn test_native_flat_payload_header_helpers_preserve_pointer_identity() { $if macos && arm64 { run_native_runtime_fixture('payload_pointer', 'module main fn C.exit(int) -fn C.malloc(usize) voidptr +fn C.malloc(uint) voidptr fn C.free(voidptr) -fn C.v_flat_payload_ptr_get(voidptr, usize) voidptr -fn C.v_flat_payload_ptr_set(voidptr, usize, voidptr) +fn C.v_flat_payload_ptr_get(voidptr, uint) voidptr +fn C.v_flat_payload_ptr_set(voidptr, uint, voidptr) fn main() { base := C.malloc(24) C.v_flat_payload_ptr_set(base, 0, unsafe { nil }) diff --git a/vlib/v/gen/arm64/native_signal_test.v b/vlib/v/gen/arm64/native_signal_test.v index 058f74ef9a..7b9209df2e 100644 --- a/vlib/v/gen/arm64/native_signal_test.v +++ b/vlib/v/gen/arm64/native_signal_test.v @@ -11,7 +11,7 @@ fn test_native_signal_handler_calls_fallback_on_alternate_stack() { run_native_signal_fixture('alternate', 'module main struct C.stack_t { ss_sp voidptr - ss_size usize + ss_size uint ss_flags int } fn C.exit(int) diff --git a/vlib/v/gen/arm64/native_struct_defaults_test.v b/vlib/v/gen/arm64/native_struct_defaults_test.v index db5262ef6d..118f40a2a2 100644 --- a/vlib/v/gen/arm64/native_struct_defaults_test.v +++ b/vlib/v/gen/arm64/native_struct_defaults_test.v @@ -54,11 +54,11 @@ pub: os.rmdir(directory) or {} } source := 'module main\nimport defaults\nfn C.exit(int)\n' + r' -fn C.malloc(usize) voidptr -fn C.memcpy(voidptr, voidptr, usize) voidptr -fn memdup(source voidptr, size isize) voidptr { - destination := C.malloc(usize(size)) - C.memcpy(destination, source, usize(size)) +fn C.malloc(uint) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr +fn memdup(source voidptr, size int) voidptr { + destination := C.malloc(uint(size)) + C.memcpy(destination, source, uint(size)) return destination } fn main() { diff --git a/vlib/v/gen/arm64/native_sum_guard_test.v b/vlib/v/gen/arm64/native_sum_guard_test.v index a61359dd3a..7c14eaf70a 100644 --- a/vlib/v/gen/arm64/native_sum_guard_test.v +++ b/vlib/v/gen/arm64/native_sum_guard_test.v @@ -18,11 +18,11 @@ fn test_native_negative_sum_guards_preserve_enum_payload_fields() { const builtin_void_type = Type(Void{}) const empty_type = &builtin_void_type fn C.exit(int) -fn C.malloc(usize) voidptr -fn C.memcpy(voidptr, voidptr, usize) voidptr -fn memdup(value voidptr, size isize) voidptr { - copy := C.malloc(usize(size)) - return C.memcpy(copy, value, usize(size)) +fn C.malloc(uint) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr +fn memdup(value voidptr, size int) voidptr { + copy := C.malloc(uint(size)) + return C.memcpy(copy, value, uint(size)) } fn __as_cast(obj voidptr, obj_type int, expected_type int, obj_name string, expected_name string) voidptr { if obj_type != expected_type { C.exit(80) } diff --git a/vlib/v/gen/arm64/native_threads_test.v b/vlib/v/gen/arm64/native_threads_test.v index b8c1da67f6..76d63d1927 100644 --- a/vlib/v/gen/arm64/native_threads_test.v +++ b/vlib/v/gen/arm64/native_threads_test.v @@ -13,8 +13,8 @@ fn test_native_spawn_overlaps_parent_and_returns_aggregate() { fn C.exit(int) fn C.alarm(u32) u32 fn C.pipe(voidptr) i32 -fn C.read(i32, voidptr, usize) isize -fn C.write(i32, voidptr, usize) isize +fn C.read(i32, voidptr, uint) C.ptrdiff_t +fn C.write(i32, voidptr, uint) C.ptrdiff_t fn C.close(i32) i32 fn C.pthread_self() u64 fn C.v3_pthread_is_current(u64) int @@ -51,8 +51,8 @@ fn test_native_detached_spawn_performs_side_effect() { fn C.exit(int) fn C.alarm(u32) u32 fn C.pipe(voidptr) i32 -fn C.read(i32, voidptr, usize) isize -fn C.write(i32, voidptr, usize) isize +fn C.read(i32, voidptr, uint) C.ptrdiff_t +fn C.write(i32, voidptr, uint) C.ptrdiff_t fn C.close(i32) i32 fn C.pthread_self() u64 fn send(fd i32, parent u64) { diff --git a/vlib/v/gen/arm64/native_type_identity_test.v b/vlib/v/gen/arm64/native_type_identity_test.v index 90d11d2f71..a4c8951789 100644 --- a/vlib/v/gen/arm64/native_type_identity_test.v +++ b/vlib/v/gen/arm64/native_type_identity_test.v @@ -22,12 +22,12 @@ fn test_native_compiler_types_preserve_semantic_payload_identity() { const builtin_void_type = Type(Void{}) const empty_type = &builtin_void_type fn C.exit(int) -fn C.malloc(usize) voidptr -fn C.calloc(usize, usize) voidptr -fn C.memcpy(voidptr, voidptr, usize) voidptr -fn memdup(value voidptr, size isize) voidptr { - result := C.malloc(usize(size)) - return C.memcpy(result, value, usize(size)) +fn C.malloc(uint) voidptr +fn C.calloc(uint, uint) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr +fn memdup(value voidptr, size int) voidptr { + result := C.malloc(uint(size)) + return C.memcpy(result, value, uint(size)) } // SSA sum storage starts with the i32 tag declared in ssa/builder.v. struct NativeSumHeader { typ i32 } @@ -57,7 +57,7 @@ fn main() { second := Type(FnType{params: [FnParam{typ: new_type_reference(boolean)}], return_type: new_type_reference(boolean)}) if first !is FnType || second !is FnType || semantic_types_equal(&first, &second) || semantic_type_hash(&first) == semantic_type_hash(&second) { C.exit(5) } - zero := unsafe { &Type(C.calloc(1, usize(sizeof(Type)))) } + zero := unsafe { &Type(C.calloc(1, uint(sizeof(Type)))) } if native_sum_tag(zero) != 0 { C.exit(6) } valid_void := Type(Void{}) if native_sum_tag(&valid_void) != 1 || valid_void !is Void diff --git a/vlib/v/gen/arm64/native_uname_test.v b/vlib/v/gen/arm64/native_uname_test.v index ea16a45b70..e8a38816a4 100644 --- a/vlib/v/gen/arm64/native_uname_test.v +++ b/vlib/v/gen/arm64/native_uname_test.v @@ -25,7 +25,7 @@ pub struct C.utsname { machine &char } fn C.uname(&C.utsname) int -fn C.strlen(&char) usize +fn C.strlen(&char) uint fn C.strcmp(&char, &char) int fn C.exit(int) struct UnameView { value &C.utsname } diff --git a/vlib/v/gen/c/array_pointer_free_test.v b/vlib/v/gen/c/array_pointer_free_test.v index ce1c682ef7..191a1c3a2a 100644 --- a/vlib/v/gen/c/array_pointer_free_test.v +++ b/vlib/v/gen/c/array_pointer_free_test.v @@ -9,7 +9,7 @@ import v.types fn test_c_free_preserves_the_allocator_for_aligned_array_pointer_casts() { path := os.join_path(os.vtmp_dir(), 'aligned_array_free_${os.getpid()}.c.v') - os.write_file(path, 'fn C.malloc(size usize) voidptr + os.write_file(path, 'fn C.malloc(size uint) voidptr fn C.free(value voidptr) @[aligned: 8] struct AlignedCell { value int } @@ -19,7 +19,7 @@ fn release_v(value &Cells) { unsafe { free(value) } } fn main() { ordinary := unsafe { &Cells(C.malloc(sizeof(Cells))) } release_c(ordinary) - owned := unsafe { &Cells(malloc(sizeof(Cells))) } + owned := unsafe { &Cells(malloc(int(sizeof(Cells)))) } release_v(owned) aligned := &Cells{} release_v(aligned) @@ -44,6 +44,6 @@ fn main() { assert !c_release.contains('v3_aligned_free'), c_release v_release := generated.all_after('void release_v(Array_fixed_main__AlignedCell_2* value) {').all_before('\n}').trim_space() assert v_release.contains('v3_aligned_free(value);'), v_release - assert generated.contains('v_malloc(sizeof(main__AlignedCell[2]))'), generated + assert generated.contains('v_malloc((i64)(sizeof(main__AlignedCell[2])))'), generated assert generated.contains('v3_aligned_memdup('), generated } diff --git a/vlib/v/gen/c/cleanc.v b/vlib/v/gen/c/cleanc.v index f314dd08bd..edcf36fb72 100644 --- a/vlib/v/gen/c/cleanc.v +++ b/vlib/v/gen/c/cleanc.v @@ -302,7 +302,7 @@ fn cgen_worker_scope_begin(enabled bool) voidptr { // cgen_chunk_arena_keep_bytes bounds how much of a dispatcher's chunk arena // stays mapped between chunks (see prealloc_scope_reenter). -const cgen_chunk_arena_keep_bytes = isize($d('cgen_chunk_arena_keep_mb', 1)) * 1024 * 1024 +const cgen_chunk_arena_keep_bytes = int($d('cgen_chunk_arena_keep_mb', 1)) * 1024 * 1024 // cgen_worker_scope_reenter makes a chunk arena that was left current again, // rewound, for the next chunk. False means the caller needs a new arena. @@ -3445,7 +3445,7 @@ fn (mut g FlatGen) write_scoped_output_chunk(path string, append bool, scope voi return false } unsafe { - file.write_full_buffer(output.data, usize(output.len)) or { + file.write_full_buffer(output.data, uint(output.len)) or { g.output_error = err.msg() file.close() output.free() @@ -3598,7 +3598,7 @@ fn (mut g FlatGen) append_scoped_output_file(path string, source_path string) bo break } unsafe { - output.write_full_buffer(buffer.data, usize(n_read)) or { + output.write_full_buffer(buffer.data, uint(n_read)) or { g.output_error = err.msg() output.close() source.close() @@ -16490,7 +16490,7 @@ fn (mut g FlatGen) gen_nonliteral_expr(id flat.NodeId, node &flat.Node) { expected_ct := g.value_c_type(g.expected_expr_type) if byte_value := c_char_literal_byte_value(cv) { if g.expected_expr_type !is types.Pointer && expected_ct in ['u8', 'i8', 'char', - 'u16', 'i16', 'u32', 'i32', 'int', 'u64', 'i64', 'rune', 'usize', 'isize', + 'u16', 'i16', 'u32', 'i32', 'int', 'u64', 'i64', 'rune', 'uint', 'isize', types.portable_int_c_type] { if byte_value > 0x7f { g.write('((u8)*"${cv}")') @@ -17926,7 +17926,7 @@ fn (mut g FlatGen) gen_nonliteral_expr(id flat.NodeId, node &flat.Node) { index_type := cgen_unalias_type(g.usable_expr_type(index_id)) helper := match index_type.name() { 'i64', 'isize' { 'string__at_i64' } - 'u8', 'u16', 'u32', 'u64', 'uint', 'usize' { 'string__at_u64' } + 'u8', 'u16', 'u32', 'u64', 'uint' { 'string__at_u64' } else { 'string__at' } } g.write('${helper}(') @@ -22852,6 +22852,17 @@ fn (mut g FlatGen) headerless_linux_rwlockattr_setkind_np() { g.writeln('#define pthread_rwlockattr_setkind_np(attr, kind) v3_pthread_rwlockattr_setkind_np((attr), (kind))') } +fn (mut g FlatGen) builtin_allocation_size_c_type(name string, index int) string { + if !isnil(g.tc) { + if params := g.tc.fn_param_types[name] { + if index < params.len { + return g.tc.c_type(params[index]) + } + } + } + return g.int_ct +} + fn (mut g FlatGen) builtin_abi_decls() { if !g.has_builtins { return @@ -22937,14 +22948,20 @@ fn (mut g FlatGen) builtin_abi_decls() { g.writeln('string u64__str(u64 nn);') g.writeln('string f64__str(double x);') g.writeln('string rune__str(u32 c);') - g.writeln('u8* malloc_noscan(ptrdiff_t n);') - g.writeln('void* memdup(void* src, ptrdiff_t sz);') + // Old source snapshots still declare these sizes as isize. Match their + // signatures as well as the migrated int declarations, including on LP64. + malloc_size_ct := g.builtin_allocation_size_c_type('malloc_noscan', 0) + memdup_size_ct := g.builtin_allocation_size_c_type('memdup', 1) + memdup_aligned_size_ct := g.builtin_allocation_size_c_type('memdup_align', 1) + memdup_align_ct := g.builtin_allocation_size_c_type('memdup_align', 2) + g.writeln('u8* malloc_noscan(${malloc_size_ct} n);') + g.writeln('void* memdup(void* src, ${memdup_size_ct} sz);') g.writeln('static inline Array* v3_heap_array(Array value) { return (Array*)memdup(&value, sizeof(Array)); }') // Integer types only: `qsort` is not stable, which only floats could show (see // `array_default_sort_runtime_helper` in the transformer). for sort_spec in ['int|${g.int_ct}', 'i8|signed char', 'i16|short', 'i64|long long', 'u8|unsigned char', 'u16|unsigned short', 'u32|unsigned', 'u64|unsigned long long', - 'isize|ptrdiff_t', 'usize|size_t', 'rune|unsigned', 'char|char'] { + 'isize|ptrdiff_t', 'uint|size_t', 'rune|unsigned', 'char|char'] { sort_type := sort_spec.all_before('|') c_type := sort_spec.all_after('|') g.writeln('static int v3_array_sort_${sort_type}_cmp(const void* a, const void* b) { ${c_type} av = *(const ${c_type}*)a; ${c_type} bv = *(const ${c_type}*)b; return (av > bv) - (av < bv); }') @@ -22962,7 +22979,7 @@ fn (mut g FlatGen) builtin_abi_decls() { g.writeln('int posix_memalign(void** memptr, size_t alignment, size_t size);') g.writeln('#endif') g.writeln('#endif') - g.writeln('void* memdup_align(void* src, ptrdiff_t sz, ptrdiff_t alignment);') + g.writeln('void* memdup_align(void* src, ${memdup_aligned_size_ct} sz, ${memdup_align_ct} alignment);') g.writeln('void v_free(void* p);') g.writeln('static inline void* v3_aligned_memdup(void* src, ptrdiff_t sz, size_t alignment) {') g.writeln('#if defined(CUSTOM_DEFINE_prealloc) || defined(CUSTOM_DEFINE_vgc) || defined(_VGCBOEHM) || defined(CUSTOM_DEFINE_gcboehm)') @@ -25964,7 +25981,7 @@ fn (mut g FlatGen) emit_const(name string, val_id flat.NodeId) { 'float', 'double', 'isize', - 'usize', + 'uint', ] { if qname == 'max_len' && ct == 'int' { g.writeln('enum { ${qname} = ${expr_str} };') @@ -26975,7 +26992,7 @@ fn (mut g FlatGen) gen_compound_shift_value(lhs_text string, lhs_id flat.NodeId, // already rendered as a C expression (used by `>>>=` to shift through a // pointer temp so the lvalue is evaluated exactly once). // unsigned_shift_parts maps an operand's C type to the unsigned counterpart -// used for `>>>` logical shifts and its bit-width text. isize/usize lower to +// used for `>>>` logical shifts and its bit-width text. isize/uint lower to // ptrdiff_t/size_t in C and are pointer-width, so their unsigned view and bit // width come from size_t, not a fixed 64. fn unsigned_shift_parts(ct string) (string, string) { @@ -26985,7 +27002,7 @@ fn unsigned_shift_parts(ct string) (string, string) { 'int', 'i32', 'u32' { 'u32', '32' } 'i64', 'u64' { 'u64', '64' } 'i128', 'u128' { 'u128', '128' } - 'isize', 'usize', 'ptrdiff_t', 'size_t' { 'size_t', '(sizeof(size_t) * 8)' } + 'isize', 'uint', 'ptrdiff_t', 'size_t' { 'size_t', '(sizeof(size_t) * 8)' } types.portable_int_c_type { portable_uint_c_type, '__V_INT_BITS' } else { 'u64', '64' } } diff --git a/vlib/v/gen/c/fixed_array_numeric_literal_test.v b/vlib/v/gen/c/fixed_array_numeric_literal_test.v index a09ef552b1..d24375b8ea 100644 --- a/vlib/v/gen/c/fixed_array_numeric_literal_test.v +++ b/vlib/v/gen/c/fixed_array_numeric_literal_test.v @@ -114,7 +114,7 @@ const values = [u64(0xffff_ffff_ffff_ffff), u64(0o1777777777777777777777), u64(1 const negatives = [i64(-1), i64(-9223372036854775807)]! const wide = [u128(18446744073709551616), u128(340282366920938463463374607431768211455)]! const aliases = [Wide(u128(18446744073709551616))]! -const platform = [int(123), isize(123), usize(123)]! +const platform = [int(123), int(123), uint(123)]! fn main() {} ')! defer { os.rm(path) or {} } diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 9d11ef0e28..7316f62f77 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -9525,7 +9525,7 @@ fn (g &FlatGen) expr_is_non_string_scalar_value(id flat.NodeId) bool { if node.kind == .ident { if c_type := g.local_storage_c_type(node.value) { return c_type in ['bool', 'char', 'i8', 'i16', 'int', 'i64', 'isize', 'u8', 'u16', - 'u32', 'u64', 'usize', 'f32', 'f64', 'rune', types.portable_int_c_type] + 'u32', 'u64', 'uint', 'f32', 'f64', 'rune', types.portable_int_c_type] } if raw_type_source_id := g.local_storage_raw_type(node.value) { raw_type_source_id_2 := raw_type_source_id @@ -12984,7 +12984,7 @@ fn callback_can_cast_scalar_int_param(actual_ct string, expected_ct string) bool fn callback_is_scalar_int_c_type(ct string) bool { return trimmed_space(ct) in ['int', 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'char', - 'bool', 'isize', 'usize', 'ptrdiff_t', 'size_t', types.portable_int_c_type] + 'bool', 'isize', 'uint', 'ptrdiff_t', 'size_t', types.portable_int_c_type] } fn (mut g FlatGen) callback_c_type(typ types.Type) string { @@ -18054,6 +18054,9 @@ fn (mut g FlatGen) c_extern_interop_type_name(t types.Type) ?string { return base + '*' } if t is types.Alias { + if t.name() == 'C.ptrdiff_t' { + return 'ptrdiff_t' + } // A `type Cb = fn (int)` alias over a function type must still keep C `int` // inside the C ABI; alias-over-`int` likewise. Non-interop bases return none. if _ := g.tc.c_abi_fn_ptr_type_for_type_text(t.source_type_id()) { @@ -18150,7 +18153,7 @@ fn (mut g FlatGen) c_call_arg_cabi_cast(arg_idx int, typed_param_count int, para // that prototype is exactly what the callee's parameter type was written // against. A `fn C.` declaration cannot spell C qualifiers, so casting to the // V-declared signature is what *creates* an incompatible-pointer-type error - // (e.g. `fn C.mbedtls_net_send(voidptr, &u8, usize) i32` drops the `const` in + // (e.g. `fn C.mbedtls_net_send(voidptr, &u8, uint) i32` drops the `const` in // mbedtls_net_send's real `const unsigned char *` buffer parameter). if _ := fn_type_from(param_types[arg_idx]) { if g.is_c_extern_fn_name_arg(arg_id) { diff --git a/vlib/v/gen/c/fn_parallel_notd_v3_no_parallel.v b/vlib/v/gen/c/fn_parallel_notd_v3_no_parallel.v index f2a87f64b9..5a505484ab 100644 --- a/vlib/v/gen/c/fn_parallel_notd_v3_no_parallel.v +++ b/vlib/v/gen/c/fn_parallel_notd_v3_no_parallel.v @@ -1649,7 +1649,7 @@ fn (mut g FlatGen) write_scoped_cgen_batch_output(batch &FlatGen) bool { } } else { unsafe { - file.write_full_buffer(batch.sb.data, usize(batch.sb.len)) or { + file.write_full_buffer(batch.sb.data, uint(batch.sb.len)) or { g.output_error = err.msg() file.close() return false diff --git a/vlib/v/gen/c/headerless_program_test.v b/vlib/v/gen/c/headerless_program_test.v index f1cf6feaa9..b5aaa91546 100644 --- a/vlib/v/gen/c/headerless_program_test.v +++ b/vlib/v/gen/c/headerless_program_test.v @@ -83,7 +83,7 @@ fn test_bodyless_libc_bindings_compile_without_headers() { os.rmdir_all(root) or {} } source := os.join_path(root, 'main.c.v') - os.write_file(source, 'fn C.strlen(const_s &char) usize + os.write_file(source, 'fn C.strlen(const_s &char) uint fn C.puts(const_s &char) i32 fn main() { diff --git a/vlib/v/gen/c/int128.v b/vlib/v/gen/c/int128.v index 074c6b432f..001f841799 100644 --- a/vlib/v/gen/c/int128.v +++ b/vlib/v/gen/c/int128.v @@ -419,7 +419,7 @@ fn (mut g FlatGen) gen_int128_cast(target_type types.Type, source_id flat.NodeId } // int128_narrow_c_type returns the C type a 128-bit value narrows into, or none -// when the target is not a narrower integer. `isize`, `usize`, `rune` and `char` +// when the target is not a narrower integer. `isize`, `uint`, `rune` and `char` // are types of their own in V rather than primitives, so they need naming here // too, or the cast falls through to a C cast the struct representation rejects. fn (mut g FlatGen) int128_narrow_c_type(t types.Type) ?string { @@ -593,7 +593,7 @@ fn source_signedness_known(t &types.Type) bool { } // int128_source_is_signed reports whether an integer source casts with a sign -// extension. `isize` is signed, `usize` and the unsigned primitives are not. +// extension. `isize` is signed, `uint` and the unsigned primitives are not. fn int128_source_is_signed(t &types.Type) bool { clean := unalias_type(t) if clean is types.Primitive { diff --git a/vlib/v/gen/c/output_nix.c.v b/vlib/v/gen/c/output_nix.c.v index e277ded4f3..8405722963 100644 --- a/vlib/v/gen/c/output_nix.c.v +++ b/vlib/v/gen/c/output_nix.c.v @@ -6,7 +6,7 @@ import os fn write_c_output_sequential(mut file os.File, prefix []u8, segments []string, tail string, separator string) ! { if prefix.len > 0 { - unsafe { file.write_full_buffer(prefix.data, usize(prefix.len))! } + unsafe { file.write_full_buffer(prefix.data, uint(prefix.len))! } } for segment in segments { if segment.len > 0 { @@ -37,7 +37,7 @@ fn write_c_output_vectored_batches(path string, prefix []u8, segments []string, if prefix.len > 0 { iovs << C.iovec{ iov_base: prefix.data - iov_len: usize(prefix.len) + iov_len: uint(prefix.len) } } for segment in segments { @@ -45,19 +45,19 @@ fn write_c_output_vectored_batches(path string, prefix []u8, segments []string, if separator.len > 0 { iovs << C.iovec{ iov_base: separator.str - iov_len: usize(separator.len) + iov_len: uint(separator.len) } } iovs << C.iovec{ iov_base: segment.str - iov_len: usize(segment.len) + iov_len: uint(segment.len) } } } if tail.len > 0 { iovs << C.iovec{ iov_base: tail.str - iov_len: usize(tail.len) + iov_len: uint(tail.len) } } mut file := os.open_file(path, 'wb')! @@ -85,7 +85,7 @@ fn write_c_output_vectored_batches(path string, prefix []u8, segments []string, } // A short write stops inside some piece: skip the completed pieces and // resume from the unwritten remainder of the partial one. - mut left := usize(written) + mut left := uint(written) for left > 0 && i < iovs.len { if left >= iovs[i].iov_len { left -= iovs[i].iov_len @@ -106,7 +106,7 @@ const c_output_iov_batch = 512 struct C.iovec { mut: iov_base voidptr - iov_len usize + iov_len uint } -fn C.writev(fd int, const_iov &C.iovec, iovcnt int) isize +fn C.writev(fd int, const_iov &C.iovec, iovcnt int) C.ptrdiff_t diff --git a/vlib/v/gen/c/portable_int_test.v b/vlib/v/gen/c/portable_int_test.v index 747357a6c1..f39991bfa1 100644 --- a/vlib/v/gen/c/portable_int_test.v +++ b/vlib/v/gen/c/portable_int_test.v @@ -21,6 +21,14 @@ fn maybe(n int) ?int { } fn main() { + assert sizeof(uint) == sizeof(int) + assert sizeof(uint) == sizeof(voidptr) + maximum := ~uint(0) + assert maximum >> (sizeof(uint) * 8 - 1) == 1 + assert maximum + uint(1) == 0 + mut unsigned_keys := map[uint]int{} + unsigned_keys[maximum] = 17 + assert unsigned_keys[maximum] == 17 mut m := map[int]string{} for i in 0 .. 100 { m[i * 7] = i.str() diff --git a/vlib/v/gen/c/portable_runtime_test.v b/vlib/v/gen/c/portable_runtime_test.v index c5ef404097..4a30d3de50 100644 --- a/vlib/v/gen/c/portable_runtime_test.v +++ b/vlib/v/gen/c/portable_runtime_test.v @@ -6,6 +6,26 @@ import v.flat import v.pref import v.types +fn test_allocation_runtime_prototypes_match_legacy_and_modern_sizes() { + for size in [types.Type(types.int_), types.Type(types.isize_)] { + mut ast := flat.FlatAst.new() + mut tc := types.TypeChecker.new(&ast) + tc.fn_param_types['malloc_noscan'] = [size] + tc.fn_param_types['memdup'] = [types.Type(types.voidptr_), size] + tc.fn_param_types['memdup_align'] = [types.Type(types.voidptr_), size, size] + mut g := FlatGen.new() + g.a = &ast + g.tc = &tc + g.has_builtins = true + g.builtin_abi_decls() + code := g.sb.str() + ct := tc.c_type(size) + assert code.contains('u8* malloc_noscan(${ct} n);'), code + assert code.contains('void* memdup(void* src, ${ct} sz);'), code + assert code.contains('void* memdup_align(void* src, ${ct} sz, ${ct} alignment);'), code + } +} + fn test_partial_c_closure_view_keeps_the_v_runtime_layout() { mut ast := flat.FlatAst.new() mut tc := types.TypeChecker.new(&ast) diff --git a/vlib/v/gen/c/reflection.v b/vlib/v/gen/c/reflection.v index 514af56dd5..036088d9d9 100644 --- a/vlib/v/gen/c/reflection.v +++ b/vlib/v/gen/c/reflection.v @@ -141,7 +141,7 @@ fn reflection_builtin_type_kind(name string) int { 'u16' { 12 } 'u32' { 13 } 'u64' { 14 } - 'usize' { 15 } + 'uint' { 15 } 'f32' { 16 } 'f64' { 17 } 'char' { 18 } @@ -598,7 +598,7 @@ fn (mut g FlatGen) gen_reflection_data() { mut seen_ids := map[int]bool{} builtin_names := ['void', 'voidptr', 'byteptr', 'charptr', 'i8', 'i16', 'i32', 'int', 'i64', - 'isize', 'u8', 'u16', 'u32', 'u64', 'usize', 'f32', 'f64', 'char', 'bool', 'none', 'string', + 'isize', 'u8', 'u16', 'u32', 'u64', 'uint', 'f32', 'f64', 'char', 'bool', 'none', 'string', 'rune', 'float literal', 'int literal', 'thread'] for name in builtin_names { g.gen_reflection_type(flat.source_type_id(name), 'builtin', reflection_builtin_type_kind(name), reflection_none_info(), diff --git a/vlib/v/gen/c/stmt.v b/vlib/v/gen/c/stmt.v index f8eeeb82af..f2fc10c83e 100644 --- a/vlib/v/gen/c/stmt.v +++ b/vlib/v/gen/c/stmt.v @@ -10128,7 +10128,7 @@ fn (g &FlatGen) assign_struct_operator_method(lhs_type &types.Type, op flat.Op) } if clean is types.Struct && g.tc.c_type(clean) in ['bool', 'char', 'i8', 'i16', 'i32', 'int', 'i64', 'u8', 'u16', - 'u32', 'u64', 'f32', 'f64', 'isize', 'usize', 'voidptr'] { + 'u32', 'u64', 'f32', 'f64', 'isize', 'uint', 'voidptr'] { return none } op_symbol := assign_struct_operator_symbol(op) or { return none } diff --git a/vlib/v/gen/c/str_intp.v b/vlib/v/gen/c/str_intp.v index ef50acaf7a..df03a9dc64 100644 --- a/vlib/v/gen/c/str_intp.v +++ b/vlib/v/gen/c/str_intp.v @@ -196,7 +196,7 @@ fn is_string_interp_signed_int_type(name string) bool { } fn is_string_interp_unsigned_int_type(name string) bool { - return name in ['u8', 'u16', 'u32', 'u64', 'usize'] + return name in ['u8', 'u16', 'u32', 'u64', 'uint'] } fn is_string_interp_char_code_type(name string) bool { diff --git a/vlib/v/gen/c/struct.v b/vlib/v/gen/c/struct.v index 077b63f4b7..99c8951f91 100644 --- a/vlib/v/gen/c/struct.v +++ b/vlib/v/gen/c/struct.v @@ -3228,7 +3228,7 @@ fn (g &FlatGen) is_scalar_c_type(c_type string) bool { return true } return c_type in ['bool', 'char', 'byte', 'u8', 'i8', 'u16', 'i16', 'u32', 'i32', 'u64', 'i64', - 'int', 'isize', 'usize', 'size_t', 'ptrdiff_t', 'float', 'double', 'voidptr', + 'int', 'isize', 'uint', 'size_t', 'ptrdiff_t', 'float', 'double', 'voidptr', types.portable_int_c_type] } @@ -4618,7 +4618,7 @@ fn (g &FlatGen) atomic_helper_suffix(typ &types.Type) string { return match ct { 'i8', 'u8', 'byte', 'bool', 'char' { 'byte' } 'i16', 'u16' { 'u16' } - 'i64', 'u64', 'isize', 'usize' { 'u64' } + 'i64', 'u64', 'isize', 'uint' { 'u64' } // Portable C defines the `_w` helpers for the C compiler's `int` width. types.portable_int_c_type { pointer_width_suffix } else { 'u32' } @@ -5455,8 +5455,8 @@ fn (g &FlatGen) ident_may_name_type(name string) bool { // struct_field_list_key identifies a field list by its storage and length. @[inline] fn struct_field_list_key(fields []types.StructField) u64 { - // usize keeps a 32-bit address zero-extended, clear of the length bits. - return u64(usize(voidptr(fields.data))) | (u64(fields.len) << 48) + // uint keeps a 32-bit address zero-extended, clear of the length bits. + return u64(uint(voidptr(fields.data))) | (u64(fields.len) << 48) } // new_struct_field_index_base indexes the checked field lists that @@ -6785,7 +6785,7 @@ fn (g &FlatGen) map_callback_names(key_type types.Type) (string, string, string, const pointer_width_suffix = 'w' // map_key_has_pointer_width reports whether map keys of this type are as wide as a -// pointer: V's `int`, `isize`, `usize` and pointers. +// pointer: V's `int`, `isize`, `uint` and pointers. fn map_key_has_pointer_width(key_type &types.Type, c_key string) bool { return c_key == types.portable_int_c_type || key_type is types.Pointer || key_type is types.ISize || key_type is types.USize diff --git a/vlib/v/gen/c/sumtype_escape_ownership_test.v b/vlib/v/gen/c/sumtype_escape_ownership_test.v index 75ad36f356..feaf677a23 100644 --- a/vlib/v/gen/c/sumtype_escape_ownership_test.v +++ b/vlib/v/gen/c/sumtype_escape_ownership_test.v @@ -298,13 +298,13 @@ fn exercise_factories() { assert (ordinary as &Item).code == 1 assert (manual as &Item).code == 2 assert (direct as &Item).code == 3 - assert usize(voidptr(ordinary as &Item)) % 64 == 0 + assert uint(voidptr(ordinary as &Item)) % 64 == 0 nested := nested_factory(true) absent := nested_factory(false) assert absent is int assert churn_stack() != 0 assert (nested as &Item).code == 5 - assert usize(voidptr(nested as &Item)) % 64 == 0 + assert uint(voidptr(nested as &Item)) % 64 == 0 assert C.transfer_count(5) == 0 nested_alias := nested_alias_factory() assert (nested_alias as &Item).code == 6 diff --git a/vlib/v/gen/c/sumtype_semantics_test.v b/vlib/v/gen/c/sumtype_semantics_test.v index 8b6e7a6d77..842f8c3683 100644 --- a/vlib/v/gen/c/sumtype_semantics_test.v +++ b/vlib/v/gen/c/sumtype_semantics_test.v @@ -125,7 +125,7 @@ fn main() { local := from_local() if local is &Payload { assert local.value == 17 - assert usize(local) % 64 == 0 + assert uint(local) % 64 == 0 } else { assert false } mut original := Payload{value: 23} reference := from_mut(mut original) @@ -133,7 +133,7 @@ fn main() { if reference is &Payload { assert voidptr(reference) == voidptr(&original) assert reference.value == 99 - assert usize(reference) % 64 == 0 + assert uint(reference) % 64 == 0 } else { assert false } borrowed := from_borrowed(&original) original.value = 101 diff --git a/vlib/v/gen/c/testdata/sumtype_fixed_array_pointer/aligned_owner.c.v b/vlib/v/gen/c/testdata/sumtype_fixed_array_pointer/aligned_owner.c.v index fe56a9718f..78ea27c140 100644 --- a/vlib/v/gen/c/testdata/sumtype_fixed_array_pointer/aligned_owner.c.v +++ b/vlib/v/gen/c/testdata/sumtype_fixed_array_pointer/aligned_owner.c.v @@ -33,7 +33,7 @@ fn next_choice() AlignChoice { fn owned_array_scope() { owner := AlignArrayOwner(&[2]AlignChoice{init: next_choice()}) values := owner as &[2]AlignChoice - assert usize(voidptr(values)) % 64 == 0 + assert uint(voidptr(values)) % 64 == 0 assert C.aligned_owner_visits() == 2 assert ((*values)[0] as &AlignDropItem).code == 1 assert ((*values)[1] as &AlignDropItem).code == 2 diff --git a/vlib/v/gen/c/testdata/sumtype_fixed_array_pointer/owning_sum_replace.c.v b/vlib/v/gen/c/testdata/sumtype_fixed_array_pointer/owning_sum_replace.c.v index ea2e31d329..7b16477e97 100644 --- a/vlib/v/gen/c/testdata/sumtype_fixed_array_pointer/owning_sum_replace.c.v +++ b/vlib/v/gen/c/testdata/sumtype_fixed_array_pointer/owning_sum_replace.c.v @@ -41,9 +41,9 @@ fn owned_rebind(other PairPointer) { assert C.slot_guard_count(1) == 0 assert C.slot_guard_count(2) == 0 // Rewrapping the same pointer must retain the old cleanup obligation. - same_address := usize(voidptr(owner as PairPointer)) + same_address := uint(voidptr(owner as PairPointer)) rebind(mut owner, owner as PairPointer) - assert usize(voidptr(owner as PairPointer)) == same_address + assert uint(voidptr(owner as PairPointer)) == same_address assert C.slot_guard_count(1) == 0 assert C.slot_guard_count(2) == 0 rebind(mut owner, other) diff --git a/vlib/v/gen/c/types.v b/vlib/v/gen/c/types.v index 391d251c9a..6498605b74 100644 --- a/vlib/v/gen/c/types.v +++ b/vlib/v/gen/c/types.v @@ -2579,7 +2579,7 @@ fn (g &FlatGen) enum_field_expr_value_with_enum(id flat.NodeId, enum_module stri } else { types.unalias_type(g.usable_expr_type(g.a.child(&node, 0))).name() } - if typ in ['u64', 'usize'] { i64(u64(left) >> right) } else { left >> right } + if typ in ['u64', 'uint'] { i64(u64(left) >> right) } else { left >> right } } .right_shift_unsigned { if isnil(g.tc) { @@ -2880,7 +2880,7 @@ fn (g &FlatGen) enum_comptime_expr_value(id flat.NodeId, locals map[string]i64, } else { types.unalias_type(g.usable_expr_type(g.a.child(&node, 0))).name() } - if typ in ['u64', 'usize'] { i64(u64(left) >> right) } else { left >> right } + if typ in ['u64', 'uint'] { i64(u64(left) >> right) } else { left >> right } } .right_shift_unsigned { if isnil(g.tc) { diff --git a/vlib/v/gen/c/windows_header_macro_names_test.v b/vlib/v/gen/c/windows_header_macro_names_test.v index d12bb9b3ad..7949b2e143 100644 --- a/vlib/v/gen/c/windows_header_macro_names_test.v +++ b/vlib/v/gen/c/windows_header_macro_names_test.v @@ -83,14 +83,14 @@ fn ordinary(seed int) int { v_alloca := 8 __v3_internal_symbol_libc_alloca := 9 cell := Cell{value: alloca} - return cell.value + alloca + v_alloca + __v3_internal_symbol_libc_alloca + int(usize(voidptr(&cell)) & 511) + return cell.value + alloca + v_alloca + __v3_internal_symbol_libc_alloca + int(uint(voidptr(&cell)) & 511) } fn staging(seed int) int { alloca := seed v_alloca := 8 __v3_internal_symbol_libc_alloca := 9 cell := if alloca == 7 { Cell{value: alloca} } else { Cell{value: 0} } - return cell.value + alloca + v_alloca + __v3_internal_symbol_libc_alloca + int(usize(voidptr(&cell)) & 511) + return cell.value + alloca + v_alloca + __v3_internal_symbol_libc_alloca + int(uint(voidptr(&cell)) & 511) } fn main() { _ := ordinary(7); _ := staging(7) } ')! diff --git a/vlib/v/gen/c/windows_pointer_allocator_test.v b/vlib/v/gen/c/windows_pointer_allocator_test.v index e3f581e31b..f54503ee52 100644 --- a/vlib/v/gen/c/windows_pointer_allocator_test.v +++ b/vlib/v/gen/c/windows_pointer_allocator_test.v @@ -91,7 +91,7 @@ fn test_windows_builtin_and_compiler_promoted_pointers_keep_the_v_allocator_fami defer { os.rmdir_all(dir) or {} } source := os.join_path(dir, 'main.c.v') c_source := os.join_path(dir, 'main.c') - os.write_file(source, 'fn C.malloc(size usize) voidptr + os.write_file(source, 'fn C.malloc(size uint) voidptr fn C.free(value voidptr) @[aligned: 64] struct AlignedCell { value int } @@ -112,10 +112,10 @@ fn (value &Holder) free() { unsafe { free(value) } } fn release_method(value &Holder) { unsafe { value.free() } } fn release_c(value &NaturalHolder) { unsafe { C.free(value) } } fn main() { - ordinary := unsafe { &NaturalHolder(malloc(sizeof(NaturalHolder))) } + ordinary := unsafe { &NaturalHolder(malloc(int(sizeof(NaturalHolder)))) } release_natural_v(ordinary) seed := NaturalHolder{} - copied := unsafe { &NaturalHolder(memdup(&seed, sizeof(NaturalHolder))) } + copied := unsafe { &NaturalHolder(memdup(&seed, int(sizeof(NaturalHolder)))) } release_natural_method(copied) compiler_owned := promoted() release_method(compiler_owned) @@ -127,8 +127,8 @@ fn main() { '-manualfree', '-o', c_source, source]) assert generated_result.exit_code == 0, generated_result.output generated := os.read_file(c_source)! - allocate := allocator_test_c_function(generated, 'u8* v_malloc(ptrdiff_t n) {') - copy := allocator_test_c_function(generated, 'void* memdup(void* src, ptrdiff_t sz) {') + allocate := allocator_test_c_function(generated, 'u8* v_malloc(i64 n) {') + copy := allocator_test_c_function(generated, 'void* memdup(void* src, i64 sz) {') deallocate := allocator_test_c_function(generated, 'void v_free(void* ptr) {') assert allocate.contains('_aligned_malloc(n, 1)'), allocate assert copy.contains('v_malloc(sz)'), copy @@ -283,8 +283,8 @@ fn main() { implicit_aligned() mock_source := os.join_path(dir, 'implicit_sum_mock.c') mock_binary := os.join_path(dir, 'implicit_sum_mock.exe') os.write_file(mock_source, '${allocator_test_mock_runtime(declarations)} -${allocator_test_c_function(generated, 'u8* v_malloc(ptrdiff_t n) {')} -${allocator_test_c_function(generated, 'void* memdup(void* src, ptrdiff_t sz) {')} +${allocator_test_c_function(generated, 'u8* v_malloc(i64 n) {')} +${allocator_test_c_function(generated, 'void* memdup(void* src, i64 sz) {')} ${allocator_test_c_function(generated, 'void v_free(void* ptr) {')} ${allocator_test_c_function(generated, 'static inline void* v3_aligned_memdup(void* src, ptrdiff_t sz, size_t alignment) {')} ${allocator_test_c_function(generated, 'static inline void v3_aligned_free(void* p) {')} diff --git a/vlib/v/gen/fastc/arm64_d_arm64.v b/vlib/v/gen/fastc/arm64_d_arm64.v index b35964cc66..abe0e4142e 100644 --- a/vlib/v/gen/fastc/arm64_d_arm64.v +++ b/vlib/v/gen/fastc/arm64_d_arm64.v @@ -1272,7 +1272,7 @@ fn (mut p FastArm64Program) type_id(name_source_id u32) ssa.TypeID { 'u32', 'unsigned int' { return p.u32_type } - 'u64', 'usize' { + 'u64', 'uint', 'usize' { return p.u64_type } 'f32' { @@ -6370,7 +6370,8 @@ fn (mut p FastArm64Parser) parse_prefix() !FastArm64Value { } } if p.tok == .name && (p.lit in ['bool', 'i8', 'char', 'i16', 'int', 'i32', 'rune', 'i64', - 'u8', 'u16', 'u32', 'u64', 'isize', 'usize', 'f32', 'f64', 'voidptr', 'byteptr', 'charptr'] || flat.source_type_id(p.lit) in p.program.type_ids || p.program.type_aliases.contains(p.lit)) { + 'u8', 'u16', 'u32', 'u64', 'isize', 'uint', 'usize', 'f32', 'f64', 'voidptr', 'byteptr', + 'charptr'] || flat.source_type_id(p.lit) in p.program.type_ids || p.program.type_aliases.contains(p.lit)) { mut look := p.s if look.scan() == .lpar { type_name := p.lit @@ -7056,8 +7057,8 @@ fn (mut p FastArm64Parser) parse_sizeof_expression() !FastArm64Value { if p.tok == .name { mut look := p.s if look.scan() == .rpar && (p.lit in ['bool', 'i8', 'char', 'i16', 'int', 'i32', 'rune', - 'i64', 'u8', 'u16', 'u32', 'u64', 'isize', 'usize', 'f32', 'f64', 'voidptr', 'byteptr', - 'charptr', 'string'] || flat.source_type_id(p.lit) in p.program.type_ids || p.program.type_aliases.contains(p.lit)) { + 'i64', 'u8', 'u16', 'u32', 'u64', 'isize', 'uint', 'usize', 'f32', 'f64', 'voidptr', + 'byteptr', 'charptr', 'string'] || flat.source_type_id(p.lit) in p.program.type_ids || p.program.type_aliases.contains(p.lit)) { type_name := p.lit p.next() p.expect(.rpar)! @@ -7960,7 +7961,7 @@ fn (mut p FastArm64Parser) parse_name_expression() !FastArm64Value { return p.parse_cast(flat.source_type_id(qualified_type_key)) } if (first_name in ['int', 'i8', 'char', 'i16', 'i32', 'rune', 'i64', 'u8', 'u16', 'u32', - 'u64', 'isize', 'usize', 'f32', 'f64', 'bool', 'voidptr', 'byteptr', 'charptr'] || flat.source_type_id(first_name) in p.program.type_ids || p.program.type_aliases.contains(first_name)) && display_name == first_name { + 'u64', 'isize', 'uint', 'usize', 'f32', 'f64', 'bool', 'voidptr', 'byteptr', 'charptr'] || flat.source_type_id(first_name) in p.program.type_ids || p.program.type_aliases.contains(first_name)) && display_name == first_name { return p.parse_cast(flat.source_type_id(first_name)) } return p.parse_call(key, display_name) diff --git a/vlib/v/gen/fastc/arm64_test.v b/vlib/v/gen/fastc/arm64_test.v index 6a69b1c930..1004c33b43 100644 --- a/vlib/v/gen/fastc/arm64_test.v +++ b/vlib/v/gen/fastc/arm64_test.v @@ -1401,7 +1401,7 @@ struct CacheLine { fn local_is_aligned() bool { value := CacheLine{value: 7} - return usize(&value) % 64 == 0 + return uint(&value) % 64 == 0 } fn main() { @@ -1597,7 +1597,7 @@ fn test_fastc_arm64_string_slice_owns_terminated_storage() { } source_path := os.join_path_single(test_dir, 'main.v') output_path := os.join_path_single(test_dir, 'app') - os.write_file(source_path, 'fn C.strlen(value &char) usize + os.write_file(source_path, 'fn C.strlen(value &char) uint fn C.free(value voidptr) fn main() { diff --git a/vlib/v/gen/fastc/array.v b/vlib/v/gen/fastc/array.v index 2a25dc1274..24946c0364 100644 --- a/vlib/v/gen/fastc/array.v +++ b/vlib/v/gen/fastc/array.v @@ -1087,7 +1087,7 @@ fn (g &Parser) render_raw_expression_tokens(tokens []FastcExpressionToken) ?stri } else { fastc_primitive_c_type(item.lit) or { '' } } - is_c_cast := i >= 2 && tokens[i - 2].tok == .name && tokens[i - 2].lit == 'C' && tokens[i - 1].tok == .dot && item.lit.len > 0 && 'C.${item.lit}' !in g.functions && fastc_call_has_one_argument(tokens, i + 1) && (item.lit[0].is_capital() || '#Cstruct#${item.lit}' in g.declared_types) + is_c_cast := i >= 2 && tokens[i - 2].tok == .name && tokens[i - 2].lit == 'C' && tokens[i - 1].tok == .dot && item.lit.len > 0 && 'C.${item.lit}' !in g.functions && fastc_call_has_one_argument(tokens, i + 1) && (item.lit[0].is_capital() || '#Cstruct#${item.lit}' in g.declared_types || '#Ctypedef#${item.lit}' in g.declared_types) if is_c_cast { cast_type = if '#Cstruct#${item.lit}' in g.declared_types { 'struct ${item.lit}' @@ -1643,7 +1643,7 @@ fn (g &Parser) constant_integer_factor(tokens []FastcExpressionToken, start int) return none } if start + 1 < tokens.len && tokens[start + 1].tok == .lpar && item.lit in ['u8', 'u16', 'u32', - 'u64', 'i8', 'i16', 'i32', 'i64', 'int', 'usize', 'isize'] && item.lit !in g.locals { + 'u64', 'i8', 'i16', 'i32', 'i64', 'int', 'uint', 'usize', 'isize'] && item.lit !in g.locals { value, close := g.constant_integer_sum(tokens, start + 2)? if close >= tokens.len || tokens[close].tok != .rpar { return none } converted := match item.lit { @@ -1653,7 +1653,7 @@ fn (g &Parser) constant_integer_factor(tokens []FastcExpressionToken, start int) 'i8' { int(i8(value)) } 'i16' { int(i16(value)) } 'i32' { int(i32(value)) } - 'usize' { + 'uint', 'usize' { if g.prefs.target.pointer_bits == 32 { return int(u32(value)), close + 1 } if g.prefs.target.pointer_bits != 64 { return none } if value < 0 { return none } diff --git a/vlib/v/gen/fastc/asm.v b/vlib/v/gen/fastc/asm.v index bae1bab12f..a3213b6f13 100644 --- a/vlib/v/gen/fastc/asm.v +++ b/vlib/v/gen/fastc/asm.v @@ -488,6 +488,7 @@ fn fastc_asm_lower_template(source string, arch string, aliases map[string]Fastc flat.source_type_int, flat.source_type_i64, flat.source_type_u64, + flat.source_type_uint, flat.source_type_usize, flat.source_type_isize, ] { @@ -652,7 +653,7 @@ fn fastc_asm_intel_memory_size(typ u32) string { 'dword ptr ' } flat.source_type_int, flat.source_type_i64, flat.source_type_u64, flat.source_type_isize, - flat.source_type_usize, flat.source_type_f64 { + flat.source_type_uint, flat.source_type_usize, flat.source_type_f64 { 'qword ptr ' } else { '' } diff --git a/vlib/v/gen/fastc/c_extern_const_test.v b/vlib/v/gen/fastc/c_extern_const_test.v index 80bfa96832..f61a6ff362 100644 --- a/vlib/v/gen/fastc/c_extern_const_test.v +++ b/vlib/v/gen/fastc/c_extern_const_test.v @@ -15,7 +15,7 @@ fn test_fastc_explicit_pthread_helpers_keep_the_native_header_ownership() { @[c_extern] fn C.v3_pthread_zero() C.pthread_t @[c_extern] -fn C.v3_pthread_create(worker &C.pthread_t, stack_size usize, start_routine fn (voidptr) voidptr, arg voidptr) int +fn C.v3_pthread_create(worker &C.pthread_t, stack_size uint, start_routine fn (voidptr) voidptr, arg voidptr) int @[c_extern] fn C.v3_pthread_is_current(worker C.pthread_t) int @[c_extern] diff --git a/vlib/v/gen/fastc/c_native_array_test.v b/vlib/v/gen/fastc/c_native_array_test.v index 742fd1983e..23bdc5a56f 100644 --- a/vlib/v/gen/fastc/c_native_array_test.v +++ b/vlib/v/gen/fastc/c_native_array_test.v @@ -20,7 +20,7 @@ fn test_fastc_tagged_c_array_element_types() { struct C.iovec { mut: iov_base voidptr - iov_len usize + iov_len uint } fn main() { mut values := []C.iovec{cap: 2} diff --git a/vlib/v/gen/fastc/call_recursion_test.v b/vlib/v/gen/fastc/call_recursion_test.v index 12976ac41c..a3d3632fe1 100644 --- a/vlib/v/gen/fastc/call_recursion_test.v +++ b/vlib/v/gen/fastc/call_recursion_test.v @@ -48,9 +48,9 @@ struct C.RawNode { value u64 } fn C.raw_nodes() voidptr @[typedef] struct C.raw_const_byte {} -fn C.raw_receive(context voidptr, data &C.raw_const_byte, length usize) +fn C.raw_receive(context voidptr, data &C.raw_const_byte, length uint) fn C.raw_received() u64 -struct Ops { receive fn (voidptr, &C.raw_const_byte, usize) } +struct Ops { receive fn (voidptr, &C.raw_const_byte, uint) } struct Words { addr [2]u64 } struct Group { words Words } struct Member { group Group } @@ -141,7 +141,7 @@ fn main() { assert node.value == u64(0xf123456789abcdef) ops := Ops{ receive: C.raw_receive } bytes := [u8(1), 2, 3] - unsafe { ops.receive(voidptr(0), &C.raw_const_byte(bytes.data + 1), usize(2)) } + unsafe { ops.receive(voidptr(0), &C.raw_const_byte(bytes.data + 1), uint(2)) } assert C.raw_received() == 4 group := Group{ words: Words{ addr: [u64(1), 2]! } } member := &Member{ group: Group{ words: Words{ addr: [u64(1), 3]! } } } diff --git a/vlib/v/gen/fastc/call_result_member_test.v b/vlib/v/gen/fastc/call_result_member_test.v index f102fb4142..a9d9f98e6b 100644 --- a/vlib/v/gen/fastc/call_result_member_test.v +++ b/vlib/v/gen/fastc/call_result_member_test.v @@ -50,11 +50,11 @@ fn test_fastc_pointer_type_sizeof_and_empty_array_use_c_type_syntax() { c_source := generate('module main struct CachedName { value int } struct array { len int } -fn consume(size isize) {} +fn consume(size int) {} fn main() { ar := array{} - size := isize(sizeof(&CachedName)) - consume(isize(3) * isize(sizeof(&CachedName))) + size := int(sizeof(&CachedName)) + consume(int(3) * int(sizeof(&CachedName))) assert sizeof(&CachedName) == sizeof(voidptr) println(1 + sizeof(&CachedName)) println(ar.len) @@ -74,9 +74,9 @@ fn test_fastc_nested_pointer_type_sizeof_executes() { os.rmdir_all(root) or {} } os.write_file(os.join_path(root, 'main.v'), 'struct CachedName { value int } -fn multiplied_size(size isize) isize { return size } +fn multiplied_size(size int) int { return size } fn main() { - assert multiplied_size(isize(3) * isize(sizeof(&CachedName))) == isize(3 * sizeof(voidptr)) + assert multiplied_size(int(3) * int(sizeof(&CachedName))) == int(3 * sizeof(voidptr)) assert sizeof(&CachedName) == sizeof(voidptr) size := 1 + sizeof(&CachedName) assert size == 1 + sizeof(voidptr) diff --git a/vlib/v/gen/fastc/collection_default_storage_test.v b/vlib/v/gen/fastc/collection_default_storage_test.v index 44e3e96081..61198673bd 100644 --- a/vlib/v/gen/fastc/collection_default_storage_test.v +++ b/vlib/v/gen/fastc/collection_default_storage_test.v @@ -13,7 +13,7 @@ fn test_fastc_collection_field_defaults_preserve_storage_width() { defer { os.rmdir_all(root) or {} } os.write_file(os.join_path(root, 'main.c.v'), r"module main @[c_extern] -fn C.alias_map_value_size(voidptr) usize +fn C.alias_map_value_size(voidptr) uint type Counts = map[string]int type ScopeStack = []int struct Tracker { @@ -65,7 +65,7 @@ fn main() { t.wide.delete(key) assert (t.wide[key] or { -1 }) == -1, 'wide key deletion' assert (t.wide[2] or { -1 }) == -7, 'other key survives deletion' - assert C.alias_map_value_size(voidptr(&t.aliased_counts)) == usize(sizeof(value)), 'aliased map storage size' + assert C.alias_map_value_size(voidptr(&t.aliased_counts)) == uint(sizeof(value)), 'aliased map storage size' t.aliased_scopes << value assert t.aliased_scopes[0] == value, 'aliased array storage' assert (optional(value) or { -1 }) == value, 'wide optional payload' diff --git a/vlib/v/gen/fastc/decl.v b/vlib/v/gen/fastc/decl.v index 050f0d90f9..3bed2adae9 100644 --- a/vlib/v/gen/fastc/decl.v +++ b/vlib/v/gen/fastc/decl.v @@ -2250,7 +2250,12 @@ fn fastc_generate_type_declarations(sources []FastcSourceFile, type_sources map[ // and `match` both reference `__v_typeid_`, so the exact value only // has to be unique and consistent. for offset, primitive in fastc_boxed_primitive_types { - out.writeln('#define __v_typeid_${primitive} ${u32(0x40000000) + u32(offset)}') + if primitive == 'usize' { + // Both spellings box as uint and must also match the same runtime tag. + out.writeln('#define __v_typeid_usize __v_typeid_uint') + } else { + out.writeln('#define __v_typeid_${primitive} ${u32(0x40000000) + u32(offset)}') + } } out.writeln('') mut timer := fastc_new_phase_timer() @@ -3288,7 +3293,7 @@ fn fastc_emit_enum_declaration(mut scan scanner.Scanner, source_file FastcSource // still `int` (or `u64` for flag enums); values are emitted with an explicit // cast, so a narrower/wider spelling does not change the generated C. is_backing_int := tok == .name && scan.lit in ['i8', 'i16', 'i32', 'i64', 'int', 'u8', - 'u16', 'u32', 'u64', 'isize', 'usize'] + 'u16', 'u32', 'u64', 'isize', 'uint', 'usize'] if !is_backing_int || (is_flag && scan.lit != 'u64') { return error('fastc parser does not support enum `${name}` backing type in ${source_file.path}') } diff --git a/vlib/v/gen/fastc/declaration_abi_test.v b/vlib/v/gen/fastc/declaration_abi_test.v index d0504be343..fc9d215ed6 100644 --- a/vlib/v/gen/fastc/declaration_abi_test.v +++ b/vlib/v/gen/fastc/declaration_abi_test.v @@ -218,11 +218,11 @@ fn test_fastc_target_exports_match_unqualified_target_header_prototypes() { prefs.vroot = @VEXEROOT prefs.target_libc_headers = true source := declaration_abi_generate('target_constness', r'module main -fn C.native_copy(destination voidptr, const_source voidptr, count usize) voidptr +fn C.native_copy(destination voidptr, const_source voidptr, count uint) voidptr @[c_extern] fn C.verify_copy() @[export: "native_copy"] -fn copy(destination voidptr, source voidptr, count usize) voidptr { +fn copy(destination voidptr, source voidptr, count uint) voidptr { if count != 0 { unsafe { mut dest := &u8(destination) @@ -253,13 +253,13 @@ fn test_fastc_target_native_prototypes_match_exported_write_constness_and_abi() prefs.vroot = @VEXEROOT prefs.target_libc_headers = true source := declaration_abi_generate('target_write', r'module main -fn C.write(fd i32, const_buf voidptr, count usize) isize +fn C.write(fd i32, const_buf voidptr, count uint) C.ptrdiff_t @[export: "write"] -fn kernel_write(fd int, buf voidptr, count usize) isize { +fn kernel_write(fd int, buf voidptr, count uint) int { if fd < 0 { return -7 } if count == 0 { return 0 } ptr := unsafe { &u8(buf) } - return isize(ptr[0]) + isize(count) + return int(ptr[0]) + int(count) } fn main() { mut value := u8(40) @@ -267,7 +267,7 @@ fn main() { assert C.write(1, voidptr(&value), 2) == 42 } ', prefs) - assert source.contains('extern isize write(i32, voidptr, usize);'), source - assert !source.contains('extern isize write(i32, const void*'), source + assert source.contains('extern ptrdiff_t write(i32, voidptr, usize);'), source + assert !source.contains('extern ptrdiff_t write(i32, const void*'), source declaration_abi_run_c('target_write', source) } diff --git a/vlib/v/gen/fastc/expr.v b/vlib/v/gen/fastc/expr.v index 378c62ae0a..d65fe81f81 100644 --- a/vlib/v/gen/fastc/expr.v +++ b/vlib/v/gen/fastc/expr.v @@ -606,7 +606,7 @@ fn fastc_simple_call_scalar_type(typ u32) bool { flat.source_type_f64, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_int, flat.source_type_isize, flat.source_type_rune, flat.source_type_string, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, - flat.source_type_u64, flat.source_type_usize] + flat.source_type_u64, flat.source_type_uint, flat.source_type_usize] } fn (g &Parser) simple_call_argument_is_scalar(tok token.Token, lit string, expected u32) bool { @@ -1560,7 +1560,7 @@ fn (mut g Parser) rewrite_expression_cast(mut result strings.Builder, expression result.go_back(rendered_previous.len + 2) piece = '((${array_type})(' cast_depths << paren_depth + 1 - } else if expression_tokens.len >= 4 && expression_tokens[expression_tokens.len - 4].tok == .name && expression_tokens[expression_tokens.len - 4].lit == 'C' && expression_tokens[expression_tokens.len - 3].tok == .dot && previous_lit.len > 0 && 'C.${previous_lit}' !in g.functions && g.current_call_has_one_argument() && (previous_lit[0].is_capital() || '#Cstruct#${previous_lit}' in g.declared_types) { + } else if expression_tokens.len >= 4 && expression_tokens[expression_tokens.len - 4].tok == .name && expression_tokens[expression_tokens.len - 4].lit == 'C' && expression_tokens[expression_tokens.len - 3].tok == .dot && previous_lit.len > 0 && 'C.${previous_lit}' !in g.functions && g.current_call_has_one_argument() && (previous_lit[0].is_capital() || '#Cstruct#${previous_lit}' in g.declared_types || '#Ctypedef#${previous_lit}' in g.declared_types) { c_pointer_token := if expression_tokens.len >= 5 && fastc_token_is_prefix_operator(expression_tokens, expression_tokens.len - 5) { expression_tokens[expression_tokens.len - 5].tok } else { @@ -2202,8 +2202,8 @@ fn (g &Parser) translated_divisor_is_positive_constant() bool { if tok == .name { // Arbitrary names/calls and constant C expressions are not a proof. // Integer casts are evaluated with their actual narrowing below. - if look.lit !in ['u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'i32', 'i64', 'int', 'usize', - 'isize'] || look.lit in g.locals { + if look.lit !in ['u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'i32', 'i64', 'int', 'uint', + 'usize', 'isize'] || look.lit in g.locals { return false } } diff --git a/vlib/v/gen/fastc/fastc.v b/vlib/v/gen/fastc/fastc.v index 54648b6dda..4d241afe4c 100644 --- a/vlib/v/gen/fastc/fastc.v +++ b/vlib/v/gen/fastc/fastc.v @@ -1182,8 +1182,10 @@ pub struct GenerationResult { pub: c_pieces []string source_paths []string - uses_threads bool - c_flags []string + // Only these files need the frontend pass that locates deprecated type spellings. + deprecated_integer_paths []string + uses_threads bool + c_flags []string // units describes how c_pieces split into translation units that the // drivers can compile in parallel (see fastc_write_c_units). units FastcUnitLayout @@ -1727,8 +1729,13 @@ pub fn generate_files_with_source_paths(paths []string, prefs &pref.Preferences) sources, module_aliases := fastc_resolve_source_files_deferring_memo(entries, &scoped_prefs, mut pending_memo_store)! timer.mark('resolve') mut source_paths := []string{cap: sources.len} + mut deprecated_integer_paths := []string{} for source_file in sources { source_paths << source_file.path + if source_file.header.module_name != 'builtin' + && (source_file.source.contains('isize') || source_file.source.contains('usize')) { + deprecated_integer_paths << source_file.path + } } // The layout comes back through a parameter: a struct of arrays as a // multi-return component is not carried correctly by the self-hosted @@ -1739,11 +1746,12 @@ pub fn generate_files_with_source_paths(paths []string, prefs &pref.Preferences) fastc_wait_memo_store(mut pending_memo_store) timer.mark('generate_total') return GenerationResult{ - c_pieces: c_pieces - source_paths: source_paths - uses_threads: uses_threads - c_flags: c_flags - units: units + c_pieces: c_pieces + source_paths: source_paths + deprecated_integer_paths: deprecated_integer_paths + uses_threads: uses_threads + c_flags: c_flags + units: units } } diff --git a/vlib/v/gen/fastc/fastc_test.v b/vlib/v/gen/fastc/fastc_test.v index 40dad5157c..9d599094c9 100644 --- a/vlib/v/gen/fastc/fastc_test.v +++ b/vlib/v/gen/fastc/fastc_test.v @@ -7127,7 +7127,7 @@ fn test_map_pointer_sized_callbacks_follow_target_width() { source := 'module main fn main() { - values := map[usize]int{} + values := map[uint]int{} pointers := map[voidptr]int{} println(values.len) println(pointers.len) @@ -7136,7 +7136,7 @@ fn main() { c32 := generate(source, 'map_usize_32.v', prefs) or { panic(err) } int32_type := fastc_output_c_type('int') assert int32_type == 'i32' - for key_type in ['usize', 'voidptr'] { + for key_type in ['uint', 'voidptr'] { assert c32.contains('sizeof(${key_type}), sizeof(${int32_type}), &builtin__map_hash_int_4, &builtin__map_eq_int_4, &builtin__map_clone_int_4'), c32 } @@ -7144,7 +7144,7 @@ fn main() { c64 := generate(source, 'map_usize_64.v', prefs) or { panic(err) } int64_type := fastc_output_c_type('int') assert int64_type == 'i64' - for key_type in ['usize', 'voidptr'] { + for key_type in ['uint', 'voidptr'] { assert c64.contains('sizeof(${key_type}), sizeof(${int64_type}), &builtin__map_hash_int_8, &builtin__map_eq_int_8, &builtin__map_clone_int_8'), c64 } @@ -11951,7 +11951,7 @@ fn main() { ', 'selfhost_static_multi_return.v', prefs) or { panic(err) } assert c_source.contains('i64 number = (i64){0}'), c_source assert c_source.contains('string text = (string){0}'), c_source - assert !c_source.contains('usize number'), c_source + assert !c_source.contains('uint number'), c_source } fn test_selfhost_explicit_embed_method_call() { diff --git a/vlib/v/gen/fastc/file_scope.v b/vlib/v/gen/fastc/file_scope.v index 8eef428090..97e4039a9f 100644 --- a/vlib/v/gen/fastc/file_scope.v +++ b/vlib/v/gen/fastc/file_scope.v @@ -2,7 +2,7 @@ module fastc // Each worker reuses a bounded parser arena. Only published output survives // a file: all parser maps, tokens, and intermediate renderings are disposable. -const fastc_file_arena_keep_bytes = isize(8) * 1024 * 1024 +const fastc_file_arena_keep_bytes = int(8) * 1024 * 1024 struct FastcFileScratch { mut: diff --git a/vlib/v/gen/fastc/fn.v b/vlib/v/gen/fastc/fn.v index f1f2ed1397..4474b4f06d 100644 --- a/vlib/v/gen/fastc/fn.v +++ b/vlib/v/gen/fastc/fn.v @@ -1331,6 +1331,9 @@ fn fastc_method_c_name(module_name string, receiver_type string, name string) st // the element type (`Any`) and its method C name collides with the element type's own // method (`json2__Any_str` defined for both `Any` and `[]Any` → C redefinition). mut receiver_base := receiver_type.trim_right('*') + if receiver_base == 'usize' { + receiver_base = 'uint' + } mut composite_prefix := '' for { if receiver_base.starts_with('Array_') { @@ -1666,7 +1669,7 @@ fn (mut g Parser) parse_multi_return_types() !([]u32, []bool) { // spelling equals the V spelling for each of these, so it doubles as the smart- // cast type in a `match` branch. const fastc_boxed_primitive_types = ['int', 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', - 'f32', 'f64', 'bool', 'rune', 'isize', 'usize', 'char', 'voidptr'] + 'f32', 'f64', 'bool', 'rune', 'isize', 'uint', 'usize', 'char', 'voidptr'] // fastc_output_c_type maps a semantic FastC type string to the C spelling that // is physically written into a declaration or cast. Only the platform-width @@ -1675,6 +1678,9 @@ const fastc_boxed_primitive_types = ['int', 'i8', 'i16', 'i32', 'i64', 'u8', 'u1 // `int` and `i64` keep distinct methods). Pointer suffixes are preserved. fn fastc_output_c_type(t string) string { base := t.trim_right('*') + if base == 'uint' { + return 'usize' + t[base.len..] + } if base == 'int' { return fastc_platform_int_c_type + t[base.len..] } @@ -1701,7 +1707,7 @@ fn fastc_primitive_c_type(raw_type string) ?string { 'u16' { 'u16' } 'u32' { 'u32' } 'u64' { 'u64' } - 'uint' { 'unsigned int' } + 'uint' { 'usize' } 'usize' { 'usize' } 'voidptr' { 'voidptr' } 'byteptr' { 'byteptr' } diff --git a/vlib/v/gen/fastc/generic_atomic_test.v b/vlib/v/gen/fastc/generic_atomic_test.v index fed7841f77..d96e428788 100644 --- a/vlib/v/gen/fastc/generic_atomic_test.v +++ b/vlib/v/gen/fastc/generic_atomic_test.v @@ -117,7 +117,7 @@ fn cas[T](mut here T, _ifthis T, writethis T) bool { fn selected_width[T](value T) int { $if T is bool { return 1 } $else $if T is u32 || T is i32 { return 4 } - $else $if T is u64 || T is i64 || T is usize || T is int { return 8 } + $else $if T is u64 || T is i64 || T is uint || T is int { return 8 } $else { return sizeof(T) } } @@ -139,7 +139,7 @@ fn bts[T](mut var T, bit u8) bool { $if T is u32 || T is i32 || T is int { old := C.vinix_ldset32(voidptr(var), u32(mask)) return old & u32(mask) != 0 - } $else $if T is u64 || T is i64 || T is usize || T is isize || T is voidptr { + } $else $if T is u64 || T is i64 || T is uint || T is int || T is voidptr { old := C.vinix_ldset64(voidptr(var), u64(mask)) return old & u64(mask) != 0 } $else { $compile_error("unsupported bit-set width") } @@ -205,31 +205,31 @@ fn main() { first := &Thread{value: 17} second := &Thread{value: 18} assert cas[&Thread](mut &state.slot, unsafe { nil }, first) - assert usize(state.slot) == usize(first) + assert uint(state.slot) == uint(first) assert !cas(mut &state.slot, unsafe { nil }, second) - assert usize(state.slot) == usize(first) + assert uint(state.slot) == uint(first) assert cas(mut &state.slot, first, second) - assert usize(state.slot) == usize(second) + assert uint(state.slot) == uint(second) assert state.guard == 0x123456789abcdef0 mut pointer := first // Explicit T selects pointer-slot mutation; an inferred bare mut pointer // refers to its pointee under the ordinary V generic inference rules. assert cas[&Thread](mut pointer, first, second) - assert usize(pointer) == usize(second) + assert uint(pointer) == uint(second) assert forwarded_cas[&Thread](mut pointer, second, first) - assert usize(pointer) == usize(first) + assert uint(pointer) == uint(first) mut other := second mut slot := &pointer assert cas[&&Thread](mut &slot, &pointer, &other) - assert usize(slot) == usize(&other) - assert usize(identity(second)) == usize(second) - assert usize(forwarded_identity[&Thread](mut pointer)) == usize(pointer) + assert uint(slot) == uint(&other) + assert uint(identity(second)) == uint(second) + assert uint(forwarded_identity[&Thread](mut pointer)) == uint(pointer) copied_thread := forwarded_identity(mut pointer) assert sizeof(copied_thread) == sizeof(Thread) assert copied_thread.value == 17 assert copied_thread.guard == 0 assert forwarded_identity[int](mut state.integer) == wide - assert usize(forwarded_read[&Thread](mut pointer)) == usize(pointer) + assert uint(forwarded_read[&Thread](mut pointer)) == uint(pointer) assert forwarded_read[int](mut state.integer) == wide assert read_pointer_value[&Thread](mut pointer) == 17 assert first.value == 17 @@ -245,8 +245,8 @@ fn main() { mut copied_entry := entry assert !bts(mut copied_entry, u8(55)) assert bits == (u64(1) << 10) | (u64(1) << 55) - assert usize(entry) == usize(&bits) - assert usize(copied_entry) == usize(&bits) + assert uint(entry) == uint(&bits) + assert uint(copied_entry) == uint(&bits) assert !bts(mut &state.pending_signals, u8(55)) assert state.pending_signals == u64(1) << 55 assert bts(mut &state.pending_signals, u8(55)) diff --git a/vlib/v/gen/fastc/generic_multi_return_call_test.v b/vlib/v/gen/fastc/generic_multi_return_call_test.v index 3b7737cfbb..1bacc1d016 100644 --- a/vlib/v/gen/fastc/generic_multi_return_call_test.v +++ b/vlib/v/gen/fastc/generic_multi_return_call_test.v @@ -68,7 +68,7 @@ fn main() { // The locals of `a, b := mod.f[T](x)`, an explicit generic call into another module, are // declared as the specialized function's return types. FastC used to find no types for the -// call, which keeps its type arguments, and declared every local as `usize`. +// call, which keeps its type arguments, and declared every local as `uint`. fn test_fastc_explicit_generic_multi_return_call_declares_component_types() { $if !macos && !linux { return diff --git a/vlib/v/gen/fastc/generic_sizeof_test.v b/vlib/v/gen/fastc/generic_sizeof_test.v index eaca7de92d..3e57e961dc 100644 --- a/vlib/v/gen/fastc/generic_sizeof_test.v +++ b/vlib/v/gen/fastc/generic_sizeof_test.v @@ -10,8 +10,8 @@ fn test_fastc_unbound_generic_sizeof_uses_the_existing_diagnostic_body() { // A source without main retains every definition, so this checks the actual // erased body rather than relying on dead-code elimination to hide it. source := generate(r'module main -fn element_bytes[T](values []T) usize { return sizeof(T) } -fn nested_bytes[T](values []T) usize { return 2 * sizeof([3]&T) } +fn element_bytes[T](values []T) uint { return sizeof(T) } +fn nested_bytes[T](values []T) uint { return 2 * sizeof([3]&T) } ', 'unbound_generic_sizeof.v', prefs) or { panic(err) } assert !source.contains('sizeof(T)'), source assert !source.contains('sizeof([3]&T)'), source diff --git a/vlib/v/gen/fastc/global_assignment_test.v b/vlib/v/gen/fastc/global_assignment_test.v index 661920fea4..e0fd34f0af 100644 --- a/vlib/v/gen/fastc/global_assignment_test.v +++ b/vlib/v/gen/fastc/global_assignment_test.v @@ -35,8 +35,8 @@ struct Values { mut: items [2]u64 } -fn C.memcpy(voidptr, voidptr, usize) voidptr -fn C.memset(voidptr, int, usize) voidptr +fn C.memcpy(voidptr, voidptr, uint) voidptr +fn C.memset(voidptr, int, uint) voidptr fn main() { enabled = true count = int(1) << 40 @@ -51,9 +51,9 @@ fn main() { slots = [u64(1) << 55, u64(9)]! assert slots[0] == u64(1) << 55 && slots[1] == 9 mut state := Values{} - C.memcpy(state.items, slots, usize(16)) + C.memcpy(state.items, slots, uint(16)) assert state.items[0] == u64(1) << 55 && state.items[1] == 9 - C.memset(state.items, 0, usize(16)) + C.memset(state.items, 0, uint(16)) assert state.items[0] == 0 && state.items[1] == 0 slots = [2]u64{} assert slots[0] == 0 && slots[1] == 0 diff --git a/vlib/v/gen/fastc/loom2v_test.v b/vlib/v/gen/fastc/loom2v_test.v index 373952406a..5a094b3da4 100644 --- a/vlib/v/gen/fastc/loom2v_test.v +++ b/vlib/v/gen/fastc/loom2v_test.v @@ -139,9 +139,9 @@ fn main() { index := 1 minimum := [u32(0x80), 0x800, 0x10000][index] assert minimum == u32(0x800) - address := usize(0x12345) + address := uint(0x12345) unsafe { - assert usize(voidptr(address)) == address + assert uint(voidptr(address)) == address } assert "${u8(0):02x}" == "00" assert "${u8(255):02x}" == "ff" diff --git a/vlib/v/gen/fastc/macho_sign_darwin.c.v b/vlib/v/gen/fastc/macho_sign_darwin.c.v index 917fcbd8eb..d5278e52a9 100644 --- a/vlib/v/gen/fastc/macho_sign_darwin.c.v +++ b/vlib/v/gen/fastc/macho_sign_darwin.c.v @@ -16,7 +16,7 @@ fn fastc_sign_macho_adhoc_mapped(path string) ! { return error('`${path}`: could not extend the Mach-O file for signing') } mapped := unsafe { - C.mmap(nil, usize(capacity), C.PROT_READ | C.PROT_WRITE, C.MAP_PRIVATE, out.fd, 0) + C.mmap(nil, uint(capacity), C.PROT_READ | C.PROT_WRITE, C.MAP_PRIVATE, out.fd, 0) } if mapped == voidptr(-1) { _ = C.ftruncate(i32(out.fd), u64(original_len)) @@ -25,14 +25,14 @@ fn fastc_sign_macho_adhoc_mapped(path string) ! { } mut file := unsafe { mapped.vbytes(capacity) } patch := fastc_patch_macho_signature(mut file, original_len, path) or { - unsafe { C.munmap(mapped, usize(capacity)) } + unsafe { C.munmap(mapped, uint(capacity)) } _ = C.ftruncate(i32(out.fd), u64(original_len)) out.close() return err } load_commands := file[..patch.load_end].clone() tail := file[patch.tail_start..patch.final_len].clone() - if unsafe { C.munmap(mapped, usize(capacity)) } != 0 { + if unsafe { C.munmap(mapped, uint(capacity)) } != 0 { out.close() return error('`${path}`: could not release the mapped Mach-O image') } diff --git a/vlib/v/gen/fastc/native_flags_test.v b/vlib/v/gen/fastc/native_flags_test.v index b054dae10d..cb289f3a6f 100644 --- a/vlib/v/gen/fastc/native_flags_test.v +++ b/vlib/v/gen/fastc/native_flags_test.v @@ -110,10 +110,10 @@ fn test_fastc_prealloc_arena_is_separate_for_worker_threads() { os.rmdir_all(root) or {} } os.write_file(os.join_path(root, 'main.v'), r'module main -fn arena_root() usize { +fn arena_root() uint { values := []int{len: 64} assert values.len == 64 - return usize(g_memory_block) + return uint(g_memory_block) } fn main() { diff --git a/vlib/v/gen/fastc/platform_uint_test.v b/vlib/v/gen/fastc/platform_uint_test.v new file mode 100644 index 0000000000..7a7479809a --- /dev/null +++ b/vlib/v/gen/fastc/platform_uint_test.v @@ -0,0 +1,88 @@ +module fastc + +import os +import v.cmdexec + +fn test_uint_preserves_platform_width_in_casts_interpolation_maps_and_boxes() { + $if !macos && !linux { + return + } + root := os.join_path(os.vtmp_dir(), 'fastc_platform_uint_${os.getpid()}') + os.mkdir_all(root) or { panic(err) } + defer { os.rmdir_all(root) or {} } + os.write_file(os.join_path(root, 'main.v'), 'module main + +type Number = uint | string + +fn identity(x uint) uint { return x } + +fn unbox(x Number) uint { + match x { + uint { return x } + string { return 0 } + } +} + +fn main() { + assert sizeof(uint) == sizeof(voidptr) + maximum := ~uint(0) + assert maximum >> (sizeof(uint) * 8 - 1) == 1 + assert maximum + uint(1) == 0 + assert identity(maximum) == maximum + assert unbox(Number(maximum)) == maximum + mut m := map[uint]int{} + m[maximum] = 17 + assert m[maximum] == 17 + $if x64 || arm64 { + assert maximum.str() == "18446744073709551615" + assert "\${maximum:x}" == "ffffffffffffffff" + assert uint(1) << 40 == u64(1099511627776) + } $else { + assert maximum.str() == "4294967295" + assert "\${maximum:x}" == "ffffffff" + } + println("ok") +} +') or { panic(err) } + program := os.join_path(root, 'program') + built := cmdexec.run(@VEXE, ['-b', 'fastc', '-o', program, root]) + assert built.exit_code == 0, built.output + run := cmdexec.run(program, []) + assert run.exit_code == 0, run.output + assert run.output.trim_space() == 'ok', run.output +} + +fn test_legacy_unsigned_sum_type_uses_the_same_tag_as_uint() { + $if !macos && !linux { + return + } + root := os.join_path(os.vtmp_dir(), 'fastc_legacy_uint_${os.getpid()}') + os.mkdir_all(root) or { panic(err) } + defer { os.rmdir_all(root) or {} } + os.write_file(os.join_path(root, 'main.v'), 'module main +type Value = usize | string +fn is_numeric(value Value) bool { + return match value { usize { true } else { false } } +} +fn unbox(value Value) uint { + match value { usize { return value } else { return 0 } } +} +fn main() { + value := Value(usize(42)) + assert is_numeric(value) + assert unbox(value) == 42 + assert value is usize + assert value is uint + assert !(value is string) + assert (value as usize) == 42 + assert (value as uint) == 42 + assert is_numeric(Value(uint(123))) + assert !is_numeric(Value("text")) +} +') or { panic(err) } + program := os.join_path(root, 'program') + built := cmdexec.run(@VEXE, ['-b', 'fastc', '-o', program, root]) + assert built.exit_code == 0, built.output + ran := cmdexec.run(program, []) + assert ran.exit_code == 0, ran.output +} diff --git a/vlib/v/gen/fastc/pointer_cast_bits_test.v b/vlib/v/gen/fastc/pointer_cast_bits_test.v index 74f41ba9ab..f87be2af1f 100644 --- a/vlib/v/gen/fastc/pointer_cast_bits_test.v +++ b/vlib/v/gen/fastc/pointer_cast_bits_test.v @@ -28,13 +28,13 @@ struct Holder { pointer &u64 } fn C.sentinel_pointer() voidptr fn C.pointer_bits(pointer voidptr) u64 fn pointer_integer(pointer &u64) u64 { return unsafe { u64(pointer) } } -fn pointer_size(pointer &u64) usize { return unsafe { usize(pointer) } } +fn pointer_size(pointer &u64) uint { return unsafe { uint(pointer) } } fn pointer_alias_integer(pointer WordRef) Address { return unsafe { Address(pointer) } } fn pointer_alias_opaque(pointer WordRef) Opaque { return unsafe { Opaque(pointer) } } fn native_alias_pointer() BlockRef { return unsafe { BlockRef(C.sentinel_pointer()) } } fn returned_pointer() &u64 { return unsafe { &u64(C.sentinel_pointer()) } } fn borrowed_scalar[T](mut value T) u64 { return unsafe { u64(value) } } -fn borrowed_size[T](mut value T) usize { return unsafe { usize(value) } } +fn borrowed_size[T](mut value T) uint { return unsafe { uint(value) } } fn borrowed_opaque[T](mut value T) voidptr { return unsafe { voidptr(value) } } fn borrowed_scalar_pointer[T](mut value T) &u8 { return unsafe { &u8(value) } } fn borrowed_scalar_value[T](mut value T) u64 { return unsafe { u64(*value) } } @@ -49,7 +49,7 @@ fn main() { pointer := returned_pointer() expected := C.pointer_bits(C.sentinel_pointer()) assert pointer_integer(pointer) == expected - assert pointer_size(pointer) == usize(expected) + assert pointer_size(pointer) == uint(expected) assert pointer_alias_integer(WordRef(pointer)) == Address(expected) assert C.pointer_bits(pointer_alias_opaque(WordRef(pointer))) == expected assert C.pointer_bits(native_alias_pointer()) == expected @@ -61,7 +61,7 @@ fn main() { mut value := u64(73) value_address := C.pointer_bits(voidptr(&value)) assert borrowed_scalar(mut value) == value_address - assert borrowed_size(mut value) == usize(value_address) + assert borrowed_size(mut value) == uint(value_address) assert C.pointer_bits(borrowed_opaque(mut value)) == value_address assert C.pointer_bits(borrowed_scalar_pointer(mut value)) == value_address assert borrowed_scalar_value(mut value) == 73 diff --git a/vlib/v/gen/fastc/power.v b/vlib/v/gen/fastc/power.v index 2f625209a4..66ece02644 100644 --- a/vlib/v/gen/fastc/power.v +++ b/vlib/v/gen/fastc/power.v @@ -383,7 +383,7 @@ fn fastc_integer_promotion_index(typ u32) int { 'u16' { 12 } 'u32' { 13 } 'u64' { 14 } - 'usize' { 15 } + 'uint', 'usize' { 15 } 'rune' { 22 } else { -1 } } diff --git a/vlib/v/gen/fastc/primitive_binary_test.v b/vlib/v/gen/fastc/primitive_binary_test.v index b50ff73e1f..395877dc48 100644 --- a/vlib/v/gen/fastc/primitive_binary_test.v +++ b/vlib/v/gen/fastc/primitive_binary_test.v @@ -79,7 +79,7 @@ fn test_fastc_plain_numeric_binary_guard_keeps_non_arithmetic_and_represented_va fn test_fastc_plain_numeric_binary_guard_respects_program_metadata_and_translated_files() { assert fastc_numeric_arithmetic_has_no_overloads(map[string]FastcFunctionSignature{}, flat.TypeTextBindings{}, flat.TypeTextBindings{}, map[string]flat.TypeTextBindings{}) - for name in ['int.+', 'u64.-', 'f32.*', 'usize./', 'u8.%'] { + for name in ['int.+', 'u64.-', 'f32.*', 'uint./', 'u8.%'] { assert !fastc_numeric_arithmetic_has_no_overloads({ name: FastcFunctionSignature{} }, flat.TypeTextBindings{}, flat.TypeTextBindings{}, map[string]flat.TypeTextBindings{}) diff --git a/vlib/v/gen/fastc/primitive_type_masks.v b/vlib/v/gen/fastc/primitive_type_masks.v index 7e2cf49208..cbeb4aa82f 100644 --- a/vlib/v/gen/fastc/primitive_type_masks.v +++ b/vlib/v/gen/fastc/primitive_type_masks.v @@ -50,6 +50,7 @@ const fastc_scalar_type_mask = fastc_primitive_type_mask([ flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, + flat.source_type_uint, flat.source_type_usize, ]) @@ -65,6 +66,7 @@ const fastc_comparison_type_mask = fastc_primitive_type_mask([ flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, + flat.source_type_uint, flat.source_type_usize, flat.source_type_f32, flat.source_type_f64, @@ -81,6 +83,7 @@ const fastc_arithmetic_type_mask = fastc_primitive_type_mask([ flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, + flat.source_type_uint, flat.source_type_usize, flat.source_type_f32, flat.source_type_f64, @@ -100,6 +103,7 @@ const fastc_integer_type_mask = fastc_primitive_type_mask([ flat.source_type_u32, flat.source_type_u64, fastc_type_unsigned_int, + flat.source_type_uint, flat.source_type_usize, ]) @@ -109,6 +113,7 @@ const fastc_unsigned_integer_type_mask = fastc_primitive_type_mask([ flat.source_type_u32, flat.source_type_u64, fastc_type_unsigned_int, + flat.source_type_uint, flat.source_type_usize, ]) @@ -116,6 +121,7 @@ const fastc_wide_unsigned_integer_type_mask = fastc_primitive_type_mask([ flat.source_type_u32, flat.source_type_u64, fastc_type_unsigned_int, + flat.source_type_uint, flat.source_type_usize, ]) @@ -135,6 +141,6 @@ fn fastc_plain_arithmetic_value_type(typ u32) bool { if fastc_arithmetic_type_mask.enabled { return fastc_arithmetic_type_mask.contains(typ) } return typ in [flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_isize, flat.source_type_u8, - flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, flat.source_type_usize, - flat.source_type_f32, flat.source_type_f64] + flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, flat.source_type_uint, + flat.source_type_usize, flat.source_type_f32, flat.source_type_f64] } diff --git a/vlib/v/gen/fastc/primitive_type_masks_test.v b/vlib/v/gen/fastc/primitive_type_masks_test.v index b9a909fbb5..2361857329 100644 --- a/vlib/v/gen/fastc/primitive_type_masks_test.v +++ b/vlib/v/gen/fastc/primitive_type_masks_test.v @@ -62,26 +62,26 @@ fn test_fastc_primitive_masks_leave_caller_identity_arrays_unchanged() { assert !mask.contains(4) } -fn test_fastc_primitive_classifiers_match_the_original_exact_source_id_sets() { +fn test_fastc_primitive_classifiers_match_the_supported_source_id_sets() { scalar := [flat.source_type_bool, flat.source_type_char, flat.source_type_f32, flat.source_type_f64, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_int, flat.source_type_isize, flat.source_type_rune, flat.source_type_string, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, - flat.source_type_u64, flat.source_type_usize] + flat.source_type_u64, flat.source_type_uint, flat.source_type_usize] comparison := [flat.source_type_bool, flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_isize, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, - flat.source_type_usize, flat.source_type_f32, flat.source_type_f64] + flat.source_type_uint, flat.source_type_usize, flat.source_type_f32, flat.source_type_f64] arithmetic := [flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_isize, flat.source_type_u8, - flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, flat.source_type_usize, - flat.source_type_f32, flat.source_type_f64] + flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, flat.source_type_uint, + flat.source_type_usize, flat.source_type_f32, flat.source_type_f64] signed := [flat.source_type_char, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_int, flat.source_type_isize, flat.source_type_rune] unsigned := [flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, - fastc_type_unsigned_int, flat.source_type_usize] + fastc_type_unsigned_int, flat.source_type_uint, flat.source_type_usize] wide := [flat.source_type_u32, flat.source_type_u64, fastc_type_unsigned_int, - flat.source_type_usize] + flat.source_type_uint, flat.source_type_usize] mut integer := signed.clone() integer << unsigned for item in [ diff --git a/vlib/v/gen/fastc/raw_direct_member_test.v b/vlib/v/gen/fastc/raw_direct_member_test.v index e22d998632..a0ba576a79 100644 --- a/vlib/v/gen/fastc/raw_direct_member_test.v +++ b/vlib/v/gen/fastc/raw_direct_member_test.v @@ -303,7 +303,7 @@ fn (g &Parser) raw_direct_member29_legacy(tokens []FastcExpressionToken) ?string } else { fastc_primitive_c_type(item.lit) or { '' } } - is_c_cast := i >= 2 && tokens[i - 2].tok == .name && tokens[i - 2].lit == 'C' && tokens[i - 1].tok == .dot && item.lit.len > 0 && 'C.${item.lit}' !in g.functions && fastc_call_has_one_argument(tokens, i + 1) && (item.lit[0].is_capital() || '#Cstruct#${item.lit}' in g.declared_types) + is_c_cast := i >= 2 && tokens[i - 2].tok == .name && tokens[i - 2].lit == 'C' && tokens[i - 1].tok == .dot && item.lit.len > 0 && 'C.${item.lit}' !in g.functions && fastc_call_has_one_argument(tokens, i + 1) && (item.lit[0].is_capital() || '#Cstruct#${item.lit}' in g.declared_types || '#Ctypedef#${item.lit}' in g.declared_types) if is_c_cast { cast_type = if '#Cstruct#${item.lit}' in g.declared_types { 'struct ${item.lit}' diff --git a/vlib/v/gen/fastc/render.v b/vlib/v/gen/fastc/render.v index 7a96b061a8..f2fcc263eb 100644 --- a/vlib/v/gen/fastc/render.v +++ b/vlib/v/gen/fastc/render.v @@ -22,7 +22,7 @@ fn fastc_builtin_type_idx(type_name_source_id u32) ?int { 'u16' { 12 } 'u32' { 13 } 'u64' { 14 } - 'usize' { 15 } + 'uint', 'usize' { 15 } 'f32' { 16 } 'f64' { 17 } 'char' { 18 } @@ -1488,7 +1488,7 @@ fn (g &Parser) checked_integer_operation_type(operand_type u32) string { resolved := flat.source_type_name(g.underlying_alias_type(operand_type)) return match resolved { 'int', 'integer literal', 'negative integer literal' { fastc_output_c_type('int') } - 'char', 'i8', 'u8', 'i16', 'u16', 'i32', 'u32', 'i64', 'u64', 'isize', 'usize' { + 'char', 'i8', 'u8', 'i16', 'u16', 'i32', 'u32', 'i64', 'u64', 'isize', 'uint', 'usize' { fastc_output_c_type(resolved) } 'rune' { 'u32' } @@ -1546,7 +1546,7 @@ fn (g &Parser) shift_type_parts(operand_type u32) ?(string, string) { 'i32', 'rune', 'u32', 'unsigned int' { 'u32', '32' } 'i64', 'u64' { 'u64', '64' } 'int' { 'u${g.prefs.target.pointer_bits}', '${g.prefs.target.pointer_bits}' } - 'isize', 'usize' { 'usize', '${g.prefs.target.pointer_bits}' } + 'isize', 'uint', 'usize' { 'usize', '${g.prefs.target.pointer_bits}' } else { return none } @@ -1882,8 +1882,8 @@ fn (g &Parser) narrowed_numeric_operand_type(tokens []FastcExpressionToken, infe // fastc_numeric_arithmetic_has_no_overloads is shared by every file generator. // Ambiguous primitive metadata disables the shortcut conservatively. fn fastc_numeric_arithmetic_has_no_overloads(functions map[string]FastcFunctionSignature, declared_type_c_names flat.TypeTextBindings, alias_base_types flat.TypeTextBindings, struct_fields map[string]flat.TypeTextBindings) bool { - for type_name in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'u8', 'u16', 'u32', 'u64', 'usize', - 'f32', 'f64'] { + for type_name in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'u8', 'u16', 'u32', 'u64', 'uint', + 'usize', 'f32', 'f64'] { if declared_type_c_names.contains(type_name) || alias_base_types.contains(type_name) || type_name in struct_fields { return false @@ -1975,7 +1975,7 @@ fn (g &Parser) plain_numeric_arithmetic_expression(tokens []FastcExpressionToken // generation. Primitive metadata or comparison methods keep the full renderer. fn fastc_primitive_comparisons_have_no_overloads(functions map[string]FastcFunctionSignature, declared_type_c_names flat.TypeTextBindings, alias_base_types flat.TypeTextBindings, struct_fields map[string]flat.TypeTextBindings) bool { for type_name in ['bool', 'int', 'i8', 'i16', 'i32', 'i64', 'isize', 'u8', 'u16', 'u32', 'u64', - 'usize', 'f32', 'f64'] { + 'uint', 'usize', 'f32', 'f64'] { if declared_type_c_names.contains(type_name) || alias_base_types.contains(type_name) || type_name in struct_fields { return false @@ -2082,7 +2082,7 @@ fn fastc_primitive_member_comparison_value_type(typ u32) bool { return typ in [flat.source_type_bool, flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_isize, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, - flat.source_type_usize, flat.source_type_f32, flat.source_type_f64] + flat.source_type_uint, flat.source_type_usize, flat.source_type_f32, flat.source_type_f64] } fn (g &Parser) primitive_member_comparison_operand_type(tokens []FastcExpressionToken) u32 { @@ -5547,7 +5547,7 @@ fn fastc_map_runtime_functions(key_type_source_id u32, pointer_bits int) (string '8' } else if key_type in ['i128', 'u128'] { '16' - } else if key_type in ['isize', 'usize'] || fastc_is_pointer_type(key_type_source_id) { + } else if key_type in ['isize', 'uint', 'usize'] || fastc_is_pointer_type(key_type_source_id) { if pointer_bits == 32 { '4' } else { '8' } } else { '4' diff --git a/vlib/v/gen/fastc/review_regressions_test.v b/vlib/v/gen/fastc/review_regressions_test.v index 2ac4d83483..fa111929c3 100644 --- a/vlib/v/gen/fastc/review_regressions_test.v +++ b/vlib/v/gen/fastc/review_regressions_test.v @@ -47,12 +47,12 @@ fn main() { mut value := Value(pointer) if value !is voidptr { return } println(isnil(value)) - println(usize(value)) + println(uint(value)) mut alternate := Value(pointer) if alternate !is voidptr { assert false } else { - println(usize(alternate)) + println(uint(alternate)) alternate = Value(13) } println(read(alternate)) @@ -62,7 +62,7 @@ fn main() { address := voidptr(&number) mut nonnil := Value(address) if nonnil !is voidptr { return } - assert usize(nonnil) == usize(address) + assert uint(nonnil) == uint(address) println("identity") mut scalar := Value(9) if scalar !is int { return } diff --git a/vlib/v/gen/fastc/scan.c.v b/vlib/v/gen/fastc/scan.c.v index a598d93006..f9e2943386 100644 --- a/vlib/v/gen/fastc/scan.c.v +++ b/vlib/v/gen/fastc/scan.c.v @@ -8,7 +8,7 @@ fn fastc_next_underscore(text string, start int, end int) int { return end } unsafe { - found := C.memchr(text.str + start, `_`, usize(end - start)) + found := C.memchr(text.str + start, `_`, uint(end - start)) if found == voidptr(0) { return end } diff --git a/vlib/v/gen/fastc/signatures.v b/vlib/v/gen/fastc/signatures.v index 465cd0f13b..4da5394032 100644 --- a/vlib/v/gen/fastc/signatures.v +++ b/vlib/v/gen/fastc/signatures.v @@ -1870,7 +1870,7 @@ fn fastc_fixed_length_atom(tokens []FastcExpressionToken, start int, module_name return error('fastc parser does not support fixed array dimension token `${item.tok.str()}`') } if start + 1 < tokens.len && tokens[start + 1].tok == .lpar { - if item.lit !in ['int', 'u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'i32', 'i64', 'usize', + if item.lit !in ['int', 'u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'i32', 'i64', 'uint', 'usize', 'isize'] { return error('fastc parser does not support function call in fixed array dimension') } diff --git a/vlib/v/gen/fastc/stmt.v b/vlib/v/gen/fastc/stmt.v index 230f5de1e0..47b4f90107 100644 --- a/vlib/v/gen/fastc/stmt.v +++ b/vlib/v/gen/fastc/stmt.v @@ -2239,7 +2239,7 @@ fn (mut g Parser) parse_parallel_assignment(initial_names []string, initial_mut component_type := if i < component_types.len { flat.source_type_name(component_types[i]) } else { - 'usize' + 'uint', 'usize' } c_name := fastc_c_identifier(name) c_type := fastc_output_c_type(component_type) diff --git a/vlib/v/gen/fastc/target_option_allocator_test.v b/vlib/v/gen/fastc/target_option_allocator_test.v index 78429f572c..9c0664d7bd 100644 --- a/vlib/v/gen/fastc/target_option_allocator_test.v +++ b/vlib/v/gen/fastc/target_option_allocator_test.v @@ -19,7 +19,7 @@ mut: value u64 } type BlockRef = &Block -type Choose = fn (usize) ?BlockRef +type Choose = fn (uint) ?BlockRef struct Large { a u64 b u64 @@ -45,13 +45,13 @@ fn (mut counter Counter) next() ?u64 { enum Mode { ready } fn C.enter_allocator() fn C.leave_allocator() -fn C.next_block(size usize) voidptr +fn C.next_block(size uint) voidptr fn C.allocation_count() i64 fn C.next_wide() u64 fn C.wide_calls() i64 fn C.native_option_copy() int fn C._vinit(argc int, argv voidptr) -fn choose(size usize) ?BlockRef { +fn choose(size uint) ?BlockRef { if size > 4096 { return none } return unsafe { BlockRef(C.next_block(size)) } } @@ -59,7 +59,7 @@ fn optional_copy(value ?BlockRef) ?BlockRef { return value } fn result_copy(value BlockRef) !BlockRef { return value } fn result_forward(value BlockRef) !BlockRef { return result_copy(value)! } @[export: "test_allocator"] -fn allocator(size usize) voidptr { +fn allocator(size uint) voidptr { C.enter_allocator() callback := Choose(choose) selected := callback(size) diff --git a/vlib/v/gen/fastc/types.v b/vlib/v/gen/fastc/types.v index a6068aaf33..9eaf914468 100644 --- a/vlib/v/gen/fastc/types.v +++ b/vlib/v/gen/fastc/types.v @@ -800,7 +800,7 @@ fn (g &Parser) infer_expression_type_range_impl(tokens []FastcExpressionToken, e if '#Cstruct#${name}' in g.declared_types { return flat.source_type_id('struct ${name}') } - if name.len > 0 && name[0].is_capital() { + if name.len > 0 && (name[0].is_capital() || '#Ctypedef#${name}' in g.declared_types) { return flat.source_type_id(name) } } @@ -1558,6 +1558,8 @@ fn (g &Parser) semantic_type_key(c_type_id u32) u32 { fn (g &Parser) semantic_type_key_uncached(c_type_id u32) u32 { c_type := flat.source_type_name(c_type_id) base := fastc_trim_pointer_suffix(c_type) + // The C ABI keeps the old typedef, while methods use the canonical V name. + if base == 'usize' { return flat.source_type_uint } if key := g.declared_type_c_names.type_id(base) { return key } @@ -1844,7 +1846,7 @@ fn (g &Parser) array_element_type(typ_id u32) ?u32 { @[inline] fn fastc_is_integer_type(typ u32) bool { if fastc_integer_type_mask.enabled { return fastc_integer_type_mask.contains(typ) } - return typ == flat.source_type_char || typ == flat.source_type_i8 || typ == flat.source_type_i16 || typ == flat.source_type_i32 || typ == flat.source_type_i64 || typ == flat.source_type_int || typ == flat.source_type_isize || typ == flat.source_type_rune || typ == flat.source_type_u8 || typ == flat.source_type_u16 || typ == flat.source_type_u32 || typ == flat.source_type_u64 || typ == fastc_type_unsigned_int || typ == flat.source_type_usize + return typ == flat.source_type_char || typ == flat.source_type_i8 || typ == flat.source_type_i16 || typ == flat.source_type_i32 || typ == flat.source_type_i64 || typ == flat.source_type_int || typ == flat.source_type_isize || typ == flat.source_type_rune || typ == flat.source_type_u8 || typ == flat.source_type_u16 || typ == flat.source_type_u32 || typ == flat.source_type_u64 || typ == fastc_type_unsigned_int || typ == flat.source_type_uint || typ == flat.source_type_usize } @[inline] @@ -1852,7 +1854,7 @@ fn fastc_is_unsigned_integer_type(typ u32) bool { if fastc_unsigned_integer_type_mask.enabled { return fastc_unsigned_integer_type_mask.contains(typ) } - return typ == flat.source_type_u8 || typ == flat.source_type_u16 || typ == flat.source_type_u32 || typ == flat.source_type_u64 || typ == fastc_type_unsigned_int || typ == flat.source_type_usize + return typ == flat.source_type_u8 || typ == flat.source_type_u16 || typ == flat.source_type_u32 || typ == flat.source_type_u64 || typ == fastc_type_unsigned_int || typ == flat.source_type_uint || typ == flat.source_type_usize } @[inline] @@ -1860,7 +1862,7 @@ fn fastc_is_wide_unsigned_integer_type(typ u32) bool { if fastc_wide_unsigned_integer_type_mask.enabled { return fastc_wide_unsigned_integer_type_mask.contains(typ) } - return typ == flat.source_type_u32 || typ == flat.source_type_u64 || typ == fastc_type_unsigned_int || typ == flat.source_type_usize + return typ == flat.source_type_u32 || typ == flat.source_type_u64 || typ == fastc_type_unsigned_int || typ == flat.source_type_uint || typ == flat.source_type_usize } @[inline] diff --git a/vlib/v/gen/fastc/unit_compile_nix.c.v b/vlib/v/gen/fastc/unit_compile_nix.c.v index 53bc69e395..bf7632772a 100644 --- a/vlib/v/gen/fastc/unit_compile_nix.c.v +++ b/vlib/v/gen/fastc/unit_compile_nix.c.v @@ -10,7 +10,7 @@ fn C.v_os_exec_capture_start(argv &&char, child_pid &int, read_fd &int) int fn C.v_os_exec_capture_input_start(argv &&char, child_pid &int, read_fd &int, write_fd &int) int -fn C.v_os_fd_write_all(fd int, data &char, len usize) +fn C.v_os_fd_write_all(fd int, data &char, len uint) fn C.waitpid(pid int, status &int, options int) int @@ -93,7 +93,7 @@ fn fastc_stream_unit_compile_order(sources []string) []int { } fn fastc_write_unit_stdin(fd int, source string) { - C.v_os_fd_write_all(fd, &char(source.str), usize(source.len)) + C.v_os_fd_write_all(fd, &char(source.str), uint(source.len)) C.close(fd) } @@ -158,7 +158,7 @@ fn fastc_render_c_unit_stdin(fd int, pieces []string, units &FastcUnitLayout, g for k in units.unit_starts[first_unit] .. units.unit_starts[end_unit] { fastc_append_c_unit_piece(mut out, pieces[k]) } - C.v_os_fd_write_all(fd, &char(out.data), usize(out.len)) + C.v_os_fd_write_all(fd, &char(out.data), uint(out.len)) C.close(fd) } diff --git a/vlib/v/gen/v/gen_test.v b/vlib/v/gen/v/gen_test.v index 61e4a073e7..0a19e447a0 100644 --- a/vlib/v/gen/v/gen_test.v +++ b/vlib/v/gen/v/gen_test.v @@ -1434,8 +1434,8 @@ fn test_formatter_ignores_vfmt_directives_inside_strings() { } fn test_formatter_preserves_go_legacy_dollar_builtins_and_bodyless_functions() { - bodyless := vfmt('bodyless_functions', 'fn plain(value usize) usize\nfn C.c_call(value int) int\nfn JS.js_call(value int) int\n') - assert bodyless.contains('fn plain(value usize) usize'), bodyless + bodyless := vfmt('bodyless_functions', 'fn plain(value uint) uint\nfn C.c_call(value int) int\nfn JS.js_call(value int) int\n') + assert bodyless.contains('fn plain(value uint) uint'), bodyless assert bodyless.contains('fn C.c_call(value int) int'), bodyless assert bodyless.contains('fn JS.js_call(value int) int'), bodyless assert !bodyless.contains('fn C.plain'), bodyless diff --git a/vlib/v/gen/wasm/gen.v b/vlib/v/gen/wasm/gen.v index aade52a619..01c0a1d2ab 100644 --- a/vlib/v/gen/wasm/gen.v +++ b/vlib/v/gen/wasm/gen.v @@ -2914,7 +2914,7 @@ const signed_int_format_fns = ['strconv__format_int', 'int_str', 'i64_str', 'i8_ 'i32_str', 'isize_str', 'int.str', 'i8.str', 'i16.str', 'i32.str', 'i64.str', 'isize.str'] const unsigned_int_format_fns = ['strconv__format_uint', 'u8_str', 'u16_str', 'u32_str', 'u64_str', - 'usize_str', 'u8.str', 'u16.str', 'u32.str', 'u64.str', 'usize.str'] + 'usize_str', 'u8.str', 'u16.str', 'u32.str', 'u64.str', 'uint.str'] const bool_format_fns = ['bool.str', 'bool__str', 'bool_str'] diff --git a/vlib/v/gen/wasm/ssa_gen_test.v b/vlib/v/gen/wasm/ssa_gen_test.v index 266c0f2bba..5b1418cc4d 100644 --- a/vlib/v/gen/wasm/ssa_gen_test.v +++ b/vlib/v/gen/wasm/ssa_gen_test.v @@ -1272,10 +1272,10 @@ pub fn seeded(n int) int { fn test_ssa_wasm_refuses_an_unmappable_import_signature() { source := ' @[wasm_import_namespace: "wasi_snapshot_preview1"] -fn WASM.fd_write(fd int, iovs [4]u8, iovs_len usize, ret &usize) int +fn WASM.fd_write(fd int, iovs [4]u8, iovs_len uint, ret &uint) int pub fn report() int { - mut n := usize(0) + mut n := uint(0) chunk := [u8(1), 2, 3, 4]! return WASM.fd_write(1, chunk, 4, &n) + int(n) } diff --git a/vlib/v/gen/wasm/tests/cast.vv b/vlib/v/gen/wasm/tests/cast.vv index 81d7fedc30..8c5ee85060 100644 --- a/vlib/v/gen/wasm/tests/cast.vv +++ b/vlib/v/gen/wasm/tests/cast.vv @@ -1,3 +1,3 @@ fn main() { - println(u32(usize(0))) + println(u32(uint(0))) } diff --git a/vlib/v/gen/wasm/tests/wasi_api.vv b/vlib/v/gen/wasm/tests/wasi_api.vv index ce4744e9cc..0c32cffb35 100644 --- a/vlib/v/gen/wasm/tests/wasi_api.vv +++ b/vlib/v/gen/wasm/tests/wasi_api.vv @@ -70,7 +70,7 @@ fn wasi_fd_write() { message := 'fd_write: Hello from WASI WOORLD!\n' message_struct := CIOVec{ buf: message.str - len: usize(message.len) + len: uint(message.len) } if WASM.fd_write(1, &message_struct, 1, 0) == 0 { @@ -86,15 +86,15 @@ fn wasi_fd_write_multiple_iovecs() { iovs := [ CIOVec{ buf: msg1.str - len: usize(msg1.len) + len: uint(msg1.len) }, CIOVec{ buf: msg2.str - len: usize(msg2.len) + len: uint(msg2.len) }, CIOVec{ buf: msg3.str - len: usize(msg3.len) + len: uint(msg3.len) }, ]! diff --git a/vlib/v/help/build/build-c.txt b/vlib/v/help/build/build-c.txt index d2b4b8347a..83a355df8c 100644 --- a/vlib/v/help/build/build-c.txt +++ b/vlib/v/help/build/build-c.txt @@ -145,35 +145,35 @@ see also `v help build`. Print "V panic: " + msg, along with an optional backtrace and/or the V commit hash, and then exit. @[export: 'malloc'] - __malloc(n usize) &C.void + __malloc(n uint) &C.void Allocates n bytes of memory and returns the pointer to the first byte. @[export: 'free'] __free(ptr &C.void) Free the block of memory ptr allocated by malloc. - realloc(old_area &C.void, new_size usize) &C.void + realloc(old_area &C.void, new_size uint) &C.void Allocates a new area of size new_size, copies old_area to the new area, and returns a pointer to the new area. @[export: 'calloc'] - __calloc(nmemb usize, size usize) &C.void + __calloc(nmemb uint, size uint) &C.void Like malloc, but sets all the bytes to `0` first. - memcpy(dest &C.void, const_src &C.void, n usize) &C.void + memcpy(dest &C.void, const_src &C.void, n uint) &C.void Moves n bytes from dest to src, and returns dest - memmove(dest &C.void, const_src &C.void, n usize) &C.void + memmove(dest &C.void, const_src &C.void, n uint) &C.void Like memcpy, but guaranteed to work if dest and src overlap. - memcmp(const_a &C.void, const_b &C.void, n usize) int + memcmp(const_a &C.void, const_b &C.void, n uint) int Compare two buffers of length n. If a and b are equal, return 0. Otherwise, return the difference between the first different letter. - strlen(const_s &char) usize + strlen(const_s &char) uint Returns the amount of bytes until the first `0`, starting at s - memset(s &C.void, c int, n usize) &C.void + memset(s &C.void, c int, n uint) &C.void Sets n bytes starting at s to c (c is casted to a char) and returns s. getchar() int Read one character from stdin and return it. vsprintf(str &char, format &char, ap va_list) int See `man vsprintf`. - vsnprintf(str &char, size usize, format &char, ap va_list) int + vsnprintf(str &char, size uint, format &char, ap va_list) int See `man vsnprintf`. bare_backtrace() string Return a backtrace that can be printed. If backtraces are not diff --git a/vlib/v/legacy_tests/checker/c_fn_redeclaration_test.vv b/vlib/v/legacy_tests/checker/c_fn_redeclaration_test.vv index 417b342686..bf54924ba5 100644 --- a/vlib/v/legacy_tests/checker/c_fn_redeclaration_test.vv +++ b/vlib/v/legacy_tests/checker/c_fn_redeclaration_test.vv @@ -38,8 +38,8 @@ fn test_conflicting_c_fn_redeclarations_across_modules_are_reported_at_declarati fn test_compatible_c_fn_redeclarations_across_modules_are_accepted() { root := write_c_fn_redeclaration_project('c_fn_compatible_redeclaration', { 'v.mod': "Module { name: 'c_fn_compatible_redeclaration' }\n" - 'moda/moda.v': 'module moda\n\nstruct C.Display {}\n\nfn C.compat_probe(value int, data byteptr, display voidptr, mut state usize) int\n\npub fn touch() {\n\tmut state := usize(0)\n\tC.compat_probe(0, unsafe { nil }, unsafe { nil }, mut state)\n}\n' - 'modb/modb.v': 'module modb\n\nstruct C.Display {}\n\ntype CInt = i32\n\nfn C.compat_probe(value CInt, data &u8, display &C.Display, state &usize) i32\n\npub fn touch() {\n\tmut state := usize(0)\n\tC.compat_probe(0, unsafe { nil }, unsafe { nil }, &state)\n}\n' + 'moda/moda.v': 'module moda\n\nstruct C.Display {}\n\nfn C.compat_probe(value int, data byteptr, display voidptr, mut state uint) int\n\npub fn touch() {\n\tmut state := uint(0)\n\tC.compat_probe(0, unsafe { nil }, unsafe { nil }, mut state)\n}\n' + 'modb/modb.v': 'module modb\n\nstruct C.Display {}\n\ntype CInt = i32\n\nfn C.compat_probe(value CInt, data &u8, display &C.Display, state &uint) i32\n\npub fn touch() {\n\tmut state := uint(0)\n\tC.compat_probe(0, unsafe { nil }, unsafe { nil }, &state)\n}\n' 'main.v': 'module main\n\nimport moda\nimport modb\n\nfn main() {\n\tmoda.touch()\n\tmodb.touch()\n}\n' })! defer { @@ -151,7 +151,7 @@ fn test_fasthttp_and_veb_freebsd_c_fn_redeclarations_are_compatible() { fn test_os_and_posix_size_t_c_fn_redeclarations_are_compatible() { root := write_c_fn_redeclaration_project('c_fn_os_posix_size_t_redeclaration', { - 'main.v': 'module main\n\nimport os\n\nfn C.readlink(path &char, buf &char, size usize) int\nfn C.gethostname(name &char, size u64) int\n\nfn main() {\n\t_ = os.args\n}\n' + 'main.v': 'module main\n\nimport os\n\nfn C.readlink(path &char, buf &char, size uint) int\nfn C.gethostname(name &char, size u64) int\n\nfn main() {\n\t_ = os.args\n}\n' })! defer { os.rmdir_all(root) or {} @@ -163,7 +163,7 @@ fn test_os_and_posix_size_t_c_fn_redeclarations_are_compatible() { fn test_pointer_sized_c_fn_redeclarations_respect_target_width() { root := write_c_fn_redeclaration_project('c_fn_pointer_sized_target_width', { 'v.mod': "Module { name: 'c_fn_pointer_sized_target_width' }\n" - 'moda/moda.v': 'module moda\n\nfn C.size_probe(size usize) isize\n\npub fn touch() {}\n' + 'moda/moda.v': 'module moda\n\nfn C.size_probe(size uint) int\n\npub fn touch() {}\n' 'modb/modb.v': 'module modb\n\nfn C.size_probe(size u64) i64\n\npub fn touch() {}\n' 'main.v': 'module main\n\nimport moda\nimport modb\n\nfn main() {\n\tmoda.touch()\n\tmodb.touch()\n}\n' })! diff --git a/vlib/v/legacy_tests/gen/c/cheaders_manual_stdlib_decls_test.vv b/vlib/v/legacy_tests/gen/c/cheaders_manual_stdlib_decls_test.vv index ad9cca1b06..976d94416d 100644 --- a/vlib/v/legacy_tests/gen/c/cheaders_manual_stdlib_decls_test.vv +++ b/vlib/v/legacy_tests/gen/c/cheaders_manual_stdlib_decls_test.vv @@ -67,7 +67,7 @@ fn test_default_c_prelude_uses_manual_stdio_stdlib_string_and_stdarg_decls() { 'V_CRT_LINKAGE int V_CRT_CALL setenv(const char *name, const char *value, int overwrite);', 'V_CRT_LINKAGE int V_CRT_CALL unsetenv(const char *name);', 'V_CRT_LINKAGE char * V_CRT_CALL realpath(const char *path, char *resolved_path);', - 'V_CRT_LINKAGE isize V_CRT_CALL getline(char **lineptr, size_t *n, FILE *stream);', + 'V_CRT_LINKAGE int V_CRT_CALL getline(char **lineptr, size_t *n, FILE *stream);', 'V_CRT_LINKAGE int V_CRT_CALL fgetpos(FILE *stream, i64 *pos);', 'V_CRT_LINKAGE void * V_CRT_CALL _aligned_malloc(size_t size, size_t alignment);', 'V_CRT_LINKAGE void * V_CRT_CALL _aligned_realloc(void *memory, size_t size, size_t alignment);', diff --git a/vlib/v/legacy_tests/gen/c/freestanding_i386_test.vv b/vlib/v/legacy_tests/gen/c/freestanding_i386_test.vv index 7c7d8e8b0f..7569dcb99e 100644 --- a/vlib/v/legacy_tests/gen/c/freestanding_i386_test.vv +++ b/vlib/v/legacy_tests/gen/c/freestanding_i386_test.vv @@ -23,8 +23,8 @@ pub fn kmain() { res := os.exec([@VEXE, '-cc', 'gcc', '-gc', 'none', '-no-skip-unused', '-freestanding', '-no-std', '-is_o', '-m32', '-o', '${out_c}', '${main_v}']) assert res.exit_code == 0, '${cmd}\n${res.output}' generated := os.read_file(out_c)! - assert generated.contains('VV_LOC voidptr builtin__memdup(voidptr src, isize size);') - assert !generated.contains('\nvoidptr builtin__memdup(voidptr src, isize size);\n') + assert generated.contains('VV_LOC voidptr builtin__memdup(voidptr src, int size);') + assert !generated.contains('\nvoidptr builtin__memdup(voidptr src, int size);\n') assert generated.contains('int $0x80') assert !generated.contains('"syscall \\n\\t"') assert !generated.contains('mov %[arg4], %%r10') diff --git a/vlib/v/legacy_tests/parser/v_parser_test.vv b/vlib/v/legacy_tests/parser/v_parser_test.vv index 0ca686cc98..ddd5349afd 100644 --- a/vlib/v/legacy_tests/parser/v_parser_test.vv +++ b/vlib/v/legacy_tests/parser/v_parser_test.vv @@ -370,7 +370,7 @@ type MySum = u8 | u16 // MySum end_comment // not_MyFnType comment line1 // MyFnType comment line2 -type MyFnType = fn (msg &char, arg usize) // MyFnType end_comment +type MyFnType = fn (msg &char, arg uint) // MyFnType end_comment // not_MyEnum comment line1 diff --git a/vlib/v/markused/markused.v b/vlib/v/markused/markused.v index 0ff24deee1..f1bbce116e 100644 --- a/vlib/v/markused/markused.v +++ b/vlib/v/markused/markused.v @@ -4426,7 +4426,7 @@ fn enqueue_stringified_primitive_helpers(type_name_id u32, mut used map[string]b enqueue('i64.str', mut used, mut queue) enqueue(markused_c_name('i64.str'), mut used, mut queue) enqueue('strconv__format_int', mut used, mut queue) - } else if type_name_id == flat.source_type_u8 || type_name_id == flat.source_type_u16 || type_name_id == flat.source_type_u32 || type_name_id == flat.source_type_usize { + } else if type_name_id == flat.source_type_u8 || type_name_id == flat.source_type_u16 || type_name_id == flat.source_type_u32 || type_name_id == flat.source_type_uint { enqueue('u64.str', mut used, mut queue) enqueue(markused_c_name('u64.str'), mut used, mut queue) enqueue('strconv__format_uint', mut used, mut queue) @@ -11190,7 +11190,7 @@ fn resolve_type_name(t types.Type) u32 { } else if t is types.ISize { return flat.source_type_isize } else if t is types.USize { - return flat.source_type_usize + return flat.source_type_uint } else if t is types.Rune { return flat.source_type_rune } diff --git a/vlib/v/markused/markused_parallel_notd_v3_no_parallel.v b/vlib/v/markused/markused_parallel_notd_v3_no_parallel.v index 188e330e2c..ca39e762b1 100644 --- a/vlib/v/markused/markused_parallel_notd_v3_no_parallel.v +++ b/vlib/v/markused/markused_parallel_notd_v3_no_parallel.v @@ -102,7 +102,7 @@ fn (c &CallCollector) collect_bodies_scoped_batches(body_ids []int, body_modules // markused_batch_arena_keep_bytes bounds how much of a batch arena stays mapped // for the next batch (see prealloc_scope_reenter). -const markused_batch_arena_keep_bytes = isize(8) * 1024 * 1024 +const markused_batch_arena_keep_bytes = int(8) * 1024 * 1024 // markused_worker_scope_reenter makes a left batch arena current again, rewound. // False means the caller needs a new arena. diff --git a/vlib/v/parser/deprecated_integer_types.v b/vlib/v/parser/deprecated_integer_types.v new file mode 100644 index 0000000000..494a5cbfa5 --- /dev/null +++ b/vlib/v/parser/deprecated_integer_types.v @@ -0,0 +1,55 @@ +module parser + +import v.flat + +// Keep the old spellings readable by the formatter, but compile them as their +// replacements and point the warning at the original token. Preserve the legacy +// signed type identity for compatibility with existing methods and aliases. +fn (mut p Parser) canonical_integer_type(name string, start int, end int) string { + // These standard-library declarations retain the legacy signed type during + // migration: builtin methods and strconv.Numeric must still accept it. + if name.len != 5 || p.prefs.is_fmt + || (name == 'isize' && p.cur_module in ['builtin', 'strconv']) { + return name + } + replacement := match name { + 'isize' { 'int' } + 'usize' { 'uint' } + else { return name } + } + p.record_warning_span('`${name}` is deprecated; use `${replacement}` instead', start, end) + return if name == 'usize' { replacement } else { name } +} + +// Canonicalize type tokens inside explicit generic arguments before rebuilding +// their type name. Selector members keep their spelling, as they may be user names. +fn (mut p Parser) canonical_generic_type_arg(id flat.NodeId) flat.NodeId { + node := p.a.nodes[int(id)] + if node.kind == .ident { + name := p.canonical_integer_type(node.value, node.pos.offset, node.pos.end) + if name != node.value { + return p.add_node(flat.Node{ ...node, value: name }) + } + return id + } + if node.kind !in [.index, .prefix] { + return id + } + mut children := []flat.NodeId{} + for i in 0 .. int(node.children_count) { + child := p.a.child(&node, i) + canonical := p.canonical_generic_type_arg(child) + if canonical != child && children.len == 0 { + // Most generic arguments need no migration. Copy children only when + // a deprecated spelling actually changes the tree. + children = p.a.children[int(node.children_start)..int(node.children_start) + int(node.children_count)].clone() + } + if children.len > 0 { + children[i] = canonical + } + } + if children.len == 0 { + return id + } + return p.add_node(flat.Node{ ...node, children_start: p.add_children(children) }) +} diff --git a/vlib/v/parser/deprecated_integer_types_test.v b/vlib/v/parser/deprecated_integer_types_test.v new file mode 100644 index 0000000000..e9c01ab91e --- /dev/null +++ b/vlib/v/parser/deprecated_integer_types_test.v @@ -0,0 +1,81 @@ +module parser + +import v.flat +import v.pref + +fn test_deprecated_integer_type_spellings_warn_at_each_type_token() { + sources := { + 'fn identity[T](x T) T { return x }\nstruct Box[T] { value T }\nfn main() { _ = identity[Box[usize]](Box[usize]{}) }': 2 + 'type Old = isize': 1 + 'struct S { values []map[isize]usize }': 2 + 'fn main() { _ = usize(1) }': 1 + 'fn take(x isize) usize { return usize(x) }': 3 + 'fn take(x fn (isize) usize) {}': 2 + 'fn main() { _ = sizeof(isize) }': 1 + 'fn main() { _ = [1]usize[1] }': 1 + 'fn identity[T](x T) T { return x } +fn main() { _ = identity[isize](0) }': 1 + } + for source, count in sources { + mut p := Parser.new(pref.new_preferences()) + p.parse_text('deprecated.v', source) + assert p.diagnostics.len == count, '${source}\n${p.diagnostics}' + for diagnostic in p.diagnostics { + assert diagnostic.severity == 'warning:', diagnostic.str() + old := source[diagnostic.pos.offset..diagnostic.pos.end] + assert old in ['isize', 'usize'], old + replacement := if old == 'isize' { 'int' } else { 'uint' } + assert diagnostic.message == '`${old}` is deprecated; use `${replacement}` instead' + } + } +} + +fn test_deprecated_integer_types_compile_as_platform_integer_types() { + mut p := Parser.new(pref.new_preferences()) + a := p.parse_text('aliases.v', 'type Signed = isize\ntype Unsigned = usize\nfn main() { _ = usize(1) }') + aliases := a.nodes.filter(it.kind == .type_decl) + assert aliases.len == 2 + assert aliases[0].typ == flat.source_type_isize + assert aliases[1].typ == flat.source_type_uint + casts := a.nodes.filter(it.kind == .cast_expr) + assert casts.len == 1 + assert casts[0].value == 'uint' +} + +fn test_modern_integer_types_and_ordinary_names_do_not_warn() { + mut p := Parser.new(pref.new_preferences()) + p.parse_text('modern.v', "struct Names { isize int; usize uint } +fn main() { + isize := int(-1) + usize := uint(1) + _ = Names{isize: isize, usize: usize} + _ = 'isize usize' + // isize usize +}") + assert p.diagnostics.len == 0, p.diagnostics.str() +} + +fn test_formatter_preserves_deprecated_integer_spellings_without_warnings() { + mut prefs := pref.new_preferences() + prefs.is_fmt = true + mut p := Parser.new(prefs) + a := p.parse_text('legacy.v', 'type Signed = isize\nfn main() { _ = usize(1) }') + assert p.diagnostics.len == 0, p.diagnostics.str() + casts := a.nodes.filter(it.kind == .cast_expr) + assert casts.len == 1 + assert casts[0].value == 'usize' +} + +fn test_deprecated_integer_warnings_do_not_exhaust_parser_error_limit() { + mut p := Parser.new(pref.new_preferences()) + source := 'fn main() {\n' + '\t_ = usize(1)\n'.repeat(max_parse_diagnostics + 1) + '}\n' + p.parse_text('many_deprecations.v', source) + assert p.diagnostics.len == max_parse_diagnostics + 1 + assert p.diagnostics.all(it.severity == 'warning:') + assert !p.diagnostic_limit_reached + for _ in 0 .. max_parse_diagnostics + 1 { + p.record_diagnostic('test error', 0) + } + assert p.diagnostic_limit_reached + assert p.diagnostics.last().message == 'too many errors; stopping after ${max_parse_diagnostics} diagnostics' +} diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 2cd7199c03..f3615919e9 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1104,7 +1104,12 @@ fn (mut p Parser) append_diagnostic(diagnostic Diagnostic) { if p.diagnostic_limit_reached { return } - if p.diagnostics.len >= max_parse_diagnostics { + // Deprecations must not make otherwise valid legacy sources hit the error limit. + if diagnostic.severity in ['warning:', 'notice:'] { + p.diagnostics << diagnostic + return + } + if p.diagnostics.filter(it.severity !in ['warning:', 'notice:']).len >= max_parse_diagnostics { p.diagnostics << Diagnostic{ file: diagnostic.file pos: diagnostic.pos @@ -1725,7 +1730,7 @@ fn (mut p Parser) fn_decl() flat.NodeId { // V permits an unnamed type-only receiver, e.g. `fn (File) read()`. // Keep an explicit ignored receiver binding so downstream method // signature and dispatch indexes still receive parameter 0. - receiver_type = receiver_name + receiver_type = p.canonical_integer_type(receiver_name, name_pos, p.prev_tok_end) receiver_name = '_' } else if p.tok == .name && p.lit == 'chan' && p.peek() == .rpar { // The builtin channel methods use the generic `chan` receiver. A bare @@ -13090,7 +13095,7 @@ fn (mut p Parser) prefix_expr() flat.NodeId { name_pos, name_end) return p.map_literal() } - local_type_name := p.resolve_local_type_name(name) + mut local_type_name := p.resolve_local_type_name(name) // struct init: Name{...}; vlib/builtin also uses concrete lowercase // runtime structs like array{} and string{}. if p.tok == .lcbr && local_type_name.len > 0 @@ -13104,6 +13109,7 @@ fn (mut p Parser) prefix_expr() flat.NodeId { if p.tok == .lpar && local_type_name.len > 0 && ((local_type_name[0] >= `A` && local_type_name[0] <= `Z`) || is_builtin_type(name) || p.is_generated_type_name(name)) { + local_type_name = p.canonical_integer_type(local_type_name, name_pos, name_end) p.next() // skip ( inner := p.expr(.lowest) p.check(.rpar) @@ -14461,10 +14467,16 @@ fn (mut p Parser) generic_call_type_arg_id(id flat.NodeId) flat.NodeId { } } } - name := flat.source_type_name(p.type_expr_name(id)) - resolved := p.resolve_local_type_name(name) - if name.len == 0 || resolved == name { - return id + canonical_id := if node.kind in [.index, .prefix] { + p.canonical_generic_type_arg(id) + } else { + id + } + name := flat.source_type_name(p.type_expr_name(canonical_id)) + resolved := p.canonical_integer_type(p.resolve_local_type_name(name), node.pos.offset, + node.pos.end) + if name.len == 0 || (resolved == name && canonical_id == id) { + return canonical_id } return p.add_node(flat.Node{ kind: .ident @@ -15294,6 +15306,7 @@ fn (mut p Parser) parse_fixed_array_literal_type_name() string { if !is_builtin_type(name) { name += p.parse_type_generic_suffix() } + name = p.canonical_integer_type(name, name_start, name_end) return p.resolve_local_type_name(name) } return p.parse_type_name_bytes() @@ -16001,7 +16014,7 @@ fn (mut p Parser) translated_sizeof_name_is_const(name string) bool { return false } if !p.is_translated && name in ['bool', 'char', 'i8', 'i16', 'i32', 'int', 'i64', 'u8', 'u16', - 'u32', 'u64', 'f32', 'f64', 'string', 'rune', 'usize', 'isize', 'voidptr'] { + 'u32', 'u64', 'f32', 'f64', 'string', 'rune', 'uint', 'usize', 'isize', 'voidptr'] { return false } // `builtin` declares the other builtin types, such as `array`, so none of its @@ -17789,6 +17802,7 @@ fn (mut p Parser) parse_type_name_bytes() string { } } // generic: Type[T, U] + name = p.canonical_integer_type(name, name_start, name_end) name += p.parse_type_generic_suffix() name = p.resolve_local_type_name(name) } @@ -17974,8 +17988,8 @@ fn anonymous_struct_untyped_numeric_literal_matches(value flat.Node, expected u3 if value.kind == .int_literal { return expected in [flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_isize, flat.source_type_u8, - flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, flat.source_type_usize, - flat.source_type_f32, flat.source_type_f64] + flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, flat.source_type_uint, + flat.source_type_usize, flat.source_type_f32, flat.source_type_f64] } if value.kind == .float_literal { return expected in [flat.source_type_f32, flat.source_type_f64] @@ -18795,8 +18809,8 @@ fn write_utf8_codepoint(buf &u8, j int, code u32) int { fn is_builtin_type(name string) bool { return name in ['int', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128', - 'f32', 'f64', 'bool', 'string', 'rune', 'char', 'voidptr', 'charptr', 'byteptr', 'usize', - 'isize', 'array', 'map', 'mapnode', '_result', '_option', 'any'] + 'f32', 'f64', 'bool', 'string', 'rune', 'char', 'voidptr', 'charptr', 'byteptr', 'uint', + 'usize', 'isize', 'array', 'map', 'mapnode', '_result', '_option', 'any'] } fn parser_name_can_start_pointer_type(name string) bool { diff --git a/vlib/v/parser/sizeof_const_lookup_test.v b/vlib/v/parser/sizeof_const_lookup_test.v index f26c9b60b4..8ccf7a11ca 100644 --- a/vlib/v/parser/sizeof_const_lookup_test.v +++ b/vlib/v/parser/sizeof_const_lookup_test.v @@ -9,7 +9,7 @@ fn test_sizeof_reserved_types_do_not_index_sibling_declarations() { defer { os.rmdir_all(root) or {} } path := os.join_path(root, 'main.v') for name in ['bool', 'char', 'i8', 'i16', 'i32', 'int', 'i64', 'u8', 'u16', 'u32', 'u64', 'f32', - 'f64', 'string', 'rune', 'usize', 'isize', 'voidptr'] { + 'f64', 'string', 'rune', 'uint', 'voidptr'] { os.write_file(path, 'module main\nfn main() { _ = sizeof(${name}) }\n')! mut p := Parser.new(pref.new_preferences()) p.parse_file(path) diff --git a/vlib/v/parser/source_scan.c.v b/vlib/v/parser/source_scan.c.v index ce08a6a6b7..1e454eeadf 100644 --- a/vlib/v/parser/source_scan.c.v +++ b/vlib/v/parser/source_scan.c.v @@ -11,7 +11,7 @@ fn source_index_u8(src string, c u8, start int) int { if start < 0 || start >= src.len { return -1 } - found := unsafe { &u8(C.memchr(src.str + start, c, usize(src.len - start))) } + found := unsafe { &u8(C.memchr(src.str + start, c, uint(src.len - start))) } if isnil(found) { return -1 } @@ -116,14 +116,14 @@ fn read_batch_source(path string) string { return '' } size := i64(st.st_size) - buf := unsafe { &u8(C.malloc(usize(size + 1))) } + buf := unsafe { &u8(C.malloc(uint(size + 1))) } if isnil(buf) { C.close(fd) return '' } mut done := i64(0) for done < size { - n := i64(C.read(fd, unsafe { buf + done }, usize(size - done))) + n := i64(C.read(fd, unsafe { buf + done }, uint(size - done))) if n <= 0 { break } diff --git a/vlib/v/profiler/context.v b/vlib/v/profiler/context.v index 1bff3387a6..5b70c6a282 100644 --- a/vlib/v/profiler/context.v +++ b/vlib/v/profiler/context.v @@ -33,7 +33,7 @@ pub const default_allocator = Allocator{ } fn default_alloc(size int, ctx voidptr) voidptr { - return unsafe { C.malloc(usize(size)) } + return unsafe { C.malloc(uint(size)) } } fn default_free(ptr voidptr, ctx voidptr) { @@ -41,7 +41,7 @@ fn default_free(ptr voidptr, ctx voidptr) { } fn default_realloc(ptr voidptr, new_size int, ctx voidptr) voidptr { - return unsafe { C.realloc(ptr, usize(new_size)) } + return unsafe { C.realloc(ptr, uint(new_size)) } } // User code calls these - they use the current allocator implicitly diff --git a/vlib/v/profiler/profiler_alloc.v b/vlib/v/profiler/profiler_alloc.v index 3c09146942..e5286625d0 100644 --- a/vlib/v/profiler/profiler_alloc.v +++ b/vlib/v/profiler/profiler_alloc.v @@ -7,7 +7,7 @@ import time // profiler_alloc is the allocation function that records allocations fn profiler_alloc(size int, ctx voidptr) voidptr { - ptr := unsafe { C.malloc(usize(size)) } + ptr := unsafe { C.malloc(uint(size)) } if ptr == unsafe { nil } { return ptr } @@ -56,7 +56,7 @@ fn profiler_alloc(size int, ctx voidptr) voidptr { // profiler_alloc_with_location records allocation with source location pub fn profiler_alloc_with_location(size int, file string, line int) voidptr { - ptr := unsafe { C.malloc(usize(size)) } + ptr := unsafe { C.malloc(uint(size)) } if ptr == unsafe { nil } { return ptr } @@ -160,7 +160,7 @@ fn profiler_realloc(ptr voidptr, new_size int, ctx voidptr) voidptr { profiler_state.mu.unlock() } - new_ptr := unsafe { C.realloc(ptr, usize(new_size)) } + new_ptr := unsafe { C.realloc(ptr, uint(new_size)) } if new_ptr == unsafe { nil } { return new_ptr } diff --git a/vlib/v/reflection/reflection.v b/vlib/v/reflection/reflection.v index 5dde905ffb..f42e1eec65 100644 --- a/vlib/v/reflection/reflection.v +++ b/vlib/v/reflection/reflection.v @@ -55,7 +55,7 @@ pub enum VKind { u16 u32 u64 - usize + uint f32 f64 char diff --git a/vlib/v/skills/v-memory/references/UNSAFE.md b/vlib/v/skills/v-memory/references/UNSAFE.md index 8da4f7ac14..8bc7c443bf 100644 --- a/vlib/v/skills/v-memory/references/UNSAFE.md +++ b/vlib/v/skills/v-memory/references/UNSAFE.md @@ -42,7 +42,7 @@ module main // fill zeroes `len` bytes of raw memory. The caller guarantees the buffer is at // least `len` bytes, which the type cannot express. -fn fill_raw(data voidptr, len usize) { +fn fill_raw(data voidptr, len uint) { unsafe { C.memset(data, 0, len) } diff --git a/vlib/v/slow_tests/assembly/asm_raw_simd_crypto_test.arm64.v b/vlib/v/slow_tests/assembly/asm_raw_simd_crypto_test.arm64.v index bdefbfba1e..cb70adddff 100644 --- a/vlib/v/slow_tests/assembly/asm_raw_simd_crypto_test.arm64.v +++ b/vlib/v/slow_tests/assembly/asm_raw_simd_crypto_test.arm64.v @@ -258,7 +258,7 @@ $if macos { #include } -fn C.sysctlbyname(name &char, oldp voidptr, oldlenp &usize, newp voidptr, newlen usize) int +fn C.sysctlbyname(name &char, oldp voidptr, oldlenp &uint, newp voidptr, newlen uint) int fn C.IsProcessorFeaturePresent(feature u32) int @@ -271,7 +271,7 @@ fn can_run_pmull_test() bool { return cpuinfo.contains('pmull') } $else $if macos { mut value := u32(0) - mut size := usize(sizeof(value)) + mut size := uint(sizeof(value)) if C.sysctlbyname(c'hw.optional.arm.FEAT_PMULL', &value, &size, unsafe { nil }, 0) != 0 { return false } diff --git a/vlib/v/slow_tests/inout/v3_assert_unsigned_value.v3.v b/vlib/v/slow_tests/inout/v3_assert_unsigned_value.v3.v index b95571c5a4..23e84df8e0 100644 --- a/vlib/v/slow_tests/inout/v3_assert_unsigned_value.v3.v +++ b/vlib/v/slow_tests/inout/v3_assert_unsigned_value.v3.v @@ -1,5 +1,5 @@ fn main() { left := u64(9223372036854775808) - right := usize(9223372036854775809) + right := uint(9223372036854775809) assert left == right } diff --git a/vlib/v/ssa/builder.v b/vlib/v/ssa/builder.v index 5aea38489f..603c3bce9b 100644 --- a/vlib/v/ssa/builder.v +++ b/vlib/v/ssa/builder.v @@ -1796,7 +1796,7 @@ fn (b &Builder) enum_field_expr_value(id flat.NodeId, enum_name_id u32) ?int { } cast_name := b.qualified_expr_name(b.a.child(&node, 0)) if cast_name !in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'u8', 'u16', 'u32', 'u64', - 'usize', 'rune'] { + 'uint', 'rune'] { return none } return b.enum_field_expr_value(b.a.child(&node, 1), enum_name_id) @@ -3499,7 +3499,7 @@ fn (mut b Builder) register_array_runtime_stubs() { // Integer types only, like the C backend: the transformer lowers a float sort // to its stable merge sort. - for sort_type in ['int', 'i8', 'i16', 'i64', 'u8', 'u16', 'u32', 'u64', 'isize', 'usize', 'rune', + for sort_type in ['int', 'i8', 'i16', 'i64', 'u8', 'u16', 'u32', 'u64', 'isize', 'uint', 'rune', 'char'] { elem_type := match sort_type { 'int', 'rune' { b.i32_type } @@ -11826,7 +11826,7 @@ fn (mut b Builder) build_scalar_str_call(node flat.Node, resolved_name string, b primitive_name := name.all_before_last('.') if name.all_after_last('.') != 'str' || primitive_name !in ['int', 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'bool', - 'rune', 'isize', 'usize', 'string'] { + 'rune', 'isize', 'uint', 'string'] { return none } mut value_id := base_id @@ -12614,7 +12614,7 @@ fn (b &Builder) const_int_literal_value(id flat.NodeId) ?string { if node.children_count == 2 { callee := b.qualified_expr_name(b.a.child(&node, 0)) if callee in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'u8', 'u16', 'u32', 'u64', - 'usize', 'rune'] { + 'uint', 'rune'] { return b.const_int_literal_value(b.a.child(&node, 1)) } } @@ -14245,7 +14245,7 @@ fn (mut b Builder) primitive_type_id(name_id u32) ?TypeID { 'isize' { if b.m.target.ptr_size == 4 { b.i32_type } else { b.i64_type } } - 'usize' { + 'uint' { if b.m.target.ptr_size == 4 { b.u32_type } else { b.u64_type } } 'i8', 'char' { diff --git a/vlib/v/ssa/native_constant.v b/vlib/v/ssa/native_constant.v index 2c98513a4d..fe2e1a4a69 100644 --- a/vlib/v/ssa/native_constant.v +++ b/vlib/v/ssa/native_constant.v @@ -46,7 +46,7 @@ fn (b &Builder) native_const_requires_storage(id flat.NodeId, module_name string if node.kind == .call { callee := b.qualified_expr_name(b.a.child(node, 0)) required = callee !in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'u8', 'u16', 'u32', 'u64', - 'usize', 'rune', 'f32', 'f64', 'bool', 'voidptr', 'char'] + 'uint', 'rune', 'f32', 'f64', 'bool', 'voidptr', 'char'] } if node.kind == .infix && b.checked_expr_type_name(id) == flat.source_type_string { required = true diff --git a/vlib/v/tempname/tempname.v b/vlib/v/tempname/tempname.v index 3514221cea..bc32a2b010 100644 --- a/vlib/v/tempname/tempname.v +++ b/vlib/v/tempname/tempname.v @@ -7,6 +7,6 @@ import time // distinguishes sequential calls, while the stack address distinguishes concurrent workers. pub fn unique_token() string { stack_marker := u8(0) - stack_id := usize(voidptr(&stack_marker)) + stack_id := uint(voidptr(&stack_marker)) return '${os.getpid()}.${time.sys_mono_now()}.${stack_id}' } diff --git a/vlib/v/tests/alias_integer_pointer_cast_test.v b/vlib/v/tests/alias_integer_pointer_cast_test.v index 6eb2787934..e7c3035263 100644 --- a/vlib/v/tests/alias_integer_pointer_cast_test.v +++ b/vlib/v/tests/alias_integer_pointer_cast_test.v @@ -20,10 +20,10 @@ fn end_pointer(n int, z &U8) &U8 { fn test_pointer_cast_to_an_alias_of_an_integer_type() { all_ones := &U8(-1) - assert usize(all_ones) == ~usize(0) - assert usize(end_pointer(-1, unsafe { nil })) == ~usize(0) + assert uint(all_ones) == ~uint(0) + assert uint(end_pointer(-1, unsafe { nil })) == ~uint(0) five := &U8(5) - assert usize(five) == 5 + assert uint(five) == 5 } // `&SS('hi')`, with `SS` an alias of a value type, still points to a copy. diff --git a/vlib/v/tests/aliases/c_numeric_alias_result_test.c.v b/vlib/v/tests/aliases/c_numeric_alias_result_test.c.v index 2fbfc8d48f..f78b5bfddf 100644 --- a/vlib/v/tests/aliases/c_numeric_alias_result_test.c.v +++ b/vlib/v/tests/aliases/c_numeric_alias_result_test.c.v @@ -2,27 +2,27 @@ #define v_result_handle size_t #define v_result_make_handle(value) ((v_result_handle)(value)) -type C.v_result_handle = usize +type C.v_result_handle = uint -fn C.v_result_make_handle(value usize) C.v_result_handle +fn C.v_result_make_handle(value uint) C.v_result_handle -fn result_c_handle(value usize) !C.v_result_handle { +fn result_c_handle(value uint) !C.v_result_handle { handle := C.v_result_make_handle(value) return handle } -fn option_c_handle(value usize) ?C.v_result_handle { +fn option_c_handle(value uint) ?C.v_result_handle { handle := C.v_result_make_handle(value) return handle } -fn deferred_result_c_handle(value usize, mut seen []usize) !C.v_result_handle { +fn deferred_result_c_handle(value uint, mut seen []uint) !C.v_result_handle { defer { seen << value } handle := C.v_result_make_handle(value) return handle } -fn deferred_option_c_handle(value usize, mut seen []usize) ?C.v_result_handle { +fn deferred_option_c_handle(value uint, mut seen []uint) ?C.v_result_handle { defer { seen << value } handle := C.v_result_make_handle(value) return handle @@ -37,17 +37,17 @@ fn absent_c_handle() ?C.v_result_handle { } fn test_c_numeric_alias_result_preserves_success_value() { - values := [usize(0), usize(1), usize(0x12345678), ~usize(0)] - mut deferred_values := []usize{} + values := [uint(0), uint(1), uint(0x12345678), ~uint(0)] + mut deferred_values := []uint{} for value in values { handle := result_c_handle(value) or { panic('successful C handle became an error: ${err}') } - assert usize(handle) == value + assert uint(handle) == value optional := option_c_handle(value) or { panic('successful C handle became none') } - assert usize(optional) == value + assert uint(optional) == value deferred := deferred_result_c_handle(value, mut deferred_values) or { panic(err) } - assert usize(deferred) == value + assert uint(deferred) == value deferred_option := deferred_option_c_handle(value, mut deferred_values) or { panic('none') } - assert usize(deferred_option) == value + assert uint(deferred_option) == value } assert deferred_values.len == 2 * values.len for i, value in values { diff --git a/vlib/v/tests/builtin_arrays/array_delete_last_test.v b/vlib/v/tests/builtin_arrays/array_delete_last_test.v index 0fe8c796e7..904c6edcf7 100644 --- a/vlib/v/tests/builtin_arrays/array_delete_last_test.v +++ b/vlib/v/tests/builtin_arrays/array_delete_last_test.v @@ -1,6 +1,6 @@ struct ArrayList[T] { mut: - size usize + size uint items []&T } diff --git a/vlib/v/tests/builtin_maps/map_equality_allocation_test.c.v b/vlib/v/tests/builtin_maps/map_equality_allocation_test.c.v index 388b9b2b38..a02d64c89d 100644 --- a/vlib/v/tests/builtin_maps/map_equality_allocation_test.c.v +++ b/vlib/v/tests/builtin_maps/map_equality_allocation_test.c.v @@ -5,12 +5,12 @@ module main #include struct C.GC_prof_stats_s { - bytes_allocd_since_gc usize - allocd_bytes_before_gc usize - gc_no usize + bytes_allocd_since_gc uint + allocd_bytes_before_gc uint + gc_no uint } -fn C.GC_get_prof_stats(&C.GC_prof_stats_s, usize) usize +fn C.GC_get_prof_stats(&C.GC_prof_stats_s, uint) uint fn map_equality_allocations() (u64, u64) { mut stats := C.GC_prof_stats_s{} diff --git a/vlib/v/tests/builtin_overflow_test.v b/vlib/v/tests/builtin_overflow_test.v index f7a12769d4..c57009ccdf 100644 --- a/vlib/v/tests/builtin_overflow_test.v +++ b/vlib/v/tests/builtin_overflow_test.v @@ -136,9 +136,9 @@ fn target2paths(target_path string, postfix string) (string, string, string, str // (`min / -1`), and shift counts, and the opt-in `-check-casts` checks. Each program // is compiled once with and once without its flag, then run once per case. -const signed_int_types = ['i8', 'i16', 'i32', 'i64', 'int', 'isize']! +const signed_int_types = ['i8', 'i16', 'i32', 'i64', 'int']! -const all_int_types = ['i8', 'u8', 'i16', 'u16', 'i32', 'u32', 'i64', 'u64', 'int', 'isize', 'usize']! +const all_int_types = ['i8', 'u8', 'i16', 'u16', 'i32', 'u32', 'i64', 'u64', 'int', 'uint']! struct OpCase { args []string @@ -166,7 +166,7 @@ fn int_type_bits(typ string) int { 'i8', 'u8' { 8 } 'i16', 'u16' { 16 } 'i32', 'u32' { 32 } - 'int', 'isize', 'usize' { int(sizeof(isize)) * 8 } + 'int', 'uint' { int(sizeof(int)) * 8 } else { 64 } } } @@ -189,10 +189,10 @@ fn signed_max(bits int) string { return '${(u64(1) << (bits - 1)) - 1}' } -// printable prints an `isize` result through `i64`: printing an `isize` goes +// printable prints an `int` result through `i64`: printing an `int` goes // through `strconv.format_int`, which does not handle `min_i64` yet. fn printable(typ string, expr string) string { - return if typ == 'isize' { 'i64(${expr})' } else { expr } + return if typ == 'int' { 'i64(${expr})' } else { expr } } fn overflow_ops_source() string { @@ -332,9 +332,9 @@ const cast_pairs = [ ['i16', 'u16']!, ['i32', 'i16']!, ['u8', 'i8']!, - ['int', 'usize']!, - ['usize', 'u32']!, - ['isize', 'i8']!, + ['int', 'uint']!, + ['uint', 'u32']!, + ['int', 'i8']!, ['i8', 'i64']!, ['u32', 'i64']!, ['u8', 'u16']!, @@ -349,7 +349,7 @@ fn casts_source() string { } sb << 'fn literal_cast() u8 {\n\treturn u8(-1)\n}\n' sb << 'fn literal_not_cast() u64 {\n\treturn u64(~0)\n}\n' - sb << 'fn big_literal_casts() string {\n\treturn "\${u64(0x8000000000000000)} \${u64(18446744073709551615)} \${u64(0xcbf29ce484222325)} \${u64((0xffff_ffff_ffff_ffff))} \${u32(0xffffffff)} \${usize(0xffffffff)} \${i8(0x7f)} \${u16(0b1111111111111111)}"\n}\n' + sb << 'fn big_literal_casts() string {\n\treturn "\${u64(0x8000000000000000)} \${u64(18446744073709551615)} \${u64(0xcbf29ce484222325)} \${u64((0xffff_ffff_ffff_ffff))} \${u32(0xffffffff)} \${uint(0xffffffff)} \${i8(0x7f)} \${u16(0b1111111111111111)}"\n}\n' sb << 'fn alias_cast(x i64) Byte {\n\treturn Byte(x)\n}\n' sb << '@[ignore_overflow]\nfn ignored_cast(x i64) u8 {\n\treturn u8(x)\n}\n' sb << 'fn main() {\n\tkind := os.args[1]\n\ta := os.args[2]\n\tmatch kind {' @@ -386,7 +386,7 @@ fn casts_cases(checked bool) []OpCase { ['i16', 'u16', '-1', '65535'], ['i32', 'i16', '32768', '-32768'], ['u8', 'i8', '128', '-128'], - ['isize', 'i8', '-200', '56'], + ['int', 'i8', '-200', '56'], ] fitting := [ ['i64', 'i8', '127'], @@ -402,7 +402,7 @@ fn casts_cases(checked bool) []OpCase { ['i16', 'u16', '32767'], ['i32', 'i16', '-32768'], ['u8', 'i8', '127'], - ['int', 'usize', '0'], + ['int', 'uint', '0'], ['i8', 'i64', '-128'], ['u32', 'i64', '4294967295'], ['u8', 'u16', '255'], @@ -419,11 +419,11 @@ fn casts_cases(checked bool) []OpCase { cases << ok_case(c[3], '${c[0]}_${c[1]}', c[2]) } } - if int_type_bits('usize') == 64 { + if int_type_bits('uint') == 64 { if checked { - cases << panic_case('attempt to cast with overflow(usize(int(-1)))', 'int_usize', + cases << panic_case('attempt to cast with overflow(uint(int(-1)))', 'int_usize', '-1') - cases << panic_case('attempt to cast with overflow(u32(usize(4294967296)))', + cases << panic_case('attempt to cast with overflow(u32(uint(4294967296)))', 'usize_u32', '4294967296') } else { cases << ok_case('18446744073709551615', 'int_usize', '-1') diff --git a/vlib/v/tests/builtin_strings_and_interpolation/string_interpolation_struct_with_usize_field_test.v b/vlib/v/tests/builtin_strings_and_interpolation/string_interpolation_struct_with_usize_field_test.v index 5dc8085743..406a347ad6 100644 --- a/vlib/v/tests/builtin_strings_and_interpolation/string_interpolation_struct_with_usize_field_test.v +++ b/vlib/v/tests/builtin_strings_and_interpolation/string_interpolation_struct_with_usize_field_test.v @@ -1,17 +1,17 @@ struct StructWithUsizeField { - f_usize usize + f_usize uint f_u64 u64 f_u32 u32 - f_isize isize + f_isize int f_i64 i64 f_i32 i32 } fn test_stringified_usize_field_should_be_always_positive() { a := StructWithUsizeField{ - f_usize: usize(-1) - f_isize: isize(-1) + f_usize: uint(-1) + f_isize: int(-1) f_u64: u64(-1) f_i64: i64(-1) f_u32: u32(-1) @@ -22,11 +22,11 @@ fn test_stringified_usize_field_should_be_always_positive() { assert sa.contains('f_isize: -1') assert sa.contains('f_i64: -1') assert sa.contains('f_i32: -1') - i := sa.split_into_lines().filter(it.contains('isize'))[0] + i := sa.split_into_lines().filter(it.contains('int'))[0] assert i.contains('-'), 'all `i` fields should be negative, but ${i} != ${a.f_isize}' assert sa.contains('f_u64: 18446744073709551615') assert sa.contains('f_u32: 4294967295') - u := sa.split_into_lines().filter(it.contains('usize'))[0] + u := sa.split_into_lines().filter(it.contains('uint'))[0] assert !u.contains('-'), 'all `u` fields should be positive, but ${u} != ${a.f_usize}' } diff --git a/vlib/v/tests/byte_as_sizeof_local_test.v b/vlib/v/tests/byte_as_sizeof_local_test.v index adf50558b1..9106953eb9 100644 --- a/vlib/v/tests/byte_as_sizeof_local_test.v +++ b/vlib/v/tests/byte_as_sizeof_local_test.v @@ -4,7 +4,7 @@ struct Pair { b u64 } -fn param_width(byte u16) usize { +fn param_width(byte u16) uint { return sizeof(byte) } diff --git a/vlib/v/tests/c_function_mut_param/code_test.c.v b/vlib/v/tests/c_function_mut_param/code_test.c.v index ae121a7ff5..7d30758845 100644 --- a/vlib/v/tests/c_function_mut_param/code_test.c.v +++ b/vlib/v/tests/c_function_mut_param/code_test.c.v @@ -2,11 +2,11 @@ module main #include "@VMODROOT/code.c" -fn C.mut_arg(key &u8, mut val usize) +fn C.mut_arg(key &u8, mut val uint) fn test_c_function_mut_param() { key := unsafe { &u8(1) } - mut val := usize(1) + mut val := uint(1) C.mut_arg(key, mut &val) - assert val == usize(5) + assert val == uint(5) } diff --git a/vlib/v/tests/c_function_mut_param/option_args_test.c.v b/vlib/v/tests/c_function_mut_param/option_args_test.c.v index 5042128a64..8c978a683c 100644 --- a/vlib/v/tests/c_function_mut_param/option_args_test.c.v +++ b/vlib/v/tests/c_function_mut_param/option_args_test.c.v @@ -2,11 +2,11 @@ module main #include "@VMODROOT/code.c" -fn C.mut_arg(&u8, mut val usize) +fn C.mut_arg(&u8, mut val uint) fn test_c_function_mut_param() { key := unsafe { &u8(1) } - mut val := usize(1) + mut val := uint(1) C.mut_arg(key, mut &val) - assert val == usize(5) + assert val == uint(5) } diff --git a/vlib/v/tests/c_variadic_unqualified_call_28883/cvariadic28883/cvariadic28883.c.v b/vlib/v/tests/c_variadic_unqualified_call_28883/cvariadic28883/cvariadic28883.c.v index 49e7d5127d..364ff7364f 100644 --- a/vlib/v/tests/c_variadic_unqualified_call_28883/cvariadic28883/cvariadic28883.c.v +++ b/vlib/v/tests/c_variadic_unqualified_call_28883/cvariadic28883/cvariadic28883.c.v @@ -8,7 +8,7 @@ struct C.va_list {} fn C.va_start(voidptr, voidptr) fn C.va_end(voidptr) -fn C.vsnprintf(buf &char, size usize, fmt &char, ap C.va_list) int +fn C.vsnprintf(buf &char, size uint, fmt &char, ap C.va_list) int // cvariadic28883 shares its module's name, like the fn in the issue, and // forwards its C-style variadic args to vsnprintf. diff --git a/vlib/v/tests/call_unsafe_if_arg_order_test.v b/vlib/v/tests/call_unsafe_if_arg_order_test.v index 82ac179953..9cc3340bfe 100644 --- a/vlib/v/tests/call_unsafe_if_arg_order_test.v +++ b/vlib/v/tests/call_unsafe_if_arg_order_test.v @@ -1,11 +1,11 @@ fn describe(target voidptr, format &u8, args ...voidptr) string { - return '${usize(target)}:${unsafe { cstring_to_vstring(format) }}:${args.len}' + return '${uint(target)}:${unsafe { cstring_to_vstring(format) }}:${args.len}' } // An argument before an `unsafe { if ... }` argument is evaluated into a temporary // first (source order); that temporary must stay declared before the call. fn test_argument_before_an_unsafe_if_value() { - target := voidptr(usize(7)) + target := voidptr(uint(7)) mut results := []string{} for cond in [true, false] { if !cond { diff --git a/vlib/v/tests/casts/cast_interface_value_in_match_test.v b/vlib/v/tests/casts/cast_interface_value_in_match_test.v index 36db8ddf83..d50a63b9a7 100644 --- a/vlib/v/tests/casts/cast_interface_value_in_match_test.v +++ b/vlib/v/tests/casts/cast_interface_value_in_match_test.v @@ -2,8 +2,8 @@ interface Number2 {} fn t(v Number2) { match v { - int, i32, isize, i64 { - x := isize(v) + int, i32, int, i64 { + x := int(v) println(x) assert x == 42 } @@ -12,7 +12,7 @@ fn t(v Number2) { match v { int { - x := isize(v) + x := int(v) println(x) assert x == 42 } diff --git a/vlib/v/tests/casts/translated_alias_casts/main_test.v b/vlib/v/tests/casts/translated_alias_casts/main_test.v index 25af76f41c..629b1b7a67 100644 --- a/vlib/v/tests/casts/translated_alias_casts/main_test.v +++ b/vlib/v/tests/casts/translated_alias_casts/main_test.v @@ -7,9 +7,9 @@ fn cast_with_shadow(uintptr_t fn (int) int) int { fn test_translated_lowercase_alias_casts() { value := uintptr_t(42) - assert usize(value) == 42 + assert uint(value) == 42 pointer := &value - assert usize(uintptr_t(pointer)) == usize(pointer) + assert uint(uintptr_t(pointer)) == uint(pointer) assert Elf64_Addr(uintptr_t(42)) == Elf64_Addr(42) assert cast_with_shadow(fn (x int) int { return x + 1 }) == 42 } @@ -47,7 +47,7 @@ mut: fn test_translated_lowercase_pointer_casts() { zero := &debug_info(0) assert zero == unsafe { nil } - raw := unsafe { vcalloc(sizeof(debug_info)) } + raw := unsafe { vcalloc(int(sizeof(debug_info))) } defer { unsafe { free(raw) } } mut pointer := &debug_info(raw) pointer.value = 42 diff --git a/vlib/v/tests/casts/translated_alias_casts/types.v b/vlib/v/tests/casts/translated_alias_casts/types.v index 92bf0ae4e5..a7550bffc3 100644 --- a/vlib/v/tests/casts/translated_alias_casts/types.v +++ b/vlib/v/tests/casts/translated_alias_casts/types.v @@ -1,5 +1,5 @@ @[translated] module main -type uintptr_t = usize +type uintptr_t = uint type Elf64_Addr = u64 diff --git a/vlib/v/tests/clash_var_fn_name_test.v b/vlib/v/tests/clash_var_fn_name_test.v index 52877f69ea..e612047279 100644 --- a/vlib/v/tests/clash_var_fn_name_test.v +++ b/vlib/v/tests/clash_var_fn_name_test.v @@ -197,12 +197,12 @@ fn test_u64() { } fn test_isize() { - isize_ := isize(0) + isize_ := int(0) isize_str := isize_.str() } fn test_usize() { - usize_ := usize(0) + usize_ := uint(0) usize_str := usize_.str() } diff --git a/vlib/v/tests/comptime/comptime_zero_pointer_is_typed_test.v b/vlib/v/tests/comptime/comptime_zero_pointer_is_typed_test.v index db61e4faef..4c2bc059f9 100644 --- a/vlib/v/tests/comptime/comptime_zero_pointer_is_typed_test.v +++ b/vlib/v/tests/comptime/comptime_zero_pointer_is_typed_test.v @@ -2,7 +2,7 @@ // type from it (not `voidptr`), and a generic can recurse over `pointee_type`. fn new_pointer_to[T](value T) &T { - mut ptr := unsafe { &T(vcalloc(sizeof(T))) } + mut ptr := unsafe { &T(vcalloc(int(sizeof(T)))) } unsafe { *ptr = value } diff --git a/vlib/v/tests/fixed_array_mut_arg_escape_test.v b/vlib/v/tests/fixed_array_mut_arg_escape_test.v index 14af95d71c..8f475e5cbf 100644 --- a/vlib/v/tests/fixed_array_mut_arg_escape_test.v +++ b/vlib/v/tests/fixed_array_mut_arg_escape_test.v @@ -538,8 +538,8 @@ struct AlignedFixedHolder { fn observe_aligned_fixed(values &[]AlignedFixedItem) { unsafe { - assert usize(&values[0]) % 64 == 0 - assert usize(&values[1]) % 64 == 0 + assert uint(&values[0]) % 64 == 0 + assert uint(&values[1]) % 64 == 0 } } diff --git a/vlib/v/tests/fns/closure_mut_receiver_reference_assignment_test.v b/vlib/v/tests/fns/closure_mut_receiver_reference_assignment_test.v index e7f329e950..1b18b0a1bd 100644 --- a/vlib/v/tests/fns/closure_mut_receiver_reference_assignment_test.v +++ b/vlib/v/tests/fns/closure_mut_receiver_reference_assignment_test.v @@ -136,8 +136,8 @@ fn (mut receiver CapturedHeapReceiver) setup_with_value_blocks() { mut explicit := unsafe { &CapturedHeapReceiver(receiver) } assert typeof(explicit).name == '&CapturedHeapReceiver' explicit.bump(10000) - address := unsafe { usize(receiver) } - assert address == unsafe { usize(explicit) } + address := unsafe { uint(receiver) } + assert address == unsafe { uint(explicit) } }() } diff --git a/vlib/v/tests/gc_boehm_leak_array_displacement_test.v b/vlib/v/tests/gc_boehm_leak_array_displacement_test.v index 49e04e6eba..2941f07b34 100644 --- a/vlib/v/tests/gc_boehm_leak_array_displacement_test.v +++ b/vlib/v/tests/gc_boehm_leak_array_displacement_test.v @@ -7,7 +7,7 @@ // by default, so a collection freed array blocks that a heap object still used, // and the next free() of one aborted with "Invalid pointer passed to free()". fn C.GC_base(voidptr) voidptr -fn C.GC_size(voidptr) usize +fn C.GC_size(voidptr) uint fn C.GC_gcollect() fn C.GC_noop1(u64) fn C.GC_get_all_interior_pointers() int @@ -65,7 +65,7 @@ fn array_block_intact(holder &ArrayHolder) bool { if base == unsafe { nil } { return false } - return C.GC_size(base) >= usize(block_ints * sizeof(int)) && u64(block) - u64(base) < 256 + return C.GC_size(base) >= uint(block_ints * sizeof(int)) && u64(block) - u64(base) < 256 } fn test_boehm_leak_recognises_interior_pointers() { diff --git a/vlib/v/tests/gc_free_space_divisor_test.v b/vlib/v/tests/gc_free_space_divisor_test.v index 6872753149..7cdbaafd60 100644 --- a/vlib/v/tests/gc_free_space_divisor_test.v +++ b/vlib/v/tests/gc_free_space_divisor_test.v @@ -8,7 +8,7 @@ import os @[c_extern] -fn C.GC_get_free_space_divisor() usize +fn C.GC_get_free_space_divisor() uint fn test_free_space_divisor_is_tuned_for_throughput() { $if gcboehm_opt ? { diff --git a/vlib/v/tests/generic_call_shift_if_operand_test.v b/vlib/v/tests/generic_call_shift_if_operand_test.v index 116967b1c0..785ad86c24 100644 --- a/vlib/v/tests/generic_call_shift_if_operand_test.v +++ b/vlib/v/tests/generic_call_shift_if_operand_test.v @@ -2,7 +2,7 @@ struct Column { from i32 } -fn column_at[T](base &T, index isize) &T { +fn column_at[T](base &T, index int) &T { return unsafe { base + index } } diff --git a/vlib/v/tests/generics/generic_call_result_in_generic_body_test.v b/vlib/v/tests/generics/generic_call_result_in_generic_body_test.v index 85c9fd51a9..ad1eb20ad0 100644 --- a/vlib/v/tests/generics/generic_call_result_in_generic_body_test.v +++ b/vlib/v/tests/generics/generic_call_result_in_generic_body_test.v @@ -13,7 +13,7 @@ fn store[T](mut destination T, value T) { struct Counter[T] { mut: - value usize + value uint } fn (mut c Counter[T]) step() { @@ -21,7 +21,7 @@ fn (mut c Counter[T]) step() { store(mut &c.value, (value + 1) & 7) } -fn bitwise_ops[T](start usize) usize { +fn bitwise_ops[T](start uint) uint { mut v := start value := load(&v) store(mut &v, value | 8) diff --git a/vlib/v/tests/generics/generics_for_in_iterate_test.v b/vlib/v/tests/generics/generics_for_in_iterate_test.v index 6372136b5a..f2bf3dd1b8 100644 --- a/vlib/v/tests/generics/generics_for_in_iterate_test.v +++ b/vlib/v/tests/generics/generics_for_in_iterate_test.v @@ -1,8 +1,8 @@ pub struct Vec[T] { mut: - data &T @[required] - cap usize @[required] - len usize @[required] + data &T @[required] + cap uint @[required] + len uint @[required] } pub fn new[T]() Vec[T] { @@ -22,7 +22,7 @@ pub fn (ar &Vec[T]) iter() Iter[T] { pub struct Iter[T] { mut: v &Vec[T] @[required] - pos usize + pos uint } pub fn (mut iter Iter[T]) next() ?&T { diff --git a/vlib/v/tests/index_expr_any_int_index_test.v b/vlib/v/tests/index_expr_any_int_index_test.v index 81fb653857..65145460d7 100644 --- a/vlib/v/tests/index_expr_any_int_index_test.v +++ b/vlib/v/tests/index_expr_any_int_index_test.v @@ -4,7 +4,7 @@ fn test_array_indices_accept_any_integer_type() { idx_u32 := u32(1) idx_u64 := u64(1) idx_i64 := i64(1) - idx_usize := usize(1) + idx_usize := uint(1) assert a[idx_u32] == 2 assert a[idx_u64] == 2 diff --git a/vlib/v/tests/int128/mixed_width_test.v b/vlib/v/tests/int128/mixed_width_test.v index 29eb1d000a..89564d0fc7 100644 --- a/vlib/v/tests/int128/mixed_width_test.v +++ b/vlib/v/tests/int128/mixed_width_test.v @@ -31,8 +31,8 @@ fn test_wide_values_survive_the_sizes_and_runes() { // The low 64 bits are what the sizes carry, so the test value keeps a visible // low-bit pattern instead of being a power of two. x := (u128(1) << 100) + u128(0x1122334455667788) - assert isize(x) == isize(1234605616436508552) - assert usize(x) == usize(1234605616436508552) + assert int(x) == int(1234605616436508552) + assert uint(x) == uint(1234605616436508552) assert rune(x) == rune(1432778632) } diff --git a/vlib/v/tests/integer_size_test.v b/vlib/v/tests/integer_size_test.v index 6794e11cbc..9b02207347 100644 --- a/vlib/v/tests/integer_size_test.v +++ b/vlib/v/tests/integer_size_test.v @@ -1,8 +1,8 @@ -fn f(u usize) usize -fn g(i isize) isize +fn f(u uint) uint +fn g(i int) int fn test_usize() { - mut u := usize(3) + mut u := uint(3) u += u32(1) assert u == 4 u = 4 @@ -10,12 +10,12 @@ fn test_usize() { assert u == 5 assert u.str() == '5' $if x64 { - assert '${usize(0x140000000):X}' == '140000000' + assert '${uint(0x140000000):X}' == '140000000' } } fn test_isize() { - mut i := isize(-3) + mut i := int(-3) i -= int(1) assert i == -4 i = -5 @@ -23,6 +23,6 @@ fn test_isize() { assert i == -3 assert i.str() == '-3' $if x64 { - assert '${isize(0x140000000):X}' == '140000000' + assert '${int(0x140000000):X}' == '140000000' } } diff --git a/vlib/v/tests/interfaces/big_array_allocation_test.v b/vlib/v/tests/interfaces/big_array_allocation_test.v index eaa505acab..eaf87b597d 100644 --- a/vlib/v/tests/interfaces/big_array_allocation_test.v +++ b/vlib/v/tests/interfaces/big_array_allocation_test.v @@ -2,9 +2,9 @@ import os @[direct_array_access] fn test_big_int_array() { - dump(sizeof(isize)) + dump(sizeof(int)) mut maxn := 500_000_000 // try allocating ~2GB worth of integers on 32bit platforms - if sizeof(isize) > 4 { + if sizeof(int) > 4 { maxn = 1_000_000_000 // 1 billion integers, when each is 4 bytes => require ~4GB } // NB: this test requires RAM that many people do not have, so only run it in full, when VTEST_BIGMEM is 1 diff --git a/vlib/v/tests/interfaces/interface_readonly_cast_test.v b/vlib/v/tests/interfaces/interface_readonly_cast_test.v index a6b10fe7c7..a1553ac2b4 100644 --- a/vlib/v/tests/interfaces/interface_readonly_cast_test.v +++ b/vlib/v/tests/interfaces/interface_readonly_cast_test.v @@ -8,8 +8,8 @@ mut: id int symbol rune bytecode char - signed_size isize - unsigned_size usize + signed_size int + unsigned_size uint tone WidgetTone } @@ -22,8 +22,8 @@ mut: id int symbol rune bytecode char - signed_size isize - unsigned_size usize + signed_size int + unsigned_size uint tone WidgetTone } @@ -33,9 +33,9 @@ fn (w &Widget) read_symbol() rune { return w.symbol } fn (w &Widget) read_bytecode() char { return w.bytecode } -fn (w &Widget) read_signed_size() isize { return w.signed_size } +fn (w &Widget) read_signed_size() int { return w.signed_size } -fn (w &Widget) read_unsigned_size() usize { return w.unsigned_size } +fn (w &Widget) read_unsigned_size() uint { return w.unsigned_size } fn (w &Widget) read_tone() WidgetTone { return w.tone } diff --git a/vlib/v/tests/options/option_generic_method_ret_ptr_none_assert_test.v b/vlib/v/tests/options/option_generic_method_ret_ptr_none_assert_test.v index 272d30964e..9999b0b5e8 100644 --- a/vlib/v/tests/options/option_generic_method_ret_ptr_none_assert_test.v +++ b/vlib/v/tests/options/option_generic_method_ret_ptr_none_assert_test.v @@ -27,7 +27,7 @@ mut: struct LinkedList21559[T] { mut: - size usize + size uint head ?&Node21559[T] } diff --git a/vlib/v/tests/options/option_ptr_unwrap_test.v b/vlib/v/tests/options/option_ptr_unwrap_test.v index efbf600b6c..cfce68874b 100644 --- a/vlib/v/tests/options/option_ptr_unwrap_test.v +++ b/vlib/v/tests/options/option_ptr_unwrap_test.v @@ -11,7 +11,7 @@ mut: struct LinkedList[T] { mut: - size usize + size uint head ?&Node[T] } diff --git a/vlib/v/tests/options/option_selector_unwrap_test.v b/vlib/v/tests/options/option_selector_unwrap_test.v index 78cd0b407c..52858a0b85 100644 --- a/vlib/v/tests/options/option_selector_unwrap_test.v +++ b/vlib/v/tests/options/option_selector_unwrap_test.v @@ -1,6 +1,6 @@ import datatypes { DoublyLinkedList } -pub type LayoutBoxId = usize +pub type LayoutBoxId = uint pub struct LayoutBox { } diff --git a/vlib/v/tests/pointers/aligned_array_allocation_family_test.c.v b/vlib/v/tests/pointers/aligned_array_allocation_family_test.c.v index b5ca4e4037..fb1d59cf1e 100644 --- a/vlib/v/tests/pointers/aligned_array_allocation_family_test.c.v +++ b/vlib/v/tests/pointers/aligned_array_allocation_family_test.c.v @@ -1,6 +1,6 @@ #include -fn C.malloc(size usize) voidptr +fn C.malloc(size uint) voidptr fn C.free(value voidptr) @[aligned: 8] @@ -31,7 +31,7 @@ fn test_aligned_array_cast_keeps_the_c_allocation_family() { } fn test_aligned_array_cast_and_literal_share_the_v_allocation_family() { - mut cells := unsafe { &AllocatorAlignedCells(malloc(sizeof(AllocatorAlignedCells))) } + mut cells := unsafe { &AllocatorAlignedCells(malloc(int(sizeof(AllocatorAlignedCells)))) } assert cells != unsafe { nil } unsafe { cells[0] = AllocatorAlignedCell{ value: 31 } @@ -51,7 +51,7 @@ type AllocatorCacheLines = [2]AllocatorCacheLine fn test_aligned_literal_keeps_alignment_with_the_selected_allocator() { mut cells := &AllocatorCacheLines{} - assert usize(voidptr(cells)) % 64 == 0 + assert uint(voidptr(cells)) % 64 == 0 unsafe { cells[0] = AllocatorCacheLine{ value: 43 } cells[1] = AllocatorCacheLine{ value: 47 } diff --git a/vlib/v/tests/pointers/translated_fixed_array_first_element_test.c.v b/vlib/v/tests/pointers/translated_fixed_array_first_element_test.c.v index fd46efdeea..1144228416 100644 --- a/vlib/v/tests/pointers/translated_fixed_array_first_element_test.c.v +++ b/vlib/v/tests/pointers/translated_fixed_array_first_element_test.c.v @@ -3,7 +3,7 @@ @[has_globals; translated] module main -fn C.strlen(&i8) usize +fn C.strlen(&i8) uint __global c2v_buf [16]i8 __global c2v_buf_offset = unsafe { &c2v_buf[0] } + 3 @@ -16,7 +16,7 @@ struct C2vHolder { __global c2v_holder C2vHolder __global c2v_field_offset = unsafe { &c2v_holder.vals[0] } + 2 -fn c2v_copy(out &i8, in_ &i8, num usize) &i8 { +fn c2v_copy(out &i8, in_ &i8, num uint) &i8 { C.memcpy(voidptr(out), voidptr(in_), num) out[num] = 0 return out @@ -29,11 +29,11 @@ fn c2v_offsets(s &C2vHolder, n int, flag int) int { q := 2 + unsafe { &c2v_buf[0] } c2v_copy(unsafe { &i8(&c2v_buf[0]) }, c'hello', if flag != 0 { 3 } else { 4 }) e := unsafe { &c2v_buf[0] } + C.strlen(unsafe { &i8(&c2v_buf[0]) }) - k := int(i64((isize(e) - isize(unsafe { &c2v_buf[0] })) / isize(sizeof(i8)))) + k := int(i64((int(e) - int(unsafe { &c2v_buf[0] })) / int(sizeof(i8)))) assert k == if flag != 0 { 3 } else { 4 } assert unsafe { *q } == `l` return int(unsafe { *r } + unsafe { *t }) + - int(i64((isize(u) - isize(unsafe { &s.name[0] })) / isize(sizeof(i8)))) + int(i64((int(u) - int(unsafe { &s.name[0] })) / int(sizeof(i8)))) } fn test_translated_first_element_arithmetic() { @@ -49,6 +49,6 @@ fn test_translated_global_initializers() { assert unsafe { *c2v_buf_offset } == 9 c2v_holder.vals[2] = 5 assert unsafe { *c2v_field_offset } == 5 - d := i64((isize(c2v_field_offset) - isize(unsafe { &c2v_holder.vals[0] })) / isize(sizeof(int))) + d := i64((int(c2v_field_offset) - int(unsafe { &c2v_holder.vals[0] })) / int(sizeof(int))) assert d == 2 } diff --git a/vlib/v/tests/pointers/voidptr_callback_lookup_test.v b/vlib/v/tests/pointers/voidptr_callback_lookup_test.v index 8431a2105e..0589bbd262 100644 --- a/vlib/v/tests/pointers/voidptr_callback_lookup_test.v +++ b/vlib/v/tests/pointers/voidptr_callback_lookup_test.v @@ -2,10 +2,10 @@ // caller mutate separately stored components at an explicit unsafe boundary. struct Container { mut: - on_query fn (&Container, usize) voidptr = unsafe { nil } + on_query fn (&Container, uint) voidptr = unsafe { nil } } -fn (c &Container) query(idx usize) voidptr { +fn (c &Container) query(idx uint) voidptr { return c.on_query(c, idx) } @@ -16,7 +16,7 @@ mut: } fn Counter.from_container(c &Container) &Counter { - return unsafe { &Counter(c.query(usize(typeof(Counter{}).idx))) } + return unsafe { &Counter(c.query(uint(typeof(Counter{}).idx))) } } fn bump(c &Container) { @@ -28,7 +28,7 @@ fn bump(c &Container) { fn test_component_from_immutable_container_is_mutable() { counter := &Counter{} c := Container{ - on_query: fn [counter] (_ &Container, _ usize) voidptr { + on_query: fn [counter] (_ &Container, _ uint) voidptr { return voidptr(counter) } } @@ -58,14 +58,14 @@ fn test_visible_stored_pointer_lookup_does_not_borrow_the_container() { assert counter.hits == 13 } -fn counter_by_key(key usize, get fn (usize) voidptr) &Counter { +fn counter_by_key(key uint, get fn (uint) voidptr) &Counter { return get(key) } fn test_type_erased_lookup_with_copied_key_does_not_borrow_the_key() { - key := usize(7) + key := uint(7) counter := &Counter{} - get := fn [counter] (idx usize) voidptr { + get := fn [counter] (idx uint) voidptr { assert idx == 7 return counter } diff --git a/vlib/v/tests/reflection_test.v b/vlib/v/tests/reflection_test.v index afb12d5c76..cd26894c5e 100644 --- a/vlib/v/tests/reflection_test.v +++ b/vlib/v/tests/reflection_test.v @@ -102,3 +102,11 @@ fn test_ref() { ptr_user := &User{} assert reflection.type_of(ptr_user).str().contains("name: 'User'") } + +fn test_platform_integer_kinds_preserve_legacy_ordinals() { + assert int(reflection.VKind.int) == 9 + assert int(reflection.VKind.isize) == 10 + assert reflection.type_of(42).sym.kind == .int + assert reflection.type_of(isize(-42)).sym.kind == .isize + assert reflection.type_of(uint(42)).sym.kind == .uint +} diff --git a/vlib/v/tests/sizeof_2_test.v b/vlib/v/tests/sizeof_2_test.v index a7b8041757..36ab73ae8d 100644 --- a/vlib/v/tests/sizeof_2_test.v +++ b/vlib/v/tests/sizeof_2_test.v @@ -4,7 +4,7 @@ fn getsize[P]() u32 { return sizeof(P) } -fn accept_usize(value usize) usize { +fn accept_usize(value uint) uint { return value } diff --git a/vlib/v/tests/sizeof_expr_call_args_test.c.v b/vlib/v/tests/sizeof_expr_call_args_test.c.v index 05d9587190..8f46722eb6 100644 --- a/vlib/v/tests/sizeof_expr_call_args_test.c.v +++ b/vlib/v/tests/sizeof_expr_call_args_test.c.v @@ -1,14 +1,14 @@ #include -fn C.memset(dest voidptr, value int, count usize) voidptr +fn C.memset(dest voidptr, value int, count uint) voidptr -fn expression_byte_count(value usize) usize { +fn expression_byte_count(value uint) uint { return value } struct SizeReceiver {} -fn (receiver SizeReceiver) byte_count(value usize) usize { +fn (receiver SizeReceiver) byte_count(value uint) uint { return value } diff --git a/vlib/v/tests/sizeof_module_global_28888/globals28888/globals28888.v b/vlib/v/tests/sizeof_module_global_28888/globals28888/globals28888.v index dbf3a4f3f5..1eb2fa1c01 100644 --- a/vlib/v/tests/sizeof_module_global_28888/globals28888/globals28888.v +++ b/vlib/v/tests/sizeof_module_global_28888/globals28888/globals28888.v @@ -17,31 +17,31 @@ __global blob [5]u16 const bar_bytes = sizeof(bar) // bar_size returns the size of the unqualified module global `bar`. -pub fn bar_size() usize { +pub fn bar_size() uint { return sizeof(bar) } // point_size returns the size of the struct-typed module global `point`. -pub fn point_size() usize { +pub fn point_size() uint { return sizeof(point) } // sum_size combines `sizeof` of two module globals in one expression. -pub fn sum_size() usize { +pub fn sum_size() uint { return sizeof(bar) + sizeof(count) } // const_size returns a module const initialized from `sizeof` of a global. -pub fn const_size() usize { +pub fn const_size() uint { return bar_bytes } // generic_size mixes `sizeof` of a module global with a generic parameter. -pub fn generic_size[T](value T) usize { +pub fn generic_size[T](value T) uint { return sizeof(bar) + sizeof(value) } // exported_size returns the size of a global declared under an export name. -pub fn exported_size() usize { +pub fn exported_size() uint { return sizeof(blob) } diff --git a/vlib/v/tests/structs/struct_aligned_test.v b/vlib/v/tests/structs/struct_aligned_test.v index 676916eaad..3f9dd73608 100644 --- a/vlib/v/tests/structs/struct_aligned_test.v +++ b/vlib/v/tests/structs/struct_aligned_test.v @@ -24,5 +24,5 @@ fn aligned_struct_pointer() &MyStruct { fn test_promoted_struct_preserves_alignment() { value := aligned_struct_pointer() assert value.a == 42 - assert usize(voidptr(value)) % 512 == 0 + assert uint(voidptr(value)) % 512 == 0 } diff --git a/vlib/v/tests/sumtypes/sum_type_aligned_default_field_test.v b/vlib/v/tests/sumtypes/sum_type_aligned_default_field_test.v index bec1b3d29e..39025708b8 100644 --- a/vlib/v/tests/sumtypes/sum_type_aligned_default_field_test.v +++ b/vlib/v/tests/sumtypes/sum_type_aligned_default_field_test.v @@ -15,7 +15,7 @@ mut: } fn default_aligned_value(value &DefaultAlignedSum) int { - assert usize(voidptr(value)) % 64 == 0 + assert uint(voidptr(value)) % 64 == 0 return value.value } diff --git a/vlib/v/tests/sumtypes/sum_type_aligned_storage_test.v b/vlib/v/tests/sumtypes/sum_type_aligned_storage_test.v index 506aba673a..bd12361c98 100644 --- a/vlib/v/tests/sumtypes/sum_type_aligned_storage_test.v +++ b/vlib/v/tests/sumtypes/sum_type_aligned_storage_test.v @@ -18,7 +18,7 @@ struct AlignedSumHolder { fn test_explicit_sum_references_inherit_variant_alignment() { for i in 0 .. 64 { value := &AlignedSum(SumSmallValue{i}) - assert usize(voidptr(value)) % 64 == 0 + assert uint(voidptr(value)) % 64 == 0 assert value is SumSmallValue assert value.value == i } @@ -26,16 +26,16 @@ fn test_explicit_sum_references_inherit_variant_alignment() { fn test_sum_aliases_and_containing_values_inherit_alignment() { value := &AlignedSumAlias(SumSmallValue{5}) - assert usize(voidptr(value)) % 64 == 0 + assert uint(voidptr(value)) % 64 == 0 holder := &AlignedSumHolder{ value: SumSmallValue{7} } - assert usize(voidptr(holder)) % 64 == 0 + assert uint(voidptr(holder)) % 64 == 0 assert holder.value is SumSmallValue assert holder.value.value == 7 } fn test_fixed_arrays_of_sums_inherit_alignment() { values := &[2]AlignedSum{init: SumSmallValue{3}} - assert usize(voidptr(values)) % 64 == 0 + assert uint(voidptr(values)) % 64 == 0 for i in 0 .. 2 { assert (*values)[i] is SumSmallValue assert (*values)[i].value == 3 diff --git a/vlib/v/tests/testdata/builtin_overflow/gen_overflow_tests.vsh b/vlib/v/tests/testdata/builtin_overflow/gen_overflow_tests.vsh index c612cc6c71..16fc59e8e1 100644 --- a/vlib/v/tests/testdata/builtin_overflow/gen_overflow_tests.vsh +++ b/vlib/v/tests/testdata/builtin_overflow/gen_overflow_tests.vsh @@ -10,7 +10,7 @@ struct OverflowStruct { mid [2]string // mult by 10 every time, should overflow } -// TODO: add tests for `rune`,`int`,`isize`,`usize`. +// TODO: add tests for `rune`, `int`, `uint`. const overflows = [ OverflowStruct{ name: 'u8' diff --git a/vlib/v/tests/testdata/c_fn_module_returns/fallback/fallback.c.v b/vlib/v/tests/testdata/c_fn_module_returns/fallback/fallback.c.v index 2a08f35e4e..f552012bb9 100644 --- a/vlib/v/tests/testdata/c_fn_module_returns/fallback/fallback.c.v +++ b/vlib/v/tests/testdata/c_fn_module_returns/fallback/fallback.c.v @@ -2,7 +2,7 @@ module fallback // contains_b uses builtin's declaration without declaring or importing another one. pub fn contains_b(buf []u8) bool { - return unsafe { C.memchr(buf.data, int(`b`), usize(buf.len)) } != unsafe { nil } + return unsafe { C.memchr(buf.data, int(`b`), uint(buf.len)) } != unsafe { nil } } // return_type reports builtin's opaque return regardless of other modules' declarations. diff --git a/vlib/v/tests/testdata/c_fn_module_returns/opaque/opaque.c.v b/vlib/v/tests/testdata/c_fn_module_returns/opaque/opaque.c.v index c4a7f04fe9..070d9b74fe 100644 --- a/vlib/v/tests/testdata/c_fn_module_returns/opaque/opaque.c.v +++ b/vlib/v/tests/testdata/c_fn_module_returns/opaque/opaque.c.v @@ -1,10 +1,10 @@ module opaque -fn C.memchr(buf voidptr, c int, n usize) voidptr +fn C.memchr(buf voidptr, c int, n uint) voidptr // contains_b uses this module's opaque C return. pub fn contains_b(buf []u8) bool { - return unsafe { C.memchr(buf.data, int(`b`), usize(buf.len)) } != unsafe { nil } + return unsafe { C.memchr(buf.data, int(`b`), uint(buf.len)) } != unsafe { nil } } // return_type reports the C call type resolved by the checker. diff --git a/vlib/v/tests/testdata/c_fn_module_returns/typed/typed.c.v b/vlib/v/tests/testdata/c_fn_module_returns/typed/typed.c.v index d9a67ea5b8..9538824fce 100644 --- a/vlib/v/tests/testdata/c_fn_module_returns/typed/typed.c.v +++ b/vlib/v/tests/testdata/c_fn_module_returns/typed/typed.c.v @@ -1,11 +1,11 @@ module typed -fn C.memchr(buf &u8, c int, n usize) &u8 +fn C.memchr(buf &u8, c int, n uint) &u8 // index_of_lf computes a byte offset using this module's typed C return. pub fn index_of_lf(buf []u8) int { base := unsafe { &u8(buf.data) } - p := unsafe { C.memchr(base, int(`\n`), usize(buf.len)) } + p := unsafe { C.memchr(base, int(`\n`), uint(buf.len)) } if p == unsafe { nil } { return -1 } return int(unsafe { p - base }) } diff --git a/vlib/v/tests/translated_fixed_array_args_test.c.v b/vlib/v/tests/translated_fixed_array_args_test.c.v index 8544ccbb81..b9f20c229f 100644 --- a/vlib/v/tests/translated_fixed_array_args_test.c.v +++ b/vlib/v/tests/translated_fixed_array_args_test.c.v @@ -4,7 +4,7 @@ module main #include #include "@VMODROOT/vlib/v/tests/testdata/translated_fixed_array_args.h" -fn C.memset(dest voidptr, value int, count usize) voidptr +fn C.memset(dest voidptr, value int, count uint) voidptr fn sum(values &int) int { return unsafe { values[0] + values[1] } } diff --git a/vlib/v/tests/translated_fixed_array_ordering_test.c.v b/vlib/v/tests/translated_fixed_array_ordering_test.c.v index c061fce08e..23aa92b936 100644 --- a/vlib/v/tests/translated_fixed_array_ordering_test.c.v +++ b/vlib/v/tests/translated_fixed_array_ordering_test.c.v @@ -3,7 +3,7 @@ module main #include -fn C.memset(dest voidptr, value int, count usize) voidptr +fn C.memset(dest voidptr, value int, count uint) voidptr fn write_array_value(values &int, value int) { unsafe { *values = value } @@ -32,7 +32,7 @@ fn test_array_pointer_arguments_keep_the_original_storage() { assert values[0] == 44 mut bytes := [4]u8{} - C.memset(bytes, 23, if flag { usize(4) } else { usize(1) }) + C.memset(bytes, 23, if flag { uint(4) } else { uint(1) }) assert bytes == [u8(23), 23, 23, 23]! } diff --git a/vlib/v/tests/translated_scalar_promotions_test.v b/vlib/v/tests/translated_scalar_promotions_test.v index b4fed49a18..d86f31ea48 100644 --- a/vlib/v/tests/translated_scalar_promotions_test.v +++ b/vlib/v/tests/translated_scalar_promotions_test.v @@ -188,7 +188,7 @@ fn test_translated_boolean_indices_and_pointer_offsets() { assert *ptr == 11 mut raw := voidptr(ptr) raw += 1 - assert usize(raw) == usize(ptr) + 1 + assert uint(raw) == uint(ptr) + 1 raw -= 1 assert raw == voidptr(ptr) } @@ -213,7 +213,7 @@ fn test_translated_pointer_subtraction_retains_pointer_width() { start := unsafe { &values[0] } end := unsafe { &values[3] } delta := unsafe { end - start } - assert typeof(delta).name == 'isize' + assert typeof(delta).name == 'int' assert delta == 3 } diff --git a/vlib/v/tests/unsigned_right_shift_test.v b/vlib/v/tests/unsigned_right_shift_test.v index 2095a11a28..d6d8c264e6 100644 --- a/vlib/v/tests/unsigned_right_shift_test.v +++ b/vlib/v/tests/unsigned_right_shift_test.v @@ -6,12 +6,12 @@ const answer_u8 = u8(125) fn test_unsigned_right_shift_expr_isize_usize() { $if x32 { - assert isize(-5) >>> 1 == answer_u32 - assert usize(-5) >>> 1 == answer_u32 + assert int(-5) >>> 1 == answer_u32 + assert uint(-5) >>> 1 == answer_u32 } $if x64 { - assert isize(-5) >>> 1 == answer_u64 - assert usize(-5) >>> 1 == answer_u64 + assert int(-5) >>> 1 == answer_u64 + assert uint(-5) >>> 1 == answer_u64 } } diff --git a/vlib/v/tests/value_parameter_escape_allocation_test.v b/vlib/v/tests/value_parameter_escape_allocation_test.v index 68a26291f0..9cfe0f4071 100644 --- a/vlib/v/tests/value_parameter_escape_allocation_test.v +++ b/vlib/v/tests/value_parameter_escape_allocation_test.v @@ -145,20 +145,20 @@ struct EncodedAddressValue { value int } -type EncodedAddress = usize +type EncodedAddress = uint -type TaggedAddress = usize | string +type TaggedAddress = uint | string @[noinline] -fn encode_local_address(value int) usize { +fn encode_local_address(value int) uint { local := EncodedAddressValue{value} - return usize(&local.value) + return uint(&local.value) } @[noinline] -fn encode_local_address_as_signed(value int) isize { +fn encode_local_address_as_signed(value int) int { local := EncodedAddressValue{value} - return isize(&local.value) + return int(&local.value) } @[noinline] @@ -171,51 +171,51 @@ fn encode_local_address_through_alias(value int) u64 { @[noinline] fn encode_local_address_through_nested_casts(value int) u64 { local := EncodedAddressValue{value} - return u64(usize(&local.value)) + return u64(uint(&local.value)) } @[noinline] -fn encode_local_address_through_sum_type(value int) usize { +fn encode_local_address_through_sum_type(value int) uint { local := EncodedAddressValue{value} - tagged := TaggedAddress(usize(&local.value)) - return tagged as usize + tagged := TaggedAddress(uint(&local.value)) + return tagged as uint } -fn unavailable_encoded_address() !usize { +fn unavailable_encoded_address() !uint { return error('unavailable') } @[noinline] -fn encode_local_address_in_or_fallback(value int) usize { +fn encode_local_address_in_or_fallback(value int) uint { local := EncodedAddressValue{value} - return unavailable_encoded_address() or { usize(&local.value) } + return unavailable_encoded_address() or { uint(&local.value) } } @[noinline] -fn encode_parameter_address(value EncodedAddressValue) usize { - return usize(&value.value) +fn encode_parameter_address(value EncodedAddressValue) uint { + return uint(&value.value) } @[noinline] -fn encode_local_pointer_alias(value int) usize { +fn encode_local_pointer_alias(value int) uint { local := EncodedAddressValue{value} pointer := &local.value - return usize(pointer) + return uint(pointer) } @[noinline] -fn encode_local_address_through_option(value int) usize { +fn encode_local_address_through_option(value int) uint { local := EncodedAddressValue{value} - encoded := ?usize(usize(&local.value)) - return encoded or { usize(0) } + encoded := ?uint(uint(&local.value)) + return encoded or { uint(0) } } -fn encoded_unsigned_result(value &EncodedAddressValue) !usize { - return usize(&value.value) +fn encoded_unsigned_result(value &EncodedAddressValue) !uint { + return uint(&value.value) } -fn encoded_signed_result(value &EncodedAddressValue) !isize { - return isize(&value.value) +fn encoded_signed_result(value &EncodedAddressValue) !int { + return int(&value.value) } fn encoded_alias_result(value &EncodedAddressValue) !EncodedAddress { @@ -223,13 +223,13 @@ fn encoded_alias_result(value &EncodedAddressValue) !EncodedAddress { } @[noinline] -fn encode_parameter_through_unsigned_result(value EncodedAddressValue) usize { - return encoded_unsigned_result(&value) or { usize(0) } +fn encode_parameter_through_unsigned_result(value EncodedAddressValue) uint { + return encoded_unsigned_result(&value) or { uint(0) } } @[noinline] -fn encode_parameter_through_signed_result(value EncodedAddressValue) isize { - return encoded_signed_result(&value) or { isize(0) } +fn encode_parameter_through_signed_result(value EncodedAddressValue) int { + return encoded_signed_result(&value) or { int(0) } } @[noinline] @@ -275,7 +275,7 @@ fn encode_parameter_through_int_result(value EncodedAddressValue) int { } fn encoded_float_result(value &EncodedAddressValue) !f64 { - return f64(usize(&value.value)) + return f64(uint(&value.value)) } @[noinline] @@ -284,7 +284,7 @@ fn encode_parameter_through_float_result(value EncodedAddressValue) f64 { } fn encoded_halves_result(value &EncodedAddressValue) !(u32, u32) { - address := u64(usize(&value.value)) + address := u64(uint(&value.value)) return u32(address), u32(address >> 32) } @@ -341,13 +341,13 @@ fn test_integer_casts_keep_the_addressed_local_alive() { assert *(&int(u64_result)) == 956 assert *(&int(i64_result)) == 967 assert *(&int(int_result)) == 978 - assert *(&int(usize(float_result))) == 989 - assert *(&int(usize(halves))) == 990 + assert *(&int(uint(float_result))) == 989 + assert *(&int(uint(halves))) == 990 } } __global scalar_retained &EncodedAddressValue = unsafe { nil } -__global scalar_retained_bits usize +__global scalar_retained_bits uint type ScalarSuccess = bool @@ -362,7 +362,7 @@ struct ScalarCarrier { } struct ScalarEncodedCarrier { - bits usize + bits uint } @[noinline] @@ -440,7 +440,7 @@ fn scalar_retain_encoded(value ScalarEncodedCarrier) !bool { } @[noinline] -fn scalar_retain_pointee(value &usize) !bool { +fn scalar_retain_pointee(value &uint) !bool { scalar_retained_bits = unsafe { *value } return true } @@ -563,14 +563,14 @@ fn scalar_carrier_wrapper(seed int) bool { @[noinline] fn scalar_encoded_field_wrapper(seed int) bool { local := EncodedAddressValue{seed} - carrier := ScalarEncodedCarrier{usize(&local.value)} + carrier := ScalarEncodedCarrier{uint(&local.value)} return scalar_retain_encoded(carrier) or { false } } @[noinline] fn scalar_encoded_pointee_wrapper(seed int) bool { local := EncodedAddressValue{seed} - bits := usize(&local.value) + bits := uint(&local.value) return scalar_retain_pointee(&bits) or { false } } diff --git a/vlib/v/tests/vls/sample_mod1/sample.v b/vlib/v/tests/vls/sample_mod1/sample.v index b13a086bdd..d22111a739 100644 --- a/vlib/v/tests/vls/sample_mod1/sample.v +++ b/vlib/v/tests/vls/sample_mod1/sample.v @@ -44,7 +44,7 @@ pub type PublicAlias1_1 = u8 | u16 | int pub type PublicAlias1_2 = PublicStruct1 // PublicCB is a funtion type -pub type PublicCB = fn (msg &char, arg usize) +pub type PublicCB = fn (msg &char, arg uint) // public_fn1 is a public function, return string pub fn public_fn1(val int) string { @@ -85,7 +85,7 @@ type PrivateAlias1_1 = u8 | u16 | int type PrivateAlias1_2 = PublicStruct1 -type PrivateCB = fn (msg &char, arg usize) +type PrivateCB = fn (msg &char, arg uint) fn private_fn1(val int) string { return '${val}' diff --git a/vlib/v/trace_calls/tracing_calls_nix.c.v b/vlib/v/trace_calls/tracing_calls_nix.c.v index 1dba5462ef..19e0689302 100644 --- a/vlib/v/trace_calls/tracing_calls_nix.c.v +++ b/vlib/v/trace_calls/tracing_calls_nix.c.v @@ -12,5 +12,5 @@ fn C.clock_gettime(i32, &C.timespec) i32 $if macos { fn C.pthread_self() voidptr } $else { - fn C.pthread_self() usize + fn C.pthread_self() uint } diff --git a/vlib/v/transform/anonymous_struct.v b/vlib/v/transform/anonymous_struct.v index ed1944f949..2511661c0f 100644 --- a/vlib/v/transform/anonymous_struct.v +++ b/vlib/v/transform/anonymous_struct.v @@ -38,7 +38,7 @@ fn (mut t Transformer) materialize_inferred_anonymous_structs() bool { for { idx++ if use_flags && idx < original_node_count { - found := unsafe { &u8(C.memchr(&u8(candidate_flags.data) + idx, 1, usize(original_node_count - idx))) } + found := unsafe { &u8(C.memchr(&u8(candidate_flags.data) + idx, 1, uint(original_node_count - idx))) } idx = if isnil(found) { original_node_count } else { diff --git a/vlib/v/transform/array.v b/vlib/v/transform/array.v index bfe9edbf50..a0cc0142ca 100644 --- a/vlib/v/transform/array.v +++ b/vlib/v/transform/array.v @@ -4608,7 +4608,7 @@ fn (mut t Transformer) lower_array_map_call(node flat.Node, fn_node flat.Node, b t.make_call_expr_typed(fn_value, [t.make_ident(elem_name)], result_elem_type) } } else if has_bound_method_array { - t.make_cast(result_elem_type, t.make_cast(flat.source_type_usize, t.make_ident(elem_name), flat.source_type_usize), result_elem_type) + t.make_cast(result_elem_type, t.make_cast(flat.source_type_uint, t.make_ident(elem_name), flat.source_type_uint), result_elem_type) } else if mapped_source_node.kind == .map_init && flat.source_type_shape(result_elem_type).has(.map_type) { t.transform_expr_for_type(mapped_source, result_elem_type) } else if decl_type_is_usable(result_elem_type) && result_elem_type != flat.source_type_void { @@ -8134,7 +8134,7 @@ fn (t &Transformer) array_default_sort_runtime_helper(elem_type_id u32) ?string clean := flat.source_type_name(clean_comparison_type_id_4) if clean_comparison_type_id_4 in [flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i64, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, - flat.source_type_u64, flat.source_type_isize, flat.source_type_usize, flat.source_type_rune, + flat.source_type_u64, flat.source_type_isize, flat.source_type_uint, flat.source_type_rune, flat.source_type_char] { return 'v3_array_sort_${clean}' } diff --git a/vlib/v/transform/array_noscan_test.v b/vlib/v/transform/array_noscan_test.v index eac1f0fe7c..66dac83554 100644 --- a/vlib/v/transform/array_noscan_test.v +++ b/vlib/v/transform/array_noscan_test.v @@ -13,7 +13,7 @@ fn test_array_new_selects_noscan_for_scalar_elements() { }) len_expr := t.make_int_literal(3) cap_expr := t.make_int_literal(7) - for elem_type in ['f64', 'f32', 'int', 'u8', 'bool', 'char', 'rune', 'isize', 'usize', 'ScalarAlias', + for elem_type in ['f64', 'f32', 'int', 'u8', 'bool', 'char', 'rune', 'uint', 'ScalarAlias', 'ScalarAliasChain', '?f64'] { id := t.make_array_new_call(flat.source_type_id(elem_type), len_expr, cap_expr) call := a.nodes[int(id)] diff --git a/vlib/v/transform/call_provenance_borrow_test.v b/vlib/v/transform/call_provenance_borrow_test.v index 4bcb97694f..fa8d441408 100644 --- a/vlib/v/transform/call_provenance_borrow_test.v +++ b/vlib/v/transform/call_provenance_borrow_test.v @@ -28,8 +28,8 @@ fn (mut holder Holder) retain(value &i16) !bool { holder.pointer = value return true } -fn narrow_encoded(value &usize) !bool { return unsafe { *value != 0 } } -fn encoded(value &i16) !usize { return usize(value) } +fn narrow_encoded(value &uint) !bool { return unsafe { *value != 0 } } +fn encoded(value &i16) !uint { return uint(value) } fn alias_math(value &Narrow) !i16 { return unsafe { i16(*value + *value) } } fn main() {} ')! diff --git a/vlib/v/transform/comptime.v b/vlib/v/transform/comptime.v index b3c394dd6f..cc2606997c 100644 --- a/vlib/v/transform/comptime.v +++ b/vlib/v/transform/comptime.v @@ -4466,7 +4466,7 @@ fn (t &Transformer) comptime_field_type_id_key_uncached(typ string, decl_module fn comptime_is_primitive_type(typ string) bool { return typ in ['string', 'bool', 'rune', 'char', 'i8', 'i16', 'i32', 'i64', 'int', 'isize', - 'u8', 'u16', 'u32', 'u64', 'usize', 'f32', 'f64', 'int literal', 'float literal', 'voidptr', + 'u8', 'u16', 'u32', 'u64', 'uint', 'f32', 'f64', 'int literal', 'float literal', 'voidptr', 'byteptr', 'charptr', 'nil', 'void'] } diff --git a/vlib/v/transform/comptime_test.v b/vlib/v/transform/comptime_test.v index 253229750a..12de323291 100644 --- a/vlib/v/transform/comptime_test.v +++ b/vlib/v/transform/comptime_test.v @@ -53,7 +53,7 @@ fn test_comptime_field_type_id_keeps_custom_types_above_builtin_range() { } type_id := t.type_index(flat.source_type_id('T207'), '') assert type_id > 65535 - assert type_id != types.builtin_type_index('isize') + assert type_id != types.builtin_type_index('int') assert type_id & (0xff << 16) == 0 } @@ -967,7 +967,7 @@ fn test_comptime_method_metadata_keeps_generic_receiver_specializations() { tc.struct_generic_params['Box'] = ['T'] mut t := new_transformer(mut a, &tc, map[string]bool{}) t.cur_module = 'main' - for typ in ['int', 'string', 'int'] { + for typ in ['int', 'string', 'uint'] { for name in ['Box[${typ}]', 'Box_${typ}'] { methods := t.comptime_method_metas(flat.source_type_id(name)) assert methods.len == 1 diff --git a/vlib/v/transform/expr.v b/vlib/v/transform/expr.v index d6f323adb3..e808761131 100644 --- a/vlib/v/transform/expr.v +++ b/vlib/v/transform/expr.v @@ -5206,7 +5206,7 @@ pub fn (mut t Transformer) make_sizeof_type(type_name_id u32) flat.NodeId { return t.a.add_node(flat.Node{ kind: .sizeof_expr value: type_name - typ: flat.source_type_usize + typ: flat.source_type_uint }) } diff --git a/vlib/v/transform/fn.v b/vlib/v/transform/fn.v index 8f9e0e7092..e0916e8b18 100644 --- a/vlib/v/transform/fn.v +++ b/vlib/v/transform/fn.v @@ -1030,7 +1030,7 @@ fn (t &Transformer) alias_receiver_type_matches(base_type_id u32, alias_type_id // is_integer_type_name reports whether is integer type name applies in transform. fn (t &Transformer) is_integer_type_name(typ_id u32) bool { - return typ_id == flat.source_type_int || typ_id == flat.source_type_i8 || typ_id == flat.source_type_i16 || typ_id == flat.source_type_i32 || typ_id == flat.source_type_i64 || typ_id == flat.source_type_u8 || typ_id == flat.source_type_u16 || typ_id == flat.source_type_u32 || typ_id == flat.source_type_u64 || typ_id == flat.source_type_rune || typ_id == flat.source_type_isize || typ_id == flat.source_type_usize || typ_id == transform_source_type_i128 || typ_id == transform_source_type_u128 + return typ_id == flat.source_type_int || typ_id == flat.source_type_i8 || typ_id == flat.source_type_i16 || typ_id == flat.source_type_i32 || typ_id == flat.source_type_i64 || typ_id == flat.source_type_u8 || typ_id == flat.source_type_u16 || typ_id == flat.source_type_u32 || typ_id == flat.source_type_u64 || typ_id == flat.source_type_rune || typ_id == flat.source_type_isize || typ_id == flat.source_type_uint || typ_id == transform_source_type_i128 || typ_id == transform_source_type_u128 } // raw_var_type_for_expr supports raw var type for expr handling for Transformer. @@ -5966,7 +5966,7 @@ fn (mut t Transformer) stringify_expr(expr_id flat.NodeId, for_print bool) flat. } const stringify_narrow_integer_types = ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'u8', 'u16', - 'u32', 'u64', 'usize', 'rune'] + 'u32', 'u64', 'uint', 'rune'] // wide_method_receiver_type returns `u128` or `i128` when the expression is an // arithmetic node this compiler lowers as a 128-bit value, and an empty string @@ -6211,7 +6211,7 @@ fn (t &Transformer) unsigned_shift_type_text(typ_id u32, node flat.Node) u32 { resolved_comparison_type_id := resolved_source_id if resolved_comparison_type_id in [flat.source_type_u8, flat.source_type_u16, - flat.source_type_u32, flat.source_type_u64, flat.source_type_usize] { + flat.source_type_u32, flat.source_type_u64, flat.source_type_uint] { return resolved_source_id } } @@ -6276,7 +6276,7 @@ fn unsigned_type_text_accepts_int_literal(typ u32, value int) bool { max := match typ { flat.source_type_u8 { 255 } flat.source_type_u16 { 65535 } - flat.source_type_u32, flat.source_type_u64, flat.source_type_usize { + flat.source_type_u32, flat.source_type_u64, flat.source_type_uint { return true } else { @@ -6324,7 +6324,7 @@ fn int_stringify_rank(typ u32) int { flat.source_type_i32, flat.source_type_u32, flat.source_type_int, flat.source_type_rune { 32 } - flat.source_type_i64, flat.source_type_u64, flat.source_type_isize, flat.source_type_usize { + flat.source_type_i64, flat.source_type_u64, flat.source_type_isize, flat.source_type_uint { 64 } else { 32 } @@ -6334,7 +6334,7 @@ fn int_stringify_rank(typ u32) int { // is_numeric_stringify_type reports whether is numeric stringify type applies in transform. fn (t &Transformer) is_numeric_stringify_type(typ_id u32) bool { typ := flat.source_type_name(typ_id) - is_number := typ in ['int', 'int literal', 'i8', 'i16', 'i32', 'i64', 'isize', 'usize', 'u8', + is_number := typ in ['int', 'int literal', 'i8', 'i16', 'i32', 'i64', 'isize', 'uint', 'u8', 'u16', 'u32', 'u64', 'f32', 'f64', 'float literal', 'rune'] return is_number || typ in t.enum_types } @@ -6749,7 +6749,7 @@ fn (mut t Transformer) wrap_string_conversion(expr flat.NodeId, typ_id u32) flat 'bool' { return t.make_call_typed('bool.str', [expr], flat.source_type_string) } - 'u8', 'u16', 'u32', 'usize' { + 'u8', 'u16', 'u32', 'uint' { // C integer promotion would pass an untruncated `int` into the u64 // param (`u8(255) + u8(1)` is 256 in C); cast back to the value // type first so the arithmetic wraps at the V type's width. @@ -7528,7 +7528,7 @@ fn (mut t Transformer) lower_ref_value_str_with_custom_prefix(expr flat.NodeId, if normalized_elem !in [flat.source_type_string, flat.source_type_rune, flat.source_type_bool, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_int, flat.source_type_isize, flat.source_type_u8, flat.source_type_u16, - flat.source_type_u32, flat.source_type_u64, flat.source_type_usize, flat.source_type_f32, + flat.source_type_u32, flat.source_type_u64, flat.source_type_uint, flat.source_type_f32, flat.source_type_f64] { if aggregate_source_id := t.stringify_aggregate_type_name(flat.source_type_id(elem_type)) { if str_fn := t.aggregate_str_method_name(aggregate_source_id) { @@ -7987,7 +7987,7 @@ fn (mut t Transformer) optional_payload_alias_display_name(typ_id u32) ?string { flat.source_type_rune, flat.source_type_char, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_int, flat.source_type_isize, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, - flat.source_type_usize, flat.source_type_f32, flat.source_type_f64] { + flat.source_type_uint, flat.source_type_f32, flat.source_type_f64] { return none } return t.alias_string_display_name(alias_name_source_id_4, base_source_id) @@ -8015,7 +8015,7 @@ fn (t &Transformer) alias_str_needs_name_wrapper(base_type_id u32) bool { return false } return flat.source_type_name(clean) !in ['string', 'bool', 'rune', 'char', 'i8', 'i16', 'i32', - 'i64', 'int', 'isize', 'u8', 'u16', 'u32', 'u64', 'usize', 'f32', 'f64', 'int literal', + 'i64', 'int', 'isize', 'u8', 'u16', 'u32', 'u64', 'uint', 'f32', 'f64', 'int literal', 'float literal', 'voidptr', 'byteptr', 'charptr', 'nil', 'void'] } @@ -9544,7 +9544,7 @@ fn (mut t Transformer) wrap_formatted_string_conversion(expr flat.NodeId, typ_id if plus_format := plus_numeric_format(format) { is_float := clean_typ in ['f32', 'f64', 'float_literal'] is_integer := clean_typ in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'rune', 'u8', 'u16', - 'u32', 'u64', 'usize', 'i128', 'u128'] + 'u32', 'u64', 'uint', 'i128', 'u128'] if is_integer || (is_float && (plus_format.width > 0 || plus_format.core.starts_with('.'))) { // A rune's ordinary str() returns a character; numeric flags need its code point. converted := if clean_typ == 'rune' { @@ -9652,7 +9652,7 @@ fn (mut t Transformer) wrap_formatted_string_conversion(expr flat.NodeId, typ_id } if char_format := character_format(format) { if normalized_typ in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'u8', 'u16', 'u32', 'u64', - 'usize', 'char', 'rune'] { + 'uint', 'char', 'rune'] { arg := if normalized_typ == 'int' { expr } else { @@ -9674,7 +9674,7 @@ fn (mut t Transformer) wrap_formatted_string_conversion(expr flat.NodeId, typ_id return t.signed_plus_string(expr, flat.source_type_id(clean_typ)) } if base := integer_format_base(format) { - if clean_typ in ['u8', 'u16', 'u32', 'u64', 'usize'] { + if clean_typ in ['u8', 'u16', 'u32', 'u64', 'uint'] { arg := t.widened_unsigned_format_arg(expr, flat.source_type_id(clean_typ)) formatted := t.make_call_typed('strconv__format_uint', [arg, t.make_int_literal(base)], flat.source_type_string) return if format == 'X' { @@ -9693,7 +9693,7 @@ fn (mut t Transformer) wrap_formatted_string_conversion(expr flat.NodeId, typ_id } } if base_format := zero_padded_integer_base_format(format) { - converted := if clean_typ in ['u8', 'u16', 'u32', 'u64', 'usize'] { + converted := if clean_typ in ['u8', 'u16', 'u32', 'u64', 'uint'] { arg := t.widened_unsigned_format_arg(expr, flat.source_type_id(clean_typ)) t.make_call_typed('strconv__format_uint', [arg, t.make_int_literal(base_format.base)], flat.source_type_string) } else if clean_typ in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'rune'] { @@ -9713,9 +9713,9 @@ fn (mut t Transformer) wrap_formatted_string_conversion(expr flat.NodeId, typ_id return t.make_call_typed('v3_string_rpad_zero', [converted, t.make_int_literal(width)], flat.source_type_string) } if width := zero_padded_decimal_width(format) { - if clean_typ in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'rune', 'usize', 'u8', 'u16', + if clean_typ in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'rune', 'uint', 'u8', 'u16', 'u32', 'u64'] { - if clean_typ in ['u64', 'usize', 'u32', 'u16', 'u8'] { + if clean_typ in ['u64', 'uint', 'u32', 'u16', 'u8'] { arg := t.widened_unsigned_format_arg(expr, flat.source_type_id(clean_typ)) return t.make_call_typed('v3_u64_zpad', [arg, t.make_int_literal(width)], flat.source_type_string) } @@ -9732,7 +9732,7 @@ fn (mut t Transformer) wrap_formatted_string_conversion(expr flat.NodeId, typ_id } if width := static_format_width(format) { mut converted := if base := integer_format_base_suffix(format) { - if clean_typ in ['u8', 'u16', 'u32', 'u64', 'usize'] { + if clean_typ in ['u8', 'u16', 'u32', 'u64', 'uint'] { arg := t.widened_unsigned_format_arg(expr, flat.source_type_id(clean_typ)) t.make_call_typed('strconv__format_uint', [arg, t.make_int_literal(base)], flat.source_type_string) } else if clean_typ in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'rune'] { @@ -9872,7 +9872,7 @@ fn (mut t Transformer) dynamic_format_conversion(expr flat.NodeId, typ_id u32, c if width := t.dynamic_zero_width_expr(format) { if clean_typ_comparison_type_id in [flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_isize, - flat.source_type_rune, flat.source_type_usize, flat.source_type_u8, flat.source_type_u16, + flat.source_type_rune, flat.source_type_uint, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, flat.source_type_u64] { converted := t.wrap_formatted_string_conversion(expr, typ_id, 'd') return t.make_call_typed('v3_string_zpad', [converted, width], flat.source_type_string) @@ -10230,7 +10230,7 @@ fn (t &Transformer) enum_backing_is_unsigned(clean_typ_id u32) bool { backing = t.enum_backing_types.type_id('${t.cur_module}.${clean_typ}') or { u32(0) } } return backing in [flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, - flat.source_type_u64, flat.source_type_usize] + flat.source_type_u64, flat.source_type_uint] } fn (t &Transformer) is_formatted_enum_type(clean_typ_id u32) bool { @@ -10912,7 +10912,7 @@ fn (t &Transformer) map_str_type_has_transform_conversion(typ_id u32) bool { return true } if clean in ['string', 'rune', 'bool', 'i8', 'i16', 'i32', 'i64', 'int', 'isize', 'u8', 'u16', - 'u32', 'u64', 'usize', 'i128', 'u128', 'f32', 'f64', 'int literal', 'float literal', 'voidptr', + 'u32', 'u64', 'uint', 'i128', 'u128', 'f32', 'f64', 'int literal', 'float literal', 'voidptr', 'byteptr', 'charptr', 'IError'] { return true } @@ -10953,7 +10953,7 @@ fn (t &Transformer) map_str_kind_for_type(typ_id u32) int { 'isize', 'char', 'i8', 'i16', 'i32', 'i64', 'int' { return 2 } - 'usize', 'u8', 'u16', 'u32', 'u64' { + 'uint', 'u8', 'u16', 'u32', 'u64' { return 3 } 'f32', 'f64' { @@ -15369,7 +15369,7 @@ fn index_node_is_range(a &flat.FlatAst, node flat.Node) bool { } const primitive_cast_type_names = ['bool', 'int', 'i8', 'i16', 'i32', 'i64', 'isize', 'u8', 'u16', - 'u32', 'u64', 'usize', 'f32', 'f64', 'rune', 'char']! + 'u32', 'u64', 'uint', 'f32', 'f64', 'rune', 'char']! // try_lower_primitive_cast_call supports try lower primitive cast call handling for Transformer. fn (mut t Transformer) try_lower_primitive_cast_call(node flat.Node) ?flat.NodeId { @@ -17369,7 +17369,7 @@ fn specialized_int_literal_fits_type(literal SpecializedIntLiteral, typ u32) boo flat.source_type_u8 { !literal.negative && literal.magnitude <= 255 } flat.source_type_u16 { !literal.negative && literal.magnitude <= 65535 } flat.source_type_u32 { !literal.negative && literal.magnitude <= u64(4294967295) } - flat.source_type_u64, flat.source_type_usize { !literal.negative } + flat.source_type_u64, flat.source_type_uint { !literal.negative } flat.source_type_i8 { specialized_signed_literal_fits(literal, 127) } flat.source_type_i16 { specialized_signed_literal_fits(literal, 32767) } flat.source_type_int, flat.source_type_i32, flat.source_type_rune { diff --git a/vlib/v/transform/for.v b/vlib/v/transform/for.v index da799aba71..e364c647d5 100644 --- a/vlib/v/transform/for.v +++ b/vlib/v/transform/for.v @@ -210,7 +210,7 @@ fn (t &Transformer) for_loop_var_unsigned_type(name string) u32 { } typ = t.trim_all_pointer_type(typ) if typ in [flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, - flat.source_type_usize] { + flat.source_type_uint] { return typ } return u32(0) diff --git a/vlib/v/transform/map.v b/vlib/v/transform/map.v index 06afc20c3f..8c5e0178e1 100644 --- a/vlib/v/transform/map.v +++ b/vlib/v/transform/map.v @@ -1694,7 +1694,7 @@ fn (t &Transformer) map_key_backing_type(key_type_id u32) ?u32 { } if alias_target != u32(0) { base := trimmed_transform_text(flat.source_type_name(t.normalize_type_alias(alias_target))) - if base in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'usize', 'u8', 'u16', 'u32', + if base in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'uint', 'u8', 'u16', 'u32', 'u64', 'rune', 'char', 'string'] { return flat.source_type_id(base) } @@ -1757,7 +1757,7 @@ fn map_callback_names(key_type string) (string, string, string, string) { size_suffix = '1' } else if key_type in ['u16', 'i16'] { size_suffix = '2' - } else if key_type in ['int', 'isize', 'usize', 'uint', 'voidptr', 'charptr', 'byteptr'] + } else if key_type in ['int', 'isize', 'uint', 'voidptr', 'charptr', 'byteptr'] || key_type.starts_with('&') { // Match the target's key storage, not the host or a fixed 32-bit int. // Portable C (`-os cross`) defines the `_w` callbacks as the ones for the diff --git a/vlib/v/transform/map_key_callbacks_test.v b/vlib/v/transform/map_key_callbacks_test.v index 1621b8d919..985b562f10 100644 --- a/vlib/v/transform/map_key_callbacks_test.v +++ b/vlib/v/transform/map_key_callbacks_test.v @@ -20,8 +20,7 @@ fn test_map_callbacks_follow_target_width_not_host_width() { for bits in [32, 64] { types.set_platform_int_bits(bits) expected := map_callback_test_integer_names((bits / 8).str()) - for key in ['int', 'isize', 'usize', 'uint', 'voidptr', 'charptr', 'byteptr', '&int', '&Item', - '&&Item'] { + for key in ['int', 'uint', 'voidptr', 'charptr', 'byteptr', '&int', '&Item', '&&Item'] { assert map_callback_test_names(key) == expected, '${bits}: ${key}' } } @@ -64,7 +63,7 @@ fn test_map_callbacks_resolve_aliases_and_keep_fixed_array_helpers() { 'WideKey': 'u64' 'TinyKey': 'u8' 'TextKey': 'string' - 'IndexKey': 'usize' + 'IndexKey': 'uint' 'PtrKey': 'voidptr' 'NestedKey': 'TextKey' 'BlockKey': '[2]u64' diff --git a/vlib/v/transform/monomorphize.v b/vlib/v/transform/monomorphize.v index e774454560..a8df234b6e 100644 --- a/vlib/v/transform/monomorphize.v +++ b/vlib/v/transform/monomorphize.v @@ -4770,7 +4770,7 @@ fn grow_node_context_cache(mut cache []u16, size int, capacity int) { // Extend in place instead of retaining a temporary zero-filled array. unsafe { cache.grow_len(size - old_len) - vmemset(&cache[old_len], 0, isize(size - old_len) * isize(sizeof(u16))) + vmemset(&cache[old_len], 0, int(size - old_len) * int(sizeof(u16))) } } @@ -6214,7 +6214,7 @@ fn (mut t Transformer) refresh_decl_assign_types_after_generic_rewrite() bool { if node.kind == .call && node.children_count > 0 && !isnil(t.tc) { callee := t.a.child_node(&node, 0) if callee.kind == .ident && callee.value.len > 0 { - slot := int((usize(callee.value.str) >> 3) & 4095) + slot := int((uint(callee.value.str) >> 3) & 4095) if plain_callee_ptrs[slot] == voidptr(callee.value.str) && plain_callee_lens[slot] == callee.value.len { continue diff --git a/vlib/v/transform/or.v b/vlib/v/transform/or.v index 8e6c4186bc..d6fd2a5b0b 100644 --- a/vlib/v/transform/or.v +++ b/vlib/v/transform/or.v @@ -1585,7 +1585,7 @@ fn (mut t Transformer) zero_value_for_type(typ_id u32) flat.NodeId { if clean in ['void', ''] { return t.make_int_literal(0) } - if clean in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'usize', 'u8', 'u16', 'u32', 'u64', + if clean in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'uint', 'u8', 'u16', 'u32', 'u64', 'rune', 'char'] { return t.make_int_literal(0) } diff --git a/vlib/v/transform/sum.v b/vlib/v/transform/sum.v index 1903c527e6..492da09d16 100644 --- a/vlib/v/transform/sum.v +++ b/vlib/v/transform/sum.v @@ -1284,21 +1284,21 @@ fn (t &Transformer) interface_concrete_impl_name(name_id u32) ?u32 { } if name_comparison_type_id_6 in [flat.source_type_bool, flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_isize, - flat.source_type_usize, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, + flat.source_type_uint, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, flat.source_type_f32, flat.source_type_f64, flat.source_type_string, flat.source_type_char, flat.source_type_rune, flat.source_type_voidptr] { return name_id } if name.starts_with('builtin.') { short := name['builtin.'.len..] - if short in ['bool', 'int', 'i8', 'i16', 'i32', 'i64', 'isize', 'usize', 'u8', 'u16', 'u32', + if short in ['bool', 'int', 'i8', 'i16', 'i32', 'i64', 'isize', 'uint', 'u8', 'u16', 'u32', 'u64', 'f32', 'f64', 'string', 'char', 'rune', 'voidptr'] { return flat.source_type_id(short) } } if name.contains('.') { short := name.all_after_last('.') - if short in ['bool', 'int', 'i8', 'i16', 'i32', 'i64', 'isize', 'usize', 'u8', 'u16', 'u32', + if short in ['bool', 'int', 'i8', 'i16', 'i32', 'i64', 'isize', 'uint', 'u8', 'u16', 'u32', 'u64', 'f32', 'f64', 'string', 'char', 'rune', 'voidptr'] { return flat.source_type_id(short) } diff --git a/vlib/v/transform/transform.v b/vlib/v/transform/transform.v index a412c95bfc..aae1a4ce12 100644 --- a/vlib/v/transform/transform.v +++ b/vlib/v/transform/transform.v @@ -1777,7 +1777,7 @@ fn reserve_parallel_transform_ast_with_cache_mode(mut a flat.FlatAst, skip_gener copy_thread2 := spawn transform_byte_copy_thread(unsafe { voidptr(&copies[2]) }) tail_start := third * 2 unsafe { - vmemcpy(voidptr(&grown_nodes[tail_start]), voidptr(&old_nodes[tail_start]), isize(u64(old_nodes.len - tail_start) * u64(old_nodes.element_size))) + vmemcpy(voidptr(&grown_nodes[tail_start]), voidptr(&old_nodes[tail_start]), int(u64(old_nodes.len - tail_start) * u64(old_nodes.element_size))) } _ = copy_thread0.wait() _ = copy_thread1.wait() @@ -1824,7 +1824,7 @@ struct TransformByteCopy { fn transform_byte_copy_thread(arg voidptr) voidptr { c := unsafe { &TransformByteCopy(arg) } - unsafe { vmemcpy(c.dst, c.src, isize(c.bytes)) } + unsafe { vmemcpy(c.dst, c.src, int(c.bytes)) } return unsafe { nil } } @@ -1843,19 +1843,19 @@ fn transform_worker_scope_begin(enabled bool) voidptr { // mapped between batches (see prealloc_scope_reenter). Large helper chunks use // small batches (see shared_helper_batch_count), so a bigger floor would only // keep idle pages of every helper resident through the parallel peak. -const transform_batch_arena_keep_bytes = isize($d('transform_batch_arena_keep_mb', 1)) * 1024 * 1024 +const transform_batch_arena_keep_bytes = int($d('transform_batch_arena_keep_mb', 1)) * 1024 * 1024 // transform_sole_batch_arena_keep_bytes is the bound for batches that run one at a time // with no helper beside them. Their arena is mapped in full while a batch is published // anyway, and a batch that starts in mapped memory does not fault its pages in again. The // bound is what a program can then hold over its former peak, when its largest batch is // an early one. -const transform_sole_batch_arena_keep_bytes = isize($d('transform_sole_batch_arena_keep_mb', 64)) * 1024 * 1024 +const transform_sole_batch_arena_keep_bytes = int($d('transform_sole_batch_arena_keep_mb', 64)) * 1024 * 1024 // transform_worker_scope_reenter makes a helper arena that was left current // again, rewound, for the next batch, with at most `keep_bytes` of it still // mapped. False means the caller needs a new arena. -fn transform_worker_scope_reenter(scope voidptr, keep_bytes isize) bool { +fn transform_worker_scope_reenter(scope voidptr, keep_bytes int) bool { $if prealloc { if scope != unsafe { nil } { return unsafe { prealloc_scope_reenter(scope, keep_bytes) } @@ -2730,7 +2730,7 @@ fn (t &Transformer) interface_boxed_impl_name_is_direct(name_id u32) bool { || name.starts_with('map[') || name.starts_with('builtin.') { return true } - if name in ['bool', 'int', 'i8', 'i16', 'i32', 'i64', 'isize', 'usize', 'u8', 'u16', 'u32', + if name in ['bool', 'int', 'i8', 'i16', 'i32', 'i64', 'isize', 'uint', 'u8', 'u16', 'u32', 'u64', 'f32', 'f64', 'string', 'char', 'rune', 'voidptr'] { return true } @@ -3042,7 +3042,7 @@ fn (mut t Transformer) apply_ignored_comptime_for_nodes() { flags := t.ignored_comptime_for_nodes mut idx := 0 for idx < flags.len { - found := unsafe { &u8(C.memchr(&u8(flags.data) + idx, 1, usize(flags.len - idx))) } + found := unsafe { &u8(C.memchr(&u8(flags.data) + idx, 1, uint(flags.len - idx))) } if isnil(found) { break } @@ -4922,8 +4922,8 @@ fn (t &Transformer) clone_ast_base(base_nodes int, base_children int) &flat.Flat mut cloned := t.allocate_ast_base_clone(base_nodes, base_children) // Both arrays own enough storage for these immutable base payloads. unsafe { - vmemcpy(cloned.nodes.data, t.a.nodes.data, isize(base_nodes) * isize(t.a.nodes.element_size)) - vmemcpy(cloned.children.data, t.a.children.data, isize(base_children) * isize(t.a.children.element_size)) + vmemcpy(cloned.nodes.data, t.a.nodes.data, int(base_nodes) * int(t.a.nodes.element_size)) + vmemcpy(cloned.children.data, t.a.children.data, int(base_children) * int(t.a.children.element_size)) } return cloned } @@ -5672,7 +5672,7 @@ fn transform_scope_owns(scope voidptr, ptr voidptr) bool { // transform_scope_address_range returns the union address range of the blocks // owned by `scope`, so callers can reject most pointers before the per-block // search in transform_scope_owns. -fn transform_scope_address_range(scope voidptr) (usize, usize) { +fn transform_scope_address_range(scope voidptr) (uint, uint) { $if prealloc { unsafe { lo, hi := prealloc_scope_address_range(scope) @@ -5827,7 +5827,7 @@ fn (mut t Transformer) merge_worker(w &Transformer, items []FnWorkItem, base_nod // A parallel pass already applied node_shift inside the region; // compaction is a plain leftward move. unsafe { - vmemmove(&t.a.children[old_len], &w.a.children[base_children], isize(new_children) * isize(t.a.children.element_size)) + vmemmove(&t.a.children[old_len], &w.a.children[base_children], int(new_children) * int(t.a.children.element_size)) } } else { // Fused copy+relocate: under the shared-base path compaction copies @@ -5863,7 +5863,7 @@ fn (mut t Transformer) merge_worker(w &Transformer, items []FnWorkItem, base_nod if t.merge_regions_relocated && !clone_worker_nodes { // A parallel pass already applied child_shift inside the region. unsafe { - vmemmove(&t.a.nodes[nodes_old_len], &w.a.nodes[base_nodes], isize(new_nodes) * isize(t.a.nodes.element_size)) + vmemmove(&t.a.nodes[nodes_old_len], &w.a.nodes[base_nodes], int(new_nodes) * int(t.a.nodes.element_size)) } } else { // Fused copy+relocate, same leftward-overlap argument as the children @@ -6124,8 +6124,8 @@ fn (mut t Transformer) set_resolved_call_canonical(idx int, canonical string) { unsafe { t.tc.resolved_call_names.grow_len(amount) t.tc.resolved_call_set.grow_len(amount) - vmemset(&t.tc.resolved_call_names[start], 0, isize(amount) * isize(sizeof(&types.CachedName))) - vmemset(&t.tc.resolved_call_set[set_start], 0, isize(amount)) + vmemset(&t.tc.resolved_call_names[start], 0, int(amount) * int(sizeof(&types.CachedName))) + vmemset(&t.tc.resolved_call_set[set_start], 0, int(amount)) } } t.tc.resolved_call_names[idx] = types.cached_name(canonical) @@ -7685,7 +7685,7 @@ fn (mut t Transformer) make_memdup_call_for_type(addr flat.NodeId, type_name_id fn (mut t Transformer) make_type_alignment(type_name_id u32) flat.NodeId { // Cgen emits the type operand directly; MSVC rejects expression operands. - return t.make_call_typed('__alignof__', [t.make_sizeof_type(type_name_id)], flat.source_type_usize) + return t.make_call_typed('__alignof__', [t.make_sizeof_type(type_name_id)], flat.source_type_uint) } fn (mut t Transformer) make_non_aliasing_allocation_call(name string, args []flat.NodeId, typ_id u32) flat.NodeId { @@ -13439,7 +13439,7 @@ fn (mut t Transformer) transform_sizeof_expr(id flat.NodeId, node flat.Node) fla return id } mut lowered := node - lowered.typ = flat.source_type_usize + lowered.typ = flat.source_type_uint lowered.value = value if value.len > 0 { lowered.children_count = 0 @@ -21417,7 +21417,7 @@ fn (t &Transformer) local_binding_flags_before(name string, before flat.NodeId) fn (mut t Transformer) build_source_parent_index() { t.source_parent_ids = []i32{len: t.a.nodes.len} // -1 in every slot, in one memset rather than one store per node. - unsafe { C.memset(t.source_parent_ids.data, 0xff, usize(t.source_parent_ids.len) * sizeof(i32)) } + unsafe { C.memset(t.source_parent_ids.data, 0xff, uint(t.source_parent_ids.len) * sizeof(i32)) } mut decls := map[string][]int{} mut fn_offsets := map[int][]int{} mut if_exprs := map[int][]int{} @@ -24171,7 +24171,7 @@ fn (mut t Transformer) try_lower_bound_method_array_call(node flat.Node) ?flat.N index_id := t.a.child(&callee, 1) encoded := t.make_index(t.transform_expr(base_id), t.transform_expr(index_id), info.fn_type) t.set_node_generic_params(int(encoded), [bound_method_array_index_marker]) - as_usize := t.make_cast(flat.source_type_usize, encoded, flat.source_type_usize) + as_usize := t.make_cast(flat.source_type_uint, encoded, flat.source_type_uint) receiver := t.make_cast(info.receiver_type, as_usize, info.receiver_type) selector := t.make_selector(receiver, info.method, u32(0)) mut args := []flat.NodeId{cap: int(node.children_count) - 1} @@ -24321,7 +24321,7 @@ fn (mut t Transformer) transform_struct_init(id flat.NodeId, node flat.Node) fla || clean_value_comparison_type_id in [flat.source_type_f32, flat.source_type_f64, flat.source_type_int, flat.source_type_i8, flat.source_type_i16, flat.source_type_i32, flat.source_type_i64, flat.source_type_isize, - flat.source_type_usize, flat.source_type_u8, flat.source_type_u16, + flat.source_type_uint, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, flat.source_type_rune, flat.source_type_char] { return t.zero_value_for_type(clean_value_source_id) @@ -30669,7 +30669,7 @@ fn is_numeric_type_name(name_id u32) bool { } fn is_integer_type_name(name_id u32) bool { - return name_id == flat.source_type_int || name_id == flat.source_type_i8 || name_id == flat.source_type_i16 || name_id == flat.source_type_i64 || name_id == flat.source_type_u8 || name_id == flat.source_type_u16 || name_id == flat.source_type_u32 || name_id == flat.source_type_u64 || name_id == flat.source_type_isize || name_id == flat.source_type_usize || name_id == flat.source_type_rune || name_id == transform_source_type_i128 || name_id == transform_source_type_u128 + return name_id == flat.source_type_int || name_id == flat.source_type_i8 || name_id == flat.source_type_i16 || name_id == flat.source_type_i64 || name_id == flat.source_type_u8 || name_id == flat.source_type_u16 || name_id == flat.source_type_u32 || name_id == flat.source_type_u64 || name_id == flat.source_type_isize || name_id == flat.source_type_uint || name_id == flat.source_type_rune || name_id == transform_source_type_i128 || name_id == transform_source_type_u128 } fn is_float_type_name(name_id u32) bool { @@ -31743,7 +31743,7 @@ fn (mut t Transformer) instantiate_match_variant_body(id flat.NodeId, subject st operand := t.sizeof_operand_name(node) if operand == subject || operand == original_subject { node.value = variant_name - node.typ = flat.source_type_usize + node.typ = flat.source_type_uint node.children_count = 0 if !copy { t.set_node(int(id), node) diff --git a/vlib/v/transform/transform_parallel_notd_v3_no_parallel.v b/vlib/v/transform/transform_parallel_notd_v3_no_parallel.v index 399d0a40fc..75d477e050 100644 --- a/vlib/v/transform/transform_parallel_notd_v3_no_parallel.v +++ b/vlib/v/transform/transform_parallel_notd_v3_no_parallel.v @@ -153,22 +153,22 @@ mut: wave int nodes_base voidptr children_base voidptr - node_size usize - child_size usize + node_size uint + child_size uint } fn region_compact_thread(arg voidptr) voidptr { c := unsafe { &RegionCompaction(arg) } if c.node_len > 0 && c.node_dst != c.node_src { unsafe { - vmemmove(&u8(c.nodes_base) + usize(c.node_dst) * c.node_size, &u8(c.nodes_base) + - usize(c.node_src) * c.node_size, isize(usize(c.node_len) * c.node_size)) + vmemmove(&u8(c.nodes_base) + uint(c.node_dst) * c.node_size, &u8(c.nodes_base) + + uint(c.node_src) * c.node_size, int(uint(c.node_len) * c.node_size)) } } if c.child_len > 0 && c.child_dst != c.child_src { unsafe { - vmemmove(&u8(c.children_base) + usize(c.child_dst) * c.child_size, &u8(c.children_base) + - usize(c.child_src) * c.child_size, isize(usize(c.child_len) * c.child_size)) + vmemmove(&u8(c.children_base) + uint(c.child_dst) * c.child_size, &u8(c.children_base) + + uint(c.child_src) * c.child_size, int(uint(c.child_len) * c.child_size)) } } return unsafe { nil } @@ -237,8 +237,8 @@ fn (mut t Transformer) compact_worker_regions_parallel(worker_ptrs []voidptr, no for mut move in moves { move.nodes_base = t.a.nodes.data move.children_base = t.a.children.data - move.node_size = usize(t.a.nodes.element_size) - move.child_size = usize(t.a.children.element_size) + move.node_size = uint(t.a.nodes.element_size) + move.child_size = uint(t.a.children.element_size) } for wave in 0 .. wave_count { mut tasks := []workers.Task{cap: moves.len} @@ -333,11 +333,11 @@ fn (mut t Transformer) absorb_worker_regions(worker_ptrs []voidptr, base_nodes i // nothing lands exactly on the end of the array. nodes_base := unsafe { &u8(t.a.nodes.data) } children_base := unsafe { &u8(t.a.children.data) } - node_size := usize(t.a.nodes.element_size) - child_size := usize(t.a.children.element_size) + node_size := uint(t.a.nodes.element_size) + child_size := uint(t.a.children.element_size) for i in 0 .. absorb_args.len { - node_off := usize(absorb_args[i].node_start + int(absorb_args[i].node_shift)) - child_off := usize(absorb_args[i].child_start + int(absorb_args[i].child_shift)) + node_off := uint(absorb_args[i].node_start + int(absorb_args[i].node_shift)) + child_off := uint(absorb_args[i].child_start + int(absorb_args[i].child_shift)) absorb_args[i].dst_nodes = unsafe { voidptr(nodes_base + node_off * node_size) } absorb_args[i].dst_children = unsafe { voidptr(children_base + child_off * child_size) @@ -548,7 +548,7 @@ struct WorkerScopeFreeArgs { // `scopes`. `lo`/`hi` bound the union of the arenas' address ranges: nearly // every text lives outside them, so the per-arena search is rarely needed. @[inline] -fn node_has_any_scoped_text(node &flat.Node, scopes []voidptr, lo usize, hi usize) bool { +fn node_has_any_scoped_text(node &flat.Node, scopes []voidptr, lo uint, hi uint) bool { if node.value.len > 0 && text_pointer_in_scopes(node.value.str, scopes, lo, hi) { return true } @@ -585,8 +585,8 @@ fn node_has_any_scoped_text(node &flat.Node, scopes []voidptr, lo usize, hi usiz // Reject pointers outside the union once, before consulting individual arenas. @[inline] -fn text_pointer_in_scopes(ptr voidptr, scopes []voidptr, lo usize, hi usize) bool { - addr := usize(ptr) +fn text_pointer_in_scopes(ptr voidptr, scopes []voidptr, lo uint, hi uint) bool { + addr := uint(ptr) if addr < lo || addr >= hi { return false } @@ -599,9 +599,9 @@ fn text_pointer_in_scopes(ptr voidptr, scopes []voidptr, lo usize, hi usize) boo } // scopes_address_range returns the union address range of `scopes`. -fn scopes_address_range(scopes []voidptr) (usize, usize) { - mut lo := usize(0) - mut hi := usize(0) +fn scopes_address_range(scopes []voidptr) (uint, uint) { + mut lo := uint(0) + mut hi := uint(0) $if prealloc { for scope in scopes { scope_lo, scope_hi := transform_scope_address_range(scope) @@ -1971,7 +1971,7 @@ fn (mut t Transformer) run_scoped_monomorphize_specs(specs []PendingGenericFnSpe scope_lo, scope_hi := transform_scope_address_range(scope) for idx in 0 .. t.a.nodes.len { node := unsafe { &t.a.nodes[idx] } - value_address := usize(node.value.str) + value_address := uint(node.value.str) if node.payload == 0 && (value_address < scope_lo || value_address >= scope_hi) { continue } diff --git a/vlib/v/transform/type_propagation.v b/vlib/v/transform/type_propagation.v index c4561c88d2..210bae0558 100644 --- a/vlib/v/transform/type_propagation.v +++ b/vlib/v/transform/type_propagation.v @@ -1782,7 +1782,7 @@ fn is_plain_builtin_alias_type_bytes(typ string) bool { } return match typ { 'bool', 'string', 'void', 'int', 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'f32', - 'f64', 'rune', 'isize', 'usize', 'voidptr', 'byteptr', 'charptr' { + 'f64', 'rune', 'isize', 'uint', 'voidptr', 'byteptr', 'charptr' { true } else { diff --git a/vlib/v/transform/value_parameter_escape_test.v b/vlib/v/transform/value_parameter_escape_test.v index f10206b977..741beba427 100644 --- a/vlib/v/transform/value_parameter_escape_test.v +++ b/vlib/v/transform/value_parameter_escape_test.v @@ -176,7 +176,7 @@ fn test_scalar_success_keeps_addresses_that_can_escape_in_a_result_error() { } fn test_pointer_to_integer_casts_keep_addresses_through_aliases_and_nested_casts() { - for target in ['usize', 'isize', 'u64'] { + for target in ['uint', 'int', 'u64'] { mut a := flat.FlatAst.new() mut tc := types.TypeChecker.new(&a) mut t := new_transformer(mut a, &tc, map[string]bool{}) @@ -233,8 +233,8 @@ fn test_sum_type_scalar_extraction_preserves_encoded_address_aliases() { tagged := t.make_ident('tagged') start := a.children.len a.children << tagged - unwrapped := a.add_node(flat.Node{ kind: .as_expr, children_start: start, children_count: 1, value: 'usize' }) - tc.register_synth_type(unwrapped, tc.parse_type(flat.source_type_id('usize'))) + unwrapped := a.add_node(flat.Node{ kind: .as_expr, children_start: start, children_count: 1, value: 'uint' }) + tc.register_synth_type(unwrapped, tc.parse_type(flat.source_type_id('uint'))) assert t.escape_aggregate_address_sources(unwrapped, { 'tagged': ['value'] }, map[string]string{}) == ['value'] @@ -248,12 +248,12 @@ fn test_scalar_optional_alias_preserves_its_encoded_address() { mut tc := types.TypeChecker.new(&a) mut t := new_transformer(mut a, &tc, map[string]bool{}) alias := t.make_ident('alias') - tc.register_synth_type(alias, tc.parse_type(flat.source_type_id('?usize'))) + tc.register_synth_type(alias, tc.parse_type(flat.source_type_id('?uint'))) fallback := t.make_block([t.make_expr_stmt(t.make_int_literal(0))]) start := a.children.len a.children << [alias, fallback] unwrapped := a.add_node(flat.Node{ kind: .or_expr, children_start: start, children_count: 2 }) - tc.register_synth_type(unwrapped, tc.parse_type(flat.source_type_id('usize'))) + tc.register_synth_type(unwrapped, tc.parse_type(flat.source_type_id('uint'))) assert t.escape_aggregate_address_sources(unwrapped, { 'alias': ['value'] }, map[string]string{}) == ['value'] @@ -263,7 +263,7 @@ fn test_scalar_optional_alias_preserves_its_encoded_address() { } fn test_address_sized_result_success_preserves_argument_addresses() { - for target in ['usize', 'isize', 'u64', 'i64', 'int', 'f64', 'f32'] { + for target in ['uint', 'int', 'u64', 'i64', 'f64', 'f32'] { mut a := flat.FlatAst.new() mut tc := types.TypeChecker.new(&a) mut t := new_transformer(mut a, &tc, map[string]bool{}) diff --git a/vlib/v/transform/voidptr_variadic_storage_test.v b/vlib/v/transform/voidptr_variadic_storage_test.v index 518eb7d1d8..9db963da37 100644 --- a/vlib/v/transform/voidptr_variadic_storage_test.v +++ b/vlib/v/transform/voidptr_variadic_storage_test.v @@ -38,8 +38,8 @@ fn test_voidptr_variadic_storage_widens_integers_narrower_than_the_target_int() expected := if bits == 64 { 'int' } else { typ } assert voidptr_variadic_test_storage(mut t, typ) == expected, '${bits}: ${typ}' } - for typ in ['int', 'i64', 'u64', 'isize', 'usize', 'bool', 'f64', 'string', 'Whole', 'Wide', - 'dep.Tiny', 'Point'] { + for typ in ['int', 'i64', 'u64', 'uint', 'bool', 'f64', 'string', 'Whole', 'Wide', 'dep.Tiny', + 'Point'] { assert voidptr_variadic_test_storage(mut t, typ) == typ, '${bits}: ${typ}' } assert voidptr_variadic_test_storage(mut t, 'f32') == 'f64' diff --git a/vlib/v/types/c_constant_context_test.v b/vlib/v/types/c_constant_context_test.v index 2758191744..a84b2267b4 100644 --- a/vlib/v/types/c_constant_context_test.v +++ b/vlib/v/types/c_constant_context_test.v @@ -6,7 +6,7 @@ import v.pref fn test_c_integer_constant_adopts_numeric_alias_call_context() { path := os.join_path(os.vtmp_dir(), 'v3_c_constant_context_${os.getpid()}.c.v') - os.write_file(path, 'module main\n\ntype Flag = usize\n\nfn consume(value Flag) {}\n\nfn main() { consume(C.TEST_FLAG) }\n')! + os.write_file(path, 'module main\n\ntype Flag = uint\n\nfn consume(value Flag) {}\n\nfn main() { consume(C.TEST_FLAG) }\n')! defer { os.rm(path) or {} } diff --git a/vlib/v/types/checker.v b/vlib/v/types/checker.v index 1ad112a447..7c75b61caf 100644 --- a/vlib/v/types/checker.v +++ b/vlib/v/types/checker.v @@ -555,7 +555,7 @@ mut: // Per-checker symbol probes front the compilation-wide interner. Resolved // names are usually repeated as the same canonical string pointer inside a // worker, so these slots avoid taking the interner mutex on every call. - symbol_recent_ptrs [type_cache_recent_slots]usize + symbol_recent_ptrs [type_cache_recent_slots]uint symbol_recent_lens [type_cache_recent_slots]int symbol_recent_ids [type_cache_recent_slots]SymbolId symbol_recent_vals [type_cache_recent_slots]string @@ -605,8 +605,8 @@ mut: fn new_type_cache(parse_enabled bool) &TypeCache { // Allocate the fixed caches in place instead of copying a large temporary. // Their owned map/array payloads need a scanned allocation under a GC. - mut cache := unsafe { &TypeCache(malloc(sizeof(TypeCache))) } - unsafe { vmemset(cache, 0, sizeof(TypeCache)) } + mut cache := unsafe { &TypeCache(malloc(int(sizeof(TypeCache)))) } + unsafe { vmemset(cache, 0, int(sizeof(TypeCache))) } cache.parse_enabled = parse_enabled cache.generated_parent_entries = map[int]flat.NodeId{} cache.parse_entries = map[u64]ParseTypeCacheEntry{} @@ -2268,7 +2268,7 @@ fn new_zeroed_name_cache(n int) []&CachedName { // used during transform growth without synthesizing per-element stores. unsafe { values.grow_len(n) - vmemset(values.data, 0, isize(n) * isize(sizeof(&CachedName))) + vmemset(values.data, 0, int(n) * int(sizeof(&CachedName))) } } return values @@ -3098,7 +3098,7 @@ fn extend_name_cache(mut values []&CachedName, n int) { start := values.len unsafe { values.grow_len(n - start) - vmemset(&values[start], 0, isize(n - start) * isize(sizeof(&CachedName))) + vmemset(&values[start], 0, int(n - start) * int(sizeof(&CachedName))) } } } @@ -11097,7 +11097,7 @@ fn (tc &TypeChecker) intern_symbol(name string) (SymbolId, string) { } mut cache := unsafe { tc.type_cache } if !isnil(cache) { - ptr := usize(name.str) + ptr := uint(name.str) slot := int((u64(ptr) >> 4 ^ u64(name.len)) & u64(type_cache_recent_slots - 1)) if cache.symbol_recent_set[slot] && cache.symbol_recent_ptrs[slot] == ptr && cache.symbol_recent_lens[slot] == name.len { @@ -19733,7 +19733,7 @@ fn reserved_const_type_name(name string) bool { 'string', 'rune', 'thread', - 'usize', + 'uint', 'isize', 'voidptr', ] diff --git a/vlib/v/types/checker_comptime.v b/vlib/v/types/checker_comptime.v index 1f7ad1fd6e..9de248924c 100644 --- a/vlib/v/types/checker_comptime.v +++ b/vlib/v/types/checker_comptime.v @@ -1232,7 +1232,7 @@ fn (tc &TypeChecker) comptime_static_enum_field_value(id flat.NodeId, enum_modul .left_shift { i64(u64(left) << right) } .right_shift { typ := unalias_type(tc.comptime_enum_local_expr_type(tc.a.child(node, 0), map[string]Type{})).name() - if typ in ['u64', 'usize'] { i64(u64(left) >> right) } else { left >> right } + if typ in ['u64', 'uint'] { i64(u64(left) >> right) } else { left >> right } } .right_shift_unsigned { comptime_enum_unsigned_right_shift(left, right, unalias_type(tc.comptime_enum_local_expr_type(tc.a.child(&node, 0), map[string]Type{})).source_type_id()) @@ -1402,7 +1402,7 @@ pub fn comptime_enum_integer_literal(value string) ?i64 { // comptime_enum_integer_division uses unsigned arithmetic for unsigned 64-bit operands. // typ_id is a process-wide source-spelling ID. pub fn comptime_enum_integer_division(left i64, right i64, typ_id u32, remainder bool) i64 { - if typ_id in [flat.source_type_u64, flat.source_type_usize] { + if typ_id in [flat.source_type_u64, flat.source_type_uint] { return if remainder { i64(u64(left) % u64(right)) } else { i64(u64(left) / u64(right)) } } return if remainder { left % right } else { left / right } @@ -1569,7 +1569,7 @@ fn (tc &TypeChecker) comptime_static_enum_local_expr_value(id flat.NodeId, local .left_shift { i64(u64(left) << right) } .right_shift { typ := unalias_type(tc.comptime_enum_local_expr_type(tc.a.child(node, 0), local_types)).name() - if typ in ['u64', 'usize'] { i64(u64(left) >> right) } else { left >> right } + if typ in ['u64', 'uint'] { i64(u64(left) >> right) } else { left >> right } } .right_shift_unsigned { comptime_enum_unsigned_right_shift(left, right, unalias_type(tc.comptime_enum_local_expr_type(tc.a.child(node, 0), local_types)).source_type_id()) @@ -9344,7 +9344,7 @@ fn (mut tc TypeChecker) check_infix(id flat.NodeId, node flat.Node) { } skip_inactive_compact_else := tc.shift_is_in_inactive_compact_else(id) bit_size := if tc.node_is_in_translated_file(id) { - int_max(32, tc.integer_shift_bit_size(lhs_type)) + int_max(32, tc.integer_shift_bit_size(tc.translated_promoted_shift_type(lhs_type))) } else { tc.integer_shift_bit_size(lhs_type) } @@ -9645,12 +9645,12 @@ fn (tc &TypeChecker) integer_shift_bit_size(typ Type) int { } if clean is Primitive { if clean.name() == 'int' || clean.size == 0 { - return 32 + return platform_int_bits() } return int(clean.size) } if clean is ISize || clean is USize { - return 64 + return platform_int_bits() } return 0 } diff --git a/vlib/v/types/checker_const_numeric.v b/vlib/v/types/checker_const_numeric.v index 95a1e6f90f..dd456fea46 100644 --- a/vlib/v/types/checker_const_numeric.v +++ b/vlib/v/types/checker_const_numeric.v @@ -11,7 +11,7 @@ fn independent_numeric_const_initializer(a &flat.FlatAst, id flat.NodeId) bool { } node := unsafe { &a.nodes[int(id)] } if node.typ_text().len > 0 && node.typ_text() !in ['int', 'i8', 'i16', 'i32', 'i64', 'u8', - 'u16', 'u32', 'u64', 'f32', 'f64', 'usize', 'isize'] { + 'u16', 'u32', 'u64', 'f32', 'f64', 'uint', 'isize'] { return false } match node.kind { @@ -20,7 +20,7 @@ fn independent_numeric_const_initializer(a &flat.FlatAst, id flat.NodeId) bool { } .cast_expr { if node.value !in ['int', 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'f32', - 'f64', 'usize', 'isize'] || node.children_count != 1 { + 'f64', 'uint', 'isize'] || node.children_count != 1 { return false } } diff --git a/vlib/v/types/checker_generic_constraints.v b/vlib/v/types/checker_generic_constraints.v index 97c8c4c286..405ad55890 100644 --- a/vlib/v/types/checker_generic_constraints.v +++ b/vlib/v/types/checker_generic_constraints.v @@ -2499,7 +2499,7 @@ fn (o ConstraintOperand) is_bool() bool { enum ConstraintTypeKind { unchecked // pointers and what else the rules below do not cover integer - isize // `isize` and `usize`: no `==` with a float + isize // `isize` and `uint`: no `==` with a float rune float string diff --git a/vlib/v/types/checker_parallel.v b/vlib/v/types/checker_parallel.v index b161dedec0..06fe4c43e7 100644 --- a/vlib/v/types/checker_parallel.v +++ b/vlib/v/types/checker_parallel.v @@ -991,7 +991,7 @@ fn (mut tc TypeChecker) check_scoped_batches(items []CheckWorkItem, batch_limit // check_batch_arena_keep_bytes bounds how much of a worker's batch arena stays // mapped between its batches (see prealloc_scope_reenter). -const check_batch_arena_keep_bytes = isize(8) * 1024 * 1024 +const check_batch_arena_keep_bytes = int(8) * 1024 * 1024 // begin_check_batch_scope starts the arena of one check batch. A worker that // reuses its batch arena rewinds the previous batch's one: unmapping and diff --git a/vlib/v/types/checker_tail.v b/vlib/v/types/checker_tail.v index e30b218783..dca9d846c9 100644 --- a/vlib/v/types/checker_tail.v +++ b/vlib/v/types/checker_tail.v @@ -6445,7 +6445,7 @@ fn legacy_comptime_type_index(name string) ?int { 'u16' { 12 } 'u32' { 13 } 'u64' { 14 } - 'usize' { 15 } + 'uint' { 15 } 'f32' { 16 } 'f64' { 17 } 'char' { 18 } @@ -21433,9 +21433,9 @@ fn valid_string_data(s string) bool { if s == '' { return true } - // Go through usize: C sign-extends a 32-bit pointer converted to a wider + // Go through uint: C sign-extends a 32-bit pointer converted to a wider // integer, which put every address above 2 GiB out of range on 32-bit hosts. - ptr := unsafe { u64(usize(voidptr(s.str))) } + ptr := unsafe { u64(uint(voidptr(s.str))) } return ptr >= 4096 && ptr < 281474976710656 && s.len < 1048576 } diff --git a/vlib/v/types/checker_tail_stmt.v b/vlib/v/types/checker_tail_stmt.v index 57f3a44110..5b2ce1b750 100644 --- a/vlib/v/types/checker_tail_stmt.v +++ b/vlib/v/types/checker_tail_stmt.v @@ -8122,7 +8122,7 @@ fn (mut tc TypeChecker) check_index_overload_arg(id flat.NodeId, node flat.Node, } fn js_index_type_requires_int_cast(typ &Type) bool { - return unalias_type(typ).name() in ['i64', 'u64', 'isize', 'usize'] + return unalias_type(typ).name() in ['i64', 'u64', 'isize', 'uint'] } fn (mut tc TypeChecker) check_js_index_type(id flat.NodeId, typ Type, base_type Type) bool { @@ -11269,7 +11269,7 @@ fn call_arg_integer_type(typ &Type) bool { } Struct, Enum, Interface, SumType { clean.name() in ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'u8', 'u16', 'u32', 'u64', - 'usize', 'rune'] + 'uint', 'rune'] } else { false } } @@ -11299,7 +11299,7 @@ fn call_arg_numeric_promotion_index(name string) int { 'u16' { 12 } 'u32' { 13 } 'u64' { 14 } - 'usize' { 15 } + 'uint' { 15 } // 128-bit ranks above the 64-bit types, so a narrower integer widens into // it. Without these rows the index is -1, no widening is offered, and an // expression like `wide + 1` is typed `int` and cut to 64 bits. @@ -12936,7 +12936,7 @@ pub fn (tc &TypeChecker) interface_accepts_implicit_str(iface_name_id u32) bool fn implicit_str_builtin_type_names() []u32 { return [flat.source_type_bool, flat.source_type_int, flat.source_type_i8, flat.source_type_i16, - flat.source_type_i32, flat.source_type_i64, flat.source_type_isize, flat.source_type_usize, + flat.source_type_i32, flat.source_type_i64, flat.source_type_isize, flat.source_type_uint, flat.source_type_u8, flat.source_type_u16, flat.source_type_u32, flat.source_type_u64, flat.source_type_f32, flat.source_type_f64, flat.source_type_string, flat.source_type_rune] } @@ -18968,7 +18968,7 @@ fn (tc &TypeChecker) resolve_type_slow(id flat.NodeId) Type { } const narrow_integer_type_names = ['int', 'i8', 'i16', 'i32', 'i64', 'isize', 'u8', 'u16', 'u32', - 'u64', 'usize', 'rune', 'char'] + 'u64', 'uint', 'rune', 'char'] @[inline] fn narrow_integer_type_for_widening(typ Type) bool { @@ -21766,7 +21766,7 @@ fn resolve_type_name_for_method(t &Type) u32 { return flat.source_type_isize } if t is USize { - return flat.source_type_usize + return flat.source_type_uint } if t is Array { return flat.source_type_id('[]${nested_type_name(t.elem_type)}') diff --git a/vlib/v/types/integer_cast_platform_width_test.v b/vlib/v/types/integer_cast_platform_width_test.v index d64dab7db7..2b0abd91fd 100644 --- a/vlib/v/types/integer_cast_platform_width_test.v +++ b/vlib/v/types/integer_cast_platform_width_test.v @@ -89,3 +89,23 @@ fn test_int_literal_cast_overflow_warnings_follow_the_target_width() { } } } + +fn test_platform_integer_shifts_use_target_width_and_preserve_c_int_width() { + saved_bits := platform_int_bits() + defer { set_platform_int_bits(saved_bits) } + for bits in [32, 64] { + set_platform_int_bits(bits) + for typ in ['int', 'uint', 'Count'] { + valid := check_integer_cast_platform_source('type Count = int +fn main() { _ = ${typ}(1) << ${bits - 1} }') + assert valid.errors.len == 0, valid.errors.str() + invalid := check_integer_cast_platform_source('type Count = int +fn main() { _ = ${typ}(1) << ${bits} }') + assert invalid.errors.any(it.msg.contains('maximum: ${bits - 1} bits')), invalid.errors.str() + } + translated := check_integer_cast_platform_source('@[translated] +module main +fn main() { _ = int(1) << 32 }') + assert translated.errors.any(it.msg.contains('maximum: 31 bits')), translated.errors.str() + } +} diff --git a/vlib/v/types/opaque_call_alias_test.v b/vlib/v/types/opaque_call_alias_test.v index 40630141d1..a9e43e992a 100644 --- a/vlib/v/types/opaque_call_alias_test.v +++ b/vlib/v/types/opaque_call_alias_test.v @@ -18,10 +18,10 @@ fn check_alias_source(name string, source string) TypeChecker { } fn test_voidptr_lookup_with_an_unsafe_boundary_does_not_borrow_its_arguments() { - tc := check_alias_source('voidptr', 'struct Queryable { mut: on_query fn (&Queryable, usize) voidptr = unsafe { nil } } -fn (q &Queryable) query(idx usize) voidptr { return q.on_query(q, idx) } + tc := check_alias_source('voidptr', 'struct Queryable { mut: on_query fn (&Queryable, uint) voidptr = unsafe { nil } } +fn (q &Queryable) query(idx uint) voidptr { return q.on_query(q, idx) } struct View { mut: render_inc int } -fn View.from_context(ctx &Queryable) &View { return unsafe { &View(ctx.query(usize(typeof(View{}).idx))) } } +fn View.from_context(ctx &Queryable) &View { return unsafe { &View(ctx.query(uint(typeof(View{}).idx))) } } fn dev(ctx &Queryable) { mut view := View.from_context(ctx) view.render_inc++ @@ -118,8 +118,8 @@ fn main() {} fn test_visible_voidptr_lookup_of_fresh_storage_does_not_borrow_arguments() { tc := check_alias_source('separate_fresh_storage', 'struct View { mut: x int } -struct Container { key usize } -fn fresh(container &Container, key usize) voidptr { _ = container; _ = key; return &View{} } +struct Container { key uint } +fn fresh(container &Container, key uint) voidptr { _ = container; _ = key; return &View{} } fn lookup(container &Container) &View { return fresh(container, container.key) } fn dev(container &Container) { mut view := lookup(container) @@ -164,10 +164,10 @@ fn container_lookup_source(fields string) string { return 'struct View { mut: render_inc int } struct Queryable { ${fields} - on_query fn (&Queryable, usize) voidptr = unsafe { nil } + on_query fn (&Queryable, uint) voidptr = unsafe { nil } } -fn (q &Queryable) query(idx usize) voidptr { return q.on_query(q, idx) } -fn View.from_context(ctx &Queryable) &View { return ctx.query(usize(typeof(View{}).idx)) } +fn (q &Queryable) query(idx uint) voidptr { return q.on_query(q, idx) } +fn View.from_context(ctx &Queryable) &View { return ctx.query(uint(typeof(View{}).idx)) } fn dev(ctx &Queryable) { mut view := View.from_context(ctx) view.render_inc++ @@ -196,8 +196,8 @@ fn test_voidptr_lookup_of_a_type_the_container_holds_borrows_it() { fn test_voidptr_lookup_through_a_copied_scalar_argument_does_not_borrow_it() { tc := check_alias_source('scalar_lookup', 'struct View { mut: render_inc int } -fn lookup(idx usize, get fn (usize) voidptr) &View { return get(idx) } -fn dev(idx usize, get fn (usize) voidptr) { +fn lookup(idx uint, get fn (uint) voidptr) &View { return get(idx) } +fn dev(idx uint, get fn (uint) voidptr) { mut view := lookup(idx, get) view.render_inc = 5 } @@ -209,8 +209,8 @@ fn main() {} fn test_voidptr_lookup_through_a_referenced_scalar_keeps_its_source() { tc := check_alias_source('scalar_lookup_ref', 'struct View { mut: render_inc int } -fn lookup(idx usize, get fn (&usize) voidptr) &View { return get(idx) } -fn dev(idx usize, get fn (&usize) voidptr) { +fn lookup(idx uint, get fn (&uint) voidptr) &View { return get(idx) } +fn dev(idx uint, get fn (&uint) voidptr) { mut view := lookup(idx, get) view.render_inc = 5 } diff --git a/vlib/v/types/platform_uint_test.v b/vlib/v/types/platform_uint_test.v index 89e05935c0..e9418afc85 100644 --- a/vlib/v/types/platform_uint_test.v +++ b/vlib/v/types/platform_uint_test.v @@ -7,6 +7,7 @@ fn test_uint_is_platform_width_unsigned_builtin() { assert builtin_type_value('uint') == Type(uint_) assert builtin_type_value('uint') == builtin_type_value('usize') assert builtin_type_value('uint').is_integer() + assert builtin_type_value('uint').name() == 'uint' a := flat.FlatAst.new() mut tc := TypeChecker.new(&a) diff --git a/vlib/v/types/source_text_span_test.v b/vlib/v/types/source_text_span_test.v index 5716abf66d..35d8963165 100644 --- a/vlib/v/types/source_text_span_test.v +++ b/vlib/v/types/source_text_span_test.v @@ -35,7 +35,7 @@ fn test_source_text_span_clamps_offsets_and_preserves_empty_span_fallbacks() { assert tc.source_text_for_node(ids[i]) == item.expected } span := tc.source_text_for_node(ids[0]) - assert usize(span.str) == usize(source.str) + 7 + assert uint(span.str) == uint(source.str) + 7 assert tc.source_text_for_node(flat.empty_node) == '' tc.source_texts_by_file.delete('span.v') assert tc.source_text_for_node(ids[0]) == 'fallback' @@ -56,6 +56,6 @@ fn test_source_text_span_preserves_bytes_outside_trim_space_cutset() { tc.source_texts_by_file['bytes.v'] = source span := tc.source_text_for_node(id) assert span == source.trim_space() - assert usize(span.str) == usize(source.str) + 1 + assert uint(span.str) == uint(source.str) + 1 } } diff --git a/vlib/v/types/translated_alias_casts_test.v b/vlib/v/types/translated_alias_casts_test.v index 1c29f38198..f1150a5cf5 100644 --- a/vlib/v/types/translated_alias_casts_test.v +++ b/vlib/v/types/translated_alias_casts_test.v @@ -8,10 +8,10 @@ fn test_translated_alias_casts_preserve_argument_checks() { defer { os.rmdir_all(root) or {} } os.write_file(os.join_path(root, 'main.v'), '@[translated] module main -type uintptr_t = usize +type uintptr_t = uint fn main() { _ = uintptr_t("invalid") - _ = usize("invalid") + _ = uint("invalid") _ = missing_typedef(42) } ')! @@ -20,7 +20,7 @@ fn main() { assert result.exit_code != 0, result.output assert result.output.contains('cannot cast'), result.output assert result.output.contains('to `uintptr_t`'), result.output - assert result.output.contains('to `usize`'), result.output + assert result.output.contains('to `uint`'), result.output assert result.output.contains('unknown function: missing_typedef'), result.output assert !result.output.contains('unknown function: uintptr_t'), result.output } diff --git a/vlib/v/types/type.v b/vlib/v/types/type.v index e56365f223..3b940aa51e 100644 --- a/vlib/v/types/type.v +++ b/vlib/v/types/type.v @@ -77,7 +77,7 @@ pub struct ISize { dummy_ u8 } -// USize represents usize data used by types. +// USize represents uint data used by types. pub struct USize { dummy_ u8 } @@ -557,7 +557,7 @@ pub fn (t &Type) name() string { Char { 'char' } Rune { 'rune' } ISize { 'isize' } - USize { 'usize' } + USize { 'uint' } else { t.composite_name() } } } @@ -789,7 +789,7 @@ pub fn (t &Type) source_type_id() u32 { Char { flat.source_type_char } Rune { flat.source_type_rune } ISize { flat.source_type_isize } - USize { flat.source_type_usize } + USize { flat.source_type_uint } Primitive { primitive_source_type_id(t.props, t.size) } else { flat.source_type_id(t.name()) } } diff --git a/vlib/v/types/type_index.v b/vlib/v/types/type_index.v index fd857e0bc4..fbacecd865 100644 --- a/vlib/v/types/type_index.v +++ b/vlib/v/types/type_index.v @@ -42,7 +42,7 @@ pub fn builtin_type_index(name string) int { 'u16' { 12 } 'u32' { 13 } 'u64' { 14 } - 'usize' { 15 } + 'uint', 'usize' { 15 } 'f32' { 16 } 'f64' { 17 } 'char' { 18 } diff --git a/vlib/v/types/type_interner_cache.c.v b/vlib/v/types/type_interner_cache.c.v index 14e189ad35..68429ba414 100644 --- a/vlib/v/types/type_interner_cache.c.v +++ b/vlib/v/types/type_interner_cache.c.v @@ -149,7 +149,7 @@ fn canonical_intern_child_key(t &Type) u64 { // structural verification, even when their address has appeared before. @[direct_array_access; inline] fn (i &TypeInterner) canonical_identity(t &Type) &CanonicalTypeEntry { - slot := int((usize(t) >> 4) & 4095) + slot := int((uint(t) >> 4) & 4095) entry := unsafe { &CanonicalTypeEntry(C.atomic_load_ptr(&i.identities[slot])) } if !isnil(entry) && voidptr(entry.typ) == voidptr(t) { return entry @@ -159,7 +159,7 @@ fn (i &TypeInterner) canonical_identity(t &Type) &CanonicalTypeEntry { @[direct_array_access; inline] fn (i &TypeInterner) remember_canonical_identity(entry &CanonicalTypeEntry) { - slot := int((usize(entry.typ) >> 4) & 4095) + slot := int((uint(entry.typ) >> 4) & 4095) unsafe { C.atomic_store_ptr(&i.identities[slot], entry) } diff --git a/vlib/v/types/valid_string_data_test.v b/vlib/v/types/valid_string_data_test.v index ffba4a53a7..097efa2c65 100644 --- a/vlib/v/types/valid_string_data_test.v +++ b/vlib/v/types/valid_string_data_test.v @@ -4,8 +4,8 @@ fn test_valid_string_data_accepts_addresses_above_2_gib() { // Only the address is inspected. C sign-extends a 32-bit pointer converted to u64, // so 32-bit hosts rejected every address above 2 GiB and dropped the smartcasts // recorded under such names. - high := unsafe { tos(&u8(voidptr(usize(0x9000_0000))), 1) } + high := unsafe { tos(&u8(voidptr(uint(0x9000_0000))), 1) } assert valid_string_data(high) - low := unsafe { tos(&u8(voidptr(usize(16))), 1) } + low := unsafe { tos(&u8(voidptr(uint(16))), 1) } assert !valid_string_data(low) } diff --git a/vlib/v/workers/thread_nix.c.v b/vlib/v/workers/thread_nix.c.v index c09f3479f1..5db0f37b87 100644 --- a/vlib/v/workers/thread_nix.c.v +++ b/vlib/v/workers/thread_nix.c.v @@ -21,7 +21,7 @@ fn C.v3_linux_name_worker() int fn C.v3_pthread_zero() C.pthread_t @[c_extern] -fn C.v3_pthread_create(worker &C.pthread_t, stack_size usize, start_routine fn (voidptr) voidptr, arg voidptr) int +fn C.v3_pthread_create(worker &C.pthread_t, stack_size uint, start_routine fn (voidptr) voidptr, arg voidptr) int @[c_extern] fn C.v3_pthread_is_current(worker C.pthread_t) int @@ -33,7 +33,7 @@ struct WorkerThread { // worker_thread_create starts a joinable worker with an explicit stack // reservation. A non-zero result is the pthread error code. -fn worker_thread_create(stack_size usize, start_routine fn (voidptr) voidptr, arg voidptr) (WorkerThread, int) { +fn worker_thread_create(stack_size uint, start_routine fn (voidptr) voidptr, arg voidptr) (WorkerThread, int) { mut thread_id := C.v3_pthread_zero() rc := C.v3_pthread_create(&thread_id, stack_size, start_routine, arg) return WorkerThread{ diff --git a/vlib/v/workers/thread_windows.c.v b/vlib/v/workers/thread_windows.c.v index 615a8953d5..5fecce8c40 100644 --- a/vlib/v/workers/thread_windows.c.v +++ b/vlib/v/workers/thread_windows.c.v @@ -2,7 +2,7 @@ module workers #flag @VMODROOT/vlib/v/winthread_helper_windows.o -fn C.v3_win_thread_create(stack_size usize, start_routine fn (voidptr) voidptr, arg voidptr, thread_id &u32) voidptr +fn C.v3_win_thread_create(stack_size uint, start_routine fn (voidptr) voidptr, arg voidptr, thread_id &u32) voidptr fn C.v3_win_thread_join(handle voidptr) int fn C.v3_win_thread_is_current(thread_id u32) int @@ -19,7 +19,7 @@ struct WorkerThread { // callback runs behind a WINAPI thunk, so its C calling convention never has // to match the thread start routine's. A non-zero result means the thread // (or its thunk context) could not be created. -fn worker_thread_create(stack_size usize, start_routine fn (voidptr) voidptr, arg voidptr) (WorkerThread, int) { +fn worker_thread_create(stack_size uint, start_routine fn (voidptr) voidptr, arg voidptr) (WorkerThread, int) { mut id := u32(0) handle := C.v3_win_thread_create(stack_size, start_routine, arg, &id) if handle == unsafe { nil } { diff --git a/vlib/v/workers/worker_pool.c.v b/vlib/v/workers/worker_pool.c.v index cb59d48eb9..5a153bc2fb 100644 --- a/vlib/v/workers/worker_pool.c.v +++ b/vlib/v/workers/worker_pool.c.v @@ -54,20 +54,20 @@ pub fn limit_pool_size(size int) { // worker_stack_size resolves the per-worker stack size, honoring the // V3_WORKER_STACK_MB override and falling back to the default when it is unset, // non-numeric, or non-positive. -fn worker_stack_size() usize { +fn worker_stack_size() uint { requested_mb := os.getenv('V3_WORKER_STACK_MB') if requested_mb.len == 0 { - return usize(compiler_worker_stack_size) + return uint(compiler_worker_stack_size) } mb := requested_mb.int() if mb <= 0 { - return usize(compiler_worker_stack_size) + return uint(compiler_worker_stack_size) } mut bytes := i64(mb) * 1024 * 1024 if bytes < min_worker_stack_size { bytes = min_worker_stack_size } - return usize(bytes) + return uint(bytes) } // Task is one type-erased compiler phase callback submitted to Pool. diff --git a/vlib/v/workers/worker_pool_test.v b/vlib/v/workers/worker_pool_test.v index b800521d03..4e90c28d1c 100644 --- a/vlib/v/workers/worker_pool_test.v +++ b/vlib/v/workers/worker_pool_test.v @@ -37,20 +37,20 @@ fn test_pool_preserves_recursive_phase_stack_size() { fn test_worker_stack_size_env_override_and_clamp() { os.unsetenv('V3_WORKER_STACK_MB') - assert worker_stack_size() == usize(compiler_worker_stack_size) + assert worker_stack_size() == uint(compiler_worker_stack_size) os.setenv('V3_WORKER_STACK_MB', '16', true) - assert worker_stack_size() == usize(16 * 1024 * 1024) + assert worker_stack_size() == uint(16 * 1024 * 1024) // Below the floor is clamped up to min_worker_stack_size. os.setenv('V3_WORKER_STACK_MB', '1', true) - assert worker_stack_size() == usize(min_worker_stack_size) + assert worker_stack_size() == uint(min_worker_stack_size) // Non-numeric / non-positive values fall back to the default. os.setenv('V3_WORKER_STACK_MB', 'not-a-number', true) - assert worker_stack_size() == usize(compiler_worker_stack_size) + assert worker_stack_size() == uint(compiler_worker_stack_size) os.setenv('V3_WORKER_STACK_MB', '0', true) - assert worker_stack_size() == usize(compiler_worker_stack_size) + assert worker_stack_size() == uint(compiler_worker_stack_size) os.unsetenv('V3_WORKER_STACK_MB') } diff --git a/vlib/veb/openapi_document_test.v b/vlib/veb/openapi_document_test.v index 0018fd66a6..0d7a0e0bfe 100644 --- a/vlib/veb/openapi_document_test.v +++ b/vlib/veb/openapi_document_test.v @@ -835,10 +835,10 @@ fn test_typed_openapi_sum_first_reference_observes_later_override() { fn test_typed_openapi_unsigned_64_bit_schema_accepts_full_range() { mut doc := new_openapi(title: 'Unsigned values')! assert json2.encode(u64(18446744073709551615)) == '18446744073709551615' - for schema in [doc.schema[u64](), doc.schema[usize]()] { + for schema in [doc.schema[u64](), doc.schema[uint]()] { assert schema['type']!.str() == 'integer' assert api_at(json2.Any(schema), 'minimum').str() == '0' - if sizeof(usize) == 8 { + if sizeof(uint) == 8 { assert 'format' !in schema } } diff --git a/vlib/veb/openapi_schema.v b/vlib/veb/openapi_schema.v index e90c67b8a0..d158ce3737 100644 --- a/vlib/veb/openapi_schema.v +++ b/vlib/veb/openapi_schema.v @@ -313,13 +313,13 @@ fn openapi_integer_schema[T](_value T) OpenApiSchema { mut schema := OpenApiSchema({ 'type': json2.Any('integer') }) - $if T.unaliased_typ is u64 || T.unaliased_typ is usize { + $if T.unaliased_typ is u64 || T.unaliased_typ is uint { schema['minimum'] = 0 // OpenAPI's int64 is signed and cannot describe the full unsigned range. if sizeof(T) > 4 { return schema } } mut format := if sizeof(T) > 4 { 'int64' } else { 'int32' } - $if T.unaliased_typ is u32 || T.unaliased_typ is usize { + $if T.unaliased_typ is u32 || T.unaliased_typ is uint { format = 'int64' } schema['format'] = format diff --git a/vlib/veb/route_info.v b/vlib/veb/route_info.v index 2dcecb2c40..5d0c915a0b 100644 --- a/vlib/veb/route_info.v +++ b/vlib/veb/route_info.v @@ -32,14 +32,14 @@ fn flatten_route_info[A](app &A, routes map[string]Route) []RouteInfo { // Classify reflected parameter types directly; param.typ is not a generic value. $if param.typ is u64 { schemas << openapi_integer_schema(u64(0)) - } $else $if param.typ is usize { - schemas << openapi_integer_schema(usize(0)) + } $else $if param.typ is uint { + schemas << openapi_integer_schema(uint(0)) } $else $if param.typ is u32 { schemas << openapi_integer_schema(u32(0)) } $else $if param.typ is i64 { schemas << openapi_integer_schema(i64(0)) - } $else $if param.typ is isize { - schemas << openapi_integer_schema(isize(0)) + } $else $if param.typ is int { + schemas << openapi_integer_schema(int(0)) } $else $if param.typ is $int { schemas << openapi_integer_schema(int(0)) } $else $if param.typ is bool { diff --git a/vlib/veb/sendfile_freebsd.c.v b/vlib/veb/sendfile_freebsd.c.v index 8a5c205902..ea0e781296 100644 --- a/vlib/veb/sendfile_freebsd.c.v +++ b/vlib/veb/sendfile_freebsd.c.v @@ -1,11 +1,11 @@ module veb -fn C.sendfile(in_fd i32, out_fd i32, offset i64, count usize, hdtr voidptr, sent &i64, flags i32) i32 +fn C.sendfile(in_fd i32, out_fd i32, offset i64, count uint, hdtr voidptr, sent &i64, flags i32) i32 fn sendfile(out_fd int, in_fd int, nr_bytes int) int { // out_fd must be a stream socket descriptor. mut sent := i64(0) - r := C.sendfile(in_fd, out_fd, 0, usize(nr_bytes), unsafe { nil }, &sent, 0) + r := C.sendfile(in_fd, out_fd, 0, uint(nr_bytes), unsafe { nil }, &sent, 0) if r == 0 { return nr_bytes } diff --git a/vlib/veb/sendfile_linux.c.v b/vlib/veb/sendfile_linux.c.v index 7f1313fea2..61b9b9581e 100644 --- a/vlib/veb/sendfile_linux.c.v +++ b/vlib/veb/sendfile_linux.c.v @@ -2,9 +2,9 @@ module veb #include -fn C.sendfile(out_fd i32, in_fd i32, offset voidptr, count usize) i32 +fn C.sendfile(out_fd i32, in_fd i32, offset voidptr, count uint) i32 fn sendfile(out_fd int, in_fd int, nr_bytes int) int { // always pass nil as offset, so the file offset will be used and updated. - return C.sendfile(out_fd, in_fd, 0, usize(nr_bytes)) + return C.sendfile(out_fd, in_fd, 0, uint(nr_bytes)) } diff --git a/vlib/x/benchmark/benchmark.v b/vlib/x/benchmark/benchmark.v index 65c4d62989..c58732b2d8 100644 --- a/vlib/x/benchmark/benchmark.v +++ b/vlib/x/benchmark/benchmark.v @@ -17,8 +17,8 @@ pub mut: start_time time.Time // start timestamp of timer duration time.Duration // expected time of benchmark process failed bool // flag of bench_func failure. true if one of bench_func run failed - start_memory usize // memory status on start benchmark - start_allocs usize // size of object allocated on heap + start_memory uint // memory status on start benchmark + start_allocs uint // size of object allocated on heap } // BenchmarkDefaults is params struct for providing parameters of benchmarking to setup function @@ -220,8 +220,8 @@ struct BenchmarkResult { pub mut: n i64 // iterations count t time.Duration // elapsed time - mem usize // all allocated memory - allocs usize // heap allocated memory + mem uint // all allocated memory + allocs uint // heap allocated memory } // ns_per_op - elapsed time in nanoseconds per iteration diff --git a/vlib/x/crypto/slhdsa/slhdsa.c.v b/vlib/x/crypto/slhdsa/slhdsa.c.v index 8ef80bcf4e..1cc127f7a0 100644 --- a/vlib/x/crypto/slhdsa/slhdsa.c.v +++ b/vlib/x/crypto/slhdsa/slhdsa.c.v @@ -50,7 +50,7 @@ fn C.EVP_PKEY_is_a(pkey &C.EVP_PKEY, name &char) i32 fn C.EVP_PKEY_size(key &C.EVP_PKEY) i32 fn C.EVP_PKEY_dup(key &C.EVP_PKEY) &C.EVP_PKEY fn C.EVP_PKEY_free(key &C.EVP_PKEY) -fn C.EVP_PKEY_get_octet_string_param(pkey &C.EVP_PKEY, key_name &char, buf &u8, max_buf_sz usize, out_len &usize) i32 +fn C.EVP_PKEY_get_octet_string_param(pkey &C.EVP_PKEY, key_name &char, buf &u8, max_buf_sz uint, out_len &uint) i32 fn C.EVP_PKEY_print_private(out &C.BIO, pkey &C.EVP_PKEY, indent i32, pctx voidptr) i32 fn C.EVP_PKEY_print_public(out &C.BIO, pkey &C.EVP_PKEY, indent i32, pctx voidptr) i32 fn C.EVP_PKEY_keygen_init(ctx &C.EVP_PKEY_CTX) i32 // 1 success @@ -62,10 +62,10 @@ fn C.EVP_PKEY_get_bits(pkey &C.EVP_PKEY) i32 fn C.EVP_PKEY_get_security_bits(pkey &C.EVP_PKEY) i32 fn C.EVP_PKEY_sign_init_ex(ctx &C.EVP_PKEY_CTX, params &C.OSSL_PARAM) i32 fn C.EVP_PKEY_sign_message_init(ctx &C.EVP_PKEY_CTX, algo &C.EVP_SIGNATURE, params &C.OSSL_PARAM) i32 -fn C.EVP_PKEY_sign(ctx &C.EVP_PKEY_CTX, sig &u8, siglen &usize, tbs &u8, tbslen usize) i32 +fn C.EVP_PKEY_sign(ctx &C.EVP_PKEY_CTX, sig &u8, siglen &uint, tbs &u8, tbslen uint) i32 fn C.EVP_PKEY_verify_message_init(ctx &C.EVP_PKEY_CTX, algo &C.EVP_SIGNATURE, params &C.OSSL_PARAM) i32 -fn C.EVP_PKEY_verify(ctx &C.EVP_PKEY_CTX, sig &u8, siglen usize, tbs &u8, tbslen usize) i32 -fn C.EVP_PKEY_set_octet_string_param(key &C.EVP_PKEY, key_name &char, buf voidptr, bsize usize) i32 +fn C.EVP_PKEY_verify(ctx &C.EVP_PKEY_CTX, sig &u8, siglen uint, tbs &u8, tbslen uint) i32 +fn C.EVP_PKEY_set_octet_string_param(key &C.EVP_PKEY, key_name &char, buf voidptr, bsize uint) i32 fn C.EVP_PKEY_fromdata_init(ctx &C.EVP_PKEY_CTX) i32 fn C.EVP_PKEY_fromdata(ctx &C.EVP_PKEY_CTX, ppkey &&C.EVP_PKEY, selection i32, params &C.OSSL_PARAM) i32 fn C.EVP_PKEY_check(ctx &C.EVP_PKEY_CTX) i32 @@ -98,7 +98,7 @@ fn C.OSSL_PARAM_free(params &C.OSSL_PARAM) fn C.OSSL_PARAM_BLD_free(param_bld &C.OSSL_PARAM_BLD) fn C.OSSL_PARAM_BLD_new() &C.OSSL_PARAM_BLD fn C.OSSL_PARAM_BLD_push_int(bld &C.OSSL_PARAM_BLD, key &char, val i32) i32 -fn C.OSSL_PARAM_BLD_push_octet_string(bld &C.OSSL_PARAM_BLD, key &char, buf voidptr, bsize usize) i32 +fn C.OSSL_PARAM_BLD_push_octet_string(bld &C.OSSL_PARAM_BLD, key &char, buf voidptr, bsize uint) i32 fn C.OSSL_PARAM_BLD_to_param(bld &C.OSSL_PARAM_BLD) &C.OSSL_PARAM @[typedef] @@ -108,6 +108,6 @@ struct C.BIO_METHOD {} struct C.BIO {} fn C.BIO_new(t &C.BIO_METHOD) &C.BIO -fn C.BIO_read_ex(b &C.BIO, data voidptr, dlen i32, readbytes &usize) i32 +fn C.BIO_read_ex(b &C.BIO, data voidptr, dlen i32, readbytes &uint) i32 fn C.BIO_free_all(a &C.BIO) fn C.BIO_s_mem() &C.BIO_METHOD diff --git a/vlib/x/crypto/slhdsa/slhdsa.v b/vlib/x/crypto/slhdsa/slhdsa.v index b3c0af46ff..f030d380d9 100644 --- a/vlib/x/crypto/slhdsa/slhdsa.v +++ b/vlib/x/crypto/slhdsa/slhdsa.v @@ -82,7 +82,7 @@ pub fn (pv PrivateKey) dump_key() !string { C.BIO_free_all(bo) return error('print private failed') } - size := usize(0) + size := uint(0) buf := []u8{len: default_bioread_bufsize} m := C.BIO_read_ex(bo, buf.data, buf.len, &size) @@ -142,7 +142,7 @@ pub fn (pb PublicKey) dump_key() !string { C.BIO_free_all(bo) return error('EVP_PKEY_print_public failed') } - size := usize(0) + size := uint(0) mut m := C.BIO_read_ex(bo, 0, default_bioread_bufsize, &size) mut buf := []u8{len: int(size)} m = C.BIO_read_ex(bo, buf.data, buf.len, &size) @@ -168,7 +168,7 @@ pub fn (mut pb PublicKey) free() { const default_privkey_buffer = 128 fn (pv PrivateKey) bytes() ![]u8 { - priv_len := usize(0) + priv_len := uint(0) priv := []u8{len: default_privkey_buffer} n := C.EVP_PKEY_get_octet_string_param(pv.key, c'priv', priv.data, priv.len, &priv_len) @@ -185,7 +185,7 @@ fn (pv PrivateKey) bytes() ![]u8 { const default_pubkey_buffer = 144 fn (pv PrivateKey) public_bytes() ![]u8 { - pblen := usize(0) + pblen := uint(0) buf := []u8{len: default_pubkey_buffer} n := C.EVP_PKEY_get_octet_string_param(pv.key, c'pub', buf.data, buf.len, &pblen) if n <= 0 { @@ -280,7 +280,7 @@ fn slhdsa_do_sign(key &C.EVP_PKEY, msg []u8, opt SignerOpts) ![]u8 { return error('EVP_PKEY_sign_message_init failed') } - sig_len := usize(C.EVP_PKEY_size(key)) + sig_len := uint(C.EVP_PKEY_size(key)) buf := []u8{len: int(sig_len)} // Do signing the msg and updates the sig_len. m := C.EVP_PKEY_sign(sctx, buf.data, &sig_len, msg.data, msg.len) diff --git a/vlib/x/multiwindow/appkit_backend.c.v b/vlib/x/multiwindow/appkit_backend.c.v index bf89587755..8b552a98ab 100644 --- a/vlib/x/multiwindow/appkit_backend.c.v +++ b/vlib/x/multiwindow/appkit_backend.c.v @@ -191,11 +191,11 @@ $if darwin { fn C.v_multiwindow_appkit_service_set_fullscreen(state voidptr, enabled int) int fn C.v_multiwindow_appkit_service_monitor_revision() u64 fn C.v_multiwindow_appkit_service_monitor_count() int - fn C.v_multiwindow_appkit_service_monitor_info(index int, out_native_id &u64, out_x &int, out_y &int, out_width &int, out_height &int, out_work_x &int, out_work_y &int, out_work_width &int, out_work_height &int, out_scale &f32, out_primary &int, out_name_length &usize) int - fn C.v_multiwindow_appkit_service_copy_monitor_name(index int, out_name &char, capacity usize) int - fn C.v_multiwindow_appkit_service_set_clipboard_text(state voidptr, text &char, text_length usize) int - fn C.v_multiwindow_appkit_service_clipboard_text_length(state voidptr, out_length &usize) int - fn C.v_multiwindow_appkit_service_copy_clipboard_text(state voidptr, out_text &char, capacity usize) int + fn C.v_multiwindow_appkit_service_monitor_info(index int, out_native_id &u64, out_x &int, out_y &int, out_width &int, out_height &int, out_work_x &int, out_work_y &int, out_work_width &int, out_work_height &int, out_scale &f32, out_primary &int, out_name_length &uint) int + fn C.v_multiwindow_appkit_service_copy_monitor_name(index int, out_name &char, capacity uint) int + fn C.v_multiwindow_appkit_service_set_clipboard_text(state voidptr, text &char, text_length uint) int + fn C.v_multiwindow_appkit_service_clipboard_text_length(state voidptr, out_length &uint) int + fn C.v_multiwindow_appkit_service_copy_clipboard_text(state voidptr, out_text &char, capacity uint) int fn C.v_multiwindow_appkit_service_set_owner(state voidptr, owner_state voidptr, modal int) int fn C.v_multiwindow_appkit_service_clear_owner(state voidptr) int fn C.v_multiwindow_appkit_service_native_window(state voidptr) voidptr @@ -206,8 +206,8 @@ $if darwin { fn C.v_multiwindow_appkit_service_stage_window_readback(state voidptr, request u64, x int, y int, width int, height int, producing_frame u64) int fn C.v_multiwindow_appkit_service_stage_image_readback(state voidptr, texture voidptr, request u64, x int, y int, width int, height int, producing_frame u64) int fn C.v_multiwindow_appkit_service_resolve_readbacks_after_submit(state voidptr, submitted_frame u64, submission_succeeded int) int - fn C.v_multiwindow_appkit_service_take_readback_result(state voidptr, out_request &u64, out_status &int, out_width &int, out_height &int, out_stride &int, out_submitted_frame &u64, out_byte_length &usize) int - fn C.v_multiwindow_appkit_service_copy_readback_pixels(state voidptr, request u64, out_pixels &u8, capacity usize) int + fn C.v_multiwindow_appkit_service_take_readback_result(state voidptr, out_request &u64, out_status &int, out_width &int, out_height &int, out_stride &int, out_submitted_frame &u64, out_byte_length &uint) int + fn C.v_multiwindow_appkit_service_copy_readback_pixels(state voidptr, request u64, out_pixels &u8, capacity uint) int fn C.v_multiwindow_appkit_service_release_readback_result(state voidptr, request u64) int fn C.v_multiwindow_appkit_service_cancel_readback(state voidptr, request u64) int fn C.v_multiwindow_appkit_service_cancel_all_readbacks(state voidptr) int @@ -570,8 +570,8 @@ fn appkit_plan_service_monitors(records []AppKitServiceMonitorRecord, snapshot [ } } -fn appkit_clipboard_length_is_valid(length usize) bool { - return length <= usize(service_appkit_clipboard_max_bytes) +fn appkit_clipboard_length_is_valid(length uint) bool { + return length <= uint(service_appkit_clipboard_max_bytes) } fn appkit_require_clipboard_result(status int) ! { @@ -1013,16 +1013,16 @@ fn (mut backend AppKitBackend) service_monitor_snapshot(app_instance u64) ![]Ser mut snapshot := []AppKitServiceRawMonitor{cap: count} for index in 0 .. count { mut raw := AppKitServiceRawMonitor{} - mut name_length := usize(0) + mut name_length := uint(0) if C.v_multiwindow_appkit_service_monitor_info(index, &raw.native_id, &raw.x, &raw.y, &raw.width, &raw.height, &raw.work_x, &raw.work_y, &raw.work_width, &raw.work_height, &raw.scale, &raw.primary, &name_length) <= 0 - || name_length > usize(service_appkit_monitor_name_max_bytes) { + || name_length > uint(service_appkit_monitor_name_max_bytes) { return error(err_capability_unsupported) } mut monitor_name := 'AppKit display ${raw.native_id}' if name_length > 0 { mut name := []u8{len: int(name_length) + 1} if C.v_multiwindow_appkit_service_copy_monitor_name(index, - unsafe { &char(name.data) }, usize(name.len)) <= 0 { + unsafe { &char(name.data) }, uint(name.len)) <= 0 { return error(err_capability_unsupported) } monitor_name = name[..int(name_length)].bytestr() @@ -1045,12 +1045,12 @@ fn (mut backend AppKitBackend) service_monitor_snapshot(app_instance u64) ![]Ser fn (mut backend AppKitBackend) service_set_clipboard_text(id WindowId, request ServiceRequestId, text string) !BackendClipboardStart { index := backend.ensure_service_bridge(id)! _ = request - if !appkit_clipboard_length_is_valid(usize(text.len)) { + if !appkit_clipboard_length_is_valid(uint(text.len)) { return error(err_clipboard_capacity) } $if darwin { status := C.v_multiwindow_appkit_service_set_clipboard_text(backend.windows[index].state, - &char(text.str), usize(text.len)) + &char(text.str), uint(text.len)) if status == service_appkit_result_indeterminate { return BackendClipboardStart{ completed: true @@ -1070,7 +1070,7 @@ fn (mut backend AppKitBackend) service_request_clipboard_text(id WindowId, reque index := backend.ensure_service_bridge(id)! _ = request $if darwin { - mut text_length := usize(0) + mut text_length := uint(0) length_status := C.v_multiwindow_appkit_service_clipboard_text_length(backend.windows[index].state, &text_length) appkit_require_clipboard_result(length_status)! @@ -1084,7 +1084,7 @@ fn (mut backend AppKitBackend) service_request_clipboard_text(id WindowId, reque } mut text := []u8{len: int(text_length) + 1} copy_status := C.v_multiwindow_appkit_service_copy_clipboard_text(backend.windows[index].state, - unsafe { &char(text.data) }, usize(text.len)) + unsafe { &char(text.data) }, uint(text.len)) appkit_require_clipboard_result(copy_status)! return BackendClipboardStart{ completed: true @@ -1278,7 +1278,7 @@ fn (mut backend AppKitBackend) service_take_readback_results() ![]BackendReadbac mut height := 0 mut stride := 0 mut submitted_frame := u64(0) - mut byte_length := usize(0) + mut byte_length := uint(0) take_status := C.v_multiwindow_appkit_service_take_readback_result(record.state, &request, &status, &width, &height, &stride, &submitted_frame, &byte_length) if take_status == service_appkit_result_unavailable { @@ -1295,8 +1295,8 @@ fn (mut backend AppKitBackend) service_take_readback_results() ![]BackendReadbac mut pixels := []u8{} mut copied := false if status == service_appkit_readback_ready && width > 0 && height > 0 - && stride >= width * 4 && byte_length == usize(stride) * usize(height) - && byte_length <= usize(0x7fffffff) { + && stride >= width * 4 && byte_length == uint(stride) * uint(height) + && byte_length <= uint(0x7fffffff) { pixels = []u8{len: int(byte_length)} if C.v_multiwindow_appkit_service_copy_readback_pixels(record.state, request, pixels.data, byte_length) == service_appkit_result_ok { diff --git a/vlib/x/multiwindow/multiwindow_test.v b/vlib/x/multiwindow/multiwindow_test.v index 4bf9400957..473a5f13b2 100644 --- a/vlib/x/multiwindow/multiwindow_test.v +++ b/vlib/x/multiwindow/multiwindow_test.v @@ -2965,15 +2965,15 @@ fn test_win32_clipboard_read_budget_survives_native_terminal_until_core_delivery slot: 0 generation: 1 } - backend.admit_clipboard_request(request, window, voidptr(usize(1)), .clipboard_read, []u16{})! + backend.admit_clipboard_request(request, window, voidptr(uint(1)), .clipboard_read, []u16{})! assert backend.clipboard_pending.len == 1 - assert backend.clipboard_pending_bytes == usize(win32_clipboard_max_pending_bytes) + assert backend.clipboard_pending_bytes == uint(win32_clipboard_max_pending_bytes) event := backend.finish_clipboard_head(.ready, 'tiny read', '') assert backend.clipboard_pending.len == 0 assert event.event.service.clipboard.id == request assert event.event.service.clipboard.status == .ready - assert backend.clipboard_pending_bytes == usize('tiny read'.len + 1) + assert backend.clipboard_pending_bytes == uint('tiny read'.len + 1) assert backend.clipboard_retained.len == 1 assert !backend.clipboard_retained[0].claimed_by_app mismatched := ServiceEvent{ @@ -2988,16 +2988,16 @@ fn test_win32_clipboard_read_budget_survives_native_terminal_until_core_delivery } backend.claim_clipboard_terminal_storage(mismatched) backend.discard_unclaimed_clipboard_terminal_storage(mismatched) - assert backend.clipboard_pending_bytes == usize('tiny read'.len + 1) + assert backend.clipboard_pending_bytes == uint('tiny read'.len + 1) assert !backend.clipboard_retained[0].claimed_by_app backend.claim_clipboard_terminal_storage(event.event.service) assert backend.clipboard_retained.len == 1 assert backend.clipboard_retained[0].claimed_by_app backend.purge_clipboard_window(window) - assert backend.clipboard_pending_bytes == usize('tiny read'.len + 1) + assert backend.clipboard_pending_bytes == uint('tiny read'.len + 1) backend.discard_unclaimed_clipboard_terminal_storage(event.event.service) - assert backend.clipboard_pending_bytes == usize('tiny read'.len + 1) + assert backend.clipboard_pending_bytes == uint('tiny read'.len + 1) assert backend.clipboard_retained.len == 1 backend.release_claimed_clipboard_terminal_storage(event.event.service) assert backend.clipboard_pending_bytes == 0 @@ -3009,10 +3009,10 @@ fn test_win32_clipboard_read_budget_survives_native_terminal_until_core_delivery app_instance: 1 serial: 2 } - backend.admit_clipboard_request(second_request, window, voidptr(usize(1)), .clipboard_read, + backend.admit_clipboard_request(second_request, window, voidptr(uint(1)), .clipboard_read, []u16{})! rejected := backend.finish_clipboard_head(.ready, 'rejected read', '') - assert backend.clipboard_pending_bytes == usize('rejected read'.len + 1) + assert backend.clipboard_pending_bytes == uint('rejected read'.len + 1) backend.discard_unclaimed_clipboard_terminal_storage(rejected.event.service) assert backend.clipboard_pending_bytes == 0 assert backend.clipboard_retained.len == 0 diff --git a/vlib/x/multiwindow/native_operation_proof_test.v b/vlib/x/multiwindow/native_operation_proof_test.v index b248838da9..f2a9fb2273 100644 --- a/vlib/x/multiwindow/native_operation_proof_test.v +++ b/vlib/x/multiwindow/native_operation_proof_test.v @@ -216,9 +216,9 @@ $if gg_multiwindow ?|| x_multiwindow_render ? { fn C.v_multiwindow_test_native_primitive_reset() fn C.v_multiwindow_test_native_primitive_call_count() u64 fn C.v_multiwindow_test_native_primitive(valid_mask u64, return_value i64, handle u64, native_code i64, observed_count u64, observed_flags u64, out &C.VMultiwindowNativePrimitive) -fn C.v_multiwindow_test_native_primitive_abi_size() usize -fn C.v_multiwindow_test_native_primitive_abi_last_offset() usize -fn C.v_multiwindow_test_common_native_primitive_size() usize +fn C.v_multiwindow_test_native_primitive_abi_size() uint +fn C.v_multiwindow_test_native_primitive_abi_last_offset() uint +fn C.v_multiwindow_test_common_native_primitive_size() uint fn C.v_multiwindow_test_common_native_primitive_mask() u64 struct NativeContextMismatchCase { @@ -502,9 +502,9 @@ fn after_each() { fn test_native_primitive_abi_is_portable_and_included_from_production_header() { expected_mask := native_valid_return_value | native_valid_handle | native_valid_egl_error | native_valid_errno | native_valid_wayland_display_error | native_valid_dxgi_removal_reason | native_valid_observed_count | native_valid_observed_flags | native_valid_selected_value | native_valid_object_identity_0 | u64(1024) | u64(2048) - assert C.v_multiwindow_test_native_primitive_abi_size() == usize(104) - assert C.v_multiwindow_test_common_native_primitive_size() == usize(104) - assert C.v_multiwindow_test_native_primitive_abi_last_offset() == usize(96) + assert C.v_multiwindow_test_native_primitive_abi_size() == uint(104) + assert C.v_multiwindow_test_common_native_primitive_size() == uint(104) + assert C.v_multiwindow_test_native_primitive_abi_last_offset() == uint(96) assert C.v_multiwindow_test_common_native_primitive_mask() == expected_mask } @@ -2752,7 +2752,7 @@ $if gg_multiwindow ?|| x_multiwindow_render ? { started: app.backend.x11.started render_health: app.backend.x11.render_health render_sequence: app.backend.x11.render_sequence - native_display: u64(usize(app.backend.x11.display)) + native_display: u64(uint(app.backend.x11.display)) egl_display: native_identity(app.backend.x11.egl_display) egl_config: native_identity(app.backend.x11.egl_config) egl_context: native_identity(app.backend.x11.egl_context) @@ -2768,12 +2768,12 @@ $if gg_multiwindow ?|| x_multiwindow_render ? { binding_surface: native_identity(binding.surface) egl_bad_current_recovery_used: app.backend.x11.egl_bad_current_recovery_used native_visual_id: app.backend.x11.native_visual_id - native_operations_identity: u64(usize(app.backend.x11.native_operations)) + native_operations_identity: u64(uint(app.backend.x11.native_operations)) x11_screen: app.backend.x11.screen x11_xdnd_version: i64(app.backend.x11.xdnd_version) x11_keycodes: app.backend.x11.keycodes backend_owned_identities: [ - u64(usize(app.backend.x11.display)), + u64(uint(app.backend.x11.display)), u64(app.backend.x11.root), u64(app.backend.x11.wm_protocols), u64(app.backend.x11.wm_delete_window), @@ -2835,8 +2835,8 @@ $if gg_multiwindow ?|| x_multiwindow_render ? { } windows << NativePhaseAWindowOwnershipSnapshot{ id: record.id - native_operations_identity: u64(usize(record.native_operations)) - owner_identity: u64(usize(record.owner)) + native_operations_identity: u64(uint(record.native_operations)) + owner_identity: u64(uint(record.owner)) native_window_identity: native_identity(record.surface) native_aux_identity_0: native_identity(record.xdg_surface) native_aux_identity_1: native_identity(record.xdg_toplevel) @@ -2920,7 +2920,7 @@ $if gg_multiwindow ?|| x_multiwindow_render ? { event_sequence_terminal: app.backend.wayland.event_sequence_terminal wayland_display_unavailable: app.backend.wayland.wayland_display_unavailable wayland_display_error: app.backend.wayland.wayland_display_error - native_operations_identity: u64(usize(app.backend.wayland.native_operations)) + native_operations_identity: u64(uint(app.backend.wayland.native_operations)) data_offer_has_uri_list: app.backend.wayland.data_offer_has_uri_list data_offer_source_actions: app.backend.wayland.data_offer_source_actions data_offer_selected_action: app.backend.wayland.data_offer_selected_action @@ -5625,7 +5625,7 @@ $if gg_multiwindow ?|| x_multiwindow_render ? { fn native_assert_sokol_sequence_for_test(snapshot multiwindow_sokol_trace.TypedSnapshot, expected []multiwindow_sokol_trace.Operation) { assert !snapshot.overflow assert snapshot.install_generation != 0 - assert snapshot.count == usize(snapshot.records.len) + assert snapshot.count == uint(snapshot.records.len) assert snapshot.records.len == expected.len for index, operation in expected { record := snapshot.records[index] @@ -5714,7 +5714,7 @@ $if gg_multiwindow ?|| x_multiwindow_render ? { fn native_sokol_swapchain_record_for_test(snapshot multiwindow_sokol_trace.TypedSnapshot) multiwindow_sokol_trace.Record { assert !snapshot.overflow assert snapshot.install_generation != 0 - assert snapshot.count == usize(snapshot.records.len) + assert snapshot.count == uint(snapshot.records.len) mut result := multiwindow_sokol_trace.Record{} mut matches := 0 for record in snapshot.records { @@ -9843,7 +9843,7 @@ $if gg_multiwindow ?|| x_multiwindow_render ? { match selected { .x11 { $if linux && x_multiwindow_x11 ? { - native_display = u64(usize(backend.x11.display)) + native_display = u64(uint(backend.x11.display)) xim_identity = native_identity(backend.x11.xim) assert native_display != 0 assert xim_identity != 0 diff --git a/vlib/x/multiwindow/render_native_state.v b/vlib/x/multiwindow/render_native_state.v index af20b4ca05..fb400dfbe3 100644 --- a/vlib/x/multiwindow/render_native_state.v +++ b/vlib/x/multiwindow/render_native_state.v @@ -452,11 +452,11 @@ mut: } fn native_identity(value voidptr) u64 { - return u64(usize(value)) + return u64(uint(value)) } fn native_pointer(identity u64) voidptr { - return voidptr(usize(identity)) + return voidptr(uint(identity)) } const native_valid_return_value = u64(1) diff --git a/vlib/x/multiwindow/service_native_appkit_contract_red_test.v b/vlib/x/multiwindow/service_native_appkit_contract_red_test.v index d09ffda722..a891ff5e96 100644 --- a/vlib/x/multiwindow/service_native_appkit_contract_red_test.v +++ b/vlib/x/multiwindow/service_native_appkit_contract_red_test.v @@ -189,15 +189,15 @@ fn test_appkit_common_clipboard_owner_borrow_and_titlebar_contracts() { slot: 0 generation: 1 } - parent_state := voidptr(usize(0x1234)) + parent_state := voidptr(uint(0x1234)) records := [AppKitWindowRecord{ id: parent, state: parent_state }] assert appkit_owner_native_state(parent, records)! == parent_state appkit_owner_native_state(WindowId{ app_instance: 9, slot: 1, generation: 1 }, records) or { assert err.msg() == err_window_not_found } - borrow := appkit_native_window_borrow_from_pointer(voidptr(usize(0x5678)))! + borrow := appkit_native_window_borrow_from_pointer(voidptr(uint(0x5678)))! assert borrow.backend == .appkit - assert borrow.primary == voidptr(usize(0x5678)) + assert borrow.primary == voidptr(uint(0x5678)) appkit_native_window_borrow_from_pointer(unsafe { nil }) or { assert err.msg() == err_capability_unsupported } diff --git a/vlib/x/multiwindow/service_native_appkit_nonreadback_test.v b/vlib/x/multiwindow/service_native_appkit_nonreadback_test.v index efdb0e7b8f..17736f2019 100644 --- a/vlib/x/multiwindow/service_native_appkit_nonreadback_test.v +++ b/vlib/x/multiwindow/service_native_appkit_nonreadback_test.v @@ -7,7 +7,7 @@ $if darwin { #flag darwin -framework Cocoa #include "@VMODROOT/vlib/x/multiwindow/testdata/appkit_nonreadback_test_helpers.h" - fn C.v_multiwindow_appkit_test_set_clipboard_ascii_payload(length usize) int + fn C.v_multiwindow_appkit_test_set_clipboard_ascii_payload(length uint) int fn C.v_multiwindow_appkit_test_install_release_mouse_lock_failure(window voidptr) int fn C.v_multiwindow_appkit_test_restore_release_mouse_lock() fn C.v_multiwindow_appkit_test_window_is_visible(window voidptr) int @@ -423,7 +423,7 @@ fn test_appkit_oversized_clipboard_is_capacity_not_unsupported() { title: 'AppKit clipboard capacity' visible: false )! - assert C.v_multiwindow_appkit_test_set_clipboard_ascii_payload(usize(service_appkit_clipboard_max_bytes) + 1) == 1 + assert C.v_multiwindow_appkit_test_set_clipboard_ascii_payload(uint(service_appkit_clipboard_max_bytes) + 1) == 1 app.service_request_clipboard_text(window) or { assert err.msg() == err_clipboard_capacity return diff --git a/vlib/x/multiwindow/service_native_appkit_readback_metal_red_test.v b/vlib/x/multiwindow/service_native_appkit_readback_metal_red_test.v index e28827fde7..30cbc3d398 100644 --- a/vlib/x/multiwindow/service_native_appkit_readback_metal_red_test.v +++ b/vlib/x/multiwindow/service_native_appkit_readback_metal_red_test.v @@ -22,7 +22,7 @@ $if darwin { fn C.v_multiwindow_appkit_readback_probe_state(window voidptr) voidptr fn C.v_multiwindow_appkit_readback_probe_framebuffer_only(window voidptr) int fn C.v_multiwindow_appkit_readback_probe_make_pattern_texture(window voidptr) voidptr - fn C.v_multiwindow_appkit_readback_probe_make_pattern_texture_size(window voidptr, width usize, height usize) voidptr + fn C.v_multiwindow_appkit_readback_probe_make_pattern_texture_size(window voidptr, width uint, height uint) voidptr fn C.v_multiwindow_appkit_readback_probe_release_texture(texture voidptr) fn C.v_multiwindow_appkit_readback_probe_arm_offscreen(state voidptr, texture voidptr, pass_serial u64, producing_frame u64) int fn C.v_multiwindow_appkit_readback_probe_make_command_buffer(window voidptr) voidptr @@ -32,8 +32,8 @@ $if darwin { fn C.v_multiwindow_appkit_readback_probe_stage_window(state voidptr, request u64, x int, y int, width int, height int, producing_frame u64) int fn C.v_multiwindow_appkit_readback_probe_stage_image(state voidptr, texture voidptr, request u64, x int, y int, width int, height int, producing_frame u64) int fn C.v_multiwindow_appkit_readback_probe_resolve(state voidptr, submitted_frame u64, submission_succeeded int) int - fn C.v_multiwindow_appkit_readback_probe_take(state voidptr, out_request &u64, out_status &int, out_width &int, out_height &int, out_stride &int, out_submitted_frame &u64, out_byte_length &usize) int - fn C.v_multiwindow_appkit_readback_probe_copy(state voidptr, request u64, out_pixels &u8, capacity usize) int + fn C.v_multiwindow_appkit_readback_probe_take(state voidptr, out_request &u64, out_status &int, out_width &int, out_height &int, out_stride &int, out_submitted_frame &u64, out_byte_length &uint) int + fn C.v_multiwindow_appkit_readback_probe_copy(state voidptr, request u64, out_pixels &u8, capacity uint) int fn C.v_multiwindow_appkit_readback_probe_release(state voidptr, request u64) int fn C.v_multiwindow_appkit_readback_probe_cancel(state voidptr, request u64) int fn C.v_multiwindow_appkit_readback_probe_cancel_all(state voidptr) int @@ -63,7 +63,7 @@ struct AppKitReadbackProbeResult { height int stride int submitted_frame u64 - byte_length usize + byte_length uint mut: take_status int } @@ -672,16 +672,16 @@ $if darwin && sokol_metal ?&& gg_multiwindow ? { assert result.width > 0 assert result.height > 0 assert result.stride == result.width * 4 - assert result.byte_length == usize(result.stride * result.height) + assert result.byte_length == uint(result.stride * result.height) mut pixels := []u8{len: int(result.byte_length)} if pixels.len > 1 { assert C.v_multiwindow_appkit_readback_probe_copy(state, result.request, pixels.data, - usize(pixels.len - 1)) <= 0 + uint(pixels.len - 1)) <= 0 } assert C.v_multiwindow_appkit_readback_probe_copy(state, result.request, pixels.data, - usize(pixels.len)) == 1 + uint(pixels.len)) == 1 assert C.v_multiwindow_appkit_readback_probe_copy(state, result.request, pixels.data, - usize(pixels.len)) == 0 + uint(pixels.len)) == 0 assert C.v_multiwindow_appkit_readback_probe_release(state, result.request) == 1 assert C.v_multiwindow_appkit_readback_probe_release(state, result.request) == 0 return pixels @@ -1047,7 +1047,7 @@ fn test_appkit_metal_readback_offscreen_slot_two_windows_and_odd_widths_red() { for width in [1, 3, 257] { texture := C.v_multiwindow_appkit_readback_probe_make_pattern_texture_size(native_a, - usize(width), 1) + uint(width), 1) assert texture != unsafe { nil } request := u64(400 + width) command := C.v_multiwindow_appkit_readback_probe_make_command_buffer(native_a) diff --git a/vlib/x/multiwindow/service_native_wayland_test.v b/vlib/x/multiwindow/service_native_wayland_test.v index 03075b5223..b384e8610d 100644 --- a/vlib/x/multiwindow/service_native_wayland_test.v +++ b/vlib/x/multiwindow/service_native_wayland_test.v @@ -53,8 +53,8 @@ fn test_wayland_owner_relation_reaches_xdg_toplevel_parent() { app.stop()! panic(err_window_not_found) } - assert C.v_multiwindow_wayland_get_last_parent_child() == usize(app.backend.wayland.windows[child_index].xdg_toplevel) - assert C.v_multiwindow_wayland_get_last_parent_owner() == usize(app.backend.wayland.windows[owner_index].xdg_toplevel) + assert C.v_multiwindow_wayland_get_last_parent_child() == uint(app.backend.wayland.windows[child_index].xdg_toplevel) + assert C.v_multiwindow_wayland_get_last_parent_owner() == uint(app.backend.wayland.windows[owner_index].xdg_toplevel) service_index := app.services.window_index(child)! registered_owner := app.services.windows[service_index].owner or { app.stop()! @@ -72,9 +72,9 @@ fn test_wayland_cursor_support_is_runtime_and_shape_specific() { mut backend := &WaylandBackend{} assert backend.cursor_support(.pointer) == .conditional assert backend.cursor_support(.resize_all) == .unsupported - backend.pointer = voidptr(usize(0x11)) - backend.cursor_shape_manager = voidptr(usize(0x12)) - backend.cursor_shape_device = voidptr(usize(0x13)) + backend.pointer = voidptr(uint(0x11)) + backend.cursor_shape_manager = voidptr(uint(0x12)) + backend.cursor_shape_device = voidptr(uint(0x13)) for shape in [CursorShape.default, .pointer, .move, .n_resize, .s_resize, .e_resize, .w_resize, .ne_resize, .nw_resize, .se_resize, .sw_resize, .ew_resize, .ns_resize, .nesw_resize, .nwse_resize, .grab, .grabbing, .text, .crosshair, .not_allowed] { @@ -134,10 +134,10 @@ fn test_wayland_output_scale_commits_at_done_and_refreshes_only_member_windows() native_operations.advance_renderer_attempt(1, 2)! mut backend := &WaylandBackend{ started: true - display: voidptr(usize(0x20)) + display: voidptr(uint(0x20)) native_operations: native_operations } - proxy := voidptr(usize(0x21)) + proxy := voidptr(uint(0x21)) output := &WaylandOutputRecord{ slot: 0 owner: backend @@ -159,7 +159,7 @@ fn test_wayland_output_scale_commits_at_done_and_refreshes_only_member_windows() global_name: 8 bound_version: 4 generation: 4 - proxy: voidptr(usize(0x22)) + proxy: voidptr(uint(0x22)) mode_width: 2560 mode_height: 1440 scale: 3 @@ -229,9 +229,9 @@ fn test_wayland_output_scale_commits_at_done_and_refreshes_only_member_windows() height: 48 buffer_scale: 1 render_scale: 1.5 - fractional_scale: voidptr(usize(0x23)) + fractional_scale: voidptr(uint(0x23)) fractional_scale_numerator: 180 - viewport: voidptr(usize(0x24)) + viewport: voidptr(uint(0x24)) render_target_generation: 11 output_slots: [0] } @@ -291,8 +291,8 @@ fn test_wayland_output_scale_commits_at_done_and_refreshes_only_member_windows() fn test_wayland_fractional_scale_preference_updates_metrics_and_framebuffer() { $if linux && sokol_wayland ? { mut backend := &WaylandBackend{} - fractional_scale := voidptr(usize(0x31)) - viewport := voidptr(usize(0x32)) + fractional_scale := voidptr(uint(0x31)) + viewport := voidptr(uint(0x32)) mut record := &WaylandWindowRecord{ id: WindowId{ app_instance: 1 @@ -417,7 +417,7 @@ fn test_wayland_remap_replays_persisted_toplevel_attributes_before_commit_and_pa mut owner := &WaylandWindowRecord{ id: owner_id owner: backend - xdg_toplevel: voidptr(usize(0xb1)) + xdg_toplevel: voidptr(uint(0xb1)) mapped: true } mut child := &WaylandWindowRecord{ @@ -433,9 +433,9 @@ fn test_wayland_remap_replays_persisted_toplevel_attributes_before_commit_and_pa request_server_decoration: true requested_maximized: true requested_fullscreen: true - surface: voidptr(usize(0xb2)) - xdg_toplevel: voidptr(usize(0xb3)) - toplevel_decoration: voidptr(usize(0xb4)) + surface: voidptr(uint(0xb2)) + xdg_toplevel: voidptr(uint(0xb3)) + toplevel_decoration: voidptr(uint(0xb4)) mapped: true } backend.windows << owner @@ -463,7 +463,7 @@ fn test_wayland_remap_replays_persisted_toplevel_attributes_before_commit_and_pa fn test_wayland_hide_barrier_failure_preserves_visible_window_state() { $if linux && sokol_wayland ? { mut backend := &WaylandBackend{ - display: voidptr(usize(0xc1)) + display: voidptr(uint(0xc1)) toplevel_replay_test: WaylandToplevelReplayTestSeam{ hide_barrier_override: true } @@ -476,7 +476,7 @@ fn test_wayland_hide_barrier_failure_preserves_visible_window_state() { mut record := &WaylandWindowRecord{ id: window owner: backend - surface: voidptr(usize(0xc2)) + surface: voidptr(uint(0xc2)) requested_visible: true mapped: true configured: true @@ -512,7 +512,7 @@ fn test_wayland_hide_barrier_failure_preserves_visible_window_state() { fn new_wayland_show_handshake_test_backend(observations []WaylandShowHandshakeTestObservation, requested_maximized bool, requested_fullscreen bool, baseline_maximized bool, baseline_fullscreen bool) (&WaylandBackend, WindowId) { mut backend := &WaylandBackend{ - display: voidptr(usize(0xd1)) + display: voidptr(uint(0xd1)) toplevel_replay_test: WaylandToplevelReplayTestSeam{ active: true show_handshake_override: true @@ -529,10 +529,10 @@ fn new_wayland_show_handshake_test_backend(observations []WaylandShowHandshakeTe owner: backend title: 'handshake' app_id: 'org.vlang.handshake' - surface: voidptr(usize(0xd2)) - xdg_surface: voidptr(usize(0xd3)) - xdg_toplevel: voidptr(usize(0xd4)) - wl_egl_window: voidptr(usize(0xd5)) + surface: voidptr(uint(0xd2)) + xdg_surface: voidptr(uint(0xd3)) + xdg_toplevel: voidptr(uint(0xd4)) + wl_egl_window: voidptr(uint(0xd5)) width: 360 height: 260 min_width: 1 @@ -849,9 +849,9 @@ fn test_wayland_hide_releases_only_egl_surface_and_invalidates_old_generation_on height: 60 frame_ready: true pending_egl_resize: true - egl_surface: voidptr(usize(0xe1)) + egl_surface: voidptr(uint(0xe1)) egl_surface_ticket: 91 - wl_egl_window: voidptr(usize(0xe2)) + wl_egl_window: voidptr(uint(0xe2)) wl_egl_window_ticket: 92 render_target_generation: 9 } @@ -860,7 +860,7 @@ fn test_wayland_hide_releases_only_egl_surface_and_invalidates_old_generation_on assert backend.toplevel_replay_test.operations == ['anchor', 'release_egl_surface'] assert record.egl_surface == unsafe { nil } assert record.egl_surface_ticket == 0 - assert record.wl_egl_window == voidptr(usize(0xe2)) + assert record.wl_egl_window == voidptr(uint(0xe2)) assert record.wl_egl_window_ticket == 92 assert record.render_target_generation == 10 assert record.pending_egl_resize @@ -886,12 +886,12 @@ fn test_wayland_hide_releases_only_egl_surface_and_invalidates_old_generation_on false) anchor_failure.toplevel_replay_test.hide_render_target_override = true anchor_failure.toplevel_replay_test.hide_anchor_failure = true - anchor_failure.windows[0].egl_surface = voidptr(usize(0xe3)) + anchor_failure.windows[0].egl_surface = voidptr(uint(0xe3)) anchor_failure.windows[0].egl_surface_ticket = 93 mut anchor_error := '' anchor_failure.release_window_render_target_for_hide(0) or { anchor_error = err.msg() } assert anchor_error == err_render_native_renderer_unavailable - assert anchor_failure.windows[0].egl_surface == voidptr(usize(0xe3)) + assert anchor_failure.windows[0].egl_surface == voidptr(uint(0xe3)) assert anchor_failure.windows[0].egl_surface_ticket == 93 assert anchor_failure.windows[0].render_target_generation == 7 @@ -899,12 +899,12 @@ fn test_wayland_hide_releases_only_egl_surface_and_invalidates_old_generation_on false) release_failure.toplevel_replay_test.hide_render_target_override = true release_failure.toplevel_replay_test.hide_surface_release_failure = true - release_failure.windows[0].egl_surface = voidptr(usize(0xe4)) + release_failure.windows[0].egl_surface = voidptr(uint(0xe4)) release_failure.windows[0].egl_surface_ticket = 94 mut release_error := '' release_failure.release_window_render_target_for_hide(0) or { release_error = err.msg() } assert release_error == err_wayland_egl_surface_failed - assert release_failure.windows[0].egl_surface == voidptr(usize(0xe4)) + assert release_failure.windows[0].egl_surface == voidptr(uint(0xe4)) assert release_failure.windows[0].egl_surface_ticket == 94 assert release_failure.windows[0].render_target_generation == 7 @@ -912,14 +912,14 @@ fn test_wayland_hide_releases_only_egl_surface_and_invalidates_old_generation_on false, false) unclaimed_terminal.toplevel_replay_test.hide_render_target_override = true unclaimed_terminal.toplevel_replay_test.hide_surface_unclaimed_terminal = true - unclaimed_terminal.windows[0].egl_surface = voidptr(usize(0xe6)) + unclaimed_terminal.windows[0].egl_surface = voidptr(uint(0xe6)) unclaimed_terminal.windows[0].egl_surface_ticket = 96 mut unclaimed_error := '' unclaimed_terminal.release_window_render_target_for_hide(0) or { unclaimed_error = err.msg() } assert unclaimed_error == err_wayland_egl_surface_failed - assert unclaimed_terminal.windows[0].egl_surface == voidptr(usize(0xe6)) + assert unclaimed_terminal.windows[0].egl_surface == voidptr(uint(0xe6)) assert unclaimed_terminal.windows[0].egl_surface_ticket == 96 assert unclaimed_terminal.windows[0].render_target_generation == 7 @@ -927,21 +927,21 @@ fn test_wayland_hide_releases_only_egl_surface_and_invalidates_old_generation_on false) terminal_failure.toplevel_replay_test.hide_render_target_override = true terminal_failure.toplevel_replay_test.hide_surface_terminal_failure = true - terminal_failure.windows[0].egl_surface = voidptr(usize(0xe5)) + terminal_failure.windows[0].egl_surface = voidptr(uint(0xe5)) terminal_failure.windows[0].egl_surface_ticket = 95 mut terminal_error := '' terminal_failure.release_window_render_target_for_hide(0) or { terminal_error = err.msg() } assert terminal_error == err_wayland_egl_surface_failed assert terminal_failure.windows[0].egl_surface == unsafe { nil } assert terminal_failure.windows[0].egl_surface_ticket == 0 - assert terminal_failure.windows[0].wl_egl_window == voidptr(usize(0xd5)) + assert terminal_failure.windows[0].wl_egl_window == voidptr(uint(0xd5)) assert terminal_failure.windows[0].render_target_generation == 8 } } fn test_wayland_fallback_buffer_is_reused_only_for_the_exact_remap_extent() { $if linux && sokol_wayland ? { - buffer := voidptr(usize(0xf1)) + buffer := voidptr(uint(0xf1)) record := &WaylandWindowRecord{ fallback_current_buffer: buffer fallback_buffer_width: 360 @@ -956,7 +956,7 @@ fn test_wayland_fallback_buffer_is_reused_only_for_the_exact_remap_extent() { fn test_wayland_fractional_scale_requires_both_protocol_objects() { $if linux && sokol_wayland ? { mut backend := &WaylandBackend{} - fractional_scale := voidptr(usize(0x41)) + fractional_scale := voidptr(uint(0x41)) mut record := &WaylandWindowRecord{ id: WindowId{ app_instance: 1 @@ -995,8 +995,8 @@ fn test_wayland_xdg_configure_states_are_published_after_surface_configure() { } mut active_states := [u32(1), u32(4)] mut active_array := C.wl_array{ - size: usize(active_states.len) * sizeof(u32) - alloc: usize(active_states.len) * sizeof(u32) + size: uint(active_states.len) * sizeof(u32) + alloc: uint(active_states.len) * sizeof(u32) data: active_states.data } wayland_xdg_toplevel_configure(record.listener_data(), unsafe { nil }, 64, 48, @@ -1030,11 +1030,11 @@ fn test_wayland_state_operations_are_deferred_by_capability_until_observation() native_operations.advance_renderer_attempt(1, 2)! mut backend := &WaylandBackend{ started: true - display: voidptr(usize(1)) + display: voidptr(uint(1)) native_operations: native_operations - pointer: voidptr(usize(2)) - relative_pointer_manager: voidptr(usize(3)) - pointer_constraints: voidptr(usize(4)) + pointer: voidptr(uint(2)) + relative_pointer_manager: voidptr(uint(3)) + pointer_constraints: voidptr(uint(4)) } for operation in [ServiceOperation.show, .minimize, .maximize, .restore, .fullscreen, .mouse_lock] { @@ -1053,7 +1053,7 @@ fn test_wayland_state_operations_are_deferred_by_capability_until_observation() backend.started = true backend.display = unsafe { nil } assert state_operations.map(backend.service_operation_capability(it).support) == expected_dead_support - backend.display = voidptr(usize(1)) + backend.display = voidptr(uint(1)) backend.wayland_display_unavailable = true assert state_operations.map(backend.service_operation_capability(it).support) == expected_dead_support backend.wayland_display_unavailable = false @@ -1110,10 +1110,10 @@ fn test_wayland_existing_mouse_lock_can_be_released_after_capability_loss() { app.backend.kind = .wayland app.backend.wayland = WaylandBackend{ started: true - display: voidptr(usize(1)) + display: voidptr(uint(1)) wayland_display_unavailable: true - relative_pointer_manager: voidptr(usize(2)) - pointer_constraints: voidptr(usize(3)) + relative_pointer_manager: voidptr(uint(2)) + pointer_constraints: voidptr(uint(3)) } mut record := &WaylandWindowRecord{ id: window @@ -1160,10 +1160,10 @@ fn test_wayland_synchronous_clipboard_write_reserves_terminal_before_native_muta original_backend := app.backend.kind app.backend.kind = .wayland app.backend.wayland.started = true - app.backend.wayland.display = voidptr(usize(1)) - app.backend.wayland.data_device_manager = voidptr(usize(2)) - app.backend.wayland.data_device = voidptr(usize(3)) - app.backend.wayland.seat = voidptr(usize(4)) + app.backend.wayland.display = voidptr(uint(1)) + app.backend.wayland.data_device_manager = voidptr(uint(2)) + app.backend.wayland.data_device = voidptr(uint(3)) + app.backend.wayland.seat = voidptr(uint(4)) request_before := app.services.next_request pending_before := app.services.pending.len source_before := app.backend.wayland.clipboard_source @@ -1207,8 +1207,8 @@ fn test_wayland_relative_pointer_callbacks_publish_observed_state_and_motion() { width: 64 height: 48 } - locked_pointer := voidptr(usize(0x21)) - relative_pointer := voidptr(usize(0x22)) + locked_pointer := voidptr(uint(0x21)) + relative_pointer := voidptr(uint(0x22)) record.locked_pointer = locked_pointer record.relative_pointer = relative_pointer record.mouse_lock_requested = true @@ -1452,7 +1452,7 @@ fn test_wayland_xdg_foreign_callback_retains_and_releases_exact_lease() { app_instance: 7 serial: 11 } - exported := voidptr(usize(0x41)) + exported := voidptr(uint(0x41)) mut portal := &WaylandPortalExport{ request: request window: window @@ -1789,7 +1789,7 @@ fn test_wayland_clipboard_read_timeout_is_terminal_exactly_once() { fn test_wayland_fatal_dispatch_terminalizes_active_clipboard_read_exactly_once() { $if linux && sokol_wayland ? { mut backend := &WaylandBackend{ - display: voidptr(usize(0x11)) + display: voidptr(uint(0x11)) } _, record, fds := wayland_test_begin_clipboard_read(mut backend, 86, []u8{}) request := backend.clipboard_read.request @@ -1829,7 +1829,7 @@ fn test_wayland_fatal_dispatch_terminalizes_active_clipboard_read_exactly_once() assert record.pending_events.len == 1 mut fallback_backend := &WaylandBackend{ - display: voidptr(usize(0x12)) + display: voidptr(uint(0x12)) wayland_display_unavailable: true } _, fallback_record, fallback_fds := wayland_test_begin_clipboard_read(mut fallback_backend, @@ -1850,7 +1850,7 @@ fn test_wayland_fatal_dispatch_terminalizes_active_clipboard_read_exactly_once() assert fallback_record.pending_events.len == 1 mut health_backend := &WaylandBackend{ - display: voidptr(usize(0x13)) + display: voidptr(uint(0x13)) render_health: .unavailable } assert health_backend.transport_can_marshal() @@ -1876,7 +1876,7 @@ fn test_wayland_fatal_dispatch_terminalizes_active_clipboard_read_exactly_once() fn test_wayland_fatal_dispatch_cleans_nonterminal_resources_once_and_preserves_ready_portals() { $if linux && sokol_wayland ? { mut backend := &WaylandBackend{ - display: voidptr(usize(0x21)) + display: voidptr(uint(0x21)) render_health: .unavailable io_test: WaylandIoTestSeam{ pending_drop_native_bypass: true @@ -1902,7 +1902,7 @@ fn test_wayland_fatal_dispatch_cleans_nonterminal_resources_once_and_preserves_r lease: pending_lease owner: backend } - ready_exported := voidptr(usize(0x25)) + ready_exported := voidptr(uint(0x25)) mut ready_portal := &WaylandPortalExport{ request: ServiceRequestId{ app_instance: 1 @@ -1933,7 +1933,7 @@ fn test_wayland_fatal_dispatch_cleans_nonterminal_resources_once_and_preserves_r backend.clipboard_send_cursor = 1 backend.clipboard_send_snapshot_bytes = 3 drop_fds := wayland_pipe()! - offer := voidptr(usize(0x22)) + offer := voidptr(uint(0x22)) backend.data_offer = offer backend.data_offer_has_uri_list = true backend.data_offer_window = window @@ -1981,8 +1981,8 @@ fn test_wayland_fatal_dispatch_cleans_nonterminal_resources_once_and_preserves_r assert backend.clipboard_sends.len == 0 assert backend.clipboard_send_cursor == 0 assert backend.clipboard_send_snapshot_bytes == 0 - assert C.write(send_a[1], c'x', usize(1)) == -1 - assert C.write(send_b[1], c'x', usize(1)) == -1 + assert C.write(send_a[1], c'x', uint(1)) == -1 + assert C.write(send_b[1], c'x', uint(1)) == -1 C.close(send_a[0]) C.close(send_b[0]) assert backend.data_offer == unsafe { nil } @@ -2007,7 +2007,7 @@ fn test_wayland_fatal_dispatch_cleans_nonterminal_resources_once_and_preserves_r assert backend.portal_exports.len == 0 mut nonfatal_backend := &WaylandBackend{ - display: voidptr(usize(0x23)) + display: voidptr(uint(0x23)) io_test: WaylandIoTestSeam{ pending_drop_native_bypass: true } @@ -2032,7 +2032,7 @@ fn test_wayland_fatal_dispatch_cleans_nonterminal_resources_once_and_preserves_r fd: nonfatal_send[1] payload: 'retained' } - nonfatal_offer := voidptr(usize(0x24)) + nonfatal_offer := voidptr(uint(0x24)) nonfatal_backend.data_offer = nonfatal_offer nonfatal_backend.pending_drop_offer = nonfatal_offer nonfatal_backend.pending_drop_fd = nonfatal_drop[0] @@ -2073,7 +2073,7 @@ fn test_wayland_clipboard_queued_eof_wins_over_expired_deadline_exactly_once() { _, record, fds := wayland_test_begin_clipboard_read(mut backend, 79, []u8{}) payload := 'queued-after-deadline' assert C.v_multiwindow_wayland_fd_set_nonblocking(fds[0]) == 1 - assert C.write(fds[1], payload.str, usize(payload.len)) == payload.len + assert C.write(fds[1], payload.str, uint(payload.len)) == payload.len C.close(fds[1]) backend.clipboard_read.deadline_ns = 0 backend.io_test.clipboard_read_interruptions = 1 @@ -2147,7 +2147,7 @@ fn test_wayland_clipboard_read_progress_refreshes_inactivity_deadline_before_eag _, record, fds := wayland_test_begin_clipboard_read(mut backend, 85, []u8{}) assert C.v_multiwindow_wayland_fd_set_nonblocking(fds[0]) == 1 payload := 'progress-before-read-eagain' - assert C.write(fds[1], payload.str, usize(payload.len)) == payload.len + assert C.write(fds[1], payload.str, uint(payload.len)) == payload.len backend.clipboard_read.deadline_ns = 0 backend.drain_clipboard_read() @@ -2174,10 +2174,10 @@ fn wayland_assert_clipboard_replacement_preflight_failure(fail_listener bool) { $if linux && sokol_wayland ? { mut backend := &WaylandBackend{ started: true - display: voidptr(usize(0x11)) - data_device_manager: voidptr(usize(0x12)) - data_device: voidptr(usize(0x13)) - seat: voidptr(usize(0x14)) + display: voidptr(uint(0x11)) + data_device_manager: voidptr(uint(0x12)) + data_device: voidptr(uint(0x13)) + seat: voidptr(uint(0x14)) poll_generation: 1 } window := WindowId{ @@ -2191,10 +2191,10 @@ fn wayland_assert_clipboard_replacement_preflight_failure(fail_listener bool) { } record.store_user_action_serial(19, backend.poll_generation) backend.windows << record - old_source := voidptr(usize(0x21)) + old_source := voidptr(uint(0x21)) mut new_source := voidptr(unsafe { nil }) if fail_listener { - new_source = voidptr(usize(0x22)) + new_source = voidptr(uint(0x22)) } fds := wayland_pipe() or { panic(err) } backend.clipboard_source = old_source @@ -2226,11 +2226,11 @@ fn wayland_assert_clipboard_replacement_preflight_failure(fail_listener bool) { assert backend.clipboard_sends[0].payload == 'previous clipboard' assert record.pending_events.len == 0 if fail_listener { - assert backend.clipboard_source_test.destroyed == [usize(new_source)] + assert backend.clipboard_source_test.destroyed == [uint(new_source)] } else { assert backend.clipboard_source_test.destroyed.len == 0 } - assert C.write(fds[1], c'x', usize(1)) == 1 + assert C.write(fds[1], c'x', uint(1)) == 1 backend.clipboard_source = unsafe { nil } backend.clipboard_source_test.active = false backend.close_all_clipboard_sends() @@ -2251,14 +2251,14 @@ fn test_wayland_clipboard_transport_plan_exhaustion_has_no_ghost_and_flush_failu mut native_operations := &NativeOperationAuthority{} native_operations.bind_app_lifetime(1, 1)! native_operations.advance_renderer_attempt(1, 2)! - old_source := voidptr(usize(0x31)) - new_source := voidptr(usize(0x32)) + old_source := voidptr(uint(0x31)) + new_source := voidptr(uint(0x32)) mut backend := &WaylandBackend{ started: true - display: voidptr(usize(0x33)) - data_device_manager: voidptr(usize(0x34)) - data_device: voidptr(usize(0x35)) - seat: voidptr(usize(0x36)) + display: voidptr(uint(0x33)) + data_device_manager: voidptr(uint(0x34)) + data_device: voidptr(uint(0x35)) + seat: voidptr(uint(0x36)) poll_generation: 1 native_operations: native_operations clipboard_source: old_source @@ -2316,7 +2316,7 @@ fn test_wayland_clipboard_transport_plan_exhaustion_has_no_ghost_and_flush_failu assert result.error == err_wayland_flush_failed assert !record.user_action_serial_valid assert backend.clipboard_source_test.selection_requests == 1 - assert backend.clipboard_source_test.destroyed == [usize(new_source)] + assert backend.clipboard_source_test.destroyed == [uint(new_source)] assert backend.clipboard_source_test.destroyed_local == [true] assert backend.clipboard_source == old_source assert backend.clipboard_text == 'old clipboard' @@ -2346,8 +2346,8 @@ fn test_wayland_interactive_move_resize_preflight_preserves_serial_and_ordinals( native_operations.advance_renderer_attempt(1, 2)! mut backend := &WaylandBackend{ started: true - display: voidptr(usize(0x41)) - seat: voidptr(usize(0x42)) + display: voidptr(uint(0x41)) + seat: voidptr(uint(0x42)) poll_generation: 1 native_operations: native_operations toplevel_replay_test: WaylandToplevelReplayTestSeam{ @@ -2363,7 +2363,7 @@ fn test_wayland_interactive_move_resize_preflight_preserves_serial_and_ordinals( id: window owner: backend resizable: true - xdg_toplevel: voidptr(usize(0x43)) + xdg_toplevel: voidptr(uint(0x43)) } backend.windows << record @@ -2423,10 +2423,10 @@ fn test_wayland_visible_create_preplans_lifecycle_transport_before_native_creati native_operations.next_ordinal = ~u64(0) - 5 mut backend := &WaylandBackend{ started: true - display: voidptr(usize(0x61)) - compositor: voidptr(usize(0x62)) + display: voidptr(uint(0x61)) + compositor: voidptr(uint(0x62)) compositor_name: 1 - wm_base: voidptr(usize(0x63)) + wm_base: voidptr(uint(0x63)) wm_base_name: 2 native_operations: native_operations toplevel_replay_test: WaylandToplevelReplayTestSeam{ @@ -2459,7 +2459,7 @@ fn test_wayland_live_cleanup_plan_exhaustion_preserves_mouse_and_portal_handles( native_operations.next_ordinal = ~u64(0) mut backend := &WaylandBackend{ started: true - display: voidptr(usize(0x51)) + display: voidptr(uint(0x51)) native_operations: native_operations } window := WindowId{ @@ -2467,8 +2467,8 @@ fn test_wayland_live_cleanup_plan_exhaustion_preserves_mouse_and_portal_handles( slot: 0 generation: 1 } - locked := voidptr(usize(0x52)) - relative := voidptr(usize(0x53)) + locked := voidptr(uint(0x52)) + relative := voidptr(uint(0x53)) mut record := &WaylandWindowRecord{ id: window owner: backend @@ -2482,7 +2482,7 @@ fn test_wayland_live_cleanup_plan_exhaustion_preserves_mouse_and_portal_handles( app_instance: 1 serial: 7 } - exported := voidptr(usize(0x54)) + exported := voidptr(uint(0x54)) backend.portal_exports << &WaylandPortalExport{ window: window lease: lease @@ -2533,7 +2533,7 @@ fn test_wayland_clipboard_selection_replacement_cancels_read_exactly_once() { deadline_ns: i64(0x7fffffffffffffff) } backend.clipboard_read_active = true - replacement := voidptr(usize(0x51)) + replacement := voidptr(uint(0x51)) backend.set_selection_offer(replacement) C.close(fds[1]) @@ -2655,7 +2655,7 @@ fn test_wayland_clipboard_capacity_plus_one_fails() { mut backend := &WaylandBackend{} payload := []u8{len: wayland_clipboard_max_bytes, init: `b`} _, record, fds := wayland_test_begin_clipboard_read(mut backend, 83, payload) - assert C.write(fds[1], c'x', usize(1)) == 1 + assert C.write(fds[1], c'x', uint(1)) == 1 C.close(fds[1]) backend.drain_clipboard_read() @@ -2697,7 +2697,7 @@ fn test_wayland_clipboard_exact_capacity_waits_on_eagain_then_succeeds_at_eof() fn test_wayland_file_drop_poll_and_read_eintr_preserve_transaction_until_exact_terminal() { $if linux && sokol_wayland ? { mut backend := &WaylandBackend{ - display: voidptr(usize(0x91)) + display: voidptr(uint(0x91)) io_test: WaylandIoTestSeam{ pending_drop_poll_interruptions: 1 pending_drop_read_interruptions: 1 @@ -2719,9 +2719,9 @@ fn test_wayland_file_drop_poll_and_read_eintr_preserve_transaction_until_exact_t fds := wayland_pipe()! assert C.v_multiwindow_wayland_fd_set_nonblocking(fds[0]) == 1 payload := 'file:///tmp/eintr-proof\n' - assert C.write(fds[1], payload.str, usize(payload.len)) == payload.len + assert C.write(fds[1], payload.str, uint(payload.len)) == payload.len C.close(fds[1]) - offer := voidptr(usize(0x92)) + offer := voidptr(uint(0x92)) backend.data_offer = offer backend.pending_drop_offer = offer backend.pending_drop_fd = fds[0] @@ -2754,7 +2754,7 @@ fn test_wayland_file_drop_poll_and_read_eintr_preserve_transaction_until_exact_t fn test_wayland_file_drop_empty_open_pipe_expires_without_terminal_event() { $if linux && sokol_wayland ? { mut backend := &WaylandBackend{ - display: voidptr(usize(0x93)) + display: voidptr(uint(0x93)) io_test: WaylandIoTestSeam{ pending_drop_native_bypass: true } @@ -2771,7 +2771,7 @@ fn test_wayland_file_drop_empty_open_pipe_expires_without_terminal_event() { backend.windows << record fds := wayland_pipe()! assert C.v_multiwindow_wayland_fd_set_nonblocking(fds[0]) == 1 - offer := voidptr(usize(0x94)) + offer := voidptr(uint(0x94)) backend.data_offer = offer backend.pending_drop_offer = offer backend.pending_drop_fd = fds[0] @@ -2794,7 +2794,7 @@ fn test_wayland_file_drop_exact_capacity_requires_eof_and_rejects_one_extra_byte $if linux && sokol_wayland ? { for extra in 0 .. 2 { mut backend := &WaylandBackend{ - display: voidptr(usize(0x95 + extra)) + display: voidptr(uint(0x95 + extra)) io_test: WaylandIoTestSeam{ pending_drop_native_bypass: true } @@ -2815,10 +2815,10 @@ fn test_wayland_file_drop_exact_capacity_requires_eof_and_rejects_one_extra_byte payload := prefix + 'a'.repeat(wayland_uri_list_buffer_size - prefix.len - 1) + '\n' assert payload.len == wayland_uri_list_buffer_size if extra == 1 { - assert C.write(fds[1], c'x', usize(1)) == 1 + assert C.write(fds[1], c'x', uint(1)) == 1 } C.close(fds[1]) - offer := voidptr(usize(0x97 + extra)) + offer := voidptr(uint(0x97 + extra)) backend.data_offer = offer backend.pending_drop_offer = offer backend.pending_drop_fd = fds[0] @@ -2851,19 +2851,19 @@ fn wayland_read_exact_pipe_payload(fd int, expected_len int) string { mut payload := []u8{len: expected_len} mut offset := 0 for offset < expected_len { - n := C.read(fd, unsafe { &payload[offset] }, usize(expected_len - offset)) + n := C.read(fd, unsafe { &payload[offset] }, uint(expected_len - offset)) assert n > 0 offset += int(n) } mut eof := [1]u8{} - assert C.read(fd, unsafe { &eof[0] }, usize(1)) == 0 + assert C.read(fd, unsafe { &eof[0] }, uint(1)) == 0 return payload.bytestr() } fn test_wayland_clipboard_send_is_fair_when_first_consumer_is_backpressured() { $if linux && sokol_wayland ? { mut backend := &WaylandBackend{} - source := voidptr(usize(0x61)) + source := voidptr(uint(0x61)) backend.clipboard_source = source backend.clipboard_text = 'bounded clipboard payload' first := wayland_pipe()! @@ -2872,7 +2872,7 @@ fn test_wayland_clipboard_send_is_fair_when_first_consumer_is_backpressured() { mut fill := [4096]u8{} mut saturated := false for _ in 0 .. 4096 { - if C.write(first[1], unsafe { &fill[0] }, usize(fill.len)) < 0 { + if C.write(first[1], unsafe { &fill[0] }, uint(fill.len)) < 0 { assert C.v_multiwindow_wayland_read_would_block() != 0 saturated = true break @@ -2902,7 +2902,7 @@ fn test_wayland_clipboard_send_progress_refreshes_inactivity_deadline_before_eag mut fill := [4096]u8{} mut saturated := false for _ in 0 .. 4096 { - if C.write(fds[1], unsafe { &fill[0] }, usize(fill.len)) < 0 { + if C.write(fds[1], unsafe { &fill[0] }, uint(fill.len)) < 0 { assert C.v_multiwindow_wayland_read_would_block() != 0 saturated = true break @@ -2910,7 +2910,7 @@ fn test_wayland_clipboard_send_progress_refreshes_inactivity_deadline_before_eag } assert saturated mut drained := [4096]u8{} - assert C.read(fds[0], unsafe { &drained[0] }, usize(drained.len)) == drained.len + assert C.read(fds[0], unsafe { &drained[0] }, uint(drained.len)) == drained.len payload := 'p'.repeat(wayland_clipboard_io_chunk_size * 2) mut backend := &WaylandBackend{ clipboard_sends: [ @@ -2939,14 +2939,14 @@ fn test_wayland_clipboard_send_progress_refreshes_inactivity_deadline_before_eag fn test_wayland_clipboard_send_snapshots_survive_replacement_and_cancel() { $if linux && sokol_wayland ? { - old_source := voidptr(usize(0x71)) - new_source := voidptr(usize(0x72)) + old_source := voidptr(uint(0x71)) + new_source := voidptr(uint(0x72)) mut backend := &WaylandBackend{ started: true - display: voidptr(usize(0x73)) - data_device_manager: voidptr(usize(0x74)) - data_device: voidptr(usize(0x75)) - seat: voidptr(usize(0x76)) + display: voidptr(uint(0x73)) + data_device_manager: voidptr(uint(0x74)) + data_device: voidptr(uint(0x75)) + seat: voidptr(uint(0x76)) poll_generation: 1 clipboard_source: old_source clipboard_text: 'old payload' @@ -2984,7 +2984,7 @@ fn test_wayland_clipboard_send_snapshots_survive_replacement_and_cancel() { wayland_data_source_cancelled(backend, new_source) assert backend.clipboard_source == unsafe { nil } assert backend.clipboard_sends.len == 2 - assert backend.clipboard_source_test.destroyed == [usize(old_source), usize(new_source)] + assert backend.clipboard_source_test.destroyed == [uint(old_source), uint(new_source)] assert backend.clipboard_source_test.destroyed_local == [false, false] backend.io_test.clipboard_write_interruptions = 1 @@ -3001,7 +3001,7 @@ fn test_wayland_clipboard_send_snapshots_survive_replacement_and_cancel() { fn test_wayland_clipboard_send_expired_writable_progress_and_teardown_are_independent() { $if linux && sokol_wayland ? { mut backend := &WaylandBackend{} - source := voidptr(usize(0x81)) + source := voidptr(uint(0x81)) backend.clipboard_source = source backend.clipboard_text = 'still delivered' expired := wayland_pipe()! @@ -3024,7 +3024,7 @@ fn test_wayland_clipboard_send_expired_writable_progress_and_teardown_are_indepe assert backend.clipboard_sends.len == 0 assert backend.clipboard_send_snapshot_bytes == 0 mut eof := [1]u8{} - assert C.read(teardown[0], unsafe { &eof[0] }, usize(1)) == 0 + assert C.read(teardown[0], unsafe { &eof[0] }, uint(1)) == 0 C.close(teardown[0]) backend.clipboard_source = unsafe { nil } } @@ -3033,7 +3033,7 @@ fn test_wayland_clipboard_send_expired_writable_progress_and_teardown_are_indepe fn test_wayland_clipboard_send_expired_backpressure_closes_only_that_transfer() { $if linux && sokol_wayland ? { mut backend := &WaylandBackend{} - source := voidptr(usize(0x82)) + source := voidptr(uint(0x82)) backend.clipboard_source = source backend.clipboard_text = 'independent live payload' expired := wayland_pipe()! @@ -3042,7 +3042,7 @@ fn test_wayland_clipboard_send_expired_backpressure_closes_only_that_transfer() mut fill := [4096]u8{} mut saturated := false for _ in 0 .. 4096 { - if C.write(expired[1], unsafe { &fill[0] }, usize(fill.len)) < 0 { + if C.write(expired[1], unsafe { &fill[0] }, uint(fill.len)) < 0 { assert C.v_multiwindow_wayland_read_would_block() != 0 saturated = true break @@ -3072,7 +3072,7 @@ fn test_wayland_clipboard_safe_write_contains_sigpipe_in_child_process() { fn test_wayland_clipboard_send_rejects_invalid_and_bounded_admissions_only() { $if linux && sokol_wayland ? { mut backend := &WaylandBackend{} - source := voidptr(usize(0xa1)) + source := voidptr(uint(0xa1)) backend.clipboard_source = source backend.clipboard_text = 'x' invalid_source := wayland_pipe()! @@ -3080,7 +3080,7 @@ fn test_wayland_clipboard_send_rejects_invalid_and_bounded_admissions_only() { byte_limit := wayland_pipe()! count_limit := wayland_pipe()! - wayland_data_source_send(backend, voidptr(usize(0xa2)), c'text/plain', invalid_source[1]) + wayland_data_source_send(backend, voidptr(uint(0xa2)), c'text/plain', invalid_source[1]) wayland_data_source_send(backend, source, c'application/octet-stream', invalid_mime[1]) backend.clipboard_send_snapshot_bytes = wayland_clipboard_max_outgoing_snapshot_bytes wayland_data_source_send(backend, source, c'text/plain', byte_limit[1]) @@ -3091,10 +3091,10 @@ fn test_wayland_clipboard_send_rejects_invalid_and_bounded_admissions_only() { wayland_data_source_send(backend, source, c'text/plain', count_limit[1]) assert backend.clipboard_sends.len == wayland_clipboard_max_outgoing_transfers - assert C.write(invalid_source[1], c'x', usize(1)) == -1 - assert C.write(invalid_mime[1], c'x', usize(1)) == -1 - assert C.write(byte_limit[1], c'x', usize(1)) == -1 - assert C.write(count_limit[1], c'x', usize(1)) == -1 + assert C.write(invalid_source[1], c'x', uint(1)) == -1 + assert C.write(invalid_mime[1], c'x', uint(1)) == -1 + assert C.write(byte_limit[1], c'x', uint(1)) == -1 + assert C.write(count_limit[1], c'x', uint(1)) == -1 backend.close_all_clipboard_sends() C.close(invalid_source[0]) C.close(invalid_mime[0]) diff --git a/vlib/x/multiwindow/service_native_win32_contract_red_test.v b/vlib/x/multiwindow/service_native_win32_contract_red_test.v index b43d66ce92..ddef0af80f 100644 --- a/vlib/x/multiwindow/service_native_win32_contract_red_test.v +++ b/vlib/x/multiwindow/service_native_win32_contract_red_test.v @@ -94,8 +94,8 @@ $if windows { fn C.v_multiwindow_test_win32_monitor_enumeration_info_failure_calls() int fn C.v_multiwindow_test_win32_monitor_enumeration_growth_calls() int fn C.v_multiwindow_test_win32_monitor_enumeration_growth_callbacks() int - fn C.v_multiwindow_test_win32_clipboard_equals(expected &u16, expected_units usize) int - fn C.v_multiwindow_test_win32_set_clipboard(owner voidptr, text &u16, units usize) int + fn C.v_multiwindow_test_win32_clipboard_equals(expected &u16, expected_units uint) int + fn C.v_multiwindow_test_win32_set_clipboard(owner voidptr, text &u16, units uint) int fn C.v_multiwindow_test_win32_clipboard_unterminated_parser_probe() int fn C.v_multiwindow_test_win32_set_clipboard_malformed(owner voidptr, kind int) int fn C.v_multiwindow_win32_service_test_clipboard_configure(backend voidptr, now_ns i64, fail_open_attempts int) @@ -107,7 +107,7 @@ $if windows { fn C.v_multiwindow_win32_service_test_clipboard_last_open_owner(backend voidptr) voidptr fn C.v_multiwindow_win32_service_test_clipboard_pending_count(backend voidptr) int fn C.v_multiwindow_win32_service_test_clipboard_pending_deadline_ns(backend voidptr, index int) i64 - fn C.v_multiwindow_win32_service_test_clipboard_pending_write_matches(backend voidptr, index int, request_app u64, request_serial u64, window_app u64, window_slot int, window_generation u32, text &u16, units usize) int + fn C.v_multiwindow_win32_service_test_clipboard_pending_write_matches(backend voidptr, index int, request_app u64, request_serial u64, window_app u64, window_slot int, window_generation u32, text &u16, units uint) int fn C.v_multiwindow_win32_service_test_clipboard_owned_globals(backend voidptr) int fn C.v_multiwindow_win32_service_test_clipboard_owned_globals_peak(backend voidptr) int fn C.v_multiwindow_win32_service_test_clipboard_global_allocations(backend voidptr) int @@ -116,7 +116,7 @@ $if windows { fn C.v_multiwindow_win32_service_test_clipboard_sequence_allocations(backend voidptr) int fn C.v_multiwindow_win32_service_test_clipboard_timeout_ns(backend voidptr) i64 fn C.v_multiwindow_test_win32_dwm_dark(hwnd voidptr, value &int) int - fn C.SendMessageW(hwnd voidptr, msg u32, wparam usize, lparam isize) isize + fn C.SendMessageW(hwnd voidptr, msg u32, wparam uint, lparam C.ptrdiff_t) C.ptrdiff_t } fn C.v_multiwindow_test_win32_raw_mouse_target() voidptr @@ -315,10 +315,10 @@ mut: valid_inside bool } -fn win32_red_utf16_units(text string) usize { - mut units := usize(1) +fn win32_red_utf16_units(text string) uint { + mut units := uint(1) for codepoint in text.runes() { - units += if codepoint > 0xffff { usize(2) } else { usize(1) } + units += if codepoint > 0xffff { uint(2) } else { uint(1) } } return units } @@ -2584,7 +2584,7 @@ fn test_win32_native_cf_unicodetext_roundtrip_exact_limit_and_terminal_queue_red exact := win32_red_exact_mixed_clipboard_text() exact_units := win32_red_utf16_units(exact) win32_red_add(mut issues, 'exact boundary payload is not exactly 16 MiB including NUL', - exact_units * 2 == usize(win32_red_clipboard_max_bytes)) + exact_units * 2 == uint(win32_red_clipboard_max_bytes)) win32_red_add(mut issues, 'exact mixed payload exceeds the independent UTF-8 bound', exact.len + 1 <= win32_red_clipboard_max_bytes && exact.contains('漢') && exact.contains('🙂')) @@ -2638,7 +2638,7 @@ fn test_win32_native_cf_unicodetext_roundtrip_exact_limit_and_terminal_queue_red win32_red_events_are_globally_ordered(late_delivery)) } oversized := exact + 'A' - win32_red_add(mut issues, 'one-unit-over payload is not exactly one UTF-16 unit over', win32_red_utf16_units(oversized) * 2 == usize(win32_red_clipboard_max_bytes + 2)) + win32_red_add(mut issues, 'one-unit-over payload is not exactly one UTF-16 unit over', win32_red_utf16_units(oversized) * 2 == uint(win32_red_clipboard_max_bytes + 2)) win32_red_add(mut issues, 'one-unit-over payload does not isolate the UTF-16 bound', oversized.len + 1 <= win32_red_clipboard_max_bytes) @@ -2760,7 +2760,7 @@ fn test_win32_native_clipboard_exact_utf8_limit_and_over_red() { exact.len + 1 == win32_red_clipboard_max_bytes) win32_red_add(mut issues, 'exact UTF-8 fixture accidentally reaches the UTF-16 bound', - exact_units * 2 < usize(win32_red_clipboard_max_bytes)) + exact_units * 2 < uint(win32_red_clipboard_max_bytes)) exact_request := app.service_set_clipboard_text(window, exact) or { issues << 'exact UTF-8 write was not admitted: ${err.msg()}' ServiceRequestId{} @@ -2787,7 +2787,7 @@ fn test_win32_native_clipboard_exact_utf8_limit_and_over_red() { over.len + 1 == win32_red_clipboard_max_bytes + 1) win32_red_add(mut issues, 'over-limit UTF-8 fixture accidentally reaches the UTF-16 bound', - win32_red_utf16_units(over) * 2 < usize(win32_red_clipboard_max_bytes)) + win32_red_utf16_units(over) * 2 < uint(win32_red_clipboard_max_bytes)) core_pending_before := app.services.pending.len native_pending_before := C.v_multiwindow_win32_service_test_clipboard_pending_count(backend) allocations_before := @@ -3241,7 +3241,7 @@ fn test_win32_native_clipboard_real_wm_close_global_order_red() { if second != ServiceRequestId{} { win32_red_add(mut issues, 'post-WM_CLOSE write was attempted during admission', C.v_multiwindow_win32_service_test_clipboard_request_attempts(backend, second.app_instance, second.serial) == 0) - _ = C.SendMessageW(hwnd, win32_red_wm_close, usize(0), isize(0)) + _ = C.SendMessageW(hwnd, win32_red_wm_close, uint(0), int(0)) win32_red_add(mut issues, 'real WM_CLOSE destroyed the HWND synchronously', C.v_multiwindow_test_win32_is_window(hwnd) == 1) win32_red_add(mut issues, 'real WM_CLOSE removed the public window synchronously', @@ -3337,7 +3337,7 @@ fn win32_w4_clipboard_timeout_case(test_now_ns i64) ![]string { win32_red_add(mut issues, 'occupied read was not native-pending', C.v_multiwindow_win32_service_test_clipboard_pending_count(backend) == 1) win32_red_add(mut issues, 'occupied read did not reserve the aggregate byte limit', - app.backend.win32.clipboard_pending_bytes == usize(win32_red_clipboard_max_bytes)) + app.backend.win32.clipboard_pending_bytes == uint(win32_red_clipboard_max_bytes)) deadline := C.v_multiwindow_win32_service_test_clipboard_pending_deadline_ns(backend, 0) win32_red_add(mut issues, 'occupied read deadline was not admission+2s', deadline == test_now_ns + i64(2_000_000_000)) @@ -3442,11 +3442,11 @@ fn win32_w4_clipboard_ready_storage_case(test_now_ns i64) ![]string { return issues } win32_red_add(mut issues, 'read admission did not reserve the full aggregate limit', - app.backend.win32.clipboard_pending_bytes == usize(win32_red_clipboard_max_bytes)) + app.backend.win32.clipboard_pending_bytes == uint(win32_red_clipboard_max_bytes)) app.poll_events() or { win32_w4_add_infra(mut issues, 'retained-ready read poll failed: ${err.msg()}') } - read_charge := usize(read_text.len + 1) + read_charge := uint(read_text.len + 1) win32_red_add(mut issues, 'ready read remained native-pending', C.v_multiwindow_win32_service_test_clipboard_pending_count(backend) == 0) win32_red_add(mut issues, 'ready read did not retain its exact stable payload charge', @@ -3478,7 +3478,7 @@ fn win32_w4_clipboard_ready_storage_case(test_now_ns i64) ![]string { && win32_red_core_pending(app, read).len == 1) write_text := 'small FIFO write' - write_bytes := win32_red_utf16_units(write_text) * usize(2) + write_bytes := win32_red_utf16_units(write_text) * uint(2) write := app.service_set_clipboard_text(queue_window, write_text) or { issues << 'small write was rejected despite retained-read budget: ${err.msg()}' ServiceRequestId{} @@ -3515,7 +3515,7 @@ fn win32_w4_clipboard_ready_storage_case(test_now_ns i64) ![]string { } if retry != ServiceRequestId{} { win32_red_add(mut issues, 'read retry did not reserve the full aggregate limit', - app.backend.win32.clipboard_pending_bytes == usize(win32_red_clipboard_max_bytes)) + app.backend.win32.clipboard_pending_bytes == uint(win32_red_clipboard_max_bytes)) app.destroy_window(queue_window) or { issues << 'destroy-before-read-poll failed: ${err.msg()}' } diff --git a/vlib/x/multiwindow/testdata/native_primitive_darwin_consumer.v b/vlib/x/multiwindow/testdata/native_primitive_darwin_consumer.v index 4b2b060f39..dd8c1ffa07 100644 --- a/vlib/x/multiwindow/testdata/native_primitive_darwin_consumer.v +++ b/vlib/x/multiwindow/testdata/native_primitive_darwin_consumer.v @@ -5,11 +5,11 @@ import x.multiwindow #insert "@VMODROOT/vlib/x/multiwindow/native_render_result.h" #insert "@VMODROOT/vlib/x/multiwindow/testdata/native_primitive_darwin_consumer.c" -fn C.v_multiwindow_test_darwin_primitive_size() usize +fn C.v_multiwindow_test_darwin_primitive_size() uint fn C.v_multiwindow_test_darwin_primitive_mask() u64 fn main() { - assert C.v_multiwindow_test_darwin_primitive_size() == usize(104) + assert C.v_multiwindow_test_darwin_primitive_size() == uint(104) assert C.v_multiwindow_test_darwin_primitive_mask() != 0 capabilities := multiwindow.capabilities_for_backend(.appkit) or { panic(err) } assert capabilities.backend == .appkit diff --git a/vlib/x/multiwindow/wayland_backend.c.v b/vlib/x/multiwindow/wayland_backend.c.v index 6dc1671709..fcba72f17e 100644 --- a/vlib/x/multiwindow/wayland_backend.c.v +++ b/vlib/x/multiwindow/wayland_backend.c.v @@ -119,7 +119,7 @@ const wayland_fractional_scale_denominator = u32(120) const wayland_protocol_extent_max = u64(0x7fffffff) const wayland_prot_read = 1 const wayland_map_private = 2 -const wayland_map_failed = voidptr(usize(~u64(0))) +const wayland_map_failed = voidptr(uint(~u64(0))) const err_wayland_egl_config_failed = 'multiwindow: wayland egl config failed' const err_wayland_egl_context_failed = 'multiwindow: wayland egl context failed' const err_wayland_egl_display_failed = 'multiwindow: wayland egl display failed' @@ -302,7 +302,7 @@ mut: exercise_transport_plan bool fail_flush_after_selection bool selection_requests int - destroyed []usize + destroyed []uint destroyed_local []bool } @@ -961,8 +961,8 @@ $if linux && sokol_wayland ? { struct C.wl_output {} struct C.wl_array { - size usize - alloc usize + size uint + alloc uint data voidptr } @@ -1010,10 +1010,10 @@ $if linux && sokol_wayland ? { fn C.strcmp(a &char, b &char) int fn C.close(fd int) int fn C.pipe(fds &i32) i32 - fn C.read(fd int, buf voidptr, count usize) isize - fn C.write(fd int, buf voidptr, count usize) isize - fn C.mmap(addr voidptr, length usize, prot int, flags int, fd int, offset i64) voidptr - fn C.munmap(addr voidptr, length usize) int + fn C.read(fd int, buf voidptr, count uint) C.ptrdiff_t + fn C.write(fd int, buf voidptr, count uint) C.ptrdiff_t + fn C.mmap(addr voidptr, length uint, prot int, flags int, fd int, offset i64) voidptr + fn C.munmap(addr voidptr, length uint) int fn C.xkb_context_new(flags int) &C.xkb_context fn C.xkb_context_unref(ctx &C.xkb_context) fn C.xkb_keymap_new_from_string(ctx &C.xkb_context, str &char, format int, flags int) &C.xkb_keymap @@ -1021,7 +1021,7 @@ $if linux && sokol_wayland ? { fn C.xkb_keymap_key_repeats(keymap &C.xkb_keymap, key u32) int fn C.xkb_state_new(keymap &C.xkb_keymap) &C.xkb_state fn C.xkb_state_unref(state &C.xkb_state) - fn C.xkb_state_key_get_utf8(state &C.xkb_state, key u32, buf &char, size usize) int + fn C.xkb_state_key_get_utf8(state &C.xkb_state, key u32, buf &char, size uint) int fn C.xkb_state_update_mask(state &C.xkb_state, depressed u32, latched u32, locked u32, dep_group u32, lat_group u32, lock_group u32) int fn C.xkb_state_mod_name_is_active(state &C.xkb_state, name &char, @type int) int fn C.v_multiwindow_wayland_compositor_bind_version(version u32) u32 @@ -1082,7 +1082,7 @@ $if linux && sokol_wayland ? { fn C.v_multiwindow_wayland_fd_set_nonblocking(fd int) int fn C.v_multiwindow_wayland_read_would_block() int fn C.v_multiwindow_wayland_io_interrupted() int - fn C.v_multiwindow_wayland_safe_write(fd int, buffer voidptr, size usize) isize + fn C.v_multiwindow_wayland_safe_write(fd int, buffer voidptr, size uint) C.ptrdiff_t fn C.v_multiwindow_wayland_safe_write_broken_pipe_probe() int fn C.v_multiwindow_wayland_toplevel_state_contains(states &C.wl_array, expected u32) int fn C.wl_surface_set_buffer_scale(surface &C.wl_surface, scale int) @@ -1142,8 +1142,8 @@ $if linux && sokol_wayland ? { fn C.v_multiwindow_wayland_xdg_toplevel_set_title(toplevel &C.xdg_toplevel, title &char) fn C.v_multiwindow_wayland_xdg_toplevel_set_app_id(toplevel &C.xdg_toplevel, app_id &char) fn C.v_multiwindow_wayland_get_last_marshaled_app_id() &char - fn C.v_multiwindow_wayland_get_last_parent_child() usize - fn C.v_multiwindow_wayland_get_last_parent_owner() usize + fn C.v_multiwindow_wayland_get_last_parent_child() uint + fn C.v_multiwindow_wayland_get_last_parent_owner() uint fn C.v_multiwindow_wayland_xdg_toplevel_set_parent(toplevel &C.xdg_toplevel, parent &C.xdg_toplevel) fn C.v_multiwindow_wayland_xdg_toplevel_set_min_size(toplevel &C.xdg_toplevel, width i32, height i32) fn C.v_multiwindow_wayland_xdg_toplevel_set_max_size(toplevel &C.xdg_toplevel, width i32, height i32) @@ -2180,14 +2180,14 @@ $if linux && sokol_wayland ? { return } map_str := - C.mmap(unsafe { nil }, usize(size), wayland_prot_read, wayland_map_private, fd, 0) + C.mmap(unsafe { nil }, uint(size), wayland_prot_read, wayland_map_private, fd, 0) if map_str == wayland_map_failed { C.close(fd) return } keymap := C.xkb_keymap_new_from_string(unsafe { &C.xkb_context(backend.xkb_context) }, &char(map_str), wayland_xkb_keymap_format_text_v1, wayland_xkb_keymap_compile_no_flags) - C.munmap(map_str, usize(size)) + C.munmap(map_str, uint(size)) C.close(fd) if keymap == unsafe { nil } { return @@ -5104,7 +5104,7 @@ fn (backend &WaylandBackend) char_code_for_key(key u32) u32 { } mut buf := [8]u8{} count := C.xkb_state_key_get_utf8(unsafe { &C.xkb_state(backend.xkb_state) }, key, - &char(&buf[0]), usize(buf.len)) + &char(&buf[0]), uint(buf.len)) if count <= 0 || count >= buf.len { return 0 } @@ -7062,7 +7062,7 @@ fn (mut backend WaylandBackend) destroy_clipboard_source_handle(source voidptr, } $if test { if backend.clipboard_source_test.active { - backend.clipboard_source_test.destroyed << usize(source) + backend.clipboard_source_test.destroyed << uint(source) backend.clipboard_source_test.destroyed_local << local_only return } @@ -7111,7 +7111,7 @@ fn (mut backend WaylandBackend) add_clipboard_source_listener(source voidptr) in return -1 } -fn (mut backend WaylandBackend) clipboard_read_once(fd int, buffer voidptr, size usize) i64 { +fn (mut backend WaylandBackend) clipboard_read_once(fd int, buffer voidptr, size uint) i64 { $if linux && sokol_wayland ? { $if test { if backend.io_test.clipboard_read_interruptions > 0 { @@ -7124,7 +7124,7 @@ fn (mut backend WaylandBackend) clipboard_read_once(fd int, buffer voidptr, size return -1 } -fn (mut backend WaylandBackend) clipboard_write_once(fd int, buffer voidptr, size usize) i64 { +fn (mut backend WaylandBackend) clipboard_write_once(fd int, buffer voidptr, size uint) i64 { $if linux && sokol_wayland ? { $if test { if backend.io_test.clipboard_write_interruptions > 0 { @@ -7175,7 +7175,7 @@ fn (mut backend WaylandBackend) drain_clipboard_send() { backend.clipboard_sends[index].payload.str + backend.clipboard_sends[index].offset } attempts++ - n := backend.clipboard_write_once(backend.clipboard_sends[index].fd, ptr, usize(chunk)) + n := backend.clipboard_write_once(backend.clipboard_sends[index].fd, ptr, uint(chunk)) if n > 0 { backend.clipboard_sends[index].deadline_ns = vtime.sys_mono_now() + wayland_clipboard_timeout_ns @@ -7266,7 +7266,7 @@ fn (mut backend WaylandBackend) drain_clipboard_read() { if remaining <= 0 { mut probe := [1]u8{} n := backend.clipboard_read_once(backend.clipboard_read.fd, unsafe { &probe[0] }, - usize(1)) + uint(1)) if n > 0 { backend.clipboard_read.deadline_ns = vtime.sys_mono_now() + wayland_clipboard_timeout_ns @@ -7299,7 +7299,7 @@ fn (mut backend WaylandBackend) drain_clipboard_read() { wayland_clipboard_io_chunk_size } n := backend.clipboard_read_once(backend.clipboard_read.fd, unsafe { &chunk[0] }, - usize(read_size)) + uint(read_size)) if n > 0 { backend.clipboard_read.deadline_ns = vtime.sys_mono_now() + wayland_clipboard_timeout_ns @@ -7469,7 +7469,7 @@ fn (mut backend WaylandBackend) pending_drop_poll_once(poll_fd voidptr) int { return -1 } -fn (mut backend WaylandBackend) pending_drop_read_once(fd int, buffer voidptr, size usize) i64 { +fn (mut backend WaylandBackend) pending_drop_read_once(fd int, buffer voidptr, size uint) i64 { $if linux && sokol_wayland ? { $if test { if backend.io_test.pending_drop_read_interruptions > 0 { @@ -7517,7 +7517,7 @@ fn (mut backend WaylandBackend) drain_pending_data_offer_drop() { if remaining <= 0 { mut probe := [1]u8{} n := backend.pending_drop_read_once(backend.pending_drop_fd, - unsafe { &probe[0] }, usize(1)) + unsafe { &probe[0] }, uint(1)) if n > 0 { backend.clear_data_offer(true) return @@ -7543,7 +7543,7 @@ fn (mut backend WaylandBackend) drain_pending_data_offer_drop() { wayland_data_offer_drain_chunk_size } n := backend.pending_drop_read_once(backend.pending_drop_fd, unsafe { &chunk[0] }, - usize(read_size)) + uint(read_size)) if n > 0 { made_progress = true for i in 0 .. int(n) { diff --git a/vlib/x/multiwindow/win32_backend.c.v b/vlib/x/multiwindow/win32_backend.c.v index bb5f86cc87..c580f45410 100644 --- a/vlib/x/multiwindow/win32_backend.c.v +++ b/vlib/x/multiwindow/win32_backend.c.v @@ -133,7 +133,7 @@ mut: service_monitor_poll_dirty bool clipboard_pending []Win32ClipboardPending clipboard_retained []Win32ClipboardRetainedCharge - clipboard_pending_bytes usize + clipboard_pending_bytes uint } struct Win32D3DDeviceLaneAttempt { diff --git a/vlib/x/multiwindow/win32_readback_d3d11.c.v b/vlib/x/multiwindow/win32_readback_d3d11.c.v index b01ec76f3b..349a9946b2 100644 --- a/vlib/x/multiwindow/win32_readback_d3d11.c.v +++ b/vlib/x/multiwindow/win32_readback_d3d11.c.v @@ -13,8 +13,8 @@ struct Win32D3D11ReadbackNativeResult { status int width u32 height u32 - stride usize - byte_length usize + stride uint + byte_length uint } struct Win32D3D11ReadbackBridgeResult { @@ -27,8 +27,8 @@ struct Win32D3D11ReadbackBridgeResult { status int width u32 height u32 - stride usize - byte_length usize + stride uint + byte_length uint } struct Win32D3D11ReadbackBridge { @@ -57,8 +57,8 @@ $if windows && sokol_d3d11 ? { status int width u32 height u32 - stride usize - byte_length usize + stride uint + byte_length uint } fn C.v_multiwindow_win32_d3d11_readback_native_create(device_identity u64, context_identity u64, state_identity u64, renderer_generation u64) voidptr @@ -69,7 +69,7 @@ $if windows && sokol_d3d11 ? { fn C.v_multiwindow_win32_d3d11_readback_native_notify_failure(state voidptr, state_identity u64, renderer_generation u64, failure_origin int) int fn C.v_multiwindow_win32_d3d11_readback_native_poll(state voidptr) int fn C.v_multiwindow_win32_d3d11_readback_native_take(state voidptr, result &C.VMultiwindowWin32ReadbackResult) int - fn C.v_multiwindow_win32_d3d11_readback_native_copy(state voidptr, request u64, pixels &u8, capacity usize) int + fn C.v_multiwindow_win32_d3d11_readback_native_copy(state voidptr, request u64, pixels &u8, capacity uint) int fn C.v_multiwindow_win32_d3d11_readback_native_release(state voidptr, request u64) int fn C.v_multiwindow_win32_d3d11_readback_native_cancel(state voidptr, request u64) int fn C.v_multiwindow_win32_d3d11_readback_native_quiesce_window(state voidptr, window_slot u64, window_generation u32) int @@ -121,7 +121,7 @@ fn win32_d3d11_readback_bridge_result(raw Win32D3D11ReadbackNativeResult) (bool, && raw.window_slot != 0 && raw.window_generation != 0 if raw.status == win32_d3d11_readback_status_ready { ready_valid := base_valid && raw.submitted_frame != 0 && raw.width != 0 && raw.height != 0 - && raw.stride == usize(raw.width) * 4 + && raw.stride == uint(raw.width) * 4 && u64(raw.stride) * u64(raw.height) == u64(raw.byte_length) return ready_valid, Win32D3D11ReadbackBridgeResult{ request: raw.request @@ -285,7 +285,7 @@ fn (bridge &Win32D3D11ReadbackBridge) copy(request u64, mut pixels []u8) bool { } $if windows && sokol_d3d11 ? { return C.v_multiwindow_win32_d3d11_readback_native_copy(bridge.native, request, - pixels.data, usize(pixels.len)) == 1 + pixels.data, uint(pixels.len)) == 1 } $else { return false } diff --git a/vlib/x/multiwindow/win32_service_backend.c.v b/vlib/x/multiwindow/win32_service_backend.c.v index 72da6a0c19..873b4cdc82 100644 --- a/vlib/x/multiwindow/win32_service_backend.c.v +++ b/vlib/x/multiwindow/win32_service_backend.c.v @@ -21,7 +21,7 @@ struct Win32ClipboardPending { hwnd voidptr operation ServiceOperation write_utf16 []u16 - reserved_bytes usize + reserved_bytes uint mut: deadline_ns i64 } @@ -29,7 +29,7 @@ mut: struct Win32ClipboardRetainedCharge { request ServiceRequestId window WindowId - bytes usize + bytes uint mut: claimed_by_app bool } @@ -112,16 +112,16 @@ $if windows { fn C.v_multiwindow_win32_service_window_monitor(hwnd voidptr) u64 fn C.v_multiwindow_win32_service_window_dpi(hwnd voidptr) u32 fn C.v_multiwindow_win32_clipboard_now_ns() i64 - fn C.v_multiwindow_win32_clipboard_utf8_to_utf16(text &char, text_bytes usize, output &u16, output_units usize, out_units &usize) int - fn C.v_multiwindow_win32_clipboard_write(owner voidptr, text &u16, units usize) int - fn C.v_multiwindow_win32_clipboard_read(owner voidptr, out_text &voidptr, out_text_bytes &usize) int + fn C.v_multiwindow_win32_clipboard_utf8_to_utf16(text &char, text_bytes uint, output &u16, output_units uint, out_units &uint) int + fn C.v_multiwindow_win32_clipboard_write(owner voidptr, text &u16, units uint) int + fn C.v_multiwindow_win32_clipboard_read(owner voidptr, out_text &voidptr, out_text_bytes &uint) int fn C.v_multiwindow_win32_clipboard_text_free(text voidptr) $if test { fn C.v_multiwindow_win32_service_test_focus_cleanup_failures(count int) fn C.v_multiwindow_win32_clipboard_now_for_test(backend voidptr, real_now_ns i64) i64 - fn C.v_multiwindow_win32_clipboard_write_for_test(backend voidptr, request_app u64, request_serial u64, owner voidptr, text &u16, units usize) int - fn C.v_multiwindow_win32_clipboard_read_for_test(backend voidptr, request_app u64, request_serial u64, owner voidptr, out_text &voidptr, out_text_bytes &usize) int + fn C.v_multiwindow_win32_clipboard_write_for_test(backend voidptr, request_app u64, request_serial u64, owner voidptr, text &u16, units uint) int + fn C.v_multiwindow_win32_clipboard_read_for_test(backend voidptr, request_app u64, request_serial u64, owner voidptr, out_text &voidptr, out_text_bytes &uint) int fn C.v_multiwindow_win32_clipboard_record_sequence_for_test(backend voidptr) } } @@ -488,23 +488,23 @@ fn (backend &Win32Backend) clipboard_now_ns() i64 { fn win32_clipboard_utf16(text string) ![]u16 { $if windows { - mut units := usize(0) - query := C.v_multiwindow_win32_clipboard_utf8_to_utf16(&char(text.str), usize(text.len), + mut units := uint(0) + query := C.v_multiwindow_win32_clipboard_utf8_to_utf16(&char(text.str), uint(text.len), unsafe { nil }, 0, &units) if query == win32_clipboard_convert_capacity { return error(err_clipboard_capacity) } if query != win32_clipboard_convert_ready || units == 0 - || units > usize(win32_clipboard_max_bytes / 2) { + || units > uint(win32_clipboard_max_bytes / 2) { return error(err_capability_unsupported) } mut wide := []u16{len: int(units)} converted := C.v_multiwindow_win32_clipboard_utf8_to_utf16(&char(text.str), - usize(text.len), wide.data, units, &units) + uint(text.len), wide.data, units, &units) if converted == win32_clipboard_convert_capacity { return error(err_clipboard_capacity) } - if converted != win32_clipboard_convert_ready || units != usize(wide.len) { + if converted != win32_clipboard_convert_ready || units != uint(wide.len) { return error(err_capability_unsupported) } return wide @@ -514,13 +514,13 @@ fn win32_clipboard_utf16(text string) ![]u16 { } } -fn (backend &Win32Backend) clipboard_can_admit(reserved_bytes usize) bool { +fn (backend &Win32Backend) clipboard_can_admit(reserved_bytes uint) bool { return backend.clipboard_pending.len < win32_clipboard_max_pending_operations - && reserved_bytes <= usize(win32_clipboard_max_pending_bytes) - && backend.clipboard_pending_bytes <= usize(win32_clipboard_max_pending_bytes) - reserved_bytes + && reserved_bytes <= uint(win32_clipboard_max_pending_bytes) + && backend.clipboard_pending_bytes <= uint(win32_clipboard_max_pending_bytes) - reserved_bytes } -fn (mut backend Win32Backend) release_clipboard_bytes(bytes usize) { +fn (mut backend Win32Backend) release_clipboard_bytes(bytes uint) { if bytes <= backend.clipboard_pending_bytes { backend.clipboard_pending_bytes -= bytes } @@ -575,9 +575,9 @@ fn (mut backend Win32Backend) admit_clipboard_request(request ServiceRequestId, return error(err_capability_unsupported) } reserved_bytes := if operation == .clipboard_write { - usize(write_utf16.len) * usize(2) + uint(write_utf16.len) * uint(2) } else { - usize(win32_clipboard_max_pending_bytes) + uint(win32_clipboard_max_pending_bytes) } if !backend.clipboard_can_admit(reserved_bytes) { return error(err_clipboard_capacity) @@ -607,8 +607,8 @@ fn (mut backend Win32Backend) finish_clipboard_head(status ServiceStatus, text s mut terminal_text := text mut terminal_message := message if status == .ready && pending.operation == .clipboard_read { - read_charge := usize(text.len) + usize(1) - if read_charge <= usize(win32_clipboard_max_pending_bytes) + read_charge := uint(text.len) + uint(1) + if read_charge <= uint(win32_clipboard_max_pending_bytes) && backend.clipboard_can_admit(read_charge) { backend.clipboard_retained << Win32ClipboardRetainedCharge{ request: pending.request @@ -662,14 +662,14 @@ fn (mut backend Win32Backend) collect_clipboard_events() []Win32NativeQueuedEven $if test { status = C.v_multiwindow_win32_clipboard_write_for_test(voidptr(backend), pending.request.app_instance, pending.request.serial, pending.hwnd, - pending.write_utf16.data, usize(pending.write_utf16.len)) + pending.write_utf16.data, uint(pending.write_utf16.len)) } $else { status = C.v_multiwindow_win32_clipboard_write(pending.hwnd, - pending.write_utf16.data, usize(pending.write_utf16.len)) + pending.write_utf16.data, uint(pending.write_utf16.len)) } } else { mut native_text := voidptr(unsafe { nil }) - mut text_bytes := usize(0) + mut text_bytes := uint(0) $if test { status = C.v_multiwindow_win32_clipboard_read_for_test(voidptr(backend), pending.request.app_instance, pending.request.serial, pending.hwnd, @@ -680,7 +680,7 @@ fn (mut backend Win32Backend) collect_clipboard_events() []Win32NativeQueuedEven } if status == win32_clipboard_attempt_ready { if native_text == unsafe { nil } - || text_bytes > usize(win32_clipboard_max_bytes - 1) { + || text_bytes > uint(win32_clipboard_max_bytes - 1) { status = win32_clipboard_attempt_failed } else { text = unsafe { tos(native_text, int(text_bytes)).clone() } @@ -715,7 +715,7 @@ fn (mut backend Win32Backend) purge_clipboard_window(id WindowId) { } head_removed := backend.clipboard_pending[0].window == id mut retained := []Win32ClipboardPending{cap: backend.clipboard_pending.len} - mut removed_bytes := usize(0) + mut removed_bytes := uint(0) for pending in backend.clipboard_pending { if pending.window == id { removed_bytes += pending.reserved_bytes @@ -732,7 +732,7 @@ fn (mut backend Win32Backend) purge_clipboard_window(id WindowId) { } fn (mut backend Win32Backend) purge_all_clipboard_requests() { - mut removed_bytes := usize(0) + mut removed_bytes := uint(0) for pending in backend.clipboard_pending { removed_bytes += pending.reserved_bytes } @@ -1440,7 +1440,7 @@ $if test { } @[markused] - fn win32_service_test_clipboard_pending_write_matches(backend_pointer voidptr, index int, request_app u64, request_serial u64, window_app u64, window_slot int, window_generation u32, text &u16, units usize) int { + fn win32_service_test_clipboard_pending_write_matches(backend_pointer voidptr, index int, request_app u64, request_serial u64, window_app u64, window_slot int, window_generation u32, text &u16, units uint) int { if backend_pointer == unsafe { nil } || text == unsafe { nil } { return 0 } @@ -1452,7 +1452,7 @@ $if test { if pending.operation != .clipboard_write || pending.request.app_instance != request_app || pending.request.serial != request_serial || pending.window.app_instance != window_app || pending.window.slot != window_slot || pending.window.generation != window_generation - || usize(pending.write_utf16.len) != units { + || uint(pending.write_utf16.len) != units { return 0 } for unit_index in 0 .. pending.write_utf16.len { diff --git a/vlib/x/multiwindow/x11_backend.c.v b/vlib/x/multiwindow/x11_backend.c.v index 855c41bf87..9d19857fac 100644 --- a/vlib/x/multiwindow/x11_backend.c.v +++ b/vlib/x/multiwindow/x11_backend.c.v @@ -90,8 +90,8 @@ struct X11ReadbackProbe { actual_height int requested_width int requested_height int - pixels_length usize - expected_pixels_length usize + pixels_length uint + expected_pixels_length uint } $if linux && x_multiwindow_x11 ? { @@ -138,8 +138,8 @@ $if linux && x_multiwindow_x11 ? { actual_height int requested_width int requested_height int - pixels_length usize - expected_pixels_length usize + pixels_length uint + expected_pixels_length uint } @[typedef] @@ -371,8 +371,8 @@ $if linux && x_multiwindow_x11 ? { fn C.v_multiwindow_x11_subscribe_randr(display &C.Display, root X11NativeWindow, event_base &int, error_base &int) int fn C.v_multiwindow_x11_is_randr_event(event_type int, event_base int) int fn C.v_multiwindow_x11_update_randr_configuration(event &C.XEvent, event_base int) - fn C.v_multiwindow_x11_readback_rgba8(display &C.Display, connection voidptr, window X11NativeWindow, x int, y int, width int, height int, pixels &u8, pixels_len usize) int - fn C.v_multiwindow_x11_readback_probe(connection voidptr, window X11NativeWindow, width int, height int, pixels_len usize) C.VMultiwindowX11ReadbackProbe + fn C.v_multiwindow_x11_readback_rgba8(display &C.Display, connection voidptr, window X11NativeWindow, x int, y int, width int, height int, pixels &u8, pixels_len uint) int + fn C.v_multiwindow_x11_readback_probe(connection voidptr, window X11NativeWindow, width int, height int, pixels_len uint) C.VMultiwindowX11ReadbackProbe fn C.v_multiwindow_x11_paint_rgba8_test_pattern(display &C.Display, window X11NativeWindow, x int, y int) int fn C.v_multiwindow_x11_owner_modal_matches(display &C.Display, window X11NativeWindow, owner X11NativeWindow, modal int) int fn C.v_multiwindow_x11_get_window_size(connection voidptr, window X11NativeWindow, out_width &int, out_height &int) int @@ -1993,7 +1993,7 @@ fn (backend &X11Backend) service_readback_probe_for_test(id WindowId, width int, $if linux && x_multiwindow_x11 ? { index := backend.window_record_index(id) or { return error(err_window_not_found) } probe := C.v_multiwindow_x11_readback_probe(backend.checked_connection, - backend.windows[index].window, width, height, usize(width * height * 4)) + backend.windows[index].window, width, height, uint(width * height * 4)) return X11ReadbackProbe{ attributes_available: probe.attributes_available map_state: probe.map_state @@ -4295,7 +4295,7 @@ fn (mut backend X11Backend) init_renderer() ! { backend.release_egl_lifetime() return error(err_render_native_renderer_unavailable) } - C.v_multiwindow_linux_egl_get_display(u64(usize(backend.display)), &raw) + C.v_multiwindow_linux_egl_get_display(u64(uint(backend.display)), &raw) backend.native_operations.bind_linux_egl_thread_lifetime_ticket(backend.egl_thread_ticket) actual_display := raw.handle if actual_display != 0 { diff --git a/vlib/x/ttf/render_sokol/cpu.v b/vlib/x/ttf/render_sokol/cpu.v index 32d78db427..07e35619b0 100644 --- a/vlib/x/ttf/render_sokol/cpu.v +++ b/vlib/x/ttf/render_sokol/cpu.v @@ -137,7 +137,7 @@ pub fn (mut tf_skl TTF_render_Sokol) create_texture() { // comment for dynamic img_desc.data.subimage[0][0] = gfx.Range{ ptr: tf_skl.bmp.buf - size: usize(sz) + size: uint(sz) } simg := gfx.make_image(&img_desc) @@ -169,7 +169,7 @@ pub fn (mut tf_skl TTF_render_Sokol) update_text_texture() { mut tmp_sbc := gfx.ImageData{} tmp_sbc.subimage[0][0] = gfx.Range{ ptr: tf_skl.bmp.buf - size: usize(sz) + size: uint(sz) } gfx.update_image(tf_skl.sg_img, &tmp_sbc) } diff --git a/vlib/x/x11/x11.v b/vlib/x/x11/x11.v index 6f4e4bd905..587bc5bd35 100644 --- a/vlib/x/x11/x11.v +++ b/vlib/x/x11/x11.v @@ -5,7 +5,7 @@ module x11 // Basic X11 types pub type Window = u64 pub type Atom = u64 -pub type VisualID = usize +pub type VisualID = uint pub type Time = u64 pub type Colormap = u64