From: Eric Wong <normalperson@yhbt.net>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:60780] Re: volatile usages
Date: Sun, 16 Feb 2014 04:48:05 +0000 [thread overview]
Message-ID: <20140216044805.GA18028@dcvr.yhbt.net> (raw)
In-Reply-To: <20140215015300.GA24747@dcvr.yhbt.net>
Eric Wong <normalperson@yhbt.net> wrote:
> array.c: volatile in rb_ary_each along with the explanation in r32201 is
> scaring me :x If that volatile is needed, then it would also be
> necessary in similar functions such as rb_ary_each_with_index and
> rb_reverse_each. Of course, those functions do not use volatile and
> seem fine after all these years.
I suspect it is because rb_ary_each is in the public C API,
so a guard becomes necessary.
--- a/array.c
+++ b/array.c
@@ -1784,16 +1784,21 @@ ary_enum_length(VALUE ary, VALUE args, VALUE eobj)
*/
VALUE
-rb_ary_each(VALUE array)
+rb_ary_each(VALUE ary)
{
long i;
- volatile VALUE ary = array;
RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);
for (i=0; i<RARRAY_LEN(ary); i++) {
rb_yield(RARRAY_AREF(ary, i));
}
- return ary;
+
+ /*
+ * GC guard may be necessary if rb_ary_each is called like this:
+ * rb_ary_each(rb_ary_new());
+ * (ary argument is allocated inline and the return value ignored)
+ */
+ return RB_GC_GUARD(ary);
}
/*
prev parent reply other threads:[~2014-02-16 4:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-13 10:04 [ruby-core:60682] volatile usages Eric Wong
2014-02-14 2:40 ` [ruby-core:60688] " Nobuyoshi Nakada
2014-02-14 10:55 ` [ruby-core:60741] " Eric Wong
2014-02-15 1:53 ` [ruby-core:60751] " Eric Wong
2014-02-16 4:48 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140216044805.GA18028@dcvr.yhbt.net \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).