Skip to content

Commit 5f9e1df

Browse files
authored
Merge branch 'release-0.6' into w04/fix-refcount-calculation
2 parents 77cfcbb + ac46edd commit 5f9e1df

File tree

5 files changed

+67
-14
lines changed

5 files changed

+67
-14
lines changed

CHANGELOG.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Added
1010

11-
- Added the ability to run beams from the CLI for Generic Unix platform (it was already possible with nodejs and emscripten).
11+
- Added the ability to run beams from the CLI for Generic Unix platform (it was already possible
12+
with nodejs and emscripten)
1213
- Added preliminary support for ESP32P4 (no networking support yet).
1314

1415
### Fixed
@@ -18,11 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1819
- Adding missing check, passing a non numeric argument to a function expecting a floating point
1920
might lead to a crash in certain situations.
2021
- Fixed several bugs in `http_server` (#1366)
21-
- Fixed generic\_unix `socket_driver` to return `{gen_tcp, closed}` when socket is closed on Linux instead of `{gen_tcp, {recv, 104}}`
22+
- Fixed generic\_unix `socket_driver` to return `{gen_tcp, closed}` when socket is closed on Linux
23+
instead of `{gen_tcp, {recv, 104}}`
2224
- Fixed a memory leak where modules were not properly destroyed when the global context is destroyd
2325
- alisp: fix support to variables that are not binaries or integers.
2426
- Fixed destruction of ssl-related resources
25-
- Fix corruption when dealing with specific situations that involve more than 16 x registers when
27+
- Fixed corruption when dealing with specific situations that involve more than 16 x registers when
2628
certain VM instructions are used.
2729
- Fixed ESP32 GPIO interrupt trigger `none`
2830
- Fixed an issue where a timeout would occur immediately in a race condition
@@ -31,19 +33,20 @@ certain VM instructions are used.
3133
- Fixed a race condition affecting multi-core MCUs where a timeout would not be properly cleared
3234
- Fixed a double free when esp32 uart driver was closed, yielding an assert abort
3335
- Fixed compilation with latest debian gcc-arm-none-eabi
34-
- Fix `network:stop/0` on ESP32 so the network can be started again
35-
- Fix a memory corruption caused by `binary:split/2,3`
36-
- Fix deadlock in socket code
37-
- Fix bug in opcode implementation (`select_val`): when selecting a value among many others a
36+
- Fixed `network:stop/0` on ESP32 so the network can be started again
37+
- Fixed a memory corruption caused by `binary:split/2,3`
38+
- Fixed deadlock in socket code
39+
- Fixed bug in opcode implementation (`select_val`): when selecting a value among many others a
3840
shallow comparison was performed, so it was working just for plain values such as atoms and small
3941
integers
4042
- Fixed support for setting esp32 boot_path in NVS.
4143
- Fixed race conditions in network:start/stop.
4244
- Fixed crash calling network:sta_rssi(), when network not up.
43-
- Fix error handling when calling `min` and `max` with code compiled before OTP-26: there was a
44-
bug when handling errors from BIFs used as NIFs (when called with `CALL_EXT` and similar opcodes)`
45-
- Fix matching of binaries on unaligned boundaries for code compiled with older versions of OTP
46-
- Add missing out of memory handling in binary_to_atom
45+
- Fixed error handling when calling `min` and `max` with code compiled before OTP-26: there was a
46+
bug when handling errors from BIFs used as NIFs (when called with `CALL_EXT` and similar opcodes)
47+
- Fixed matching of binaries on unaligned boundaries for code compiled with older versions of OTP
48+
- Added missing out of memory handling in binary_to_atom
49+
- Fixed call to funs such as fun erlang:'not'/1, that make use of BIFs
4750
- Fixed potential crashes or memory leaks caused by a mistake in calculation of reference counts
4851
and a race condition in otp_socket code
4952

src/libAtomVM/opcodesswitch.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,9 +1161,8 @@ static void destroy_extended_registers(Context *ctx, unsigned int live)
11611161
fun_arity = term_to_int(boxed_value[3]); \
11621162
AtomString module_name = globalcontext_atomstring_from_term(glb, module); \
11631163
AtomString function_name = globalcontext_atomstring_from_term(glb, index_or_function); \
1164-
struct Nif *nif = (struct Nif *) nifs_get(module_name, function_name, fun_arity); \
1165-
if (!IS_NULL_PTR(nif)) { \
1166-
term return_value = nif->nif_ptr(ctx, fun_arity, x_regs); \
1164+
term return_value; \
1165+
if (maybe_call_native(ctx, module_name, function_name, fun_arity, &return_value)) { \
11671166
PROCESS_MAYBE_TRAP_RETURN_VALUE(return_value); \
11681167
x_regs[0] = return_value; \
11691168
if (ctx->heap.root->next) { \

tests/erlang_tests/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ compile_erlang(test_funs11)
197197

198198
compile_erlang(test_make_fun3)
199199

200+
compile_erlang(fun_call_bif)
201+
200202
compile_erlang(complex_struct_size0)
201203
compile_erlang(complex_struct_size1)
202204
compile_erlang(complex_struct_size2)
@@ -669,6 +671,8 @@ add_custom_target(erlang_test_modules DEPENDS
669671

670672
test_make_fun3.beam
671673

674+
fun_call_bif.beam
675+
672676
complex_struct_size0.beam
673677
complex_struct_size1.beam
674678
complex_struct_size2.beam

tests/erlang_tests/fun_call_bif.erl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
%
2+
% This file is part of AtomVM.
3+
%
4+
% Copyright 2025 Paul Guyot <pguyot@kallisys.net>
5+
% Copyright 2025 Davide Bettio <davide@uninstall.it>
6+
%
7+
% Licensed under the Apache License, Version 2.0 (the "License");
8+
% you may not use this file except in compliance with the License.
9+
% You may obtain a copy of the License at
10+
%
11+
% http://www.apache.org/licenses/LICENSE-2.0
12+
%
13+
% Unless required by applicable law or agreed to in writing, software
14+
% distributed under the License is distributed on an "AS IS" BASIS,
15+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
% See the License for the specific language governing permissions and
17+
% limitations under the License.
18+
%
19+
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
20+
%
21+
22+
-module(fun_call_bif).
23+
24+
-export([
25+
start/0,
26+
g/2,
27+
h/4
28+
]).
29+
30+
start() ->
31+
Fun1 = fun erlang:'not'/1,
32+
A = ?MODULE:h(Fun1, true, false, 1) - 1,
33+
R1 = erlang:list_to_existing_atom("start"),
34+
Fun2 = fun erlang:list_to_existing_atom/1,
35+
B = ?MODULE:g(Fun2, atom_to_list(R1)),
36+
A + B.
37+
38+
g(Fun, R1) ->
39+
start = Fun(R1),
40+
0.
41+
42+
h(Fun, In, Exp, V) ->
43+
case Fun(In) of
44+
Exp -> V;
45+
_ -> 0
46+
end.

tests/test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ struct Test tests[] = {
234234
TEST_CASE_EXPECTED(test_funs10, 6817),
235235
TEST_CASE_EXPECTED(test_funs11, 817),
236236
TEST_CASE(test_make_fun3),
237+
TEST_CASE(fun_call_bif),
237238

238239
TEST_CASE(nested_list_size0),
239240
TEST_CASE_EXPECTED(nested_list_size1, 2),

0 commit comments

Comments
 (0)