Skip to content

Commit

Permalink
fixup! extract_variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Joroks committed Jun 27, 2024
1 parent c407391 commit 028e52a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/LAMMPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ function extract_variable(lmp::LMP, name::String, lmp_variable::LMP_VARIABLE, gr
expect = extract_variable_datatype(lmp, name)
recieve = get_enum(lmp_variable)
if expect != recieve
if expect in (API.LMP_VAR_ATOM, API.LMP_VAR_VECTOR)
# the documentation instructs us to free the pointers for these styles specifically
if expect in (API.LMP_VAR_ATOM, API.LMP_VAR_EQUAL)
API.lammps_free(void_ptr)
end

Expand All @@ -542,6 +543,10 @@ function extract_variable(lmp::LMP, name::String, lmp_variable::LMP_VARIABLE, gr
end

if lmp_variable == VAR_VECTOR
# Calling lammps_extract_variable directly through the API instead of the higher level wrapper, as
# "GET_VECTOR_SIZE" is the only group name that won't be ignored for Vector Style Variables.
# This isn't exposed to the high level API as it causes type instability for something that probably won't
# ever be used outside of this implementation
ndata_ptr = _lammps_reinterpret(LAMMPS_INT, API.lammps_extract_variable(lmp, name, "GET_VECTOR_SIZE"))
ndata = unsafe_load(ndata_ptr)
API.lammps_free(ndata_ptr)
Expand Down

0 comments on commit 028e52a

Please sign in to comment.