public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-python/numpy/files/, dev-python/numpy/
Date: Mon, 26 Jun 2023 13:14:47 +0000 (UTC)	[thread overview]
Message-ID: <1687785258.6e1f8eac3fc440fe8fe3de5d6f408e1a209df777.sam@gentoo> (raw)

commit:     6e1f8eac3fc440fe8fe3de5d6f408e1a209df777
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 26 13:11:27 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Jun 26 13:14:18 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6e1f8eac

dev-python/numpy: backport long double check fix

Many thanks to matoro for this.

Closes: https://bugs.gentoo.org/908738
Signed-off-by: Sam James <sam <AT> gentoo.org>

 .../files/numpy-1.25.0-fix-long-double-check.patch | 151 +++++++++++++++++++++
 dev-python/numpy/numpy-1.25.0.ebuild               |   1 +
 2 files changed, 152 insertions(+)

diff --git a/dev-python/numpy/files/numpy-1.25.0-fix-long-double-check.patch b/dev-python/numpy/files/numpy-1.25.0-fix-long-double-check.patch
new file mode 100644
index 000000000000..4f3ef21c93b3
--- /dev/null
+++ b/dev-python/numpy/files/numpy-1.25.0-fix-long-double-check.patch
@@ -0,0 +1,151 @@
+https://github.com/numpy/numpy/commit/de0b2d5c6dee9303c4a055e7591978ed5a06e403
+
+From de0b2d5c6dee9303c4a055e7591978ed5a06e403 Mon Sep 17 00:00:00 2001
+From: matoro <matoro@users.noreply.github.com>
+Date: Sun, 18 Jun 2023 19:39:06 -0400
+Subject: [PATCH] BLD: Port long double identification to C for meson
+
+This ports the old Python code for identifying the long double
+representation to C, so that it can be easily invoked by meson.  The
+original implementation is at https://github.com/numpy/numpy/blob/eead09a3d02c09374942cdc787c0b5e4fe9e7472/numpy/core/setup_common.py#L264-L434
+
+The C portion of the code has been tested and confirmed to work on
+systems with the following formats, either natively or via an
+alternative ABI:  INTEL_EXTENDED_16_BYTES_LE, IEEE_QUAD_BE,
+IEEE_QUAD_LE, IBM_DOUBLE_DOUBLE_BE, IBM_DOUBLE_DOUBLE_LE,
+IEEE_DOUBLE_BE, INTEL_EXTENDED_12_BYTES_LE.
+
+The original meson port includes an error condition with the comment
+"This should not be possible, 12 bits of "content" should still result
+in sizeof() being 16."  As far as I can tell this is incorrect, as
+compiling on an x86_64 system with 32-bit ABI (gcc -m32) does indeed
+have sizeof(long double)==12.  This is reflected in the C code.
+
+Closes gh-23972, closes
+https://github.com/mesonbuild/meson/issues/11068.
+---
+ numpy/core/meson.build | 110 ++++++++++++++++++++++++++++++++---------
+ 1 file changed, 87 insertions(+), 23 deletions(-)
+
+diff --git a/numpy/core/meson.build b/numpy/core/meson.build
+index 3427de408f1..92b393e4bc1 100644
+--- a/numpy/core/meson.build
++++ b/numpy/core/meson.build
+@@ -361,29 +361,93 @@ foreach intrin: optional_intrinsics
+   endif
+ endforeach
+ 
+-# long double representation detection (see setup_common.py)
+-# TODO: this is still incomplete, and different from how it's done in the
+-# numpy.distutils based build, see https://github.com/mesonbuild/meson/issues/11068
+-longdouble_size = cc.sizeof('long double')
+-if longdouble_size == 8
+-  if host_machine.endian() == 'little'
+-    longdouble_format = 'IEEE_DOUBLE_LE'
+-  else
+-    longdouble_format = 'IEEE_DOUBLE_BE'
+-  endif
+-elif longdouble_size == 12
+-  error('This should not be possible, 12 bits of "content" should still result in sizeof() being 16. Please report this error!'
+-  )
+-elif longdouble_size == 16
+-  if host_machine.endian() == 'little'
+-    # FIXME: this varies, there's multiple formats here! Not yet implemented.
+-    #        TBD how we deal with the mess of old long double formats.
+-    longdouble_format = 'INTEL_EXTENDED_16_BYTES_LE'
+-  else
+-    error('No idea what this is ....')
+-  endif
+-else
+-  error('Unknown long double size: ' + londouble_size)
++# This is a port of the old python code for identifying the long double
++# representation to C.  The old Python code is in this range:
++# https://github.com/numpy/numpy/blob/eead09a3d02c09374942cdc787c0b5e4fe9e7472/numpy/core/setup_common.py#L264-L434
++# This port is in service of solving gh-23972
++# as well as https://github.com/mesonbuild/meson/issues/11068
++longdouble_format = meson.get_compiler('c').run(
++'''
++#include <stdio.h>
++#include <string.h>
++
++#define repcmp(z) (memcmp((const char *)&foo.x, z, sizeof(foo.x)) == 0)
++
++const struct {
++  char before[16];
++  long double x;
++  char after[8];
++} foo = {{'\0'}, -123456789.0, {'\0'}};
++
++int main(void) {
++  switch (sizeof(foo.x)) {
++  case 8: {
++    if (repcmp(
++            ((const char[]){0000, 0000, 0000, 0124, 0064, 0157, 0235, 0301}))) {
++      fprintf(stdout, "IEEE_DOUBLE_LE");
++      return 0;
++    }
++    if (repcmp(
++            ((const char[]){0301, 0235, 0157, 0064, 0124, 0000, 0000, 0000}))) {
++      fprintf(stdout, "IEEE_DOUBLE_BE");
++      return 0;
++    }
++    fprintf(stdout, "UNKNOWN");
++    return 1;
++  }
++  case 12: {
++    if (repcmp(((const char[]){0000, 0000, 0000, 0000, 0240, 0242, 0171, 0353,
++                               0031, 0300, 0000, 0000}))) {
++      fprintf(stdout, "INTEL_EXTENDED_12_BYTES_LE");
++      return 0;
++    }
++    if (repcmp(((const char[]){0300, 0031, 0000, 0000, 0353, 0171, 0242, 0240,
++                               0000, 0000, 0000, 0000}))) {
++      fprintf(stdout, "MOTOROLA_EXTENDED_12_BYTES_BE");
++      return 0;
++    }
++    fprintf(stdout, "UNKNOWN");
++    return 1;
++  }
++  case 16: {
++    if (repcmp(
++            ((const char[]){0000, 0000, 0000, 0000, 0240, 0242, 0171, 0353,
++                            0031, 0300, 0000, 0000, 0000, 0000, 0000, 0000}))) {
++      fprintf(stdout, "INTEL_EXTENDED_16_BYTES_LE");
++      return 0;
++    }
++    if (repcmp(
++            ((const char[]){0300, 0031, 0326, 0363, 0105, 0100, 0000, 0000,
++                            0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000}))) {
++      fprintf(stdout, "IEEE_QUAD_BE");
++      return 0;
++    }
++    if (repcmp(
++            ((const char[]){0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
++                            0000, 0000, 0100, 0105, 0363, 0326, 0031, 0300}))) {
++      fprintf(stdout, "IEEE_QUAD_LE");
++      return 0;
++    }
++    if (repcmp(
++            ((const char[]){0000, 0000, 0000, 0124, 0064, 0157, 0235, 0301,
++                            0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000}))) {
++      fprintf(stdout, "IBM_DOUBLE_DOUBLE_LE");
++      return 0;
++    }
++    if (repcmp(
++            ((const char[]){0301, 0235, 0157, 0064, 0124, 0000, 0000, 0000,
++                            0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000}))) {
++      fprintf(stdout, "IBM_DOUBLE_DOUBLE_BE");
++      return 0;
++    }
++    fprintf(stdout, "UNKNOWN");
++    return 1;
++  }
++  }
++}
++''').stdout()
++if longdouble_format == 'UNKNOWN' or longdouble_format == 'UNDEFINED'
++  error('Unknown long double format of size: ' + cc.sizeof('long double').to_string())
+ endif
+ cdata.set10('HAVE_LDOUBLE_' + longdouble_format, true)
+ 
+

