builtin,cgen,markused: add struct @[aligned] support for structs allocated on the heap too (#24886)

This commit is contained in:
kbkpbot 2025-07-14 01:56:28 +08:00 committed by GitHub
parent f06def7d6d
commit fa904c495e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 285 additions and 36 deletions

View file

@ -5,8 +5,17 @@ module builtin
@[unsafe]
pub fn __malloc(size usize) voidptr {
unsafe {
return C.malloc(int(size))
$if windows {
// Warning! On windows, we always use _aligned_malloc to allocate memory.
// This ensures that we can later free the memory with _aligned_free
// without needing to track whether the memory was originally allocated
// by malloc or _aligned_malloc.
return C._aligned_malloc(size, 1)
} $else {
return C.malloc(int(size))
}
}
return unsafe { nil }
}
@[unsafe]