@@ -0,0 +1,106 @@
1+From c636f0cc386c9ded9f31947bbd74affccc93c21a Mon Sep 17 00:00:00 2001
2+From: yoch <yoch.melka@gmail.com>
3+Date: Mon, 14 May 2018 21:55:00 +0300
4+Subject: [PATCH] Adding buffer protocol support for Python 3
7+ bitarray/_bitarray.c | 12 ++++++++++--
8+ bitarray/test_bitarray.py | 14 +++++++-------
9+ 2 files changed, 17 insertions(+), 9 deletions(-)
11+diff --git a/bitarray/_bitarray.c b/bitarray/_bitarray.c
12+index d2c19cb..be6b379 100644
13+--- a/bitarray/_bitarray.c
14++++ b/bitarray/_bitarray.c
15+@@ -48,7 +48,7 @@ int PyIndex_Check(PyObject *o)
16+ #define Py_SIZE(ob) (((PyVarObject *) (ob))->ob_size)
19+-#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 7
20++#if PY_MAJOR_VERSION == 3 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 7)
21+ /* (new) buffer protocol */
24+@@ -2787,6 +2787,8 @@ static PyTypeObject BitarrayIter_Type = {
26+ /********************* Bitarray Buffer Interface ************************/
29++#if PY_MAJOR_VERSION == 2
31+ bitarray_buffer_getreadbuf(bitarrayobject *self,
32+ Py_ssize_t index, const void **ptr)
33+@@ -2831,6 +2833,8 @@ bitarray_buffer_getcharbuf(bitarrayobject *self,
34+ return Py_SIZE(self);
40+ bitarray_getbuffer(bitarrayobject *self, Py_buffer *view, int flags)
42+@@ -2857,14 +2861,18 @@ bitarray_releasebuffer(bitarrayobject *self, Py_buffer *view)
45+ static PyBufferProcs bitarray_as_buffer = {
46++#if PY_MAJOR_VERSION == 2 // old buffer protocol
47+ (readbufferproc) bitarray_buffer_getreadbuf,
48+ (writebufferproc) bitarray_buffer_getwritebuf,
49+ (segcountproc) bitarray_buffer_getsegcount,
50+ (charbufferproc) bitarray_buffer_getcharbuf,
52+ (getbufferproc) bitarray_getbuffer,
53+ (releasebufferproc) bitarray_releasebuffer,
56+ #endif /* WITH_BUFFER */
58+ /************************** Bitarray Type *******************************/
60+ static PyTypeObject Bitarraytype = {
61+@@ -2898,7 +2906,7 @@ static PyTypeObject Bitarraytype = {
62+ 0, /* tp_as_buffer */
64+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS
66++#if defined(WITH_BUFFER) && PY_MAJOR_VERSION == 2
67+ | Py_TPFLAGS_HAVE_NEWBUFFER
70+diff --git a/bitarray/test_bitarray.py b/bitarray/test_bitarray.py
71+index 44de2f0..b72b554 100644
72+--- a/bitarray/test_bitarray.py
73++++ b/bitarray/test_bitarray.py
74+@@ -2113,10 +2113,10 @@ def test_read1(self):
75+ a = bitarray('01000001' '01000010' '01000011', endian='big')
77+ self.assertEqual(len(v), 3)
78+- self.assertEqual(v[0], 'A')
79+- self.assertEqual(v[:].tobytes(), 'ABC')
80++ #self.assertEqual(v[0], 'A')
81++ self.assertEqual(v[:].tobytes(), b'ABC')
83+- self.assertEqual(v[:].tobytes(), 'AFC')
84++ self.assertEqual(v[:].tobytes(), b'AFC')
86+ def test_read2(self):
87+ a = bitarray([randint(0, 1) for d in range(8000)])
88+@@ -2131,14 +2131,14 @@ def test_write(self):
91+ self.assertFalse(v.readonly)
93++ v[50000] = 255 if is_py3k else '\xff'
94+ self.assertEqual(a[399999:400009], bitarray('0111111110'))
96+ self.assertEqual(a[399999:400009], bitarray('0111011110'))
97+- v[30001:30004] = 'ABC'
98+- self.assertEqual(a[240000:240040].tobytes(), '\x00ABC\x00')
99++ v[30001:30004] = b'ABC'
100++ self.assertEqual(a[240000:240040].tobytes(), b'\x00ABC\x00')
102+-if sys.version_info[:2] == (2, 7):
103++if sys.version_info[:2] >= (2, 7):
104+ tests.append(BufferInterfaceTests)
106+ # ---------------------------------------------------------------------------