Skip to content

Commit e4f0cb5

Browse files
author
Johannes Markert
committed
Adding convenient dispatch on type conversion.
1 parent 76d5295 commit e4f0cb5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/T8code.jl

+7
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ mutable struct ForestWrapper
212212
end
213213
end
214214

215+
Base.pointer(fw::ForestWrapper) = fw.pointer
216+
# This dispatched conversion allows to directly pass a ForestWrapper object to,
217+
# for example, `t8_forest_...` call. The following link leads to a lengthy
218+
# discussion about if this is a valid way to do achieve this:
219+
# https://discourse.julialang.org/t/how-to-use-ccall-cconvert-and-unsafe-convert-in-a-convenient-and-memory-safe-way/41932/18
220+
Base.unsafe_convert(::Type{Ptr{T8code.Libt8.t8_forest}}, fw::ForestWrapper) = fw.pointer
221+
215222
function clean_up()
216223
# Finalize all registered t8code objects before MPI shuts down.
217224
while length(T8CODE_OBJECT_TRACKER) > 0

0 commit comments

Comments
 (0)