ruby-changes:69851
From: Hiroshi <ko1@a...>
Date: Mon, 22 Nov 2021 10:52:04 +0900 (JST)
Subject: [ruby-changes:69851] 8cdb0ebb55 (ruby_3_0): Bump etc version to 1.3.0
https://git.ruby-lang.org/ruby.git/commit/?id=8cdb0ebb55 From 8cdb0ebb55ec88ea909b98d3c89e30debedc33b6 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA <hsbt@r...> Date: Thu, 11 Nov 2021 18:20:09 +0900 Subject: Bump etc version to 1.3.0 --- ext/etc/etc.c | 32 +++++++++++++++++++++++--------- ext/etc/extconf.rb | 5 +---- test/etc/test_etc.rb | 1 + 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/ext/etc/etc.c b/ext/etc/etc.c index 477423c9eda..737d295abc6 100644 --- a/ext/etc/etc.c +++ b/ext/etc/etc.c @@ -52,7 +52,7 @@ char *getenv(); https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L52 #endif char *getlogin(); -#define RUBY_ETC_VERSION "1.2.0" +#define RUBY_ETC_VERSION "1.3.0" #ifdef HAVE_RB_DEPRECATE_CONSTANT void rb_deprecate_constant(VALUE mod, const char *name); @@ -68,6 +68,15 @@ void rb_deprecate_constant(VALUE mod, const char *name); https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L68 typedef int rb_atomic_t; # define RUBY_ATOMIC_CAS(var, oldval, newval) \ ((var) == (oldval) ? ((var) = (newval), (oldval)) : (var)) +# define RUBY_ATOMIC_EXCHANGE(var, newval) \ + atomic_exchange(&var, newval) +static inline rb_atomic_t +atomic_exchange(volatile rb_atomic_t *var, rb_atomic_t newval) +{ + rb_atomic_t oldval = *var; + *var = newval; + return oldval; +} #endif /* call-seq: @@ -253,7 +262,9 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L262 passwd_ensure(VALUE _) { endpwent(); - passwd_blocking = 0; + if (RUBY_ATOMIC_EXCHANGE(passwd_blocking, 0) != 1) { + rb_raise(rb_eRuntimeError, "unexpected passwd_blocking"); + } return Qnil; } @@ -495,7 +506,9 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L506 group_ensure(VALUE _) { endgrent(); - group_blocking = 0; + if (RUBY_ATOMIC_EXCHANGE(group_blocking, 0) != 1) { + rb_raise(rb_eRuntimeError, "unexpected group_blocking"); + } return Qnil; } @@ -944,11 +957,13 @@ io_pathconf(VALUE io, VALUE arg) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L957 static int etc_nprocessors_affin(void) { - cpu_set_t *cpuset; + cpu_set_t *cpuset, cpuset_buff[1024 / sizeof(cpu_set_t)]; size_t size; int ret; int n; + CPU_ZERO_S(sizeof(cpuset_buff), cpuset_buff); + /* * XXX: * man page says CPU_ALLOC takes number of cpus. But it is not accurate @@ -967,13 +982,12 @@ etc_nprocessors_affin(void) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L982 */ for (n=64; n <= 16384; n *= 2) { size = CPU_ALLOC_SIZE(n); - if (size >= 1024) { + if (size >= sizeof(cpuset_buff)) { cpuset = xcalloc(1, size); if (!cpuset) return -1; } else { - cpuset = alloca(size); - CPU_ZERO_S(size, cpuset); + cpuset = cpuset_buff; } ret = sched_getaffinity(0, size, cpuset); @@ -982,10 +996,10 @@ etc_nprocessors_affin(void) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L996 ret = CPU_COUNT_S(size, cpuset); } - if (size >= 1024) { + if (size >= sizeof(cpuset_buff)) { xfree(cpuset); } - if (ret > 0) { + if (ret > 0 || errno != EINVAL) { return ret; } } diff --git a/ext/etc/extconf.rb b/ext/etc/extconf.rb index b6ae7700dab..6e7810a5e87 100644 --- a/ext/etc/extconf.rb +++ b/ext/etc/extconf.rb @@ -47,10 +47,7 @@ if !File.exist?("#{srcdir}/depend") https://github.com/ruby/ruby/blob/trunk/ext/etc/extconf.rb#L47 %x[#{RbConfig.ruby} #{srcdir}/mkconstants.rb -o #{srcdir}/constdefs.h] end -decl = [ - "void rb_deprecate_constant(VALUE, const char *);", -] -have_func('rb_deprecate_constant(Qnil, "None")', [decl]) +have_func('rb_deprecate_constant(Qnil, "None")') $distcleanfiles << "constdefs.h" diff --git a/test/etc/test_etc.rb b/test/etc/test_etc.rb index dc224d0d322..2eddcf49d73 100644 --- a/test/etc/test_etc.rb +++ b/test/etc/test_etc.rb @@ -171,6 +171,7 @@ class TestEtc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/etc/test_etc.rb#L171 def test_ractor return unless Etc.passwd # => skip test if no platform support + Etc.endpwent assert_ractor(<<~RUBY, require: 'etc') ractor = Ractor.new do -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/