Dune.Parser.Opts (dune v0.2.1) View Source
Defines the parsing options for Dune, which restrict the code that can safely be executed.
See Dune.Eval.Opts
for runtime restriction options.
The available fields are:
atom_pool_size
: Defines the maximum total number of atoms that can be created. Must be an integer>= 0
. Defaults to5000
.max_length
: Defines the maximum length of code strings that can be parsed. Defaults to5000
.allowlist
: Defines which module and functions are considered safe or restricted. Should be a module implementing theDune.Allowlist
behaviour. Defaults toDune.Allowlist.Default
.
Extra note about atom_pool_size
Atoms are reused from one evaluation to the other so the total is not expected to grow. Atoms will not be leaked.
Also, the atom pool is actually split into several pools: regular atoms, module names,
unused variable names, ...
So defining a value of 100
does not mean that 100
atoms will be available, but
rather 25
of each type.
Atoms being very lightweight, there is no need to use a low value, as long as there is an upper bound preventing atom leaks.
Link to this section Summary
Functions
Validates untrusted options from a keyword or a map and returns a Dune.Parser.Opts
struct.
Link to this section Types
Specs
t() :: %Dune.Parser.Opts{ allowlist: module(), atom_pool_size: non_neg_integer(), max_length: term() }
Link to this section Functions
Specs
Validates untrusted options from a keyword or a map and returns a Dune.Parser.Opts
struct.
Examples
iex> Dune.Parser.Opts.validate!([])
%Dune.Parser.Opts{atom_pool_size: 5000, allowlist: Dune.Allowlist.Default}
iex> Dune.Parser.Opts.validate!(atom_pool_size: 10)
%Dune.Parser.Opts{atom_pool_size: 10, allowlist: Dune.Allowlist.Default}
iex> Dune.Parser.Opts.validate!(atom_pool_size: -10)
** (ArgumentError) atom_pool_size should be an integer >= 0
iex> Dune.Parser.Opts.validate!(allowlist: DoesNotExists)
** (ArgumentError) could not load module DoesNotExists due to reason :nofile
iex> Dune.Parser.Opts.validate!(allowlist: List)
** (ArgumentError) List does not implement the Dune.Allowlist behaviour