Project

General

Profile

Bug #13085 ยป 0001-io.c-io_fwrite-temporarily-freeze-string-when-writin.patch

normalperson (Eric Wong), 12/31/2016 01:01 AM

View differences:

io.c
1419 1419
    return str;
1420 1420
}
1421 1421

  
1422
struct fwrite_tmp_freeze {
1423
    VALUE str;
1424
    union {
1425
	rb_io_t *fptr;
1426
	long written;
1427
    } as;
1428
    int nosync;
1429
};
1430

  
1431
static VALUE
1432
fwrite_freeze(VALUE p)
1433
{
1434
    struct fwrite_tmp_freeze *x = (struct fwrite_tmp_freeze *)p;
1435
    const char *ptr;
1436
    long len;
1437

  
1438
    OBJ_FREEZE_RAW(x->str);
1439
    RSTRING_GETMEM(x->str, ptr, len);
1440
    x->as.written = io_binwrite(x->str, ptr, len, x->as.fptr, x->nosync);
1441

  
1442
    return Qfalse;
1443
}
1444

  
1445
static VALUE
1446
fwrite_unfreeze(VALUE str)
1447
{
1448
    FL_UNSET_RAW(str, FL_FREEZE);
1449

  
1450
    return Qfalse;
1451
}
1452

  
1422 1453
static long
1423 1454
io_fwrite(VALUE str, rb_io_t *fptr, int nosync)
1424 1455
{
......
1432 1463
    str = do_writeconv(str, fptr, &converted);
1433 1464
    if (converted)
1434 1465
	OBJ_FREEZE(str);
1435
    else
1436
	str = rb_str_new_frozen(str);
1466
    else if (!OBJ_FROZEN_RAW(str)) {
1467
	struct fwrite_tmp_freeze x;
1468

  
1469
	x.str = str;
1470
	x.as.fptr = fptr;
1471
	x.nosync = nosync;
1472
	rb_ensure(fwrite_freeze, (VALUE)&x, fwrite_unfreeze, str);
1473

  
1474
	return x.as.written;
1475
    }
1437 1476

  
1438 1477
    return io_binwrite(str, RSTRING_PTR(str), RSTRING_LEN(str),
1439 1478
		       fptr, nosync);
1440
-