1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: deprecate size_t (#11443)

This commit is contained in:
Enzo
2021-09-08 12:09:32 +02:00
committed by GitHub
parent 892971024e
commit e3b65092d6
31 changed files with 160 additions and 152 deletions

View File

@@ -11,7 +11,7 @@ pub:
element_size int // size in bytes of one element in the array.
pub mut:
data voidptr
offset int // in bytes (should be `size_t`)
offset int // in bytes (should be `usize`)
len int // length of the array.
cap int // capacity of the array.
}
@@ -150,7 +150,7 @@ pub fn (mut a array) sort_with_compare(callback fn (voidptr, voidptr) int) {
$if freestanding {
panic('sort does not work with -freestanding')
} $else {
unsafe { vqsort(a.data, size_t(a.len), size_t(a.element_size), callback) }
unsafe { vqsort(a.data, usize(a.len), usize(a.element_size), callback) }
}
}

View File

@@ -58,13 +58,13 @@ $if gcboehm_leak ? {
// for use with Boehm-GC
// Do not use them manually. They are automatically chosen when
// compiled with `-gc boehm` or `-gc boehm_leak`.
fn C.GC_MALLOC(n size_t) voidptr
fn C.GC_MALLOC(n usize) voidptr
fn C.GC_MALLOC_ATOMIC(n size_t) voidptr
fn C.GC_MALLOC_ATOMIC(n usize) voidptr
fn C.GC_MALLOC_UNCOLLECTABLE(n size_t) voidptr
fn C.GC_MALLOC_UNCOLLECTABLE(n usize) voidptr
fn C.GC_REALLOC(ptr voidptr, n size_t) voidptr
fn C.GC_REALLOC(ptr voidptr, n usize) voidptr
fn C.GC_FREE(ptr voidptr)

View File

@@ -4,13 +4,13 @@ module builtin
// NB: they will NOT be used, since calls to them are wrapped with `$if gcboehm ? { }`
fn C.GC_MALLOC(n size_t) voidptr
fn C.GC_MALLOC(n usize) voidptr
fn C.GC_MALLOC_ATOMIC(n size_t) voidptr
fn C.GC_MALLOC_ATOMIC(n usize) voidptr
fn C.GC_MALLOC_UNCOLLECTABLE(n size_t) voidptr
fn C.GC_MALLOC_UNCOLLECTABLE(n usize) voidptr
fn C.GC_REALLOC(ptr voidptr, n size_t) voidptr
fn C.GC_REALLOC(ptr voidptr, n usize) voidptr
fn C.GC_FREE(ptr voidptr)

View File

@@ -1,13 +1,13 @@
module builtin
// <string.h>
fn C.memcpy(dest voidptr, const_src voidptr, n size_t) voidptr
fn C.memcpy(dest voidptr, const_src voidptr, n usize) voidptr
fn C.memcmp(const_s1 voidptr, const_s2 voidptr, n size_t) int
fn C.memcmp(const_s1 voidptr, const_s2 voidptr, n usize) int
fn C.memmove(dest voidptr, const_src voidptr, n size_t) voidptr
fn C.memmove(dest voidptr, const_src voidptr, n usize) voidptr
fn C.memset(str voidptr, c int, n size_t) voidptr
fn C.memset(str voidptr, c int, n usize) voidptr
[trusted]
fn C.calloc(int, int) &byte
@@ -21,7 +21,7 @@ fn C.free(ptr voidptr)
[noreturn; trusted]
fn C.exit(code int)
fn C.qsort(base voidptr, items size_t, item_size size_t, cb C.qsort_callback_func)
fn C.qsort(base voidptr, items usize, item_size usize, cb C.qsort_callback_func)
fn C.sprintf(a ...voidptr) int
@@ -65,9 +65,9 @@ fn C.fopen(filename &char, mode &char) &C.FILE
fn C.fileno(&C.FILE) int
fn C.fread(ptr voidptr, item_size size_t, items size_t, stream &C.FILE) size_t
fn C.fread(ptr voidptr, item_size usize, items usize, stream &C.FILE) usize
fn C.fwrite(ptr voidptr, item_size size_t, items size_t, stream &C.FILE) size_t
fn C.fwrite(ptr voidptr, item_size usize, items usize, stream &C.FILE) usize
fn C.fclose(stream &C.FILE) int
@@ -130,7 +130,7 @@ fn C.fgets(str &char, n int, stream &C.FILE) int
[trusted]
fn C.sigemptyset() int
fn C.getcwd(buf &char, size size_t) &char
fn C.getcwd(buf &char, size usize) &char
[trusted]
fn C.mktime() int
@@ -173,7 +173,7 @@ fn C.getchar() int
[trusted]
fn C.strerror(int) &char
fn C.snprintf(str &char, size size_t, format &char, opt ...voidptr) int
fn C.snprintf(str &char, size usize, format &char, opt ...voidptr) int
fn C.fprintf(voidptr, &char, ...voidptr)
@@ -194,7 +194,7 @@ fn C.isatty(fd int) int
fn C.syscall(number int, va ...voidptr) int
fn C.sysctl(name &int, namelen u32, oldp voidptr, oldlenp voidptr, newp voidptr, newlen size_t) int
fn C.sysctl(name &int, namelen u32, oldp voidptr, oldlenp voidptr, newp voidptr, newlen usize) int
[trusted]
fn C._fileno(int) int
@@ -444,9 +444,9 @@ fn C.dispatch_time(u64, i64) u64
fn C.dispatch_release(voidptr)
// file descriptor based reading/writing
fn C.read(fd int, buf voidptr, count size_t) int
fn C.read(fd int, buf voidptr, count usize) int
fn C.write(fd int, buf voidptr, count size_t) int
fn C.write(fd int, buf voidptr, count usize) int
fn C.close(fd int) int

View File

@@ -67,6 +67,6 @@ pub fn vmemset(s voidptr, c int, n int) voidptr {
type FnSortCB = fn (const_a voidptr, const_b voidptr) int
[inline; unsafe]
fn vqsort(base voidptr, nmemb size_t, size size_t, sort_cb FnSortCB) {
fn vqsort(base voidptr, nmemb usize, size usize, sort_cb FnSortCB) {
C.qsort(base, nmemb, size, voidptr(sort_cb))
}

View File

@@ -1,7 +1,7 @@
module builtin
[unsafe]
pub fn memcpy(dest &C.void, src &C.void, n size_t) &C.void {
pub fn memcpy(dest &C.void, src &C.void, n usize) &C.void {
dest_ := unsafe { &byte(dest) }
src_ := unsafe { &byte(src) }
unsafe {
@@ -14,24 +14,24 @@ pub fn memcpy(dest &C.void, src &C.void, n size_t) &C.void {
[export: 'malloc']
[unsafe]
fn __malloc(n size_t) &C.void {
fn __malloc(n usize) &C.void {
return unsafe { malloc(int(n)) }
}
[unsafe]
fn strlen(_s &C.void) size_t {
fn strlen(_s &C.void) usize {
s := unsafe { &byte(_s) }
mut i := 0
for ; unsafe { s[i] } != 0; i++ {}
return size_t(i)
return usize(i)
}
[unsafe]
fn realloc(old_area &C.void, new_size size_t) &C.void {
fn realloc(old_area &C.void, new_size usize) &C.void {
if old_area == 0 {
return unsafe { malloc(int(new_size)) }
}
if new_size == size_t(0) {
if new_size == usize(0) {
unsafe { free(old_area) }
return 0
}
@@ -40,14 +40,14 @@ fn realloc(old_area &C.void, new_size size_t) &C.void {
return unsafe { old_area }
} else {
new_area := unsafe { malloc(int(new_size)) }
unsafe { memmove(new_area, old_area, size_t(old_size)) }
unsafe { memmove(new_area, old_area, usize(old_size)) }
unsafe { free(old_area) }
return new_area
}
}
[unsafe]
fn memset(s &C.void, c int, n size_t) &C.void {
fn memset(s &C.void, c int, n usize) &C.void {
mut s_ := unsafe { &char(s) }
for i in 0 .. int(n) {
unsafe {
@@ -58,7 +58,7 @@ fn memset(s &C.void, c int, n size_t) &C.void {
}
[unsafe]
fn memmove(dest &C.void, src &C.void, n size_t) &C.void {
fn memmove(dest &C.void, src &C.void, n usize) &C.void {
dest_ := unsafe { &byte(dest) }
src_ := unsafe { &byte(src) }
mut temp_buf := unsafe { malloc(int(n)) }
@@ -79,7 +79,7 @@ fn memmove(dest &C.void, src &C.void, n size_t) &C.void {
[export: 'calloc']
[unsafe]
fn __calloc(nmemb size_t, size size_t) &C.void {
fn __calloc(nmemb usize, size usize) &C.void {
new_area := unsafe { malloc(int(nmemb) * int(size)) }
unsafe { memset(new_area, 0, nmemb * size) }
return new_area
@@ -91,7 +91,7 @@ fn getchar() int {
return int(x)
}
fn memcmp(a &C.void, b &C.void, n size_t) int {
fn memcmp(a &C.void, b &C.void, n usize) int {
a_ := unsafe { &byte(a) }
b_ := unsafe { &byte(b) }
for i in 0 .. int(n) {
@@ -118,7 +118,7 @@ fn vsprintf(str &char, format &char, ap &byte) int {
panic('vsprintf(): string interpolation is not supported in `-freestanding`')
}
fn vsnprintf(str &char, size size_t, format &char, ap &byte) int {
fn vsnprintf(str &char, size usize, format &char, ap &byte) int {
panic('vsnprintf(): string interpolation is not supported in `-freestanding`')
}
@@ -157,6 +157,6 @@ fn __exit(code int) {
}
[export: 'qsort']
fn __qsort(base voidptr, nmemb size_t, size size_t, sort_cb FnSortCB) {
fn __qsort(base voidptr, nmemb usize, size usize, sort_cb FnSortCB) {
panic('qsort() is not yet implemented in `-freestanding`')
}