Skip to content

Commit

Permalink
change byte types to u8 types
Browse files Browse the repository at this point in the history
  • Loading branch information
kimshrier committed Nov 19, 2023
1 parent 53e1e5e commit ac46001
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 45 deletions.
2 changes: 1 addition & 1 deletion vlib/builtin/linux_bare/memory_managment.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module builtin

import dlmalloc

fn mm_alloc(size u64) (&byte, Errno) {
fn mm_alloc(size u64) (&u8, Errno) {
// BEGIN CONSTS
// the constants need to be here, since the initialization of other constants,
// which happen before these ones would, require malloc
Expand Down
8 changes: 4 additions & 4 deletions vlib/builtin/linux_bare/old/linuxsys_bare.v
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,16 @@ fn split_int_errno(rc_in u64) (i64, Errno) {
}

// 0 sys_read unsigned int fd char *buf size_t count
pub fn sys_read(fd i64, buf &byte, count u64) (i64, Errno) {
pub fn sys_read(fd i64, buf &u8, count u64) (i64, Errno) {
return split_int_errno(sys_call3(0, u64(fd), u64(buf), count))
}

// 1 sys_write unsigned int fd, const char *buf, size_t count
pub fn sys_write(fd i64, buf &byte, count u64) (i64, Errno) {
pub fn sys_write(fd i64, buf &u8, count u64) (i64, Errno) {
return split_int_errno(sys_call3(1, u64(fd), u64(buf), count))
}

pub fn sys_open(filename &byte, flags i64, mode int) (i64, Errno) {
pub fn sys_open(filename &u8, flags i64, mode int) (i64, Errno) {
// 2 sys_open const char *filename int flags int mode
return split_int_errno(sys_call3(2, u64(filename), u64(flags), u64(mode)))
}
Expand All @@ -357,7 +357,7 @@ pub fn sys_close(fd i64) Errno {
}

// 9 sys_mmap unsigned long addr unsigned long len unsigned long prot unsigned long flags unsigned long fd unsigned long off
pub fn sys_mmap(addr &byte, len u64, prot Mm_prot, flags Map_flags, fildes u64, off u64) (&byte, Errno) {
pub fn sys_mmap(addr &u8, len u64, prot Mm_prot, flags Map_flags, fildes u64, off u64) (&u8, Errno) {
rc := sys_call6(9, u64(addr), len, u64(prot), u64(flags), fildes, off)
a, e := split_int_errno(rc)
return &u8(a), e
Expand Down
6 changes: 3 additions & 3 deletions vlib/builtin/linux_bare/old/mm_bare.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn mm_pages(size u64) u32 {
return u32(pages)
}

pub fn mm_alloc(size u64) (&byte, Errno) {
pub fn mm_alloc(size u64) (&u8, Errno) {
pages := mm_pages(size)
n_bytes := u64(pages * u32(Linux_mem.page_size))

Expand All @@ -24,7 +24,7 @@ pub fn mm_alloc(size u64) (&byte, Errno) {
return &u8(0), e
}

pub fn mm_free(addr &byte) Errno {
pub fn mm_free(addr &u8) Errno {
ap := &int(addr - 4)
size := u64(*ap) * u64(Linux_mem.page_size)

Expand All @@ -41,7 +41,7 @@ pub fn mem_copy(dest0 voidptr, src0 voidptr, n isize) voidptr {
}

@[unsafe]
pub fn malloc(n isize) &byte {
pub fn malloc(n isize) &u8 {
if n < 0 {
panic('malloc(<0)')
}
Expand Down
10 changes: 5 additions & 5 deletions vlib/builtin/linux_bare/old/string_bare.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ module builtin

pub struct string {
pub:
str &byte
str &u8
len int
}

pub fn strlen(s &byte) int {
pub fn strlen(s &u8) int {
mut i := 0
for ; s[i] != 0; i++ {}
return i
}

pub fn tos(s &byte, len int) string {
pub fn tos(s &u8, len int) string {
if s == 0 {
panic('tos(): nil string')
}
Expand Down Expand Up @@ -49,7 +49,7 @@ pub fn tos_clone(s byteptr) string {

// Same as `tos`, but calculates the length. Called by `string(bytes)` casts.
// Used only internally.
pub fn tos2(s &byte) string {
pub fn tos2(s &u8) string {
if s == 0 {
panic('tos2: nil string')
}
Expand Down Expand Up @@ -85,7 +85,7 @@ pub fn string_ne(s1 string, s2 string) bool {
return !string_eq(s1, s2)
}

pub fn i64_tos(buf &byte, len int, n0 i64, base int) string {
pub fn i64_tos(buf &u8, len int, n0 i64, base int) string {
if base < 2 {
panic('base must be >= 2')
}
Expand Down
2 changes: 1 addition & 1 deletion vlib/builtin/map.c.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module builtin

fn C.wyhash(&byte, u64, u64, &u64) u64
fn C.wyhash(&u8, u64, u64, &u64) u64

fn C.wyhash64(u64, u64) u64

Expand Down
12 changes: 6 additions & 6 deletions vlib/builtin/wasm_bare/libc_impl.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ fn memcmp(a &C.void, b &C.void, n usize) int {
return 0
}

fn vsprintf(str &char, format &char, ap &byte) int {
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 &byte) int {
fn vsnprintf(str &char, size usize, format &char, ap &u8) int {
panic('vsnprintf(): string interpolation is not supported in `-freestanding`')
}

Expand All @@ -119,17 +119,17 @@ enum Errno {
}

// not really needed
fn bare_read(buf &byte, count u64) (i64, Errno) {
fn bare_read(buf &u8, count u64) (i64, Errno) {
return 0, Errno.eerror
}

pub fn bare_print(buf &byte, len u64) {
pub fn bare_print(buf &u8, len u64) {
}

fn bare_eprint(buf &byte, len u64) {
fn bare_eprint(buf &u8, len u64) {
}

pub fn write(_fd i64, _buf &byte, _count u64) i64 {
pub fn write(_fd i64, _buf &u8, _count u64) i64 {
return -1
}

Expand Down
2 changes: 1 addition & 1 deletion vlib/crypto/rand/rand_freebsd.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module rand

#include <stdlib.h>

fn C.arc4random_buf(p &byte, n usize)
fn C.arc4random_buf(p &u8, n usize)

// read returns an array of `bytes_needed` random bytes read from the OS.
pub fn read(bytes_needed int) ![]u8 {
Expand Down
2 changes: 1 addition & 1 deletion vlib/crypto/rand/rand_openbsd.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module rand

#include <stdlib.h>

fn C.arc4random_buf(p &byte, n usize)
fn C.arc4random_buf(p &u8, n usize)

// read returns an array of `bytes_needed` random bytes read from the OS.
pub fn read(bytes_needed int) ![]u8 {
Expand Down
2 changes: 1 addition & 1 deletion vlib/crypto/rand/rand_solaris.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module rand

#include <sys/random.h>

fn C.getrandom(p &byte, n usize, flags u32) int
fn C.getrandom(p &u8, n usize, flags u32) int

const (
read_batch_size = 256
Expand Down
2 changes: 1 addition & 1 deletion vlib/encoding/base32/base32.v
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ fn (enc &Encoding) decode_(src_ []u8, mut dst []u8) !(int, bool) {

// strip_newlines removes newline characters and returns the number
// of non-newline characters copied to dst.
// fn strip_newlines(mut dst []u8, src []byte) int {
// fn strip_newlines(mut dst []u8, src []u8) int {
// mut offset := 0
// for b in src {
// if b in [`\r`, `\n`] {
Expand Down
2 changes: 0 additions & 2 deletions vlib/math/math_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,6 @@ fn test_maxof_minof() {
assert maxof[i32]() == 2147483647
assert maxof[i64]() == 9223372036854775807
assert maxof[u8]() == 255
assert maxof[byte]() == 255
assert maxof[u16]() == 65535
assert maxof[u32]() == 4294967295
assert maxof[u64]() == 18446744073709551615
Expand All @@ -1161,7 +1160,6 @@ fn test_maxof_minof() {
assert minof[i32]() == -2147483648
assert minof[i64]() == -9223372036854775807 - 1
assert minof[u8]() == 0
assert minof[byte]() == 0
assert minof[u16]() == 0
assert minof[u32]() == 0
assert minof[u64]() == 0
Expand Down
4 changes: 2 additions & 2 deletions vlib/stbi/stbi.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn C.stbi_write_bmp(filename &char, w int, h int, comp int, buffer &u8) int
fn C.stbi_write_tga(filename &char, w int, h int, comp int, buffer &u8) int
fn C.stbi_write_jpg(filename &char, w int, h int, comp int, buffer &u8, quality int) int

// fn C.stbi_write_hdr(filename &char, w int, h int, comp int, buffer &byte) int // buffer &byte => buffer &f32
// fn C.stbi_write_hdr(filename &char, w int, h int, comp int, buffer &u8) int // buffer &u8 => buffer &f32

// stbi_write_png write on path a PNG file
// row_stride_in_bytes is usually equal to: w * comp
Expand Down Expand Up @@ -222,7 +222,7 @@ pub fn stbi_write_jpg(path string, w int, h int, comp int, buf &u8, quality int)
}

/*
pub fn stbi_write_hdr(path string, w int, h int, comp int, buf &byte) ! {
pub fn stbi_write_hdr(path string, w int, h int, comp int, buf &u8) ! {
if 0 == C.stbi_write_hdr(&char(path.str), w , h , comp , buf){
return error('stbi_image failed to write hdr file to "$path"')
}
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/checker/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
}
if node.op == .assign {
// `mut arr := [u8(1),2,3]`
// `arr = [byte(4),5,6]`
// `arr = [u8(4),5,6]`
left_info := left_sym.info as ast.Array
left_elem_type := c.table.unaliased_type(left_info.elem_type)
if left_type_unwrapped.nr_muls() == right_type_unwrapped.nr_muls()
Expand Down
6 changes: 3 additions & 3 deletions vlib/v/tests/aliased_array_method_call_test.v
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
fn get_bytes_array() []byte {
return [byte(97), 98, 99]
fn get_bytes_array() []u8 {
return [u8(97), 98, 99]
}

fn test_element_aliased_array_method_call() {
assert get_bytes_array().bytestr() == 'abc'

arr := [byte(97), 98, 99]
arr := [u8(97), 98, 99]
assert arr.bytestr() == 'abc'
}
2 changes: 1 addition & 1 deletion vlib/v/tests/assign_array_of_aliases_test.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn test_assign_array_of_aliases() {
mut arr := [u8(1), 2, 3]
arr = [byte(4), 5, 6]
arr = [u8(4), 5, 6]

println(arr)
assert arr.len == 3
Expand Down
1 change: 0 additions & 1 deletion vlib/v/tests/check_init_value_for_arrays_of_option_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ fn test_primitives() {
check_init_value_for_arrays_of_option[i64]()

check_init_value_for_arrays_of_option[u8]()
check_init_value_for_arrays_of_option[byte]()
check_init_value_for_arrays_of_option[u16]()
check_init_value_for_arrays_of_option[u32]()
check_init_value_for_arrays_of_option[u64]()
Expand Down
6 changes: 3 additions & 3 deletions vlib/v/tests/const_from_bytes_test.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type UUID = [16]byte
type UUID = [16]u8

const codec_test_uuid = UUID([byte(0x6b), 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4,
0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8]!)
const codec_test_uuid = UUID([u8(0x6b), 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00,
0xc0, 0x4f, 0xd4, 0x30, 0xc8]!)

fn test_const_from_bytes() {
println(codec_test_uuid)
Expand Down
4 changes: 2 additions & 2 deletions vlib/v/tests/fn_call_mut_array_of_aliases_args_test.v
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fn f1(mut b []byte) string {
fn f1(mut b []u8) string {
return '${b}'
}

fn f2(b []byte) string {
fn f2(b []u8) string {
return '${b}'
}

Expand Down
2 changes: 1 addition & 1 deletion vlib/v/tests/fn_with_array_of_aliases_argument_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn (f Foo) show_array_of_u8(data []u8) string {
}

fn test_fn_with_array_of_aliases_argument() {
a := [byte(1), 2, 3]
a := [u8(1), 2, 3]

s1 := show_array_of_u8(a)
println(s1)
Expand Down
1 change: 0 additions & 1 deletion vlib/v/tests/typeof_simple_types_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fn test_typeof_for_builtin_int_types() {
assert typeof(u32(1)).name == 'u32'
assert typeof(u64(1)).name == 'u64'
//
assert typeof(byte(1)).name == 'byte'
assert typeof(char(1)).name == 'char'
}

Expand Down
2 changes: 0 additions & 2 deletions vlib/x/json2/encoder.v
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,6 @@ fn (e &Encoder) encode_array[U](val []U, level int, mut wr io.Writer) ! {
e.encode_any(i64(val[i]), level + 1, mut wr)!
} $else $if U is u8 {
e.encode_any(u8(val[i]), level + 1, mut wr)!
} $else $if U is byte {
e.encode_any(u8(val[i]), level + 1, mut wr)!
} $else $if U is u16 {
e.encode_any(u16(val[i]), level + 1, mut wr)!
} $else $if U is u32 {
Expand Down
4 changes: 2 additions & 2 deletions vlib/x/json2/json_module_compatibility_test/json_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ fn test_encode_alias_struct() {
}

struct StByteArray {
ba []byte
ba []u8
}

fn test_byte_array() {
assert json.encode(StByteArray{ ba: [byte(1), 2, 3, 4, 5] }) == '{"ba":[1,2,3,4,5]}'
assert json.encode(StByteArray{ ba: [u8(1), 2, 3, 4, 5] }) == '{"ba":[1,2,3,4,5]}'
}

struct Bar {
Expand Down

0 comments on commit ac46001

Please sign in to comment.