You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, C unions and structs containing a union are wrapped as a julia struct having one field data with overwritten Base.getproperty and Base.setproperty! functions, e.g.
using CEnum
struct testunion
data::NTuple{4, UInt8}endfunction Base.getproperty(x::Ptr{testunion}, f::Symbol)
f ===:y&&returnPtr{Cint}(x +0)
returngetfield(x, f)
endfunction Base.getproperty(x::testunion, f::Symbol)
r =Ref{testunion}(x)
ptr = Base.unsafe_convert(Ptr{testunion}, r)
fptr =getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
endfunction Base.setproperty!(x::Ptr{testunion}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
endstruct teststruct
data::NTuple{8, UInt8}endfunction Base.getproperty(x::Ptr{teststruct}, f::Symbol)
f ===:x&&returnPtr{Cint}(x +0)
f ===:p&&returnPtr{testunion}(x +4)
returngetfield(x, f)
endfunction Base.getproperty(x::teststruct, f::Symbol)
r =Ref{teststruct}(x)
ptr = Base.unsafe_convert(Ptr{teststruct}, r)
fptr =getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
endfunction Base.setproperty!(x::Ptr{teststruct}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
This doesn' t allow to properly use fieldnames or propertynames (and similar functions) as they return (:data,) (or similar) and not the actual fields you can access by getproperty. The problem came up in trixi-framework/P4est.jl#72.
It isn't really the same issue? In #316 the autocomplete doesn't work for the Ptr{T} type, but it would work for struct T directly. In this issue, there is only the ":data" field in the struct. Way to the solution is probably quite different?
Currently, C
union
s andstruct
s containing aunion
are wrapped as a juliastruct
having one fielddata
with overwrittenBase.getproperty
andBase.setproperty!
functions, e.g.is wrapped as
This doesn' t allow to properly use
fieldnames
orpropertynames
(and similar functions) as they return(:data,)
(or similar) and not the actual fields you can access bygetproperty
. The problem came up in trixi-framework/P4est.jl#72.cc @ranocha, @sloede
The text was updated successfully, but these errors were encountered: