Skip to content

Commit 6a66edf

Browse files
authored
Merge branch 'main' into gh-97914
2 parents 0c9b4ca + c72ffe7 commit 6a66edf

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

Doc/library/sqlite3.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ Connection objects
620620
supplied, this must be a :term:`callable` returning
621621
an instance of :class:`Cursor` or its subclasses.
622622

623-
.. method:: blobopen(table, column, row, /, *, readonly=False, name="main")
623+
.. method:: blobopen(table, column, rowid, /, *, readonly=False, name="main")
624624

625625
Open a :class:`Blob` handle to an existing
626626
:abbr:`BLOB (Binary Large OBject)`.
@@ -631,8 +631,8 @@ Connection objects
631631
:param str column:
632632
The name of the column where the blob is located.
633633

634-
:param str row:
635-
The name of the row where the blob is located.
634+
:param int rowid:
635+
The row id where the blob is located.
636636

637637
:param bool readonly:
638638
Set to ``True`` if the blob should be opened without write

Modules/_sqlite/clinic/connection.c.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_sqlite/connection.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ _sqlite3.Connection.blobopen as blobopen
578578
Table name.
579579
column as col: str
580580
Column name.
581-
row: sqlite3_int64
582-
Row index.
581+
rowid as row: sqlite3_int64
582+
Row id.
583583
/
584584
*
585585
readonly: bool = False
@@ -593,7 +593,7 @@ Open and return a BLOB object.
593593
static PyObject *
594594
blobopen_impl(pysqlite_Connection *self, const char *table, const char *col,
595595
sqlite3_int64 row, int readonly, const char *name)
596-
/*[clinic end generated code: output=6a02d43efb885d1c input=23576bd1108d8774]*/
596+
/*[clinic end generated code: output=6a02d43efb885d1c input=cc3d4b47dac08401]*/
597597
{
598598
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
599599
return NULL;

Modules/_testclinic.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -663,16 +663,16 @@ str_converter_encoding_impl(PyObject *module, char *a, char *b, char *c,
663663
static PyObject *
664664
bytes_from_buffer(Py_buffer *buf)
665665
{
666-
PyObject *bytes_obj = PyBytes_FromStringAndSize(NULL, buf->len);
667-
if (!bytes_obj) {
666+
PyBytesWriter *writer = PyBytesWriter_Create(buf->len);
667+
if (writer == NULL) {
668668
return NULL;
669669
}
670-
void *bytes_obj_buf = ((PyBytesObject *)bytes_obj)->ob_sval;
671-
if (PyBuffer_ToContiguous(bytes_obj_buf, buf, buf->len, 'C') < 0) {
672-
Py_DECREF(bytes_obj);
670+
void *data = PyBytesWriter_GetData(writer);
671+
if (PyBuffer_ToContiguous(data, buf, buf->len, 'C') < 0) {
672+
PyBytesWriter_Discard(writer);
673673
return NULL;
674674
}
675-
return bytes_obj;
675+
return PyBytesWriter_Finish(writer);
676676
}
677677

678678
/*[clinic input]

Objects/bytesobject.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3805,12 +3805,12 @@ byteswriter_resize(PyBytesWriter *writer, Py_ssize_t size, int overallocate)
38053805
{
38063806
assert(size >= 0);
38073807

3808-
if (size <= byteswriter_allocated(writer)) {
3808+
Py_ssize_t old_allocated = byteswriter_allocated(writer);
3809+
if (size <= old_allocated) {
38093810
return 0;
38103811
}
38113812

3812-
overallocate &= writer->overallocate;
3813-
if (overallocate) {
3813+
if (overallocate & writer->overallocate) {
38143814
if (size <= (PY_SSIZE_T_MAX - size / OVERALLOCATE_FACTOR)) {
38153815
size += size / OVERALLOCATE_FACTOR;
38163816
}
@@ -3849,6 +3849,15 @@ byteswriter_resize(PyBytesWriter *writer, Py_ssize_t size, int overallocate)
38493849
writer->small_buffer,
38503850
sizeof(writer->small_buffer));
38513851
}
3852+
3853+
#ifdef Py_DEBUG
3854+
Py_ssize_t allocated = byteswriter_allocated(writer);
3855+
if (overallocate && allocated > old_allocated) {
3856+
memset(byteswriter_data(writer) + old_allocated, 0xff,
3857+
allocated - old_allocated);
3858+
}
3859+
#endif
3860+
38523861
return 0;
38533862
}
38543863

@@ -3869,9 +3878,6 @@ byteswriter_create(Py_ssize_t size, int use_bytearray)
38693878
return NULL;
38703879
}
38713880
}
3872-
#ifdef Py_DEBUG
3873-
memset(writer->small_buffer, 0xff, sizeof(writer->small_buffer));
3874-
#endif
38753881
writer->obj = NULL;
38763882
writer->size = 0;
38773883
writer->use_bytearray = use_bytearray;
@@ -3884,6 +3890,9 @@ byteswriter_create(Py_ssize_t size, int use_bytearray)
38843890
}
38853891
writer->size = size;
38863892
}
3893+
#ifdef Py_DEBUG
3894+
memset(byteswriter_data(writer), 0xff, byteswriter_allocated(writer));
3895+
#endif
38873896
return writer;
38883897
}
38893898

0 commit comments

Comments
 (0)