diff options
author | Indu Bhagat <indu.bhagat@oracle.com> | 2023-06-05 14:16:02 -0700 |
---|---|---|
committer | Indu Bhagat <indu.bhagat@oracle.com> | 2023-06-05 14:17:15 -0700 |
commit | 1466e49f7de4642859f2bf5e31d9a22b845b7797 (patch) | |
tree | 422f4ab05c86dbe68dcabd0fba275756a8c4e692 /libsframe | |
parent | 3c5e824b9cee93a987a77906240c509add260a0d (diff) | |
download | fsf-binutils-gdb-1466e49f7de4642859f2bf5e31d9a22b845b7797.zip fsf-binutils-gdb-1466e49f7de4642859f2bf5e31d9a22b845b7797.tar.gz fsf-binutils-gdb-1466e49f7de4642859f2bf5e31d9a22b845b7797.tar.bz2 |
libsframe: avoid unnecessary type casts
Change the data type of some of the members of the sframe_decoder_ctx
and sframe_encoder_ctx data structures to use the applicable data types
explicitly. Current implementation in libsframe does type casts, which
seem unnecessary.
libsframe/
* libsframe/sframe-impl.h (struct sframe_decoder_ctx): Use
applicable data type explicitly.
(struct sframe_encoder_ctx): Likewise. Use same style of
comments consistently.
* libsframe/sframe.c (struct sf_fde_tbl): Define without
typedef.
(struct sf_fre_tbl): Likewise.
(sframe_decode): Remove unnecessary type casts.
(sframe_encoder_get_funcdesc_at_index): Likewise.
(sframe_encoder_add_fre): Likewise.
(sframe_encoder_add_funcdesc): Likewise.
(sframe_sort_funcdesc): Likewise.
(sframe_encoder_write_sframe): Likewise.
Diffstat (limited to 'libsframe')
-rw-r--r-- | libsframe/sframe-impl.h | 25 | ||||
-rw-r--r-- | libsframe/sframe.c | 34 |
2 files changed, 34 insertions, 25 deletions
diff --git a/libsframe/sframe-impl.h b/libsframe/sframe-impl.h index b179680..06b4a89 100644 --- a/libsframe/sframe-impl.h +++ b/libsframe/sframe-impl.h @@ -35,9 +35,9 @@ struct sframe_decoder_ctx /* SFrame header. */ sframe_header sfd_header; /* SFrame function desc entries table. */ - uint32_t *sfd_funcdesc; + sframe_func_desc_entry *sfd_funcdesc; /* SFrame FRE table. */ - void *sfd_fres; + char *sfd_fres; /* Number of bytes needed for SFrame FREs. */ int sfd_fre_nbytes; /* Reference to the internally malloc'd buffer, if any, for endian flipping @@ -45,14 +45,23 @@ struct sframe_decoder_ctx void *sfd_buf; }; +typedef struct sf_fde_tbl sf_fde_tbl; +typedef struct sf_fre_tbl sf_fre_tbl; + struct sframe_encoder_ctx { - sframe_header sfe_header; /* SFrame header. */ - uint32_t *sfe_funcdesc; /* SFrame function desc entries table. */ - sframe_frame_row_entry *sfe_fres; /* SFrame FRE table. */ - uint32_t sfe_fre_nbytes; /* Number of bytes needed for SFrame FREs. */ - char *sfe_data; /* SFrame data buffer. */ - size_t sfe_data_size; /* Size of the SFrame data buffer. */ + /* SFrame header. */ + sframe_header sfe_header; + /* SFrame function desc entries table. */ + sf_fde_tbl *sfe_funcdesc; + /* SFrame FRE table. */ + sf_fre_tbl *sfe_fres; + /* Number of bytes needed for SFrame FREs. */ + uint32_t sfe_fre_nbytes; + /* SFrame output data buffer. */ + char *sfe_data; + /* Size of the SFrame output data buffer. */ + size_t sfe_data_size; }; #ifdef __cplusplus diff --git a/libsframe/sframe.c b/libsframe/sframe.c index a97c64f..b05fed9 100644 --- a/libsframe/sframe.c +++ b/libsframe/sframe.c @@ -25,19 +25,19 @@ #include "sframe-impl.h" #include "swap.h" -typedef struct sf_funidx_tbl +struct sf_fde_tbl { unsigned int count; unsigned int alloced; sframe_func_desc_entry entry[1]; -} sf_funidx_tbl; +}; -typedef struct sf_fre_tbl +struct sf_fre_tbl { unsigned int count; unsigned int alloced; sframe_frame_row_entry entry[1]; -} sf_fre_tbl; +}; #define _sf_printflike_(string_index,first_to_check) \ __attribute__ ((__format__ (__printf__, (string_index), (first_to_check)))) @@ -867,7 +867,7 @@ sframe_decode (const char *sf_buf, size_t sf_size, int *errp) frame_buf += (fidx_size); /* Handle the SFrame Frame Row Entry section. */ - dctx->sfd_fres = malloc (sfheaderp->sfh_fre_len); + dctx->sfd_fres = (char *) malloc (sfheaderp->sfh_fre_len); if (dctx->sfd_fres == NULL) { sframe_ret_set_errno (errp, SFRAME_ERR_NOMEM); @@ -1217,7 +1217,7 @@ sframe_encoder_get_funcdesc_at_index (sframe_encoder_ctx *encoder, sframe_func_desc_entry *fde = NULL; if (func_idx < sframe_encoder_get_num_fidx (encoder)) { - sf_funidx_tbl *func_tbl = (sf_funidx_tbl *) encoder->sfe_funcdesc; + sf_fde_tbl *func_tbl = encoder->sfe_funcdesc; fde = func_tbl->entry + func_idx; } return fde; @@ -1351,7 +1351,7 @@ sframe_encoder_add_fre (sframe_encoder_ctx *encoder, return sframe_set_errno (&err, SFRAME_ERR_FDE_NOTFOUND); fre_type = sframe_get_fre_type (fdep); - sf_fre_tbl *fre_tbl = (sf_fre_tbl *) encoder->sfe_fres; + sf_fre_tbl *fre_tbl = encoder->sfe_fres; if (fre_tbl == NULL) { @@ -1402,7 +1402,7 @@ sframe_encoder_add_fre (sframe_encoder_ctx *encoder, esz = sframe_fre_entry_size (frep, fre_type); fre_tbl->count++; - encoder->sfe_fres = (void *) fre_tbl; + encoder->sfe_fres = fre_tbl; encoder->sfe_fre_nbytes += esz; ehp = sframe_encoder_get_header (encoder); @@ -1432,7 +1432,7 @@ sframe_encoder_add_funcdesc (sframe_encoder_ctx *encoder, uint32_t num_fres __attribute__ ((unused))) { sframe_header *ehp; - sf_funidx_tbl *fd_info; + sf_fde_tbl *fd_info; size_t fd_tbl_sz; int err = 0; @@ -1440,12 +1440,12 @@ sframe_encoder_add_funcdesc (sframe_encoder_ctx *encoder, if (encoder == NULL) return sframe_set_errno (&err, SFRAME_ERR_INVAL); - fd_info = (sf_funidx_tbl *) encoder->sfe_funcdesc; + fd_info = encoder->sfe_funcdesc; ehp = sframe_encoder_get_header (encoder); if (fd_info == NULL) { - fd_tbl_sz = (sizeof (sf_funidx_tbl) + fd_tbl_sz = (sizeof (sf_fde_tbl) + (number_of_entries * sizeof (sframe_func_desc_entry))); fd_info = malloc (fd_tbl_sz); if (fd_info == NULL) @@ -1458,7 +1458,7 @@ sframe_encoder_add_funcdesc (sframe_encoder_ctx *encoder, } else if (fd_info->count == fd_info->alloced) { - fd_tbl_sz = (sizeof (sf_funidx_tbl) + fd_tbl_sz = (sizeof (sf_fde_tbl) + ((fd_info->alloced + number_of_entries) * sizeof (sframe_func_desc_entry))); fd_info = realloc (fd_info, fd_tbl_sz); @@ -1488,7 +1488,7 @@ sframe_encoder_add_funcdesc (sframe_encoder_ctx *encoder, #endif fd_info->entry[fd_info->count].sfde_func_info = func_info; fd_info->count++; - encoder->sfe_funcdesc = (void *) fd_info; + encoder->sfe_funcdesc = fd_info; ehp->sfh_num_fdes++; return 0; @@ -1507,7 +1507,7 @@ sframe_sort_funcdesc (sframe_encoder_ctx *encoder) ehp = sframe_encoder_get_header (encoder); /* Sort and write out the FDE table. */ - sf_funidx_tbl *fd_info = (sf_funidx_tbl *) encoder->sfe_funcdesc; + sf_fde_tbl *fd_info = encoder->sfe_funcdesc; if (fd_info) { qsort (fd_info->entry, fd_info->count, @@ -1613,7 +1613,7 @@ sframe_encoder_write_sframe (sframe_encoder_ctx *encoder) size_t esz = 0; sframe_header *ehp; unsigned char flags; - sf_funidx_tbl *fd_info; + sf_fde_tbl *fd_info; sf_fre_tbl *fr_info; uint32_t i, num_fdes; uint32_t j, num_fres; @@ -1630,8 +1630,8 @@ sframe_encoder_write_sframe (sframe_encoder_ctx *encoder) ehp = sframe_encoder_get_header (encoder); hdr_size = sframe_get_hdr_size (ehp); - fd_info = (sf_funidx_tbl *) encoder->sfe_funcdesc; - fr_info = (sf_fre_tbl *) encoder->sfe_fres; + fd_info = encoder->sfe_funcdesc; + fr_info = encoder->sfe_fres; /* Sanity checks: - buffers must be malloc'd by the caller. */ |