From b1a22af46ba7d6f7faf0906ba9182b5d5d913e04 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Thu, 1 Apr 2021 01:08:12 +0200 Subject: [PATCH] main: Use mallinfo2 when available at build time `mallinfo` has been deprecated in favor of `mallinfo2`: ``` The fields of the mallinfo structure that is returned by the older mallinfo() function are typed as int. However, because some internal bookkeeping values may be of type long, the reported values may wrap around zero and thus be inaccurate. ``` Part-of: (cherry picked from commit 3cfbb48f46ca96c968ed98a216595557faa2bf3a) --- config.h.meson | 3 +++ meson.build | 1 + src/main.c | 10 +++++++--- src/shell-global.c | 5 ----- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/config.h.meson b/config.h.meson index 141b2240a..b93fda872 100644 --- a/config.h.meson +++ b/config.h.meson @@ -13,6 +13,9 @@ /* Define to 1 if you have the `mallinfo' function. */ #mesondefine HAVE_MALLINFO +/* Define to 1 if you have the `mallinfo2' function. */ +#mesondefine HAVE_MALLINFO2 + /* Define to 1 fi you have the header file. */ #mesondefine HAVE_SYS_RESOURCE_H diff --git a/meson.build b/meson.build index 5958a7b31..38b7a97af 100644 --- a/meson.build +++ b/meson.build @@ -159,6 +159,7 @@ cdata.set('HAVE_GIO_DESKTOP_LAUNCH_URIS_WITH_FDS', ) cdata.set('HAVE_FDWALK', cc.has_function('fdwalk')) cdata.set('HAVE_MALLINFO', cc.has_function('mallinfo')) +cdata.set('HAVE_MALLINFO2', cc.has_function('mallinfo2')) cdata.set('HAVE_SYS_RESOURCE_H', cc.has_header('sys/resource.h')) cdata.set('HAVE__NL_TIME_FIRST_WEEKDAY', cc.has_header_symbol('langinfo.h', '_NL_TIME_FIRST_WEEKDAY') diff --git a/src/main.c b/src/main.c index 5d07a4301..91e5493fd 100644 --- a/src/main.c +++ b/src/main.c @@ -2,7 +2,7 @@ #include "config.h" -#ifdef HAVE_MALLINFO +#if defined (HAVE_MALLINFO) || defined (HAVE_MALLINFO2) #include #endif #include @@ -213,8 +213,12 @@ static void malloc_statistics_callback (ShellPerfLog *perf_log, gpointer data) { -#ifdef HAVE_MALLINFO +#if defined (HAVE_MALLINFO) || defined (HAVE_MALLINFO2) +#ifdef HAVE_MALLINFO2 + struct mallinfo2 info = mallinfo2 (); +#else struct mallinfo info = mallinfo (); +#endif shell_perf_log_update_statistic_i (perf_log, "malloc.arenaSize", @@ -225,7 +229,7 @@ malloc_statistics_callback (ShellPerfLog *perf_log, shell_perf_log_update_statistic_i (perf_log, "malloc.usedSize", info.uordblks); -#endif +#endif /* defined (HAVE_MALLINFO) || defined (HAVE_MALLINFO2) */ } static void diff --git a/src/shell-global.c b/src/shell-global.c index 027c9d6c4..f05ec9b41 100644 --- a/src/shell-global.c +++ b/src/shell-global.c @@ -32,11 +32,6 @@ #define GNOME_DESKTOP_USE_UNSTABLE_API #include -/* Memory report bits */ -#ifdef HAVE_MALLINFO -#include -#endif - #if defined __OpenBSD__ || defined __FreeBSD__ #include #endif