<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Worth a radar to improve docs.<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 13 Jun 2017, at 22:12, Jens Persson via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Thanks!<div class=""><br class=""><div class=""><div class="">The documentation that Xcode displays (for CharacterSet's hasMember(inPlane plane:)) is as follows:</div><div class=""><br class=""></div><div class="">Declaration:</div><div class="">func hasMember(inPlane plane: UInt8) -> Bool<br class=""></div><div class=""><br class=""></div><div class="">Description:</div><div class=""><div class="">Returns true if the `CharacterSet` has a member in the specified plane.</div><div class="">This method makes it easier to find the plane containing the members of the current character set.</div><div class="">The Basic Multilingual Plane (BMP) is plane 0.</div><div class=""><br class=""></div><div class="">Parameters:</div><div class="">plane - No description</div><div class=""><br class=""></div><div class="">Which is about the same as here:</div><div class=""><a href="https://developer.apple.com/documentation/foundation/characterset/1779728-hasmember" class="">https://developer.apple.com/documentation/foundation/characterset/1779728-hasmember</a><br class=""></div><div class="">and here:</div><div class=""><a href="https://developer.apple.com/documentation/foundation/nscharacterset/1412406-hasmemberinplane" class="">https://developer.apple.com/documentation/foundation/nscharacterset/1412406-hasmemberinplane</a><br class=""></div><div class=""><br class=""></div><div class="">No where does it mention anything about undefined behavior for some values of plane.</div><div class=""><br class=""></div><div class="">In order to find that crucial info, I'd have to do what you did, write it in Objective C and dig through the stack trace, or just guess that it calls <span style="font-size:12.800000190734863px" class="">CFCharacterSetHasMemberInPlane and that its documentation contains very valuable pieces of information that for some reason got lost on the way to NSCharacterSet's method hasMemberInPlane ...</span></div><div class=""><br class=""></div><div class=""><span style="font-size:12.800000190734863px" class="">Kind of makes one wonder what other undocumented undefined behavior might hide in Foundation and other places.</span></div><div class=""><span style="font-size:12.800000190734863px" class=""><br class=""></span></div><div class=""><span style="font-size:12.800000190734863px" class="">/Jens</span></div><div class=""><span style="font-size:12.800000190734863px" class=""><br class=""></span></div><div class=""><br class=""></div><div class=""> </div></div></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Jun 13, 2017 at 7:14 PM, Doug Hill via swift-users <span dir="ltr" class=""><<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">I tried your calls to NSFont in Objective-C, and it also crashes. Looking at the stack trace, I see that it crashes in CFCharacterSetHasMemberInPlane<wbr class="">. I see documentation for <span style="color:rgb(0,132,0);font-family:Menlo;font-size:12px" class="">thePlane</span> parameter of this function says:</div><div class=""><br class=""></div><div class=""><span style="font-size:12px" class=""><span style="color:rgb(0,132,0);font-family:Menlo" class="">The valid value range is from 0 to 16.</span><span style="color:rgb(0,132,0);font-family:Menlo" class=""> </span><span style="color:rgb(0,132,0);font-family:Menlo" class="">If the value is outside of the valid </span><span style="color:rgb(0,132,0);font-family:Menlo" class="">plane number range, the behavior is undefined.</span></span></div><div class=""><br class=""></div>I guess randomly crashing counts as undefined behavior.<div class="">While it would be great if this function was more robust, Apple is definitely saying Don’t Do That.</div><div class=""><br class=""></div><div class="">Doug Hill<br class=""><div class=""><a href="https://github.com/djfitz/SFFontFeatures" target="_blank" class="">https://github.com/djfitz/<wbr class="">SFFontFeatures</a></div><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="h5"><div class="">On Jun 13, 2017, at 9:42 AM, Jens Persson via swift-users <<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>> wrote:</div><br class="m_-3958914847974300398Apple-interchange-newline"></div></div><div class=""><div class=""><div class="h5"><div dir="ltr" class=""><div class="">PS</div>There are only 17 planes in the (current?) Unicode standard, but I'm assuming that the CharacterSet.hasMember(<wbr class="">inPlane:) shouldn't (randomly?) crash for UInt8 values other than 0 ... 16?<div class="">It also seems strange that it reproducibly crashes or not depending on which specific font I use.</div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Jun 13, 2017 at 4:00 PM, Jens Persson <span dir="ltr" class=""><<a href="mailto:jens@bitcycle.com" target="_blank" class="">jens@bitcycle.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="">The below program demonstrates a possible bug that I encountered.</div>Can anyone else reproduce my results (as explained in the comments)?<div class="">If so, is it a Swift or Cocoa bug (I haven't tried it in Objective C)?</div><div class=""><div class=""><br class=""></div><div class="">import AppKit</div><div class=""><br class=""></div><div class="">extension NSFont {</div><div class=""> var planesWithMembers: [UInt8] {</div><div class=""> return (UInt8(0) ... UInt8(255)).filter {</div><div class=""> // The follwing line will crash (EXC_BAD_ACCESS) for some fonts:</div><div class=""> coveredCharacterSet.hasMember(<wbr class="">inPlane: $0)</div><div class=""> // I have tested it with Xcode 8.3.3 and Xcode 9 beta 1, both</div><div class=""> // Swift 3 and 4, and they all reproduce the crash.</div><div class=""> // macOS 10.12.5</div><div class=""> }</div><div class=""> }</div><div class="">}</div><div class=""><br class=""></div><div class="">// Examples that will not cause the crash:</div><div class="">// let fontName = "AlBayan"</div><div class="">// let fontName = "AppleBraille"</div><div class="">// let fontName = "Chalkboard"</div><div class="">// let fontName = "Helvetica"</div><div class="">// let fontName = "Zapfino"</div><div class=""><br class=""></div><div class="">// Examples that will cause the crash:</div><div class="">// let fontName = "AppleColorEmoji"</div><div class="">// let fontName = "AppleSymbols"</div><div class="">let fontName = "Baskerville"</div><div class="">// let fontName = "Geneva"</div><div class="">// let fontName = "SnellRoundhand"</div><div class=""><br class=""></div><div class="">let font = NSFont(name: fontName, size: 12)!</div><div class="">let result = font.planesWithMembers</div><div class="">print("Planes that contains members:", result)</div></div><div class=""><br class=""></div></div>
</blockquote></div><br class=""></div></div></div>
______________________________<wbr class="">_________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></div></div><br class="">______________________________<wbr class="">_________________<br class="">
swift-users mailing list<br class="">
<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-users</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></body></html>