[PATCH v2 evemu 1.5/2] python: fix ctypes NULL-pointer checks
Peter Hutterer
peter.hutterer at who-t.net
Thu Nov 10 00:32:51 UTC 2016
NULL-pointers are None, not 0. This only worked because we kept falling
through until some other later condition triggered and happened to return the
correct value at all times (usually because the type/code ended up as -1)
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
New in this series
python/evemu/__init__.py | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index 230559f..a9b768a 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -50,17 +50,16 @@ def event_get_value(event_type, event_code = None):
if isinstance(event_type, int):
event_type = _libevdev.libevdev_event_type_get_name(event_type)
- if event_type == 0: # NULL
+ if event_type is None:
return None
t = _libevdev.libevdev_event_type_from_name(str(event_type))
-
if event_code is None:
return None if t < 0 else t
if isinstance(event_code, int):
event_code = _libevdev.libevdev_event_code_get_name(t, event_code)
- if event_code == 0: # NULL
+ if event_code is None:
return None
c = _libevdev.libevdev_event_code_from_name(t, str(event_code))
@@ -84,7 +83,7 @@ def event_get_name(event_type, event_code = None):
if event_code is None:
type_name = _libevdev.libevdev_event_type_get_name(event_type)
- return None if type_name == 0 else type_name
+ return type_name
if not isinstance(event_code, int):
event_code = event_get_value(event_type, event_code)
@@ -94,7 +93,7 @@ def event_get_name(event_type, event_code = None):
code_name = _libevdev.libevdev_event_code_get_name(event_type, event_code)
- return None if code_name == 0 else code_name
+ return code_name
def input_prop_get_name(prop):
"""
@@ -107,7 +106,7 @@ def input_prop_get_name(prop):
return None
prop = _libevdev.libevdev_property_get_name(prop)
- return None if prop == 0 else prop
+ return prop
def input_prop_get_value(prop):
"""
--
2.9.3
More information about the Input-tools
mailing list