[libcxx-commits] [PATCH] D99520: [libcxx] Convert the result of math.floor to int

Petr Hosek via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 29 10:53:00 PDT 2021


phosek created this revision.
phosek added a reviewer: ldionne.
Herald added a subscriber: arichardson.
phosek requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

In Python 3, math.floor returns int when both arguments are ints.
In Python 2, math.floor returns float. This leads to a failure
because the result of math.floor is used as an array index. While
Python 2 is on its way out, it's still used in some places so
add an explicit cast to avoid the issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99520

Files:
  libcxx/utils/gdb/libcxx/printers.py


Index: libcxx/utils/gdb/libcxx/printers.py
===================================================================
--- libcxx/utils/gdb/libcxx/printers.py
+++ libcxx/utils/gdb/libcxx/printers.py
@@ -439,7 +439,7 @@
 
     def _list_it(self):
         for bit in range(self.bit_count):
-            word = math.floor(bit / self.bits_per_word)
+            word = int(math.floor(bit / self.bits_per_word))
             word_bit = bit % self.bits_per_word
             if self.values[word] & (1 << word_bit):
                 yield ("[%d]" % bit, 1)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99520.333929.patch
Type: text/x-patch
Size: 543 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210329/136d520a/attachment-0001.bin>


More information about the libcxx-commits mailing list