summaryrefslogtreecommitdiffstats
path: root/lib/libpmc
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2015-05-19 18:58:18 +0000
committerjhb <jhb@FreeBSD.org>2015-05-19 18:58:18 +0000
commitd8d8e019c09564f7481439b2714426c420684b42 (patch)
treeaa664d8329f113634ac3854a3d1ae6a917e94b85 /lib/libpmc
parenta7c0f715c79bd7b1f11f62502ce7ec0fc2ffed0f (diff)
downloadFreeBSD-src-d8d8e019c09564f7481439b2714426c420684b42.zip
FreeBSD-src-d8d8e019c09564f7481439b2714426c420684b42.tar.gz
Use fixed enum values for PMC_CLASSES().
This removes one of the frequent causes of ABI breakage when new CPU types are added to hwpmc(4). Differential Revision: https://reviews.freebsd.org/D2586 Reviewed by: davide, emaste, gnn (earlier version) MFC after: 2 weeks
Diffstat (limited to 'lib/libpmc')
-rw-r--r--lib/libpmc/libpmc.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/libpmc/libpmc.c b/lib/libpmc/libpmc.c
index c4482c8..d9d7902 100644
--- a/lib/libpmc/libpmc.c
+++ b/lib/libpmc/libpmc.c
@@ -423,9 +423,14 @@ static const char * pmc_capability_names[] = {
__PMC_CAPS()
};
-static const char * pmc_class_names[] = {
+struct pmc_class_map {
+ enum pmc_class pm_class;
+ const char *pm_name;
+};
+
+static const struct pmc_class_map pmc_class_names[] = {
#undef __PMC_CLASS
-#define __PMC_CLASS(C) #C ,
+#define __PMC_CLASS(S,V,D) { .pm_class = PMC_CLASS_##S, .pm_name = #S } ,
__PMC_CLASSES()
};
@@ -3362,9 +3367,11 @@ pmc_name_of_capability(enum pmc_caps cap)
const char *
pmc_name_of_class(enum pmc_class pc)
{
- if ((int) pc >= PMC_CLASS_FIRST &&
- pc <= PMC_CLASS_LAST)
- return (pmc_class_names[pc]);
+ size_t n;
+
+ for (n = 0; n < PMC_TABLE_SIZE(pmc_class_names); n++)
+ if (pc == pmc_class_names[n].pm_class)
+ return (pmc_class_names[n].pm_name);
errno = EINVAL;
return (NULL);
OpenPOWER on IntegriCloud