library: cleanup of library includes

The includes used to define a lot of things a library include
should not. It was also a bit messy what was exposed in the library
and what was not.

get_pid_digits -> procps_pid_length and exported correctly

MALLOC attribute move into relevant .c files
NORETURN attribute moved to relevant .c, not used in library
PURE attribute removed, it wasn't used
KLONG/KLF/STRTOUKL were fixed for long, so now just use long

HIDDEN attribute removed. It was for 3 functions. The PROCPS_EXPORT
seems to do the same (opposite) thing.

likely/unlikely removed from most places, its highly debateable
this does anything useful as CPUs have gotten smarter about branches.

Re-arranged the includes, ALL external programs should just #include
<proc/procps.h> then proc/procps.h includes headers for files that
have exported functions. procps.h and the headers it includes should
not use items that are not exportable (e.g. hidden functions or
macros) they go in procps-private.h
This commit is contained in:
Craig Small
2016-04-16 17:03:57 +10:00
parent d15a8901d2
commit ccb6ae8de1
38 changed files with 137 additions and 181 deletions

View File

@ -13,11 +13,10 @@
#define PROCPS_PS_H
#include "../include/nls.h"
#include "../proc/escape.h"
#include <proc/procps.h>
// --- <pids> interface begin ||||||||||||||||||||||||||||||||||||||||||||
// -----------------------------------------------------------------------
#include <proc/pids.h>
// hack to minimize code impact
#undef proc_t

View File

@ -28,9 +28,6 @@
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <proc/pids.h>
#include "../proc/sysinfo.h"
#include "../include/c.h"
#include "../include/fileutils.h"
#include "../include/signals.h"

View File

@ -31,8 +31,6 @@
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <proc/uptime.h>
#include "../include/c.h"
#include "../include/xalloc.h"
@ -614,8 +612,8 @@ void self_info(void){
);
fprintf(stderr,
"sizeof(proc_t)=%d sizeof(long)=%d sizeof(KLONG)=%d\n",
(int)sizeof(proc_t), (int)sizeof(long), (int)sizeof(KLONG)
"sizeof(proc_t)=%d sizeof(long)=%d sizeof(long)=%d\n",
(int)sizeof(proc_t), (int)sizeof(long), (int)sizeof(long)
);
fprintf(stderr, "archdefs:%s\n", archdefs);

View File

@ -86,7 +86,7 @@ static int parse_help_opt (const char *opt) {
}
void do_help (const char *opt, int rc) NORETURN;
void do_help (const char *opt, int rc);
void do_help (const char *opt, int rc) {
FILE *out = (rc == EXIT_SUCCESS) ? stdout : stderr;
int section = parse_help_opt(opt);

View File

@ -62,11 +62,8 @@
#include <sys/resource.h>
#include <sys/types.h>
#include <proc/meminfo.h>
#include <proc/readstat.h>
#include "../include/c.h"
#include "../proc/escape.h"
#include "common.h"
@ -1896,7 +1893,7 @@ void show_one_proc(const proc_t *restrict const p, const format_node *restrict f
char *restrict const outbuf = saved_outbuf;
static int did_stuff = 0; /* have we ever printed anything? */
if(unlikely(-1==(long)p)){ /* true only once, at the end */
if(-1==(long)p){ /* true only once, at the end */
if(did_stuff) return;
/* have _never_ printed anything, but might need a header */
if(!--lines_to_next_header){
@ -1906,14 +1903,14 @@ void show_one_proc(const proc_t *restrict const p, const format_node *restrict f
/* fprintf(stderr, "No processes available.\n"); */ /* legal? */
exit(1);
}
if(likely(p)){ /* not header, maybe we should call ourselves for it */
if(unlikely(!--lines_to_next_header)){
if(p){ /* not header, maybe we should call ourselves for it */
if(!--lines_to_next_header){
lines_to_next_header = header_gap;
show_one_proc(NULL,fmt);
}
}
did_stuff = 1;
if(unlikely(active_cols>(int)OUTBUF_SIZE)) fprintf(stderr,_("fix bigness error\n"));
if(active_cols>(int)OUTBUF_SIZE) fprintf(stderr,_("fix bigness error\n"));
/* print row start sequence */
for(;;){
@ -1922,7 +1919,7 @@ void show_one_proc(const proc_t *restrict const p, const format_node *restrict f
// if(likely(fmt->next)) max_rightward = fmt->width;
// else max_rightward = active_cols-((correct>actual) ? correct : actual);
if(likely(fmt->next)){
if(fmt->next){
max_rightward = fmt->width;
tmpspace = 0;
}else{
@ -1940,7 +1937,7 @@ void show_one_proc(const proc_t *restrict const p, const format_node *restrict f
// active_cols, max_rightward, max_leftward, actual, correct);
/* prepare data and calculate leftpad */
if(likely(p) && likely(fmt->pr)) amount = (*fmt->pr)(outbuf,p);
if(p && fmt->pr) amount = (*fmt->pr)(outbuf,p);
else amount = strlen(strcpy(outbuf, fmt->name)); /* AIX or headers */
switch((fmt->flags) & CF_JUST_MASK){
@ -2003,13 +2000,13 @@ void show_one_proc(const proc_t *restrict const p, const format_node *restrict f
*/
space = correct - actual + leftpad;
if(space<1) space=dospace;
if(unlikely(space>SPACE_AMOUNT)) space=SPACE_AMOUNT; // only so much available
if(space>SPACE_AMOUNT) space=SPACE_AMOUNT; // only so much available
/* real size -- don't forget in 'amount' is number of cells */
sz = strlen(outbuf);
/* print data, set x position stuff */
if(unlikely(!fmt->next)){
if(!fmt->next){
/* Last column. Write padding + data + newline all together. */
outbuf[sz] = '\n';
fwrite(outbuf-space, space+sz+1, 1, stdout);

View File

@ -47,7 +47,7 @@ static format_node *do_one_spec(const char *spec, const char *override){
format_node *thisnode;
thisnode = xmalloc(sizeof(format_node));
if(fs->flags & CF_PIDMAX){
w1 = (int)get_pid_digits();
w1 = (int)procps_pid_length();
w2 = strlen(fs->head);
if(w2>w1) w1=w2; // FIXME w/ separate header/body column sizing
}else{