Skip to content

Commit

Permalink
Ensure the proper cconvert function is called during ccall
Browse files Browse the repository at this point in the history
  • Loading branch information
serenity4 committed Nov 27, 2023
1 parent 32cb3d6 commit e1d35a8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/prewrap/pointers.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Make sure our dispatches for vectors are hit before any other method.
# Unfortunately, we'll still need to add dispatches from `Base.cconvert` to this `cconvert`
# because `Base.cconvert` is what will be called during `ccall`s, not this function.
cconvert(T, x) = Base.cconvert(T, x)

Base.cconvert(T::Type{Ptr{Cvoid}}, x::Handle) = x
Expand All @@ -10,6 +12,16 @@ cconvert(T::Type{<:Ptr}, x::AbstractVector{<:VulkanStruct{false}}) = Base.cconve
cconvert(T::Type{<:Ptr}, x::AbstractVector{<:VulkanStruct{true}}) = (x, Base.cconvert(T, getproperty.(x, :vks)))
cconvert(T::Type{<:Ptr}, x::AbstractVector{<:HighLevelStruct}) = Base.cconvert(T, convert.(getproperty(@__MODULE__, Symbol(:_, nameof(eltype(x)))), x))

Base.cconvert(T::Type{<:Ptr}, x::AbstractVector{<:VulkanStruct{false}}) = cconvert(T, x)
Base.cconvert(T::Type{<:Ptr}, x::AbstractVector{<:VulkanStruct{true}}) = cconvert(T, x)
Base.cconvert(T::Type{<:Ptr}, x::AbstractVector{<:HighLevelStruct}) = cconvert(T, x)

# Shadow the otherwise more specific Base
# method `cconvert(::Type{Ptr{P<:Union{Cstring,Cwstring,Ptr}}}, ::Array)`.
Base.cconvert(T::Type{Ptr{P}}, x::Vector{<:VulkanStruct{false}}) where {P<:Ptr} = cconvert(T, x)
Base.cconvert(T::Type{Ptr{P}}, x::Vector{<:VulkanStruct{true}}) where {P<:Ptr} = cconvert(T, x)
Base.cconvert(T::Type{Ptr{P}}, x::Vector{<:HighLevelStruct}) where {P<:Ptr} = cconvert(T, x)

convert(T::Type{Ptr{Cvoid}}, x::Handle) = x.vks

unsafe_convert(T::Type, x::VulkanStruct) = x.vks
Expand Down

0 comments on commit e1d35a8

Please sign in to comment.