Skip to content

Add support for atoms longer than 255 bytes (but less than 256 chars) #1586

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

Merged
merged 7 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/libAtomVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ project (libAtomVM)

set(HEADER_FILES
atom.h
atomshashtable.h
atom_table.h
avmpack.h
bif.h
Expand Down Expand Up @@ -75,7 +74,6 @@ set(HEADER_FILES

set(SOURCE_FILES
atom.c
atomshashtable.c
atom_table.c
avmpack.c
bif.c
Expand Down
8 changes: 3 additions & 5 deletions src/libAtomVM/atom.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,17 @@ static void utoa10(unsigned int int_value, char *integer_string)
integer_string[integer_string_len] = '\0';
}

void atom_write_mfa(char *buf, size_t buf_size, AtomString module, AtomString function, unsigned int arity)
void atom_write_mfa(char *buf, size_t buf_size, size_t module_name_len, const void *module_data, size_t function_name_len, const void *function_data, unsigned int arity)
{
size_t module_name_len = atom_string_len(module);
memcpy(buf, atom_string_data(module), module_name_len);
memcpy(buf, module_data, module_name_len);

buf[module_name_len] = ':';

size_t function_name_len = atom_string_len(function);
if (UNLIKELY((module_name_len + 1 + function_name_len + 1 + 4 + 1 > buf_size))) {
fprintf(stderr, "Insufficient room to write mfa.\n");
AVM_ABORT();
}
memcpy(buf + module_name_len + 1, atom_string_data(function), function_name_len);
memcpy(buf + module_name_len + 1, function_data, function_name_len);

buf[module_name_len + function_name_len + 1] = '/';
utoa10(arity, buf + module_name_len + 1 + function_name_len + 1);
Expand Down
9 changes: 6 additions & 3 deletions src/libAtomVM/atom.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extern "C" {
#define ATOM_STR(LENSTR, STR) (LENSTR STR)

typedef const void *AtomString;
typedef uint32_t atom_index_t;

/**
* @brief Gets a C string from an AtomString
Expand Down Expand Up @@ -98,11 +99,13 @@ static inline const void *atom_string_data(AtomString atom_str)
* buffer size.
* @param buf the buffer to write into
* @param buf_size the amount of room in the buffer
* @param module the module name
* @param function the function name
* @param module_name_len length of the module name
* @param module_data the module name
* @param function_name_len length of the function name
* @param function_data the function name
* @param arity the function arity
*/
void atom_write_mfa(char *buf, size_t buf_size, AtomString module, AtomString function, unsigned int arity);
void atom_write_mfa(char *buf, size_t buf_size, size_t module_name_len, const void *module_data, size_t function_name_len, const void *function_data, unsigned int arity);

#ifdef __cplusplus
}
Expand Down
Loading
Loading