Skip to content

Commit

Permalink
Merge pull request #27793 from QuLogic/backport-crash-fixes
Browse files Browse the repository at this point in the history
Backport crash fixes to v3.7.x
  • Loading branch information
ksunden committed Feb 15, 2024
2 parents 03947d0 + e97c7f3 commit 3d76f2d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 35 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
https://github.com/qhull/qhull/raw/2020.2/COPYING.txt
- name: Build wheels for CPython 3.12
uses: pypa/cibuildwheel@39a63b5912f086dd459cf6fcb13dcdd3fe3bc24d # v2.15.0
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
env:
CIBW_BUILD: "cp312-*"
CIBW_SKIP: "*-musllinux* *i686* *win32*"
Expand All @@ -94,7 +94,7 @@ jobs:
pip install --pre "numpy>=1.25"
- name: Build wheels for CPython 3.11
uses: pypa/cibuildwheel@39a63b5912f086dd459cf6fcb13dcdd3fe3bc24d # v2.15.0
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
env:
CIBW_BUILD: "cp311-*"
CIBW_SKIP: "*-musllinux*"
Expand All @@ -107,7 +107,7 @@ jobs:
CIBW_ARCHS: ${{ matrix.cibw_archs }}

- name: Build wheels for CPython 3.10
uses: pypa/cibuildwheel@39a63b5912f086dd459cf6fcb13dcdd3fe3bc24d # v2.15.0
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
env:
CIBW_BUILD: "cp310-*"
CIBW_SKIP: "*-musllinux*"
Expand All @@ -120,7 +120,7 @@ jobs:
CIBW_ARCHS: ${{ matrix.cibw_archs }}

- name: Build wheels for CPython 3.9
uses: pypa/cibuildwheel@39a63b5912f086dd459cf6fcb13dcdd3fe3bc24d # v2.15.0
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
env:
CIBW_BUILD: "cp39-*"
CIBW_SKIP: "*-musllinux*"
Expand All @@ -133,7 +133,7 @@ jobs:
CIBW_ARCHS: ${{ matrix.cibw_archs }}

- name: Build wheels for CPython 3.8
uses: pypa/cibuildwheel@39a63b5912f086dd459cf6fcb13dcdd3fe3bc24d # v2.15.0
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
env:
CIBW_BUILD: "cp38-*"
CIBW_SKIP: "*-musllinux*"
Expand All @@ -146,7 +146,7 @@ jobs:
CIBW_ARCHS: ${{ matrix.cibw_archs }}

- name: Build wheels for PyPy 3.8
uses: pypa/cibuildwheel@39a63b5912f086dd459cf6fcb13dcdd3fe3bc24d # v2.15.0
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
env:
CIBW_BUILD: "pp38-*"
CIBW_SKIP: "*-musllinux*"
Expand All @@ -157,7 +157,7 @@ jobs:
if: matrix.cibw_archs != 'aarch64'

- name: Build wheels for PyPy 3.9
uses: pypa/cibuildwheel@39a63b5912f086dd459cf6fcb13dcdd3fe3bc24d # v2.15.0
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
env:
CIBW_BUILD: "pp39-*"
CIBW_SKIP: "*-musllinux*"
Expand Down
37 changes: 20 additions & 17 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,24 +286,14 @@ def __init__(self):
self._finalize_tmpdir = weakref.finalize(self, self._tmpdir.cleanup)

# test the LaTeX setup to ensure a clean startup of the subprocess
try:
self._setup_latex_process(expect_reply=False)
except FileNotFoundError as err:
raise RuntimeError(
f"{self.latex.args[0]!r} not found. Install it or change "
f"rcParams['pgf.texsystem'] to an available TeX "
f"implementation.") from err
except OSError as err:
raise RuntimeError(
f"Error starting process {self.latex.args[0]!r}") from err
self._setup_latex_process(expect_reply=False)
stdout, stderr = self.latex.communicate("\n\\makeatletter\\@@end\n")
if self.latex.returncode != 0:
raise LatexError(
f"LaTeX errored (probably missing font or error in preamble) "
f"while processing the following input:\n"
f"{self._build_latex_header()}",
stdout)

self.latex = None # Will be set up on first use.
# Per-instance cache.
self._get_box_metrics = functools.lru_cache()(self._get_box_metrics)
Expand All @@ -317,15 +307,28 @@ def _setup_latex_process(self, *, expect_reply=True):
# Open LaTeX process for real work; register it for deletion. On
# Windows, we must ensure that the subprocess has quit before being
# able to delete the tmpdir in which it runs; in order to do so, we
# must first `kill()` it, and then `communicate()` with it.
self.latex = subprocess.Popen(
[mpl.rcParams["pgf.texsystem"], "-halt-on-error"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
encoding="utf-8", cwd=self.tmpdir)
# must first `kill()` it, and then `communicate()` with or `wait()` on
# it.
try:
self.latex = subprocess.Popen(
[mpl.rcParams["pgf.texsystem"], "-halt-on-error"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
encoding="utf-8", cwd=self.tmpdir)
except FileNotFoundError as err:
raise RuntimeError(
f"{mpl.rcParams['pgf.texsystem']!r} not found; install it or change "
f"rcParams['pgf.texsystem'] to an available TeX implementation"
) from err
except OSError as err:
raise RuntimeError(
f"Error starting {mpl.rcParams['pgf.texsystem']!r}") from err

def finalize_latex(latex):
latex.kill()
latex.communicate()
try:
latex.communicate()
except RuntimeError:
latex.wait()

self._finalize_latex = weakref.finalize(
self, finalize_latex, self.latex)
Expand Down
11 changes: 8 additions & 3 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
import itertools
import unittest.mock
from packaging.version import parse as parse_version

from io import BytesIO
import numpy as np
Expand Down Expand Up @@ -146,9 +147,13 @@ def test_double_register_builtin_cmap():
with pytest.raises(ValueError, match='A colormap named "viridis"'):
with pytest.warns(mpl.MatplotlibDeprecationWarning):
cm.register_cmap(name, mpl.colormaps[name])
with pytest.warns(UserWarning):
# TODO is warning more than once!
cm.register_cmap(name, mpl.colormaps[name], override_builtin=True)

if parse_version(pytest.__version__).major < 8:
with pytest.warns(UserWarning):
cm.register_cmap(name, mpl.colormaps[name], override_builtin=True)
else:
with pytest.warns(UserWarning), pytest.warns(mpl.MatplotlibDeprecationWarning):
cm.register_cmap(name, mpl.colormaps[name], override_builtin=True)


def test_unregister_builtin_cmap():
Expand Down
6 changes: 2 additions & 4 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,12 @@ def test_rcparams_update():
rc = mpl.RcParams({'figure.figsize': (3.5, 42)})
bad_dict = {'figure.figsize': (3.5, 42, 1)}
# make sure validation happens on input
with pytest.raises(ValueError), \
pytest.warns(UserWarning, match="validate"):
with pytest.raises(ValueError):
rc.update(bad_dict)


def test_rcparams_init():
with pytest.raises(ValueError), \
pytest.warns(UserWarning, match="validate"):
with pytest.raises(ValueError):
mpl.RcParams({'figure.figsize': (3.5, 42, 1)})


Expand Down
16 changes: 12 additions & 4 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import locale
import logging
import re
from packaging.version import parse as parse_version

import numpy as np
from numpy.testing import assert_almost_equal, assert_array_equal
Expand Down Expand Up @@ -730,10 +731,17 @@ def test_mathtext_ticks(self):
'axes.formatter.use_mathtext': False
})

with pytest.warns(UserWarning, match='cmr10 font should ideally'):
fig, ax = plt.subplots()
ax.set_xticks([-1, 0, 1])
fig.canvas.draw()
if parse_version(pytest.__version__).major < 8:
with pytest.warns(UserWarning, match='cmr10 font should ideally'):
fig, ax = plt.subplots()
ax.set_xticks([-1, 0, 1])
fig.canvas.draw()
else:
with pytest.warns(UserWarning, match="Glyph 8722"), \
pytest.warns(UserWarning, match='cmr10 font should ideally'):
fig, ax = plt.subplots()
ax.set_xticks([-1, 0, 1])
fig.canvas.draw()

def test_cmr10_substitutions(self, caplog):
mpl.rcParams.update({
Expand Down
4 changes: 4 additions & 0 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ int mpl_check_modifier(
close(channel[0]);
}

Py_BEGIN_ALLOW_THREADS

NSDate* date =
(timeout > 0.0) ? [NSDate dateWithTimeIntervalSinceNow: timeout]
: [NSDate distantFuture];
Expand All @@ -559,6 +561,8 @@ int mpl_check_modifier(
[NSApp sendEvent: event];
}

Py_END_ALLOW_THREADS

if (py_sigint_handler) { PyOS_setsig(SIGINT, py_sigint_handler); }
if (sigint_socket) { CFSocketInvalidate(sigint_socket); }
if (!error) { close(channel[1]); }
Expand Down

0 comments on commit 3d76f2d

Please sign in to comment.