]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_STR) (#125583)
authorVictor Stinner <vstinner@python.org>
Fri, 25 Oct 2024 09:14:52 +0000 (11:14 +0200)
committerGitHub <noreply@github.com>
Fri, 25 Oct 2024 09:14:52 +0000 (11:14 +0200)
Replace PyUnicode_FromStringAndSize(NULL, 0)
with Py_GetConstant(Py_CONSTANT_EMPTY_STR).

Modules/_datetimemodule.c
Modules/_io/textio.c
Modules/getpath.c

index e1bb98fcf0586219a4a51b3b91706bb4588a0039..b1102984cb5e9e48588eef0a5916b55bc2223775 100644 (file)
@@ -1766,7 +1766,7 @@ make_Zreplacement(PyObject *object, PyObject *tzinfoarg)
 {
     PyObject *temp;
     PyObject *tzinfo = get_tzinfo_member(object);
-    PyObject *Zreplacement = PyUnicode_FromStringAndSize(NULL, 0);
+    PyObject *Zreplacement = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
 
     if (Zreplacement == NULL)
         return NULL;
index 68d163619624126332f4ad94d7a9df47ffe6e7f8..0d851ee211511c9f600d4e258c3ca499b12e6fcd 100644 (file)
@@ -1806,7 +1806,7 @@ textiowrapper_get_decoded_chars(textio *self, Py_ssize_t n)
     Py_ssize_t avail;
 
     if (self->decoded_chars == NULL)
-        return PyUnicode_FromStringAndSize(NULL, 0);
+        return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
 
     /* decoded_chars is guaranteed to be "ready". */
     avail = (PyUnicode_GET_LENGTH(self->decoded_chars)
index d0128b20faeeae0e73a1756a73a021c7688828df..18ddfaf8dbce1a47a8148192729e19b8580046c5 100644 (file)
@@ -108,7 +108,7 @@ getpath_dirname(PyObject *Py_UNUSED(self), PyObject *args)
     Py_ssize_t end = PyUnicode_GET_LENGTH(path);
     Py_ssize_t pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
     if (pos < 0) {
-        return PyUnicode_FromStringAndSize(NULL, 0);
+        return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
     }
     return PyUnicode_Substring(path, 0, pos);
 }
@@ -258,7 +258,7 @@ getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
     }
     Py_ssize_t n = PyTuple_GET_SIZE(args);
     if (n == 0) {
-        return PyUnicode_FromStringAndSize(NULL, 0);
+        return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
     }
     /* Convert all parts to wchar and accumulate max final length */
     wchar_t **parts = (wchar_t **)PyMem_Malloc(n * sizeof(wchar_t *));
@@ -302,7 +302,7 @@ getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
             PyErr_NoMemory();
             return NULL;
         }
-        return PyUnicode_FromStringAndSize(NULL, 0);
+        return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
     }
 
     final[0] = '\0';