Skip to content
Prev Previous commit
Next Next commit
Cast
  • Loading branch information
Erlend E. Aasland committed Apr 16, 2022
commit 86e324a49243b7789e5254335b8dab22842c831f
18 changes: 10 additions & 8 deletions Modules/_sqlite/blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ blob_seterror(pysqlite_Blob *self, int rc)
}

static PyObject *
inner_read(pysqlite_Blob *self, int length, int offset)
inner_read(pysqlite_Blob *self, Py_ssize_t length, Py_ssize_t offset)
{
PyObject *buffer = PyBytes_FromStringAndSize(NULL, length);
if (buffer == NULL) {
Expand All @@ -130,7 +130,7 @@ inner_read(pysqlite_Blob *self, int length, int offset)
char *raw_buffer = PyBytes_AS_STRING(buffer);
int rc;
Py_BEGIN_ALLOW_THREADS
rc = sqlite3_blob_read(self->blob, raw_buffer, length, offset);
rc = sqlite3_blob_read(self->blob, raw_buffer, (int)length, (int)offset);
Py_END_ALLOW_THREADS

if (rc != SQLITE_OK) {
Expand Down Expand Up @@ -181,17 +181,19 @@ blob_read_impl(pysqlite_Blob *self, int length)
};

static int
inner_write(pysqlite_Blob *self, const void *buf, Py_ssize_t len, int offset)
inner_write(pysqlite_Blob *self, const void *buf, Py_ssize_t len,
Py_ssize_t offset)
{
int remaining_len = sqlite3_blob_bytes(self->blob) - self->offset;
int blob_len = sqlite3_blob_bytes(self->blob);
int remaining_len = blob_len - self->offset;
if (len > remaining_len) {
PyErr_SetString(PyExc_ValueError, "data longer than blob length");
return -1;
}

int rc;
Py_BEGIN_ALLOW_THREADS
rc = sqlite3_blob_write(self->blob, buf, (int)len, offset);
rc = sqlite3_blob_write(self->blob, buf, (int)len, (int)offset);
Py_END_ALLOW_THREADS

if (rc != SQLITE_OK) {
Expand Down Expand Up @@ -356,7 +358,7 @@ blob_length(pysqlite_Blob *self)
return sqlite3_blob_bytes(self->blob);
};

static int
static Py_ssize_t
get_subscript_index(pysqlite_Blob *self, PyObject *item)
{
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
Expand All @@ -377,7 +379,7 @@ get_subscript_index(pysqlite_Blob *self, PyObject *item)
static PyObject *
subscript_index(pysqlite_Blob *self, PyObject *item)
{
int i = get_subscript_index(self, item);
Py_ssize_t i = get_subscript_index(self, item);
if (i < 0) {
return NULL;
}
Expand Down Expand Up @@ -455,7 +457,7 @@ ass_subscript_index(pysqlite_Blob *self, PyObject *item, PyObject *value)
return -1;
}

int i = get_subscript_index(self, item);
Py_ssize_t i = get_subscript_index(self, item);
if (i < 0) {
return -1;
}
Expand Down