diff --git a/dev-python/numpy/numpy-1.25.0.ebuild b/dev-python/numpy/numpy-1.25.0.ebuild
index fc0a38bcd8ac..46dd443d0758 100644
--- a/dev-python/numpy/numpy-1.25.0.ebuild
+++ b/dev-python/numpy/numpy-1.25.0.ebuild
@@ -53,6 +53,7 @@ BDEPEND="
 PATCHES=(
 	"${FILESDIR}"/${PN}-1.25.0_rc1-meson-pyproject.toml.patch
 	"${FILESDIR}"/${PN}-1.25.0-skip-python3.12-irrelevant-tests.patch
+	"${FILESDIR}"/${PN}-1.25.0-fix-long-double-check.patch
 )
 
 distutils_enable_tests pytest


             reply	other threads:[~2023-06-26 13:14 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-26 13:14 Sam James [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-06-13  3:51 [gentoo-commits] repo/gentoo:master commit in: dev-python/numpy/files/, dev-python/numpy/ Michał Górny
2024-05-26 14:28 Michał Górny
2023-12-11 13:43 Michał Górny
2023-09-30  8:40 Michał Górny
2023-07-26  4:55 Sam James
2023-07-08 11:30 Benda XU
2023-06-12 15:22 Sam James
2023-06-12  0:45 Sam James
2022-05-23  8:33 Michał Górny
2022-01-26  8:38 Michał Górny
2022-01-14 20:32 Sam James
2022-01-06 16:31 Sam James
2021-11-24  1:49 Sam James
2021-11-17 23:13 Sam James
2021-10-24 20:52 Michał Górny
2020-04-16 17:44 Mike Gilbert
2019-12-29 16:11 罗百科
2019-06-24  4:31 Benda XU
2018-01-05 13:26 Michał Górny
2017-05-03  7:37 Michał Górny
2017-04-14 19:34 Justin Lecher
2017-02-15  2:38 Benda XU
2016-08-30 17:26 David Seifert
2015-12-16  8:49 Justin Lecher
2015-10-21 13:41 Justin Lecher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1687785258.6e1f8eac3fc440fe8fe3de5d6f408e1a209df777.sam@gentoo \
    --to=sam@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox