Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

popcount conflict #189

Closed
0-wiz-0 opened this issue Feb 20, 2023 · 5 comments
Closed

popcount conflict #189

0-wiz-0 opened this issue Feb 20, 2023 · 5 comments

Comments

@0-wiz-0
Copy link

0-wiz-0 commented Feb 20, 2023

NetBSD provides its own set of popcount functions since about 2009:
https://man.netbsd.org/popcount.3

bitarray 2.7.2 breaks on NetBSD because:

In file included from bitarray/_bitarray.c:14:
bitarray/bitarray.h:171:1: error: conflicting types for 'popcount64'
  171 | popcount64(uint64_t x)
      | ^~~~~~~~~~
In file included from bitarray/_util.c:13:
bitarray/bitarray.h:171:1: error: conflicting types for 'popcount64'
  171 | popcount64(uint64_t x)
      | ^~~~~~~~~~
In file included from /usr/include/string.h:98,
                 from /scratch/devel/py-bitarray/work/.buildlink/include/python3.11/Python.h:26,
                 from bitarray/_bitarray.c:12:
/usr/include/strings.h:61:14: note: previous declaration of 'popcount64' was here
   61 | unsigned int popcount64(__uint64_t) __constfunc;
      |              ^~~~~~~~~~
In file included from /usr/include/string.h:98,
                 from /scratch/devel/py-bitarray/work/.buildlink/include/python3.11/Python.h:26,
                 from bitarray/_util.c:11:
/usr/include/strings.h:61:14: note: previous declaration of 'popcount64' was here
   61 | unsigned int popcount64(__uint64_t) __constfunc;
      |              ^~~~~~~~~~

Please rename the function, or detect and use the builtin one on NetBSD. Thanks.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Feb 20, 2023
This defines its own popcount.
Reported upstream at
ilanschnell/bitarray#189
@ilanschnell
Copy link
Owner

Thanks for reporting this issue and for using bitarray.
I just renamed the function in d8ce774 . Can you confirm that there no other issues on NetBSD, before I tag a new release? Thanks

@0-wiz-0
Copy link
Author

0-wiz-0 commented Feb 20, 2023

Thanks for fixing this so quickly! git head now builds fine.
I tried python setup.py build and python setup.py test and the tests mostly worked except for:

======================================================================
ERROR: test_copy_n_example (bitarray.test_bitarray.InternalTests.test_copy_n_example)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 732, in test_copy_n_example
    x._copy_n(21, y, 6, 31)
    ^^^^^^^^^
AttributeError: 'bitarray.bitarray' object has no attribute '_copy_n'

======================================================================
ERROR: test_copy_n_explicit (bitarray.test_bitarray.InternalTests.test_copy_n_explicit)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 714, in test_copy_n_explicit
    x._copy_n(4, y, 1, 5)
    ^^^^^^^^^
AttributeError: 'bitarray.bitarray' object has no attribute '_copy_n'

======================================================================
ERROR: test_copy_n_random_other (bitarray.test_bitarray.InternalTests.test_copy_n_random_other)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 766, in test_copy_n_random_other
    self.check_copy_n(N, M, a, b, n)
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 741, in check_copy_n
    x._copy_n(a, y, b, n)
    ^^^^^^^^^
AttributeError: 'bitarray.bitarray' object has no attribute '_copy_n'

======================================================================
ERROR: test_copy_n_random_self (bitarray.test_bitarray.InternalTests.test_copy_n_random_self)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 758, in test_copy_n_random_self
    self.check_copy_n(N, -1, a, b, n)
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 741, in check_copy_n
    x._copy_n(a, y, b, n)
    ^^^^^^^^^
AttributeError: 'bitarray.bitarray' object has no attribute '_copy_n'

======================================================================
ERROR: test_copy_n_range (bitarray.test_bitarray.InternalTests.test_copy_n_range)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 750, in test_copy_n_range
    self.check_copy_n(100,  -1, a, b, n)
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 741, in check_copy_n
    x._copy_n(a, y, b, n)
    ^^^^^^^^^
AttributeError: 'bitarray.bitarray' object has no attribute '_copy_n'

======================================================================
ERROR: test_getslice (bitarray.test_bitarray.InternalTests.test_getslice)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 781, in test_getslice
    b = self.getslice(a, i, j - i)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 772, in getslice
    b._copy_n(0, a, start, slicelength)
    ^^^^^^^^^
AttributeError: 'bitarray.bitarray' object has no attribute '_copy_n'

