summaryrefslogtreecommitdiff
path: root/ext/etc
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2021-11-11 18:20:09 +0900
committernagachika <nagachika@ruby-lang.org>2021-11-22 10:51:35 +0900
commit8cdb0ebb55ec88ea909b98d3c89e30debedc33b6 (patch)
treedfcb6d40f3d3b91c810122b7ed2e32e5f64d330e /ext/etc
parentbfed3296ec81c2ca53e65dc3df5b0e8f1e6810ab (diff)
Bump etc version to 1.3.0
Diffstat (limited to 'ext/etc')
-rw-r--r--ext/etc/etc.c32
-rw-r--r--ext/etc/extconf.rb5
2 files changed, 24 insertions, 13 deletions
diff --git a/ext/etc/etc.c b/ext/etc/etc.c
index 477423c9ed..737d295abc 100644
--- a/ext/etc/etc.c
+++ b/ext/etc/etc.c
@@ -52,7 +52,7 @@ char *getenv();
#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);
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
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
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)
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)
*/
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)
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 b6ae7700da..6e7810a5e8 100644
--- a/ext/etc/extconf.rb
+++ b/ext/etc/extconf.rb
@@ -47,10 +47,7 @@ if !File.exist?("#{srcdir}/depend")
%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"