Discussion:
get-rusage-data: avoid warnings on Mac OS X
(too old to reply)
Bruno Haible
2017-04-22 12:59:25 UTC
Permalink
Raw Message
On Mac OS X, with CPPFLAGS=-Wall, I'm seeing these warnings:

get-rusage-data.c:230:30: warning: 'sbrk' is deprecated [-Wdeprecated-declarations]
void *new_page = sbrk (pagesize);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/unistd.h:587:7: note: 'sbrk' has been explicitly marked deprecated here
void *sbrk(int);
^
get-rusage-data.c:235:17: warning: 'sbrk' is deprecated [-Wdeprecated-declarations]
sbrk (- pagesize);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/unistd.h:587:7: note: 'sbrk' has been explicitly marked deprecated here
void *sbrk(int);
^
get-rusage-data.c:274:30: warning: 'sbrk' is deprecated [-Wdeprecated-declarations]
void *new_page = sbrk (pagesize);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/unistd.h:587:7: note: 'sbrk' has been explicitly marked deprecated here
void *sbrk(int);
^
get-rusage-data.c:279:17: warning: 'sbrk' is deprecated [-Wdeprecated-declarations]
sbrk (- pagesize);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/unistd.h:587:7: note: 'sbrk' has been explicitly marked deprecated here
void *sbrk(int);
^
get-rusage-data.c:363:15: warning: 'sbrk' is deprecated [-Wdeprecated-declarations]
brk_value = sbrk (0);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/unistd.h:587:7: note: 'sbrk' has been explicitly marked deprecated here
void *sbrk(int);
^

This fixes it.


2017-04-22 Bruno Haible <***@clisp.org>

get-rusage-data: Avoid warnings on Mac OS X.
* lib/get-rusage-data.c: On Mac OS X, don't define
get_rusage_data_via_setrlimit nor get_rusage_data_via_iterator.
(get_rusage_data) [Mac OS X]: Just return 0.

diff --git a/lib/get-rusage-data.c b/lib/get-rusage-data.c
index 62293ad..1fc8202 100644
--- a/lib/get-rusage-data.c
+++ b/lib/get-rusage-data.c
@@ -148,13 +148,16 @@
#include "vma-iter.h"


-#if HAVE_SETRLIMIT && defined RLIMIT_DATA
+#if !(defined __APPLE__ && defined __MACH__) || defined TEST
+/* Implement get_rusage_data_via_setrlimit(). */

-# ifdef _AIX
-# define errno_expected() (errno == EINVAL || errno == EFAULT)
-# else
-# define errno_expected() (errno == EINVAL)
-# endif
+# if HAVE_SETRLIMIT && defined RLIMIT_DATA
+
+# ifdef _AIX
+# define errno_expected() (errno == EINVAL || errno == EFAULT)
+# else
+# define errno_expected() (errno == EINVAL)
+# endif

static uintptr_t
get_rusage_data_via_setrlimit (void)
@@ -163,7 +166,7 @@ get_rusage_data_via_setrlimit (void)

struct rlimit orig_limit;

-# ifdef __hpux
+# ifdef __hpux
/* On HP-UX 11.00, setrlimit() RLIMIT_DATA of does not work: It cannot
restore the previous limits.
On HP-UX 11.11, setrlimit() RLIMIT_DATA of does not work: It sometimes
@@ -177,7 +180,7 @@ get_rusage_data_via_setrlimit (void)
|| strcmp (buf.release + strlen (buf.release) - 5, "11.11") == 0))
return 0;
}
-# endif
+# endif

/* Record the original limit. */
if (getrlimit (RLIMIT_DATA, &orig_limit) < 0)
@@ -310,7 +313,7 @@ get_rusage_data_via_setrlimit (void)
return result;
}

-#else
+# else

static uintptr_t
get_rusage_data_via_setrlimit (void)
@@ -318,10 +321,15 @@ get_rusage_data_via_setrlimit (void)
return 0;
}

+# endif
+
#endif


-#if VMA_ITERATE_SUPPORTED
+#if !(defined __APPLE__ && defined __MACH__) || defined TEST
+/* Implement get_rusage_data_via_iterator(). */
+
+# if VMA_ITERATE_SUPPORTED

struct locals
{
@@ -346,7 +354,7 @@ vma_iterate_callback (void *data, uintptr_t start, uintptr_t end,
static uintptr_t
get_rusage_data_via_iterator (void)
{
-# if ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) || defined __BEOS__ || defined __HAIKU__
+# if ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) || defined __BEOS__ || defined __HAIKU__
/* On native Windows, there is no sbrk() function.
On Haiku, sbrk(0) always returns 0. */
static void *brk_value;
@@ -357,13 +365,13 @@ get_rusage_data_via_iterator (void)
if (brk_value == NULL)
return 0;
}
-# else
+# else
void *brk_value;

brk_value = sbrk (0);
if (brk_value == (void *)-1)
return 0;
-# endif
+# endif

{
struct locals l;
@@ -376,7 +384,7 @@ get_rusage_data_via_iterator (void)
}
}

-#else
+# else

static uintptr_t
get_rusage_data_via_iterator (void)
@@ -384,13 +392,20 @@ get_rusage_data_via_iterator (void)
return 0;
}

+# endif
+
#endif


uintptr_t
get_rusage_data (void)
{
-#if (defined __APPLE__ && defined __MACH__) || defined __CYGWIN__ /* Mac OS X, Cygwin */
+#if (defined __APPLE__ && defined __MACH__) /* Mac OS X */
+ /* get_rusage_data_via_setrlimit() does not work: it always returns 0.
+ get_rusage_data_via_iterator() does not work: it always returns 0x400000.
+ And sbrk() is deprecated. */
+ return 0;
+#elif defined __CYGWIN__ /* Cygwin */
/* get_rusage_data_via_setrlimit() does not work.
Prefer get_rusage_data_via_iterator(). */
return get_rusage_data_via_iterator ();

Loading...