[igt-dev] [PATCH i-g-t v3 3/9] lib/aux: Typecast gettid() as pid_t
Lyude
lyude at redhat.com
Wed Apr 24 20:20:27 UTC 2019
From: Lyude Paul <lyude at redhat.com>
Partly, for correctness. But mostly because not typecasting properly
causes the gettid() macro provided by newer glibc to be typed as pid_t
(aka int), while ours is typed as long. Causing annoying warnings:
[158/846] Compiling C object 'tests/59830eb@@drm_import_export at exe/drm_import_export.c.o'.
In file included from ../../mnt/vol/lib/drmtest.h:39,
from ../../mnt/vol/lib/igt.h:27,
from ../../mnt/vol/tests/drm_import_export.c:27:
../../mnt/vol/tests/drm_import_export.c: In function ‘test_thread’:
../../mnt/vol/tests/drm_import_export.c:123:12: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘__pid_t’ {aka ‘int’} [-Wformat=]
123 | igt_debug("start %ld\n", gettid());
| ^~~~~~~~~~~~~ ~~~~~~~~
| |
| __pid_t {aka int}
../../mnt/vol/lib/igt_core.h:875:64: note: in definition of macro ‘igt_debug’
875 | #define igt_debug(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_DEBUG, f)
| ^
../../mnt/vol/tests/drm_import_export.c:123:21: note: format string is defined here
123 | igt_debug("start %ld\n", gettid());
| ~~^
| |
| long int
| %d
So, typecast gettid() as pid_t and update all of our callers accordingly
Signed-off-by: Lyude Paul <lyude at redhat.com>
---
lib/igt_aux.h | 3 ++-
tests/drm_import_export.c | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index cbcb1844..7dfcacb1 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -32,6 +32,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <sys/time.h>
+#include <sys/types.h>
#ifdef __linux__
# include <sys/syscall.h>
#endif
@@ -40,7 +41,7 @@
/* signal interrupt helpers */
#ifdef __linux__
-# define gettid() syscall(__NR_gettid)
+# define gettid() (pid_t)(syscall(__NR_gettid))
#endif
#define sigev_notify_thread_id _sigev_un._tid
diff --git a/tests/drm_import_export.c b/tests/drm_import_export.c
index e1b0abae..f79c09db 100644
--- a/tests/drm_import_export.c
+++ b/tests/drm_import_export.c
@@ -120,7 +120,7 @@ static void start_test(void)
static void * test_thread(void * par)
{
#ifdef __linux__
- igt_debug("start %ld\n", gettid());
+ igt_debug("start %ld\n", (long) gettid());
#else
igt_debug("start %ld\n", (long) pthread_self());
#endif
--
2.20.1
More information about the igt-dev
mailing list