Skip to content

Commit

Permalink
Use static_fn rather than static
Browse files Browse the repository at this point in the history
I introduced `static_fn` long ago when I when I started contributing
changes and wanted a better way to report a minimally useful backtrace when
events like SIGSEGV being delivered occur. This changes the declarations
of the remaining ksh `static` functions that should use `static_fn`.
This is mostly for consistency rather than any belief that having these
functions be global will materially improve diagnostic feedback.
  • Loading branch information
krader1961 committed Oct 29, 2019
1 parent dd2c8ea commit 4a5d206
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 267 deletions.
58 changes: 29 additions & 29 deletions src/cmd/ksh93/bltins/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,111 +18,111 @@ typedef Sfdouble_t (*Math_f)(Sfdouble_t, ...);

// This used to use `finite()` but that function is deprecated and generates compiler warnings
// on some platforms.
static int local_finite(Sfdouble_t a1) {
static_fn int local_finite(Sfdouble_t a1) {
if (isinf(a1)) return 0; //!OCLINT(constant conditional operator)
if (isnan(a1)) return 0; //!OCLINT(constant conditional operator)
return 1;
}

static Sfdouble_t local_float(Sfdouble_t a1) { return a1; }
static_fn Sfdouble_t local_float(Sfdouble_t a1) { return a1; }

static Sfdouble_t local_int(Sfdouble_t a1) {
static_fn Sfdouble_t local_int(Sfdouble_t a1) {
if (a1 < LLONG_MIN || a1 > ULLONG_MAX) return 0.0;
if (a1 < 0) return (Sfdouble_t)((Sflong_t)a1);
return (Sfdouble_t)((Sfulong_t)a1);
}

static int local_isfinite(Sfdouble_t a1) {
static_fn int local_isfinite(Sfdouble_t a1) {
return isfinite(a1); //!OCLINT(constant conditional operator)
}

static int local_isgreater(Sfdouble_t a1, Sfdouble_t a2) { return isgreater(a1, a2); }
static_fn int local_isgreater(Sfdouble_t a1, Sfdouble_t a2) { return isgreater(a1, a2); }

static int local_isgreaterequal(Sfdouble_t a1, Sfdouble_t a2) { return isgreaterequal(a1, a2); }
static_fn int local_isgreaterequal(Sfdouble_t a1, Sfdouble_t a2) { return isgreaterequal(a1, a2); }

static int local_isinf(Sfdouble_t a1) {
static_fn int local_isinf(Sfdouble_t a1) {
// Some platforms return -1 for -inf and +1 for +inf while others only return +1. Normalize our
// return value to be zero (not inf) or one (inf).
return isinf(a1) != 0; //!OCLINT(constant conditional operator)
}

static int local_isless(Sfdouble_t a1, Sfdouble_t a2) { return isless(a1, a2); }
static_fn int local_isless(Sfdouble_t a1, Sfdouble_t a2) { return isless(a1, a2); }

static int local_islessequal(Sfdouble_t a1, Sfdouble_t a2) { return islessequal(a1, a2); }
static_fn int local_islessequal(Sfdouble_t a1, Sfdouble_t a2) { return islessequal(a1, a2); }

static int local_islessgreater(Sfdouble_t a1, Sfdouble_t a2) { return islessgreater(a1, a2); }
static_fn int local_islessgreater(Sfdouble_t a1, Sfdouble_t a2) { return islessgreater(a1, a2); }

static int local_isnan(Sfdouble_t a1) {
static_fn int local_isnan(Sfdouble_t a1) {
// Some platforms return -1 for -nan and +1 for +nan while others only return +1. Normalize our
// return value to be zero (not -nan) or one (nan).
return isnan(a1) != 0; //!OCLINT(constant conditional operator)
}

static int local_isnormal(Sfdouble_t a1) {
static_fn int local_isnormal(Sfdouble_t a1) {
return isnormal(a1); //!OCLINT(constant conditional operator)
}

static int local_issubnormal(Sfdouble_t a1) {
static_fn int local_issubnormal(Sfdouble_t a1) {
int q = fpclassify(a1); //!OCLINT(constant conditional operator)
return q == FP_SUBNORMAL;
}

static int local_isunordered(Sfdouble_t a1, Sfdouble_t a2) { return isunordered(a1, a2); }
static_fn int local_isunordered(Sfdouble_t a1, Sfdouble_t a2) { return isunordered(a1, a2); }

static int local_iszero(Sfdouble_t a1) {
static_fn int local_iszero(Sfdouble_t a1) {
int q = fpclassify(a1); //!OCLINT(constant conditional operator)
return q == FP_ZERO;
}

static Sfdouble_t local_j0(Sfdouble_t a1) { return j0(a1); }
static_fn Sfdouble_t local_j0(Sfdouble_t a1) { return j0(a1); }

static Sfdouble_t local_j1(Sfdouble_t a1) { return j1(a1); }
static_fn Sfdouble_t local_j1(Sfdouble_t a1) { return j1(a1); }

static Sfdouble_t local_jn(Sfdouble_t a1, Sfdouble_t a2) { return jn(a1, a2); }
static_fn Sfdouble_t local_jn(Sfdouble_t a1, Sfdouble_t a2) { return jn(a1, a2); }

static int local_signbit(Sfdouble_t a1) {
static_fn int local_signbit(Sfdouble_t a1) {
return signbit(a1) != 0; //!OCLINT(constant conditional operator)
}

static Sfdouble_t local_y0(Sfdouble_t a1) { return y0(a1); }
static_fn Sfdouble_t local_y0(Sfdouble_t a1) { return y0(a1); }

static Sfdouble_t local_y1(Sfdouble_t a1) { return y1(a1); }
static_fn Sfdouble_t local_y1(Sfdouble_t a1) { return y1(a1); }

static Sfdouble_t local_yn(Sfdouble_t a1, Sfdouble_t a2) { return yn(a1, a2); }
static_fn Sfdouble_t local_yn(Sfdouble_t a1, Sfdouble_t a2) { return yn(a1, a2); }

#if !_lib_expm1l
static Sfdouble_t local_expm1(Sfdouble_t a1) { return expm1(a1); }
static_fn Sfdouble_t local_expm1(Sfdouble_t a1) { return expm1(a1); }
#define expm1l local_expm1
#endif

#if !_lib_lgammal
static Sfdouble_t local_lgamma(Sfdouble_t a1) { return lgamma(a1); }
static_fn Sfdouble_t local_lgamma(Sfdouble_t a1) { return lgamma(a1); }
#define lgammal local_lgamma
#endif

#if !_lib_log1pl
static Sfdouble_t local_log1p(Sfdouble_t a1) { return log1p(a1); }
static_fn Sfdouble_t local_log1p(Sfdouble_t a1) { return log1p(a1); }
#define log1pl local_log1p
#endif

#if !_lib_log2l
static Sfdouble_t local_log2(Sfdouble_t a1) { return log2(a1); }
static_fn Sfdouble_t local_log2(Sfdouble_t a1) { return log2(a1); }
#define log2l local_log2
#endif

#if !_lib_remainderl
static Sfdouble_t local_remainder(Sfdouble_t a1, Sfdouble_t a2) { return remainder(a1, a2); }
static_fn Sfdouble_t local_remainder(Sfdouble_t a1, Sfdouble_t a2) { return remainder(a1, a2); }
#define remainderl local_remainder
#endif

#if !_lib_tgammal
static Sfdouble_t local_tgamma(Sfdouble_t a1) { return tgamma(a1); }
static_fn Sfdouble_t local_tgamma(Sfdouble_t a1) { return tgamma(a1); }
#define tgammal local_tgamma
#endif

#if __CYGWIN__
// The sqrtl() function on Cygwin incorrectly returns its input if negative rather than NaN.
static Sfdouble_t local_sqrtl(Sfdouble_t a1) {
static_fn Sfdouble_t local_sqrtl(Sfdouble_t a1) {
if (a1 < 0.0) return NAN;
return sqrtl(a1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/cmds/basename.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static const struct optget_option long_options[] = {
{"suffix", optget_no_arg, NULL, 's'},
{NULL, 0, NULL, 0}};

static void namebase(Sfio_t *outfile, char *pathname, char *suffix) {
static_fn void namebase(Sfio_t *outfile, char *pathname, char *suffix) {
char *first, *last;
int n = 0;
for (first = last = pathname; *last; last++) {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/cmds/cat.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static char *stdin_argv[] = {"-", NULL};
* called for any special output processing
*/

static int vcat(char *states, Sfio_t *ip, Sfio_t *op, int flags) {
static_fn int vcat(char *states, Sfio_t *ip, Sfio_t *op, int flags) {
unsigned char *cp;
unsigned char *pp;
unsigned char *cur;
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/ksh93/cmds/cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static const struct optget_option long_options[] = {
{"silent", optget_no_arg, NULL, 's'},
{NULL, 0, NULL, 0}};

static void pretty(Sfio_t *out, int o, int delim, int flags) {
static_fn void pretty(Sfio_t *out, int o, int delim, int flags) {
int m;
char *s;
char buf[10];
Expand Down Expand Up @@ -107,8 +107,8 @@ static void pretty(Sfio_t *out, int o, int delim, int flags) {
* compare two files
*/

static int cmp(const char *file1, Sfio_t *f1, const char *file2, Sfio_t *f2, int flags,
Sfoff_t count, Sfoff_t differences) {
static_fn int cmp(const char *file1, Sfio_t *f1, const char *file2, Sfio_t *f2, int flags,
Sfoff_t count, Sfoff_t differences) {
int c1;
int c2;
unsigned char *p1 = NULL;
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/ksh93/cmds/cut.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ static const struct optget_option long_options[] = {
* compare the first of an array of integers
*/

static int mycomp(const void *a, const void *b) {
static_fn int mycomp(const void *a, const void *b) {
if (*((int *)a) < *((int *)b)) return -1;
if (*((int *)a) > *((int *)b)) return 1;
return 0;
}

static Cut_t *cutinit(int mode, char *str, Delim_t *wdelim, Delim_t *ldelim, size_t reclen) {
static_fn Cut_t *cutinit(int mode, char *str, Delim_t *wdelim, Delim_t *ldelim, size_t reclen) {
int *lp;
int c;
int n = 0;
Expand Down Expand Up @@ -210,7 +210,7 @@ static Cut_t *cutinit(int mode, char *str, Delim_t *wdelim, Delim_t *ldelim, siz
* cut each line of file <fdin> and put results to <fdout> using list <list>
*/

static void cutcols(Cut_t *cut, Sfio_t *fdin, Sfio_t *fdout) {
static_fn void cutcols(Cut_t *cut, Sfio_t *fdin, Sfio_t *fdout) {
int c;
int len;
int ncol = 0;
Expand Down Expand Up @@ -314,7 +314,7 @@ static void cutcols(Cut_t *cut, Sfio_t *fdin, Sfio_t *fdout) {
* stream <fdin> must be line buffered
*/

static void cutfields(Cut_t *cut, Sfio_t *fdin, Sfio_t *fdout) {
static_fn void cutfields(Cut_t *cut, Sfio_t *fdin, Sfio_t *fdout) {
unsigned char *sp = cut->space;
unsigned char *cp;
unsigned char *wp;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/cmds/dirname.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static const struct optget_option long_options[] = {
{"executable", optget_no_arg, NULL, 'x'},
{NULL, 0, NULL, 0}};

static void l_dirname(Sfio_t *outfile, const char *pathname) {
static_fn void l_dirname(Sfio_t *outfile, const char *pathname) {
const char *last;
/* go to end of path */
for (last = pathname; *last; last++) {
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/ksh93/cmds/uname.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ static const struct optget_option long_options[] = {
{"domain", 0, NULL, 'd'},
{NULL, 0, NULL, 0}};

static bool output(bool sep, uint32_t flags, uint32_t flag, const char *value, const char *name) {
static_fn bool output(bool sep, uint32_t flags, uint32_t flag, const char *value,
const char *name) {
if (!(flags & flag)) return sep;

if (*value || flags & OPT_all) {
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/ksh93/edit/completion.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include "sfio.h"
#include "stk.h"

static char *fmtx(Shell_t *shp, const char *string) {
static_fn char *fmtx(Shell_t *shp, const char *string) {
const char *cp = string;
int n, c;
const unsigned char *norm_state = (const unsigned char *)sh_lexstates[ST_NORM];
Expand All @@ -66,7 +66,7 @@ static char *fmtx(Shell_t *shp, const char *string) {
return stkptr(shp->stk, offset);
}

static int charcmp(int a, int b, int nocase) {
static_fn int charcmp(int a, int b, int nocase) {
if (nocase) {
if (isupper(a)) a = tolower(a);
if (isupper(b)) b = tolower(b);
Expand All @@ -78,7 +78,7 @@ static int charcmp(int a, int b, int nocase) {
// Overwrites <str> to common prefix of <str> and <newstr>. If <str> is equal to <newstr> returns
// <str>+strlen(<str>)+1 otherwise returns <str>+strlen(<str>).
//
static char *overlaid(char *str, const char *newstr, int nocase) {
static_fn char *overlaid(char *str, const char *newstr, int nocase) {
int c, d;
while ((c = *(unsigned char *)str) &&
((d = *(unsigned char *)newstr++), charcmp(c, d, nocase))) {
Expand All @@ -95,7 +95,7 @@ static char *overlaid(char *str, const char *newstr, int nocase) {
//
// Returns pointer to beginning of expansion and sets type of expansion.
//
static char *find_begin(char outbuff[], char *last, int endchar, int *type) {
static_fn char *find_begin(char outbuff[], char *last, int endchar, int *type) {
char *cp = outbuff, *bp, *xp;
int c, inquote = 0, inassign = 0;
int mode = *type;
Expand Down Expand Up @@ -186,7 +186,7 @@ static char *find_begin(char outbuff[], char *last, int endchar, int *type) {
return bp;
}

static char **prog_complete(Dt_t *dict, char *line, char *word, int cur) {
static_fn char **prog_complete(Dt_t *dict, char *line, char *word, int cur) {
char *cp = line, *cmd, c, **com = NULL;
struct Complete *pcp;
while (isspace(*cp) || *cp == '#') cp++;
Expand Down
14 changes: 7 additions & 7 deletions src/cmd/ksh93/edit/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static char *savelex;
#define ECHOMODE 3
#define SYSERR -1

static int keytrap(Edit_t *, char *, int, int, int);
static_fn int keytrap(Edit_t *, char *, int, int, int);

#ifndef _POSIX_DISABLE
#define _POSIX_DISABLE 0
Expand Down Expand Up @@ -478,12 +478,12 @@ void ed_setup(Edit_t *ep, int fd, int reedit) {
}
}

static void ed_putstring(Edit_t *ep, const char *str) {
static_fn void ed_putstring(Edit_t *ep, const char *str) {
int c;
while ((c = *str++)) ed_putchar(ep, c);
}

static void ed_nputchar(Edit_t *ep, int n, int c) {
static_fn void ed_nputchar(Edit_t *ep, int n, int c) {
while (n-- > 0) ed_putchar(ep, c);
}

Expand Down Expand Up @@ -592,7 +592,7 @@ int ed_read(void *context, int fd, char *buff, int size, int reedit) {
// character is put onto the stack so that it can be checked for KEYTRAP. Putstack() returns 1
// except when in the middle of a multi-byte char.
//
static int putstack(Edit_t *ep, char string[], int nbyte, int type) {
static_fn int putstack(Edit_t *ep, char string[], int nbyte, int type) {
int c;
char *endp, *p = string;
int size, offset = ep->e_lookahead + nbyte;
Expand Down Expand Up @@ -1049,19 +1049,19 @@ static_fn int keytrap(Edit_t *ep, char *inbuff, int insize, int bufsize, int mod
return insize;
}

static int ed_sortdata(const char *s1, const char *s2) {
static_fn int ed_sortdata(const char *s1, const char *s2) {
Histmatch_t *m1 = (Histmatch_t *)s1;
Histmatch_t *m2 = (Histmatch_t *)s2;
return strcmp(m1->data, m2->data);
}

static int ed_sortindex(const char *s1, const char *s2) {
static_fn int ed_sortindex(const char *s1, const char *s2) {
Histmatch_t *m1 = (Histmatch_t *)s1;
Histmatch_t *m2 = (Histmatch_t *)s2;
return m2->index - m1->index;
}

static int ed_histlencopy(const char *cp, char *dp) {
static_fn int ed_histlencopy(const char *cp, char *dp) {
int c, n = 1, col = 1;
const char *oldcp = cp;

Expand Down
Loading

0 comments on commit 4a5d206

Please sign in to comment.