Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Shafer committed Apr 18, 2024
2 parents a2ce0d8 + 827115e commit 7ae5d0e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 54 deletions.
36 changes: 16 additions & 20 deletions libxo/libxo.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,11 @@ extern char etext;
#define TRUE 1
#endif

/*
* Older versions of GCC don't have this
*/
/* Make our own version for older versions of GCC that don't have this */
#ifndef __GNUC_PREREQ
#define __GNUC_PREREQ(maj,min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#endif
#define __GNUC_PREREQ(maj,min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#endif /* __GNUC_PREREQ */

/*
* Three styles of specifying thread-local variables are supported.
Expand Down Expand Up @@ -719,6 +718,13 @@ xo_init_handle (xo_handle_t *xop)
XOIF_CLEAR(xop, XOIF_INIT_IN_PROGRESS);
}

static void
xo_default_init_utf8 (xo_handle_t *xop)
{
if (xo_codeset_is_utf8)
XOF_SET(xop, XOF_UTF8);
}

/*
* Initialize the default handle.
*/
Expand All @@ -728,9 +734,7 @@ xo_default_init (void)
xo_handle_t *xop = &xo_default_handle;

xo_init_handle(xop);

if (xo_codeset_is_utf8)
XOF_SET(xop, XOF_UTF8);
xo_default_init_utf8(xop);

xo_default_inited = 1;
}
Expand Down Expand Up @@ -3475,23 +3479,15 @@ xo_trim_ws (xo_buffer_t *xbp, ssize_t len)
}

/*
* Safely pull a "long double" off a va_list. This is a workaround
* for a va_arg bug on PowerPC for gcc 4.9.2 and later.
* Pull a "long double" off our va_list. This was originally done as
* a function to hide some evil bits we had to do to work around a
* gcc-4.9 bug, but that's ancient so we've removed the evil but left
* the function just in case the bug returns. A pessimist, eh?
*/
static inline void
xo_safe_va_arg_long_double (xo_handle_t *xop)
{
#ifndef __GNUC_PREREQ
#if !__GNUC_PREREQ(4, 9) || !defined(PPC)
va_arg(xop->xo_vap, long double);
#elif (sizeof(long double) != sizeof(uint64_t))
#error "size check failure: (sizeof(long double) != sizeof(uint64_t))"
#else
va_arg(xop->xo_vap, uint64_t);
#endif /* __GNUC_PREREQ(4, 9) */
#else /* __GNUC_PREREQ */
va_arg(xop->xo_vap, uint64_t);
#endif /* __GNUC_PREREQ */
}

/*
Expand Down
24 changes: 10 additions & 14 deletions libxo/xo_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,9 @@ typedef struct xo_eval_value_s {
#define XEVF_UNSUPPORTED (1<<3) /* Token type is not supported */
#define XEVF_FINAL (1<<4) /* This is the final answer */

#define XO_EVAL_VALUE_ZERO { .xev_flags = 0 }
#define XO_EVAL_VALUE_INVALID { .xev_type = M_ERROR, .xev_flags = XEVF_INVALID }

