Project

General

Profile

Bug #13085 ยป 0001-v2-io.c-io_fwrite-copy-to-hidden-buffer-when-writing.patch

normalperson (Eric Wong), 01/05/2017 11:09 PM

View differences:

io.c
1423 1423
io_fwrite(VALUE str, rb_io_t *fptr, int nosync)
1424 1424
{
1425 1425
    int converted = 0;
1426
    VALUE tmp = str;
1427
    const char *ptr;
1428
    long len;
1429

  
1426 1430
#ifdef _WIN32
1427 1431
    if (fptr->mode & FMODE_TTY) {
1428 1432
	long len = rb_w32_write_console(str, fptr->fd);
1429 1433
	if (len > 0) return len;
1430 1434
    }
1431 1435
#endif
1432
    str = do_writeconv(str, fptr, &converted);
1433
    if (converted)
1434
	OBJ_FREEZE(str);
1435
    else
1436
	str = rb_str_new_frozen(str);
1436
    tmp = do_writeconv(str, fptr, &converted);
1437
    if (converted) {
1438
	rb_obj_hide(tmp);
1439
    }
1440
    else if (!OBJ_FROZEN_RAW(str)) {
1441
	tmp = rb_str_tmp_new(0);
1442
	rb_str_buf_append(tmp, str);
1443
    }
1444

  
1445
    RSTRING_GETMEM(tmp, ptr, len);
1446
    len = io_binwrite(tmp, ptr, len, fptr, nosync);
1437 1447

  
1438
    return io_binwrite(str, RSTRING_PTR(str), RSTRING_LEN(str),
1439
		       fptr, nosync);
1448
    if (tmp != str) {
1449
	rb_str_resize(tmp, 0);
1450
	rb_gc_force_recycle(tmp);
1451
    }
1452

  
1453
    return len;
1440 1454
}
1441 1455

  
1442 1456
ssize_t
1443
-