Subject: bug#57969: 29.0.50; `device-class' errors when NAME is nil

From: Po Lu <[email-masked]>
Date: Wed, 21 Sep 2022 19:53:40 +0800

Lars Ingebrigtsen <[email-masked]> writes:

> Visuwesh <[email-masked]> writes:
>
>> According to the docstring of `device-class', nil is a valid value for
>> the NAME argument however it errors out since `x-device-class' uses
>> `downcase' without checking if NAME is non-nil.  Backtrace is below,
>>
>> Debugger entered--Lisp error: (wrong-type-argument char-or-string-p nil)
>>   downcase(nil)
>
> Yes --
>
> --
> Return the class of the device NAME for an event generated on FRAME.
> NAME is a string that can be the value of last-event-device, or
> nil.
> --
>
> But it's not clear what the meaning of nil should be.  Perhaps Po Lu
> knows; added to the CCs.

It does say later on that if the type could not be determined, the
return value is nil.  So that is what I made it return.

> (And if nil really is a meaningful value for NAME, and not just a
> documentation error, then perhaps that argument should be optional?)

Well, no, it's only intended to be valid so you can do this:

  (device-class last-event-frame last-event-device)

FTR, I consider `device-class' and `last-event-device' low level
interfaces that will be eventually replaced with a better user-facing
one, based on keymaps and virtual function keys, but that is still WIP.

Thanks.