-
Notifications
You must be signed in to change notification settings - Fork 2
Fix ItemInfo struct layout (ImGuiTestItemInfo bitfields) #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,39 +247,75 @@ end | |
|
|
||
|
|
||
| struct ImGuiTestItemInfo | ||
| ID::Cuint | ||
| DebugLabel::NTuple{32, Cchar} | ||
| Window::Ptr{ImGuiWindow} | ||
| NavLayer::Cuint | ||
| Depth::Cint | ||
| TimestampMain::Cint | ||
| TimestampStatus::Cint | ||
| ParentID::Cuint | ||
| RectFull::ImRect | ||
| RectClipped::ImRect | ||
| ItemFlags::Cint | ||
| StatusFlags::Cint | ||
| data::NTuple{96, UInt8} | ||
| end | ||
|
|
||
| function Base.getproperty(x::Ptr{ImGuiTestItemInfo}, f::Symbol) | ||
| f === :ID && return Ptr{Cuint}(x + 0) | ||
| f === :DebugLabel && return Ptr{NTuple{32, Cchar}}(x + 4) | ||
| f === :Window && return Ptr{Ptr{ImGuiWindow}}(x + 36) | ||
| f === :NavLayer && return Ptr{Cuint}(x + 40) | ||
| f === :Depth && return Ptr{Cint}(x + 44) | ||
| f === :TimestampMain && return Ptr{Cint}(x + 48) | ||
| f === :TimestampStatus && return Ptr{Cint}(x + 52) | ||
| f === :ParentID && return Ptr{Cuint}(x + 56) | ||
| f === :RectFull && return Ptr{ImRect}(x + 60) | ||
| f === :RectClipped && return Ptr{ImRect}(x + 76) | ||
| f === :ItemFlags && return Ptr{Cint}(x + 92) | ||
| f === :StatusFlags && return Ptr{Cint}(x + 96) | ||
| f === :NavLayer && return (Ptr{Cuint}(x + 40), 0, 1) | ||
| f === :Depth && return (Ptr{Cint}(x + 40), 1, 16) | ||
| f === :TimestampMain && return Ptr{Cint}(x + 44) | ||
| f === :TimestampStatus && return Ptr{Cint}(x + 48) | ||
| f === :ParentID && return Ptr{Cuint}(x + 52) | ||
| f === :RectFull && return Ptr{ImRect}(x + 56) | ||
| f === :RectClipped && return Ptr{ImRect}(x + 72) | ||
| f === :ItemFlags && return Ptr{Cint}(x + 88) | ||
| f === :StatusFlags && return Ptr{Cint}(x + 92) | ||
| return getfield(x, f) | ||
| end | ||
|
|
||
| function Base.getproperty(x::ImGuiTestItemInfo, f::Symbol) | ||
| r = Ref{ImGuiTestItemInfo}(x) | ||
| ptr = Base.unsafe_convert(Ptr{ImGuiTestItemInfo}, r) | ||
| fptr = getproperty(ptr, f) | ||
| begin | ||
| if fptr isa Ptr | ||
| return GC.@preserve(r, unsafe_load(fptr)) | ||
| else | ||
| (baseptr, offset, width) = fptr | ||
| ty = eltype(baseptr) | ||
| baseptr32 = convert(Ptr{UInt32}, baseptr) | ||
| u64 = GC.@preserve(r, unsafe_load(baseptr32)) | ||
| if offset + width > 32 | ||
| u64 |= GC.@preserve(r, unsafe_load(baseptr32 + 4)) << 32 | ||
| end | ||
| u64 = u64 >> offset & (1 << width - 1) | ||
| return u64 % ty | ||
| end | ||
| end | ||
| end | ||
|
|
||
| function Base.setproperty!(x::Ptr{ImGuiTestItemInfo}, f::Symbol, v) | ||
| unsafe_store!(getproperty(x, f), v) | ||
| fptr = getproperty(x, f) | ||
| if fptr isa Ptr | ||
| unsafe_store!(getproperty(x, f), v) | ||
| else | ||
| (baseptr, offset, width) = fptr | ||
| baseptr32 = convert(Ptr{UInt32}, baseptr) | ||
| u64 = unsafe_load(baseptr32) | ||
| straddle = offset + width > 32 | ||
| if straddle | ||
| u64 |= unsafe_load(baseptr32 + 4) << 32 | ||
| end | ||
| mask = 1 << width - 1 | ||
| u64 &= ~(mask << offset) | ||
| u64 |= (unsigned(v) & mask) << offset | ||
| unsafe_store!(baseptr32, u64 & typemax(UInt32)) | ||
| if straddle | ||
| unsafe_store!(baseptr32 + 4, u64 >> 32) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| function Base.propertynames(x::ImGuiTestItemInfo, private::Bool = false) | ||
| (:ID, :DebugLabel, :Window, :NavLayer, :Depth, :TimestampMain, :TimestampStatus, :ParentID, :RectFull, :RectClipped, :ItemFlags, :StatusFlags, if private | ||
| fieldnames(typeof(x)) | ||
| else | ||
| () | ||
| end...) | ||
| end | ||
|
|
||
| struct ImVector_ImGuiTestItemInfo | ||
| Size::Cint | ||
|
|
@@ -439,7 +475,7 @@ struct ImGuiTestGenericItemStatus | |
| DeactivatedAfterEdit::Cint | ||
| end | ||
|
|
||
| struct ImGuiTestGenericVars | ||
| mutable struct ImGuiTestGenericVars | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this and other structs now mutable?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's Clang.jl-generated... |
||
| Step::Cint | ||
| Count::Cint | ||
| DockId::Cuint | ||
|
|
@@ -488,10 +524,34 @@ struct ImVector_ImGuiTestRunTask | |
| end | ||
|
|
||
| struct ImGuiTestInfoTask | ||
| ID::Cuint | ||
| FrameCount::Cint | ||
| DebugName::NTuple{64, Cchar} | ||
| Result::ImGuiTestItemInfo | ||
| data::NTuple{168, UInt8} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somehow it seems odd to me that a struct containing bitfield structs as fields itself gets treated as a bitfield struct by Clang 🤔 @Gnimuc, do you know if that's right? It looks like it calculates the offsets correctly and everything, I just don't know if it's actually needed. |
||
| end | ||
|
|
||
| function Base.getproperty(x::Ptr{ImGuiTestInfoTask}, f::Symbol) | ||
| f === :ID && return Ptr{Cuint}(x + 0) | ||
| f === :FrameCount && return Ptr{Cint}(x + 4) | ||
| f === :DebugName && return Ptr{NTuple{64, Cchar}}(x + 8) | ||
| f === :Result && return Ptr{ImGuiTestItemInfo}(x + 72) | ||
| return getfield(x, f) | ||
| end | ||
|
|
||
| function Base.getproperty(x::ImGuiTestInfoTask, f::Symbol) | ||
| r = Ref{ImGuiTestInfoTask}(x) | ||
| ptr = Base.unsafe_convert(Ptr{ImGuiTestInfoTask}, r) | ||
| fptr = getproperty(ptr, f) | ||
| GC.@preserve r unsafe_load(fptr) | ||
| end | ||
|
|
||
| function Base.setproperty!(x::Ptr{ImGuiTestInfoTask}, f::Symbol, v) | ||
| unsafe_store!(getproperty(x, f), v) | ||
| end | ||
|
|
||
| function Base.propertynames(x::ImGuiTestInfoTask, private::Bool = false) | ||
| (:ID, :FrameCount, :DebugName, :Result, if private | ||
| fieldnames(typeof(x)) | ||
| else | ||
| () | ||
| end...) | ||
| end | ||
|
|
||
| struct ImVector_ImGuiTestInfoTask_Ptr | ||
|
|
@@ -783,40 +843,9 @@ end | |
| end | ||
|
|
||
| struct ImGuiTestContext | ||
| GenericVars::ImGuiTestGenericVars | ||
| UserVars::Ptr{Cvoid} | ||
| UiContext::Ptr{ImGuiContext} | ||
| EngineIO::Ptr{ImGuiTestEngineIO} | ||
| Test::Ptr{ImGuiTest} | ||
| TestOutput::Ptr{ImGuiTestOutput} | ||
| OpFlags::Cint | ||
| PerfStressAmount::Cint | ||
| FrameCount::Cint | ||
| FirstTestFrameCount::Cint | ||
| FirstGuiFrame::Bool | ||
| HasDock::Bool | ||
| CaptureArgs::Ptr{ImGuiCaptureArgs} | ||
| Engine::Ptr{ImGuiTestEngine} | ||
| Inputs::Ptr{ImGuiTestInputs} | ||
| RunFlags::Cint | ||
| ActiveFunc::ImGuiTestActiveFunc | ||
| RunningTime::Cdouble | ||
| ActionDepth::Cint | ||
| CaptureCounter::Cint | ||
| ErrorCounter::Cint | ||
| Abort::Bool | ||
| PerfRefDt::Cdouble | ||
| PerfIterations::Cint | ||
| RefStr::NTuple{256, Cchar} | ||
| RefID::Cuint | ||
| RefWindowID::Cuint | ||
| InputMode::ImGuiInputSource | ||
| TempString::ImVector_char | ||
| Clipboard::ImVector_char | ||
| ForeignWindowsToHide::ImVector_ImGuiWindowPtr | ||
| DummyItemInfoNull::ImGuiTestItemInfo | ||
| CachedLinesPrintedToTTY::Bool | ||
| data::NTuple{1312, UInt8} | ||
| end | ||
|
|
||
| function Base.getproperty(x::Ptr{ImGuiTestContext}, f::Symbol) | ||
| f === :GenericVars && return Ptr{ImGuiTestGenericVars}(x + 0) | ||
| f === :UserVars && return Ptr{Ptr{Cvoid}}(x + 812) | ||
|
|
@@ -850,14 +879,28 @@ function Base.getproperty(x::Ptr{ImGuiTestContext}, f::Symbol) | |
| f === :Clipboard && return Ptr{ImVector_char}(x + 1188) | ||
| f === :ForeignWindowsToHide && return Ptr{ImVector_ImGuiWindowPtr}(x + 1200) | ||
| f === :DummyItemInfoNull && return Ptr{ImGuiTestItemInfo}(x + 1212) | ||
| f === :CachedLinesPrintedToTTY && return Ptr{Bool}(x + 1312) | ||
| f === :CachedLinesPrintedToTTY && return Ptr{Bool}(x + 1308) | ||
| return getfield(x, f) | ||
| end | ||
|
|
||
| function Base.getproperty(x::ImGuiTestContext, f::Symbol) | ||
| r = Ref{ImGuiTestContext}(x) | ||
| ptr = Base.unsafe_convert(Ptr{ImGuiTestContext}, r) | ||
| fptr = getproperty(ptr, f) | ||
| GC.@preserve r unsafe_load(fptr) | ||
| end | ||
|
|
||
| function Base.setproperty!(x::Ptr{ImGuiTestContext}, f::Symbol, v) | ||
| unsafe_store!(getproperty(x, f), v) | ||
| end | ||
|
|
||
| function Base.propertynames(x::ImGuiTestContext, private::Bool = false) | ||
| (:GenericVars, :UserVars, :UiContext, :EngineIO, :Test, :TestOutput, :OpFlags, :PerfStressAmount, :FrameCount, :FirstTestFrameCount, :FirstGuiFrame, :HasDock, :CaptureArgs, :Engine, :Inputs, :RunFlags, :ActiveFunc, :RunningTime, :ActionDepth, :CaptureCounter, :ErrorCounter, :Abort, :PerfRefDt, :PerfIterations, :RefStr, :RefID, :RefWindowID, :InputMode, :TempString, :Clipboard, :ForeignWindowsToHide, :DummyItemInfoNull, :CachedLinesPrintedToTTY, if private | ||
| fieldnames(typeof(x)) | ||
| else | ||
| () | ||
| end...) | ||
| end | ||
|
|
||
| mutable struct ImBuildInfo | ||
| Type::Ptr{Cchar} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to update the changelog entry for the new release.