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/sqfs/data_reader.c | |
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/sqfs/data_reader.c')
-rw-r--r-- | lib/sqfs/data_reader.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/sqfs/data_reader.c b/lib/sqfs/data_reader.c index c8886c5..8c9bb2e 100644 --- a/lib/sqfs/data_reader.c +++ b/lib/sqfs/data_reader.c @@ -21,6 +21,8 @@ #include <string.h> struct sqfs_data_reader_t { + sqfs_object_t obj; + sqfs_frag_table_t *frag_tbl; sqfs_compressor_t *cmp; sqfs_file_t *file; @@ -125,6 +127,16 @@ static int precache_fragment_block(sqfs_data_reader_t *data, size_t idx) &data->frag_blk_size, &data->frag_block); } +static void data_reader_destroy(sqfs_object_t *obj) +{ + sqfs_data_reader_t *data = (sqfs_data_reader_t *)obj; + + sqfs_destroy(data->frag_tbl); + free(data->data_block); + free(data->frag_block); + free(data); +} + sqfs_data_reader_t *sqfs_data_reader_create(sqfs_file_t *file, size_t block_size, sqfs_compressor_t *cmp) @@ -140,6 +152,7 @@ sqfs_data_reader_t *sqfs_data_reader_create(sqfs_file_t *file, return NULL; } + ((sqfs_object_t *)data)->destroy = data_reader_destroy; data->file = file; data->block_size = block_size; data->cmp = cmp; @@ -164,14 +177,6 @@ int sqfs_data_reader_load_fragment_table(sqfs_data_reader_t *data, return 0; } -void sqfs_data_reader_destroy(sqfs_data_reader_t *data) -{ - sqfs_frag_table_destroy(data->frag_tbl); - free(data->data_block); - free(data->frag_block); - free(data); -} - int sqfs_data_reader_get_block(sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, size_t index, size_t *size, sqfs_u8 **out) |