From 12879a4c3b71a9d566a20a73a72430ca44b17e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Duraffort?= Date: Sun, 2 Nov 2008 12:40:43 +0100 Subject: [PATCH] Remove MALLOC_(VOID|ERR). (and use calloc instead of malloc+memset) --- include/vlc_access.h | 30 +++++++++++++++--------------- include/vlc_common.h | 4 ---- include/vlc_demux.h | 3 ++- modules/control/hotkeys.c | 4 +++- modules/demux/playlist/gvp.c | 4 +++- modules/misc/notify/msn.c | 4 +++- modules/misc/notify/telepathy.c | 4 +++- 7 files changed, 29 insertions(+), 24 deletions(-) diff --git a/include/vlc_access.h b/include/vlc_access.h index 821c01c8c9..32b7592700 100644 --- a/include/vlc_access.h +++ b/include/vlc_access.h @@ -149,22 +149,22 @@ static inline void access_InitFields( access_t *p_a ) p_a->info.i_seekpoint = 0; } -#define ACCESS_SET_CALLBACKS( read, block, control, seek ) \ - p_access->pf_read = read; \ - p_access->pf_block = block; \ - p_access->pf_control = control; \ - p_access->pf_seek = seek; \ +#define ACCESS_SET_CALLBACKS( read, block, control, seek ) \ + p_access->pf_read = read; \ + p_access->pf_block = block; \ + p_access->pf_control = control; \ + p_access->pf_seek = seek; -#define STANDARD_READ_ACCESS_INIT \ - access_InitFields( p_access ); \ - ACCESS_SET_CALLBACKS( Read, NULL, Control, Seek ); \ - MALLOC_ERR( p_access->p_sys, access_sys_t ); \ - p_sys = p_access->p_sys; memset( p_sys, 0, sizeof( access_sys_t ) ); +#define STANDARD_READ_ACCESS_INIT \ + access_InitFields( p_access ); \ + ACCESS_SET_CALLBACKS( Read, NULL, Control, Seek ); \ + p_sys = p_access->p_sys = calloc( 1, sizeof( access_sys_t )); \ + if( !p_sys ) return VLC_ENOMEM; -#define STANDARD_BLOCK_ACCESS_INIT \ - access_InitFields( p_access ); \ - ACCESS_SET_CALLBACKS( NULL, Block, Control, Seek ); \ - MALLOC_ERR( p_access->p_sys, access_sys_t ); \ - p_sys = p_access->p_sys; memset( p_sys, 0, sizeof( access_sys_t ) ); +#define STANDARD_BLOCK_ACCESS_INIT \ + access_InitFields( p_access ); \ + ACCESS_SET_CALLBACKS( NULL, Block, Control, Seek ); \ + p_sys = p_access->p_sys = calloc( 1, sizeof( access_sys_t ) ); \ + if( !p_sys ) return VLC_ENOMEM; #endif diff --git a/include/vlc_common.h b/include/vlc_common.h index 27d594d465..a637bad3c4 100644 --- a/include/vlc_common.h +++ b/include/vlc_common.h @@ -604,12 +604,8 @@ static inline uint8_t clip_uint8_vlc( int32_t a ) } /* Malloc with automatic error */ -#define MALLOC_VOID( var, type ) do { var = (type*)malloc( sizeof( type) ); \ - if( !var ) return; } while(0) #define MALLOC_NULL( var, type ) do { var = (type*)malloc( sizeof( type) ); \ if( !var ) return NULL; } while(0) -#define MALLOC_ERR( var, type ) do { var = (type*)malloc( sizeof( type) ); \ - if( !var ) return VLC_ENOMEM; } while(0) #define FREENULL(a) do { free( a ); a = NULL; } while(0) diff --git a/include/vlc_demux.h b/include/vlc_demux.h index 6af44af48c..487efea45a 100644 --- a/include/vlc_demux.h +++ b/include/vlc_demux.h @@ -192,7 +192,8 @@ VLC_EXPORT( void, demux_PacketizerDestroy, ( decoder_t *p_packetizer ) ); #define DEMUX_INIT_COMMON() do { \ p_demux->pf_control = Control; \ p_demux->pf_demux = Demux; \ - MALLOC_ERR( p_demux->p_sys, demux_sys_t ); \ + p_demux->p_sys = malloc( sizeof( demux_sys_t ) ); \ + if( !p_demux->p_sys ) return VLC_ENOMEM;\ memset( p_demux->p_sys, 0, sizeof( demux_sys_t ) ); } while(0) #define STANDARD_DEMUX_INIT_MSG( msg ) do { \ diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c index 73b0e71827..aaa6014197 100644 --- a/modules/control/hotkeys.c +++ b/modules/control/hotkeys.c @@ -109,7 +109,9 @@ static int Open( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_sys_t *p_sys; - MALLOC_ERR( p_sys, intf_sys_t ); + p_sys = malloc( sizeof( intf_sys_t ) ); + if( !p_sys ) + return VLC_ENOMEM; p_intf->p_sys = p_sys; p_intf->pf_run = Run; diff --git a/modules/demux/playlist/gvp.c b/modules/demux/playlist/gvp.c index 19d6d3702b..e66b95fc4a 100644 --- a/modules/demux/playlist/gvp.c +++ b/modules/demux/playlist/gvp.c @@ -96,7 +96,9 @@ int Import_GVP( vlc_object_t *p_this ) STANDARD_DEMUX_INIT_MSG( "using Google Video Playlist (gvp) import" ); p_demux->pf_control = Control; p_demux->pf_demux = Demux; - MALLOC_ERR( p_demux->p_sys, demux_sys_t ); + p_demux->p_sys = malloc( sizeof( demux_sys_t ) ); + if( !p_demux->p_sys ) + return VLC_ENOMEM; return VLC_SUCCESS; } diff --git a/modules/misc/notify/msn.c b/modules/misc/notify/msn.c index a609cb452a..1629ca8924 100644 --- a/modules/misc/notify/msn.c +++ b/modules/misc/notify/msn.c @@ -89,7 +89,9 @@ static int Open( vlc_object_t *p_this ) intf_thread_t *p_intf = (intf_thread_t *)p_this; playlist_t *p_playlist; - MALLOC_ERR( p_intf->p_sys, intf_sys_t ); + p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); + if( !p_intf->p_sys ) + return VLC_ENOMEM; p_intf->p_sys->psz_format = config_GetPsz( p_intf, "msn-format" ); if( !p_intf->p_sys->psz_format ) diff --git a/modules/misc/notify/telepathy.c b/modules/misc/notify/telepathy.c index 32b9e80802..886b3f2a8f 100644 --- a/modules/misc/notify/telepathy.c +++ b/modules/misc/notify/telepathy.c @@ -97,7 +97,9 @@ static int Open( vlc_object_t *p_this ) DBusConnection *p_conn; DBusError error; - MALLOC_ERR( p_intf->p_sys, intf_sys_t ); + p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); + if( !p_intf->p_sys ) + return VLC_ENOMEM; /* connect to the session bus */ dbus_error_init( &error );