Skip to content

Commit 8746f29

Browse files
committed
Fix sre_compile._bytes_to_code
1 parent e807383 commit 8746f29

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

Lib/sre_compile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,9 @@ def _mk_bitmap(bits, _CODEBITS=_CODEBITS, _int=int):
380380

381381
def _bytes_to_codes(b):
382382
# Convert block indices to word array
383-
a = memoryview(b).cast('I')
383+
import array
384+
a = array.array('I')
385+
a.frombytes(bytes(b))
384386
assert a.itemsize == _sre.CODESIZE
385387
assert len(a) * a.itemsize == len(b)
386388
return a.tolist()

Lib/textwrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class TextWrapper:
113113
sentence_end_re = re.compile(r'[a-z]' # lowercase letter
114114
r'[\.!\?]' # sentence-ending punct.
115115
r'["\']?' # optional end-of-quote
116-
r'\z') # end of chunk
116+
r'\Z') # end of chunk
117117

118118
def __init__(self,
119119
width=70,

vm/src/stdlib/array.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ def_array_enum!(
165165
// TODO: support unicode char
166166
(SignedShort, i16, 'h'),
167167
(UnsignedShort, u16, 'H'),
168-
(SignedInt, i16, 'i'),
169-
(UnsignedInt, u16, 'I'),
170-
(SignedLong, i32, 'l'),
171-
(UnsignedLong, u32, 'L'),
168+
(SignedInt, i32, 'i'),
169+
(UnsignedInt, u32, 'I'),
170+
(SignedLong, i64, 'l'),
171+
(UnsignedLong, u64, 'L'),
172172
(SignedLongLong, i64, 'q'),
173173
(UnsignedLongLong, u64, 'Q'),
174174
(Float, f32, 'f'),
@@ -305,6 +305,16 @@ impl PyArray {
305305
self.array.borrow().tobytes()
306306
}
307307

308+
#[pymethod]
309+
fn tolist(&self, vm: &VirtualMachine) -> PyResult {
310+
let array = self.array.borrow();
311+
let mut v = Vec::with_capacity(array.len());
312+
for obj in array.iter(vm) {
313+
v.push(obj?);
314+
}
315+
Ok(vm.ctx.new_list(v))
316+
}
317+
308318
#[pymethod]
309319
fn reverse(&self, _vm: &VirtualMachine) {
310320
self.array.borrow_mut().reverse()
@@ -338,6 +348,11 @@ impl PyArray {
338348
}
339349
}
340350

351+
#[pymethod(name = "__len__")]
352+
fn len(&self, _vm: &VirtualMachine) -> usize {
353+
self.array.borrow().len()
354+
}
355+
341356
#[pymethod(name = "__iter__")]
342357
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyArrayIter {
343358
PyArrayIter {

0 commit comments

Comments
 (0)