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 /include/sqfs/predef.h | |
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 'include/sqfs/predef.h')
-rw-r--r-- | include/sqfs/predef.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/include/sqfs/predef.h b/include/sqfs/predef.h index d8cc293..6ca3503 100644 --- a/include/sqfs/predef.h +++ b/include/sqfs/predef.h @@ -57,6 +57,12 @@ #endif #endif +#ifdef _MSC_VER + #define SQFS_INLINE __forceinline +#else + #define SQFS_INLINE __inline__ __attribute__((always_inline)) +#endif + typedef uint8_t sqfs_u8; typedef uint16_t sqfs_u16; typedef uint32_t sqfs_u32; @@ -108,4 +114,25 @@ typedef struct sqfs_xattr_value_t sqfs_xattr_value_t; typedef struct sqfs_xattr_id_t sqfs_xattr_id_t; typedef struct sqfs_xattr_id_table_t sqfs_xattr_id_table_t; +/** + * @interface sqfs_object_t + * + * @brief Base interface for all libsquashfs in-memory data structures. + */ +typedef struct sqfs_object_t { + void (*destroy)(struct sqfs_object_t *instance); +} sqfs_object_t; + +/** + * @brief Destroy an object and free all its memory + * + * @memberof sqfs_object_t + * + * @param obj A pointer to an object + */ +static SQFS_INLINE void sqfs_destroy(void *obj) +{ + ((sqfs_object_t *)obj)->destroy(obj); +} + #endif /* SQFS_PREDEF_H */ |