misc: fix return value of memory functions (#3818)

Specifically uv_get_free_memory and uv_get_total_memory.
This commit is contained in:
theanarkh 2022-11-11 17:56:06 +08:00 committed by GitHub
parent 3706c4f855
commit 6f69654294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 10 deletions

View File

@ -107,7 +107,7 @@ uint64_t uv_get_free_memory(void) {
if (host_statistics(mach_host_self(), HOST_VM_INFO,
(host_info_t)&info, &count) != KERN_SUCCESS) {
return UV_EINVAL; /* FIXME(bnoordhuis) Translate error. */
return 0;
}
return (uint64_t) info.free_count * sysconf(_SC_PAGESIZE);
@ -120,7 +120,7 @@ uint64_t uv_get_total_memory(void) {
size_t size = sizeof(info);
if (sysctl(which, ARRAY_SIZE(which), &info, &size, NULL, 0))
return UV__ERR(errno);
return 0;
return (uint64_t) info;
}

View File

@ -91,7 +91,7 @@ uint64_t uv_get_free_memory(void) {
size_t size = sizeof(freecount);
if (sysctlbyname("vm.stats.vm.v_free_count", &freecount, &size, NULL, 0))
return UV__ERR(errno);
return 0;
return (uint64_t) freecount * sysconf(_SC_PAGESIZE);
@ -105,7 +105,7 @@ uint64_t uv_get_total_memory(void) {
size_t size = sizeof(info);
if (sysctl(which, ARRAY_SIZE(which), &info, &size, NULL, 0))
return UV__ERR(errno);
return 0;
return (uint64_t) info;
}

View File

@ -103,7 +103,7 @@ uint64_t uv_get_free_memory(void) {
int which[] = {CTL_VM, VM_UVMEXP};
if (sysctl(which, ARRAY_SIZE(which), &info, &size, NULL, 0))
return UV__ERR(errno);
return 0;
return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
}
@ -120,7 +120,7 @@ uint64_t uv_get_total_memory(void) {
size_t size = sizeof(info);
if (sysctl(which, ARRAY_SIZE(which), &info, &size, NULL, 0))
return UV__ERR(errno);
return 0;
return (uint64_t) info;
}

View File

@ -116,7 +116,7 @@ uint64_t uv_get_free_memory(void) {
int which[] = {CTL_VM, VM_UVMEXP};
if (sysctl(which, ARRAY_SIZE(which), &info, &size, NULL, 0))
return UV__ERR(errno);
return 0;
return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
}
@ -128,7 +128,7 @@ uint64_t uv_get_total_memory(void) {
size_t size = sizeof(info);
if (sysctl(which, ARRAY_SIZE(which), &info, &size, NULL, 0))
return UV__ERR(errno);
return 0;
return (uint64_t) info;
}

View File

@ -338,7 +338,7 @@ uint64_t uv_get_free_memory(void) {
memory_status.dwLength = sizeof(memory_status);
if (!GlobalMemoryStatusEx(&memory_status)) {
return -1;
return 0;
}
return (uint64_t)memory_status.ullAvailPhys;
@ -350,7 +350,7 @@ uint64_t uv_get_total_memory(void) {
memory_status.dwLength = sizeof(memory_status);
if (!GlobalMemoryStatusEx(&memory_status)) {
return -1;
return 0;
}
return (uint64_t)memory_status.ullTotalPhys;