Skip to content

Commit

Permalink
Fix Ruby 3.4-dev compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Mar 6, 2024
1 parent 2b739f4 commit 540ff69
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
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

0 comments on commit 540ff69

Please sign in to comment.