Skip to content

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

Merged
merged 1 commit into from
Aug 13, 2016

Conversation

garyliu1
Copy link

Previous s390x PR #386 has a change to make the _length field of CF_CONST_STRING to uint64_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

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
Copy link
Contributor

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?

Copy link
Author

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

@parkera
Copy link
Contributor

parkera commented Jul 21, 2016

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?

@parkera
Copy link
Contributor

parkera commented Jul 21, 2016

@swift-ci please test

@garyliu1
Copy link
Author

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.

@parkera
Copy link
Contributor

parkera commented Jul 25, 2016

@swift-ci please test

@parkera
Copy link
Contributor

parkera commented Jul 25, 2016

Looks like an unrelated failure in swiftpm.

@garyliu1
Copy link
Author

garyliu1 commented Aug 8, 2016

@parkera, I've resolved the conflict with a modified change. Can you re-issue a test request please?

Thanks

@parkera
Copy link
Contributor

parkera commented Aug 8, 2016

@swift-ci please test linux

@parkera
Copy link
Contributor

parkera commented Aug 8, 2016

yup!

@parkera
Copy link
Contributor

parkera commented Aug 13, 2016

Tested manually

@parkera parkera merged commit 980e3c0 into swiftlang:master Aug 13, 2016
@garyliu1
Copy link
Author

@parkera Thanks Tony!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants