-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Use CFNumberCreate()
as factory initializer on NSNumber
#1093
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
swift-ci
merged 12 commits into
swiftlang:master
from
norio-nomura:use-factory-initializer-on-nsnumber
Jul 3, 2017
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0a7ddcb
Add `TestNSNumber.test_objCType()` reproducing SR-4907
norio-nomura 67c7981
Add missing entry to `TestNumber.allTests`
norio-nomura 00737ae
Change `NSNumber.init(value: Bool)` to returning `__NSCFBoolean` by u…
norio-nomura 3cbad1d
Change `JSONSerialization` to use `_cfTypeID` for checking whether `N…
norio-nomura 070cf25
Update test_objCType
norio-nomura 358b4f3
Explicitly declare `_Factory` protocol as `internal`
norio-nomura b19da15
Change `NSNumber` to initialize with `CFNumberCreate()`
norio-nomura 0592ccf
Fix `NSKeyedUnarchiver.decodeBool(forKey:)` and add test to `TestNSPr…
norio-nomura b9fa1ac
Stop using `@_silgen_name`
norio-nomura bb182da
Remove stored instance properties from `NSNumber`
norio-nomura 5a26410
`_CFNumberGetType2` only emit `SInt*` and `Float*` types
norio-nomura 829de81
Revert "Remove stored instance properties from `NSNumber`"
norio-nomura File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I like this trick better than the way I was thinking, however I wonder if we have a guarantee this is safe?
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.
Wouldn't the static string need to be a static property to guarantee its lifetime?
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.
I am not fully certain which way this falls, constant strings should emit static references in the binary so it is probably safe-ish?
We have a few alternatives; we could thunk out to C and use the real
@encode
since we always have clang available. We could thunk out to C and reference C strings as opaque memory blobs. This approach. Or the other thought I had was something like this https://gist.github.com/phausler/2630092f1b391d6a5db0a562288514bfThere 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.
I was thinking along the same lines, but simpler:
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.
yea, I think there is also value in abstracting it out to an isolated file to do that work in and provide a shared internal (minimal) version of
@encode
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.
I discarded following codes that rewrote
_NSSimpleObjCType
inNSObjCRuntime.swift
, since memory layout is not compatible with current implementation.https://gist.github.com/norio-nomura/a1383f258c38bb1e081597a538f46e8f
Should we create another static values for
@encode
?I feel we should do re-writing
_NSSimpleObjCType
instead of adding them, and doing that with this PR will make it too large.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.
As I tested,
utf8Start
points directly cstring in__TEXT,__cstring,cstring_literals
whetherStaticString
is instantiated as static variable or function parameter.