gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_STR) (#125583)

Replace PyUnicode_FromStringAndSize(NULL, 0)
with Py_GetConstant(Py_CONSTANT_EMPTY_STR).
This commit is contained in:
Victor Stinner 2024-10-25 11:14:52 +02:00 committed by GitHub
parent db96327203
commit ebcc578dff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 5 deletions

View 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';