schafdog
(Dennis Schafroth)
January 25, 2017, 10:04pm
1
Hi
Trying to do some simple date parsing from syslog format (“Jan 25 20:21:22”) into Date. Seem to work once but crashes on second call
func dateConv(_ dateString: String) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM dd HH:mm"
dateFormatter.locale = Locale(identifier: "da_DK_POSIX")
if let date = dateFormatter.date(from: dateString) {
print("Real date: \(date)" )
return date
}
return nil
}
var date = dateConv("Jan 25 20:10")
var date2 = dateConv("Jan 25 20:11”)
# swift main.swift
Real date: 2000-01-25 19:10:00 +0000
0 swift 0x000000000334ab78 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x0000000003349346 llvm::sys::RunSignalHandlers() + 54
2 swift 0x000000000334b6aa
3 libpthread.so.0 0x00007fec92166890
4 libswiftCore.so 0x00007fec8e8f0735
5 libFoundation.so 0x00007fec8c0ab6ee
6 libFoundation.so 0x00007fec8bd7a222
7 libFoundation.so 0x00007fec8bd7c623
8 libFoundation.so 0x00007fec8bf0e873 _TFC10Foundation6NSDateg11descriptionSS + 99
9 libFoundation.so 0x00007fec8c182829 _TTWV10Foundation4Dates23CustomStringConvertibleS_FS1_g11descriptionSS + 57
10 libswiftCore.so 0x00007fec8e78c745 _TFs15_print_unlockedu0_R_s16TextOutputStreamrFTxRq__T_ + 997
using swift 3.0.1. Am I doing something wrong? I seems to work on macOS.
cheers,
:-Dennis
Check out your parentheses. The last one is a right curly quote not the straight ascii quote that it should be.
···
On Jan 25, 2017, at 5:04 PM, Dennis Schafroth via swift-users <swift-users@swift.org> wrote:
Hi
Trying to do some simple date parsing from syslog format (“Jan 25 20:21:22”) into Date. Seem to work once but crashes on second call
func dateConv(_ dateString: String) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM dd HH:mm"
dateFormatter.locale = Locale(identifier: "da_DK_POSIX")
if let date = dateFormatter.date(from: dateString) {
print("Real date: \(date)" )
return date
}
return nil
}
var date = dateConv("Jan 25 20:10")
var date2 = dateConv("Jan 25 20:11”)
We should run those tests with ASAN, I thought I had fixed that with the Sierra merge.
···
Sent from my iPhone
On Jan 25, 2017, at 6:11 PM, Will Stanton via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:
Based on the backtrace, I think the code is running into a memory issue with Swift Foundation:
[SR-2485] Segmentation fault in Date · Issue #4331 · apple/swift-corelibs-foundation · GitHub
[SR-2462] Compiler is sometimes overreleasing CF objects · Issue #45067 · apple/swift · GitHub
I haven’t seen this in a while - are you able to try running on Swift 3.1 or 3.0.2?
Your code seems to work on the IBM Sandbox with 3.0.2 but not 3.0.1.
You could also try replacing every 'let’ with ‘var’ but that might not be the right solution :-)
Regards,
Will Stanton
On Jan 25, 2017, at 5:04 PM, Dennis Schafroth via swift-users <swift-users@swift.org> wrote:
Hi
Trying to do some simple date parsing from syslog format (“Jan 25 20:21:22”) into Date. Seem to work once but crashes on second call
func dateConv(_ dateString: String) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM dd HH:mm"
dateFormatter.locale = Locale(identifier: "da_DK_POSIX")
if let date = dateFormatter.date(from: dateString) {
print("Real date: \(date)" )
return date
}
return nil
}
var date = dateConv("Jan 25 20:10")
var date2 = dateConv("Jan 25 20:11”)
# swift main.swift
Real date: 2000-01-25 19:10:00 +0000
0 swift 0x000000000334ab78 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x0000000003349346 llvm::sys::RunSignalHandlers() + 54
2 swift 0x000000000334b6aa
3 libpthread.so.0 0x00007fec92166890
4 libswiftCore.so 0x00007fec8e8f0735
5 libFoundation.so 0x00007fec8c0ab6ee
6 libFoundation.so 0x00007fec8bd7a222
7 libFoundation.so 0x00007fec8bd7c623
8 libFoundation.so 0x00007fec8bf0e873 _TFC10Foundation6NSDateg11descriptionSS + 99
9 libFoundation.so 0x00007fec8c182829 _TTWV10Foundation4Dates23CustomStringConvertibleS_FS1_g11descriptionSS + 57
10 libswiftCore.so 0x00007fec8e78c745 _TFs15_print_unlockedu0_R_s16TextOutputStreamrFTxRq__T_ + 997
using swift 3.0.1. Am I doing something wrong? I seems to work on macOS.
cheers,
:-Dennis
_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev
Based on the backtrace, I think the code is running into a memory issue with Swift Foundation:
opened 07:10PM - 25 Aug 16 UTC
closed 08:27PM - 27 Aug 18 UTC
bug
Foundation
RunTimeCrash
Linux
| | |
|------------------|-----------------|…
|Previous ID | SR-2485 |
|Radar | None |
|Original Reporter | sigge75 (JIRA User) |
|Type | Bug |
|Status | Resolved |
|Resolution | Done |
<details>
<summary>Environment</summary>
Ubuntu 15.10 Desktop on Parallels 12
MacBook Pro ca 2012 (1st gen retina), OSX El Capitan
</details>
<details>
<summary>Additional Detail from JIRA</summary>
| | |
|------------------|-----------------|
|Votes | 2 |
|Component/s | Foundation |
|Labels | Bug, Linux, RunTimeCrash |
|Assignee | None |
|Priority | Medium |
md5: eadbe71e96fe163f2418e8f283419c9e
</details>
**relates to**:
* [SR-2462](https://bugs.swift.org/browse/SR-2462) Compiler is sometimes overreleasing CF objects
**Issue Description:**
Printing date 4 times triggers segmentation fault. The following code prints the date three times. It is always on the fourth iteration the segfault occurs.
``` java
for _ in 0..<4 { print(Date()) }
```
The bug apparently is in Date.description. The following code behaves similarly:
``` java
for _ in 0..<4 { _ = Date().description }
```
(swift-DEVELOPMENT-SNAPSHOT-2016-08-24-a)
opened 05:50PM - 23 Aug 16 UTC
closed 11:51PM - 16 Jan 20 UTC
bug
compiler
| | |
|------------------|-----------------|…
|Previous ID | SR-2462 |
|Radar | rdar://problem/27970214 |
|Original Reporter | @spevans |
|Type | Bug |
|Status | Closed |
|Resolution | Cannot Reproduce |
Attachment: [Download](https://user-images.githubusercontent.com/2727770/164961559-75ce39c6-2b36-4d4e-8e56-82f75a2b5372.gz)
<details>
<summary>Environment</summary>
This is on linux but I have seen the same issue on Darwin as well
Swift version 3.0-dev (LLVM 17c4c6cf7a, Clang 4ca9e01a7c, Swift 7a0ba75a1b)
Target: x86_64-unknown-linux-gnu
swift-corelibs-foundation: 66fad9f029a9
</details>
<details>
<summary>Additional Detail from JIRA</summary>
| | |
|------------------|-----------------|
|Votes | 1 |
|Component/s | Compiler |
|Labels | Bug |
|Assignee | None |
|Priority | Medium |
md5: a5c7bc4b60607dd23f9b56699626d161
</details>
**relates to**:
* [SR-2707](https://bugs.swift.org/browse/SR-2707) Swift 3.0 Release Run time Crash With Date/NSDate function
* [SR-2485](https://bugs.swift.org/browse/SR-2485) Segmentation fault in Date
* [SR-2879](https://bugs.swift.org/browse/SR-2879) Creating 4 calendars results in an assertion failure
**Issue Description:**
When calling CoreFoundation functions the swift compiler inserts rt_swift_release calls to release any objects it has gained ownership of. However sometimes it releases objects incorrectly causing the object to be freed early when it shouldnt be. The attached cftest.swift demonstrates this
import Foundation
import CoreFoundation
public func testCFString() {
let asciiBytes = Data(bytes: [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x53, 0x77, 0x69, 0x66, 0x74, 0x21, 0x00])
let str = asciiBytes.withUnsafeBytes { (bytes: UnsafePointer<Int8>) -> CFString in
CFStringCreateWithCString(kCFAllocatorSystemDefault, bytes, UInt32(kCFStringEncodingASCII))
}
print(str)
CFHash(str)
CFHash(str)
CFHash(str)
CFHash(str)
CFHash(str)
}
public func testCFTimezone() {
let tz = CFTimeZoneCreateWithTimeIntervalFromGMT(kCFAllocatorSystemDefault, 0.0)
print(tz)
CFHash(tz)
CFHash(tz)
CFHash(tz)
CFHash(tz)
CFHash(tz)
}
testCFString()
testCFTimezone()
print("Finished")
running it gives:
Hello Swift!
Optional(<CFTimeZone 0xb4aad0 [0x7f80de59d500]>{name = GMT; abbreviation = GMT; GMT offset = 0; is DST = false})
Segmentation fault
I have attached an disassembly of the two functions, the extra calls after each call to CFHash() can be seen here
<cftest.testCFTimezone () -> ()>:
.
.
401da4: e8 37 f8 ff ff callq 4015e0 <Swift.print ([Any], separator : Swift.String, terminator : Swift.String) -> ()@plt>
401da9: 4c 89 e7 mov %r12,%rdi
401dac: e8 7f f8 ff ff callq 401630 <CFHash@plt>
401db1: 4c 89 e7 mov %r12,%rdi
401db4: e8 57 04 00 00 callq 402210 <rt_swift_release>
401db9: 4c 89 e7 mov %r12,%rdi
401dbc: e8 6f f8 ff ff callq 401630 <CFHash@plt>
401dc1: 4c 89 e7 mov %r12,%rdi
401dc4: e8 47 04 00 00 callq 402210 <rt_swift_release>
401dc9: 4c 89 e7 mov %r12,%rdi
401dcc: e8 5f f8 ff ff callq 401630 <CFHash@plt>
401dd1: 4c 89 e7 mov %r12,%rdi
401dd4: e8 37 04 00 00 callq 402210 <rt_swift_release>
401dd9: 4c 89 e7 mov %r12,%rdi
401ddc: e8 4f f8 ff ff callq 401630 <CFHash@plt>
401de1: 4c 89 e7 mov %r12,%rdi
401de4: e8 27 04 00 00 callq 402210 <rt_swift_release>
401de9: 4c 89 e7 mov %r12,%rdi
401dec: e8 3f f8 ff ff callq 401630 <CFHash@plt>
401df1: be 02 00 00 00 mov $0x2,%esi
401df6: 4c 89 e7 mov %r12,%rdi
compared to:
<cftest.testCFString () -> ()>:
.
.
401b9c: e8 3f fa ff ff callq 4015e0 <Swift.print ([Any], separator : Swift.String, terminator : Swift.String) -> ()@plt>
401ba1: 4c 89 e7 mov %r12,%rdi
401ba4: e8 87 fa ff ff callq 401630 <CFHash@plt>
401ba9: 4c 89 e7 mov %r12,%rdi
401bac: e8 7f fa ff ff callq 401630 <CFHash@plt>
401bb1: 4c 89 e7 mov %r12,%rdi
401bb4: e8 77 fa ff ff callq 401630 <CFHash@plt>
401bb9: 4c 89 e7 mov %r12,%rdi
401bbc: e8 6f fa ff ff callq 401630 <CFHash@plt>
401bc1: 4c 89 e7 mov %r12,%rdi
401bc4: e8 67 fa ff ff callq 401630 <CFHash@plt>
401bc9: 4c 89 e7 mov %r12,%rdi
401bcc: e8 3f 06 00 00 callq 402210 <rt_swift_release>
401bd1: 48 8b 7d c0 mov -0x40(%rbp),%rdi
401bd5: e8 36 06 00 00 callq 402210 <rt_swift_release>
which has just the one release to balance the CFStringCreateWithCString() ownership
I haven’t seen this in a while - are you able to try running on Swift 3.1 or 3.0.2?
Your code seems to work on the IBM Sandbox with 3.0.2 but not 3.0.1.
You could also try replacing every 'let’ with ‘var’ but that might not be the right solution :-)
Regards,
Will Stanton
···
On Jan 25, 2017, at 5:04 PM, Dennis Schafroth via swift-users <swift-users@swift.org> wrote:
Hi
Trying to do some simple date parsing from syslog format (“Jan 25 20:21:22”) into Date. Seem to work once but crashes on second call
func dateConv(_ dateString: String) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM dd HH:mm"
dateFormatter.locale = Locale(identifier: "da_DK_POSIX")
if let date = dateFormatter.date(from: dateString) {
print("Real date: \(date)" )
return date
}
return nil
}
var date = dateConv("Jan 25 20:10")
var date2 = dateConv("Jan 25 20:11”)
# swift main.swift
Real date: 2000-01-25 19:10:00 +0000
0 swift 0x000000000334ab78 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x0000000003349346 llvm::sys::RunSignalHandlers() + 54
2 swift 0x000000000334b6aa
3 libpthread.so.0 0x00007fec92166890
4 libswiftCore.so 0x00007fec8e8f0735
5 libFoundation.so 0x00007fec8c0ab6ee
6 libFoundation.so 0x00007fec8bd7a222
7 libFoundation.so 0x00007fec8bd7c623
8 libFoundation.so 0x00007fec8bf0e873 _TFC10Foundation6NSDateg11descriptionSS + 99
9 libFoundation.so 0x00007fec8c182829 _TTWV10Foundation4Dates23CustomStringConvertibleS_FS1_g11descriptionSS + 57
10 libswiftCore.so 0x00007fec8e78c745 _TFs15_print_unlockedu0_R_s16TextOutputStreamrFTxRq__T_ + 997
using swift 3.0.1. Am I doing something wrong? I seems to work on macOS.
cheers,
:-Dennis
Zhao_Xin
(Zhao Xin)
January 26, 2017, 1:18am
5
That why I am choosing to use an IDE. It shows the typos.
Zhaoxin
···
On Thu, Jan 26, 2017 at 7:53 AM, Michael Bauer via swift-users < swift-users@swift.org> wrote:
On Jan 25, 2017, at 5:04 PM, Dennis Schafroth via swift-users < > swift-users@swift.org> wrote:
Hi
Trying to do some simple date parsing from syslog format (“Jan 25
20:21:22”) into Date. Seem to work once but crashes on second call
func dateConv(_ dateString: String) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM dd HH:mm"
dateFormatter.locale = Locale(identifier: "da_DK_POSIX")
if let date = dateFormatter.date(from: dateString) {
print("Real date: \(date)" )
return date
}
return nil
}
var date = dateConv("Jan 25 20:10")
var date2 = dateConv("Jan 25 20:11”)
Check out your parentheses. The last one is a right curly quote not the
straight ascii quote that it should be.
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users
schafdog
(Dennis Schafroth)
January 26, 2017, 2:33pm
6
Thanks for the suggestions.
It works with 3.0.2 but won't compile with 3.1 beta for Ubuntu 14.04. Missing a Block.h which does exist in 3.0.2
:-Dennis
···
On 26 Jan 2017, at 05.20, Philippe Hausler <phausler@apple.com> wrote:
We should run those tests with ASAN, I thought I had fixed that with the Sierra merge.
Sent from my iPhone
On Jan 25, 2017, at 6:11 PM, Will Stanton via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:
Based on the backtrace, I think the code is running into a memory issue with Swift Foundation:
[SR-2485] Segmentation fault in Date · Issue #4331 · apple/swift-corelibs-foundation · GitHub
[SR-2462] Compiler is sometimes overreleasing CF objects · Issue #45067 · apple/swift · GitHub
I haven’t seen this in a while - are you able to try running on Swift 3.1 or 3.0.2?
Your code seems to work on the IBM Sandbox with 3.0.2 but not 3.0.1.
You could also try replacing every 'let’ with ‘var’ but that might not be the right solution :-)
Regards,
Will Stanton
On Jan 25, 2017, at 5:04 PM, Dennis Schafroth via swift-users <swift-users@swift.org> wrote:
Hi
Trying to do some simple date parsing from syslog format (“Jan 25 20:21:22”) into Date. Seem to work once but crashes on second call
func dateConv(_ dateString: String) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM dd HH:mm"
dateFormatter.locale = Locale(identifier: "da_DK_POSIX")
if let date = dateFormatter.date(from: dateString) {
print("Real date: \(date)" )
return date
}
return nil
}
var date = dateConv("Jan 25 20:10")
var date2 = dateConv("Jan 25 20:11”)
# swift main.swift
Real date: 2000-01-25 19:10:00 +0000
0 swift 0x000000000334ab78 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x0000000003349346 llvm::sys::RunSignalHandlers() + 54
2 swift 0x000000000334b6aa
3 libpthread.so.0 0x00007fec92166890
4 libswiftCore.so 0x00007fec8e8f0735
5 libFoundation.so 0x00007fec8c0ab6ee
6 libFoundation.so 0x00007fec8bd7a222
7 libFoundation.so 0x00007fec8bd7c623
8 libFoundation.so 0x00007fec8bf0e873 _TFC10Foundation6NSDateg11descriptionSS + 99
9 libFoundation.so 0x00007fec8c182829 _TTWV10Foundation4Dates23CustomStringConvertibleS_FS1_g11descriptionSS + 57
10 libswiftCore.so 0x00007fec8e78c745 _TFs15_print_unlockedu0_R_s16TextOutputStreamrFTxRq__T_ + 997
using swift 3.0.1. Am I doing something wrong? I seems to work on macOS.
cheers,
:-Dennis
_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev
You are probably missing the package libblocksruntime-dev. That would cause that failure.
···
Sent from my iPhone
On Jan 26, 2017, at 6:33 AM, Dennis Schafroth <dennis@schafroth.com> wrote:
Thanks for the suggestions.
It works with 3.0.2 but won't compile with 3.1 beta for Ubuntu 14.04. Missing a Block.h which does exist in 3.0.2
:-Dennis
On 26 Jan 2017, at 05.20, Philippe Hausler <phausler@apple.com> wrote:
We should run those tests with ASAN, I thought I had fixed that with the Sierra merge.
Sent from my iPhone
On Jan 25, 2017, at 6:11 PM, Will Stanton via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:
Based on the backtrace, I think the code is running into a memory issue with Swift Foundation:
[SR-2485] Segmentation fault in Date · Issue #4331 · apple/swift-corelibs-foundation · GitHub
[SR-2462] Compiler is sometimes overreleasing CF objects · Issue #45067 · apple/swift · GitHub
I haven’t seen this in a while - are you able to try running on Swift 3.1 or 3.0.2?
Your code seems to work on the IBM Sandbox with 3.0.2 but not 3.0.1.
You could also try replacing every 'let’ with ‘var’ but that might not be the right solution :-)
Regards,
Will Stanton
On Jan 25, 2017, at 5:04 PM, Dennis Schafroth via swift-users <swift-users@swift.org> wrote:
Hi
Trying to do some simple date parsing from syslog format (“Jan 25 20:21:22”) into Date. Seem to work once but crashes on second call
func dateConv(_ dateString: String) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM dd HH:mm"
dateFormatter.locale = Locale(identifier: "da_DK_POSIX")
if let date = dateFormatter.date(from: dateString) {
print("Real date: \(date)" )
return date
}
return nil
}
var date = dateConv("Jan 25 20:10")
var date2 = dateConv("Jan 25 20:11”)
# swift main.swift
Real date: 2000-01-25 19:10:00 +0000
0 swift 0x000000000334ab78 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x0000000003349346 llvm::sys::RunSignalHandlers() + 54
2 swift 0x000000000334b6aa
3 libpthread.so.0 0x00007fec92166890
4 libswiftCore.so 0x00007fec8e8f0735
5 libFoundation.so 0x00007fec8c0ab6ee
6 libFoundation.so 0x00007fec8bd7a222
7 libFoundation.so 0x00007fec8bd7c623
8 libFoundation.so 0x00007fec8bf0e873 _TFC10Foundation6NSDateg11descriptionSS + 99
9 libFoundation.so 0x00007fec8c182829 _TTWV10Foundation4Dates23CustomStringConvertibleS_FS1_g11descriptionSS + 57
10 libswiftCore.so 0x00007fec8e78c745 _TFs15_print_unlockedu0_R_s16TextOutputStreamrFTxRq__T_ + 997
using swift 3.0.1. Am I doing something wrong? I seems to work on macOS.
cheers,
:-Dennis
_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev