diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-02-02 23:21:08 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-02-02 23:21:08 (GMT) |
commit | 4fdb68491e8b2d044c9173babf625bbb815c39d1 (patch) | |
tree | 652360cd0b400bb3077d6106bee5f02bbea30c61 /Objects/floatobject.c | |
parent | b0ef78535a94b6b368a8b9935525cb3162c670d4 (diff) | |
download | cpython-4fdb68491e8b2d044c9173babf625bbb815c39d1.zip cpython-4fdb68491e8b2d044c9173babf625bbb815c39d1.tar.gz cpython-4fdb68491e8b2d044c9173babf625bbb815c39d1.tar.bz2 |
Issue #22896: Avoid to use PyObject_AsCharBuffer(), PyObject_AsReadBuffer()
and PyObject_AsWriteBuffer().
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r-- | Objects/floatobject.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 05b7679..33e30ca 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -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; } |