Skip to content

Commit ebcc578

Browse files
authored
gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_STR) (#125583)
Replace PyUnicode_FromStringAndSize(NULL, 0) with Py_GetConstant(Py_CONSTANT_EMPTY_STR).
1 parent db96327 commit ebcc578

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

Modules/_datetimemodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ make_Zreplacement(PyObject *object, PyObject *tzinfoarg)
17661766
{
17671767
PyObject *temp;
17681768
PyObject *tzinfo = get_tzinfo_member(object);
1769-
PyObject *Zreplacement = PyUnicode_FromStringAndSize(NULL, 0);
1769+
PyObject *Zreplacement = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
17701770

17711771
if (Zreplacement == NULL)
17721772
return NULL;

Modules/_io/textio.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ textiowrapper_get_decoded_chars(textio *self, Py_ssize_t n)
18061806
Py_ssize_t avail;
18071807

18081808
if (self->decoded_chars == NULL)
1809-
return PyUnicode_FromStringAndSize(NULL, 0);
1809+
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
18101810

18111811
/* decoded_chars is guaranteed to be "ready". */
18121812
avail = (PyUnicode_GET_LENGTH(self->decoded_chars)

Modules/getpath.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ getpath_dirname(PyObject *Py_UNUSED(self), PyObject *args)
108108
Py_ssize_t end = PyUnicode_GET_LENGTH(path);
109109
Py_ssize_t pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
110110
if (pos < 0) {
111-
return PyUnicode_FromStringAndSize(NULL, 0);
111+
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
112112
}
113113
return PyUnicode_Substring(path, 0, pos);
114114
}
@@ -258,7 +258,7 @@ getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
258258
}
259259
Py_ssize_t n = PyTuple_GET_SIZE(args);
260260
if (n == 0) {
261-
return PyUnicode_FromStringAndSize(NULL, 0);
261+
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
262262
}
263263
/* Convert all parts to wchar and accumulate max final length */
264264
wchar_t **parts = (wchar_t **)PyMem_Malloc(n * sizeof(wchar_t *));
@@ -302,7 +302,7 @@ getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
302302
PyErr_NoMemory();
303303
return NULL;
304304
}
305-
return PyUnicode_FromStringAndSize(NULL, 0);
305+
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
306306
}
307307

308308
final[0] = '\0';

0 commit comments

Comments
 (0)