Skip to content

Commit c4598d2

Browse files
committed
pythongh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_STR)
Replace PyUnicode_New(0, 0) with Py_GetConstant(Py_CONSTANT_EMPTY_STR).
1 parent c203955 commit c4598d2

File tree

10 files changed

+13
-13
lines changed

10 files changed

+13
-13
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4756,7 +4756,7 @@ Array_subscript(PyObject *myself, PyObject *item)
47564756
wchar_t *dest;
47574757

47584758
if (slicelen <= 0)
4759-
return PyUnicode_New(0, 0);
4759+
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
47604760
if (step == 1) {
47614761
return PyUnicode_FromWideChar(ptr + start,
47624762
slicelen);
@@ -5438,7 +5438,7 @@ Pointer_subscript(PyObject *myself, PyObject *item)
54385438
wchar_t *dest;
54395439

54405440
if (len <= 0)
5441-
return PyUnicode_New(0, 0);
5441+
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
54425442
if (step == 1) {
54435443
return PyUnicode_FromWideChar(ptr + start,
54445444
len);

Modules/_elementtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ _elementtree_Element_findtext_impl(ElementObject *self, PyTypeObject *cls,
13171317
PyObject* text = element_get_text((ElementObject*)item);
13181318
if (text == Py_None) {
13191319
Py_DECREF(item);
1320-
return PyUnicode_New(0, 0);
1320+
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
13211321
}
13221322
Py_XINCREF(text);
13231323
Py_DECREF(item);

Modules/_io/stringio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ _stringio_readline(stringio *self, Py_ssize_t limit)
353353

354354
/* In case of overseek, return the empty string */
355355
if (self->pos >= self->string_size)
356-
return PyUnicode_New(0, 0);
356+
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
357357

358358
start = self->buf + self->pos;
359359
if (limit < 0 || limit > self->string_size - self->pos)

Modules/cjkcodecs/multibytecodec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ _multibytecodec_MultibyteCodec_decode_impl(MultibyteCodecObject *self,
669669

670670
if (datalen == 0) {
671671
ERROR_DECREF(errorcb);
672-
return make_tuple(PyUnicode_New(0, 0), 0);
672+
return make_tuple(Py_GetConstant(Py_CONSTANT_EMPTY_STR), 0);
673673
}
674674

675675
_PyUnicodeWriter_Init(&buf.writer);
@@ -1434,7 +1434,7 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
14341434
Py_ssize_t rsize;
14351435

14361436
if (sizehint == 0)
1437-
return PyUnicode_New(0, 0);
1437+
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
14381438

14391439
_PyUnicodeWriter_Init(&buf.writer);
14401440
buf.excobj = NULL;

Modules/socketmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5636,7 +5636,7 @@ socket_gethostname(PyObject *self, PyObject *unused)
56365636
return PyErr_SetFromWindowsErr(0);
56375637

56385638
if (size == 0)
5639-
return PyUnicode_New(0, 0);
5639+
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
56405640

56415641
/* MSDN says ERROR_MORE_DATA may occur because DNS allows longer
56425642
names */

Objects/abstract.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
862862

863863
/* If no format_spec is provided, use an empty string */
864864
if (format_spec == NULL) {
865-
empty = PyUnicode_New(0, 0);
865+
empty = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
866866
format_spec = empty;
867867
}
868868

Objects/stringlib/unicode_format.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Py_LOCAL_INLINE(PyObject *)
7373
SubString_new_object_or_empty(SubString *str)
7474
{
7575
if (str->str == NULL) {
76-
return PyUnicode_New(0, 0);
76+
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
7777
}
7878
return SubString_new_object(str);
7979
}
@@ -531,7 +531,7 @@ render_field(PyObject *fieldobj, SubString *format_spec, _PyUnicodeWriter *write
531531
format_spec->start,
532532
format_spec->end);
533533
else
534-
format_spec_object = PyUnicode_New(0, 0);
534+
format_spec_object = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
535535
if (format_spec_object == NULL)
536536
goto done;
537537

Python/codecs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ PyObject *PyCodec_IgnoreErrors(PyObject *exc)
696696
wrong_exception_type(exc);
697697
return NULL;
698698
}
699-
return Py_BuildValue("(Nn)", PyUnicode_New(0, 0), end);
699+
return Py_BuildValue("(Nn)", Py_GetConstant(Py_CONSTANT_EMPTY_STR), end);
700700
}
701701

702702

Python/formatter_unicode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ get_locale_info(enum LocaleType type, LocaleInfo *locale_info)
740740
break;
741741
case LT_NO_LOCALE:
742742
locale_info->decimal_point = PyUnicode_FromOrdinal('.');
743-
locale_info->thousands_sep = PyUnicode_New(0, 0);
743+
locale_info->thousands_sep = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
744744
if (!locale_info->decimal_point || !locale_info->thousands_sep)
745745
return -1;
746746
locale_info->grouping = no_grouping;

Python/marshal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ r_object(RFILE *p)
12181218
v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass");
12191219
}
12201220
else {
1221-
v = PyUnicode_New(0, 0);
1221+
v = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
12221222
}
12231223
if (v == NULL)
12241224
break;

0 commit comments

Comments
 (0)