======================================================================
ERROR: test_overlap_distinct (bitarray.test_bitarray.InternalTests.test_overlap_distinct)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 802, in test_overlap_distinct
    self.check_overlap(a, a, bool(a))
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 786, in check_overlap
    r1 = a._overlap(b)
         ^^^^^^^^^^
AttributeError: 'bitarray.bitarray' object has no attribute '_overlap'

======================================================================
ERROR: test_overlap_empty (bitarray.test_bitarray.InternalTests.test_overlap_empty)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 795, in test_overlap_empty
    self.check_overlap(a, a, False)
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 786, in check_overlap
    r1 = a._overlap(b)
         ^^^^^^^^^^
AttributeError: 'bitarray.bitarray' object has no attribute '_overlap'

======================================================================
ERROR: test_overlap_shared (bitarray.test_bitarray.InternalTests.test_overlap_shared)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 809, in test_overlap_shared
    self.check_overlap(b, a, True)
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 786, in check_overlap
    r1 = a._overlap(b)
         ^^^^^^^^^^
AttributeError: 'bitarray.bitarray' object has no attribute '_overlap'

======================================================================
ERROR: test_overlap_shared_random (bitarray.test_bitarray.InternalTests.test_overlap_shared_random)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 842, in test_overlap_shared_random
    self.check_overlap(b1, b2, (x1 & x2).any())
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 786, in check_overlap
    r1 = a._overlap(b)
         ^^^^^^^^^^
AttributeError: 'bitarray.bitarray' object has no attribute '_overlap'

======================================================================
ERROR: test_shift_r8_empty (bitarray.test_bitarray.InternalTests.test_shift_r8_empty)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 677, in test_shift_r8_empty
    a._shift_r8(0, 0, 3)
    ^^^^^^^^^^^
AttributeError: 'bitarray.bitarray' object has no attribute '_shift_r8'

======================================================================
ERROR: test_shift_r8_explicit (bitarray.test_bitarray.InternalTests.test_shift_r8_explicit)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 689, in test_shift_r8_explicit
    x._shift_r8(1, 4, 5)
    ^^^^^^^^^^^
AttributeError: 'bitarray.bitarray' object has no attribute '_shift_r8'

======================================================================
ERROR: test_shift_r8_random_bytes (bitarray.test_bitarray.InternalTests.test_shift_r8_random_bytes)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_bitarray.py", line 704, in test_shift_r8_random_bytes
    x._shift_r8(a, b, n)
    ^^^^^^^^^^^
AttributeError: 'bitarray.bitarray' object has no attribute '_shift_r8'

======================================================================
FAIL: test_encode_zeros (bitarray.test_util.SC_Tests.test_encode_zeros)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/bitarray/bitarray/test_util.py", line 1404, in test_encode_zeros
    self.assertEqual(
AssertionError: b'\x04\x00\x00\x00\x02\xc4\x01\x00\x00\x00\x00\x00' != b'\x14\x00\x00\x00\x02\xc4\x01\x00\x00\x00\x00\x00'

----------------------------------------------------------------------
Ran 480 tests in 0.903s

FAILED (failures=1, errors=13)

Not sure what goes wrong here.

# python --version
Python 3.11.2

@ilanschnell
Copy link
Owner

Most of those errors you see are from tests which should only be run in debug mode (compiling the extension without the -DNDEBUG flag). These additional debug tests https://github.com/ilanschnell/bitarray/blob/master/bitarray/test_bitarray.py#L670 test bitarray methods which are only added in debug mode https://github.com/ilanschnell/bitarray/blob/master/bitarray/_bitarray.c#L1754 .

It is very strange that these tests are being run.
Ah, I see now. You use python setup.py test (which I didn't even know about), and get I get the same errors. Please use make test. This will run python -c "import bitarray; bitarray.test()" which is the proper way of testing bitarray. You can even run this once the library is installed on a system, and the setup.py isn't there anymore.

Thanks for testing!

@0-wiz-0
Copy link
Author

0-wiz-0 commented Feb 20, 2023

Yes, that works!

DEBUG: 0
.....................................................................................................................................................................
.....................................................................................................................................................................
.........................................................................................................................................
----------------------------------------------------------------------
Ran 467 tests in 0.645s

OK

Thanks for the pointer.

@ilanschnell
Copy link
Owner

I just released bitarray 2.7.3 which includes this fix. Thanks again for reporting the issue and testing on NetBSD.
BTW: Since you're probably not the only person who tried python setup.py test, I made that work now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants