From: Eric Wong Date: 2015-08-10T18:37:12+00:00 Subject: [ruby-core:70317] Re: [ruby-cvs:58640] nobu:r51492 (trunk): node.c: NODE_ALLOCA for ALLOCV Nobuyoshi Nakada wrote: > On 2015/08/06 4:11, Eric Wong wrote: > > Besides possible backwards compatibility, can we drop volatile > > from rb_alloc_tmp_buffer and rb_free_tmp_buffer? volatile > > seems unnecessary since we call rb_free_tmp_buffer anyways. > > It doesn't force the buffer variable to be `volatile`, but just allow. Right, but many current use of volatile variables is wrong and other APIs (PRI*VALUE or RB_GC_GUARD) are better instead. Better to warn and avoid volatile instead of perpetuating it: diff --git a/array.c b/array.c index 27b6325..d08e2f5 100644 --- a/array.c +++ b/array.c @@ -4982,7 +4982,7 @@ rb_ary_permutation(int argc, VALUE *argv, VALUE ary) } } else { /* this is the general case */ - volatile VALUE t0; + VALUE t0; long *p = ALLOCV_N(long, t0, r+roomof(n, sizeof(long))); char *used = (char*)(p + r); VALUE ary0 = ary_make_shared_copy(ary); /* private defensive copy of ary */ @@ -5073,7 +5073,7 @@ rb_ary_combination(VALUE ary, VALUE num) } else { VALUE ary0 = ary_make_shared_copy(ary); /* private defensive copy of ary */ - volatile VALUE t0; + VALUE t0; long *stack = ALLOCV_N(long, t0, n+1); RBASIC_CLEAR_CLASS(ary0); @@ -5178,7 +5178,7 @@ rb_ary_repeated_permutation(VALUE ary, VALUE num) } } else { /* this is the general case */ - volatile VALUE t0; + VALUE t0; long *p = ALLOCV_N(long, t0, r * sizeof(long)); VALUE ary0 = ary_make_shared_copy(ary); /* private defensive copy of ary */ RBASIC_CLEAR_CLASS(ary0); @@ -5274,7 +5274,7 @@ rb_ary_repeated_combination(VALUE ary, VALUE num) /* yield nothing */ } else { - volatile VALUE t0; + VALUE t0; long *p = ALLOCV_N(long, t0, n); VALUE ary0 = ary_make_shared_copy(ary); /* private defensive copy of ary */ RBASIC_CLEAR_CLASS(ary0); diff --git a/gc.c b/gc.c index a3af6fe..44080ec 100644 --- a/gc.c +++ b/gc.c @@ -7767,7 +7767,7 @@ ruby_mimfree(void *ptr) } void * -rb_alloc_tmp_buffer(volatile VALUE *store, long len) +rb_alloc_tmp_buffer(VALUE *store, long len) { NODE *s; long cnt; @@ -7786,7 +7786,7 @@ rb_alloc_tmp_buffer(volatile VALUE *store, long len) } void -rb_free_tmp_buffer(volatile VALUE *store) +rb_free_tmp_buffer(VALUE *store) { VALUE s = ATOMIC_VALUE_EXCHANGE(*store, 0); if (s) { diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 01b3c2e..d853fca 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1429,8 +1429,8 @@ rb_num2char_inline(VALUE x) #define ALLOCA_N(type,n) ((type*)alloca(sizeof(type)*(n))) -void *rb_alloc_tmp_buffer(volatile VALUE *store, long len) RUBY_ATTR_ALLOC_SIZE((2)); -void rb_free_tmp_buffer(volatile VALUE *store); +void *rb_alloc_tmp_buffer(VALUE *store, long len) RUBY_ATTR_ALLOC_SIZE((2)); +void rb_free_tmp_buffer(VALUE *store); /* allocates _n_ bytes temporary buffer and stores VALUE including it * in _v_. _n_ may be evaluated twice. */ #ifdef C_ALLOCA -- EW