interop.h

Include dependency graph for interop.h:

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

This graph shows which files directly or indirectly include interop.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "7" [label="/__w/AtomVM/AtomVM/src/libAtomVM/interop.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/interop.c"]
    "1" [label="/__w/AtomVM/AtomVM/src/libAtomVM/interop.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/interop.h" fillcolor="#BFBFBF"]
    "8" [label="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.c"]
    "9" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_crypto.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_crypto.c"]
    "4" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_net.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_net.c"]
    "3" [label="/__w/AtomVM/AtomVM/src/libAtomVM/inet.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/inet.c"]
    "11" [label="/__w/AtomVM/AtomVM/src/libAtomVM/term.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/term.c"]
    "2" [label="/__w/AtomVM/AtomVM/src/libAtomVM/inet.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/inet.h"]
    "5" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_socket.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_socket.c"]
    "6" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c"]
    "10" [label="/__w/AtomVM/AtomVM/src/libAtomVM/posix_nifs.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/posix_nifs.c"]
    "1" -> "2" [dir=back tooltip="include"]
    "1" -> "7" [dir=back tooltip="include"]
    "1" -> "8" [dir=back tooltip="include"]
    "1" -> "9" [dir=back tooltip="include"]
    "1" -> "4" [dir=back tooltip="include"]
    "1" -> "5" [dir=back tooltip="include"]
    "1" -> "6" [dir=back tooltip="include"]
    "1" -> "10" [dir=back tooltip="include"]
    "1" -> "11" [dir=back tooltip="include"]
    "2" -> "3" [dir=back tooltip="include"]
    "2" -> "4" [dir=back tooltip="include"]
    "2" -> "5" [dir=back tooltip="include"]
    "2" -> "6" [dir=back tooltip="include"]
}

Defines

SELECT_INT_DEFAULT(i_val)

{                             \

.as_val = NULL, i_val     \

}


An idiomatic macro for marking an AtomStringIntPair table entry as a interop_atom_term_select_int default.

Typedefs

typedef InteropFunctionResult (*interop_chardata_fold_fun)(term t, void *accum)
typedef void (*interop_chardata_rest_fun)(term t, void *accum)

Enums

enum InteropFunctionResult

Values:

enumerator InteropOk
enumerator InteropMemoryAllocFail
enumerator InteropBadArg
enum UnicodeConversionResult

Values:

enumerator UnicodeOk = InteropOk
enumerator UnicodeMemoryAllocFail = InteropMemoryAllocFail
enumerator UnicodeBadArg = InteropBadArg
enumerator UnicodeError
enumerator UnicodeIncompleteTransform
enum CharDataEncoding

Values:

enumerator Latin1Encoding
enumerator UTF8Encoding
enumerator UCS4NativeEncoding

Functions

char *interop_term_to_string(term t, int *ok)
char *interop_binary_to_string(term binary)
char *interop_list_to_utf8_string(term list, int *ok)
char *interop_list_to_string(term list, int *ok)
char *interop_iolist_to_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)
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)
term interop_chars_to_list(const char *chars, size_t len, Heap *heap)
NO_DISCARD InteropFunctionResult interop_iolist_size (term t, size_t *size)
NO_DISCARD InteropFunctionResult interop_write_iolist (term t, char *p)
inline NO_DISCARD InteropFunctionResult interop_chardata_fold (term t, interop_chardata_fold_fun fold_fun, interop_chardata_rest_fun rest_fun, void *accum)
NO_DISCARD enum UnicodeConversionResult interop_chardata_to_bytes_size (term t, size_t *size, size_t *rest_size, enum CharDataEncoding in_encoding, enum CharDataEncoding out_encoding)
NO_DISCARD enum UnicodeConversionResult interop_chardata_to_bytes (term t, uint8_t *output, term *rest, enum CharDataEncoding in_encoding, enum CharDataEncoding out_encoding, Heap *heap)
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_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_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.

static inline term interop_kv_get_value(term kv, AtomString key, 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. This function returns the invalid term if there is no such entry in kv.

Parameters:
  • kv – any proplist or map.

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

  • glb – the global context.

Returns:

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

static inline term interop_bytes_to_list(const void *bytes, int len, Heap *heap)
struct AtomStringIntPair
#include <interop.h>

A structure to represent atom strings and int pairs. Such as {“\x8” “universe”, 42}.

Public Members

AtomString as_val
int i_val