lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] [PATCH] Avoid dangling else problem


From: Rishi Khan
Subject: Re: [lwip-users] [PATCH] Avoid dangling else problem
Date: Thu, 9 Apr 2009 07:15:40 -0400

Roy,
I think you need to drop the semicolons after the while(0). If I write this:
if (blah) TCP_EVENT_ERR(errf,arg,err);
else blah2;

it will expand to:
if (blah) do { \
    if((errf))                                                 \
    (errf)((arg),(err));                                     \
  } while (0);;
else blah2;

Notice the double semicolon.

Rishi

On Apr 9, 2009, at 6:35 AM, Roy Lee wrote:

---
src/include/lwip/tcp.h | 63 +++++++++++++++++++++++++++++++ +---------------
 1 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h
index e9e82fb..8f6c2b9 100644
--- a/src/include/lwip/tcp.h
+++ b/src/include/lwip/tcp.h
@@ -467,26 +467,49 @@ err_t lwip_tcp_event(void *arg, struct tcp_pcb *pcb,
 #define TCP_EVENT_ERR(errf,arg,err)  lwip_tcp_event((arg), NULL, \
                 LWIP_EVENT_ERR, NULL, 0, (err))
 #else /* LWIP_EVENT_API */
-#define TCP_EVENT_ACCEPT(pcb,err,ret)     \
-                        if((pcb)->accept != NULL) \
- (ret = (pcb)->accept((pcb)->callback_arg, (pcb),(err)))
-#define TCP_EVENT_SENT(pcb,space,ret) \
-                        if((pcb)->sent != NULL) \
- (ret = (pcb)->sent((pcb)->callback_arg, (pcb),(space)))
-#define TCP_EVENT_RECV(pcb,p,err,ret) \
-                        if((pcb)->recv != NULL) \
- { ret = (pcb)->recv((pcb)->callback_arg, (pcb),(p),(err)); } else { \
-                          ret = ERR_OK; \
-                          if (p) pbuf_free(p); }
-#define TCP_EVENT_CONNECTED(pcb,err,ret) \
-                        if((pcb)->connected != NULL) \
- (ret = (pcb)->connected((pcb)- >callback_arg,(pcb),(err)))
-#define TCP_EVENT_POLL(pcb,ret) \
-                        if((pcb)->poll != NULL) \
- (ret = (pcb)->poll((pcb)->callback_arg, (pcb)))
-#define TCP_EVENT_ERR(errf,arg,err) \
-                        if((errf) != NULL) \
-                        (errf)((arg),(err))
+
+#define TCP_EVENT_ACCEPT(pcb,err,ret)                          \
+  do {                                                         \
+    if((pcb)->accept)                                          \
+      ret = (pcb)->accept((pcb)->callback_arg,(pcb),(err));    \
+  } while (0);
+
+#define TCP_EVENT_SENT(pcb,space,ret)                          \
+  do {                                                         \
+    if((pcb)->sent)                                            \
+      ret = (pcb)->sent((pcb)->callback_arg,(pcb),(space));    \
+  } while (0);
+
+#define TCP_EVENT_RECV(pcb,p,err,ret)                          \
+  do {                                                         \
+    if((pcb)->recv) {                                          \
+      ret = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err));  \
+    }                                                          \
+    else {                                                     \
+      ret = ERR_OK;                                            \
+      if (p)                                                   \
+            pbuf_free(p);                                      \
+    }                                                          \
+  } while (0);
+
+#define TCP_EVENT_CONNECTED(pcb,err,ret)                       \
+  do {                                                         \
+    if((pcb)->connected)                                       \
+      ret = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \
+  } while (0);
+
+#define TCP_EVENT_POLL(pcb,ret)                                \
+  do {                                                         \
+    if((pcb)->poll)                                            \
+      ret = (pcb)->poll((pcb)->callback_arg,(pcb));            \
+  } while (0);
+
+#define TCP_EVENT_ERR(errf,arg,err)                            \
+  do {                                                         \
+    if((errf))                                                 \
+      (errf)((arg),(err));                                     \
+  } while (0);
+
 #endif /* LWIP_EVENT_API */

/* This structure represents a TCP segment on the unsent and unacked queues */
--
1.6.2



_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users






reply via email to

[Prev in Thread] Current Thread [Next in Thread]