Issue #22896: Avoid to use PyObject_AsCharBuffer(), PyObject_AsReadBuffer()
and PyObject_AsWriteBuffer().
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user