get-rusage-as: Allow for easier testing.
authorBruno Haible <bruno@clisp.org>
Wed, 26 Jan 2011 01:11:18 +0000 (02:11 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 26 Jan 2011 01:14:28 +0000 (02:14 +0100)
* lib/resource-ext.h (get_rusage_as): Add comment.
* lib/get-rusage-as.c (get_rusage_as_via_setrlimit): Define always.
(main): New function for interactive testing.

ChangeLog
lib/get-rusage-as.c
lib/resource-ext.h

index b5fb644..33b3038 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2011-01-25  Bruno Haible  <bruno@clisp.org>
 
+       get-rusage-as: Allow for easier testing.
+       * lib/resource-ext.h (get_rusage_as): Add comment.
+       * lib/get-rusage-as.c (get_rusage_as_via_setrlimit): Define always.
+       (main): New function for interactive testing.
+
+2011-01-25  Bruno Haible  <bruno@clisp.org>
+
        vma-iter: Treat Haiku like BeOS.
        * lib/vma-iter.h (VMA_ITERATE_SUPPORTED): Define on Haiku as well.
        * lib/vma-iter.c (vma_iterate) [Haiku]: Use the BeOS API.
index 41363c5..46f1f21 100644 (file)
@@ -308,6 +308,14 @@ get_rusage_as_via_setrlimit (void)
   return result;
 }
 
+#else
+
+static inline uintptr_t
+get_rusage_as_via_setrlimit (void)
+{
+  return 0;
+}
+
 #endif
 
 
@@ -364,3 +372,31 @@ get_rusage_as (void)
   return get_rusage_as_via_iterator ();
 #endif
 }
+
+
+#ifdef TEST
+
+#include <stdio.h>
+
+int
+main ()
+{
+  printf ("Initially:           0x%08lX 0x%08lX 0x%08lX\n",
+          get_rusage_as_via_setrlimit (), get_rusage_as_via_iterator (),
+          get_rusage_as ());
+  malloc (0x88);
+  printf ("After small malloc:  0x%08lX 0x%08lX 0x%08lX\n",
+          get_rusage_as_via_setrlimit (), get_rusage_as_via_iterator (),
+          get_rusage_as ());
+  malloc (0x8812);
+  printf ("After medium malloc: 0x%08lX 0x%08lX 0x%08lX\n",
+          get_rusage_as_via_setrlimit (), get_rusage_as_via_iterator (),
+          get_rusage_as ());
+  malloc (0x281237);
+  printf ("After large malloc:  0x%08lX 0x%08lX 0x%08lX\n",
+          get_rusage_as_via_setrlimit (), get_rusage_as_via_iterator (),
+          get_rusage_as ());
+  return 0;
+}
+
+#endif /* TEST */
index 95e1f7d..e7dcc6f 100644 (file)
@@ -27,7 +27,8 @@ extern "C" {
 
 /* Returns the amount of address space currently in use by the current
    process, or zero if unknown.
-   This is the quantity which is limited by setrlimit(RLIMIT_AS,...).  */
+   This is the quantity which is limited by setrlimit(RLIMIT_AS,...).
+   Note: This function always returns zero on OpenBSD and AIX.  */
 extern uintptr_t get_rusage_as (void);