add realloc (and update c_allocator)
This commit is contained in:
@@ -150,6 +150,78 @@ task_list_deinit func(list @mut TaskList) void {
|
||||
}
|
||||
|
||||
main func() i32 {
|
||||
resized ?*mut u8 = mem.realloc(mem.c_allocator, none, 0, 4, 1)
|
||||
if resized |bytes| {
|
||||
bytes[0] = 10
|
||||
bytes[1] = 20
|
||||
bytes[2] = 30
|
||||
bytes[3] = 40
|
||||
} else {
|
||||
return 20
|
||||
}
|
||||
|
||||
grown ?*mut u8 = mem.realloc(mem.c_allocator, resized, 4, 8, 1)
|
||||
if grown |bytes| {
|
||||
resized = grown
|
||||
if bytes[0] != 10 or bytes[1] != 20 or bytes[2] != 30 or bytes[3] != 40 {
|
||||
mem.free(mem.c_allocator, grown, 8, 1)
|
||||
return 21
|
||||
}
|
||||
} else {
|
||||
mem.free(mem.c_allocator, resized, 4, 1)
|
||||
return 22
|
||||
}
|
||||
|
||||
shrunk ?*mut u8 = mem.realloc(mem.c_allocator, resized, 8, 2, 1)
|
||||
if shrunk |bytes| {
|
||||
resized = shrunk
|
||||
if bytes[0] != 10 or bytes[1] != 20 {
|
||||
mem.free(mem.c_allocator, shrunk, 2, 1)
|
||||
return 23
|
||||
}
|
||||
} else {
|
||||
mem.free(mem.c_allocator, resized, 8, 1)
|
||||
return 24
|
||||
}
|
||||
|
||||
invalid ?*mut u8 = mem.realloc(mem.c_allocator, resized, 2, 4, 24)
|
||||
if invalid |memory| {
|
||||
mem.free(mem.c_allocator, memory, 4, 24)
|
||||
mem.free(mem.c_allocator, resized, 2, 1)
|
||||
return 25
|
||||
}
|
||||
if resized |bytes| {
|
||||
if bytes[0] != 10 or bytes[1] != 20 {
|
||||
mem.free(mem.c_allocator, resized, 2, 1)
|
||||
return 26
|
||||
}
|
||||
}
|
||||
|
||||
resized = mem.realloc(mem.c_allocator, resized, 2, 0, 1)
|
||||
if resized |memory| {
|
||||
mem.free(mem.c_allocator, memory, 0, 1)
|
||||
return 27
|
||||
}
|
||||
|
||||
over_aligned ?*mut u8 = mem.alloc(mem.c_allocator, 4, 32)
|
||||
if over_aligned |bytes| {
|
||||
bytes[0] = 11
|
||||
bytes[1] = 22
|
||||
} else {
|
||||
return 28
|
||||
}
|
||||
over_aligned_grown ?*mut u8 = mem.realloc(mem.c_allocator, over_aligned, 4, 8, 32)
|
||||
if over_aligned_grown |bytes| {
|
||||
if bytes[0] != 11 or bytes[1] != 22 {
|
||||
mem.free(mem.c_allocator, over_aligned_grown, 8, 32)
|
||||
return 29
|
||||
}
|
||||
mem.free(mem.c_allocator, over_aligned_grown, 8, 32)
|
||||
} else {
|
||||
mem.free(mem.c_allocator, over_aligned, 4, 32)
|
||||
return 30
|
||||
}
|
||||
|
||||
zero_alignment ?*mut u8 = mem.alloc(mem.c_allocator, 8, 0)
|
||||
if zero_alignment |memory| {
|
||||
mem.free(mem.c_allocator, memory, 8, 0)
|
||||
|
||||
Reference in New Issue
Block a user