diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-02-12 02:22:31 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-02-12 02:26:24 +0100 |
commit | 303680ebcd5adaac2934b63a0edc2d9d1a36d7fb (patch) | |
tree | bd2012dc6fa56f7259dbe2e5edd7ab3042f8e0a0 /lib/common | |
parent | ec7a522a520017327dd73b4d8e3787016ee1a31e (diff) |
Implement a more explicit object system
Make every dynamically allocated, opaque data structure inherit from
a common sqfs_object_t structure with common entry points (e.g. destroy).
This removes tons of public API functions and replaces them with a
simple sqfs_destroy instead. If semantics of the (until now implicit)
object system need to be extended, it can be much more conveniantely
done this way.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/common')
-rw-r--r-- | lib/common/comp_lzo.c | 4 | ||||
-rw-r--r-- | lib/common/io_stdin.c | 4 | ||||
-rw-r--r-- | lib/common/writer.c | 42 |
3 files changed, 25 insertions, 25 deletions
diff --git a/lib/common/comp_lzo.c b/lib/common/comp_lzo.c index f371fb6..a0c838a 100644 --- a/lib/common/comp_lzo.c +++ b/lib/common/comp_lzo.c @@ -195,7 +195,7 @@ static sqfs_compressor_t *lzo_create_copy(sqfs_compressor_t *cmp) return (sqfs_compressor_t *)lzo; } -static void lzo_destroy(sqfs_compressor_t *base) +static void lzo_destroy(sqfs_object_t *base) { free(base); } @@ -247,11 +247,11 @@ sqfs_compressor_t *lzo_compressor_create(const sqfs_compressor_config_t *cfg) lzo->buf_size = scratch_size; lzo->work_size = lzo_algs[cfg->opt.lzo.algorithm].bufsize; - base->destroy = lzo_destroy; base->do_block = (cfg->flags & SQFS_COMP_FLAG_UNCOMPRESS) ? lzo_uncomp_block : lzo_comp_block; base->write_options = lzo_write_options; base->read_options = lzo_read_options; base->create_copy = lzo_create_copy; + ((sqfs_object_t *)base)->destroy = lzo_destroy; return base; } diff --git a/lib/common/io_stdin.c b/lib/common/io_stdin.c index ca6bf49..469e300 100644 --- a/lib/common/io_stdin.c +++ b/lib/common/io_stdin.c @@ -21,7 +21,7 @@ typedef struct { } sqfs_file_stdinout_t; -static void stdinout_destroy(sqfs_file_t *base) +static void stdinout_destroy(sqfs_object_t *base) { free(base); } @@ -159,7 +159,7 @@ sqfs_file_t *sqfs_get_stdin_file(FILE *fp, const sparse_map_t *map, file->map = map; file->fp = fp; - base->destroy = stdinout_destroy; + ((sqfs_object_t *)base)->destroy = stdinout_destroy; base->write_at = stdin_write_at; base->get_size = stdinout_get_size; base->truncate = stdinout_truncate; diff --git a/lib/common/writer.c b/lib/common/writer.c index 84a40d2..4762b82 100644 --- a/lib/common/writer.c +++ b/lib/common/writer.c @@ -90,7 +90,7 @@ int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg) #ifdef WITH_LZO if (cfg.id == SQFS_COMP_LZO) { if (sqfs->cmp != NULL) - sqfs->cmp->destroy(sqfs->cmp); + sqfs_destroy(sqfs->cmp); sqfs->cmp = lzo_compressor_create(&cfg); } @@ -187,26 +187,26 @@ int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg) return 0; fail_dm: - sqfs_meta_writer_destroy(sqfs->dm); + sqfs_destroy(sqfs->dm); fail_im: - sqfs_meta_writer_destroy(sqfs->im); + sqfs_destroy(sqfs->im); fail_xwr: if (sqfs->xwr != NULL) - sqfs_xattr_writer_destroy(sqfs->xwr); + sqfs_destroy(sqfs->xwr); fail_id: - sqfs_id_table_destroy(sqfs->idtbl); + sqfs_destroy(sqfs->idtbl); fail_data: - sqfs_block_processor_destroy(sqfs->data); + sqfs_destroy(sqfs->data); fail_fragtbl: - sqfs_frag_table_destroy(sqfs->fragtbl); + sqfs_destroy(sqfs->fragtbl); fail_blkwr: - sqfs_block_writer_destroy(sqfs->blkwr); + sqfs_destroy(sqfs->blkwr); fail_cmp: - sqfs->cmp->destroy(sqfs->cmp); + sqfs_destroy(sqfs->cmp); fail_fs: fstree_cleanup(&sqfs->fs); fail_file: - sqfs->outfile->destroy(sqfs->outfile); + sqfs_destroy(sqfs->outfile); return -1; } @@ -299,16 +299,16 @@ int sqfs_writer_finish(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *cfg) void sqfs_writer_cleanup(sqfs_writer_t *sqfs) { if (sqfs->xwr != NULL) - sqfs_xattr_writer_destroy(sqfs->xwr); - - sqfs_dir_writer_destroy(sqfs->dirwr); - sqfs_meta_writer_destroy(sqfs->dm); - sqfs_meta_writer_destroy(sqfs->im); - sqfs_id_table_destroy(sqfs->idtbl); - sqfs_block_processor_destroy(sqfs->data); - sqfs_block_writer_destroy(sqfs->blkwr); - sqfs_frag_table_destroy(sqfs->fragtbl); - sqfs->cmp->destroy(sqfs->cmp); + sqfs_destroy(sqfs->xwr); + + sqfs_destroy(sqfs->dirwr); + sqfs_destroy(sqfs->dm); + sqfs_destroy(sqfs->im); + sqfs_destroy(sqfs->idtbl); + sqfs_destroy(sqfs->data); + sqfs_destroy(sqfs->blkwr); + sqfs_destroy(sqfs->fragtbl); + sqfs_destroy(sqfs->cmp); fstree_cleanup(&sqfs->fs); - sqfs->outfile->destroy(sqfs->outfile); + sqfs_destroy(sqfs->outfile); } |