Skip to content

Compile time member offsets in PyObjects #18

Description

@LiarPrincess

Currently we use GenericLayout to calculate offsets of PyObject members (like this).

Instead we could do the usual offset/size dance:

extension PyObject {
  public static let member2Offset = calculateOffset(
    previousMemberOffset: Self.member1Offset,
    previousMemberSize: MemoryLayout<Member1Type>.size,
    alignment: MemoryLayout<Member2Type>.alignment
  )
}

func calculateOffset(previousMemberOffset: Int, previousMemberSize: Int, alignment: Int) -> Int {
  var offset = previousMemberOffset + previousMemberSize
  return round(offset, to: alignment)
}

Though, I have not checked what Swift compiler emits for the current version, so maybe it is not needed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions