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

[SR-439] Cached floating-point CF values do not bridge #4183

Closed
lhoward opened this issue Jan 2, 2016 · 6 comments
Closed

[SR-439] Cached floating-point CF values do not bridge #4183

lhoward opened this issue Jan 2, 2016 · 6 comments
Assignees

Comments

@lhoward
Copy link
Contributor

lhoward commented Jan 2, 2016

Previous ID SR-439
Radar None
Original Reporter @lhoward
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @lhoward
Priority Medium

md5: 2aa412194ae7a2adb1b033486a975c53

relates to:

  • SR-377 Implement NSKeyed[Un]Archiver

Issue Description:

Noticed this whilst working on NSKeyedUnarchiver.

Decoding <real> values that are integers is stomping on a CFNumber somewhere (looks like the isa pointer is invalid, as a result it fails to cast to a NSNumber and _expensivePropertyListConversion() fails).

fatal error: Attempt to convert a non-plist type <CFNumber 0x7efc06b16ff8 [0x7efc06b16848]>{value = +1.00000000000000000000, type = kCFNumberFloat64Type}: file Foundation/NSPropertyList.swift, line 144
@lhoward
Copy link
Contributor Author

lhoward commented Jan 2, 2016

This may be a simpler demonstration:

var floatVal : Double = 1.0
let cf = CFNumberCreate(kCFAllocatorSystemDefault, kCFNumberFloat64Type, &floatVal)!
print("\(cf)")
print("\(cf.dynamicType)")

returns:

<CFNumber 0x7f4197cbbff8 [0x7f4197cbb848]>{value = +1.00000000000000000000, type = kCFNumberFloat64Type}
__NSCFType

changing floatVal to 1.01 returns:

1.01
NSNumber

@lhoward
Copy link
Contributor Author

lhoward commented Jan 2, 2016

Also an issue for 32-bit floats.

@lhoward
Copy link
Contributor Author

lhoward commented Jan 2, 2016

Ah, it's not to do with integer-ness, it's caching – kCFNumberFloat32Zero/kCFNumberFloat32One are not being bridged correctly. CFGetTypeID() returns 0.

@lhoward
Copy link
Contributor Author

lhoward commented Jan 2, 2016

I'm going to take a punt on the problem being that the cached objects are created before __CFInitializeSwift() is called and that this is probably also an issue for kCFBooleanTrue/kCFBooleanFalse (which are interestingly explicitly bridged in _expensivePropertyListConversion) and kCFNull (which only appears to be used by NSURL). (Edit: not an issue as CFBoolean and CFNull are not bridged.)

Obviously a quick workaround would be to add explicit bridges for floating point 0/1 in _expensiveProperyListConversion but I'll try find the right fix.

@lhoward
Copy link
Contributor Author

lhoward commented Jan 2, 2016

Patch in #207

@lhoward
Copy link
Contributor Author

lhoward commented Jan 2, 2016

integrated in c9e528a

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant