[pypy-commit] cffi strbuf-as-buffer: allow from_buffer for buffer and memoryview even when they point to bytes/unicode
plan_rich
pypy.commits at gmail.com
Fri Dec 9 10:23:16 EST 2016
Author: Richard Plangger <planrichi at gmail.com>
Branch: strbuf-as-buffer
Changeset: r2832:f92733f03d32
Date: 2016-12-09 16:22 +0100
http://bitbucket.org/cffi/cffi/changeset/f92733f03d32/
Log: allow from_buffer for buffer and memoryview even when they point to
bytes/unicode
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -6110,24 +6110,13 @@
#if PY_MAJOR_VERSION < 3
if (PyBuffer_Check(x)) {
- /* XXX fish fish fish in an inofficial way */
- typedef struct {
- PyObject_HEAD
- PyObject *b_base;
- } _my_PyBufferObject;
-
- _my_PyBufferObject *b = (_my_PyBufferObject *)x;
- x = b->b_base;
- if (x == NULL)
- return 0;
+ return 0;
}
else
#endif
#if PY_MAJOR_VERSION > 2 || PY_MINOR_VERSION > 6
if (PyMemoryView_Check(x)) {
- x = PyMemoryView_GET_BASE(x);
- if (x == NULL)
- return 0;
+ return 0;
}
else
#endif
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -3426,18 +3426,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")
try:
from __builtin__ import buffer
except ImportError:
- # python3 does not allow a buffer from unicode!
- raises(TypeError, from_buffer, BCharA, u+"foo")
+ # python3 does not allow from to get buffer from unicode!
+ py.test.raises(TypeError, from_buffer, BCharA, u+"foo")
else:
contents = from_buffer(BCharA, buffer(b"foo"))
for i in range(len(contents)):
assert contents[i] == p1[i]
- p4 = from_buffer(BCharA, u+"foo")
+ 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]
More information about the pypy-commit
mailing list