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

@ -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`')
}