Armin Rigo avatar Armin Rigo committed e46ecf8

Fixes for Python 3: the easy part (thanks Gabriel).

Comments (0)

Files changed (1)

     if (left < 0)     left = 0;
     if (right > size) right = size;
     if (left > right) left = right;
-    return PyString_FromStringAndSize(self->mb_data + left, right - left);
+    return PyBytes_FromStringAndSize(self->mb_data + left, right - left);
 }
 
 static int mb_ass_item(MiniBufferObj *self, Py_ssize_t idx, PyObject *other)
     return 0;
 }
 
+#if PY_MAJOR_VERSION < 3
 static Py_ssize_t mb_getdata(MiniBufferObj *self, Py_ssize_t idx, void **pp)
 {
     *pp = self->mb_data;
         *lenp = self->mb_size;
     return 1;
 }
+#endif
 
 static int mb_getbuf(MiniBufferObj *self, Py_buffer *view, int flags)
 {
 };
 
 static PyBufferProcs mb_as_buffer = {
+#if PY_MAJOR_VERSION < 3
     (readbufferproc)mb_getdata,
     (writebufferproc)mb_getdata,
     (segcountproc)mb_getsegcount,
     (charbufferproc)mb_getdata,
+#endif
     (getbufferproc)mb_getbuf,
     (releasebufferproc)0,
 };
 
+#if PY_MAJOR_VERSION >= 3
+# define MINIBUF_TPFLAGS (Py_TPFLAGS_DEFAULT)
+#else
+# define MINIBUF_TPFLAGS (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GETCHARBUFFER | Py_TPFLAGS_HAVE_NEWBUFFER)
+#endif
+
 static PyTypeObject MiniBuffer_Type = {
     PyVarObject_HEAD_INIT(NULL, 0)
     "_cffi_backend.buffer",
     PyObject_GenericGetAttr,                    /* tp_getattro */
     0,                                          /* tp_setattro */
     &mb_as_buffer,                              /* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GETCHARBUFFER |
-        Py_TPFLAGS_HAVE_NEWBUFFER,              /* tp_flags */
+    MINIBUF_TPFLAGS,                            /* tp_flags */
 };
 
 static PyObject *minibuffer_new(char *data, Py_ssize_t size)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.