Merge pull request #264 from hpux735/arm-fixes

Foundation fixes for 32-bit systems and more
diff --git a/CoreFoundation/NumberDate.subproj/CFNumber.c b/CoreFoundation/NumberDate.subproj/CFNumber.c
index a180815..46cd9ab 100644
--- a/CoreFoundation/NumberDate.subproj/CFNumber.c
+++ b/CoreFoundation/NumberDate.subproj/CFNumber.c
@@ -1202,7 +1202,7 @@
 	}
     }
 
-    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);
 #if OLD_CRAP_TOO
     size += 2 * sizeof(void *);
 #endif
diff --git a/Foundation/NSDateFormatter.swift b/Foundation/NSDateFormatter.swift
index ec35ed8..dff51ab 100644
--- a/Foundation/NSDateFormatter.swift
+++ b/Foundation/NSDateFormatter.swift
@@ -23,6 +23,9 @@
             #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
         }
@@ -51,7 +54,7 @@
     }
 
     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
@@ -100,7 +103,16 @@
 
     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() } }
 
diff --git a/Foundation/NSGeometry.swift b/Foundation/NSGeometry.swift
index dd9aad5..4cbd468 100644
--- a/Foundation/NSGeometry.swift
+++ b/Foundation/NSGeometry.swift
@@ -33,7 +33,11 @@
     public var native: NativeType
     
     private var hash: Int {
+#if arch(i386) || arch(arm)
+        return Int(Float(self.native)._toBitPattern())
+#else
         return Int(self.native._toBitPattern())
+#endif
     }
 }
 
diff --git a/Foundation/NSNumberFormatter.swift b/Foundation/NSNumberFormatter.swift
index eef11fe..2c46db4 100644
--- a/Foundation/NSNumberFormatter.swift
+++ b/Foundation/NSNumberFormatter.swift
@@ -59,7 +59,7 @@
     }
     
     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)
diff --git a/Foundation/NSPathUtilities.swift b/Foundation/NSPathUtilities.swift
index 15d6700..10a0c0a 100644
--- a/Foundation/NSPathUtilities.swift
+++ b/Foundation/NSPathUtilities.swift
@@ -24,7 +24,11 @@
     }
     #endif
     if let tmpdir = NSProcessInfo.processInfo().environment["TMPDIR"] {
-        return tmpdir
+        if !tmpdir.hasSuffix("/") {
+            return tmpdir + "/"
+        } else {
+            return tmpdir
+        }
     }
     return "/tmp/"
 }
@@ -644,4 +648,4 @@
         }
         throw _NSErrorWithErrno(errno, reading: false, path: filePath)
     }
-}
\ No newline at end of file
+}
diff --git a/Foundation/NSXMLElement.swift b/Foundation/NSXMLElement.swift
index 76cee7a..221c7c3 100644
--- a/Foundation/NSXMLElement.swift
+++ b/Foundation/NSXMLElement.swift
@@ -159,6 +159,7 @@
     */
     public func attributeForName(name: String) -> NSXMLNode? {
         let attribute = _CFXMLNodeHasProp(_xmlNode, name)
+        if attribute == nil { return nil }
         return NSXMLNode._objectNodeForNode(attribute)
     }