svn commit: r346196 - in head/lib/libpmc: . pmu-events

Enji Cooper ngie at FreeBSD.org
Tue Sep 3 14:06:52 UTC 2019


Author: ngie
Date: Sun Apr 14 00:06:49 2019
New Revision: 346196
URL: https://svnweb.freebsd.org/changeset/base/346196

Log:
  Fix warnings with lib/libpmc
  
  * Use `MIN` instead of similar hand rolled macro.
  * Sort headers.
  * Use `errno.h` instead of `sys/errno.h`.
  * Wrap the argument to sizeof in parentheses for clarity.
  * Remove `__BSD_VISIBLE` and `_XOPEN_SOURCE` #defines to mute warnings about
    incompatible snprintf definitions.
  
  This fixes a number of warnings I've been seeing lately in my builds.
  
  Sort makefile variables per style.Makefile(9) (`CFLAGS`/`CWARNFLAG.gcc`) and
  bump `WARNS` to 3.
  
  MFC after:	2 weeks
  Reviewed by:	jtl
  Approved by:	jtl (mentor)
  MFC after:	1 month
  Differential Revision:	https://reviews.freebsd.org/D19851

Added:
  head/lib/libpmc/Makefile.inc   (contents, props changed)
Modified:
  head/lib/libpmc/Makefile
  head/lib/libpmc/libpmc_json.cc
  head/lib/libpmc/pmu-events/jevents.c
  head/lib/libpmc/pmu-events/jevents.h

Modified: head/lib/libpmc/Makefile
==============================================================================
--- head/lib/libpmc/Makefile	Sat Apr 13 23:52:33 2019	(r346195)
+++ head/lib/libpmc/Makefile	Sun Apr 14 00:06:49 2019	(r346196)
@@ -6,9 +6,6 @@ LIB=	pmc
 SRCS=	libpmc.c pmclog.c libpmc_pmu_util.c libpmc_json.cc
 INCS=	pmc.h pmclog.h pmcformat.h
 
-CFLAGS+= -I${.CURDIR}
-CWARNFLAGS.gcc+= -Wno-shadow -Wno-cast-align
-
 .if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
 
 .if ${MACHINE_ARCH} == "aarch64"
@@ -30,6 +27,11 @@ libpmc_events.c: ${JEVENTS}
 	${JEVENTS} ${EVENT_ARCH} ${.CURDIR}/pmu-events/arch libpmc_events.c
 SRCS+= libpmc_events.c
 .endif
+
+WARNS?=	3
+
+CFLAGS+= -I${.CURDIR}
+CWARNFLAGS.gcc+= -Wno-shadow -Wno-cast-align
 
 MAN=	pmc.3
 MAN+=	pmc_allocate.3

Added: head/lib/libpmc/Makefile.inc
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libpmc/Makefile.inc	Sun Apr 14 00:06:49 2019	(r346196)
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+WARNS?=	3

Modified: head/lib/libpmc/libpmc_json.cc
==============================================================================
--- head/lib/libpmc/libpmc_json.cc	Sat Apr 13 23:52:33 2019	(r346195)
+++ head/lib/libpmc/libpmc_json.cc	Sun Apr 14 00:06:49 2019	(r346196)
@@ -29,19 +29,21 @@
  */
 
 #include <sys/types.h>
-#include <sys/errno.h>
 #include <sys/sysctl.h>
-#include <stddef.h>
-#include <stdlib.h>
+#include <assert.h>
 #include <err.h>
+#include <errno.h>
 #include <limits.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
-#include <pmc.h>
-#include <pmclog.h>
-#include <assert.h>
 #include <string>
 #include <sysexits.h>
+
+#include <pmc.h>
 #include <pmcformat.h>
+#include <pmclog.h>
 
 using std::string;
 

Modified: head/lib/libpmc/pmu-events/jevents.c
==============================================================================
--- head/lib/libpmc/pmu-events/jevents.c	Sat Apr 13 23:52:33 2019	(r346195)
+++ head/lib/libpmc/pmu-events/jevents.c	Sun Apr 14 00:06:49 2019	(r346196)
@@ -1,5 +1,3 @@
-#define  _XOPEN_SOURCE 500	/* needed for nftw() */
-#define __BSD_VISIBLE 1	/* needed for asprintf() */
 /* Parse event JSON files */
 
 /*
@@ -33,22 +31,22 @@
  *
 */
 
-
+#include <sys/param.h>
+#include <sys/resource.h>		/* getrlimit */
+#include <sys/stat.h>
+#include <sys/time.h>			/* getrlimit */
+#include <ctype.h>
+#include <dirent.h>
+#include <errno.h>
+#include <libgen.h>
+#include <limits.h>
+#include <stdarg.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <errno.h>
 #include <string.h>
-#include <ctype.h>
 #include <unistd.h>
-#include <stdarg.h>
-#include <libgen.h>
-#include <limits.h>
-#include <dirent.h>
-#include <sys/time.h>			/* getrlimit */
-#include <sys/resource.h>		/* getrlimit */
 #include <ftw.h>
-#include <sys/stat.h>
 #include "list.h"
 #include "jsmn.h"
 #include "json.h"
@@ -641,7 +639,7 @@ int json_events(const char *fn,
 				addfield(map, &extra_desc, " ",
 						"(Precise event)", NULL);
 		}
-		snprintf(buf, sizeof buf, "event=%#llx", eventcode);
+		snprintf(buf, sizeof(buf), "event=%#llx", eventcode);
 		addfield(map, &event, ",", buf, NULL);
 		if (desc && extra_desc)
 			addfield(map, &desc, " ", extra_desc, NULL);
@@ -866,7 +864,7 @@ static int get_maxfds(void)
 	if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
 		if (rlim.rlim_max == RLIM_INFINITY)
 			return 512;
-		return min((unsigned)rlim.rlim_max / 2, 512);
+		return MIN(rlim.rlim_max / 2, 512);
 	}
 
 	return 512;

Modified: head/lib/libpmc/pmu-events/jevents.h
==============================================================================
--- head/lib/libpmc/pmu-events/jevents.h	Sat Apr 13 23:52:33 2019	(r346195)
+++ head/lib/libpmc/pmu-events/jevents.h	Sun Apr 14 00:06:49 2019	(r346196)
@@ -11,12 +11,4 @@ int json_events(const char *fn,
 		void *data);
 char *get_cpu_str(void);
 
-#ifndef min
-#define min(x, y) ({                            \
-	typeof(x) _min1 = (x);                  \
-	typeof(y) _min2 = (y);                  \
-	(void) (&_min1 == &_min2);              \
-	_min1 < _min2 ? _min1 : _min2; })
-#endif
-
 #endif




More information about the svn-src-head mailing list