Commit 2e05ee78 authored by Alexandre Vassalotti's avatar Alexandre Vassalotti

Remove the buffer API from PyUnicode as specified by PEP 3137. Also,

fix the error message of the 't' format unit, in getargs.c, so that it
asks for bytes, instead of string.
parent 417e75aa
...@@ -1674,6 +1674,15 @@ getstring(PyObject* string, Py_ssize_t* p_length, int* p_charsize) ...@@ -1674,6 +1674,15 @@ getstring(PyObject* string, Py_ssize_t* p_length, int* p_charsize)
void* ptr; void* ptr;
Py_buffer view; Py_buffer view;
/* Unicode objects do not support the buffer API. So, get the data
directly instead. */
if (PyUnicode_Check(string)) {
ptr = (void *)PyUnicode_AS_DATA(string);
*p_length = PyUnicode_GET_SIZE(string);
*p_charsize = sizeof(Py_UNICODE);
return ptr;
}
/* get pointer to string buffer */ /* get pointer to string buffer */
view.len = -1; view.len = -1;
buffer = Py_Type(string)->tp_as_buffer; buffer = Py_Type(string)->tp_as_buffer;
......
...@@ -2135,7 +2135,8 @@ posix_listdir(PyObject *self, PyObject *args) ...@@ -2135,7 +2135,8 @@ posix_listdir(PyObject *self, PyObject *args)
FILEFINDBUF3 ep; FILEFINDBUF3 ep;
APIRET rc; APIRET rc;
if (!PyArg_ParseTuple(args, "t#:listdir", &name, &len)) if (!PyArg_ParseTuple(args, "et#:listdir",
Py_FileSystemDefaultEncoding, &name, &len))
return NULL; return NULL;
if (len >= MAX_PATH) { if (len >= MAX_PATH) {
PyErr_SetString(PyExc_ValueError, "path too long"); PyErr_SetString(PyExc_ValueError, "path too long");
......
...@@ -8113,15 +8113,6 @@ static PyMappingMethods unicode_as_mapping = { ...@@ -8113,15 +8113,6 @@ static PyMappingMethods unicode_as_mapping = {
}; };
static int
unicode_buffer_getbuffer(PyUnicodeObject *self, Py_buffer *view, int flags)
{
return PyBuffer_FillInfo(view, (void *)self->str,
PyUnicode_GET_DATA_SIZE(self), 1, flags);
}
/* Helpers for PyUnicode_Format() */ /* Helpers for PyUnicode_Format() */
static PyObject * static PyObject *
...@@ -8815,11 +8806,6 @@ PyObject *PyUnicode_Format(PyObject *format, ...@@ -8815,11 +8806,6 @@ PyObject *PyUnicode_Format(PyObject *format,
return NULL; return NULL;
} }
static PyBufferProcs unicode_as_buffer = {
(getbufferproc) unicode_buffer_getbuffer,
NULL,
};
static PyObject * static PyObject *
unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds); unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
...@@ -8903,7 +8889,7 @@ PyTypeObject PyUnicode_Type = { ...@@ -8903,7 +8889,7 @@ PyTypeObject PyUnicode_Type = {
(reprfunc) unicode_str, /* tp_str */ (reprfunc) unicode_str, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */ PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */ 0, /* tp_setattro */
&unicode_as_buffer, /* tp_as_buffer */ 0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_UNICODE_SUBCLASS, /* tp_flags */ Py_TPFLAGS_UNICODE_SUBCLASS, /* tp_flags */
unicode_doc, /* tp_doc */ unicode_doc, /* tp_doc */
......
...@@ -1252,7 +1252,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, ...@@ -1252,7 +1252,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
arg, msgbuf, bufsize); arg, msgbuf, bufsize);
if (pb == NULL || pb->bf_getbuffer == NULL) if (pb == NULL || pb->bf_getbuffer == NULL)
return converterr( return converterr(
"string or read-only character buffer", "bytes or read-only character buffer",
arg, msgbuf, bufsize); arg, msgbuf, bufsize);
if ((*pb->bf_getbuffer)(arg, &view, PyBUF_SIMPLE) != 0) if ((*pb->bf_getbuffer)(arg, &view, PyBUF_SIMPLE) != 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment