From 5de3037e95273ede31452b025bd713a20c5086ca Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Apr 11 2021 08:04:07 +0000 Subject: Fix crash on big-endian machines. --- diff --git a/0001-Fix-pkg-config-handling.patch b/0001-Fix-pkg-config-handling.patch new file mode 100644 index 0000000..e107622 --- /dev/null +++ b/0001-Fix-pkg-config-handling.patch @@ -0,0 +1,42 @@ +From 11bb8a3950acf5d61aaf78e4b7fd3c62ba997384 Mon Sep 17 00:00:00 2001 +From: Antony Lee +Date: Sun, 4 Apr 2021 15:35:27 +0200 +Subject: [PATCH 1/2] Fix pkg-config handling. + +Signed-off-by: Elliott Sales de Andrade +--- + setup.py | 16 ++++++++++------ + 1 file changed, 10 insertions(+), 6 deletions(-) + +diff --git a/setup.py b/setup.py +index 1f4f4c0..b06fd18 100644 +--- a/setup.py ++++ b/setup.py +@@ -111,14 +111,18 @@ class build_ext(build_ext): + is_arch = "Arch Linux" in Path("/etc/os-release").read_text() + except OSError: + is_arch = False +- has_pkgconfig_raqm = False +- if not is_arch: ++ if is_arch: ++ has_pkgconfig_raqm = False ++ else: + try: +- has_pkgconfig_raqm = get_pkgconfig( +- f"--atleast-version={MIN_RAQM_VERSION}", "raqm") ++ get_pkgconfig(f"--atleast-version={MIN_RAQM_VERSION}", "raqm") + except (FileNotFoundError, CalledProcessError): +- pass +- if not has_pkgconfig_raqm: ++ has_pkgconfig_raqm = False ++ else: ++ has_pkgconfig_raqm = True ++ if has_pkgconfig_raqm: ++ ext.extra_compile_args += get_pkgconfig("--cflags", "raqm") ++ else: + (tmp_include_dir / "raqm-version.h").write_text("") # Touch it. + with urllib.request.urlopen( + f"https://raw.githubusercontent.com/HOST-Oman/libraqm/" +-- +2.29.2 + diff --git a/0002-Fix-RGBA-processing-on-big-endian-machines.patch b/0002-Fix-RGBA-processing-on-big-endian-machines.patch new file mode 100644 index 0000000..dbeae53 --- /dev/null +++ b/0002-Fix-RGBA-processing-on-big-endian-machines.patch @@ -0,0 +1,35 @@ +From dfb31cdc3ca614f97d843c8d799e35504ad6b826 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 11 Apr 2021 02:13:41 -0400 +Subject: [PATCH 2/2] Fix RGBA processing on big-endian machines. + +Signed-off-by: Elliott Sales de Andrade +--- + src/_mplcairo.cpp | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/_mplcairo.cpp b/src/_mplcairo.cpp +index 8f16841..fc90572 100644 +--- a/src/_mplcairo.cpp ++++ b/src/_mplcairo.cpp +@@ -129,7 +129,7 @@ py::bytes Region::get_straight_argb32_bytes() { + } + } else { // big-endian + auto u32_ptr = static_cast(buf.ptr); +- for (auto i = 0; i < size; i += 4) { ++ for (auto i = 0; i < size / 4; i++) { + u32_ptr[i] = (u32_ptr[i] >> 8) + (u32_ptr[i] << 24); // RGBA->ARGB + } + } +@@ -1816,7 +1816,7 @@ py::array_t cairo_to_premultiplied_rgba8888( + } + } else { // big-endian + auto u32_ptr = reinterpret_cast(u8.mutable_data()); +- for (auto i = 0; i < size; i += 4) { ++ for (auto i = 0; i < size / 4; i++) { + u32_ptr[i] = (u32_ptr[i] << 8) + (u32_ptr[i] >> 24); // ARGB->RGBA + } + } +-- +2.29.2 + diff --git a/11bb8a3950acf5d61aaf78e4b7fd3c62ba997384.patch b/11bb8a3950acf5d61aaf78e4b7fd3c62ba997384.patch deleted file mode 100644 index 7661534..0000000 --- a/11bb8a3950acf5d61aaf78e4b7fd3c62ba997384.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 11bb8a3950acf5d61aaf78e4b7fd3c62ba997384 Mon Sep 17 00:00:00 2001 -From: Antony Lee -Date: Sun, 4 Apr 2021 15:35:27 +0200 -Subject: [PATCH] Fix pkg-config handling. - ---- - setup.py | 16 ++++++++++------ - 1 file changed, 10 insertions(+), 6 deletions(-) - -diff --git a/setup.py b/setup.py -index 1f4f4c0..b06fd18 100644 ---- a/setup.py -+++ b/setup.py -@@ -111,14 +111,18 @@ def finalize_options(self): - is_arch = "Arch Linux" in Path("/etc/os-release").read_text() - except OSError: - is_arch = False -- has_pkgconfig_raqm = False -- if not is_arch: -+ if is_arch: -+ has_pkgconfig_raqm = False -+ else: - try: -- has_pkgconfig_raqm = get_pkgconfig( -- f"--atleast-version={MIN_RAQM_VERSION}", "raqm") -+ get_pkgconfig(f"--atleast-version={MIN_RAQM_VERSION}", "raqm") - except (FileNotFoundError, CalledProcessError): -- pass -- if not has_pkgconfig_raqm: -+ has_pkgconfig_raqm = False -+ else: -+ has_pkgconfig_raqm = True -+ if has_pkgconfig_raqm: -+ ext.extra_compile_args += get_pkgconfig("--cflags", "raqm") -+ else: - (tmp_include_dir / "raqm-version.h").write_text("") # Touch it. - with urllib.request.urlopen( - f"https://raw.githubusercontent.com/HOST-Oman/libraqm/" diff --git a/python-mplcairo.spec b/python-mplcairo.spec index bf297c1..f5fcdc3 100644 --- a/python-mplcairo.spec +++ b/python-mplcairo.spec @@ -8,7 +8,10 @@ Summary: A (new) cairo backend for Matplotlib License: MIT URL: https://github.com/matplotlib/mplcairo Source0: %pypi_source -Patch0001: https://github.com/matplotlib/mplcairo/commit/11bb8a3950acf5d61aaf78e4b7fd3c62ba997384.patch +# https://github.com/matplotlib/mplcairo/commit/11bb8a3950acf5d61aaf78e4b7fd3c62ba997384 +Patch0001: 0001-Fix-pkg-config-handling.patch +# https://github.com/matplotlib/mplcairo/pull/30 +Patch0002: 0002-Fix-RGBA-processing-on-big-endian-machines.patch BuildRequires: gcc-c++