-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fun_info/2 #1351
Add fun_info/2 #1351
Conversation
src/libAtomVM/nifs.c
Outdated
if (UNLIKELY(memory_ensure_free_opt(ctx, TUPLE_SIZE(2), MEMORY_CAN_SHRINK) != MEMORY_GC_OK)) { | ||
RAISE_ERROR(OUT_OF_MEMORY_ATOM); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like there need to be better system for using those. GC invalidates any pointers to data on process' heap and some functions use it internally. Not only it makes several GC runs but also prevents allocating terms one by one.
Initially, I implemented both /1 and /2 as NIF but experienced problems of invalid pointers when I tried to turn a cstring into a list – it calls a GC so creating second list invalidates pointer to the first one.
I assume the correct way is to put the first one as a root but then the cstring -> list function needs to take two another parameters.
It's a hard problem but I thought about passing some struct that accumulates how much memory is needed and does it as one pass, something like adding an out parameter GCTracker* tracker
that is used before final allocation. This necessarily splits memory calculation and memory allocation.
f054dfc
to
6ee08f3
Compare
Sorry for straining CI so much. Function name representation changed frequently in Erlang (OTP 21, 24, 25 has all different reprs). |
2 side comments: I would rebase this on top of main branch, we are adding new features on that branch now. Also I think this change is worth being mentioned in the changelog. |
6ee08f3
to
1522549
Compare
Done. |
src/libAtomVM/nifs.c
Outdated
case MODULE_ATOM: { | ||
const term *boxed_value = term_to_const_term_ptr(fun); | ||
if (term_is_external_fun(fun)) { | ||
term module_atom = boxed_value[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest adding some inline functions to term.h
(or use existing ones) in order to access fun inner structure, so we don't leak outside of term.h
the fun layout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I used single function for that with null checks for arguments. If this adds too much branching, I can split them into three functions.
Also passing entire context, not sure if it should take global and heap separately instead.
1522549
to
da4070f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are quite close, just the last changes.
I suggest also rebasing it on latest main.
Signed-off-by: Jakub Gonet <[email protected]>
da4070f
to
3fdcd0d
Compare
I noticed that I only preserved |
@bettio do you want me to rebase on latest main to potentially fix ESP CI problems and resolve conflicts? |
These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later