ci: fix some of `v test-cleancode` 4

pull/9611/head
Delyan Angelov 2021-04-05 21:39:32 +03:00
parent 9aabf222fe
commit 291a88bc62
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
9 changed files with 60 additions and 60 deletions

View File

@ -95,7 +95,7 @@ fn (mut a array) ensure_cap(required int) {
cap *= 2 cap *= 2
} }
new_size := cap * a.element_size new_size := cap * a.element_size
mut new_data := byteptr(0) mut new_data := &byte(0)
if a.cap > 0 { if a.cap > 0 {
new_data = unsafe { realloc_data(a.data, a.cap * a.element_size, new_size) } new_data = unsafe { realloc_data(a.data, a.cap * a.element_size, new_size) }
} else { } else {
@ -128,7 +128,7 @@ pub fn (a array) repeat(count int) array {
ary_clone := ary.clone() ary_clone := ary.clone()
unsafe { C.memcpy(arr.get_unsafe(i * a.len), &ary_clone, a.len * a.element_size) } unsafe { C.memcpy(arr.get_unsafe(i * a.len), &ary_clone, a.len * a.element_size) }
} else { } else {
unsafe { C.memcpy(arr.get_unsafe(i * a.len), byteptr(a.data), a.len * a.element_size) } unsafe { C.memcpy(arr.get_unsafe(i * a.len), &byte(a.data), a.len * a.element_size) }
} }
} }
return arr return arr
@ -213,7 +213,7 @@ pub fn (mut a array) trim(index int) {
[inline; unsafe] [inline; unsafe]
fn (a array) get_unsafe(i int) voidptr { fn (a array) get_unsafe(i int) voidptr {
unsafe { unsafe {
return byteptr(a.data) + i * a.element_size return &byte(a.data) + i * a.element_size
} }
} }
@ -225,7 +225,7 @@ fn (a array) get(i int) voidptr {
} }
} }
unsafe { unsafe {
return byteptr(a.data) + i * a.element_size return &byte(a.data) + i * a.element_size
} }
} }
@ -235,7 +235,7 @@ fn (a array) get_with_check(i int) voidptr {
return 0 return 0
} }
unsafe { unsafe {
return byteptr(a.data) + i * a.element_size return &byte(a.data) + i * a.element_size
} }
} }
@ -257,7 +257,7 @@ pub fn (a array) last() voidptr {
} }
} }
unsafe { unsafe {
return byteptr(a.data) + (a.len - 1) * a.element_size return &byte(a.data) + (a.len - 1) * a.element_size
} }
} }
@ -270,7 +270,7 @@ pub fn (mut a array) pop() voidptr {
} }
} }
new_len := a.len - 1 new_len := a.len - 1
last_elem := unsafe { byteptr(a.data) + (new_len) * a.element_size } last_elem := unsafe { &byte(a.data) + (new_len) * a.element_size }
a.len = new_len a.len = new_len
// NB: a.cap is not changed here *on purpose*, so that // NB: a.cap is not changed here *on purpose*, so that
// further << ops on that array will be more efficient. // further << ops on that array will be more efficient.
@ -305,9 +305,9 @@ fn (a array) slice(start int, _end int) array {
panic('array.slice: slice bounds out of range ($start < 0)') panic('array.slice: slice bounds out of range ($start < 0)')
} }
} }
mut data := byteptr(0) mut data := &byte(0)
unsafe { unsafe {
data = byteptr(a.data) + start * a.element_size data = &byte(a.data) + start * a.element_size
} }
l := end - start l := end - start
res := array{ res := array{
@ -363,7 +363,7 @@ pub fn (a &array) clone() array {
} }
if !isnil(a.data) { if !isnil(a.data) {
unsafe { C.memcpy(byteptr(arr.data), a.data, a.cap * a.element_size) } unsafe { C.memcpy(&byte(arr.data), a.data, a.cap * a.element_size) }
} }
return arr return arr
} }
@ -381,9 +381,9 @@ fn (a &array) slice_clone(start int, _end int) array {
panic('array.slice: slice bounds out of range ($start < 0)') panic('array.slice: slice bounds out of range ($start < 0)')
} }
} }
mut data := byteptr(0) mut data := &byte(0)
unsafe { unsafe {
data = byteptr(a.data) + start * a.element_size data = &byte(a.data) + start * a.element_size
} }
l := end - start l := end - start
res := array{ res := array{
@ -398,7 +398,7 @@ fn (a &array) slice_clone(start int, _end int) array {
// we manually inline this for single operations for performance without -prod // we manually inline this for single operations for performance without -prod
[inline; unsafe] [inline; unsafe]
fn (mut a array) set_unsafe(i int, val voidptr) { fn (mut a array) set_unsafe(i int, val voidptr) {
unsafe { C.memcpy(byteptr(a.data) + a.element_size * i, val, a.element_size) } unsafe { C.memcpy(&byte(a.data) + a.element_size * i, val, a.element_size) }
} }
// Private function. Used to implement assigment to the array element. // Private function. Used to implement assigment to the array element.
@ -408,12 +408,12 @@ fn (mut a array) set(i int, val voidptr) {
panic('array.set: index out of range (i == $i, a.len == $a.len)') panic('array.set: index out of range (i == $i, a.len == $a.len)')
} }
} }
unsafe { C.memcpy(byteptr(a.data) + a.element_size * i, val, a.element_size) } unsafe { C.memcpy(&byte(a.data) + a.element_size * i, val, a.element_size) }
} }
fn (mut a array) push(val voidptr) { fn (mut a array) push(val voidptr) {
a.ensure_cap(a.len + 1) a.ensure_cap(a.len + 1)
unsafe { C.memmove(byteptr(a.data) + a.element_size * a.len, val, a.element_size) } unsafe { C.memmove(&byte(a.data) + a.element_size * a.len, val, a.element_size) }
a.len++ a.len++
} }
@ -446,10 +446,10 @@ pub fn (mut a array) reverse_in_place() {
unsafe { unsafe {
mut tmp_value := malloc(a.element_size) mut tmp_value := malloc(a.element_size)
for i in 0 .. a.len / 2 { for i in 0 .. a.len / 2 {
C.memcpy(tmp_value, byteptr(a.data) + i * a.element_size, a.element_size) C.memcpy(tmp_value, &byte(a.data) + i * a.element_size, a.element_size)
C.memcpy(byteptr(a.data) + i * a.element_size, byteptr(a.data) + C.memcpy(&byte(a.data) + i * a.element_size, &byte(a.data) +
(a.len - 1 - i) * a.element_size, a.element_size) (a.len - 1 - i) * a.element_size, a.element_size)
C.memcpy(byteptr(a.data) + (a.len - 1 - i) * a.element_size, tmp_value, a.element_size) C.memcpy(&byte(a.data) + (a.len - 1 - i) * a.element_size, tmp_value, a.element_size)
} }
free(tmp_value) free(tmp_value)
} }
@ -545,7 +545,7 @@ pub fn (b []byte) hex() string {
pub fn copy(dst []byte, src []byte) int { pub fn copy(dst []byte, src []byte) int {
min := if dst.len < src.len { dst.len } else { src.len } min := if dst.len < src.len { dst.len } else { src.len }
if min > 0 { if min > 0 {
unsafe { C.memcpy(byteptr(dst.data), src.data, min) } unsafe { C.memcpy(&byte(dst.data), src.data, min) }
} }
return min return min
} }
@ -619,8 +619,8 @@ pub fn (a1 []string) eq(a2 []string) bool {
size_of_string := int(sizeof(string)) size_of_string := int(sizeof(string))
for i in 0 .. a1.len { for i in 0 .. a1.len {
offset := i * size_of_string offset := i * size_of_string
s1 := &string(unsafe { byteptr(a1.data) + offset }) s1 := unsafe { &string(&byte(a1.data) + offset) }
s2 := &string(unsafe { byteptr(a2.data) + offset }) s2 := unsafe { &string(&byte(a2.data) + offset) }
if *s1 != *s2 { if *s1 != *s2 {
return false return false
} }

View File

@ -4,8 +4,8 @@
module builtin module builtin
__global ( __global (
g_m2_buf byteptr g_m2_buf &byte
g_m2_ptr byteptr g_m2_ptr &byte
) )
// isnil returns true if an object is nil (only for C objects). // isnil returns true if an object is nil (only for C objects).

View File

@ -71,7 +71,7 @@ fn print_backtrace_skipping_top_frames_freebsd(skipframes int) bool {
return true return true
} }
fn C.tcc_backtrace(fmt charptr, other ...charptr) int fn C.tcc_backtrace(fmt &char) int
fn print_backtrace_skipping_top_frames_linux(skipframes int) bool { fn print_backtrace_skipping_top_frames_linux(skipframes int) bool {
$if android { $if android {
eprintln('On Android no backtrace is available.') eprintln('On Android no backtrace is available.')
@ -86,7 +86,7 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool {
return false return false
} $else { } $else {
$if tinyc { $if tinyc {
C.tcc_backtrace('Backtrace') C.tcc_backtrace(c'Backtrace')
return false return false
} }
buffer := [100]voidptr{} buffer := [100]voidptr{}
@ -100,7 +100,7 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool {
//////csymbols := backtrace_symbols(*voidptr(&buffer[skipframes]), nr_actual_frames) //////csymbols := backtrace_symbols(*voidptr(&buffer[skipframes]), nr_actual_frames)
csymbols := C.backtrace_symbols(voidptr(&buffer[skipframes]), nr_actual_frames) csymbols := C.backtrace_symbols(voidptr(&buffer[skipframes]), nr_actual_frames)
for i in 0 .. nr_actual_frames { for i in 0 .. nr_actual_frames {
sframes << unsafe { tos2(byteptr(csymbols[i])) } sframes << unsafe { tos2(&byte(csymbols[i])) }
} }
for sframe in sframes { for sframe in sframes {
executable := sframe.all_before('(') executable := sframe.all_before('(')

View File

@ -36,7 +36,7 @@ pub mut:
f_size_of_struct u32 f_size_of_struct u32
f_key voidptr f_key voidptr
f_line_number u32 f_line_number u32
f_file_name byteptr f_file_name &byte
f_address u64 f_address u64
} }
@ -46,7 +46,7 @@ fn C.SymSetOptions(symoptions u32) u32
// returns handle // returns handle
fn C.GetCurrentProcess() voidptr fn C.GetCurrentProcess() voidptr
fn C.SymInitialize(h_process voidptr, p_user_search_path byteptr, b_invade_process int) int fn C.SymInitialize(h_process voidptr, p_user_search_path &byte, b_invade_process int) int
fn C.CaptureStackBackTrace(frames_to_skip u32, frames_to_capture u32, p_backtrace voidptr, p_backtrace_hash voidptr) u16 fn C.CaptureStackBackTrace(frames_to_skip u32, frames_to_capture u32, p_backtrace voidptr, p_backtrace_hash voidptr) u16
@ -176,7 +176,7 @@ fn print_backtrace_skipping_top_frames_mingw(skipframes int) bool {
return false return false
} }
fn C.tcc_backtrace(fmt charptr, other ...charptr) int fn C.tcc_backtrace(fmt &char) int
fn print_backtrace_skipping_top_frames_tcc(skipframes int) bool { fn print_backtrace_skipping_top_frames_tcc(skipframes int) bool {
$if tinyc { $if tinyc {
@ -184,7 +184,7 @@ fn print_backtrace_skipping_top_frames_tcc(skipframes int) bool {
eprintln('backtraces are disabled') eprintln('backtraces are disabled')
return false return false
} $else { } $else {
C.tcc_backtrace('Backtrace') C.tcc_backtrace(c'Backtrace')
return true return true
} }
} $else { } $else {

View File

@ -1,18 +1,18 @@
module builtin module builtin
// <string.h> // <string.h>
fn C.memcpy(dest byteptr, src byteptr, n int) voidptr fn C.memcpy(dest &byte, src &byte, n int) voidptr
fn C.memcmp(byteptr, byteptr, int) int fn C.memcmp(&byte, &byte, int) int
fn C.memmove(byteptr, byteptr, int) voidptr fn C.memmove(&byte, &byte, int) voidptr
[trusted] [trusted]
fn C.calloc(int, int) byteptr fn C.calloc(int, int) &byte
fn C.malloc(int) byteptr fn C.malloc(int) &byte
fn C.realloc(a byteptr, b int) byteptr fn C.realloc(a &byte, b int) &byte
fn C.free(ptr voidptr) fn C.free(ptr voidptr)
@ -25,7 +25,7 @@ fn C.sprintf(a ...voidptr) int
fn C.strlen(s &char) int fn C.strlen(s &char) int
fn C.sscanf(byteptr, byteptr, ...byteptr) int fn C.sscanf(&byte, &byte, ...&byte) int
[trusted] [trusted]
fn C.isdigit(c int) bool fn C.isdigit(c int) bool
@ -46,13 +46,13 @@ pub fn proc_pidpath(int, voidptr, int) int
fn C.realpath(&char, &char) &char fn C.realpath(&char, &char) &char
// fn C.chmod(byteptr, mode_t) int // fn C.chmod(byteptr, mode_t) int
fn C.chmod(byteptr, u32) int fn C.chmod(&byte, u32) int
fn C.printf(byteptr, ...voidptr) int fn C.printf(&byte, ...voidptr) int
fn C.puts(byteptr) int fn C.puts(&byte) int
fn C.fputs(str byteptr, stream &C.FILE) int fn C.fputs(str &byte, stream &C.FILE) int
fn C.fflush(&C.FILE) int fn C.fflush(&C.FILE) int
@ -83,11 +83,11 @@ fn C.posix_spawnp(child_pid &int, exefile &char, file_actions voidptr, attrp voi
fn C.execve(cmd_path &char, args voidptr, envs voidptr) int fn C.execve(cmd_path &char, args voidptr, envs voidptr) int
fn C.execvp(cmd_path charptr, args &charptr) int fn C.execvp(cmd_path &char, args &&char) int
fn C._execve(cmd_path charptr, args voidptr, envs voidptr) int fn C._execve(cmd_path &char, args voidptr, envs voidptr) int
fn C._execvp(cmd_path charptr, args &charptr) int fn C._execvp(cmd_path &char, args &&char) int
[trusted] [trusted]
fn C.fork() int fn C.fork() int
@ -173,7 +173,7 @@ fn C.strerror(int) &char
fn C.snprintf(str &char, size size_t, format &char, opt ...voidptr) int fn C.snprintf(str &char, size size_t, format &char, opt ...voidptr) int
fn C.fprintf(byteptr, ...byteptr) fn C.fprintf(&byte, ...&byte)
[trusted] [trusted]
fn C.WIFEXITED(status int) bool fn C.WIFEXITED(status int) bool
@ -224,11 +224,11 @@ fn C.CreateProcessW(lpApplicationName &u16, lpCommandLine &u16, lpProcessAttribu
fn C.ReadFile(hFile voidptr, lpBuffer voidptr, nNumberOfBytesToRead u32, lpNumberOfBytesRead C.LPDWORD, lpOverlapped voidptr) bool fn C.ReadFile(hFile voidptr, lpBuffer voidptr, nNumberOfBytesToRead u32, lpNumberOfBytesRead C.LPDWORD, lpOverlapped voidptr) bool
fn C.GetFileAttributesW(lpFileName byteptr) u32 fn C.GetFileAttributesW(lpFileName &byte) u32
fn C.RegQueryValueEx(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData byteptr, lpcbData &u32) voidptr fn C.RegQueryValueEx(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &byte, lpcbData &u32) voidptr
fn C.RegQueryValueExW(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData byteptr, lpcbData &u32) int fn C.RegQueryValueExW(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &byte, lpcbData &u32) int
fn C.RegOpenKeyEx(hKey voidptr, lpSubKey &u16, ulOptions u32, samDesired u32, phkResult voidptr) voidptr fn C.RegOpenKeyEx(hKey voidptr, lpSubKey &u16, ulOptions u32, samDesired u32, phkResult voidptr) voidptr
@ -236,7 +236,7 @@ fn C.RegOpenKeyExW(hKey voidptr, lpSubKey &u16, ulOptions u32, samDesired u32, p
fn C.RegSetValueEx() voidptr fn C.RegSetValueEx() voidptr
fn C.RegSetValueExW(hKey voidptr, lpValueName &u16, Reserved u32, dwType u32, lpData byteptr, lpcbData u32) int fn C.RegSetValueExW(hKey voidptr, lpValueName &u16, Reserved u32, dwType u32, lpData &byte, lpcbData u32) int
fn C.RegCloseKey(hKey voidptr) fn C.RegCloseKey(hKey voidptr)
@ -308,7 +308,7 @@ fn C.LocalFree()
fn C.FindFirstFileW(lpFileName &u16, lpFindFileData voidptr) voidptr fn C.FindFirstFileW(lpFileName &u16, lpFindFileData voidptr) voidptr
fn C.FindFirstFile(lpFileName byteptr, lpFindFileData voidptr) voidptr fn C.FindFirstFile(lpFileName &byte, lpFindFileData voidptr) voidptr
fn C.FindNextFile(hFindFile voidptr, lpFindFileData voidptr) int fn C.FindNextFile(hFindFile voidptr, lpFindFileData voidptr) int
@ -337,7 +337,7 @@ fn C.closesocket(int) int
fn C.vschannel_init(&C.TlsContext) fn C.vschannel_init(&C.TlsContext)
fn C.request(&C.TlsContext, int, &u16, byteptr, &byteptr) fn C.request(&C.TlsContext, int, &u16, &byte, &&byte)
fn C.vschannel_cleanup(&C.TlsContext) fn C.vschannel_cleanup(&C.TlsContext)
@ -345,19 +345,19 @@ fn C.URLDownloadToFile(int, &u16, &u16, int, int)
fn C.GetLastError() u32 fn C.GetLastError() u32
fn C.CreateDirectory(byteptr, int) bool fn C.CreateDirectory(&byte, int) bool
// win crypto // win crypto
fn C.BCryptGenRandom(int, voidptr, int, int) int fn C.BCryptGenRandom(int, voidptr, int, int) int
// win synchronization // win synchronization
fn C.CreateMutex(int, bool, byteptr) voidptr fn C.CreateMutex(int, bool, &byte) voidptr
fn C.WaitForSingleObject(voidptr, int) int fn C.WaitForSingleObject(voidptr, int) int
fn C.ReleaseMutex(voidptr) bool fn C.ReleaseMutex(voidptr) bool
fn C.CreateEvent(int, bool, bool, byteptr) voidptr fn C.CreateEvent(int, bool, bool, &byte) voidptr
fn C.SetEvent(voidptr) int fn C.SetEvent(voidptr) int

View File

@ -1,5 +1,5 @@
fn test_isnil_byteptr() { fn test_isnil_byteptr() {
pb := byteptr(0) pb := &byte(0)
assert isnil(pb) assert isnil(pb)
} }

View File

@ -1539,7 +1539,7 @@ pub fn (s &string) free() {
return return
} }
if s.is_lit == -98761234 { if s.is_lit == -98761234 {
C.printf('double string.free() detected\n') C.printf(c'double string.free() detected\n')
return return
} }
if s.is_lit == 1 || s.len == 0 { if s.is_lit == 1 || s.len == 0 {

View File

@ -182,7 +182,7 @@ pub fn (mut f File) writeln(s string) ?int {
if written == 0 && s.len != 0 { if written == 0 && s.len != 0 {
return error('0 bytes written') return error('0 bytes written')
} }
x := C.fputs('\n', f.cfile) x := C.fputs(c'\n', f.cfile)
if x < 0 { if x < 0 {
return error('could not add newline') return error('could not add newline')
} }

View File

@ -50,7 +50,7 @@ const (
fn parse_iso8601_date(s string) ?(int, int, int) { fn parse_iso8601_date(s string) ?(int, int, int) {
year, month, day, dummy := 0, 0, 0, byte(0) year, month, day, dummy := 0, 0, 0, byte(0)
count := unsafe { C.sscanf(&char(s.str), '%4d-%2d-%2d%c', &year, &month, &day, &dummy) } count := unsafe { C.sscanf(&char(s.str), c'%4d-%2d-%2d%c', &year, &month, &day, &dummy) }
if count != 3 { if count != 3 {
return time.err_invalid_8601 return time.err_invalid_8601
} }
@ -66,13 +66,13 @@ fn parse_iso8601_time(s string) ?(int, int, int, int, i64, bool) {
offset_hour := 0 offset_hour := 0
offset_minute := 0 offset_minute := 0
mut count := unsafe { mut count := unsafe {
C.sscanf(&char(s.str), '%2d:%2d:%2d.%6d%c%2d:%2d', &hour_, &minute_, &second_, C.sscanf(&char(s.str), c'%2d:%2d:%2d.%6d%c%2d:%2d', &hour_, &minute_, &second_,
&microsecond_, &char(&plus_min_z), &offset_hour, &offset_minute) &microsecond_, &char(&plus_min_z), &offset_hour, &offset_minute)
} }
// Missread microsecond ([Sec Hour Minute].len == 3 < 4) // Missread microsecond ([Sec Hour Minute].len == 3 < 4)
if count < 4 { if count < 4 {
count = unsafe { count = unsafe {
C.sscanf(&char(s.str), '%2d:%2d:%2d%c%2d:%2d', &hour_, &minute_, &second_, C.sscanf(&char(s.str), c'%2d:%2d:%2d%c%2d:%2d', &hour_, &minute_, &second_,
&char(&plus_min_z), &offset_hour, &offset_minute) &char(&plus_min_z), &offset_hour, &offset_minute)
} }
count++ // Increment count because skipped microsecond count++ // Increment count because skipped microsecond