Skip to content

Commit 1352259

Browse files
committed
gh-139353: Add Objects/unicode_format.c file
Move PyUnicode_Format() implementation from unicodeobject.c to unicode_format.c.
1 parent 75b1afe commit 1352259

File tree

10 files changed

+1029
-985
lines changed

10 files changed

+1029
-985
lines changed

Include/internal/pycore_unicodeobject.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,43 @@ extern "C" {
1111
#include "pycore_fileutils.h" // _Py_error_handler
1212
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
1313

14+
// Maximum code point of Unicode 6.0: 0x10ffff (1,114,111).
15+
// The value must be the same in fileutils.c.
16+
#define _Py_MAX_UNICODE 0x10ffff
17+
18+
19+
extern void _PyUnicode_Fill(
20+
int kind,
21+
void *data,
22+
Py_UCS4 value,
23+
Py_ssize_t start,
24+
Py_ssize_t length);
25+
extern int _PyUnicode_IsModifiable(PyObject *unicode);
26+
27+
28+
static inline int
29+
_PyUnicode_EnsureUnicode(PyObject *obj)
30+
{
31+
if (!PyUnicode_Check(obj)) {
32+
PyErr_Format(PyExc_TypeError,
33+
"must be str, not %T", obj);
34+
return -1;
35+
}
36+
return 0;
37+
}
38+
39+
static inline int
40+
_PyUnicodeWriter_WriteCharInline(_PyUnicodeWriter *writer, Py_UCS4 ch)
41+
{
42+
assert(ch <= _Py_MAX_UNICODE);
43+
if (_PyUnicodeWriter_Prepare(writer, 1, ch) < 0)
44+
return -1;
45+
PyUnicode_WRITE(writer->kind, writer->data, writer->pos, ch);
46+
writer->pos++;
47+
return 0;
48+
}
49+
50+
1451
/* --- Characters Type APIs ----------------------------------------------- */
1552

1653
extern int _PyUnicode_IsXidStart(Py_UCS4 ch);

Makefile.pre.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,9 @@ OBJECT_OBJS= \
558558
Objects/tupleobject.o \
559559
Objects/typeobject.o \
560560
Objects/typevarobject.o \
561-
Objects/unicodeobject.o \
561+
Objects/unicode_format.o \
562562
Objects/unicodectype.o \
563+
Objects/unicodeobject.o \
563564
Objects/unionobject.o \
564565
Objects/weakrefobject.o \
565566
@PERF_TRAMPOLINE_OBJ@
@@ -2105,6 +2106,7 @@ Objects/bytes_methods.o: $(srcdir)/Objects/bytes_methods.c $(BYTESTR_DEPS)
21052106
Objects/bytesobject.o: $(srcdir)/Objects/bytesobject.c $(BYTESTR_DEPS)
21062107
Objects/bytearrayobject.o: $(srcdir)/Objects/bytearrayobject.c $(BYTESTR_DEPS)
21072108

2109+
Objects/unicode_format.o: $(srcdir)/Objects/unicode_format.c $(UNICODE_DEPS)
21082110
Objects/unicodeobject.o: $(srcdir)/Objects/unicodeobject.c $(UNICODE_DEPS)
21092111

21102112
Objects/dictobject.o: $(srcdir)/Objects/stringlib/eq.h

Objects/stringlib/localeutil.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ InsertThousandsGrouping_fill(_PyUnicodeWriter *writer, Py_ssize_t *buffer_pos,
8989
}
9090
int kind = PyUnicode_KIND(writer->buffer);
9191
void *data = PyUnicode_DATA(writer->buffer);
92-
unicode_fill(kind, data, '0', *buffer_pos, n_zeros);
92+
_PyUnicode_Fill(kind, data, '0', *buffer_pos, n_zeros);
9393
if (forward) {
9494
*buffer_pos += n_zeros;
9595
}

0 commit comments

Comments
 (0)