Permalink
Browse files

Change return type of uv_get_*_memory() functions

... from double to uint64_t. Limit use of floating point in public API as much
as possible.
  • Loading branch information...
1 parent 9757a43 commit d3967992107551988ef309465974eee67fb92c10 @bnoordhuis bnoordhuis committed Oct 21, 2011
Showing with 37 additions and 37 deletions.
  1. +2 −2 include/uv.h
  2. +4 −4 src/unix/cygwin.c
  3. +4 −4 src/unix/darwin.c
  4. +4 −4 src/unix/freebsd.c
  5. +4 −4 src/unix/linux.c
  6. +4 −4 src/unix/netbsd.c
  7. +4 −4 src/unix/openbsd.c
  8. +4 −4 src/unix/sunos.c
  9. +4 −4 src/win/util.c
  10. +3 −3 test/test-get-memory.c
View
@@ -1127,8 +1127,8 @@ int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size);
int uv_exepath(char* buffer, size_t* size);
/* Gets memory info in bytes */
-double uv_get_free_memory(void);
-double uv_get_total_memory(void);
+uint64_t uv_get_free_memory(void);
+uint64_t uv_get_total_memory(void);
/*
* Returns the current high-resolution real time. This is expressed in
View
@@ -58,12 +58,12 @@ int uv_exepath(char* buffer, size_t* size) {
return 0;
}
-double uv_get_free_memory(void) {
- return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
+uint64_t uv_get_free_memory(void) {
+ return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
}
-double uv_get_total_memory(void) {
- return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
+uint64_t uv_get_total_memory(void) {
+ return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
}
int uv_fs_event_init(uv_loop_t* loop,
View
@@ -71,7 +71,7 @@ int uv_exepath(char* buffer, size_t* size) {
return 0;
}
-double uv_get_free_memory(void) {
+uint64_t uv_get_free_memory(void) {
vm_statistics_data_t info;
mach_msg_type_number_t count = sizeof(info) / sizeof(integer_t);
@@ -80,10 +80,10 @@ double uv_get_free_memory(void) {
return -1;
}
- return (double) info.free_count * sysconf(_SC_PAGESIZE);
+ return (uint64_t) info.free_count * sysconf(_SC_PAGESIZE);
}
-double uv_get_total_memory(void) {
+uint64_t uv_get_total_memory(void) {
uint64_t info;
int which[] = {CTL_HW, HW_MEMSIZE};
size_t size = sizeof(info);
@@ -92,7 +92,7 @@ double uv_get_total_memory(void) {
return -1;
}
- return (double) info;
+ return (uint64_t) info;
}
void uv_loadavg(double avg[3]) {
View
@@ -70,19 +70,19 @@ int uv_exepath(char* buffer, size_t* size) {
return 0;
}
-double uv_get_free_memory(void) {
+uint64_t uv_get_free_memory(void) {
int freecount;
size_t size = sizeof(freecount);
if(sysctlbyname("vm.stats.vm.v_free_count",
&freecount, &size, NULL, 0) == -1){
return -1;
}
- return (double) freecount * sysconf(_SC_PAGESIZE);
+ return (uint64_t) freecount * sysconf(_SC_PAGESIZE);
}
-double uv_get_total_memory(void) {
+uint64_t uv_get_total_memory(void) {
unsigned long info;
int which[] = {CTL_HW, HW_PHYSMEM};
@@ -92,7 +92,7 @@ double uv_get_total_memory(void) {
return -1;
}
- return (double) info;
+ return (uint64_t) info;
}
void uv_loadavg(double avg[3]) {
View
@@ -75,12 +75,12 @@ int uv_exepath(char* buffer, size_t* size) {
return 0;
}
-double uv_get_free_memory(void) {
- return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
+uint64_t uv_get_free_memory(void) {
+ return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
}
-double uv_get_total_memory(void) {
- return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
+uint64_t uv_get_total_memory(void) {
+ return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
}
static int new_inotify_fd(void) {
View
@@ -82,7 +82,7 @@ int uv_exepath(char* buffer, size_t* size) {
return 0;
}
-double uv_get_free_memory(void) {
+uint64_t uv_get_free_memory(void) {
struct uvmexp info;
size_t size = sizeof(info);
int which[] = {CTL_VM, VM_UVMEXP};
@@ -91,10 +91,10 @@ double uv_get_free_memory(void) {
return -1;
}
- return (double) info.free * psysconf(_SC_PAGESIZE);
+ return (uint64_t) info.free * psysconf(_SC_PAGESIZE);
}
-double uv_get_total_memory(void) {
+uint64_t uv_get_total_memory(void) {
#if defined(HW_PHYSMEM64)
uint64_t info;
int which[] = {CTL_HW, HW_PHYSMEM64};
@@ -108,5 +108,5 @@ double uv_get_total_memory(void) {
return -1;
}
- return (double) info;
+ return (uint64_t) info;
}
View
@@ -98,7 +98,7 @@ int uv_exepath(char* buffer, size_t* size) {
return status;
}
-double uv_get_free_memory(void) {
+uint64_t uv_get_free_memory(void) {
struct uvmexp info;
size_t size = sizeof(info);
int which[] = {CTL_VM, VM_UVMEXP};
@@ -107,10 +107,10 @@ double uv_get_free_memory(void) {
return -1;
}
- return (double) info.free * sysconf(_SC_PAGESIZE);
+ return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
}
-double uv_get_total_memory(void) {
+uint64_t uv_get_total_memory(void) {
uint64_t info;
int which[] = {CTL_HW, HW_PHYSMEM64};
size_t size = sizeof(info);
@@ -119,5 +119,5 @@ double uv_get_total_memory(void) {
return -1;
}
- return (double) info;
+ return (uint64_t) info;
}
View
@@ -66,13 +66,13 @@ int uv_exepath(char* buffer, size_t* size) {
}
-double uv_get_free_memory(void) {
- return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
+uint64_t uv_get_free_memory(void) {
+ return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
}
-double uv_get_total_memory(void) {
- return (double) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
+uint64_t uv_get_total_memory(void) {
+ return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
}
View
@@ -103,7 +103,7 @@ void uv_loadavg(double avg[3]) {
}
-double uv_get_free_memory(void) {
+uint64_t uv_get_free_memory(void) {
MEMORYSTATUSEX memory_status;
memory_status.dwLength = sizeof(memory_status);
@@ -112,11 +112,11 @@ double uv_get_free_memory(void) {
return -1;
}
- return (double)memory_status.ullAvailPhys;
+ return (uint64_t)memory_status.ullAvailPhys;
}
-double uv_get_total_memory(void) {
+uint64_t uv_get_total_memory(void) {
MEMORYSTATUSEX memory_status;
memory_status.dwLength = sizeof(memory_status);
@@ -125,7 +125,7 @@ double uv_get_total_memory(void) {
return -1;
}
- return (double)memory_status.ullTotalPhys;
+ return (uint64_t)memory_status.ullTotalPhys;
}
View
@@ -23,10 +23,10 @@
#include "task.h"
TEST_IMPL(get_memory) {
- double free_mem = uv_get_free_memory();
- double total_mem = uv_get_total_memory();
+ uint64_t free_mem = uv_get_free_memory();
+ uint64_t total_mem = uv_get_total_memory();
- printf("free_mem=%.0f, total_mem=%.0f\n", free_mem, total_mem);
+ printf("free_mem=%llu, total_mem=%llu\n", free_mem, total_mem);
ASSERT(free_mem > 0);
ASSERT(total_mem > 0);

0 comments on commit d396799

Please sign in to comment.