interop.c

Include dependency graph for interop.c:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "9" [label="stdbool.h" tooltip="stdbool.h"] "1" [label="/__w/AtomVM/AtomVM/src/libAtomVM/interop.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/interop.c" fillcolor="#BFBFBF"] "2" [label="interop.h" tooltip="interop.h"] "26" [label="refc_binary.h" tooltip="refc_binary.h"] "32" [label="defaultatoms.h" tooltip="defaultatoms.h"] "6" [label="atom.h" tooltip="atom.h"] "12" [label="assert.h" tooltip="assert.h"] "24" [label="utils.h" tooltip="utils.h"] "17" [label="synclist.h" tooltip="synclist.h"] "16" [label="list.h" tooltip="list.h"] "5" [label="stdint.h" tooltip="stdint.h"] "7" [label="stdlib.h" tooltip="stdlib.h"] "3" [label="context.h" tooltip="context.h"] "23" [label="memory.h" tooltip="memory.h"] "35" [label="valueshashtable.h" tooltip="valueshashtable.h"] "27" [label="resources.h" tooltip="resources.h"] "20" [label="term.h" tooltip="term.h"] "25" [label="stddef.h" tooltip="stddef.h"] "10" [label="erl_nif.h" tooltip="erl_nif.h"] "33" [label="defaultatoms.def" tooltip="defaultatoms.def"] "13" [label="limits.h" tooltip="limits.h"] "8" [label="atom_table.h" tooltip="atom_table.h"] "21" [label="sys/types.h" tooltip="sys/types.h"] "22" [label="string.h" tooltip="string.h"] "11" [label="term_typedef.h" tooltip="term_typedef.h"] "4" [label="globalcontext.h" tooltip="globalcontext.h"] "30" [label="bitstring.h" tooltip="bitstring.h"] "19" [label="smp.h" tooltip="smp.h"] "31" [label="unicode.h" tooltip="unicode.h"] "29" [label="timer_list.h" tooltip="timer_list.h"] "34" [label="tempstack.h" tooltip="tempstack.h"] "28" [label="mailbox.h" tooltip="mailbox.h"] "18" [label="stdio.h" tooltip="stdio.h"] "15" [label="ets.h" tooltip="ets.h"] "14" [label="inttypes.h" tooltip="inttypes.h"] "1" -> "2" [dir=forward tooltip="include"] "1" -> "8" [dir=forward tooltip="include"] "1" -> "30" [dir=forward tooltip="include"] "1" -> "32" [dir=forward tooltip="include"] "1" -> "34" [dir=forward tooltip="include"] "1" -> "20" [dir=forward tooltip="include"] "1" -> "11" [dir=forward tooltip="include"] "1" -> "35" [dir=forward tooltip="include"] "1" -> "5" [dir=forward tooltip="include"] "2" -> "3" [dir=forward tooltip="include"] "2" -> "20" [dir=forward tooltip="include"] "26" -> "9" [dir=forward tooltip="include"] "26" -> "7" [dir=forward tooltip="include"] "26" -> "16" [dir=forward tooltip="include"] "26" -> "27" [dir=forward tooltip="include"] "32" -> "4" [dir=forward tooltip="include"] "32" -> "33" [dir=forward tooltip="include"] "6" -> "5" [dir=forward tooltip="include"] "6" -> "7" [dir=forward tooltip="include"] "24" -> "25" [dir=forward tooltip="include"] "24" -> "18" [dir=forward tooltip="include"] "24" -> "7" [dir=forward tooltip="include"] "17" -> "18" [dir=forward tooltip="include"] "17" -> "16" [dir=forward tooltip="include"] "17" -> "19" [dir=forward tooltip="include"] "16" -> "9" [dir=forward tooltip="include"] "3" -> "4" [dir=forward tooltip="include"] "3" -> "16" [dir=forward tooltip="include"] "3" -> "28" [dir=forward tooltip="include"] "3" -> "19" [dir=forward tooltip="include"] "3" -> "20" [dir=forward tooltip="include"] "3" -> "29" [dir=forward tooltip="include"] "23" -> "5" [dir=forward tooltip="include"] "23" -> "7" [dir=forward tooltip="include"] "23" -> "10" [dir=forward tooltip="include"] "23" -> "11" [dir=forward tooltip="include"] "23" -> "24" [dir=forward tooltip="include"] "27" -> "7" [dir=forward tooltip="include"] "27" -> "10" [dir=forward tooltip="include"] "27" -> "16" [dir=forward tooltip="include"] "27" -> "23" [dir=forward tooltip="include"] "27" -> "17" [dir=forward tooltip="include"] "20" -> "21" [dir=forward tooltip="include"] "20" -> "9" [dir=forward tooltip="include"] "20" -> "5" [dir=forward tooltip="include"] "20" -> "18" [dir=forward tooltip="include"] "20" -> "7" [dir=forward tooltip="include"] "20" -> "22" [dir=forward tooltip="include"] "20" -> "23" [dir=forward tooltip="include"] "20" -> "26" [dir=forward tooltip="include"] "20" -> "24" [dir=forward tooltip="include"] "20" -> "11" [dir=forward tooltip="include"] "10" -> "11" [dir=forward tooltip="include"] "8" -> "9" [dir=forward tooltip="include"] "8" -> "6" [dir=forward tooltip="include"] "11" -> "12" [dir=forward tooltip="include"] "11" -> "13" [dir=forward tooltip="include"] "11" -> "14" [dir=forward tooltip="include"] "11" -> "5" [dir=forward tooltip="include"] "4" -> "5" [dir=forward tooltip="include"] "4" -> "6" [dir=forward tooltip="include"] "4" -> "8" [dir=forward tooltip="include"] "4" -> "10" [dir=forward tooltip="include"] "4" -> "15" [dir=forward tooltip="include"] "4" -> "16" [dir=forward tooltip="include"] "4" -> "28" [dir=forward tooltip="include"] "4" -> "19" [dir=forward tooltip="include"] "4" -> "17" [dir=forward tooltip="include"] "4" -> "20" [dir=forward tooltip="include"] "4" -> "29" [dir=forward tooltip="include"] "30" -> "20" [dir=forward tooltip="include"] "30" -> "31" [dir=forward tooltip="include"] "30" -> "9" [dir=forward tooltip="include"] "30" -> "5" [dir=forward tooltip="include"] "19" -> "9" [dir=forward tooltip="include"] "31" -> "9" [dir=forward tooltip="include"] "31" -> "25" [dir=forward tooltip="include"] "31" -> "5" [dir=forward tooltip="include"] "29" -> "9" [dir=forward tooltip="include"] "29" -> "5" [dir=forward tooltip="include"] "29" -> "16" [dir=forward tooltip="include"] "28" -> "9" [dir=forward tooltip="include"] "28" -> "16" [dir=forward tooltip="include"] "28" -> "11" [dir=forward tooltip="include"] "28" -> "24" [dir=forward tooltip="include"] "15" -> "16" [dir=forward tooltip="include"] "15" -> "17" [dir=forward tooltip="include"] "15" -> "20" [dir=forward tooltip="include"] }

