Skip to content

Commit

Permalink
Fix compat to ruby < 3.0
Browse files Browse the repository at this point in the history
Older rubies require the use of the rb_io_t structure for wait functions.
But older rb_io_wait_* functions are soft-deprecated, since they have to re-wrap the IO objects for the scheduler.
Moreover they don't fully support nonblocking behavior on Windows.
  • Loading branch information
larskanis committed Sep 7, 2021
1 parent c2d9d0b commit ea99287
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ module PG
have_func 'timegm'
have_func 'rb_gc_adjust_memory_usage' # since ruby-2.4
have_func 'rb_gc_mark_movable' # since ruby-2.7
have_func 'rb_io_wait' # since ruby-3.0

# unistd.h confilicts with ruby/win32.h when cross compiling for win32 and ruby 1.9.1
have_header 'unistd.h'
Expand Down
11 changes: 11 additions & 0 deletions ext/pg_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -3101,6 +3101,17 @@ pgconn_get_last_result(VALUE self)
return rb_pgresult;
}

#if !defined(HAVE_RB_IO_WAIT)
#define rb_io_wait(io, event, timeout) do { \
rb_io_t *fptr; \
GetOpenFile((io), fptr); \
if( (event) == RB_INT2NUM(RUBY_IO_READABLE) ) \
rb_io_wait_readable(fptr->fd); \
else \
rb_io_wait_writable(fptr->fd); \
} while(false)
#endif

/*
* call-seq:
* conn.discard_results()
Expand Down

0 comments on commit ea99287

Please sign in to comment.