Author: Richard Plangger <[email protected]>
Branch: strbuf-as-buffer
Changeset: r2851:44df83151f36
Date: 2017-01-03 10:04 +0100
http://bitbucket.org/cffi/cffi/changeset/44df83151f36/

Log:    kill invalid_input_buffer_type, update docs to state that now only
        unicode objects are forbidden

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -6101,43 +6101,18 @@
     return 0;
 }
 
-static int invalid_input_buffer_type(PyObject *x)
-{
-    /* From PyPy 5.4, from_buffer() accepts strings (but still not buffers
-       or memoryviews on strings). */
-    if (PyBytes_Check(x))
-        return 0;
-
-#if PY_MAJOR_VERSION < 3
-    if (PyBuffer_Check(x)) {
-        return 0;
-    }
-    else
-#endif
-#if PY_MAJOR_VERSION > 2 || PY_MINOR_VERSION > 6
-    if (PyMemoryView_Check(x)) {
-        return 0;
-    }
-    else
-#endif
-        ;
-
-    if (PyBytes_Check(x) || PyUnicode_Check(x))
-        return 1;
-    /* From PyPy 5.2, bytearray buffers can fetch a raw pointer, so
-       there is no reason any more to prevent from_buffer(bytearray()). */
-    return 0;
-}
-
 static PyObject *direct_from_buffer(CTypeDescrObject *ct, PyObject *x)
 {
     CDataObject *cd;
     Py_buffer *view;
 
-    if (invalid_input_buffer_type(x)) {
+    /* PyPy 5.7 can obtain buffers for string (python 2)
+       or bytes (python 3). from_buffer(u"foo") is disallowed.
+     */
+    if (PyUnicode_Check(x)) {
         PyErr_SetString(PyExc_TypeError,
-                        "from_buffer() cannot return the address of the "
-                        "raw string within a "STR_OR_BYTES" or unicode 
object");
+                        "from_buffer() cannot return the address "
+                        "of a unicode object");
         return NULL;
     }
 
diff --git a/doc/source/ref.rst b/doc/source/ref.rst
--- a/doc/source/ref.rst
+++ b/doc/source/ref.rst
@@ -175,9 +175,8 @@
 **ffi.from_buffer(python_buffer)**: return a ``<cdata 'char[]'>`` that
 points to the data of the given Python object, which must support the
 buffer interface.  This is the opposite of ``ffi.buffer()``.  It gives
-a reference to the existing data, not a copy; for this
-reason, and for PyPy compatibility, it does not work with the built-in
-type unicode; nor buffers/memoryviews to byte or unicode strings.
+a reference to the existing data, not a copy; It does not work with the 
built-in
+type unicode.
 It is meant to be used on objects
 containing large quantities of raw data, like bytearrays
 or ``array.array`` or numpy
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to