bitarray 3.10.1__tar.gz → 3.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bitarray-3.10.1 → bitarray-3.11.0}/PKG-INFO +53 -16
- {bitarray-3.10.1 → bitarray-3.11.0}/README.rst +52 -15
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray/__init__.py +1 -2
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray/__init__.pyi +0 -1
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray/_bitarray.c +18 -23
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray/_util.c +503 -141
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray/bitarray.h +9 -7
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray/test_bitarray.py +4 -3
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray/test_free_threading.py +6 -3
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray/test_util.py +466 -148
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray/util.py +77 -17
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray/util.pyi +4 -1
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray.egg-info/PKG-INFO +53 -16
- {bitarray-3.10.1 → bitarray-3.11.0}/LICENSE +0 -0
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray/py.typed +0 -0
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray/pythoncapi_compat.h +0 -0
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray/test_281.pickle +0 -0
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray.egg-info/SOURCES.txt +0 -0
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray.egg-info/dependency_links.txt +0 -0
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray.egg-info/not-zip-safe +0 -0
- {bitarray-3.10.1 → bitarray-3.11.0}/bitarray.egg-info/top_level.txt +0 -0
- {bitarray-3.10.1 → bitarray-3.11.0}/pyproject.toml +0 -0
- {bitarray-3.10.1 → bitarray-3.11.0}/setup.cfg +0 -0
- {bitarray-3.10.1 → bitarray-3.11.0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bitarray
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.11.0
|
|
4
4
|
Summary: efficient arrays of booleans -- C extension
|
|
5
5
|
Home-page: https://github.com/ilanschnell/bitarray
|
|
6
6
|
Author: Ilan Schnell
|
|
@@ -54,16 +54,17 @@ Key features
|
|
|
54
54
|
operations ``+``, ``*``, ``+=``, ``*=``, the ``in`` operator, ``len()``
|
|
55
55
|
* Bitwise operations: ``~``, ``&``, ``|``, ``^``, ``<<``, ``>>`` (as well as
|
|
56
56
|
their in-place versions ``&=``, ``|=``, ``^=``, ``<<=``, ``>>=``).
|
|
57
|
-
* Free-threading support (for GIL
|
|
58
|
-
* Fast methods for encoding and decoding variable
|
|
57
|
+
* Free-threading support (for GIL-disabled CPython 3.14 and later)
|
|
58
|
+
* Fast methods for encoding and decoding variable-length prefix codes.
|
|
59
59
|
* Bitarray objects support the buffer protocol (both importing and
|
|
60
60
|
exporting buffers).
|
|
61
|
-
*
|
|
61
|
+
* Efficient packing and unpacking for interoperability with byte-oriented
|
|
62
|
+
objects such as NumPy arrays.
|
|
62
63
|
* Pickling and unpickling of bitarray objects.
|
|
63
64
|
* Immutable ``frozenbitarray`` objects which are hashable
|
|
64
|
-
*
|
|
65
|
+
* Fast searching for bits and bit patterns
|
|
65
66
|
* Type hinting
|
|
66
|
-
* Extensive test suite with
|
|
67
|
+
* Extensive test suite with over 600 unit tests
|
|
67
68
|
* Utility module ``bitarray.util``:
|
|
68
69
|
|
|
69
70
|
* conversion to and from hexadecimal strings
|
|
@@ -72,7 +73,8 @@ Key features
|
|
|
72
73
|
* conversion to and from integers
|
|
73
74
|
* creating Huffman codes
|
|
74
75
|
* compression of sparse bitarrays
|
|
75
|
-
*
|
|
76
|
+
* run-length encoding
|
|
77
|
+
* serialization and deserialization
|
|
76
78
|
* various count functions
|
|
77
79
|
* other helpful functions
|
|
78
80
|
|
|
@@ -94,7 +96,7 @@ Once you have installed the package, you may want to test it:
|
|
|
94
96
|
$ python -c 'import bitarray; bitarray.test()'
|
|
95
97
|
bitarray is installed in: /Users/ilan/bitarray/bitarray
|
|
96
98
|
sys.prefix: /Users/ilan/miniforge
|
|
97
|
-
bitarray version: 3.
|
|
99
|
+
bitarray version: 3.11.0
|
|
98
100
|
sys.version: 3.14.5 (main, May 20 2026) [Clang 20.1.8]
|
|
99
101
|
sys.abiflags: ''
|
|
100
102
|
sys._is_gil_enabled(): True
|
|
@@ -111,7 +113,7 @@ Once you have installed the package, you may want to test it:
|
|
|
111
113
|
..........s.....................................s........................
|
|
112
114
|
......s.........................................................
|
|
113
115
|
----------------------------------------------------------------------
|
|
114
|
-
Ran
|
|
116
|
+
Ran 654 tests in 0.192s
|
|
115
117
|
|
|
116
118
|
OK (skipped=4)
|
|
117
119
|
|
|
@@ -283,8 +285,8 @@ this topic, please read `buffer protocol <https://github.com/ilanschnell/bitarra
|
|
|
283
285
|
to memory-map a file to a bitarray: `mmapped-file.py <https://github.com/ilanschnell/bitarray/blob/master/examples/mmapped-file.py>`__
|
|
284
286
|
|
|
285
287
|
|
|
286
|
-
Variable
|
|
287
|
-
|
|
288
|
+
Variable-length prefix codes
|
|
289
|
+
----------------------------
|
|
288
290
|
|
|
289
291
|
The ``.encode()`` method takes a dictionary mapping symbols to bitarrays
|
|
290
292
|
and an iterable, and extends the bitarray object with the encoded symbols
|
|
@@ -358,7 +360,7 @@ and can therefore be used as a dictionary key:
|
|
|
358
360
|
Reference
|
|
359
361
|
=========
|
|
360
362
|
|
|
361
|
-
bitarray version: 3.
|
|
363
|
+
bitarray version: 3.11.0 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
|
|
362
364
|
|
|
363
365
|
In the following, ``item`` and ``value`` are usually a single bit -
|
|
364
366
|
an integer 0 or 1.
|
|
@@ -970,13 +972,34 @@ This sub-module was added in version 1.2.
|
|
|
970
972
|
New in version 3.5
|
|
971
973
|
|
|
972
974
|
|
|
975
|
+
``rl_decode(stream, /, endian=None)`` -> bitarray
|
|
976
|
+
Decode a run-length encoded bitarray from a binary stream (an integer
|
|
977
|
+
iterator, or bytes-like object), and return the decoded bitarray.
|
|
978
|
+
This function consumes only one bitarray and leaves the remaining stream
|
|
979
|
+
untouched. Use ``rl_encode()`` for encoding.
|
|
980
|
+
|
|
981
|
+
See also: `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
|
|
982
|
+
|
|
983
|
+
New in version 3.11
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
``rl_encode(bitarray, /)`` -> bytes
|
|
987
|
+
Return the run-length encoded binary representation of a bitarray.
|
|
988
|
+
This representation may be useful for bitarrays with long runs of
|
|
989
|
+
identical bits. Use ``rl_decode()`` for decoding.
|
|
990
|
+
|
|
991
|
+
See also: `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
|
|
992
|
+
|
|
993
|
+
New in version 3.11
|
|
994
|
+
|
|
995
|
+
|
|
973
996
|
``sc_decode(stream, /)`` -> bitarray
|
|
974
997
|
Decompress binary stream (an integer iterator, or bytes-like object) of a
|
|
975
998
|
sparse compressed (``sc``) bitarray, and return the decoded bitarray.
|
|
976
999
|
This function consumes only one bitarray and leaves the remaining stream
|
|
977
1000
|
untouched. Use ``sc_encode()`` for compressing (encoding).
|
|
978
1001
|
|
|
979
|
-
See also: `Compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__
|
|
1002
|
+
See also: `Compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__, `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
|
|
980
1003
|
|
|
981
1004
|
New in version 2.7
|
|
982
1005
|
|
|
@@ -986,11 +1009,25 @@ This sub-module was added in version 1.2.
|
|
|
986
1009
|
representation. This representation is useful for efficiently storing
|
|
987
1010
|
sparse bitarrays. Use ``sc_decode()`` for decompressing (decoding).
|
|
988
1011
|
|
|
989
|
-
See also: `Compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__
|
|
1012
|
+
See also: `Compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__, `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
|
|
990
1013
|
|
|
991
1014
|
New in version 2.7
|
|
992
1015
|
|
|
993
1016
|
|
|
1017
|
+
``sc_stat(stream)`` -> dict
|
|
1018
|
+
Scan a stream produced by ``sc_encode()`` and return a dictionary containing
|
|
1019
|
+
its bit-endianness (``endian``), length (``nbits``), and the number of blocks
|
|
1020
|
+
of each type (``blocks``). ``blocks`` is a list such that ``blocks[i]`` is the
|
|
1021
|
+
number of blocks of type ``i``.
|
|
1022
|
+
|
|
1023
|
+
Like ``sc_decode()``, it consumes one encoded bitarray and leaves remaining
|
|
1024
|
+
input untouched.
|
|
1025
|
+
|
|
1026
|
+
See also: `Compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__
|
|
1027
|
+
|
|
1028
|
+
New in version 3.11
|
|
1029
|
+
|
|
1030
|
+
|
|
994
1031
|
``serialize(bitarray, /)`` -> bytes
|
|
995
1032
|
Return a serialized representation of the bitarray, which may be passed to
|
|
996
1033
|
``deserialize()``. It efficiently represents the bitarray object (including
|
|
@@ -1034,7 +1071,7 @@ This sub-module was added in version 1.2.
|
|
|
1034
1071
|
return the decoded bitarray. This function consumes only one bitarray and
|
|
1035
1072
|
leaves the remaining stream untouched. Use ``vl_encode()`` for encoding.
|
|
1036
1073
|
|
|
1037
|
-
See also: `Variable length bitarray format <https://github.com/ilanschnell/bitarray/blob/master/doc/variable_length.rst>`__
|
|
1074
|
+
See also: `Variable length bitarray format <https://github.com/ilanschnell/bitarray/blob/master/doc/variable_length.rst>`__, `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
|
|
1038
1075
|
|
|
1039
1076
|
New in version 2.2
|
|
1040
1077
|
|
|
@@ -1044,7 +1081,7 @@ This sub-module was added in version 1.2.
|
|
|
1044
1081
|
This representation is useful for efficiently storing small bitarray
|
|
1045
1082
|
in a binary stream. Use ``vl_decode()`` for decoding.
|
|
1046
1083
|
|
|
1047
|
-
See also: `Variable length bitarray format <https://github.com/ilanschnell/bitarray/blob/master/doc/variable_length.rst>`__
|
|
1084
|
+
See also: `Variable length bitarray format <https://github.com/ilanschnell/bitarray/blob/master/doc/variable_length.rst>`__, `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
|
|
1048
1085
|
|
|
1049
1086
|
New in version 2.2
|
|
1050
1087
|
|
|
@@ -19,16 +19,17 @@ Key features
|
|
|
19
19
|
operations ``+``, ``*``, ``+=``, ``*=``, the ``in`` operator, ``len()``
|
|
20
20
|
* Bitwise operations: ``~``, ``&``, ``|``, ``^``, ``<<``, ``>>`` (as well as
|
|
21
21
|
their in-place versions ``&=``, ``|=``, ``^=``, ``<<=``, ``>>=``).
|
|
22
|
-
* Free-threading support (for GIL
|
|
23
|
-
* Fast methods for encoding and decoding variable
|
|
22
|
+
* Free-threading support (for GIL-disabled CPython 3.14 and later)
|
|
23
|
+
* Fast methods for encoding and decoding variable-length prefix codes.
|
|
24
24
|
* Bitarray objects support the buffer protocol (both importing and
|
|
25
25
|
exporting buffers).
|
|
26
|
-
*
|
|
26
|
+
* Efficient packing and unpacking for interoperability with byte-oriented
|
|
27
|
+
objects such as NumPy arrays.
|
|
27
28
|
* Pickling and unpickling of bitarray objects.
|
|
28
29
|
* Immutable ``frozenbitarray`` objects which are hashable
|
|
29
|
-
*
|
|
30
|
+
* Fast searching for bits and bit patterns
|
|
30
31
|
* Type hinting
|
|
31
|
-
* Extensive test suite with
|
|
32
|
+
* Extensive test suite with over 600 unit tests
|
|
32
33
|
* Utility module ``bitarray.util``:
|
|
33
34
|
|
|
34
35
|
* conversion to and from hexadecimal strings
|
|
@@ -37,7 +38,8 @@ Key features
|
|
|
37
38
|
* conversion to and from integers
|
|
38
39
|
* creating Huffman codes
|
|
39
40
|
* compression of sparse bitarrays
|
|
40
|
-
*
|
|
41
|
+
* run-length encoding
|
|
42
|
+
* serialization and deserialization
|
|
41
43
|
* various count functions
|
|
42
44
|
* other helpful functions
|
|
43
45
|
|
|
@@ -59,7 +61,7 @@ Once you have installed the package, you may want to test it:
|
|
|
59
61
|
$ python -c 'import bitarray; bitarray.test()'
|
|
60
62
|
bitarray is installed in: /Users/ilan/bitarray/bitarray
|
|
61
63
|
sys.prefix: /Users/ilan/miniforge
|
|
62
|
-
bitarray version: 3.
|
|
64
|
+
bitarray version: 3.11.0
|
|
63
65
|
sys.version: 3.14.5 (main, May 20 2026) [Clang 20.1.8]
|
|
64
66
|
sys.abiflags: ''
|
|
65
67
|
sys._is_gil_enabled(): True
|
|
@@ -76,7 +78,7 @@ Once you have installed the package, you may want to test it:
|
|
|
76
78
|
..........s.....................................s........................
|
|
77
79
|
......s.........................................................
|
|
78
80
|
----------------------------------------------------------------------
|
|
79
|
-
Ran
|
|
81
|
+
Ran 654 tests in 0.192s
|
|
80
82
|
|
|
81
83
|
OK (skipped=4)
|
|
82
84
|
|
|
@@ -248,8 +250,8 @@ this topic, please read `buffer protocol <https://github.com/ilanschnell/bitarra
|
|
|
248
250
|
to memory-map a file to a bitarray: `mmapped-file.py <https://github.com/ilanschnell/bitarray/blob/master/examples/mmapped-file.py>`__
|
|
249
251
|
|
|
250
252
|
|
|
251
|
-
Variable
|
|
252
|
-
|
|
253
|
+
Variable-length prefix codes
|
|
254
|
+
----------------------------
|
|
253
255
|
|
|
254
256
|
The ``.encode()`` method takes a dictionary mapping symbols to bitarrays
|
|
255
257
|
and an iterable, and extends the bitarray object with the encoded symbols
|
|
@@ -323,7 +325,7 @@ and can therefore be used as a dictionary key:
|
|
|
323
325
|
Reference
|
|
324
326
|
=========
|
|
325
327
|
|
|
326
|
-
bitarray version: 3.
|
|
328
|
+
bitarray version: 3.11.0 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
|
|
327
329
|
|
|
328
330
|
In the following, ``item`` and ``value`` are usually a single bit -
|
|
329
331
|
an integer 0 or 1.
|
|
@@ -935,13 +937,34 @@ This sub-module was added in version 1.2.
|
|
|
935
937
|
New in version 3.5
|
|
936
938
|
|
|
937
939
|
|
|
940
|
+
``rl_decode(stream, /, endian=None)`` -> bitarray
|
|
941
|
+
Decode a run-length encoded bitarray from a binary stream (an integer
|
|
942
|
+
iterator, or bytes-like object), and return the decoded bitarray.
|
|
943
|
+
This function consumes only one bitarray and leaves the remaining stream
|
|
944
|
+
untouched. Use ``rl_encode()`` for encoding.
|
|
945
|
+
|
|
946
|
+
See also: `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
|
|
947
|
+
|
|
948
|
+
New in version 3.11
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
``rl_encode(bitarray, /)`` -> bytes
|
|
952
|
+
Return the run-length encoded binary representation of a bitarray.
|
|
953
|
+
This representation may be useful for bitarrays with long runs of
|
|
954
|
+
identical bits. Use ``rl_decode()`` for decoding.
|
|
955
|
+
|
|
956
|
+
See also: `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
|
|
957
|
+
|
|
958
|
+
New in version 3.11
|
|
959
|
+
|
|
960
|
+
|
|
938
961
|
``sc_decode(stream, /)`` -> bitarray
|
|
939
962
|
Decompress binary stream (an integer iterator, or bytes-like object) of a
|
|
940
963
|
sparse compressed (``sc``) bitarray, and return the decoded bitarray.
|
|
941
964
|
This function consumes only one bitarray and leaves the remaining stream
|
|
942
965
|
untouched. Use ``sc_encode()`` for compressing (encoding).
|
|
943
966
|
|
|
944
|
-
See also: `Compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__
|
|
967
|
+
See also: `Compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__, `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
|
|
945
968
|
|
|
946
969
|
New in version 2.7
|
|
947
970
|
|
|
@@ -951,11 +974,25 @@ This sub-module was added in version 1.2.
|
|
|
951
974
|
representation. This representation is useful for efficiently storing
|
|
952
975
|
sparse bitarrays. Use ``sc_decode()`` for decompressing (decoding).
|
|
953
976
|
|
|
954
|
-
See also: `Compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__
|
|
977
|
+
See also: `Compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__, `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
|
|
955
978
|
|
|
956
979
|
New in version 2.7
|
|
957
980
|
|
|
958
981
|
|
|
982
|
+
``sc_stat(stream)`` -> dict
|
|
983
|
+
Scan a stream produced by ``sc_encode()`` and return a dictionary containing
|
|
984
|
+
its bit-endianness (``endian``), length (``nbits``), and the number of blocks
|
|
985
|
+
of each type (``blocks``). ``blocks`` is a list such that ``blocks[i]`` is the
|
|
986
|
+
number of blocks of type ``i``.
|
|
987
|
+
|
|
988
|
+
Like ``sc_decode()``, it consumes one encoded bitarray and leaves remaining
|
|
989
|
+
input untouched.
|
|
990
|
+
|
|
991
|
+
See also: `Compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__
|
|
992
|
+
|
|
993
|
+
New in version 3.11
|
|
994
|
+
|
|
995
|
+
|
|
959
996
|
``serialize(bitarray, /)`` -> bytes
|
|
960
997
|
Return a serialized representation of the bitarray, which may be passed to
|
|
961
998
|
``deserialize()``. It efficiently represents the bitarray object (including
|
|
@@ -999,7 +1036,7 @@ This sub-module was added in version 1.2.
|
|
|
999
1036
|
return the decoded bitarray. This function consumes only one bitarray and
|
|
1000
1037
|
leaves the remaining stream untouched. Use ``vl_encode()`` for encoding.
|
|
1001
1038
|
|
|
1002
|
-
See also: `Variable length bitarray format <https://github.com/ilanschnell/bitarray/blob/master/doc/variable_length.rst>`__
|
|
1039
|
+
See also: `Variable length bitarray format <https://github.com/ilanschnell/bitarray/blob/master/doc/variable_length.rst>`__, `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
|
|
1003
1040
|
|
|
1004
1041
|
New in version 2.2
|
|
1005
1042
|
|
|
@@ -1009,7 +1046,7 @@ This sub-module was added in version 1.2.
|
|
|
1009
1046
|
This representation is useful for efficiently storing small bitarray
|
|
1010
1047
|
in a binary stream. Use ``vl_decode()`` for decoding.
|
|
1011
1048
|
|
|
1012
|
-
See also: `Variable length bitarray format <https://github.com/ilanschnell/bitarray/blob/master/doc/variable_length.rst>`__
|
|
1049
|
+
See also: `Variable length bitarray format <https://github.com/ilanschnell/bitarray/blob/master/doc/variable_length.rst>`__, `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
|
|
1013
1050
|
|
|
1014
1051
|
New in version 2.2
|
|
1015
1052
|
|
|
@@ -13,8 +13,7 @@ from collections import namedtuple
|
|
|
13
13
|
|
|
14
14
|
from bitarray._bitarray import (
|
|
15
15
|
bitarray, decodetree, decodeiterator, _bitarray_reconstructor,
|
|
16
|
-
get_default_endian, bits2bytes,
|
|
17
|
-
BITARRAY_VERSION as __version__
|
|
16
|
+
get_default_endian, bits2bytes, BITARRAY_VERSION as __version__
|
|
18
17
|
)
|
|
19
18
|
|
|
20
19
|
__all__ = ['bitarray', 'frozenbitarray', 'decodetree', 'decodeiterator',
|
|
@@ -169,7 +169,6 @@ __version__: str
|
|
|
169
169
|
def bits2bytes(n: int) -> int: ...
|
|
170
170
|
def get_default_endian() -> str: ...
|
|
171
171
|
def test(verbosity: int = ...) -> TextTestResult: ...
|
|
172
|
-
def _sysinfo(key: str) -> int: ...
|
|
173
172
|
def _bitarray_reconstructor(cls: type,
|
|
174
173
|
buffer: bytes,
|
|
175
174
|
endian: str,
|
|
@@ -57,8 +57,9 @@ resize(bitarrayobject *self, Py_ssize_t nbits)
|
|
|
57
57
|
{
|
|
58
58
|
const size_t size = Py_SIZE(self);
|
|
59
59
|
const size_t allocated = self->allocated;
|
|
60
|
-
const size_t newsize = BYTES(
|
|
60
|
+
const size_t newsize = BYTES(nbits);
|
|
61
61
|
size_t new_allocated;
|
|
62
|
+
char *item;
|
|
62
63
|
|
|
63
64
|
if (self->ob_exports > 0) {
|
|
64
65
|
PyErr_SetString(PyExc_BufferError,
|
|
@@ -76,47 +77,41 @@ resize(bitarrayobject *self, Py_ssize_t nbits)
|
|
|
76
77
|
|
|
77
78
|
#ifndef NDEBUG
|
|
78
79
|
assert(self->readonly == 0);
|
|
79
|
-
assert(allocated >= size && size == BYTES(
|
|
80
|
+
assert(allocated >= size && size == BYTES(self->nbits));
|
|
80
81
|
if (self->ob_item == NULL)
|
|
81
82
|
assert(size == 0 && allocated == 0);
|
|
82
83
|
assert(self->readonly == 0);
|
|
83
84
|
#endif
|
|
84
85
|
|
|
85
86
|
/* bypass everything when buffer size hasn't changed */
|
|
86
|
-
if (newsize == size)
|
|
87
|
-
|
|
88
|
-
return 0;
|
|
89
|
-
}
|
|
87
|
+
if (newsize == size)
|
|
88
|
+
goto done;
|
|
90
89
|
|
|
91
90
|
if (newsize == 0) {
|
|
92
91
|
PyMem_Free(self->ob_item);
|
|
93
92
|
self->ob_item = NULL;
|
|
94
93
|
Py_SET_SIZE(self, 0);
|
|
95
94
|
self->allocated = 0;
|
|
96
|
-
|
|
97
|
-
return 0;
|
|
95
|
+
goto done;
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
new_allocated = new_allocation(size, allocated, newsize);
|
|
101
|
-
|
|
102
99
|
if (new_allocated == allocated) {
|
|
103
100
|
/* bypass reallocation */
|
|
104
101
|
Py_SET_SIZE(self, newsize);
|
|
105
|
-
|
|
106
|
-
return 0;
|
|
102
|
+
goto done;
|
|
107
103
|
}
|
|
108
104
|
|
|
109
105
|
assert(new_allocated >= newsize);
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
Py_SET_SIZE(self, 0);
|
|
113
|
-
self->allocated = 0;
|
|
114
|
-
self->nbits = 0;
|
|
106
|
+
item = PyMem_Realloc(self->ob_item, new_allocated);
|
|
107
|
+
if (item == NULL) {
|
|
115
108
|
PyErr_NoMemory();
|
|
116
109
|
return -1;
|
|
117
110
|
}
|
|
111
|
+
self->ob_item = item;
|
|
118
112
|
Py_SET_SIZE(self, newsize);
|
|
119
113
|
self->allocated = new_allocated;
|
|
114
|
+
done:
|
|
120
115
|
self->nbits = nbits;
|
|
121
116
|
return 0;
|
|
122
117
|
}
|
|
@@ -125,7 +120,7 @@ resize(bitarrayobject *self, Py_ssize_t nbits)
|
|
|
125
120
|
static bitarrayobject *
|
|
126
121
|
newbitarrayobject(PyTypeObject *type, Py_ssize_t nbits, int endian)
|
|
127
122
|
{
|
|
128
|
-
const size_t nbytes = BYTES(
|
|
123
|
+
const size_t nbytes = BYTES(nbits);
|
|
129
124
|
bitarrayobject *obj;
|
|
130
125
|
|
|
131
126
|
assert(nbits >= 0);
|
|
@@ -5228,7 +5223,7 @@ sysinfo(PyObject *module, PyObject *args)
|
|
|
5228
5223
|
{
|
|
5229
5224
|
char *key;
|
|
5230
5225
|
|
|
5231
|
-
if (!PyArg_ParseTuple(args, "s:
|
|
5226
|
+
if (!PyArg_ParseTuple(args, "s:sysinfo", &key))
|
|
5232
5227
|
return NULL;
|
|
5233
5228
|
|
|
5234
5229
|
#define R(k, v) \
|
|
@@ -5265,20 +5260,20 @@ sysinfo(PyObject *module, PyObject *args)
|
|
|
5265
5260
|
}
|
|
5266
5261
|
|
|
5267
5262
|
PyDoc_STRVAR(sysinfo_doc,
|
|
5268
|
-
"
|
|
5263
|
+
"sysinfo(key) -> int\n\
|
|
5269
5264
|
\n\
|
|
5270
5265
|
Return system- and compile-specific information given a key.");
|
|
5271
5266
|
|
|
5272
5267
|
|
|
5273
5268
|
static PyMethodDef module_functions[] = {
|
|
5274
|
-
{"bits2bytes",
|
|
5269
|
+
{"bits2bytes", (PyCFunction) bits2bytes, METH_O,
|
|
5275
5270
|
bits2bytes_doc},
|
|
5276
5271
|
{"_bitarray_reconstructor",
|
|
5277
|
-
|
|
5272
|
+
(PyCFunction) reconstructor, METH_VARARGS,
|
|
5278
5273
|
reduce_doc},
|
|
5279
|
-
{"get_default_endian",
|
|
5274
|
+
{"get_default_endian", (PyCFunction) get_default_endian, METH_NOARGS,
|
|
5280
5275
|
get_default_endian_doc},
|
|
5281
|
-
{"
|
|
5276
|
+
{"sysinfo", (PyCFunction) sysinfo, METH_VARARGS,
|
|
5282
5277
|
sysinfo_doc},
|
|
5283
5278
|
{NULL} /* sentinel */
|
|
5284
5279
|
};
|