[vlc-devel] [PATCH 02/15] input: attachment: Add a private structure
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Tue Nov 10 18:40:12 CET 2020
which will hold the refcount in the next commit
---
src/input/attachment.c | 38 +++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/src/input/attachment.c b/src/input/attachment.c
index 1f9f2faf45..0b4bb99ab9 100644
--- a/src/input/attachment.c
+++ b/src/input/attachment.c
@@ -25,16 +25,28 @@
#include <vlc_common.h>
#include <vlc_input.h>
+struct input_attachment_priv
+{
+ input_attachment_t a;
+};
+
+static struct input_attachment_priv* input_attachment_priv( input_attachment_t* a )
+{
+ return container_of( a, struct input_attachment_priv, a );
+}
+
void vlc_input_attachment_Delete( input_attachment_t *a )
{
if( !a )
return;
+ struct input_attachment_priv* p = input_attachment_priv( a );
+
free( a->p_data );
free( a->psz_description );
free( a->psz_mime );
free( a->psz_name );
- free( a );
+ free( p );
}
input_attachment_t *vlc_input_attachment_New( const char *psz_name,
@@ -43,25 +55,25 @@ input_attachment_t *vlc_input_attachment_New( const char *psz_name,
const void *p_data,
size_t i_data )
{
- input_attachment_t *a = (input_attachment_t *)malloc( sizeof (*a) );
+ struct input_attachment_priv *a = (struct input_attachment_priv *)malloc( sizeof (*a) );
if( unlikely(a == NULL) )
return NULL;
- a->psz_name = strdup( psz_name ? psz_name : "" );
- a->psz_mime = strdup( psz_mime ? psz_mime : "" );
- a->psz_description = strdup( psz_description ? psz_description : "" );
- a->i_data = i_data;
- a->p_data = malloc( i_data );
- if( i_data > 0 && likely(a->p_data != NULL) )
- memcpy( a->p_data, p_data, i_data );
+ a->a.psz_name = strdup( psz_name ? psz_name : "" );
+ a->a.psz_mime = strdup( psz_mime ? psz_mime : "" );
+ a->a.psz_description = strdup( psz_description ? psz_description : "" );
+ a->a.i_data = i_data;
+ a->a.p_data = malloc( i_data );
+ if( i_data > 0 && likely(a->a.p_data != NULL) )
+ memcpy( a->a.p_data, p_data, i_data );
- if( unlikely(a->psz_name == NULL || a->psz_mime == NULL
- || a->psz_description == NULL || (i_data > 0 && a->p_data == NULL)) )
+ if( unlikely(a->a.psz_name == NULL || a->a.psz_mime == NULL
+ || a->a.psz_description == NULL || (i_data > 0 && a->a.p_data == NULL)) )
{
- vlc_input_attachment_Delete( a );
+ vlc_input_attachment_Delete( &a->a );
a = NULL;
}
- return a;
+ return &a->a;
}
input_attachment_t *vlc_input_attachment_Duplicate( const input_attachment_t *a )
--
2.28.0
More information about the vlc-devel
mailing list