diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c index 661847ad26702e..39677d30e41e95 100644 --- a/Modules/_bz2module.c +++ b/Modules/_bz2module.c @@ -664,7 +664,7 @@ _bz2_BZ2Decompressor_impl(PyTypeObject *type) self->bzs_avail_in_real = 0; self->input_buffer = NULL; self->input_buffer_size = 0; - self->unused_data = PyBytes_FromStringAndSize(NULL, 0); + self->unused_data = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); if (self->unused_data == NULL) goto error; diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index b1102984cb5e9e..76629868066e01 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -1747,7 +1747,7 @@ make_somezreplacement(PyObject *object, char *sep, PyObject *tzinfoarg) PyObject *tzinfo = get_tzinfo_member(object); if (tzinfo == Py_None || tzinfo == NULL) { - return PyUnicode_FromStringAndSize(NULL, 0); + return Py_GetConstant(Py_CONSTANT_EMPTY_STR); } assert(tzinfoarg != NULL); diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c index 1be4234aad3291..ced31cdd05b080 100644 --- a/Modules/_dbmmodule.c +++ b/Modules/_dbmmodule.c @@ -394,7 +394,7 @@ _dbm_dbm_setdefault_impl(dbmobject *self, PyTypeObject *cls, const char *key, return PyBytes_FromStringAndSize(val.dptr, val.dsize); } if (default_value == NULL) { - default_value = PyBytes_FromStringAndSize(NULL, 0); + default_value = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); if (default_value == NULL) { return NULL; } diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index bc5fff54a62b6d..a8916de62e6ada 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -1030,7 +1030,7 @@ _io__Buffered_read1_impl(buffered *self, Py_ssize_t n) CHECK_CLOSED(self, "read of closed file") if (n == 0) - return PyBytes_FromStringAndSize(NULL, 0); + return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); /* Return up to n bytes. If at least one byte is buffered, we only return buffered bytes. Otherwise, we do one raw read. */ diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index fb66d3db0f7a1f..967b0420bf2fc4 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -913,7 +913,7 @@ bytesio_new(PyTypeObject *type, PyObject *args, PyObject *kwds) /* tp_alloc initializes all the fields to zero. So we don't have to initialize them here. */ - self->buf = PyBytes_FromStringAndSize(NULL, 0); + self->buf = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); if (self->buf == NULL) { Py_DECREF(self); return PyErr_NoMemory(); diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index d7cb5abfdc0abd..69ed77fb326c57 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -874,7 +874,7 @@ _io__WindowsConsoleIO_readall_impl(winconsoleio *self) if (len == 0 && _buflen(self) == 0) { /* when the result starts with ^Z we return an empty buffer */ PyMem_Free(buf); - return PyBytes_FromStringAndSize(NULL, 0); + return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); } if (len) { diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c index 97f3a8f03da9a8..d8cda0a44ddd7b 100644 --- a/Modules/_lzmamodule.c +++ b/Modules/_lzmamodule.c @@ -1255,7 +1255,7 @@ _lzma_LZMADecompressor_impl(PyTypeObject *type, int format, self->needs_input = 1; self->input_buffer = NULL; self->input_buffer_size = 0; - Py_XSETREF(self->unused_data, PyBytes_FromStringAndSize(NULL, 0)); + Py_XSETREF(self->unused_data, Py_GetConstant(Py_CONSTANT_EMPTY_BYTES)); if (self->unused_data == NULL) { goto error; } diff --git a/Modules/_sqlite/blob.c b/Modules/_sqlite/blob.c index d1a549a971c24a..3bbcc7d30dda6e 100644 --- a/Modules/_sqlite/blob.c +++ b/Modules/_sqlite/blob.c @@ -191,7 +191,7 @@ blob_read_impl(pysqlite_Blob *self, int length) assert(length >= 0); if (length == 0) { - return PyBytes_FromStringAndSize(NULL, 0); + return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); } PyObject *buffer = read_multiple(self, length, self->offset); diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c index 53135ae4aa7968..94fd0375b714fe 100644 --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -498,7 +498,7 @@ multibytecodec_encode(const MultibyteCodec *codec, datalen = PyUnicode_GET_LENGTH(text); if (datalen == 0 && !(flags & MBENC_RESET)) - return PyBytes_FromStringAndSize(NULL, 0); + return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); buf.excobj = NULL; buf.outobj = NULL; diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 78dcce73cdaade..b5639a3551d13c 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -990,7 +990,7 @@ zlib_Compress_flush_impl(compobject *self, PyTypeObject *cls, int mode) /* Flushing with Z_NO_FLUSH is a no-op, so there's no point in doing any work at all; just return an empty string. */ if (mode == Z_NO_FLUSH) { - return PyBytes_FromStringAndSize(NULL, 0); + return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); } ENTER_ZLIB(self); @@ -1739,7 +1739,7 @@ ZlibDecompressor__new__(PyTypeObject *cls, self->zst.zfree = PyZlib_Free; self->zst.next_in = NULL; self->zst.avail_in = 0; - self->unused_data = PyBytes_FromStringAndSize(NULL, 0); + self->unused_data = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); if (self->unused_data == NULL) { Py_CLEAR(self); return NULL; diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index dcc1aba76abbed..83dfde1465e32d 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2706,7 +2706,7 @@ bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding, "errors without a string argument"); return NULL; } - bytes = PyBytes_FromStringAndSize(NULL, 0); + bytes = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); } else if (encoding != NULL) { /* Encode via the codec registry */ @@ -3604,7 +3604,7 @@ _PyBytesWriter_Finish(_PyBytesWriter *writer, void *str) if (size == 0 && !writer->use_bytearray) { Py_CLEAR(writer->buffer); /* Get the empty byte string singleton */ - result = PyBytes_FromStringAndSize(NULL, 0); + result = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); } else if (writer->use_small_buffer) { if (writer->use_bytearray) { diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 9cd9781e412524..67cddf114c514b 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -4868,7 +4868,7 @@ _PyUnicode_EncodeUTF7(PyObject *str, len = PyUnicode_GET_LENGTH(str); if (len == 0) - return PyBytes_FromStringAndSize(NULL, 0); + return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); /* It might be possible to tighten this worst case */ if (len > PY_SSIZE_T_MAX / 8) @@ -6636,7 +6636,7 @@ PyUnicode_AsUnicodeEscapeString(PyObject *unicode) len = PyUnicode_GET_LENGTH(unicode); if (len == 0) { - return PyBytes_FromStringAndSize(NULL, 0); + return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); } kind = PyUnicode_KIND(unicode); @@ -7086,7 +7086,7 @@ unicode_encode_ucs1(PyObject *unicode, /* allocate enough for a simple encoding without replacements, if we need more, we'll resize */ if (size == 0) - return PyBytes_FromStringAndSize(NULL, 0); + return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); _PyBytesWriter_Init(&writer); str = _PyBytesWriter_Alloc(&writer, size); @@ -8031,7 +8031,7 @@ encode_code_page(int code_page, } if (len == 0) - return PyBytes_FromStringAndSize(NULL, 0); + return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); offset = 0; do