Fix incorrect initialization of `rb_io_t::self`.

This commit is contained in:
Samuel Williams 2020-09-15 14:19:54 +12:00
Родитель b2b855f486
Коммит a9b2a96c5c
2 изменённых файлов: 8 добавлений и 3 удалений

2
gc.c
Просмотреть файл

@ -5636,6 +5636,7 @@ gc_mark_children(rb_objspace_t *objspace, VALUE obj)
case T_FILE:
if (any->as.file.fptr) {
gc_mark(objspace, any->as.file.fptr->self);
gc_mark(objspace, any->as.file.fptr->pathv);
gc_mark(objspace, any->as.file.fptr->tied_io_for_writing);
gc_mark(objspace, any->as.file.fptr->writeconv_asciicompat);
@ -8555,6 +8556,7 @@ gc_update_object_references(rb_objspace_t *objspace, VALUE obj)
case T_FILE:
if (any->as.file.fptr) {
UPDATE_IF_MOVED(objspace, any->as.file.fptr->self);
UPDATE_IF_MOVED(objspace, any->as.file.fptr->pathv);
UPDATE_IF_MOVED(objspace, any->as.file.fptr->tied_io_for_writing);
UPDATE_IF_MOVED(objspace, any->as.file.fptr->writeconv_asciicompat);

9
io.c
Просмотреть файл

@ -8214,6 +8214,7 @@ prep_io(int fd, int fmode, VALUE klass, const char *path)
VALUE io = io_alloc(klass);
MakeOpenFile(io, fp);
fp->self = io;
fp->fd = fd;
fp->mode = fmode;
if (!io_check_tty(fp)) {
@ -8297,6 +8298,7 @@ static inline rb_io_t *
rb_io_fptr_new(void)
{
rb_io_t *fp = ALLOC(rb_io_t);
fp->self = Qnil;
fp->fd = -1;
fp->stdio_file = NULL;
fp->mode = 0;
@ -8329,11 +8331,12 @@ rb_io_make_open_file(VALUE obj)
Check_Type(obj, T_FILE);
if (RFILE(obj)->fptr) {
rb_io_close(obj);
rb_io_fptr_finalize(RFILE(obj)->fptr);
RFILE(obj)->fptr = 0;
rb_io_close(obj);
rb_io_fptr_finalize(RFILE(obj)->fptr);
RFILE(obj)->fptr = 0;
}
fp = rb_io_fptr_new();
fp->self = obj;
RFILE(obj)->fptr = fp;
return fp;
}