ruby-changes:31443
From: nobu <ko1@a...>
Date: Mon, 4 Nov 2013 10:08:27 +0900 (JST)
Subject: [ruby-changes:31443] nobu:r43522 (trunk): eval_intern.h: avoid undefined behavior of setjmp
nobu 2013-11-04 10:08:21 +0900 (Mon, 04 Nov 2013) New Revision: 43522 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43522 Log: eval_intern.h: avoid undefined behavior of setjmp * eval_intern.h (TH_EXEC_TAG, TH_JUMP_TAG): get rid of undefined behavior of setjmp() in rhs of assignment expression. [ISO/IEC 9899:1999] 7.13.1.1 Modified files: trunk/ChangeLog trunk/eval_intern.h Index: eval_intern.h =================================================================== --- eval_intern.h (revision 43521) +++ eval_intern.h (revision 43522) @@ -108,14 +108,33 @@ extern int select_large_fdset(int, fd_se https://github.com/ruby/ruby/blob/trunk/eval_intern.h#L108 #define PUSH_TAG() TH_PUSH_TAG(GET_THREAD()) #define POP_TAG() TH_POP_TAG() -#define TH_EXEC_TAG() ruby_setjmp(_th->tag->buf) +/* clear th->state, and return the value */ +static inline int +ruby_threadptr_tag_state(rb_thread_t *th) +{ + int state = th->state; + th->state = 0; + return state; +} + +NORETURN(static inline void ruby_threadptr_tag_jump(rb_thread_t *, int)); +static inline void +ruby_threadptr_tag_jump(rb_thread_t *th, int st) +{ + ruby_longjmp(th->tag->buf, (th->state = st)); +} + +/* + setjmp() in assignment expression rhs is undefined behavior + [ISO/IEC 9899:1999] 7.13.1.1 +*/ +#define TH_EXEC_TAG() \ + (ruby_setjmp(_th->tag->buf) ? ruby_threadptr_tag_state(_th) : 0) #define EXEC_TAG() \ TH_EXEC_TAG() -#define TH_JUMP_TAG(th, st) do { \ - ruby_longjmp((th)->tag->buf,(st)); \ -} while (0) +#define TH_JUMP_TAG(th, st) ruby_threadptr_tag_jump(th, st) #define JUMP_TAG(st) TH_JUMP_TAG(GET_THREAD(), (st)) Index: ChangeLog =================================================================== --- ChangeLog (revision 43521) +++ ChangeLog (revision 43522) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Nov 4 10:08:17 2013 Nobuyoshi Nakada <nobu@r...> + + * eval_intern.h (TH_EXEC_TAG, TH_JUMP_TAG): get rid of undefined + behavior of setjmp() in rhs of assignment expression. + [ISO/IEC 9899:1999] 7.13.1.1 + Sun Nov 3 23:06:51 2013 Tanaka Akira <akr@f...> * sample/test.rb: Make temporary file names unique. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/