From f2bf5d585e4e9e0d3e7fb2ac3b64bc08818041b3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Thu, 16 Aug 2007 15:43:28 +0000 Subject: [PATCH] Prepare to privatize some members of VLC_COMMON_MEMBERS --- include/vlc_common.h | 3 +++ src/libvlc.h | 11 +++++++++++ src/misc/objects.c | 23 ++++++++++++++--------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/include/vlc_common.h b/include/vlc_common.h index 8ef6ff2dd7..93759eec44 100644 --- a/include/vlc_common.h +++ b/include/vlc_common.h @@ -525,6 +525,8 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's object */ #include "vlc_threads.h" +typedef struct vlc_object_internals_t vlc_object_internals_t; + /***************************************************************************** * Common structure members *****************************************************************************/ @@ -535,6 +537,7 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's object */ * these members are common for all vlc objects \ */ \ /**@{*/ \ + vlc_object_internals_t *p_internals; \ int i_object_id; \ int i_object_type; \ const char *psz_object_type; \ diff --git a/src/libvlc.h b/src/libvlc.h index 1019056c52..9aedae50f2 100644 --- a/src/libvlc.h +++ b/src/libvlc.h @@ -83,4 +83,15 @@ static inline libvlc_global_data_t *__vlc_global( vlc_object_t *p_this ) extern uint32_t cpu_flags; uint32_t CPUCapabilities( void ); +/* Private LibVLC data for each objects */ +struct vlc_object_internals_t +{ + +}; + +static inline vlc_object_internals_t *vlc_internals( vlc_object_t *obj ) +{ + return obj->p_internals; +} + #endif diff --git a/src/misc/objects.c b/src/misc/objects.c index 0ba4961582..b33447d57a 100644 --- a/src/misc/objects.c +++ b/src/misc/objects.c @@ -88,23 +88,30 @@ static void ListChildren ( vlc_list_t *, vlc_object_t *, int ); * Local structure lock *****************************************************************************/ static vlc_mutex_t structure_lock; +static vlc_object_internals_t global_internals; vlc_object_t *vlc_custom_create( vlc_object_t *p_this, size_t i_size, int i_type, const char *psz_type ) { - vlc_object_t * p_new = NULL; + vlc_object_t *p_new; + vlc_object_internals_t *p_priv; if( i_type == VLC_OBJECT_GLOBAL ) { p_new = p_this; + p_priv = &global_internals; + memset( p_priv, 0, sizeof( *p_priv ) ); } else { - p_new = malloc( i_size ); - if( !p_new ) return NULL; - memset( p_new, 0, i_size ); + p_priv = calloc( 1, sizeof( *p_priv ) + i_size ); + if( p_priv == NULL ) + return NULL; + + p_new = (vlc_object_t *)(p_priv + 1); } + p_new->p_internals = p_priv; p_new->i_object_type = i_type; p_new->psz_object_type = psz_type; @@ -132,7 +139,7 @@ vlc_object_t *vlc_custom_create( vlc_object_t *p_this, size_t i_size, if( !p_new->p_vars ) { if( i_type != VLC_OBJECT_GLOBAL ) - free( p_new ); + free( p_priv ); return NULL; } @@ -336,6 +343,7 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type ) *****************************************************************************/ void __vlc_object_destroy( vlc_object_t *p_this ) { + vlc_object_internals_t *p_priv = vlc_internals( p_this ); int i_delay = 0; if( p_this->i_children ) @@ -426,10 +434,7 @@ void __vlc_object_destroy( vlc_object_t *p_this ) /* global is not dynamically allocated by vlc_object_create */ if( p_this->i_object_type != VLC_OBJECT_GLOBAL ) - { - free( p_this ); - p_this = NULL; - } + free( p_priv ); } -- 2.39.2