]> granicus.if.org Git - procps-ng/commitdiff
library: eliminate one potential source of human error
authorJim Warner <james.warner@comcast.net>
Sat, 22 Aug 2020 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Wed, 26 Aug 2020 11:50:20 +0000 (21:50 +1000)
There's a huge toe-stubber awaiting future maintenance
as reflected in that commit below which deals with the
addition of new enumerators to the Item_table. Namely,
whenever the table is grown, one must remember to also
change that existing 'logical_end' enumerator's value.

Well, not anymore! Since that MAXTABLE macro was added
to the procps-private.h header we can now also exploit
it so a 'logical_end' automatically tracks table size.

This change also renders some code associated with the
ITEMTABLE_DEBUG #define unnecessary. So it's gone too.

Reference(s):
. 08/2016, add new enumerators
commit 09e1886c9e731f8b8c89a55d11f72f53f030b2de
. 08/2020, added MAXTABLE macro
commit c865b06c304e645c05eae0f5e06a1f49ea105285
. 08/2020, introduced ITEMTABLE_DEBUG
commit 92d0297e1e4d5946c5b098e37c91c7e524a0eca0

Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/diskstats.c
proc/meminfo.c
proc/pids.c
proc/slabinfo.c
proc/stat.c
proc/vmstat.c

index 0fb5d58bd964841b3dc42dfdc0206a4fba9372b2..fb8aa00d25a690e026555af19f236c68c080e32b 100644 (file)
@@ -270,7 +270,7 @@ static struct {
 
     /* please note,
      * this enum MUST be 1 greater than the highest value of any enum */
-enum diskstats_item DISKSTATS_logical_end = DISKSTATS_DELTA_WEIGHTED_TIME + 1;
+enum diskstats_item DISKSTATS_logical_end = MAXTABLE(Item_table);
 
 #undef setNAME
 #undef srtNAME
@@ -725,11 +725,6 @@ PROCPS_EXPORT int procps_diskstats_new (
             failed = 1;
         }
     }
-    if (i != DISKSTATS_logical_end) {
-        fprintf(stderr, "%s: DISKSTATS_logical_end is %d, expected %d\n"
-            , __FILE__, DISKSTATS_logical_end, i);
-        failed = 1;
-    }
     if (failed) _Exit(EXIT_FAILURE);
 #endif
 
index 2ae287631bb4abb516682852d34a1a23336883eb..4ab767b006dfb26f54cd17c3c899984ef6bb18a4 100644 (file)
@@ -454,7 +454,7 @@ static struct {
 
     /* please note,
      * this enum MUST be 1 greater than the highest value of any enum */
-enum meminfo_item MEMINFO_logical_end = MEMINFO_SWAP_DELTA_USED + 1;
+enum meminfo_item MEMINFO_logical_end = MAXTABLE(Item_table);
 
 #undef setNAME
 #undef RS
@@ -808,11 +808,6 @@ PROCPS_EXPORT int procps_meminfo_new (
             failed = 1;
         }
     }
-    if (i != MEMINFO_logical_end) {
-        fprintf(stderr, "%s: MEMINFO_logical_end is %d, expected %d\n"
-            , __FILE__, MEMINFO_logical_end, i);
-        failed = 1;
-    }
     if (failed) _Exit(EXIT_FAILURE);
 #endif
 
index a17245d038df465bcef148dc89bab962a58f364f..53d364825a32390d8a9a076d4b06d6f5924ae76d 100644 (file)
@@ -518,7 +518,7 @@ static struct {
 
     /* please note,
      * this enum MUST be 1 greater than the highest value of any enum */
-enum pids_item PIDS_logical_end = PIDS_WCHAN_NAME + 1;
+enum pids_item PIDS_logical_end = MAXTABLE(Item_table);
 
 #undef setNAME
 #undef freNAME
@@ -1137,11 +1137,6 @@ PROCPS_EXPORT int procps_pids_new (
             failed = 1;
         }
     }
-    if (i != PIDS_logical_end) {
-        fprintf(stderr, "%s: PIDS_logical_end is %d, expected %d\n"
-            , __FILE__, PIDS_logical_end, i);
-        failed = 1;
-    }
     if (failed) _Exit(EXIT_FAILURE);
 #endif
 
index e3b7598a08ab04717bdfef178cb81aaf6c61a572..c36450411c8007818ab49e0bf6505736fad961ab 100644 (file)
@@ -311,7 +311,7 @@ static struct {
 
     /* please note,
      * this enum MUST be 1 greater than the highest value of any enum */
-enum slabinfo_item SLABINFO_logical_end = SLABS_DELTA_SIZE_TOTAL + 1;
+enum slabinfo_item SLABINFO_logical_end = MAXTABLE(Item_table);
 
 #undef setNAME
 #undef srtNAME
@@ -753,11 +753,6 @@ PROCPS_EXPORT int procps_slabinfo_new (
             failed = 1;
         }
     }
-    if (i != SLABINFO_logical_end) {
-        fprintf(stderr, "%s: SLABINFO_logical_end is %d, expected %d\n"
-            , __FILE__, SLABINFO_logical_end, i);
-        failed = 1;
-    }
     if (failed) _Exit(EXIT_FAILURE);
 #endif
 
index 110932ad7206430b2bab3ae9c8405c970a035c32..ff138adc1f65a5763ef09b42855bba6d8d3b0cf0 100644 (file)
@@ -361,7 +361,7 @@ static struct {
 #ifdef ENFORCE_LOGICAL
 enum stat_item STAT_TIC_highest = STAT_TIC_DELTA_GUEST_NICE;
 #endif
-enum stat_item STAT_logical_end = STAT_SYS_DELTA_PROC_RUNNING + 1;
+enum stat_item STAT_logical_end = MAXTABLE(Item_table);
 
 #undef setNAME
 #undef srtNAME
@@ -875,11 +875,6 @@ PROCPS_EXPORT int procps_stat_new (
             failed = 1;
         }
     }
-    if (i != STAT_logical_end) {
-        fprintf(stderr, "%s: STAT_logical_end is %d, expected %d\n"
-            , __FILE__, STAT_logical_end, i);
-        failed = 1;
-    }
     if (failed) _Exit(EXIT_FAILURE);
 #endif
 
index 331659a427911bfd9f69426e7fe605425b962db0..3a81f23818d713f31b222e8a7cf81378375f6b22 100644 (file)
@@ -898,7 +898,7 @@ static struct {
 
     /* please note,
      * this enum MUST be 1 greater than the highest value of any enum */
-enum vmstat_item VMSTAT_logical_end = VMSTAT_DELTA_ZONE_RECLAIM_FAILED + 1;
+enum vmstat_item VMSTAT_logical_end = MAXTABLE(Item_table);
 
 #undef setNAME
 #undef RS
@@ -1305,11 +1305,6 @@ PROCPS_EXPORT int procps_vmstat_new (
             failed = 1;
         }
     }
-    if (i != VMSTAT_logical_end) {
-        fprintf(stderr, "%s: VMSTAT_logical_end is %d, expected %d\n"
-            , __FILE__, VMSTAT_logical_end, i);
-        failed = 1;
-    }
     if (failed) _Exit(EXIT_FAILURE);
 #endif