ruby-changes:57174
From: Nobuyoshi <ko1@a...>
Date: Mon, 19 Aug 2019 16:28:08 +0900 (JST)
Subject: [ruby-changes:57174] Nobuyoshi Nakada: 8108594f47 (master): unsigned int should have enough bits for rb_thread_shield_waiting
https://git.ruby-lang.org/ruby.git/commit/?id=8108594f47 From 8108594f4701b02bfb7b90b7c2585a8214d8e64d Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 19 Aug 2019 16:18:54 +0900 Subject: unsigned int should have enough bits for rb_thread_shield_waiting diff --git a/thread.c b/thread.c index 52304f7..db4326b 100644 --- a/thread.c +++ b/thread.c @@ -4708,16 +4708,22 @@ thread_shield_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/thread.c#L4708 } #define GetThreadShieldPtr(obj) ((VALUE)rb_check_typeddata((obj), &thread_shield_data_type)) -#define THREAD_SHIELD_WAITING_MASK (FL_USER0|FL_USER1|FL_USER2|FL_USER3|FL_USER4|FL_USER5|FL_USER6|FL_USER7|FL_USER8|FL_USER9|FL_USER10|FL_USER11|FL_USER12|FL_USER13|FL_USER14|FL_USER15|FL_USER16|FL_USER17|FL_USER18|FL_USER19) +#define THREAD_SHIELD_WAITING_MASK (((FL_USER19-1)&~(FL_USER0-1))|FL_USER19) #define THREAD_SHIELD_WAITING_SHIFT (FL_USHIFT) -#define rb_thread_shield_waiting(b) ((RBASIC(b)->flags&THREAD_SHIELD_WAITING_MASK)>>THREAD_SHIELD_WAITING_SHIFT) +#define THREAD_SHIELD_WAITING_MAX (THREAD_SHIELD_WAITING_MASK>>THREAD_SHIELD_WAITING_SHIFT) +STATIC_ASSERT(THREAD_SHIELD_WAITING_MAX, THREAD_SHIELD_WAITING_MAX <= UINT_MAX); +static inline unsigned int +rb_thread_shield_waiting(VALUE b) +{ + return ((RBASIC(b)->flags&THREAD_SHIELD_WAITING_MASK)>>THREAD_SHIELD_WAITING_SHIFT); +} static inline void rb_thread_shield_waiting_inc(VALUE b) { - unsigned long w = rb_thread_shield_waiting(b); + unsigned int w = rb_thread_shield_waiting(b); w++; - if (w > (THREAD_SHIELD_WAITING_MASK>>THREAD_SHIELD_WAITING_SHIFT)) + if (w > THREAD_SHIELD_WAITING_MAX) rb_raise(rb_eRuntimeError, "waiting count overflow"); RBASIC(b)->flags &= ~THREAD_SHIELD_WAITING_MASK; RBASIC(b)->flags |= ((VALUE)w << THREAD_SHIELD_WAITING_SHIFT); @@ -4726,7 +4732,7 @@ rb_thread_shield_waiting_inc(VALUE b) https://github.com/ruby/ruby/blob/trunk/thread.c#L4732 static inline void rb_thread_shield_waiting_dec(VALUE b) { - unsigned long w = rb_thread_shield_waiting(b); + unsigned int w = rb_thread_shield_waiting(b); if (!w) rb_raise(rb_eRuntimeError, "waiting count underflow"); w--; RBASIC(b)->flags &= ~THREAD_SHIELD_WAITING_MASK; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/