Author: Armin Rigo <[email protected]>
Branch:
Changeset: r3019:0a518e0c9470
Date: 2017-09-20 08:55 +0200
http://bitbucket.org/cffi/cffi/changeset/0a518e0c9470/
Log: Get rid of deprecated Python C API functions
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -101,7 +101,11 @@
# define PyText_FromFormat PyUnicode_FromFormat
# define PyText_AsUTF8 _PyUnicode_AsString /* PyUnicode_AsUTF8 in Py3.3 */
# define PyText_AS_UTF8 _PyUnicode_AsString
-# define PyText_GetSize PyUnicode_GetSize
+# if PY_VERSION_HEX >= 0x03030000
+# define PyText_GetSize PyUnicode_GetLength
+# else
+# define PyText_GetSize PyUnicode_GetSize
+# endif
# define PyText_FromString PyUnicode_FromString
# define PyText_FromStringAndSize PyUnicode_FromStringAndSize
# define PyText_InternInPlace PyUnicode_InternInPlace
diff --git a/c/minibuffer.h b/c/minibuffer.h
--- a/c/minibuffer.h
+++ b/c/minibuffer.h
@@ -56,14 +56,17 @@
}
}
+/* forward: from _cffi_backend.c */
+static int _fetch_as_buffer(PyObject *x, Py_buffer *view, int writable_only);
+
static int mb_ass_slice(MiniBufferObj *self,
Py_ssize_t left, Py_ssize_t right, PyObject *other)
{
- const void *buffer;
- Py_ssize_t buffer_len, count;
+ Py_ssize_t count;
Py_ssize_t size = self->mb_size;
+ Py_buffer src_view;
- if (PyObject_AsReadBuffer(other, &buffer, &buffer_len) < 0)
+ if (_fetch_as_buffer(other, &src_view, 0) < 0)
return -1;
if (left < 0) left = 0;
@@ -71,12 +74,14 @@
if (left > right) left = right;
count = right - left;
- if (count != buffer_len) {
+ if (count != src_view.len) {
+ PyBuffer_Release(&src_view);
PyErr_SetString(PyExc_ValueError,
"right operand length must match slice length");
return -1;
}
- memcpy(self->mb_data + left, buffer, count);
+ memcpy(self->mb_data + left, src_view.buf, count);
+ PyBuffer_Release(&src_view);
return 0;
}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit