From 89870a35bde2f67f9c371ba145e90b86d3e2dd1b Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Wed, 22 Feb 2017 02:18:27 +0300 Subject: xcb: Wrap xcb callings in macros ... to improve readability and reliability. This change introduces macros Q_XCB_REPLY and Q_XCB_REPLY_UNCHECKED that allow to replace couples of xcb cookie/reply callings by a single "calling" of a macro. The macros wrap the reply in std::unique_ptr thus preventing the need to free it manually. The following C++11 features are used: - variadic macros - std::unique_ptr - auto type deduction Change-Id: Icf9b93353404a39bf5f4a4562b9234db18cac696 Reviewed-by: Gatis Paeglis --- src/plugins/platforms/xcb/qxcbconnection.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/plugins/platforms/xcb/qxcbconnection.h') diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index 7f0d5cf2cc..c298c08322 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -56,6 +56,8 @@ #include #include +#include + // This is needed to make Qt compile together with XKB. xkb.h is using a variable // which is called 'explicit', this is a reserved keyword in c++ #if QT_CONFIG(xkb) @@ -731,6 +733,20 @@ private: QXcbConnection *m_connection; }; +#define Q_XCB_REPLY_CONNECTION_ARG(connection, ...) connection + +#define Q_XCB_REPLY(call, ...) \ + std::unique_ptr( \ + call##_reply(Q_XCB_REPLY_CONNECTION_ARG(__VA_ARGS__), call(__VA_ARGS__), nullptr), \ + std::free \ + ) + +#define Q_XCB_REPLY_UNCHECKED(call, ...) \ + std::unique_ptr( \ + call##_reply(Q_XCB_REPLY_CONNECTION_ARG(__VA_ARGS__), call##_unchecked(__VA_ARGS__), nullptr), \ + std::free \ + ) + #ifdef Q_XCB_DEBUG template cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file, -- cgit v1.2.3