Skip to content

Commit 578904c

Browse files
committed
Ensure struct rb_io is passed through to thread.c.
1 parent ccc7493 commit 578904c

File tree

7 files changed

+41
-29
lines changed

7 files changed

+41
-29
lines changed

file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,11 +2625,11 @@ io_blocking_fchmod(void *ptr)
26252625
}
26262626

26272627
static int
2628-
rb_fchmod(int fd, mode_t mode)
2628+
rb_fchmod(struct rb_io* io, mode_t mode)
26292629
{
26302630
(void)rb_chmod; /* suppress unused-function warning when HAVE_FCHMOD */
2631-
struct nogvl_fchmod_data data = {.fd = fd, .mode = mode};
2632-
return (int)rb_thread_io_blocking_region(io_blocking_fchmod, &data, fd);
2631+
struct nogvl_fchmod_data data = {.fd = io->fd, .mode = mode};
2632+
return (int)rb_thread_io_blocking_region(io, io_blocking_fchmod, &data);
26332633
}
26342634
#endif
26352635

@@ -2659,7 +2659,7 @@ rb_file_chmod(VALUE obj, VALUE vmode)
26592659

26602660
GetOpenFile(obj, fptr);
26612661
#ifdef HAVE_FCHMOD
2662-
if (rb_fchmod(fptr->fd, mode) == -1) {
2662+
if (rb_fchmod(fptr, mode) == -1) {
26632663
if (HAVE_FCHMOD || errno != ENOSYS)
26642664
rb_sys_fail_path(fptr->pathv);
26652665
}

gc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,11 +1154,17 @@ cvar_table_free_i(VALUE value, void *ctx)
11541154
return ID_TABLE_CONTINUE;
11551155
}
11561156

1157+
static void
1158+
io_fptr_finalize(void *fptr)
1159+
{
1160+
rb_io_fptr_finalize((struct rb_io *)fptr);
1161+
}
1162+
11571163
static inline void
11581164
make_io_zombie(void *objspace, VALUE obj)
11591165
{
11601166
rb_io_t *fptr = RFILE(obj)->fptr;
1161-
rb_gc_impl_make_zombie(objspace, obj, rb_io_fptr_finalize_internal, fptr);
1167+
rb_gc_impl_make_zombie(objspace, obj, io_fptr_finalize, fptr);
11621168
}
11631169

11641170
static bool

internal.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@
5858
/* internal/array.h */
5959
#define rb_ary_new_from_args(...) rb_nonexistent_symbol(__VA_ARGS__)
6060

61-
/* internal/io.h */
62-
#define rb_io_fptr_finalize(...) rb_nonexistent_symbol(__VA_ARGS__)
63-
6461
/* internal/string.h */
6562
#define rb_fstring_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
6663

internal/io.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,6 @@ void rb_stdio_set_default_encoding(void);
119119
VALUE rb_io_flush_raw(VALUE, int);
120120
size_t rb_io_memsize(const rb_io_t *);
121121
int rb_stderr_tty_p(void);
122-
void rb_io_fptr_finalize_internal(void *ptr);
123-
#ifdef rb_io_fptr_finalize
124-
# undef rb_io_fptr_finalize
125-
#endif
126-
#define rb_io_fptr_finalize rb_io_fptr_finalize_internal
127122
VALUE rb_io_popen(VALUE pname, VALUE pmode, VALUE env, VALUE opt);
128123

129124
VALUE rb_io_prep_stdin(void);

internal/thread.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ VALUE rb_mutex_owned_p(VALUE self);
5555
VALUE rb_exec_recursive_outer_mid(VALUE (*f)(VALUE g, VALUE h, int r), VALUE g, VALUE h, ID mid);
5656
void ruby_mn_threads_params(void);
5757

58+
int rb_thread_io_wait(struct rb_io *io, int events, struct timeval * timeout);
5859
int rb_thread_wait_for_single_fd(int fd, int events, struct timeval * timeout);
5960

