<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 4 Oct 2016, at 10:29, Pushkar N Kulkarni via swift-corelibs-dev <<a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><font face="Verdana,Arial,Helvetica,sans-serif" size="2" class="">Hi there, <div class=""><br class=""></div><div class="">I've hit an obstacle while working on a crash seen in initing a Calendar (<a href="https://bugs.swift.org/browse/SR-2551)" target="_blank" class="">https://bugs.swift.org/browse/SR-2551)</a><br class=""><font face="Verdana,Arial,Helvetica,sans-serif" size="2" class=""><font class=""><font class=""><div class="socmaildefaultfont" dir="ltr"><div class="socmaildefaultfont" dir="ltr"><div class="socmaildefaultfont" dir="ltr"><div dir="ltr" style="font-style: normal;" class=""><br class=""></div><div dir="ltr" style="font-style: normal;" class="">For the Calendar initialiser "<span class="syntax-keyword" style="box-sizing: inherit; font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px;"><font color="#aa0d91" class="">init</font></span><span style="font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px; background-color: rgb(249, 250, 250);" class=""><font color="#333333" class="">(</font></span><span class="syntax-identifier" style="box-sizing: inherit; font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px;">identifier</span><span style="font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px; background-color: rgb(249, 250, 250);" class=""><font color="#333333" class="">: </font></span><span class="syntax-type" style="box-sizing: inherit; font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px;"><font color="#5c2699" class="">Calendar</font></span><span style="font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px; background-color: rgb(249, 250, 250);" class=""><font color="#333333" class="">.</font></span><span class="syntax-type" style="box-sizing: inherit; font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px;"><font color="#5c2699" class="">Identifier</font></span><span class="syntax-type" style="box-sizing: inherit; font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px; background-color: rgb(249, 250, 250);"><font color="#333333" class="">)", </font></span>the possible values of Calendar.Identifier are listed <a target="_blank" href="https://developer.apple.com/reference/foundation/calendar.identifier" title="https://developer.apple.com/reference/foundation/calendar.identifier" class="">here</a>. However, we eventually end up calling "<span class="pl-en" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; white-space: pre;"><font color="#795da3" class="">_CFCalendarInitWithIdentifier</font></span><span style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; white-space: pre;" class=""><font color="#333333" class="">(</font></span><span class="pl-c1" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; white-space: pre;"><font color="#0086b3" class="">CFCalendarRef</font></span><span style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; white-space: pre;" class=""><font color="#333333" class=""> calendar, </font></span><span class="pl-c1" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; white-space: pre;"><font color="#0086b3" class="">CFStringRef</font></span><span style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; white-space: pre;" class=""><font color="#333333" class=""> identifier)" </font></span>and the latter works only for a specific set of calendar identifiers. See this if statement:</div><div dir="ltr" style="font-style: normal;" class=""> <a href="https://github.com/apple/swift-corelibs-foundation/blob/master/CoreFoundation/Locale.subproj/CFCalendar.c#L239" target="_blank" class="">https://github.com/apple/swift-corelibs-foundation/blob/master/CoreFoundation/Locale.subproj/CFCalendar.c#L239</a><br class=""></div><div dir="ltr" style="font-style: normal;" class=""><br class=""></div><div dir="ltr" style="font-style: normal;" class="">For other identifier values, we crash (that is SR-2551). On mac, all the identifier values are supported. It seems that the calendar identifier is ultimately encoded as a key-value pair in the locale ID for the calendar. </div><div dir="ltr" style="font-style: normal;" class=""><br class=""></div><div dir="ltr" style="font-style: normal;" class="">Can anybody please help me understand the rationale of the if-statement above? I am new to ICU. I did search for justifications but didn't come across convincing. <br class=""></div></div></div></div></font></font></font></div></font></div></blockquote><br class=""></div><div>The if statement is canonicalising the reference to the constant e.g. kCFCalendarIdentifierBuddhist. This allows other instances to be passed in but then resolved to the same instance, such that pointer comparisons work for future calls. The same is done for Swift.</div><div><br class=""></div><div>On macOS, there are additional checks in the CoreFoundation equivalent (such as kCFCalendarIdentifierISO8601) which is why it works on Darwin. However, I don't know if there were specific reasons for excluding the ISO8601 calendar, unless the ICU library doesn't understand it. Testing adding support should be a case of doing something similar to this commit, which re-enabled the Chinese calendar:</div><div><br class=""></div><div><a href="https://github.com/apple/swift-corelibs-foundation/commit/c1d940dd6099de65f959fd42274cf0e65984efe0" class="">https://github.com/apple/swift-corelibs-foundation/commit/c1d940dd6099de65f959fd42274cf0e65984efe0</a></div><br class=""><div class="">Of course building with the 'if' switch enabled may highlight other issues, but on a quick test build it seems that adding the additional if case to the statement results in the ISO8601 calendar being returned. I'll let others explain in more detail if there's some specific subtlety for why it was left out in the first place.</div><div class=""><br class=""></div><div class="">Alex</div></body></html>