Lines Matching defs:self
4 #define clinic_state() (pysqlite_get_state_by_type(Py_TYPE(self)))
15 close_blob(pysqlite_Blob *self)
17 if (self->blob) {
18 sqlite3_blob *blob = self->blob;
19 self->blob = NULL;
28 blob_traverse(pysqlite_Blob *self, visitproc visit, void *arg)
30 Py_VISIT(Py_TYPE(self));
31 Py_VISIT(self->connection);
36 blob_clear(pysqlite_Blob *self)
38 Py_CLEAR(self->connection);
43 blob_dealloc(pysqlite_Blob *self)
45 PyTypeObject *tp = Py_TYPE(self);
46 PyObject_GC_UnTrack(self);
48 close_blob(self);
50 if (self->in_weakreflist != NULL) {
51 PyObject_ClearWeakRefs((PyObject*)self);
53 tp->tp_clear((PyObject *)self);
54 tp->tp_free(self);
60 check_blob(pysqlite_Blob *self)
62 if (!pysqlite_check_connection(self->connection) ||
63 !pysqlite_check_thread(self->connection)) {
66 if (self->blob == NULL) {
67 pysqlite_state *state = self->connection->state;
83 blob_close_impl(pysqlite_Blob *self)
86 if (!pysqlite_check_connection(self->connection) ||
87 !pysqlite_check_thread(self->connection))
91 close_blob(self);
96 pysqlite_close_all_blobs(pysqlite_Connection *self)
98 for (int i = 0; i < PyList_GET_SIZE(self->blobs); i++) {
99 PyObject *weakref = PyList_GET_ITEM(self->blobs, i);
108 blob_seterror(pysqlite_Blob *self, int rc)
110 assert(self->connection != NULL);
114 PyErr_SetString(self->connection->OperationalError,
119 _pysqlite_seterror(self->connection->state, self->connection->db);
123 read_single(pysqlite_Blob *self, Py_ssize_t offset)
128 rc = sqlite3_blob_read(self->blob, (void *)&buf, 1, (int)offset);
132 blob_seterror(self, rc);
139 read_multiple(pysqlite_Blob *self, Py_ssize_t length, Py_ssize_t offset)
141 assert(length <= sqlite3_blob_bytes(self->blob));
142 assert(offset < sqlite3_blob_bytes(self->blob));
152 rc = sqlite3_blob_read(self->blob, raw_buffer, (int)length, (int)offset);
157 blob_seterror(self, rc);
179 blob_read_impl(pysqlite_Blob *self, int length)
182 if (!check_blob(self)) {
188 int blob_len = sqlite3_blob_bytes(self->blob);
189 int max_read_len = blob_len - self->offset;
199 PyObject *buffer = read_multiple(self, length, self->offset);
203 self->offset += length;
208 inner_write(pysqlite_Blob *self, const void *buf, Py_ssize_t len,
211 Py_ssize_t blob_len = sqlite3_blob_bytes(self->blob);
221 rc = sqlite3_blob_write(self->blob, buf, (int)len, (int)offset);
225 blob_seterror(self, rc);
245 blob_write_impl(pysqlite_Blob *self, Py_buffer *data)
248 if (!check_blob(self)) {
252 int rc = inner_write(self, data->buf, data->len, self->offset);
256 self->offset += (int)data->len;
276 blob_seek_impl(pysqlite_Blob *self, int offset, int origin)
279 if (!check_blob(self)) {
283 int blob_len = sqlite3_blob_bytes(self->blob);
288 if (offset > INT_MAX - self->offset) {
291 offset += self->offset;
311 self->offset = offset;
327 blob_tell_impl(pysqlite_Blob *self)
330 if (!check_blob(self)) {
333 return PyLong_FromLong(self->offset);
344 blob_enter_impl(pysqlite_Blob *self)
347 if (!check_blob(self)) {
350 return Py_NewRef(self);
366 blob_exit_impl(pysqlite_Blob *self, PyObject *type, PyObject *val,
370 if (!check_blob(self)) {
373 close_blob(self);
378 blob_length(pysqlite_Blob *self)
380 if (!check_blob(self)) {
383 return sqlite3_blob_bytes(self->blob);
387 get_subscript_index(pysqlite_Blob *self, PyObject *item)
393 int blob_len = sqlite3_blob_bytes(self->blob);
405 subscript_index(pysqlite_Blob *self, PyObject *item)
407 Py_ssize_t i = get_subscript_index(self, item);
411 return read_single(self, i);
415 get_slice_info(pysqlite_Blob *self, PyObject *item, Py_ssize_t *start,
421 int len = sqlite3_blob_bytes(self->blob);
427 subscript_slice(pysqlite_Blob *self, PyObject *item)
430 if (get_slice_info(self, item, &start, &stop, &step, &len) < 0) {
435 return read_multiple(self, len, start);
437 PyObject *blob = read_multiple(self, stop - start, start);
454 blob_subscript(pysqlite_Blob *self, PyObject *item)
456 if (!check_blob(self)) {
461 return subscript_index(self, item);
464 return subscript_slice(self, item);
472 ass_subscript_index(pysqlite_Blob *self, PyObject *item, PyObject *value)
485 Py_ssize_t i = get_subscript_index(self, item);
501 return inner_write(self, (const void *)&byte, 1, i);
505 ass_subscript_slice(pysqlite_Blob *self, PyObject *item, PyObject *value)
514 if (get_slice_info(self, item, &start, &stop, &step, &len) < 0) {
533 rc = inner_write(self, vbuf.buf, len, start);
536 PyObject *blob_bytes = read_multiple(self, stop - start, start);
542 rc = inner_write(self, blob_buf, stop - start, start);
551 blob_ass_subscript(pysqlite_Blob *self, PyObject *item, PyObject *value)
553 if (!check_blob(self)) {
558 return ass_subscript_index(self, item, value);
561 return ass_subscript_slice(self, item, value);