summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2014-03-07 07:00:36 +0100
committerStefan Behnel <stefan_ml@behnel.de>2014-03-07 07:00:36 +0100
commit3d6f0126b8381f9b4e790bab813f5681d75f6787 (patch)
tree1400bad362d2fddf54e9b3174c51913209c988a2
parent73e24e80bb9722b4bac90e806b76555e2095e002 (diff)
downloadcython-3d6f0126b8381f9b4e790bab813f5681d75f6787.tar.gz
make sure we always optimise bytearray.append(INT_LITERAL)
-rw-r--r--Cython/Compiler/Optimize.py2
-rw-r--r--tests/run/bytearraymethods.pyx22
2 files changed, 13 insertions, 11 deletions
diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py
index 35c35c757..cc5a8c948 100644
--- a/Cython/Compiler/Optimize.py
+++ b/Cython/Compiler/Optimize.py
@@ -2450,7 +2450,7 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
func_type = self.PyByteArray_Append_func_type
value = unwrap_coerced_node(args[1])
- if value.type.is_int:
+ if value.type.is_int or isinstance(value, ExprNodes.IntNode):
value = value.coerce_to(PyrexTypes.c_int_type, self.current_env())
utility_code = UtilityCode.load_cached("ByteArrayAppend", "StringTools.c")
elif value.is_string_literal:
diff --git a/tests/run/bytearraymethods.pyx b/tests/run/bytearraymethods.pyx
index 389a63046..d0130575a 100644
--- a/tests/run/bytearraymethods.pyx
+++ b/tests/run/bytearraymethods.pyx
@@ -198,23 +198,24 @@ def bytearray_decode_unbound_method(bytearray s, start=None, stop=None):
else:
return bytearray.decode(s[start:stop], 'utf8')
-
+@cython.test_fail_if_path_exists('//SimpleCallNode')
+@cython.test_assert_path_exists('//PythonCapiCallNode')
def bytearray_append(bytearray b, signed char c, int i, object o):
"""
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), ord('y'), ord('z'))
>>> print(b.decode('ascii'))
- abcXxyz
+ abcX@xyz
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), ord('y'), ord('z') if IS_PY3 else b'z')
>>> print(b.decode('ascii'))
- abcXxyz
+ abcX@xyz
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), ord('y'), ord('\\xc3') if IS_PY3 else b'\\xc3')
>>> print(b[:-1].decode('ascii'))
- abcXxy
+ abcX@xy
>>> print('%x' % b[-1])
c3
@@ -224,44 +225,45 @@ def bytearray_append(bytearray b, signed char c, int i, object o):
... except (TypeError, ValueError): pass # (Py3, Py2)
... else: print("FAIL")
>>> print(b.decode('ascii'))
- abcXxy
+ abcX@xy
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, -1, ord('y'), ord('z')) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> print(b.decode('ascii'))
- abcX
+ abcX@
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), -1, ord('z')) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> print(b.decode('ascii'))
- abcXx
+ abcX@x
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), 256, ord('z')) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> print(b.decode('ascii'))
- abcXx
+ abcX@x
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), ord('y'), -1) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> print(b.decode('ascii'))
- abcXxy
+ abcX@xy
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), ord('y'), 256) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> print(b.decode('ascii'))
- abcXxy
+ abcX@xy
"""
assert b.append('X') is None
+ b.append(64)
b.append(c)
b.append(i)
b.append(o)