8000 backport 20172 by nurse · Pull Request #9796 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

backport 20172 #9796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ext/socket/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,6 @@ def %(s) s || self end

have_func("pthread_create")
have_func("pthread_detach")
have_func("pthread_attr_setaffinity_np")
have_func("sched_getcpu")

$VPATH << '$(topdir)' << '$(top_srcdir)'
create_makefile("socket")
Expand Down
38 changes: 4 additions & 34 deletions ext/socket/raddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,15 @@ cancel_getaddrinfo(void *ptr)
}

static int
do_pthread_create(pthread_t *th, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg)
do_pthread_create(pthread_t *th, void *(*start_routine) (void *), void *arg)
{
int limit = 3, ret;
do {
// It is said that pthread_create may fail spuriously, so we follow the JDK and retry several times.
//
// https://bugs.openjdk.org/browse/JDK-8268605
// https://github.com/openjdk/jdk/commit/e35005d5ce383ddd108096a3079b17cb0bcf76f1
ret = pthread_create(th, attr, start_routine, arg);
ret = pthread_create(th, 0, start_routine, arg);
} while (ret == EAGAIN && limit-- > 0);
return ret;
}
Expand All @@ -489,23 +489,8 @@ rb_getaddrinfo(const char *hostp, const char *portp, const struct addrinfo *hint
return EAI_MEMORY;
}

pthread_attr_t attr;
if (pthread_attr_init(&attr) != 0) {
free_getaddrinfo_arg(arg);
return EAI_AGAIN;
}
#if defined(HAVE_PTHREAD_ATTR_SETAFFINITY_NP) && defined(HAVE_SCHED_GETCPU)
cpu_set_t tmp_cpu_set;
CPU_ZERO(&tmp_cpu_set);
int cpu = sched_getcpu();
if (cpu < CPU_SETSIZE) {
CPU_SET(cpu, &tmp_cpu_set);
pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &tmp_cpu_set);
}
#endif

pthread_t th;
if (do_pthread_create(&th, &attr, do_getaddrinfo, arg) != 0) {
if (do_pthread_create(&th, do_getaddrinfo, arg) != 0) {
free_getaddrinfo_arg(arg);
return EAI_AGAIN;
}
Expand Down Expand Up @@ -716,23 +701,8 @@ rb_getnameinfo(const struct sockaddr *sa, socklen_t salen,
return EAI_MEMORY;
}

pthread_attr_t attr;
if (pthread_attr_init(&attr) != 0) {
free_getnameinfo_arg(arg);
return EAI_AGAIN;
}
#if defined(HAVE_PTHREAD_ATTR_SETAFFINITY_NP) && defined(HAVE_SCHED_GETCPU)
cpu_set_t tmp_cpu_set;
CPU_ZERO(&tmp_cpu_set);
int cpu = sched_getcpu();
if (cpu < CPU_SETSIZE) {
CPU_SET(cpu, &tmp_cpu_set);
pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &tmp_cpu_set);
}
#endif

pthread_t th;
if (do_pthread_create(&th, 0, do_getnameinfo, arg) != 0) {
if (do_pthread_create(&th, do_getnameinfo, arg) != 0) {
free_getnameinfo_arg(arg);
return EAI_AGAIN;
}
Expand Down
24 changes: 16 additions & 8 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -9749,10 +9749,6 @@ gc_enter_count(enum gc_enter_event event)
}
}

#ifndef MEASURE_GC
#define MEASURE_GC (objspace->flags.measure_gc)
#endif

static bool current_process_time(struct timespec *ts);

static void
Expand Down Expand Up @@ -9822,36 +9818,48 @@ gc_exit(rb_objspace_t *objspace, enum gc_enter_event event, unsigned int *lock_l
RB_VM_LOCK_LEAVE_LEV(lock_lev);
}

#ifndef MEASURE_GC
#define MEASURE_GC (objspace->flags.measure_gc)
#endif

static void
gc_marking_enter(rb_objspace_t *objspace)
{
GC_ASSERT(during_gc != 0);

gc_clock_start(&objspace->profile.marking_start_time);
if (MEASURE_GC) {
gc_clock_start(&objspace->profile.marking_start_time);
}
}

static void
gc_marking_exit(rb_objspace_t *objspace)
{
GC_ASSERT(during_gc != 0);

objspace->profile.marking_time_ns += gc_clock_end(&objspace->profile.marking_start_time);
if (MEASURE_GC) {
objspace->profile.marking_time_ns += gc_clock_end(&objspace->profile.marking_start_time);
}
}

static void
gc_sweeping_enter(rb_objspace_t *objspace)
{
GC_ASSERT(during_gc != 0);

gc_clock_start(&objspace->profile.sweeping_start_time);
if (MEASURE_GC) {
gc_clock_start(&objspace->profile.sweeping_start_time);
}
}

static void
gc_sweeping_exit(rb_objspace_t *objspace)
{
GC_ASSERT(during_gc != 0);

objspace->profile.sweeping_time_ns += gc_clock_end(&objspace->profile.sweeping_start_time);
if (MEASURE_GC) {
objspace->profile.sweeping_time_ns += gc_clock_end(&objspace->profile.sweeping_start_time);
}
}

static void *
Expand Down
6 changes: 3 additions & 3 deletions gems/bundled_gems
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ rake 13.1.0 https://github.com/ruby/rake
test-unit 3.6.1 https://github.com/test-unit/test-unit
rexml 3.2.6 https://github.com/ruby/rexml
rss 0.3.0 https://github.com/ruby/rss
net-ftp 0.3.3 https://github.com/ruby/net-ftp
net-imap 0.4.9 https://github.com/ruby/net-imap
net-ftp 0.3.4 https://github.com/ruby/net-ftp
net-imap 0.4.9.1 https://github.com/ruby/net-imap
net-pop 0.1.2 https://github.com/ruby/net-pop
net-smtp 0.4.0 https://github.com/ruby/net-smtp
net-smtp 0.4.0.1 https://github.com/ruby/net-smtp
matrix 0.4.2 https://github.com/ruby/matrix
prime 0.1.2 https://github.com/ruby/prime
rbs 3.4.0 https://github.com/ruby/rbs
Expand Down
10 changes: 9 additions & 1 deletion hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,15 @@ hash_copy(VALUE ret, VALUE hash)
static VALUE
hash_dup_with_compare_by_id(VALUE hash)
{
return hash_copy(copy_compare_by_id(rb_hash_new(), hash), hash);
VALUE dup = hash_alloc_flags(rb_cHash, 0, Qnil, RHASH_ST_TABLE_P(hash));
if (RHASH_ST_TABLE_P(hash)) {
RHASH_SET_ST_FLAG(dup);
}
else {
RHASH_UNSET_ST_FLAG(dup);
}

return hash_copy(dup, hash);
}

static VALUE
Expand Down
18 changes: 12 additions & 6 deletions io_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ enum {

// This is used to validate the flags given by the user.
RB_IO_BUFFER_FLAGS_MASK = RB_IO_BUFFER_EXTERNAL | RB_IO_BUFFER_INTERNAL | RB_IO_BUFFER_MAPPED | RB_IO_BUFFER_SHARED | RB_IO_BUFFER_LOCKED | RB_IO_BUFFER_PRIVATE | RB_IO_BUFFER_READONLY,

RB_IO_BUFFER_DEBUG = 0,
};

struct rb_io_buffer {
Expand Down Expand Up @@ -113,6 +115,7 @@ io_buffer_map_file(struct rb_io_buffer *buffer, int descriptor, size_t size, rb_
}

HANDLE mapping = CreateFileMapping(file, NULL, protect, 0, 0, NULL);
if (RB_IO_BUFFER_DEBUG) fprintf(stderr, "io_buffer_map_file:CreateFileMapping -> %p\n", mapping);
if (!mapping) rb_sys_fail("io_buffer_map_descriptor:CreateFileMapping");

void *base = MapViewOfFile(mapping, access, (DWORD)(offset >> 32), (DWORD)(offset & 0xFFFFFFFF), size);
Expand Down Expand Up @@ -213,9 +216,13 @@ io_buffer_initialize(VALUE self, struct rb_io_buffer *buffer, void *base, size_t
buffer->size = size;
buffer->flags = flags;
RB_OBJ_WRITE(self, &buffer->source, source);

#if defined(_WIN32)
buffer->mapping = NULL;
#endif
}

static int
static void
io_buffer_free(struct rb_io_buffer *buffer)
{
if (buffer->base) {
Expand Down Expand Up @@ -247,18 +254,17 @@ io_buffer_free(struct rb_io_buffer *buffer)
buffer->size = 0;
buffer->flags = 0;
buffer->source = Qnil;

return 1;
}

#if defined(_WIN32)
if (buffer->mapping) {
CloseHandle(buffer->mapping);
if (RB_IO_BUFFER_DEBUG) fprintf(stderr, "io_buffer_free:CloseHandle -> %p\n", buffer->mapping);
if (!CloseHandle(buffer->mapping)) {
fprintf(stderr, "io_buffer_free:GetLastError -> %d\n", GetLastError());
}
buffer->mapping = NULL;
}
#endif

return 0;
}

void
Expand Down
2 changes: 1 addition & 1 deletion lib/bundled_gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Gem::BUNDLED_GEMS
"net-pop" => "3.1.0",
"net-smtp" => "3.1.0",
"prime" => "3.1.0",
"racc" => "3.3.0",
"abbrev" => "3.4.0",
"base64" => "3.4.0",
"bigdecimal" => "3.4.0",
Expand All @@ -22,7 +23,6 @@ module Gem::BUNDLED_GEMS
"mutex_m" => "3.4.0",
"nkf" => "3.4.0",
"observer" => "3.4.0",
"racc" => "3.4.0",
"resolv-replace" => "3.4.0",
"rinda" => "3.4.0",
"syslog" => "3.4.0",
Expand Down
2 changes: 1 addition & 1 deletion lib/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ class HTTPHeaderSyntaxError < StandardError; end
class HTTP < Protocol

# :stopdoc:
VERSION = "0.4.0"
VERSION = "0.4.1"
HTTPVersion = '1.1'
begin
require 'zlib'
Expand Down
4 changes: 2 additions & 2 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -3800,9 +3800,9 @@ args : arg_value
| args ',' arg_splat
{
/*%%%*/
$$ = rest_arg_append(p, $args, $arg_splat, &@$);
$$ = rest_arg_append(p, $1, $3, &@$);
/*% %*/
/*% ripper: args_add_star!($args, $arg_splat) %*/
/*% ripper: args_add_star!($1, $3) %*/
}
;

Expand Down
9 changes: 6 additions & 3 deletions re.c
Original file line number Diff line number Diff line change
Expand Up @@ -1747,15 +1747,18 @@ rb_reg_search_set_match(VALUE re, VALUE str, long pos, int reverse, int set_back
.range = reverse ? 0 : len,
};

VALUE match = match_alloc(rb_cMatch);
struct re_registers *regs = RMATCH_REGS(match);
struct re_registers regs = {0};

OnigPosition result = rb_reg_onig_match(re, str, reg_onig_search, &args, regs);
OnigPosition result = rb_reg_onig_match(re, str, reg_onig_search, &args, &regs);
if (result == ONIG_MISMATCH) {
rb_backref_set(Qnil);
return ONIG_MISMATCH;
}

VALUE match = match_alloc(rb_cMatch);
rb_matchext_t *rm = RMATCH_EXT(match);
rm->regs = regs;

if (set_backref_str) {
RB_OBJ_WRITE(match, &RMATCH(match)->str, rb_str_new4(str));
}
Expand Down
5 changes: 3 additions & 2 deletions regexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ init_cache_opcodes(const regex_t* reg, OnigCacheOpcode* cache_opcodes, long* num
cache_opcodes->num_cache_points_at_outer_repeat = num_cache_points_at_repeat;\
cache_opcodes->num_cache_points_in_outer_repeat = 0;\
cache_opcodes->lookaround_nesting = lookaround_nesting;\
cache_point += lookaround_nesting > 0 ? 2 : 1;\
cache_point += lookaround_nesting != 0 ? 2 : 1;\
cache_opcodes++;\
} while (0)

Expand Down Expand Up @@ -3756,14 +3756,15 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,

CASE(OP_PUSH_IF_PEEK_NEXT) MOP_IN(OP_PUSH_IF_PEEK_NEXT);
GET_RELADDR_INC(addr, p);
CHECK_MATCH_CACHE;
if (*p == *s) {
p++;
CHECK_MATCH_CACHE;
STACK_PUSH_ALT(p + addr, s, sprev, pkeep);
MOP_OUT;
JUMP;
}
p++;
INC_NUM_FAILS;
MOP_OUT;
JUMP;

Expand Down
6 changes: 3 additions & 3 deletions test/net/fixtures/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ regen_certs:
make server.crt

cacert.pem: server.key
openssl req -new -x509 -days 1825 -key server.key -out cacert.pem -text -subj "/C=JP/ST=Shimane/L=Matz-e city/O=Ruby Core Team/CN=Ruby Test CA/emailAddress=security@ruby-lang.org"
openssl req -new -x509 -days 3650 -key server.key -out cacert.pem -subj "/C=JP/ST=Shimane/L=Matz-e city/O=Ruby Core Team/CN=Ruby Test CA/emailAddress=security@ruby-lang.org"

server.csr:
openssl req -new -key server.key -out server.csr -text -subj "/C=JP/ST=Shimane/O=Ruby Core Team/OU=Ruby Test/CN=localhost"
openssl req -new -key server.key -out server.csr -subj "/C=JP/ST=Shimane/O=Ruby Core Team/OU=Ruby Test/CN=localhost"

server.crt: server.csr cacert.pem
openssl x509 -days 1825 -CA cacert.pem -CAkey server.key -set_serial 00 -in server.csr -req -text -out server.crt
openssl x509 -days 3650 -CA cacert.pem -CAkey server.key -set_serial 00 -in server.csr -req -out server.crt
rm server.csr
44 changes: 22 additions & 22 deletions test/net/fixtures/cacert.pem
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
-----BEGIN CERTIFICATE-----
MIID7TCCAtWgAwIBAgIJAIltvxrFAuSnMA0GCSqGSIb3DQEBCwUAMIGMMQswCQYD
VQQGEwJKUDEQMA4GA1UECAwHU2hpbWFuZTEUMBIGA1UEBwwLTWF0ei1lIGNpdHkx
FzAVBgNVBAoMDlJ1YnkgQ29yZSBUZWFtMRUwEwYDVQQDDAxSdWJ5IFRlc3QgQ0Ex
JTAjBgkqhkiG9w0BCQEWFnNlY3VyaXR5QHJ1YnktbGFuZy5vcmcwHhcNMTkwMTAy
MDI1ODI4WhcNMjQwMTAxMDI1ODI4WjCBjDELMAkGA1UEBhMCSlAxEDAOBgNVBAgM
B1NoaW1hbmUxFDASBgNVBAcMC01hdHotZSBjaXR5MRcwFQYDVQQKDA5SdWJ5IENv
cmUgVGVhbTEVMBMGA1UEAwwMUnVieSBUZXN0IENBMSUwIwYJKoZIhvcNAQkBFhZz
ZWN1cml0eUBydWJ5LWxhbmcub3JnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
CgKCAQEAznlbjRVhz1NlutHVrhcGnK8W0qug2ujKXv1njSC4U6nJF6py7I9EeehV
SaKePyv+I9z3K1LnfUHOtUbdwdKC77yN66A6q2aqzu5q09/NSykcZGO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