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

freestanding: malloc/free with mm_alloc an mm_free

Added more array support that depends on malloc. Added string clone (that uses malloc). Added test for it. Eliminated stack allocated buffers from most of the unit checks.
This commit is contained in:
bogen85
2019-12-08 04:44:52 -06:00
committed by Alexander Medvednikov
parent 6ec626c5e9
commit 8178e1f7da
10 changed files with 96 additions and 56 deletions

View File

@@ -8,9 +8,8 @@ fn check_string_eq () {
}
fn check_i64_tos() {
buffer, e := mm_alloc(128)
assert e == .enoerror
assert !isnil(buffer)
buffer0 := [byte(0)].repeat(128)
buffer := byteptr(buffer0.data)
s0 := i64_tos(buffer, 70, 140, 10)
assert s0 == "140"
@@ -23,14 +22,29 @@ fn check_i64_tos() {
s3 := i64_tos(buffer, 70, -160000, 10)
assert s3 == "-160000"
}
assert mm_free(buffer) == .enoerror
fn check_i64_str() {
assert "141" == i64_str(141, 10)
assert "-161" == i64_str(-161, 10)
assert "10002" == i64_str(65538, 16)
assert "-160001" == i64_str(-160001, 10)
}
fn check_str_clone() {
a := i64_str(1234,10)
b := a.clone()
assert a == b
c := i64_str(-6789,10).clone()
assert c == "-6789"
}
fn main () {
mut fails := 0
fails += forkedtest.normal_run(check_string_eq, "check_string_eq")
fails += forkedtest.normal_run(check_i64_tos, "check_i64_tos")
fails += forkedtest.normal_run(check_i64_str, "check_i64_str")
fails += forkedtest.normal_run(check_str_clone, "check_str_clone")
assert fails == 0
sys_exit(0)
}