[vlc-commits] Improve access initialization macro safety

Rémi Denis-Courmont git at videolan.org
Thu Sep 1 20:17:46 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Sep  1 21:14:20 2011 +0300| [6a51c0a21a0d9724db9718e621fd5e7d466cdea5] | committer: Rémi Denis-Courmont

Improve access initialization macro safety

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6a51c0a21a0d9724db9718e621fd5e7d466cdea5
---

 include/vlc_access.h |   40 +++++++++++++++++++++++-----------------
 1 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/include/vlc_access.h b/include/vlc_access.h
index f9475a8..04a30b0 100644
--- a/include/vlc_access.h
+++ b/include/vlc_access.h
@@ -153,23 +153,29 @@ static inline void access_InitFields( access_t *p_a )
  */
 VLC_API input_thread_t * access_GetParentInput( access_t *p_access ) VLC_USED;
 
-#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 );                  \
-    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 );                 \
-    p_sys = p_access->p_sys = calloc( 1, sizeof( access_sys_t ) );      \
-    if( !p_sys ) return VLC_ENOMEM;
+#define ACCESS_SET_CALLBACKS( read, block, control, seek ) \
+    do { \
+        p_access->pf_read = (read); \
+        p_access->pf_block = (block); \
+        p_access->pf_control = (control); \
+        p_access->pf_seek = (seek); \
+    } while(0)
+
+#define STANDARD_READ_ACCESS_INIT \
+    do { \
+        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;\
+    } while(0);
+
+#define STANDARD_BLOCK_ACCESS_INIT \
+    do { \
+        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; \
+    } while(0);
 
 /**
  * @}



More information about the vlc-commits mailing list