summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite
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
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')
-rw-r--r--Modules/_sqlite/connection.c11
-rw-r--r--Modules/_sqlite/statement.c13
2 files changed, 14 insertions, 10 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;
}
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c
index 34babfd..e870633 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -94,7 +94,6 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
{
int rc = SQLITE_OK;
- const char* buffer;
char* string;
Py_ssize_t buflen;
parameter_type paramtype;
@@ -145,18 +144,22 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
}
rc = sqlite3_bind_text(self->st, pos, string, (int)buflen, SQLITE_TRANSIENT);
break;
- case TYPE_BUFFER:
- if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) != 0) {
+ case TYPE_BUFFER: {
+ Py_buffer view;
+ if (PyObject_GetBuffer(parameter, &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;
}
- rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT);
+ rc = sqlite3_bind_blob(self->st, pos, view.buf, (int)view.len, SQLITE_TRANSIENT);
+ PyBuffer_Release(&view);
break;
+ }
case TYPE_UNKNOWN:
rc = -1;
}