Deprecate enif_make_resource* in favor of term_from_resource*#2108
Deprecate enif_make_resource* in favor of term_from_resource*#2108bettio merged 1 commit intoatomvm:mainfrom
enif_make_resource* in favor of term_from_resource*#2108Conversation
|
I made this comment on the |
There was a problem hiding this comment.
I think that our memory managment model and the fact that we care about malloc failures, cannot work well with the BEAM original API.
So as I previously mentioned in #2101, IMHO the way to go is using term_from_resource() + explicit memory allocation.
So right now, we have a number of components around (both ours and 3rd party) using enif_make_resource.
If we do this change, if any of those components miss adding the term_is_invalid_term() check, we end having in the best case a crash or even undefined behaviors around. This kind of change can be hard to spot since we are not changing function signature.
Also the purpose of enif_make_resource (and the other similar functions) was to match the BEAM API, so I don't think we should require additional actions / checks after them, otherwise we mostly defeat their purpose.
Anyway, I dont like calling AVM_ABORT() but I think it is the less risky approach right now.
Also, there was the problem I mentioned here. So I think that right now the only solution is unconditionally allocate a heap fragment just for the resource. It is not efficient, but it is not risky as we do now, and it is acceptable since we are saying that term_from_resource() should be used instead.
7246c60 to
c9de9be
Compare
enif_make_resource* return invalid term in case of OOMenif_make_resource* in favor of term_from_resource*
c9de9be to
58547a5
Compare
Update all call sites to use `term_from_resource` and `term_from_resource_binary`. Also fix allocation size for `enif_make_resource_binary` Signed-off-by: Paul Guyot <pguyot@kallisys.net>
58547a5 to
3f631d9
Compare
Also fix allocation size for
enif_make_resource_binaryThese 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