On Sun, Feb 23, 2020 at 10:40:32PM +0100, Enrico Forestieri wrote:
> On Sun, Feb 23, 2020 at 12:04:20PM -0500, Scott Kostyshak wrote:
> > On Sun, Feb 23, 2020 at 03:10:37PM +0100, Enrico Forestieri wrote:
> > > On Sun, Feb 23, 2020 at 08:22:55AM -0500, Scott Kostyshak wrote:
> > > > On Wed, Feb 19, 2020 at 08:07:46PM +0100, Enrico Forestieri wrote:
> > > > > On Wed, Feb 19, 2020 at 01:19:54PM -0500, Scott Kostyshak wrote:
> > > > > > 
> > > > > > It seems I committed too soon. Sorry for not waiting. Both the macro
> > > > > > approach and Enrico's proposal are cleaner than my approach. I was
> > > > > > planning to pursue the macro approach in a follow-up commit.
> > > > > 
> > > > > Apparently, the macro approach was abandoned by the Qt folks.
> > > > > 
> > > > > > Regarding
> > > > > > C++11, don't we already use range-based for loops? Or is the 
> > > > > > question
> > > > > > about if we require *all* of C++11?
> > > > > 
> > > > > The latter. As shown by Pavel in the other post gcc 4.7 is lacking
> > > > > something. As we use xcb_selection_notify_event_t only in one place,
> > > > > I think defining a macro is overkill. In order to avoid many calls
> > > > > to calloc() (I don't know how memory fragmentation is dealt with by
> > > > > modern compilers), we could anyway use that idea as follows:
> > > > > 
> > > > >       union {
> > > > >               xcb_selection_notify_event_t event;
> > > > >               char padding[32];
> > > > >       } padded_event;
> > > > >       auto & nev = padded_event.event;
> > > > 
> > > > Enrico, I propose that you commit. Thanks for the fix.
> > > 
> > > According to the followups to the post by Pavel and commit 748bb5a0,
> > > I think that the C++11 alignas solution is preferred. Given that you
> > > can check its effectiveness, I think that it is better that you
> > > commit it.
> > 
> > I tried to test but probably I'm missing something in the change that I
> > tested since I still get the following with Valgrind:
> 
> Please, can you also try with the union approach above?

I tested but still get the Valgrind error. I'm wondering if I
implemented the approach incorrectly. Attached is the patch.

Scott
diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index 2cdd5f6e3b..3409272f3b 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -3356,22 +3356,22 @@ bool GuiApplication::nativeEventFilter(const QByteArray & eventType,
 				// It is expected that every X11 event is 32 bytes long,
 				// even if not all 32 bytes are needed. See:
 				// https://www.x.org/releases/current/doc/man/man3/xcb_send_event.3.xhtml
-				// TODO switch to Q_DECLARE_XCB_EVENT(event, xcb_selection_notify_event_t)
-				//      once we require qt >= 5.6.3 or just copy the macro def.
-				xcb_selection_notify_event_t *nev = (xcb_selection_notify_event_t*) calloc(32, 1);
-
-				nev->response_type = XCB_SELECTION_NOTIFY;
-				nev->requestor = srev->requestor;
-				nev->selection = srev->selection;
-				nev->target = srev->target;
-				nev->property = XCB_NONE;
-				nev->time = XCB_CURRENT_TIME;
+				union {
+				        xcb_selection_notify_event_t event;
+				        char padding[32];
+				} padded_event;
+				auto & nev = padded_event.event;
+				nev.response_type = XCB_SELECTION_NOTIFY;
+				nev.requestor = srev->requestor;
+				nev.selection = srev->selection;
+				nev.target = srev->target;
+				nev.property = XCB_NONE;
+				nev.time = XCB_CURRENT_TIME;
 				xcb_connection_t * con = QX11Info::connection();
 				xcb_send_event(con, 0, srev->requestor,
 					XCB_EVENT_MASK_NO_EVENT,
-					reinterpret_cast<char const *>(nev));
+					reinterpret_cast<char const *>(&nev));
 				xcb_flush(con);
-				free(nev);
 #endif
 				return true;
 			}

Attachment: signature.asc
Description: PGP signature

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to