Hi Craig,
I've long puzzled over how to assist developers (us & any others) in
validating the result types referenced in program logic against those
reflected in the header.
The attached does the trick, providing the _GET and/or _VAL macros are
used. Or, as with several of our programs, at least used as the basis
for derived macros.
I tried for a solution that was minimally invasive. And unless
validation was activated during make, there is no run-time cost except a
little storage for Item_table addresses and a few unused (and unseen)
functions. But once activated, we get validation of type references for
_GET and _VAL macros, plus detection of invalid item references with the
_VAL macro.
The only wholesale external change required was a one-time addition of
an 'info' parameter to all of the _VAL macros. That parameter remains
unused until either ./configure CFLAGS='-DXTRA_PROCPS_DEBUG' (for all
programs) or a #include <proc/xtra-procps-debug.h> is added after
<proc/procps.h> (for a single program).
With this new tool several errors were uncovered and I've included a
patch for them as well. The type errors discovered probably wouldn't
have caused any real problems. But the invalid items found in both ps
and top were more serious. They arose because some required enumerators
were missing (ps) and a wrong enumerator was used (top).
It's easy to test. After adding the ./configure option or the #include,
just force some type to be wrong. Invalid items and incorrect types
will be noted on stderr.
Regards,
Jim
p.s. Someday, maybe configure.ac could provide a formal build option.
But for now, this manual approach just feels safer.
Attachment:
newlib-types-check.tgz
Description: application/compressed-tar