mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Issue #22896: Avoid to use PyObject_AsCharBuffer(), PyObject_AsReadBuffer()
and PyObject_AsWriteBuffer().
This commit is contained in:
commit
3dd3e26680
18 changed files with 422 additions and 397 deletions
|
@ -131,6 +131,7 @@ PyFloat_FromString(PyObject *v)
|
|||
double x;
|
||||
PyObject *s_buffer = NULL;
|
||||
Py_ssize_t len;
|
||||
Py_buffer view = {NULL, NULL};
|
||||
PyObject *result = NULL;
|
||||
|
||||
if (PyUnicode_Check(v)) {
|
||||
|
@ -143,7 +144,11 @@ PyFloat_FromString(PyObject *v)
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (PyObject_AsCharBuffer(v, &s, &len)) {
|
||||
else if (PyObject_GetBuffer(v, &view, PyBUF_SIMPLE) == 0) {
|
||||
s = (const char *)view.buf;
|
||||
len = view.len;
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"float() argument must be a string or a number, not '%.200s'",
|
||||
Py_TYPE(v)->tp_name);
|
||||
|
@ -170,6 +175,7 @@ PyFloat_FromString(PyObject *v)
|
|||
else
|
||||
result = PyFloat_FromDouble(x);
|
||||
|
||||
PyBuffer_Release(&view);
|
||||
Py_XDECREF(s_buffer);
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue