GNU bug report logs - #54376
[PATCH] gnu: python-mypy: Fix test errors on i686-linux.

Previous Next

Package: guix-patches;

Reported by: itd <itd <at> net.in.tum.de>

Date: Sun, 13 Mar 2022 20:14:01 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 54376 in the body.
You can then email your comments to 54376 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#54376; Package guix-patches. (Sun, 13 Mar 2022 20:14:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to itd <itd <at> net.in.tum.de>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Sun, 13 Mar 2022 20:14:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: itd <itd <at> net.in.tum.de>
To: guix-patches <at> gnu.org
Subject: [PATCH] gnu: python-mypy: Fix test errors on i686-linux.
Date: Sun, 13 Mar 2022 21:08:03 +0100
From a8de61a3f6ca50bf4a68222532029e8e9e84c510 Mon Sep 17 00:00:00 2001

* gnu/packages/patches/python-mypy-12332.patch: New patch.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/python-check.scm (python-mypy)[source]<origin>: Use patch
"python-mypy-12332.patch" to avoid overflow issues resulting in test failures.
---
Hi,

currently, python-mypy on i686-linux does not build [0] due to test
errors [1].  To my knowledge, the merged fix [2] is not part of a
release yet.  But, it [2] fixes the python-mypy build for me.  Please
consider applying it.  Thanks!

[0]: https://ci.guix.gnu.org/build/484670/details
[1]: https://github.com/python/mypy/issues/11148
[2]: https://github.com/python/mypy/pull/12332

Regards
itd

 gnu/local.mk                                 |  1 +
 gnu/packages/patches/python-mypy-12332.patch | 68 ++++++++++++++++++++
 gnu/packages/python-check.scm                |  4 +-
 3 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/python-mypy-12332.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 484757b207..05d01c858f 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1716,6 +1716,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/python-versioneer-guix-support.patch	\
   %D%/packages/patches/python-waitress-fix-tests.patch		\
   %D%/packages/patches/python-werkzeug-tests.patch		\
+  %D%/packages/patches/python-mypy-12332.patch			\
   %D%/packages/patches/qemu-build-info-manual.patch		\
   %D%/packages/patches/qemu-glibc-2.27.patch 			\
   %D%/packages/patches/qemu-glibc-2.30.patch 			\
diff --git a/gnu/packages/patches/python-mypy-12332.patch b/gnu/packages/patches/python-mypy-12332.patch
new file mode 100644
index 0000000000..d43cf42ed1
--- /dev/null
+++ b/gnu/packages/patches/python-mypy-12332.patch
@@ -0,0 +1,68 @@
+From 518c864805dd93e62d59439e665a0ce9d6778419 Mon Sep 17 00:00:00 2001
+From: Ekin Dursun <ekindursun <at> gmail.com>
+Date: Thu, 10 Mar 2022 22:06:48 +0300
+Subject: [PATCH] mypyc: Fix overflow in id function (CPyTagged_Id)
+
+In CPython, the id of an object is its address. It's computed by
+converting the pointer to an unsigned integer (PyLong_FromVoidPtr). A
+similar logic is present here, pointer is converted to a Py_ssize_t and
+CPyTagged_FromSsize_t is called with that integer.
+
+There is a problem with that approach: Py_ssize_t cannot hold every
+pointer value. Sometimes overflow happens and CPyTagged_FromSsize_t is
+called with a negative integer.
+
+With the new approach, the number is checked: If it fits in a
+Py_ssize_t, CPyTagged_FromSsize_t is called. If not, it is directly
+converted to a PyObject using PyLong_FromVoidPtr.
+---
+ mypyc/lib-rt/CPy.h      | 1 +
+ mypyc/lib-rt/int_ops.c  | 9 +++++++++
+ mypyc/lib-rt/misc_ops.c | 2 +-
+ 3 files changed, 11 insertions(+), 1 deletion(-)
+
+diff --git a/mypyc/lib-rt/CPy.h b/mypyc/lib-rt/CPy.h
+index 987819154ab..9f5ae52d4e4 100644
+--- a/mypyc/lib-rt/CPy.h
++++ b/mypyc/lib-rt/CPy.h
+@@ -121,6 +121,7 @@ static inline size_t CPy_FindAttrOffset(PyTypeObject *trait, CPyVTableItem *vtab
+ 
+ 
+ CPyTagged CPyTagged_FromSsize_t(Py_ssize_t value);
++CPyTagged CPyTagged_FromVoidPtr(void *ptr);
+ CPyTagged CPyTagged_FromObject(PyObject *object);
+ CPyTagged CPyTagged_StealFromObject(PyObject *object);
+ CPyTagged CPyTagged_BorrowFromObject(PyObject *object);
+diff --git a/mypyc/lib-rt/int_ops.c b/mypyc/lib-rt/int_ops.c
+index 1275f2c1057..edf06314161 100644
+--- a/mypyc/lib-rt/int_ops.c
++++ b/mypyc/lib-rt/int_ops.c
+@@ -26,6 +26,15 @@ CPyTagged CPyTagged_FromSsize_t(Py_ssize_t value) {
+     }
+ }
+ 
++CPyTagged CPyTagged_FromVoidPtr(void *ptr) {
++    if ((uintptr_t)ptr > PY_SSIZE_T_MAX) {
++        PyObject *object = PyLong_FromVoidPtr(ptr);
++        return ((CPyTagged)object) | CPY_INT_TAG;
++    } else {
++        return CPyTagged_FromSsize_t((Py_ssize_t)ptr);
++    }
++}
++
+ CPyTagged CPyTagged_FromObject(PyObject *object) {
+     int overflow;
+     // The overflow check knows about CPyTagged's width
+diff --git a/mypyc/lib-rt/misc_ops.c b/mypyc/lib-rt/misc_ops.c
+index cebd1cf997f..dcce89d9072 100644
+--- a/mypyc/lib-rt/misc_ops.c
++++ b/mypyc/lib-rt/misc_ops.c
+@@ -437,7 +437,7 @@ CPyPickle_GetState(PyObject *obj)
+ }
+ 
+ CPyTagged CPyTagged_Id(PyObject *o) {
+-    return CPyTagged_FromSsize_t((Py_ssize_t)o);
++    return CPyTagged_FromVoidPtr(o);
+ }
+ 
+ #define MAX_INT_CHARS 22
diff --git a/gnu/packages/python-check.scm b/gnu/packages/python-check.scm
index 05a378601f..5bbe544113 100644
--- a/gnu/packages/python-check.scm
+++ b/gnu/packages/python-check.scm
@@ -1658,7 +1658,9 @@ supported by the MyPy typechecker.")
        (file-name (git-file-name name version))
        (sha256
         (base32
-         "1v83flrdxh8grcp40qw04q4hzjflih9xwib64078vsxv2w36f817"))))
+         "1v83flrdxh8grcp40qw04q4hzjflih9xwib64078vsxv2w36f817"))
+       (patches
+        (search-patches "python-mypy-12332.patch"))))
     (build-system python-build-system)
     (arguments
      `(#:phases
-- 
2.30.2






Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Sat, 19 Mar 2022 22:22:02 GMT) Full text and rfc822 format available.

Notification sent to itd <itd <at> net.in.tum.de>:
bug acknowledged by developer. (Sat, 19 Mar 2022 22:22:02 GMT) Full text and rfc822 format available.

Message #10 received at 54376-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: itd <itd <at> net.in.tum.de>
Cc: 54376-done <at> debbugs.gnu.org
Subject: Re: bug#54376: [PATCH] gnu: python-mypy: Fix test errors on
 i686-linux.
Date: Sat, 19 Mar 2022 23:21:14 +0100
Hi,

itd <itd <at> net.in.tum.de> skribis:

>>From a8de61a3f6ca50bf4a68222532029e8e9e84c510 Mon Sep 17 00:00:00 2001
>
> * gnu/packages/patches/python-mypy-12332.patch: New patch.
> * gnu/local.mk (dist_patch_DATA): Add it.
> * gnu/packages/python-check.scm (python-mypy)[source]<origin>: Use patch
> "python-mypy-12332.patch" to avoid overflow issues resulting in test failures.
> ---
> Hi,
>
> currently, python-mypy on i686-linux does not build [0] due to test
> errors [1].  To my knowledge, the merged fix [2] is not part of a
> release yet.  But, it [2] fixes the python-mypy build for me.  Please
> consider applying it.  Thanks!

Perfect, applied!

Thanks,
Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 17 Apr 2022 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 60 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.