Functions

char *interop_term_to_string(term t, int *ok)
char *interop_binary_to_string(term binary)
char *interop_iolist_to_string(term list, int *ok)
char *interop_list_to_string(term list, int *ok)
char *interop_list_to_utf8_string(term list, int *ok)
char *interop_atom_to_string(Context *ctx, term atom)
term interop_proplist_get_value(term list, term key)
term interop_proplist_get_value_default(term list, term key, term default_value)
inline InteropFunctionResult interop_chardata_fold(term t, interop_chardata_fold_fun fold_fun, interop_chardata_rest_fun rest_fun, void *accum)
static inline InteropFunctionResult size_fold_fun(term t, void *accum)
InteropFunctionResult interop_iolist_size(term t, size_t *size)
static inline InteropFunctionResult write_string_fold_fun(term t, void *accum)
InteropFunctionResult interop_write_iolist(term t, char *p)
static enum UnicodeConversionResult interop_binary_conversion(term t, uint8_t *output, size_t *output_len, size_t *rest_crsr, enum CharDataEncoding in_encoding, enum CharDataEncoding out_encoding)
static InteropFunctionResult chardata_to_bytes_size_fold_fun(term t, void *accum)
static void chardata_to_bytes_size_rest_fun(term t, void *accum)
enum UnicodeConversionResult interop_chardata_to_bytes_size(term t, size_t *size, size_t *rest_size, enum CharDataEncoding in_encoding, enum CharDataEncoding out_encoding)
static InteropFunctionResult chardata_to_bytes_fold_fun(term t, void *accum)
static void chardata_to_bytes_rest_fun(term t, void *accum)
enum UnicodeConversionResult interop_chardata_to_bytes(term t, uint8_t *output, term *rest, enum CharDataEncoding in_encoding, enum CharDataEncoding out_encoding, Heap *heap)
term interop_map_get_value(GlobalContext *glb, term map, term key)
term interop_map_get_value_default(GlobalContext *glb, term map, term key, term default_value)
int interop_atom_term_select_int(const AtomStringIntPair *table, term atom, GlobalContext *global)

Finds on a table the first matching atom string.

Allows to quickly translate atoms to any integer constant. This function is useful for creating switch statements for atom values. A linear search is performed, so table entries should be sorted by frequency.

Parameters:
  • table – an array AtomStringIntPair structs, terminated with a default entry marked with SELECT_INT_DEFAULT macro.

  • atom – the atom used for comparison.

  • global – the global context.

Returns:

the found int value which corresponds to the given atom.

term interop_kv_get_value_default(term kv, AtomString key, term default_value, GlobalContext *glb)

Get a value given a key (as AtomString) from any proplist or map.

This function allows to easily get values from proplists or maps, without poluting the atom table.

Parameters:
  • kv – any proplist or map.

  • key – an AtomString, such as ATOM_STR(“\x3”, “key”).

  • default_value – that is returned in case of missing item.

  • glb – the global context.

Returns:

the value term in case given key exists, otherwise the default_value.

term interop_atom_term_select_atom(const AtomStringIntPair *table, int value, GlobalContext *global)

Finds the first matching atom in an atoms table .

Allows to quickly translate integer constants to an atom in an atoms table. This function is the inverse of interop_atom_term_select_int.

Parameters:
  • table – an array AtomStringIntPair structs, terminated with a default entry marked with SELECT_INT_DEFAULT macro.

  • value – the in value used for comparison.

  • global – the global context.

Returns:

the found atom which corresponds to the given int value, or the invalid term, if there is no such value in the table.

term interop_chars_to_list(const char *chars, size_t len, Heap *heap)
struct CharDataToBytesSizeAcc

Public Members

enum CharDataEncoding in_encoding
enum CharDataEncoding out_encoding
size_t size
size_t rest_size
bool badarg
bool incomplete_transform
struct CharDataToBytesAcc

Collaboration diagram for CharDataToBytesAcc:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "3" [label="HeapFragment" tooltip="HeapFragment"] "2" [label="Heap" tooltip="Heap"] "1" [label="CharDataToBytesAcc" tooltip="CharDataToBytesAcc" fillcolor="#BFBFBF"] "3" -> "3" [dir=forward tooltip="usage"] "2" -> "3" [dir=forward tooltip="usage"] "1" -> "2" [dir=forward tooltip="usage"] }

Public Members

enum CharDataEncoding in_encoding
enum CharDataEncoding out_encoding
uint8_t *output
term *rest
Heap *heap
bool badarg
bool incomplete_transform