self->bzs_avail_in_real = 0;
self->input_buffer = NULL;
self->input_buffer_size = 0;
- self->unused_data = PyBytes_FromStringAndSize(NULL, 0);
- if (self->unused_data == NULL)
- goto error;
+ self->unused_data = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
bzerror = BZ2_bzDecompressInit(&self->bzs, 0, 0);
if (catch_bz2_error(bzerror))
return PyBytes_FromStringAndSize(val.dptr, val.dsize);
}
if (default_value == NULL) {
- default_value = PyBytes_FromStringAndSize(NULL, 0);
- if (default_value == NULL) {
- return NULL;
- }
+ default_value = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
val.dptr = NULL;
val.dsize = 0;
}
self->needs_input = 1;
self->input_buffer = NULL;
self->input_buffer_size = 0;
- Py_XSETREF(self->unused_data, PyBytes_FromStringAndSize(NULL, 0));
- if (self->unused_data == NULL) {
- goto error;
- }
+ Py_XSETREF(self->unused_data, Py_GetConstant(Py_CONSTANT_EMPTY_BYTES));
switch (format) {
case FORMAT_AUTO:
/* 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);
self->zst.zfree = PyZlib_Free;
self->zst.next_in = NULL;
self->zst.avail_in = 0;
- self->unused_data = PyBytes_FromStringAndSize(NULL, 0);
- if (self->unused_data == NULL) {
- Py_CLEAR(self);
- return NULL;
- }
+ self->unused_data = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
self->lock = PyThread_allocate_lock();
if (self->lock == NULL) {
Py_DECREF(self);
"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 */
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) {
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)
len = PyUnicode_GET_LENGTH(unicode);
if (len == 0) {
- return PyBytes_FromStringAndSize(NULL, 0);
+ return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
}
kind = PyUnicode_KIND(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);
}
if (len == 0)
- return PyBytes_FromStringAndSize(NULL, 0);
+ return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
offset = 0;
do