@@ -1219,8 +1219,8 @@ JL_DLLEXPORT jl_value_t *jl_box_bool(int8_t x)
1219
1219
1220
1220
JL_DLLEXPORT jl_value_t * jl_new_struct (jl_datatype_t * type , ...)
1221
1221
{
1222
- jl_ptls_t ptls = jl_get_ptls_states ();
1223
1222
if (type -> instance != NULL ) return type -> instance ;
1223
+ jl_ptls_t ptls = jl_get_ptls_states ();
1224
1224
va_list args ;
1225
1225
size_t nf = jl_datatype_nfields (type );
1226
1226
va_start (args , type );
@@ -1318,9 +1318,9 @@ JL_DLLEXPORT jl_value_t *jl_new_structt(jl_datatype_t *type, jl_value_t *tup)
1318
1318
1319
1319
JL_DLLEXPORT jl_value_t * jl_new_struct_uninit (jl_datatype_t * type )
1320
1320
{
1321
- jl_ptls_t ptls = jl_get_ptls_states ();
1322
1321
if (type -> instance != NULL ) return type -> instance ;
1323
1322
size_t size = jl_datatype_size (type );
1323
+ jl_ptls_t ptls = jl_get_ptls_states ();
1324
1324
jl_value_t * jv = jl_gc_alloc (ptls , size , type );
1325
1325
if (size > 0 )
1326
1326
memset (jl_data_ptr (jv ), 0 , size );
@@ -1389,16 +1389,20 @@ JL_DLLEXPORT jl_value_t *jl_get_nth_field(jl_value_t *v, size_t i)
1389
1389
return ((jl_datatype_t * )ty )-> instance ;
1390
1390
}
1391
1391
jl_value_t * r ;
1392
- int needlock = (isatomic && jl_datatype_size (ty ) > MAX_ATOMIC_SIZE );
1392
+ size_t fsz = jl_datatype_size (ty );
1393
+ int needlock = (isatomic && fsz > MAX_ATOMIC_SIZE );
1393
1394
if (isatomic && !needlock ) {
1394
1395
r = jl_atomic_new_bits (ty , (char * )v + offs );
1395
1396
}
1397
+ else if (needlock ) {
1398
+ jl_ptls_t ptls = jl_get_ptls_states ();
1399
+ r = jl_gc_alloc (ptls , fsz , ty );
1400
+ jl_lock_value (v );
1401
+ memcpy ((char * )r , (char * )v + offs , fsz );
1402
+ jl_unlock_value (v );
1403
+ }
1396
1404
else {
1397
- if (needlock )
1398
- jl_lock_value (v );
1399
1405
r = jl_new_bits (ty , (char * )v + offs );
1400
- if (needlock )
1401
- jl_unlock_value (v );
1402
1406
}
1403
1407
return undefref_check ((jl_datatype_t * )ty , r );
1404
1408
}
@@ -1484,12 +1488,13 @@ void set_nth_field(jl_datatype_t *st, jl_value_t *v, size_t i, jl_value_t *rhs,
1484
1488
if (hasptr )
1485
1489
jl_gc_multi_wb (v , rhs ); // rhs is immutable
1486
1490
}
1491
+ else if (needlock ) {
1492
+ jl_lock_value (v );
1493
+ memcpy ((char * )v + offs , (char * )rhs , fsz );
1494
+ jl_unlock_value (v );
1495
+ }
1487
1496
else {
1488
- if (needlock )
1489
- jl_lock_value (v );
1490
1497
memassign_safe (hasptr , v , (char * )v + offs , rhs , fsz );
1491
- if (needlock )
1492
- jl_unlock_value (v );
1493
1498
}
1494
1499
}
1495
1500
}
@@ -1536,13 +1541,21 @@ jl_value_t *swap_nth_field(jl_datatype_t *st, jl_value_t *v, size_t i, jl_value_
1536
1541
jl_gc_multi_wb (v , rhs ); // rhs is immutable
1537
1542
}
1538
1543
else {
1539
- if (needlock )
1544
+ if (needlock ) {
1545
+ jl_ptls_t ptls = jl_get_ptls_states ();
1546
+ r = jl_gc_alloc (ptls , fsz , ty );
1540
1547
jl_lock_value (v );
1541
- if (!isunion )
1542
- r = undefref_check ((jl_datatype_t * )ty , jl_new_bits (ty , (char * )v + offs ));
1543
- memassign_safe (hasptr , v , (char * )v + offs , rhs , fsz );
1544
- if (needlock )
1548
+ memcpy ((char * )r , (char * )v + offs , fsz );
1549
+ memcpy ((char * )v + offs , (char * )rhs , fsz );
1545
1550
jl_unlock_value (v );
1551
+ }
1552
+ else {
1553
+ if (!isunion )
1554
+ r = jl_new_bits (ty , (char * )v + offs );
1555
+ memassign_safe (hasptr , v , (char * )v + offs , rhs , fsz );
1556
+ }
1557
+ if (needlock || !isunion )
1558
+ r = undefref_check ((jl_datatype_t * )ty , r );
1546
1559
}
1547
1560
}
1548
1561
if (__unlikely (r == NULL ))
@@ -1610,16 +1623,18 @@ jl_value_t *modify_nth_field(jl_datatype_t *st, jl_value_t *v, size_t i, jl_valu
1610
1623
if (jl_is_datatype_singleton ((jl_datatype_t * )yty ))
1611
1624
break ;
1612
1625
}
1626
+ fsz = jl_datatype_size ((jl_datatype_t * )yty ); // need to shrink-wrap the final copy
1627
+ }
1628
+ else {
1629
+ assert (yty == ty && rty == ty );
1613
1630
}
1614
- fsz = jl_datatype_size ((jl_datatype_t * )yty ); // need to shrink-wrap the final copy
1615
1631
memassign_safe (hasptr , v , (char * )v + offs , y , fsz );
1616
1632
}
1617
- if (!success )
1618
- r = jl_new_bits (ty , (char * )v + offs );
1619
1633
if (needlock )
1620
1634
jl_unlock_value (v );
1621
1635
if (success )
1622
1636
break ;
1637
+ r = jl_get_nth_field (v , i );
1623
1638
}
1624
1639
}
1625
1640
args [0 ] = r ;
@@ -1658,18 +1673,20 @@ jl_value_t *cmpswap_nth_field(jl_datatype_t *st, jl_value_t *v, size_t i, jl_val
1658
1673
else {
1659
1674
int hasptr ;
1660
1675
int isunion = jl_is_uniontype (ty );
1676
+ int needlock ;
1677
+ jl_value_t * rty = ty ;
1678
+ size_t fsz ;
1661
1679
if (isunion ) {
1662
1680
assert (!isatomic );
1663
1681
hasptr = 0 ;
1682
+ needlock = 0 ;
1683
+ isatomic = 0 ; // this makes GCC happy
1664
1684
}
1665
1685
else {
1666
1686
hasptr = ((jl_datatype_t * )ty )-> layout -> npointers > 0 ;
1667
- }
1668
- jl_value_t * rty = ty ;
1669
- size_t fsz ;
1670
- if (!isunion )
1671
1687
fsz = jl_datatype_size ((jl_datatype_t * )rty ); // need to shrink-wrap the final copy
1672
- int needlock = (isatomic && fsz > MAX_ATOMIC_SIZE );
1688
+ needlock = (isatomic && fsz > MAX_ATOMIC_SIZE );
1689
+ }
1673
1690
if (isatomic && !needlock ) {
1674
1691
r = jl_atomic_cmpswap_bits ((jl_datatype_t * )rty , (char * )v + offs , r , rhs , fsz );
1675
1692
int success = * ((uint8_t * )r + fsz );
0 commit comments