Skip to content
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

Compile time member offsets in PyObjects #18

Open
LiarPrincess opened this issue May 25, 2022 · 0 comments
Open

Compile time member offsets in PyObjects #18

LiarPrincess opened this issue May 25, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@LiarPrincess
Copy link
Owner

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.

@LiarPrincess LiarPrincess added the enhancement New feature or request label May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant