Skip to content
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

Fix Ruby 3.4-dev compatibility #95

Merged
merged 1 commit into from
Mar 6, 2024
Merged
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: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
ruby: ["3.2", "3.1", "3.0", "2.7", "2.6"]
ruby: ["ruby-head", "3.3", "3.2", "3.1", "3.0", "2.7", "2.6"]
runs-on: ubuntu-latest
steps:
- name: Check out code
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- Fix Ruby 3.4-dev compatibility.

# 0.11.0

- Drop invalid response headers.
Expand Down
5 changes: 2 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PATH
GEM
remote: https://rubygems.org/
specs:
minitest (5.15.0)
minitest (5.22.2)
nio4r (2.7.0)
puma (6.4.2)
nio4r (~> 2.0)
Expand All @@ -20,8 +20,7 @@ GEM

PLATFORMS
aarch64-linux
arm64-darwin-21
arm64-darwin-22
arm64-darwin
x86_64-linux

DEPENDENCIES
Expand Down
22 changes: 15 additions & 7 deletions ext/pitchfork_http/epollexclusive.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
# define USE_EPOLL (0)
#endif

#ifndef HAVE_RB_IO_DESCRIPTOR /* Ruby < 3.1 */
static int rb_io_descriptor(VALUE io)
{
rb_io_t *fptr;
GetOpenFile(io, fptr);
rb_io_check_closed(fptr);
return fptr->fd;
}
#endif

#if USE_EPOLL
/*
* :nodoc:
Expand Down Expand Up @@ -54,8 +64,7 @@ static VALUE prep_readers(VALUE cls, VALUE readers)
*/
e.events = EPOLLEXCLUSIVE | EPOLLIN;
io = rb_io_get_io(io);
GetOpenFile(io, fptr);
rc = epoll_ctl(epfd, EPOLL_CTL_ADD, fptr->fd, &e);
rc = epoll_ctl(epfd, EPOLL_CTL_ADD, rb_io_descriptor(io), &e);
if (rc < 0) rb_sys_fail("epoll_ctl");
}
return epio;
Expand All @@ -65,7 +74,7 @@ static VALUE prep_readers(VALUE cls, VALUE readers)
#if USE_EPOLL
struct ep_wait {
struct epoll_event event;
rb_io_t *fptr;
VALUE io;
int timeout_msec;
};

Expand All @@ -79,7 +88,7 @@ static void *do_wait(void *ptr) /* runs w/o GVL */
* at-a-time (c.f. fs/eventpoll.c in linux.git, it's quite
* easy-to-understand for anybody familiar with Ruby C).
*/
return (void *)(long)epoll_wait(epw->fptr->fd, &epw->event, 1,
return (void *)(long)epoll_wait(rb_io_descriptor(epw->io), &epw->event, 1,
epw->timeout_msec);
}

Expand All @@ -93,11 +102,10 @@ get_readers(VALUE epio, VALUE ready, VALUE readers, VALUE timeout_msec)

Check_Type(ready, T_ARRAY);
Check_Type(readers, T_ARRAY);
epio = rb_io_get_io(epio);
GetOpenFile(epio, epw.fptr);

epw.io = rb_io_get_io(epio);
epw.timeout_msec = NUM2INT(timeout_msec);
n = (long)rb_thread_call_without_gvl(do_wait, &epw, RUBY_UBF_IO, NULL);
RB_GC_GUARD(epw.io);
if (n < 0) {
if (errno != EINTR) rb_sys_fail("epoll_wait");
} else if (n > 0) { /* maxevents is hardcoded to 1 */
Expand Down
2 changes: 2 additions & 0 deletions ext/pitchfork_http/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

have_const("PR_SET_CHILD_SUBREAPER", "sys/prctl.h")
have_func("rb_enc_interned_str", "ruby.h") # Ruby 3.0+
have_func("rb_io_descriptor", "ruby.h") # Ruby 3.1+

if RUBY_VERSION.start_with?('3.0.')
# https://bugs.ruby-lang.org/issues/18772
$CFLAGS << ' -DRB_ENC_INTERNED_STR_NULL_CHECK=1 '
Expand Down
Loading