6061
struct rb_io_close_wait_list {
@@ -73,8 +74,8 @@ RUBY_SYMBOL_EXPORT_BEGIN
7374
void *rb_thread_prevent_fork(void *(*func)(void *), void *data); /* for ext/socket/raddrinfo.c */
7475

7576
/* Temporary. This API will be removed (renamed). */
76-
VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
77-
VALUE rb_thread_io_blocking_call(rb_blocking_function_t *func, void *data1, int fd, int events);
77+
VALUE rb_thread_io_blocking_region(struct rb_io *io, rb_blocking_function_t *func, void *data1);
78+
VALUE rb_thread_io_blocking_call(struct rb_io *io, rb_blocking_function_t *func, void *data1, int events);
7879

7980
/* thread.c (export) */
8081
int ruby_thread_has_gvl_p(void); /* for ext/fiddle/closure.c */

io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static VALUE prep_io(int fd, enum rb_io_mode fmode, VALUE klass, const char *pat
225225
VALUE
226226
rb_io_blocking_region_wait(struct rb_io *io, rb_blocking_function_t *function, void *argument, enum rb_io_event events)
227227
{
228-
return rb_thread_io_blocking_call(function, argument, io->fd, events);
228+
return rb_thread_io_blocking_call(io, function, argument, events);
229229
}
230230

231231
VALUE rb_io_blocking_region(struct rb_io *io, rb_blocking_function_t *function, void *argument)
@@ -1473,7 +1473,7 @@ rb_io_wait(VALUE io, VALUE events, VALUE timeout)
14731473
tv = &tv_storage;
14741474
}
14751475

1476-
int ready = rb_thread_wait_for_single_fd(fptr->fd, RB_NUM2INT(events), tv);
1476+
int ready = rb_thread_io_wait(fptr, RB_NUM2INT(events), tv);
14771477

14781478
if (ready < 0) {
14791479
rb_sys_fail(0);

thread.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,12 +1798,12 @@ rb_thread_mn_schedulable(VALUE thval)
17981798
}
17991799

18001800
VALUE
1801-
rb_thread_io_blocking_call(rb_blocking_function_t *func, void *data1, int fd, int events)
1801+
rb_thread_io_blocking_call(struct rb_io* io, rb_blocking_function_t *func, void *data1, int events)
18021802
{
18031803
rb_execution_context_t *volatile ec = GET_EC();
18041804
rb_thread_t *volatile th = rb_ec_thread_ptr(ec);
18051805

1806-
RUBY_DEBUG_LOG("th:%u fd:%d ev:%d", rb_th_serial(th), fd, events);
1806+
RUBY_DEBUG_LOG("th:%u fd:%d ev:%d", rb_th_serial(th), io->fd, events);
18071807

18081808
struct waiting_fd waiting_fd;
18091809
volatile VALUE val = Qundef; /* shouldn't be used */
@@ -1812,6 +1812,8 @@ rb_thread_io_blocking_call(rb_blocking_function_t *func, void *data1, int fd, in
18121812
volatile bool prev_mn_schedulable = th->mn_schedulable;
18131813
th->mn_schedulable = thread_io_mn_schedulable(th, events, NULL);
18141814

1815+
int fd = io->fd;
1816+
18151817
// `errno` is only valid when there is an actual error - but we can't
18161818
// extract that from the return value of `func` alone, so we clear any
18171819
// prior `errno` value here so that we can later check if it was set by
@@ -1824,10 +1826,10 @@ rb_thread_io_blocking_call(rb_blocking_function_t *func, void *data1, int fd, in
18241826
if ((state = EC_EXEC_TAG()) == TAG_NONE) {
18251827
volatile enum ruby_tag_type saved_state = state; /* for BLOCKING_REGION */
18261828
retry:
1827-
BLOCKING_REGION(waiting_fd.th, {
1829+
BLOCKING_REGION(th, {
18281830
val = func(data1);
18291831
saved_errno = errno;
1830-
}, ubf_select, waiting_fd.th, FALSE);
1832+
}, ubf_select, th, FALSE);
18311833

18321834
th = rb_ec_thread_ptr(ec);
18331835
if (events &&
@@ -1866,9 +1868,9 @@ rb_thread_io_blocking_call(rb_blocking_function_t *func, void *data1, int fd, in
18661868
}
18671869

18681870
VALUE
1869-
rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd)
1871+
rb_thread_io_blocking_region(struct rb_io *io, rb_blocking_function_t *func, void *data1)
18701872
{
1871-
return rb_thread_io_blocking_call(func, data1, fd, 0);
1873+
return rb_thread_io_blocking_call(io, func, data1, 0);
18721874
}
18731875

18741876
/*
@@ -4398,8 +4400,8 @@ wait_for_single_fd_blocking_region(rb_thread_t *th, struct pollfd *fds, nfds_t n
43984400
/*
43994401
* returns a mask of events
44004402
*/
4401-
int
4402-
rb_thread_wait_for_single_fd(int fd, int events, struct timeval *timeout)
4403+
static int
4404+
thread_io_wait(struct rb_io *io, int fd, int events, struct timeval *timeout)
44034405
{
44044406
struct pollfd fds[1] = {{
44054407
.fd = fd,
@@ -4533,15 +4535,14 @@ init_set_fd(int fd, rb_fdset_t *fds)
45334535
return fds;
45344536
}
45354537

4536-
int
4537-
rb_thread_wait_for_single_fd(int fd, int events, struct timeval *timeout)
4538+
static int
4539+
thread_io_wait(struct rb_io *io, int fd, int events, struct timeval *timeout)
45384540
{
45394541
rb_fdset_t rfds, wfds, efds;
45404542
struct select_args args;
45414543
int r;
45424544
VALUE ptr = (VALUE)&args;
4543-
rb_execution_context_t *ec = GET_EC();
4544-
rb_thread_t *th = rb_ec_thread_ptr(ec);
4545+
rb_thread_t *th = GET_THREAD();
45454546

45464547
args.as.fd = fd;
45474548
args.read = (events & RB_WAITFD_IN) ? init_set_fd(fd, &rfds) : NULL;
@@ -4558,6 +4559,18 @@ rb_thread_wait_for_single_fd(int fd, int events, struct timeval *timeout)
45584559
}
45594560
#endif /* ! USE_POLL */
45604561

4562+
int
4563+
rb_thread_wait_for_single_fd(int fd, int events, struct timeval *timeout)
4564+
{
4565+
return thread_io_wait(NULL, fd, events, timeout);
4566+
}
4567+
4568+
int
4569+
rb_thread_io_wait(struct rb_io *io, int events, struct timeval * timeout)
4570+
{
4571+
return thread_io_wait(io, io->fd, events, timeout);
4572+
}
4573+
45614574
/*
45624575
* for GC
45634576
*/

0 commit comments

Comments
 (0)