Questions regarding libevdev

Callum Oz acheronfail at gmail.com
Wed Mar 20 22:44:21 UTC 2019


For reference, we're referring to these functions here:
https://gitlab.freedesktop.org/libevdev/libevdev/blob/master/libevdev/libevdev.h#L1327
https://gitlab.freedesktop.org/libevdev/libevdev/blob/master/libevdev/libevdev.h#L1338

On Thu, Mar 21, 2019 at 9:42 AM Callum Oz <acheronfail at gmail.com> wrote:

> (Sending this email again, since I wasn't on the mailing list and I think
> it was blocked the first time).
>
> Peter,
>
> We don't have a requirement to "set" the field more than 16 bits, it's
> just a quirk that we noticed.
> If I understand correctly the `int` type is larger than 16 bits.
>
> My C isn't the best, but this example should demonstrate why I'm confused:
>
> ```c
> #include <stdio.h>
>
> int main() {
>    int x = 70000;
>    printf("x: %d", x); // Not truncated to 16 bits
>
>    short y = 70000;
>    printf("y: %d", y); // This IS truncated
>
>   return 0;
> }
> ```
>
> Whereas using the `short` type would accurately display the value as 16
> bits.
>
> We're writing bindings for libevdev to Rust, and wanted to get the types
> right.
> In our tests we noticed that although the API's return type is `int`, it's
> being
> treated as something smaller and is getting truncated to 16 bits.
>
> Regards,
> Cal
>
> On Thu, Mar 21, 2019 at 9:39 AM Callum Oz <acheronfail at gmail.com> wrote:
>
>> Peter,
>>
>> We don't have a requirement to "set" the field more than 16 bits, it's
>> just a quirk that we noticed.
>> If I understand correctly the `int` type is larger than 16 bits.
>>
>> My C isn't the best, but this example should demonstrate why I'm confused:
>>
>> ```c
>> #include <stdio.h>
>>
>> int main() {
>>    int x = 70000;
>>    printf("x: %d", x); // Not truncated to 16 bits
>>
>>    short y = 70000;
>>    printf("y: %d", y); // This IS truncated
>>
>>   return 0;
>> }
>> ```
>>
>> Whereas using the `short` type would accurately display the value as 16
>> bits.
>>
>> We're writing bindings for libevdev to Rust, and wanted to get the types
>> right.
>> In our tests we noticed that although the API's return type is `int`,
>> it's being
>> treated as something smaller and is getting truncated to 16 bits.
>>
>> Regards,
>> Cal
>>
>> On Thu, Mar 21, 2019 at 9:24 AM Peter Hutterer <peter.hutterer at who-t.net>
>> wrote:
>>
>>> On Thu, Mar 21, 2019 at 12:14:25AM +0900, Nayan Deshmukh wrote:
>>> > Hello,
>>> >
>>> > We have encountered a quirky behavior of libevdev and wanted to make
>>> > sure that it is known and intentional quirk.
>>> >
>>> > Whenever I set the version for a device through
>>> > `libevdev_set_id_version`, the value set is truncated at 65,535 which
>>> > is the max value of unsigned short. Any thoughts on this?
>>>
>>> the id_version sets/gets the struct input_id's version field, from
>>> linux/input.h. That's a uint16 so we mirror the kernel API here.
>>> The same applies to the other libevdev_set_id_* fields, those are 16 bit
>>> only too.
>>>
>>> Many drivers don't really use that version field at all, so it's largely
>>> ignored by userspace anyway. Out of interest - what do you need it be
>>> bigger
>>> than 16 bits for?
>>>
>>> Cheers,
>>>    Peter
>>>
>>


More information about the Input-tools mailing list