Skip to content

Commit 9fee649

Browse files
committed
Merge pull request atomvm#761 from fadushin/prepend-avm
Prepend AVM files that are loaded via add_avm_pack_file This PR prepends the AVM data to the list of AVMs when using the `atomvm: add_avm_pack_file` function. In so doing, modules in AVM files that are so added are searched first when loading, allowing users to over-ride module definitions in applications (for testing/debugging) 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
2 parents 3c05f26 + f044469 commit 9fee649

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/libAtomVM/nifs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "posix_nifs.h"
4646
#include "scheduler.h"
4747
#include "smp.h"
48+
#include "synclist.h"
4849
#include "sys.h"
4950
#include "term.h"
5051
#include "utils.h"
@@ -3590,7 +3591,7 @@ static term nif_atomvm_add_avm_pack_file(Context *ctx, int argc, term argv[])
35903591
if (name != UNDEFINED_ATOM) {
35913592
avmpack_data->name_atom_id = term_to_atom_index(name);
35923593
}
3593-
synclist_append(&ctx->global->avmpack_data, &avmpack_data->avmpack_head);
3594+
synclist_prepend(&ctx->global->avmpack_data, &avmpack_data->avmpack_head);
35943595

35953596
return OK_ATOM;
35963597
}

src/libAtomVM/synclist.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ static inline void synclist_unlock(struct SyncList *synclist)
7272
smp_rwlock_unlock(synclist->lock);
7373
}
7474

75+
static inline void synclist_prepend(struct SyncList *synclist, struct ListHead *new_item)
76+
{
77+
struct ListHead *head = synclist_wrlock(synclist);
78+
list_prepend(head, new_item);
79+
synclist_unlock(synclist);
80+
}
81+
7582
static inline void synclist_append(struct SyncList *synclist, struct ListHead *new_item)
7683
{
7784
struct ListHead *head = synclist_wrlock(synclist);
@@ -104,6 +111,7 @@ static inline int synclist_is_empty(struct SyncList *synclist)
104111
#define synclist_nolock(list) list
105112
#define synclist_unlock(list) UNUSED(list)
106113
#define synclist_destroy(list) UNUSED(list)
114+
#define synclist_prepend(list, new_item) list_prepend(list, new_item)
107115
#define synclist_append(list, new_item) list_append(list, new_item)
108116
#define synclist_remove(list, new_item) list_remove(new_item)
109117
#define synclist_is_empty(list) list_is_empty(list)

0 commit comments

Comments
 (0)