blob: 154172ca88ae89206b29a844b363bcdc5525cab7 [file] [log] [blame]
Brad Bishope42b3e32020-01-15 22:08:42 -05001From 435e78aaf6745e4da0fe3d4455473011626c77d1 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 30 Nov 2019 11:21:20 -0800
4Subject: [PATCH] Fix build on 32bit arches with 64bit time_t
5
6time element is deprecated on new input_event structure in kernel's
7input.h [1]
8
9[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=152194fe9c3f
10
11Upstream-Status: Submitted [https://github.com/gvalkov/python-evdev/pull/112]
12Signed-off-by: Khem Raj <raj.khem@gmail.com>
13---
14 evdev/input.c | 13 +++++++++----
15 evdev/uinput.c | 9 ++++++++-
16 2 files changed, 17 insertions(+), 5 deletions(-)
17
18diff --git a/evdev/input.c b/evdev/input.c
19index 67b9348..432db92 100644
20--- a/evdev/input.c
21+++ b/evdev/input.c
22@@ -24,6 +24,11 @@
23 #include <linux/input.h>
24 #endif
25
26+#ifndef input_event_sec
27+#define input_event_sec time.tv_sec
28+#define input_event_usec time.tv_usec
29+#endif
30+
31 #define MAX_NAME_SIZE 256
32
33 extern char* EV_NAME[EV_CNT];
34@@ -60,8 +65,8 @@ device_read(PyObject *self, PyObject *args)
35 return NULL;
36 }
37
38- PyObject* sec = PyLong_FromLong(event.time.tv_sec);
39- PyObject* usec = PyLong_FromLong(event.time.tv_usec);
40+ PyObject* sec = PyLong_FromLong(event.input_event_sec);
41+ PyObject* usec = PyLong_FromLong(event.input_event_usec);
42 PyObject* val = PyLong_FromLong(event.value);
43 PyObject* py_input_event = NULL;
44
45@@ -102,8 +107,8 @@ device_read_many(PyObject *self, PyObject *args)
46
47 // Construct a list of event tuples, which we'll make sense of in Python
48 for (unsigned i = 0 ; i < nread/event_size ; i++) {
49- sec = PyLong_FromLong(event[i].time.tv_sec);
50- usec = PyLong_FromLong(event[i].time.tv_usec);
51+ sec = PyLong_FromLong(event[i].input_event_sec);
52+ usec = PyLong_FromLong(event[i].input_event_usec);
53 val = PyLong_FromLong(event[i].value);
54
55 py_input_event = Py_BuildValue("OOhhO", sec, usec, event[i].type, event[i].code, val);
56diff --git a/evdev/uinput.c b/evdev/uinput.c
57index 192568d..56fe86c 100644
58--- a/evdev/uinput.c
59+++ b/evdev/uinput.c
60@@ -16,6 +16,10 @@
61 #include <linux/uinput.h>
62 #endif
63
64+#ifndef input_event_sec
65+#define input_event_sec time.tv_sec
66+#define input_event_usec time.tv_usec
67+#endif
68
69 // Workaround for installing on kernels newer than 4.4.
70 #ifndef FF_MAX_EFFECTS
71@@ -232,8 +236,11 @@ uinput_write(PyObject *self, PyObject *args)
72 if (!ret) return NULL;
73
74 struct input_event event;
75+ struct timeval tval;
76 memset(&event, 0, sizeof(event));
77- gettimeofday(&event.time, 0);
78+ gettimeofday(&tval, 0);
79+ event.input_event_usec = tval.tv_usec;
80+ event.input_event_sec = tval.tv_sec;
81 event.type = type;
82 event.code = code;
83 event.value = value;