Skip to content

Foundation fixes for 32-bit systems and more #264

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 6 commits into from
Feb 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CoreFoundation/NumberDate.subproj/CFNumber.c
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType type, const vo
}
}

CFIndex size = 8 + ((!__CFNumberTypeTable[type].floatBit && __CFNumberTypeTable[type].storageBit) ? 8 : 0);
CFIndex size = (sizeof(struct __CFNumber) - sizeof(CFRuntimeBase)) + ((!__CFNumberTypeTable[type].floatBit && __CFNumberTypeTable[type].storageBit) ? 8 : 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, this seems to work just fine on 32 bit linked processes; I will have to do some digging to verify that...
The change listed here actually looks more correct.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux/arm the alignment is different, the _pad is found at 24, while CFRuntimeBase is 20 bytes long leading to an awful heap overflow.

#if OLD_CRAP_TOO
size += 2 * sizeof(void *);
#endif
Expand Down
16 changes: 14 additions & 2 deletions Foundation/NSDateFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class NSDateFormatter : NSFormatter {
#endif
let obj = CFDateFormatterCreate(kCFAllocatorSystemDefault, locale._cfObject, dateStyle, timeStyle)
// TODO: Set up attributes here
if let dateFormat = _dateFormat {
CFDateFormatterSetFormat(obj, dateFormat._cfObject)
}
__cfObject = obj
return obj
}
Expand Down Expand Up @@ -51,7 +54,7 @@ public class NSDateFormatter : NSFormatter {
}

public func dateFromString(string: String) -> NSDate? {
var range = CFRange()
var range = CFRange(location: 0, length: string.length)
let date = withUnsafeMutablePointer(&range) { (rangep: UnsafeMutablePointer<CFRange>) -> NSDate? in
guard let res = CFDateFormatterCreateDateFromString(kCFAllocatorSystemDefault, _cfObject, string._cfObject, rangep) else {
return nil
Expand Down Expand Up @@ -100,7 +103,16 @@ public class NSDateFormatter : NSFormatter {

public var timeStyle: NSDateFormatterStyle = .NoStyle { willSet { _reset() } }

/*@NSCopying*/ public var locale: NSLocale! { willSet { _reset() } }
internal var _locale: NSLocale = NSLocale.currentLocale()
/*@NSCopying*/ public var locale: NSLocale! {
get {
return _locale
}
set {
_reset()
_locale = newValue
}
}

public var generatesCalendarDates = false { willSet { _reset() } }

Expand Down
4 changes: 4 additions & 0 deletions Foundation/NSGeometry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public struct CGFloat {
public var native: NativeType

private var hash: Int {
#if arch(i386) || arch(arm)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish we had a #if 32bit or some sort of equiv; ala the discussion on swift-evolution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES!! I agree. I'd also love an endianness flag. :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have my tree where I have done endian([big|little]) and intsize(nn) but reading the discussion I decided to postpone the submission. :)

return Int(Float(self.native)._toBitPattern())
#else
return Int(self.native._toBitPattern())
#endif
}
}

Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSNumberFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class NSNumberFormatter : NSFormatter {
}

public func numberFromString(string: String) -> NSNumber? {
var range = CFRange()
var range = CFRange(location: 0, length: string.length)
let number = withUnsafeMutablePointer(&range) { (rangePointer: UnsafeMutablePointer<CFRange>) -> NSNumber? in

#if os(OSX) || os(iOS)
Expand Down
8 changes: 6 additions & 2 deletions Foundation/NSPathUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public func NSTemporaryDirectory() -> String {
}
#endif
if let tmpdir = NSProcessInfo.processInfo().environment["TMPDIR"] {
return tmpdir
if !tmpdir.hasSuffix("/") {
return tmpdir + "/"
} else {
return tmpdir
}
}
return "/tmp/"
}
Expand Down Expand Up @@ -644,4 +648,4 @@ internal func _NSCleanupTemporaryFile(auxFilePath: String, _ filePath: String) t
}
throw _NSErrorWithErrno(errno, reading: false, path: filePath)
}
}
}
1 change: 1 addition & 0 deletions Foundation/NSXMLElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public class NSXMLElement : NSXMLNode {
*/
public func attributeForName(name: String) -> NSXMLNode? {
let attribute = _CFXMLNodeHasProp(_xmlNode, name)
if attribute == nil { return nil }
return NSXMLNode._objectNodeForNode(attribute)
}

Expand Down