summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite/connection.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-02-02 23:21:08 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-02-02 23:21:08 (GMT)
commit4fdb68491e8b2d044c9173babf625bbb815c39d1 (patch)
tree652360cd0b400bb3077d6106bee5f02bbea30c61 /Modules/_sqlite/connection.c
parentb0ef78535a94b6b368a8b9935525cb3162c670d4 (diff)
downloadcpython-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 'Modules/_sqlite/connection.c')
-rw-r--r--Modules/_sqlite/connection.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 535464d..2e8cab5 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -522,19 +522,20 @@ _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
return -1;
sqlite3_result_text(context, str, -1, SQLITE_TRANSIENT);
} else if (PyObject_CheckBuffer(py_val)) {
- const char* buffer;
- Py_ssize_t buflen;
- if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) {
+ Py_buffer view;
+ if (PyObject_GetBuffer(py_val, &view, PyBUF_SIMPLE) != 0) {
PyErr_SetString(PyExc_ValueError,
"could not convert BLOB to buffer");
return -1;
}
- if (buflen > INT_MAX) {
+ if (view.len > INT_MAX) {
PyErr_SetString(PyExc_OverflowError,
"BLOB longer than INT_MAX bytes");
+ PyBuffer_Release(&view);
return -1;
}
- sqlite3_result_blob(context, buffer, (int)buflen, SQLITE_TRANSIENT);
+ sqlite3_result_blob(context, view.buf, (int)view.len, SQLITE_TRANSIENT);
+ PyBuffer_Release(&view);
} else {
return -1;
}