#define XO_EVAL_OP_ARGS \
xo_handle_t *xop UNUSED, xo_filter_t *xfp UNUSED, xo_match_t *xmp UNUSED, \
xo_xparse_node_t *xnp UNUSED, \
Expand All @@ -1057,7 +1060,7 @@ typedef xo_eval_value_t (xo_eval_calc_fn_t)(XO_EVAL_CALC_ARGS);
static inline xo_eval_value_t
xo_eval_value_make (unsigned type, unsigned flags, xo_xparse_node_id_t id)
{
xo_eval_value_t value = { 0 };
xo_eval_value_t value = XO_EVAL_VALUE_ZERO;

value.xev_type = type;
value.xev_flags = flags;
Expand All @@ -1071,7 +1074,7 @@ xo_eval_value_make (unsigned type, unsigned flags, xo_xparse_node_id_t id)
static inline xo_eval_value_t
xo_eval_value_float (unsigned flags, xo_float_t val)
{
xo_eval_value_t value = { 0 };
xo_eval_value_t value = XO_EVAL_VALUE_ZERO;

value.xev_type = C_FLOAT;
value.xev_flags = flags;
Expand All @@ -1083,14 +1086,7 @@ xo_eval_value_float (unsigned flags, xo_float_t val)
static inline xo_eval_value_t
xo_eval_value_invalid (void)
{
xo_eval_value_t value = { 0 };

value.xev_type = M_ERROR;
value.xev_flags = XEVF_INVALID;
value.xev_pad = 0;
value.xev_node = 0;
value.xev_uint64 = 0;

xo_eval_value_t value = XO_EVAL_VALUE_INVALID;
return value;
}

Expand All @@ -1102,7 +1098,7 @@ xo_eval (xo_handle_t *xop, xo_filter_t *xfp, xo_match_t *xmp,
static xo_eval_value_t
xo_eval_number (XO_EVAL_NODE_ARGS)
{
xo_eval_value_t value = { .xev_flags = 0 };
xo_eval_value_t value = XO_EVAL_VALUE_ZERO;
const char *str = xo_xparse_str(&xfp->xf_xd, xnp->xn_str);
char *ep;
int64_t ival = strtoll(str, &ep, 0);
Expand Down Expand Up @@ -1293,7 +1289,7 @@ xo_eval_dump_value (xo_handle_t *xop UNUSED, xo_filter_t *xfp UNUSED,
static xo_eval_value_t
xo_eval_compare (XO_EVAL_OP_ARGS)
{
xo_eval_value_t value = { 0 };
xo_eval_value_t value = XO_EVAL_VALUE_ZERO;
int rc = 0;
xo_float_t fval;

Expand Down Expand Up @@ -1555,8 +1551,8 @@ xo_eval (xo_handle_t *xop, xo_filter_t *xfp, xo_match_t *xmp,
xo_xparse_node_id_t id, xo_eval_op_fn_t op_fn)
{
xo_eval_value_t value = xo_eval_value_invalid();
xo_eval_value_t last = XO_EVAL_VALUE_ZERO;
int first = 1;
xo_eval_value_t last = { 0 };

xo_xparse_dump_one_node(&xfp->xf_xd, id, 0, "eval one: ");

Expand Down Expand Up @@ -1699,7 +1695,7 @@ xo_eval (xo_handle_t *xop, xo_filter_t *xfp, xo_match_t *xmp,
static xo_eval_value_t
xo_filter_pred_eval (xo_handle_t *xop, xo_filter_t *xfp, xo_match_t *xmp)
{
xo_eval_value_t value = { 0 };
xo_eval_value_t value = XO_EVAL_VALUE_ZERO;

xo_xparse_dump_one_node(&xfp->xf_xd, xmp->xm_stackp->xs_predicates,
0, "eval: ");
Expand Down
32 changes: 24 additions & 8 deletions libxo/xo_humanize.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,30 @@ xo_humanize_number (char *buf, size_t len, int64_t bytes,
const char *suffix, int scale, int flags)
{
const char *prefixes, *sep;
int b, i, r, maxscale, s1, s2, sign;
int b, i, r, s1, s2, sign;
int64_t divisor, max;
// We multiply bytes by 100 to deal with rounding, so we need something
// big enough to hold LLONG_MAX * 100. On 64-bit we can use 128-bit wide
// integers with __int128_t, but on 32-bit we have to use long double.

/*
* We multiply bytes by 100 to deal with rounding, so we need
* something big enough to hold LLONG_MAX * 100. On 64-bit we
* can use 128-bit wide integers with __int128_t, but on
* 32-bit we have to use long double.
*
* Note: For mips 64 but architecture, we have missing
* undefined reference to `__divti3', which is observed when
* 128 bit wide integers with __int128_t is used, so in this
* case also we will use 32-bit and we have to use long
* double.
*/
#ifdef __LP64__
__int128_t scalable = (__int128_t)bytes;
#if defined __FreeBSD__ && __FreeBSD__ == 6 && defined __mips64__
long double scalable = (long double)bytes;
#else
long double scalable = (long double)bytes;
__int128_t scalable = (__int128_t)bytes;
#endif
#else
long double scalable = (long double)bytes;
#endif
size_t baselen;

assert(buf != NULL);
assert(suffix != NULL);
Expand All @@ -98,7 +111,8 @@ xo_humanize_number (char *buf, size_t len, int64_t bytes,
}

#define SCALE2PREFIX(scale) (&prefixes[(scale) << 1])
maxscale = 7;
int maxscale = 7;
size_t baselen;

if (scale >= maxscale &&
(scale & (HN_AUTOSCALE | HN_GETSCALE)) == 0)
Expand All @@ -118,12 +132,14 @@ xo_humanize_number (char *buf, size_t len, int64_t bytes,
scalable *= 100;
baselen = 2; /* digit, prefix */
}

if (flags & HN_NOSPACE)
sep = "";
else {
sep = " ";
baselen++;
}

baselen += strlen(suffix);

/* Check if enough room for `x y' + suffix + `\0' */
Expand Down
15 changes: 7 additions & 8 deletions libxo/xo_syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include <sys/syslog.h>
#include <sys/uio.h>
#include <sys/un.h>
#include <netdb.h>
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
Expand Down Expand Up @@ -99,13 +98,13 @@
#define XO_DEFAULT_EID 32473 /* Fallback to the "example" number */
#endif

#ifndef HOST_NAME_MAX
#ifndef XO_HOST_NAME_MAX
#ifdef _POSIX_HOST_NAME_MAX
#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
#define XO_HOST_NAME_MAX _POSIX_HOST_NAME_MAX
#else
#define HOST_NAME_MAX 255
#define XO_HOST_NAME_MAX 255
#endif /* _POSIX_HOST_NAME_MAX */
#endif /* HOST_NAME_MAX */
#endif /* XO_HOST_NAME_MAX */

static int xo_logfile = -1; /* fd for log */
static int xo_status; /* connection xo_status */
Expand Down Expand Up @@ -550,7 +549,7 @@ xo_vsyslog (int pri, const char *name, const char *fmt, va_list vap)
} else
gettimeofday(&tv, NULL);

(void) localtime_r(&tv.tv_sec, &tm);
(void) localtime_r((time_t *) &tv.tv_sec, &tm);

if (xo_logstat & LOG_PERROR) {
/*
Expand Down Expand Up @@ -584,13 +583,13 @@ xo_vsyslog (int pri, const char *name, const char *fmt, va_list vap)
* Add HOSTNAME; we rely on gethostname and don't fluff with
* ip addresses. Might need to revisit.....
*/
char hostname[HOST_NAME_MAX + 1];
char hostname[XO_HOST_NAME_MAX + 1];
hostname[0] = '\0';
if (xo_unit_test)
strcpy(hostname, "worker-host");
else
(void) gethostname(hostname, sizeof(hostname) - 1);
hostname[HOST_NAME_MAX] = '\0'; /* Ensure NUL-terminated */
hostname[XO_HOST_NAME_MAX] = '\0'; /* Ensure NUL-terminated */

xb.xb_curp += xo_snprintf(xb.xb_curp, xo_buf_left(&xb), "%s ",
hostname[0] ? hostname : "-");
Expand Down
8 changes: 4 additions & 4 deletions libxo/xo_xpath.y
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
* Literal tokens which _may_ preceed the multiplication operator
*/
%token M_MULTIPLICATION_TEST_LAST 45 /* Magic marker: highest token number */
%token L_ASTERISK 46 "*"
%token L_ASTERISK 46 /* "*" */
%token L_CBRACK 47 "]"
%token L_CPAREN 48 ")"
%token L_DOT 49 "."
Expand Down Expand Up @@ -211,6 +211,9 @@
#define yylex(_lvalp, _param) \
xo_xpath_yylex(_param, _lvalp)

#define yytname xo_xpath_yyname
#define yypact xo_xpath_yydefred

/*
* Even if we don't want debug printfs, we still need the arrays with
* names for our own nefarious purposes.
Expand Down Expand Up @@ -830,9 +833,6 @@ xp_relational_expr :
#define YYLAST ((sizeof(yytable) / sizeof(yytable[0])) - 1)
#endif /* YYLAST */

#define yytname xo_xpath_yyname
#define yypact xo_xpath_yydefred

const int xo_xparse_num_tokens = YYNTOKENS;
const char *xo_xparse_keyword_string[YYNTOKENS];
const char *xo_xparse_token_name_fancy[YYNTOKENS];
Expand Down

0 comments on commit 7ae5d0e

Please sign in to comment.