]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_BYTES) (#125195)
authorVictor Stinner <vstinner@python.org>
Wed, 9 Oct 2024 15:12:11 +0000 (17:12 +0200)
committerGitHub <noreply@github.com>
Wed, 9 Oct 2024 15:12:11 +0000 (17:12 +0200)
Replace PyBytes_FromString("") and PyBytes_FromStringAndSize("", 0)
with Py_GetConstant(Py_CONSTANT_EMPTY_BYTES).

Modules/_ctypes/_ctypes.c
Modules/_io/textio.c
Modules/mmapmodule.c
Modules/zlibmodule.c
Objects/bytesobject.c
Parser/action_helpers.c

index 951e6914ba67a4bb9bab4d34c3b7e3084feed6b7..9453ed3250bc3b8835dbf73fd986af6837e412f4 100644 (file)
@@ -4732,7 +4732,7 @@ Array_subscript(PyObject *myself, PyObject *item)
             char *dest;
 
             if (slicelen <= 0)
-                return PyBytes_FromStringAndSize("", 0);
+                return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
             if (step == 1) {
                 return PyBytes_FromStringAndSize(ptr + start,
                                                  slicelen);
@@ -5418,7 +5418,7 @@ Pointer_subscript(PyObject *myself, PyObject *item)
             char *dest;
 
             if (len <= 0)
-                return PyBytes_FromStringAndSize("", 0);
+                return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
             if (step == 1) {
                 return PyBytes_FromStringAndSize(ptr + start,
                                                  len);
index 439e26c5271939bef89e0a86480b1adf7c463fe1..68d163619624126332f4ad94d7a9df47ffe6e7f8 100644 (file)
@@ -559,7 +559,7 @@ _io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self)
         Py_DECREF(state);
     }
     else {
-        buffer = PyBytes_FromString("");
+        buffer = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
         flag = 0;
     }
     flag <<= 1;
index 99a85e9e49ad4775107f3a72478467661b2970a4..e1c26e19932664056c21f58413c0d11062eb32fb 100644 (file)
@@ -486,7 +486,7 @@ mmap_read_line_method(mmap_object *self,
 
     remaining = (self->pos < self->size) ? self->size - self->pos : 0;
     if (!remaining)
-        return PyBytes_FromString("");
+        return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
     start = self->data + self->pos;
 
     if (safe_memchr(&eol, start, '\n', remaining) < 0) {
@@ -1274,7 +1274,7 @@ mmap_subscript(mmap_object *self, PyObject *item)
 
         CHECK_VALID(NULL);
         if (slicelen <= 0)
-            return PyBytes_FromStringAndSize("", 0);
+            return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
         else if (step == 1)
             return _safe_PyBytes_FromStringAndSize(self->data + start, slicelen);
         else {
index c5aaf22eeb294876c85bea24559d12a7334c341e..78dcce73cdaade5d3a23743e608e5d922c1522ea 100644 (file)
@@ -267,12 +267,12 @@ newcompobject(PyTypeObject *type)
     self->eof = 0;
     self->is_initialised = 0;
     self->zdict = NULL;
-    self->unused_data = PyBytes_FromStringAndSize("", 0);
+    self->unused_data = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
     if (self->unused_data == NULL) {
         Py_DECREF(self);
         return NULL;
     }
-    self->unconsumed_tail = PyBytes_FromStringAndSize("", 0);
+    self->unconsumed_tail = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
     if (self->unconsumed_tail == NULL) {
         Py_DECREF(self);
         return NULL;
index 58a4feed351707c34c9b1584e2fb5253f5a1e6d9..bf58e55e100b3a56c098fcacdf2554afbb62ec54 100644 (file)
@@ -1638,7 +1638,7 @@ bytes_subscript(PyObject *op, PyObject* item)
                                             &stop, step);
 
         if (slicelength <= 0) {
-            return PyBytes_FromStringAndSize("", 0);
+            return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
         }
         else if (start == 0 && step == 1 &&
                  slicelength == PyBytes_GET_SIZE(self) &&
index 1972c606827cdb7c1a52b89550f8f689451cd8aa..24b817c6f8ff2708aba78a140c745af9d31ec688 100644 (file)
@@ -1541,7 +1541,7 @@ _PyPegen_concatenate_strings(Parser *p, asdl_expr_seq *strings,
     }
 
     if (bytes_found) {
-        PyObject* res = PyBytes_FromString("");
+        PyObject* res = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
 
         /* Bytes literals never get a kind, but just for consistency
            since they are represented as Constant nodes, we'll mirror