From d3940a52c6c9c8572fb4dc91686a25e4e8923744 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Sun, 26 Sep 2021 23:38:53 +0200 Subject: [PATCH] Backport PR #21172: skip QImage leak workaround for PySide2 >= 5.12 --- lib/matplotlib/backends/backend_qtagg.py | 5 +++-- lib/matplotlib/backends/backend_qtcairo.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/backends/backend_qtagg.py b/lib/matplotlib/backends/backend_qtagg.py index 3d96fbda8da5..0ccf32fccd1e 100644 --- a/lib/matplotlib/backends/backend_qtagg.py +++ b/lib/matplotlib/backends/backend_qtagg.py @@ -61,7 +61,7 @@ def paintEvent(self, event): if QT_API == "PyQt6": from PyQt6 import sip - ptr = sip.voidptr(buf) + ptr = int(sip.voidptr(buf)) else: ptr = buf qimage = QtGui.QImage( @@ -74,7 +74,8 @@ def paintEvent(self, event): # Adjust the buf reference count to work around a memory # leak bug in QImage under PySide. if QT_API in ('PySide', 'PySide2'): - ctypes.c_long.from_address(id(buf)).value = 1 + if QtCore.__version_info__ < (5, 12): + ctypes.c_long.from_address(id(buf)).value = 1 self._draw_rect_callback(painter) finally: diff --git a/lib/matplotlib/backends/backend_qtcairo.py b/lib/matplotlib/backends/backend_qtcairo.py index 9619f4fdb686..8d6def2d79e5 100644 --- a/lib/matplotlib/backends/backend_qtcairo.py +++ b/lib/matplotlib/backends/backend_qtcairo.py @@ -29,7 +29,7 @@ def paintEvent(self, event): buf = self._renderer.gc.ctx.get_target().get_data() if QT_API == "PyQt6": from PyQt6 import sip - ptr = sip.voidptr(buf) + ptr = int(sip.voidptr(buf)) else: ptr = buf qimage = QtGui.QImage( @@ -38,7 +38,8 @@ def paintEvent(self, event): # Adjust the buf reference count to work around a memory leak bug in # QImage under PySide. if QT_API in ('PySide', 'PySide2'): - ctypes.c_long.from_address(id(buf)).value = 1 + if QtCore.__version_info__ < (5, 12): + ctypes.c_long.from_address(id(buf)).value = 1 _setDevicePixelRatio(qimage, self.device_pixel_ratio) painter = QtGui.QPainter(self) painter.eraseRect(event.rect())