Author: Armin Rigo <[email protected]>
Branch:
Changeset: r1019:e46ecf80c64f
Date: 2012-10-30 10:52 +0100
http://bitbucket.org/cffi/cffi/changeset/e46ecf80c64f/
Log: Fixes for Python 3: the easy part (thanks Gabriel).
diff --git a/c/minibuffer.h b/c/minibuffer.h
--- a/c/minibuffer.h
+++ b/c/minibuffer.h
@@ -32,7 +32,7 @@
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)
@@ -78,6 +78,7 @@
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;
@@ -90,6 +91,7 @@
*lenp = self->mb_size;
return 1;
}
+#endif
static int mb_getbuf(MiniBufferObj *self, Py_buffer *view, int flags)
{
@@ -108,14 +110,22 @@
};
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",
@@ -136,8 +146,7 @@
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)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit