[pulseaudio-discuss] [PATCH RFCv3 02/51] tagstruct: Replace dynamic flag with type
Peter Meerwald
pmeerw at pmeerw.net
Tue Nov 4 15:25:57 PST 2014
From: Peter Meerwald <p.meerwald at bct-electronic.com>
... in order to prepare for a new type _APPENDED
remove the assert() for dynamic in pa_tagstruct_data() as
the function makes sense for all tagstruct types (and the returned pointer
is const)
Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
src/pulsecore/tagstruct.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/pulsecore/tagstruct.c b/src/pulsecore/tagstruct.c
index c74a9ab..f737291 100644
--- a/src/pulsecore/tagstruct.c
+++ b/src/pulsecore/tagstruct.c
@@ -47,7 +47,10 @@ struct pa_tagstruct {
size_t length, allocated;
size_t rindex;
- bool dynamic;
+ enum {
+ PA_TAGSTRUCT_FIXED,
+ PA_TAGSTRUCT_DYNAMIC,
+ } type;
};
pa_tagstruct *pa_tagstruct_new(void) {
@@ -57,7 +60,7 @@ pa_tagstruct *pa_tagstruct_new(void) {
t->data = NULL;
t->allocated = t->length = 0;
t->rindex = 0;
- t->dynamic = true;
+ t->type = PA_TAGSTRUCT_DYNAMIC;
return t;
}
@@ -71,7 +74,7 @@ pa_tagstruct *pa_tagstruct_new_fixed(const uint8_t* data, size_t length) {
t->data = (uint8_t*) data;
t->allocated = t->length = length;
t->rindex = 0;
- t->dynamic = false;
+ t->type = PA_TAGSTRUCT_FIXED;
return t;
}
@@ -79,7 +82,7 @@ pa_tagstruct *pa_tagstruct_new_fixed(const uint8_t* data, size_t length) {
void pa_tagstruct_free(pa_tagstruct*t) {
pa_assert(t);
- if (t->dynamic)
+ if (t->type == PA_TAGSTRUCT_DYNAMIC)
pa_xfree(t->data);
pa_xfree(t);
}
@@ -88,7 +91,7 @@ uint8_t* pa_tagstruct_free_data(pa_tagstruct*t, size_t *l) {
uint8_t *p;
pa_assert(t);
- pa_assert(t->dynamic);
+ pa_assert(t->type == PA_TAGSTRUCT_DYNAMIC);
pa_assert(l);
p = t->data;
@@ -99,7 +102,7 @@ uint8_t* pa_tagstruct_free_data(pa_tagstruct*t, size_t *l) {
static void extend(pa_tagstruct*t, size_t l) {
pa_assert(t);
- pa_assert(t->dynamic);
+ pa_assert(t->type != PA_TAGSTRUCT_FIXED);
if (t->length+l <= t->allocated)
return;
@@ -434,7 +437,6 @@ int pa_tagstruct_eof(pa_tagstruct*t) {
const uint8_t* pa_tagstruct_data(pa_tagstruct*t, size_t *l) {
pa_assert(t);
- pa_assert(t->dynamic);
pa_assert(l);
*l = t->length;
--
1.9.1
More information about the pulseaudio-discuss
mailing list