From e03c0329c1ae309a5b160c2c69476f8f4bc572ff Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 26 Jul 2023 09:01:37 +0300 Subject: [PATCH] Revert "runtime: cleanup free_memory comptime conditional (#18968)" This reverts commit 571469a6ac33fb22801879ce74a898c427830ebc. --- vlib/runtime/free_memory_impl_darwin.c.v | 19 +++++++++++-------- vlib/runtime/free_memory_impl_linux.c.v | 9 ++++++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/vlib/runtime/free_memory_impl_darwin.c.v b/vlib/runtime/free_memory_impl_darwin.c.v index 28bb9773fa..9c6c2f897f 100644 --- a/vlib/runtime/free_memory_impl_darwin.c.v +++ b/vlib/runtime/free_memory_impl_darwin.c.v @@ -19,13 +19,16 @@ fn C.host_page_size(host C.host_t, out_page_size &C.vm_size_t) int fn C.host_statistics64(host C.host_t, flavor int, host_info_out &int, host_info_outCnt &u32) int fn free_memory_impl() usize { - mut hs := C.vm_statistics64_data_t{} - mut vmsz := u32(C.HOST_VM_INFO64_COUNT) - mut hps := u32(0) - mut host := C.mach_host_self() - unsafe { - C.host_statistics64(host, C.HOST_VM_INFO64, &int(&hs), &vmsz) - C.host_page_size(host, &C.vm_size_t(&hps)) + $if macos { + mut hs := C.vm_statistics64_data_t{} + mut vmsz := u32(C.HOST_VM_INFO64_COUNT) + mut hps := u32(0) + mut host := C.mach_host_self() + unsafe { + C.host_statistics64(host, C.HOST_VM_INFO64, &int(&hs), &vmsz) + C.host_page_size(host, &C.vm_size_t(&hps)) + } + return usize(u64(hs.free_count) * u64(hps)) } - return usize(u64(hs.free_count) * u64(hps)) + return 1 } diff --git a/vlib/runtime/free_memory_impl_linux.c.v b/vlib/runtime/free_memory_impl_linux.c.v index fa166f41d3..7344f7c518 100644 --- a/vlib/runtime/free_memory_impl_linux.c.v +++ b/vlib/runtime/free_memory_impl_linux.c.v @@ -1,7 +1,10 @@ module runtime fn free_memory_impl() usize { - page_size := usize(C.sysconf(C._SC_PAGESIZE)) - av_phys_pages := usize(C.sysconf(C._SC_AVPHYS_PAGES)) - return page_size * av_phys_pages + $if linux { + page_size := usize(C.sysconf(C._SC_PAGESIZE)) + av_phys_pages := usize(C.sysconf(C._SC_AVPHYS_PAGES)) + return page_size * av_phys_pages + } + return 1 }