[pypy-commit] pypy strbuf-as-buffer: copy over test_c.py to _backend_test_c.py (of the strbuf-as-buffer branch)
plan_rich
pypy.commits at gmail.com
Fri Dec 9 11:04:44 EST 2016
Author: Richard Plangger <planrichi at gmail.com>
Branch: strbuf-as-buffer
Changeset: r88988:c78e1e9c9ed9
Date: 2016-12-09 17:04 +0100
http://bitbucket.org/pypy/pypy/changeset/c78e1e9c9ed9/
Log: copy over test_c.py to _backend_test_c.py (of the strbuf-as-buffer
branch)
diff --git a/pypy/module/_cffi_backend/func.py b/pypy/module/_cffi_backend/func.py
--- a/pypy/module/_cffi_backend/func.py
+++ b/pypy/module/_cffi_backend/func.py
@@ -135,7 +135,16 @@
#
return _from_buffer(space, w_ctype, w_x)
+def invalid_input_buffer_type(space, w_x):
+ if space.isinstance_w(w_x, space.w_unicode):
+ return True
+ return False
+
def _from_buffer(space, w_ctype, w_x):
+ if invalid_input_buffer_type(space, w_x):
+ raise oefmt(space.w_TypeError,
+ "from_buffer() cannot return the address of the "
+ "raw string within a str or unicode object")
buf = _fetch_as_read_buffer(space, w_x)
if space.isinstance_w(w_x, space.w_str):
_cdata = get_raw_address_of_string(space, w_x)
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -3415,18 +3415,16 @@
BCharA = new_array_type(BCharP, None)
p1 = from_buffer(BCharA, b"foo")
assert p1 == from_buffer(BCharA, b"foo")
- import gc; gc.collect()
- assert p1 == from_buffer(BCharA, b"foo")
+ py.test.raises(TypeError, from_buffer, BCharA, u+"foo")
try:
from __builtin__ import buffer
except ImportError:
- # python3 does not allow from to get buffer from unicode!
- raises(TypeError, from_buffer, BCharA, u+"foo")
+ pass
else:
- p4 = from_buffer(BCharA, u+"foo")
contents = from_buffer(BCharA, buffer(b"foo"))
for i in range(len(contents)):
assert contents[i] == p1[i]
+ p4 = from_buffer(BCharA, b"f\x00\x00\x00o\x00\x00\x00o\x00\x00\x00")
contents = from_buffer(BCharA, buffer(u+"foo"))
for i in range(len(contents)):
assert contents[i] == p4[i]
@@ -3439,6 +3437,7 @@
for i in range(len(contents)):
assert contents[i] == p1[i]
+
def test_from_buffer_bytearray():
a = bytearray(b"xyz")
BChar = new_primitive_type("char")
diff --git a/pypy/objspace/std/test/test_bufferobject.py b/pypy/objspace/std/test/test_bufferobject.py
--- a/pypy/objspace/std/test/test_bufferobject.py
+++ b/pypy/objspace/std/test/test_bufferobject.py
@@ -199,7 +199,9 @@
raises(TypeError, "buf[MyInt(0):MyInt(5)]")
def test_pypy_raw_address_base(self):
- raises(ValueError, buffer("foobar")._pypy_raw_address)
- raises(ValueError, buffer(u"foobar")._pypy_raw_address)
- a = buffer(bytearray("foobar"))._pypy_raw_address()
+ a = buffer("foobar")._pypy_raw_address()
assert a != 0
+ b = buffer(u"foobar")._pypy_raw_address()
+ assert b != 0
+ c = buffer(bytearray("foobar"))._pypy_raw_address()
+ assert c != 0
diff --git a/pypy/objspace/std/test/test_memoryobject.py b/pypy/objspace/std/test/test_memoryobject.py
--- a/pypy/objspace/std/test/test_memoryobject.py
+++ b/pypy/objspace/std/test/test_memoryobject.py
@@ -56,6 +56,7 @@
assert u"abc" != memoryview("abc")
def test_pypy_raw_address_base(self):
- raises(ValueError, memoryview("foobar")._pypy_raw_address)
- a = memoryview(bytearray("foobar"))._pypy_raw_address()
+ a = memoryview("foobar")._pypy_raw_address()
assert a != 0
+ b = memoryview(bytearray("foobar"))._pypy_raw_address()
+ assert b != 0
More information about the pypy-commit
mailing list