Skip to content

Commit d00d935

Browse files
committed
Merge branch 'maint'
* maint: binary_to_term: Relax the trapping logic for on-heap bitstrings
2 parents d1280c9 + 00031df commit d00d935

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

erts/emulator/beam/external.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4883,14 +4883,35 @@ dec_term(ErtsDistExternal *edep,
48834883
NBITS(ep - data),
48844884
size_in_bits);
48854885
hp = factory->hp;
4886+
} else if (size_in_bits <= ERL_ONHEAP_BITS_LIMIT) {
4887+
ErlHeapBits *hb;
4888+
4889+
if (ctx) {
4890+
/* Count reductions but don't bother trying to trap in
4891+
* the middle, it's short enough not to matter. */
4892+
reds -= MIN(reds, (SWord)nu / B2T_MEMCPY_FACTOR);
4893+
}
4894+
4895+
hb = (ErlHeapBits*)hp;
4896+
hb->thing_word = header_heap_bits(size_in_bits);
4897+
hb->size = size_in_bits;
4898+
4899+
sys_memcpy((byte*)hb->data, ep, nu);
4900+
hp += heap_bits_size(size_in_bits);
4901+
4902+
*objp = make_bitstring(hb);
48864903
} else {
4887-
byte *data;
4904+
Binary *refc_binary = erts_bin_nrml_alloc(NBYTES(size_in_bits));
4905+
byte *data = (byte*)refc_binary->orig_bytes;
48884906

48894907
factory->hp = hp;
4890-
*objp = erts_hfact_new_bitstring(factory,
4908+
*objp = erts_wrap_refc_bitstring(&(factory->off_heap)->first,
4909+
&(factory->off_heap)->overhead,
4910+
&factory->hp,
4911+
refc_binary,
4912+
data,
48914913
0,
4892-
size_in_bits,
4893-
&data);
4914+
size_in_bits);
48944915
hp = factory->hp;
48954916

48964917
if (ctx) {

0 commit comments

Comments
 (0)