<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="">On Jul 19, 2016, at 2:59 AM, DavidL <<a href="mailto:david.dljunk@gmail.com" class="">david.dljunk@gmail.com</a>> wrote:<br class=""><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">On Mon, Jul 18, 2016 at 10:59 PM, Ken Thomases <span dir="ltr" class=""><<a href="mailto:ken@codeweavers.com" target="_blank" class="">ken@codeweavers.com</a>></span> wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On Jul 18, 2016, at 1:57 AM, David Lawrie <<a href="mailto:david.dljunk@gmail.com" class="">david.dljunk@gmail.com</a>> wrote:<br class="">
<br class=""></span></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">
> +        else if (ref)<br class="">
> +            name = CFCopyDescription(ref);<br class="">
> +        else<br class="">
> +            name = CFStringCreateCopy(kCFAllocatorDefault,CFSTR("(null)"));<br class="">
<br class="">
</span>You don't want to fall back to a string based on the vendor and product ID?<br class=""></blockquote><div class=""><br class=""></div><div class="">I thought about it, but then<span style="font-size:13px" class=""> </span>I wanted to try to hew as close to the behavior of debugstr_cf as possible since that is the output that the user sees already in trace logs.</div></div></div></div></div></blockquote><div><br class=""></div><div>I don't think it's particularly important that they match to that degree.  First, users generally don't see the trace logs.  Second, it's good enough that they match when the product property is non-null.  There's no strong reason to make them match for the null case.  It's fine to have this function return something more useful than that, especially since it's currently used as a sort key and "(null)" is useless for that.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> This label "(null)" is how debugstr handles that case. The alternative of course is changing both functions to try to get the venture/product ID - though I think the concern is if it doesn't have aProductKey it may not have a proper productId or vendorID either</div></div></div></div></div></blockquote><div><br class=""></div><div>I have no objection if you want to make debugstr_device() also include the vendor/product ID as a fallback, but I don't think it's especially important.  The result from copy_device_name() is not currently logged, so there's no way for a reader of the logs to benefit if the two functions match in that way, nor lose anything if they don't match.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> ... also there is a function get_os_x_device_name (in dinput only) which doesn't handle this case at all I don't think. What's your recommendation?</div></div></div></div></div></blockquote><div><br class=""></div><div>I don't know how important it is for get_osx_device_name() to return a non-empty name.  It could be changed to call copy_device_name() to get the name and then extract that to the buffer.  Mind you, it's currently buggy in how it treats the CFString length vs. the buffer length.  The former is in number of UTF-16 code units, the latter in terms of ASCII characters, so they're not directly comparable.  (Also, nothing ever checks the function's return value, so returning the supposed required length doesn't achieve anything.)</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> > @@ -203,7 +227,18 @@ static void copy_set_to_array(const void *value, void *context)</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">
>     CFArrayAppendValue(context, value);<br class="">
> }<br class="">
><br class="">
> -static CFComparisonResult device_location_comparator(const void *val1, const void *val2, void *context)<br class="">
> +static CFComparisonResult device_name_comparator(IOHIDDeviceRef device1, IOHIDDeviceRef device2)<br class="">
> +{<br class="">
> +    CFStringRef name1 = copy_device_name(device1), name2 = copy_device_name(device2);<br class="">
> +    CFComparisonResult result = CFStringCompare(name1, name2, (kCFCompareForcedOrdering | kCFCompareNumerically));<br class="">
> +    if(name1)<br class="">
> +        CFRelease(name1);<br class="">
> +    if(name2)<br class="">
> +        CFRelease(name2);<br class="">
<br class="">
</span>If name1 or name2 might be NULL as these tests imply, then what does the preceding CFStringCompare() call do?  Probably crashes.  So, either assume/assure that copy_device_name() doesn't return NULL in normal operation or handle the possibility that it might more thoroughly.<br class=""></blockquote><div class=""><br class=""></div><div class="">Actually I think it doesn't crash, though I should test it to be sure.</div></div></div></div></div></blockquote><div><br class=""></div><div>Testing isn't appropriate.  It could work in some versions of the frameworks and not in others.  The authority on the design contract is the documentation (including header comments), with the understanding that if it doesn't explicitly say that NULL is acceptable, then it's not.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> However, maybe for completeness/robustness I should include if statements dealing with all the possible name-NULL combinations and return - something like:</div><div class=""><br class=""></div><div class="">if ((!name1 && !name2) || !name1)</div><div class="">   return lessThan;</div><div class="">else if (!name2)</div><div class="">   return greaterThan;</div><div class=""><br class=""></div><div class="">Then it wouldn't matter what CFStringCompare's behavior was if it crashes ... or I could set name equal to an empty string in copy_device_name which would have the same effect as the above few lines.</div></div></div></div></div></blockquote><br class=""></div><div>Returning the empty string is probably simplest.  If you go the pointer testing route, then surely (!name1 && !name2) implies equal, not less-than.</div><br class=""><div class="">-Ken</div><div class=""><br class=""></div></body></html>