This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA/JVMTI] New JVMTI Environment Initialization/Allocation


Andrew Haley wrote:

These macros are dangerous because of hidden dangling else:

How's this?


Keith

ChangeLog
2006-09-01  Keith Seitz  <keiths@redhat.com>

* jvmti.cc (THREAD_DEFAULT_TO_CURRENT): Encapsulate in do..while loop.
(THREAD_CHECK_VALID): Likewise.
(THREAD_CHECK_IS_ALIVE): Likewise.
(NULL_CHECK): Likewise.
(ILLEGAL_ARGUMENT): Likewise.


Index: jvmti.cc
===================================================================
--- jvmti.cc	(revision 116635)
+++ jvmti.cc	(working copy)
@@ -56,25 +56,49 @@
 
 // Some commonly-used checks
 
-#define THREAD_DEFAULT_TO_CURRENT(jthread)				\
-  if (jthread == NULL) jthread = java::lang::Thread::currentThread ();
+#define THREAD_DEFAULT_TO_CURRENT(jthread)		\
+  do							\
+    {							\
+      if (jthread == NULL)				\
+	jthread = java::lang::Thread::currentThread ();	\
+    }							\
+  while (0)
 
 #define THREAD_CHECK_VALID(jthread)					\
-  if (!java::lang::Thread::class$.isAssignableFrom (&(jthread->class$))) \
-    return JVMTI_ERROR_INVALID_THREAD;
+  do									\
+    {									\
+      if (!java::lang::Thread::class$.isAssignableFrom (&(jthread->class$))) \
+	return JVMTI_ERROR_INVALID_THREAD;				\
+    }									\
+  while (0)
 
-#define THREAD_CHECK_IS_ALIVE(thread)				\
-  if (!thread->isAlive ()) return JVMTI_ERROR_THREAD_NOT_ALIVE;
+#define THREAD_CHECK_IS_ALIVE(thread)	     \
+  do					     \
+    {					     \
+      if (!thread->isAlive ())		     \
+	return JVMTI_ERROR_THREAD_NOT_ALIVE; \
+    }					     \
+  while (0)
 
 // FIXME: if current phase is not set in Phases,
 // return JVMTI_ERROR_WRONG_PHASE
 #define REQUIRE_PHASE(Env, Phases)
 
-#define NULL_CHECK(Ptr)					\
-  if (Ptr == NULL) return JVMTI_ERROR_NULL_POINTER;
+#define NULL_CHECK(Ptr)				\
+  do						\
+    {						\
+      if (Ptr == NULL)				\
+	return JVMTI_ERROR_NULL_POINTER;	\
+    }						\
+  while (0)
 
-#define ILLEGAL_ARGUMENT(Cond)				\
-  if ((Cond)) return JVMTI_ERROR_ILLEGAL_ARGUMENT
+#define ILLEGAL_ARGUMENT(Cond)			\
+  do						\
+    {						\
+      if ((Cond))				\
+	return JVMTI_ERROR_ILLEGAL_ARGUMENT;	\
+    }						\
+  while (0)
 
 static jvmtiError JNICALL
 _Jv_JVMTI_SuspendThread (MAYBE_UNUSED jvmtiEnv *env, jthread thread)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]