mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +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
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue