gcc macro cleanup 07/5207/1
authorHanoh Haim <[email protected]>
Sun, 25 Dec 2016 09:25:02 +0000 (11:25 +0200)
committerHanoh Haim <[email protected]>
Sun, 25 Dec 2016 09:25:29 +0000 (11:25 +0200)
Signed-off-by: Hanoh Haim <[email protected]>
src/bp_sim.cpp
src/common/utl_gcc_diag.h [new file with mode: 0644]
src/gtest/bp_timer_gtest.cpp

index 72eb91b..68cc325 100755 (executable)
@@ -26,6 +26,7 @@ limitations under the License.
 #include "msg_manager.h"
 #include "trex_watchdog.h"
 #include "utl_ipg_bucket.h"
+#include <common/utl_gcc_diag.h>
 
 #include <common/basic_utils.h>
 
@@ -3791,16 +3792,6 @@ inline void CFlowGenListPerThread::on_flow_tick(CGenNode *node){
     }
 }
 
-#define GCC_DIAG_STR(s) #s
-#define GCC_DIAG_JOINSTR(x,y) GCC_DIAG_STR(x ## y)
-# define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
-# define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
-#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
-    GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
-#define GCC_DIAG_ON() GCC_DIAG_PRAGMA(pop)
-
-#define UNSAFE_CONTAINER_OF_PUSH GCC_DIAG_OFF(invalid-offsetof)
-#define UNSAFE_CONTAINER_OF_POP  GCC_DIAG_ON()
 
 
 static void tw_free_node(void *userdata,
diff --git a/src/common/utl_gcc_diag.h b/src/common/utl_gcc_diag.h
new file mode 100644 (file)
index 0000000..1bda919
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef UTL_GCC_DIAG_H
+#define UTL_GCC_DIAG_H
+
+/*
+ Hanoh Haim
+ Cisco Systems, Inc.
+*/
+
+/*
+Copyright (c) 2015-2015 Cisco Systems, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+
+#define GCC_DIAG_STR(s) #s
+#define GCC_DIAG_JOINSTR(x,y) GCC_DIAG_STR(x ## y)
+# define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
+# define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
+#define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
+    GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
+#define GCC_DIAG_ON() GCC_DIAG_PRAGMA(pop)
+
+#define UNSAFE_CONTAINER_OF_PUSH GCC_DIAG_OFF(invalid-offsetof)
+#define UNSAFE_CONTAINER_OF_POP  GCC_DIAG_ON()
+
+
+
+#endif
index 5185da8..07f0e21 100644 (file)
@@ -22,6 +22,8 @@ limitations under the License.
 #include <common/gtest.h>
 #include <common/basic_utils.h>
 #include "h_timer.h"
+#include <common/utl_gcc_diag.h>
+
 
 
 class gt_r_timer  : public testing::Test {
@@ -150,9 +152,9 @@ void my_test_on_tick_cb(void *userdata,CHTimerObj *tmr){
 
 
     CHTimerWheel * lp=(CHTimerWheel *)userdata;
-    #pragma GCC diagnostic ignored "-Winvalid-offsetof"
+    UNSAFE_CONTAINER_OF_PUSH
     CMyTestObject *lpobj=(CMyTestObject *)((uint8_t*)tmr-offsetof (CMyTestObject,m_timer));
-    #pragma GCC diagnostic pop
+    UNSAFE_CONTAINER_OF_POP
     printf(" [event %d ]",lpobj->m_id);
     lp->timer_start(tmr,2);
 }
@@ -182,9 +184,9 @@ void my_test_on_tick_cb7(void *userdata,CHTimerObj *tmr){
 
 
     CHTimerWheel * lp=(CHTimerWheel *)userdata;
-    #pragma GCC diagnostic ignored "-Winvalid-offsetof"
+    UNSAFE_CONTAINER_OF_PUSH
     CMyTestObject *lpobj=(CMyTestObject *)((uint8_t*)tmr-offsetof (CMyTestObject,m_timer));
-    #pragma GCC diagnostic pop
+    UNSAFE_CONTAINER_OF_POP
     printf(" [event %d ]",lpobj->m_id);
     lp->timer_start(tmr,9);
 }
@@ -193,9 +195,9 @@ void my_test_on_tick_cb_free(void *userdata,CHTimerObj *tmr){
 
 
     //CHTimerWheel * lp=(CHTimerWheel *)userdata;
-    #pragma GCC diagnostic ignored "-Winvalid-offsetof"
+    UNSAFE_CONTAINER_OF_PUSH
     CMyTestObject *lpobj=(CMyTestObject *)((uint8_t*)tmr-offsetof (CMyTestObject,m_timer));
-    #pragma GCC diagnostic pop
+    UNSAFE_CONTAINER_OF_POP
     printf(" [event %d ]",lpobj->m_id);
     delete lpobj;
 }
@@ -262,9 +264,9 @@ private:
 
 void my_test_on_tick_cb8(void *userdata,CHTimerObj *tmr){
     CHTimerWheelBase * lp=(CHTimerWheelBase *)userdata;
-    #pragma GCC diagnostic ignored "-Winvalid-offsetof"
+    UNSAFE_CONTAINER_OF_PUSH
     CMyTestObject *lpobj=(CMyTestObject *)((uint8_t*)tmr-offsetof (CMyTestObject,m_timer));
-    #pragma GCC diagnostic pop
+    UNSAFE_CONTAINER_OF_POP
     lp->on_tick(lpobj);
 }