diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2019-04-08 13:51:28 +0200 |
---|---|---|
committer | Aapo Keskimolo <aapo.keskimolo@qt.io> | 2019-05-01 13:54:40 +0000 |
commit | 3eea45e31ef796ab6f1363f8fd2882c151becc20 (patch) | |
tree | 297b6c6629cff45a29c93903bc205811803e5eee /src/qtwaylandscanner | |
parent | eb74002869d624678e1484dd577ab5d9fff842bf (diff) | |
download | qtwayland-3eea45e31ef796ab6f1363f8fd2882c151becc20.tar.gz |
Client: Add safer fromObject function to scanner
Makes the scanner produce generated static functions such as
QtWaylandClient::wl_surface *wl_surface::fromObject(struct ::wl_surface *object);
Which casts from the wayland-scanner generated types, such as struct ::wl_surface *,
to types types generated by qtwaylandscanner, but performs a check to see if
the listener is set to the wrapper class first (at least for interfaces with events).
This lets us easily fix crashes in a couple of places where we receive events
with wayland objects that we didn't create.
Also adds nullptr checks whenever we use the fromWlSurface() and fromWlOutput()
functions to handle failed conversions.
Task-number: QTBUG-73801
Fixes: QTBUG-74085
Change-Id: I9f33c31c7d1a939ccb3ebbbcb0eb67af10037237
Reviewed-by: Jaroslaw Kubik <jarek@froglogic.com>
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/qtwaylandscanner')
-rw-r--r-- | src/qtwaylandscanner/qtwaylandscanner.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/qtwaylandscanner/qtwaylandscanner.cpp b/src/qtwaylandscanner/qtwaylandscanner.cpp index 56045e88..7f3dc5ad 100644 --- a/src/qtwaylandscanner/qtwaylandscanner.cpp +++ b/src/qtwaylandscanner/qtwaylandscanner.cpp @@ -986,6 +986,7 @@ bool Scanner::process() printf("\n"); printf(" struct ::%s *object() { return m_%s; }\n", interfaceName, interfaceName); printf(" const struct ::%s *object() const { return m_%s; }\n", interfaceName, interfaceName); + printf(" static %s *fromObject(struct ::%s *object);\n", interfaceName, interfaceName); printf("\n"); printf(" bool isInitialized() const;\n"); printf("\n"); @@ -1130,6 +1131,16 @@ bool Scanner::process() printf(" }\n"); printf("\n"); + printf(" %s *%s::fromObject(struct ::%s *object)\n", interfaceName, interfaceName, interfaceName); + printf(" {\n"); + if (hasEvents) { + printf(" if (wl_proxy_get_listener((struct ::wl_proxy *)object) != (void *)&m_%s_listener)\n", interfaceName); + printf(" return nullptr;\n"); + } + printf(" return static_cast<%s *>(%s_get_user_data(object));\n", interfaceName, interfaceName); + printf(" }\n"); + printf("\n"); + printf(" bool %s::isInitialized() const\n", interfaceName); printf(" {\n"); printf(" return m_%s != nullptr;\n", interfaceName); |