Skip to content

Commit ee61823

Browse files
committed
Merge branch 'swift-4.0.1-branch'
# Conflicts: # Foundation/JSONEncoder.swift # Foundation/URLSession/URLSessionTask.swift
2 parents 666ed07 + 4f6b3c8 commit ee61823

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#include <malloc/malloc.h>
3434
#endif
3535

36+
#if __has_include(<malloc/malloc.h>)
37+
#include <malloc/malloc.h>
38+
#endif
39+
3640
_CF_EXPORT_SCOPE_BEGIN
3741

3842
struct __CFSwiftObject {

Foundation/Decimal.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ extension Decimal : SignedNumeric {
327327
}
328328

329329
public mutating func negate() {
330+
guard _length != 0 else { return }
330331
_isNegative = _isNegative == 0 ? 1 : 0
331332
}
332333
}
@@ -1282,9 +1283,7 @@ fileprivate func integerSubtract(_ result: inout Decimal, _ left: inout Decimal,
12821283

12831284
public func NSDecimalSubtract(_ result: UnsafeMutablePointer<Decimal>, _ leftOperand: UnsafePointer<Decimal>, _ rightOperand: UnsafePointer<Decimal>, _ roundingMode: NSDecimalNumber.RoundingMode) -> NSDecimalNumber.CalculationError {
12841285
var r = rightOperand.pointee
1285-
if r._length != 0 {
1286-
r.negate()
1287-
}
1286+
r.negate()
12881287
return NSDecimalAdd(result, leftOperand, &r, roundingMode)
12891288
}
12901289
// Exact operations. result may be a pointer to same space as leftOperand or rightOperand

TestFoundation/TestDecimal.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ class TestDecimal: XCTestCase {
289289
XCTAssertEqual(.minus, d.sign)
290290
d.negate()
291291
XCTAssertEqual(.plus, d.sign)
292+
var e = Decimal(0)
293+
e.negate()
294+
XCTAssertEqual(e, 0)
292295
XCTAssertTrue(Decimal(3.5).isEqual(to: Decimal(3.5)))
293296
XCTAssertTrue(Decimal.nan.isEqual(to: Decimal.nan))
294297
XCTAssertTrue(Decimal(1.28).isLess(than: Decimal(2.24)))

0 commit comments

Comments
 (0)