[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] xen/decompress: Drop bool_t and use bool instead



On Tue, 20 Jun 2023, Andrew Cooper wrote:
> In particular, the libxg wrapper for unxz.c uses char for bool_t which is a
> major antipattern.  Luckily the code doesn't suffer from truncated values.
> 
> No functional change.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>

FYI I checked patchew and it took the patch off of xen-devel, applied it
to a branch, triggered a gitlab-ci pipeline, and it was successful:
https://gitlab.com/xen-project/patchew/xen/-/pipelines/906050463

All of this without me having to do anything! We live in the future.

Reviewed-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>


> ---
> CC: Jan Beulich <JBeulich@xxxxxxxx>
> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> CC: Wei Liu <wl@xxxxxxx>
> CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
> CC: Julien Grall <julien@xxxxxxx>
> CC: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
> CC: Bertrand Marquis <bertrand.marquis@xxxxxxx>
> ---
>  .../libs/guest/xg_dom_decompress_unsafe_xz.c  |  1 -
>  xen/common/unxz.c                             |  2 +-
>  xen/common/xz/dec_bcj.c                       |  6 +++---
>  xen/common/xz/dec_lzma2.c                     | 20 +++++++++----------
>  xen/common/xz/dec_stream.c                    |  8 ++++----
>  xen/common/xz/lzma2.h                         |  2 +-
>  xen/common/xz/private.h                       |  2 +-
>  7 files changed, 20 insertions(+), 21 deletions(-)
> 
> diff --git a/tools/libs/guest/xg_dom_decompress_unsafe_xz.c 
> b/tools/libs/guest/xg_dom_decompress_unsafe_xz.c
> index fc4819874111..80eed912dd68 100644
> --- a/tools/libs/guest/xg_dom_decompress_unsafe_xz.c
> +++ b/tools/libs/guest/xg_dom_decompress_unsafe_xz.c
> @@ -11,7 +11,6 @@
>  // TODO
>  #define XZ_DEC_X86
>  
> -typedef char bool_t;
>  typedef uint8_t u8;
>  typedef uint16_t u16;
>  typedef uint32_t u32;
> diff --git a/xen/common/unxz.c b/xen/common/unxz.c
> index 17aead0adfe6..9586a4e5c94f 100644
> --- a/xen/common/unxz.c
> +++ b/xen/common/unxz.c
> @@ -166,7 +166,7 @@ int __init unxz(unsigned char *in, unsigned int in_size,
>       struct xz_buf b;
>       struct xz_dec *s;
>       enum xz_ret ret;
> -     bool_t must_free_in = false;
> +     bool must_free_in = false;
>  
>       xz_crc32_init();
>  
> diff --git a/xen/common/xz/dec_bcj.c b/xen/common/xz/dec_bcj.c
> index bfa498587ab8..bdc59770f8a6 100644
> --- a/xen/common/xz/dec_bcj.c
> +++ b/xen/common/xz/dec_bcj.c
> @@ -35,7 +35,7 @@ struct xz_dec_bcj {
>       enum xz_ret ret;
>  
>       /* True if we are operating in single-call mode. */
> -     bool_t single_call;
> +     bool single_call;
>  
>       /*
>        * Absolute position relative to the beginning of the uncompressed
> @@ -87,7 +87,7 @@ static inline int __init bcj_x86_test_msbyte(uint8_t b)
>  
>  static size_t __init bcj_x86(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
>  {
> -     static const bool_t mask_to_allowed_status[8]
> +     static const bool mask_to_allowed_status[8]
>               = { true, true, true, false, true, false, false, false };
>  
>       static const uint8_t mask_to_bit_num[8] = { 0, 1, 2, 2, 3, 3, 3, 3 };
> @@ -524,7 +524,7 @@ XZ_EXTERN enum xz_ret __init xz_dec_bcj_run(struct 
> xz_dec_bcj *s,
>       return s->ret;
>  }
>  
> -XZ_EXTERN struct xz_dec_bcj *__init xz_dec_bcj_create(bool_t single_call)
> +XZ_EXTERN struct xz_dec_bcj *__init xz_dec_bcj_create(bool single_call)
>  {
>       struct xz_dec_bcj *s = malloc(sizeof(*s));
>       if (s != NULL)
> diff --git a/xen/common/xz/dec_lzma2.c b/xen/common/xz/dec_lzma2.c
> index f80d8309f4c3..71359fab9f60 100644
> --- a/xen/common/xz/dec_lzma2.c
> +++ b/xen/common/xz/dec_lzma2.c
> @@ -241,13 +241,13 @@ struct lzma2_dec {
>        * True if dictionary reset is needed. This is false before
>        * the first chunk (LZMA or uncompressed).
>        */
> -     bool_t need_dict_reset;
> +     bool need_dict_reset;
>  
>       /*
>        * True if new LZMA properties are needed. This is false
>        * before the first LZMA chunk.
>        */
> -     bool_t need_props;
> +     bool need_props;
>  };
>  
>  struct xz_dec_lzma2 {
> @@ -306,7 +306,7 @@ static void __init dict_limit(struct dictionary *dict, 
> size_t out_max)
>  }
>  
>  /* Return true if at least one byte can be written into the dictionary. */
> -static inline bool_t __init dict_has_space(const struct dictionary *dict)
> +static inline bool __init dict_has_space(const struct dictionary *dict)
>  {
>       return dict->pos < dict->limit;
>  }
> @@ -343,7 +343,7 @@ static inline void __init dict_put(struct dictionary 
> *dict, uint8_t byte)
>   * invalid, false is returned. On success, true is returned and *len is
>   * updated to indicate how many bytes were left to be repeated.
>   */
> -static bool_t __init dict_repeat(struct dictionary *dict, uint32_t *len, 
> uint32_t dist)
> +static bool __init dict_repeat(struct dictionary *dict, uint32_t *len, 
> uint32_t dist)
>  {
>       size_t back;
>       uint32_t left;
> @@ -463,7 +463,7 @@ static void __init rc_reset(struct rc_dec *rc)
>   * Read the first five initial bytes into rc->code if they haven't been
>   * read already. (Yes, the first byte gets completely ignored.)
>   */
> -static bool_t __init rc_read_init(struct rc_dec *rc, struct xz_buf *b)
> +static bool __init rc_read_init(struct rc_dec *rc, struct xz_buf *b)
>  {
>       while (rc->init_bytes_left > 0) {
>               if (b->in_pos == b->in_size)
> @@ -477,7 +477,7 @@ static bool_t __init rc_read_init(struct rc_dec *rc, 
> struct xz_buf *b)
>  }
>  
>  /* Return true if there may not be enough input for the next decoding loop. 
> */
> -static inline bool_t __init rc_limit_exceeded(const struct rc_dec *rc)
> +static inline bool __init rc_limit_exceeded(const struct rc_dec *rc)
>  {
>       return rc->in_pos > rc->in_limit;
>  }
> @@ -486,7 +486,7 @@ static inline bool_t __init rc_limit_exceeded(const 
> struct rc_dec *rc)
>   * Return true if it is possible (from point of view of range decoder) that
>   * we have reached the end of the LZMA chunk.
>   */
> -static inline bool_t __init rc_is_finished(const struct rc_dec *rc)
> +static inline bool __init rc_is_finished(const struct rc_dec *rc)
>  {
>       return rc->code == 0;
>  }
> @@ -736,7 +736,7 @@ static void __init lzma_rep_match(struct xz_dec_lzma2 *s, 
> uint32_t pos_state)
>  }
>  
>  /* LZMA decoder core */
> -static bool_t __init lzma_main(struct xz_dec_lzma2 *s)
> +static bool __init lzma_main(struct xz_dec_lzma2 *s)
>  {
>       uint32_t pos_state;
>  
> @@ -814,7 +814,7 @@ static void __init lzma_reset(struct xz_dec_lzma2 *s)
>   * from the decoded lp and pb values. On success, the LZMA decoder state is
>   * reset and true is returned.
>   */
> -static bool_t __init lzma_props(struct xz_dec_lzma2 *s, uint8_t props)
> +static bool __init lzma_props(struct xz_dec_lzma2 *s, uint8_t props)
>  {
>       if (props > (4 * 5 + 4) * 9 + 8)
>               return false;
> @@ -861,7 +861,7 @@ static bool_t __init lzma_props(struct xz_dec_lzma2 *s, 
> uint8_t props)
>   * function. We decode a few bytes from the temporary buffer so that we can
>   * continue decoding from the caller-supplied input buffer again.
>   */
> -static bool_t __init lzma2_lzma(struct xz_dec_lzma2 *s, struct xz_buf *b)
> +static bool __init lzma2_lzma(struct xz_dec_lzma2 *s, struct xz_buf *b)
>  {
>       size_t in_avail;
>       uint32_t tmp;
> diff --git a/xen/common/xz/dec_stream.c b/xen/common/xz/dec_stream.c
> index b91d8362c19c..caea4f2596a1 100644
> --- a/xen/common/xz/dec_stream.c
> +++ b/xen/common/xz/dec_stream.c
> @@ -55,7 +55,7 @@ struct xz_dec {
>        * True if the next call to xz_dec_run() is allowed to return
>        * XZ_BUF_ERROR.
>        */
> -     bool_t allow_buf_error;
> +     bool allow_buf_error;
>  
>       /* Information stored in Block Header */
>       struct {
> @@ -132,7 +132,7 @@ struct xz_dec {
>  
>  #ifdef XZ_DEC_BCJ
>       struct xz_dec_bcj *bcj;
> -     bool_t bcj_active;
> +     bool bcj_active;
>  #endif
>  };
>  
> @@ -154,7 +154,7 @@ static const uint8_t check_sizes[16] = {
>   * to copy into s->temp.buf. Return true once s->temp.pos has reached
>   * s->temp.size.
>   */
> -static bool_t __init fill_temp(struct xz_dec *s, struct xz_buf *b)
> +static bool __init fill_temp(struct xz_dec *s, struct xz_buf *b)
>  {
>       size_t copy_size = min_t(size_t,
>                       b->in_size - b->in_pos, s->temp.size - s->temp.pos);
> @@ -367,7 +367,7 @@ static enum xz_ret __init crc32_validate(struct xz_dec 
> *s, struct xz_buf *b)
>   * Skip over the Check field when the Check ID is not supported.
>   * Returns true once the whole Check field has been skipped over.
>   */
> -static bool_t __init check_skip(struct xz_dec *s, struct xz_buf *b)
> +static bool __init check_skip(struct xz_dec *s, struct xz_buf *b)
>  {
>       while (s->pos < check_sizes[s->check_type]) {
>               if (b->in_pos == b->in_size)
> diff --git a/xen/common/xz/lzma2.h b/xen/common/xz/lzma2.h
> index e0ef42e880a0..06a7edb4d720 100644
> --- a/xen/common/xz/lzma2.h
> +++ b/xen/common/xz/lzma2.h
> @@ -90,7 +90,7 @@ static inline void __init lzma_state_short_rep(enum 
> lzma_state *state)
>  }
>  
>  /* Test if the previous symbol was a literal. */
> -static inline bool_t __init lzma_state_is_literal(enum lzma_state state)
> +static inline bool __init lzma_state_is_literal(enum lzma_state state)
>  {
>       return state < LIT_STATES;
>  }
> diff --git a/xen/common/xz/private.h b/xen/common/xz/private.h
> index 511343fcc234..e6814250e84f 100644
> --- a/xen/common/xz/private.h
> +++ b/xen/common/xz/private.h
> @@ -237,7 +237,7 @@ XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s);
>   * Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before
>   * calling xz_dec_bcj_run().
>   */
> -XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool_t single_call);
> +XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call);
>  
>  /*
>   * Decode the Filter ID of a BCJ filter. This implementation doesn't
> -- 
> 2.30.2
> 

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.