[PATCH evemu] python: call only once the libevdev backend per request

Daniel Martin consume.noise at gmail.com
Tue Sep 2 00:29:29 PDT 2014


On Tue, Sep 02, 2014 at 04:42:05PM +1000, Peter Hutterer wrote:
> On Fri, Aug 29, 2014 at 05:34:16PM -0400, Benjamin Tissoires wrote:
> > We can factorize some code, and provide a cleaner way of implementing
> > event_get_value(), event_get_name(), input_prop_get_name() and
> > input_prop_get_value()
> > 
> > Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
> > ---
> >  python/evemu/__init__.py | 112 ++++++++++++++++++++++++++---------------------
> >  1 file changed, 62 insertions(+), 50 deletions(-)
> > 
> > diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
> > index 65e4673..22035b8 100644
> > --- a/python/evemu/__init__.py
> > +++ b/python/evemu/__init__.py
> > @@ -37,6 +37,54 @@ __all__ = ["Device",
> >  
> >  _libevdev = evemu.base.LibEvdev()
> >  
> > +def _event_type_get_value_name(event_type):
> > +    event_type_value = event_type_name = None
> > +
> > +    if isinstance(event_type, int):
> > +        event_type_name = _libevdev.libevdev_event_type_get_name(event_type)
> > +        if event_type_name == None:
> 
> shouldn't that be 0 for NULL?

Neither. Just was curious myself and tested it.

- Everything returning a pointer should be sufficient for testing what
  happens if it returns NULL. Use malloc() and say that it returns a
  c_char_p:

    >>> from ctypes import *
    >>> libc = CDLL("libc.so.6")
    >>> libc.malloc.restype = c_char_p
    >>> libc.malloc.argtypes = [c_size_t]

    >>> ptr = libc.malloc(0)

- Aaaah ...

    >>> type(ptr)
    <class 'bytes'>

- As it is an (bytes) object, the test with None doesn't work:

    >>> ptr is None
    False

- But, a test on its length is possible:

    >>> len(ptr)
    0


Cheers,
    Daniel Martin


More information about the Input-tools mailing list