[前][次][番号順一覧][スレッド一覧]

ruby-changes:39166

From: nobu <ko1@a...>
Date: Wed, 15 Jul 2015 08:59:43 +0900 (JST)
Subject: [ruby-changes:39166] nobu:r51247 (trunk): gc.h: evaluate the macro argument only once

nobu	2015-07-15 08:59:23 +0900 (Wed, 15 Jul 2015)

  New Revision: 51247

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51247

  Log:
    gc.h: evaluate the macro argument only once
    
    * gc.h (RUBY_MARK_UNLESS_NULL): evaluate the argument only once
      to get rid of inadvertent side effects.

  Modified files:
    trunk/ChangeLog
    trunk/gc.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51246)
+++ ChangeLog	(revision 51247)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul 15 08:59:19 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* gc.h (RUBY_MARK_UNLESS_NULL): evaluate the argument only once
+	  to get rid of inadvertent side effects.
+
 Wed Jul 15 02:53:11 2015  Koichi Sasada  <ko1@a...>
 
 	* vm_core.h, vm.c: remove rb_proc_t::envval because we can know it via
Index: gc.h
===================================================================
--- gc.h	(revision 51246)
+++ gc.h	(revision 51247)
@@ -57,7 +57,10 @@ rb_gc_debug_body(const char *mode, const https://github.com/ruby/ruby/blob/trunk/gc.h#L57
 #define RUBY_GC_INFO if(0)printf
 #endif
 
-#define RUBY_MARK_UNLESS_NULL(ptr) if(RTEST(ptr)){rb_gc_mark(ptr);}
+#define RUBY_MARK_UNLESS_NULL(ptr) do { \
+    VALUE markobj = (ptr); \
+    if (RTEST(markobj)) {rb_gc_mark(markobj);} \
+} while (0)
 #define RUBY_FREE_UNLESS_NULL(ptr) if(ptr){ruby_xfree(ptr);(ptr)=NULL;}
 
 #if STACK_GROW_DIRECTION > 0

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]