-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix _length access on CF_CONST_STRING for s390x #457
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
Conversation
let ptr = unsafeAddress(of: self) + offset | ||
return UnsafePointer<UInt64>(ptr).pointee | ||
} | ||
#else | ||
internal var _length : UInt32 { | ||
let offset = sizeof(OpaquePointer.self) + sizeof(Int32.self) + sizeof(Int32.self) + sizeof(_CFInfo.self) + sizeof(UnsafePointer<UInt8>.self) | ||
let ptr = unsafeAddress(of: self) + offset | ||
return UnsafePointer<UInt32>(ptr).pointee |
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.
Can we more tightly scope this conditional code, so as not to duplicate the rest?
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.
Thanks for the comment @parkera, how about something like this instead?
private var _lenPtr : UnsafePointer<Void> {
let offset = sizeof(OpaquePointer.self) + sizeof(Int32.self) + sizeof(Int32.self) + sizeof(_CFInfo.self) + sizeof(UnsafePointer<UInt8>.self)
return unsafeAddress(of: self) + offset
}
#if arch(s390x)
internal var _length : UInt64 {
return UnsafePointer<UInt64>(_lenPtr).pointee
}
#else
internal var _length : UInt32 {
return UnsafePointer<UInt32>(_lenPtr).pointee
}
#endif
I guess that's better. What makes me nervous is having fundamental things like the size of that field depend on platform. It's 32 bits even on other 64 bit platforms, so if we start adding a lot of special cases like this all over the place then maintenance will be extremely difficult. Do you anticipate this difference in the definition of the constant CFString size to affect any other places? |
@swift-ci please test |
Thanks @parkera. s390x and ppc64 (not ppc64le) are the ones I know that need 64 bit. I did a sanity search for other uses of the _length field and didn't spot any other occurrences that needs attention. |
@swift-ci please test |
Looks like an unrelated failure in swiftpm. |
@parkera, I've resolved the conflict with a modified change. Can you re-issue a test request please? Thanks |
@swift-ci please test linux |
yup! |
Tested manually |
@parkera Thanks Tony! |
Previous s390x PR #386 has a change to make the
_length
field ofCF_CONST_STRING
touint64_t
. This requires a subsequent change to access the field correctly in_NSCFConstantString
.This change has been tested and verified to have no regression on x86-64. On s390x, we see a good pass rate jump including TestNSURL, TestNSCalendar and TestNSNotificationQueue