Skip to content

Commit

Permalink
eval full string to avoid using Meta.parseall
Browse files Browse the repository at this point in the history
  • Loading branch information
efaulhaber committed Oct 2, 2023
1 parent 6363e6e commit 61b144d
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/meshes/mesh_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,32 +263,27 @@ function load_mesh_serial(mesh_file::AbstractString; n_cells_max, RealT)
size = Tuple(size_)

# TODO: `@eval` is evil
# A temporary workaround to evaluate the code that defines the domain mapping in a local scope.
# This prevents errors when multiple restart elixirs are executed in one session, where one
# defines `mapping` as a variable, while the other defines it as a function.
#
# This should be replaced with something more robust and secure,
# see https://github.com/trixi-framework/Trixi.jl/issues/541).
expr = Meta.parseall(mapping_as_string)
if expr.head == :toplevel
expr.head = :block
end

if ndims == 1
mapping = @eval function (xi)
$expr
mapping = eval(Meta.parse("""function (xi)
$mapping_as_string
mapping(xi)
end
"""))
elseif ndims == 2
mapping = @eval function (xi, eta)
$expr
mapping = eval(Meta.parse("""function (xi, eta)
$mapping_as_string
mapping(xi, eta)
end
"""))
else # ndims == 3
mapping = @eval function (xi, eta, zeta)
$expr
mapping = eval(Meta.parse("""function (xi, eta, zeta)
$mapping_as_string
mapping(xi, eta, zeta)
end
"""))
end

mesh = StructuredMesh(size, mapping; RealT = RealT, unsaved_changes = false,
Expand Down

0 comments on commit 61b144d

Please sign in to comment.