@@ -391,6 +391,8 @@ typedef union
391391 DECODE_LITERAL (allocator_size , code_chunk , base_index , off ); \
392392 if (allocator_tag == COMPACT_EXTENDED_ALLOCATOR_LIST_TAG_FLOATS ) { \
393393 allocator_size *= FLOAT_SIZE ; \
394+ } else if (allocator_tag == COMPACT_EXTENDED_ALLOCATOR_LIST_TAG_FUNS ) { \
395+ allocator_size *= BOXED_FUN_SIZE ; \
394396 } \
395397 need += allocator_size ; \
396398 } \
@@ -654,6 +656,8 @@ typedef union
654656 DECODE_LITERAL (allocator_size , code_chunk , base_index , off ); \
655657 if (allocator_tag == COMPACT_EXTENDED_ALLOCATOR_LIST_TAG_FLOATS ) { \
656658 allocator_size *= FLOAT_SIZE ; \
659+ } else if (allocator_tag == COMPACT_EXTENDED_ALLOCATOR_LIST_TAG_FUNS ) { \
660+ allocator_size *= BOXED_FUN_SIZE ; \
657661 } \
658662 need += allocator_size ; \
659663 } \
@@ -1132,13 +1136,13 @@ term make_fun(Context *ctx, const Module *mod, int fun_index)
11321136{
11331137 uint32_t n_freeze = module_get_fun_freeze (mod , fun_index );
11341138
1135- int size = 2 + n_freeze ;
1136- if (memory_ensure_free (ctx , size + 1 ) != MEMORY_GC_OK ) {
1139+ int size = BOXED_FUN_SIZE + n_freeze ;
1140+ if (memory_ensure_free (ctx , size ) != MEMORY_GC_OK ) {
11371141 return term_invalid_term ();
11381142 }
1139- term * boxed_func = memory_heap_alloc (ctx , size + 1 );
1143+ term * boxed_func = memory_heap_alloc (ctx , size );
11401144
1141- boxed_func [0 ] = (size << 6 ) | TERM_BOXED_FUN ;
1145+ boxed_func [0 ] = (( size - 1 ) << 6 ) | TERM_BOXED_FUN ;
11421146 boxed_func [1 ] = (term ) mod ;
11431147 boxed_func [2 ] = term_from_int (fun_index );
11441148
@@ -6117,22 +6121,20 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
61176121 dreg_type_t dreg_type ;
61186122 DECODE_DEST_REGISTER (dreg , dreg_type , code , i , next_off );
61196123 DECODE_EXTENDED_LIST_TAG (code , i , next_off );
6120- uint32_t size ;
6121- DECODE_LITERAL (size , code , i , next_off )
6122- TRACE ("make_fun3/3, fun_index=%i dreg=%c%i arity =%i\n" , fun_index , T_DEST_REG (dreg_type , dreg ), size );
6124+ uint32_t numfree ;
6125+ DECODE_LITERAL (numfree , code , i , next_off )
6126+ TRACE ("make_fun3/3, fun_index=%i dreg=%c%i numfree =%i\n" , fun_index , T_DEST_REG (dreg_type , dreg ), numfree );
61236127
61246128 #ifdef IMPL_EXECUTE_LOOP
6125- if (memory_ensure_free (ctx , size + 3 ) != MEMORY_GC_OK ) {
6126- RAISE_ERROR (OUT_OF_MEMORY_ATOM );
6127- }
6128- term * boxed_func = memory_heap_alloc (ctx , size + 3 );
6129+ size_t size = numfree + BOXED_FUN_SIZE ;
6130+ term * boxed_func = memory_heap_alloc (ctx , size );
61296131
6130- boxed_func [0 ] = ((size + 2 ) << 6 ) | TERM_BOXED_FUN ;
6132+ boxed_func [0 ] = ((size - 1 ) << 6 ) | TERM_BOXED_FUN ;
61316133 boxed_func [1 ] = (term ) mod ;
61326134 boxed_func [2 ] = term_from_int (fun_index );
61336135 #endif
61346136
6135- for (uint32_t j = 0 ; j < size ; j ++ ) {
6137+ for (uint32_t j = 0 ; j < numfree ; j ++ ) {
61366138 term arg ;
61376139 DECODE_COMPACT_TERM (arg , code , i , next_off );
61386140 #ifdef IMPL_EXECUTE_LOOP
@@ -6543,9 +6545,6 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
65436545 DECODE_LITERAL (size , code , i , next_off );
65446546 #ifdef IMPL_EXECUTE_LOOP
65456547 term dst ;
6546- if (UNLIKELY (memory_ensure_free (ctx , TUPLE_SIZE (size )) != MEMORY_GC_OK )) {
6547- RAISE_ERROR (OUT_OF_MEMORY_ATOM );
6548- }
65496548 dst = term_alloc_tuple (size , ctx );
65506549 #endif
65516550 term src ;
0 commit comments