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: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1786>
This commit is contained in:
Robert Mader 2021-04-01 01:08:12 +02:00 committed by Marge Bot
parent 757501b33a
commit 3cfbb48f46
4 changed files with 11 additions and 8 deletions

View File

@ -13,6 +13,9 @@
/* Define to 1 if you have the `mallinfo' function. */ /* Define to 1 if you have the `mallinfo' function. */
#mesondefine HAVE_MALLINFO #mesondefine HAVE_MALLINFO
/* Define to 1 if you have the `mallinfo2' function. */
#mesondefine HAVE_MALLINFO2
/* Define to 1 fi you have the <sys/resource.h> header file. */ /* Define to 1 fi you have the <sys/resource.h> header file. */
#mesondefine HAVE_SYS_RESOURCE_H #mesondefine HAVE_SYS_RESOURCE_H

View File

@ -158,6 +158,7 @@ cdata.set('HAVE_GIO_DESKTOP_LAUNCH_URIS_WITH_FDS',
) )
cdata.set('HAVE_FDWALK', cc.has_function('fdwalk')) cdata.set('HAVE_FDWALK', cc.has_function('fdwalk'))
cdata.set('HAVE_MALLINFO', cc.has_function('mallinfo')) 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_SYS_RESOURCE_H', cc.has_header('sys/resource.h'))
cdata.set('HAVE__NL_TIME_FIRST_WEEKDAY', cdata.set('HAVE__NL_TIME_FIRST_WEEKDAY',
cc.has_header_symbol('langinfo.h', '_NL_TIME_FIRST_WEEKDAY') cc.has_header_symbol('langinfo.h', '_NL_TIME_FIRST_WEEKDAY')

View File

@ -2,7 +2,7 @@
#include "config.h" #include "config.h"
#ifdef HAVE_MALLINFO #if defined (HAVE_MALLINFO) || defined (HAVE_MALLINFO2)
#include <malloc.h> #include <malloc.h>
#endif #endif
#include <stdlib.h> #include <stdlib.h>
@ -212,8 +212,12 @@ static void
malloc_statistics_callback (ShellPerfLog *perf_log, malloc_statistics_callback (ShellPerfLog *perf_log,
gpointer data) gpointer data)
{ {
#ifdef HAVE_MALLINFO #if defined (HAVE_MALLINFO) || defined (HAVE_MALLINFO2)
#ifdef HAVE_MALLINFO2
struct mallinfo2 info = mallinfo2 ();
#else
struct mallinfo info = mallinfo (); struct mallinfo info = mallinfo ();
#endif
shell_perf_log_update_statistic_i (perf_log, shell_perf_log_update_statistic_i (perf_log,
"malloc.arenaSize", "malloc.arenaSize",
@ -224,7 +228,7 @@ malloc_statistics_callback (ShellPerfLog *perf_log,
shell_perf_log_update_statistic_i (perf_log, shell_perf_log_update_statistic_i (perf_log,
"malloc.usedSize", "malloc.usedSize",
info.uordblks); info.uordblks);
#endif #endif /* defined (HAVE_MALLINFO) || defined (HAVE_MALLINFO2) */
} }
static void static void

View File

@ -31,11 +31,6 @@
#define GNOME_DESKTOP_USE_UNSTABLE_API #define GNOME_DESKTOP_USE_UNSTABLE_API
#include <libgnome-desktop/gnome-systemd.h> #include <libgnome-desktop/gnome-systemd.h>
/* Memory report bits */
#ifdef HAVE_MALLINFO
#include <malloc.h>
#endif
#if defined __OpenBSD__ || defined __FreeBSD__ #if defined __OpenBSD__ || defined __FreeBSD__
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif