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