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

ruby-changes:33437

From: nobu <ko1@a...>
Date: Fri, 4 Apr 2014 17:34:18 +0900 (JST)
Subject: [ruby-changes:33437] nobu:r45516 (trunk): eval_intern.h: VAR_INITIALIZED

nobu	2014-04-04 17:34:12 +0900 (Fri, 04 Apr 2014)

  New Revision: 45516

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

  Log:
    eval_intern.h: VAR_INITIALIZED
    
    * eval_intern.h (VAR_INITIALIZED): macro to suppress
      maybe-uninitialized warnings by gcc 4.7 and 4.8.

  Modified files:
    trunk/cont.c
    trunk/eval_intern.h
    trunk/eval_jump.c
    trunk/proc.c
    trunk/vm_eval.c
Index: eval_intern.h
===================================================================
--- eval_intern.h	(revision 45515)
+++ eval_intern.h	(revision 45516)
@@ -128,6 +128,14 @@ extern int select_large_fdset(int, fd_se https://github.com/ruby/ruby/blob/trunk/eval_intern.h#L128
 #define PUSH_TAG() TH_PUSH_TAG(GET_THREAD())
 #define POP_TAG()      TH_POP_TAG()
 
+#if defined __GNUC__ && __GNUC__ == 4 && (__GNUC_MINOR__ == 7 || __GNUC_MINOR__ == 8)
+# define VAR_FROM_MEMORY(var) __extension__(*(__typeof__(var) volatile *)&(var))
+# define VAR_INITIALIZED(var) ((var) = VAR_FROM_MEMORY(var))
+#else
+# define VAR_FROM_MEMORY(var) (var)
+# define VAR_INITIALIZED(var) ((void)&(var))
+#endif
+
 /* clear th->state, and return the value */
 static inline int
 rb_threadptr_tag_state(rb_thread_t *th)
@@ -150,7 +158,7 @@ rb_threadptr_tag_jump(rb_thread_t *th, i https://github.com/ruby/ruby/blob/trunk/eval_intern.h#L158
   [ISO/IEC 9899:1999] 7.13.1.1
 */
 #define TH_EXEC_TAG() \
-    (ruby_setjmp(_tag.buf) ? rb_threadptr_tag_state(_th) : (TH_REPUSH_TAG(), 0))
+    (ruby_setjmp(_tag.buf) ? rb_threadptr_tag_state(VAR_FROM_MEMORY(_th)) : (TH_REPUSH_TAG(), 0))
 
 #define EXEC_TAG() \
   TH_EXEC_TAG()
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 45515)
+++ vm_eval.c	(revision 45516)
@@ -1060,6 +1060,8 @@ rb_iterate(VALUE (* it_proc) (VALUE), VA https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1060
     TH_PUSH_TAG(th);
     state = TH_EXEC_TAG();
     if (state == 0) {
+	VAR_INITIALIZED(th);
+	VAR_INITIALIZED(node);
       iter_retry:
 	{
 	    rb_block_t *blockptr;
Index: proc.c
===================================================================
--- proc.c	(revision 45515)
+++ proc.c	(revision 45516)
@@ -1899,6 +1899,7 @@ rb_method_call_with_block(int argc, VALU https://github.com/ruby/ruby/blob/trunk/proc.c#L1899
 	}
 
 	th->passed_block = block;
+	VAR_INITIALIZED(data);
 	result = rb_vm_call(th, data->recv, data->id,  argc, argv, data->me, data->defined_class);
     }
     POP_TAG();
Index: eval_jump.c
===================================================================
--- eval_jump.c	(revision 45515)
+++ eval_jump.c	(revision 45516)
@@ -123,6 +123,7 @@ rb_exec_end_proc(void) https://github.com/ruby/ruby/blob/trunk/eval_jump.c#L123
 	exec_end_procs_chain(&end_procs);
     }
     else {
+	VAR_INITIALIZED(th);
 	TH_TMPPOP_TAG();
 	error_handle(status);
 	if (!NIL_P(th->errinfo)) errinfo = th->errinfo;
Index: cont.c
===================================================================
--- cont.c	(revision 45515)
+++ cont.c	(revision 45516)
@@ -510,6 +510,7 @@ cont_capture(volatile int *stat) https://github.com/ruby/ruby/blob/trunk/cont.c#L510
     if (ruby_setjmp(cont->jmpbuf)) {
 	volatile VALUE value;
 
+	VAR_INITIALIZED(cont);
 	value = cont->value;
 	if (cont->argc == -1) rb_exc_raise(value);
 	cont->value = Qnil;
@@ -1271,15 +1272,14 @@ rb_fiber_start(void) https://github.com/ruby/ruby/blob/trunk/cont.c#L1272
 {
     rb_thread_t *th = GET_THREAD();
     rb_fiber_t *fib;
-    rb_context_t *cont;
     rb_proc_t *proc;
     int state;
 
     GetFiberPtr(th->fiber, fib);
-    cont = &fib->cont;
 
     TH_PUSH_TAG(th);
     if ((state = EXEC_TAG()) == 0) {
+	rb_context_t *cont = &VAR_FROM_MEMORY(fib)->cont;
 	int argc;
 	const VALUE *argv, args = cont->value;
 	GetProcPtr(cont->saved_thread.first_proc, proc);

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

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