Skip to content

Commit e65dcc8

Browse files
committed
gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_BYTES)
Replace PyBytes_FromStringAndSize(NULL, 0) with Py_GetConstant(Py_CONSTANT_EMPTY_BYTES).
1 parent 37e533a commit e65dcc8

File tree

12 files changed

+17
-17
lines changed

12 files changed

+17
-17
lines changed

Modules/_bz2module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ _bz2_BZ2Decompressor_impl(PyTypeObject *type)
664664
self->bzs_avail_in_real = 0;
665665
self->input_buffer = NULL;
666666
self->input_buffer_size = 0;
667-
self->unused_data = PyBytes_FromStringAndSize(NULL, 0);
667+
self->unused_data = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
668668
if (self->unused_data == NULL)
669669
goto error;
670670

Modules/_datetimemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ make_somezreplacement(PyObject *object, char *sep, PyObject *tzinfoarg)
17471747
PyObject *tzinfo = get_tzinfo_member(object);
17481748

17491749
if (tzinfo == Py_None || tzinfo == NULL) {
1750-
return PyBytes_FromStringAndSize(NULL, 0);
1750+
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
17511751
}
17521752

17531753
assert(tzinfoarg != NULL);

Modules/_dbmmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ _dbm_dbm_setdefault_impl(dbmobject *self, PyTypeObject *cls, const char *key,
394394
return PyBytes_FromStringAndSize(val.dptr, val.dsize);
395395
}
396396
if (default_value == NULL) {
397-
default_value = PyBytes_FromStringAndSize(NULL, 0);
397+
default_value = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
398398
if (default_value == NULL) {
399399
return NULL;
400400
}

Modules/_io/bufferedio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ _io__Buffered_read1_impl(buffered *self, Py_ssize_t n)
10301030
CHECK_CLOSED(self, "read of closed file")
10311031

10321032
if (n == 0)
1033-
return PyBytes_FromStringAndSize(NULL, 0);
1033+
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
10341034

10351035
/* Return up to n bytes. If at least one byte is buffered, we
10361036
only return buffered bytes. Otherwise, we do one raw read. */

Modules/_io/bytesio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ bytesio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
913913
/* tp_alloc initializes all the fields to zero. So we don't have to
914914
initialize them here. */
915915

916-
self->buf = PyBytes_FromStringAndSize(NULL, 0);
916+
self->buf = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
917917
if (self->buf == NULL) {
918918
Py_DECREF(self);
919919
return PyErr_NoMemory();

Modules/_io/winconsoleio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ _io__WindowsConsoleIO_readall_impl(winconsoleio *self)
874874
if (len == 0 && _buflen(self) == 0) {
875875
/* when the result starts with ^Z we return an empty buffer */
876876
PyMem_Free(buf);
877-
return PyBytes_FromStringAndSize(NULL, 0);
877+
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
878878
}
879879

880880
if (len) {

Modules/_lzmamodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ _lzma_LZMADecompressor_impl(PyTypeObject *type, int format,
12551255
self->needs_input = 1;
12561256
self->input_buffer = NULL;
12571257
self->input_buffer_size = 0;
1258-
Py_XSETREF(self->unused_data, PyBytes_FromStringAndSize(NULL, 0));
1258+
Py_XSETREF(self->unused_data, Py_GetConstant(Py_CONSTANT_EMPTY_BYTES));
12591259
if (self->unused_data == NULL) {
12601260
goto error;
12611261
}

Modules/_sqlite/blob.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ blob_read_impl(pysqlite_Blob *self, int length)
191191

192192
assert(length >= 0);
193193
if (length == 0) {
194-
return PyBytes_FromStringAndSize(NULL, 0);
194+
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
195195
}
196196

197197
PyObject *buffer = read_multiple(self, length, self->offset);

Modules/cjkcodecs/multibytecodec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ multibytecodec_encode(const MultibyteCodec *codec,
498498
datalen = PyUnicode_GET_LENGTH(text);
499499

500500
if (datalen == 0 && !(flags & MBENC_RESET))
501-
return PyBytes_FromStringAndSize(NULL, 0);
501+
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
502502

503503
buf.excobj = NULL;
504504
buf.outobj = NULL;

Modules/zlibmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ zlib_Compress_flush_impl(compobject *self, PyTypeObject *cls, int mode)
990990
/* Flushing with Z_NO_FLUSH is a no-op, so there's no point in
991991
doing any work at all; just return an empty string. */
992992
if (mode == Z_NO_FLUSH) {
993-
return PyBytes_FromStringAndSize(NULL, 0);
993+
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
994994
}
995995

996996
ENTER_ZLIB(self);
@@ -1739,7 +1739,7 @@ ZlibDecompressor__new__(PyTypeObject *cls,
17391739
self->zst.zfree = PyZlib_Free;
17401740
self->zst.next_in = NULL;
17411741
self->zst.avail_in = 0;
1742-
self->unused_data = PyBytes_FromStringAndSize(NULL, 0);
1742+
self->unused_data = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
17431743
if (self->unused_data == NULL) {
17441744
Py_CLEAR(self);
17451745
return NULL;

0 commit comments

Comments
 (0)